public override void Update(TerraGuardian guardian)
        {
            TerraGuardian ControlledGuardian = PlayerMod.PlayerControllingGuardian(PlayerToPlaceOnFloor) ? PlayerToPlaceOnFloor.GetModPlayer <PlayerMod>().Guardian : null;

            if (Time == 0 && guardian.PlayerMounted)
            {
                guardian.ToggleMount(false, false);
            }
            if (guardian.ReverseMount || guardian.Base.DontUseRightHand || guardian.UsingFurniture)
            {
                InUse = false;
            }
            else
            {
                FocusCameraOnGuardian = true;
                if (Time >= 20)
                {
                    InUse = false;
                    if (ControlledGuardian == null)
                    {
                        PlayerToPlaceOnFloor.position.X = guardian.Position.X - PlayerToPlaceOnFloor.width * 0.5f;
                        PlayerToPlaceOnFloor.position.Y = guardian.Position.Y - PlayerToPlaceOnFloor.height;
                        PlayerToPlaceOnFloor.velocity   = guardian.Velocity;
                        PlayerToPlaceOnFloor.fallStart  = (int)PlayerToPlaceOnFloor.position.Y / 16;
                    }
                    else
                    {
                        ControlledGuardian.Position = guardian.Position;
                        ControlledGuardian.Velocity = guardian.Velocity;
                        ControlledGuardian.SetFallStart();
                    }
                }
                else
                {
                    int AnimFrame = guardian.Base.ItemUseFrames[0];
                    if (Time >= 15)
                    {
                        AnimFrame = guardian.Base.ItemUseFrames[3];
                    }
                    else if (Time >= 10)
                    {
                        AnimFrame = guardian.Base.ItemUseFrames[2];
                    }
                    else if (Time >= 5)
                    {
                        AnimFrame = guardian.Base.ItemUseFrames[1];
                    }
                    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 -= PlayerToPlaceOnFloor.width * 0.5f;
                        HandPosition.Y -= PlayerToPlaceOnFloor.height * 0.5f;
                        PlayerToPlaceOnFloor.position   = HandPosition;
                        PlayerToPlaceOnFloor.fallStart  = (int)PlayerToPlaceOnFloor.position.Y / 16;
                        PlayerToPlaceOnFloor.velocity.X = 0;
                        PlayerToPlaceOnFloor.velocity.Y = -Player.defaultGravity;
                        if (PlayerToPlaceOnFloor.itemAnimation == 0)
                        {
                            PlayerToPlaceOnFloor.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 = PlayerToPlaceOnFloor.controlRight;
            guardian.MoveLeft  = PlayerToPlaceOnFloor.controlLeft;
            guardian.MoveUp    = PlayerToPlaceOnFloor.controlUp;
            guardian.MoveDown  = PlayerToPlaceOnFloor.controlDown;
            guardian.Jump      = PlayerToPlaceOnFloor.controlJump;
        }
Example #2
0
        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) //Add a overrideable method for custom dialogues.
        {
            this.guardian = guardian;
            bool IsWere        = CastellaBase.OnWerewolfForm(guardian);
            bool LookForVictim = false;

            switch (Step)
            {
            case 0:     //Pick behavior step;
                IgnoreCombat = true;
                if (IsWere)
                {
                    if (StepStart)
                    {
                        Main.NewText("Awooooooooooo!!");
                    }
                    if (Time >= 300)
                    {
                        ChangeStep(1);
                    }
                }
                else
                {
                    InUse = false;
                }
                break;

            case 1:
            {
                IgnoreCombat  = false;
                LookForVictim = true;
            }
            break;

            case 200:
            case 201:
            case 202:
            {
                IgnoreCombat      = true;
                AvoidItemUsage    = true;
                guardian.MoveLeft = guardian.MoveRight = guardian.Jump = guardian.MoveDown = false;
                switch (VictimType)
                {
                case TerraGuardian.TargetTypes.Guardian:
                {
                    if (!MainMod.ActiveGuardians.ContainsKey(VictimID))
                    {
                        ChangeStep(1);
                        return;
                    }
                    TerraGuardian Victim = MainMod.ActiveGuardians[VictimID];
                    Victim.IsBeingPulledByPlayer = false;
                    if (Victim.PlayerMounted)
                    {
                        Victim.ToggleMount(true, false);
                    }
                    Vector2 Position = guardian.GetGuardianBetweenHandPosition;
                    Victim.Position  = Position + new Vector2(0, Victim.Height * 0.5f);
                    Victim.Direction = -guardian.Direction;
                    Victim.Velocity  = Vector2.Zero;
                    Victim.SetFallStart();
                    Victim.AddBuff(Terraria.ID.BuffID.Cursed, 5, true);
                    if (Time == 120)
                    {
                        Victim.EnterDownedState();
                        Victim.KnockedOutCold = true;
                    }
                    if (Time >= 150)
                    {
                        ChangeStep(1);
                    }
                }
                break;

                case TerraGuardian.TargetTypes.Player:
                {
                    if (!Main.player[VictimID].active || Main.player[VictimID].dead)
                    {
                        ChangeStep(1);
                        return;
                    }
                    Player    Victim   = Main.player[VictimID];
                    PlayerMod pm       = Victim.GetModPlayer <PlayerMod>();
                    Vector2   Position = guardian.GetGuardianBetweenHandPosition;
                    Position.X      -= Victim.width * 0.5f;
                    Position.Y      -= Victim.height * 0.5f;
                    Victim.position  = Position;
                    Victim.direction = -guardian.Direction;
                    Victim.velocity  = Vector2.Zero;
                    Victim.fallStart = (int)(Victim.position.Y * (1f / 16));
                    Victim.AddBuff(Terraria.ID.BuffID.Cursed, 5);
                    if (guardian.TalkPlayerID > -1)
                    {
                        ChangeStep(201);
                    }
                    if (Step == 200 || Step == 202)
                    {
                        if (Time == 90)
                        {
                            if (Victim.statLife == 1)
                            {
                                Victim.statLife++;
                            }
                            if (!pm.KnockedOut)
                            {
                                Victim.Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(Victim.name + " couldn't endure the bite."), 1, 0);
                            }
                            pm.EnterDownedState(true);
                            Victim.statLife = 1;
                            Victim.Bottom   = guardian.Position;
                            if (Main.netMode == 0 && Victim.whoAmI == Main.myPlayer)
                            {
                                foreach (TerraGuardian tg in pm.GetAllGuardianFollowers)
                                {
                                    if (tg.Active)
                                    {
                                        tg.EnterDownedState();
                                    }
                                }
                                if (guardian.IsTownNpc)
                                {
                                    guardian.TeleportHome();
                                }
                                else
                                {
                                    if (Main.rand.Next(3) != 0)
                                    {
                                        NpcMod.DespawnGuardianNPC(guardian);
                                    }
                                }
                                MainMod.DoBlackoutPlayer();
                                WorldMod.SkipTimeUntilMorning();
                                return;
                            }
                        }
                        if (Time >= 120)
                        {
                            ChangeStep(1);
                        }
                    }
                }
                break;
                }
            }
            break;
            }
            if (LookForVictim)
            {
                if (guardian.TargetID > -1 && guardian.TargetType != TerraGuardian.TargetTypes.Npc)
                {
                    AvoidItemUsage = true;
                    Rectangle GrabBox = guardian.HitBox;
                    GrabBox.Width += 8;
                    if (guardian.LookingLeft)
                    {
                        GrabBox.X -= 8;
                    }
                    switch (guardian.TargetType)
                    {
                    case TerraGuardian.TargetTypes.Guardian:
                        if (GrabBox.Intersects(MainMod.ActiveGuardians[guardian.TargetID].HitBox))
                        {
                            VictimID   = guardian.TargetID;
                            VictimType = guardian.TargetType;
                            ChangeStep(200);
                        }
                        break;

                    case TerraGuardian.TargetTypes.Player:
                        if (GrabBox.Intersects(Main.player[guardian.TargetID].getRect()))
                        {
                            VictimID   = guardian.TargetID;
                            VictimType = guardian.TargetType;
                            ChangeStep(200);
                        }
                        break;
                    }
                }
                else
                {
                    AvoidItemUsage = false;
                }
            }
        }
Example #4
0
        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;
            }
        }
