forked from Flashkirby/WeaponOut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModPlayerFists.cs
More file actions
1780 lines (1577 loc) · 69.9 KB
/
ModPlayerFists.cs
File metadata and controls
1780 lines (1577 loc) · 69.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
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.Graphics.Shaders;
using Terraria.World.Generation;
using Terraria.Localization;
// using static WeaponOut.ProjFX;
// uses ReflectProjectilePlayer(Projectile projectile, Player player)
// using static WeaponOut.WeaponOut;
// NetUpdateDash()
// NetUpdateParry()
// NetUpdateCombo()
// Also requires in WeaponOut.WeaponOut:
// HandlePacketDash
// HandlePacketParry
// HandlePacketCombo
namespace WeaponOut
{
/// <summary>
/// Version 1.5.3 by Flashkirby99
/// This class provides almost all the methods required for fist type weapons.
/// </summary>
public class ModPlayerFists : ModPlayer
{
public override bool Autoload(ref string name)
{
ModTranslation text;
text = mod.CreateTranslation("WOFistComboPower");
text.SetDefault("$POWER combo power cost");
text.AddTranslation(GameCulture.Chinese, "$POWER 点连击能量消耗");
text.AddTranslation(GameCulture.Russian, "$POWER стоимость заряда комбо");
mod.AddTranslation(text);
text = mod.CreateTranslation("WOFistPrefixSize");
text.SetDefault("% combo cost");
text.AddTranslation(GameCulture.Chinese, "%连击能量消耗");
text.AddTranslation(GameCulture.Russian, "% стоимость комбо");
mod.AddTranslation(text);
return true;
}
private const bool DEBUG_FISTBOXES = false;
private const bool DEBUG_DASHFISTS = false;
private const bool DEBUG_PARRYFISTS = false;
public static ModPlayerFists Get(Player player)
{
return player.GetModPlayer<ModPlayerFists>();
}
private const bool DEBUG_COMBOFISTS = false;
public const int useStyle = 102115116; //http://www.unit-conversion.info/texttools/ascii/ with fst to ASCII numbers
public const int parryBuffTime = 300;
/// <summary> Default combo is held for 2 seconds. </summary>
public const int ComboResetTime = 2 * 60;
/// <summary> Flat combo time modifier </summary>
public int comboResetTimeBonus;
/// <summary> Colour for active combo counter </summary>
private static Color highColour = Color.Cyan;
/// <summary> Colour for inactive combo counter </summary>
private static Color lowColour = Color.DarkCyan;
/// <summary> Colour for combo tooltip </summary>
private static Color tooltipColour = Color.LightCyan;
private Color comboColour
{
get
{
if (IsComboActive) return highColour;
return lowColour;
}
}
/// <summary> Reset every hit, allows 1 combo bounce and invincibility during each punch. </summary>
bool allowComboBounce = false;
/// <summary>
/// The type of fist attack initiated.
/// 0 = Default (dash forward)
/// 1 = Uppercut (rising strike)
/// 2 = Dive (falling stomp)
/// </summary>
public int specialMove;
/// <summary> Allows uppercuts without staying grounded (requires air hits) </summary>
public bool jumpAgainUppercut = false;
/// <summary> Allows uppercuts with wingtime </summary>
public bool jumpWingUppercut = false;
public int jumpWingCost = 20;
/// <summary> Should normal punches bounce as usual? </summary>
private bool noBounce = false;
// Bonuses
public float uppercutDamage = 1f;
public float uppercutKnockback = 1.5f;
public float divekickDamage = 1f;
public float divekickKnockback = 1f;
public float parryLifesteal = 0f;
#region Combo Counter Vars
/// <summary> Keep track of the number of hits from fists. </summary>
protected int comboCounter;
protected int oldComboCounter;
public int ComboCounter { get { return comboCounter; } }
public int OldComboCounter { get { return oldComboCounter; } }
/// <summary> The "minimum" required combo get the bonus effects. Must be at least 2. </summary>
public int comboCounterMax;
/// <summary> Flat bonus to combo counter max. Typically negative. </summary>
public int comboCounterMaxBonus;
/// <summary> Flat bonus to combo counter max. Typically negative. </summary>
internal float comboCounterMaxScaleMod;
/// <summary> Time since last combo hit. </summary>
public int comboTimer;
/// <summary> Time until combo is reset. </summary>
public int comboTimerMax;
/// <summary> The real combo counter max, including bonus. </summary>
public int ComboCounterMaxReal { get { return Math.Max(2, (int)((comboCounterMax + comboCounterMaxBonus) * comboCounterMaxScaleMod)); } }
/// <summary> Active when combo counter reaches the combo max. </summary>
public bool IsComboActive { get { return comboCounter >= ComboCounterMaxReal && comboCounter > 1; } }
/// <summary> Active when combo counter reaches the combo max. Call this in the item because ItemLoader method is called before PlayerHooks. </summary>
public bool IsComboActiveItemOnHit { get { return comboCounter >= ComboCounterMaxReal - 1 && comboCounter > 0; } }
#endregion
#region Parry Vars
/// <summary> Ticks of current parry.
/// Non zero positive whilst in effect (count down), negative whilst on cooldown. </summary>
protected int parryTime;
/// <summary> Maximum time for current parry, used for swing animation. </summary>
public int parryTimeMax;
/// <summary> Number of active frames for the parry, also used for swing animation. </summary>
public int parryWindow;
/// <summary> Flat bonus on parry window. </summary>
public int parryWindowBonus;
public int ParryTimeMaxReal { get { return parryTimeMax + parryWindowBonus; } }
public int ParryWindowReal { get { return parryWindow + parryWindowBonus; } }
/// <summary> Frame that parry is active until. </summary>
public int ParryActiveFrame { get { return Math.Max(parryTimeMax - parryWindow, 2); } }
/// <summary> Active while parry time greater/equal to parry time </summary>
public bool IsParryActive { get { return parryTime >= ParryActiveFrame && parryTime > 0; } }
/// <summary> Provided by a buff, is the parry bonus active. </summary>
public bool parryBuff;
// Bonuses
public float parryDamage = 1f;
public bool longParry = false;
#endregion
#region Dash Vars
/// <summary> normally 20 but custom dash seems to end sooner for some reason </summary>
public const int dashCooldownDelay = 35;
/// <summary> The initial speed of a dash.
///<para /> * Normal: 3
///<para /> * Aglet/Anklet: 3.15, 3.3
///<para /> * Hermes: 6
///<para /> * Lightning: 6.75
///<para /> * Fishron Air: 8
///<para /> * Solar Wings: 9</summary>
public float dashSpeed;
/// <summary> The speed at which the dash will slow down towards. </summary>
public float dashMaxSpeedThreshold;
/// <summary> Friction applied when above the maxSpeed threshold. </summary>
public float dashMaxFriction;
/// <summary> Friction applied when below the maxSpeed threshold. </summary>
public float dashMinFriction;
/// <summary> ID for dash effect. Register these with RegisterDashEffect. Starts at 1 </summary>
public int dashEffect;
private static List<Action<Player, Item>> dashEffectsMethods;
/// <summary> Void method for dash effects. </summary>
protected static List<Action<Player, Item>> DashEffectsMethods
{
get
{
if (dashEffectsMethods == null) { dashEffectsMethods = new List<Action<Player, Item>>(); }
return dashEffectsMethods;
}
}
#endregion
#region Combo Special Vars
/// <summary> ID for combo effect. Register these with RegisterComboEffect. Uses negative as post initialised. </summary>
private int comboEffect;
public int ComboEffectAbs { get { return Math.Abs(comboEffect); } }
private static List<Action<Player, Item, bool>> comboEffectsMethods;
/// <summary> Void method for combo effects. </summary>
protected static List<Action<Player, Item, bool>> ComboEffectsMethods
{
get
{
if (comboEffectsMethods == null) { comboEffectsMethods = new List<Action<Player, Item, bool>>(); }
return comboEffectsMethods;
}
}
/// <summary> ID for combo effect. Register these with RegisterComboEffect. Starts at 1 </summary>
#endregion
#region overrides
public override void Initialize()
{
if (!ModConf.EnableFists) return;
specialMove = 0;
comboResetTimeBonus = 0;
comboCounter = 0;
oldComboCounter = 0;
comboCounterMax = 0;
comboCounterMaxBonus = 0;
comboCounterMaxScaleMod = 1f;
comboTimer = -1;
comboTimerMax = ComboResetTime + comboResetTimeBonus;
parryTime = 0;
parryTimeMax = 0;
parryWindow = 0;
parryWindowBonus = 0;
parryBuff = false;
comboEffect = 0;
ResetDashVars();
player.dashDelay = 0;
player.dash = 0;
}
public override void UpdateDead()
{
if (!ModConf.EnableFists) return;
this.Initialize();
}
public override void ResetEffects()
{
if (!ModConf.EnableFists) return;
oldComboCounter = comboCounter;
ResetVariables();
}
public override bool PreItemCheck()
{
if (!ModConf.EnableFists) return true;
// Main.NewText("cd = " + player.attackCD + " : " + noBounce);
// Don't use the item whilst a parry is in progress
if (ItemCheckParry())
{
return false;
}
// Reset comboEffect at the end of animation
ManageComboMethodCall();
// Make dashing effects hit everything it passes through
if (dashEffect != 0 || specialMove == 1 || noBounce)
{
player.attackCD = 0;
}
return true;
}
public override void PreUpdate()
{
if (!ModConf.EnableFists) return;
comboCounterMax = player.HeldItem.tileBoost;
comboCounterMaxScaleMod = Math.Max(0, 2 - player.HeldItem.scale);
// Jump again uppercut cannot be used from ground, only after attack resets
if (player.velocity.Y == 0)
{
// But upgraded fists can
Item i = new Item(); i.SetDefaults(player.HeldItem.type);
if (i.rare >= 4)
{ jumpAgainUppercut = true; }
else
{ jumpAgainUppercut = false; }
jumpWingUppercut = false;
}
// Reset dash here when grappling
if (player.pulley || player.grapCount > 0)
{
if (player.dashDelay == -1) player.dashDelay = dashCooldownDelay;
ResetDashVars();
}
if (specialMove == 2)
{
// Increase speed whilst diving
player.maxFallSpeed *= 1.5f;
}
}
public override void PostUpdate()
{
if (!ModConf.EnableFists) return;
// Set up parry frames
SetComboEffectLogic();
FistBodyFrame();
ParryBodyFrame();
ShowFistHandOn();
}
public override void PostUpdateRunSpeeds()
{
if (!ModConf.EnableFists) return;
CustomDashMovement();
}
public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
if (!ModConf.EnableFists) return true;
// All fists have a global damage reduction on projectiles, because they're all about closing
// in and doing big DPS. Due to the nature of the weapon, dodging projectiles is less important
// than positioning between the player and enemies. Therefore this defence buff is in place to
// reduce the pressure of projectiles on an already heavily stacked against usestyle.
if (player.HeldItem.useStyle == useStyle && damageSource.SourceProjectileIndex >= 0)
{ damage = (int)(damage * 0.75f); }
return !ParryPreHurt(damageSource, ref damage);
}
// This gets called last in the hook stack, after Item, then NPC
public override void ModifyHitNPC(Item item, NPC target, ref int damage, ref float knockback, ref bool crit)
{
if (!ModConf.EnableFists) return;
if (specialMove == 1) // Uppercut
{
damage = (int)(damage * uppercutDamage);
knockback *= uppercutKnockback;
}
else if (specialMove == 2) // Divekick
{
damage = (int)(damage * divekickDamage);
knockback *= divekickKnockback;
}
}
public override void ModifyHitPvp(Item item, Player target, ref int damage, ref bool crit)
{
if (!ModConf.EnableFists) return;
if (specialMove == 1)
{
damage = (int)(damage * uppercutDamage);
}
else if (specialMove == 2)
{
damage = (int)(damage * divekickDamage);
}
}
public override void OnHitNPC(Item item, NPC target, int damage, float knockback, bool crit)
{
if (!ModConf.EnableFists) return;
OnHitComboLogic(item, target);
}
#endregion
private void ShowFistHandOn()
{
if (player.itemAnimation > 0)
{
if (player.HeldItem.useStyle == useStyle)
{
if (player.HeldItem.handOnSlot > 0)
{
player.handon = player.HeldItem.handOnSlot;
player.cHandOn = 0;
}
if (player.HeldItem.handOffSlot > 0)
{
player.handoff = player.HeldItem.handOffSlot;
player.cHandOff = 0;
}
}
}
}
public void ResetVariables()
{
comboCounterMaxBonus = 0;
comboTimerMax = ComboResetTime + comboResetTimeBonus; // 2? seconds count
comboResetTimeBonus = 0; // reset
// Count up, otherwise reset to -1
if (comboTimer >= 0 && comboTimer < comboTimerMax) comboTimer++;
else
{
// Show the total number of hits, and disable count until next hit
if (comboTimer >= comboTimerMax)
{
if (comboCounter > 1)
{
CombatText.NewText(player.getRect(),
highColour, comboCounter + " hits", false, false);
}
comboCounter = 0;
comboTimer = -1;
}
}
// Reset special move when set to 0
if (player.itemAnimation <= (player.HeldItem.autoReuse ? 1 : 0))
{
specialMove = 0;
}
parryBuff = false;
parryDamage = 1f;
longParry = false;
uppercutDamage = 1f;
uppercutKnockback = 1.5f;
divekickDamage = 1f;
divekickKnockback = 1f;
parryLifesteal = 0f;
}
#region Fist Hitboxes
/// <summary>
/// Assign special moves, attack rotation and hitboxes, called in the ModItem
/// </summary>
/// <param name="distance">Pixels extended outwards</param>
/// <param name="jumpSpeed">Jump provided from uppercut. Default jump roughly 9-10</param>
/// <param name="fallSpeedXmod"></param>
/// <param name="fallSpeedY">Set dive Y speed, fall speed is auto increased by 1.5 (velY = 15)</param>
/// <returns></returns>
public static bool UseItemHitbox(Player player, ref Rectangle hitbox, int distance, float jumpSpeed = 9f, float fallSpeedXmod = 0.5f, float fallSpeedY = 8f, bool disableBounce = false)
{
ModPlayerFists mpf = player.GetModPlayer<ModPlayerFists>();
if (mpf == null) return false;
// Special attack assign on Start frame
if (player.itemAnimation == player.itemAnimationMax - 1)
{
mpf.allowComboBounce = true;
mpf.SetSpecialMove(player, jumpSpeed, fallSpeedXmod, fallSpeedY);
if (mpf.specialMove == 0)
{
SetAttackRotation(player);
}
if (Main.netMode == 1 && Main.myPlayer == player.whoAmI)
{
NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, player.whoAmI, 0f, 0f, 0f, 0, 0, 0);
NetMessage.SendData(MessageID.ItemAnimation, -1, -1, null, player.whoAmI, 0f, 0f, 0f, 0, 0, 0);
}
}
if (player.dashDelay >= 0)
{
mpf.noBounce = disableBounce;
}
return mpf.SetHitBox(player, out hitbox, distance);
}
private void SetSpecialMove(Player player, float jumpSpeed, float fallSpeedXmod, float fallSpeedY)
{
// Ground available counts includes the start of a jump
bool canUseGrounded = (player.velocity.Y == 0 && player.oldVelocity.Y == 0) || (player.jump > 0);
// Choose special move
if ((player.controlDown || player.controlUp)
&& canUseGrounded
&& jumpSpeed > 0)
{ // Uppercut from ground or start of jump
specialMove = 1;
}
else if (player.controlUp && !canUseGrounded &&
(jumpAgainUppercut ||
(jumpWingUppercut && player.wingTime > jumpWingCost)))
{ // Uppercut from jumpagain
specialMove = 1;
if(jumpAgainUppercut)
{
jumpAgainUppercut = false;
}
else
{
player.wingTime -= jumpWingCost;
}
}
else if (player.controlDown
&& fallSpeedXmod >= 0f)
{ // Divekick
specialMove = 2;
}
if (specialMove == 1 || specialMove == 2)
{
if (player.controlLeft && !player.controlRight)
{ player.direction = -1; }
if (player.controlRight && !player.controlLeft)
{ player.direction = 1; }
}
// Set uppercut jump
if (specialMove == 1)
{
player.itemRotation = -(float)(player.direction * Math.PI / 2);
player.velocity.Y = -jumpSpeed * player.gravDir;
player.jump = 0;
player.fallStart = (int)(player.position.Y / 16f); // Reset fall
}
// Set dive trajectory
else if (specialMove == 2)
{
player.itemRotation = (float)(player.direction * Math.PI / 2);
player.velocity.X *= fallSpeedXmod;
if (player.gravDir > 0)
{
if (player.velocity.Y < fallSpeedY) player.velocity.Y = fallSpeedY;
}
else
{
if (player.velocity.Y > -fallSpeedY) player.velocity.Y = -fallSpeedY;
}
player.jump = 0;
}
}
private static void SetAttackRotation(Player player)
{
// Get rotation at use
if (Main.myPlayer == player.whoAmI)
{
Vector2 vector2 = player.RotatedRelativePoint(player.MountedCenter, true);
Vector2 value = Vector2.UnitX.RotatedBy((double)player.fullRotation, default(Vector2));
float num79 = (float)Main.mouseX + Main.screenPosition.X - vector2.X;
float num80 = (float)Main.mouseY + Main.screenPosition.Y - vector2.Y;
if (player.gravDir == -1f)
{
num80 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector2.Y;
}
player.itemRotation = (float)Math.Atan2((double)(num80 * (float)player.direction), (double)(num79 * (float)player.direction)) - player.fullRotation;
}
if (Math.Abs(player.itemRotation) > Math.PI / 2) //swapping then doing it again because lazy and can't be bothered to find in code
{
player.direction *= -1;
if (Main.myPlayer == player.whoAmI)
{
Vector2 vector2 = player.RotatedRelativePoint(player.MountedCenter, true);
Vector2 value = Vector2.UnitX.RotatedBy((double)player.fullRotation, default(Vector2));
float num79 = (float)Main.mouseX + Main.screenPosition.X - vector2.X;
float num80 = (float)Main.mouseY + Main.screenPosition.Y - vector2.Y;
if (player.gravDir == -1f)
{
num80 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector2.Y;
}
player.itemRotation = (float)Math.Atan2((double)(num80 * (float)player.direction), (double)(num79 * (float)player.direction)) - player.fullRotation;
}
}
}
private bool SetHitBox(Player player, out Rectangle hitbox, int distance)
{
// Animation normal
float anim = player.itemAnimation / (float)player.itemAnimationMax;
hitbox = new Rectangle();
// If set above the max, no hitbox yet (see combo attacks)
if (player.itemAnimation > player.itemAnimationMax) return false;
if (specialMove == 0)
{
// Calculate hitbox for normal punch
#region Standard Punch
if (anim > 0.15f)
{
// Start as player hitbox
if (anim > 0.7f)
{
// Provide immunity for 1/3
provideImmunity(player);
hitbox = player.getRect();
hitbox.X += (int)player.velocity.X;
hitbox.Y += (int)player.velocity.Y;
}
// Move to pointed direction
else
{
// Size an extension of the player
hitbox.Width = Player.defaultWidth;
hitbox.Height = Player.defaultHeight;
// Work out which way to go
float xDir = player.direction;
float yDir = 1f;
if (Math.Abs(player.itemRotation) > Math.PI / 4 && Math.Abs(player.itemRotation) < 3 * Math.PI / 4)
{
xDir /= 2;
if (player.itemRotation * player.direction > 0)
{
// Up high
yDir *= 1f;
}
else
{
// Down low
yDir *= -1f;
}
}
else
{
// Too slow
yDir = 0;
hitbox.Height += Math.Max(0, distance - Player.defaultHeight);
}
hitbox.Width += (int)(Math.Abs(xDir) * distance);
hitbox.Height += (int)(Math.Abs(yDir) * distance);
hitbox.Location = (player.MountedCenter + new Vector2(
-hitbox.Width + xDir * distance,
-hitbox.Height + yDir * distance
) / 2).ToPoint();
}
}
else
{
// No hitbox during last third
return false;
}
#endregion
}
else
{
// Calculate hitbox for rising/falling
#region Special Attack
if (anim > 0.2f)
{
// Provide immunity for 2/3
provideImmunity(player);
// Size is relative to distance past default size
hitbox.Width = Player.defaultWidth + distance;
hitbox.Height = Player.defaultHeight + distance;
Vector2 centreLeft = new Vector2(player.position.X, player.MountedCenter.Y);
// Work out which way to go
if (player.direction < 0)
{
hitbox.Location = (centreLeft - new Vector2(
distance,
hitbox.Height / 2f)).ToPoint();
}
else
{
hitbox.Location = (centreLeft - new Vector2(
0,
hitbox.Height / 2f)).ToPoint();
}
}
else
{
// No hitbox during last bit
return false;
}
#endregion
}
if (DEBUG_FISTBOXES)
{
Dust.NewDustPerfect(hitbox.TopLeft(), 213);
Dust.NewDustPerfect(hitbox.TopRight(), 213);
Dust.NewDustPerfect(hitbox.BottomLeft(), 213);
Dust.NewDustPerfect(hitbox.BottomRight(), 213);
}
return true;
}
#endregion
#region Fist Combo Logic
private void OnHitComboLogic(Item item, NPC target)
{
// Fist Items only
if (item.useStyle != useStyle) return;
// Add up that combo, reset timer, Display the combo counter, lower if not combo active
// Combo specials don't grant more combo
if (comboEffect == 0) ModifyComboCounter(1, true);
// Manage player bump
if (DEBUG_DASHFISTS) Main.NewText(string.Concat("COmbo dash: ", dashEffect, " - alt: ", player.altFunctionUse));
if (dashEffect == 0 && comboEffect == 0 && (allowComboBounce || specialMove == 2))
{
ManagePlayerComboMovement(target);
}
else if (dashEffect != 0)
{
// Dash attacks provide a short immunity
if (allowComboBounce)
{
provideImmunity(player, 20);
}
}
else
{
// Combo specials provide immunity over duration
if (allowComboBounce)
{
provideImmunity(player, player.itemAnimation + 1);
}
}
allowComboBounce = false;
// Set time to match, to sync up projectiles
player.itemTime = player.itemAnimation;
}
public void ModifyComboCounter(int amount, bool resetTimer = true)
{
comboCounter += amount;
if (comboCounter == ComboCounterMaxReal) ItemFlashFX();
if (resetTimer) comboTimer = 0;
// Don't bother showing spent combo
if (comboCounter <= 0) return;
Rectangle rect = player.getRect();
if (ComboCounterMaxReal == 0) return; // avoid div by 0
bool comboMatchMax = comboCounter % ComboCounterMaxReal == 0;
if (!comboMatchMax) rect.Y += (int)(rect.Height * player.gravDir * 1f);
CombatText.NewText(rect,
comboColour, comboCounter, comboMatchMax, !IsComboActive || !comboMatchMax);
}
private void ManagePlayerComboMovement(NPC target)
{
if (noBounce)
{
provideImmunity(player, 20);
return;
}
if (target.aiStyle == 28) // WOF eye follows head position
{ target = Main.npc[Main.wof]; }
Vector2 cappedVelocity = target.velocity;
if (target.aiStyle == 27)
{
// Keep normal "velocity" since WoF doesn't update old position for some reason.
}
else if (target.knockBackResist == 0f ||
(cappedVelocity.X == 0 && cappedVelocity.Y == 0))
{
cappedVelocity = target.position - target.oldPosition;
}
// Double knockback if target is moving towards player
if ((player.direction < 0f && cappedVelocity.X > 0f) ||
(player.direction > 0f && cappedVelocity.X < 0f))
{ cappedVelocity.X *= 2f; }
cappedVelocity = new Vector2(
Math.Min(8f + player.accRunSpeed, Math.Max(-8f - player.accRunSpeed, cappedVelocity.X)),
Math.Min(8f + player.accRunSpeed, Math.Max(-8f - player.accRunSpeed, cappedVelocity.Y)));
if (target.velocity.X == 0f && target.velocity.Y == 0f)
{
cappedVelocity = new Vector2(
Math.Min(10f, Math.Max(-10f, (target.oldPosition.X - target.position.X) * 1.5f)),
Math.Min(10f, Math.Max(-10f, target.oldPosition.Y - target.position.Y)));
}
if (specialMove != 1)
{
// Punches and stomps reset uppercut
jumpAgainUppercut = true;
}
if (specialMove == 0)
{
#region Normal Punch
// Allow punches to be combo'd together quickly by reducing time between attacks
player.itemAnimation = 2 * player.itemAnimation / 3;
provideImmunity(player, player.itemAnimationMax / 2);
// Check if NPC is in air
bool aerial = target.noGravity;
Point origin = target.Center.ToTileCoordinates();
Point point;
if (!aerial && !WorldUtils.Find(origin, Searches.Chain(new Searches.Down(4), new GenCondition[]
{
new Conditions.IsSolid()
}), out point))
{
aerial = true;
}
// Partially follow the target if it's in the air
if (aerial)
{
player.velocity = cappedVelocity;
player.velocity.X -= player.direction * 3f + player.direction * player.HeldItem.knockBack * 0.1f; // Some bounce off
player.velocity.Y -= player.gravDir * 0.125f * player.itemAnimationMax; // Try to preserve Y velo, based on attack speed (claws do less, fists do more)
player.fallStart = (int)(player.position.Y / 16f); // Reset fall
}
else
{
// Bounce off
player.velocity = new Vector2(
-player.direction * (2f + player.HeldItem.knockBack * 0.5f) + cappedVelocity.X * 0.5f,
cappedVelocity.Y * 1.5f * target.knockBackResist);
player.fallStart = (int)(player.position.Y / 16f); // Reset fall
}
#endregion
}
else if (specialMove == 1)
{
// Uppercut grants full immunity for rest of uppercut but no bounces etc.
provideImmunity(player, player.itemAnimation - 1);
}
else if (specialMove == 2)
{
#region Divekick
// Grant mostly invulnerable divekicks on hit
provideImmunity(player, player.itemAnimation - 1);
// Bounce off
int direction = 1;
if (player.Center.X < target.Center.X) direction = -1;
float bounceY = player.gravDir * -2f + Math.Min(0, cappedVelocity.Y * 1.5f);
player.velocity = new Vector2(direction * 4f, bounceY);
// Reset fall and restore jumps
player.wingTime = (float)player.wingTimeMax;
player.rocketTime = Math.Max(player.rocketTime, player.rocketTimeMax);
player.rocketDelay = 0;
player.fallStart = (int)(player.position.Y / 16f);
player.jumpAgainCloud = player.doubleJumpCloud;
player.jumpAgainSandstorm = player.doubleJumpSandstorm;
player.jumpAgainBlizzard = player.doubleJumpBlizzard;
player.jumpAgainFart = player.jumpAgainBlizzard;
player.jumpAgainSail = player.doubleJumpSail;
player.jumpAgainUnicorn = player.doubleJumpUnicorn;
#endregion
}
// Combo hits reset dash
ResetDashVars();
player.dashDelay = 0;
player.dash = 0;
}
private void FistBodyFrame()
{
// Don't show when not attacking
if (player.itemAnimation == 0) return;
// Don't apply to non fists
if (player.HeldItem.useStyle != useStyle) return;
// Animation normal
float anim = player.itemAnimation / (float)player.itemAnimationMax;
if (specialMove == 0)
{
#region Normal Punch
//wind up animation
if (anim > 0.7f) player.bodyFrame.Y = player.bodyFrame.Height * 10;
else if (anim > 0.66f)
{
player.bodyFrame.Y = player.bodyFrame.Height * 17;
}
//punch
else if (anim > 0.3f)
{
if (Math.Abs(player.itemRotation) > Math.PI / 4 && Math.Abs(player.itemRotation) < 3 * Math.PI / 4)
{
if (player.itemRotation * player.direction * player.gravDir > 0)
{
//Down low
player.bodyFrame.Y = player.bodyFrame.Height * 4;
}
else
{
//Up high
player.bodyFrame.Y = player.bodyFrame.Height * 2;
}
}
else
{
//along the middle
player.bodyFrame.Y = player.bodyFrame.Height * 3;
}
}
//wind back
else player.bodyFrame.Y = player.bodyFrame.Height * 17;
#endregion
}
else
{
#region Special
// Uppercut
if (specialMove == 1)
{
if (anim > 0.8)
{
player.bodyFrame.Y = player.bodyFrame.Height * 4;
}
else if (anim > 0.6)
{
player.bodyFrame.Y = player.bodyFrame.Height * 3;
}
else if (anim > 0.2)
{
player.bodyFrame.Y = player.bodyFrame.Height * 2;
}
else
{
player.bodyFrame.Y = player.bodyFrame.Height * 17;
}
}
// Dive
else if (specialMove == 2)
{
if (anim > 0.6)
{
player.bodyFrame.Y = player.bodyFrame.Height * 1;
}
else if (anim > 0.5)
{
player.bodyFrame.Y = player.bodyFrame.Height * 17;
}
else if (anim > 0.1)
{
player.bodyFrame.Y = player.bodyFrame.Height * 4;
}
else
{
player.bodyFrame.Y = player.bodyFrame.Height * 6;
}
}
#endregion
}
}
#endregion
#region Fist Item Methods
public static void ModifyTooltips(List<TooltipLine> tooltips, Item item)
{
// Fist Items only
if (item.useStyle == useStyle)
{
int index = 0;
foreach (TooltipLine tooltip in tooltips)
{
if (tooltip.Name.Equals("TileBoost")) break;
index++;
}
int comboPower = item.tileBoost;
int comboBonus = Main.LocalPlayer.GetModPlayer<ModPlayerFists>().comboCounterMaxBonus;
float comboMod = Math.Max(0, 2 - item.scale);
int comboTotal = (int)((comboPower + comboBonus) * comboMod);
tooltips.RemoveAt(index);
TooltipLine tt = new TooltipLine(item.modItem.mod, "FistComboPower",
WeaponOut.GetTranslationTextValue("WOFistComboPower").Replace
("$POWER", "" + Math.Max(2, comboTotal)));
tt.overrideColor = tooltipColour;
tooltips.Insert(index, tt);
if(item.scale != 1f) {
TooltipLine PrefixSize;
foreach (TooltipLine tooltip in tooltips) {
if (tooltip.Name.Equals("PrefixSize")) {
PrefixSize = tooltip;