forked from Jofairden/EvenMoreModifiers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifierProjectile.cs
More file actions
137 lines (120 loc) · 4.46 KB
/
Copy pathModifierProjectile.cs
File metadata and controls
137 lines (120 loc) · 4.46 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
using System;
using System.Collections.Generic;
using Loot.Modifiers.WeaponModifiers;
using Terraria;
using Terraria.ModLoader;
namespace Loot
{
public class ModifierProjectile : GlobalProjectile
{
public override bool InstancePerEntity => true;
public override bool CloneNewInstances => true;
public override GlobalProjectile Clone()
{
var clone = (ModifierProjectile)base.MemberwiseClone();
clone.SNAPSHOT_DebuffChances = new List<RandomDebuff.DebuffTrigger>(SNAPSHOT_DebuffChances);
return clone;
}
public ModifierProjectile Info(Projectile projectile, Mod mod = null)
=> mod == null
? projectile.GetGlobalProjectile<ModifierProjectile>()
: projectile.GetGlobalProjectile<ModifierProjectile>(mod);
public bool NeedsClear;
public bool FirstTick;
public float SNAPSHOT_HealthyFoesMulti = 1f;
public float SNAPSHOT_CritMulti = 1f;
public IList<RandomDebuff.DebuffTrigger> SNAPSHOT_DebuffChances = new List<RandomDebuff.DebuffTrigger>();
private void AttemptDebuff(Projectile projectile, Player target)
{
foreach (var x in Info(projectile).SNAPSHOT_DebuffChances)
{
if (Main.rand.NextFloat() < x.InflictionChance)
target.AddBuff(x.BuffType, x.BuffTime);
}
}
private void AttemptDebuff(Projectile projectile, NPC target)
{
foreach (var x in Info(projectile).SNAPSHOT_DebuffChances)
{
if (Main.rand.NextFloat() < x.InflictionChance)
target.AddBuff(x.BuffType, x.BuffTime);
}
}
private void HealthyBonus(Projectile projectile, ref int damage, NPC target)
{
if (target.life == target.lifeMax) damage = (int)Math.Ceiling(damage * Info(projectile).SNAPSHOT_HealthyFoesMulti);
}
private void HealthyBonus(Projectile projectile, ref int damage, Player target)
{
if (target.statLife == target.statLifeMax2) damage = (int)Math.Ceiling(damage * Info(projectile).SNAPSHOT_HealthyFoesMulti);
}
private void CritBonus(Projectile projectile, ref int damage, bool crit)
{
if (crit) damage = (int)Math.Ceiling(damage * Info(projectile).SNAPSHOT_CritMulti);
}
public override bool PreAI(Projectile projectile)
{
// On first tick, copy over player stats
if (!FirstTick)
{
FirstTick = true;
var mproj = Info(projectile);
// Snapshot current player values
if (projectile.owner != 255 && projectile.friendly && projectile.owner == Main.myPlayer)
{
var mplr = Main.LocalPlayer.GetModPlayer<ModifierPlayer>();
mproj.SNAPSHOT_DebuffChances = new List<RandomDebuff.DebuffTrigger>(mplr.DebuffChances);
mproj.SNAPSHOT_HealthyFoesMulti = mplr.HealthyFoesMulti;
if (!projectile.minion) // minions do not crit
mproj.SNAPSHOT_CritMulti = mplr.CritMultiplier;
}
else if (projectile.owner == 255)
{
// TODO snapshot npc values. possible?
}
}
if (NeedsClear)
{
var mproj = Info(projectile);
mproj.SNAPSHOT_HealthyFoesMulti = 1f;
mproj.SNAPSHOT_DebuffChances.Clear();
}
return base.PreAI(projectile);
}
// TODO I hate the copy pasta
public override void ModifyHitNPC(Projectile projectile, NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
HealthyBonus(projectile, ref damage, target);
CritBonus(projectile, ref damage, crit);
base.ModifyHitNPC(projectile, target, ref damage, ref knockback, ref crit, ref hitDirection);
}
// shouldn't run
public override void ModifyHitPlayer(Projectile projectile, Player target, ref int damage, ref bool crit)
{
HealthyBonus(projectile, ref damage, target);
CritBonus(projectile, ref damage, crit);
base.ModifyHitPlayer(projectile, target, ref damage, ref crit);
}
public override void ModifyHitPvp(Projectile projectile, Player target, ref int damage, ref bool crit)
{
HealthyBonus(projectile, ref damage, target);
CritBonus(projectile, ref damage, crit);
base.ModifyHitPvp(projectile, target, ref damage, ref crit);
}
public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
{
AttemptDebuff(projectile, target);
base.OnHitNPC(projectile, target, damage, knockback, crit);
}
public override void OnHitPlayer(Projectile projectile, Player target, int damage, bool crit)
{
AttemptDebuff(projectile, target);
base.OnHitPlayer(projectile, target, damage, crit);
}
public override void OnHitPvp(Projectile projectile, Player target, int damage, bool crit)
{
AttemptDebuff(projectile, target);
base.OnHitPvp(projectile, target, damage, crit);
}
}
}