Example #1
0
        public override void AI()
        {
            if (npc.ai[2] == 0)
            {
                npc.ai[2] = 1;
                npc.ai[3] = -3;
                npc.TargetClosest(false);
                Main.NewText("A huge Terra Guardian appeared " + GuardianBountyQuest.GetDirectionText(npc.Center - Main.player[npc.target].Center) + " near to " + Main.player[npc.target].name + ".");
            }
            if (npc.direction == 0)
            {
                npc.direction = 1;
            }
            bool JustSpottedPlayer = false;

            if (!SpottedPlayer)
            {
                Rectangle rect = new Rectangle((int)npc.Center.X, (int)npc.Center.Y, 300, 300);
                rect.Y -= rect.Height / 2;
                if (npc.direction < 0)
                {
                    rect.X -= rect.Width;
                }
                for (int p = 0; p < 255; p++)
                {
                    if (Main.player[p].active && Main.player[p].getRect().Intersects(rect) &&
                        Collision.CanHitLine(npc.position, npc.width, npc.height, Main.player[p].position, Main.player[p].width, Main.player[p].height))
                    {
                        SpottedPlayer     = true;
                        JustSpottedPlayer = true;
                        npc.target        = p;
                        if (Main.player[p].Center.X < npc.Center.X)
                        {
                            npc.direction = -1;
                        }
                        else
                        {
                            npc.direction = 1;
                        }
                        break;
                    }
                }
            }
            if (!RequestTaken)
            {
                this.Idle = true;
                npc.ai[0]++;
                if (SpottedPlayer)
                {
                    if (JustSpottedPlayer)
                    {
                        SayMessage("*Hey! Can you hear me? Come closer so we can talk, please.*");
                    }
                }
                else
                {
                    if (npc.ai[0] >= (300 + 60 * npc.ai[1]))
                    {
                        npc.ai[1] = 3 + Main.rand.Next(4);
                        npc.ai[0] = 0;
                        string Message = "";
                        switch (Main.rand.Next(5))
                        {
                        case 0:
                            Message = "*Is there really a town around here?*";
                            break;

                        case 1:
                            Message = "*I'm so hungry... I've been walking for days...*";
                            break;

                        case 2:
                            Message = "*I need to take some rest...*";
                            break;

                        case 3:
                            Message = "*Why are all the creatures here so aggressive?*";
                            break;

                        case 4:
                            Message = "*I wonder if there is someone nearby...*";
                            break;
                        }
                        SayMessage(Message);
                    }
                    npc.TargetClosest(false);
                }
                if (Main.player[npc.target].talkNPC == npc.whoAmI || SpottedPlayer)
                {
                    Idle = false;
                    if (Main.player[npc.target].Center.X < npc.Center.X)
                    {
                        npc.direction = -1;
                    }
                    else
                    {
                        npc.direction = 1;
                    }
                }
            }
            else if (RequestComplete)
            {
                if (HuggingPlayer != -1)
                {
                    Player player = Main.player[Main.myPlayer];
                    player.immuneTime    = 3;
                    player.immuneNoBlink = true;
                    PlayerMod pm = player.GetModPlayer <PlayerMod>();
                    bool      ControllingGuardian = pm.ControllingGuardian;
                    bool      ItemUsed = false, JumpUsed = false, MoveUsed = false;
                    if (ControllingGuardian)
                    {
                        pm.Guardian.ImmuneTime    = 3;
                        pm.Guardian.ImmuneNoBlink = true;
                        ItemUsed = pm.Guardian.LastAction && pm.Guardian.ItemAnimationTime == 0;
                        JumpUsed = pm.Guardian.LastJump;
                        MoveUsed = (pm.Guardian.LastMoveLeft) ||
                                   (pm.Guardian.LastMoveUp) ||
                                   (pm.Guardian.LastMoveRight) ||
                                   (pm.Guardian.LastMoveDown);
                    }
                    else
                    {
                        ItemUsed = player.controlUseItem;
                        JumpUsed = player.controlJump;
                        MoveUsed = (player.controlLeft) || (player.controlUp) || (player.controlRight) || (player.controlDown);
                    }
                    if (PlayerMod.PlayerMountedOnGuardian(player))
                    {
                        foreach (TerraGuardian guardian in pm.GetAllGuardianFollowers)
                        {
                            if (guardian.Active && guardian.PlayerMounted)
                            {
                                guardian.ToggleMount(true, false);
                            }
                        }
                    }
                    string Message = null;
                    if (HugPassed && HuggingPlayer > -1 && (ItemUsed || JumpUsed || MoveUsed))
                    {
                        if (ComplaintCooldown == 0)
                        {
                            switch (Main.rand.Next(3))
                            {
                            case 0:
                                Message = "*You can just talk to me if that's enough.*";
                                break;

                            case 1:
                                Message = "*Do you want me to stop? Talk to me again.*";
                                break;

                            case 2:
                                Message = "*Had enough of hugs? Talk to me so I can stop.*";
                                break;
                            }
                        }
                        ComplaintCooldown = 30;
                    }
                    else if (ItemUsed)
                    {
                        if (ComplaintCooldown == 0)
                        {
                            npc.ai[0] -= Main.rand.Next(19, 41);
                            if (player.inventory[player.selectedItem].damage > 0)
                            {
                                switch (Main.rand.Next(5))
                                {
                                case 0:
                                    Message = ("*Be careful! That can hurt someone!*");
                                    break;

                                case 1:
                                    Message = ("*Hey! Are you trying to hurt me?*");
                                    break;

                                case 2:
                                    Message = ("*You're doing the complete oposite of what a hug should do!*");
                                    break;

                                case 3:
                                    Message = ("*You'll end up hurting someone with that.*");
                                    break;

                                case 4:
                                    Message = ("*Keep that off my skin!*");
                                    break;
                                }
                            }
                            else
                            {
                                switch (Main.rand.Next(5))
                                {
                                case 0:
                                    Message = ("*What are you doing?*");
                                    break;

                                case 1:
                                    Message = ("*Can you stop doing that?*");
                                    break;

                                case 2:
                                    Message = ("*Hey! Watch out!*");
                                    break;

                                case 3:
                                    Message = ("*Do you easily get bored?*");
                                    break;

                                case 4:
                                    Message = ("*Why are you doing that?*");
                                    break;
                                }
                            }
                        }
                        ComplaintCooldown = 30;
                    }
                    else if (JumpUsed)
                    {
                        if (ComplaintCooldown == 0)
                        {
                            npc.ai[0] -= Main.rand.Next(23, 54);
                            switch (Main.rand.Next(5))
                            {
                            case 0:
                                Message = ("*Oof! Hey! My stomach!*");
                                break;

                            case 1:
                                Message = ("*Ouch! Are you a cat or something?*");
                                break;

                            case 2:
                                Message = ("*Urgh. Don't hit my belly!*");
                                break;

                            case 3:
                                Message = ("*Hey! Why the aggression?*");
                                break;

                            case 4:
                                Message = ("*Urrrf... (Breathing for a moment) Gasp! You took out all my air with that kick! Why?! Tell me why you did that?*");
                                break;
                            }
                        }
                        ComplaintCooldown = 30;
                    }
                    else if (MoveUsed)
                    {
                        if (ComplaintCooldown == 0)
                        {
                            npc.ai[0] -= Main.rand.Next(14, 33);
                            switch (Main.rand.Next(5))
                            {
                            case 0:
                                Message = ("*What are you doing?*");
                                break;

                            case 1:
                                Message = ("*It's hard to hug with you like that.*");
                                break;

                            case 2:
                                Message = ("*If you want me to stop, just tell me.*");
                                break;

                            case 3:
                                Message = ("*Are you tense or something? Stop that.*");
                                break;

                            case 4:
                                Message = ("*You'll end up falling if you keep doing that.*");
                                break;
                            }
                        }
                        ComplaintCooldown = 30;
                    }
                    else
                    {
                        if (ComplaintCooldown > 0)
                        {
                            ComplaintCooldown--;
                        }
                        npc.ai[0]++;
                        if (ControllingGuardian)
                        {
                            if (pm.Guardian.ItemAnimationTime == 0 && !pm.Guardian.MoveLeft && !pm.Guardian.MoveRight)
                            {
                                pm.Guardian.LookingLeft = npc.direction == 1;
                            }
                        }
                        else
                        {
                            if (player.itemAnimation == 0 && !player.controlLeft && !player.controlRight)
                            {
                                player.direction = -npc.direction;
                            }
                        }
                        if (HugPassed && npc.ai[0] % (60 * 10) == 0)
                        {
                            switch (Main.rand.Next(4))
                            {
                            case 0:
                                Message = "*You want some more hug? I don't mind.*";
                                break;

                            case 1:
                                Message = "*(Humming)*";
                                break;

                            case 2:
                                Message = "*Talk to me If you had enough.*";
                                break;

                            case 3:
                                Message = "*Warm.*";
                                break;
                            }
                        }
                        else if (npc.ai[0] >= (PlayerHasVladimir ? 0.3f : (Main.expertMode ? 1.2f : 0.5f)) * 60 * 60)
                        {
                            if (!HugPassed)
                            {
                                HugPassed = true;
                                Message   = "*Thank you, I was really needing that. I think this world could make use of someone like me. Call me Vladimir, It's my name.*";
                                npc.ai[0] = 1;
                            }
                        }
                        else if (player.talkNPC == npc.whoAmI && npc.ai[0] % (60 * 10) == 0)
                        {
                            switch (Main.rand.Next(5))
                            {
                            case 0:
                                Message = ("*You don't know how much I missed doing that.*");
                                break;

                            case 1:
                                Message = ("*It's good to feel another warm body after so much travel.*");
                                break;

                            case 2:
                                Message = ("*Just some more.*");
                                break;

                            case 3:
                                Message = ("*Thanks for the fishs, by the way.*");
                                break;

                            case 4:
                                Message = ("*Are there more people like you in this world?*");
                                break;
                            }
                        }
                    }
                    if (Message != null)
                    {
                        if (player.talkNPC == npc.whoAmI)
                        {
                            Main.npcChatText = Message;
                        }
                        else
                        {
                            SayMessage(Message);
                        }
                    }
                    Vector2 HugPosition = Base.MountShoulderPoints.GetPositionFromFrameVector(BodyAnimationFrame);
                    if (npc.direction < 0)
                    {
                        HugPosition.X = Base.SpriteWidth - HugPosition.X;
                    }
                    HugPosition.X -= Base.SpriteWidth * 0.5f;
                    HugPosition.Y -= Base.SpriteHeight;
                    HugPosition.X  = HugPosition.X * npc.scale + npc.position.X + npc.width * 0.5f;
                    HugPosition.Y  = HugPosition.Y * npc.scale + npc.position.Y + npc.height;
                    if (npc.ai[0] < -200)
                    {
                        switch (Main.rand.Next(5))
                        {
                        case 0:
                            Message = "*Alright, there you go. Happy?*";
                            break;

                        case 1:
                            Message = "*It was just a hug, why were you moving around like crazy?*";
                            break;

                        case 2:
                            Message = "*Does hugs makes you uncomfortable or something?*";
                            break;

                        case 3:
                            Message = "*Need to use the toilet or something?*";
                            break;

                        case 4:
                            Message = "*Is It the environment or me?*";
                            break;
                        }
                        HugPosition   = npc.Center;
                        HuggingPlayer = -1;
                    }
                    if (MessageTime <= 0 && !HasHugCommentHappened)
                    {
                        HasHugCommentHappened = true;
                        pm.CompanionReaction(GuardianBase.MessageIDs.VladimirRecruitPlayerGetsHugged);
                    }
                    if (ControllingGuardian)
                    {
                        pm.Guardian.Position      = HugPosition;
                        pm.Guardian.Position.Y   += pm.Guardian.Height * 0.5f;
                        pm.Guardian.Velocity.Y    = -pm.Guardian.Mass;
                        pm.Guardian.ImmuneTime    = 3;
                        pm.Guardian.ImmuneNoBlink = true;
                    }
                    else
                    {
                        player.Center     = HugPosition;
                        player.velocity.Y = -Player.defaultGravity;
                    }
                    if (!player.active)
                    {
                        SayMessage("*Where did that person go?*");
                        HuggingPlayer = -1;
                    }
                }
                else
                {
                    npc.TargetClosest();
                }
            }
            else if (RequestTaken)
            {
                npc.TargetClosest();
                float Distance = npc.Center.X - Main.player[npc.target].Center.X;
                if (Math.Abs(Distance) >= 68f)
                {
                    if (Distance < 0)
                    {
                        MoveRight = true;
                    }
                    else
                    {
                        MoveLeft = true;
                    }
                }
                if (npc.Distance(Main.player[npc.target].Center) >= 520f)
                {
                    npc.position    = Main.player[npc.target].position;
                    npc.position.Y -= Base.SpriteHeight - Player.defaultHeight;
                }
            }
            if (HuggingPlayer > -1)
            {
                DrawInFrontOfPlayers.Add(HuggingPlayer);
            }
            base.AI();
        }
