OBT/1.2.0(Spring Update)
Sync with Upstream
This commit is contained in:
+58
-65
@@ -1,84 +1,77 @@
|
||||
namespace Barotrauma
|
||||
#nullable enable
|
||||
namespace Barotrauma;
|
||||
|
||||
/// <summary>Changes the state of missions. The way the states are used depends on the type of mission.</summary>
|
||||
internal sealed class MissionStateAction : EventAction
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Changes the state of a specific active mission. The way the states are used depends on the type of mission.
|
||||
/// </summary>
|
||||
class MissionStateAction : EventAction
|
||||
/// <summary>The operation to perform on missions' states.</summary>
|
||||
public enum OperationType
|
||||
{
|
||||
[Serialize("", IsPropertySaveable.Yes, description: "Identifier of the mission whose state to change.")]
|
||||
public Identifier MissionIdentifier { get; set; }
|
||||
/// <summary>Sets the missions' states to <see cref="State"/>.</summary>
|
||||
Set,
|
||||
/// <summary>Adds <see cref="State"/> to the missions' states.</summary>
|
||||
Add
|
||||
}
|
||||
|
||||
public enum OperationType
|
||||
[Serialize("", IsPropertySaveable.Yes, "Identifiers of the missions whose states to change. Leave blank to only set the state of the mission that triggered the parent event.")]
|
||||
public Identifier MissionIdentifier { get; set; }
|
||||
|
||||
[Serialize(OperationType.Set, IsPropertySaveable.Yes, "The operation to perform on missions' states.")]
|
||||
public OperationType Operation { get; set; }
|
||||
|
||||
[Serialize(0, IsPropertySaveable.Yes, "The value to apply to missions' states.")]
|
||||
public int State { get; set; }
|
||||
|
||||
[Serialize(false, IsPropertySaveable.Yes, "If set to true, missions are forced to fail without a chance of retrying them.")]
|
||||
public bool ForceFailure { get; set; }
|
||||
|
||||
public MissionStateAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
|
||||
{
|
||||
State = element.GetAttributeInt("value", State);
|
||||
if (Operation == OperationType.Add && State == 0 && !ForceFailure)
|
||||
{
|
||||
Set,
|
||||
Add
|
||||
DebugConsole.AddWarning($"Potential error in event \"{parentEvent.Prefab.Identifier}\": {nameof(MissionStateAction)} is set to only add 0 to the mission state, which will do nothing.",
|
||||
contentPackage: element.ContentPackage);
|
||||
}
|
||||
}
|
||||
|
||||
[Serialize(OperationType.Set, IsPropertySaveable.Yes, description: "Should the value be added to the state of the mission, or should the state be set to the specified value.")]
|
||||
public OperationType Operation { get; set; }
|
||||
private bool isFinished;
|
||||
public override bool IsFinished(ref string goTo) => isFinished;
|
||||
public override void Reset() => isFinished = false;
|
||||
|
||||
[Serialize(0, IsPropertySaveable.Yes, description: "The state to set the mission to, or how much to add to the state of the mission.")]
|
||||
public int State { get; set; }
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (isFinished) { return; }
|
||||
|
||||
[Serialize(false, IsPropertySaveable.Yes, description: "If set to true, the mission is forced to fail without a chance of retrying it.")]
|
||||
public bool ForceFailure { get; set; }
|
||||
|
||||
private bool isFinished;
|
||||
|
||||
public MissionStateAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
|
||||
if (!MissionIdentifier.IsEmpty)
|
||||
{
|
||||
State = element.GetAttributeInt("value", State);
|
||||
if (MissionIdentifier.IsEmpty)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": MissionIdentifier has not been configured.",
|
||||
contentPackage: element.ContentPackage);
|
||||
}
|
||||
if (Operation == OperationType.Add && State == 0 && !ForceFailure)
|
||||
{
|
||||
DebugConsole.AddWarning($"Potential error in event \"{parentEvent.Prefab.Identifier}\": {nameof(MissionStateAction)} is set to add 0 to the mission state, which will do nothing.",
|
||||
contentPackage: element.ContentPackage);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsFinished(ref string goTo)
|
||||
{
|
||||
return isFinished;
|
||||
}
|
||||
public override void Reset()
|
||||
{
|
||||
isFinished = false;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (isFinished) { return; }
|
||||
|
||||
foreach (Mission mission in GameMain.GameSession.Missions)
|
||||
{
|
||||
if (mission.Prefab.Identifier != MissionIdentifier) { continue; }
|
||||
if (ForceFailure)
|
||||
{
|
||||
mission.ForceFailure = true;
|
||||
}
|
||||
|
||||
switch (Operation)
|
||||
{
|
||||
case OperationType.Set:
|
||||
mission.State = State;
|
||||
break;
|
||||
case OperationType.Add:
|
||||
mission.State += State;
|
||||
break;
|
||||
}
|
||||
SetMissionState(mission);
|
||||
}
|
||||
|
||||
isFinished = true;
|
||||
}
|
||||
else if (ParentEvent.TriggeringMission != null)
|
||||
{
|
||||
SetMissionState(ParentEvent.TriggeringMission);
|
||||
}
|
||||
|
||||
public override string ToDebugString()
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
private void SetMissionState(Mission mission)
|
||||
{
|
||||
if (ForceFailure) { mission.ForceFailure = true; }
|
||||
switch (Operation)
|
||||
{
|
||||
return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionStateAction)} -> ({(Operation == OperationType.Set ? State : '+' + State)})";
|
||||
case OperationType.Set:
|
||||
mission.State = State;
|
||||
break;
|
||||
case OperationType.Add:
|
||||
mission.State += State;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToDebugString() => $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionStateAction)} -> ({(Operation == OperationType.Set ? State : '+' + State)})";
|
||||
}
|
||||
Reference in New Issue
Block a user