Merge branch 'master' into moRags

This commit is contained in:
Alex Noir
2017-12-17 22:41:45 +03:00
81 changed files with 770 additions and 256 deletions
@@ -84,9 +84,13 @@ namespace Barotrauma
{
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
Collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
if (Math.Abs(Collider.Rotation-GetLimb(LimbType.Torso).Rotation)>Math.PI*0.6f)
{
Collider.SetTransform(Collider.SimPosition, MathHelper.WrapAngle(Collider.Rotation + (float)Math.PI));
}
Collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
return;
}
@@ -1083,8 +1087,6 @@ namespace Barotrauma
public override void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle)
{
Holdable holdable = item.GetComponent<Holdable>();
if (character.IsUnconscious || character.Stun > 0.0f) aim = false;
//calculate the handle positions
@@ -1102,7 +1104,6 @@ namespace Barotrauma
bool usingController = character.SelectedConstruction != null && character.SelectedConstruction.GetComponent<Controller>() != null;
float itemAngle;
if (Anim != Animation.Climbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero)
{
@@ -1114,6 +1115,7 @@ namespace Barotrauma
itemAngle = (torso.body.Rotation + holdAngle * Dir);
Holdable holdable = item.GetComponent<Holdable>();
if (holdable.ControlPose)
{
head.body.SmoothRotate(itemAngle);
@@ -1339,13 +1339,34 @@ namespace Barotrauma
}
}
Vector2 positionError = serverPos.Position - localPos.Position;
for (int i = localPosIndex; i < character.MemLocalState.Count; i++)
Hull serverHull = Hull.FindHull(serverPos.Position, character.CurrentHull, false);
Hull clientHull = Hull.FindHull(localPos.Position, serverHull, false);
Vector2 positionError = serverPos.Position - localPos.Position;
float rotationError = serverPos.Rotation - localPos.Rotation;
if (serverHull!=clientHull && ((serverHull==null) || (clientHull==null) || (serverHull.Submarine != clientHull.Submarine)))
{
character.MemLocalState[i].Translate(positionError);
//hull subs don't match => just teleport the player to exactly this position to avoid mismatches,
//since this would completely break the camera
positionError = Collider.SimPosition - serverPos.Position;
character.MemLocalState.Clear();
}
else
{
for (int i = localPosIndex; i < character.MemLocalState.Count; i++)
{
Hull pointHull = Hull.FindHull(character.MemLocalState[i].Position, clientHull, false);
if (pointHull != clientHull && ((pointHull == null) || (clientHull == null) || (pointHull.Submarine == clientHull.Submarine))) break;
character.MemLocalState[i].Translate(positionError, rotationError);
}
}
Collider.SetTransform(Collider.SimPosition + positionError, Collider.Rotation);
Collider.SetTransform(Collider.SimPosition + positionError, Collider.Rotation + rotationError);
foreach (Limb limb in Limbs)
{
limb.body.SetTransform(limb.body.SimPosition + positionError, limb.body.Rotation);
}
}
if (character.MemLocalState.Count > 120) character.MemLocalState.RemoveRange(0, character.MemLocalState.Count - 120);
@@ -138,6 +138,27 @@ namespace Barotrauma
return info != null && !string.IsNullOrWhiteSpace(info.Name) ? info.Name : SpeciesName;
}
}
//Only used by server logs to determine "true identity" of the player for cases when they're disguised
public string LogName
{
get
{
return info != null && !string.IsNullOrWhiteSpace(info.Name) ? info.Name + (info.DisplayName != info.Name ? " (as " + info.DisplayName + ")" : "") : SpeciesName;
}
}
private float hideFaceTimer;
public bool HideFace
{
get
{
return hideFaceTimer > 0.0f;
}
set
{
hideFaceTimer = MathHelper.Clamp(hideFaceTimer + (value ? 1.0f : -0.5f), 0.0f, 10.0f);
}
}
public string ConfigPath
{
@@ -591,7 +612,7 @@ namespace Barotrauma
{
AnimController = new HumanoidAnimController(this, doc.Root.Element("ragdoll"));
AnimController.TargetDir = Direction.Right;
inventory = new CharacterInventory(16, this);
inventory = new CharacterInventory(17, this);
}
else
{
@@ -926,13 +947,16 @@ namespace Barotrauma
}
}
for (int i = 0; i < selectedItems.Length; i++ )
if (SelectedConstruction == null || !SelectedConstruction.Prefab.DisableItemUsageWhenSelected)
{
if (selectedItems[i] == null) continue;
if (i == 1 && selectedItems[0] == selectedItems[1]) continue;
for (int i = 0; i < selectedItems.Length; i++ )
{
if (selectedItems[i] == null) continue;
if (i == 1 && selectedItems[0] == selectedItems[1]) continue;
if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this);
if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this);
if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this);
if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this);
}
}
if (selectedConstruction != null)
@@ -1406,6 +1430,8 @@ namespace Barotrauma
item.Submarine = Submarine;
}
}
HideFace = false;
if (isDead) return;
@@ -1633,7 +1659,7 @@ namespace Barotrauma
var attackingCharacter = attacker as Character;
if (attackingCharacter != null && attackingCharacter.AIController == null)
{
GameServer.Log(Name + " attacked by " + attackingCharacter.Name+". Damage: "+attackResult.Damage+" Bleeding damage: "+attackResult.Bleeding, ServerLog.MessageType.Attack);
GameServer.Log(LogName + " attacked by " + attackingCharacter.LogName +". Damage: "+attackResult.Damage+" Bleeding damage: "+attackResult.Bleeding, ServerLog.MessageType.Attack);
}
if (GameMain.Client == null &&
@@ -1798,7 +1824,7 @@ namespace Barotrauma
AnimController.Frozen = false;
GameServer.Log(Name+" has died (Cause of death: "+causeOfDeath+")", ServerLog.MessageType.Attack);
GameServer.Log(LogName+" has died (Cause of death: "+causeOfDeath+")", ServerLog.MessageType.Attack);
if (OnDeath != null) OnDeath(this, causeOfDeath);
@@ -12,7 +12,34 @@ namespace Barotrauma
partial class CharacterInfo
{
public string Name;
public string DisplayName
{
get {
string disguiseName = "?";
if (Character != null && Character.HideFace)
{
if (Character.Inventory != null)
{
var idCard = Character.Inventory.FindItem("ID Card");
if (idCard != null && Character.Inventory.IsInLimbSlot(idCard, InvSlotType.Card)) //Disguise as the ID card name if it's equipped
{
string[] readTags = idCard.Tags.Split(',');
foreach (string tag in readTags)
{
string[] s = tag.Split(':');
if (s[0] == "name")
{
disguiseName = s[1];
break;
}
}
}
}
return disguiseName;
}
return Name;
}
}
public Character Character;
public readonly string File;
@@ -15,18 +15,18 @@ namespace Barotrauma
public readonly AnimController.Animation Animation;
public CharacterStateInfo(Vector2 pos, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, 0, time, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float rotation, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, 0, time, dir, interact, animation)
{
}
public CharacterStateInfo(Vector2 pos, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, ID, 0.0f, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, ID, 0.0f, dir, interact, animation)
{
}
protected CharacterStateInfo(Vector2 pos, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: base(pos, ID, time)
protected CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: base(pos, rotation, ID, time)
{
Direction = dir;
Interact = interact;
@@ -197,6 +197,7 @@ namespace Barotrauma
{
var posInfo = new CharacterStateInfo(
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter == null ? (Entity)selectedConstruction : (Entity)SelectedCharacter,
@@ -471,6 +472,7 @@ namespace Barotrauma
tempBuffer.Write(SimPosition.X);
tempBuffer.Write(SimPosition.Y);
tempBuffer.Write(AnimController.Collider.Rotation);
tempBuffer.WritePadBits();
@@ -130,6 +130,10 @@ namespace Barotrauma
{
item.AddTag(s);
}
item.AddTag("name:" + character.Name);
item.AddTag("job:" + Name);
if (!string.IsNullOrWhiteSpace(spawnPoint.IdCardDesc))
item.Description = spawnPoint.IdCardDesc;
}
if (parentItem != null) parentItem.Combine(item);
@@ -265,7 +265,7 @@ namespace Barotrauma
{
SerializableProperty property;
if (!target.SerializableProperties.TryGetValue(propertyNames[i], out property)) continue;
if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(propertyNames[i], out property)) continue;
if (duration > 0.0f)
{
@@ -97,7 +97,7 @@ namespace Barotrauma
NewMessage("***************", Color.Cyan);
foreach (Client c in GameMain.Server.ConnectedClients)
{
NewMessage("- " + c.ID.ToString() + ": " + c.Name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), Color.Cyan);
NewMessage("- " + c.ID.ToString() + ": " + c.Name + (c.Character != null ? " playing " + c.Character.LogName : "") + ", " + c.Connection.RemoteEndPoint.Address.ToString(), Color.Cyan);
}
NewMessage("***************", Color.Cyan);
}));
@@ -114,6 +114,18 @@ namespace Barotrauma
NewMessage("The code words are: " + traitorManager.codeWords + ", response: " + traitorManager.codeResponse + ".", Color.Cyan);
}));
commands.Add(new Command("itemlist", "itemlist: List all the item prefabs available for spawning.", (string[] args) =>
{
NewMessage("***************", Color.Cyan);
foreach (MapEntityPrefab ep in MapEntityPrefab.List)
{
var itemPrefab = ep as ItemPrefab;
if (itemPrefab == null || itemPrefab.Name == null) continue;
NewMessage("- " + itemPrefab.Name, Color.Cyan);
}
NewMessage("***************", Color.Cyan);
}));
commands.Add(new Command("createfilelist", "", (string[] args) =>
{
UpdaterUtil.SaveFileList("filelist.xml");
@@ -360,7 +372,11 @@ namespace Barotrauma
commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) =>
{
if (GameMain.Server == null) return;
if (args.Length < 1) return;
if (args.Length < 1)
{
NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan);
return;
}
int id;
int.TryParse(args[0], out id);
@@ -370,7 +386,13 @@ namespace Barotrauma
ThrowError("Client id \"" + id + "\" not found.");
return;
}
NewMessage("Valid permissions are:",Color.White);
NewMessage(" - all",Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
NewMessage(" - " + permission.ToString(),Color.White);
}
ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) =>
{
ClientPermissions permission = ClientPermissions.None;
@@ -380,7 +402,11 @@ namespace Barotrauma
}
else
{
Enum.TryParse<ClientPermissions>(perm, out permission);
if (!Enum.TryParse<ClientPermissions>(perm, out permission))
{
ThrowError("\"" + perm + "\" sn't a valid permission!");
return;
}
}
client.SetPermissions(client.Permissions | permission);
GameMain.Server.UpdateClientPermissions(client);
@@ -391,7 +417,11 @@ namespace Barotrauma
commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) =>
{
if (GameMain.Server == null) return;
if (args.Length < 1) return;
if (args.Length < 1)
{
NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan);
return;
}
int id;
int.TryParse(args[0], out id);
@@ -402,6 +432,12 @@ namespace Barotrauma
return;
}
NewMessage("Valid permissions are:", Color.White);
NewMessage(" - all", Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
NewMessage(" - " + permission.ToString(), Color.White);
}
ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) =>
{
ClientPermissions permission = ClientPermissions.None;
@@ -411,7 +447,11 @@ namespace Barotrauma
}
else
{
Enum.TryParse<ClientPermissions>(perm, out permission);
if (!Enum.TryParse<ClientPermissions>(perm, out permission))
{
ThrowError("\"" + perm + "\" isn't a valid permission!");
return;
}
}
client.SetPermissions(client.Permissions & ~permission);
GameMain.Server.UpdateClientPermissions(client);
@@ -34,7 +34,7 @@ namespace Barotrauma
base.Init();
Vector2 position = Level.Loaded.GetRandomItemPos(
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 30.0f);
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f);
item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true;
@@ -28,7 +28,7 @@ namespace Barotrauma
public override void Start(Level level)
{
Vector2 spawnPos;
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, true, out spawnPos);
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out spawnPos);
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false);
monster.Enabled = false;
@@ -46,7 +46,7 @@ namespace Barotrauma
public override void Start(Level level)
{
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, 30.0f);
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, Level.Loaded.Size.X * 0.3f, 30.0f);
item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true;
@@ -85,7 +85,7 @@ namespace Barotrauma
if (disallowed) return null;
Vector2 spawnPos;
if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out spawnPos))
if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, 20000.0f, out spawnPos))
{
//no suitable position found, disable the event
repeat = false;
@@ -10,7 +10,7 @@ namespace Barotrauma
[Flags]
public enum InvSlotType
{
None = 0, Any = 1, RightHand = 2, LeftHand = 4, Head = 8, Torso = 16, Legs = 32, Face=64
None = 0, Any = 1, RightHand = 2, LeftHand = 4, Head = 8, Torso = 16, Legs = 32, Face=64, Card=128
};
partial class CharacterInventory : Inventory
@@ -18,7 +18,7 @@ namespace Barotrauma
private Character character;
public static InvSlotType[] limbSlots = new InvSlotType[] {
InvSlotType.Head, InvSlotType.Torso, InvSlotType.Legs, InvSlotType.LeftHand, InvSlotType.RightHand, InvSlotType.Face,
InvSlotType.Head, InvSlotType.Torso, InvSlotType.Legs, InvSlotType.LeftHand, InvSlotType.RightHand, InvSlotType.Face, InvSlotType.Card,
InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any,
InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any, InvSlotType.Any};
@@ -699,12 +699,12 @@ namespace Barotrauma.Items.Components
if (docked)
{
if (item.Submarine != null && dockingTarget?.item?.Submarine != null)
GameServer.Log(sender.Name + " docked " + item.Submarine.Name + " to " + dockingTarget.item.Submarine.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(sender.LogName + " docked " + item.Submarine.Name + " to " + dockingTarget.item.Submarine.Name, ServerLog.MessageType.ItemInteraction);
}
else
{
if (item.Submarine != null && prevDockingTarget?.item?.Submarine != null)
GameServer.Log(sender.Name + " undocked " + item.Submarine.Name + " from " + prevDockingTarget.item.Submarine.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(sender.LogName + " undocked " + item.Submarine.Name + " from " + prevDockingTarget.item.Submarine.Name, ServerLog.MessageType.ItemInteraction);
}
}
}
@@ -13,7 +13,7 @@ using Barotrauma.Lights;
namespace Barotrauma.Items.Components
{
partial class Door : ItemComponent, IDrawableComponent, IServerSerializable
partial class Door : Pickable, IDrawableComponent, IServerSerializable
{
private Gap linkedGap;
@@ -203,12 +203,13 @@ namespace Barotrauma.Items.Components
#endif
}
public override bool Pick(Character picker)
public override bool OnPicked(Character picker)
{
isOpen = !isOpen;
return true;
SetState(predictedState == null ? !isOpen : !predictedState.Value, false, true); //crowbar function
#if CLIENT
PlaySound(ActionType.OnPicked, item.WorldPosition);
#endif
return false;
}
public override bool Select(Character character)
@@ -419,7 +420,7 @@ namespace Barotrauma.Items.Components
bool newState = predictedState == null ? isOpen : predictedState.Value;
if (sender != null && wasOpen != newState)
{
GameServer.Log(sender.Name + (newState ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(sender.LogName + (newState ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction);
}
}
@@ -184,13 +184,13 @@ namespace Barotrauma.Items.Components
item.SetTransform(rightHand.SimPosition, 0.0f);
}
bool alreadySelected = character.HasSelectedItem(item);
if (picker.TrySelectItem(item))
bool alreadySelected = character.HasEquippedItem(item);
if (picker.TrySelectItem(item) || picker.HasEquippedItem(item))
{
item.body.Enabled = true;
IsActive = true;
if (!alreadySelected) GameServer.Log(character.Name + " equipped " + item.Name, ServerLog.MessageType.ItemInteraction);
if (!alreadySelected) GameServer.Log(character.LogName + " equipped " + item.Name, ServerLog.MessageType.ItemInteraction);
}
}
@@ -200,7 +200,7 @@ namespace Barotrauma.Items.Components
picker.DeselectItem(item);
GameServer.Log(character.Name + " unequipped " + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(character.LogName + " unequipped " + item.Name, ServerLog.MessageType.ItemInteraction);
item.body.Enabled = false;
IsActive = false;
@@ -224,7 +224,7 @@ namespace Barotrauma.Items.Components
}
}
protected override bool OnPicked(Character picker)
public override bool OnPicked(Character picker)
{
if (base.OnPicked(picker))
{
@@ -235,7 +235,7 @@ namespace Barotrauma.Items.Components
item.CreateServerEvent(this);
if (picker != null)
{
Networking.GameServer.Log(picker.Name + " detached " + item.Name + " from a wall", ServerLog.MessageType.ItemInteraction);
Networking.GameServer.Log(picker.LogName + " detached " + item.Name + " from a wall", ServerLog.MessageType.ItemInteraction);
}
}
return true;
@@ -290,7 +290,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
GameServer.Log(character.Name + " attached " + item.Name+" to a wall", ServerLog.MessageType.ItemInteraction);
GameServer.Log(character.LogName + " attached " + item.Name+" to a wall", ServerLog.MessageType.ItemInteraction);
}
item.Drop();
}
@@ -308,7 +308,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (item.body == null || !item.body.Enabled) return;
if (picker == null || !picker.HasSelectedItem(item))
if (picker == null || !picker.HasEquippedItem(item))
{
IsActive = false;
return;
@@ -320,7 +320,37 @@ namespace Barotrauma.Items.Components
item.Submarine = picker.Submarine;
picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle);
if (picker.HasSelectedItem(item))
{
picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle);
}
else
{
Limb equipLimb = null;
if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Face) || picker.Inventory.IsInLimbSlot(item, InvSlotType.Head))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Head);
}
else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Torso))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Torso);
}
else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Legs))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Waist);
}
if (equipLimb != null)
{
float itemAngle = (equipLimb.Rotation + holdAngle * picker.AnimController.Dir);
Matrix itemTransfrom = Matrix.CreateRotationZ(equipLimb.Rotation);
Vector2 transformedHandlePos = Vector2.Transform(handlePos[0], itemTransfrom);
item.body.ResetDynamics();
item.SetTransform(equipLimb.SimPosition - transformedHandlePos, itemAngle);
}
}
}
protected void Flip(Item item)
@@ -137,7 +137,7 @@ namespace Barotrauma.Items.Components
}
else
{
ac.HoldItem(deltaTime, item, handlePos, new Vector2(hitPos, 0.0f), aimPos, false, holdAngle);
ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, false, holdAngle);
}
}
else
@@ -255,12 +255,12 @@ namespace Barotrauma.Items.Components
{
GameMain.Server.CreateEntityEvent(item, new object[] { Networking.NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, targetCharacter.ID });
string logStr = picker?.Name + " used " + item.Name;
string logStr = picker?.LogName + " used " + item.Name;
if (item.ContainedItems != null && item.ContainedItems.Length > 0)
{
logStr += "(" + string.Join(", ", item.ContainedItems.Select(i => i?.Name)) + ")";
}
logStr += " on " + targetCharacter + ".";
logStr += " on " + targetCharacter.LogName + ".";
Networking.GameServer.Log(logStr, Networking.ServerLog.MessageType.Attack);
}
@@ -70,7 +70,7 @@ namespace Barotrauma.Items.Components
}
}
protected virtual bool OnPicked(Character picker)
public virtual bool OnPicked(Character picker)
{
if (picker.Inventory.TryPutItem(item, picker, allowedSlots))
{
@@ -89,6 +89,7 @@ namespace Barotrauma.Items.Components
#if CLIENT
if (!GameMain.Instance.LoadingScreenOpen && picker == Character.Controlled) GUI.PlayUISound(GUISoundType.PickItem);
PlaySound(ActionType.OnPicked, item.WorldPosition);
#endif
return true;
@@ -11,6 +11,7 @@ namespace Barotrauma.Items.Components
float throwPos;
bool throwing;
bool throwDone;
[Serialize(1.0f, false)]
public float ThrowForce
@@ -27,18 +28,14 @@ namespace Barotrauma.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (character == null) return false;
if (!character.IsKeyDown(InputType.Aim) || throwing) return false;
throwing = true;
IsActive = true;
return true;
return true; //We do the actual throwing in Aim because Use might be used by chems
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (throwing) return;
if (!throwDone) return false; //This should only be triggered in update
throwDone = false;
return true;
}
public override void Drop(Character dropper)
@@ -57,7 +54,14 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (!item.body.Enabled) return;
if (!picker.HasSelectedItem(item)) IsActive = false;
if (!picker.HasSelectedItem(item))
{
IsActive = false;
return;
}
if (picker.IsKeyDown(InputType.Aim) && picker.IsKeyHit(InputType.Use))
throwing = true;
if (!picker.IsKeyDown(InputType.Aim) && !throwing) throwPos = 0.0f;
@@ -93,7 +97,7 @@ namespace Barotrauma.Items.Components
Vector2 throwVector = picker.CursorWorldPosition - picker.WorldPosition;
throwVector = Vector2.Normalize(throwVector);
GameServer.Log(picker.Name + " threw " + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(picker.LogName + " threw " + item.Name, ServerLog.MessageType.ItemInteraction);
item.Drop();
item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f);
@@ -103,7 +107,8 @@ namespace Barotrauma.Items.Components
Limb rightHand = ac.GetLimb(LimbType.RightHand);
item.body.AngularVelocity = rightHand.body.AngularVelocity;
throwDone = true;
ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, picker); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse"
throwing = false;
}
}
@@ -291,7 +291,10 @@ namespace Barotrauma.Items.Components
}
//called when the item is equipped and right mouse button is pressed
public virtual void SecondaryUse(float deltaTime, Character character = null) { }
public virtual bool SecondaryUse(float deltaTime, Character character = null)
{
return false;
}
//called when the item is placed in a "limbslot"
public virtual void Equip(Character character) { }
@@ -503,13 +506,15 @@ namespace Barotrauma.Items.Components
}
List<RelatedItem> prevRequiredItems = new List<RelatedItem>(requiredItems);
requiredItems.Clear();
bool overrideRequiredItems = false;
foreach (XElement subElement in componentElement.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "requireditem":
if (!overrideRequiredItems) requiredItems.Clear();
overrideRequiredItems = true;
RelatedItem newRequiredItem = RelatedItem.Load(subElement);
if (newRequiredItem == null) continue;
@@ -160,20 +160,20 @@ namespace Barotrauma.Items.Components
return true;
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item))
{
character = null;
return;
return false;
}
if (character == null) return;
if (character == null) return false;
Entity focusTarget = GetFocusTarget();
if (focusTarget == null)
{
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
return;
return false;
}
character.ViewTarget = focusTarget;
@@ -191,6 +191,8 @@ namespace Barotrauma.Items.Components
{
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
}
return true;
}
private Item GetFocusTarget()
@@ -105,7 +105,7 @@ namespace Barotrauma.Items.Components
if (user != null)
{
GameServer.Log(user.Name + (IsActive ? " activated " : " deactivated ") + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(user.LogName + (IsActive ? " activated " : " deactivated ") + item.Name, ServerLog.MessageType.ItemInteraction);
}
#if CLIENT
@@ -159,7 +159,7 @@ namespace Barotrauma.Items.Components
if (user != null)
{
GameServer.Log(user.Name + " started fabricating " + selectedItem.TargetItem.Name + " in " + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(user.LogName + " started fabricating " + selectedItem.TargetItem.Name + " in " + item.Name, ServerLog.MessageType.ItemInteraction);
}
#if CLIENT
@@ -184,7 +184,7 @@ namespace Barotrauma.Items.Components
{
if (fabricatedItem != null && user != null)
{
GameServer.Log(user.Name + " cancelled the fabrication of " + fabricatedItem.TargetItem.Name + " in " + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(user.LogName + " cancelled the fabrication of " + fabricatedItem.TargetItem.Name + " in " + item.Name, ServerLog.MessageType.ItemInteraction);
}
IsActive = false;
@@ -157,11 +157,11 @@ namespace Barotrauma.Items.Components
{
if (newFlowPercentage != FlowPercentage)
{
GameServer.Log(c.Character + " set the pumping speed of " + item.Name + " to " + (int)(newFlowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(c.Character.LogName + " set the pumping speed of " + item.Name + " to " + (int)(newFlowPercentage) + " %", ServerLog.MessageType.ItemInteraction);
}
if (newIsActive != IsActive)
{
GameServer.Log(c.Character + (newIsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(c.Character.LogName + (newIsActive ? " turned on " : " turned off ") + item.Name, ServerLog.MessageType.ItemInteraction);
}
FlowPercentage = newFlowPercentage;
@@ -173,7 +173,7 @@ namespace Barotrauma.Items.Components
{
if (Timing.TotalTime >= (float)nextServerLogWriteTime)
{
GameServer.Log(lastUser + " adjusted reactor settings: " +
GameServer.Log(lastUser.LogName + " adjusted reactor settings: " +
"Temperature: " + (int)temperature +
", Fission rate: " + (int)fissionRate +
", Cooling rate: " + (int)coolingRate +
@@ -201,7 +201,7 @@ namespace Barotrauma.Items.Components
if (item.CanClientAccess(c))
{
RechargeSpeed = newRechargeSpeed;
GameServer.Log(c.Character + " set the recharge speed of "+item.Name+" to "+ (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
GameServer.Log(c.Character.LogName + " set the recharge speed of "+item.Name+" to "+ (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", ServerLog.MessageType.ItemInteraction);
}
item.CreateServerEvent(this);
@@ -88,7 +88,16 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (currPowerConsumption == 0.0f) return;
if (currPowerConsumption == 0.0f)
{
//if the item consumes no power, ignore the voltage requirement and
//apply OnActive statuseffects as long as this component is active
if (powerConsumption == 0.0f)
{
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
}
return;
}
#if CLIENT
if (voltage > minVoltage)
@@ -12,9 +12,14 @@ namespace Barotrauma.Items.Components
{
class Projectile : ItemComponent
{
private float launchImpulse;
//continuous collision detection is used while the projectile is moving faster than this
const float ContinuousCollisionThreshold = 5.0f;
private bool doesStick;
//a duration during which the projectile won't drop from the body it's stuck to
private const float PersistentStickJointDuration = 1.0f;
private float launchImpulse;
private PrismaticJoint stickJoint;
private Body stickTarget;
@@ -24,6 +29,8 @@ namespace Barotrauma.Items.Components
public Character User;
private float persistentStickJointTimer;
[Serialize(10.0f, false)]
public float LaunchImpulse
{
@@ -39,10 +46,32 @@ namespace Barotrauma.Items.Components
}
[Serialize(false, false)]
//backwards compatibility, can stick to anything
public bool DoesStick
{
get { return doesStick; }
set { doesStick = value; }
get;
set;
}
[Serialize(false, false)]
public bool StickToCharacters
{
get;
set;
}
[Serialize(false, false)]
public bool StickToStructures
{
get;
set;
}
[Serialize(false, false)]
public bool StickToItems
{
get;
set;
}
[Serialize(false, false)]
@@ -106,7 +135,7 @@ namespace Barotrauma.Items.Components
IsActive = true;
if (stickJoint == null || !doesStick) return;
if (stickJoint == null) return;
if (stickTarget != null)
{
@@ -182,7 +211,7 @@ namespace Barotrauma.Items.Components
//the raycast didn't hit anything -> the projectile flew somewhere outside the level and is permanently lost
if (!hitSomething)
{
Item.Spawner.AddToRemoveQueue(item);
Entity.Spawner.AddToRemoveQueue(item);
}
}
@@ -190,8 +219,23 @@ namespace Barotrauma.Items.Components
{
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
if (stickJoint != null &&
(stickJoint.JointTranslation < stickJoint.LowerLimit * 0.9f || stickJoint.JointTranslation > stickJoint.UpperLimit * 0.9f))
if (item.body != null && item.body.FarseerBody.IsBullet)
{
if (item.body.LinearVelocity.LengthSquared() < ContinuousCollisionThreshold * ContinuousCollisionThreshold)
{
item.body.FarseerBody.IsBullet = false;
}
}
if (stickJoint == null) return;
if (persistentStickJointTimer > 0.0f)
{
persistentStickJointTimer -= deltaTime;
return;
}
if (stickJoint.JointTranslation < stickJoint.LowerLimit * 0.9f || stickJoint.JointTranslation > stickJoint.UpperLimit * 0.9f)
{
if (stickTarget != null)
{
@@ -218,7 +262,7 @@ namespace Barotrauma.Items.Components
stickJoint = null;
IsActive = false;
if (!item.body.FarseerBody.IsBullet) IsActive = false;
}
}
@@ -237,6 +281,7 @@ namespace Barotrauma.Items.Components
}
AttackResult attackResult = new AttackResult();
Character character = null;
if (attack != null)
{
var submarine = target.Body.UserData as Submarine;
@@ -248,11 +293,13 @@ namespace Barotrauma.Items.Components
return true;
}
Limb limb;
Limb limb = target.Body.UserData as Limb;
Structure structure;
if ((limb = (target.Body.UserData as Limb)) != null)
if (limb != null)
{
attackResult = attack.DoDamageToLimb(User, limb, item.WorldPosition, 1.0f);
if (limb.character != null)
character = limb.character;
}
else if ((structure = (target.Body.UserData as Structure)) != null)
{
@@ -260,14 +307,11 @@ namespace Barotrauma.Items.Components
}
}
ApplyStatusEffects(ActionType.OnUse, 1.0f);
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
IsActive = false;
ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
ApplyStatusEffects(ActionType.OnImpact, 1.0f, character);
item.body.FarseerBody.OnCollision -= OnProjectileCollision;
item.body.FarseerBody.IsBullet = false;
item.body.CollisionCategories = Physics.CollisionItem;
item.body.CollidesWith = Physics.CollisionWall | Physics.CollisionLevel;
@@ -280,17 +324,20 @@ namespace Barotrauma.Items.Components
{
item.body.LinearVelocity *= 0.1f;
}
else if (doesStick)
else if (Vector2.Dot(item.body.LinearVelocity, collisionNormal) < 0.0f &&
(DoesStick ||
(StickToCharacters && target.Body.UserData is Limb) ||
(StickToStructures && target.Body.UserData is Structure) ||
(StickToItems && target.Body.UserData is Item)))
{
Vector2 dir = new Vector2(
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation));
StickToTarget(target.Body, dir);
item.body.LinearVelocity *= 0.5f;
if (Vector2.Dot(item.body.LinearVelocity, collisionNormal) < 0.0f)
{
StickToTarget(target.Body, dir);
return Hitscan;
}
return Hitscan;
}
else
{
@@ -306,7 +353,7 @@ namespace Barotrauma.Items.Components
{
contained.SetTransform(item.SimPosition, contained.body.Rotation);
}
contained.Condition = 0.0f;
//contained.Condition = 0.0f; //Let the freaking .xml handle it jeez
}
}
@@ -333,6 +380,8 @@ namespace Barotrauma.Items.Components
stickJoint.UpperLimit = ConvertUnits.ToSimUnits(item.Sprite.size.X * 0.3f);
}
persistentStickJointTimer = PersistentStickJointDuration;
item.body.FarseerBody.IgnoreCollisionWith(targetBody);
stickTarget = targetBody;
GameMain.World.AddJoint(stickJoint);
@@ -118,9 +118,9 @@ namespace Barotrauma.Items.Components
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (reload > 0.0f) return;
if (reload > 0.0f) return false;
bool first = true;
for (int i = 0; i < ropeBodies.Length - 1; i++)
@@ -157,7 +157,8 @@ namespace Barotrauma.Items.Components
//ropeBodies[i + 1].ApplyForce(dist / length * pullForce * 0.1f);
}
}
}
return true;
}
private void NextSection(int i)
@@ -215,7 +215,7 @@ namespace Barotrauma.Items.Components
if (existingWire.Locked)
{
//this should not be possible unless the client is running a modified version of the game
GameServer.Log(c.Character.Name + " attempted to disconnect a locked wire from " +
GameServer.Log(c.Character.LogName + " attempted to disconnect a locked wire from " +
Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.Error);
continue;
}
@@ -224,20 +224,37 @@ namespace Barotrauma.Items.Components
if (existingWire.Connections[0] == null && existingWire.Connections[1] == null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
GameServer.Log(c.Character.LogName + " disconnected a wire from " +
Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (existingWire.Connections[0] != null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
GameServer.Log(c.Character.LogName + " disconnected a wire from " +
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
//wires that are not in anyone's inventory (i.e. not currently being rewired)
//can never be connected to only one connection
// -> the client must have dropped the wire from the connection panel
if (existingWire.Item.ParentInventory == null)
{
//let other clients know the item was also disconnected from the other connection
existingWire.Connections[0].Item.CreateServerEvent(existingWire.Connections[0].Item.GetComponent<ConnectionPanel>());
existingWire.Item.Drop(c.Character);
}
}
else if (existingWire.Connections[1] != null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
GameServer.Log(c.Character.LogName + " disconnected a wire from " +
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
if (existingWire.Item.ParentInventory == null)
{
//let other clients know the item was also disconnected from the other connection
existingWire.Connections[1].Item.CreateServerEvent(existingWire.Connections[1].Item.GetComponent<ConnectionPanel>());
existingWire.Item.Drop(c.Character);
}
}
Connections[i].Wires[j] = null;
}
@@ -259,13 +276,13 @@ namespace Barotrauma.Items.Components
if (otherConnection == null)
{
GameServer.Log(c.Character.Name + " connected a wire to " +
GameServer.Log(c.Character.LogName + " connected a wire to " +
Connections[i].Item.Name + " (" + Connections[i].Name + ")",
ServerLog.MessageType.ItemInteraction);
}
else
{
GameServer.Log(c.Character.Name + " connected a wire from " +
GameServer.Log(c.Character.LogName + " connected a wire from " +
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " +
(otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"),
ServerLog.MessageType.ItemInteraction);
@@ -281,6 +298,9 @@ namespace Barotrauma.Items.Components
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
List<Wire> prevWires = Connections.SelectMany(c => Array.FindAll(c.Wires, w => w != null)).ToList();
List<Wire> newWires = new List<Wire>();
foreach (Connection connection in Connections)
{
connection.ClearConnections();
@@ -289,16 +309,33 @@ namespace Barotrauma.Items.Components
{
ushort wireId = msg.ReadUInt16();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
Item wireItem = Entity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
newWires.Add(wireComponent);
connection.Wires[i] = wireComponent;
wireComponent.Connect(connection, false);
}
}
foreach (Wire wire in prevWires)
{
if (wire.Connections[0] == null && wire.Connections[1] == null)
{
wire.Item.Drop(null);
}
//wires that are not in anyone's inventory (i.e. not currently being rewired) can never be connected to only one connection
// -> someone must have dropped the wire from the connection panel
else if (wire.Item.ParentInventory == null &&
(wire.Connections[0] != null ^ wire.Connections[1] != null))
{
wire.Item.Drop(null);
}
}
}
}
}
@@ -242,7 +242,7 @@ namespace Barotrauma.Items.Components
return true;
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (nodes.Count > 1)
{
@@ -251,6 +251,7 @@ namespace Barotrauma.Items.Components
}
Drawable = IsActive || sections.Count > 0;
return true;
}
public override bool Pick(Character picker)
@@ -307,18 +308,18 @@ namespace Barotrauma.Items.Components
{
if (connections[0] != null && connections[1] != null)
{
GameServer.Log(user.Name + " disconnected a wire from " +
GameServer.Log(user.LogName + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[0] != null)
{
GameServer.Log(user.Name + " disconnected a wire from " +
GameServer.Log(user.LogName + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[1] != null)
{
GameServer.Log(user.Name + " disconnected a wire from " +
GameServer.Log(user.LogName + " disconnected a wire from " +
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
}
@@ -175,7 +175,7 @@ namespace Barotrauma.Items.Components
if (character != null)
{
string msg = character.Name + " launched " + item.Name + " (projectile: " + projectiles[0].Item.Name;
string msg = character.LogName + " launched " + item.Name + " (projectile: " + projectiles[0].Item.Name;
if (projectiles[0].Item.ContainedItems == null || projectiles[0].Item.ContainedItems.All(i => i == null))
{
msg += ")";
@@ -212,11 +212,11 @@ namespace Barotrauma
{
if (Owner == c.Character)
{
GameServer.Log(c.Character + " picked up " + item.Name, ServerLog.MessageType.Inventory);
GameServer.Log(c.Character.LogName+ " picked up " + item.Name, ServerLog.MessageType.Inventory);
}
else
{
GameServer.Log(c.Character + " placed " + item.Name + " in " + Owner, ServerLog.MessageType.Inventory);
GameServer.Log(c.Character.LogName + " placed " + item.Name + " in " + Owner, ServerLog.MessageType.Inventory);
}
}
}
@@ -227,11 +227,11 @@ namespace Barotrauma
{
if (Owner == c.Character)
{
GameServer.Log(c.Character + " dropped " + item.Name, ServerLog.MessageType.Inventory);
GameServer.Log(c.Character.LogName + " dropped " + item.Name, ServerLog.MessageType.Inventory);
}
else
{
GameServer.Log(c.Character + " removed " + item.Name + " from " + Owner, ServerLog.MessageType.Inventory);
GameServer.Log(c.Character.LogName + " removed " + item.Name + " from " + Owner, ServerLog.MessageType.Inventory);
}
}
}
@@ -119,9 +119,12 @@ namespace Barotrauma
get { return prefab.Name; }
}
private string description;
[Editable, Serialize("", true)]
public string Description
{
get { return prefab.Description; }
get { return description == null ? prefab.Description : description; }
set { description = value; }
}
public float ImpactTolerance
@@ -800,6 +803,7 @@ namespace Barotrauma
if (!ic.WasUsed)
{
ic.StopSounds(ActionType.OnUse);
ic.StopSounds(ActionType.OnSecondaryUse);
}
#endif
ic.WasUsed = false;
@@ -1167,11 +1171,28 @@ namespace Barotrauma
public void SecondaryUse(float deltaTime, Character character = null)
{
if (condition == 0.0f) return;
bool remove = false;
foreach (ItemComponent ic in components)
{
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
ic.SecondaryUse(deltaTime, character);
if (ic.SecondaryUse(deltaTime, character))
{
ic.WasUsed = true;
#if CLIENT
ic.PlaySound(ActionType.OnSecondaryUse, WorldPosition);
#endif
ic.ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, character);
if (ic.DeleteOnUse) remove = true;
}
}
if (remove) Remove();
}
public List<ColoredText> GetHUDTexts(Character character)
@@ -1341,12 +1362,12 @@ namespace Barotrauma
if (ContainedItems == null || ContainedItems.All(i => i == null))
{
GameServer.Log(c.Character.Name + " used item " + Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(c.Character.LogName + " used item " + Name, ServerLog.MessageType.ItemInteraction);
}
else
{
GameServer.Log(
c.Character.Name + " used item " + Name + " (contained items: " + string.Join(", ", Array.FindAll(ContainedItems, i => i != null).Select(i => i.Name)) + ")",
c.Character.LogName + " used item " + Name + " (contained items: " + string.Join(", ", Array.FindAll(ContainedItems, i => i != null).Select(i => i.Name)) + ")",
ServerLog.MessageType.ItemInteraction);
}
@@ -1440,6 +1461,7 @@ namespace Barotrauma
if (GameMain.Server == null) return;
msg.Write(Prefab.Name);
msg.Write(Description);
msg.Write(ID);
if (ParentInventory == null || ParentInventory.Owner == null)
@@ -1458,7 +1480,8 @@ namespace Barotrauma
msg.Write(index < 0 ? (byte)255 : (byte)index);
}
if (Name == "ID Card") msg.Write(Tags);
//TODO: See if tags are different from their prefab before sending 'em
msg.Write(Tags);
}
public static Item ReadSpawnData(NetBuffer msg, bool spawn = true)
@@ -1466,6 +1489,7 @@ namespace Barotrauma
if (GameMain.Server != null) return null;
string itemName = msg.ReadString();
string itemDesc = msg.ReadString();
ushort itemId = msg.ReadUInt16();
ushort inventoryId = msg.ReadUInt16();
@@ -1489,11 +1513,7 @@ namespace Barotrauma
}
}
string tags = "";
if (itemName == "ID Card")
{
tags = msg.ReadString();
}
string tags = msg.ReadString();
if (!spawn) return null;
@@ -1523,6 +1543,7 @@ namespace Barotrauma
var item = new Item(itemPrefab, pos, sub);
item.Description = itemDesc;
item.ID = itemId;
if (sub != null)
{
@@ -134,6 +134,13 @@ namespace Barotrauma
private set;
}
[Serialize(false, false)]
public bool DisableItemUsageWhenSelected
{
get;
private set;
}
public bool CanSpriteFlipX
{
get { return canSpriteFlipX; }
@@ -74,6 +74,15 @@ namespace Barotrauma
{
if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue;
//don't apply OnFire effects if the item is inside a fireproof container
//(or if it's inside a container that's inside a fireproof container, etc)
Item container = item.Container;
while (container != null)
{
if (container.FireProof) return;
container = container.Container;
}
if (Vector2.Distance(item.WorldPosition, worldPosition) > attack.Range * 0.1f) continue;
item.ApplyStatusEffects(ActionType.OnFire, 1.0f);
@@ -217,7 +217,15 @@ namespace Barotrauma
foreach (Item item in Item.ItemList)
{
if (item.CurrentHull != hull || item.FireProof || item.Condition <= 0.0f) continue;
if (item.ParentInventory != null && item.ParentInventory.Owner is Character) return;
//don't apply OnFire effects if the item is inside a fireproof container
//(or if it's inside a container that's inside a fireproof container, etc)
Item container = item.Container;
while (container != null)
{
if (container.FireProof) return;
container = container.Container;
}
float range = (float)Math.Sqrt(size.X) * 10.0f;
if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue;
@@ -163,8 +163,11 @@ namespace Barotrauma
searchPos[1] = new Vector2(rect.Center.X, rect.Y - rect.Height);
}
hulls[0] = Hull.FindHullOld(searchPos[0], null, false);
hulls[1] = Hull.FindHullOld(searchPos[1], null, false);
for (int i = 0; i < 2; i++)
{
hulls[i] = Hull.FindHullOld(searchPos[i], null, false);
if (hulls[i] == null) hulls[i] = Hull.FindHullOld(searchPos[i], null, false, true);
}
if (hulls[0] == null && hulls[1] == null) return;
@@ -558,23 +558,23 @@ namespace Barotrauma
return null;
}
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = false)
{
return FindHullOld(position, hullList, guess, useWorldCoordinates);
return FindHullOld(position, hullList, guess, useWorldCoordinates, inclusive);
}
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = false)
{
if (guess != null && hulls.Contains(guess))
{
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position, inclusive)) return guess;
}
foreach (Hull hull in hulls)
{
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position, inclusive)) return hull;
}
return null;
@@ -817,7 +817,7 @@ namespace Barotrauma
//50% chance of placing the ruins at a cave
if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f)
{
TryGetInterestingPosition(true, PositionType.Cave, false, out ruinPos);
TryGetInterestingPosition(true, PositionType.Cave, 0.0f, out ruinPos);
}
ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2);
@@ -894,7 +894,7 @@ namespace Barotrauma
}
}
public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float offsetFromWall = 10.0f)
public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float minDistFromSubs, float offsetFromWall = 10.0f)
{
if (!positionsOfInterest.Any()) return Size*0.5f;
@@ -906,7 +906,7 @@ namespace Barotrauma
do
{
Vector2 startPos;
Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out startPos);
Loaded.TryGetInterestingPosition(true, spawnPosType, minDistFromSubs, out startPos);
startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server);
@@ -935,7 +935,7 @@ namespace Barotrauma
public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs, out Vector2 position)
public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, float minDistFromSubs, out Vector2 position)
{
if (!positionsOfInterest.Any())
{
@@ -945,17 +945,20 @@ namespace Barotrauma
var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType));
if (avoidSubs)
if (minDistFromSubs > 0.0f)
{
foreach (Submarine sub in Submarine.Loaded)
{
float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height);
matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist);
matchingPositions.RemoveAll(p => Vector2.DistanceSquared(p.Position, sub.WorldPosition) < minDistFromSubs * minDistFromSubs);
}
}
if (!matchingPositions.Any())
{
#if DEBUG
DebugConsole.ThrowError("Could not find a suitable position of interest. (PositionType: " + positionType + ", minDistFromSubs: " + minDistFromSubs + "\n" + Environment.StackTrace);
#endif
position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position;
return false;
}
@@ -506,15 +506,15 @@ namespace Barotrauma
float impact = Vector2.Dot(f2.Body.LinearVelocity, -normal)*f2.Body.Mass*0.1f;
if (impact < 10.0f) return true;
#if CLIENT
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact,
new Vector2(
sections[section].rect.X + sections[section].rect.Width / 2,
sections[section].rect.Y - sections[section].rect.Height / 2));
sections[section].rect.X + sections[section].rect.Width / 2,
sections[section].rect.Y - sections[section].rect.Height / 2), tags: Tags);
#endif
if (impact < 10.0f) return true;
AddDamage(section, impact);
}
}
@@ -661,10 +661,10 @@ namespace Barotrauma
#if CLIENT
GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f);
if (playSound && !SectionBodyDisabled(i))
if (playSound)// && !SectionBodyDisabled(i))
{
DamageSoundType damageSoundType = (attack.DamageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, worldPosition);
SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, worldPosition, tags: Tags);
}
#endif
@@ -491,10 +491,18 @@ namespace Barotrauma
return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
}
public static bool RectContains(Rectangle rect, Vector2 pos)
public static bool RectContains(Rectangle rect, Vector2 pos, bool inclusive = false)
{
return (pos.X > rect.X && pos.X < rect.X + rect.Width
&& pos.Y < rect.Y && pos.Y > rect.Y - rect.Height);
if (inclusive)
{
return (pos.X >= rect.X && pos.X <= rect.X + rect.Width
&& pos.Y <= rect.Y && pos.Y >= rect.Y - rect.Height);
}
else
{
return (pos.X > rect.X && pos.X < rect.X + rect.Width
&& pos.Y < rect.Y && pos.Y > rect.Y - rect.Height);
}
}
public static bool RectsOverlap(Rectangle rect1, Rectangle rect2, bool inclusive=true)
@@ -1258,7 +1266,7 @@ namespace Barotrauma
return;
}
subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, sendingTime));
subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, 0.0f, sendingTime));
}
}
@@ -21,6 +21,7 @@ namespace Barotrauma
protected SpawnType spawnType;
//characters spawning at the waypoint will be given an ID card with these tags
private string idCardDesc;
private string[] idCardTags;
//only characters with this job will be spawned at the waypoint
@@ -57,6 +58,11 @@ namespace Barotrauma
}
}
public string IdCardDesc
{
get { return idCardDesc; }
private set { idCardDesc = value; }
}
public string[] IdCardTags
{
get { return idCardTags; }
@@ -113,6 +119,7 @@ namespace Barotrauma
public override MapEntity Clone()
{
var clone = new WayPoint(rect, Submarine);
clone.idCardDesc = idCardDesc;
clone.idCardTags = idCardTags;
clone.spawnType = spawnType;
clone.assignedJob = assignedJob;
@@ -570,6 +577,11 @@ namespace Barotrauma
Enum.TryParse<SpawnType>(element.GetAttributeString("spawn", "Path"), out w.spawnType);
string idCardDescString = element.GetAttributeString("idcarddesc", "");
if (!string.IsNullOrWhiteSpace(idCardDescString))
{
w.IdCardDesc = idCardDescString;
}
string idCardTagString = element.GetAttributeString("idcardtags", "");
if (!string.IsNullOrWhiteSpace(idCardTagString))
{
@@ -604,6 +616,7 @@ namespace Barotrauma
new XAttribute("y", (int)(rect.Y - Submarine.HiddenSubPosition.Y)),
new XAttribute("spawn", spawnType));
if (!string.IsNullOrWhiteSpace(idCardDesc)) element.Add(new XAttribute("idcarddesc", idCardDesc));
if (idCardTags.Length > 0)
{
element.Add(new XAttribute("idcardtags", string.Join(",", idCardTags)));
@@ -105,18 +105,18 @@ namespace Barotrauma.Networking
return ApplyDistanceEffect(listener, Sender, Text, SpeakRange);
}
public static string ApplyDistanceEffect(Entity listener, Entity Sender, string text, float range)
public static string ApplyDistanceEffect(Entity listener, Entity Sender, string text, float range, float obstructionmult = 2.0f)
{
if (listener.WorldPosition == Sender.WorldPosition) return text;
float dist = Vector2.Distance(listener.WorldPosition, Sender.WorldPosition);
if (dist > range) return "";
if (Submarine.CheckVisibility(listener.SimPosition, Sender.SimPosition) != null) dist *= 2.0f;
if (Submarine.CheckVisibility(listener.SimPosition, Sender.SimPosition) != null) dist = (dist + 100f) * obstructionmult;
if (dist > range) return "";
float garbleAmount = dist / range;
if (garbleAmount < 0.5f) return text;
if (garbleAmount < 0.3f) return text;
int startIndex = Math.Max(text.IndexOf(':') + 1, 1);
@@ -1848,7 +1848,7 @@ namespace Barotrauma.Networking
case ChatMessageType.Default:
if (!receiver.IsDead)
{
return ChatMessage.ApplyDistanceEffect(receiver, sender, message, ChatMessage.SpeakRange);
return ChatMessage.ApplyDistanceEffect(receiver, sender, message, ChatMessage.SpeakRange, 3.0f);
}
break;
case ChatMessageType.Radio:
@@ -533,7 +533,9 @@ namespace Barotrauma.Networking
foreach (string s in shuttleSpawnPoints[i].IdCardTags)
{
item.AddTag(s);
}
}
if (!string.IsNullOrWhiteSpace(shuttleSpawnPoints[i].IdCardDesc))
item.Description = shuttleSpawnPoints[i].IdCardDesc;
}
#if CLIENT
GameMain.GameSession.CrewManager.AddCharacter(character);
@@ -16,22 +16,29 @@ namespace Barotrauma
private set;
}
public float Rotation
{
get;
private set;
}
public readonly float Timestamp;
public readonly UInt16 ID;
public PosInfo(Vector2 pos, float time)
: this(pos, 0, time)
public PosInfo(Vector2 pos, float rotation, float time)
: this(pos, rotation, 0, time)
{
}
public PosInfo(Vector2 pos, UInt16 ID)
: this(pos, ID, 0.0f)
public PosInfo(Vector2 pos, float rotation, UInt16 ID)
: this(pos, rotation, ID, 0.0f)
{
}
protected PosInfo(Vector2 pos, UInt16 ID, float time)
protected PosInfo(Vector2 pos, float rotation, UInt16 ID, float time)
{
Position = pos;
Rotation = rotation;
this.ID = ID;
Timestamp = time;
@@ -52,9 +59,9 @@ namespace Barotrauma
}
}
public void Translate(Vector2 amount)
public void Translate(Vector2 posAmount,float rotationAmount)
{
Position += amount;
Position += posAmount; Rotation += rotationAmount;
}
}