Broken items can be repaired, fixed clients never removing firesources (causing the lights to stay after the flames have been extinguished)

This commit is contained in:
Regalis
2017-01-14 20:30:46 +02:00
parent bd7766d3e7
commit f7ac98ab5f
5 changed files with 101 additions and 41 deletions
+28 -14
View File
@@ -46,33 +46,39 @@ namespace Barotrauma
} }
} }
public bool CanBeFixed(Character character, GUIComponent reqFrame) public bool CanBeFixed(Character character, GUIComponent reqFrame = null)
{ {
if (character == null) return false;
bool success = true; bool success = true;
foreach (string itemName in requiredItems) foreach (string itemName in requiredItems)
{ {
GUIComponent component = reqFrame.children.Find(c => c.UserData as string == itemName);
GUITextBlock text = component as GUITextBlock;
Item item = character.Inventory.FindItem(itemName); Item item = character.Inventory.FindItem(itemName);
bool itemFound = (item != null); bool itemFound = (item != null);
if (!itemFound) success = false; if (!itemFound) success = false;
if (text != null) text.TextColor = itemFound ? Color.LightGreen : Color.Red; if (reqFrame != null)
{
GUIComponent component = reqFrame.children.Find(c => c.UserData as string == itemName);
GUITextBlock text = component as GUITextBlock;
if (text != null) text.TextColor = itemFound ? Color.LightGreen : Color.Red;
}
} }
foreach (Skill skill in requiredSkills) foreach (Skill skill in requiredSkills)
{ {
GUIComponent component = reqFrame.children.Find(c => c.UserData as Skill == skill);
GUITextBlock text = component as GUITextBlock;
float characterSkill = character.GetSkillLevel(skill.Name); float characterSkill = character.GetSkillLevel(skill.Name);
bool sufficientSkill = characterSkill >= skill.Level; bool sufficientSkill = characterSkill >= skill.Level;
if (!sufficientSkill) success = false; if (!sufficientSkill) success = false;
if (text != null) text.TextColor = sufficientSkill ? Color.LightGreen : Color.Red; if (reqFrame != null)
{
GUIComponent component = reqFrame.children.Find(c => c.UserData as Skill == skill);
GUITextBlock text = component as GUITextBlock;
if (text != null) text.TextColor = sufficientSkill ? Color.LightGreen : Color.Red;
}
} }
return success; return success;
@@ -133,15 +139,23 @@ namespace Barotrauma
private static bool FixButtonPressed(GUIButton button, object obj) private static bool FixButtonPressed(GUIButton button, object obj)
{ {
FixRequirement requirement = obj as FixRequirement; FixRequirement requirement = obj as FixRequirement;
if (requirement == null) return false; if (requirement == null) return true;
if (!requirement.CanBeFixed(Character.Controlled, button.Parent)) return true;
requirement.Fixed = true;
Item item = frame.UserData as Item; Item item = frame.UserData as Item;
if (item == null) return true; if (item == null) return true;
if (!requirement.CanBeFixed(Character.Controlled, button.Parent)) return true;
if (GameMain.Client != null)
{
GameMain.Client.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.RepairItem, item.FixRequirements.IndexOf(requirement)});
}
else if (GameMain.Server != null)
{
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Status });
requirement.Fixed = true;
}
return true; return true;
} }
+61 -22
View File
@@ -1671,7 +1671,6 @@ namespace Barotrauma
} }
msg.WriteRangedInteger(0, 2, (int)((NetEntityEvent.Type)extraData[0])); msg.WriteRangedInteger(0, 2, (int)((NetEntityEvent.Type)extraData[0]));
switch ((NetEntityEvent.Type)extraData[0]) switch ((NetEntityEvent.Type)extraData[0])
{ {
case NetEntityEvent.Type.ComponentState: case NetEntityEvent.Type.ComponentState:
@@ -1685,6 +1684,12 @@ namespace Barotrauma
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
msg.WriteRangedSingle(condition, 0.0f, 100.0f, 8); msg.WriteRangedSingle(condition, 0.0f, 100.0f, 8);
if (condition <= 0.0f && FixRequirements.Count > 0)
{
for (int i = 0; i<FixRequirements.Count; i++)
msg.Write(FixRequirements[i].Fixed);
}
break; break;
} }
} }
@@ -1692,7 +1697,6 @@ namespace Barotrauma
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime) public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
{ {
NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadRangedInteger(0, 2); NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadRangedInteger(0, 2);
switch (eventType) switch (eventType)
{ {
case NetEntityEvent.Type.ComponentState: case NetEntityEvent.Type.ComponentState:
@@ -1704,6 +1708,20 @@ namespace Barotrauma
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
Condition = msg.ReadRangedSingle(0.0f, 100.0f, 8); Condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
if (FixRequirements.Count > 0)
{
if (Condition <= 0.0f)
{
for (int i = 0; i < FixRequirements.Count; i++)
FixRequirements[i].Fixed = msg.ReadBoolean();
}
else
{
for (int i = 0; i < FixRequirements.Count; i++)
FixRequirements[i].Fixed = true;
}
}
break; break;
} }
} }
@@ -1714,35 +1732,56 @@ namespace Barotrauma
{ {
return; return;
} }
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.ComponentState)
//TODO: use WriteRangedInteger to write the event type
msg.Write((byte)((int)extraData[0]));
switch ((NetEntityEvent.Type)extraData[0])
{ {
msg.Write(true); case NetEntityEvent.Type.ComponentState:
int componentIndex = (int)extraData[1];
msg.WriteRangedInteger(0, components.Count - 1, componentIndex);
int componentIndex = (int)extraData[1]; (components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
msg.WriteRangedInteger(0, components.Count - 1, componentIndex); break;
case NetEntityEvent.Type.InventoryState:
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData); ownInventory.ClientWrite(msg, extraData);
} break;
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.InventoryState) case NetEntityEvent.Type.RepairItem:
{ if (FixRequirements.Count > 0)
msg.Write(false); {
int requirementIndex = (int)extraData[1];
ownInventory.ClientWrite(msg, extraData); msg.WriteRangedInteger(0, FixRequirements.Count - 1, requirementIndex);
}
break;
} }
} }
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c) public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
{ {
bool isComponentUpdate = msg.ReadBoolean(); NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadByte();
if (isComponentUpdate) switch (eventType)
{ {
int componentIndex = msg.ReadRangedInteger(0, components.Count - 1); case NetEntityEvent.Type.ComponentState:
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c); int componentIndex = msg.ReadRangedInteger(0, components.Count - 1);
} (components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
else break;
{ case NetEntityEvent.Type.InventoryState:
ownInventory.ServerRead(type, msg, c); ownInventory.ServerRead(type, msg, c);
break;
case NetEntityEvent.Type.RepairItem:
if (FixRequirements.Count == 0) return;
int requirementIndex = FixRequirements.Count == 1 ?
0 : msg.ReadRangedInteger(0, FixRequirements.Count - 1);
if (!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;
} }
} }
+4 -2
View File
@@ -305,6 +305,8 @@ namespace Barotrauma
hull.Volume -= extinquishAmount; hull.Volume -= extinquishAmount;
if (GameMain.Client != null) return;
if (size.X < 1.0f) Remove(); if (size.X < 1.0f) Remove();
} }
@@ -337,13 +339,13 @@ namespace Barotrauma
hull.Volume -= extinquishAmount; hull.Volume -= extinquishAmount;
if (GameMain.Client != null) return;
if (size.X < 1.0f) Remove(); if (size.X < 1.0f) Remove();
} }
public void Remove() public void Remove()
{ {
if (GameMain.Client != null) return;
lightSource.Remove(); lightSource.Remove();
if (basicSoundIndex > -1) Sounds.SoundManager.Stop(basicSoundIndex); if (basicSoundIndex > -1) Sounds.SoundManager.Stop(basicSoundIndex);
+5 -1
View File
@@ -881,7 +881,11 @@ namespace Barotrauma
newFire.Hull == null ? size : size * newFire.Hull.rect.Width, newFire.Hull == null ? size : size * newFire.Hull.rect.Width,
newFire.Size.Y); newFire.Size.Y);
//ignore if the fire wasn't added to this room (invalid position)? //ignore if the fire wasn't added to this room (invalid position)?
if (!fireSources.Contains(newFire)) continue; if (!fireSources.Contains(newFire))
{
newFire.Remove();
continue;
}
newFireSources.Add(newFire); newFireSources.Add(newFire);
} }
} }
@@ -13,7 +13,8 @@ namespace Barotrauma.Networking
{ {
ComponentState, ComponentState,
InventoryState, InventoryState,
Status Status,
RepairItem
} }
public readonly Entity Entity; public readonly Entity Entity;