-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssassinPlugin.cs
More file actions
240 lines (207 loc) · 10.9 KB
/
AssassinPlugin.cs
File metadata and controls
240 lines (207 loc) · 10.9 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
using BepInEx;
using AssassinMod.Survivors.Assassin;
using R2API.Utils;
using RoR2;
using RoR2.Skills;
using System.Collections.Generic;
using System.Security;
using System.Security.Permissions;
using UnityEngine;
using AssassinMod.Characters.Survivors.Assassin;
using R2API;
using System.Runtime.CompilerServices;
using RoR2.Skills;
using AssassinMod.Survivors.Assassin.Components;
using RoR2.Projectile;
using AssassinMod.Characters.Entities.Decoy;
using R2API.Networking.Interfaces;
using System.Reflection;
using System.Linq;
[module: UnverifiableCode]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
namespace AssassinMod
{
//[BepInDependency("com.rune580.riskofoptions", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.bepis.r2api", BepInDependency.DependencyFlags.HardDependency)]
[BepInDependency("com.weliveinasociety.CustomEmotesAPI", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.DestroyedClone.AncientScepter", BepInDependency.DependencyFlags.SoftDependency)]
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.EveryoneNeedSameModVersion)]
[BepInPlugin(MODUID, MODNAME, MODVERSION)]
public class AssassinPlugin : BaseUnityPlugin
{
public const string MODUID = "com.HasteReapr.AssassinMod";
public const string MODNAME = "AssassinMod";
public const string MODVERSION = "2.2.2";
public const string DEVELOPER_PREFIX = "HASTEREAPR";
public static AssassinPlugin instance;
//public static bool emoteAPILoaded => BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("com.weliveinasociety.CustomEmotesAPI");
public static bool scepterStandaloneLoaded = BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("com.DestroyedClone.AncientScepter");
void Awake()
{
instance = this;
//easy to use logger
Log.Init(Logger);
// used when you want to properly set up language folders
Modules.Language.Init();
// character initialization
new AssassinPlr().Initialize();
// Hooks into things like ServerOnTakeDamage
Hook();
//handles all of the emoteAPI compatability stuff
if (EmoteAPICompat.enabled) EmoteAPICompat.EmoteHook();
// Loads AssassinDecoy
new AssassinDecoy().Create();
// Make a content pack and add it. this has to be last
new Modules.ContentPacks().Initialize();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private void Hook()
{
On.RoR2.CharacterBody.RecalculateStats += CharacterBody_RecalculateStats;
On.RoR2.CharacterBody.OnTakeDamageServer += CharacterBody_OnTakeDamageServer;
On.RoR2.HealthComponent.TakeDamage += HealthComponent_TakeDamage;
}
private void CharacterBody_RecalculateStats(On.RoR2.CharacterBody.orig_RecalculateStats orig, CharacterBody self)
{
orig(self);
if (self)
{
if (self.HasBuff(AssassinBuffs.madGodBuff))
{
self.damage *= 1 + (0.075f * self.GetBuffCount(AssassinBuffs.madGodBuff));
self.attackSpeed *= 1 + (0.075f * self.GetBuffCount(AssassinBuffs.madGodBuff));
}
if (self.HasBuff(AssassinBuffs.hardcoreDrugsBuff))
{
self.damage *= 1.05f;
self.attackSpeed *= 1.05f;
self.maxHealth *= 1.05f;
self.moveSpeed *= 1.05f;
self.regen *= 1.05f;
}
}
}
private void HealthComponent_TakeDamage(On.RoR2.HealthComponent.orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
{
if (self.body.HasBuff(AssassinBuffs.poisonDebuff))
{
damageInfo.damage *= 1f + (0.025f * self.body.GetBuffCount(AssassinBuffs.poisonDebuff));
}
orig(self, damageInfo);
}
private void CharacterBody_OnTakeDamageServer(On.RoR2.CharacterBody.orig_OnTakeDamageServer orig, CharacterBody self, DamageReport damageReport)
{
orig(self, damageReport);
if (self.TryGetComponent(out AssassinPassiveController passiveCtrl))
{
if (passiveCtrl.GetPassiveType() == 0) // Rage Passive
{
if (self.healthComponent.combinedHealth <= (self.healthComponent.fullCombinedHealth) * 0.6f)
{
self.AddTimedBuff(AssassinBuffs.madGodBuff, 3);
}
}
else if (passiveCtrl.GetPassiveType() == 1 && damageReport.attackerBody) // Poison Passive
{
// If we do not have the cooldown debuff or we are drugged we can shoot, otherwise we have a 4.5 second cooldown
if (!self.HasBuff(AssassinBuffs.terrorCD) || self.HasBuff(AssassinBuffs.assassinDrugsBuff))
{
// This isn't 100% throwing in the direction of the attacker, and it does end up being kinda random, however this is the closest I can get right now.
var forward = self.corePosition;
var toOther = damageReport.attackerBody.corePosition;
var potDir = Vector3.Dot(forward, toOther);
ProjectileManager.instance.FireProjectile(new FireProjectileInfo()
{
owner = self.gameObject,
damage = AssassinStaticValues.poisonDamageCoef * self.damage,
force = 0,
position = new Vector3(self.gameObject.transform.position.x, self.gameObject.transform.position.y + 2, self.gameObject.transform.position.z),
rotation = Quaternion.Euler(0, potDir, 0),
projectilePrefab = AssassinAssets.poison,
speedOverride = 32,
});
// If we have the drugs buff we throw poison out regardless of cooldown, and don't apply the cooldown
if (!self.HasBuff(AssassinBuffs.assassinDrugsBuff))
{
self.AddTimedBuff(AssassinBuffs.terrorCD, 4f);
}
}
}
else if (passiveCtrl.GetPassiveType() == 2) // Decoy Passive
{
if(RoR2.Util.CheckRoll(5 + damageReport.damageInfo.procCoefficient, self.master))
{
new DecoySync(self.gameObject).Send(R2API.Networking.NetworkDestination.Server);
}
}
};
// If the victim is hit by any of the poison stuff
if (DamageAPI.HasModdedDamageType(damageReport.damageInfo, AssassinAssets.poisonDmgType))
{
DotController.InflictDot(self.gameObject, damageReport.attacker, AssassinBuffs.poisonDoT, 10, 0.3f);
//DotController.InflictDot(self.gameObject, damageReport.attacker, AssassinBuffs.poisonDoT);
}
// If the victim is hit by the smokebomb AOE apply stun
if (DamageAPI.HasModdedDamageType(damageReport.damageInfo, AssassinAssets.smokeDmgType))
{
//damageReport.victimBody.AddTimedBuff(RoR2Content.Buffs., 2);
RoR2.SetStateOnHurt.SetStunOnObject(damageReport.victimBody.gameObject, 2.5f);
}
// If the victim is hit by backstab damage type
if (DamageAPI.HasModdedDamageType(damageReport.damageInfo, AssassinAssets.backStabDmg))
{ // Then checks if its a backstab
if (BackstabManager.IsBackstab(damageReport.attackerBody.characterDirection.forward, damageReport.victimBody))
{
float curHP = damageReport.victimBody.healthComponent.combinedHealth;
float maxHP = damageReport.victimBody.healthComponent.fullCombinedHealth;
float dmg = 0;
if (AssassinConfig.BackstabInsta.Value || !damageReport.victimBody.isBoss)
{
// If we arent a boss, then do the damage thing
// Just making sure we dont overflow & do negative damage
if ((curHP + maxHP) * 6 <= int.MaxValue)
dmg = (curHP + maxHP) * 6;
else
dmg = int.MaxValue;
}
else
{
if (RoR2.Util.CheckRoll(AssassinConfig.BackstabChance.Value, damageReport.attackerMaster))
{
// Just making sure we dont overflow & do negative damage
if ((curHP + maxHP) * 6 <= int.MaxValue)
dmg = (curHP + maxHP) * 6;
else
dmg = int.MaxValue;
}
else
dmg = damageReport.victimBody.healthComponent.fullHealth * 0.25f + damageReport.victimBody.healthComponent.adaptiveArmorValue;
}
DamageInfo dmgInfo = new DamageInfo()
{
attacker = damageReport.attackerBody.gameObject,
crit = false,
damage = dmg,
damageColorIndex = DamageColorIndex.Bleed,
force = Vector3.zero,
procCoefficient = 0,
damageType = DamageType.Generic,
position = damageReport.victimBody.corePosition,
inflictor = damageReport.attackerBody.gameObject
};
damageReport.victimBody.healthComponent.TakeDamage(dmgInfo);
damageReport.attackerBody.AddTimedBuff(RoR2Content.Buffs.CloakSpeed, 2.5f);
}
}
}
public static void SetupScepterStandalone(string bodyName, SkillDef scepterSkill, SkillSlot skillSlot, int skillIndex)
{
if (scepterStandaloneLoaded) SetupScepterStandaloneInternal(bodyName, scepterSkill, skillSlot, skillIndex);
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void SetupScepterStandaloneInternal(string bodyName, SkillDef scepterSkill, SkillSlot skillSlot, int skillIndex)
{
AncientScepter.AncientScepterItem.instance.RegisterScepterSkill(scepterSkill, bodyName, skillSlot, skillIndex);
}
}
}