forked from Flashkirby/WeaponOut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeaponOut.cs
499 lines (451 loc) · 18.3 KB
/
WeaponOut.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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
/*
RARITY:
* 1 - Special/Unique early armour + weapons
* 2 - Dungeon loot and other decent mid-early things
* 3 - Hell/Jungle
* 4 - Hardmode ore stuff
* 5 - Mechanical Bosses
* 6 - Unique/Powerful (intermediate)
* 7 - Chloropyhte and Plantera Loot
* 8 - Golem Loot, the Terrarian
* 9 - Lunar materials, dev loot
* 10 - Ancient Manipulator + Moonlord
*/
namespace WeaponOut
{
public class WeaponOut : Mod
{
internal static Mod mod;
public static Texture2D dHeart;
public static Texture2D pumpkinMark;
public static int BuffIDManaReduction;
public static int BuffIDMirrorBarrier;
public static int DustIDManaDust;
public static int shakeIntensity = 0;
private static int shakeTick = 0;
public WeaponOut()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
ModConf.Load();
}
public override void Load()
{
mod = this;
}
public override void PostSetupContent()
{
if (ModConf.enableAccessories) BuffIDMirrorBarrier = GetBuff("MirrorBarrier").Type;
if (ModConf.enableDualWeapons) BuffIDManaReduction = GetBuff("ManaReduction").Type;
DustIDManaDust = GetDust<Dusts.ManaDust>().Type;
if (ModConf.enableEmblems) Items.Accessories.HeliosphereEmblem.SetUpGlobalDPS();
if (Main.netMode != 2)
{
dHeart = mod.GetTexture("Gores/DemonHearts");
pumpkinMark = mod.GetTexture("Gores/PumpkinMark");
}
else
{
Console.WriteLine("WeaponOut loaded: fistsupdate2#01");
}
}
/// <summary>
/// Registers a glowmask texture to the game's array, and returns that value.
/// The file should be located under Glow/ItemName_Glow. Make sure to register
/// the returned value under item.glowMask in SetDefaults.
/// </summary>
/// <param name="modItem">The mod item to register. </param>
/// <returns></returns>
public static short SetStaticDefaultsGlowMask(ModItem modItem)
{
if (!Main.dedServ)
{
Texture2D[] glowMasks = new Texture2D[Main.glowMaskTexture.Length + 1];
for (int i = 0; i < Main.glowMaskTexture.Length; i++)
{
glowMasks[i] = Main.glowMaskTexture[i];
}
glowMasks[glowMasks.Length - 1] = mod.GetTexture("Glow/" + modItem.GetType().Name + "_Glow");
Main.glowMaskTexture = glowMasks;
return (short)(glowMasks.Length - 1);
}
else return 0;
}
/// <summary>
/// Handy dandy game method for implementating screen shake
/// </summary>
/// <param name="Transform"></param>
/// <returns></returns>
public override Microsoft.Xna.Framework.Matrix ModifyTransformMatrix(Microsoft.Xna.Framework.Matrix Transform)
{
if (!Main.gameMenu)
{
if (!Main.gamePaused)
{
shakeTick++;
if (shakeIntensity >= 0 && shakeTick >= 4) shakeIntensity--;
if (shakeIntensity > 10) shakeIntensity = 10;//cap it
if (shakeIntensity < 0) shakeIntensity = 0;
return Transform
* Microsoft.Xna.Framework.Matrix.CreateTranslation(
Main.rand.Next((int)(shakeIntensity * -0.5f), (int)(shakeIntensity * 0.5f + 1)),
Main.rand.Next((int)(shakeIntensity * -0.5f), (int)(shakeIntensity * 0.5f + 1)),
0f);
}
}
else
{
shakeIntensity = 0;
shakeTick = 0;
}
return Transform;
}
public override void PostDrawInterface(SpriteBatch spriteBatch)
{
try { DrawPumpkinMark(spriteBatch); } catch { }
DrawInterfaceDemonBloodHeart(spriteBatch);
DrawInterfaceWeaponOutToggleEye(spriteBatch);
if(ModConf.enableFists)
{
Main.LocalPlayer.meleeDamage += Main.LocalPlayer.GetModPlayer<PlayerFX>().PatienceBonus;
}
}
private void DrawPumpkinMark(SpriteBatch spriteBatch)
{
if (!ModConf.enableFists) return;
if (Main.gameMenu) return;
int buffID = BuffType<Buffs.PumpkinMark>();
Dictionary<Vector2, bool> drawPositions = new Dictionary<Vector2, bool>();
foreach (NPC i in Main.npc)
{
if (i.active && i.life > 0)
{ // Can crash here because of findIndex
int buffIndex = i.FindBuffIndex(buffID);
if (buffIndex >= 0)
{
drawPositions.Add(i.Center + new Vector2(0, i.gfxOffY), i.buffTime[buffIndex] < 120);
}
}
}
foreach (Player i in Main.player)
{
if (i.active && !i.dead && i.FindBuffIndex(buffID) >= 0)
{
drawPositions.Add(i.Center + new Vector2(0, i.gfxOffY), false);
}
}
if (drawPositions.Count > 0)
{
int frameHeight = pumpkinMark.Height / 3;
int frameY = 0;
int explodeFrameY = frameY;
if ((int)(Main.time / 6) % 2 == 0)
{ explodeFrameY = frameHeight; }
else
{ explodeFrameY = frameHeight * 2; }
if (ModPlayerFists.Get(Main.LocalPlayer).GetParryBuff() >= 0)
{
frameY = explodeFrameY;
}
spriteBatch.End();
//spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Main.GameViewMatrix.ZoomMatrix);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, null, null, null, Main.GameViewMatrix.ZoomMatrix);
foreach (KeyValuePair<Vector2, bool> kvp in drawPositions)
{
spriteBatch.Draw(pumpkinMark, (kvp.Key - Main.screenPosition),
new Rectangle(0, kvp.Value ? explodeFrameY : frameY, pumpkinMark.Width, frameHeight),
new Color(0.8f, 0.8f, 0.8f, 0.5f), 0f, new Vector2(pumpkinMark.Width / 2, frameHeight / 2),
1f, SpriteEffects.None, 0f);
}
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateScale(Main.UIScale, Main.UIScale, 1f));
}
}
private void DrawInterfaceDemonBloodHeart(SpriteBatch spriteBatch)
{
if (!ModConf.enableFists) return;
Player p = Main.LocalPlayer;
PlayerFX pfx = p.GetModPlayer<PlayerFX>();
if (pfx.demonBloodRally <= 0) return;
float lifePerHeart = Math.Max(20f, p.statLifeMax2 / 20f);
// 2 rows of 10
int numOfHearts = (int)Math.Min(20f, p.statLifeMax2 / lifePerHeart);
float rally = p.statLife + pfx.demonBloodRally;
bool firstHeart = !p.dead;
float currentHeartLife = 0;
int frame = 1;
int frameHeight = dHeart.Height / 2;
int heartOffsetHeight = Main.heartTexture.Height + (frameHeight - Main.heartTexture.Height) / 2;
int ScreenAnchorX = Main.screenWidth - 800;
Vector2 basePos = new Vector2(ScreenAnchorX + 500, 32);
// Two rows of 10 columns
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 10; x++)
{
if (numOfHearts <= 0) { break; } // Don't go over heart limit
numOfHearts--;
currentHeartLife = 1 + lifePerHeart * (x + 1) + lifePerHeart * 10 * y;
float hpNormal = 1f;
if (currentHeartLife <= p.statLife) continue; // Not at rally amonut yet
else if (currentHeartLife > rally + lifePerHeart) continue; // higher than rally amount
else if (currentHeartLife >= rally)
{
hpNormal = (rally + lifePerHeart - currentHeartLife) / lifePerHeart;
}
else if (currentHeartLife <= rally + lifePerHeart)
{
hpNormal = (rally - p.statLife) / lifePerHeart;
}
if (hpNormal <= 0f) continue;
if (hpNormal > 1f) hpNormal = 1f;
float alpha = hpNormal;
float size = 0.75f;
frame = 1;
if (firstHeart)
{
alpha = 0.25f + alpha * 0.75f;
float heartNormInverse = ((p.statLife - currentHeartLife) / -lifePerHeart);
size = Main.cursorScale - 0.25f * heartNormInverse;
frame = 0;
}
spriteBatch.Draw(dHeart,
basePos + new Vector2(
26 * x + Main.heartTexture.Width / 2,
26 * y + Main.heartTexture.Height
),
new Rectangle(0, frame * frameHeight, dHeart.Width, frameHeight - 1),
new Color(hpNormal, hpNormal, hpNormal, hpNormal),
0f,
new Vector2(dHeart.Width / 2, heartOffsetHeight),
size, SpriteEffects.None, 0);
firstHeart = false;
}
}
}
private void DrawInterfaceWeaponOutToggleEye(SpriteBatch spriteBatch)
{
// Janky quick inventory visibilty
if (!Main.playerInventory || !ModConf.showWeaponOut || ModConf.forceShowWeaponOut) return;
//Get vars
PlayerFX pfx = Main.LocalPlayer.GetModPlayer<PlayerFX>(this);
Texture2D eye = Main.inventoryTickOnTexture;
string hoverText = "Weapon " + Lang.inter[59]; // Visible
Vector2 position = new Vector2(20, 10);
// Show hidden instead
if (!pfx.weaponVisual)
{
eye = Main.inventoryTickOffTexture;
hoverText = "Weapon " + Lang.inter[60]; // Hidden
}
// Get rectangle for eye
Rectangle eyeRect = new Rectangle(
(int)position.X, (int)position.Y - (eye.Height / 2),
eye.Width, eye.Height);
if (eyeRect.Contains(Main.mouseX, Main.mouseY))
{
// Prevent item use and show text
Main.hoverItemName = hoverText;
Main.blockMouse = true;
// On click
if (Main.mouseLeft && Main.mouseLeftRelease)
{
Main.PlaySound(SoundID.MenuTick);
pfx.weaponVisual = !pfx.weaponVisual;
NetUpdateWeaponVisual(this, pfx);
}
}
// Draw this!
spriteBatch.Draw(
eye,
new Vector2(20, 4),
null,
Color.White
);
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
int code = reader.ReadInt32();
int sender = reader.ReadInt32();
#region Dash
if (code == 1) // Set dash used
{
HandlePacketDash(reader, code, sender);
}
#endregion
#region Parrying
if (code == 2) // Set parry move
{
HandlePacketParry(reader, code, sender);
}
#endregion
#region Weapon Visual
if (code == 3) // Set weapon
{
HandlePacketWeaponVisual(reader, code, sender);
}
#endregion
#region Combo Special
if (code == 4) // Set combo altfunction
{
HandlePacketCombo(reader, code, sender);
}
#endregion
}
public static void NetUpdateDash(ModPlayerFists mpf)
{
if (Main.netMode == 1 && mpf.player.whoAmI == Main.myPlayer)
{
//-/ Main.NewText("sent " + mpf.dashSpeed + "dash " + mpf.dashEffect + " from " + Main.myPlayer);
ModPacket message = mpf.mod.GetPacket();
message.Write(1);
message.Write(Main.myPlayer);
message.Write(mpf.dashSpeed);
message.Write(mpf.dashMaxSpeedThreshold);
message.Write(mpf.dashMaxFriction);
message.Write(mpf.dashMinFriction);
message.Write(mpf.dashEffect);
message.Send();
}
}
private void HandlePacketDash(BinaryReader reader, int code, int sender)
{
float dSpeed = reader.ReadSingle();
float dThreshold = reader.ReadSingle();
float dMax = reader.ReadSingle();
float dMin = reader.ReadSingle();
int dEffect = reader.ReadInt32();
if (Main.netMode == 2)
{
ModPacket me = GetPacket();
me.Write(code);
me.Write(sender);
me.Write(dSpeed);
me.Write(dThreshold);
me.Write(dMax);
me.Write(dMin);
me.Write(dEffect);
me.Send(-1, sender);
//-/ Console.WriteLine("echo " + dSpeed + " dash " + dEffect + " from " + sender);
}
else
{
ModPlayerFists pfx = Main.player[sender].GetModPlayer<ModPlayerFists>();
pfx.SetDash(dSpeed, dThreshold, dMax, dMin, true, dEffect);
}
}
public static void NetUpdateParry(ModPlayerFists pfx)
{
if (Main.netMode == 1 && pfx.player.whoAmI == Main.myPlayer)
{
//-/ Main.NewText("sent parry from " + Main.myPlayer);
ModPacket message = pfx.mod.GetPacket();
message.Write(2);
message.Write(Main.myPlayer);
message.Write(pfx.parryTimeMax);
message.Write(pfx.parryWindow);
message.Send();
}
}
private void HandlePacketParry(BinaryReader reader, int code, int sender)
{
int parryTimeMax = reader.ReadInt32();
int parryWindow = reader.ReadInt32();
if (Main.netMode == 2)
{
ModPacket me = GetPacket();
me.Write(code);
me.Write(sender);
me.Write(parryTimeMax);
me.Write(parryWindow);
me.Send(-1, sender);
//-/ Console.WriteLine("received parry from " + sender);
}
else
{
ModPlayerFists pfx = Main.player[sender].GetModPlayer<ModPlayerFists>(this);
pfx.AltFunctionParryMax(Main.player[sender], parryWindow, parryTimeMax);
//-/ Main.NewText("received parry from " + sender);
}
}
public static void NetUpdateCombo(ModPlayerFists pfx)
{
if (Main.netMode == 1 && pfx.player.whoAmI == Main.myPlayer)
{
//-/ Main.NewText("sent combo " + pfx.ComboEffectAbs + " from " + Main.myPlayer);
ModPacket message = pfx.mod.GetPacket();
message.Write(4);
message.Write(Main.myPlayer);
message.Write(pfx.ComboEffectAbs);
message.Send();
}
}
private void HandlePacketCombo(BinaryReader reader, int code, int sender)
{
int comboEffect = reader.ReadInt32();
if (Main.netMode == 2)
{
ModPacket me = GetPacket();
me.Write(code);
me.Write(sender);
me.Write(comboEffect);
me.Send(-1, sender);
//-/ Console.WriteLine("echo combo " + comboEffect + " from " + sender);
}
else
{
ModPlayerFists pfx = Main.player[sender].GetModPlayer<ModPlayerFists>(this);
pfx.player.itemAnimation = 0;
pfx.AltFunctionCombo(Main.player[sender], comboEffect, true);
//-/ Main.NewText("received combo " + comboEffect + " from " + sender);
}
}
public static void NetUpdateWeaponVisual(Mod mod, PlayerFX pfx)
{
if (Main.netMode == 1 && pfx.player.whoAmI == Main.myPlayer)
{
ModPacket message = mod.GetPacket();
message.Write(3);
message.Write(Main.myPlayer);
message.Write(pfx.weaponVisual);
message.Send();
}
}
private void HandlePacketWeaponVisual(BinaryReader reader, int code, int sender)
{
bool weaponVis = reader.ReadBoolean();
if (Main.netMode == 2)
{
ModPacket me = GetPacket();
me.Write(code);
me.Write(sender);
me.Write(weaponVis);
me.Send(-1, sender);
}
else
{
PlayerFX pfx = Main.player[sender].GetModPlayer<PlayerFX>(this);
pfx.weaponVisual = weaponVis;
}
}
public static Vector2 CalculateNormalAngle(Vector2 start, Vector2 end)
{
Vector2 diff = end - start;
diff.Normalize();
return diff;
}
}
}