Beispiel #1
0
        public static void Spawn(On.Terraria.Player.orig_Spawn orig, Player instance)
        {
            Main.InitLifeBytes();
            if (instance.whoAmI == Main.myPlayer)
            {
                if (Main.mapTime < 5)
                {
                    Main.mapTime = 5;
                }
                Main.quickBG = 10;
                instance.FindSpawn();
                if (!Player.CheckSpawn(instance.SpawnX, instance.SpawnY))
                {
                    instance.SpawnX = -1;
                    instance.SpawnY = -1;
                }
                Main.maxQ = true;
            }
            if (Main.netMode == 1 && instance.whoAmI == Main.myPlayer)
            {
                NetMessage.SendData(12, -1, -1, null, Main.myPlayer, 0f, 0f, 0f, 0, 0, 0);
                Main.gameMenu = false;
            }
            instance.headPosition = Vector2.Zero;
            instance.bodyPosition = Vector2.Zero;
            instance.legPosition  = Vector2.Zero;
            instance.headRotation = 0f;
            instance.bodyRotation = 0f;
            instance.legRotation  = 0f;
            instance.lavaTime     = instance.lavaMax;
            if (instance.statLife <= 0)
            {
                int num = instance.statLifeMax2 / 2;
                instance.statLife = 100;
                if (num > instance.statLife)
                {
                    instance.statLife = num;
                }
                instance.breath = instance.breathMax;
                if (instance.spawnMax)
                {
                    instance.statLife = instance.statLifeMax2;
                    instance.statMana = instance.statManaMax2;
                }
            }
            instance.immune = true;
            if (instance.dead)
            {
                PlayerHooks.OnRespawn(instance);
            }

            instance.dead       = false;
            instance.immuneTime = 0;
            instance.active     = true;
            if (instance.SpawnX >= 0 && instance.SpawnY >= 0)
            {
                instance.position.X = (float)(instance.SpawnX * 16 + 8 - instance.width / 2);
                instance.position.Y = (float)(instance.SpawnY * 16 - instance.height);
            }
            else
            {
                instance.position.X = (float)(Main.spawnTileX * 16 + 8 - instance.width / 2);
                instance.position.Y = (float)(Main.spawnTileY * 16 - instance.height);
                for (int i = Main.spawnTileX - 1; i < Main.spawnTileX + 2; i++)
                {
                    for (int j = Main.spawnTileY - 3; j < Main.spawnTileY; j++)
                    {
                        ILog log = LogManager.GetLogger("Temp dim logger");
                        log.Info($"Spawn tile : {i} , {j}");
                        log.Info($"World size : {Main.tile.Length}");
                        if (i < Main.tile.GetLength(0) && j < Main.tile.GetLength(1) && Main.tile[i, j] != null)
                        {
                            if (Main.tileSolid[(int)Main.tile[i, j].type] && !Main.tileSolidTop[(int)Main.tile[i, j].type])
                            {
                                WorldGen.KillTile(i, j, false, false, false);
                            }
                            if (Main.tile[i, j].liquid > 0)
                            {
                                Main.tile[i, j].lava(false);
                                Main.tile[i, j].liquid = 0;
                                WorldGen.SquareTileFrame(i, j, true);
                            }
                        }
                    }
                }
            }
            instance.wet        = false;
            instance.wetCount   = 0;
            instance.lavaWet    = false;
            instance.fallStart  = (int)(instance.position.Y / 16f);
            instance.fallStart2 = instance.fallStart;
            instance.velocity.X = 0f;
            instance.velocity.Y = 0f;
            for (int k = 0; k < 3; k++)
            {
                instance.UpdateSocialShadow();
            }
            instance.oldPosition = instance.position + instance.BlehOldPositionFixer;
            instance.talkNPC     = -1;
            if (instance.whoAmI == Main.myPlayer)
            {
                Main.npcChatCornerItem = 0;
            }
            if (instance.pvpDeath)
            {
                instance.pvpDeath   = false;
                instance.immuneTime = 300;
                instance.statLife   = instance.statLifeMax;
            }
            else
            {
                instance.immuneTime = 60;
            }
            if (instance.whoAmI == Main.myPlayer)
            {
                Main.BlackFadeIn = 255;
                Main.renderNow   = true;
                if (Main.netMode == 1)
                {
                    Netplay.newRecent();
                }
                Main.screenPosition.X = instance.position.X + (float)(instance.width / 2) - (float)(Main.screenWidth / 2);
                Main.screenPosition.Y = instance.position.Y + (float)(instance.height / 2) - (float)(Main.screenHeight / 2);
            }
        }