Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ AI_045_Golem()

void Terraria.NPC.AI_045_Golem ( )
inlineprivate

Definition at line 13310 of file NPC.cs.

13311 {
13312 golemBoss = whoAmI;
13313 float num = GetMyBalance();
13314 if (Main.getGoodWorld)
13315 {
13316 num += 2f;
13317 }
13318 if ((!Main.player[target].ZoneLihzhardTemple && !Main.player[target].ZoneJungle) || (double)Main.player[target].Center.Y < Main.worldSurface * 16.0)
13319 {
13320 num *= 2f;
13321 }
13322 if (localAI[0] == 0f)
13323 {
13324 localAI[0] = 1f;
13325 NewNPC(GetSpawnSourceForNPCFromNPCAI(), (int)base.Center.X - 84, (int)base.Center.Y - 9, 247);
13326 NewNPC(GetSpawnSourceForNPCFromNPCAI(), (int)base.Center.X + 78, (int)base.Center.Y - 9, 248);
13327 NewNPC(GetSpawnSourceForNPCFromNPCAI(), (int)base.Center.X - 3, (int)base.Center.Y - 57, 246);
13328 }
13329 if (target >= 0 && Main.player[target].dead)
13330 {
13331 TargetClosest();
13332 if (Main.player[target].dead)
13333 {
13334 noTileCollide = true;
13335 }
13336 }
13337 if (alpha > 0)
13338 {
13339 alpha -= 10;
13340 if (alpha < 0)
13341 {
13342 alpha = 0;
13343 }
13344 ai[1] = 0f;
13345 }
13346 bool flag = false;
13347 bool flag2 = false;
13348 bool flag3 = false;
13349 dontTakeDamage = false;
13350 for (int i = 0; i < 200; i++)
13351 {
13352 if (Main.npc[i].active && Main.npc[i].type == 246)
13353 {
13354 flag = true;
13355 }
13356 if (Main.npc[i].active && Main.npc[i].type == 247)
13357 {
13358 flag2 = true;
13359 }
13360 if (Main.npc[i].active && Main.npc[i].type == 248)
13361 {
13362 flag3 = true;
13363 }
13364 }
13365 dontTakeDamage = flag;
13366 if (Main.netMode != 1 && Main.getGoodWorld && velocity.Y > 0f)
13367 {
13368 for (int j = (int)(position.X / 16f); (float)j < (position.X + (float)width) / 16f; j++)
13369 {
13370 for (int k = (int)(position.Y / 16f); (float)k < (position.Y + (float)width) / 16f; k++)
13371 {
13372 if (Main.tile[j, k].type == 4)
13373 {
13374 Main.tile[j, k].active(active: false);
13375 if (Main.netMode == 2)
13376 {
13377 NetMessage.SendTileSquare(-1, j, k);
13378 }
13379 }
13380 }
13381 }
13382 }
13384 if (!Main.getGoodWorld)
13385 {
13386 if (!flag2)
13387 {
13388 int num2 = Dust.NewDust(new Vector2(base.Center.X - 80f * scale, base.Center.Y - 9f), 8, 8, 31, 0f, 0f, 100);
13389 Main.dust[num2].alpha += Main.rand.Next(100);
13390 Main.dust[num2].velocity *= 0.2f;
13391 Main.dust[num2].velocity.Y -= 0.5f + (float)Main.rand.Next(10) * 0.1f;
13392 Main.dust[num2].fadeIn = 0.5f + (float)Main.rand.Next(10) * 0.1f;
13393 if (Main.rand.Next(10) == 0)
13394 {
13395 num2 = Dust.NewDust(new Vector2(base.Center.X - 80f * scale, base.Center.Y - 9f), 8, 8, 6);
13396 if (Main.rand.Next(20) != 0)
13397 {
13398 Main.dust[num2].noGravity = true;
13399 Main.dust[num2].scale *= 1f + (float)Main.rand.Next(10) * 0.1f;
13400 Main.dust[num2].velocity.Y -= 1f;
13401 }
13402 }
13403 }
13404 if (!flag3)
13405 {
13406 int num3 = Dust.NewDust(new Vector2(base.Center.X + 62f * scale, base.Center.Y - 9f), 8, 8, 31, 0f, 0f, 100);
13407 Main.dust[num3].alpha += Main.rand.Next(100);
13408 Main.dust[num3].velocity *= 0.2f;
13409 Main.dust[num3].velocity.Y -= 0.5f + (float)Main.rand.Next(10) * 0.1f;
13410 Main.dust[num3].fadeIn = 0.5f + (float)Main.rand.Next(10) * 0.1f;
13411 if (Main.rand.Next(10) == 0)
13412 {
13413 num3 = Dust.NewDust(new Vector2(base.Center.X + 62f * scale, base.Center.Y - 9f), 8, 8, 6);
13414 if (Main.rand.Next(20) != 0)
13415 {
13416 Main.dust[num3].noGravity = true;
13417 Main.dust[num3].scale *= 1f + (float)Main.rand.Next(10) * 0.1f;
13418 Main.dust[num3].velocity.Y -= 1f;
13419 }
13420 }
13421 }
13422 }
13424 if (noTileCollide && !Main.player[target].dead)
13425 {
13426 if (velocity.Y > 0f && base.Bottom.Y > Main.player[target].Top.Y)
13427 {
13428 noTileCollide = false;
13429 }
13430 else if (Collision.CanHit(position, width, height, Main.player[target].Center, 1, 1) && !Collision.SolidTiles(position, width, height))
13431 {
13432 noTileCollide = false;
13433 }
13434 }
13435 if (ai[0] == 0f)
13436 {
13437 if (velocity.Y == 0f)
13438 {
13439 velocity.X *= 0.8f;
13440 float num4 = 1f;
13441 if (ai[1] > 0f)
13442 {
13443 if (!flag2)
13444 {
13445 num4 += 2f;
13446 }
13447 if (!flag3)
13448 {
13449 num4 += 2f;
13450 }
13451 if (!flag)
13452 {
13453 num4 += 2f;
13454 }
13455 if (life < lifeMax)
13456 {
13457 num4 += 1f;
13458 }
13459 if (life < lifeMax / 2)
13460 {
13461 num4 += 4f;
13462 }
13463 if (life < lifeMax / 3)
13464 {
13465 num4 += 8f;
13466 }
13467 num4 *= num;
13468 if (Main.getGoodWorld)
13469 {
13470 num4 += 100f;
13471 }
13472 }
13473 ai[1] += num4;
13474 if (ai[1] >= 300f)
13475 {
13476 ai[1] = -20f;
13477 frameCounter = 0.0;
13478 }
13479 else if (ai[1] == -1f)
13480 {
13481 noTileCollide = true;
13482 TargetClosest();
13483 velocity.X = 4 * direction;
13484 if (life < lifeMax)
13485 {
13486 velocity.Y = -12.1f * (num + 9f) / 10f;
13487 if ((double)velocity.Y < -19.1)
13488 {
13489 velocity.Y = -19.1f;
13490 }
13491 }
13492 else
13493 {
13494 velocity.Y = -12.1f;
13495 }
13496 ai[0] = 1f;
13497 ai[1] = 0f;
13498 }
13499 }
13500 }
13501 else if (ai[0] == 1f)
13502 {
13503 if (velocity.Y == 0f)
13504 {
13506 ai[0] = 0f;
13507 for (int l = (int)position.X - 20; l < (int)position.X + width + 40; l += 20)
13508 {
13509 for (int m = 0; m < 4; m++)
13510 {
13511 int num5 = Dust.NewDust(new Vector2(position.X - 20f, position.Y + (float)height), width + 20, 4, 31, 0f, 0f, 100, default(Color), 1.5f);
13512 Main.dust[num5].velocity *= 0.2f;
13513 }
13514 int num6 = Gore.NewGore(new Vector2(l - 20, position.Y + (float)height - 8f), default(Vector2), Main.rand.Next(61, 64));
13515 Main.gore[num6].velocity *= 0.4f;
13516 }
13517 }
13518 else
13519 {
13520 TargetClosest();
13521 if (position.X < Main.player[target].position.X && position.X + (float)width > Main.player[target].position.X + (float)Main.player[target].width)
13522 {
13523 velocity.X *= 0.9f;
13524 if (base.Bottom.Y < Main.player[target].position.Y)
13525 {
13526 velocity.Y += 0.2f * (num + 1f) / 2f;
13527 }
13528 }
13529 else
13530 {
13531 if (direction < 0)
13532 {
13533 velocity.X -= 0.2f;
13534 }
13535 else if (direction > 0)
13536 {
13537 velocity.X += 0.2f;
13538 }
13539 float num7 = 3f;
13540 if (life < lifeMax)
13541 {
13542 num7 += 1f;
13543 }
13544 if (life < lifeMax / 2)
13545 {
13546 num7 += 1f;
13547 }
13548 if (life < lifeMax / 4)
13549 {
13550 num7 += 1f;
13551 }
13552 num7 *= (num + 1f) / 2f;
13553 if (velocity.X < 0f - num7)
13554 {
13555 velocity.X = 0f - num7;
13556 }
13557 if (velocity.X > num7)
13558 {
13559 velocity.X = num7;
13560 }
13561 }
13562 }
13563 }
13564 if (target <= 0 || target == 255 || Main.player[target].dead)
13565 {
13566 TargetClosest();
13567 }
13568 int num8 = 3000;
13569 if (Math.Abs(base.Center.X - Main.player[target].Center.X) + Math.Abs(base.Center.Y - Main.player[target].Center.Y) > (float)num8)
13570 {
13571 TargetClosest();
13572 if (Math.Abs(base.Center.X - Main.player[target].Center.X) + Math.Abs(base.Center.Y - Main.player[target].Center.Y) > (float)num8)
13573 {
13574 active = false;
13575 }
13576 }
13577 }
static double Abs(double value)
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
static readonly LegacySoundStyle Item14
Definition SoundID.cs:442
Vector2 netOffset
Definition NPC.cs:103
float GetMyBalance()
Definition NPC.cs:12262
float[] localAI
Definition NPC.cs:449
int lifeMax
Definition NPC.cs:479
void TargetClosest(bool faceTarget=true)
Definition NPC.cs:69934
float[] ai
Definition NPC.cs:447
bool dontTakeDamage
Definition NPC.cs:527
float scale
Definition NPC.cs:493
int alpha
Definition NPC.cs:489
double frameCounter
Definition NPC.cs:483
IEntitySource GetSpawnSourceForNPCFromNPCAI()
Definition NPC.cs:87546
static int NewNPC(IEntitySource source, int X, int Y, int Type, int Start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int Target=255)
Definition NPC.cs:77654
bool noTileCollide
Definition NPC.cs:505
static int golemBoss
Definition NPC.cs:161
int life
Definition NPC.cs:477
int target
Definition NPC.cs:459

