Syncing StatusEffects applied by meleeweapons or using an item on self
This commit is contained in:
@@ -95,10 +95,18 @@ namespace Barotrauma
|
||||
int slotIndex = (int)obj;
|
||||
|
||||
if (Items[slotIndex] == null) return false;
|
||||
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect });
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect, character.ID });
|
||||
}
|
||||
|
||||
//save the ID in a variable in case the statuseffect causes the item to be dropped/destroyed
|
||||
ushort itemID = Items[slotIndex].ID;
|
||||
|
||||
Items[slotIndex].ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private bool OnCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
{
|
||||
IDamageable target = null;
|
||||
Character target = null;
|
||||
|
||||
Limb limb = f2.Body.UserData as Limb;
|
||||
if (limb != null)
|
||||
@@ -227,16 +227,23 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
target = f2.Body.UserData as IDamageable;
|
||||
target = f2.Body.UserData as Character;
|
||||
}
|
||||
|
||||
if (target == null) return false;
|
||||
|
||||
if (attack!=null) attack.DoDamage(user, target, item.WorldPosition, 1.0f);
|
||||
if (attack != null) attack.DoDamage(user, target, item.WorldPosition, 1.0f);
|
||||
|
||||
RestoreCollision();
|
||||
hitting = false;
|
||||
|
||||
if (GameMain.Client != null) return true;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { Barotrauma.Networking.NetEntityEvent.Type.ApplyStatusEffect, target.ID });
|
||||
}
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, limb.character);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -660,7 +660,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (string s in effect.OnContainingNames)
|
||||
{
|
||||
if (!containedItems.Any(x => x!=null && x.Name==s && x.Condition > 0.0f)) return;
|
||||
if (!containedItems.Any(x => x != null && x.Name == s && x.Condition > 0.0f)) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,7 +699,6 @@ namespace Barotrauma
|
||||
targets.Add(CurrentHull);
|
||||
}
|
||||
|
||||
|
||||
if (effect.Targets.HasFlag(StatusEffect.TargetType.This))
|
||||
{
|
||||
foreach (var pobject in AllPropertyObjects)
|
||||
@@ -707,21 +706,12 @@ namespace Barotrauma
|
||||
targets.Add(pobject);
|
||||
}
|
||||
}
|
||||
//effect.Apply(type, deltaTime, this);
|
||||
//ApplyStatusEffect(effect, type, deltaTime, this);
|
||||
|
||||
if (effect.Targets.HasFlag(StatusEffect.TargetType.Character)) targets.Add(character);
|
||||
//effect.Apply(type, deltaTime, null, Character);
|
||||
//ApplyStatusEffect(effect, type, deltaTime, null, Character, limb);
|
||||
|
||||
if (Container != null && effect.Targets.HasFlag(StatusEffect.TargetType.Parent)) targets.Add(Container);
|
||||
//{
|
||||
// effect.Apply(type, deltaTime, container);
|
||||
// //container.ApplyStatusEffect(effect, type, deltaTime, container);
|
||||
//}
|
||||
|
||||
effect.Apply(type, deltaTime, this, targets);
|
||||
|
||||
effect.Apply(type, deltaTime, this, targets);
|
||||
}
|
||||
|
||||
|
||||
@@ -1670,7 +1660,8 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
msg.WriteRangedInteger(0, 2, (int)((NetEntityEvent.Type)extraData[0]));
|
||||
//TODO: use WriteRangedInteger to write the event type
|
||||
msg.Write((byte)((int)extraData[0]));
|
||||
switch ((NetEntityEvent.Type)extraData[0])
|
||||
{
|
||||
case NetEntityEvent.Type.ComponentState:
|
||||
@@ -1691,12 +1682,16 @@ namespace Barotrauma
|
||||
msg.Write(FixRequirements[i].Fixed);
|
||||
}
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
ushort targetID = (ushort)extraData[1];
|
||||
msg.Write(targetID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
|
||||
{
|
||||
NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadRangedInteger(0, 2);
|
||||
NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadByte();
|
||||
switch (eventType)
|
||||
{
|
||||
case NetEntityEvent.Type.ComponentState:
|
||||
@@ -1723,6 +1718,15 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
ushort targetID = msg.ReadUInt16();
|
||||
|
||||
Character target = FindEntityByID(targetID) as Character;
|
||||
|
||||
if (target == null) return;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, (float)Timing.Step, target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1753,6 +1757,8 @@ namespace Barotrauma
|
||||
msg.WriteRangedInteger(0, FixRequirements.Count - 1, requirementIndex);
|
||||
}
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1775,12 +1781,20 @@ namespace Barotrauma
|
||||
int requirementIndex = FixRequirements.Count == 1 ?
|
||||
0 : msg.ReadRangedInteger(0, FixRequirements.Count - 1);
|
||||
|
||||
if (!c.Character.CanAccessItem(this)) return;
|
||||
if (c.Character == null || !c.Character.CanAccessItem(this)) return;
|
||||
if (!FixRequirements[requirementIndex].CanBeFixed(c.Character)) return;
|
||||
|
||||
FixRequirements[requirementIndex].Fixed = true;
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
|
||||
|
||||
break;
|
||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||
if (c.Character == null || !c.Character.CanAccessItem(this)) return;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, (float)Timing.Step, c.Character);
|
||||
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ApplyStatusEffect, c.Character.ID });
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace Barotrauma.Networking
|
||||
ComponentState,
|
||||
InventoryState,
|
||||
Status,
|
||||
RepairItem
|
||||
RepairItem,
|
||||
ApplyStatusEffect
|
||||
}
|
||||
|
||||
public readonly Entity Entity;
|
||||
|
||||
Reference in New Issue
Block a user