public override void GuardianUpdateScript(TerraGuardian guardian)
 {
     if (GetIfIsCloudForm(guardian))
     {
         if (guardian.Velocity.Y >= 2.3f)
         {
             guardian.Velocity.Y = 2.3f;
             guardian.SetFallStart();
         }
         else
         {
             //guardian.Velocity.Y += 0.05f;
         }
         if (!guardian.KnockedOut && !guardian.MountedOnPlayer && !guardian.UsingFurniture && guardian.Velocity.Y == 0 && guardian.BodyAnimationFrame != CloudFormRevive)
         {
             guardian.OffsetY -= ((float)Math.Sin(Main.GlobalTime * 2)) * 5;
         }
     }
 }
Esempio n. 2
0
        public const int PullMaxTime     = 45; //Like his miniboss version

        public override void Update(TerraGuardian Me)
        {
            if (Me.UsingFurniture)
            {
                Me.LeaveFurniture(true);
            }
            if (Time >= PullMaxTime)
            {
                if (Time == PullMaxTime)
                {
                    if (TargetIsPlayer)
                    {
                        PullStartPosition = TargetPlayer.Center;
                        if (TargetPlayer.GetModPlayer <PlayerMod>().BeingCarriedByGuardian)
                        {
                            InUse = false;
                            return;
                        }
                    }
                    else
                    {
                        PullStartPosition = TargetGuardian.CenterPosition;
                        if (TargetGuardian.BeingCarriedByGuardian)
                        {
                            InUse = false;
                            return;
                        }
                    }
                }
                if (TargetIsPlayer)
                {
                    Player  player        = TargetPlayer;
                    Vector2 MoveDirection = Me.CenterPosition - player.Center;
                    MoveDirection.Normalize();
                    Me.LookingLeft       = player.Center.X < Me.Position.X;
                    player.velocity      = Vector2.Zero;
                    player.position     += MoveDirection * 8f;
                    player.fallStart     = (int)player.position.Y / 16;
                    player.immuneTime    = 5;
                    player.immuneNoBlink = true;
                    if (player.getRect().Intersects(Me.HitBox))
                    {
                        player.velocity = Vector2.Zero;
                        InUse           = false;
                        Me.StartNewGuardianAction(new Actions.CarryDownedAlly(player));
                        return;
                    }
                }
                else
                {
                    TerraGuardian guardian      = TargetGuardian;
                    Vector2       MoveDirection = Me.CenterPosition - guardian.CenterPosition;
                    MoveDirection.Normalize();
                    Me.LookingLeft     = guardian.Position.X < Me.Position.X;
                    guardian.Velocity  = Vector2.Zero;
                    guardian.Position += MoveDirection * 8f;
                    guardian.SetFallStart();
                    guardian.ImmuneTime    = 5;
                    guardian.ImmuneNoBlink = true;
                    if (guardian.HitBox.Intersects(Me.HitBox))
                    {
                        guardian.Velocity = Vector2.Zero;
                        InUse             = false;
                        Me.StartNewGuardianAction(new Actions.CarryDownedAlly(guardian));
                        return;
                    }
                }
            }
            else
            {
                if (Time == 30)
                {
                    switch (Main.rand.Next(5))
                    {
                    case 0:
                        Me.SaySomething("*Better you stay close to me.*");
                        break;

                    case 1:
                        Me.SaySomething("*Let's avoid another death.*");
                        break;

                    case 2:
                        Me.SaySomething("*Come here.*");
                        break;

                    case 3:
                        Me.SaySomething("*Get over here.*");
                        break;

                    case 4:
                        Me.SaySomething("*No, you wont.*");
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        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;
                }
            }
        }
        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;
        }
