static public SequenceAction Create(List <FiniteTimeAction> actionList) { SequenceAction ret = null; do { int count = actionList.Count; if (count == 0) { break; } FiniteTimeAction prev = actionList[0]; if (count > 1) { for (int i = 1; i < count; ++i) { prev = CreateWithTwoActions(prev, actionList[i]); } } else { // If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action. prev = CreateWithTwoActions(prev, ExtraAction.Create()); } ret = (SequenceAction)prev; }while (false); return(ret); }
public static void ThrowingKnifeAI(int index, int airTime = 20, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.03f * (float)projectile.direction; projectile.localAI[0] += 1f; if (projectile.localAI[0] >= (float)airTime) { projectile.velocity.Y = projectile.velocity.Y + 0.4f; projectile.velocity.X = projectile.velocity.X * 0.98f; } else { projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; } if (projectile.velocity.Y > 16f) { projectile.velocity.Y = 16f; } if (action != null) { action(); } }
public static void Explode(int index, int sizeX, int sizeY, ExtraAction visualAction = null, bool weakerExplosion = false) { Projectile projectile = Main.projectile[index]; if (!projectile.active) { return; } projectile.tileCollide = false; projectile.alpha = 255; projectile.position = projectile.Center; projectile.width = sizeX; projectile.height = sizeY; projectile.position.X -= (projectile.width / 2f); projectile.position.Y -= (projectile.height / 2f); if (weakerExplosion) { projectile.damage = (int)(projectile.damage * .75f); } projectile.Damage(); Main.projectileIdentity[projectile.owner, projectile.identity] = -1; projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = (int)((float)sizeX / 5.8f); projectile.height = (int)((float)sizeY / 5.8f); projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); if (visualAction == null) { for (int i = 0; i < 30; i++) { int num = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, DustID.Smoke, 0f, 0f, 100, default, 1.5f);
public static Spawn Create(List <FiniteTimeAction> arrayOfActions) { Spawn ret = null; do { int count = arrayOfActions.Count; UnityEngine.Debug.Assert(count > 0); FiniteTimeAction prev = arrayOfActions[0]; if (count > 1) { for (int i = 1; i < arrayOfActions.Count; ++i) { prev = createWithTwoActions(prev, arrayOfActions[i]); } } else { // If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action. prev = createWithTwoActions(prev, ExtraAction.Create()); } ret = (Spawn)prev; }while (false); return(ret); }
public static Spawn Create(FiniteTimeAction action1, params FiniteTimeAction[] args) { FiniteTimeAction now; FiniteTimeAction prev = action1; bool bOneAction = true; for (int i = 0; i < args.Length; i++) { now = args[i]; prev = CreateWithTwoActions(prev, now); bOneAction = false; } if (bOneAction) { prev = CreateWithTwoActions(prev, ExtraAction.Create()); } return(prev as Spawn); }
public bool Init(List <FiniteTimeAction> arrayOfActions) { var count = arrayOfActions.Count; if (count == 0) { return(false); } if (count == 1) { return(InitWithTwoActions(arrayOfActions[0], ExtraAction.Create())); } var prev = arrayOfActions[0]; for (int i = 1; i < count - 1; i++) { prev = CreateWithTwoActions(prev, arrayOfActions[i]); } return(InitWithTwoActions(prev, arrayOfActions[count - 1])); }
/// <summary> /// /// </summary> /// <param name="index">Index of the projectile in the Main.projecile array.</param> /// <param name="retractTime">The time (in ticks) before the boomerang returns to its owner.</param> /// <param name="speed">A speed modifier for the boomerang.</param> /// <param name="speedAcceleration">The speed at which the boomerang comes back to the player.</param> /// <param name="action">An action to perform when the projectile is out in front of the player.</param> /// <param name="initalize">An action to perform once when initializing.</param> public static void BoomerangAI(int index, float retractTime = 30, float speed = 9, float speedAcceleration = 0.4F, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0) { projectile.localAI[1] = 1; initialize(); } if (projectile.soundDelay == 0) { projectile.soundDelay = 8; Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 7); } if (projectile.ai[0] == 0f) { projectile.ai[1] += 1f; if (projectile.ai[1] >= retractTime) { projectile.ai[0] = 1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } } else { projectile.tileCollide = false; Vector2 projectileCenter = new Vector2(projectile.position.X + projectile.width * 0.5f, projectile.position.Y + projectile.height * 0.5f); float dirX = Main.player[projectile.owner].position.X + (Main.player[projectile.owner].width / 2) - projectileCenter.X; float dirY = Main.player[projectile.owner].position.Y + (Main.player[projectile.owner].height / 2) - projectileCenter.Y; float length = (float)Math.Sqrt((double)(dirX * dirX + dirY * dirY)); // Projectile reached max range, destroy it. if (length > 3000f) { projectile.Kill(); } length = speed / length; dirX *= length; dirY *= length; if (projectile.velocity.X < dirX) { projectile.velocity.X = projectile.velocity.X + speedAcceleration; if (projectile.velocity.X < 0f && dirX > 0f) { projectile.velocity.X = projectile.velocity.X + speedAcceleration; } } else if (projectile.velocity.X > dirX) { projectile.velocity.X = projectile.velocity.X - speedAcceleration; if (projectile.velocity.X > 0f && dirX < 0f) { projectile.velocity.X = projectile.velocity.X - speedAcceleration; } } if (projectile.velocity.Y < dirY) { projectile.velocity.Y = projectile.velocity.Y + speedAcceleration; if (projectile.velocity.Y < 0f && dirY > 0f) { projectile.velocity.Y = projectile.velocity.Y + speedAcceleration; } } else if (projectile.velocity.Y > dirY) { projectile.velocity.Y = projectile.velocity.Y - speedAcceleration; if (projectile.velocity.Y > 0f && dirY < 0f) { projectile.velocity.Y = projectile.velocity.Y - speedAcceleration; } } if (Main.myPlayer == projectile.owner) { Rectangle projectileCol = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height); Rectangle playerCol = new Rectangle((int)Main.player[projectile.owner].position.X, (int)Main.player[projectile.owner].position.Y, Main.player[projectile.owner].width, Main.player[projectile.owner].height); if (projectileCol.Intersects(playerCol)) { projectile.Kill(); } } } projectile.rotation += 0.4f * projectile.direction; if (action != null) { action(); // Run the action specified. } }
void CallFuncTest() { btn_text.text = "点击停止"; var action = Sequence.Create( CallFunc.Create(CallBackO, "延时0.5秒"), DelayTime.Create(0.5f), CallFunc.Create(CallBackO, "图片移动"), MoveTo.Create(1f, 200, 100).InitSubjectTransform(image.transform), MoveTo.Create(1f, 0, 0).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "颜色渐变"), ColorTo.Create(0.5f, 1, 0, 0, 1f).InitSubjectComponent(image), ColorTo.Create(0.5f, 0, 1, 0, 1f).InitSubjectComponent(image), ColorTo.Create(0.5f, 0, 0, 1, 1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "颜色reset"), ColorTo.Create(0.5f, 1, 1, 1, 1).InitSubjectComponent(image), CallFunc.Create(CallBackO, "渐隐"), FadeOut.Create(1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "渐出"), FadeIn.Create(1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "1秒闪烁5次"), Blink.Create(1f, 5), CallFunc.Create(CallBackO, "二阶贝塞尔曲线"), BezierTo.Create(2.0f, new Vector3(200, 100, 0), new Vector3(-100, 50, 0), new Vector3(100, 80, 0)).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "移动回原点"), MoveTo.Create(1f, 0, 0).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "边移动边放大"), Spawn.Create(MoveTo.Create(1.0f, 200, 100f), ScaleTo.Create(1.0f, 3.0f, 3.0f, 3.0f)), CallFunc.Create(CallBackO, "缩放位置回原位"), Spawn.Create(MoveTo.Create(1.0f, 0, 0), ScaleTo.Create(1.0f, 1f, 1f, 1f)), NumberBy.Create(2.0f, "数字跳跃,从100到200:{0:f2}", 100, 100).InitSubjectComponent(text), DelayTime.Create(0.5f), NumberTo.Create(2.0f, "数字跳跃,从200到0:{0:f2}", 200, 0).InitSubjectComponent(text), DelayTime.Create(0.5f), CallFunc.Create(CallBackO, "Image Filled"), FillAmountTo.Create(1.5f, 0f).InitSubjectComponent(image), FillAmountTo.Create(1.5f, 1.0f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "reset"), CallFunc.Create(CallBackO, "旋转 放大2倍,复原。重复3次"), Repeat.Create(Spawn.Create( RotationBy.Create(1.0f, 0, 0, 360f), Sequence.Create( ScaleTo.Create(0.5f, 2.0f, 2.0f, 2.0f), ScaleTo.Create(0.5f, 1.0f, 1.0f, 1.0f))).InitSubjectTransform(image.transform), 3), ExtraAction.Create() ); float toX = 300f; var easeAction = Sequence.Create( CallFunc.Create(CallBackO, "变速运动演示,图一正常,图二是变速运动"), DelayTime.Create(1f), CallFunc.Create(CallBackO, "当前变速是EaseIn"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseIn.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseIn.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "当前变速是EaseOut"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseOut.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseOut.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "当前变速是EaseInOut"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseInOut.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseInOut.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "变速运动未完待续"), DelayTime.Create(1f), ExtraAction.Create() ); CCActionManager.Instance.AddAction(Sequence.Create(action, easeAction, CallFunc.Create(CallBackEnd)), transform); }
/// <summary> /// LocalAI[1] cannot be used in either of the Extra Actions due to it being used for the initialization (or at least if it is never set to 0 it can be). /// </summary> /// <param name="index">Index of the projectile in the Main.projecile array.</param> /// <param name="seconds">How long before the yoyo comes back to the player in seconds.</param> /// <param name="length">How far away from the player the yoyo can go.</param> /// <param name="acceleration">How fast the yoyo travels?</param> /// <param name="rotationSpeed">The rotation speed of the yoyo.</param> /// <param name="action">An action to perform when the projectile is out in front of the player.</param> /// <param name="initialize">An action to perform once when initializing.</param> public static void YoyoAI(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) //0.45f is the default { //extra action allows us to shoot extra projectiles and such /*variable dictionary: * num7 = max length of yoyo in pixels, so 16 = 1 tile. * num6 = something related to velocity */ Projectile projectile = Main.projectile[index]; bool flag = false; if (initialize != null && projectile.localAI[1] == 0) { projectile.localAI[1] = 1; initialize(); } for (int i = 0; i < projectile.whoAmI; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type) { flag = true; } } if (projectile.owner == Main.myPlayer) { projectile.localAI[0] += 1f; if (flag) { projectile.localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f; } float num = projectile.localAI[0] / 60f; num /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f; if (num > seconds) { projectile.ai[0] = -1f; //retract yoyo } } bool flag2 = false; //Just gonna leave this here, it was to check if it is a counterweight but in our case it never can be if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } if (!flag2 && !flag) { Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemAnimation = 2; Main.player[projectile.owner].itemTime = 2; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } } if (projectile.velocity.HasNaNs()) { projectile.Kill(); } projectile.timeLeft = 6; float num6 = acceleration; float num7 = length; if (Main.player[projectile.owner].yoyoString) { num7 = num7 * 1.25f + 30f; } // take this part out if we were ever to release this :P if (Gyrolite.GetPlayer(Main.player[projectile.owner]).yoyoStringBall) { num7 += 112f; } // num7 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; num6 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; float num10 = 14f - num6 / 2f; float num11 = 5f + num6 / 2f; if (flag) { num11 += 20f; } if (projectile.ai[0] >= 0f) { if (projectile.velocity.Length() > num6) { projectile.velocity *= 0.98f; } bool flag3 = false; bool flag4 = false; Vector2 vector3 = Main.player[projectile.owner].Center - projectile.Center; if (vector3.Length() > num7) { flag3 = true; if ((double)vector3.Length() > (double)num7 * 1.3) { flag4 = true; } } if (projectile.owner == Main.myPlayer) { if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen) { projectile.ai[0] = -1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } else { Vector2 vector4 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition; float x = vector4.X; float y = vector4.Y; Vector2 vector5 = new Vector2(x, y) - Main.player[projectile.owner].Center; if (vector5.Length() > num7) { vector5.Normalize(); vector5 *= num7; vector5 = Main.player[projectile.owner].Center + vector5; x = vector5.X; y = vector5.Y; } if (projectile.ai[0] != x || projectile.ai[1] != y) { Vector2 value = new Vector2(x, y); Vector2 vector6 = value - Main.player[projectile.owner].Center; if (vector6.Length() > num7 - 1f) { vector6.Normalize(); vector6 *= num7 - 1f; value = Main.player[projectile.owner].Center + vector6; x = value.X; y = value.Y; } projectile.ai[0] = x; projectile.ai[1] = y; projectile.netUpdate = true; } } } if (flag4 && projectile.owner == Main.myPlayer) { projectile.ai[0] = -1f; projectile.netUpdate = true; } if (projectile.ai[0] >= 0f) { if (flag3) { num10 /= 2f; num6 *= 2f; if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } } Vector2 value2 = new Vector2(projectile.ai[0], projectile.ai[1]); Vector2 vector7 = value2 - projectile.Center; projectile.velocity.Length(); if (vector7.Length() > num11) { vector7.Normalize(); vector7 *= num6; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10; } else if (flag) { if ((double)projectile.velocity.Length() < (double)num6 * 0.6) { vector7 = projectile.velocity; vector7.Normalize(); vector7 *= num6 * 0.6f; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10; } } else { projectile.velocity *= 0.8f; } if (flag && !flag3 && (double)projectile.velocity.Length() < (double)num6 * 0.6) { projectile.velocity.Normalize(); projectile.velocity *= num6 * 0.6f; } if (action != null) { action(); // Run the action specified. } } } else // projectile is returning to player { num10 = (float)((int)((double)num10 * 0.8)); num6 *= 1.5f; projectile.tileCollide = false; Vector2 vector8 = Main.player[projectile.owner].position - projectile.Center; float num12 = vector8.Length(); if (num12 < num6 + 10f || num12 == 0f) { projectile.Kill(); } else { vector8.Normalize(); vector8 *= num6; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector8) / num10; } } projectile.rotation += rotationSpeed; }
/// <summary> /// /// </summary> /// <param name="index">Index of the projectile in the Main.projecile array.</param> /// <param name="initialRange">The range of the initial shoot of the flail.</param> /// <param name="weaponOutRange">The range of the flail once it has been shot out.</param> /// <param name="retractRange">The range at which the flail starts to direct towards the player.</param> /// <param name="action">An action to perform when the projectile is out in front of the player.</param> /// <param name="initalize">An action to perform once when initializing.</param> public static void FlailAI(int index, float initialRange = 160, float weaponOutRange = 300, float retractRange = 100, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0) { projectile.localAI[1] = 1; initialize(); } if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } Main.player[projectile.owner].itemAnimation = 10; Main.player[projectile.owner].itemTime = 10; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } Vector2 mountedCenter2 = Main.player[projectile.owner].MountedCenter; Vector2 vector18 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num204 = mountedCenter2.X - vector18.X; float num205 = mountedCenter2.Y - vector18.Y; float num206 = (float)Math.Sqrt((double)(num204 * num204 + num205 * num205)); if (projectile.ai[0] == 0f) { float num207 = initialRange; projectile.tileCollide = true; if (num206 > num207) { projectile.ai[0] = 1f; projectile.netUpdate = true; } else if (!Main.player[projectile.owner].channel) { if (projectile.velocity.Y < 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.9f; } projectile.velocity.Y = projectile.velocity.Y + 1f; projectile.velocity.X = projectile.velocity.X * 0.9f; } } else if (projectile.ai[0] == 1f) { float num208 = 14f / Main.player[projectile.owner].meleeSpeed; float num209 = 0.9f / Main.player[projectile.owner].meleeSpeed; float num210 = weaponOutRange; Math.Abs(num204); Math.Abs(num205); if (projectile.ai[1] == 1f) { projectile.tileCollide = false; } if (!Main.player[projectile.owner].channel || num206 > num210 || !projectile.tileCollide) { projectile.ai[1] = 1f; if (projectile.tileCollide) { projectile.netUpdate = true; } projectile.tileCollide = false; if (num206 < 20f) { projectile.Kill(); } } if (!projectile.tileCollide) { num209 *= 2f; } int num211 = (int)retractRange; if (num206 > (float)num211 || !projectile.tileCollide) { num206 = num208 / num206; num204 *= num206; num205 *= num206; new Vector2(projectile.velocity.X, projectile.velocity.Y); float num212 = num204 - projectile.velocity.X; float num213 = num205 - projectile.velocity.Y; float num214 = (float)Math.Sqrt((double)(num212 * num212 + num213 * num213)); num214 = num209 / num214; num212 *= num214; num213 *= num214; projectile.velocity.X = projectile.velocity.X * 0.98f; projectile.velocity.Y = projectile.velocity.Y * 0.98f; projectile.velocity.X = projectile.velocity.X + num212; projectile.velocity.Y = projectile.velocity.Y + num213; } else { if (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y) < 6f) { projectile.velocity.X = projectile.velocity.X * 0.96f; projectile.velocity.Y = projectile.velocity.Y + 0.2f; } if (Main.player[projectile.owner].velocity.X == 0f) { projectile.velocity.X = projectile.velocity.X * 0.96f; } } } if (projectile.velocity.X < 0f) { projectile.rotation -= (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } else { projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } if (action != null) { action(); // Run the action specified. } }
public static void YoyoAI(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) { Terraria.Projectile projectile = Main.projectile[index]; bool flag = false; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } for (int i = 0; i < projectile.whoAmI; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type) { flag = true; } } if (projectile.owner == Main.myPlayer) { projectile.localAI[0] += 1f; if (flag) { projectile.localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f; } float num = projectile.localAI[0] / 60f; num /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f; if (num > seconds) { projectile.ai[0] = -1f; } } bool flag2 = false; if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } if (!flag2 && !flag) { Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemAnimation = 2; Main.player[projectile.owner].itemTime = 2; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } } if (Utils.HasNaNs(projectile.velocity)) { projectile.Kill(); } projectile.timeLeft = 6; float num2 = length; if (Main.player[projectile.owner].yoyoString) { num2 = num2 * 1.25f + 30f; } num2 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; float num3 = acceleration / ((1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f); float num4 = 14f - num3 / 2f; float num5 = 5f + num3 / 2f; if (flag) { num5 += 20f; } if (projectile.ai[0] >= 0f) { if (projectile.velocity.Length() > num3) { projectile.velocity *= 0.98f; } bool flag3 = false; bool flag4 = false; Vector2 vector = Main.player[projectile.owner].Center - projectile.Center; if (vector.Length() > num2) { flag3 = true; if ((double)vector.Length() > (double)num2 * 1.3) { flag4 = true; } } if (projectile.owner == Main.myPlayer) { if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen) { projectile.ai[0] = -1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } else { Vector2 vector2 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition; float x = vector2.X; float y = vector2.Y; Vector2 vector3 = new Vector2(x, y) - Main.player[projectile.owner].Center; if (vector3.Length() > num2) { vector3.Normalize(); vector3 *= num2; vector3 = Main.player[projectile.owner].Center + vector3; x = vector3.X; y = vector3.Y; } if (projectile.ai[0] != x || projectile.ai[1] != y) { Vector2 value = new Vector2(x, y); Vector2 vector4 = value - Main.player[projectile.owner].Center; if (vector4.Length() > num2 - 1f) { vector4.Normalize(); vector4 *= num2 - 1f; value = Main.player[projectile.owner].Center + vector4; x = value.X; y = value.Y; } projectile.ai[0] = x; projectile.ai[1] = y; projectile.netUpdate = true; } } } if (flag4 && projectile.owner == Main.myPlayer) { projectile.ai[0] = -1f; projectile.netUpdate = true; } if (projectile.ai[0] >= 0f) { if (flag3) { num4 /= 2f; num3 *= 2f; if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } } Vector2 value2 = new Vector2(projectile.ai[0], projectile.ai[1]); Vector2 vector5 = value2 - projectile.Center; projectile.velocity.Length(); if (vector5.Length() > num5) { vector5.Normalize(); vector5 *= num3; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector5) / num4; } else if (flag) { if ((double)projectile.velocity.Length() < (double)num3 * 0.6) { vector5 = projectile.velocity; vector5.Normalize(); vector5 *= num3 * 0.6f; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector5) / num4; } } else { projectile.velocity *= 0.8f; } if (flag && !flag3 && (double)projectile.velocity.Length() < (double)num3 * 0.6) { projectile.velocity.Normalize(); projectile.velocity *= num3 * 0.6f; } if (action != null) { action(); } } } else { num4 = (float)((int)((double)num4 * 0.8)); num3 *= 1.5f; projectile.tileCollide = false; Vector2 vector6 = Main.player[projectile.owner].position - projectile.Center; float num6 = vector6.Length(); if (num6 < num3 + 10f || num6 == 0f) { projectile.Kill(); } else { vector6.Normalize(); vector6 *= num3; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector6) / num4; } } projectile.rotation += rotationSpeed; }
//0.45f is the default /// <summary> /// LocalAI[1] cannot be used in either of the Extra Actions due to it being used for the initialization (or at least if it is never set to 0 it can be). /// </summary> /// <param name="index">Index of the projectile in the Main.projecile array.</param> /// <param name="seconds">How long before the yoyo comes back to the player in seconds.</param> /// <param name="length">How far away from the player the yoyo can go.</param> /// <param name="acceleration">How fast the yoyo travels?</param> /// <param name="rotationSpeed">The rotation speed of the yoyo.</param> /// <param name="action">An action to perform when the projectile is out in front of the player.</param> /// <param name="initialize">An action to perform once when initializing.</param> public static void YoyoAI(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) { //extra action allows us to shoot extra projectiles and such /*variable dictionary: num7 = max length of yoyo in pixels, so 16 = 1 tile. num6 = something related to velocity */ Projectile projectile = Main.projectile[index]; bool flag = false; if (initialize != null && projectile.localAI[1] == 0) { projectile.localAI[1] = 1; initialize(); } for (int i = 0; i < projectile.whoAmI; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type) { flag = true; } } if (projectile.owner == Main.myPlayer) { projectile.localAI[0] += 1f; if (flag) { projectile.localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f; } float num = projectile.localAI[0] / 60f; num /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f; if (num > seconds) { projectile.ai[0] = -1f; //retract yoyo } } bool flag2 = false; //Just gonna leave this here, it was to check if it is a counterweight but in our case it never can be if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } if (!flag2 && !flag) { Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemAnimation = 2; Main.player[projectile.owner].itemTime = 2; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } } if (projectile.velocity.HasNaNs()) { projectile.Kill(); } projectile.timeLeft = 6; float num6 = acceleration; float num7 = length; if (Main.player[projectile.owner].yoyoString) { num7 = num7 * 1.25f + 30f; } // take this part out if we were ever to release this :P if (Gyrolite.GetPlayer(Main.player[projectile.owner]).yoyoStringBall) { num7 += 112f; } // num7 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; num6 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; float num10 = 14f - num6 / 2f; float num11 = 5f + num6 / 2f; if (flag) { num11 += 20f; } if (projectile.ai[0] >= 0f) { if (projectile.velocity.Length() > num6) { projectile.velocity *= 0.98f; } bool flag3 = false; bool flag4 = false; Vector2 vector3 = Main.player[projectile.owner].Center - projectile.Center; if (vector3.Length() > num7) { flag3 = true; if ((double)vector3.Length() > (double)num7 * 1.3) { flag4 = true; } } if (projectile.owner == Main.myPlayer) { if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen) { projectile.ai[0] = -1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } else { Vector2 vector4 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition; float x = vector4.X; float y = vector4.Y; Vector2 vector5 = new Vector2(x, y) - Main.player[projectile.owner].Center; if (vector5.Length() > num7) { vector5.Normalize(); vector5 *= num7; vector5 = Main.player[projectile.owner].Center + vector5; x = vector5.X; y = vector5.Y; } if (projectile.ai[0] != x || projectile.ai[1] != y) { Vector2 value = new Vector2(x, y); Vector2 vector6 = value - Main.player[projectile.owner].Center; if (vector6.Length() > num7 - 1f) { vector6.Normalize(); vector6 *= num7 - 1f; value = Main.player[projectile.owner].Center + vector6; x = value.X; y = value.Y; } projectile.ai[0] = x; projectile.ai[1] = y; projectile.netUpdate = true; } } } if (flag4 && projectile.owner == Main.myPlayer) { projectile.ai[0] = -1f; projectile.netUpdate = true; } if (projectile.ai[0] >= 0f) { if (flag3) { num10 /= 2f; num6 *= 2f; if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } } Vector2 value2 = new Vector2(projectile.ai[0], projectile.ai[1]); Vector2 vector7 = value2 - projectile.Center; projectile.velocity.Length(); if (vector7.Length() > num11) { vector7.Normalize(); vector7 *= num6; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10; } else if (flag) { if ((double)projectile.velocity.Length() < (double)num6 * 0.6) { vector7 = projectile.velocity; vector7.Normalize(); vector7 *= num6 * 0.6f; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector7) / num10; } } else { projectile.velocity *= 0.8f; } if (flag && !flag3 && (double)projectile.velocity.Length() < (double)num6 * 0.6) { projectile.velocity.Normalize(); projectile.velocity *= num6 * 0.6f; } if (action != null) { action(); // Run the action specified. } } } else // projectile is returning to player { num10 = (float)((int)((double)num10 * 0.8)); num6 *= 1.5f; projectile.tileCollide = false; Vector2 vector8 = Main.player[projectile.owner].position - projectile.Center; float num12 = vector8.Length(); if (num12 < num6 + 10f || num12 == 0f) { projectile.Kill(); } else { vector8.Normalize(); vector8 *= num6; projectile.velocity = (projectile.velocity * (num10 - 1f) + vector8) / num10; } } projectile.rotation += rotationSpeed; }
public static void BoomerangAI(int index, float retractTime = 30f, float speed = 9f, float speedAcceleration = 0.4f, ExtraAction action = null, ExtraAction initialize = null) { Terraria.Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } if (projectile.soundDelay == 0) { projectile.soundDelay = 8; Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 7); } if (projectile.ai[0] == 0f) { projectile.ai[1] += 1f; if (projectile.ai[1] >= retractTime) { projectile.ai[0] = 1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } } else { projectile.tileCollide = false; Vector2 vector = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - vector.X; float num2 = Main.player[projectile.owner].position.Y + (float)(Main.player[projectile.owner].height / 2) - vector.Y; float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2)); if (num3 > 3000f) { projectile.Kill(); } num3 = speed / num3; num *= num3; num2 *= num3; if (projectile.velocity.X < num) { projectile.velocity.X = projectile.velocity.X + speedAcceleration; if (projectile.velocity.X < 0f && num > 0f) { projectile.velocity.X = projectile.velocity.X + speedAcceleration; } } else if (projectile.velocity.X > num) { projectile.velocity.X = projectile.velocity.X - speedAcceleration; if (projectile.velocity.X > 0f && num < 0f) { projectile.velocity.X = projectile.velocity.X - speedAcceleration; } } if (projectile.velocity.Y < num2) { projectile.velocity.Y = projectile.velocity.Y + speedAcceleration; if (projectile.velocity.Y < 0f && num2 > 0f) { projectile.velocity.Y = projectile.velocity.Y + speedAcceleration; } } else if (projectile.velocity.Y > num2) { projectile.velocity.Y = projectile.velocity.Y - speedAcceleration; if (projectile.velocity.Y > 0f && num2 < 0f) { projectile.velocity.Y = projectile.velocity.Y - speedAcceleration; } } if (Main.myPlayer == projectile.owner) { Rectangle rectangle = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height); Rectangle value = new Rectangle((int)Main.player[projectile.owner].position.X, (int)Main.player[projectile.owner].position.Y, Main.player[projectile.owner].width, Main.player[projectile.owner].height); if (rectangle.Intersects(value)) { projectile.Kill(); } } } projectile.rotation += 0.4f * (float)projectile.direction; if (action != null) { action(); } }
public static void YoyoAI(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; bool flag = false; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } for (int i = 0; i < projectile.whoAmI; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type) { flag = true; } } if (projectile.owner == Main.myPlayer) { projectile.localAI[0] += 1f; if (flag) { projectile.localAI[0] += (float)Main.rand.Next(10, 31) * 0.1f; } float num = projectile.localAI[0] / 60f; num /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f; if (num > seconds) { projectile.ai[0] = -1f; } } if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } if (!flag) { Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemAnimation = 2; Main.player[projectile.owner].itemTime = 2; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } } if (Utils.HasNaNs(projectile.velocity)) { projectile.Kill(); } projectile.timeLeft = 6; float num2 = length; if (Main.player[projectile.owner].yoyoString) { num2 = num2 * 1.25f + 30f; } num2 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; float num3 = acceleration / ((1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f); float num4 = 14f - num3 / 2f; float num5 = 5f + num3 / 2f; if (flag) { num5 += 20f; } if (projectile.ai[0] >= 0f) { if (projectile.velocity.Length() > num3) { projectile.velocity *= 0.98f; } bool flag3 = false; bool flag4 = false; Vector2 vector = Main.player[projectile.owner].Center - projectile.Center; if (vector.Length() > num2) { flag3 = true; if (vector.Length() > num2 * 1.3f) { flag4 = true; } } if (projectile.owner == Main.myPlayer) { if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen) { projectile.ai[0] = -1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } else { Vector2 vector2 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition; float x = vector2.X; float y = vector2.Y; Vector2 vector3 = new Vector2(x, y) - Main.player[projectile.owner].Center; if (vector3.Length() > num2) { vector3.Normalize(); vector3 *= num2; vector3 = Main.player[projectile.owner].Center + vector3; x = vector3.X; y = vector3.Y; } if (projectile.ai[0] != x || projectile.ai[1] != y) { Vector2 value = new Vector2(x, y); Vector2 vector4 = value - Main.player[projectile.owner].Center; if (vector4.Length() > num2 - 1f) { vector4.Normalize(); vector4 *= num2 - 1f; value = Main.player[projectile.owner].Center + vector4; x = value.X; y = value.Y; } projectile.ai[0] = x; projectile.ai[1] = y; projectile.netUpdate = true; } } } if (flag4 && projectile.owner == Main.myPlayer) { projectile.ai[0] = -1f; projectile.netUpdate = true; } if (projectile.ai[0] >= 0f) { if (flag3) { num4 /= 2f; num3 *= 2f; if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } else if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } else if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } } Vector2 value2 = new Vector2(projectile.ai[0], projectile.ai[1]); Vector2 vector5 = value2 - projectile.Center; projectile.velocity.Length(); if (vector5.Length() > num5) { vector5.Normalize(); vector5 *= num3; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector5) / num4; } else if (flag) { if ((double)projectile.velocity.Length() < (double)num3 * 0.6) { vector5 = projectile.velocity; vector5.Normalize(); vector5 *= num3 * 0.6f; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector5) / num4; } } else { projectile.velocity *= 0.8f; } if (flag && !flag3 && (double)projectile.velocity.Length() < (double)num3 * 0.6) { projectile.velocity.Normalize(); projectile.velocity *= num3 * 0.6f; } if (action != null) { action(); } } } else { num4 = (float)((int)((double)num4 * 0.8)); num3 *= 1.5f; projectile.tileCollide = false; Vector2 vector6 = Main.player[projectile.owner].position - projectile.Center; float num6 = vector6.Length(); if (num6 < num3 + 10f || num6 == 0f) { projectile.Kill(); } else { vector6.Normalize(); vector6 *= num3; projectile.velocity = (projectile.velocity * (num4 - 1f) + vector6) / num4; } } projectile.rotation += rotationSpeed; }
public static void Explode(int index, int sizeX, int sizeY, ExtraAction visualAction = null) { Terraria.Projectile projectile = Main.projectile[index]; if (!projectile.active) { return; } projectile.tileCollide = false; projectile.alpha = 255; projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = sizeX; projectile.height = sizeY; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); projectile.Damage(); Main.projectileIdentity[projectile.owner, projectile.identity] = -1; projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = (int)((float)sizeX / 5.8f); projectile.height = (int)((float)sizeY / 5.8f); projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); if (visualAction == null) { for (int i = 0; i < 30; i++) { int num = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f); Main.dust[num].velocity *= 1.4f; } for (int j = 0; j < 20; j++) { int num2 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 3.5f); Main.dust[num2].noGravity = true; Main.dust[num2].velocity *= 7f; num2 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f); Main.dust[num2].velocity *= 3f; } for (int k = 0; k < 2; k++) { float scaleFactor = 0.4f; if (k == 1) { scaleFactor = 0.8f; } int num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore = Main.gore[num3]; gore.velocity.X = gore.velocity.X + 1f; Gore gore2 = Main.gore[num3]; gore2.velocity.Y = gore2.velocity.Y + 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore3 = Main.gore[num3]; gore3.velocity.X = gore3.velocity.X - 1f; Gore gore4 = Main.gore[num3]; gore4.velocity.Y = gore4.velocity.Y + 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore5 = Main.gore[num3]; gore5.velocity.X = gore5.velocity.X + 1f; Gore gore6 = Main.gore[num3]; gore6.velocity.Y = gore6.velocity.Y - 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore7 = Main.gore[num3]; gore7.velocity.X = gore7.velocity.X - 1f; Gore gore8 = Main.gore[num3]; gore8.velocity.Y = gore8.velocity.Y - 1f; } return; } visualAction(); }
public static void FlailAI(int index, float initialRange = 160f, float weaponOutRange = 300f, float retractRange = 100f, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } Main.player[projectile.owner].itemAnimation = 10; Main.player[projectile.owner].itemTime = 10; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter; Vector2 vector = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num = mountedCenter.X - vector.X; float num2 = mountedCenter.Y - vector.Y; float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2)); if (projectile.ai[0] == 0f) { projectile.tileCollide = true; if (num3 > initialRange) { projectile.ai[0] = 1f; projectile.netUpdate = true; } else if (!Main.player[projectile.owner].channel) { if (projectile.velocity.Y < 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.9f; } projectile.velocity.Y = projectile.velocity.Y + 1f; projectile.velocity.X = projectile.velocity.X * 0.9f; } } else if (projectile.ai[0] == 1f) { float num4 = 14f / Main.player[projectile.owner].meleeSpeed; float num5 = 0.9f / Main.player[projectile.owner].meleeSpeed; Math.Abs(num); Math.Abs(num2); if (projectile.ai[1] == 1f) { projectile.tileCollide = false; } if (!Main.player[projectile.owner].channel || num3 > weaponOutRange || !projectile.tileCollide) { projectile.ai[1] = 1f; if (projectile.tileCollide) { projectile.netUpdate = true; } projectile.tileCollide = false; if (num3 < 20f) { projectile.Kill(); } } if (!projectile.tileCollide) { num5 *= 2f; } int num6 = (int)retractRange; if (num3 > (float)num6 || !projectile.tileCollide) { num3 = num4 / num3; num *= num3; num2 *= num3; new Vector2(projectile.velocity.X, projectile.velocity.Y); float num7 = num - projectile.velocity.X; float num8 = num2 - projectile.velocity.Y; float num9 = (float)Math.Sqrt((double)(num7 * num7 + num8 * num8)); num9 = num5 / num9; num7 *= num9; num8 *= num9; projectile.velocity.X = projectile.velocity.X * 0.98f; projectile.velocity.Y = projectile.velocity.Y * 0.98f; projectile.velocity.X = projectile.velocity.X + num7; projectile.velocity.Y = projectile.velocity.Y + num8; } else { if (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y) < 6f) { projectile.velocity.X = projectile.velocity.X * 0.96f; projectile.velocity.Y = projectile.velocity.Y + 0.2f; } if (Main.player[projectile.owner].velocity.X == 0f) { projectile.velocity.X = projectile.velocity.X * 0.96f; } } } if (projectile.velocity.X < 0f) { projectile.rotation -= (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } else { projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } if (action != null) { action(); } }
static public ExtraAction Create() { ExtraAction obj = new ExtraAction(); return(obj); }
public static void FlailAI(int index, float initialRange = 160f, float weaponOutRange = 300f, float retractRange = 100f, ExtraAction action = null, ExtraAction initialize = null) { Terraria.Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } Main.player[projectile.owner].itemAnimation = 10; Main.player[projectile.owner].itemTime = 10; if (projectile.position.X + (float)(projectile.width / 2) > Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2)) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter; Vector2 vector = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num = mountedCenter.X - vector.X; float num2 = mountedCenter.Y - vector.Y; float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2)); if (projectile.ai[0] == 0f) { projectile.tileCollide = true; if (num3 > initialRange) { projectile.ai[0] = 1f; projectile.netUpdate = true; } else if (!Main.player[projectile.owner].channel) { if (projectile.velocity.Y < 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.9f; } projectile.velocity.Y = projectile.velocity.Y + 1f; projectile.velocity.X = projectile.velocity.X * 0.9f; } } else if (projectile.ai[0] == 1f) { float num4 = 14f / Main.player[projectile.owner].meleeSpeed; float num5 = 0.9f / Main.player[projectile.owner].meleeSpeed; Math.Abs(num); Math.Abs(num2); if (projectile.ai[1] == 1f) { projectile.tileCollide = false; } if (!Main.player[projectile.owner].channel || num3 > weaponOutRange || !projectile.tileCollide) { projectile.ai[1] = 1f; if (projectile.tileCollide) { projectile.netUpdate = true; } projectile.tileCollide = false; if (num3 < 20f) { projectile.Kill(); } } if (!projectile.tileCollide) { num5 *= 2f; } int num6 = (int)retractRange; if (num3 > (float)num6 || !projectile.tileCollide) { num3 = num4 / num3; num *= num3; num2 *= num3; new Vector2(projectile.velocity.X, projectile.velocity.Y); float num7 = num - projectile.velocity.X; float num8 = num2 - projectile.velocity.Y; float num9 = (float)Math.Sqrt((double)(num7 * num7 + num8 * num8)); num9 = num5 / num9; num7 *= num9; num8 *= num9; projectile.velocity.X = projectile.velocity.X * 0.98f; projectile.velocity.Y = projectile.velocity.Y * 0.98f; projectile.velocity.X = projectile.velocity.X + num7; projectile.velocity.Y = projectile.velocity.Y + num8; } else { if (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y) < 6f) { projectile.velocity.X = projectile.velocity.X * 0.96f; projectile.velocity.Y = projectile.velocity.Y + 0.2f; } if (Main.player[projectile.owner].velocity.X == 0f) { projectile.velocity.X = projectile.velocity.X * 0.96f; } } } if (projectile.velocity.X < 0f) { projectile.rotation -= (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } else { projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f; } if (action != null) { action(); } }
public static void FighterAI(int index, float speed = 0.1F, float acceleration = 0.1F, ExtraAction initialize = null, ExtraAction action = null) { NPC npc = Main.npc[index]; if (initialize != null && npc.localAI[3] == 0) { initialize(); npc.localAI[3] = 1; } bool idle = false; if ((double)npc.velocity.X == 0.0) { idle = true; } if (npc.justHit) { idle = false; } int cooldown = 60; bool moving = false; // If the NPC is grounded and moving. if ((double)npc.velocity.Y == 0.0 && ((double)npc.velocity.X > 0.0 && npc.direction < 0 || (double)npc.velocity.X < 0.0 && npc.direction > 0)) { moving = true; } if ((double)npc.position.X == (double)npc.oldPosition.X || (double)npc.ai[3] >= (double)cooldown || moving) { ++npc.ai[3]; } else if ((double)Math.Abs(npc.velocity.X) > 0.9 && (double)npc.ai[3] > 0.0) { --npc.ai[3]; } if ((double)npc.ai[3] > (double)(cooldown * 10)) { npc.ai[3] = 0.0f; } if (npc.justHit) { npc.ai[3] = 0.0f; } if ((double)npc.ai[3] == (double)cooldown) { npc.netUpdate = true; } // Find the closest target npc.TargetClosest(true); if ((double)npc.velocity.X < -(double)speed || (double)npc.velocity.X > (double)speed) { if ((double)npc.velocity.Y == 0.0) { float vecX = npc.velocity.X * 0.8f; float vecY = npc.velocity.Y * 0.8f; npc.velocity.X = vecX; npc.velocity.Y = vecY; } } else if ((double)npc.velocity.X < (double)speed && npc.direction == 1) { npc.velocity.X = npc.velocity.X + acceleration; if ((double)npc.velocity.X > (double)speed) { npc.velocity.X = speed; } } else if ((double)npc.velocity.X > -(double)speed && npc.direction == -1) { npc.velocity.X = npc.velocity.X - acceleration; if ((double)npc.velocity.X < -(double)speed) { npc.velocity.X = -speed; } } bool flag11 = false; if ((double)npc.velocity.Y == 0.0) { int index1 = (int)((double)npc.position.Y + (double)npc.height + 7.0) / 16; int num1 = (int)npc.position.X / 16; int num2 = (int)((double)npc.position.X + (double)npc.width) / 16; for (int index2 = num1; index2 < num2; ++index2) { if (Main.tile[index2, index1] == null) { return; } if (Main.tile[index2, index1].nactive() && Main.tileSolid[(int)Main.tile[index2, index1].type]) { flag11 = true; break; } } } if ((double)npc.velocity.Y >= 0.0) { int num1 = 0; if ((double)npc.velocity.X < 0.0) { num1 = -1; } if ((double)npc.velocity.X > 0.0) { num1 = 1; } float posX = npc.position.X; float posY = npc.position.Y; posX += npc.velocity.X; int index1 = (int)(((double)posX + (double)(npc.width / 2) + (double)((npc.width / 2 + 1) * num1)) / 16.0); int index2 = (int)(((double)posY + (double)npc.height - 1.0) / 16.0); if (Main.tile[index1, index2] == null) { Main.tile[index1, index2] = new Tile(); } if (Main.tile[index1, index2 - 1] == null) { Main.tile[index1, index2 - 1] = new Tile(); } if (Main.tile[index1, index2 - 2] == null) { Main.tile[index1, index2 - 2] = new Tile(); } if (Main.tile[index1, index2 - 3] == null) { Main.tile[index1, index2 - 3] = new Tile(); } if (Main.tile[index1, index2 + 1] == null) { Main.tile[index1, index2 + 1] = new Tile(); } if (Main.tile[index1 - num1, index2 - 3] == null) { Main.tile[index1 - num1, index2 - 3] = new Tile(); } if ((double)(index1 * 16) < (double)posX + (double)npc.width && (double)(index1 * 16 + 16) > (double)posX && (Main.tile[index1, index2].nactive() && !Main.tile[index1, index2].topSlope() && (!Main.tile[index1, index2 - 1].topSlope() && Main.tileSolid[(int)Main.tile[index1, index2].type]) && !Main.tileSolidTop[(int)Main.tile[index1, index2].type] || Main.tile[index1, index2 - 1].halfBrick() && Main.tile[index1, index2 - 1].nactive()) && ((!Main.tile[index1, index2 - 1].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 1].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 1].type] || Main.tile[index1, index2 - 1].halfBrick() && (!Main.tile[index1, index2 - 4].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 4].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 4].type])) && ((!Main.tile[index1, index2 - 2].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 2].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 2].type]) && (!Main.tile[index1, index2 - 3].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 3].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 3].type]) && (!Main.tile[index1 - num1, index2 - 3].nactive() || !Main.tileSolid[(int)Main.tile[index1 - num1, index2 - 3].type])))) { float num2 = (float)(index2 * 16); if (Main.tile[index1, index2].halfBrick()) { num2 += 8f; } if (Main.tile[index1, index2 - 1].halfBrick()) { num2 -= 8f; } if ((double)num2 < (double)posY + (double)npc.height) { float num3 = posY + (float)npc.height - num2; float num4 = 16.1f; if ((double)num3 <= (double)num4) { npc.gfxOffY += npc.position.Y + (float)npc.height - num2; npc.position.Y = num2 - (float)npc.height; npc.stepSpeed = (double)num3 >= 9.0 ? 2f : 1f; } } } } if (flag11) { int index1 = (int)(((double)npc.position.X + (double)(npc.width / 2) + (double)(15 * npc.direction)) / 16.0); int index2 = (int)(((double)npc.position.Y + (double)npc.height - 15.0) / 16.0); if (Main.tile[index1, index2] == null) { Main.tile[index1, index2] = new Tile(); } if (Main.tile[index1, index2 - 1] == null) { Main.tile[index1, index2 - 1] = new Tile(); } if (Main.tile[index1, index2 - 2] == null) { Main.tile[index1, index2 - 2] = new Tile(); } if (Main.tile[index1, index2 - 3] == null) { Main.tile[index1, index2 - 3] = new Tile(); } if (Main.tile[index1, index2 + 1] == null) { Main.tile[index1, index2 + 1] = new Tile(); } if (Main.tile[index1 + npc.direction, index2 - 1] == null) { Main.tile[index1 + npc.direction, index2 - 1] = new Tile(); } if (Main.tile[index1 + npc.direction, index2 + 1] == null) { Main.tile[index1 + npc.direction, index2 + 1] = new Tile(); } if (Main.tile[index1 - npc.direction, index2 + 1] == null) { Main.tile[index1 - npc.direction, index2 + 1] = new Tile(); } Main.tile[index1, index2 + 1].halfBrick(); if (Main.tile[index1, index2 - 1].nactive() && ((int)Main.tile[index1, index2 - 1].type == 10 || (int)Main.tile[index1, index2 - 1].type == 388)) { ++npc.ai[2]; npc.ai[3] = 0.0f; if ((double)npc.ai[2] >= 60.0) { npc.velocity.X = 0.5f * -(float)npc.direction; int num1 = 5; if ((int)Main.tile[index1, index2 - 1].type == 388) { num1 = 2; } npc.ai[1] += (float)num1; if (npc.type == 27) { ++npc.ai[1]; } if (npc.type == 31 || npc.type == 294 || (npc.type == 295 || npc.type == 296)) { npc.ai[1] += 6f; } npc.ai[2] = 0.0f; bool flag6 = false; if ((double)npc.ai[1] >= 10.0) { flag6 = true; npc.ai[1] = 10f; } if (npc.type == 460) { flag6 = true; } WorldGen.KillTile(index1, index2 - 1, true, false, false); if ((Main.netMode != 1 || !flag6) && (flag6 && Main.netMode != 1)) { if (TileLoader.OpenDoorID(Main.tile[index1, index2 - 1]) >= 0) { bool flag7 = WorldGen.OpenDoor(index1, index2 - 1, npc.direction); if (!flag7) { npc.ai[3] = (float)cooldown; npc.netUpdate = true; } if (Main.netMode == 2 && flag7) { NetMessage.SendData(19, -1, -1, null, 0, (float)index1, (float)(index2 - 1), (float)npc.direction, 0, 0, 0); } } if ((int)Main.tile[index1, index2 - 1].type == 388) { bool flag7 = WorldGen.ShiftTallGate(index1, index2 - 1, false); if (!flag7) { npc.ai[3] = (float)cooldown; npc.netUpdate = true; } if (Main.netMode == 2 && flag7) { NetMessage.SendData(19, -1, -1, null, 4, (float)index1, (float)(index2 - 1), 0.0f, 0, 0, 0); } } } } } else { if ((double)npc.velocity.X < 0.0 && npc.spriteDirection == -1 || (double)npc.velocity.X > 0.0 && npc.spriteDirection == 1) { if (npc.height >= 32 && Main.tile[index1, index2 - 2].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 2].type]) { if (Main.tile[index1, index2 - 3].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 3].type]) { npc.velocity.Y = -8f; npc.netUpdate = true; } else { npc.velocity.Y = -7f; npc.netUpdate = true; } } else if (Main.tile[index1, index2 - 1].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 1].type]) { npc.velocity.Y = -6f; npc.netUpdate = true; } else if ((double)npc.position.Y + (double)npc.height - (double)(index2 * 16) > 20.0 && Main.tile[index1, index2].nactive() && (!Main.tile[index1, index2].topSlope() && Main.tileSolid[(int)Main.tile[index1, index2].type])) { npc.velocity.Y = -5f; npc.netUpdate = true; } else if (npc.directionY < 0 && (!Main.tile[index1, index2 + 1].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 + 1].type]) && (!Main.tile[index1 + npc.direction, index2 + 1].nactive() || !Main.tileSolid[(int)Main.tile[index1 + npc.direction, index2 + 1].type])) { npc.velocity.Y = -8f; npc.velocity.X = npc.velocity.X * 1.5f; npc.netUpdate = true; } else { npc.ai[1] = 0.0f; npc.ai[2] = 0.0f; } if ((double)npc.velocity.Y == 0.0 && idle && (double)npc.ai[3] == 1.0) { npc.velocity.Y = -5f; } } } } else { npc.ai[1] = 0.0f; npc.ai[2] = 0.0f; } if (action != null) { action(); } }
public static void YoyoAi(int index, float seconds, float length, float acceleration = 14f, float rotationSpeed = 0.45f, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; bool haveProj = false; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } for (int i = 0; i < projectile.whoAmI; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && Main.projectile[i].type == projectile.type) { haveProj = true; } } if (projectile.owner == Main.myPlayer) { projectile.localAI[0] += 1f; if (haveProj) { projectile.localAI[0] += Main.rand.Next(10, 31) * 0.1f; } float time = projectile.localAI[0] / 60f; time /= (1f + Main.player[projectile.owner].meleeSpeed) / 2f; if (time > seconds) { projectile.ai[0] = -1f; } } bool flag2 = false; if (Main.player[projectile.owner].dead) { projectile.Kill(); return; } if (!flag2 && !haveProj) { Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemAnimation = 2; Main.player[projectile.owner].itemTime = 2; if (projectile.position.X + projectile.width / 2 > Main.player[projectile.owner].position.X + Main.player[projectile.owner].width / 2) { Main.player[projectile.owner].ChangeDir(1); projectile.direction = 1; } else { Main.player[projectile.owner].ChangeDir(-1); projectile.direction = -1; } } if (projectile.velocity.HasNaNs()) { projectile.Kill(); } projectile.timeLeft = 6; float long1 = length; if (Main.player[projectile.owner].yoyoString) { long1 = long1 * 1.25f + 30f; } long1 /= (1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f; float acc = acceleration / ((1f + Main.player[projectile.owner].meleeSpeed * 3f) / 4f); float num4 = 14f - acc / 2f; float num5 = 5f + acc / 2f; if (haveProj) { num5 += 20f; } if (projectile.ai[0] >= 0f) { if (projectile.velocity.Length() > acc) { projectile.velocity *= 0.98f; } bool reachMax = false; bool reachMax2 = false; Vector2 vector = Main.player[projectile.owner].Center - projectile.Center; if (vector.Length() > long1) { reachMax = true; if (vector.Length() > long1 * 1.3) { reachMax2 = true; } } if (projectile.owner == Main.myPlayer) { if (!Main.player[projectile.owner].channel || Main.player[projectile.owner].stoned || Main.player[projectile.owner].frozen) { projectile.ai[0] = -1f; projectile.ai[1] = 0f; projectile.netUpdate = true; } else { Vector2 vector2 = Main.ReverseGravitySupport(Main.MouseScreen, 0f) + Main.screenPosition; float x = vector2.X; float y = vector2.Y; Vector2 vector3 = new Vector2(x, y) - Main.player[projectile.owner].Center; if (vector3.Length() > long1) { vector3.Normalize(); vector3 *= long1; vector3 = Main.player[projectile.owner].Center + vector3; x = vector3.X; y = vector3.Y; } if (projectile.ai[0] != x || projectile.ai[1] != y) { Vector2 vector4 = new Vector2(x, y); Vector2 vector5 = vector4 - Main.player[projectile.owner].Center; if (vector5.Length() > long1 - 1f) { vector5.Normalize(); vector5 *= long1 - 1f; vector4 = Main.player[projectile.owner].Center + vector5; x = vector4.X; y = vector4.Y; } projectile.ai[0] = x; projectile.ai[1] = y; projectile.netUpdate = true; } } } if (reachMax2 && projectile.owner == Main.myPlayer) { projectile.ai[0] = -1f; projectile.netUpdate = true; } if (projectile.ai[0] >= 0f) { if (reachMax) { num4 /= 2f; acc *= 2f; if (projectile.Center.X > Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y > Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } if (projectile.Center.X < Main.player[projectile.owner].Center.X && projectile.velocity.X > 0f) { projectile.velocity.X = projectile.velocity.X * 0.5f; } if (projectile.Center.Y < Main.player[projectile.owner].Center.Y && projectile.velocity.Y > 0f) { projectile.velocity.Y = projectile.velocity.Y * 0.5f; } } Vector2 vector6 = new Vector2(projectile.ai[0], projectile.ai[1]); Vector2 difference = vector6 - projectile.Center; projectile.velocity.Length(); if (difference.Length() > num5) { difference.Normalize(); difference *= acc; projectile.velocity = (projectile.velocity * (num4 - 1f) + difference) / num4; } else if (haveProj) { if (projectile.velocity.Length() < acc * 0.6) { difference = projectile.velocity; difference.Normalize(); difference *= acc * 0.6f; projectile.velocity = (projectile.velocity * (num4 - 1f) + difference) / num4; } } else { projectile.velocity *= 0.8f; } if (haveProj && !reachMax && projectile.velocity.Length() < acc * 0.6) { projectile.velocity.Normalize(); projectile.velocity *= acc * 0.6f; } if (action != null) { action(); } } } else { num4 = (int)(num4 * 0.8); acc *= 1.5f; projectile.tileCollide = false; Vector2 diff = Main.player[projectile.owner].position - projectile.Center; float len = diff.Length(); if (len < acc + 10f || len == 0f) { projectile.Kill(); } else { diff.Normalize(); diff *= acc; projectile.velocity = (projectile.velocity * (num4 - 1f) + diff) / num4; } } projectile.rotation += rotationSpeed; }
public override Action Reverse() { return(ExtraAction.Create()); }
public static void SpearAi(int index, float protractSpeed = 1.5f, float retractSpeed = 1.4f, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; Player p = Main.player[projectile.owner]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } Vector2 playerCenter = p.RotatedRelativePoint(p.MountedCenter, true); projectile.direction = p.direction; p.heldProj = projectile.whoAmI; p.itemTime = Main.player[projectile.owner].itemAnimation; projectile.position = playerCenter - projectile.Size / 2; if (!p.frozen) { if (projectile.ai[0] == 0f) { projectile.ai[0] = 3f; projectile.netUpdate = true; } if (p.itemAnimation < p.itemAnimationMax / 3) { projectile.ai[0] -= retractSpeed; } else { projectile.ai[0] += protractSpeed; } } projectile.position += projectile.velocity * projectile.ai[0]; if (p.itemAnimation == 0) { projectile.Kill(); } projectile.rotation = (float)Math.Atan2(projectile.velocity.Y, projectile.velocity.X) + 2.355f; if (projectile.spriteDirection == -1) { projectile.rotation -= 1.57f; } if (action != null) { action(); } }
public override Action Clone() { return(ExtraAction.Create()); }
public static void SpearAI(int index, float protractSpeed = 1.5f, float retractSpeed = 1.4f, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } Vector2 vector = Main.player[projectile.owner].RotatedRelativePoint(Main.player[projectile.owner].MountedCenter, true); projectile.direction = Main.player[projectile.owner].direction; Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemTime = Main.player[projectile.owner].itemAnimation; projectile.position.X = vector.X - (float)(projectile.width / 2); projectile.position.Y = vector.Y - (float)(projectile.height / 2); if (!Main.player[projectile.owner].frozen) { if (projectile.ai[0] == 0f) { projectile.ai[0] = 3f; projectile.netUpdate = true; } if (Main.player[projectile.owner].itemAnimation < Main.player[projectile.owner].itemAnimationMax / 3) { projectile.ai[0] -= retractSpeed; } else { projectile.ai[0] += protractSpeed; } } projectile.position += projectile.velocity * projectile.ai[0]; if (Main.player[projectile.owner].itemAnimation == 0) { projectile.Kill(); } projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f; if (projectile.spriteDirection == -1) { projectile.rotation -= 1.57f; } if (action != null) { action(); } }
public static void ThrowingKnifeAI(int index, int airTime = 20, ExtraAction action = null, ExtraAction initialize = null) { Terraria.Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0f) { projectile.localAI[1] = 1f; initialize(); } projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.03f * (float)projectile.direction; projectile.localAI[0] += 1f; if (projectile.localAI[0] >= (float)airTime) { projectile.velocity.Y = projectile.velocity.Y + 0.4f; projectile.velocity.X = projectile.velocity.X * 0.98f; } else { projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; } if (projectile.velocity.Y > 16f) { projectile.velocity.Y = 16f; } if (action != null) { action(); } }
public static void Explode(int index, int sizeX, int sizeY, ExtraAction visualAction = null) { Projectile projectile = Main.projectile[index]; if (!projectile.active) { return; } projectile.tileCollide = false; projectile.alpha = 255; projectile.position.X = projectile.position.X + projectile.width / 2; projectile.position.Y = projectile.position.Y + projectile.height / 2; projectile.width = sizeX; projectile.height = sizeY; projectile.position.X = projectile.position.X - projectile.width / 2; projectile.position.Y = projectile.position.Y - projectile.height / 2; projectile.Damage(); Main.projectileIdentity[projectile.owner, projectile.identity] = -1; projectile.position.X = projectile.position.X + projectile.width / 2; projectile.position.Y = projectile.position.Y + projectile.height / 2; projectile.width = (int)(sizeX / 5.8f); projectile.height = (int)(sizeY / 5.8f); projectile.position.X = projectile.position.X - projectile.width / 2; projectile.position.Y = projectile.position.Y - projectile.height / 2; if (visualAction == null) { for (int i = 0; i < 30; i++) { int num = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f); Main.dust[num].velocity *= 1.4f; } for (int j = 0; j < 20; j++) { int num2 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 3.5f); Main.dust[num2].noGravity = true; Main.dust[num2].velocity *= 7f; num2 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f); Main.dust[num2].velocity *= 3f; } for (int k = 0; k < 2; k++) { float scaleFactor = 0.4f; if (k == 1) { scaleFactor = 0.8f; } int num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore = Main.gore[num3]; gore.velocity.X = gore.velocity.X + 1f; Gore gore2 = Main.gore[num3]; gore2.velocity.Y = gore2.velocity.Y + 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore3 = Main.gore[num3]; gore3.velocity.X = gore3.velocity.X - 1f; Gore gore4 = Main.gore[num3]; gore4.velocity.Y = gore4.velocity.Y + 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore5 = Main.gore[num3]; gore5.velocity.X = gore5.velocity.X + 1f; Gore gore6 = Main.gore[num3]; gore6.velocity.Y = gore6.velocity.Y - 1f; num3 = Gore.NewGore(new Vector2(projectile.position.X, projectile.position.Y), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num3].velocity *= scaleFactor; Gore gore7 = Main.gore[num3]; gore7.velocity.X = gore7.velocity.X - 1f; Gore gore8 = Main.gore[num3]; gore8.velocity.Y = gore8.velocity.Y - 1f; } return; } visualAction(); }
/// <summary> /// /// </summary> /// <param name="index">Index of the projectile in the Main.projecile array.</param> /// <param name="protractSpeed">The speed at which the spear shoots outward (protracts).</param> /// <param name="retractSpeed">The speed at which the spear shoots back (retracts).</param> /// <param name="action">An action to perform when the projectile is out in front of the player.</param> /// <param name="initialize">An action to perform once when initializing.</param> public static void SpearAI(int index, float protractSpeed = 1.5F, float retractSpeed = 1.4F, ExtraAction action = null, ExtraAction initialize = null) { Projectile projectile = Main.projectile[index]; if (initialize != null && projectile.localAI[1] == 0) { projectile.localAI[1] = 1; initialize(); } Vector2 vector21 = Main.player[projectile.owner].RotatedRelativePoint(Main.player[projectile.owner].MountedCenter, true); projectile.direction = Main.player[projectile.owner].direction; Main.player[projectile.owner].heldProj = projectile.whoAmI; Main.player[projectile.owner].itemTime = Main.player[projectile.owner].itemAnimation; projectile.position.X = vector21.X - (float)(projectile.width / 2); projectile.position.Y = vector21.Y - (float)(projectile.height / 2); if (!Main.player[projectile.owner].frozen) { if (projectile.ai[0] == 0f) { projectile.ai[0] = 3f; projectile.netUpdate = true; } if (Main.player[projectile.owner].itemAnimation < Main.player[projectile.owner].itemAnimationMax / 3) { projectile.ai[0] -= retractSpeed; } else { projectile.ai[0] += protractSpeed; } } projectile.position += projectile.velocity * projectile.ai[0]; if (Main.player[projectile.owner].itemAnimation == 0) { projectile.Kill(); } projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f; if (projectile.spriteDirection == -1) { projectile.rotation -= 1.57f; } if (action != null) { action(); // Run the action specified. } }
public static ExtraAction Create() { ExtraAction ret = new ExtraAction(); return(ret); }