public static void StartInvasion(int musicType, IReadOnlyList <KeyValuePair <int, ISet <int> > > spawnInfo) { var myworld = ModContent.GetInstance <DynamicInvasionsWorld>(); if (Main.netMode == 0) { myworld.Logic.StartInvasion(musicType, spawnInfo); } else if (Main.netMode == 1) { ClientPacketHandlers.SendInvasionRequestFromClient(musicType, spawnInfo); } else if (Main.netMode == 2) { string spawnInfoEnc = JsonConvert.SerializeObject(spawnInfo); myworld.Logic.StartInvasion(musicType, spawnInfo); for (int i = 0; i < Main.player.Length; i++) { Player player = Main.player[i]; if (player == null || !player.active) { continue; } ServerPacketHandlers.SendInvasionFromServer(player, musicType, spawnInfoEnc); } } }
//////////////// public override void OnEnterWorld(Player player) { if (player.whoAmI != Main.myPlayer) { return; } if (this.player.whoAmI != Main.myPlayer) { return; } var mymod = (DynamicInvasionsMod)this.mod; if (Main.netMode == 0) { this.FinishModSettingsSync(); } if (Main.netMode == 1) // Client { ClientPacketHandlers.SendInvasionStatusRequestFromClient(); } this.HasEnteredWorld = true; }
public override void OnCraft(Item item) { var mymod = (InjuryMod)this.mod; int odds = mymod.Config.VitaeCraftingAccidentOdds; if (!Main.hardMode && (odds == 0 || Main.rand.Next(odds) == 0)) { Main.LocalPlayer.AddBuff(BuffID.Cursed, 60 * 15); // 15 seconds of curse if (Main.netMode == 1) { ClientPacketHandlers.SendSpawnRequest(mymod, NPCID.Wraith); } else if (Main.netMode == 0) { NPC.SpawnOnPlayer(Main.LocalPlayer.whoAmI, NPCID.Wraith); } if (Main.LocalPlayer.FindBuffIndex(BuffID.Cursed) != -1) { Main.NewText("An otherworldly presense has noticed your act. Your body seizes up.", Color.Red); } else { Main.NewText("An otherworldly presense has noticed your act...", Color.Red); } } }
public static void EndInvasion() { var myworld = ModContent.GetInstance <DynamicInvasionsWorld>(); if (Main.netMode == 0) { myworld.Logic.EndInvasion(); } else if (Main.netMode == 1) { ClientPacketHandlers.SendEndInvasionRequestFromClient(); } else if (Main.netMode == 2) { myworld.Logic.EndInvasion(); for (int i = 0; i < Main.player.Length; i++) { Player player = Main.player[i]; if (player == null || !player.active) { continue; } ServerPacketHandlers.SendEndInvasionFromServer(player); } } }
public void GiveMaskToLoony(Player player, Item maskItem) { var mymod = TheLunaticMod.Instance; if (Main.netMode == 1) // Client { ClientPacketHandlers.SendGivenMaskFromClient(maskItem); } else if (Main.netMode == 2) // Server { throw new ModHelpersException("Server should not be giving masks to loonys."); } int bossType = -1; if (maskItem.type == ModContent.ItemType <CustomBossMaskItem>() && maskItem.modItem != null) { bossType = ((CustomBossMaskItem)maskItem.modItem).BossNpcType; } else { var bossOfMask = MaskLogic.VanillaBossOfMask .Where(x => x.Value == maskItem.type) .First(); bossType = bossOfMask.Value > 0 ? bossOfMask.Value : bossType; } this.RegisterReceiptOfMask(player, maskItem.type, bossType); maskItem.TurnToAir(); Main.PlaySound(SoundID.Unlock, player.position); }
//////////////// public override void HandlePacket(BinaryReader reader, int player_who) { if (Main.netMode == 1) // Client { ClientPacketHandlers.HandlePacket(this, reader); } else if (Main.netMode == 2) // Server { ServerPacketHandlers.HandlePacket(this, reader, player_who); } }
//////////////// public override void HandlePacket(BinaryReader reader, int playerWho) { if (Main.netMode == 1) { ClientPacketHandlers.RoutePacket(this, reader); } else if (Main.netMode == 2) { ServerPacketHandlers.RoutePacket(this, reader, playerWho); } }
public void ApplyChaosHit(WormholeModContext ctx) { if (Main.netMode == 0) // Single { var mngr = ctx.MyMod.GetModWorld <WormholesWorld>().Wormholes; mngr.Reroll(this); } else // Non-single { ClientPacketHandlers.SendWormholeRerollRequestViaClient(ctx.MyMod, this.ID); } }
private void OnClientConnect(Player clientPlr) { if (clientPlr.whoAmI == this.player.whoAmI) // Current player { var mymod = (TheLunaticMod)this.mod; var myworld = ModContent.GetInstance <TheLunaticWorld>(); myworld.GameLogic.ApplyDebugOverrides(mymod); ClientPacketHandlers.SendRequestModDataFromClient(); } }
private void ActivateNoHonor() { var mymod = HonorBoundMod.Instance; var modworld = ModContent.GetInstance<HonorBoundWorld>(); var mylogic = modworld.Logic; mylogic.NoHonor(); mylogic.BeginGameModeForLocalPlayer(); if( Main.netMode == 1 ) { // Client ClientPacketHandlers.SendHonorSettingsFromClient( Main.LocalPlayer ); } }
//////////////// public override void HandlePacket(BinaryReader reader, int playerWho) { try { if (Main.netMode == 1) { ClientPacketHandlers.HandlePacket(reader); } else if (Main.netMode == 2) { ServerPacketHandlers.HandlePacket(reader, playerWho); } } catch (Exception e) { LogHelpers.Log("HandlePacket " + e.ToString()); } }
public override void RightClick(Player player) { var config = DynamicInvasionsMod.Config; var myworld = ModContent.GetInstance <DynamicInvasionsWorld>(); if (config.CanAbortInvasions && myworld.Logic.IsInvasionHappening()) { Item fuelItem = CrossDimensionalAggregatorItem.GetFuelItemFromInventory(player); int fuelAmt = fuelItem != null && !fuelItem.IsAir ? fuelItem.stack : 0; if (config.InvasionAbortFuelCost == 0 || fuelAmt >= config.InvasionAbortFuelCost) { if (config.InvasionAbortFuelCost > 0) { ItemHelpers.ReduceStack(fuelItem, config.InvasionAbortFuelCost); } Main.NewText("Ending invasion..."); if (Main.netMode == 0) { myworld.Logic.EndInvasion(); } else if (Main.netMode == 1) { ClientPacketHandlers.SendEndInvasionRequestFromClient(); } } else { Main.NewText("You need " + config.InvasionAbortFuelCost + " Eternia Crystals to abort an invasion.", Color.Yellow); } } else { Main.NewText("No custom invasion in progress.", Color.Yellow); } }
//////////////// public override void OnEnterWorld(Player player) { if (Main.netMode == 2) { return; } // Not server if (player.whoAmI == this.player.whoAmI) // Current player { var mymod = (WormholesMod)this.mod; var modworld = this.mod.GetModWorld <WormholesWorld>(); if (!mymod.Config.LoadFile()) { mymod.Config.SaveFile(); } if (modworld.HasCorrectID) { this.ReopenTownPortal(); } else { this.HasLoadedTownPortals = false; } if (Main.netMode == 1) // Client { ClientPacketHandlers.SendWormholesAndSettingsRequestViaClient(mymod, player); } else if (Main.netMode == 0) // Single { modworld.SetupWormholes(); } this.HasEnteredWorld = true; } }
private void ActivateInvasion(Item fuelItem) { var myworld = ModContent.GetInstance <DynamicInvasionsWorld>(); var itemInfo = this.item.GetGlobalItem <AggregatorItemInfo>(); int fuelCost = this.GetFuelCost(); if (DynamicInvasionsMod.Config.DebugModeInfo) { Main.NewText("Activating invasion..."); } ItemHelpers.ReduceStack(fuelItem, fuelCost); itemInfo.Use(); if (Main.netMode == 0) { myworld.Logic.StartInvasion(itemInfo.MusicType, itemInfo.BannerItemTypesToNpcTypes); } else if (Main.netMode == 1) { ClientPacketHandlers.SendInvasionRequestFromClient(itemInfo.MusicType, itemInfo.BannerItemTypesToNpcTypes); } }