Esempio n. 5
0
        public override void Update(TerraGuardian guardian)
        {
            switch (Step)
            {
            case 0:
            {
                if (guardian.Inventory[ItemSlot].type == 0 || guardian.Inventory[ItemSlot].stack < ItemStack)
                {
                    InUse = false;
                    return;
                }
                if (guardian.UsingFurniture)
                {
                    guardian.LeaveFurniture(true);
                }
                if (Formally)
                {
                    ChangeStep();
                }
                else
                {
                    ChangeStep(2);
                }
            }
            break;

            case 1:
            {
                Vector2 TargetPosition = Vector2.Zero;
                if (player != null)
                {
                    TargetPosition = player.Bottom;
                }
                else
                {
                    TargetPosition = tg.Position;
                }
                if (guardian.Position.X > TargetPosition.X)
                {
                    guardian.MoveLeft  = true;
                    guardian.MoveRight = false;
                }
                else
                {
                    guardian.MoveRight = true;
                    guardian.MoveLeft  = false;
                }
                if (Time >= 10 * 60)
                {
                    guardian.Position = TargetPosition;
                    guardian.SetFallStart();
                }
                if (TargetPosition.X >= guardian.Position.X - guardian.Width * 0.5f && TargetPosition.X < guardian.Position.X + guardian.Width * 0.5f &&
                    TargetPosition.Y >= guardian.Position.Y - guardian.Height && TargetPosition.Y - 24 < guardian.Position.Y)
                {
                    ChangeStep();
                }
            }
            break;

            case 2:
            {
                if (guardian.Inventory[ItemSlot].type == 0)
                {
                    InUse = false;         //Where's the item I was going to give?
                    guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.DeliveryItemMissing,
                                                              "*They seems to have wanted to deliver something, but can't find it in their inventory.*"));
                    return;
                }
                if (StepStart)
                {
                    if (player != null)
                    {
                        byte EmptySlot = 255;
                        byte MaxSlots  = 50;
                        if (guardian.Inventory[ItemSlot].ammo > 0)
                        {
                            MaxSlots = 54;
                        }
                        for (byte i = 0; i < MaxSlots; i++)
                        {
                            if (player.inventory[i].type == 0)
                            {
                                EmptySlot = i;
                            }
                        }
                        if (EmptySlot == 255)
                        {
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull,
                                                                 "*It seems like [target] have no room for what they wanted to give.*").
                                             Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name));
                            guardian.SaySomething(Message);
                            InUse = false;
                        }
                    }
                    else
                    {
                        int EmptySlot = -1;
                        for (int i = 0; i < guardian.Inventory.Length; i++)
                        {
                            if (guardian.Inventory[i].type == 0)
                            {
                                EmptySlot = i;
                            }
                        }
                        if (EmptySlot == 255)
                        {
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull,
                                                                 "*It seems like you have no room for what they wanted to give [target].*").Replace("[target]", tg.Name);
                            guardian.SaySomething(Message);
                            InUse = false;
                        }
                    }
                }
                else if (Time >= 60)
                {
                    if (player != null)
                    {
                        byte EmptySlot = 255;
                        byte MaxSlots  = 50;
                        if (guardian.Inventory[ItemSlot].ammo > 0)
                        {
                            MaxSlots = 54;
                        }
                        for (byte i = 0; i < MaxSlots; i++)
                        {
                            if (player.inventory[i].type == 0)
                            {
                                EmptySlot = i;
                            }
                        }
                        if (EmptySlot == 255)
                        {
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull,
                                                                 "*It seems like [target] have no room for what they wanted to give.*").
                                             Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name));
                            guardian.SaySomething(Message);
                        }
                        else
                        {
                            Item item = guardian.Inventory[ItemSlot].DeepClone();
                            player.GetItem(player.whoAmI, item);
                            guardian.Inventory[ItemSlot].SetDefaults(0, true);
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryGiveItem,
                                                                 "*" + guardian.Name + " gave [target] some [item].*").
                                             Replace("[target]", (player.whoAmI == Main.myPlayer ? guardian.PersonalNicknameToPlayer : player.name)).
                                             Replace("[item]", item.Name);
                            guardian.SaySomething(Message);
                        }
                    }
                    else
                    {
                        int EmptySlot = -1;
                        for (int i = 0; i < guardian.Inventory.Length; i++)
                        {
                            if (guardian.Inventory[i].type == 0)
                            {
                                EmptySlot = i;
                            }
                        }
                        if (EmptySlot == 255)
                        {
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryInventoryFull,
                                                                 "*It seems like [target] have no room for what they wanted to give.*").
                                             Replace("[target]", tg.Name);
                            guardian.SaySomething(Message);
                        }
                        else
                        {
                            Item item = guardian.Inventory[ItemSlot].DeepClone();
                            tg.Inventory[EmptySlot] = item;
                            guardian.Inventory[EmptySlot].SetDefaults(0, true);
                            string Message = guardian.GetMessage(GuardianBase.MessageIDs.DeliveryGiveItem,
                                                                 "*" + guardian.Name + " gave [target] some [item].*").
                                             Replace("[target]", tg.Name).
                                             Replace("[item]", item.Name);
                            guardian.SaySomething(Message);
                        }
                    }
                    InUse = false;
                }
            }
            break;
            }
        }
        public override void Update(TerraGuardian guardian)
        {
            if (guardian.TargetID > -1 || guardian.TalkPlayerID > -1 || guardian.IsBeingPulledByPlayer)
            {
                InUse = false;
                return;
            }
            bool MakeNpcFocusOnGuardian = false;

            if (!guardian.PlayerMounted)
            {
                guardian.MoveLeft = guardian.MoveRight = false;
            }
            if (guardian.IsBeingPulledByPlayer)
            {
                InUse = false;
                return;
            }
            switch (Step)
            {
            case 0:     //Try reaching npc
            {
                NPC npc = Main.npc[NpcPosition];
                if (!npc.active)
                {
                    InUse = false;
                    return;
                }
                Vector2 NpcBottom = npc.Bottom;
                if (guardian.PlayerMounted)
                {
                    if (StepStart)
                    {
                        string Message = guardian.GetMessage(GuardianBase.MessageIDs.AskPlayerToGetCloserToShopNpc, "*This companion wants to buy from [shop]'s store.\nGet closer to It so they can buy from It.*");
                        Message.Replace("[shop]", npc.GivenOrTypeName);
                        guardian.SaySomething(Message);
                    }
                    if (Math.Abs(guardian.Position.X - NpcBottom.X) >= 500)
                    {
                        guardian.DisplayEmotion(TerraGuardian.Emotions.Neutral);
                        InUse = false;
                        return;
                    }
                }
                if (!guardian.PlayerMounted && Time == 5 * 60)
                {
                    guardian.Position = NpcBottom;
                    guardian.SetFallStart();
                }
                else if (!guardian.PlayerMounted && Math.Abs(NpcBottom.X - guardian.Position.X) < 16)
                {
                    if (guardian.Position.X >= NpcBottom.X)
                    {
                        guardian.MoveRight = true;
                    }
                    else
                    {
                        guardian.MoveLeft = true;
                    }
                }
                else if (Math.Abs(NpcBottom.X - guardian.Position.X) >= 16f + guardian.Width * 0.5f)
                {
                    if (!guardian.PlayerMounted)
                    {
                        if (guardian.Position.X < NpcBottom.X)
                        {
                            guardian.MoveRight = true;
                        }
                        else
                        {
                            guardian.MoveLeft = true;
                        }
                    }
                }
                else
                {
                    MakeNpcFocusOnGuardian = true;
                    ChangeStep();
                    if (guardian.PlayerMounted)
                    {
                        string Message = guardian.GetMessage(GuardianBase.MessageIDs.AskPlayerToWaitAMomentWhileCompanionIsShopping, "*They ask you to wait a moment.*");
                        Message = Message.Replace("[shop]", npc.GivenOrTypeName);
                        guardian.SaySomething(Message);
                    }
                }
                if (!guardian.PlayerMounted && Math.Abs(NpcBottom.Y - guardian.Position.Y) > 8)
                {
                    if (guardian.Position.Y < NpcBottom.Y)
                    {
                        if (guardian.Velocity.Y == 0)
                        {
                            bool SolidBlockBellow = false;
                            int  CheckY           = (int)(guardian.Position.Y + 2) / 16;
                            for (int i = 0; i < guardian.Width / 16; i++)
                            {
                                int CheckX = (int)(guardian.TopLeftPosition.X / 16) + i;
                                if (Main.tile[CheckX, CheckY].active() && Main.tileSolid[Main.tile[CheckX, CheckY].type] && !Terraria.ID.TileID.Sets.Platforms[Main.tile[CheckX, CheckY].type])
                                {
                                    SolidBlockBellow = true;
                                    break;
                                }
                            }
                            if (!SolidBlockBellow)
                            {
                                guardian.MoveDown = true;
                                guardian.Jump     = true;
                            }
                        }
                    }
                    else
                    {
                        int CheckX = (int)(guardian.Position.X / 16);
                        if (guardian.JumpHeight == 0 && !guardian.Jump || guardian.JumpHeight > 0)
                        {
                            for (int i = 1; i < 6; i++)
                            {
                                int CheckY = (int)(guardian.Position.Y / 16) - i;
                                if (Main.tile[CheckX, CheckY].active() && Terraria.ID.TileID.Sets.Platforms[Main.tile[CheckX, CheckY].type])
                                {
                                    guardian.Jump = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            break;

            case 1:
            {
                NPC npc = Main.npc[NpcPosition];
                MakeNpcFocusOnGuardian = true;
                Vector2 NpcCenter = npc.Center;
                if (Math.Abs(guardian.Position.X - NpcCenter.X) < 16)
                {
                    if (guardian.Position.X < NpcCenter.X)
                    {
                        guardian.MoveLeft = true;
                    }
                    else
                    {
                        guardian.MoveRight = true;
                    }
                }
                else if (guardian.Velocity.X == 0)
                {
                    guardian.LookingLeft = guardian.Position.X >= NpcCenter.X;
                }
                if (Time == 60)
                {
                    guardian.BuyItem(ItemID, BuyPrice, BuyStack, true);
                }
                if (Time >= (int)(1.5f * 60))
                {
                    InUse = false;
                    if (guardian.PlayerMounted)
                    {
                        guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.GenericThankYou, "*They thanked you.*"));
                    }
                    return;
                }
            }
            break;

            default:
                InUse = false;
                return;
            }
            if (MakeNpcFocusOnGuardian)
            {
                NPC npc = Main.npc[NpcPosition];
                if (npc.ai[0] != 0)
                {
                    npc.netUpdate = true;
                }
                npc.ai[0]      = 0;
                npc.ai[1]      = 300;
                npc.localAI[3] = 100;
                if (npc.Center.X < guardian.Position.X)
                {
                    npc.direction = 1;
                }
                else
                {
                    npc.direction = -1;
                }
            }
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        public override void Update(TerraGuardian guardian)
        {
            bool TargetIsKod = true;

            if (guardian.UsingFurniture)
            {
                guardian.LeaveFurniture(true);
            }
            if (CarriedPlayer != null)
            {
                PlayerMod pm = CarriedPlayer.GetModPlayer <PlayerMod>();
                TargetIsKod = pm.KnockedOut;
                if (CarriedPlayer.dead)
                {
                    InUse = false;
                    if (guardian.TargetID != -1)
                    {
                        guardian.CheckIfSomeoneNeedsPickup();
                    }
                    return;
                }
                bool BeingCarriedByMe = false;
                if (!PlayerMod.IsBeingCarriedBySomeone(CarriedPlayer) || (BeingCarriedByMe = PlayerMod.IsBeingCarriedByThisGuardian(CarriedPlayer, guardian)))
                {
                    pm.CarriedByGuardianID    = guardian.WhoAmID;
                    pm.BeingCarriedByGuardian = false;
                    if (!BeingCarriedByMe)
                    {
                        guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueComingMessage));
                    }
                }
                else
                {
                    InUse = false;
                    return;
                }
                if (CarriedPlayer.whoAmI == guardian.OwnerPos)
                {
                    guardian.StuckTimer = 0;
                }
            }
            else
            {
                TargetIsKod = CarriedGuardian.KnockedOut;
                if (CarriedGuardian.Downed)
                {
                    InUse = false;
                    return;
                }
                bool BeingCarriedByMe = false;
                if (!CarriedGuardian.IsBeingCarriedBySomeone() || (BeingCarriedByMe = CarriedGuardian.IsBeingCarriedByThisGuardian(guardian)))
                {
                    CarriedGuardian.CarriedByGuardianID    = guardian.WhoAmID;
                    CarriedGuardian.BeingCarriedByGuardian = false;
                    if (!BeingCarriedByMe)
                    {
                        guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueComingMessage));
                    }
                }
                else
                {
                    InUse = false;
                    return;
                }
            }
            if (!Carrying)
            {
                float TargetX = CarriedPlayer != null ? CarriedPlayer.Center.X : CarriedGuardian.Position.X;
                float TargetY = CarriedPlayer != null ? CarriedPlayer.Bottom.Y : CarriedGuardian.Position.Y;
                if (Math.Abs(guardian.Position.X - TargetX) < 16 && Math.Abs(guardian.Position.Y - TargetY) < guardian.Height * 0.5f)
                {
                    Carrying = true;
                    guardian.SaySomething(guardian.GetMessage(GuardianBase.MessageIDs.RescueGotMessage));
                    ChangeStep();
                }
                else
                {
                    IgnoreCombat       = true;
                    guardian.MoveRight = guardian.MoveLeft = false;
                    if (TargetX < guardian.Position.X)
                    {
                        guardian.MoveLeft = true;
                    }
                    else
                    {
                        guardian.MoveRight = true;
                    }
                    if (Time >= 5 * 60)
                    {
                        guardian.Position = new Microsoft.Xna.Framework.Vector2(TargetX, TargetY);
                        guardian.SetFallStart();
                        Carrying = true;
                        ChangeStep();
                    }
                    else
                    {
                        return;
                    }
                }
                DelayBeforePlacingOnGround = MaxDelay;
            }
            IgnoreCombat = false;
            bool SafeToPlaceAllyDown = true;

            {
                if (guardian.Velocity.Y == 0)
                {
                    int StartCheckX = (int)((guardian.Position.X - guardian.CollisionWidth * 0.5f) * TerraGuardian.DivisionBy16),
                        EndCheckX   = (int)((guardian.Position.X + guardian.CollisionWidth * 0.5f + 1) * TerraGuardian.DivisionBy16);
                    int CheckY      = (int)((guardian.Position.Y + 1) * TerraGuardian.DivisionBy16);
                    for (int x = StartCheckX; x < EndCheckX; x++)
                    {
                        if (MainMod.IsDangerousTile(x, CheckY, false))
                        {
                            SafeToPlaceAllyDown = false;
                            break;
                        }

                        /*Tile tile = MainMod.GetTile(x, CheckY);
                         * if (tile.liquid >= 20)
                         * {
                         *  SafeToPlaceAllyDown = false;
                         *  break;
                         * }*/
                    }
                }
                else
                {
                    SafeToPlaceAllyDown = false;
                }
                if (!TargetIsKod && DelayBeforePlacingOnGround > 2.5f * 60)
                {
                    DelayBeforePlacingOnGround = (int)(2.5f * 60);
                }
                if (SafeToPlaceAllyDown && TargetIsKod)
                {
                    for (int n = 0; n < 200; n++)
                    {
                        if (Main.npc[n].active && guardian.IsNpcHostile(Main.npc[n]) && guardian.Distance(Main.npc[n].Center) < 400 && (Main.npc[n].noTileCollide || Collision.CanHitLine(Main.npc[n].position, Main.npc[n].width, Main.npc[n].height, guardian.TopLeftPosition, guardian.Width, guardian.Height)))
                        {
                            SafeToPlaceAllyDown = false;
                            break;
                        }
                    }
                }
            }
            if (SafeToPlaceAllyDown)
            {
                guardian.MoveLeft = guardian.MoveRight = false;
                if (DelayBeforePlacingOnGround <= 0)
                {
                    if (CarriedPlayer != null)
                    {
                        CarriedPlayer.position.X = guardian.Position.X - CarriedPlayer.width * 0.5f;
                        CarriedPlayer.position.Y = guardian.Position.Y - CarriedPlayer.height;
                        InUse = false;
                        return;
                    }
                    CarriedGuardian.Position.X = guardian.Position.X;
                    CarriedGuardian.Position.Y = guardian.Position.Y;
                    InUse = false;
                    return;
                }
                DelayBeforePlacingOnGround--;
            }
            else
            {
                if (TargetIsKod)
                {
                    DelayBeforePlacingOnGround = MaxDelay;
                }
                bool AllyIsDying = CarriedPlayer != null ? CarriedPlayer.statLife < CarriedPlayer.statLifeMax2 * 0.35f : CarriedGuardian.HP < CarriedGuardian.MHP * 0.35f;
                ForcedTactic = AllyIsDying ? CombatTactic.Snipe : CombatTactic.Assist;
            }
            {
                Vector2 CarryPosition = Vector2.Zero;
                Vector2 Origin        = Vector2.One * 0.5f;
                if (guardian.Ducking)
                {
                    CarryPosition = guardian.GetBetweenHandsPosition(guardian.Base.DuckingSwingFrames[2]);
                }
                else
                {
                    CarryPosition = guardian.GetBetweenHandsPosition(guardian.Base.ItemUseFrames[2]);
                }
                CarryPosition += guardian.Position;
                if (CarriedPlayer != null)
                {
                    CarriedPlayer.position.X    = CarryPosition.X - CarriedPlayer.width * Origin.X + guardian.OffsetX;
                    CarriedPlayer.position.Y    = CarryPosition.Y - CarriedPlayer.height * Origin.Y + guardian.OffsetY;
                    CarriedPlayer.fallStart     = (int)(CarriedPlayer.position.Y * TerraGuardian.DivisionBy16);
                    CarriedPlayer.direction     = guardian.Direction;
                    CarriedPlayer.immune        = true;
                    CarriedPlayer.immuneTime    = 3;
                    CarriedPlayer.immuneNoBlink = true;
                    PlayerMod pm = CarriedPlayer.GetModPlayer <PlayerMod>();
                    pm.ReviveBoost++;
                    pm.BeingCarriedByGuardian = true;
                    MainMod.DrawMoment.Add(new GuardianDrawMoment(guardian.WhoAmID, TerraGuardian.TargetTypes.Player, CarriedPlayer.whoAmI));
                }
                else
                {
                    CarriedGuardian.IsBeingPulledByPlayer = false;
                    CarriedGuardian.Position.X            = CarryPosition.X - (CarriedGuardian.Width * (Origin.X - 0.5f)) + guardian.OffsetX;
                    CarriedGuardian.Position.Y            = CarryPosition.Y + (CarriedGuardian.Height * (1.1f - Origin.Y)) + guardian.OffsetY;
                    CarriedGuardian.SetFallStart();
                    CarriedGuardian.Direction = guardian.Direction;
                    CarriedGuardian.ReviveBoost++;
                    CarriedGuardian.BeingCarriedByGuardian = true;
                    CarriedGuardian.ImmuneTime             = 3;
                    CarriedGuardian.ImmuneNoBlink          = true;
                    MainMod.DrawMoment.Add(new GuardianDrawMoment(guardian.WhoAmID, TerraGuardian.TargetTypes.Guardian, CarriedGuardian.WhoAmID, true));
                }
            }
        }
Esempio n. 9
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;
            }
        }