Example #5
0
        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)
        {
            LiebreBase.ReaperGuardianData data = (LiebreBase.ReaperGuardianData)guardian.Data;
            switch (Step)
            {
            case 0:
                if (StepStart)
                {
                    SoulsValue = data.SoulsLoaded;
                    if (SoulsValue >= LiebreBase.MaxSoulsContainedValue)
                    {
                        guardian.SaySomething("*I must go, now!*");
                    }
                    else if (SoulsValue >= LiebreBase.MaxSoulsContainedValue * 0.9f)
                    {
                        guardian.SaySomething("*I'll unload those souls, I feel like I'm reaching my capacity.*");
                    }
                    else
                    {
                        guardian.SaySomething("*I'll be right back.*");
                    }
                }
                IgnoreCombat = true;
                if (Main.rand.NextDouble() < 0.333)
                {
                    Dust.NewDust(guardian.TopLeftPosition, guardian.Width, guardian.Height, 192, 0, -0.2f, Scale: Main.rand.NextFloat(0.8f, 1.2f));
                }
                if (Time >= 3 * 60)
                {
                    ChangeStep();
                    data.SoulsLoaded     = 0;
                    Invisibility         = true;
                    LastWasPlayerMounted = guardian.PlayerMounted;
                    guardian.ToggleMount(true);
                    guardian.ClearMessagesSaid();
                }
                break;

            case 1:
                Invisibility = true;
                IgnoreCombat = true;
                Inactivity   = true;
                if (guardian.OwnerPos > -1)
                {
                    guardian.Position = Main.player[guardian.OwnerPos].Bottom;
                }
                if (Time >= 10 * 60)
                {
                    ChangeStep();
                }
                break;

            case 2:
                Invisibility = false;
                IgnoreCombat = false;
                Inactivity   = false;
                if (StepStart)
                {
                    guardian.Spawn();
                    if (guardian.OwnerPos > -1)
                    {
                        guardian.Position = Main.player[guardian.OwnerPos].Bottom;
                        if (LastWasPlayerMounted)
                        {
                            guardian.ToggleMount(true, false);
                        }
                    }
                }
                if (Time >= 30)
                {
                    if (SoulsValue >= LiebreBase.MaxSoulsContainedValue)
                    {
                        guardian.SaySomething("*I felt like about to blow...*");
                    }
                    else if (SoulsValue >= LiebreBase.MaxSoulsContainedValue * 0.9f)
                    {
                        guardian.SaySomething("*I'm glad I managed to do the delivery in time.*");
                    }
                    else
                    {
                        guardian.SaySomething("*I returned.*");
                    }
                }
                if (Time % 10 == 0)
                {
                    float HeightVal = Time / 10 * 0.1f * guardian.Height;
                    for (int i = -1; i < 2; i++)
                    {
                        Vector2 EffectPosition = new Vector2(guardian.Position.X, guardian.Position.Y);
                        EffectPosition.Y -= HeightVal;
                        EffectPosition.X += guardian.Width * 0.6f * i;
                        Dust.NewDust(EffectPosition, 1, 1, 192, 0, -0.2f, 192, Scale: Main.rand.NextFloat(0.8f, 1.2f));
                    }
                }
                if (Time >= 100)
                {
                    {
                        float CapacityPercentage = (float)SoulsValue / LiebreBase.MaxSoulsContainedValue;
                        int   BuffDuration       = (int)(CapacityPercentage * 900) * 60;
                        if (SoulsValue > LiebreBase.MaxSoulsContainedValue)
                        {
                            BuffDuration = (int)(BuffDuration * 0.75f);
                        }
                        for (int i = 0; i < CapacityPercentage * 5; i++)
                        {
                            int BuffID = Utils.SelectRandom(Main.rand, new int[] { Terraria.ID.BuffID.Lifeforce, Terraria.ID.BuffID.Regeneration,
                                                                                   Terraria.ID.BuffID.Endurance, Terraria.ID.BuffID.ManaRegeneration, Terraria.ID.BuffID.Mining, Terraria.ID.BuffID.ObsidianSkin,
                                                                                   Terraria.ID.BuffID.Thorns });
                            for (int p = 0; p < 255; p++)
                            {
                                if (Main.player[p].active && !guardian.IsPlayerHostile(Main.player[p]))
                                {
                                    Main.player[p].AddBuff(BuffID, BuffDuration);
                                }
                            }
                            foreach (TerraGuardian g in MainMod.ActiveGuardians.Values)
                            {
                                if (g.OwnerPos == guardian.OwnerPos && !g.IsGuardianHostile(guardian))
                                {
                                    g.AddBuff(BuffID, BuffDuration);
                                }
                            }
                        }
                        guardian.SaySomethingCanSchedule("*Take this blessing as a reward for helping me.*");
                    }
                    guardian.DoAction.InUse = false;
                }
                break;
            }
        }
Example #7
0
        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;
            }
        }