Skip to content

Commit 5357144

Browse files
committed
fix: lookups for stats/vitals since exposing the enums isn't working
1 parent bf0e876 commit 5357144

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

Framework/Intersect.Framework.Core/GameObjects/ClassBase.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,32 @@ public partial class ClassBase : DatabaseObject<ClassBase>, IFolderable
1616

1717
public const long DEFAULT_EXPERIENCE_INCREASE = 50;
1818

19-
[NotMapped]
19+
[NotMapped, JsonIgnore]
2020
public int[] BaseStat { get; set; } = new int[Enum.GetValues<Stat>().Length];
2121

22-
[NotMapped]
22+
[NotMapped, JsonIgnore]
2323
public long[] BaseVital { get; set; } = new long[Enum.GetValues<Vital>().Length];
2424

25+
[JsonProperty(nameof(BaseVital)), NotMapped]
26+
public IReadOnlyDictionary<Vital, long> BaseVitalLookup => BaseVital.Select((value, index) => (value, index))
27+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
28+
29+
[JsonProperty(nameof(VitalIncrease)), NotMapped]
30+
public IReadOnlyDictionary<Vital, long> VitalIncreaseLookup => VitalIncrease.Select((value, index) => (value, index))
31+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
32+
33+
[JsonProperty(nameof(VitalRegen)), NotMapped]
34+
public IReadOnlyDictionary<Vital, long> VitalRegenLookup => VitalRegen.Select((value, index) => (value, index))
35+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
36+
37+
[JsonProperty(nameof(BaseStat)), NotMapped]
38+
public IReadOnlyDictionary<Stat, int> BaseStatLookup => BaseStat.Select((statValue, index) => (statValue, index))
39+
.ToDictionary(t => (Stat)t.index, t => t.statValue).AsReadOnly();
40+
41+
[JsonProperty(nameof(StatIncrease)), NotMapped]
42+
public IReadOnlyDictionary<Stat, int> StatIncreaseLookup => StatIncrease.Select((statValue, index) => (statValue, index))
43+
.ToDictionary(t => (Stat)t.index, t => t.statValue).AsReadOnly();
44+
2545
[NotMapped] public Dictionary<int, long> ExperienceOverrides { get; set; } = [];
2646

2747
[NotMapped]
@@ -39,13 +59,13 @@ public partial class ClassBase : DatabaseObject<ClassBase>, IFolderable
3959
[NotMapped]
4060
public List<ClassSprite> Sprites { get; set; } = [];
4161

42-
[NotMapped]
62+
[NotMapped, JsonIgnore]
4363
public int[] StatIncrease { get; set; } = new int[Enum.GetValues<Stat>().Length];
4464

45-
[NotMapped]
65+
[NotMapped, JsonIgnore]
4666
public long[] VitalIncrease { get; set; } = new long[Enum.GetValues<Vital>().Length];
4767

48-
[NotMapped]
68+
[NotMapped, JsonIgnore]
4969
public long[] VitalRegen { get; set; } = new long[Enum.GetValues<Vital>().Length];
5070

5171
[JsonConstructor]

Framework/Intersect.Framework.Core/GameObjects/NpcBase.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Intersect.GameObjects;
1212

