forked from GabeHasWon/spritersguildwip
/
ShieldHandler.cs
190 lines (165 loc) · 7.77 KB
/
ShieldHandler.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
namespace StarlightRiver
{
class ShieldHandler : GlobalNPC
{
public int MaxShield;
public int Shield;
public int MaxRed;
public int Red;
public override bool InstancePerEntity => true;
public override void OnHitByProjectile(NPC npc, Projectile projectile, int damage, float knockback, bool crit)
{
if (Shield > 0)
{
for (int k = 0; k <= 10; k++)
{
Dust.NewDustPerfect(npc.Center, ModContent.DustType<Dusts.Starlight>(), Vector2.Normalize(npc.Center - projectile.Center).RotatedByRandom(1.1f) * Main.rand.NextFloat(20), 0, default, 0.6f);
}
Shield -= damage * 2 / (projectile.GetGlobalProjectile<ShieldBreakingProjectile>().Piercing ? 5 : 10);
if (Shield <= 0)
{
Main.PlaySound(SoundID.NPCDeath37, npc.Center);
for (int k = 0; k <= 30; k++)
{
Dust.NewDustPerfect(npc.Center, ModContent.DustType<Dusts.Starlight>(), Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(25));
}
}
CombatText.NewText(new Rectangle((int)npc.position.X, (int)npc.position.Y + 12, npc.width, 0), new Color(60, 220, 255),
damage * 2 / (projectile.GetGlobalProjectile<ShieldBreakingProjectile>().Piercing ? 5 : 10));
Main.PlaySound(SoundID.NPCHit34, npc.Center);
}
if(Red > 0 && projectile.GetGlobalProjectile<ShieldBreakingProjectile>().RedHurting)
{
Red -= projectile.damage * 2;
CombatText.NewText(npc.Hitbox, new Color(250, 100, 100), projectile.damage * 2);
}
}
public override void OnHitByItem(NPC npc, Player player, Item item, int damage, float knockback, bool crit)
{
if (Shield > 0)
{
for (int k = 0; k <= 10; k++)
{
Dust.NewDustPerfect(npc.Center, ModContent.DustType<Dusts.Starlight>(), Vector2.Normalize(npc.Center - player.Center).RotatedByRandom(1.1f) * Main.rand.NextFloat(20), 0, default, 0.6f);
}
Shield -= damage * 2 / (item.GetGlobalItem<ShieldBreakingItem>().Piercing ? 5 : 10);
if (Shield <= 0)
{
Main.PlaySound(SoundID.NPCDeath37, npc.Center);
for (int k = 0; k <= 30; k++)
{
Dust.NewDustPerfect(npc.Center, ModContent.DustType<Dusts.Starlight>(), Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(25));
}
}
CombatText.NewText(new Rectangle((int)npc.position.X, (int)npc.position.Y + 12, npc.width, 0), new Color(60, 220, 255),
damage * 2 / (item.GetGlobalItem<ShieldBreakingItem>().Piercing ? 5 : 10));
Main.PlaySound(SoundID.NPCHit34, npc.Center);
}
if (Red > 0 && item.GetGlobalItem<ShieldBreakingItem>().RedHurting)
{
Red -= item.damage * 2;
CombatText.NewText(npc.Hitbox, new Color(250, 100, 100), item.damage * 2);
}
}
public override bool StrikeNPC(NPC npc, ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit)
{
if (Shield > 0)
{
damage *= (Main.expertMode) ? 0.3f : 0.5f;
}
if (Red > 0)
{
damage *= 0;
return false;
}
return true;
}
public override void PostAI(NPC npc)
{
if (Shield > MaxShield) Shield = MaxShield;
if (Shield < 0) Shield = 0;
if (Red > MaxRed) Red = MaxRed;
if (Red < 0) Red = 0;
}
public override void PostDraw(NPC npc, SpriteBatch spriteBatch, Color drawColor)
{
if (Shield > 0 && npc.modNPC != null)
{
Vector2 drawpos = npc.Center - Main.screenPosition;
Texture2D tex = ModContent.GetTexture(npc.modNPC.Texture);
spriteBatch.Draw(tex, drawpos, npc.frame, new Color(80, 230, 255) * (0.5f + (float)Math.Sin(LegendWorld.rottime * 2) * 0.2f),
npc.rotation, npc.Size / 2, npc.scale + 0.1f + (float)Math.Sin(LegendWorld.rottime * 4) * 0.05f, 0, 0);
}
base.PostDraw(npc, spriteBatch, drawColor);
}
public override bool? DrawHealthBar(NPC npc, byte hbPosition, ref float scale, ref Vector2 position)
{
SpriteBatch spriteBatch = Main.spriteBatch;
Vector2 drawpos = position - Main.screenPosition;
Color color = new Color(60, 50 + (int)(Shield / (float)MaxShield * 170f), 255 );
if (Shield > 0)
{
Rectangle target = new Rectangle((int)drawpos.X - 16, (int)drawpos.Y + 12, 34, 6);
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/ShieldBar0"), target, color * Lighting.Brightness((int)npc.position.X / 16, (int)npc.position.Y / 16));
Rectangle target2 = new Rectangle((int)drawpos.X - 17, (int)drawpos.Y + 10, (int)(Shield/(float)MaxShield * 36f), 10);
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/ShieldBar1"), target2, color * Lighting.Brightness((int)npc.position.X / 16, (int)npc.position.Y / 16));
}
if(Red > 0)
{
int offset = Shield > 0 ? 8 : 0;
Rectangle target = new Rectangle((int)drawpos.X - 16, (int)drawpos.Y + 12 + offset, 34, 6);
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/ShieldBar0"), target, Color.Red * Lighting.Brightness((int)npc.position.X / 16, (int)npc.position.Y / 16));
Rectangle target2 = new Rectangle((int)drawpos.X - 17, (int)drawpos.Y + 10 + offset, (int)(Red / (float)MaxRed * 36f), 10);
spriteBatch.Draw(ModContent.GetTexture("StarlightRiver/GUI/ShieldBar1"), target2, Color.Red * Lighting.Brightness((int)npc.position.X / 16, (int)npc.position.Y / 16));
return true;
}
return base.DrawHealthBar(npc, hbPosition, ref scale, ref position);
}
}
public class ShieldBreakingItem : GlobalItem
{
public bool Piercing = false;
public bool RedHurting = false;
public override bool InstancePerEntity => true;
public override bool CloneNewInstances => true;
public override void SetDefaults(Item item)
{
if(item.hammer > 0)
{
Piercing = true;
}
}
public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
{
if (Piercing)
{
TooltipLine line = new TooltipLine(mod, "Pierce", "2x Damage to Shields");
line.overrideColor = new Color(140, 220, 255);
tooltips.Add(line);
}
if (RedHurting)
{
TooltipLine line = new TooltipLine(mod, "RedHurt", "Can Damage [PH]REDHEALTH");
line.overrideColor = new Color(255, 210, 210);
tooltips.Add(line);
}
}
}
public class ShieldBreakingProjectile : GlobalProjectile
{
public bool Piercing = false;
public bool RedHurting = false;
public override bool InstancePerEntity => true;
}
}