forked from GabeHasWon/VerdantMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VinePulleyPlayer.cs
127 lines (104 loc) · 4.27 KB
/
VinePulleyPlayer.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
using Microsoft.Xna.Framework;
using System;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
using Verdant.Systems.Foreground;
using Verdant.Systems.Foreground.Parallax;
using Verdant.Projectiles.Misc;
namespace Verdant
{
public class VinePulleyPlayer : ModPlayer
{
public const int MaxVineResource = 80;
public int vineTimer = 0;
public float vineOffset = 0;
public int vineResource = 0;
public int vineRegenCooldown = 0;
public EnchantedVine CurrentVine = null;
public override void ResetEffects()
{
if (vineRegenCooldown-- < 0 && vineRegenCooldown % 5 == 0 && vineResource < MaxVineResource)
vineResource++;
}
public int VineCount() => Main.projectile.Where(x => x.active && x.owner == Player.whoAmI && x.type == ModContent.ProjectileType<VineWandVine>()).Count();
public override void PreUpdateMovement()
{
const float ClimbSpeed = 0.5f;
vineTimer--;
if (CurrentVine is not null)
{
if (CurrentVine.lifeTimer < 5 || CurrentVine.killMe || Player.dead || Player.DistanceSQ(CurrentVine.Center) > 80 * 80)
{
CurrentVine = null;
return;
}
Player.velocity = Vector2.Zero;
CurrentVine.PulleyVelocity(Player);
Player.fallStart = (int)(CurrentVine.position.Y / 16f);
Player.pulley = true;
Player.pulleyDir = 0;
if (Player.velocity.X != 0)
{
Player.ChangeDir(Math.Sign(Player.velocity.X));
Player.pulleyFrameCounter++;
if (Player.pulleyFrameCounter % 10 == 0)
Player.pulleyFrame = Player.pulleyFrame == 0 ? 1 : 0;
}
if (!Player.controlDown && !Player.controlUp)
Player.velocity *= 0.9f;
if (Player.controlJump)
{
Player.pulley = false;
Player.pulleyFrame = (int)(Main.GameUpdateCount / 4) % 2;
Player.velocity.Y -= 6;
CurrentVine = null;
vineTimer = 0;
return;
}
else if (Player.controlUp && !CurrentVine.InvalidVine(false))
{
vineOffset -= Player.velocity.Length();
if (Collision.SolidCollision(Player.position, Player.width, Player.height))
vineOffset += ClimbSpeed;
if (vineOffset < 0 && vineTimer < 0)
{
CurrentVine = CurrentVine.NextVine;
vineTimer = 2;
vineOffset = 1;
}
}
else if (Player.controlDown && !CurrentVine.InvalidVine(true))
{
vineOffset += Player.velocity.Length();
if (Collision.SolidCollision(Player.position, Player.width, Player.height))
vineOffset -= ClimbSpeed;
if (vineOffset > 1 && vineTimer < 0)
{
CurrentVine = CurrentVine.PriorVine;
vineTimer = 2;
vineOffset = 0;
}
}
}
}
public static void Player_QuickMount(On.Terraria.Player.orig_QuickMount orig, Player self)
{
if (self.GetModPlayer<VinePulleyPlayer>().CurrentVine != null)
{
self.GetModPlayer<VinePulleyPlayer>().CurrentVine = null;
self.GetModPlayer<VinePulleyPlayer>().vineTimer = 0;
}
orig(self);
}
public static void Player_Teleport(On.Terraria.Player.orig_Teleport orig, Player self, Vector2 newPos, int Style, int extraInfo)
{
if (self.GetModPlayer<VinePulleyPlayer>().CurrentVine != null)
{
self.GetModPlayer<VinePulleyPlayer>().CurrentVine = null;
self.GetModPlayer<VinePulleyPlayer>().vineTimer = 0;
}
orig(self, newPos, Style, extraInfo);
}
}
}