Skip to content

Commit 5959a71

Browse files
committed
Add enum for condition cancel on flags
1 parent 888987f commit 5959a71

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/MHServerEmu.Games/GameData/Prototypes/ConditionPrototype.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using MHServerEmu.Core;
2-
using MHServerEmu.Games.GameData.Calligraphy;
1+
using MHServerEmu.Games.GameData.Calligraphy;
32
using MHServerEmu.Games.GameData.Calligraphy.Attributes;
3+
using MHServerEmu.Games.Powers;
44

55
namespace MHServerEmu.Games.GameData.Prototypes
66
{
@@ -173,7 +173,7 @@ public class ConditionPrototype : Prototype
173173
[DoNotCopy]
174174
public TimeSpan UpdateInterval { get => TimeSpan.FromMilliseconds(UpdateIntervalMS); }
175175
[DoNotCopy]
176-
public UInt32Flags CancelOnFlags { get; private set; } = UInt32Flags.None;
176+
public ConditionCancelOnFlags CancelOnFlags { get; private set; } = ConditionCancelOnFlags.None;
177177

178178
public override void PostProcess()
179179
{
@@ -182,12 +182,12 @@ public override void PostProcess()
182182
// TODO: stuff
183183

184184
// Combine cancel flags into a single bit field (TODO: flag enum)
185-
if (CancelOnHit) CancelOnFlags |= UInt32Flags.Flag0;
186-
if (CancelOnKilled) CancelOnFlags |= UInt32Flags.Flag1;
187-
if (CancelOnPowerUse) CancelOnFlags |= UInt32Flags.Flag2;
188-
if (CancelOnPowerUsePost) CancelOnFlags |= UInt32Flags.Flag3;
189-
if (CancelOnTransfer) CancelOnFlags |= UInt32Flags.Flag4;
190-
if (CancelOnIntraRegionTeleport) CancelOnFlags |= UInt32Flags.Flag5;
185+
if (CancelOnHit) CancelOnFlags |= ConditionCancelOnFlags.OnHit;
186+
if (CancelOnKilled) CancelOnFlags |= ConditionCancelOnFlags.OnKilled;
187+
if (CancelOnPowerUse) CancelOnFlags |= ConditionCancelOnFlags.OnPowerUse;
188+
if (CancelOnPowerUsePost) CancelOnFlags |= ConditionCancelOnFlags.OnPowerUsePost;
189+
if (CancelOnTransfer) CancelOnFlags |= ConditionCancelOnFlags.OnTransfer;
190+
if (CancelOnIntraRegionTeleport) CancelOnFlags |= ConditionCancelOnFlags.OnIntraRegionTeleport;
191191

192192
// TODO: more stuff
193193
}

src/MHServerEmu.Games/Powers/Condition.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Text;
22
using Google.ProtocolBuffers;
3-
using MHServerEmu.Core;
43
using MHServerEmu.Core.Extensions;
54
using MHServerEmu.Core.Logging;
65
using MHServerEmu.Core.Serialization;
@@ -31,6 +30,18 @@ public enum ConditionSerializationFlags : uint
3130
HasCancelOnFlags = 1 << 11, // cancelOnFalgs from ConditionPrototype
3231
}
3332

33+
[Flags]
34+
public enum ConditionCancelOnFlags : uint
35+
{
36+
None = 0,
37+
OnHit = 1 << 0,
38+
OnKilled = 1 << 1,
39+
OnPowerUse = 1 << 2,
40+
OnPowerUsePost = 1 << 3,
41+
OnTransfer = 1 << 4,
42+
OnIntraRegionTeleport = 1 << 5
43+
}
44+
3445
public class Condition
3546
{
3647
private static readonly Logger Logger = LogManager.CreateLogger();
@@ -53,7 +64,7 @@ public class Condition
5364
private bool _isEnabled = true;
5465
private int _updateIntervalMS; // milliseconds
5566
private ReplicatedPropertyCollection _properties = new();
56-
private UInt32Flags _cancelOnFlags;
67+
private ConditionCancelOnFlags _cancelOnFlags;
5768

5869
private ulong _creatorPlayerId; // Player guid
5970

@@ -82,7 +93,7 @@ public PrototypeId CreatorPowerPrototypeRef {
8293
public bool IsEnabled { get => _isEnabled; set => _isEnabled = value; }
8394
public TimeSpan UpdateInterval { get => TimeSpan.FromMilliseconds(_updateIntervalMS); set => _updateIntervalMS = (int)value.TotalMilliseconds; }
8495
public ReplicatedPropertyCollection Properties { get => _properties; }
85-
public UInt32Flags CancelOnFlags { get => _cancelOnFlags; set => _cancelOnFlags = value; }
96+
public ConditionCancelOnFlags CancelOnFlags { get => _cancelOnFlags; set => _cancelOnFlags = value; }
8697

8798
public ulong CreatorPlayerId { get => _creatorPlayerId; set => _creatorPlayerId = value; }
8899

@@ -248,7 +259,7 @@ public bool Serialize(Archive archive, WorldEntity owner)
248259
{
249260
uint cancelOnFlags = 0;
250261
success &= Serializer.Transfer(archive, ref cancelOnFlags);
251-
_cancelOnFlags = (UInt32Flags)cancelOnFlags;
262+
_cancelOnFlags = (ConditionCancelOnFlags)cancelOnFlags;
252263
}
253264
}
254265

@@ -297,7 +308,7 @@ public void Decode(CodedInputStream stream)
297308
_properties.Decode(stream);
298309

299310
if (_serializationFlags.HasFlag(ConditionSerializationFlags.HasCancelOnFlags))
300-
_cancelOnFlags = (UInt32Flags)stream.ReadRawVarint32();
311+
_cancelOnFlags = (ConditionCancelOnFlags)stream.ReadRawVarint32();
301312
}
302313

303314
public void Encode(CodedOutputStream stream)

0 commit comments

Comments
 (0)