/// <summary> /// Broadcasts a chat message to all users /// </summary> /// <param name="message"></param> public void Broadcast(string message) => NetMessage.SendData(25, -1, -1, NetworkText.FromLiteral(message), 255, 255, 0, 160);
public override void RightClick(int i, int j) { Player player = Main.LocalPlayer; if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0) { Main.CancelClothesWindow(true); Main.mouseRightRelease = false; int left = (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18); left %= 3; left = Player.tileTargetX - left; int top = Player.tileTargetY - (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18); if (player.sign > -1) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = string.Empty; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = string.Empty; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest != -1) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { player.flyingPigChest = -1; int num213 = Chest.FindChest(left, top); if (num213 != -1) { Main.stackSplit = 600; if (num213 == player.chest) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else if (num213 != player.chest && player.chest == -1) { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(SoundID.MenuOpen); player.chestX = left; player.chestY = top; } else { player.chest = num213; Main.playerInventory = true; Main.recBigList = false; Main.PlaySound(SoundID.MenuTick); player.chestX = left; player.chestY = top; } Recipe.FindRecipes(); } } } else { Main.playerInventory = false; player.chest = -1; Recipe.FindRecipes(); Main.dresserX = Player.tileTargetX; Main.dresserY = Player.tileTargetY; Main.OpenClothesWindow(); } }
/*public override void SetDefaults(NPC npc) * { * Mod thoriummod = ModLoader.GetMod("ThoriumMod"); * Mod calamitymod = ModLoader.GetMod("CalamityMod"); * * if (MyPlayer.RealismMode) * { * if (npc.type == NPCID.EyeofCthulhu) * { * npc.lifeMax = npc.lifeMax * 2; * } * else if (npc.type == NPCID.EaterofWorldsHead) * { * npc.lifeMax = npc.lifeMax * 3; * } * else if (npc.type == NPCID.EaterofWorldsBody) * { * npc.lifeMax = npc.lifeMax * 3; * } * else if (npc.type == NPCID.EaterofWorldsTail) * { * npc.lifeMax = npc.lifeMax * 3; * } * else if (npc.type == NPCID.BrainofCthulhu) * { * npc.lifeMax = npc.lifeMax * 3; * } * else if (npc.type == NPCID.QueenBee) * { * npc.lifeMax = npc.lifeMax * 4; * } * else if (npc.type == NPCID.SkeletronHead) * { * npc.lifeMax = npc.lifeMax * 5; * } * else if (npc.type == NPCID.SkeletronHand) * { * npc.lifeMax = npc.lifeMax * 5; * } * else if (npc.type == NPCID.WallofFlesh) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == NPCID.WallofFleshEye) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == NPCID.Spazmatism) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == NPCID.Retinazer) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == NPCID.SkeletronPrime) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == NPCID.TheDestroyer) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == NPCID.Plantera) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == NPCID.Golem) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == NPCID.GolemHead) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == NPCID.GolemFistLeft) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == NPCID.GolemFistRight) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == NPCID.DukeFishron) * { * npc.lifeMax = npc.lifeMax * 10; * } * else if (npc.type == NPCID.CultistBoss) * { * npc.lifeMax = npc.lifeMax * 11; * } * else if (npc.type == NPCID.MoonLordCore) * { * npc.lifeMax = npc.lifeMax * 12; * } * else if (npc.type == NPCID.MoonLordHand) * { * npc.lifeMax = npc.lifeMax * 12; * } * else if (npc.type == NPCID.MoonLordHead) * { * npc.lifeMax = npc.lifeMax * 12; * } * else if (npc.type == thoriummod.NPCType("TheGrandThunderBirdv2")) * { * npc.lifeMax = npc.lifeMax * 2; * } * else if (npc.type == thoriummod.NPCType("QueenJelly")) * { * npc.lifeMax = npc.lifeMax * 3; * } * else if (npc.type == thoriummod.NPCType("Viscount")) * { * npc.lifeMax = npc.lifeMax * 4; * } * else if (npc.type == thoriummod.NPCType("TheBuriedWarrior")) * { * npc.lifeMax = npc.lifeMax * 5; * } * else if (npc.type == thoriummod.NPCType("GraniteEnergyStorm")) * { * npc.lifeMax = npc.lifeMax * 5; * } * else if (npc.type == thoriummod.NPCType("ThePrimeScouter")) * { * npc.lifeMax = npc.lifeMax * 6; * } * else if (npc.type == thoriummod.NPCType("BoreanStrider")) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == thoriummod.NPCType("BoreanStriderPopped")) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == thoriummod.NPCType("FallenDeathBeholder")) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == thoriummod.NPCType("FallenDeathBeholder2")) * { * npc.lifeMax = npc.lifeMax * 7; * } * else if (npc.type == thoriummod.NPCType("Lich")) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == thoriummod.NPCType("LichHeadless")) * { * npc.lifeMax = npc.lifeMax * 8; * } * else if (npc.type == thoriummod.NPCType("Abyssion")) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == thoriummod.NPCType("AbyssionCracked")) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == thoriummod.NPCType("AbyssionReleased")) * { * npc.lifeMax = npc.lifeMax * 9; * } * else if (npc.type == thoriummod.NPCType("Aquaius")) * { * npc.lifeMax = npc.lifeMax * 13; * } * else if (npc.type == thoriummod.NPCType("Aquaius2")) * { * npc.lifeMax = npc.lifeMax * 13; * } * else if (npc.type == thoriummod.NPCType("Omnicide")) * { * npc.lifeMax = npc.lifeMax * 13; * } * else if (npc.type == thoriummod.NPCType("SlagFury")) * { * npc.lifeMax = npc.lifeMax * 13; * } * else if (npc.type == thoriummod.NPCType("RealityBreaker")) * { * npc.lifeMax = npc.lifeMax * 13; * } * } * base.SetDefaults(npc); * }*/ public override void NPCLoot(NPC npc) { if (npc.type == NPCID.EaterofWorldsHead && npc.boss) { if (!MyPlayer.JungleMessage) { MyPlayer.JungleMessage = true; if (Main.netMode != 2) { Main.NewText("You feel a calm radiance of ki from the jungle.", 13, 201, 10); } else { NetworkText text2 = NetworkText.FromKey("You feel a calm radiance of ki from the jungle."); NetMessage.BroadcastChatMessage(text2, new Color(13, 201, 10)); } } } if (npc.type == NPCID.BrainofCthulhu) { if (!MyPlayer.JungleMessage) { MyPlayer.JungleMessage = true; if (Main.netMode != 2) { Main.NewText("You feel a calm radiance of ki from the jungle.", 13, 201, 10); } else { NetworkText text2 = NetworkText.FromKey("You feel a calm radiance of ki from the jungle."); NetMessage.BroadcastChatMessage(text2, new Color(13, 201, 10)); } } } if (npc.type == NPCID.SkeletronHead) { if (!MyPlayer.HellMessage) { MyPlayer.HellMessage = true; if (Main.netMode != 2) { Main.NewText("The underworld's flames shimmer with energy.", 201, 10, 10); } else { NetworkText text2 = NetworkText.FromKey("The underworld's flames shimmer with energy."); NetMessage.BroadcastChatMessage(text2, new Color(201, 10, 10)); } } } if (npc.type == NPCID.WallofFlesh) { if (!MyPlayer.EvilMessage) { MyPlayer.EvilMessage = true; if (Main.netMode != 2) { Main.NewText("The world's evil erupts with destructive energy.", 152, 36, 173); } else { NetworkText text2 = NetworkText.FromKey("The world's evil erupts with destructive energy."); NetMessage.BroadcastChatMessage(text2, new Color(152, 36, 173)); } } } if (npc.type == NPCID.Plantera) { if (!MyPlayer.MushroomMessage) { Main.NewText("The glowing mushrooms of the caverns explode with radiance.", 232, 242, 50); MyPlayer.MushroomMessage = true; if (Main.netMode != 2) { Main.NewText("The glowing mushrooms of the caverns explode with radiance.", 232, 242, 50); } else { NetworkText text2 = NetworkText.FromKey("The glowing mushrooms of the caverns explode with radiance."); NetMessage.BroadcastChatMessage(text2, new Color(232, 242, 50)); } } } if (npc.damage > 1 && npc.lifeMax > 10 && !npc.friendly) { if (!Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneBeach && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneCorrupt && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneCrimson && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneDesert && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneDungeon && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneGlowshroom && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneHoly && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneJungle && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneMeteor && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneOldOneArmy && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneSandstorm && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneSnow && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneTowerNebula && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneTowerSolar && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneTowerStardust && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneTowerVortex && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneUndergroundDesert && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneUnderworldHeight && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneRockLayerHeight && !Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneDirtLayerHeight) { if (Main.rand.Next(3) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("StableKiCrystal"), Main.rand.Next(1, 2)); } } if (NPC.downedBoss2) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneJungle) { if (Main.rand.Next(2) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("CalmKiCrystal"), Main.rand.Next(1, 3)); } } } if (NPC.downedBoss3) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneUnderworldHeight) { if (Main.rand.Next(2) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PridefulKiCrystal"), Main.rand.Next(1, 3)); } } } if (Main.hardMode) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneCrimson) { if (Main.rand.Next(2) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AngerKiCrystal"), Main.rand.Next(1, 3)); } } } if (Main.hardMode) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneCorrupt) { if (Main.rand.Next(2) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AngerKiCrystal"), Main.rand.Next(1, 3)); } } } if (Main.hardMode && NPC.downedPlantBoss) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneGlowshroom) { if (Main.rand.Next(2) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("RadiantKiCrystal"), Main.rand.Next(1, 4)); } } } } if (npc.boss) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SenzuBean"), Main.rand.Next(1, 3)); } } } if (!Main.expertMode) { if (npc.type == NPCID.EyeofCthulhu) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KiFragment1"), 1); } } } if (npc.type == NPCID.SkeletronHead) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KiFragment2"), 1); } } } if (npc.type == NPCID.SkeletronPrime) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KiFragment3"), 1); } } } if (npc.type == NPCID.Plantera) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KiFragment4"), 1); } } } if (npc.type == NPCID.CultistBoss) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KiFragment5"), 1); } } } } if (!Main.expertMode) { if (npc.type == NPCID.EyeofCthulhu) { if (Main.rand.Next(3) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KaioFragmentFirst"), 1); } } } if (!Main.expertMode) { if (npc.type == NPCID.SkeletronHead) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KaioFragment1"), 1); } } } } if (!Main.expertMode) { if (npc.type == NPCID.SkeletronPrime) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KaioFragment2"), 1); } } } } if (!Main.expertMode) { if (npc.type == NPCID.Golem) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KaioFragment3"), 1); } } } } if (!Main.expertMode) { if (npc.type == NPCID.MoonLordCore) { if (Main.rand.Next(3) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("KaioFragment4"), 1); } } } } if (NPC.downedQueenBee) { if (npc.type == NPCID.Harpy) { if (Main.rand.Next(2) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AstralEssentia"), 1); } } } } if (NPC.downedBoss3) { if (npc.type == NPCID.AngryBones || npc.type == NPCID.AngryBonesBig || npc.type == NPCID.AngryBonesBigHelmet || npc.type == NPCID.AngryBonesBigMuscle || npc.type == NPCID.DarkCaster) { if (Main.rand.Next(4) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SkeletalEssence"), Main.rand.Next(1, 3)); } } } } if (NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3) { if (npc.type == NPCID.CrimsonAxe || npc.type == NPCID.PossessedArmor || npc.type == NPCID.EnchantedSword || npc.type == NPCID.CursedHammer) { if (Main.rand.Next(2) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SoulofEntity"), Main.rand.Next(1, 4)); } } } } if (NPC.downedGolemBoss) { if (npc.type == NPCID.RedDevil) { if (Main.rand.Next(2) == 0) { { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DemonicSoul"), 1); } } } } if (NPC.downedBoss2) { if (Main.player[(int)Player.FindClosest(npc.position, npc.width, npc.height)].ZoneRockLayerHeight) { if (Main.rand.Next(9) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("EarthenShard"), Main.rand.Next(1, 2)); } } } if (Main.hardMode) { if (npc.type == NPCID.LunarTowerSolar || npc.type == NPCID.LunarTowerNebula || npc.type == NPCID.LunarTowerVortex || npc.type == NPCID.LunarTowerStardust) { int stacks = Main.rand.Next(6, 12) / 2; if (Main.expertMode) { stacks = (int)(stacks * 1.5f); } for (int i = 0; i < stacks; i++) { Item.NewItem((int)npc.position.X + Main.rand.Next(npc.width), (int)npc.position.Y + Main.rand.Next(npc.height), 2, 2, mod.ItemType("RadiantFragment"), Main.rand.Next(1, 4)); } } } }
// SpawnBoss(player, mod.NPCType("MyBoss"), true, player.Center + new Vector2(0, 800f), "DerpFromBelow", false); internal static int SpawnBoss(Player player, int bossType, bool spawnMessage = true, Vector2 npcCenter = default, string overrideDisplayName = "", bool namePlural = false) { if (npcCenter == default) { npcCenter = player.Center; } if (Main.netMode != NetmodeID.MultiplayerClient) { int npcID = NPC.NewNPC((int)npcCenter.X, (int)npcCenter.Y, bossType); Main.npc[npcID].Center = npcCenter; Main.npc[npcID].netUpdate2 = true; if (spawnMessage) { string npcName = !string.IsNullOrEmpty(Main.npc[npcID].GivenName) ? Main.npc[npcID].GivenName : overrideDisplayName; if ((npcName == null || string.IsNullOrEmpty(npcName)) && Main.npc[npcID].modNPC != null) { npcName = Main.npc[npcID].modNPC.DisplayName.GetDefault(); } if (namePlural) { if (Main.netMode == NetmodeID.SinglePlayer) { Main.NewText(npcName + " have awoken!", 175, 75); } else if (Main.netMode == NetmodeID.Server) { NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(npcName + " have awoken!"), new Color(175, 75, 255)); } } else { if (Main.netMode == NetmodeID.SinglePlayer) { Main.NewText(Language.GetTextValue("Announcement.HasAwoken", npcName), 175, 75); } else if (Main.netMode == NetmodeID.Server) { NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[] { NetworkText.FromLiteral(npcName) }), new Color(175, 75, 255)); } } } } else { // I have no idea how to convert this to the standard system so im gonna post this method too lol FargoNet.SendNetMessage(FargoNet.SummonNPCFromClient, (byte)player.whoAmI, (short)bossType, spawnMessage, npcCenter.X, npcCenter.Y, overrideDisplayName, namePlural); } return(200); }
public void ProcessIncomingMessage(string text, byte clientId) { ChatHelper.SendChatMessageToClient(NetworkText.FromLiteral(string.Join(", ", from player in Main.player where player.active select player.name)), RESPONSE_COLOR, clientId); }
/// <summary> /// Intercept all other messages from Terraria. E.g. blood moon, death notifications, and player join/leaves. /// </summary> private void NetMessage_BroadcastChatMessage(On.Terraria.NetMessage.orig_BroadcastChatMessage orig, NetworkText text, Color color, int excludedPlayer) { if (Global.Config.ShowGameEvents && !text.ToString().EndsWith(PlayerJoinEndingString) && !text.ToString().EndsWith(PlayerLeaveEndingString)) { Core.RaiseTerrariaMessageReceived(this, (excludedPlayer > 0 ? Main.player[excludedPlayer].ToTCRPlayer(excludedPlayer) : TCRPlayer.Server), text.ToString()); } orig(text, color, excludedPlayer); }
internal static bool HijackSendData(int whoAmI, int msgType, int remoteClient, int ignoreClient, NetworkText text, int number, float number2, float number3, float number4, int number5, int number6, int number7) { bool hijacked = false; foreach (Mod mod in ModLoader.Mods) { hijacked |= mod.HijackSendData(whoAmI, msgType, remoteClient, ignoreClient, text, number, number2, number3, number4, number5, number6, number7); } return(hijacked); }
/// <summary> /// Determines whether to block damage if they have recently used a banned item or modifies damage /// if the projectile is on the modifications list. /// </summary> /// <param name="args">The GetDataHandlerArgs object containing the player who sent the packet and the /// data in it</param> /// <returns>Whether or not the packet was handled (and should therefore not be processed /// by anything else</returns> private bool HandleDamage(GetDataHandlerArgs args) { if (args.Player == null) { return(false); } var index = args.Player.Index; var playerId = (byte)args.Data.ReadByte(); var damageSourceFlags = (BitsByte)args.Data.ReadByte(); var sourceItemType = -1; var sourceProjectileType = -1; var sourceItemPrefix = -1; if (damageSourceFlags[0]) { var sourcePlayerIndex = args.Data.ReadInt16(); } if (damageSourceFlags[1]) { var sourceNPCIndex = args.Data.ReadInt16(); } if (damageSourceFlags[2]) { var sourceProjectileIndex = args.Data.ReadInt16(); } if (damageSourceFlags[3]) { var sourceOtherIndex = args.Data.ReadByte(); } if (damageSourceFlags[4]) { sourceProjectileType = args.Data.ReadInt16(); } if (damageSourceFlags[5]) { sourceItemType = args.Data.ReadInt16(); } if (damageSourceFlags[6]) { sourceItemPrefix = args.Data.ReadByte(); } var damage = args.Data.ReadInt16(); var dir = args.Data.ReadByte(); var flags = args.Data.ReadByte(); args.Data.ReadByte(); if (TShock.Players[playerId] == null || sourceItemType == -1 || args.Player.IsDead || Controller.Players[playerId].IsDead) { return(true); } // The sourceItemType is only reliable if no projectile is involved // as sourceItemType is simply the active slot item // TODO: Change this to use active slot item of server Item weapon = new Item(); if (sourceProjectileType == -1) { weapon.SetDefaults(sourceItemType); weapon.Prefix(sourceItemPrefix); weapon.owner = args.Player.Index; } else if (args.Player.ProjectileWeapon[sourceProjectileType] != null) { Item bestWeaponGuess = args.Player.ProjectileWeapon[sourceProjectileType]; weapon.SetDefaults(bestWeaponGuess.netID); weapon.Prefix(bestWeaponGuess.prefix); weapon.owner = args.Player.Index; } double internalDamage = Main.player[args.Player.Index].GetWeaponDamage(weapon); // Check whether the source of damage is banned if (Controller.Weapons.Count(p => p.netID == weapon.netID && p.banned) > 0 || Controller.Projectiles.Count(p => p.netID == sourceProjectileType && p.banned) > 0) { args.Player.TshockPlayer.SendData(PacketTypes.PlayerHp, "", playerId); return(true); } internalDamage = DamageController.DecideDamage(args.Player, Controller.Players[playerId], weapon, sourceProjectileType, internalDamage); // Send Damage and Damage Text int realDamage = (int)Math.Round(DamageUtils.GetRealDamageFromInternalDamage(Main.player[playerId], internalDamage)); Color msgColor = new Color(162, 0, 255); NetMessage.SendData(119, index, -1, NetworkText.FromLiteral($"{realDamage}"), (int)msgColor.PackedValue, Main.player[playerId].position.X, Main.player[playerId].position.Y - 32); var killer = new PlayerKiller(args.Player.TshockPlayer, weapon); Controller.Players[playerId].ApplyPlayerDamage(killer, weapon, dir, (int)internalDamage, realDamage); NetMessage.SendData((int)PacketTypes.PlayerHp, -1, playerId, NetworkText.Empty, playerId); // Update spectating time so they cannot simply hide from their attacker if (Controller.Players[playerId].LastSpectating < DateTime.UtcNow.AddSeconds(-15)) { Controller.Players[playerId].LastSpectating = DateTime.UtcNow.AddSeconds(-15); } return(true); }
public override void AI() { npc.GivenName = ""; Rectangle room = MWorld.TorizoRoomLocation; if (room.X > 0 && room.Y > 0) { Vector2 pos = new Vector2(room.X + 8, room.Y + room.Height - 4); npc.direction = 1; if (room.X > Main.maxTilesX / 2) { pos.X = (room.X + room.Width - 8); npc.direction = -1; } pos *= 16f; npc.spriteDirection = npc.direction; npc.position.X = pos.X - npc.width / 2; npc.position.Y = pos.Y - npc.height; } for (int i = 0; i < 255; i++) { Player player = Main.player[i]; if (player.active && !player.dead && Vector2.Distance(player.Center, npc.Center) < 200f && Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height) && npc.ai[0] == 0) { npc.ai[0] = 1; npc.target = player.whoAmI; } } eTankFrameCounter++; if (eTankFrameCounter > 2) { eTankFrame++; eTankFrameCounter = 0; } if (eTankFrame > 1) { eTankFrame = 0; } if (npc.ai[0] == 1) { if (npc.ai[1] <= 0) { Vector2 ePos = npc.Center + new Vector2(eTankPos.X * npc.direction, eTankPos.Y); for (int i = 0; i < 10; i++) { Dust dust = Dust.NewDustDirect(ePos - new Vector2(16, 16), 32, 32, 57, 0f, 0f, 100, default(Color), 3f); dust.velocity *= 1.4f; dust.noGravity = true; dust = Dust.NewDustDirect(ePos - new Vector2(16, 16), 32, 32, 30, 0f, 0f, 100, default(Color), 3f); dust.velocity *= 1.4f; dust.noGravity = true; } for (int i = 1; i <= 4; i++) { Vector2 velocity = new Vector2(-Main.rand.Next(31), -Main.rand.Next(31)) * 0.2f * 0.4f; if (i % 2 == 0) { velocity.X *= -1; } Gore gore = Gore.NewGoreDirect(ePos, velocity, mod.GetGoreSlot("Gores/TorizoETankGore" + i)); gore.velocity.X = velocity.X; gore.timeLeft = 60; } Main.PlaySound(2, (int)ePos.X, (int)ePos.Y, 14); drawETank = false; for (int i = 0; i < 6; i++) { Vector2 velocity = new Vector2(Main.rand.Next(12) * npc.direction, -Main.rand.Next(12)); if (velocity.Length() < 6f) { velocity *= (6f / velocity.Length()); } Projectile part = Projectile.NewProjectileDirect(ePos, velocity, mod.ProjectileType("Torizo_EnergyParticle"), 0, 0f); part.ai[0] = npc.Center.X; part.ai[1] = npc.Center.Y; } npc.ai[1] = 1; } else { npc.ai[1]++; if (npc.ai[1] > 180) { npc.ai[0] = 2; npc.ai[1] = 0; } } } if (npc.ai[0] == 2) { for (int i = 9; i >= 0; i--) { Vector2 gPos = npc.Center + gorePos[i]; byte goreFrame = 0; if (npc.direction == -1) { gPos.X = npc.Center.X - gorePos[i].X; goreFrame = 1; } Vector2 velocity = new Vector2(gPos.X - npc.Center.X, gPos.Y - (npc.position.Y + npc.height)) * 0.02f; int type = mod.GetGoreSlot("Gores/TorizoStatueGore" + (1 + i)); gPos.X -= Main.goreTexture[type].Width / 2; gPos.Y -= Main.goreTexture[type].Height / 4; Gore gore = Gore.NewGorePerfect(gPos, velocity, type); gore.numFrames = 2; gore.frame = goreFrame; gore.timeLeft = 60; int stype = 0; if (i % 2 == 0) { stype = 21; } Main.PlaySound(stype, (int)gPos.X, (int)gPos.Y, 1, 1f, 0f); } for (int i = 0; i < 35; i++) { Dust dust = Main.dust[Dust.NewDust(npc.position - new Vector2(8, 8), npc.width + 16, npc.height + 16, 30, 0f, 0f, 100, default(Color), 2.5f)]; dust.velocity *= 1.4f; dust.noGravity = true; } if (!NPC.AnyNPCs(mod.NPCType("Torizo"))) { Vector2 tPos = new Vector2(npc.Center.X - 26 * npc.direction, npc.position.Y + npc.height - 117); NPC.NewNPC((int)tPos.X, (int)tPos.Y, mod.NPCType("Torizo"), npc.whoAmI, 0, 1, 0, 0, npc.target); } if (Main.netMode == 0) { Main.NewText(Language.GetTextValue("Announcement.HasAwoken", "Torizo"), 175, 75, 255, false); } if (Main.netMode == 2) { NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", "The Torizo"), new Color(175, 75, 255), -1); } npc.active = false; } }
private void CleanInventory(int Who) { if (TShock.ServerSideCharacterConfig.Enabled && !TShock.Players[Who].IsLoggedIn) { var player = TShock.Players[Who]; player.TPlayer.SpawnX = -1; player.TPlayer.SpawnY = -1; player.sX = -1; player.sY = -1; for (int i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventorySlots) { //0-58 player.TPlayer.inventory[i].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots) { //59-78 var index = i - NetItem.InventorySlots; player.TPlayer.armor[index].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots) { //79-88 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots); player.TPlayer.dye[index].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots) { //89-93 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots); player.TPlayer.miscEquips[index].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots) { //93-98 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots); player.TPlayer.miscDyes[index].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots) { //98-138 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots); player.TPlayer.bank.item[index].netDefaults(0); } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots) { //138-178 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots); player.TPlayer.bank2.item[index].netDefaults(0); } else { //179 player.TPlayer.trashItem.netDefaults(0); } } for (int k = 0; k < NetItem.MaxInventory; k++) { NetMessage.SendData(5, -1, -1, NetworkText.Empty, player.Index, (float)k, 0f, 0f, 0); } for (int k = 0; k < Player.maxBuffs; k++) { player.TPlayer.buffType[k] = 0; } NetMessage.SendData(4, -1, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(42, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(16, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(50, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); for (int k = 0; k < NetItem.MaxInventory; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.Empty, player.Index, (float)k, 0f, 0f, 0); } for (int k = 0; k < Player.maxBuffs; k++) { player.TPlayer.buffType[k] = 0; } NetMessage.SendData(4, player.Index, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(42, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(16, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(50, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); } }
/// <summary> /// Restores a player's character to the state stored in the database /// </summary> /// <param name="player"></param> public void RestoreCharacter(TSPlayer player) { // Start ignoring SSC-related packets! This is critical so that we don't send or receive dirty data! player.IgnoreSSCPackets = true; player.TPlayer.statLife = this.health; player.TPlayer.statLifeMax = this.maxHealth; player.TPlayer.statMana = this.maxMana; player.TPlayer.statManaMax = this.maxMana; player.TPlayer.SpawnX = this.spawnX; player.TPlayer.SpawnY = this.spawnY; player.sX = this.spawnX; player.sY = this.spawnY; player.TPlayer.hairDye = this.hairDye; player.TPlayer.anglerQuestsFinished = this.questsCompleted; if (extraSlot != null) { player.TPlayer.extraAccessory = extraSlot.Value == 1 ? true : false; } if (this.skinVariant != null) { player.TPlayer.skinVariant = this.skinVariant.Value; } if (this.hair != null) { player.TPlayer.hair = this.hair.Value; } if (this.hairColor != null) { player.TPlayer.hairColor = this.hairColor.Value; } if (this.pantsColor != null) { player.TPlayer.pantsColor = this.pantsColor.Value; } if (this.shirtColor != null) { player.TPlayer.shirtColor = this.shirtColor.Value; } if (this.underShirtColor != null) { player.TPlayer.underShirtColor = this.underShirtColor.Value; } if (this.shoeColor != null) { player.TPlayer.shoeColor = this.shoeColor.Value; } if (this.skinColor != null) { player.TPlayer.skinColor = this.skinColor.Value; } if (this.eyeColor != null) { player.TPlayer.eyeColor = this.eyeColor.Value; } if (this.hideVisuals != null) { player.TPlayer.hideVisibleAccessory = this.hideVisuals; } else { player.TPlayer.hideVisibleAccessory = new bool[player.TPlayer.hideVisibleAccessory.Length]; } if (this.unlockedBiomeTorches != null) { player.TPlayer.unlockedBiomeTorches = this.unlockedBiomeTorches == 1 ? true : false; player.TPlayer.UsingBiomeTorches = this.unlockedBiomeTorches == 1 ? true : false; } for (int i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventoryIndex.Item2) { //0-58 player.TPlayer.inventory[i].netDefaults(this.inventory[i].NetId); if (player.TPlayer.inventory[i].netID != 0) { player.TPlayer.inventory[i].stack = this.inventory[i].Stack; player.TPlayer.inventory[i].prefix = this.inventory[i].PrefixId; } } else if (i < NetItem.ArmorIndex.Item2) { //59-78 var index = i - NetItem.ArmorIndex.Item1; player.TPlayer.armor[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.armor[index].netID != 0) { player.TPlayer.armor[index].stack = this.inventory[i].Stack; player.TPlayer.armor[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.DyeIndex.Item2) { //79-88 var index = i - NetItem.DyeIndex.Item1; player.TPlayer.dye[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.dye[index].netID != 0) { player.TPlayer.dye[index].stack = this.inventory[i].Stack; player.TPlayer.dye[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.MiscEquipIndex.Item2) { //89-93 var index = i - NetItem.MiscEquipIndex.Item1; player.TPlayer.miscEquips[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.miscEquips[index].netID != 0) { player.TPlayer.miscEquips[index].stack = this.inventory[i].Stack; player.TPlayer.miscEquips[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.MiscDyeIndex.Item2) { //93-98 var index = i - NetItem.MiscDyeIndex.Item1; player.TPlayer.miscDyes[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.miscDyes[index].netID != 0) { player.TPlayer.miscDyes[index].stack = this.inventory[i].Stack; player.TPlayer.miscDyes[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.PiggyIndex.Item2) { //98-138 var index = i - NetItem.PiggyIndex.Item1; player.TPlayer.bank.item[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.bank.item[index].netID != 0) { player.TPlayer.bank.item[index].stack = this.inventory[i].Stack; player.TPlayer.bank.item[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.SafeIndex.Item2) { //138-178 var index = i - NetItem.SafeIndex.Item1; player.TPlayer.bank2.item[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.bank2.item[index].netID != 0) { player.TPlayer.bank2.item[index].stack = this.inventory[i].Stack; player.TPlayer.bank2.item[index].prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.TrashIndex.Item2) { //179-219 var index = i - NetItem.TrashIndex.Item1; player.TPlayer.trashItem.netDefaults(this.inventory[i].NetId); if (player.TPlayer.trashItem.netID != 0) { player.TPlayer.trashItem.stack = this.inventory[i].Stack; player.TPlayer.trashItem.prefix = (byte)this.inventory[i].PrefixId; } } else if (i < NetItem.ForgeIndex.Item2) { //220 var index = i - NetItem.ForgeIndex.Item1; player.TPlayer.bank3.item[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.bank3.item[index].netID != 0) { player.TPlayer.bank3.item[index].stack = this.inventory[i].Stack; player.TPlayer.bank3.item[index].Prefix((byte)this.inventory[i].PrefixId); } } else { //260 var index = i - NetItem.VoidIndex.Item1; player.TPlayer.bank4.item[index].netDefaults(this.inventory[i].NetId); if (player.TPlayer.bank4.item[index].netID != 0) { player.TPlayer.bank4.item[index].stack = this.inventory[i].Stack; player.TPlayer.bank4.item[index].Prefix((byte)this.inventory[i].PrefixId); } } } float slot = 0f; for (int k = 0; k < NetItem.InventorySlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].inventory[k].Name), player.Index, slot, (float)Main.player[player.Index].inventory[k].prefix); slot++; } for (int k = 0; k < NetItem.ArmorSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].armor[k].Name), player.Index, slot, (float)Main.player[player.Index].armor[k].prefix); slot++; } for (int k = 0; k < NetItem.DyeSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].dye[k].Name), player.Index, slot, (float)Main.player[player.Index].dye[k].prefix); slot++; } for (int k = 0; k < NetItem.MiscEquipSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].miscEquips[k].Name), player.Index, slot, (float)Main.player[player.Index].miscEquips[k].prefix); slot++; } for (int k = 0; k < NetItem.MiscDyeSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].miscDyes[k].Name), player.Index, slot, (float)Main.player[player.Index].miscDyes[k].prefix); slot++; } for (int k = 0; k < NetItem.PiggySlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].bank.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank.item[k].prefix); slot++; } for (int k = 0; k < NetItem.SafeSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].bank2.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank2.item[k].prefix); slot++; } NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].trashItem.Name), player.Index, slot++, (float)Main.player[player.Index].trashItem.prefix); for (int k = 0; k < NetItem.ForgeSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].bank3.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank3.item[k].prefix); slot++; } for (int k = 0; k < NetItem.VoidSlots; k++) { NetMessage.SendData(5, -1, -1, NetworkText.FromLiteral(Main.player[player.Index].bank4.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank4.item[k].prefix); slot++; } NetMessage.SendData(4, -1, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(42, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(16, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); slot = 0f; for (int k = 0; k < NetItem.InventorySlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].inventory[k].Name), player.Index, slot, (float)Main.player[player.Index].inventory[k].prefix); slot++; } for (int k = 0; k < NetItem.ArmorSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].armor[k].Name), player.Index, slot, (float)Main.player[player.Index].armor[k].prefix); slot++; } for (int k = 0; k < NetItem.DyeSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].dye[k].Name), player.Index, slot, (float)Main.player[player.Index].dye[k].prefix); slot++; } for (int k = 0; k < NetItem.MiscEquipSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].miscEquips[k].Name), player.Index, slot, (float)Main.player[player.Index].miscEquips[k].prefix); slot++; } for (int k = 0; k < NetItem.MiscDyeSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].miscDyes[k].Name), player.Index, slot, (float)Main.player[player.Index].miscDyes[k].prefix); slot++; } for (int k = 0; k < NetItem.PiggySlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].bank.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank.item[k].prefix); slot++; } for (int k = 0; k < NetItem.SafeSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].bank2.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank2.item[k].prefix); slot++; } NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].trashItem.Name), player.Index, slot++, (float)Main.player[player.Index].trashItem.prefix); for (int k = 0; k < NetItem.ForgeSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].bank3.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank3.item[k].prefix); slot++; } for (int k = 0; k < NetItem.VoidSlots; k++) { NetMessage.SendData(5, player.Index, -1, NetworkText.FromLiteral(Main.player[player.Index].bank4.item[k].Name), player.Index, slot, (float)Main.player[player.Index].bank4.item[k].prefix); slot++; } NetMessage.SendData(4, player.Index, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(42, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(16, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); for (int k = 0; k < 22; k++) { player.TPlayer.buffType[k] = 0; } /* * The following packets are sent twice because the server will not send a packet to a client * if they have not spawned yet if the remoteclient is -1 * This is for when players login via uuid or serverpassword instead of via * the login command. */ NetMessage.SendData(50, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(50, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0); NetMessage.SendData(76, player.Index, -1, NetworkText.Empty, player.Index); NetMessage.SendData(76, -1, -1, NetworkText.Empty, player.Index); NetMessage.SendData(39, player.Index, -1, NetworkText.Empty, 400); if (Main.GameModeInfo.IsJourneyMode) { var sacrificedItems = TShock.ResearchDatastore.GetSacrificedItems(); for (int i = 0; i < ItemID.Count; i++) { var amount = 0; if (sacrificedItems.ContainsKey(i)) { amount = sacrificedItems[i]; } var response = NetCreativeUnlocksModule.SerializeItemSacrifice(i, amount); NetManager.Instance.SendToClient(response, player.Index); } } }
/// <summary> /// Sets a condition delegate that will determine whether or not the recipe will be to be available for the player to /// use. The condition can be unrelated to items or tiles (for example, biome or time). /// </summary> /// <param name="condition">The predicate delegate condition.</param> /// <param name="description"> /// A description of this condition. Use NetworkText.FromKey, or NetworkText.FromLiteral for /// this. /// </param> public NewRecipeFinder AddCondition(NetworkText description, Predicate <Recipe> condition) => AddCondition(new Recipe.Condition(description, condition));
public override void PostUpdate() { Player player = Main.player[Main.myPlayer]; ReducedGrindingPlayer mPlayer = player.GetModPlayer <ReducedGrindingPlayer>(mod); if (player.HasItem(1528)) //Jungle Chest { jungleChestMined = true; } if (player.HasItem(1529)) //Corruption Chest { infectionChestMined = true; } if (player.HasItem(1530)) //Crimson Chest { infectionChestMined = true; } if (player.HasItem(1531)) //Hallowed Chest { hallowedChestMined = true; } if (player.HasItem(1532)) //Frozen Chest { frozenChestMined = true; } int playerCoinAmount = 0; foreach (Item i in player.inventory) { switch (i.type) { case ItemID.CopperCoin: playerCoinAmount += 1 * i.stack; break; case ItemID.SilverCoin: playerCoinAmount += 100 * i.stack; break; case ItemID.GoldCoin: playerCoinAmount += 10000 * i.stack; break; case ItemID.PlatinumCoin: playerCoinAmount += 1000000 * i.stack; break; } } bool anyPlayerHasCelestialBeacon = false; for (int i = 0; i < 255; i++) { if (Main.player[i].active && Main.player[i].HasItem(mod.ItemType("Celestial_Beacon"))) { anyPlayerHasCelestialBeacon = true; break; } } if (NPC.MoonLordCountdown > 1 && anyPlayerHasCelestialBeacon) { NPC.MoonLordCountdown = 1; } //if (NPC.MoonLordCountdown > 1 && Main.player.Any(x => x.HasItem(mod.ItemType("Celestial_Beacon")))) //NPC.MoonLordCountdown = 1; if (Main.time % 600 == 0 && !NPC.downedMoonlord) { for (int i = 0; i < Main.npc.Length; i++) { if (Main.npc[i].type == NPCID.MoonLordCore && !anyPlayerHasCelestialBeacon) { Main.player[(int)Player.FindClosest(Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)].QuickSpawnItem(mod.ItemType("Celestial_Beacon")); break; } } } if (skipToNight) { if (Main.sundialCooldown > 0) { ReducedGrindingWorld.skippedToDayOrNight = true; } Main.time = 54000; skipToDay = false; skipToNight = false; //Force Traveling Merchant despawn in order to prevent exploiting. int travelingMerchantTarget = -1; for (int i = 0; i < 200; i++) { if (Main.npc[i].active && Main.npc[i].type == 368) { travelingMerchantTarget = i; break; } } if (travelingMerchantTarget > -1) { string fullName = Main.npc[travelingMerchantTarget].FullName; if (Main.netMode == NetmodeID.SinglePlayer) //0) { Main.NewText(Lang.misc[35].Format(fullName), 50, 125); } else if (Main.netMode == NetmodeID.Server) //2) { NetMessage.BroadcastChatMessage(NetworkText.FromKey(Lang.misc[35].Key, Main.npc[travelingMerchantTarget].GetFullNetName()), new Color(50, 125, 255)); } Main.npc[travelingMerchantTarget].active = false; Main.npc[travelingMerchantTarget].netSkip = -1; Main.npc[travelingMerchantTarget].life = 0; NetMessage.SendData(23, -1, -1, null, travelingMerchantTarget); } if (Main.netMode == NetmodeID.Server) //Server { var netMessage = mod.GetPacket(); netMessage.Write((byte)ReducedGrindingMessageType.skipToNight); netMessage.Write(ReducedGrindingWorld.skipToNight); netMessage.Send(); netMessage.Write((byte)ReducedGrindingMessageType.skipToDay); netMessage.Write(ReducedGrindingWorld.skipToDay); netMessage.Send(); NetMessage.SendData(7); } } if (skipToDay) { if (Main.sundialCooldown > 0) { ReducedGrindingWorld.skippedToDayOrNight = true; } Main.time = 32400; skipToDay = false; skipToNight = false; if (Main.netMode == NetmodeID.Server) { var netMessage = mod.GetPacket(); netMessage.Write((byte)ReducedGrindingMessageType.skipToNight); netMessage.Write(ReducedGrindingWorld.skipToNight); netMessage.Send(); netMessage.Write((byte)ReducedGrindingMessageType.skipToDay); netMessage.Write(ReducedGrindingWorld.skipToDay); netMessage.Send(); NetMessage.SendData(7); } } if (Main.dayTime && skippedToDayOrNight) { Main.sundialCooldown++; skippedToDayOrNight = false; } //There are 21 stationary vanilla NPCs (excluding Guide and Santa) as of 5/26/2017; 15 Pre-Hardmode and 6 Hardmode. float TownNPCs = 0f; float TownNPCsMax = 15f; float TownHardmodeNPCs = 0f; float TownHardmodeNPCsMax = 6f; bool travelingMerchantExists = false; bool stationaryMerchantExists = false; bool tryToSpawnTravelingMerchant = true; if (mPlayer.clientConf.BoneMerchant) { TownNPCsMax++; } if (mPlayer.clientConf.ChestSalesman) { TownNPCsMax++; } if (mPlayer.clientConf.StationaryMerchant) { TownNPCsMax++; } if (mPlayer.clientConf.LootMerchant) { TownNPCsMax++; } if (mPlayer.clientConf.Santa) { TownHardmodeNPCsMax++; } for (int i = 0; i < Terraria.Main.npc.Length; i++) //Do once for each NPC in the world { if (Terraria.Main.npc[i].townNPC == true) { if (Terraria.Main.npc[i].type == NPCID.TravellingMerchant) { travelingMerchantExists = true; tryToSpawnTravelingMerchant = false; } if (Terraria.Main.npc[i].type == mod.NPCType("StationaryMerchant")) { stationaryMerchantExists = true; } if ( Terraria.Main.npc[i].type == NPCID.Merchant || Terraria.Main.npc[i].type == NPCID.Nurse || Terraria.Main.npc[i].type == NPCID.Demolitionist || Terraria.Main.npc[i].type == NPCID.DyeTrader || Terraria.Main.npc[i].type == NPCID.Dryad || Terraria.Main.npc[i].type == NPCID.DD2Bartender || Terraria.Main.npc[i].type == NPCID.ArmsDealer || Terraria.Main.npc[i].type == NPCID.Stylist || Terraria.Main.npc[i].type == NPCID.Painter || Terraria.Main.npc[i].type == NPCID.Angler || Terraria.Main.npc[i].type == NPCID.GoblinTinkerer || Terraria.Main.npc[i].type == NPCID.WitchDoctor || Terraria.Main.npc[i].type == NPCID.Clothier || Terraria.Main.npc[i].type == NPCID.Mechanic || Terraria.Main.npc[i].type == NPCID.PartyGirl || (Terraria.Main.npc[i].type == mod.NPCType("BoneMerchant") && mPlayer.clientConf.BoneMerchant) || (Terraria.Main.npc[i].type == mod.NPCType("ChestSalesman") && mPlayer.clientConf.ChestSalesman) || (Terraria.Main.npc[i].type == mod.NPCType("StationaryMerchant") && mPlayer.clientConf.StationaryMerchant) || (Terraria.Main.npc[i].type == mod.NPCType("LootMerchant") && mPlayer.clientConf.LootMerchant) ) { TownNPCs++; } else if ( Terraria.Main.npc[i].type == NPCID.Wizard || Terraria.Main.npc[i].type == NPCID.TaxCollector || Terraria.Main.npc[i].type == NPCID.Truffle || Terraria.Main.npc[i].type == NPCID.Pirate || Terraria.Main.npc[i].type == NPCID.Steampunker || Terraria.Main.npc[i].type == NPCID.Cyborg || (Terraria.Main.npc[i].type == mod.NPCType("Santa") && mPlayer.clientConf.Santa) ) { TownHardmodeNPCs++; } } } float TownNPCPercent = (TownNPCs / TownNPCsMax + TownHardmodeNPCs / TownHardmodeNPCsMax) / 2; if (!Main.fastForwardTime && Main.dayTime && Main.time < 27000.0) { int alltownNPCs = 0; for (int j = 0; j < 200; j++) { if (Main.npc[j].active && Main.npc[j].townNPC && Main.npc[j].type != 37 && Main.npc[j].type != 453) { alltownNPCs++; } } if (alltownNPCs >= 2) { if (tryToSpawnTravelingMerchant) { tryToSpawnTravelingMerchant = false; if (!Main.fastForwardTime && Main.dayTime && Main.time < 27000.0) { int chanceRoll = (int)(27000.0 / (double)Main.dayRate); chanceRoll *= 4; for (int i = 0; i < 3; i++) { if (Main.rand.Next(chanceRoll) == 0) { tryToSpawnTravelingMerchant = true; break; } } } } if (tryToSpawnTravelingMerchant && Main.rand.NextFloat() < mPlayer.clientConf.ChanceEachMorningTravelingMerchantWillSpawn * Math.Pow(TownNPCPercent, 2)) { WorldGen.SpawnTravelNPC(); } } } if (travelingMerchantExists && stationaryMerchantExists) { bool TravelingMerchantRestockOrder = false; for (int i = 0; i < 255; i++) { if (Main.player[i].active && Main.player[i].HasItem(mod.ItemType("Traveling_Merchant_Restock_Order"))) { TravelingMerchantRestockOrder = true; break; } } //Each Second there is an item that has a chance to appear in Traveling Merchant shop and isn't in Stationary Merchant shop. if (Main.time % 60 == 0 && (TravelingMerchantRestockOrder || ( smItemSake == false || smItemPho == false || smItemPadThai == false || smItemUltrabrightTorch == false || smItemAmmoBox == false || smItemMagicHat == false || smItemGypsyRobe == false || smItemGi == false || smItemCelestialMagnet == false || smItemDPSMeter == false || smItemLifeformAnalyzer == false || smItemStopwatch == false || smItemPaintSprayer == false || smItemBrickLayer == false || smItemPortableCementMixer == false || smItemExtendoGrip == false || smItemPresserator == false || smItemBlackCounterweight == false || smItemYellowCounterweight == false || smItemSittingDucksFishingPole == false || smItemKatana == false || (smItemCode1 == false && NPC.downedBoss1) || //Eye of Cthulhu (smItemRevolver == false && WorldGen.shadowOrbSmashed) || (smItemGatligator == false && Main.hardMode) || (smItemCode2 == false && NPC.downedMechBossAny) || (smItemPulseBow == false && NPC.downedPlantBoss) || smItemRedTeamBlock == false || smItemYellowTeamBlock == false || smItemGreenTeamBlock == false || smItemBlueTeamBlock == false || smItemPinkTeamBlock == false || smItemWhiteTeamBlock == false || smItemDiamondRing == false || smItemAngelHalo == false || smItemFez == false || smItemWinterCape == false || smItemRedCape == false || smItemCrimsonCloak == false || smItemMysteriousCape == false || smItemKimono == false || smItemWaterGun == false || smItemCompanionCube == false || smItemChalice == false || smItemArcaneRuneWall == false || smItemFancyDishes == false || smItemDynastyWood == false || smItemZebraSkin == false || smItemLeopardSkin == false || smItemTigerSkin == false || (smItemCastleMarsberg == false && NPC.downedMartians) || (smItemMartiaLisa == false && NPC.downedMartians) || (smItemTheTruthIsUpThere == false && NPC.downedMartians) || (smItemNotAKidNorASquid == false && NPC.downedMoonlord) || (smItemAcorns == false && Main.xMas) || (smItemColdSnap == false && Main.xMas) || (smItemCursedSaint == false && Main.xMas) || (smItemSnowfellas == false && Main.xMas) || (smItemTheSeason == false && Main.xMas) ) )) { for (int i = 0; i < Terraria.Main.npc.Length; i++) //Do once for each NPC in the world { if (Terraria.Main.npc[i].type == NPCID.TravellingMerchant) { if (Main.rand.NextFloat() < mPlayer.clientConf.ChanceEachInGameMinuteWillResetTravelingMerchant * Math.Pow(TownNPCPercent, 2)) { Chest.SetupTravelShop(); if (Main.netMode == NetmodeID.Server) { NetMessage.BroadcastChatMessage(NetworkText.FromKey("The traveling merchant restocked his shop."), new Color(0, 127, 255)); } else if (Main.netMode == NetmodeID.SinglePlayer) // Single Player { Main.NewText("The traveling merchant restocked his shop.", 0, 127, 255); } } break; } } } } }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; bool anycursedarmor = false; for (int indexX = -70; indexX <= 70; indexX++) { for (int indexY = -90; indexY <= 90; indexY++) { if (Framing.GetTileSafely(indexX + i, indexY + j).type == mod.TileType("CursedArmor")) { WorldGen.KillTile(indexX + i, indexY + j); if (Main.netMode != NetmodeID.SinglePlayer) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, indexX + i, indexY + j); } anycursedarmor = true; } } } if (anycursedarmor) { CombatText.NewText(new Rectangle(i * 16, j * 16, 20, 10), Color.GreenYellow, "Trapped!"); return(true); } else if (NPC.AnyNPCs(ModContent.NPCType <Enchanted_Armor>())) { Main.PlaySound(new LegacySoundStyle(SoundID.NPCKilled, 6).WithPitchVariance(0.2f).WithVolume(0.5f), new Vector2(i * 16, j * 16)); foreach (NPC npc in Main.npc.Where(x => x.active && x.type == ModContent.NPCType <Enchanted_Armor>())) { npc.ai[1] = 30; } return(true); } Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == NetmodeID.MultiplayerClient) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } return(true); }
public override void PostUpdate() { if (Main.dayTime && VolcanoCountdown == 0) { if (VolcanoCooldown > 0) { VolcanoCooldown--; } if (VolcanoCooldown <= 0 && Main.rand.NextBool(VolcanoChance) && !ExampleMod.exampleServerConfig.DisableVolcanos) { string key = "Mods.ExampleMod.VolcanoWarning"; Color messageColor = Color.Orange; if (Main.netMode == 2) // Server { NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor); } else if (Main.netMode == 0) // Single Player { Main.NewText(Language.GetTextValue(key), messageColor); } VolcanoCountdown = DefaultVolcanoCountdown; VolcanoCooldown = DefaultVolcanoCooldown; } } if (VolcanoCountdown > 0) { VolcanoCountdown--; if (VolcanoCountdown == 0) { VolcanoTremorTime = DefaultVolcanoTremorTime; // Since PostUpdate only happens in single and server, we need to inform the clients to shake if this is a server if (Main.netMode == 2) { var netMessage = mod.GetPacket(); netMessage.Write((byte)ExampleModMessageType.SetTremorTime); netMessage.Write(VolcanoTremorTime); netMessage.Send(); } for (int playerIndex = 0; playerIndex < 255; playerIndex++) { if (Main.player[playerIndex].active) { Player player = Main.player[playerIndex]; int speed = 12; float spawnX = Main.rand.Next(1000) - 500 + player.Center.X; float spawnY = -1000 + player.Center.Y; Vector2 baseSpawn = new Vector2(spawnX, spawnY); Vector2 baseVelocity = player.Center - baseSpawn; baseVelocity.Normalize(); baseVelocity = baseVelocity * speed; List <int> identities = new List <int>(); for (int i = 0; i < VolcanoProjectiles; i++) { Vector2 spawn = baseSpawn; spawn.X = spawn.X + i * 30 - VolcanoProjectiles * 15; Vector2 velocity = baseVelocity; velocity = baseVelocity.RotatedBy(MathHelper.ToRadians(-VolcanoAngleSpread / 2 + VolcanoAngleSpread * i / (float)VolcanoProjectiles)); velocity.X = velocity.X + 3 * Main.rand.NextFloat() - 1.5f; int projectile = Projectile.NewProjectile(spawn.X, spawn.Y, velocity.X, velocity.Y, Main.rand.Next(ProjectileID.MolotovFire, ProjectileID.MolotovFire3 + 1), 10, 10f, Main.myPlayer, 0f, 0f); Main.projectile[projectile].hostile = true; Main.projectile[projectile].Name = "Volcanic Rubble"; identities.Add(Main.projectile[projectile].identity); } if (Main.netMode == 2) { var netMessage = mod.GetPacket(); netMessage.Write((byte)ExampleModMessageType.VolcanicRubbleMultiplayerFix); netMessage.Write(identities.Count); for (int i = 0; i < identities.Count; i++) { netMessage.Write(identities[i]); } netMessage.Send(); } } } } } }
/// <summary> /// Hijacks the send data method. Only use if you absolutely know what you are doing. If any hooks return true, the message is not sent. /// </summary> public virtual bool HijackSendData(int whoAmI, int msgType, int remoteClient, int ignoreClient, NetworkText text, int number, float number2, float number3, float number4, int number5, int number6, int number7) { return(false); }
public override void HandlePacket(BinaryReader reader, int whoAmI) { ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte(); switch (msgType) { // This message sent by the server to initialize the Volcano Tremor on clients case ExampleModMessageType.SetTremorTime: int tremorTime = reader.ReadInt32(); ExampleWorld world = GetModWorld <ExampleWorld>(); world.VolcanoTremorTime = tremorTime; break; // This message sent by the server to initialize the Volcano Rubble. case ExampleModMessageType.VolcanicRubbleMultiplayerFix: int numberProjectiles = reader.ReadInt32(); for (int i = 0; i < numberProjectiles; i++) { int identity = reader.ReadInt32(); bool found = false; for (int j = 0; j < 1000; j++) { if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active) { Main.projectile[j].hostile = true; //Main.projectile[j].name = "Volcanic Rubble"; found = true; break; } } if (!found) { Logger.Error("Error: Projectile not found"); } } break; case ExampleModMessageType.PuritySpirit: if (Main.npc[reader.ReadInt32()].modNPC is PuritySpirit spirit && spirit.npc.active) { spirit.HandlePacket(reader); } break; case ExampleModMessageType.HeroLives: Player player = Main.player[reader.ReadInt32()]; int lives = reader.ReadInt32(); player.GetModPlayer <ExamplePlayer>().heroLives = lives; if (lives > 0) { NetworkText text; if (lives == 1) { text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name); } else { text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives); } NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25)); } break; // This message syncs ExamplePlayer.exampleLifeFruits case ExampleModMessageType.ExamplePlayerSyncPlayer: byte playernumber = reader.ReadByte(); ExamplePlayer examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>(); int exampleLifeFruits = reader.ReadInt32(); examplePlayer.exampleLifeFruits = exampleLifeFruits; examplePlayer.nonStopParty = reader.ReadBoolean(); // SyncPlayer will be called automatically, so there is no need to forward this data to other clients. break; case ExampleModMessageType.NonStopPartyChanged: playernumber = reader.ReadByte(); examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>(); examplePlayer.nonStopParty = reader.ReadBoolean(); // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients if (Main.netMode == NetmodeID.Server) { var packet = GetPacket(); packet.Write((byte)ExampleModMessageType.NonStopPartyChanged); packet.Write(playernumber); packet.Write(examplePlayer.nonStopParty); packet.Send(-1, playernumber); } break; case ExampleModMessageType.ExampleTeleportToStatue: if (Main.npc[reader.ReadByte()].modNPC is NPCs.ExamplePerson person && person.npc.active) { person.StatueTeleport(); } break; default: Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType); break; } }
public override void AI() { ++timer; Player owner = null; if (projectile.owner != -1) { owner = Main.player[projectile.owner]; } else if (projectile.owner == 255) { owner = Main.LocalPlayer; } var player = owner; projectile.alpha--; projectile.frameCounter++; projectile.rotation = 0f; if (projectile.frameCounter > 2) { projectile.frame++; projectile.frameCounter = 0; } if (projectile.frame >= 4) { projectile.frame = 0; } foreach (var npc in Main.npc) { if (!npc.friendly && !npc.boss && npc.active && !npc.dontTakeDamage && npc.lifeMax > 5 && !npc.immortal) { if (projectile.Hitbox.Intersects(npc.Hitbox)) { npc.velocity.Y -= 0.65f; if (timer % 15 == 0) { var damage = 10f * player.meleeDamage; var knockBack = 5f; var direction = projectile.direction; if (projectile.velocity.X < 0f) { direction = -1; } if (projectile.velocity.X > 0f) { direction = 1; } npc.StrikeNPC((int)damage, knockBack, direction, false, false, false); if (Main.netMode != 0) { NetMessage.SendData(28, -1, -1, NetworkText.FromLiteral(""), npc.whoAmI, (float)1, knockBack, (float)direction, (int)damage); } } } } } if (projectile.Hitbox.Intersects(player.Hitbox)) { player.velocity.Y -= 0.95f; if (Main.time % 15 == 0) { player.controlHook = false; player.controlUseItem = false; for (var i = 0; i < 1000; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].aiStyle == 7) { Main.projectile[i].Kill(); } } } if (Main.time % 15 == 0) { var k = Main.rand.Next(1, 2); player.statLife += k; player.HealEffect(k); NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, projectile.owner, k); var i = Main.rand.Next(1, 2); player.statMana += i; player.ManaEffect(i); } } }
private void NetMessage_greetPlayer(On.Terraria.NetMessage.orig_greetPlayer orig, int plr) { NetPacket packet = Terraria.GameContent.NetModules.NetTextModule.SerializeServerMessage(NetworkText.FromLiteral("This chat is powered by TerrariaChatRelay"), Color.LawnGreen, byte.MaxValue); NetManager.Instance.SendToClient(packet, plr); orig(plr); }
public override void ProcessTriggers(TriggersSet triggersSet) { if (AIDistort.AIScrambleHotKey.JustPressed && hotkeyCooldown == 0) { if (Main.netMode != NetmodeID.MultiplayerClient) { #region Hotkey if (!GetInstance <AIScramblerConfig>().AIScrambleBoolean) { GetInstance <AIScramblerConfig>().AIScrambleBoolean = true; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("[c/0AFF00:AI Scramble is ON!]"); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText("[c/0AFF00:AI Scramble is ON!]"); } if (GetInstance <AIScramblerConfig>().HotkeyCooldown) { hotkeyCooldown = 600; } } else if (GetInstance <AIScramblerConfig>().AIScrambleBoolean) { GetInstance <AIScramblerConfig>().AIScrambleBoolean = false; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("[c/FF0000:AI Scramble is OFF!]"); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText("[c/FF0000:AI Scramble is OFF!]"); } if (GetInstance <AIScramblerConfig>().HotkeyCooldown) { hotkeyCooldown = 600; } } #endregion } else if (Main.netMode == NetmodeID.MultiplayerClient && GetInstance <AIScramblerConfig>().ClientHotkeyPermission) { #region Hotkey if (!GetInstance <AIScramblerConfig>().AIScrambleBoolean) { GetInstance <AIScramblerConfig>().AIScrambleBoolean = true; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("[c/0AFF00:AI Scramble is ON!]"); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText("[c/0AFF00:AI Scramble is ON!]"); } hotkeyCooldown = 600; } else if (GetInstance <AIScramblerConfig>().AIScrambleBoolean) { GetInstance <AIScramblerConfig>().AIScrambleBoolean = false; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("[c/FF0000:AI Scramble is OFF!]"); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText("[c/FF0000:AI Scramble is OFF!]"); } hotkeyCooldown = 600; } #endregion } } #region Randomize Player Hotkey if (AIDistort.PlayerRandomize.JustPressed && !GetInstance <PlayerRandomizeConfig>().NoRandom&& !reset && !rainbow) { ItemLoader.UpdateVanitySet(player); if (GetInstance <PlayerRandomizeConfig>().RandomizeEyeColor) { player.eyeColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizeSkinColor) { player.skinColor = randomizeColor(); if (GetInstance <PlayerRandomizeConfig>().SkinChangeType) { float num13 = (float)Main.rand.Next(60, 120) * 0.01f; if (num13 > 1f) { num13 = 1f; } player.skinColor.R = (byte)((float)Main.rand.Next(240, 255) * num13); player.skinColor.G = (byte)((float)Main.rand.Next(110, 140) * num13); player.skinColor.B = (byte)((float)Main.rand.Next(75, 110) * num13); } } if (GetInstance <PlayerRandomizeConfig>().RandomizeShoeColor) { player.shoeColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizePantsColor) { player.pantsColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizeShirtColor) { player.shirtColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizeUndershirtColor) { player.underShirtColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizeHairColor) { player.hairColor = randomizeColor(); } if (GetInstance <PlayerRandomizeConfig>().RandomizeHair) { if (player.name == "The Chosen One") { player.hair = Main.rand.Next(0, 134); } else { if (NPC.savedStylist) { player.hair = Main.rand.Next(0, 124); } else if (NPC.savedStylist && NPC.downedMartians) { player.hair = Main.rand.Next(0, 134); } else if (NPC.savedStylist && NPC.downedMartians && NPC.downedMoonlord) { player.hair = Main.rand.Next(0, 135); } else { player.hair = Main.rand.Next(0, 52); } } } if (GetInstance <PlayerRandomizeConfig>().RandomizeClothes) { CycleClothingStyle(player); } if (GetInstance <PlayerRandomizeConfig>().RandomizeGender) { int gender = Main.rand.Next(2); if (gender == 0) { player.Male = true; if (GetInstance <PlayerRandomizeConfig>().IndicatorAGender) { Main.PlaySound(SoundID.PlayerHit, player.position); } if (GetInstance <PlayerRandomizeConfig>().IndicatorVGender) { for (int i = 0; i < 25; i++) { Vector2 position = player.Center + Vector2.UnitX.RotatedBy(MathHelper.ToRadians(360f / 25 * i)); Dust dust = Dust.NewDustPerfect(position, DustID.BlueCrystalShard); dust.noGravity = true; dust.velocity = Vector2.Normalize(dust.position - player.Center) * 4; dust.noLight = false; dust.fadeIn = 1f; } } } if (gender == 1) { player.Male = false; if (GetInstance <PlayerRandomizeConfig>().IndicatorAGender) { Main.PlaySound(SoundID.FemaleHit, player.position); } if (GetInstance <PlayerRandomizeConfig>().IndicatorVGender) { for (int i = 0; i < 25; i++) { Vector2 position = player.Center + Vector2.UnitX.RotatedBy(MathHelper.ToRadians(360f / 25 * i)); Dust dust = Dust.NewDustPerfect(position, DustID.PinkCrystalShard); dust.noGravity = true; dust.velocity = Vector2.Normalize(dust.position - player.Center) * 4; dust.noLight = false; dust.fadeIn = 1f; } } } } } #endregion if (AIDistort.ButcherHotKey.JustReleased && !AIWorld.butcher) { AIWorld.butcher = true; } }
public override void HandlePacket(BinaryReader reader, int whoAmI) { byte messageType = reader.ReadByte(); switch (messageType) { // Regal statue case 1: FargoWorld.CurrentSpawnRateTile[whoAmI] = reader.ReadBoolean(); break; // Abominationn clear events case 2: if (Main.netMode == NetmodeID.Server) { bool eventOccurring = false; if (ClearEvents(ref eventOccurring)) { NetMessage.SendData(MessageID.WorldData); NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("The event has been cancelled!"), new Color(175, 75, 255)); } } break; // Angler reset case 3: if (Main.netMode == NetmodeID.Server) { Main.AnglerQuestSwap(); } break; // Sync npc max life case 4: { int n = reader.ReadInt32(); int lifeMax = reader.ReadInt32(); if (Main.netMode == NetmodeID.MultiplayerClient) { Main.npc[n].lifeMax = lifeMax; } } break; // Kill super dummies case 5: if (Main.netMode == NetmodeID.Server) { for (int i = 0; i < Main.maxNPCs; i++) { if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType <NPCs.SuperDummy>()) { NPC npc = Main.npc[i]; npc.life = 0; npc.HitEffect(); Main.npc[i].StrikeNPCNoInteraction(int.MaxValue, 0, 0, false, false, false); if (Main.netMode == NetmodeID.Server) { NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, i); } } } } break; default: break; } }
public static void UpdateTravelingMerchant() { NPC traveler = FindNPC(NPCType <ExampleTravelingMerchant>()); // Find an Explorer if there's one spawned in the world if (traveler != null && (!Main.dayTime || Main.time >= despawnTime) && !IsNpcOnscreen(traveler.Center)) // If it's past the despawn time and the NPC isn't onscreen { // Here we despawn the NPC and send a message stating that the NPC has despawned if (Main.netMode == NetmodeID.SinglePlayer) { Main.NewText(traveler.FullName + " has departed!", 50, 125, 255); } else { NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(traveler.FullName + " has departed!"), new Color(50, 125, 255)); } traveler.active = false; traveler.netSkip = -1; traveler.life = 0; traveler = null; } // Main.time is set to 0 each morning, and only for one update. Sundialling will never skip past time 0 so this is the place for 'on new day' code if (Main.dayTime && Main.time == 0) { // insert code here to change the spawn chance based on other conditions (say, npcs which have arrived, or milestones the player has passed) // You can also add a day counter here to prevent the merchant from possibly spawning multiple days in a row. // NPC won't spawn today if it stayed all night if (traveler == null && Main.rand.NextBool(4)) // 4 = 25% Chance // Here we can make it so the NPC doesnt spawn at the EXACT same time every time it does spawn { spawnTime = GetRandomSpawnTime(5400, 8100); // minTime = 6:00am, maxTime = 7:30am } else { spawnTime = double.MaxValue; // no spawn today } } // Spawn the traveler if the spawn conditions are met (time of day, no events, no sundial) if (traveler == null && CanSpawnNow()) { int newTraveler = NPC.NewNPC(Main.spawnTileX * 16, Main.spawnTileY * 16, NPCType <ExampleTravelingMerchant>(), 1); // Spawning at the world spawn traveler = Main.npc[newTraveler]; traveler.homeless = true; traveler.direction = Main.spawnTileX >= WorldGen.bestX ? -1 : 1; traveler.netUpdate = true; shopItems = CreateNewShop(); // Prevents the traveler from spawning again the same day spawnTime = double.MaxValue; // Annouce that the traveler has spawned in! if (Main.netMode == NetmodeID.SinglePlayer) { Main.NewText(Language.GetTextValue("Announcement.HasArrived", traveler.FullName), 50, 125, 255); } else { NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasArrived", traveler.GetFullNetName()), new Color(50, 125, 255)); } } }
public override void AI() { // Slowly remove alpha as it is present if (projectile.alpha > 0) { projectile.alpha -= alphaReduction; } // If alpha gets lower than 0, set it to 0 if (projectile.alpha < 0) { projectile.alpha = 0; } // If ai0 is 0f, run this code. This is the 'movement' code for the javelin as long as it isn't sticking to a target if (!isStickingToTarget) { targetWhoAmI += 1f; // For a little while, the javelin will travel with the same speed, but after this, the javelin drops velocity very quickly. if (targetWhoAmI >= maxTicks) { // Change these multiplication factors to alter the javelin's movement change after reaching maxTicks float velXmult = 1f; // x velocity factor, every AI update the x velocity will be 98% of the original speed float velYmult = 1f; // y velocity factor, every AI update the y velocity will be be 0.35f bigger of the original speed, causing the javelin to drop to the ground targetWhoAmI = maxTicks; // set ai1 to maxTicks continuously projectile.velocity.X = projectile.velocity.X * velXmult; projectile.velocity.Y = projectile.velocity.Y + velYmult; } // Make sure to set the rotation accordingly to the velocity, and add some to work around the sprite's rotation projectile.rotation = projectile.velocity.ToRotation() + MathHelper.ToRadians(90f); // Please notice the MathHelper usage, offset the rotation by 90 degrees (to radians because rotation uses radians) because the sprite's rotation is not aligned! } // This code is ran when the javelin is sticking to a target if (isStickingToTarget) { // These 2 could probably be moved to the ModifyNPCHit hook, but in vanilla they are present in the AI projectile.ignoreWater = true; // Make sure the projectile ignores water projectile.tileCollide = false; // Make sure the projectile doesn't collide with tiles anymore int aiFactor = 15; // Change this factor to change the 'lifetime' of this sticking javelin bool killProj = false; // if true, kill projectile at the end bool hitEffect = false; // if true, perform a hit effect projectile.localAI[0] += 1f; // Every 30 ticks, the javelin will perform a hit effect hitEffect = projectile.localAI[0] % 30f == 0f; int projTargetIndex = (int)targetWhoAmI; Main.npc[projTargetIndex].AddBuff(169, 60, false); if (projectile.localAI[0] >= (float)(60 * aiFactor) || // If it's time for this javelin to die, kill it (projTargetIndex < 0 || projTargetIndex >= 200)) // If the index is past its limits, kill it { killProj = true; } else if (Main.npc[projTargetIndex].active && !Main.npc[projTargetIndex].dontTakeDamage) // If the target is active and can take damage { // Set the projectile's position relative to the target's center projectile.Center = Main.npc[projTargetIndex].Center - projectile.velocity * 2f; projectile.gfxOffY = Main.npc[projTargetIndex].gfxOffY; if (hitEffect) // Perform a hit effect here { var direction = Main.npc[projTargetIndex].direction; if (Main.npc[projTargetIndex].velocity.X < 0f) { direction = -1; } if (Main.npc[projTargetIndex].velocity.X > 0f) { direction = 1; } Main.npc[projTargetIndex].StrikeNPC((int)11, 1f, direction, false, false, false); if (Main.netMode != 0) { NetMessage.SendData(28, -1, -1, NetworkText.FromLiteral(""), Main.npc[projTargetIndex].whoAmI, (float)1, 1f, (float)direction, 11); } } } else // Otherwise, kill the projectile { killProj = true; } if (killProj) // Kill the projectile { projectile.Kill(); } } }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == NetmodeID.MultiplayerClient) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } return(true); }
public void ProcessIncomingMessage(string text, byte clientId) { ChatHelper.SendChatMessageToClient(NetworkText.FromLiteral(string.Join(", ", ((IEnumerable <Player>)Main.player).Where <Player>((Func <Player, bool>)(player => player.active)).Select <Player, string>((Func <Player, string>)(player => player.name)))), ListPlayersCommand.RESPONSE_COLOR, (int)clientId); }
public override void RightClick(int i, int j) { Player player = Main.player[Main.myPlayer]; Tile tile = Main.tile[i, j]; // tile.frameX != 72 tile.frameX != 90 if (tile.frameX != 36) { Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(11, -1, -1, 1); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(12, -1, -1, 1); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); player.editedChestName = false; } if (Main.netMode == 1) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(11, -1, -1, 1); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(11, -1, -1, 1); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? 10 : 12, -1, -1, 1); } Recipe.FindRecipes(); } } } }
private static void ApplyInventory(TSPlayer player, IReadOnlyList <NetItem> inventory) { int index; var ssc = Main.ServerSideCharacter; if (!ssc) { Main.ServerSideCharacter = true; NetMessage.SendData((int)PacketTypes.WorldInfo, player.Index, -1, NetworkText.Empty); } for (var i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventoryIndex.Item2) { player.TPlayer.inventory[i].netDefaults(inventory[i].NetId); if (player.TPlayer.inventory[i].netID != 0) { player.TPlayer.inventory[i].prefix = inventory[i].PrefixId; player.TPlayer.inventory[i].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.inventory[i].Name), player.Index, i, player.TPlayer.inventory[i].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.inventory[i].Name), player.Index, i, player.TPlayer.inventory[i].prefix); } else if (i < NetItem.ArmorIndex.Item2) { index = i - NetItem.ArmorIndex.Item1; player.TPlayer.armor[index].netDefaults(inventory[i].NetId); if (player.TPlayer.armor[index].netID != 0) { player.TPlayer.armor[index].prefix = inventory[i].PrefixId; player.TPlayer.armor[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, i, player.TPlayer.armor[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, i, player.TPlayer.armor[index].prefix); } else if (i < NetItem.DyeIndex.Item2) { index = i - NetItem.DyeIndex.Item1; player.TPlayer.dye[index].netDefaults(inventory[i].NetId); if (player.TPlayer.dye[index].netID != 0) { player.TPlayer.dye[index].prefix = inventory[i].PrefixId; player.TPlayer.dye[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, i, player.TPlayer.dye[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, i, player.TPlayer.dye[index].prefix); } else if (i < NetItem.MiscEquipIndex.Item2) { index = i - NetItem.MiscEquipIndex.Item1; player.TPlayer.miscEquips[index].netDefaults(inventory[i].NetId); if (player.TPlayer.miscEquips[index].netID != 0) { player.TPlayer.miscEquips[index].prefix = inventory[i].PrefixId; player.TPlayer.miscEquips[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, i, player.TPlayer.miscEquips[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, i, player.TPlayer.miscEquips[index].prefix); } else if (i < NetItem.MiscDyeIndex.Item2) { index = i - NetItem.MiscDyeIndex.Item1; player.TPlayer.miscDyes[index].netDefaults(inventory[i].NetId); if (player.TPlayer.miscDyes[index].netID != 0) { player.TPlayer.miscDyes[index].prefix = inventory[i].PrefixId; player.TPlayer.miscDyes[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, i, player.TPlayer.miscDyes[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, i, player.TPlayer.miscDyes[index].prefix); } else if (i < NetItem.PiggyIndex.Item2) { index = i - NetItem.PiggyIndex.Item1; player.TPlayer.bank.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank.item[index].netID != 0) { player.TPlayer.bank.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank.item[index].Name), player.Index, i, player.TPlayer.bank.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank.item[index].Name), player.Index, i, player.TPlayer.bank.item[index].prefix); } else if (i < NetItem.SafeIndex.Item2) { index = i - NetItem.SafeIndex.Item1; player.TPlayer.bank2.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank2.item[index].netID != 0) { player.TPlayer.bank2.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank2.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank2.item[index].Name), player.Index, i, player.TPlayer.bank2.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank2.item[index].Name), player.Index, i, player.TPlayer.bank2.item[index].prefix); } else if (i < NetItem.TrashIndex.Item2) { player.TPlayer.trashItem.netDefaults(inventory[i].NetId); if (player.TPlayer.trashItem.netID != 0) { player.TPlayer.trashItem.prefix = inventory[i].PrefixId; player.TPlayer.trashItem.stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.trashItem.Name), player.Index, i, player.TPlayer.trashItem.prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.trashItem.Name), player.Index, i, player.TPlayer.trashItem.prefix); } else if (i < NetItem.ForgeIndex.Item2) { index = i - NetItem.ForgeIndex.Item1; player.TPlayer.bank3.item[index].netDefaults(inventory[i].NetId); if (player.TPlayer.bank3.item[index].netID != 0) { player.TPlayer.bank3.item[index].prefix = inventory[i].PrefixId; player.TPlayer.bank3.item[index].stack = inventory[i].Stack; } NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.bank3.item[index].Name), player.Index, i, player.TPlayer.bank3.item[index].prefix); NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.bank3.item[index].Name), player.Index, i, player.TPlayer.bank3.item[index].prefix); } } if (!ssc) { Main.ServerSideCharacter = false; NetMessage.SendData((int)PacketTypes.WorldInfo, player.Index, -1, NetworkText.Empty); } }
public static void SpawnOnPlayerButNoTextAndReturnValue(int plr, int Type, out int npc) { npc = -1; if (Main.netMode == 1) { return; } if (Type == 262 && NPC.AnyNPCs(262)) { return; } if (Type == 245) { if (NPC.AnyNPCs(245)) { return; } try { int num = (int)Main.player[plr].Center.X / 16; int num2 = (int)Main.player[plr].Center.Y / 16; int num3 = 0; int num4 = 0; for (int i = num - 20; i < num + 20; i++) { for (int j = num2 - 20; j < num2 + 20; j++) { if (Main.tile[i, j].active() && Main.tile[i, j].type == 237 && Main.tile[i, j].frameX == 18 && Main.tile[i, j].frameY == 0) { num3 = i; num4 = j; } } } if (num3 > 0 && num4 > 0) { int num5 = num4 - 15; int num6 = num4 - 15; for (int k = num4; k > num4 - 100; k--) { if (WorldGen.SolidTile(num3, k)) { num5 = k; break; } } for (int l = num4; l < num4 + 100; l++) { if (WorldGen.SolidTile(num3, l)) { num6 = l; break; } } num4 = (num5 + num5 + num6) / 3; int num7 = NPC.NewNPC(num3 * 16 + 8, num4 * 16, 245, 100, 0f, 0f, 0f, 0f, 255); npc = num7; Main.npc[num7].target = plr; string typeName = Main.npc[num7].TypeName; } } catch { } return; } else if (Type == 370) { Player player = Main.player[plr]; if (!player.active || player.dead) { return; } int m = 0; while (m < 1000) { Projectile projectile = Main.projectile[m]; if (projectile.active && projectile.bobber && projectile.owner == plr) { int num8 = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y + 100, 370, 0, 0f, 0f, 0f, 0f, 255); string typeName2 = Main.npc[num8].TypeName; if (Main.netMode == 0) { Main.NewText(Language.GetTextValue("Announcement.HasAwoken", typeName2), 175, 75, 255, false); return; } if (Main.netMode == 2) { NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[] { Main.npc[num8].GetTypeNetName() }), new Color(175, 75, 255), -1); return; } break; } else { m++; } } return; } else { if (Type != 398) { bool flag = false; int num9 = 0; int num10 = 0; int num11 = (int)(Main.player[plr].position.X / 16f) - Assist.spawnRangeX * 2; int num12 = (int)(Main.player[plr].position.X / 16f) + Assist.spawnRangeX * 2; int num13 = (int)(Main.player[plr].position.Y / 16f) - Assist.spawnRangeY * 2; int num14 = (int)(Main.player[plr].position.Y / 16f) + Assist.spawnRangeY * 2; int num15 = (int)(Main.player[plr].position.X / 16f) - NPC.safeRangeX; int num16 = (int)(Main.player[plr].position.X / 16f) + NPC.safeRangeX; int num17 = (int)(Main.player[plr].position.Y / 16f) - NPC.safeRangeY; int num18 = (int)(Main.player[plr].position.Y / 16f) + NPC.safeRangeY; if (num11 < 0) { num11 = 0; } if (num12 > Main.maxTilesX) { num12 = Main.maxTilesX; } if (num13 < 0) { num13 = 0; } if (num14 > Main.maxTilesY) { num14 = Main.maxTilesY; } for (int n = 0; n < 1000; n++) { int num19 = 0; while (num19 < 100) { int num20 = Main.rand.Next(num11, num12); int num21 = Main.rand.Next(num13, num14); if (Main.tile[num20, num21].nactive() && Main.tileSolid[(int)Main.tile[num20, num21].type]) { goto IL_730; } if ((!Main.wallHouse[(int)Main.tile[num20, num21].wall] || n >= 999) && (Type != 50 || n >= 500 || Main.tile[num21, num21].wall <= 0)) { int num22 = num21; while (num22 < Main.maxTilesY) { if (Main.tile[num20, num22].nactive() && Main.tileSolid[(int)Main.tile[num20, num22].type]) { if (num20 < num15 || num20 > num16 || num22 < num17 || num22 > num18 || n == 999) { ushort num23 = Main.tile[num20, num22].type; num9 = num20; num10 = num22; flag = true; break; } break; } else { num22++; } } if (flag && Type == 50 && n < 900) { int num24 = 20; if (!Collision.CanHit(new Vector2((float)num9, (float)(num10 - 1)) * 16f, 16, 16, new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16) || !Collision.CanHit(new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16, Main.player[plr].Center, 0, 0)) { num9 = 0; num10 = 0; flag = false; } } if (!flag || n >= 999) { goto IL_730; } int num25 = num9 - Assist.spawnSpaceX / 2; int num26 = num9 + Assist.spawnSpaceX / 2; int num27 = num10 - Assist.spawnSpaceY; int num28 = num10; if (num25 < 0) { flag = false; } if (num26 > Main.maxTilesX) { flag = false; } if (num27 < 0) { flag = false; } if (num28 > Main.maxTilesY) { flag = false; } if (flag) { for (int num29 = num25; num29 < num26; num29++) { for (int num30 = num27; num30 < num28; num30++) { if (Main.tile[num29, num30].nactive() && Main.tileSolid[(int)Main.tile[num29, num30].type]) { flag = false; break; } } } goto IL_730; } goto IL_730; } IL_728: num19++; continue; IL_730: if (!flag && !flag) { goto IL_728; } break; } if (flag && n < 999) { Rectangle rectangle = new Rectangle(num9 * 16, num10 * 16, 16, 16); for (int num31 = 0; num31 < 255; num31++) { if (Main.player[num31].active) { Rectangle rectangle2 = new Rectangle((int)(Main.player[num31].position.X + (float)(Main.player[num31].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[num31].position.Y + (float)(Main.player[num31].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); if (rectangle.Intersects(rectangle2)) { flag = false; } } } } if (flag) { break; } } if (flag) { int num32 = NPC.NewNPC(num9 * 16 + 8, num10 * 16, Type, 1, 0f, 0f, 0f, 0f, 255); npc = num32; if (num32 == 200) { return; } Main.npc[num32].target = plr; Main.npc[num32].timeLeft *= 20; string typeName3 = Main.npc[num32].TypeName; if (Main.netMode == 2 && num32 < 200) { NetMessage.SendData(23, -1, -1, null, num32, 0f, 0f, 0f, 0, 0, 0); } if (Type == 125) { if (Main.netMode == 0) { Main.NewText(Lang.misc[48].Value, 175, 75, 255, false); return; } if (Main.netMode == 2) { NetMessage.BroadcastChatMessage(Lang.misc[48].ToNetworkText(), new Color(175, 75, 255), -1); return; } } else if (Type != 82 && Type != 126 && Type != 50 && Type != 398 && Type != 551) { } } return; } Player player2 = Main.player[plr]; npc = NPC.NewNPC((int)player2.Center.X, (int)player2.Center.Y - 150, Type, 0, 0f, 0f, 0f, 0f, 255); return; } }
public override bool NewRightClick(int i, int j) { Player player = Main.LocalPlayer; Tile tile = Main.tile[i, j]; Main.mouseRightRelease = false; int left = i; int top = j; if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } if (player.sign >= 0) { Main.PlaySound(SoundID.MenuClose); player.sign = -1; Main.editSign = false; Main.npcChatText = ""; } if (Main.editChest) { Main.PlaySound(SoundID.MenuTick); Main.editChest = false; Main.npcChatText = ""; } if (player.editedChestName) { NetMessage.SendData(33, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f); player.editedChestName = false; } bool isLocked = IsLockedChest(left, top); Main.NewText(isLocked); if (Main.netMode == 1 && !isLocked) { if (left == player.chestX && top == player.chestY && player.chest >= 0) { player.chest = -1; Recipe.FindRecipes(); Main.PlaySound(SoundID.MenuClose); } else { NetMessage.SendData(31, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); Main.stackSplit = 600; } } else { if (isLocked) { int key = ItemType <Items.Misc.TMMCChestKey>(); if (player.ConsumeItem(key) && Chest.Unlock(left, top)) { if (Main.netMode == 1) { NetMessage.SendData(MessageID.Unlock, -1, -1, null, player.whoAmI, 1f, (float)left, (float)top); } } } else { int chest = Chest.FindChest(left, top); if (chest >= 0) { Main.stackSplit = 600; if (chest == player.chest) { player.chest = -1; Main.PlaySound(SoundID.MenuClose); } else { player.chest = chest; Main.playerInventory = true; Main.recBigList = false; player.chestX = left; player.chestY = top; Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); } Recipe.FindRecipes(); } } } return(true); }
public override void HandlePacket(BinaryReader reader, int whoAmI) { ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte(); switch (msgType) { // This message sent by the server to initialize the Volcano Tremor on clients case ExampleModMessageType.SetTremorTime: int tremorTime = reader.ReadInt32(); ExampleWorld world = GetModWorld <ExampleWorld>(); world.VolcanoTremorTime = tremorTime; break; // This message sent by the server to initialize the Volcano Rubble. case ExampleModMessageType.VolcanicRubbleMultiplayerFix: int numberProjectiles = reader.ReadInt32(); for (int i = 0; i < numberProjectiles; i++) { int identity = reader.ReadInt32(); bool found = false; for (int j = 0; j < 1000; j++) { if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active) { Main.projectile[j].hostile = true; //Main.projectile[j].name = "Volcanic Rubble"; found = true; break; } } if (!found) { ErrorLogger.Log("Error: Projectile not found"); } } break; case ExampleModMessageType.PuritySpirit: PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit; if (spirit != null && spirit.npc.active) { spirit.HandlePacket(reader); } break; case ExampleModMessageType.HeroLives: Player player = Main.player[reader.ReadInt32()]; int lives = reader.ReadInt32(); player.GetModPlayer <ExamplePlayer>(this).heroLives = lives; if (lives > 0) { NetworkText text; if (lives == 1) { text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name); } else { text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives); } NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25)); } break; // This message syncs ExamplePlayer.exampleLifeFruits case ExampleModMessageType.ExampleLifeFruits: byte playernumber = reader.ReadByte(); Player lifeFruitsPlayer = Main.player[playernumber]; int exampleLifeFruits = reader.ReadInt32(); lifeFruitsPlayer.GetModPlayer <ExamplePlayer>().exampleLifeFruits = exampleLifeFruits; break; default: ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType); break; } }