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

◆ AI_113_WindyBalloon()

void Terraria.NPC.AI_113_WindyBalloon ( )
inlineprivate

Definition at line 41103 of file NPC.cs.

41104 {
41105 if (localAI[0] == 0f && Main.netMode != 1)
41106 {
41107 TargetClosest();
41108 localAI[0] = 1f;
41109 ai[2] = Main.rand.Next(7) + 1;
41110 int num = NewNPC(GetSpawnSourceForNPCFromNPCAI(), (int)position.X, (int)position.Y, 1);
41111 if (Main.rand.Next(180) == 0)
41112 {
41113 Main.npc[num].SetDefaults(-4);
41114 }
41115 else if (Main.rand.Next(10) == 0)
41116 {
41117 Main.npc[num].SetDefaults(-7);
41118 }
41119 else if (Main.rand.Next(3) == 0)
41120 {
41121 Main.npc[num].SetDefaults(-3);
41122 }
41123 Main.npc[num].ai[0] = -999f;
41124 Main.npc[num].netUpdate = true;
41125 ai[3] = num;
41126 netUpdate = true;
41127 ai[1] = Main.npc[num].scale;
41128 }
41129 position = base.Center;
41130 base.Size = new Vector2(20f, 20f) * ai[1];
41131 scale = ai[1];
41132 base.Center = position;
41134 rotation = velocity.X * 0.05f;
41135 if (nPC != null)
41136 {
41138 float num2 = float.PositiveInfinity;
41139 int num3 = 0;
41141 if (!targetData.Invalid)
41142 {
41143 zero = targetData.Center - base.Bottom;
41144 if (zero.Y < 0f)
41145 {
41146 num3 = (int)zero.Y / -16;
41147 }
41148 num2 = zero.Length();
41149 if (direction != Math.Sign(zero.X))
41150 {
41151 num3 = 0;
41152 }
41153 }
41154 if (wet || nPC.wet || collideX || (collideY && oldVelocity.Y < 0f))
41155 {
41156 float num4 = oldVelocity.X + (float)(direction * 8);
41157 position.X -= num4;
41158 nPC.position.X -= num4;
41160 direction *= -1;
41161 velocity.X = direction * 2;
41162 life = -1;
41163 HitEffect();
41164 active = false;
41165 netUpdate = true;
41167 return;
41168 }
41169 if (collideY)
41170 {
41171 velocity.Y = ((oldVelocity.Y > 0f) ? 1 : (-1));
41173 }
41174 float num5 = 2f + Math.Abs(Main.windSpeedTarget) * 2f;
41176 {
41177 velocity.X += (float)direction * 0.01f;
41178 if (velocity.X * (float)direction < 0f)
41179 {
41180 if (Math.Abs(velocity.X) > num5)
41181 {
41182 velocity.X += (float)direction * 0.1f;
41183 }
41184 else
41185 {
41186 velocity.X += (float)direction * 0.05f;
41187 }
41188 }
41189 else if (Math.Abs(velocity.X) > num5)
41190 {
41191 velocity.X = (float)direction * num5;
41192 }
41193 }
41194 int num6 = (int)((position.X + (float)(width / 2)) / 16f) + direction;
41195 int num7 = (int)((position.Y + (float)height) / 16f);
41196 bool flag = true;
41197 int num8 = 8 + num3;
41198 bool flag2 = false;
41199 for (int i = num7; i < num7 + num8; i++)
41200 {
41201 if (Main.tile[num6, i] == null)
41202 {
41203 Main.tile[num6, i] = new Tile();
41204 }
41205 if ((Main.tile[num6, i].nactive() && Main.tileSolid[Main.tile[num6, i].type]) || Main.tile[num6, i].liquid > 0)
41206 {
41207 if (i < num7 + 5 + num3)
41208 {
41209 flag2 = true;
41210 }
41211 flag = false;
41212 break;
41213 }
41214 }
41215 if (num2 < 400f && Collision.CanHit(position, width, height, Main.player[target].position, Main.player[target].width, Main.player[target].height))
41216 {
41217 float num9 = 2f;
41218 float num10 = 0.035f;
41219 if (base.Center.Y + (float)(height / 4) > Main.player[target].position.Y + (float)(Main.player[target].height / 4) && velocity.Y > 0f - num9)
41220 {
41221 velocity.Y -= num10;
41222 if (velocity.Y > 0f)
41223 {
41224 velocity.Y -= num10;
41225 }
41226 }
41227 else if (base.Center.Y + (float)(height / 4) < Main.player[target].position.Y + (float)(Main.player[target].height / 4) && velocity.Y < num9)
41228 {
41229 velocity.Y += num10;
41230 if (velocity.Y < 0f)
41231 {
41232 velocity.Y += num10;
41233 }
41234 }
41235 }
41236 else
41237 {
41238 if (flag)
41239 {
41240 velocity.Y += 0.05f;
41241 }
41242 else
41243 {
41244 velocity.Y -= 0.1f;
41245 }
41246 if (flag2)
41247 {
41248 velocity.Y -= 0.2f;
41249 }
41250 if (velocity.Y > 2f)
41251 {
41252 velocity.Y = 2f;
41253 }
41254 if (velocity.Y < -4f)
41255 {
41256 velocity.Y = -4f;
41257 }
41258 }
41259 nPC.Center = base.Bottom + new Vector2(0f, -8f) + new Vector2(0f, 56f * ai[1]);
41260 nPC.velocity = velocity;
41261 }
41262 else
41263 {
41264 velocity.Y = MathHelper.Clamp(velocity.Y - 0.2f, -8f, 8f);
41265 velocity.X = MathHelper.Clamp(velocity.X + Main.windSpeedTarget * 0.3f, -4f, 4f);
41266 if (collideX || collideY)
41267 {
41268 float num11 = oldVelocity.X + (float)(direction * 8);
41269 position.X -= num11;
41271 direction *= -1;
41272 velocity.X = direction * 2;
41273 life = -1;
41274 HitEffect();
41275 active = false;
41276 netUpdate = true;
41278 }
41279 }
41280 }
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Abs(double value)
static int Sign(decimal value)
Definition Math.cs:1202
static void PlaySound(int type, Vector2 position, int style=1)
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
Vector2 oldVelocity
Definition Entity.cs:20
float[] localAI
Definition NPC.cs:449
void TargetClosest(bool faceTarget=true)
Definition NPC.cs:69934
NPCAimedTarget GetTargetData(bool ignorePlayerTankPets=true)
Definition NPC.cs:864
float[] ai
Definition NPC.cs:447
float scale
Definition NPC.cs:493
bool collideX
Definition NPC.cs:511
bool collideY
Definition NPC.cs:513
LegacySoundStyle DeathSound
Definition NPC.cs:475
float rotation
Definition NPC.cs:501
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
void HitEffect(int hitDirection=0, double dmg=10.0)
Definition NPC.cs:78386
int life
Definition NPC.cs:477
NPC AI_113_WindyBalloon_GetSlaveNPC()
Definition NPC.cs:41282
bool netUpdate
Definition NPC.cs:507
int target
Definition NPC.cs:459