1313
public partial class NpcBase : DatabaseObject<NpcBase>, IFolderable
1414
{
15-
private long[] _maxVital = new long[Enum.GetValues<Vital>().Length];
15+
private long[] _maxVitals = new long[Enum.GetValues<Vital>().Length];
1616
private int[] _stats = new int[Enum.GetValues<Stat>().Length];
1717
private long[] _vitalRegen = new long[Enum.GetValues<Vital>().Length];
1818

@@ -22,27 +22,39 @@ public partial class NpcBase : DatabaseObject<NpcBase>, IFolderable
2222
[NotMapped]
2323
public List<Drop> Drops { get; set; }= [];
2424

25-
[NotMapped]
26-
public long[] MaxVital
25+
[NotMapped, JsonIgnore]
26+
public long[] MaxVitals
2727
{
28-
get => _maxVital;
29-
set => _maxVital = value;
28+
get => _maxVitals;
29+
set => _maxVitals = value;
3030
}
3131

32+
[JsonProperty(nameof(MaxVitals)), NotMapped]
33+
public IReadOnlyDictionary<Vital, long> MaxVitalsLookup => MaxVitals.Select((value, index) => (value, index))
34+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
35+
36+
[JsonProperty(nameof(VitalRegen)), NotMapped]
37+
public IReadOnlyDictionary<Vital, long> VitalRegenLookup => VitalRegen.Select((value, index) => (value, index))
38+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
39+
40+
[JsonProperty(nameof(Stats)), NotMapped]
41+
public IReadOnlyDictionary<Stat, int> StatsLookup => Stats.Select((statValue, index) => (statValue, index))
42+
.ToDictionary(t => (Stat)t.index, t => t.statValue).AsReadOnly();
43+
3244
[NotMapped]
3345
public ConditionLists PlayerCanAttackConditions { get; set; } = new();
3446

3547
[NotMapped]
3648
public ConditionLists PlayerFriendConditions { get; set; } = new();
3749

38-
[NotMapped]
50+
[NotMapped, JsonIgnore]
3951
public int[] Stats
4052
{
4153
get => _stats;
4254
set => _stats = value;
4355
}
4456

45-
[NotMapped]
57+
[NotMapped, JsonIgnore]
4658
public long[] VitalRegen
4759
{
4860
get => _vitalRegen;
@@ -198,8 +210,8 @@ public string JsonDrops
198210
[JsonIgnore]
199211
public string JsonMaxVital
200212
{
201-
get => DatabaseUtils.SaveLongArray(_maxVital, Enum.GetValues<Vital>().Length);
202-
set => DatabaseUtils.LoadLongArray(ref _maxVital, value, Enum.GetValues<Vital>().Length);
213+
get => DatabaseUtils.SaveLongArray(_maxVitals, Enum.GetValues<Vital>().Length);
214+
set => DatabaseUtils.LoadLongArray(ref _maxVitals, value, Enum.GetValues<Vital>().Length);
203215
}
204216

205217
//NPC vs NPC Combat

Intersect.Server.Core/Entities/Entity.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ public abstract partial class Entity : IEntity
3232
[NotMapped]
3333
public Guid MapInstanceId { get; set; } = Guid.Empty;
3434

35-
[JsonProperty("MaxVitals"), NotMapped] private long[] _maxVital = new long[Enum.GetValues<Vital>().Length];
35+
[NotMapped] private long[] _maxVital = new long[Enum.GetValues<Vital>().Length];
36+
37+
[JsonProperty("MaxVitals"), NotMapped]
38+
public IReadOnlyDictionary<Vital, long> MaxVitalsLookup => GetMaxVitals().Select((value, index) => (value, index))
39+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
3640

3741
[NotMapped, JsonIgnore] public Combat.Stat[] Stat = new Combat.Stat[Enum.GetValues<Stat>().Length];
3842

43+
[JsonProperty("Stats"), NotMapped]
44+
public IReadOnlyDictionary<Stat, int> StatsLookup => Stat.Select((computedStat, index) => (computedStat, index))
45+
.ToDictionary(t => (Stat)t.index, t => t.computedStat.Value()).AsReadOnly();
46+
47+
[JsonProperty("Vitals"), NotMapped]
48+
public IReadOnlyDictionary<Vital, long> VitalsLookup => _vitals.Select((value, index) => (value, index))
49+
.ToDictionary(t => (Vital)t.index, t => t.value).AsReadOnly();
50+
3951
[NotMapped, JsonIgnore] public Entity Target { get; set; } = null;
4052

4153
public Entity() : this(Guid.NewGuid(), Guid.Empty)
@@ -102,12 +114,12 @@ public string JsonColor
102114
[JsonIgnore, Column("Vitals")]
103115
public string VitalsJson
104116
{
105-
get => DatabaseUtils.SaveLongArray(mVitals, Enum.GetValues<Vital>().Length);
106-
set => mVitals = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
117+
get => DatabaseUtils.SaveLongArray(_vitals, Enum.GetValues<Vital>().Length);
118+
set => _vitals = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
107119
}
108120

109-
[JsonProperty("Vitals"), NotMapped]
110-
private long[] mVitals { get; set; } = new long[Enum.GetValues<Vital>().Length];
121+
[NotMapped]
122+
private long[] _vitals { get; set; } = new long[Enum.GetValues<Vital>().Length];
111123

112124
[JsonIgnore, NotMapped]
113125
private long[] mOldVitals { get; set; } = new long[Enum.GetValues<Vital>().Length];
@@ -1402,13 +1414,13 @@ public virtual void ProcessRegen()
14021414

14031415
public long GetVital(int vital)
14041416
{
1405-
return mVitals[vital];
1417+
return _vitals[vital];
14061418
}
14071419

14081420
public long[] GetVitals()
14091421
{
14101422
var vitals = new long[Enum.GetValues<Vital>().Length];
1411-
Array.Copy(mVitals, 0, vitals, 0, Enum.GetValues<Vital>().Length);
1423+
Array.Copy(_vitals, 0, vitals, 0, Enum.GetValues<Vital>().Length);
14121424

14131425
return vitals;
14141426
}
@@ -1430,7 +1442,7 @@ public void SetVital(int vital, long value)
14301442
value = GetMaxVital(vital);
14311443
}
14321444

1433-
mVitals[vital] = value;
1445+
_vitals[vital] = value;
14341446
}
14351447

14361448
public void SetVital(Vital vital, long value)

Intersect.Server.Core/Entities/Npc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public Npc(NpcBase myBase, bool despawnable = false) : base()
139139

140140
for (var i = 0; i < Enum.GetValues<Vital>().Length; i++)
141141
{
142-
SetMaxVital(i, myBase.MaxVital[i]);
143-
SetVital(i, myBase.MaxVital[i]);
142+
SetMaxVital(i, myBase.MaxVitals[i]);
143+
SetVital(i, myBase.MaxVitals[i]);
144144
}
145145

146146
Range = (byte)myBase.SightRange;

Intersect.Server.Core/Entities/Player.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public partial class Player : Entity
6969

7070
public static int OnlineCount => OnlinePlayers.Count;
7171

72-
[JsonProperty("MaxVitals"), NotMapped]
73-
public new long[] MaxVitals => GetMaxVitals();
72+
[JsonIgnore, NotMapped]
73+
public long[] MaxVitals => GetMaxVitals();
7474

7575
//Name, X, Y, Dir, Etc all in the base Entity Class
7676
public Guid ClassId { get; set; }

Intersect.Server/Web/Net7/ApiService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
172172
sgo.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: true);
173173
sgo.UseOneOfForPolymorphism();
174174
sgo.UseAllOfForInheritance();
175-
sgo.MapType(
176-
typeof(LookupKey),
175+
sgo.MapType<LookupKey>(
177176
() => new OpenApiSchema
178177
{
179178
Type = "string",

0 commit comments

Comments
 (0)