Server notifies clients when an OnFire statuseffect causes an item to break (-> clients can see oxygen/fuel tanks exploding again)

This commit is contained in:
Regalis
2017-05-24 17:13:56 +03:00
parent 3183c9fb03
commit 4d0a6677e9
5 changed files with 30 additions and 15 deletions
@@ -104,7 +104,7 @@ namespace Barotrauma
if (GameMain.Server != null) if (GameMain.Server != null)
{ {
GameMain.Server.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect, character.ID }); GameMain.Server.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, character.ID });
} }
Items[slotIndex].ApplyStatusEffects(ActionType.OnUse, 1.0f, character); Items[slotIndex].ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
@@ -242,7 +242,7 @@ namespace Barotrauma.Items.Components
if (GameMain.Server != null) if (GameMain.Server != null)
{ {
GameMain.Server.CreateEntityEvent(item, new object[] { Networking.NetEntityEvent.Type.ApplyStatusEffect, target.ID }); GameMain.Server.CreateEntityEvent(item, new object[] { Networking.NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, target.ID });
string logStr = picker?.Name + " used " + item.Name; string logStr = picker?.Name + " used " + item.Name;
if (item.ContainedItems != null && item.ContainedItems.Length > 0) if (item.ContainedItems != null && item.ContainedItems.Length > 0)
+14 -10
View File
@@ -645,7 +645,7 @@ namespace Barotrauma
} }
public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null) public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null, bool isNetworkEvent = false)
{ {
if (statusEffectLists == null) return; if (statusEffectLists == null) return;
@@ -654,13 +654,16 @@ namespace Barotrauma
foreach (StatusEffect effect in statusEffects) foreach (StatusEffect effect in statusEffects)
{ {
ApplyStatusEffect(effect, type, deltaTime, character); ApplyStatusEffect(effect, type, deltaTime, character, isNetworkEvent);
} }
} }
public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null) public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaTime, Character character = null, bool isNetworkEvent = false)
{ {
if (condition == 0.0f && effect.type != ActionType.OnBroken) return; if (!isNetworkEvent)
{
if (condition == 0.0f && effect.type != ActionType.OnBroken) return;
}
if (effect.type != type) return; if (effect.type != type) return;
bool hasTargets = (effect.TargetNames == null); bool hasTargets = (effect.TargetNames == null);
@@ -1718,7 +1721,10 @@ namespace Barotrauma
} }
break; break;
case NetEntityEvent.Type.ApplyStatusEffect: case NetEntityEvent.Type.ApplyStatusEffect:
ushort targetID = (ushort)extraData[1]; ActionType actionType = (ActionType)extraData[1];
ushort targetID = extraData.Length > 2 ? (ushort)extraData[2] : (ushort)0;
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ActionType)).Length - 1, (int)actionType);
msg.Write(targetID); msg.Write(targetID);
break; break;
case NetEntityEvent.Type.ChangeProperty: case NetEntityEvent.Type.ChangeProperty:
@@ -1765,13 +1771,11 @@ namespace Barotrauma
} }
break; break;
case NetEntityEvent.Type.ApplyStatusEffect: case NetEntityEvent.Type.ApplyStatusEffect:
ActionType actionType = (ActionType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ActionType)).Length -1);
ushort targetID = msg.ReadUInt16(); ushort targetID = msg.ReadUInt16();
Character target = FindEntityByID(targetID) as Character; Character target = FindEntityByID(targetID) as Character;
ApplyStatusEffects(actionType, (float)Timing.Step, target, true);
if (target == null) return;
ApplyStatusEffects(ActionType.OnUse, (float)Timing.Step, target);
break; break;
case NetEntityEvent.Type.ChangeProperty: case NetEntityEvent.Type.ChangeProperty:
ReadPropertyChange(msg); ReadPropertyChange(msg);
@@ -1856,7 +1860,7 @@ namespace Barotrauma
GameServer.Log(c.Character.Name + " used item " + Name, ServerLog.MessageType.ItemInteraction); GameServer.Log(c.Character.Name + " used item " + Name, ServerLog.MessageType.ItemInteraction);
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ApplyStatusEffect, c.Character.ID }); GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, c.Character.ID });
break; break;
case NetEntityEvent.Type.ChangeProperty: case NetEntityEvent.Type.ChangeProperty:
+6
View File
@@ -3,6 +3,7 @@ using Barotrauma.Lights;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml.Linq; using System.Xml.Linq;
using Barotrauma.Networking;
using FarseerPhysics; using FarseerPhysics;
namespace Barotrauma namespace Barotrauma
@@ -91,6 +92,11 @@ namespace Barotrauma
if (Vector2.Distance(item.WorldPosition, worldPosition) > attack.Range * 0.1f) continue; if (Vector2.Distance(item.WorldPosition, worldPosition) > attack.Range * 0.1f) continue;
item.ApplyStatusEffects(ActionType.OnFire, 1.0f); item.ApplyStatusEffects(ActionType.OnFire, 1.0f);
if (item.Condition <= 0.0f)
{
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnFire });
}
} }
} }
+7 -2
View File
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Barotrauma.Networking;
namespace Barotrauma namespace Barotrauma
{ {
@@ -267,7 +268,7 @@ namespace Barotrauma
private void DamageItems(float deltaTime) private void DamageItems(float deltaTime)
{ {
if (size.X <= 0.0f) return; if (size.X <= 0.0f || GameMain.Client != null) return;
foreach (Item item in Item.ItemList) foreach (Item item in Item.ItemList)
{ {
@@ -278,7 +279,11 @@ namespace Barotrauma
if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue; if (item.Position.X < position.X - range || item.Position.X > position.X + size.X + range) continue;
if (item.Position.Y < position.Y - size.Y || item.Position.Y > hull.Rect.Y) continue; if (item.Position.Y < position.Y - size.Y || item.Position.Y > hull.Rect.Y) continue;
if (GameMain.Client == null) item.ApplyStatusEffects(ActionType.OnFire, deltaTime); item.ApplyStatusEffects(ActionType.OnFire, deltaTime);
if (item.Condition <= 0.0f)
{
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnFire });
}
} }
} }