References System.Math.Abs(), Terraria.Entity.active, Terraria.NPC.ai, Terraria.NPC.AI_113_WindyBalloon_GetSlaveNPC(), Terraria.Collision.CanHit(), Microsoft.Xna.Framework.MathHelper.Clamp(), Terraria.NPC.collideX, Terraria.NPC.collideY, Terraria.NPC.DeathSound, Terraria.Entity.direction, Terraria.NPC.GetSpawnSourceForNPCFromNPCAI(), Terraria.NPC.GetTargetData(), Terraria.Entity.height, Terraria.NPC.HitEffect(), Terraria.NPC.life, Terraria.NPC.localAI, Terraria.Main.netMode, Terraria.NPC.netUpdate, Terraria.NPC.NewNPC(), Terraria.Main.npc, Terraria.Entity.oldVelocity, Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Entity.position, Terraria.Main.rand, Terraria.NPC.rotation, Terraria.NPC.scale, System.Math.Sign(), Terraria.NPC.target, Terraria.NPC.TargetClosest(), Terraria.DataStructures.Tile, Terraria.Main.tile, Terraria.Main.tileSolid, Microsoft.Xna.Framework.Graphics.Vector2, Terraria.Entity.velocity, Terraria.Entity.wet, Terraria.Entity.width, Terraria.Main.windSpeedTarget, Microsoft.Xna.Framework.Vector2.X, Microsoft.Xna.Framework.Vector2.Y, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.NPC.AI().