-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ExampleGlobalNPC.cs
133 lines (129 loc) · 3.63 KB
/
ExampleGlobalNPC.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
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ExampleMod.NPCs
{
public class ExampleGlobalNPC : GlobalNPC
{
public override void ResetEffects(NPC npc)
{
ExampleNPCInfo info = (ExampleNPCInfo)npc.GetModInfo(mod, "ExampleNPCInfo");
info.eFlames = false;
}
public override void UpdateLifeRegen(NPC npc, ref int damage)
{
ExampleNPCInfo info = (ExampleNPCInfo)npc.GetModInfo(mod, "ExampleNPCInfo");
if (info.eFlames)
{
if (npc.lifeRegen > 0)
{
npc.lifeRegen = 0;
}
npc.lifeRegen -= 16;
if (damage < 2)
{
damage = 2;
}
}
}
public override void NPCLoot(NPC npc)
{
if (npc.lifeMax > 5 && npc.value > 0f)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ExampleItem"));
}
if (((npc.type == NPCID.Pumpking && Main.pumpkinMoon) || (npc.type == NPCID.IceQueen && Main.snowMoon)) && NPC.waveCount > 10)
{
int chance = NPC.waveCount - 10;
if (Main.expertMode)
{
chance++;
}
if (Main.rand.Next(5) < chance)
{
int stack = 1;
if (NPC.waveCount >= 15)
{
stack = Main.rand.Next(4, 7);
if (Main.expertMode)
{
stack++;
}
}
else if (Main.rand.Next(2) == 0)
{
stack++;
}
string type = npc.type == NPCID.Pumpking ? "ScytheBlade" : "Icicle";
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType(type), stack);
}
}
if (npc.type == NPCID.DukeFishron && !Main.expertMode)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Bubble"), Main.rand.Next(5, 8));
}
if (npc.type == NPCID.Bunny && npc.AnyInteractions())
{
int left = (int)(npc.position.X / 16f);
int top = (int)(npc.position.Y / 16f);
int right = (int)((npc.position.X + npc.width) / 16f);
int bottom = (int)((npc.position.Y + npc.height) / 16f);
bool flag = false;
for (int i = left; i <= right; i++)
{
for (int j = top; j <= bottom; j++)
{
Tile tile = Main.tile[i, j];
if (tile.active() && tile.type == mod.TileType("ElementalPurge") && !NPC.AnyNPCs(mod.NPCType("PuritySpirit")))
{
i -= Main.tile[i, j].frameX / 18;
j -= Main.tile[i, j].frameY / 18;
i = (i * 16) + 16;
j = (j * 16) + 24 + 60;
for (int k = 0; k < 255; k++)
{
Player player = Main.player[k];
if (player.active && player.position.X > i - NPC.sWidth / 2 && player.position.X + player.width < i + NPC.sWidth / 2 && player.position.Y > j - NPC.sHeight / 2 && player.position.Y < j + NPC.sHeight / 2)
{
flag = true;
break;
}
}
if (flag)
{
NPC.NewNPC(i, j, mod.NPCType("PuritySpirit"));
break;
}
}
}
if (flag)
{
break;
}
}
}
}
public override void DrawEffects(NPC npc, ref Color drawColor)
{
ExampleNPCInfo info = (ExampleNPCInfo)npc.GetModInfo(mod, "ExampleNPCInfo");
if (info.eFlames)
{
if (Main.rand.Next(4) < 3)
{
int dust = Dust.NewDust(npc.position - new Vector2(2f, 2f), npc.width + 4, npc.height + 4, mod.DustType("EtherealFlame"), npc.velocity.X * 0.4f, npc.velocity.Y * 0.4f, 100, default(Color), 3.5f);
Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= 1.8f;
Main.dust[dust].velocity.Y -= 0.5f;
if (Main.rand.Next(4) == 0)
{
Main.dust[dust].noGravity = false;
Main.dust[dust].scale *= 0.5f;
}
}
Lighting.AddLight(npc.position, 0.1f, 0.2f, 0.7f);
}
}
}
}