27917ee376
commit 483f2ad4fd9d91b9763d25df592a899cdf39ba67 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 19:19:01 2019 +0200 Instead of making coilgun bolts continuously deteriorate to give them a lifetime of 5 seconds, simply create a delayed status effect that removes them after 5 seconds of being launched. commit 00b8d48d4d1d933e76a6c0d7df5320c50dc0a07d Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 19:16:40 2019 +0200 Wait at least 0.15 seconds before creating a new condition update event for an item. Some rapidly deteriorating items (e.g. coilgun bolt, faraday artifacts) would otherwise cause new events to be created at an excessively high rate. commit 84e6948a4898dd040b2a84eb5f1ad97c20dfc69f Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 19:14:58 2019 +0200 Server can send multiple network event packets per update if there's too many events to fit in one packet (up to 4 packets per update). commit 40797e91d67f965ac6d292367fef5386214abbdb Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 17:34:49 2019 +0200 NetEntityEvent changes: - Don't restrict the number of events per message, but instead write as many events as the packet can fit (up to a maximum of 1024 bytes to leave some space for other types of data (event IDs, chat messages and such)). - Decrease the delay after which events can be resent (RTT * 1.5 -> RTT). commit bfefbb5d7da3ce6a5fe9cb7ff733ec5df37a8a15 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 14:31:03 2019 +0200 Fixed FixDurationLowSkill & FixDurationHighSkill parameters in Repairable being case-sensitive, causing almost none of the xml values to be used. + Moved client-specific repairable methods to the client project, and server-specific to the server project. commit 311f67c6c6b8d2cd9f4f4ca820e42316938c4f17 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 24 14:09:10 2019 +0200 Fixed "trying to add a dead character to crewmanager" errors when attempting to revive a character killed by some other affliction than internal damage, bleeding or burns. Closes #1341
190 lines
6.6 KiB
C#
190 lines
6.6 KiB
C#
using Barotrauma.Networking;
|
|
using Lidgren.Network;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
partial class Repairable : ItemComponent, IServerSerializable, IClientSerializable
|
|
{
|
|
public static float SkillIncreaseMultiplier = 0.4f;
|
|
|
|
private string header;
|
|
|
|
private float deteriorationTimer;
|
|
|
|
[Serialize(0.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, DecimalCount = 2, ToolTip = "How fast the condition of the item deteriorates per second.")]
|
|
public float DeteriorationSpeed
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(0.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1000.0f, DecimalCount = 2, ToolTip = "Minimum initial delay before the item starts to deteriorate.")]
|
|
public float MinDeteriorationDelay
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(0.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1000.0f, DecimalCount = 2, ToolTip = "Maximum initial delay before the item starts to deteriorate.")]
|
|
public float MaxDeteriorationDelay
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(50.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, ToolTip = "The item won't deteriorate spontaneously if the condition is below this value. For example, if set to 10, the condition will spontaneously drop to 10 and then stop dropping (unless the item is damaged further by external factors).")]
|
|
public float MinDeteriorationCondition
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(80.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, ToolTip = "The condition of the item has to be below this before the repair UI becomes usable.")]
|
|
public float ShowRepairUIThreshold
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(100.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, ToolTip = "The amount of time it takes to fix the item with insufficient skill levels.")]
|
|
public float FixDurationLowSkill
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
[Serialize(10.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, ToolTip = "The amount of time it takes to fix the item with sufficient skill levels.")]
|
|
public float FixDurationHighSkill
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
private Character currentFixer;
|
|
public Character CurrentFixer
|
|
{
|
|
get { return currentFixer; }
|
|
set
|
|
{
|
|
if (currentFixer == value || item.IsFullCondition) return;
|
|
if (currentFixer != null) currentFixer.AnimController.Anim = AnimController.Animation.None;
|
|
currentFixer = value;
|
|
}
|
|
}
|
|
|
|
public Repairable(Item item, XElement element)
|
|
: base(item, element)
|
|
{
|
|
IsActive = true;
|
|
canBeSelected = true;
|
|
|
|
this.item = item;
|
|
header = element.GetAttributeString("name", "");
|
|
InitProjSpecific(element);
|
|
}
|
|
|
|
public override void OnItemLoaded()
|
|
{
|
|
deteriorationTimer = Rand.Range(MinDeteriorationDelay, MaxDeteriorationDelay);
|
|
|
|
#if SERVER
|
|
//let the clients know the initial deterioration delay
|
|
item.CreateServerEvent(this);
|
|
#endif
|
|
}
|
|
|
|
partial void InitProjSpecific(XElement element);
|
|
|
|
public void StartRepairing(Character character)
|
|
{
|
|
CurrentFixer = character;
|
|
}
|
|
|
|
public override void UpdateBroken(float deltaTime, Camera cam)
|
|
{
|
|
Update(deltaTime, cam);
|
|
}
|
|
|
|
public override void Update(float deltaTime, Camera cam)
|
|
{
|
|
UpdateProjSpecific(deltaTime);
|
|
|
|
if (CurrentFixer == null)
|
|
{
|
|
if (item.Condition > 0.0f)
|
|
{
|
|
if (deteriorationTimer > 0.0f)
|
|
{
|
|
if (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient)
|
|
{
|
|
deteriorationTimer -= deltaTime;
|
|
#if SERVER
|
|
if (deteriorationTimer <= 0.0f) { item.CreateServerEvent(this); }
|
|
#endif
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (item.Condition > MinDeteriorationCondition)
|
|
{
|
|
item.Condition -= DeteriorationSpeed * deltaTime;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Item.IsFullCondition || CurrentFixer.SelectedConstruction != item || !currentFixer.CanInteractWith(item))
|
|
{
|
|
currentFixer.AnimController.Anim = AnimController.Animation.None;
|
|
currentFixer = null;
|
|
return;
|
|
}
|
|
|
|
UpdateFixAnimation(CurrentFixer);
|
|
|
|
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
|
|
|
|
float successFactor = requiredSkills.Count == 0 ? 1.0f : 0.0f;
|
|
foreach (Skill skill in requiredSkills)
|
|
{
|
|
float characterSkillLevel = CurrentFixer.GetSkillLevel(skill.Identifier);
|
|
if (characterSkillLevel >= skill.Level) successFactor += 1.0f / requiredSkills.Count;
|
|
CurrentFixer.Info.IncreaseSkillLevel(skill.Identifier,
|
|
SkillIncreaseMultiplier * deltaTime / Math.Max(characterSkillLevel, 1.0f),
|
|
CurrentFixer.WorldPosition + Vector2.UnitY * 100.0f);
|
|
}
|
|
|
|
bool wasBroken = !item.IsFullCondition;
|
|
float fixDuration = MathHelper.Lerp(FixDurationLowSkill, FixDurationHighSkill, successFactor);
|
|
if (fixDuration <= 0.0f)
|
|
{
|
|
item.Condition = item.MaxCondition;
|
|
}
|
|
else
|
|
{
|
|
item.Condition += deltaTime / (fixDuration / item.MaxCondition);
|
|
}
|
|
|
|
if (wasBroken && item.IsFullCondition)
|
|
{
|
|
SteamAchievementManager.OnItemRepaired(item, currentFixer);
|
|
deteriorationTimer = Rand.Range(MinDeteriorationDelay, MaxDeteriorationDelay);
|
|
#if SERVER
|
|
item.CreateServerEvent(this);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
partial void UpdateProjSpecific(float deltaTime);
|
|
|
|
private void UpdateFixAnimation(Character character)
|
|
{
|
|
character.AnimController.UpdateUseItem(false, item.WorldPosition + new Vector2(0.0f, 100.0f) * ((item.Condition / item.MaxCondition) % 0.1f));
|
|
}
|
|
}
|
|
}
|