Exemplo n.º 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();
        }