Example #2
0
        public override void AI()
        {
            int NextStep = NpcRecruitStep;

            switch (NpcRecruitStep)
            {
            case IdleStep:
            {
                Idle = true;
                Rectangle SightRange = new Rectangle((int)npc.Center.X, (int)npc.Center.Y, 300, 300);
                SightRange.Y -= (int)(SightRange.Height * 0.5f);
                if (npc.direction < 0)
                {
                    SightRange.X -= SightRange.Width;
                }
                DialogueDuration++;
                if (DialogueDuration >= 600)
                {
                    DialogueDuration -= 600;
                    switch (Main.rand.Next(5))
                    {
                    case 0:
                        SayMessage("*Hm... It must be around here somewhere...*");
                        break;

                    case 1:
                        SayMessage("*Come on... Show up...*");
                        break;

                    case 2:
                        SayMessage("*...It's around here... I smell It.*");
                        break;

                    case 3:
                        SayMessage("*Terrarian, where are you...*");
                        break;

                    case 4:
                        SayMessage("*Once I catch that Terrarian.... Ugh...*");
                        break;
                    }
                }
                for (int p = 0; p < 255; p++)
                {
                    if (Main.player[p].active && !Main.player[p].dead)
                    {
                        if (Main.player[p].getRect().Intersects(SightRange) && Collision.CanHitLine(npc.position, npc.width, npc.height, Main.player[p].position, Main.player[p].width, Main.player[p].height) &&
                            !Main.player[p].GetModPlayer <PlayerMod>().ControllingGuardian)
                        {
                            npc.target = p;
                            NextStep   = CallingOutPlayerStep;
                            break;
                        }
                    }
                }
            }
            break;

            case CallingOutPlayerStep:
            {
                Idle = false;
                if (DialogueDuration == 0)
                {
                    if (PlayerMod.PlayerHasGuardian(Main.player[npc.target], GuardianID, GuardianModID))
                    {
                        SayMessage("*Hey, Terrarian! Over here!*");
                    }
                    else if (Main.player[npc.target].GetModPlayer <PlayerMod>().KnockedOut)
                    {
                        SayMessage("*You there! Hang on!*");
                    }
                    else
                    {
                        if (Main.rand.Next(2) == 0)
                        {
                            SayMessage("*Hey! You there! Stop!*");
                        }
                        else
                        {
                            SayMessage("*Hey! You! Don't move!*");
                        }
                    }
                }
                if (DialogueDuration >= 120)
                {
                    NextStep = ChasingPlayerStep;
                }
                else
                {
                    DialogueDuration++;
                }
                if (Main.player[npc.target].Center.X < npc.Center.X)
                {
                    npc.direction = -1;
                }
                else
                {
                    npc.direction = 1;
                }
                if (!Main.player[npc.target].active)
                {
                    NextStep = IdleStep;
                    SayMessage("*Hm... " + (Main.player[npc.target].Male ? "He" : "She") + " disappeared...*");
                }
                else if (Main.player[npc.target].dead)
                {
                    NextStep = IdleStep;
                    SayMessage("*Well... That's... Horrible...*");
                }
            }
            break;

            case ChasingPlayerStep:
            {
                Player player = Main.player[npc.target];
                if (player.Center.X < npc.Center.X)
                {
                    MoveLeft = true;
                }
                else
                {
                    MoveRight = true;
                }
                if (!player.GetModPlayer <PlayerMod>().KnockedOut&& npc.velocity.Y == 0 && player.velocity.Y != 0)
                {
                    Jump = true;
                }
                if (PlayerMod.PlayerHasGuardian(Main.player[npc.target], GuardianID, GuardianModID) && Math.Abs(player.Center.X - npc.Center.X) < 80)
                {
                    NextStep = SpeakingToAlreadyKnownPlayer;
                }
                else if (player.getRect().Intersects(npc.getRect()))
                {
                    if (Main.halloween)
                    {
                        MainMod.TriggerCompanionJS(GuardianID);
                    }
                    if (PlayerMod.PlayerHasGuardian(Main.player[npc.target], GuardianID, GuardianModID))
                    {
                        NextStep = SpeakingToAlreadyKnownPlayer;
                    }
                    else
                    {
                        NextStep = InvestigatingPlayerStep;
                    }
                }
                if (!player.active)
                {
                    NextStep = IdleStep;
                    SayMessage("*Hm... " + (Main.player[npc.target].Male ? "He" : "She") + " disappeared...*");
                }
                else if (player.dead)
                {
                    NextStep = IdleStep;
                    SayMessage("*Damn, I'm too late...*");
                }
            }
            break;

            case InvestigatingPlayerStep:
            {
                if (DialogueDuration == 0)
                {
                    FindFrame(0);
                }
                Player player = Main.player[npc.target];
                if (player.mount.Active)
                {
                    player.mount.Dismount(player);
                }
                if (player.GetModPlayer <PlayerMod>().MountedOnGuardian)
                {
                    foreach (TerraGuardian tg in player.GetModPlayer <PlayerMod>().GetAllGuardianFollowers)
                    {
                        if (tg.Active && tg.PlayerMounted)
                        {
                            tg.ToggleMount(true, false);
                        }
                    }
                }
                player.immuneTime    = 90;
                player.immuneNoBlink = true;
                Vector2 PlayerPosition = new Vector2(npc.Center.X + 32 * npc.direction, npc.position.Y + npc.height);
                player.fullRotationOrigin = new Vector2(player.width, player.height) * 0.5f;
                player.aggro = -99999;
                if (npc.direction > 0)
                {
                    player.fullRotation = 1.570796f;
                    player.direction    = -1;
                }
                else
                {
                    player.fullRotation = -1.570796f;
                    //PlayerPosition.X *= -1;
                    player.direction = 1;
                }
                DrawInFrontOfPlayers.Add(npc.whoAmI);
                player.velocity = Vector2.Zero;
                player.Center   = PlayerPosition;
                player.statLife++;
                if (player.mount.Active)
                {
                    player.mount.Dismount(player);
                }
                player.gfxOffY = -2;
                player.AddBuff(Terraria.ID.BuffID.Cursed, 5);
                if (npc.velocity.X != 0 || npc.velocity.Y != 0)
                {
                }
                else if (player.GetModPlayer <PlayerMod>().KnockedOut)
                {
                    if (DialogueDuration == 0)
                    {
                        SayMessage("*Better I take care of those wounds first.*");
                        DialogueDuration++;
                    }
                    player.GetModPlayer <PlayerMod>().ReviveBoost++;
                }
                else
                {
                    if (DialogueDuration % 210 == 0)
                    {
                        switch (DialogueDuration / 210)
                        {
                        case 0:
                            SayMessage("*Got you! Now don't move.*");
                            break;

                        case 1:
                            SayMessage("*Hm...*");
                            break;

                        case 2:
                            SayMessage("*Interesting...*");
                            break;

                        case 3:
                            SayMessage("*Uh huh...*");
                            break;

                        case 4:
                            SayMessage("*But you're not the one I'm looking for...*");
                            break;

                        case 5:
                            NextStep                  = IntroductingToPlayerStep;
                            player.fullRotation       = 0;
                            player.fullRotationOrigin = new Vector2(40, 56) * 0.5f;
                            player.position           = npc.Bottom;
                            player.position.Y        -= player.height;
                            player.immuneNoBlink      = false;
                            break;
                        }
                    }
                    DialogueDuration++;
                }
                if (!player.active)
                {
                    NextStep = IdleStep;
                    SayMessage("*" + (Main.player[npc.target].Male ? "He" : "She") + " disappeared!*");
                }
            }
            break;

            case IntroductingToPlayerStep:
            {
                if (DialogueDuration == 0)
                {
                    Main.player[npc.target].talkNPC = npc.whoAmI;
                    DialogueDuration = 1;
                    Main.npcChatText = GetChat();
                }
                if (!Main.player[npc.target].active)
                {
                    npc.TargetClosest(false);
                    DialogueDuration = 1;
                }
                if (DialogueDuration > 1 && Main.player[npc.target].talkNPC != npc.whoAmI)
                {
                    DialogueDuration = 1;
                }
            }
            break;

            case SpeakingToAlreadyKnownPlayer:
            {
                if (DialogueDuration % 180 == 0)
                {
                    switch (DialogueDuration / 180)
                    {
                    case 0:
                        SayMessage("*I didn't expected to see you here.*");
                        break;

                    case 1:
                        SayMessage("*I think I may have caught that Terrarian's scent around here.*");
                        break;

                    case 2:
                        SayMessage("*Or maybe I accidentally caught your scent again.*");
                        break;

                    case 3:
                        SayMessage("*Anyway, If you need me, I'll be around.*");
                        break;

                    case 4:
                    {
                        NpcMod.AddGuardianMet(GuardianID, GuardianModID);
                        WorldMod.TurnNpcIntoGuardianTownNpc(npc, GuardianID, GuardianModID);
                    }
                        return;
                    }
                }
                if (Math.Abs(Main.player[npc.target].Center.X - npc.Center.X) >= 30)
                {
                    Walk = true;
                    if (Main.player[npc.target].Center.X < npc.Center.X)
                    {
                        MoveLeft = true;
                    }
                    else
                    {
                        MoveRight = true;
                    }
                }
                else
                {
                    if (Main.player[npc.target].Center.X < npc.Center.X)
                    {
                        npc.direction = -1;
                    }
                    else
                    {
                        npc.direction = 1;
                    }
                }
                if (!Main.player[npc.target].active)
                {
                    NextStep = IdleStep;
                    SayMessage("*" + (Main.player[npc.target].Male ? "He" : "She") + " disappeared!*");
                }
                DialogueDuration++;
            }
            break;
            }
            if (NextStep != NpcRecruitStep)
            {
                NpcRecruitStep   = NextStep;
                DialogueDuration = 0;
            }
            base.AI();
        }