Esempio n. 1
0
        public override void Update(TerraGuardian guardian)
        {
            IgnoreCombat = true;
            Cancellable  = false;
            if (guardian.Downed || guardian.KnockedOut)
            {
                MainMod.ScreenColorAlpha = 0;
                InUse = false;
                return;
            }
            bool       SetPlayerToGuardianBed = false;
            const bool UseBedSharing          = false;

            switch (Step)
            {
            case 0:
            {
                if (UseBedSharing && guardian.Base.Size >= GuardianBase.GuardianSize.Large)
                {
                    if (guardian.AttemptToGrabPlayer())
                    {
                        ChangeStep();
                    }
                    guardian.WalkMode = true;
                }
                else
                {
                    ChangeStep();
                }
            }
            break;

            case 1:
            {
                if (Time == 0)
                {
                    if (guardian.furniturex > -1)
                    {
                        guardian.LeaveFurniture(false);
                    }
                    guardian.TryFindingNearbyBed(false);
                }
                if (guardian.furniturex == -1 || guardian.UsingFurniture)
                {
                    ChangeStep();
                }
                if (guardian.furniturex > -1)
                {
                    guardian.WalkMode = true;
                }
            }
            break;

            case 2:
            {
                MainMod.ScreenColor.R    = MainMod.ScreenColor.G = MainMod.ScreenColor.B = 0;
                MainMod.ScreenColorAlpha = (float)Time / (5 * 60);
                if (MainMod.ScreenColorAlpha > 1)
                {
                    MainMod.ScreenColorAlpha = 1f;
                }
                if (UseBedSharing && guardian.IsSleeping && guardian.GrabbingPlayer)
                {
                    SetPlayerToGuardianBed = true;
                }
                if (Time >= 5 * 60)
                {
                    //Do time change
                    if (guardian.OwnerPos > -1)
                    {
                        Main.player[guardian.OwnerPos].position.X = guardian.Position.X - Main.player[guardian.OwnerPos].width * 0.5f;
                        Main.player[guardian.OwnerPos].position.Y = guardian.Position.Y - Main.player[guardian.OwnerPos].height;
                        Main.player[guardian.OwnerPos].velocity   = Vector2.Zero;
                        int RestValue = 4;
                        switch (RestTime)
                        {
                        case 0:
                            RestValue = 4;
                            break;

                        case 1:
                            RestValue = 8;
                            break;

                        case 2:             //UntilDawn
                            RestValue = 0;
                            if (Main.dayTime)
                            {
                                RestValue += (int)(24 * 3600 - Main.time) / 3600 + 1;
                            }
                            else
                            {
                                RestValue += (int)(9 * 3600 - Main.time) / 3600 + 1;
                            }
                            break;

                        case 3:             //UntilNight
                            RestValue = 0;
                            if (Main.dayTime)
                            {
                                RestValue += (int)(15 * 3600 - Main.time) / 3600 + 1;
                            }
                            else
                            {
                                RestValue += (int)(24 * 3600 - Main.time) / 3600 + 1;
                            }
                            break;
                        }
                        WorldMod.SkipTime(RestValue);
                        foreach (TerraGuardian g in Main.player[guardian.OwnerPos].GetModPlayer <PlayerMod>().GetAllGuardianFollowers)
                        {
                            float RestBonus = 1.5f;
                            if (g.Base.IsNocturnal)
                            {
                                if (!Main.dayTime)
                                {
                                    RestBonus = 2f;
                                }
                            }
                            else
                            {
                                if (Main.dayTime)
                                {
                                    RestBonus = 2f;
                                }
                            }
                            RestBonus *= RestValue;
                            if ((int)g.Data.Fatigue - RestBonus < 0)
                            {
                                g.Data.Fatigue = 0;
                            }
                            else
                            {
                                g.Data.Fatigue -= (sbyte)RestBonus;
                            }
                            float InjuryValue = RestBonus * 0.5f;
                            if ((int)g.Data.Injury - RestBonus < 0)
                            {
                                g.Data.Injury = 0;
                            }
                            else
                            {
                                g.Data.Injury -= (sbyte)InjuryValue;
                            }
                            if (g.request.Active)
                            {
                                g.request.RequestTimeLeft -= RestValue;
                            }
                        }
                    }
                    guardian.GrabbingPlayer = false;
                    ChangeStep();
                }
            }
            break;

            case 3:
            {
                Player player = Main.player[guardian.OwnerPos];
                if (Time >= 5 * 60)
                {
                    InUse = false;
                    MainMod.ScreenColorAlpha = 0;
                    if (guardian.IsSleeping)
                    {
                        player.fullRotation = 0;
                        guardian.LeaveFurniture();
                    }
                }
                else
                {
                    MainMod.ScreenColor.R    = MainMod.ScreenColor.G = MainMod.ScreenColor.B = 0;
                    MainMod.ScreenColorAlpha = 1f - (float)Time / (5 * 60);
                    if (guardian.IsSleeping)
                    {
                        SetPlayerToGuardianBed = true;
                    }
                }
            }
            break;
            }
            if (UseBedSharing && SetPlayerToGuardianBed)
            {
                Player player = Main.player[guardian.OwnerPos];
                player.direction            = guardian.Direction;
                player.fullRotation         = -1.570796326794897f * player.direction;
                player.position.X           = guardian.Position.X - player.width * 0.5f - guardian.Base.SleepingOffset.X;
                player.position.Y           = guardian.Position.Y - player.height - guardian.Base.SleepingOffset.Y;
                player.velocity             = Vector2.Zero;
                player.fullRotationOrigin.X = player.width * 0.5f;
                player.fullRotationOrigin.Y = player.height * 0.5f;
                guardian.GrabbingPlayer     = false;
            }
        }
