Skip to content

Commit a450496

Browse files
authored
chore: long value type for Vitals, Exp and ConsumableData (AscensionGameDev#2250)
"Oh Long Johnson"
1 parent b6b407b commit a450496

File tree

24 files changed

+147
-122
lines changed

24 files changed

+147
-122
lines changed

Intersect (Core)/GameObjects/ClassBase.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public partial class ClassBase : DatabaseObject<ClassBase>, IFolderable
2222
public int[] BaseStat = new int[Enum.GetValues<Stat>().Length];
2323

2424
[NotMapped]
25-
public int[] BaseVital = new int[Enum.GetValues<Vital>().Length];
25+
public long[] BaseVital = new long[Enum.GetValues<Vital>().Length];
2626

2727
[NotMapped]
2828
public Dictionary<int, long> ExperienceOverrides = new Dictionary<int, long>();
@@ -46,10 +46,10 @@ public partial class ClassBase : DatabaseObject<ClassBase>, IFolderable
4646
public int[] StatIncrease = new int[Enum.GetValues<Stat>().Length];
4747

4848
[NotMapped]
49-
public int[] VitalIncrease = new int[Enum.GetValues<Vital>().Length];
49+
public long[] VitalIncrease = new long[Enum.GetValues<Vital>().Length];
5050

5151
[NotMapped]
52-
public int[] VitalRegen = new int[Enum.GetValues<Vital>().Length];
52+
public long[] VitalRegen = new long[Enum.GetValues<Vital>().Length];
5353

5454
[JsonConstructor]
5555
public ClassBase(Guid id) : base(id)
@@ -171,8 +171,8 @@ public string JsonBaseStats
171171
[JsonIgnore]
172172
public string JsonBaseVitals
173173
{
174-
get => DatabaseUtils.SaveIntArray(BaseVital, Enum.GetValues<Vital>().Length);
175-
set => BaseVital = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
174+
get => DatabaseUtils.SaveLongArray(BaseVital, Enum.GetValues<Vital>().Length);
175+
set => BaseVital = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
176176
}
177177

178178
//Starting Items
@@ -216,17 +216,17 @@ public string StatIncreaseJson
216216
[Column("VitalIncreases")]
217217
public string VitalIncreaseJson
218218
{
219-
get => DatabaseUtils.SaveIntArray(VitalIncrease, Enum.GetValues<Vital>().Length);
220-
set => VitalIncrease = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
219+
get => DatabaseUtils.SaveLongArray(VitalIncrease, Enum.GetValues<Vital>().Length);
220+
set => VitalIncrease = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
221221
}
222222

223223
//Vital Regen %
224224
[JsonIgnore]
225225
[Column("VitalRegen")]
226226
public string RegenJson
227227
{
228-
get => DatabaseUtils.SaveIntArray(VitalRegen, Enum.GetValues<Vital>().Length);
229-
set => VitalRegen = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
228+
get => DatabaseUtils.SaveLongArray(VitalRegen, Enum.GetValues<Vital>().Length);
229+
set => VitalRegen = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
230230
}
231231

232232
[JsonIgnore]

Intersect (Core)/GameObjects/ItemBase.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,23 @@ public ProjectileBase Projectile
261261
[JsonIgnore]
262262
public string VitalsJson
263263
{
264-
get => DatabaseUtils.SaveIntArray(VitalsGiven, Enum.GetValues<Vital>().Length);
265-
set => VitalsGiven = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
264+
get => DatabaseUtils.SaveLongArray(VitalsGiven, Enum.GetValues<Vital>().Length);
265+
set => VitalsGiven = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
266266
}
267267

268268
[NotMapped]
269-
public int[] VitalsGiven { get; set; }
269+
public long[] VitalsGiven { get; set; }
270270

271271
[Column("VitalsRegen")]
272272
[JsonIgnore]
273273
public string VitalsRegenJson
274274
{
275-
get => DatabaseUtils.SaveIntArray(VitalsRegen, Enum.GetValues<Vital>().Length);
276-
set => VitalsRegen = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
275+
get => DatabaseUtils.SaveLongArray(VitalsRegen, Enum.GetValues<Vital>().Length);
276+
set => VitalsRegen = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
277277
}
278278

279279
[NotMapped]
280-
public int[] VitalsRegen { get; set; }
280+
public long[] VitalsRegen { get; set; }
281281

282282
[Column("PercentageVitalsGiven")]
283283
[JsonIgnore]
@@ -485,8 +485,8 @@ private void Initialize()
485485
Speed = 10; // Set to 10 by default.
486486
StatsGiven = new int[Enum.GetValues<Stat>().Length];
487487
PercentageStatsGiven = new int[Enum.GetValues<Stat>().Length];
488-
VitalsGiven = new int[Enum.GetValues<Vital>().Length];
489-
VitalsRegen = new int[Enum.GetValues<Vital>().Length];
488+
VitalsGiven = new long[Enum.GetValues<Vital>().Length];
489+
VitalsRegen = new long[Enum.GetValues<Vital>().Length];
490490
PercentageVitalsGiven = new int[Enum.GetValues<Vital>().Length];
491491
Consumable = new ConsumableData();
492492
Effects = new List<EffectData>();
@@ -499,7 +499,7 @@ public partial class ConsumableData
499499
{
500500
public ConsumableType Type { get; set; }
501501

502-
public int Value { get; set; }
502+
public long Value { get; set; }
503503

504504
public int Percentage { get; set; }
505505
}

Intersect (Core)/GameObjects/NpcBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class NpcBase : DatabaseObject<NpcBase>, IFolderable
2121
public List<Drop> Drops = new List<Drop>();
2222

2323
[NotMapped]
24-
public int[] MaxVital = new int[Enum.GetValues<Vital>().Length];
24+
public long[] MaxVital = new long[Enum.GetValues<Vital>().Length];
2525

2626
[NotMapped]
2727
public ConditionLists PlayerCanAttackConditions = new ConditionLists();
@@ -33,7 +33,7 @@ public partial class NpcBase : DatabaseObject<NpcBase>, IFolderable
3333
public int[] Stats = new int[Enum.GetValues<Stat>().Length];
3434

3535
[NotMapped]
36-
public int[] VitalRegen = new int[Enum.GetValues<Vital>().Length];
36+
public long[] VitalRegen = new long[Enum.GetValues<Vital>().Length];
3737

3838
[NotMapped]
3939
public List<SpellEffect> Immunities = new List<SpellEffect>();
@@ -184,8 +184,8 @@ public string JsonDrops
184184
[JsonIgnore]
185185
public string JsonMaxVital
186186
{
187-
get => DatabaseUtils.SaveIntArray(MaxVital, Enum.GetValues<Vital>().Length);
188-
set => DatabaseUtils.LoadIntArray(ref MaxVital, value, Enum.GetValues<Vital>().Length);
187+
get => DatabaseUtils.SaveLongArray(MaxVital, Enum.GetValues<Vital>().Length);
188+
set => DatabaseUtils.LoadLongArray(ref MaxVital, value, Enum.GetValues<Vital>().Length);
189189
}
190190

191191
//NPC vs NPC Combat
@@ -246,8 +246,8 @@ public string JsonStat
246246
[Column("VitalRegen")]
247247
public string RegenJson
248248
{
249-
get => DatabaseUtils.SaveIntArray(VitalRegen, Enum.GetValues<Vital>().Length);
250-
set => VitalRegen = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
249+
get => DatabaseUtils.SaveLongArray(VitalRegen, Enum.GetValues<Vital>().Length);
250+
set => VitalRegen = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
251251
}
252252

253253
/// <inheritdoc />

Intersect (Core)/GameObjects/SpellBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Intersect.GameObjects
1616
public partial class SpellBase : DatabaseObject<SpellBase>, IFolderable
1717
{
1818
[NotMapped]
19-
public int[] VitalCost = new int[Enum.GetValues<Vital>().Length];
19+
public long[] VitalCost = new long[Enum.GetValues<Vital>().Length];
2020

2121
[JsonConstructor]
2222
public SpellBase(Guid id) : base(id)
@@ -134,8 +134,8 @@ public EventBase Event
134134
[JsonIgnore]
135135
public string VitalCostJson
136136
{
137-
get => DatabaseUtils.SaveIntArray(VitalCost, Enum.GetValues<Vital>().Length);
138-
set => VitalCost = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
137+
get => DatabaseUtils.SaveLongArray(VitalCost, Enum.GetValues<Vital>().Length);
138+
set => VitalCost = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
139139
}
140140

141141
/// <inheritdoc />
@@ -167,7 +167,7 @@ public static SpellBase[] GetCooldownGroup(string cooldownGroup)
167167
public partial class SpellCombatData
168168
{
169169
[NotMapped]
170-
public int[] VitalDiff = new int[Enum.GetValues<Vital>().Length];
170+
public long[] VitalDiff = new long[Enum.GetValues<Vital>().Length];
171171

172172
public int CritChance { get; set; }
173173

@@ -198,8 +198,8 @@ public ProjectileBase Projectile
198198
[JsonIgnore]
199199
public string VitalDiffJson
200200
{
201-
get => DatabaseUtils.SaveIntArray(VitalDiff, Enum.GetValues<Vital>().Length);
202-
set => VitalDiff = DatabaseUtils.LoadIntArray(value, Enum.GetValues<Vital>().Length);
201+
get => DatabaseUtils.SaveLongArray(VitalDiff, Enum.GetValues<Vital>().Length);
202+
set => VitalDiff = DatabaseUtils.LoadLongArray(value, Enum.GetValues<Vital>().Length);
203203
}
204204

205205
//Buff/Debuff Data

Intersect (Core)/Network/Packets/Server/EntityPacket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public abstract partial class EntityPacket : IntersectPacket
5555
public Guid[] Animations { get; set; }
5656

5757
[Key(15)]
58-
public int[] Vital { get; set; }
58+
public long[] Vital { get; set; }
5959

6060
[Key(16)]
61-
public int[] MaxVital { get; set; }
61+
public long[] MaxVital { get; set; }
6262

6363
[Key(17)]
6464
public int[] Stats { get; set; }

Intersect (Core)/Network/Packets/Server/EntityVitalsPacket.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public EntityVitalsPacket(
1717
Guid id,
1818
EntityType type,
1919
Guid mapId,
20-
int[] vitals,
21-
int[] maxVitals,
20+
long[] vitals,
21+
long[] maxVitals,
2222
StatusPacket[] statusEffects,
2323
long combatTimeRemaining
2424
)
@@ -46,10 +46,10 @@ long combatTimeRemaining
4646
public Guid MapId { get; set; }
4747

4848
[Key(3)]
49-
public int[] Vitals { get; set; }
49+
public long[] Vitals { get; set; }
5050

5151
[Key(4)]
52-
public int[] MaxVitals { get; set; }
52+
public long[] MaxVitals { get; set; }
5353

5454
[Key(5)]
5555
public StatusPacket[] StatusEffects { get; set; }

Intersect (Core)/Network/Packets/Server/MapEntityVitalsPacket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public partial class EntityVitalData
3636
public Enums.EntityType Type { get; set; }
3737

3838
[Key(2)]
39-
public int[] Vitals { get; set; } = new int[Enum.GetValues<Vital>().Length];
39+
public long[] Vitals { get; set; } = new long[Enum.GetValues<Vital>().Length];
4040

4141
[Key(3)]
42-
public int[] MaxVitals { get; set; } = new int[Enum.GetValues<Vital>().Length];
42+
public long[] MaxVitals { get; set; } = new long[Enum.GetValues<Vital>().Length];
4343

4444
[Key(4)]
4545
public long CombatTimeRemaining { get; set; }

Intersect (Core)/Network/Packets/Server/PartyMemberPacket.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public PartyMemberPacket()
1111
{
1212
}
1313

14-
public PartyMemberPacket(Guid id, string name, int[] vital, int[] maxVital, int level)
14+
public PartyMemberPacket(Guid id, string name, long[] vital, long[] maxVital, int level)
1515
{
1616
Id = id;
1717
Name = name;
@@ -27,10 +27,10 @@ public PartyMemberPacket(Guid id, string name, int[] vital, int[] maxVital, int
2727
public string Name { get; set; }
2828

2929
[Key(2)]
30-
public int[] Vital { get; set; }
30+
public long[] Vital { get; set; }
3131

3232
[Key(3)]
33-
public int[] MaxVital { get; set; }
33+
public long[] MaxVital { get; set; }
3434

3535
[Key(4)]
3636
public int Level { get; set; }

Intersect (Core)/Network/Packets/Server/StatusPacket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public StatusPacket(
1919
string transformSprite,
2020
long timeRemaining,
2121
long totalDuration,
22-
int[] vitalShields
22+
long[] vitalShields
2323
)
2424
{
2525
SpellId = spellId;
@@ -46,7 +46,7 @@ int[] vitalShields
4646
public long TotalDuration { get; set; }
4747

4848
[Key(5)]
49-
public int[] VitalShields { get; set; }
49+
public long[] VitalShields { get; set; }
5050

5151
}
5252

Intersect (Core)/Utilities/DatabaseUtils.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,42 @@ public static string SaveIntArray(int[] array, int arrayLen)
5757
return JsonConvert.SerializeObject(output);
5858
}
5959

60+
public static long[] LoadLongArray(string json, long arrayLen)
61+
{
62+
var output = new long[arrayLen];
63+
var jsonList = json != null ? JsonConvert.DeserializeObject<List<long>>(json) : new List<long>();
64+
65+
for (var i = 0; i < arrayLen && i < jsonList.Count; i++)
66+
{
67+
output[i] = jsonList[i];
68+
}
69+
70+
return output;
71+
}
72+
73+
public static void LoadLongArray(ref long[] output, string json, long arrayLen)
74+
{
75+
var jsonList = JsonConvert.DeserializeObject<List<long>>(json);
76+
77+
for (var i = 0; i < arrayLen && i < jsonList.Count; i++)
78+
{
79+
output[i] = jsonList[i];
80+
}
81+
}
82+
83+
public static string SaveLongArray(long[] array, long arrayLen)
84+
{
85+
array ??= new long[arrayLen];
86+
87+
var output = new List<long>();
88+
for (var i = 0; i < arrayLen; i++)
89+
{
90+
output.Add(i < array.Length ? array[i] : 0);
91+
}
92+
93+
return JsonConvert.SerializeObject(output);
94+
}
95+
6096
public static string SaveColor(Color color)
6197
{
6298
if (color == null)

0 commit comments

Comments
 (0)