-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElementalProjectile.cs
161 lines (146 loc) · 6.16 KB
/
ElementalProjectile.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
namespace ElementalWeaponEnhancements
{
class ElementalProjectile : GlobalProjectile
{
// Hacky way of determining if a projectile was shot by an enhanced item
// Very hacky, but there's no better way sadly.
public override bool PreAI(Projectile projectile)
{
try
{
ElementalProjectileInfo info = projectile.GetModInfo<ElementalProjectileInfo>(mod);
if (info.num++ == 0 && !projectile.hostile && projectile.friendly)
{
Player player = Main.player[projectile.owner];
Item item = player.inventory[player.selectedItem];
ElementalInfo itemInfo = item.GetModInfo<ElementalInfo>(mod);
if (itemInfo.enhanced)
{
info.enhanced = true;
info.elementalProjectile = projectile;
info.elementalType = itemInfo.elementalType;
info.sourceItem = item;
}
}
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
}
return base.PreAI(projectile);
}
// Custom OnHitNPC
public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
{
try
{
ElementalProjectileInfo info = projectile.GetModInfo<ElementalProjectileInfo>(mod);
if (info.enhanced)
{
if (ElementalFramework.Data.elementOnHit[info.elementalType].Item3 != null)
ElementalFramework.Data.elementOnHit[info.elementalType].Item3.Invoke(projectile, target, damage, knockback, crit);
}
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
}
base.OnHitNPC(projectile, target, damage, knockback, crit);
}
// Custom OnHitPVP
public override void OnHitPvp(Projectile projectile, Player target, int damage, bool crit)
{
try
{
ElementalProjectileInfo info = projectile.GetModInfo<ElementalProjectileInfo>(mod);
if (info.enhanced)
{
if (ElementalFramework.Data.elementOnHit[info.elementalType].Item4 != null)
ElementalFramework.Data.elementOnHit[info.elementalType].Item4.Invoke(projectile, target, damage, crit);
}
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
}
base.OnHitPvp(projectile, target, damage, crit);
}
// Custom ModifyHitNPC
public override void ModifyHitNPC(Projectile projectile, NPC target, ref int damage, ref float knockback, ref bool crit)
{
try
{
ElementalProjectileInfo info = projectile.GetModInfo<ElementalProjectileInfo>(mod);
if (info.enhanced)
{
bool addDamage = true;
if (ElementalFramework.Data.elementModifyHit[info.elementalType].Item3 != null)
{
var returnObjects = ElementalFramework.Data.elementModifyHit[info.elementalType].Item3.Invoke(projectile, target, damage, knockback, crit);
if ((!(bool)returnObjects.Item6))
addDamage = false;
if (returnObjects != null)
{
projectile = (Projectile)returnObjects.Item1;
target = (NPC)returnObjects.Item2;
damage = (int)returnObjects.Item3;
knockback = (float)returnObjects.Item4;
crit = (bool)returnObjects.Item5;
}
}
if (addDamage)
{
damage += info.sourceItem.GetModInfo<ElementalInfo>(mod).GetRealDamage(Main.player[info.sourceItem.owner]);
}
}
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
}
base.ModifyHitNPC(projectile, target, ref damage, ref knockback, ref crit);
}
// Custom ModifyHitPVP
public override void ModifyHitPvp(Projectile projectile, Player target, ref int damage, ref bool crit)
{
try
{
ElementalProjectileInfo info = projectile.GetModInfo<ElementalProjectileInfo>(mod);
if (info.enhanced)
{
bool addDamage = true;
if (ElementalFramework.Data.elementModifyHit[info.elementalType].Item4 != null)
{
var returnObjects = ElementalFramework.Data.elementModifyHit[info.elementalType].Item4.Invoke(projectile, target, damage, crit);
if ((!(bool)returnObjects.Item5))
addDamage = false;
if (returnObjects != null)
{
projectile = (Projectile)returnObjects.Item1;
target = (Player)returnObjects.Item2;
damage = (int)returnObjects.Item3;
crit = (bool)returnObjects.Item5;
}
if (addDamage)
{
damage += info.sourceItem.GetModInfo<ElementalInfo>(mod).GetRealDamage(Main.player[info.sourceItem.owner]);
}
}
}
}
catch (Exception e)
{
ErrorLogger.Log(e.ToString());
}
base.ModifyHitPvp(projectile, target, ref damage, ref crit);
}
}
}