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

◆ AI_099_2()

void Terraria.Projectile.AI_099_2 ( )
inlineprivate

Definition at line 57148 of file Projectile.cs.

57149 {
57150 bool flag = false;
57151 for (int i = 0; i < whoAmI; i++)
57152 {
57153 if (Main.projectile[i].active && Main.projectile[i].owner == owner && Main.projectile[i].type == type)
57154 {
57155 flag = true;
57156 }
57157 }
57158 if (owner == Main.myPlayer)
57159 {
57160 localAI[0] += 1f;
57161 if (flag)
57162 {
57163 localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f;
57164 }
57165 float num = localAI[0] / 60f;
57166 num /= (1f + Main.player[owner].meleeSpeed) / 2f;
57168 if (num2 != -1f && num > num2)
57169 {
57170 ai[0] = -1f;
57171 }
57172 }
57173 if (type == 603 && owner == Main.myPlayer)
57174 {
57175 localAI[1] += 1f;
57176 if (localAI[1] >= 6f)
57177 {
57178 float num3 = 400f;
57180 Vector2 vector2 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101));
57181 vector2.Normalize();
57182 vector2 *= (float)Main.rand.Next(10, 41) * 0.1f;
57183 if (Main.rand.Next(3) == 0)
57184 {
57185 vector2 *= 2f;
57186 }
57187 vector *= 0.25f;
57188 vector += vector2;
57189 for (int j = 0; j < 200; j++)
57190 {
57191 if (Main.npc[j].CanBeChasedBy(this))
57192 {
57193 float num4 = Main.npc[j].position.X + (float)(Main.npc[j].width / 2);
57194 float num5 = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2);
57195 float num6 = Math.Abs(position.X + (float)(width / 2) - num4) + Math.Abs(position.Y + (float)(height / 2) - num5);
57196 if (num6 < num3 && Collision.CanHit(position, width, height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height))
57197 {
57198 num3 = num6;
57199 vector.X = num4;
57200 vector.Y = num5;
57201 vector -= base.Center;
57202 vector.Normalize();
57203 vector *= 8f;
57204 }
57205 }
57206 }
57207 vector *= 0.8f;
57208 NewProjectile(GetProjectileSource_FromThis(), base.Center.X - vector.X, base.Center.Y - vector.Y, vector.X, vector.Y, 604, damage, knockBack, owner);
57209 localAI[1] = 0f;
57210 }
57211 }
57212 bool flag2 = false;
57213 if (type >= 556 && type <= 561)
57214 {
57215 flag2 = true;
57216 }
57217 if (Main.player[owner].dead)
57218 {
57219 Kill();
57220 return;
57221 }
57222 if (!flag2 && !flag)
57223 {
57224 Main.player[owner].heldProj = whoAmI;
57225 Main.player[owner].SetDummyItemTime(2);
57226 if (position.X + (float)(width / 2) > Main.player[owner].position.X + (float)(Main.player[owner].width / 2))
57227 {
57228 Main.player[owner].ChangeDir(1);
57229 direction = 1;
57230 }
57231 else
57232 {
57233 Main.player[owner].ChangeDir(-1);
57234 direction = -1;
57235 }
57236 }
57237 if (velocity.HasNaNs())
57238 {
57239 Kill();
57240 }
57241 timeLeft = 6;
57242 float num7 = 10f;
57243 float num8 = 10f;
57244 float num9 = 3f;
57245 float num10 = 200f;
57248 if (type == 545)
57249 {
57250 if (Main.rand.Next(6) == 0)
57251 {
57252 int num11 = Dust.NewDust(position, width, height, 6);
57253 Main.dust[num11].noGravity = true;
57254 }
57255 }
57256 else if (type == 553 && Main.rand.Next(2) == 0)
57257 {
57258 int num12 = Dust.NewDust(position, width, height, 6);
57259 Main.dust[num12].noGravity = true;
57260 Main.dust[num12].scale = 1.6f;
57261 }
57262 if (Main.player[owner].yoyoString)
57263 {
57264 num10 = num10 * 1.25f + 30f;
57265 }
57266 num10 /= (1f + Main.player[owner].meleeSpeed * 3f) / 4f;
57267 num8 /= (1f + Main.player[owner].meleeSpeed * 3f) / 4f;
57268 num7 = 14f - num8 / 2f;
57269 if (num7 < 1f)
57270 {
57271 num7 = 1f;
57272 }
57273 num9 = 5f + num8 / 2f;
57274 if (flag)
57275 {
57276 num9 += 20f;
57277 }
57278 if (ai[0] >= 0f)
57279 {
57280 if (velocity.Length() > num8)
57281 {
57282 velocity *= 0.98f;
57283 }
57284 bool flag3 = false;
57285 bool flag4 = false;
57286 Vector2 vector3 = Main.player[owner].Center - base.Center;
57287 if (vector3.Length() > num10)
57288 {
57289 flag3 = true;
57290 if ((double)vector3.Length() > (double)num10 * 1.3)
57291 {
57292 flag4 = true;
57293 }
57294 }
57295 if (owner == Main.myPlayer)
57296 {
57297 if (!Main.player[owner].channel || Main.player[owner].stoned || Main.player[owner].frozen)
57298 {
57299 ai[0] = -1f;
57300 ai[1] = 0f;
57301 netUpdate = true;
57302 }
57303 else
57304 {
57305 Vector2 vector4 = Main.ReverseGravitySupport(Main.MouseScreen) + Main.screenPosition;
57306 float x = vector4.X;
57307 float y = vector4.Y;
57308 Vector2 vector5 = new Vector2(x, y) - Main.player[owner].Center;
57309 if (vector5.Length() > num10)
57310 {
57311 vector5.Normalize();
57312 vector5 *= num10;
57313 vector5 = Main.player[owner].Center + vector5;
57314 x = vector5.X;
57315 y = vector5.Y;
57316 }
57317 if (ai[0] != x || ai[1] != y)
57318 {
57319 Vector2 vector6 = new Vector2(x, y) - Main.player[owner].Center;
57320 if (vector6.Length() > num10 - 1f)
57321 {
57322 vector6.Normalize();
57323 vector6 *= num10 - 1f;
57324 Vector2 vector7 = Main.player[owner].Center + vector6;
57325 x = vector7.X;
57326 y = vector7.Y;
57327 }
57328 ai[0] = x;
57329 ai[1] = y;
57330 netUpdate = true;
57331 }
57332 }
57333 }
57334 if (flag4 && owner == Main.myPlayer)
57335 {
57336 ai[0] = -1f;
57337 netUpdate = true;
57338 }
57339 if (ai[0] >= 0f)
57340 {
57341 if (flag3)
57342 {
57343 num7 /= 2f;
57344 num8 *= 2f;
57345 if (base.Center.X > Main.player[owner].Center.X && velocity.X > 0f)
57346 {
57347 velocity.X *= 0.5f;
57348 }
57349 if (base.Center.Y > Main.player[owner].Center.Y && velocity.Y > 0f)
57350 {
57351 velocity.Y *= 0.5f;
57352 }
57353 if (base.Center.X < Main.player[owner].Center.X && velocity.X < 0f)
57354 {
57355 velocity.X *= 0.5f;
57356 }
57357 if (base.Center.Y < Main.player[owner].Center.Y && velocity.Y < 0f)
57358 {
57359 velocity.Y *= 0.5f;
57360 }
57361 }
57362 Vector2 vector8 = new Vector2(ai[0], ai[1]) - base.Center;
57363 if (flag3)
57364 {
57365 num7 = 1f;
57366 }
57367 velocity.Length();
57368 float num13 = vector8.Length();
57369 if (num13 > num9)
57370 {
57371 vector8.Normalize();
57372 float num14 = Math.Min(num13 / 2f, num8);
57373 if (flag3)
57374 {
57375 num14 = Math.Min(num14, num8 / 2f);
57376 }
57377 vector8 *= num14;
57378 velocity = (velocity * (num7 - 1f) + vector8) / num7;
57379 }
57380 else if (flag)
57381 {
57382 if ((double)velocity.Length() < (double)num8 * 0.6)
57383 {
57384 vector8 = velocity;
57385 vector8.Normalize();
57386 vector8 *= num8 * 0.6f;
57387 velocity = (velocity * (num7 - 1f) + vector8) / num7;
57388 }
57389 }
57390 else
57391 {
57392 velocity *= 0.8f;
57393 }
57394 if (flag && !flag3 && (double)velocity.Length() < (double)num8 * 0.6)
57395 {
57397 velocity *= num8 * 0.6f;
57398 }
57399 }
57400 }
57401 else
57402 {
57403 num7 = (int)((double)num7 * 0.8);
57404 num8 *= 1.5f;
57405 tileCollide = false;
57406 Vector2 vector9 = Main.player[owner].Center - base.Center;
57407 float num15 = vector9.Length();
57409 {
57410 Kill();
57411 }
57412 else
57413 {
57414 vector9.Normalize();
57415 vector9 *= num8;
57416 velocity = (velocity * (num7 - 1f) + vector9) / num7;
57417 }
57418 }
57419 rotation += 0.45f;
57420 }
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Abs(double value)
Vector2 velocity
Definition Entity.cs:16
Vector2 position
Definition Entity.cs:14
static float[] YoyosLifeTimeMultiplier
IEntitySource GetProjectileSource_FromThis()
static int NewProjectile(IEntitySource spawnSource, Vector2 position, Vector2 velocity, int Type, int Damage, float KnockBack, int Owner=-1, float ai0=0f, float ai1=0f, float ai2=0f)

References System.Math.Abs(), Terraria.Collision.CanHit(), Terraria.Main.dust, System.Math.Min(), Terraria.Main.MouseScreen, Terraria.Main.myPlayer, Terraria.Dust.NewDust(), Terraria.Main.npc, Terraria.Main.player, Terraria.Main.projectile, Terraria.Main.rand, Terraria.Main.ReverseGravitySupport(), Terraria.Main.screenPosition, System.type, Microsoft.Xna.Framework.Vector2.X, Microsoft.Xna.Framework.Vector2.Y, Terraria.ID.ProjectileID.Sets.YoyosLifeTimeMultiplier, Terraria.ID.ProjectileID.Sets.YoyosMaximumRange, and Terraria.ID.ProjectileID.Sets.YoyosTopSpeed.