-
Notifications
You must be signed in to change notification settings - Fork 2
/
Prismachine.cs
440 lines (397 loc) · 14.9 KB
/
Prismachine.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
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
using prismmod.Items.Weapons;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace prismmod.NPCs.Prismachine
{
[AutoloadBossHead]
partial class Prismachine : ModNPC
{
private int spawningPlayer = 0;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("The Prismachine");
Main.npcFrameCount[npc.type] = 21;
}
public override void SetDefaults()
{
//update hitbox to match sprite: KEEP HITBOX OUT OF ORB HITBOXES
npc.width = 364;
npc.height = 260;
//no Ai Style
npc.lifeMax = 5000; //ask braden for life values
npc.DeathSound = SoundID.NPCDeath1;
//?npc.value = 0.75f;
npc.knockBackResist = 1f;
npc.damage = 1000; //lots of damage, should not get close to it, bceeause it should not get close to you
// npc.immune = false;
npc.noGravity = true;
npc.noTileCollide = false;
npc.boss = true;
npc.dontTakeDamageFromHostiles = true;
bossBag = mod.ItemType("PrismachineBag");
Mod musicmod = ModLoader.GetMod("prismmodmusic");
if (musicmod != null)
{
musicPriority = MusicPriority.BossHigh;
music = musicmod.GetSoundSlot(SoundType.Music, "Sounds/Music/PrismachineTheme");
}
}
//on spawn method, spawn orbs around the battlefied. Ask braden for range restrictions
public override void NPCLoot()
{
//Change loot to bossbag in hard mode and regular items if not
if (Main.expertMode)
{
npc.DropBossBags();
}
else //non expert mode drops
{
bool wepGained = false;
int choice = Main.rand.Next(4/*n-1*/);
if (choice == 0)
{
Item.NewItem(npc.getRect(), ModContent.ItemType<RainBow>(), 1);
wepGained = true;
}
choice = Main.rand.Next(4/*n-1*/);
if (choice == 1)
{
//wep 2
}
choice = Main.rand.Next(4/*n-1*/);
if (choice == 1)
{
//wep 3
}
choice = Main.rand.Next(4/*n-1*/);
if (choice == 1)
{
Item.NewItem(npc.getRect(), ModContent.ItemType<Prismaspear>(), 1);
wepGained = true;
}
if (!wepGained)
{
choice = Main.rand.Next(5);
}
}
Item.NewItem(npc.getRect(), ItemID.IronBar, 10);
Item.NewItem(npc.getRect(), ItemID.SilverBar, 10);
Item.NewItem(npc.getRect(), ItemID.PlatinumBar, 10);
ModContent.GetInstance<PrismWorld>().downedPrismachine = true; //sets world variable
}
private const int AI_State_Slot = 2;
private const int AI_Timer_Slot = 1;
private const int AI_Frame_Slot = 3;
private bool GenNewAttack = false;
private int attackTimes = 0;
private bool orbsSpawned = false;
private bool[] Attacks_Enabled = { false, false, false, false };
public float AI_State
{
get => npc.ai[AI_State_Slot];
set => npc.ai[AI_State_Slot] = value;
}
public float AI_Timer
{
get => npc.ai[AI_Timer_Slot];
set => npc.ai[AI_Timer_Slot] = value;
}
public float AI_Frame
{
get => npc.ai[AI_Frame_Slot];
set => npc.ai[AI_Frame_Slot] = value;
}
public bool MasterPump
{
get => Attacks_Enabled[0];
set => Attacks_Enabled[0] = value;
}
public bool CrystallizedTelepathy
{
get => Attacks_Enabled[1];
set => Attacks_Enabled[1] = value;
}
public bool FlareCannon
{
get => Attacks_Enabled[2];
set => Attacks_Enabled[2] = value;
}
public bool SpikeSpreader
{
get => Attacks_Enabled[3];
set => Attacks_Enabled[3] = value;
}
public int numOfAttacks() //gets the number of attacks enabled
{
int t = 0;
foreach (bool b in Attacks_Enabled)
{
if (b)
{
t++;
}
}
return t;
}
public bool[] attackSetter() //transfers attack data from a float to an bool array
{
int attackNum = (int)npc.ai[0];
bool[] parsedAttackList = new bool[4];
if ((int)(attackNum / 1000) == 1)
{
parsedAttackList[0] = true;
attackNum -= 1000;
}
if ((int)(attackNum / 100) == 1)
{
parsedAttackList[1] = true;
attackNum -= 100;
}
if ((int)(attackNum / 10) == 1)
{
parsedAttackList[2] = true;
attackNum -= 10;
}
if ((int)(attackNum) == 1)
{
parsedAttackList[3] = true;
}
return parsedAttackList;
}
private int tAttacks = 0;
public override void AI()
{
npc.spriteDirection = 0;
if (tAttacks == 0 && numOfAttacks() == 1)
{
GenNewAttack = true;
}
tAttacks = numOfAttacks();
Attacks_Enabled = attackSetter();
if (GenNewAttack)
{
GenNewAttack = false;
attackTimes = 0;
AI_State = Main.rand.Next(4) + 1;
while (Attacks_Enabled[(int)AI_State - 1] == false)
{
AI_State = Main.rand.Next(4) + 1;
}
}
if (!orbsSpawned && Main.netMode != 1)
{
int playernum = -1;
for (int j = 0; j < Main.ActivePlayersCount; j++)
{
Player player = Main.player[j];
if (player.GetModPlayer<PrismPlayer>().spawnedPrismachine)//sets target player to the one who most recently used the Prismatic Chunk
{
playernum = player.whoAmI;
player.GetModPlayer<PrismPlayer>().spawnedPrismachine = false;
break;
}
}
if (playernum < 0) //if no item used, target player set to closest player
{
playernum = Main.player[npc.target].whoAmI;
}
int numX = 0;
//orb spawn code
for (int i = 0; i < 4; i++)
{
if (i == 0)
{
numX = -2;
}
else if (i == 1)
{
numX = -1;
}
else if (i == 2)
{
numX = 1;
}
else if (i == 3)
{
numX = 2;
}
int orb = NPC.NewNPC((int)Main.player[playernum].Center.X + (numX * 125), (int)Main.player[playernum].Center.Y - 250, mod.NPCType("Orb"));
Main.npc[orb].ai[0] = npc.whoAmI;
Main.npc[orb].ai[1] = i;
Main.npc[orb].ai[2] = 0;
}
orbsSpawned = true;
}
npc.velocity.X = 0f;
npc.velocity.Y = 0f;
//Add movement code here
if (MasterPump & AI_Timer % 30 == 0 & Main.netMode != 1 && AI_State == 1)
{
Projectile.NewProjectile(npc.Center.X, npc.Center.Y + (npc.height / 2), 0f, 10f, ModContent.ProjectileType<PrismachineDroplet>(), 20, 1.5f);
if (attackTimes >= 6)
{
GenNewAttack = true;
}
attackTimes++;
}
if (CrystallizedTelepathy & AI_Timer % 60 == 0 & Main.netMode != 1 & AI_State == 2)
{ //down
Projectile.NewProjectile(npc.Center.X + (npc.width / 8), npc.Center.Y - (npc.height / 18), 0f, 10f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
Projectile.NewProjectile(npc.Center.X - (npc.width / 8), npc.Center.Y - (npc.height / 18), 0f, 10f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
//up-right
Projectile.NewProjectile(npc.Center.X + (npc.width / 8), npc.Center.Y - (npc.height / 18), 5f, -5f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
Projectile.NewProjectile(npc.Center.X - (npc.width / 8), npc.Center.Y - (npc.height / 18), 5f, -5f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
//up-left
Projectile.NewProjectile(npc.Center.X + (npc.width / 8), npc.Center.Y - (npc.height / 18), -5f, -5f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
Projectile.NewProjectile(npc.Center.X - (npc.width / 8), npc.Center.Y - (npc.height / 18), -5f, -5f, ModContent.ProjectileType<PrismachineHomingBolt>(), 20, 1.5f);
if (attackTimes >= 0)
{
GenNewAttack = true;
}
attackTimes++;
}
if (FlareCannon & AI_Timer % 7 == 0 & Main.netMode != 1 & AI_State == 3)
{
Projectile.NewProjectile(npc.Center.X, npc.Center.Y - (npc.height / 2), ((float)Main.rand.Next(11) - 5), -8f, ModContent.ProjectileType<PrismachineFireball>(), 20, 1.5f);
if (attackTimes >= 59)
{
GenNewAttack = true;
}
attackTimes++;
}
if (SpikeSpreader & AI_Timer % 60 == 0 & Main.netMode != 1 & AI_State == 4)//change time intervals
{
int times = 8;//change this value for number of spikes
//left
for (int i = 0; i < times; i++)
{
Projectile.NewProjectile(npc.Left.X + 5f, npc.Center.Y + 20f, -10f, ((float)-times / 4) + i * 2, ModContent.ProjectileType<PrismachineSpike>(), 20, 1.5f);
}
//right
for (int i = 0; i < times; i++)
{
Projectile.NewProjectile(npc.Right.X - 5f, npc.Center.Y + 20f, 10f, ((float)-times / 4) + i * 2, ModContent.ProjectileType<PrismachineSpike>(), 20, 1.5f);
}
if (attackTimes >= 2)
{
GenNewAttack = true;
}
attackTimes++;
//enables attacks of orb/element 4 type
}
if (Main.netMode != 1)
{
//@todo change Prismachine sprite?
if (AI_State == 1)
{
if (AI_Timer % 25 == 0)
{
count = 0;
start = true;
}
if (start == true)
{
AI_Frame = 15 + count;
count++;
}
if (count > 5)
{
count = 0;
start = false;
}
}
else if (AI_State == 2)
{
if (AI_Timer % 58 == 0)
{
count = 0;
start = true;
}
if (start == true)
{
AI_Frame = 7 + count;
count++;
}
if (count > 1)
{
count = 2;
start = false;
AI_Frame = 8;
}
}
else if (AI_State == 3)
{
if (start == false)
{
count = 0;
start = true;
}
if (start == true)
{
AI_Frame = 1 + count;
count++;
}
if (count > 4)
{
count = 5;
}
}
else if (AI_State == 4)
{
if (AI_Timer % 55 == 0)
{
count = 0;
start = true;
}
if (start == true)
{
AI_Frame = 9 + count;
count++;
}
if (count > 5)
{
count = 0;
start = false;
}
}
else
{
AI_Frame = 0;
}
}
if (Main.netMode != 1)
{
AI_Timer++;
if (AI_Timer >= 61)
{
AI_Timer = 1;
}
}
private int count = 0;
private bool start = false;
}
public override void FindFrame(int frameHeight)
{
npc.frame.Y = frameHeight * (int)AI_Frame;
}
public override void HitEffect(int hitDirection, double damage)
{
if (npc.life > 0)
{
Main.PlaySound(SoundLoader.customSoundType, -1, -1, mod.GetSoundSlot(SoundType.Custom, "Sounds/Prismachine/zzzt"));
}
if (npc.life <= 0)
{
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore1"), 1f);
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore2"), 1f);
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore3"), 1f);
// Add death sound here
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore4"), 1f);
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore5"), 1f);
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore6"), 1f);
Gore.NewGore(npc.Center, npc.velocity, mod.GetGoreSlot("Gores/PrismachineGore7"), 1f);
}
}
}
}