forked from PoctorDepper/LevelPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModPlayer.cs
More file actions
483 lines (412 loc) · 17.4 KB
/
ModPlayer.cs
File metadata and controls
483 lines (412 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
using System;
using System.Collections.Generic;
using Terraria.ModLoader.IO;
using Terraria.ModLoader;
using Terraria;
using Terraria.ID;
using levelplus.UI;
using Terraria.Audio;
namespace levelplus {
internal enum Weapon {
SWORD,//
YOYO,//
SUMMON,//
SPEAR,//
BOOMERANG,//
MAGIC,//
BOW,//
GUN,
THROWN
}
class levelplusModPlayer : ModPlayer {
float RATE = levelplusConfig.Instance.XPRate;
ushort INCREASE = (ushort)levelplusConfig.Instance.XPIncrease;
ushort BASE_XP = (ushort)levelplusConfig.Instance.XPBase;
ushort BASE_POINTS = (ushort)levelplusConfig.Instance.PointsBase;
ushort LEVEL_POINTS = (ushort)levelplusConfig.Instance.PointsPerLevel;
private Weapon weapon = (Weapon)new Random().Next(0, Enum.GetNames(typeof(Weapon)).Length);
private string talents;
private ulong currentXP;
private ulong neededXP;
public ushort level;
private ushort pointsUnspent;
private ushort talentUnspent;
private ushort constitution; //buff to max health, base defense
private ushort strength; //buff to melee damage
private ushort intelligence; //buff to max mana and magic damage
private ushort charisma; //buff to summon damage (maybe shop price)
private ushort dexterity; //buff to ranged
private ushort mobility; //movement speed and such
private ushort excavation; //pick speed
private ushort animalia; //fishing power and minion extras
private ushort luck; //xp gain and whatnot
private ushort mysticism; //max mana and regen
public ulong GetCurrentXP() {
return currentXP;
}
public ulong GetNeededXP() {
return neededXP;
}
public ushort GetLevel() {
return level;
}
public ushort GetCon() {
return constitution;
}
public ushort GetStr() {
return strength;
}
public ushort GetInt() {
return intelligence;
}
public ushort GetCha() {
return charisma;
}
public ushort GetDex() {
return dexterity;
}
public ushort GetMys() {
return mysticism;
}
public ushort GetMob() {
return mobility;
}
public ushort GetExc() {
return excavation;
}
public ushort GetAni() {
return animalia;
}
public ushort GetLuc() {
return luck;
}
public ushort GetUnspentPoints() {
return pointsUnspent;
}
public void spend(ButtonMode stat) {
if (pointsUnspent > 0) {
//SoundID.MenuTick
//ModSound.PlaySound(SoundEffectInstance, (int)Player.Center.X, (int)Player.Center.Y, Terraria.ModLoader.SoundType.Custom);
--pointsUnspent;
switch (stat) {
case ButtonMode.CON:
++constitution;
break;
case ButtonMode.STR:
++strength;
break;
case ButtonMode.INT:
++intelligence;
break;
case ButtonMode.CHA:
++charisma;
break;
case ButtonMode.DEX:
++dexterity;
break;
case ButtonMode.MOB:
++mobility;
break;
case ButtonMode.EXC:
++excavation;
break;
case ButtonMode.ANI:
++animalia;
break;
case ButtonMode.LUC:
++luck;
break;
case ButtonMode.MYS:
++mysticism;
break;
default:
break;
}
}
}
public override void OnEnterWorld(Player player) {
base.OnEnterWorld(player);
}
public override void ModifyStartingInventory(IReadOnlyDictionary<string, List<Item>> itemsByMod, bool mediumCoreDeath) {
Random rand = new Random();
if (!mediumCoreDeath) {
currentXP = 0;
neededXP = BASE_XP;
level = 0;
pointsUnspent = BASE_POINTS;
talents = "--------";
talentUnspent = 0;
constitution = 0;
strength = 0;
intelligence = 0;
charisma = 0;
dexterity = 0;
mobility = 0;
excavation = 0;
animalia = 0;
luck = 0;
mysticism = 0;
Item respec = new Item();
respec.SetDefaults(ModContent.ItemType<Items.Respec>());
itemsByMod["Terraria"].Add(respec);
}
switch (weapon) {
case Weapon.SWORD:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.CopperBroadsword));
break;
case Weapon.BOOMERANG:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.WoodenBoomerang));
break;
case Weapon.BOW:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.CopperBow));
Item arrows = new Item();
switch (rand.Next(3)) {
default:
arrows.SetDefaults(ItemID.WoodenArrow, true);
break;
case 1:
arrows.SetDefaults(ItemID.BoneArrow, true);
break;
case 2:
arrows.SetDefaults(ItemID.FlamingArrow, true);
break;
}
arrows.stack = 100 + rand.Next(101);
itemsByMod["Terraria"].Add(arrows);
break;
case Weapon.MAGIC:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.WandofSparking));
if (!mediumCoreDeath) {
Item manaCrystal = new Item();
manaCrystal.SetDefaults(ItemID.ManaCrystal, true);
itemsByMod["Terraria"].Add(manaCrystal);
}
break;
case Weapon.SUMMON:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.BabyBirdStaff));
break;
case Weapon.SPEAR:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.Spear));
break;
case Weapon.YOYO:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.WoodYoyo));
break;
case Weapon.GUN:
Item bullets = new(ItemID.MusketBall, 100 + rand.Next(101));
itemsByMod["Terraria"].Insert(0, new Item(ItemID.FlintlockPistol));
itemsByMod["Terraria"].Add(bullets);
break;
case Weapon.THROWN:
itemsByMod["Terraria"].Insert(0, new Item(ItemID.Shuriken, 100 + rand.Next(101)));
break;
default:
break;
}
}
public override void SaveData(TagCompound tag) {
//check if this character has a save tag
if (tag.GetBool("initialized")) {
tag.Set("level", level);
tag.Set("currentXP", currentXP);
tag.Set("neededXP", neededXP);
tag.Set("points", pointsUnspent);
tag.Set("talents", talents);
tag.Set("talentPoints", talentUnspent);
tag.Set("con", constitution);
tag.Set("str", strength);
tag.Set("int", intelligence);
tag.Set("cha", charisma);
tag.Set("dex", dexterity);
tag.Set("mob", mobility);
tag.Set("exc", excavation);
tag.Set("ani", animalia);
tag.Set("luc", luck);
tag.Set("mys", mysticism);
} else {
tag.Add("initialized", true);
tag.Add("level", level);
tag.Add("currentXP", currentXP);
tag.Add("neededXP", neededXP);
tag.Add("points", pointsUnspent);
tag.Add("talents", talents);
tag.Add("talentPoints", talentUnspent);
tag.Add("con", constitution);
tag.Add("str", strength);
tag.Add("int", intelligence);
tag.Add("cha", charisma);
tag.Add("dex", dexterity);
tag.Add("mob", mobility);
tag.Add("exc", excavation);
tag.Add("ani", animalia);
tag.Add("luc", luck);
tag.Add("mys", mysticism);
}
base.SaveData(tag);
}
public override void LoadData(TagCompound tag) {
if (tag.GetBool("initialized")) {
level = (ushort)tag.GetAsShort("level");
currentXP = (ulong)tag.GetAsLong("currentXP");
neededXP = (ulong)tag.GetAsLong("neededXP");
pointsUnspent = (ushort)tag.GetAsShort("points");
talents = tag.Get<string>("talents");
talentUnspent = (ushort)tag.GetAsShort("talentPoints");
constitution = (ushort)tag.GetAsShort("con");
strength = (ushort)tag.GetAsShort("str");
intelligence = (ushort)tag.GetAsShort("int");
charisma = (ushort)tag.GetAsShort("cha");
dexterity = (ushort)tag.GetAsShort("dex");
mobility = (ushort)tag.GetAsShort("mob");
excavation = (ushort)tag.GetAsShort("exc");
animalia = (ushort)tag.GetAsShort("ani");
luck = (ushort)(tag.ContainsKey("gra") ? tag.GetAsShort("gra") : tag.GetAsShort("luc"));
mysticism = (ushort)tag.GetAsShort("mys");
} else {
currentXP = 0;
neededXP = BASE_XP;
level = 0;
pointsUnspent = BASE_POINTS;
talents = "--------";
talentUnspent = 0;
constitution = 0;
strength = 0;
intelligence = 0;
charisma = 0;
dexterity = 0;
mobility = 0;
excavation = 0;
animalia = 0;
luck = 0;
mysticism = 0;
}
if(currentXP > neededXP) {
LevelUp();
}
base.LoadData(tag);
}
public override void OnRespawn(Player player) {
base.OnRespawn(player);
//lose a quarter of your xp on death
currentXP = (ulong)(currentXP * .75);
}
public override void PostUpdateEquips() {
base.PostUpdateEquips();
//COMBAT
//constitution
//+2 life per level
//+5 life per point
//+1 defense per 3 points
Player.statLifeMax2 += (levelplusConfig.Instance.HealthPerLevel * level) + (levelplusConfig.Instance.HealthPerPoint * constitution);
Player.lifeRegen += constitution / levelplusConfig.Instance.HRegenPerPoint;
Player.statDefense += constitution / levelplusConfig.Instance.DefensePerPoint;
//intelligence
//+1% damage per point
//+1% crit chance per 15 points
Player.GetDamage(DamageClass.Magic) *= 1.00f + (intelligence * levelplusConfig.Instance.MagicDamagePerPoint);
Player.GetCritChance(DamageClass.Magic) += intelligence / levelplusConfig.Instance.MagicCritPerPoint;
//strength
//+1% damage per point
//+1% crit chance per 15 points
Player.GetDamage(DamageClass.Melee) *= 1.00f + (strength * levelplusConfig.Instance.MeleeDamagePerPoint);
Player.GetCritChance(DamageClass.Melee) += strength / levelplusConfig.Instance.MeleeCritPerPoint;
//dexterity
//+1% damage per point
//+1% crit chance per 15 points
Player.GetDamage(DamageClass.Ranged) *= 1.00f + (dexterity * levelplusConfig.Instance.RangedDamagePerPoint);
Player.GetCritChance(DamageClass.Ranged) += dexterity / levelplusConfig.Instance.RangedCritPerPoint;
//charisma
//+1% damage per point
//+1% crit chance per 15 points
Player.GetDamage(DamageClass.Summon) *= 1.00f + (charisma * levelplusConfig.Instance.SummonDamagePerPoint);
Player.GetCritChance(DamageClass.Summon) += charisma / levelplusConfig.Instance.SummonCritPerPoint;
//UTILITY
//animalia
//+2% fishing skill per point
//+1 minion per 20 points
//+2% minion kb per point
Player.fishingSkill += (int)(Player.fishingSkill * (animalia * levelplusConfig.Instance.FishSkillPerPoint));
Player.maxMinions += animalia / levelplusConfig.Instance.MinionPerPoint;
Player.minionKB *= 1.00f * (animalia * levelplusConfig.Instance.MinionKnockBack);
//excavation
//+1% pick speed per point
//+2% place speed per point
//+1 place reach per 10 points
Player.pickSpeed *= 1.00f - (excavation * levelplusConfig.Instance.PickSpeedPerPoint);
Player.tileSpeed *= 1.00f + (excavation * levelplusConfig.Instance.BuildSpeedPerPoint);
Player.wallSpeed *= 1.00f + (excavation * levelplusConfig.Instance.BuildSpeedPerPoint);
Player.blockRange += excavation / levelplusConfig.Instance.RangePerPoint;
//mobility
//+1% max run speed per point
//+2% move speed per point
//+2% max flight time per point
Player.maxRunSpeed *= 1.00f + (mobility * levelplusConfig.Instance.RunSpeedPerPoint);
Player.runAcceleration *= 1.00f + (mobility * levelplusConfig.Instance.AccelPerPoint);
Player.wingTimeMax += (int)(Player.wingTimeMax * (mobility * levelplusConfig.Instance.WingPerPoint));
//luck
//+1% xp per point
//1% chance not to consume ammo
//mysticism
//+1 max mana per level
//+2 max mana per point
//+1 mana regen per 15 points
//-0.5% mana cost per point
Player.statManaMax2 += (levelplusConfig.Instance.ManaPerLevel * level) + (levelplusConfig.Instance.ManaPerPoint * mysticism);
Player.manaRegen += mysticism / levelplusConfig.Instance.ManaRegPerPoint;
}
public override void ModifyManaCost(Item item, ref float reduce, ref float mult) {
mult *= Math.Clamp(1.00f - (mysticism * levelplusConfig.Instance.ManaCostPerPoint), 0.00f, 1.00f);
base.ModifyManaCost(item, ref reduce, ref mult);
}
public override bool CanConsumeAmmo(Item weapon, Item ammo) {
Random rand = new();
if(rand.Next(1, levelplusConfig.Instance.AmmoPerPoint) <= luck) {
return false;
}
base.CanConsumeAmmo(weapon, ammo);
return true;
}
public void AddXp(ulong amount) {
currentXP += (ulong)(amount * (1 + (luck * levelplusConfig.Instance.XPPerPoint)));
if (currentXP >= neededXP) {
LevelUp();
}
}
public void AddPoints(int points) {
pointsUnspent = (ushort)(pointsUnspent + points);
}
private void LevelUp() {
Player.statLife = Player.statLifeMax2;
Player.statMana = Player.statManaMax2;
currentXP -= neededXP;
++level;
pointsUnspent += LEVEL_POINTS;
neededXP = (ulong)(INCREASE * Math.Pow(level, RATE)) + BASE_XP;
//run levelup again if XP is still higher, otherwise, play the level up noise
if (currentXP >= neededXP)
LevelUp();
else if (!Main.dedServ) {
SoundEngine.PlaySound(SoundLoader.GetLegacySoundSlot(Mod, "Sounds/Custom/level"));
}
}
public void StatReset() {
pointsUnspent = (ushort)(level * LEVEL_POINTS + BASE_POINTS);
constitution = 0;
strength = 0;
intelligence = 0;
charisma = 0;
dexterity = 0;
mysticism = 0;
mobility = 0;
animalia = 0;
luck = 0;
excavation = 0;
}
public override void SyncPlayer(int toWho, int fromWho, bool newPlayer) {
ModPacket packet = Mod.GetPacket();
packet.Write((byte)PacketType.Level);
packet.Write((byte)Player.whoAmI);
packet.Write(level);
packet.Send(toWho, fromWho);
}
}
}