public override void Update(TerraGuardian guardian) { IgnoreCombat = true; if (!MountUser.mount.Active) { InUse = false; return; } if (TryReachingPlayer(guardian, MountUser))//guardian.HitBox.Intersects(Target.getRect())) { guardian.DoSitOnPlayerMount(true); InUse = false; } else { if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } } }
public override void Update(TerraGuardian guardian) { switch (Step) { case 0: { if (guardian.Inventory[ItemSlot].type == 0 || guardian.Inventory[ItemSlot].stack < ItemStack) { InUse = false; return; } if (guardian.UsingFurniture) { guardian.LeaveFurniture(true); } if (Formally) { ChangeStep(); } else { ChangeStep(2); } } break; case 1: { Vector2 TargetPosition = Vector2.Zero; if (player != null) { TargetPosition = player.Bottom; } else { TargetPosition = tg.Position; } if (guardian.Position.X > TargetPosition.X) { guardian.MoveLeft = true; guardian.MoveRight = false; } else { guardian.MoveRight = true; guardian.MoveLeft = false; } if (Time >= 10 * 60) { guardian.Position = TargetPosition; guardian.SetFallStart(); } if (TargetPosition.X >= guardian.Position.X - guardian.Width * 0.5f && TargetPosition.X < guardian.Position.X + guardian.Width * 0.5f && TargetPosition.Y >= guardian.Position.Y - guardian.Height && TargetPosition.Y - 24 < guardian.Position.Y) { ChangeStep(); } } break; case 2: { if (guardian.Inventory[ItemSlot].type == 0) { InUse = false; //Where's the item I was going to give? guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.DeliveryItemMissing, "*They seems to have wanted to deliver something, but can't find it in their inventory.*")); return; } if (StepStart) { if (player != null) { byte EmptySlot = 255; byte MaxSlots = 50; if (guardian.Inventory[ItemSlot].ammo > 0) { MaxSlots = 54; } for (byte i = 0; i < MaxSlots; i++) { if (player.inventory[i].type == 0) { EmptySlot = i; } } if (EmptySlot == 255) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull, "*It seems like [target] have no room for what they wanted to give.*"). Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name)); guardian.SaySomething(Message); InUse = false; } } else { int EmptySlot = -1; for (int i = 0; i < guardian.Inventory.Length; i++) { if (guardian.Inventory[i].type == 0) { EmptySlot = i; } } if (EmptySlot == 255) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull, "*It seems like you have no room for what they wanted to give [target].*").Replace("[target]", tg.Name); guardian.SaySomething(Message); InUse = false; } } } else if (Time >= 60) { if (player != null) { byte EmptySlot = 255; byte MaxSlots = 50; if (guardian.Inventory[ItemSlot].ammo > 0) { MaxSlots = 54; } for (byte i = 0; i < MaxSlots; i++) { if (player.inventory[i].type == 0) { EmptySlot = i; } } if (EmptySlot == 255) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull, "*It seems like [target] have no room for what they wanted to give.*"). Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name)); guardian.SaySomething(Message); } else { Item item = guardian.Inventory[ItemSlot].DeepClone(); player.GetItem(player.whoAmI, item); guardian.Inventory[ItemSlot].SetDefaults(0, true); string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryGiveItem, "*" + guardian.Name + " gave [target] some [item].*"). Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name)). Replace("[item]", item.Name); guardian.SaySomething(Message); } } else { int EmptySlot = -1; for (int i = 0; i < guardian.Inventory.Length; i++) { if (guardian.Inventory[i].type == 0) { EmptySlot = i; } } if (EmptySlot == 255) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull, "*It seems like [target] have no room for what they wanted to give.*"). Replace("[target]", tg.Name); guardian.SaySomething(Message); } else { Item item = guardian.Inventory[ItemSlot].DeepClone(); tg.Inventory[EmptySlot] = item; guardian.Inventory[EmptySlot].SetDefaults(0, true); string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryGiveItem, "*" + guardian.Name + " gave [target] some [item].*"). Replace("[target]", tg.Name). Replace("[item]", item.Name); guardian.SaySomething(Message); } } InUse = false; } } break; } }
public override void Update(TerraGuardian guardian) { IgnoreCombat = true; AvoidItemUsage = true; if (guardian.UsingFurniture) { guardian.LeaveFurniture(); } switch (Step) { case 0: if (StepStart) { if (Main.rand.NextDouble() < 0.01f) { Main.PlaySound(29, (int)guardian.Position.X, (int)guardian.CenterY, 89); } guardian.DisplayEmotion(TerraGuardian.Emotions.Question); int ItemPosition = BoxPosition; BoxID = guardian.Inventory[BoxPosition].type; guardian.Inventory[ItemPosition].SetDefaults(0, true); } if (Time >= 120) { ChangeStep(); } break; case 1: if (StepStart) { guardian.DisplayEmotion(TerraGuardian.Emotions.Alarmed); } if (Time % 20 == 0) { //Spawn item every 5 ticks; int ItemID = Terraria.ID.ItemID.CopperCoin, Stack = Main.rand.Next(10, 26); if (Main.rand.Next(100) == 0) { ItemID = Terraria.ID.ItemID.PlatinumCoin; Stack = Main.rand.Next(1, 3); } else if (Main.rand.Next(25) == 0) { ItemID = Terraria.ID.ItemID.GoldCoin; Stack = Main.rand.Next(3, 5); } else if (Main.rand.Next(5) == 0) { ItemID = Terraria.ID.ItemID.SilverCoin; Stack = Main.rand.Next(5, 20); } else if (Main.rand.Next(5) == 0) { ItemID = Terraria.ID.ItemID.WoodenCrate; Stack = Main.rand.Next(3, 6); } else if (Main.rand.Next(15) == 0) { ItemID = Terraria.ID.ItemID.IronCrate; Stack = Main.rand.Next(2, 4); } else if (Main.rand.Next(25) == 0) { ItemID = Terraria.ID.ItemID.GoldenCrate; Stack = Main.rand.Next(1, 3); } else if (Main.rand.Next(3) == 0) { ItemID = Terraria.ID.ItemID.HerbBag; Stack = 1; } Item.NewItem(guardian.CenterPosition, ItemID, Stack); } if (Time >= 120) { ChangeStep(); } break; case 2: if (StepStart) { guardian.DisplayEmotion(TerraGuardian.Emotions.Happy); guardian.IncreaseFriendshipProgress(5); guardian.Data.GiftGiven = true; InUse = false; } break; } }
public override void Update(TerraGuardian guardian) { if (guardian.OwnerPos == -1) { InUse = false; return; } if (!PlayerWasKnockedOut && guardian.AfkCounter < 60) { InUse = false; return; } if (guardian.UsingFurniture) { guardian.LeaveFurniture(false); } Player defended = Main.player[guardian.OwnerPos]; PlayerMod defendedPm = defended.GetModPlayer <PlayerMod>(); /*if (guardian.GrabbingPlayer) * { * guardian.PlayerCanEscapeGrab = true; * DelayBeforePlacingOnTheGround--; * if (guardian.Velocity.X != 0 || guardian.Velocity.Y != 0) * DelayBeforePlacingOnTheGround = 5 * 60; * return; * } * { * int XStart = (int)(defended.position.X * (1f / 16)), XEnd = (int)((defended.position.X + defended.width) * (1f / 16)); * int YCheck = (int)(defended.position.Y * (1f / 16)); * bool TryPickingUpPlayer = false; * for (int x = XStart; x < XEnd; x++) * { * if(MainMod.IsDangerousTile(x, YCheck, defended.fireWalk)) * { * TryPickingUpPlayer = true; * break; * } * } * if (TryPickingUpPlayer) * { * DelayBeforePlacingOnTheGround = 5 * 60; * if(TryReachingPlayer(guardian, defended)) * { * guardian.AttemptToGrabPlayer(); * } * return; * } * }*/ const int Offset = 7 * 2; float DefendX = defended.Center.X - Offset * defended.direction; if (defendedPm.KnockedOut && (defendedPm.BeingCarriedByGuardian || (defendedPm.ControllingGuardian && defendedPm.Guardian.BeingCarriedByGuardian))) { Action = 2; } if (Action == 2) { if (guardian.Position.X + guardian.Velocity.X * 0.5f > DefendX) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } PlayerMod pm = defendedPm; if (pm.ControllingGuardian) { pm.Guardian.AddBuff(ModContent.BuffType <Buffs.Defended>(), 3, true); if (pm.Guardian.KnockedOut) { pm.Guardian.ReviveBoost++; } else { if (guardian.AfkCounter < ProtectModeAutoTriggerTime && PlayerWasKnockedOut) { InUse = false; } } if (!pm.Guardian.BeingCarriedByGuardian) { Action = 0; } } else { defended.AddBuff(ModContent.BuffType <Buffs.Defended>(), 3); if (pm.KnockedOut) { pm.ReviveBoost++; } else { if (guardian.AfkCounter < ProtectModeAutoTriggerTime && PlayerWasKnockedOut) { InUse = false; } } if (pm.BeingCarriedByGuardian) { Action = 0; } } } else if (Action == 0) { if (guardian.PlayerMounted || guardian.SittingOnPlayerMount) { Action = 1; } else { guardian.MoveLeft = guardian.MoveRight = false; if (guardian.Position.X + guardian.Velocity.X * 0.5f > DefendX) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } if (Math.Abs(guardian.Position.X - DefendX) < 5 && Math.Abs(guardian.Velocity.X) < 3f) { Action = 1; if (defendedPm.ControllingGuardian) { if (defendedPm.Guardian.ModID == MainMod.mod.Name) { switch (defendedPm.Guardian.ID) { case GuardianBase.Domino: { switch (Main.rand.Next(5)) { case 0: guardian.SaySomething("*I'm only protecting him because of you, [nickname].*"); break; case 1: guardian.SaySomething("*Of anyone you could take direct control, It had to be him?*"); break; case 2: guardian.SaySomething("*Is this some kind of karma?*"); break; case 3: guardian.SaySomething("*Okay, what have I done to you, [nickname]?*"); break; case 4: guardian.SaySomething("*It's funny how I'm treating his wounds, instead of beating his face.*"); break; } } break; } } } } } } else if (Action == 1) { if (!guardian.PlayerMounted && !guardian.SittingOnPlayerMount) { guardian.Position.X = DefendX; if (!guardian.IsAttackingSomething) { guardian.LookingLeft = defended.direction == -1; } } guardian.Jump = false; if (!guardian.SittingOnPlayerMount) { guardian.MoveDown = true; } guardian.OffHandAction = true; PlayerMod pm = defendedPm; if (pm.ControllingGuardian) { pm.Guardian.AddBuff(ModContent.BuffType <Buffs.Defended>(), 3, true); if (pm.Guardian.KnockedOut) { pm.Guardian.ReviveBoost++; } else { if (guardian.AfkCounter < ProtectModeAutoTriggerTime && PlayerWasKnockedOut) { InUse = false; } } } else { defended.AddBuff(ModContent.BuffType <Buffs.Defended>(), 3); if (pm.KnockedOut) { pm.ReviveBoost++; } else { if (guardian.AfkCounter < ProtectModeAutoTriggerTime && PlayerWasKnockedOut) { InUse = false; } } } } }
public static void UponDeliveringToZacksDialogue() { if (!PlayerMod.HasGuardianSummoned(Main.player[Main.myPlayer], GuardianBase.Blue)) { Dialogue.ShowEndDialogueMessage("*You say that Blue and You have something for me? But where is Blue? She's part of that too, right?*", true); return; } Dialogue.IsImportantDialogue(); ZacksOutfitQuestData data = (ZacksOutfitQuestData)Data; TerraGuardian Blue = null, Zacks = null; for (int i = 0; i < Dialogue.DialogueParticipants.Length; i++) { if (Dialogue.DialogueParticipants[i].ModID == MainMod.mod.Name) { if (Dialogue.DialogueParticipants[i].ID == GuardianBase.Blue) { Blue = Dialogue.DialogueParticipants[i]; } if (Dialogue.DialogueParticipants[i].ID == GuardianBase.Zacks) { Zacks = Dialogue.DialogueParticipants[i]; } } } bool ZacksIsInTheTeam = PlayerMod.HasGuardianSummoned(Main.LocalPlayer, GuardianBase.Zacks); if (Blue == null) { Blue = NpcMod.GetGuardianNPCCharacter(GuardianBase.Blue); } if (Zacks == null) { Zacks = NpcMod.GetGuardianNPCCharacter(GuardianBase.Zacks); } if (!Dialogue.HasParticipant(Blue.ID, Blue.ModID)) { Dialogue.AddParticipant(Blue); } if (!Dialogue.HasParticipant(Zacks.ID, Zacks.ModID)) { Dialogue.AddParticipant(Zacks); } Dialogue.GatherAroundGuardian(Zacks); if (Zacks.UsingFurniture) { Zacks.LeaveFurniture(false); } bool ZacksKnow = data.QuestStep % 2 == 1; Dialogue.ShowDialogueWithContinue("*Zacks, we brought something for you.*", Blue); if (!ZacksKnow) { if (ZacksIsInTheTeam) { Dialogue.ShowDialogueWithContinue("*What is it that you two brought me?*", Zacks); } else { Dialogue.ShowDialogueWithContinue("*Something for me? What is It?*", Zacks); } Dialogue.ShowDialogueWithContinue("*We brought you bandages and a shirt.*", Blue); Dialogue.ShowDialogueWithContinue("*Bandages and a shirt? Why?*", Zacks); Dialogue.ShowDialogueWithContinue("*It's so we can cover those wounds of yours.*", Blue); Dialogue.ShowDialogueWithContinue("*Oh, that is actually... nice of you two.*", Zacks); } else { if (ZacksIsInTheTeam) { Dialogue.ShowDialogueWithContinue("*Finally managed to get everything, right?*", Zacks); } else { Dialogue.ShowDialogueWithContinue("*Finally managed to get everything you two were trying to get?*", Zacks); } Dialogue.ShowDialogueWithContinue("*Yes, everything is here.*", Blue); } Dialogue.ShowDialogueWithContinue("*Now let's patch up those wounds...*", Blue); Dialogue.ShowDialogueWithContinue("*Those bandages will surelly help covering the wounds.*", Zacks); Dialogue.ShowDialogueWithContinue("*...Blue... Why it's written \"Meat Bag\" in this shirt?*", Zacks); Dialogue.ShowDialogueWithContinue("*I don't know, it looked fitting.*", Blue); Dialogue.ShowDialogueWithContinue("*How fitting? Do I look like a meat bag?*", Zacks); Dialogue.ShowDialogueWithContinue("*A rotten one (giggles).*", Blue); Dialogue.ShowDialogueWithContinue("*I wont wear this.*", Zacks); Dialogue.ShowDialogueWithContinue("*Come on, don't be a child. I got all those things for you, just wear it, please.*", Blue); Dialogue.ShowDialogueWithContinue("*... Okay...*", Zacks); /*MainMod.ScreenColor = Microsoft.Xna.Framework.Color.Black; * MainMod.ScreenColorAlpha = 1; * Dialogue.ShowDialogueTimed("(Some washing, patching and cuff wearing later...)",null, 2500); * //System.Threading.Thread.Sleep(2500);*/ Zacks.OutfitID = Companions.ZacksBase.MeatBagOutfitID; //MainMod.ScreenColorAlpha = 0; data.QuestStep = (byte)(ZacksKnow ? 9 : 8); QuestCompletedNotification(data); Dialogue.ShowDialogueWithContinue("*... How do I look?*", Zacks); Dialogue.ShowDialogueWithContinue("*Perfect! Now you look less half eaten and gross.*", Blue); Blue.IncreaseFriendshipProgress(2); Zacks.IncreaseFriendshipProgress(2); Main.NewText("Zacks [Meat Bag] Outfit unlocked."); Dialogue.ShowEndDialogueMessage("*... I really hope you didn't helped her pick this shirt, [nickname].*", true, Zacks); }
public override void Update(TerraGuardian guardian) { if (guardian.furniturex > -1) { guardian.LeaveFurniture(false); } if (guardian.KnockedOut || guardian.IsBeingPulledByPlayer) { InUse = false; return; } if ((guardian.OwnerPos > -1 && guardian.PlayerMounted && !Main.player[guardian.OwnerPos].GetModPlayer <PlayerMod>().KnockedOut) || guardian.Is2PControlled) { if (!guardian.MoveDown) { InUse = false; return; } } if (guardian.ItemAnimationTime > 0) { return; } Vector2 TargetPosition = Vector2.Zero; int TargetWidth = 0, TargetHeight = 0; bool TryReaching = false; bool IsMountedPlayer = false; bool AffectedByNegativeHealing = false; if (TargetIsPlayer) { PlayerMod pm = RevivePlayer.GetModPlayer <PlayerMod>(); AffectedByNegativeHealing = pm.NegativeReviveBoost; TargetPosition = RevivePlayer.position; TargetWidth = RevivePlayer.width; TargetHeight = RevivePlayer.height; if (RevivePlayer.dead || !RevivePlayer.active || !pm.KnockedOut) { InUse = false; return; } if (guardian.PlayerMounted && RevivePlayer.whoAmI == guardian.OwnerPos) { IsMountedPlayer = true; } } else { TargetPosition = ReviveGuardian.TopLeftPosition; TargetWidth = ReviveGuardian.Width; TargetHeight = ReviveGuardian.Height; if (!ReviveGuardian.Active || ReviveGuardian.Downed || !ReviveGuardian.KnockedOut) { InUse = false; return; } if (ReviveGuardian.OwnerPos == guardian.OwnerPos && ReviveGuardian.PlayerControl && guardian.PlayerMounted) { IsMountedPlayer = true; } } bool RepelingEnemies = false; guardian.MoveLeft = guardian.MoveRight = false; if (guardian.TargetID > -1 && !AffectedByNegativeHealing) { Vector2 EnemyPosition; int EnemyWidth, EnemyHeight; guardian.GetTargetInformation(out EnemyPosition, out EnemyWidth, out EnemyHeight); EnemyPosition.X += EnemyWidth * 0.5f; EnemyPosition.Y += EnemyHeight * 0.5f; if (IsMountedPlayer || (Math.Abs(EnemyPosition.X - guardian.Position.X) < 168f + (EnemyWidth + guardian.Width) * 0.5f && Math.Abs(EnemyPosition.Y - guardian.CenterY) < 168f + (EnemyHeight + guardian.Height) * 0.5f)) { RepelingEnemies = true; IgnoreCombat = false; guardian.AttackingTarget = true; } else { IgnoreCombat = true; } } else { IgnoreCombat = false; } if (!RepelingEnemies) { bool OffSetToTheLeft = TargetPosition.X + TargetWidth * 0.5f < guardian.Position.X; { int Animation = guardian.Base.StandingFrame; int ArmAnimation = -1; if (IsMountedPlayer) { ArmAnimation = guardian.Base.ItemUseFrames[2]; } else { if (guardian.Base.ReviveFrame > -1) { Animation = guardian.Base.ReviveFrame; } else if (guardian.Base.DuckingFrame > -1) { Animation = guardian.Base.DuckingFrame; ArmAnimation = guardian.Base.DuckingSwingFrames[2]; } } if (ArmAnimation == -1) { ArmAnimation = Animation; } guardian.Base.GetBetweenHandsPosition(ArmAnimation, out int x, out int y); float ArmXDistance = (x - guardian.SpriteWidth * 0.5f) * guardian.Scale; if (ArmXDistance > 0) { TargetWidth += (int)ArmXDistance; if (OffSetToTheLeft) { TargetPosition.X -= ArmXDistance; } } } if (IsMountedPlayer || new Rectangle((int)TargetPosition.X, (int)TargetPosition.Y, TargetWidth, TargetHeight).Intersects(guardian.HitBox))//(MainMod.RectangleIntersects(guardian.TopLeftPosition, guardian.Width, guardian.Height, TargetPosition, TargetWidth, TargetHeight)) { guardian.Jump = false; float DistanceFromTarget = Math.Abs(guardian.Position.X - (TargetPosition.X + TargetWidth * 0.5f)); if (DistanceFromTarget < 8) { if (Math.Abs(guardian.Velocity.X) < 2f) { if (guardian.Position.X < TargetPosition.X + TargetWidth * 0.5f) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } } } else if (guardian.Velocity.X != 0) { if (Math.Abs(guardian.Position.X + guardian.Velocity.X - (TargetPosition.X + TargetWidth * 0.5f)) < 12) { guardian.MoveLeft = guardian.MoveRight = false; guardian.Velocity.X *= 0.8f; } } else if (guardian.Velocity.X == 0) { { Vector2 FacingLeftPosition = guardian.GetLeftHandPosition(guardian.Base.ReviveFrame, true), FacingRightPosition = FacingLeftPosition; FacingLeftPosition.X *= -1; FacingLeftPosition.X += guardian.Position.X - (TargetPosition.X + TargetWidth * 0.5f); FacingRightPosition.X += guardian.Position.X - (TargetPosition.X + TargetWidth * 0.5f); guardian.FaceDirection(Math.Abs(FacingLeftPosition.X) < Math.Abs(FacingRightPosition.X)); } byte ReviveBoost = 1; if (!guardian.IsAttackingSomething) { ReviveBoost += 2; } bool IsMounted = guardian.PlayerMounted; if (TargetIsPlayer) { RevivePlayer.GetModPlayer <PlayerMod>().ReviveBoost += ReviveBoost; } else { ReviveGuardian.ReviveBoost += ReviveBoost; } guardian.StuckTimer = 0; guardian.OffHandAction = false; if (SpeakToFallen) { SpeakToFallen = false; if (MainMod.CompanionsSpeaksWhileReviving) { guardian.SaySomething(guardian.Base.ReviveMessage(guardian, TargetIsPlayer, (TargetIsPlayer ? RevivePlayer : null), (!TargetIsPlayer ? ReviveGuardian : null))); } } } } else { TryReaching = true; } } if (TryReaching) { if (ResTime >= 5 * 60) { guardian.Position.X = TargetPosition.X + Main.rand.Next(TargetWidth); guardian.Position.Y = TargetPosition.Y + TargetHeight - 1; guardian.FallStart = (int)guardian.Position.Y / 16; } else if (TargetPosition.X + TargetWidth * 0.5f - guardian.Position.X < 0) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } guardian.WalkMode = false; ResTime++; } else { ResTime = 0; } }
public override void Update(TerraGuardian guardian) { if (guardian.OwnerPos > -1 || Main.invasionType <= 0) { InUse = false; return; } if (guardian.UsingFurniture) { guardian.LeaveFurniture(); } switch (Step) { case 0: { int DefendX = 0, DefendY = 0; WorldMod.GuardianTownNpcState townnpc = guardian.GetTownNpcInfo; bool MoveLeft = Main.rand.Next(2) == 0; if (townnpc != null && !townnpc.Homeless) { DefendX = townnpc.HomeX; DefendY = townnpc.HomeY; WorldMod.GuardianBuildingInfo house = townnpc.HouseInfo; if (house != null) { float HouseXStack = 0; byte Count = 0; foreach (WorldMod.GuardianTownNpcState tgh in house.GuardiansLivingHere) { if (!tgh.Homeless) { HouseXStack += tgh.HomeX; Count++; } } if (Count > 0) { HouseXStack /= Count; MoveLeft = (DefendX >= HouseXStack); } } } else { NPC NearestNpc = null; float NearestDistance = 1000; for (int i = 0; i < 200; i++) { if (Main.npc[i].active && Main.npc[i].townNPC && Main.npc[i].type != Terraria.ID.NPCID.OldMan && !Main.npc[i].homeless) { float Distance = (Main.npc[i].Center - guardian.CenterPosition).Length(); if (Distance < NearestDistance) { NearestNpc = Main.npc[i]; NearestDistance = Distance; } } } if (NearestNpc != null) { DefendX = NearestNpc.homeTileX; DefendY = NearestNpc.homeTileY; } else { DefendX = (int)(guardian.Position.X * (1f / 16)); DefendX = (int)(guardian.Position.Y * (1f / 16)); } } bool FoundDefendPosition = false; byte AttemptTime = 40; while (!FoundDefendPosition) { AttemptTime--; if (AttemptTime == 0) { break; } Tile tile = Framing.GetTileSafely(DefendX, DefendY); if (tile != null && tile.active() && Main.tileSolid[tile.type]) { DefendY--; continue; } if (Main.wallHouse[tile.wall]) { DefendX += (MoveLeft ? -1 : 1); } else { tile = Framing.GetTileSafely(DefendX, DefendY + 1); if (tile != null && (!tile.active() || !Main.tileSolid[tile.type])) { DefendY++; continue; } bool Failed = false; for (int x = -4; x < 5; x++) { for (int y = -1; y < 2; y++) { if (Failed) { break; } if (x != 0 || y != 0) { tile = Framing.GetTileSafely(DefendX + x, DefendY + y); if (tile != null && Main.wallHouse[tile.wall]) { DefendX += (MoveLeft ? -1 : 1); Failed = true; } } } } if (!Failed) { FoundDefendPosition = true; } } } if (AttemptTime == 0) { DefendX = (int)(guardian.Position.X * (1f / 16)); DefendY = (int)(guardian.Position.Y * (1f / 16)); } GuardPosition = new Vector2(DefendX, DefendY) * 16; ChangeStep(); } break; case 1: { if (guardian.TargetID == -1 && guardian.TalkPlayerID == -1) { guardian.MoveLeft = guardian.MoveRight = false; guardian.WalkMode = false; if (Math.Abs(guardian.Position.X - GuardPosition.X) > 20) { if (GuardPosition.X < guardian.Position.X) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } } else { } } } break; } }
public override void Update(TerraGuardian guardian) { if (guardian.SittingOnPlayerMount) { guardian.DoSitOnPlayerMount(false); } if (guardian.PlayerMounted) { guardian.ToggleMount(true); } IgnoreCombat = true; guardian.MoveLeft = guardian.MoveRight = false; switch (Step) { case 0: // guardian.HitBox.Intersects(Target.getRect()) && !guardian.BeingPulledByPlayer if (guardian.ItemAnimationTime == 0 && TryReachingPlayer(guardian, Target)) { ChangeStep(); } else { if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } /*if (Target.Center.X < guardian.CenterPosition.X) * guardian.MoveLeft = true; * else * guardian.MoveRight = true;*/ } break; case 1: HeldHand hand = HeldHand.Left; guardian.PickHandToUse(ref hand); Vector2 HandPosition = Vector2.Zero; if (hand == HeldHand.Left) { HandPosition = guardian.GetGuardianLeftHandPosition; } else if (hand == HeldHand.Right) { HandPosition = guardian.GetGuardianRightHandPosition; BlockOffHandUsage = true; } FocusCameraOnGuardian = true; if (Time >= 24) { InUse = false; } else if (Time == 12) { Target.Center = HandPosition; Target.velocity.X = guardian.Direction * 12.5f; Target.velocity.Y = guardian.GravityDirection * -16.25f; Target.fallStart = (int)Target.position.Y / 16; } else if (Time < 12) { Target.direction = guardian.Direction; Target.Center = HandPosition; Target.fallStart = (int)Target.position.Y / 16; } break; } }
public override void Update(TerraGuardian guardian) { switch (Step) { case 0: { const float DistanceBonus = 1; //3 if (Time == 0) { if (guardian.PlayerMounted) { guardian.Dismount(); } if (guardian.SittingOnPlayerMount) { guardian.DoSitOnPlayerMount(false); } if (guardian.UsingFurniture) { guardian.LeaveFurniture(false); } if (guardian.IsLeader) { guardian.RemoveFromCommanding(); } string Message; switch (Main.rand.Next(3)) { default: Message = "*No! Not again! Everyone, stay away from me!*"; break; case 1: Message = "*It's happening again! Don't follow me! Leave me alone!*"; break; case 2: Message = "*Save yourselves! I'm losing myself again!!*"; break; } guardian.SaySomethingCanSchedule(Message, false, Main.rand.Next(60, 180)); if (guardian.OwnerPos > -1 && !guardian.IsPlayerBuddy(Main.player[guardian.OwnerPos])) { if (!NpcMod.HasGuardianNPC(guardian.ID, guardian.ModID)) { WorldMod.GuardianTownNPC.Add(guardian); } Main.player[guardian.OwnerPos].GetModPlayer <PlayerMod>().DismissGuardian(guardian.ID, guardian.ModID); } } else { bool FleeToLeft = false; float FarthestAllyLeft = 0, FarthestAllyRight = 0; foreach (TerraGuardian tg in MainMod.ActiveGuardians.Values) { if (guardian.InPerceptionRange(tg.CenterPosition, DistanceBonus)) { float Distance = Math.Abs(tg.Position.X - guardian.Position.X); if (tg.Position.X < guardian.Position.X) { if (Distance > FarthestAllyLeft) { FarthestAllyLeft = Distance; } } else { if (Distance > FarthestAllyRight) { FarthestAllyRight = Distance; } } } } for (int p = 0; p < 255; p++) { if (Main.player[p].active && !Main.player[p].dead && guardian.InPerceptionRange(Main.player[p].Center, DistanceBonus)) { float Distance = Math.Abs(Main.player[p].Center.X - guardian.Position.X); if (Main.player[p].Center.X < guardian.Position.X) { if (Distance > FarthestAllyLeft) { FarthestAllyLeft = Distance; } } else { if (Distance > FarthestAllyRight) { FarthestAllyRight = Distance; } } } } FleeToLeft = FarthestAllyLeft < FarthestAllyRight; //Run to the position where allies have less distance from her. guardian.MoveLeft = guardian.MoveRight = false; guardian.WalkMode = false; if (FleeToLeft) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } if (Time >= TimeUntilActivates) { ChangeStep(); } IgnoreCombat = true; } } break; case 1: { IgnoreCombat = false; CilleBase.CilleData data = (CilleBase.CilleData)guardian.Data; if (CilleBase.TriggerBeastState(guardian)) { data.InBeastState = true; ForcedTactic = CombatTactic.Charge; if (guardian.TargetID > -1) { guardian.AttackingTarget = true; } //InUse = false; } else { data.InBeastState = false; string Message; switch (Main.rand.Next(3)) { default: Message = "*Huh? It's over... I hope I didn't hurt anyone.*"; break; case 1: Message = "*What happened? Did someone got hurt?*"; break; case 2: Message = "*I'm so glad it's over. I didn't hurt anyone, right?*"; break; } guardian.SaySomethingCanSchedule(Message, false, Main.rand.Next(30, 180)); InUse = false; } } break; } }
public override void Update(TerraGuardian guardian) { if ((guardian.Position - Target.Position).Length() < 20) { guardian.WalkMode = true; } if (guardian.UsingFurniture) { guardian.LeaveFurniture(true); } guardian.StuckTimer = 0; if (guardian.IsBeingPulledByPlayer) { guardian.SaySomething("*Alright, I'm coming, I'm coming.*"); InUse = false; return; } guardian.MoveLeft = guardian.MoveRight = false; Sleuthing = false; if (!Target.KnockedOut && !Target.IsSleeping) { if (SleuthPercent > 70) { guardian.SaySomething("*...So close...*"); } else { guardian.SaySomething(Target.GetMessage(GuardianBase.MessageIDs.AlexanderSleuthingFail, "*I... Was just checking if you were fine.*")); } InUse = false; return; } if (Target.Downed) { InUse = false; guardian.SaySomething("*...I should have helped instead...*"); return; } if (Math.Abs(guardian.Position.X - Target.Position.X) < 8f) { if (guardian.Velocity.X == 0 && guardian.Velocity.Y == 0) { Sleuthing = true; guardian.LookingLeft = (Target.Position.X < guardian.Position.X); float LastSleuthPercent = SleuthPercent; float FillSpeed = guardian.IsSleeping ? 0.07f : 0.2f; SleuthPercent += Main.rand.NextFloat() * FillSpeed; if (SleuthPercent >= 100) { AlexanderBase.AlexanderData data = (AlexanderBase.AlexanderData)guardian.Data; data.AddIdentifiedGuardian(Target.MyID); InUse = false; guardian.SaySomething(GuardianMouseOverAndDialogueInterface.MessageParser(Target.GetMessage(GuardianBase.MessageIDs.AlexanderSleuthingProgressFinished, "*Okay, so that's how you work.*"), guardian)); guardian.UpdateStatus = true; } else if (SleuthPercent >= 70 && LastSleuthPercent < 70) { guardian.SaySomething(GuardianMouseOverAndDialogueInterface.MessageParser(Target.GetMessage(GuardianBase.MessageIDs.AlexanderSleuthingProgressNearlyDone, "*Hm... Interesting...*"), guardian)); } else if (SleuthPercent >= 35 && LastSleuthPercent < 35) { guardian.SaySomething(GuardianMouseOverAndDialogueInterface.MessageParser(Target.GetMessage(GuardianBase.MessageIDs.AlexanderSleuthingProgress, "*Uh huh...*"), guardian)); } else if (SleuthPercent > 0 && LastSleuthPercent <= 0) { guardian.SaySomething(GuardianMouseOverAndDialogueInterface.MessageParser(Target.GetMessage(GuardianBase.MessageIDs.AlexanderSleuthingStart, "*Let's see how you work...*"), guardian)); } } } else { if (Target.Position.X < guardian.Position.X) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } } }
public override void Update(TerraGuardian guardian) { TerraGuardian ControlledGuardian = PlayerMod.PlayerControllingGuardian(PlayerToPickup) ? PlayerToPickup.GetModPlayer <PlayerMod>().Guardian : null; if (Step == 0) //Try reaching player { if (guardian.PlayerMounted) { InUse = false; return; } IgnoreCombat = true; if (!guardian.IsBeingPulledByPlayer) { if (TryReachingPlayer(guardian, PlayerToPickup)) { ChangeStep(); } else { if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } } } } else //Pickup Player animation. { BlockOffHandUsage = true; //guardian.PlayerMounted = true; if (guardian.ReverseMount || guardian.Base.DontUseRightHand || guardian.UsingFurniture) { guardian.ToggleMount(false, false); InUse = false; } else { FocusCameraOnGuardian = true; if (Time >= 20) { guardian.ToggleMount(false, false); InUse = false; } else { if (PlayerToPickup.mount.Active) { PlayerToPickup.mount.Dismount(PlayerToPickup); } int AnimFrame = guardian.Base.ItemUseFrames[3]; if (Time >= 15) { AnimFrame = guardian.Base.ItemUseFrames[0]; } else if (Time >= 10) { AnimFrame = guardian.Base.ItemUseFrames[1]; } else if (Time >= 5) { AnimFrame = guardian.Base.ItemUseFrames[2]; } int HPosX, HPosY; guardian.GetRightHandPosition(AnimFrame, out HPosX, out HPosY); Vector2 HandPosition = guardian.Position; HandPosition.X += HPosX; HandPosition.Y += HPosY; if (ControlledGuardian == null) { HandPosition.X -= PlayerToPickup.width * 0.5f; HandPosition.Y -= PlayerToPickup.height * 0.5f; PlayerToPickup.position = HandPosition; PlayerToPickup.fallStart = (int)PlayerToPickup.position.Y / 16; PlayerToPickup.velocity.X = 0; PlayerToPickup.velocity.Y = -Player.defaultGravity; if (PlayerToPickup.itemAnimation == 0) { PlayerToPickup.direction = guardian.Direction; } } else { HandPosition.Y += ControlledGuardian.Height * 0.5f; ControlledGuardian.Position = HandPosition; ControlledGuardian.SetFallStart(); ControlledGuardian.Velocity.X = 0; ControlledGuardian.Velocity.Y = -ControlledGuardian.Mass; if (ControlledGuardian.ItemAnimationTime == 0) { ControlledGuardian.Direction = guardian.Direction; } } } } guardian.MoveRight = PlayerToPickup.controlRight; guardian.MoveLeft = PlayerToPickup.controlLeft; guardian.MoveUp = PlayerToPickup.controlUp; guardian.MoveDown = PlayerToPickup.controlDown; guardian.Jump = PlayerToPickup.controlJump; } }
public override void Update(TerraGuardian guardian) { bool TargetIsKod = true; if (guardian.UsingFurniture) { guardian.LeaveFurniture(true); } if (CarriedPlayer != null) { PlayerMod pm = CarriedPlayer.GetModPlayer <PlayerMod>(); TargetIsKod = pm.KnockedOut; if (CarriedPlayer.dead) { InUse = false; if (guardian.TargetID != -1) { guardian.CheckIfSomeoneNeedsPickup(); } return; } bool BeingCarriedByMe = false; if (!PlayerMod.IsBeingCarriedBySomeone(CarriedPlayer) || (BeingCarriedByMe = PlayerMod.IsBeingCarriedByThisGuardian(CarriedPlayer, guardian))) { pm.CarriedByGuardianID = guardian.WhoAmID; pm.BeingCarriedByGuardian = false; if (!BeingCarriedByMe) { guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueComingMessage)); } } else { InUse = false; return; } if (CarriedPlayer.whoAmI == guardian.OwnerPos) { guardian.StuckTimer = 0; } } else { TargetIsKod = CarriedGuardian.KnockedOut; if (CarriedGuardian.Downed) { InUse = false; return; } bool BeingCarriedByMe = false; if (!CarriedGuardian.IsBeingCarriedBySomeone() || (BeingCarriedByMe = CarriedGuardian.IsBeingCarriedByThisGuardian(guardian))) { CarriedGuardian.CarriedByGuardianID = guardian.WhoAmID; CarriedGuardian.BeingCarriedByGuardian = false; if (!BeingCarriedByMe) { guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueComingMessage)); } } else { InUse = false; return; } } if (!Carrying) { float TargetX = CarriedPlayer != null ? CarriedPlayer.Center.X : CarriedGuardian.Position.X; float TargetY = CarriedPlayer != null ? CarriedPlayer.Bottom.Y : CarriedGuardian.Position.Y; if (Math.Abs(guardian.Position.X - TargetX) < 16 && Math.Abs(guardian.Position.Y - TargetY) < guardian.Height * 0.5f) { Carrying = true; guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueGotMessage)); ChangeStep(); } else { IgnoreCombat = true; guardian.MoveRight = guardian.MoveLeft = false; if (TargetX < guardian.Position.X) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } if (Time >= 5 * 60) { guardian.Position = new Microsoft.Xna.Framework.Vector2(TargetX, TargetY); guardian.SetFallStart(); Carrying = true; ChangeStep(); } else { return; } } DelayBeforePlacingOnGround = MaxDelay; } IgnoreCombat = false; bool SafeToPlaceAllyDown = true; { if (guardian.Velocity.Y == 0) { int StartCheckX = (int)((guardian.Position.X - guardian.CollisionWidth * 0.5f) * TerraGuardian.DivisionBy16), EndCheckX = (int)((guardian.Position.X + guardian.CollisionWidth * 0.5f + 1) * TerraGuardian.DivisionBy16); int CheckY = (int)((guardian.Position.Y + 1) * TerraGuardian.DivisionBy16); for (int x = StartCheckX; x < EndCheckX; x++) { if (MainMod.IsDangerousTile(x, CheckY, false)) { SafeToPlaceAllyDown = false; break; } /*Tile tile = MainMod.GetTile(x, CheckY); * if (tile.liquid >= 20) * { * SafeToPlaceAllyDown = false; * break; * }*/ } } else { SafeToPlaceAllyDown = false; } if (!TargetIsKod && DelayBeforePlacingOnGround > 2.5f * 60) { DelayBeforePlacingOnGround = (int)(2.5f * 60); } if (SafeToPlaceAllyDown && TargetIsKod) { for (int n = 0; n < 200; n++) { if (Main.npc[n].active && guardian.IsNpcHostile(Main.npc[n]) && guardian.Distance(Main.npc[n].Center) < 400 && (Main.npc[n].noTileCollide || Collision.CanHitLine(Main.npc[n].position, Main.npc[n].width, Main.npc[n].height, guardian.TopLeftPosition, guardian.Width, guardian.Height))) { SafeToPlaceAllyDown = false; break; } } } } if (SafeToPlaceAllyDown) { guardian.MoveLeft = guardian.MoveRight = false; if (DelayBeforePlacingOnGround <= 0) { if (CarriedPlayer != null) { CarriedPlayer.position.X = guardian.Position.X - CarriedPlayer.width * 0.5f; CarriedPlayer.position.Y = guardian.Position.Y - CarriedPlayer.height; InUse = false; return; } CarriedGuardian.Position.X = guardian.Position.X; CarriedGuardian.Position.Y = guardian.Position.Y; InUse = false; return; } DelayBeforePlacingOnGround--; } else { if (TargetIsKod) { DelayBeforePlacingOnGround = MaxDelay; } bool AllyIsDying = CarriedPlayer != null ? CarriedPlayer.statLife < CarriedPlayer.statLifeMax2 * 0.35f : CarriedGuardian.HP < CarriedGuardian.MHP * 0.35f; ForcedTactic = AllyIsDying ? CombatTactic.Snipe : CombatTactic.Assist; } { Vector2 CarryPosition = Vector2.Zero; Vector2 Origin = Vector2.One * 0.5f; if (guardian.Ducking) { CarryPosition = guardian.GetBetweenHandsPosition(guardian.Base.DuckingSwingFrames[2]); } else { CarryPosition = guardian.GetBetweenHandsPosition(guardian.Base.ItemUseFrames[2]); } CarryPosition += guardian.Position; if (CarriedPlayer != null) { CarriedPlayer.position.X = CarryPosition.X - CarriedPlayer.width * Origin.X + guardian.OffsetX; CarriedPlayer.position.Y = CarryPosition.Y - CarriedPlayer.height * Origin.Y + guardian.OffsetY; CarriedPlayer.fallStart = (int)(CarriedPlayer.position.Y * TerraGuardian.DivisionBy16); CarriedPlayer.direction = guardian.Direction; CarriedPlayer.immune = true; CarriedPlayer.immuneTime = 3; CarriedPlayer.immuneNoBlink = true; PlayerMod pm = CarriedPlayer.GetModPlayer <PlayerMod>(); pm.ReviveBoost++; pm.BeingCarriedByGuardian = true; MainMod.DrawMoment.Add(new GuardianDrawMoment(guardian.WhoAmID, TerraGuardian.TargetTypes.Player, CarriedPlayer.whoAmI)); } else { CarriedGuardian.IsBeingPulledByPlayer = false; CarriedGuardian.Position.X = CarryPosition.X - (CarriedGuardian.Width * (Origin.X - 0.5f)) + guardian.OffsetX; CarriedGuardian.Position.Y = CarryPosition.Y + (CarriedGuardian.Height * (1.1f - Origin.Y)) + guardian.OffsetY; CarriedGuardian.SetFallStart(); CarriedGuardian.Direction = guardian.Direction; CarriedGuardian.ReviveBoost++; CarriedGuardian.BeingCarriedByGuardian = true; CarriedGuardian.ImmuneTime = 3; CarriedGuardian.ImmuneNoBlink = true; MainMod.DrawMoment.Add(new GuardianDrawMoment(guardian.WhoAmID, TerraGuardian.TargetTypes.Guardian, CarriedGuardian.WhoAmID, true)); } } }
public override void Update(TerraGuardian guardian) { IgnoreCombat = true; AvoidItemUsage = true; if (guardian.SittingOnPlayerMount) { guardian.DoSitOnPlayerMount(false); } if (guardian.PlayerMounted) { guardian.ToggleMount(true); } if (guardian.IsBeingPulledByPlayer) { guardian.IsBeingPulledByPlayer = false; } guardian.MoveLeft = guardian.MoveRight = false; switch (Step) { case 0: if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } if (guardian.ItemAnimationTime == 0 && ((Target != null && TryReachingPlayer(guardian, Target)) || (TargetTg != null && TryReachingTg(guardian, TargetTg)))) //guardian.HitBox.Intersects(p.getRect()) && !guardian.BeingPulledByPlayer && { ChangeStep(); if (Target != null && Target.mount.Active) { Target.mount.Dismount(Target); } } else { if (Time >= 300) { InUse = false; } } break; case 1: guardian.Ducking = false; Vector2 HandPosition = guardian.GetGuardianBetweenHandPosition; BlockOffHandUsage = true; if (Time < 12) { if (Target != null) { Target.Center = HandPosition; Target.velocity = Vector2.Zero; Target.velocity.Y = -Player.defaultGravity; Target.fallStart = (int)Target.position.Y / 16; } else { TargetTg.Position = HandPosition + new Vector2(0, TargetTg.Height * 0.5f); TargetTg.Velocity = Vector2.Zero; TargetTg.SetFallStart(); } FocusCameraOnGuardian = true; } else { if (Time == 18 && Target != null && Collision.SolidCollision(Target.position, Target.width, Target.height)) { Target.Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(" should've noticed the ceiling was low, before asking " + guardian.Name + " to lift it up..."), 20, 0); guardian.DisplayEmotion(TerraGuardian.Emotions.Sweat); if (Target.dead || Target.GetModPlayer <PlayerMod>().KnockedOut) { InUse = false; } ChangeStep(); } else if (Time == 18 && TargetTg != null && Collision.SolidCollision(TargetTg.TopLeftPosition, TargetTg.Width, TargetTg.Height)) { TargetTg.Hurt(20, 0, DeathMessage: " should've noticed the ceiling was low, before asking " + guardian.Name + " to lift it up..."); guardian.DisplayEmotion(TerraGuardian.Emotions.Sweat); if (TargetTg.Downed || TargetTg.KnockedOut) { InUse = false; } ChangeStep(); } else { FocusCameraOnGuardian = false; if (Target != null) { Target.position.Y = HandPosition.Y - Target.height; Target.position.X = HandPosition.X - Target.width * 0.5f; Target.velocity.Y = -Target.gravity; Target.velocity.X = 0; Target.fallStart = (int)Target.position.Y / 16; if (Target.controlRight) { guardian.MoveRight = true; } if (Target.controlLeft) { guardian.MoveLeft = true; } if (Target.controlJump) { Target.justJumped = true; Target.velocity.Y = -Player.jumpSpeed * Target.gravDir; Target.jump = Player.jumpHeight; InUse = false; } } else { TargetTg.Position = HandPosition; TargetTg.Velocity.Y = -0.3f; TargetTg.Velocity.X = 0; TargetTg.SetFallStart(); if (TargetTg.LastMoveRight) { guardian.MoveRight = true; } if (TargetTg.LastMoveLeft) { guardian.MoveLeft = true; } if (TargetTg.LastJump) { TargetTg.Velocity.Y = -TargetTg.JumpSpeed * TargetTg.GravityDirection; InUse = false; } } } } break; case 2: FocusCameraOnGuardian = true; if (Time >= 22) { if (Target != null) { Target.position.X = guardian.Position.X - Target.width * 0.5f; Target.position.Y = guardian.Position.Y - Target.height; Target.fallStart = (int)Target.position.Y / 16; Target.velocity = Vector2.Zero; Target.velocity.Y = -Player.defaultGravity; InUse = false; } else { TargetTg.Position = guardian.Position; TargetTg.Velocity.Y = 0; TargetTg.Velocity.X = 0; TargetTg.SetFallStart(); } } else { if (Target != null) { Target.Center = guardian.GetGuardianBetweenHandPosition; Target.fallStart = (int)Target.position.Y / 16; } else { TargetTg.Position = guardian.GetGuardianBetweenHandPosition + new Vector2(0, TargetTg.Height * 0.5f); TargetTg.SetFallStart(); } } break; } }
public override void Update(TerraGuardian guardian) { if (TargetPlayer != null) { if (TargetPlayer.dead || !TargetPlayer.active) { InUse = false; return; } } if (TargetGuardian != null) { if (!TargetGuardian.Active || TargetGuardian.Downed) { InUse = false; return; } } switch (Step) { case 0: { if (StepStart) { LastPlayerFollower = guardian.OwnerPos > -1; } Rectangle TargetHitbox; Vector2 TargetPosition; if (guardian.UsingFurniture) { guardian.LeaveFurniture(); } if (TargetPlayer != null) { TargetPosition = TargetPlayer.Center; TargetHitbox = TargetPlayer.getRect(); } else { TargetPosition = TargetGuardian.CenterPosition; TargetHitbox = TargetGuardian.HitBox; } if (TargetHitbox.Intersects(guardian.HitBox) || Time >= 10 * 60) { ChangeStep(); guardian.AddFlag(GuardianFlags.IgnoreGfx); } else if (guardian.Position.X > TargetPosition.X) { guardian.MoveLeft = true; guardian.MoveRight = false; } else { guardian.MoveRight = true; guardian.MoveLeft = false; } } break; case 1: { if (guardian.OwnerPos > -1 != LastPlayerFollower) { InUse = false; return; } guardian.IsBeingPulledByPlayer = false; if (!ByPlayerOrder && Time >= DurationTime) { if (TargetPlayer != null) { guardian.Position = TargetPlayer.Bottom; } else { guardian.Position = TargetGuardian.Position; } InUse = false; return; } guardian.MoveLeft = guardian.MoveRight = guardian.Jump = false; guardian.ChangeIdleAction(TerraGuardian.IdleActions.Wait, 300); Vector2 MountedPosition = guardian.Base.GetBetweenHandsPositionVector(Reviving ? guardian.Base.ReviveFrame : guardian.Base.PlayerMountedArmAnimation); MountedPosition.X = MountedPosition.X - guardian.Base.SpriteWidth * 0.5f; Vector2 HauntPosition = Vector2.Zero; if (TargetPlayer != null) { if (Reviving) { if (guardian.ItemAnimationTime == 0) { guardian.Direction = -TargetPlayer.direction; } HauntPosition = TargetPlayer.Center; } else { if (guardian.ItemAnimationTime == 0) { guardian.Direction = TargetPlayer.direction; } HauntPosition = TargetPlayer.position; } if (guardian.Direction > 0) { MountedPosition.X *= -1; } HauntPosition.X += TargetPlayer.width * 0.5f; HauntPosition.Y += TargetPlayer.height + (guardian.Base.SpriteHeight - MountedPosition.Y - 30) * guardian.Scale; HauntPosition.X += (MountedPosition.X - 6 * guardian.Direction) * guardian.Scale; guardian.AddDrawMomentToPlayer(TargetPlayer); TargetPlayer.AddBuff(Terraria.ModLoader.ModContent.BuffType <Buffs.GhostFoxHaunts.FriendlyHaunt>(), 5); Reviving = TargetPlayer.GetModPlayer <PlayerMod>().KnockedOut; } else { if (Reviving) { if (guardian.ItemAnimationTime == 0) { guardian.Direction = -TargetGuardian.Direction; } HauntPosition = TargetGuardian.CenterPosition; } else { if (guardian.ItemAnimationTime == 0) { guardian.Direction = TargetGuardian.Direction; } HauntPosition = TargetGuardian.Position; } if (guardian.Direction > 0) { MountedPosition.X *= -1; } HauntPosition.X += MountedPosition.X * guardian.Scale - TargetGuardian.Width * 0.2f * guardian.Direction; //HauntPosition.X += (MountedPosition.X - (TargetGuardian.Width * 0.5f - 8) * guardian.Direction) * guardian.Scale; //- 8 HauntPosition.Y += MountedPosition.Y * guardian.Scale - TargetGuardian.Height * 0.95f; guardian.AddDrawMomentToTerraGuardian(TargetGuardian); TargetGuardian.AddBuff(Terraria.ModLoader.ModContent.BuffType <Buffs.GhostFoxHaunts.FriendlyHaunt>(), 5, true); Reviving = TargetGuardian.KnockedOut || TargetGuardian.IsUsingBed; } guardian.Velocity = Vector2.Zero; guardian.Position = HauntPosition; } break; } LastPlayerFollower = guardian.OwnerPos > -1; }
public override void Update(TerraGuardian guardian) { EffectOnlyMirror = true; CantUseInventory = true; bool TeleportedEffects = false; switch (Step) { case 0: { if (StepStart) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.LeavingToSellLoot); if (Message != "") { guardian.SaySomething(Message); } else { ChangeStep(); } } if (guardian.MessageTime <= 0) { ChangeStep(); } } break; case 1: //Check distance to town, calculate time to sell items. { if (StepStart) { if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } if (!guardian.HasMagicMirror) { TeleportMethod = 1; LastWasPlayerMounted = guardian.PlayerMounted; if (guardian.PlayerMounted) { guardian.ToggleMount(true); } if (guardian.SittingOnPlayerMount) { guardian.DoSitOnPlayerMount(false); } //InUse = false; //return; } else { Vector2 GuardianPos = guardian.CenterPosition; Vector2 ResultPoint = new Vector2(Main.spawnTileX * 16, Main.spawnTileY * 16); int Time = 60 * 10; //Time += (int)Math.Abs(ResultPoint.X - GuardianPos.X) / 128; //Time += (int)Math.Abs(ResultPoint.Y - GuardianPos.Y) / 128; TeleportTime = Time; TeleportMethod = 0; } } if (TeleportMethod == 1) { //make guardian walk away from the player. If It gets away from screen distance, teleport. //If passes 5 seconds and It didn't teleport, make it disappear and calculate the time until nearest vendor. bool DoMove = false; if (this.Time >= 60 * 5) { DoMove = true; } else if (Math.Abs(guardian.Position.X - Main.player[guardian.OwnerPos].Center.X) < NPC.sWidth * 16) { IgnoreCombat = true; CantUseInventory = true; Immune = true; guardian.StuckTimer = 0; guardian.MoveLeft = guardian.MoveRight = false; if (Main.player[guardian.OwnerPos].Center.X - guardian.Position.X < 0) { guardian.MoveRight = true; } else { guardian.MoveLeft = true; } } else { DoMove = true; } if (DoMove) { int NearestTownNPC = -1; float NearestDist = -1; for (int n = 0; n < 200; n++) { if (Main.npc[n].active && Main.npc[n].townNPC && MainMod.VendorNpcs.Contains(Main.npc[n].type)) { float Distance = (guardian.CenterPosition - Main.npc[n].Center).Length(); if (NearestDist == -1 || Distance < NearestDist) { NearestTownNPC = n; NearestDist = Distance; } } } Vector2 ResultPosition = Vector2.Zero; if (NearestTownNPC > -1) { ResultPosition = Main.npc[NearestTownNPC].Center; } else { ResultPosition.X = Main.spawnTileX * 16; ResultPosition.Y = Main.spawnTileY * 16; } float WalkTime = 16f / guardian.MoveSpeed; int Time = (int)((Math.Abs(ResultPosition.X - guardian.Position.X) + Math.Abs(ResultPosition.Y - guardian.CenterY)) * WalkTime) / (16 * 16) + 60 * 7; TeleportTime = Time; //Main.NewText("Teleport time: " + Math.Round((float)Time / 60, 1) + "s."); LastWasPlayerMounted = guardian.PlayerMounted; if (guardian.PlayerMounted) { guardian.ToggleMount(true); } ChangeStep(); TeleportedEffects = true; } } else { if (guardian.ItemAnimationTime <= 0) { guardian.UseMagicMirror(); } if (guardian.MagicMirrorTrigger) { LastWasPlayerMounted = guardian.PlayerMounted; if (guardian.PlayerMounted) { guardian.ToggleMount(true); } ChangeStep(); TeleportedEffects = true; } } } break; case 2: { TeleportedEffects = true; if (Time >= TeleportTime) { bool SendToPiggyBank = guardian.FriendshipGrade >= 3; bool SoldItems = false, SentItemsToPiggyBank = false; int p = 0, g = 0, s = 0, c = 0; int token = 0; int copperstack = 0; for (int i = 10; i < 50; i++) { if (i != guardian.SelectedItem && guardian.Inventory[i].type != 0 && !guardian.Inventory[i].favorited) { if ((guardian.Inventory[i].type <Terraria.ID.ItemID.CopperCoin || guardian.Inventory[i].type> Terraria.ID.ItemID.PlatinumCoin) && guardian.Inventory[i].type != Terraria.ID.ItemID.DefenderMedal) { c += guardian.Inventory[i].value * guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); SoldItems = true; } else if (SendToPiggyBank) { SentItemsToPiggyBank = true; switch (guardian.Inventory[i].type) { case Terraria.ID.ItemID.CopperCoin: copperstack += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); break; case Terraria.ID.ItemID.SilverCoin: s += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); break; case Terraria.ID.ItemID.GoldCoin: g += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); break; case Terraria.ID.ItemID.PlatinumCoin: p += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); break; case Terraria.ID.ItemID.DefenderMedal: token += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); break; } } } } c = c / 5 + copperstack; if (c >= 100) { s += c / 100; c -= s * 100; } if (s >= 100) { g += s / 100; s -= g * 100; } if (g >= 100) { p += g / 100; g -= p * 100; } string ResultText = ""; bool First = true; if (p > 0) { First = false; ResultText += p + " Platinum"; } if (g > 0) { if (!First) { ResultText += ", "; } First = false; ResultText += g + " Gold"; } if (s > 0) { if (!First) { ResultText += ", "; } First = false; ResultText += s + " Silver"; } if (c > 0) { if (!First) { ResultText += ", "; } First = false; ResultText += c + " Copper"; } if (SentItemsToPiggyBank && !SoldItems) { ResultText = guardian.Name + " stored " + ResultText + " on your Piggy Bank"; } else if (c == 0 && s == 0 && g == 0 && p == 0) { ResultText = guardian.Name + " gained nothing from selling the items"; } else { ResultText = guardian.Name + " got " + ResultText + " Coins from item sale"; if (SendToPiggyBank) { ResultText += ", and they were sent to your Piggy Bank"; } } if (token > 0) { ResultText += ", and stored " + token + " defender medals"; } Main.NewText(ResultText + ".", Color.Yellow); if (SendToPiggyBank && guardian.OwnerPos != -1) //Store on player piggy bank { Chest bank = Main.player[guardian.OwnerPos].bank; for (byte Coin = 0; Coin < 5; Coin++) { int EmptySlot = -1; int CoinID = Coin + Terraria.ID.ItemID.CopperCoin; if (Coin == 4) { CoinID = Terraria.ID.ItemID.DefenderMedal; } int CoinsToDiscount = 0; switch (Coin) { case 0: CoinsToDiscount = c; c = 0; break; case 1: CoinsToDiscount = s; s = 0; break; case 2: CoinsToDiscount = g; g = 0; break; case 3: CoinsToDiscount = p; p = 0; break; case 4: CoinsToDiscount = token; token = 0; break; } if (CoinsToDiscount == 0) { continue; } for (int i = 0; i < bank.item.Length; i++) { if (bank.item[i].type == 0) { EmptySlot = i; } if (CoinsToDiscount > 0 && bank.item[i].type == CoinID) { bank.item[i].stack += CoinsToDiscount; CoinsToDiscount = 0; if (bank.item[i].stack >= 100 && CoinID != Terraria.ID.ItemID.PlatinumCoin && CoinID != Terraria.ID.ItemID.DefenderMedal) { int NextSum = bank.item[i].stack / 100; bank.item[i].stack -= NextSum * 100; switch (Coin) { case 0: s += NextSum; break; case 1: g += NextSum; break; case 2: p += NextSum; break; } } if (CoinID == Terraria.ID.ItemID.PlatinumCoin && bank.item[i].stack > 1000) { CoinsToDiscount = bank.item[i].stack - 1000; bank.item[i].stack = 1000; } if (CoinID == Terraria.ID.ItemID.DefenderMedal && bank.item[i].stack > 999) { CoinsToDiscount = bank.item[i].stack - 999; bank.item[i].stack = 999; } if (bank.item[i].stack == 0) { bank.item[i].SetDefaults(0, true); } } } while (CoinsToDiscount > 0) { if (EmptySlot > -1) { bank.item[EmptySlot].SetDefaults(CoinID, true); if (CoinsToDiscount > 1000) { bank.item[EmptySlot].stack = 1000; CoinsToDiscount -= 1000; EmptySlot = -1; for (int i = 0; i < bank.item.Length; i++) { if (bank.item[i].type == 0) { EmptySlot = i; } } } else { bank.item[EmptySlot].stack = CoinsToDiscount; CoinsToDiscount = 0; } } else { switch (Coin) { case 0: c = CoinsToDiscount; break; case 1: s = CoinsToDiscount; break; case 2: g = CoinsToDiscount; break; case 3: p = CoinsToDiscount; break; case 4: token = CoinsToDiscount; break; } CoinsToDiscount = 0; } } } } for (int i = 0; i < 50; i++) { switch (guardian.Inventory[i].type) { case Terraria.ID.ItemID.CopperCoin: { c += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); } break; case Terraria.ID.ItemID.SilverCoin: { s += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); } break; case Terraria.ID.ItemID.GoldCoin: { g += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); } break; case Terraria.ID.ItemID.PlatinumCoin: { p += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); } break; case Terraria.ID.ItemID.DefenderMedal: { token += guardian.Inventory[i].stack; guardian.Inventory[i].SetDefaults(0, true); } break; } } if (c >= 100) { s += c / 100; c -= s * 100; } if (s >= 100) { g += s / 100; s -= g * 100; } if (g >= 100) { p += g / 100; g -= p * 100; } for (int i = 0; i < 50; i++) { if (guardian.Inventory[i].type == 0) { if (token > 0) { guardian.Inventory[i].SetDefaults(Terraria.ID.ItemID.DefenderMedal, true); guardian.Inventory[i].stack = token; token = 0; } else if (p > 0) { guardian.Inventory[i].SetDefaults(Terraria.ID.ItemID.PlatinumCoin, true); guardian.Inventory[i].stack = p; p = 0; } else if (g > 0) { guardian.Inventory[i].SetDefaults(Terraria.ID.ItemID.GoldCoin, true); guardian.Inventory[i].stack = g; g = 0; } else if (s > 0) { guardian.Inventory[i].SetDefaults(Terraria.ID.ItemID.SilverCoin, true); guardian.Inventory[i].stack = s; s = 0; } else if (c > 0) { guardian.Inventory[i].SetDefaults(Terraria.ID.ItemID.CopperCoin, true); guardian.Inventory[i].stack = c; c = 0; } } } for (byte Coin = 0; Coin < 5; Coin++) { int CoinID = Coin + Terraria.ID.ItemID.CopperCoin; if (Coin == 4) { CoinID = Terraria.ID.ItemID.DefenderMedal; } int Stack = 0; switch (Coin) { case 0: Stack = c; break; case 1: Stack = s; break; case 2: Stack = g; break; case 3: Stack = p; if (Stack > 1000) { p -= 1000; Stack = 1000; Coin--; } break; case 4: Stack = token; if (Stack > 999) { token -= 999; Stack = 999; Coin--; } break; } if (Stack > 0) { Item.NewItem(guardian.HitBox, CoinID, Stack); } } ChangeStep(); } } break; case 3: { if (TeleportMethod == 0) { if (guardian.ItemAnimationTime <= 0) { guardian.UseMagicMirror(); } if (guardian.MagicMirrorTrigger) { InUse = false; if (LastWasPlayerMounted) { guardian.ToggleMount(true); } else if (guardian.OwnerPos > -1) { guardian.Velocity = Main.player[guardian.OwnerPos].velocity; } } else { TeleportedEffects = true; } } else { if (StepStart) { TeleportTime = 60 * 5; } if (Time < TeleportTime) { TeleportedEffects = true; } else { Main.NewText(guardian.Name + " has returned."); guardian.StuckTimer = 0; InUse = false; if (LastWasPlayerMounted) { guardian.ToggleMount(); } else if (guardian.OwnerPos > -1) { guardian.Velocity = Main.player[guardian.OwnerPos].velocity; } } } } break; } IgnoreCombat = TeleportedEffects; //AvoidItemUsage = TeleportedEffects; Invisibility = TeleportedEffects; Immune = TeleportedEffects; NoAggro = TeleportedEffects; Inactivity = TeleportedEffects; if (TeleportedEffects) { if (guardian.GuardingPosition.HasValue) { guardian.Position.X = guardian.GuardingPosition.Value.X * 16; guardian.Position.Y = guardian.GuardingPosition.Value.Y * 16; } else { guardian.Position.X = Main.player[guardian.OwnerPos].Center.X; guardian.Position.Y = Main.player[guardian.OwnerPos].position.Y + Main.player[guardian.OwnerPos].height - 1; } guardian.Velocity.X = guardian.Velocity.Y = 0; } }
public override void Update(TerraGuardian guardian) { IgnoreCombat = true; Cancellable = false; if (guardian.Downed || guardian.KnockedOut) { MainMod.ScreenColorAlpha = 0; InUse = false; return; } bool SetPlayerToGuardianBed = false; const bool UseBedSharing = false; switch (Step) { case 0: { if (UseBedSharing && guardian.Base.Size >= GuardianBase.GuardianSize.Large) { if (guardian.AttemptToGrabPlayer()) { ChangeStep(); } guardian.WalkMode = true; } else { ChangeStep(); } } break; case 1: { if (Time == 0) { if (guardian.furniturex > -1) { guardian.LeaveFurniture(false); } guardian.TryFindingNearbyBed(false); } if (guardian.furniturex == -1 || guardian.UsingFurniture) { ChangeStep(); } if (guardian.furniturex > -1) { guardian.WalkMode = true; } } break; case 2: { MainMod.ScreenColor.R = MainMod.ScreenColor.G = MainMod.ScreenColor.B = 0; MainMod.ScreenColorAlpha = (float)Time / (5 * 60); if (MainMod.ScreenColorAlpha > 1) { MainMod.ScreenColorAlpha = 1f; } if (UseBedSharing && guardian.IsSleeping && guardian.GrabbingPlayer) { SetPlayerToGuardianBed = true; } if (Time >= 5 * 60) { //Do time change if (guardian.OwnerPos > -1) { Main.player[guardian.OwnerPos].position.X = guardian.Position.X - Main.player[guardian.OwnerPos].width * 0.5f; Main.player[guardian.OwnerPos].position.Y = guardian.Position.Y - Main.player[guardian.OwnerPos].height; Main.player[guardian.OwnerPos].velocity = Vector2.Zero; int RestValue = 4; switch (RestTime) { case 0: RestValue = 4; break; case 1: RestValue = 8; break; case 2: //UntilDawn RestValue = 0; if (Main.dayTime) { RestValue += (int)(24 * 3600 - Main.time) / 3600 + 1; } else { RestValue += (int)(9 * 3600 - Main.time) / 3600 + 1; } break; case 3: //UntilNight RestValue = 0; if (Main.dayTime) { RestValue += (int)(15 * 3600 - Main.time) / 3600 + 1; } else { RestValue += (int)(24 * 3600 - Main.time) / 3600 + 1; } break; } WorldMod.SkipTime(RestValue); foreach (TerraGuardian g in Main.player[guardian.OwnerPos].GetModPlayer <PlayerMod>().GetAllGuardianFollowers) { float RestBonus = 1.5f; if (g.Base.IsNocturnal) { if (!Main.dayTime) { RestBonus = 2f; } } else { if (Main.dayTime) { RestBonus = 2f; } } RestBonus *= RestValue; if ((int)g.Data.Fatigue - RestBonus < 0) { g.Data.Fatigue = 0; } else { g.Data.Fatigue -= (sbyte)RestBonus; } float InjuryValue = RestBonus * 0.5f; if ((int)g.Data.Injury - RestBonus < 0) { g.Data.Injury = 0; } else { g.Data.Injury -= (sbyte)InjuryValue; } if (g.request.Active) { g.request.RequestTimeLeft -= RestValue; } } } guardian.GrabbingPlayer = false; ChangeStep(); } } break; case 3: { Player player = Main.player[guardian.OwnerPos]; if (Time >= 5 * 60) { InUse = false; MainMod.ScreenColorAlpha = 0; if (guardian.IsSleeping) { player.fullRotation = 0; guardian.LeaveFurniture(); } } else { MainMod.ScreenColor.R = MainMod.ScreenColor.G = MainMod.ScreenColor.B = 0; MainMod.ScreenColorAlpha = 1f - (float)Time / (5 * 60); if (guardian.IsSleeping) { SetPlayerToGuardianBed = true; } } } break; } if (UseBedSharing && SetPlayerToGuardianBed) { Player player = Main.player[guardian.OwnerPos]; player.direction = guardian.Direction; player.fullRotation = -1.570796326794897f * player.direction; player.position.X = guardian.Position.X - player.width * 0.5f - guardian.Base.SleepingOffset.X; player.position.Y = guardian.Position.Y - player.height - guardian.Base.SleepingOffset.Y; player.velocity = Vector2.Zero; player.fullRotationOrigin.X = player.width * 0.5f; player.fullRotationOrigin.Y = player.height * 0.5f; guardian.GrabbingPlayer = false; } }
public override void Update(TerraGuardian guardian) { bool CanPickupPlayer = guardian.Base.MountUnlockLevel != 255 && guardian.Base.Size >= GuardianBase.GuardianSize.Large && !guardian.PlayerMounted && !guardian.SittingOnPlayerMount; AvoidItemUsage = true; bool HoldingPlayer = false; FocusCameraOnGuardian = false; /*if (Target.dead) * { * InUse = false; * return; * }*/ switch (Step) { case 0: if (guardian.furniturex > -1) { guardian.LeaveFurniture(); } if (TryReachingPlayer(guardian, Target)) { ChangeStep(); } break; case 1: if (!CanPickupPlayer) { ChangeStep(); } else { FocusCameraOnGuardian = true; if (Time < 8) { int AnimFrame = Time / 4; if (guardian.Ducking) { SetPlayerOnHandPosition(guardian, Target, guardian.Base.DuckingSwingFrames[2 - AnimFrame], HeldHand.Right); } else { SetPlayerOnHandPosition(guardian, Target, guardian.Base.ItemUseFrames[3 - AnimFrame], HeldHand.Right); } } else { HoldingPlayer = true; ChangeStep(); } } break; case 2: { IgnoreCombat = true; AvoidItemUsage = false; EffectOnlyMirror = true; if (!guardian.HasMagicMirror) { ChangeStep(4); } if (guardian.ItemAnimationTime <= 0) { guardian.UseMagicMirror(); if (Time >= 10 * 60) { ChangeStep(4); Main.NewText("For some reason, " + guardian.Name + " got Itself confused when using the magic mirror."); } } if (guardian.MagicMirrorTrigger) { ChangeStep(); Player player = Target; if (guardian.HasBuff(Terraria.ID.BuffID.Horrified)) { string Mes; switch (Main.rand.Next(6)) { default: Mes = " is asking if you are nuts."; break; case 0: Mes = " is asking what you have on your head."; break; case 1: Mes = " says that this is not the right time and place to do that."; break; case 2: Mes = " questions itself \"WHAT?!\" a few moments before attempting to teleport."; break; case 3: Mes = " asks if there is something wrong with your head."; break; case 4: Mes = " said that It's not the wisest thing to do right now."; break; } Main.NewText("*" + guardian.Name + Mes + "*"); } else { player.Spawn(); guardian.Spawn(); PlayerMod pm = player.GetModPlayer <PlayerMod>(); /*guardian.Spawn(); * guardian.Position.X = player.SpawnX * 16; * guardian.Position.Y = player.SpawnY * 16; * player.position.X = player.SpawnX * 16 + 8 - player.width * 0.5f; * player.position.Y = player.SpawnY * 16 - player.height;*/ Vector2 PlayerBottom = new Vector2(player.position.X + player.width * 0.5f, player.position.Y + player.height); guardian.Position = PlayerBottom; guardian.FallStart = (int)guardian.Position.Y / 16; foreach (TerraGuardian mg in pm.GetAllGuardianFollowers) { if (mg.Active && (mg.PlayerMounted || mg.PlayerControl)) { mg.Spawn(); mg.Position = PlayerBottom; mg.FallStart = (int)mg.Position.Y / 16; } } } } HoldingPlayer = true; } break; case 3: { if (guardian.ItemAnimationTime == 0) { ChangeStep(); } HoldingPlayer = true; } break; case 4: { if (!CanPickupPlayer) { ChangeStep(); } else { FocusCameraOnGuardian = true; if (Time < 8) { if (guardian.Ducking) { int AnimFrame = 2 - Time / 4; SetPlayerOnHandPosition(guardian, Target, guardian.Base.DuckingSwingFrames[2 - AnimFrame], HeldHand.Right); } else { int AnimFrame = 2 - Time / 4; SetPlayerOnHandPosition(guardian, Target, guardian.Base.ItemUseFrames[3 - AnimFrame], HeldHand.Right); } } else { ChangeStep(); } } } break; case 5: if (CanPickupPlayer) { SetPlayerPositionOnGuardianCenter(guardian, Target); } InUse = false; break; } if (HoldingPlayer) { if (CanPickupPlayer) { FocusCameraOnGuardian = true; if (guardian.Ducking) { SetPlayerOnHandPosition(guardian, Target, guardian.Base.DuckingSwingFrames[1], HeldHand.Right); } else { SetPlayerOnHandPosition(guardian, Target, guardian.Base.ItemUseFrames[2], HeldHand.Right); } Target.velocity.Y = -Player.defaultGravity; guardian.ProtectingPlayerFromHarm = true; } else if (!guardian.PlayerMounted && !guardian.SittingOnPlayerMount) { /*Vector2 HandPosition = GetHandPosition(guardian, guardian.Base.ItemUseFrames[2], HeldHand.Right); * float HorizontalPosChange = Target.Center.X - HandPosition.X; * if (!guardian.PlayerMounted && !guardian.SittingOnPlayerMount && Math.Abs(HorizontalPosChange) >= Target.width * 0.5f) * { * //guardian.Position.X += HorizontalPosChange; * if (HorizontalPosChange < 0) * { * guardian.MoveLeft = true; * } * else * { * guardian.MoveRight = true; * } * }*/ } } }
public const int PullMaxTime = 45; //Like his miniboss version public override void Update(TerraGuardian Me) { if (Me.UsingFurniture) { Me.LeaveFurniture(true); } if (Time >= PullMaxTime) { if (Time == PullMaxTime) { if (TargetIsPlayer) { PullStartPosition = TargetPlayer.Center; if (TargetPlayer.GetModPlayer <PlayerMod>().BeingCarriedByGuardian) { InUse = false; return; } } else { PullStartPosition = TargetGuardian.CenterPosition; if (TargetGuardian.BeingCarriedByGuardian) { InUse = false; return; } } } if (TargetIsPlayer) { Player player = TargetPlayer; Vector2 MoveDirection = Me.CenterPosition - player.Center; MoveDirection.Normalize(); Me.LookingLeft = player.Center.X < Me.Position.X; player.velocity = Vector2.Zero; player.position += MoveDirection * 8f; player.fallStart = (int)player.position.Y / 16; player.immuneTime = 5; player.immuneNoBlink = true; if (player.getRect().Intersects(Me.HitBox)) { player.velocity = Vector2.Zero; InUse = false; Me.StartNewGuardianAction(new Actions.CarryDownedAlly(player)); return; } } else { TerraGuardian guardian = TargetGuardian; Vector2 MoveDirection = Me.CenterPosition - guardian.CenterPosition; MoveDirection.Normalize(); Me.LookingLeft = guardian.Position.X < Me.Position.X; guardian.Velocity = Vector2.Zero; guardian.Position += MoveDirection * 8f; guardian.SetFallStart(); guardian.ImmuneTime = 5; guardian.ImmuneNoBlink = true; if (guardian.HitBox.Intersects(Me.HitBox)) { guardian.Velocity = Vector2.Zero; InUse = false; Me.StartNewGuardianAction(new Actions.CarryDownedAlly(guardian)); return; } } } else { if (Time == 30) { switch (Main.rand.Next(5)) { case 0: Me.SaySomething("*Better you stay close to me.*"); break; case 1: Me.SaySomething("*Let's avoid another death.*"); break; case 2: Me.SaySomething("*Come here.*"); break; case 3: Me.SaySomething("*Get over here.*"); break; case 4: Me.SaySomething("*No, you wont.*"); break; } } } }
public override void Update(TerraGuardian guardian) { if (guardian.UsingFurniture) { guardian.LeaveFurniture(true); } AvoidItemUsage = true; IgnoreCombat = true; Vector2 CastingPosition = guardian.CenterPosition; CastingPosition.Y -= guardian.Height; Target.respawnTimer++; guardian.Ducking = false; float Percentage = (float)Time / 150; if (Target.dead) { const float MoveSpeed = 0.3f; Vector2 Velocity = (CastingPosition - Target.Center) * 0.1f; if (Velocity.Length() > 2f) { Velocity.Normalize(); Velocity *= 2f; } Target.Center += Velocity; Target.immuneAlpha = (int)(255 * (1f - Percentage)); for (int i = 0; i < 3; i++) { float EstimatedDistance = 150 * (1f - Percentage); float Rotation = MathHelper.ToRadians(Time + i * 120); Vector2 EndPosition = new Vector2((float)Math.Sin(Rotation), (float)Math.Cos(Rotation)) * EstimatedDistance; switch (i) { case 0: Target.headPosition += (EndPosition - Target.headPosition) * MoveSpeed; break; case 1: Target.bodyPosition += (EndPosition - Target.bodyPosition) * MoveSpeed; break; case 2: Target.legPosition += (EndPosition - Target.legPosition) * MoveSpeed; break; } } //target.headPosition += (CastingPosition - target.headPosition) * Percentage; //target.bodyPosition += (CastingPosition - target.bodyPosition) * Percentage; //target.legPosition += (CastingPosition - target.legPosition) * Percentage; } if (Time >= 150) //Res { if (Time == 150) { if (Target.dead || Target.ghost) { Target.ghost = false; Target.respawnTimer = 0; //if(target.difficulty == 2) // Main.ActivePlayerFileData. Target.Spawn(); //target.statLife = (int)(target.statLifeMax2 * 0.5f); Target.immuneTime *= 2; //Add cooldown. Main.NewText(guardian.Name + " has resurrected " + Target.name + ".", 0, 255, 0); } } else if (Time == 151) { Target.velocity.X = 0f; Target.velocity.Y = -7.25f; Target.Center = CastingPosition; Target.fallStart = (int)guardian.Position.Y / 16; InUse = false; } } else { for (int i = 0; i < 10; i++) { int d = Dust.NewDust(CastingPosition, Target.width, Target.height, 5, 0, 0, 175, default(Color), 1.75f); Main.dust[d].noGravity = true; Main.dust[d].velocity *= 0.75f; int XChange = Main.rand.Next(-40, 41), YChange = Main.rand.Next(-40, 41); Main.dust[d].position.X += XChange; Main.dust[d].position.Y += YChange; Main.dust[d].velocity.X -= XChange * 0.075f; Main.dust[d].velocity.Y -= YChange * 0.075f; } } }