References System.Math.Abs(), Terraria.Entity.active, Terraria.NPC.ai, Terraria.NPC.alpha, Terraria.Collision.CanHit(), Terraria.Entity.direction, Terraria.NPC.dontTakeDamage, Terraria.Main.dust, Terraria.NPC.frameCounter, Terraria.Main.getGoodWorld, Terraria.NPC.GetMyBalance(), Terraria.NPC.GetSpawnSourceForNPCFromNPCAI(), Terraria.NPC.golemBoss, Terraria.Main.gore, Terraria.Entity.height, Terraria.ID.SoundID.Item14, Terraria.NPC.life, Terraria.NPC.lifeMax, Terraria.NPC.localAI, Terraria.Main.netMode, Terraria.NPC.netOffset, Terraria.Dust.NewDust(), Terraria.Gore.NewGore(), Terraria.NPC.NewNPC(), Terraria.NPC.noTileCollide, Terraria.Main.npc, Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Entity.position, Terraria.Main.rand, Terraria.NPC.scale, Terraria.NetMessage.SendTileSquare(), Terraria.Collision.SolidTiles(), Terraria.NPC.target, Terraria.NPC.TargetClosest(), Terraria.Main.tile, Microsoft.Xna.Framework.Graphics.Vector2, Terraria.Entity.velocity, Terraria.Entity.whoAmI, Terraria.Entity.width, Terraria.Main.worldSurface, Microsoft.Xna.Framework.Vector2.X, and Microsoft.Xna.Framework.Vector2.Y.

Referenced by Terraria.NPC.AI().