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;
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);
bool itemFound = (item != null);
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)
{
GUIComponent component = reqFrame.children.Find(c => c.UserData as Skill == skill);
GUITextBlock text = component as GUITextBlock;
float characterSkill = character.GetSkillLevel(skill.Name);
bool sufficientSkill = characterSkill >= skill.Level;
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;
@@ -133,14 +139,22 @@ namespace Barotrauma
private static bool FixButtonPressed(GUIButton button, object obj)
{
FixRequirement requirement = obj as FixRequirement;
if (requirement == null) return false;
if (!requirement.CanBeFixed(Character.Controlled, button.Parent)) return true;
requirement.Fixed = true;
if (requirement == null) return true;
Item item = frame.UserData as Item;
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;
}
+61 -22
View File
@@ -1671,7 +1671,6 @@ namespace Barotrauma
}
msg.WriteRangedInteger(0, 2, (int)((NetEntityEvent.Type)extraData[0]));
switch ((NetEntityEvent.Type)extraData[0])
{
case NetEntityEvent.Type.ComponentState:
@@ -1685,6 +1684,12 @@ namespace Barotrauma
break;
case NetEntityEvent.Type.Status:
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;
}
}
@@ -1692,7 +1697,6 @@ namespace Barotrauma
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
{
NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadRangedInteger(0, 2);
switch (eventType)
{
case NetEntityEvent.Type.ComponentState:
@@ -1704,6 +1708,20 @@ namespace Barotrauma
break;
case NetEntityEvent.Type.Status:
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;
}
}
@@ -1714,35 +1732,56 @@ namespace Barotrauma
{
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];
msg.WriteRangedInteger(0, components.Count - 1, componentIndex);
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
}
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.InventoryState)
{
msg.Write(false);
ownInventory.ClientWrite(msg, extraData);
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
break;
case NetEntityEvent.Type.InventoryState:
ownInventory.ClientWrite(msg, extraData);
break;
case NetEntityEvent.Type.RepairItem:
if (FixRequirements.Count > 0)
{
int requirementIndex = (int)extraData[1];
msg.WriteRangedInteger(0, FixRequirements.Count - 1, requirementIndex);
}
break;
}
}
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);
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
}
else
{
ownInventory.ServerRead(type, msg, c);
case NetEntityEvent.Type.ComponentState:
int componentIndex = msg.ReadRangedInteger(0, components.Count - 1);
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
break;
case NetEntityEvent.Type.InventoryState:
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;
}
}
+5 -3
View File
@@ -125,7 +125,7 @@ namespace Barotrauma
- leftEdge;
fireSources[j].position.X = leftEdge;
fireSources[i].Remove();
}
}
@@ -304,6 +304,8 @@ namespace Barotrauma
size.X -= extinquishAmount;
hull.Volume -= extinquishAmount;
if (GameMain.Client != null) return;
if (size.X < 1.0f) Remove();
}
@@ -337,13 +339,13 @@ namespace Barotrauma
hull.Volume -= extinquishAmount;
if (GameMain.Client != null) return;
if (size.X < 1.0f) Remove();
}
public void Remove()
{
if (GameMain.Client != null) return;
lightSource.Remove();
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.Size.Y);
//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);
}
}
@@ -13,7 +13,8 @@ namespace Barotrauma.Networking
{
ComponentState,
InventoryState,
Status
Status,
RepairItem
}
public readonly Entity Entity;