public override void Update(TerraGuardian guardian) { AvoidItemUsage = true; switch (Step) { case 0: //Reach Target Vector2 TargetPosition = Vector2.Zero; int TargetWidth = 0, TargetHeight = 0; IgnoreCombat = true; if (TargetIsPlayer) { TargetPosition = TargetPlayer.position; TargetWidth = TargetPlayer.width; TargetHeight = TargetPlayer.height; } else { TargetPosition = TargetGuardian.TopLeftPosition; TargetWidth = TargetGuardian.Width; TargetHeight = TargetGuardian.Height; } if (guardian.HitBox.Intersects(new Rectangle((int)TargetPosition.X, (int)TargetPosition.Y, TargetWidth, TargetHeight))) { ChangeStep(); } else { guardian.MoveLeft = guardian.MoveRight = false; if (TargetPosition.X + TargetWidth * 0.5f - guardian.Position.X < 0) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } if (Time >= 5 * 60) { InUse = false; guardian.DisplayEmotion(TerraGuardian.Emotions.Sad); } } break; case 1: { guardian.MoveLeft = guardian.MoveRight = false; NoAggro = AvoidItemUsage = Immune = true; Vector2 EffectPosition = new Vector2(22 * guardian.Scale * guardian.Direction, 0) + guardian.Position; bool AnimationTrigger = Time == 120 + 8 * 2 || Time == 120 + 8 * 5 + 8 * 2 || Time == 120 + 8 * 10 + 8 * 2; bool RestoreCharacters = false; if (Time >= 120 + 8 * 15) { RestoreCharacters = true; InUse = false; } if (TargetIsPlayer) { Player p = TargetPlayer; if (AnimationTrigger) { int HealthRestored = (int)(p.statLifeMax2 * 0.1f); p.statLife += HealthRestored; p.HealEffect(HealthRestored); } if (RestoreCharacters) { p.position = guardian.Position; p.position.X -= p.width * 0.5f; p.position.Y -= p.height; p.fullRotation = 0; } else { p.Center = EffectPosition; p.direction = -guardian.Direction; p.fullRotation = 1.570796326794897f * guardian.Direction; if (p.immuneTime < 5) { p.immuneTime = 5; } } } else { TerraGuardian g = TargetGuardian; if (AnimationTrigger) { g.RestoreHP((int)(g.MHP * 0.1f)); } if (RestoreCharacters) { g.Position = guardian.Position; g.Rotation = 0; } else { g.Position = EffectPosition; g.Position.Y += g.Height * 0.5f; g.Direction = -g.Direction; g.Rotation = 1.570796326794897f * guardian.Direction; if (g.ImmuneTime < 5) { g.ImmuneTime = 5; } } } } break; } }
public override void AI() { if (Main.myPlayer == -1) { return; } Player player = Main.player[npc.target]; if (JustSpawned) { //if (IsInPerceptionRange(player)) int NearestPlayer = Main.myPlayer; float NearestDistance = float.MaxValue; Vector2 NpcCenter = npc.Center; for (int p = 0; p < 255; p++) { if (Main.player[p].active) { float Distance = Main.player[p].Distance(NpcCenter); if (Distance < NearestDistance) { NearestDistance = Distance; NearestPlayer = p; } } } if (NearestPlayer > -1) { player = Main.player[NearestPlayer]; npc.target = NearestPlayer; //Main.NewText("A White Cat appeared to the " + GuardianBountyQuest.GetDirectionText(npc.Center - player.Center) + " of " + player.name + " position.", MainMod.MysteryCloseColor); } JustSpawned = false; } if (player.talkNPC == npc.whoAmI) { npc.direction = player.Center.X - npc.Center.X >= 0 ? 1 : -1; } if (SceneStep == SceneIds.NoScene && Math.Abs(player.Center.X - npc.Center.X) <= 152 && ((player.Center.X < npc.Center.X && npc.direction < 0) || (player.Center.X > npc.Center.X && npc.direction >= 0))) { //Found Sardine if (PlayerMod.PlayerHasGuardian(player, 7)) { ChangeScene(SceneIds.BreeSeesFriendlyFace); } else if (PlayerMod.PlayerHasGuardianSummoned(player, GuardianBase.Glenn) && PlayerMod.PlayerHasGuardianSummoned(player, GuardianBase.Sardine)) { ChangeScene(SceneIds.BreeSpotsSardineAndGlenn); SayMessage("Are they... Glenn! Sardine!"); HadSardineSpotted = HadGlennSpotted = true; } else if (PlayerMod.PlayerHasGuardianSummoned(player, GuardianBase.Glenn)) { ChangeScene(SceneIds.GlennSpotted); SayMessage("Gl... Glenn?!"); HadSardineSpotted = false; HadGlennSpotted = true; } else if (PlayerMod.PlayerHasGuardianSummoned(player, 2)) { ChangeScene(0); SayMessage("Sardine! I finally found you!"); HadSardineSpotted = true; HadGlennSpotted = false; } } npc.npcSlots = 1; if (SceneStep >= 0) { npc.npcSlots = 200; StepTime--; bool SceneChange = StepTime == 0; if (false && SceneStep == SceneIds.BreePersuadesThePlayerALittleCloser) { Vector2 PositionOnPlayer = player.Center; npc.direction = -player.direction; PositionOnPlayer.X += 12 * player.direction; PositionOnPlayer.Y += -Base.SpriteHeight + Base.SittingPoint.Y; int XMod = Base.SittingPoint.X; if (npc.direction < 0) { XMod = Base.SpriteWidth - XMod; } PositionOnPlayer.X += XMod - Base.SpriteWidth * 0.5f; npc.position = PositionOnPlayer; } TerraGuardian guardian = PlayerMod.GetPlayerMainGuardian(player), Sardine = PlayerMod.GetPlayerSummonedGuardian(player, GuardianBase.Sardine), Glenn = PlayerMod.GetPlayerSummonedGuardian(player, GuardianBase.Glenn); if (HadGlennSpotted && HadSardineSpotted) { if (Sardine != null && Glenn != null) { bool GlennIsClosest = (Glenn.CenterPosition - player.Center).Length() < (Sardine.CenterPosition - player.Center).Length(); if (GlennIsClosest) { guardian = Glenn; bool IsGlennToTheLeft = guardian.Position.X - npc.Center.X < 0; if (Math.Abs(guardian.Position.X - npc.Center.X) >= 96) { if (!IsGlennToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (!guardian.IsAttackingSomething && guardian.Velocity.X == 0) { guardian.FaceDirection(!IsGlennToTheLeft); } if (npc.velocity.X == 0) { npc.direction = !IsGlennToTheLeft ? 1 : -1; } } else { guardian = Sardine; bool IsSardineToTheLeft = guardian.Position.X - npc.Center.X < 0; if (Math.Abs(guardian.Position.X - npc.Center.X) >= 96) { if (!IsSardineToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (!guardian.IsAttackingSomething && guardian.Velocity.X == 0) { guardian.FaceDirection(!IsSardineToTheLeft); } if (npc.velocity.X == 0) { npc.direction = !IsSardineToTheLeft ? 1 : -1; } } if (SceneStep >= SceneIds.BreePersuadesThePlayerToCallHimBack && SceneStep <= SceneIds.BreePersuadesThePlayerALittleCloser) { if (InterruptedOnce) { ChangeScene(SceneIds.SardineIsCalledBackByPlayerAfterInterruption); } else { ChangeScene(SceneIds.PlayerCalledSardineBackAfterBreeAsked); } } } else { bool IsPlayerToTheLeft = player.Center.X - npc.Center.X < 0; if (Math.Abs(player.Center.X - npc.Center.X) >= 96) { if (!IsPlayerToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (npc.velocity.X == 0) { npc.direction = !IsPlayerToTheLeft ? 1 : -1; } if (SceneStep >= SceneIds.BothAnswers && SceneStep < SceneIds.BreeThenSaysThatTheyShouldStayInTheWorldForAWhileThen) { InterruptedOnce = true; if (Sardine == null) { ChangeScene(SceneIds.PlayerUnsummonedSardine); } else { ChangeScene(SceneIds.PlayerUnsummonedGlenn); } } } } else if (HadGlennSpotted) { if (Glenn != null) { guardian = Glenn; bool IsGlennToTheLeft = guardian.Position.X - npc.Center.X < 0; if (Math.Abs(guardian.Position.X - npc.Center.X) >= 96) { if (!IsGlennToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (!guardian.IsAttackingSomething && guardian.Velocity.X == 0) { guardian.FaceDirection(!IsGlennToTheLeft); } if (npc.velocity.X == 0) { npc.direction = !IsGlennToTheLeft ? 1 : -1; } if (SceneStep >= SceneIds.BreePersuadesThePlayerToCallHimBack && SceneStep <= SceneIds.BreePersuadesThePlayerALittleCloser) { if (InterruptedOnce) { ChangeScene(SceneIds.SardineIsCalledBackByPlayerAfterInterruption); } else { ChangeScene(SceneIds.PlayerCalledSardineBackAfterBreeAsked); } } } else { bool IsPlayerToTheLeft = player.Center.X - npc.Center.X < 0; if (Math.Abs(player.Center.X - npc.Center.X) >= 96) { if (!IsPlayerToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (npc.velocity.X == 0) { npc.direction = !IsPlayerToTheLeft ? 1 : -1; } if (SceneStep >= SceneIds.GlennAnswer && SceneStep < SceneIds.BreeJoinsToTakeCareOfGlenn) { InterruptedOnce = true; ChangeScene(SceneIds.PlayerUnsummonedGlenn); } } } else if (HadSardineSpotted) { if (Sardine != null) { guardian = Sardine; bool IsSardineToTheLeft = guardian.Position.X - npc.Center.X < 0; if (Math.Abs(guardian.Position.X - npc.Center.X) >= 96) { if (!IsSardineToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (!guardian.IsAttackingSomething) { guardian.FaceDirection(!IsSardineToTheLeft); } if (npc.velocity.X == 0) { npc.direction = !IsSardineToTheLeft ? 1 : -1; } if (SceneStep >= SceneIds.BreePersuadesThePlayerToCallHimBack && SceneStep <= SceneIds.BreePersuadesThePlayerALittleCloser) { if (InterruptedOnce) { ChangeScene(SceneIds.SardineIsCalledBackByPlayerAfterInterruption); } else { ChangeScene(SceneIds.PlayerCalledSardineBackAfterBreeAsked); } } } else { bool IsPlayerToTheLeft = player.Center.X - npc.Center.X < 0; if (Math.Abs(player.Center.X - npc.Center.X) >= 96) { if (!IsPlayerToTheLeft) { MoveRight = true; } else { MoveLeft = true; } } if (npc.velocity.X == 0) { npc.direction = !IsPlayerToTheLeft ? 1 : -1; } if (SceneStep >= SceneIds.SardineStaysAndTalksToBree && SceneStep < SceneIds.BreeTurnsToTownNpc) { InterruptedOnce = true; ChangeScene(SceneIds.PlayerUnsummonedSardine); } if (SceneStep == SceneIds.SardineSpotted) { ChangeScene(SceneIds.SardineFlees); } } } if (SceneChange) { switch (SceneStep) { case SceneIds.SardineSpotted: if (guardian.FriendshipLevel < 5 && (!PlayerMod.HasBuddiesModeOn(player) || !PlayerMod.GetPlayerBuddy(player).IsSameID(guardian))) //Tries to flee { ChangeScene(SceneIds.SardineFlees); guardian.SaySomething("Uh oh, I gotta go."); } else //Stays { ChangeScene(SceneIds.SardineStaysAndTalksToBree); guardian.SaySomething("Uh oh."); } break; case SceneIds.SardineFlees: if (PlayerMod.GetPlayerMainGuardian(player).Active) { TerraGuardian SardineRef = null; foreach (TerraGuardian tg in player.GetModPlayer <PlayerMod>().GetAllGuardianFollowers) { if (tg.ID == 2 && tg.ModID == MainMod.mod.Name) { SardineRef = tg; break; } } player.GetModPlayer <PlayerMod>().DismissGuardian(2, ""); if (SardineRef != null && SardineRef.Active) { SardineRef.Spawn(); } } SayMessage("What? Where did he go?"); ChangeScene(SceneIds.BreeAsksWhereSardineWent); break; case SceneIds.BreeAsksWhereSardineWent: SayMessage("You can call him back, right? Do so."); ChangeScene(SceneIds.BreePersuadesThePlayerToCallHimBack); break; case SceneIds.BreePersuadesThePlayerToCallHimBack: SayMessage("Call him back. NOW!"); ChangeScene(SceneIds.BreePersuadesThePlayerToCallHimBackAgain); break; case SceneIds.BreePersuadesThePlayerToCallHimBackAgain: ChangeScene(SceneIds.BreePersuadesThePlayerALittleCloser); SayMessage("I said... NOW!!!!"); break; case SceneIds.BreePersuadesThePlayerALittleCloser: { string Message = ""; switch (SceneRepeatTimes) { case 0: Message = "Call him! JUST. CALL. HIM!"; break; case 1: Message = "You are making me angry.... EVEN MORE ANGRY!!!"; break; case 2: Message = "GRRRRRRR!!! RRRRRRRRRRRRRRRR!!! RRRRRRRRRRRRRRGHHHH!!"; break; case 3: Message = "MY PATIENCE IS ALREADY GOING DOWN THE DRAIN! CALL HIM BACK, NOW!!"; break; case 4: Message = "ENOUGH!! CALL HIM, NOW!"; ChangeScene(SceneIds.BreeForcedPlayerToCallSardineBack); break; } if (SceneStep == SceneIds.BreePersuadesThePlayerALittleCloser && SceneRepeatTimes < 4) { ChangeScene(SceneIds.BreePersuadesThePlayerALittleCloser); } SayMessage(Message); } break; case SceneIds.BreeForcedPlayerToCallSardineBack: { if (HadSardineSpotted) { player.GetModPlayer <PlayerMod>().CallGuardian(2, ""); } if (HadGlennSpotted) { player.GetModPlayer <PlayerMod>().CallGuardian(GuardianBase.Glenn, ""); } SayMessage("Good."); if (HadSardineSpotted && HadGlennSpotted) { ChangeScene(SceneIds.BreeAsksWhereWasSardine); } else if (HadGlennSpotted) { ChangeScene(SceneIds.GlennSpotted); } else { ChangeScene(SceneIds.SardineStaysAndTalksToBree); } } break; case SceneIds.SardineStaysAndTalksToBree: { guardian.SaySomething("H-Hello dear, how have you been latelly?"); ChangeScene(SceneIds.BreeScoldsSardine); } break; case SceneIds.BreeScoldsSardine: { SayMessage("Seriously?! That is all you have to say?"); ChangeScene(SceneIds.BreeContinues); } break; case SceneIds.BreeContinues: { SayMessage("You abandon me and your son at home and that is what you have to say?"); ChangeScene(SceneIds.SardineTriesToApologise); } break; case SceneIds.SardineTriesToApologise: { guardian.SaySomething("I'm sorry?"); ChangeScene(SceneIds.BreeDoesntAcceptTheApology); } break; case SceneIds.BreeDoesntAcceptTheApology: { SayMessage("That is it? You numbskull, you've been missing for " + (guardian.Data.GetBirthdayAge - guardian.Base.Age + 2) + " WHOLE YEARS!!"); ChangeScene(SceneIds.BreeContinuesAfterNotAcceptingTheApology); } break; case SceneIds.BreeContinuesAfterNotAcceptingTheApology: { SayMessage("Do you know how many worlds I travelled trying to find you! Even the planet of the tentacles I had to travel through!"); ChangeScene(SceneIds.SardineTriesToApologiseAgain); } break; case SceneIds.SardineTriesToApologiseAgain: { guardian.SaySomething("I already said that I'm sorry. I... Kind of forgot what world we lived so... I couldn't return."); guardian.DisplayEmotion(TerraGuardian.Emotions.Sweat); ChangeScene(SceneIds.BreeTalksAboutTakingSardineBackWithHer); } break; case SceneIds.BreeTalksAboutTakingSardineBackWithHer: { SayMessage("Then there is no problem, since YOU are going back home with ME!"); ChangeScene(SceneIds.SardineTriesTheButs); } break; case SceneIds.SardineTriesTheButs: { guardian.SaySomething("But... But... I have a job here and..."); ChangeScene(SceneIds.BreeSaysNoToButs); } break; case SceneIds.BreeSaysNoToButs: { SayMessage("No buts! We are going back now! I just need to remember which world we-"); ChangeScene(SceneIds.BreeTakesAPauseToRealizeSheForgotToo); } break; case SceneIds.BreeTakesAPauseToRealizeSheForgotToo: { SayMessage("..."); ChangeScene(SceneIds.BreeForgotTheWorldTheyLived); } break; case SceneIds.BreeForgotTheWorldTheyLived: { SayMessage("This can't be happening... I forgot which world we lived on!"); ChangeScene(SceneIds.SardineLaughsOfBree); } break; case SceneIds.SardineLaughsOfBree: { guardian.SaySomething("Haha! Joke is on you now. Looks like you'll have to say here for a while, until you remember."); guardian.DisplayEmotion(TerraGuardian.Emotions.Happy); ChangeScene(SceneIds.BreeAgrees); } break; case SceneIds.BreeAgrees: { SayMessage("Grrr... Alright! I'll stay for a while, but only until I remember the world we lived!"); ChangeScene(SceneIds.BreeIntroducesHerself); } break; case SceneIds.BreeIntroducesHerself: { SayMessage("My name is " + Base.Name + ", don't expect me to stay for long."); ChangeScene(SceneIds.BreeTurnsToTownNpc); } break; case SceneIds.BreeTurnsToTownNpc: { TransformNPC(); } break; case SceneIds.SardineIsCalledBackByPlayer: { SayMessage("There he is."); ChangeScene(SceneIds.SardineStaysAndTalksToBree); } break; case SceneIds.SardineIsCalledBackByPlayerAfterInterruption: { SayMessage("Don't do that again!"); ChangeScene(SceneIds.BreeTalksAboutSardineGoingBackWithHer); } break; case SceneIds.BreeTalksAboutSardineGoingBackWithHer: { SayMessage("We are returning to home right now!"); ChangeScene(SceneIds.SardineTriesTheButs); } break; case SceneIds.PlayerUnsummonedSardine: { SayMessage("Hey! We were talking!"); InterruptedOnce = true; ChangeScene(SceneIds.BreePersuadesThePlayerToCallHimBack); } break; case SceneIds.PlayerCalledSardineBackAfterBreeAsked: { SayMessage("Thank you. Now where was I?"); ChangeScene(SceneIds.SardineStaysAndTalksToBree); } break; case SceneIds.BreeSeesFriendlyFace: { SayMessage("Oh, It's you again."); ChangeScene(SceneIds.BreeSaysHowSheAppearedThere); } break; case SceneIds.BreeSaysHowSheAppearedThere: { SayMessage("I'm still looking for the world I lived, but It's funny to bump into you on the way."); ChangeScene(SceneIds.BreeJoinsYou); } break; case SceneIds.BreeJoinsYou: { SayMessage("Anyway, I'm here, If you need me."); ChangeScene(SceneIds.BreeTurnsToTownNpc); } break; case SceneIds.GlennSpotted: { SayMessage("Glenn! What are you doing here? You should be at home."); ChangeScene(SceneIds.GlennAnswer); } break; case SceneIds.GlennAnswer: { guardian.SaySomething("You and Dad were taking too long to come home, so I came looking for you two."); ChangeScene(SceneIds.AsksGlennIfHesOkay); } break; case SceneIds.AsksGlennIfHesOkay: { SayMessage("But It's dangerous out there! Are you hurt?"); ChangeScene(SceneIds.GlennSaysThatIsFine); } break; case SceneIds.GlennSaysThatIsFine: { guardian.SaySomething("I'm okay, don't worry. This Terrarian let me stay here, and It's safe here."); ChangeScene(SceneIds.BreeJoinsToTakeCareOfGlenn); } break; case SceneIds.BreeJoinsToTakeCareOfGlenn: { SayMessage("I can't let you stay here alone, I shouldn't have let you stay alone at home either. I'll stay here to take care of you, and look for your father."); ChangeScene(SceneIds.BreeIntroducesHerself); } break; case SceneIds.BreeSpotsSardineAndGlenn: { SayMessage("Are you two alright?"); ChangeScene(SceneIds.BothAnswers); } break; case SceneIds.BothAnswers: { Sardine.SaySomething("Yes, we're fine."); Glenn.SaySomething("I'm okay."); ChangeScene(SceneIds.BreeAsksWhereWasSardine); } break; case SceneIds.BreeAsksWhereWasSardine: { SayMessage("I'm so glad you two are fine. Sardine, where did you go? Why didn't you returned home?"); ChangeScene(SceneIds.SardineAnswers); } break; case SceneIds.SardineAnswers: { Sardine.SaySomething("I was trying to find treasures for you two... And then I was saved by that Terrarian from a bounty hunt that gone wrong."); ChangeScene(SceneIds.BreeThenFeelsRelievedAndAsksGlennWhatIsHeDoingHere); } break; case SceneIds.BreeThenFeelsRelievedAndAsksGlennWhatIsHeDoingHere: { SayMessage("I think I should think you then, Terrarian. Now Glenn, I told you to wait for us at home!"); ChangeScene(SceneIds.GlennAnswers); } break; case SceneIds.GlennAnswers: { Glenn.SaySomething("I stayed at home, but I was worried that you two didn't returned yet, so I explored worlds trying to find you two."); ChangeScene(SceneIds.BreeSuggestsToSpendSomeTimeTogetherBeforeReturningToTheWorld); } break; case SceneIds.BreeSuggestsToSpendSomeTimeTogetherBeforeReturningToTheWorld: { SayMessage("That's really reckless and dangerous, but I'm glad you two are unharmed. Let's spend a little time here and then return home."); ChangeScene(SceneIds.SardineSaysThatForgotWhereTheWorldIsAt); } break; case SceneIds.SardineSaysThatForgotWhereTheWorldIsAt: { Sardine.SaySomething("I hope you know our way home, because I forgot."); ChangeScene(SceneIds.GlennAlsoSaysThatForgot); } break; case SceneIds.GlennAlsoSaysThatForgot: { Glenn.SaySomething("I also forgot my way back home, sorry mom."); ChangeScene(SceneIds.BreeThenSaysThatTheyShouldStayInTheWorldForAWhileThen); } break; case SceneIds.BreeThenSaysThatTheyShouldStayInTheWorldForAWhileThen: { SayMessage("I can't remember either.... Well, I hope you don't mind if we stay here for longer, Terrarian."); ChangeScene(SceneIds.BreeIntroducesHerself); } break; case SceneIds.PlayerUnsummonedGlenn: { SayMessage("Where did you sent my son? Call him back now!"); InterruptedOnce = true; ChangeScene(SceneIds.BreePersuadesThePlayerToCallHimBack); } break; } } if (StepTime <= -600) { SayMessage("Uh... What was I saying? Oh... I remember now."); ChangeScene(SceneStep); } } else { Idle = true; } base.AI(); if (!Main.dayTime) { bool PlayerInRange = false; for (int p = 0; p < 255; p++) { Player pl = Main.player[p]; if ((Math.Abs(pl.Center.X - npc.Center.X) >= NPC.sWidth * 0.5f + NPC.safeRangeX || Math.Abs(pl.Center.Y - npc.Center.Y) >= NPC.sHeight * 0.5f + NPC.safeRangeY)) { PlayerInRange = true; } } if (!PlayerInRange) { //Main.NewText("The White Cat resumed the search for her husband.", Color.OrangeRed); npc.active = false; npc.life = 0; } } }
public override void Update(TerraGuardian guardian) { if (guardian.TargetID > -1 || guardian.TalkPlayerID > -1 || guardian.IsBeingPulledByPlayer) { InUse = false; return; } bool MakeNpcFocusOnGuardian = false; if (!guardian.PlayerMounted) { guardian.MoveLeft = guardian.MoveRight = false; } if (guardian.IsBeingPulledByPlayer) { InUse = false; return; } switch (Step) { case 0: //Try reaching npc { NPC npc = Main.npc[NpcPosition]; if (!npc.active) { InUse = false; return; } Vector2 NpcBottom = npc.Bottom; if (guardian.PlayerMounted) { if (StepStart) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.AskPlayerToGetCloserToShopNpc, "*This companion wants to buy from [shop]'s store.\nGet closer to It so they can buy from It.*"); Message.Replace("[shop]", npc.GivenOrTypeName); guardian.SaySomething(Message); } if (Math.Abs(guardian.Position.X - NpcBottom.X) >= 500) { guardian.DisplayEmotion(TerraGuardian.Emotions.Neutral); InUse = false; return; } } if (!guardian.PlayerMounted && Time == 5 * 60) { guardian.Position = NpcBottom; guardian.SetFallStart(); } else if (!guardian.PlayerMounted && Math.Abs(NpcBottom.X - guardian.Position.X) < 16) { if (guardian.Position.X >= NpcBottom.X) { guardian.MoveRight = true; } else { guardian.MoveLeft = true; } } else if (Math.Abs(NpcBottom.X - guardian.Position.X) >= 16f + guardian.Width * 0.5f) { if (!guardian.PlayerMounted) { if (guardian.Position.X < NpcBottom.X) { guardian.MoveRight = true; } else { guardian.MoveLeft = true; } } } else { MakeNpcFocusOnGuardian = true; ChangeStep(); if (guardian.PlayerMounted) { string Message = guardian.GetMessage(GuardianBase.MessageIDs.AskPlayerToWaitAMomentWhileCompanionIsShopping, "*They ask you to wait a moment.*"); Message = Message.Replace("[shop]", npc.GivenOrTypeName); guardian.SaySomething(Message); } } if (!guardian.PlayerMounted && Math.Abs(NpcBottom.Y - guardian.Position.Y) > 8) { if (guardian.Position.Y < NpcBottom.Y) { if (guardian.Velocity.Y == 0) { bool SolidBlockBellow = false; int CheckY = (int)(guardian.Position.Y + 2) / 16; for (int i = 0; i < guardian.Width / 16; i++) { int CheckX = (int)(guardian.TopLeftPosition.X / 16) + i; if (Main.tile[CheckX, CheckY].active() && Main.tileSolid[Main.tile[CheckX, CheckY].type] && !Terraria.ID.TileID.Sets.Platforms[Main.tile[CheckX, CheckY].type]) { SolidBlockBellow = true; break; } } if (!SolidBlockBellow) { guardian.MoveDown = true; guardian.Jump = true; } } } else { int CheckX = (int)(guardian.Position.X / 16); if (guardian.JumpHeight == 0 && !guardian.Jump || guardian.JumpHeight > 0) { for (int i = 1; i < 6; i++) { int CheckY = (int)(guardian.Position.Y / 16) - i; if (Main.tile[CheckX, CheckY].active() && Terraria.ID.TileID.Sets.Platforms[Main.tile[CheckX, CheckY].type]) { guardian.Jump = true; break; } } } } } } break; case 1: { NPC npc = Main.npc[NpcPosition]; MakeNpcFocusOnGuardian = true; Vector2 NpcCenter = npc.Center; if (Math.Abs(guardian.Position.X - NpcCenter.X) < 16) { if (guardian.Position.X < NpcCenter.X) { guardian.MoveLeft = true; } else { guardian.MoveRight = true; } } else if (guardian.Velocity.X == 0) { guardian.LookingLeft = guardian.Position.X >= NpcCenter.X; } if (Time == 60) { guardian.BuyItem(ItemID, BuyPrice, BuyStack, true); } if (Time >= (int)(1.5f * 60)) { InUse = false; if (guardian.PlayerMounted) { guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.GenericThankYou, "*They thanked you.*")); } return; } } break; default: InUse = false; return; } if (MakeNpcFocusOnGuardian) { NPC npc = Main.npc[NpcPosition]; if (npc.ai[0] != 0) { npc.netUpdate = true; } npc.ai[0] = 0; npc.ai[1] = 300; npc.localAI[3] = 100; if (npc.Center.X < guardian.Position.X) { npc.direction = 1; } else { npc.direction = -1; } } }
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) { 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; } }