Esempio n. 2
0
        public override void AI()
        {
            if (GhostFoxHauntLifted)
            {
                SetPassive();
            }
            RevivingSomeone = false;
            YOffset         = ((float)Math.Sin(Main.GlobalTime * 2)) * 3;
            bool ReduceOpacity = Main.dayTime && !Main.eclipse && npc.position.Y < Main.worldSurface * 16 && Main.tile[(int)(npc.Center.X) / 16, (int)(npc.Center.Y / 16)].wall == 0;

            if (ReduceOpacity)
            {
                float MinOpacity = !PostBossKillDialogue ? 0 : 0.2f;
                if (Opacity > MinOpacity)
                {
                    Opacity -= 0.005f;
                    if (Opacity <= 0)
                    {
                        npc.active = false;
                        return;
                    }
                    if (Opacity > 0 && Opacity < MinOpacity)
                    {
                        Opacity = MinOpacity;
                    }
                }
            }
            else
            {
                if (Opacity < 1)
                {
                    Opacity += 0.005f;
                    if (Opacity > 1)
                    {
                        Opacity = 1;
                        return;
                    }
                }
            }
            if (PassiveAI)
            {
                Idle = true;
            }
            else if (PostBossKillDialogue)
            {
                if (Math.Abs(npc.Center.X - Main.player[npc.target].Center.X) > 48)
                {
                    if (npc.Center.X < Main.player[npc.target].Center.X)
                    {
                        MoveRight = true;
                    }
                    else
                    {
                        MoveLeft = true;
                    }
                }
                else
                {
                    if (Main.player[npc.target].GetModPlayer <PlayerMod>().KnockedOut)
                    {
                        Main.player[npc.target].GetModPlayer <PlayerMod>().ReviveBoost += 2;
                        if (npc.Center.X < Main.player[npc.target].Center.X)
                        {
                            npc.direction = 1;
                        }
                        else
                        {
                            npc.direction = -1;
                        }
                    }
                }
            }
            else if (PlayerChaseTime == 0)
            {
                Idle = true;
                npc.TargetClosest(false);
                Player player = Main.player[npc.target];
                if (((npc.direction == -1 && player.Center.X < npc.Center.X) || (npc.direction == 1 && player.Center.X > npc.Center.X)) && IsInPerceptionRange(player, 400, 300) && Collision.CanHitLine(npc.position, npc.width, npc.height, player.position, player.width, player.height))
                {
                    PlayerChaseTime = 200;
                }
            }
            else
            {
                Player player = Main.player[npc.target];
                if (Collision.CanHitLine(npc.position, npc.width, npc.height, player.position, player.width, player.height))
                {
                    PlayerChaseTime = 200;
                }
                else
                {
                    PlayerChaseTime--;
                }
                if (PlayerChaseTime > 0)
                {
                    if (player.Center.X < npc.Center.X)
                    {
                        MoveLeft = true;
                    }
                    else
                    {
                        MoveRight = true;
                    }
                    if (player.position.Y < npc.position.Y)
                    {
                        if (JumpTime > 0 || (npc.velocity.Y == 0 && JumpTime == 0))
                        {
                            Jump = true;
                        }
                    }
                    else if (player.position.Y + player.height > npc.position.Y + npc.height && npc.velocity.Y == 0)
                    {
                        npc.position.Y += 8;
                    }
                    Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle((int)npc.Center.X, (int)npc.position.Y + npc.height, Base.Width, Base.Height);
                    rect.X -= (int)(rect.Width * 0.5f);
                    rect.Y -= rect.Height;
                    if (player.getRect().Intersects(rect))
                    {
                        if (PlayerMod.PlayerHasGuardian(player, GuardianBase.Fluffles))
                        {
                            SayMessage(Main.rand.NextDouble() <= 0.5 ? "(She seems to have missed your company.)" : "(She seems really happy for seeing you.)");
                            WorldMod.TurnNpcIntoGuardianTownNpc(npc, GuardianID, GuardianModID);
                            //npc.active = false;
                            //Main.NewText(PlayerMod.GetPlayerGuardian(player, GuardianBase.Fluffles).Name + " fades away.");
                            return;
                        }
                        else
                        {
                            List <int> CurseIDs = new List <int>();
                            CurseIDs.Add(ModContent.BuffType <Buffs.GhostFoxHaunts.SkullHaunt>());
                            if (NPC.downedBoss2)
                            {
                                CurseIDs.Add(ModContent.BuffType <Buffs.GhostFoxHaunts.BeeHaunt>());
                            }
                            if (Main.hardMode)
                            {
                                CurseIDs.Add(ModContent.BuffType <Buffs.GhostFoxHaunts.MeatHaunt>());
                                CurseIDs.Add(ModContent.BuffType <Buffs.GhostFoxHaunts.SawHaunt>());
                            }
                            if (NPC.downedPlantBoss)
                            {
                                CurseIDs.Add(ModContent.BuffType <Buffs.GhostFoxHaunts.ConstructHaunt>());
                            }
                            player.AddBuff(CurseIDs[Main.rand.Next(CurseIDs.Count)], 5);
                            //player.GetModPlayer<PlayerMod>().EnterDownedState(true);
                            if (player.statLife == 1)
                            {
                                player.statLife++;
                            }
                            player.Hurt(Terraria.DataStructures.PlayerDeathReason.ByCustomReason(" didn't survived the haunt..."), 1, 0, false, true, false);
                            player.GetModPlayer <PlayerMod>().EnterDownedState(true);
                            player.statLife = 1;

                            /*for (int n = 0; n < 200; n++)
                             * {
                             *  if (Main.npc[n].active && !Main.npc[n].friendly)
                             *  {
                             *      Main.npc[n].active = false;
                             *  }
                             * }*/
                            MainMod.DoBlackoutPlayer();
                            WorldMod.SkipTime(Main.rand.Next(40, 85) * 0.1f);
                            //WorldMod.SkipTimeUntilMorning();
                            npc.active = false;
                            return;
                            //WorldGen.SaveAndQuit();
                        }
                    }
                }
            }
            base.AI();
        }