// Called at the end of each player update public override void PostUpdate() { base.PostUpdate(); if (Main.myPlayer == player.whoAmI) { // Rainbow-ify the tiles below the player if (CrowdControlMod._server != null && CrowdControlMod._server.m_rainbowPaintTimer.Enabled && player.velocity.Y == 0f) { int x = (int)(player.position.X / 16); int y = (int)(player.position.Y / 16); CrowdControlMod._server.RainbowifyTileClient(x, y + 3); CrowdControlMod._server.RainbowifyTileClient(x + 1, y + 3); } // Manually start / stop the server if testing if (TDebug.IN_DEBUG && player.selectedItem == 9 && player.justJumped) { if (CrowdControlMod._server.IsRunning) { TDebug.WriteDebug("Manually stopping server", Color.Yellow); CrowdControlMod._server.Stop(); } else { TDebug.WriteDebug("Manually starting server", Color.Yellow); CrowdControlMod._server.Start(); } } } }
// Called when setting controls public override void SetControls() { // Set the player and start the server to begin connecting to Crowd Control if (Main.netMode == NetmodeID.MultiplayerClient && Main.myPlayer == player.whoAmI && !threadStartedInMultiplayer) { threadStartedInMultiplayer = true; CrowdControlMod._server.SetPlayer(this); CrowdControlMod._server.Start(); TDebug.WriteDebug("Server started through SetControls", Color.Yellow); } base.SetControls(); }
// Called when the player is saved public override TagCompound Save() { if (Main.myPlayer == player.whoAmI && (Main.netMode == NetmodeID.SinglePlayer && threadStartedInMultiplayer)) { if (threadStartedInMultiplayer) { threadStartedInMultiplayer = false; } CrowdControlMod._server.Stop(); TDebug.WriteDebug("Server stopped due to player save", Color.Yellow); } else { TDebug.WriteDebug("Server not stopped in Save() ignored due to not exiting to menu.", Color.Yellow); } return(base.Save()); }
// Called after game is rendered private void OnPostDraw(GameTime gameTime) { // Draw wall of fish across the screen if (_server != null && _server.IsRunning && _server.m_fishWallTimer.Enabled) { Main.spriteBatch.Begin(); int maxFish = Main.screenWidth / (14 * 5 * 2); try { for (int i = 0; i < maxFish; ++i) { DrawWallOfFish(i * _server.m_fishWallOffset); } } catch (Exception e) { TDebug.WriteDebug("Error drawing wall of fish: " + e.Message, Color.Yellow); } finally { Main.spriteBatch.End(); } } }
// Called whilst the full screen map is active public override void PostDrawFullscreenMap(ref string mouseText) { // Give wormhole potion if there isn't one in the inventory if (!m_mapOpened && _server != null && _server.IsRunning && Main.netMode == Terraria.ID.NetmodeID.MultiplayerClient && CCServer._allowTeleportingToPlayers && Main.player[Main.myPlayer].team > 0) { m_mapOpened = true; // Already has a wormhole potion if (Main.player[Main.myPlayer].HasUnityPotion()) { m_wormHoleType = EWormHoleType.ALREADY_HAS; TDebug.WriteDebug("(Wormhole) Already has a wormhole", Color.Yellow); } else { Player player = Main.LocalPlayer; // No item in slot; place wormhole in slot if (player.inventory[m_wormHoleSlot] == null || player.inventory[m_wormHoleSlot].type == Terraria.ID.ItemID.None) { m_wormHoleType = EWormHoleType.IN_EMPTY_SLOT; player.inventory[m_wormHoleSlot] = new Item(); player.inventory[m_wormHoleSlot].SetDefaults(Terraria.ID.ItemID.WormholePotion); TDebug.WriteDebug("(Wormhole) No item in slot; place wormhole", Color.Yellow); } // Item in slot; replace with wormhole else { m_wormHoleType = EWormHoleType.REPLACED_ITEM; m_wormHoleOldItem = player.inventory[m_wormHoleSlot]; player.inventory[m_wormHoleSlot] = new Item(); player.inventory[m_wormHoleSlot].SetDefaults(Terraria.ID.ItemID.WormholePotion); TDebug.WriteDebug("(Wormhole) Item in slot; replace with wormhole: " + m_wormHoleOldItem.Name + "(" + m_wormHoleOldItem.stack + ")", Color.Yellow); } } } base.PostDrawFullscreenMap(ref mouseText); }
// Reapply buff effects after death public void ReapplyBuffEffects() { List <int> toRemove = new List <int>(); foreach (int buffType in m_buffEffects.Keys) { if (m_buffEffects[buffType].Expired()) { toRemove.Add(buffType); TDebug.WriteDebug("Removed expired buff: " + Lang.GetBuffName(buffType), Color.Yellow); } else { int remainingTime = m_buffEffects[buffType].RemainingTime(); player.AddBuff(buffType, remainingTime); TDebug.WriteDebug("Reapplied buff: " + Lang.GetBuffName(buffType) + " for " + (remainingTime / 60) + " seconds", Color.Yellow); } } foreach (int buffType in toRemove) { m_buffEffects.Remove(buffType); } }
// Called after everything is updated public override void PostUpdateEverything() { if (!Main.mapFullscreen && m_mapOpened) { m_mapOpened = false; Player player = Main.LocalPlayer; // Get rid of wormhole if it wasn't used if (m_wormHoleType == EWormHoleType.IN_EMPTY_SLOT && player.inventory[m_wormHoleSlot].type == Terraria.ID.ItemID.WormholePotion) { player.inventory[m_wormHoleSlot] = new Item(); TDebug.WriteDebug("(Wormhole) Got rid of unused wormhole", Color.Yellow); } // Restore previous item else if (m_wormHoleType == EWormHoleType.REPLACED_ITEM) { player.inventory[m_wormHoleSlot] = m_wormHoleOldItem; TDebug.WriteDebug("(Wormhole) Restored old item: " + m_wormHoleOldItem.Name + "(" + m_wormHoleOldItem.stack + ")", Color.Yellow); } } base.PostUpdateEverything(); }
// Set the death point if far from spawn private void UpdateDeathPoint() { m_deathPoint = player.position; TDebug.WriteDebug("Saved death position: " + m_deathPoint, Color.Yellow); }