Skip to content

Commit 7b1920d

Browse files
committed
Implement PowerCollection power source flags
1 parent e5e39cd commit 7b1920d

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

src/MHServerEmu.Games/Entities/PowerCollections/PowerCollection.cs

+44-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Google.ProtocolBuffers;
33
using MHServerEmu.Core.Logging;
44
using MHServerEmu.Core.Serialization;
5+
using MHServerEmu.Games.Entities.Avatars;
56
using MHServerEmu.Games.GameData;
67
using MHServerEmu.Games.GameData.Prototypes;
78
using MHServerEmu.Games.Network;
@@ -105,23 +106,57 @@ private Power AssignPowerInternal(PrototypeId powerProtoRef, PowerIndexPropertie
105106
PowerCollectionRecord powerRecord = GetPowerRecordByRef(powerProtoRef);
106107
if (powerRecord == null)
107108
{
108-
// Determine the source of this power
109-
bool isAvatarPowerProgressionPower = false;
110-
bool isTeamUpPassivePowerWhileAway = false;
109+
// Determine source flags for this power
110+
// (TODO: it would probably be cleaner to do this as a separate method with early returns)
111+
bool isPowerProgressionPower = false;
112+
bool isTeamUpPassiveWhileAway = false;
111113

112-
// Inherit the source from the triggering power if we have one
114+
// Inherit the flags from the triggering power if we have one
113115
PowerCollectionRecord triggeringPowerRecord = GetPowerRecordByRef(triggeringPowerRef);
114116
if (triggeringPowerRecord != null)
115117
{
116-
isAvatarPowerProgressionPower = triggeringPowerRecord.IsAvatarPowerProgressionPower;
117-
isTeamUpPassivePowerWhileAway = triggeringPowerRecord.IsTeamUpPassivePowerWhileAway;
118+
isPowerProgressionPower = triggeringPowerRecord.IsPowerProgressionPower;
119+
isTeamUpPassiveWhileAway = triggeringPowerRecord.IsTeamUpPassiveWhileAway;
118120
}
119-
else //if (_owner != null)
121+
else
120122
{
121-
// Figure out the source from the power collection's owner, skip this for now
123+
if (_owner != null)
124+
{
125+
if (_owner is Agent agentOwner)
126+
{
127+
isPowerProgressionPower = agentOwner.HasPowerInPowerProgression(powerProtoRef);
128+
129+
if (isPowerProgressionPower == false)
130+
{
131+
var avatarOwner = _owner.GetMostResponsiblePowerUser<Avatar>();
132+
if (avatarOwner != null)
133+
{
134+
Agent teamUpAgent = avatarOwner.CurrentTeamUpAgent;
135+
if (teamUpAgent != null)
136+
{
137+
teamUpAgent.GetPowerProgressionInfo(powerProtoRef, out var info);
138+
if (info.IsForTeamUp)
139+
{
140+
isPowerProgressionPower = true;
141+
isTeamUpPassiveWhileAway = info.IsPassivePowerOnAvatarWhileAway;
142+
}
143+
}
144+
145+
}
146+
}
147+
}
148+
else
149+
{
150+
isTeamUpPassiveWhileAway = _owner.Properties[PropertyEnum.IsTeamUpAwaySource];
151+
}
152+
}
153+
else
154+
{
155+
Logger.Warn("AssignPowerInternal(): _owner == null");
156+
}
122157
}
123158

124-
powerRecord = CreatePowerRecord(powerProtoRef, indexProps, triggeringPowerRef, isAvatarPowerProgressionPower, isTeamUpPassivePowerWhileAway);
159+
powerRecord = CreatePowerRecord(powerProtoRef, indexProps, triggeringPowerRef, isPowerProgressionPower, isTeamUpPassiveWhileAway);
125160
if (powerRecord == null) return Logger.WarnReturn<Power>(null, "AssignPowerInternal(): powerRecord == null");
126161
}
127162
else

src/MHServerEmu.Games/Entities/PowerCollections/PowerCollectionRecord.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ private enum SerializationFlags
4040
// The rest of data is not serialized
4141
public Power Power { get; private set; }
4242
public PowerPrototype PowerPrototype { get; private set; }
43-
public bool IsAvatarPowerProgressionPower { get; private set; }
44-
public bool IsTeamUpPassivePowerWhileAway { get; private set; }
43+
public bool IsPowerProgressionPower { get; private set; }
44+
public bool IsTeamUpPassiveWhileAway { get; private set; }
4545

4646
public PowerCollectionRecord() { }
4747

4848
public void Initialize(Power power, PrototypeId powerPrototypeRef, PowerIndexProperties indexProps, uint powerRefCount,
49-
bool isAvatarPowerProgressionPower, bool isTeamUpPassivePowerWhileAway)
49+
bool isPowerProgressionPower, bool isTeamUpPassiveWhileAway)
5050
{
5151
_powerPrototypeRef = powerPrototypeRef;
5252
_indexProps = indexProps;
5353
_powerRefCount = powerRefCount;
5454

5555
Power = power;
5656
PowerPrototype = powerPrototypeRef.As<PowerPrototype>();
57-
IsAvatarPowerProgressionPower = isAvatarPowerProgressionPower;
58-
IsTeamUpPassivePowerWhileAway = isTeamUpPassivePowerWhileAway;
57+
IsPowerProgressionPower = isPowerProgressionPower;
58+
IsTeamUpPassiveWhileAway = isTeamUpPassiveWhileAway;
5959
}
6060

6161
public bool ShouldSerializeRecordForPacking(Archive archive = null)

0 commit comments

Comments
 (0)