forked from GabeHasWon/VerdantMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerdantPlayer.cs
222 lines (187 loc) · 8.84 KB
/
VerdantPlayer.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
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Verdant.Backgrounds.BGItem;
using Verdant.Backgrounds.BGItem.Verdant;
using Verdant.Systems.Foreground;
using Verdant.Systems.Foreground.Parallax;
using Verdant.Items.Verdant.Equipables;
using Verdant.Tiles;
using Verdant.Tiles.Verdant.Basic.Blocks;
using Verdant.Tiles.Verdant.Basic.Plants;
using Verdant.Systems.ScreenText.Caches;
using Verdant.Scenes;
using Terraria.ID;
namespace Verdant;
class VerdantPlayer : ModPlayer
{
public bool ZoneVerdant => Player.InModBiome<VerdantBiome>() || Player.InModBiome<VerdantUndergroundBiome>();
public bool ZoneApotheosis => Player.InModBiome<NearApotheosisBiome>();
public bool heartOfGrowth = false;
public bool crystalHeart = false;
public bool expertPlantGuide = false;
public bool sproutBoots = false;
public float lastSlotsMinion = 0;
public delegate void FloorVisual(Player p, int type);
public static event FloorVisual FloorVisualEvent;
public delegate void ItemDrawLayer(PlayerDrawSet info);
public static event ItemDrawLayer ItemDrawLayerEvent;
public delegate void DoOnRespawn(Player p);
public static event DoOnRespawn OnRespawnEvent;
public delegate void HitByNPC(Player p, NPC npc, Player.HurtInfo hurtInfo);
public static event HitByNPC HitByNPCEvent;
public delegate void PreUpdateDelegate(Player p);
public static event PreUpdateDelegate PreUpdateEvent;
public override void ResetEffects()
{
if (heartOfGrowth) //perm bonus
Player.GetDamage(DamageClass.Summon) += 0.05f;
if (crystalHeart) //also a perm bonus
{
Player.buffImmune[BuffID.Poisoned] = true;
Player.buffImmune[BuffID.Venom] = true;
Player.buffImmune[BuffID.Bleeding] = true;
Player.buffImmune[BuffID.Confused] = true;
Player.buffImmune[BuffID.Cursed] = true;
Player.buffImmune[BuffID.Suffocation] = true;
}
sproutBoots = false;
expertPlantGuide = false;
}
public override void SaveData(TagCompound tag)
{
tag.Add(nameof(heartOfGrowth), heartOfGrowth);
tag.Add(nameof(crystalHeart), crystalHeart);
}
public override void LoadData(TagCompound tag)
{
heartOfGrowth = tag.GetBool(nameof(heartOfGrowth));
crystalHeart = tag.GetBool(nameof(crystalHeart));
}
public override void Unload()
{
FloorVisualEvent = null;
ItemDrawLayerEvent = null;
HitByNPCEvent = null;
OnRespawnEvent = null;
PreUpdateEvent = null;
}
public override void OnRespawn() => OnRespawnEvent?.Invoke(Player);
public override void PreUpdate()
{
PreUpdateEvent?.Invoke(Player);
//bootleg floor effects
Point left = Player.TileCoordsBottomLeft();
Point right = Player.TileCoordsBottomRight();
if (Player.whoAmI == Main.myPlayer && Player.velocity.Y >= 0 && (TileHelper.SolidTopTile(left.X, left.Y) || TileHelper.SolidTopTile(right.X, right.Y)))
TileFloor(left, right, Framing.GetTileSafely(left.X, left.Y).TileType, Framing.GetTileSafely(right.X, right.Y).TileType);
if (Player.HeldItem.type == ModContent.ItemType<Items.Verdant.Tools.BouncebloomItem>())
{
if (!Player.controlDown)
Player.maxFallSpeed *= 0.4f;
}
if (Main.hasFocus)
AddForegroundOrBackground();
}
public override void PostUpdate()
{
if (sproutBoots && Player.armor[2].ModItem is SproutInABoot sprout)
{
int water = sprout.GetWater();
if (water <= SproutInABoot.MaxWater * 0.66667f && water > SproutInABoot.MaxWater * 0.33333f)
Player.legs = EquipLoader.GetEquipSlot(Mod, nameof(SproutInABoot) + "_Legs_2", EquipType.Legs);
else if (water <= SproutInABoot.MaxWater * 0.33333f)
Player.legs = EquipLoader.GetEquipSlot(Mod, nameof(SproutInABoot) + "_Legs_3", EquipType.Legs);
}
}
public override void PostUpdateMiscEffects()
{
lastSlotsMinion = Player.slotsMinions;
if (ZoneVerdant && Player.Center.Y / 16f > Main.worldSurface && !ModContent.GetInstance<VerdantSystem>().apotheosisIntro)
DialogueCacheAutoloader.SyncPlay(nameof(ApotheosisDialogueCache) + ".Intro");
}
private void TileFloor(Point left, Point right, int lType, int rType)
{
bool lValid = lType == ModContent.TileType<Bouncebloom>() && TileHelper.SolidTopTile(left.X, left.Y);
bool rValid = rType == ModContent.TileType<Bouncebloom>() && TileHelper.SolidTopTile(right.X, right.Y);
if (lValid || rValid)
{
float newVel = -10f;
if (Player.controlJump) //Bigger jump if jumping
newVel = -13.5f;
if (Player.controlDown) //NO jump if holding down
return;
Player.velocity.Y = newVel;
Player.fallStart = (int)(Player.Center.Y / 16f);
int offsetX = 0;
int offsetY = 0;
if (lValid)
{
offsetX = left.X - Framing.GetTileSafely(left.X, left.Y).TileFrameX / 18;
offsetY = left.Y - Framing.GetTileSafely(left.X, left.Y).TileFrameY / 18;
}
else if (rValid)
{
offsetX = right.X - Framing.GetTileSafely(right.X, right.Y).TileFrameX / 18;
offsetY = right.Y - Framing.GetTileSafely(right.X, right.Y).TileFrameY / 18;
}
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 2; ++j)
{
if (Main.rand.Next(5) <= 3 && j == 0)
{
int type = Main.rand.NextBool(2) ? Mod.Find<ModGore>("RedPetalFalling").Type : Mod.Find<ModGore>("LushLeaf").Type;
Gore.NewGore(Player.GetSource_TileInteraction(offsetX + i, offsetY + j), (new Vector2(offsetX + i, offsetY + j) * 16) + new Vector2(Main.rand.Next(18), Main.rand.Next(18)), Vector2.Zero, type);
}
}
}
}
}
public override void PreUpdateMovement()
{
if (Player.velocity.Y > Player.gravity * 6 && Collision.SolidCollision(Player.BottomLeft + Player.velocity + new Vector2(2, 0), Player.width - 4, 6) && !Collision.SolidCollision(Player.BottomLeft, Player.width, 6))
{
Point tPos = new Point((int)(Player.Center.X / 16f), Helper.FindDown(Player.Bottom));
if (Player.GetFloorTileType(tPos.X, tPos.Y) == ModContent.TileType<VerdantGrassLeaves>())
VerdantGrassLeaves.ImpactEffects(Player);
}
}
private void AddForegroundOrBackground()
{
if (Player.GetModPlayer<VerdantPlayer>().ZoneVerdant) //Spawn BG items only when in the Verdant and above ground
{
if ((Player.Center.Y + Main.screenHeight / 2f) / 16f < Main.worldSurface)
{
if (Main.rand.NextBool(FlotieBG.SpawnChance))
{
Vector2 pos = Player.Center - new Vector2(Main.rand.Next(-(int)(Main.screenWidth * 0.75f), (int)(Main.screenWidth * 0.75f)),
Main.rand.Next(-(int)(Main.screenWidth * 0.75f), (int)(Main.screenWidth * 0.75f)));
BackgroundItemManager.AddItem(new FlotieBG(pos));
}
if (Main.raining && Main.rand.NextBool(LushLeafBG.SpawnChance))
{
Vector2 pos = Player.Center - new Vector2(Main.rand.Next(-(int)(Main.screenWidth * 1.1f), (int)(Main.screenWidth * 1.1f)), Main.screenHeight * 0.9f);
BackgroundItemManager.AddItem(new LushLeafBG(pos));
}
}
int leafFGChance = LushLeafFG.SpawnChance(Player);
if (leafFGChance != -1 && Main.rand.NextBool(leafFGChance))
{
Vector2 pos = Player.Center - new Vector2(Main.rand.Next(-(int)(Main.screenWidth * 2f), (int)(Main.screenWidth * 2f)), Main.screenHeight * 0.52f);
ForegroundManager.AddItem(new LushLeafFG(pos));
}
}
if (Player.GetModPlayer<VerdantPlayer>().ZoneApotheosis && (Main.dayTime || Player.position.Y / 16 > Main.worldSurface))
{
Vector2 pos = Player.Center - new Vector2(Main.rand.Next(-Main.screenWidth, Main.screenWidth),
Main.rand.Next(-(int)(Main.screenHeight * 2f), (int)(Main.screenHeight * 2f)));
ForegroundManager.AddItem(new ApotheosisParticle(pos));
}
}
public void FloorVisuals(Player p, int t) => FloorVisualEvent?.Invoke(p, t);
public override void OnHitByNPC(NPC npc, Player.HurtInfo hurtInfo) => HitByNPCEvent?.Invoke(Player, npc, hurtInfo);
public void InvokeDrawLayer(PlayerDrawSet set) => ItemDrawLayerEvent?.Invoke(set);
}