Beispiel #1
0
        public void ProcessIncomingMessage(string text, byte clientId)
        {
            int   team  = Main.player[(int)clientId].team;
            Color color = Main.teamColor[team];

            if (team == 0)
            {
                this.SendNoTeamError(clientId);
            }
            else
            {
                if (text == "")
                {
                    return;
                }
                for (int playerId = 0; playerId < (int)byte.MaxValue; ++playerId)
                {
                    if (Main.player[playerId].team == team)
                    {
                        ChatHelper.SendChatMessageToClientAs(clientId, NetworkText.FromLiteral(text), color, playerId);
                    }
                }
            }
        }
Beispiel #2
0
        public override void PostAI()
        {
            if (npc.timeLeft == 1 && Alerted)
            {
                DBTWorld.DBTWorld.friezaShipTriggered = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }

                if (Main.netMode != 2)
                {
                    Main.NewText("If I tell lord frieza of this then I'll surely get promoted...", Color.Red);
                    Main.NewText("The Frieza Force is coming...", Color.OrangeRed);
                }
                else
                {
                    NetworkText text2 = NetworkText.FromLiteral("If I tell lord frieza of this then I'll surely get promoted...");
                    NetworkText text3 = NetworkText.FromLiteral("The Frieza Force is coming...");
                    NetMessage.BroadcastChatMessage(text2, Color.Red);
                    NetMessage.BroadcastChatMessage(text3, Color.OrangeRed);
                }
            }
        }
Beispiel #3
0
        //Text for messages and syncing
        public static void CustomInvasionWarning()
        {
            String text = "";

            if (Main.invasionX == (double)Main.spawnTileX)
            {
                text = "The thousand heartless have reached the town!";
            }
            if (Main.invasionSize <= 0)
            {
                text = "The thousand heartless have been defeated.";
                KingdomWorld.downedCustomInvasion = true;
            }
            if (Main.netMode == NetmodeID.SinglePlayer)
            {
                Main.NewText(text, 175, 75, 255);
                return;
            }
            if (Main.netMode == 2)
            {
                //Sync with net
                NetMessage.SendData(MessageID.ChatText, -1, -1, NetworkText.FromLiteral(text), 255, 175f, 75f, 255f, 0, 0, 0);
            }
        }
Beispiel #4
0
        public static void CustomInvasionWarning()
        {
            String text = "";

            if (Main.invasionX == Main.spawnTileX)
            {
                // text = "Hostile trees spring up from the ground!";
            }
            if (Main.invasionSize <= 0)
            {
                text = "The woodland terrors retreat to their roots!";
                TGEMWorld.GentBool      = false;
                TGEMWorld.MagnoliacBool = false;
            }
            if (Main.netMode == 0)
            {
                Main.NewText(text, 175, 75, 255, false);
                return;
            }
            if (Main.netMode == 2)
            {
                NetMessage.SendData(25, -1, -1, NetworkText.FromLiteral(text), 255, 175f, 75f, 255f, 0, 0, 0);
            }
        }
        public override bool UseItem(Player player)
        {
            FargoPlayer modPlayer = player.GetFargoPlayer();

            modPlayer.BattleCry = !modPlayer.BattleCry;

            string text = "Spawn rates " + (modPlayer.BattleCry ? "increased!" : "decreased!");

            if (Main.netMode == NetmodeID.SinglePlayer)
            {
                Main.NewText(text, new Color(175, 75, 255));
            }
            else if (Main.netMode == NetmodeID.Server)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(text), new Color(175, 75, 255));
            }

            if (modPlayer.BattleCry && !Main.dedServ)
            {
                Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Horn").WithVolume(1f).WithPitchVariance(.5f), player.position);
            }

            return(true);
        }
Beispiel #6
0
        //set xp of player
        public void SetExp(double xp)
        {
            /*~~~~~~~~~~~~~~~~~~~~~~Single Player and Server Only~~~~~~~~~~~~~~~~~~~~~~*/
            if (Main.netMode == 1)
            {
                return;
            }

            //in the rare case that the player is not synced with the server, don't do anything
            double priorExp = GetExp();

            if (Main.netMode == 2 && priorExp == -1)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Failed to change the experience value for player #" + player.whoAmI + ":" + player.name + " (player not yet synced)"), ExperienceAndClasses.MESSAGE_COLOUR_RED);
                return;
            }

            int priorLevel = Methods.Experience.GetLevel(GetExp());

            experience = Math.Floor(xp);
            LimitExp();
            LevelUp(priorLevel);

            //if server, mark for update
            if (Main.netMode == 2 && !MyWorld.clientNeedsExpUpdate[player.whoAmI])
            {
                MyWorld.clientNeedsExpUpdate[player.whoAmI] = true;
                MyWorld.clientNeedsExpUpdate_who[MyWorld.clientNeedsExpUpdate_counter] = player.whoAmI;
                MyWorld.clientNeedsExpUpdate_counter++;
            }
            //if singleplayer, it's already done so display
            else if (Main.netMode == 0)
            {
                ExpMsg(experience - priorExp);
            }
        }
Beispiel #7
0
        //------------------------------------------------------//
        //--------------------BASE NET CLASS--------------------//
        //------------------------------------------------------//
        // Contains methods relating to netmessages.            //
        //------------------------------------------------------//
        //  Author(s): Grox the Great                           //
        //------------------------------------------------------//

        public static void SendData(int dataType, int dataA, int dataB, string text, int playerID, float dataC, float dataD, float dataE, int clientType)
        {
            NetMessage.SendData(dataType, dataA, dataB, NetworkText.FromLiteral(text), playerID, dataC, dataD, dataE, clientType);
        }
        public static void OpenChestUI(int i, int j)
        {
            Player player = Main.player[Main.myPlayer];
            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(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, NetworkText.FromLiteral(""), 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(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();
                }
            }
        }
Beispiel #9
0
        public static NetworkText CreateDeathMessage(string deadPlayerName, int plr = -1, int npc = -1, int proj = -1, int other = -1, int projType = 0, int plrItemType = 0)
        {
            NetworkText networkText1 = NetworkText.Empty;
            NetworkText networkText2 = NetworkText.Empty;
            NetworkText networkText3 = NetworkText.Empty;
            NetworkText networkText4 = NetworkText.Empty;

            if (proj >= 0)
            {
                networkText1 = NetworkText.FromKey(Lang.GetProjectileName(projType).Key);
            }
            if (npc >= 0)
            {
                networkText2 = Main.npc[npc].GetGivenOrTypeNetName();
            }
            if (plr >= 0 && plr < (int)byte.MaxValue)
            {
                networkText3 = NetworkText.FromLiteral(Main.player[plr].name);
            }
            if (plrItemType >= 0)
            {
                networkText4 = NetworkText.FromKey(Lang.GetItemName(plrItemType).Key);
            }
            bool        flag1        = networkText1 != NetworkText.Empty;
            bool        flag2        = plr >= 0 && plr < (int)byte.MaxValue;
            bool        flag3        = networkText2 != NetworkText.Empty;
            NetworkText networkText5 = NetworkText.Empty;
            NetworkText empty        = NetworkText.Empty;
            NetworkText networkText6 = NetworkText.FromKey(Language.RandomFromCategory("DeathTextGeneric", (UnifiedRandom)null).Key, (object)deadPlayerName, (object)Main.worldName);

            if (flag2)
            {
                networkText5 = NetworkText.FromKey("DeathSource.Player", (object)networkText6, (object)networkText3, (object)(flag1 ? networkText1 : networkText4));
            }
            else if (flag3)
            {
                networkText5 = NetworkText.FromKey("DeathSource.NPC", (object)networkText6, (object)networkText2);
            }
            else if (flag1)
            {
                networkText5 = NetworkText.FromKey("DeathSource.Projectile", (object)networkText6, (object)networkText1);
            }
            else if (other >= 0)
            {
                if (other == 0)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Fell_" + (object)(Main.rand.Next(2) + 1), (object)deadPlayerName);
                }
                else if (other == 1)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Drowned_" + (object)(Main.rand.Next(4) + 1), (object)deadPlayerName);
                }
                else if (other == 2)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Lava_" + (object)(Main.rand.Next(4) + 1), (object)deadPlayerName);
                }
                else if (other == 3)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Default", (object)networkText6);
                }
                else if (other == 4)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Slain", (object)deadPlayerName);
                }
                else if (other == 5)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Petrified_" + (object)(Main.rand.Next(4) + 1), (object)deadPlayerName);
                }
                else if (other == 6)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Stabbed", (object)deadPlayerName);
                }
                else if (other == 7)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Suffocated", (object)deadPlayerName);
                }
                else if (other == 8)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Burned", (object)deadPlayerName);
                }
                else if (other == 9)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Poisoned", (object)deadPlayerName);
                }
                else if (other == 10)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Electrocuted", (object)deadPlayerName);
                }
                else if (other == 11)
                {
                    networkText5 = NetworkText.FromKey("DeathText.TriedToEscape", (object)deadPlayerName);
                }
                else if (other == 12)
                {
                    networkText5 = NetworkText.FromKey("DeathText.WasLicked", (object)deadPlayerName);
                }
                else if (other == 13)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Teleport_1", (object)deadPlayerName);
                }
                else if (other == 14)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Teleport_2_Male", (object)deadPlayerName);
                }
                else if (other == 15)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Teleport_2_Female", (object)deadPlayerName);
                }
                else if (other == 254)
                {
                    networkText5 = NetworkText.Empty;
                }
                else if (other == (int)byte.MaxValue)
                {
                    networkText5 = NetworkText.FromKey("DeathText.Slain", (object)deadPlayerName);
                }
            }
            return(networkText5);
        }
Beispiel #10
0
 public static void SendMessageToPlayer(this Player player, string message, Color color)
 {
     ChatHelper.SendChatMessageToClient(NetworkText.FromLiteral(message), color, player.whoAmI);
 }
Beispiel #11
0
 /// <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);
Beispiel #12
0
        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;
            }
            bool isLocked = IsLockedChest(left, top);

            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.ExampleChestKey>();
                    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);
        }
Beispiel #13
0
 private void BroadcastRawMessage(ChatMessage message, byte author, Color messageColor)
 {
     NetManager.Instance.Broadcast(NetTextModule.SerializeServerMessage(NetworkText.FromLiteral(message.Text), messageColor), -1);
 }
Beispiel #14
0
        private bool AluminumMeteor(On.Terraria.WorldGen.orig_meteor orig, int i, int j)
        {
            Main.LocalPlayer.GetModPlayer <StarlightPlayer>().Shake += 80;
            Main.PlaySound(SoundID.DD2_ExplosiveTrapExplode);

            if (StarlightWorld.HasFlag(WorldFlags.AluminumMeteors))
            {
                Point16 target = new Point16();

                while (!CheckAroundMeteor(target))
                {
                    int x = Main.rand.Next(Main.maxTilesX);

                    for (int y = 0; y < Main.maxTilesY; y++)
                    {
                        if (Framing.GetTileSafely(x, y).active())
                        {
                            target = new Point16(x, y);
                            break;
                        }
                    }
                }

                for (int x = -35; x < 35; x++)
                {
                    for (int y = -35; y < 35; y++)
                    {
                        if (WorldGen.InWorld(target.X + x, target.Y + y) && Framing.GetTileSafely(target.X + x, target.Y + y).collisionType == 1)
                        {
                            float dist = new Vector2(x, y).Length();
                            if (dist < 8)
                            {
                                WorldGen.KillTile(target.X + x, target.Y + y);
                            }

                            if (dist > 8 && dist < 15)
                            {
                                WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType <Tiles.OreAluminum>(), true, true);
                                WorldGen.SlopeTile(target.X + x, target.Y + y, 0);
                            }

                            if (dist > 15 && dist < 30 && Main.rand.Next((int)dist - 15) == 0)
                            {
                                WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType <Tiles.OreAluminum>(), true, true);
                                WorldGen.SlopeTile(target.X + x, target.Y + y, 0);
                            }
                        }
                    }
                }

                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText("An asteroid has landed!", new Color(107, 233, 231));
                }

                else if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("An asteroid has landed!"), new Color(107, 233, 231));
                }

                return(true);
            }

            else
            {
                return(orig(i, j));
            }
        }
        public override void AI()
        {
            if (!npc.HasValidTarget)
            {
                //npc.ai[0] = 0;
                npc.TargetClosest();

                /*if (!npc.HasValidTarget)
                 * {
                 *  npc.active = false;
                 *  return;
                 * }*/
            }

            //npc.life = npc.lifeMax;
            npc.damage  = npc.defDamage;
            npc.defense = npc.defDefense;

            npc.ai[0] += 0.05f;

            if (npc.HasValidTarget)
            {
                Player player = Main.player[npc.target];
                npc.direction = npc.spriteDirection = npc.Center.X < player.Center.X ? 1 : -1;
                if (npc.ai[1] == 1)
                {
                    npc.position += (player.position - player.oldPosition) * 0.25f;
                }
                npc.velocity = npc.DirectionTo(player.Center) * npc.ai[0];
                if (npc.velocity.Length() > npc.Distance(player.Center))
                {
                    npc.Center = player.Center;
                }

                if (npc.timeLeft < 600)
                {
                    npc.timeLeft = 600;
                }
            }
            else
            {
                if (npc.timeLeft > 60)
                {
                    npc.timeLeft = 60;
                }
            }

            npc.scale = 1f + npc.ai[0] / 4f;

            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                int fullSize = (int)(40 * npc.scale);

                if (npc.ai[1] == 1)
                {
                    for (int i = -fullSize / 2; i <= fullSize / 2; i += 8)
                    {
                        for (int j = -fullSize / 2; j <= fullSize / 2; j += 8)
                        {
                            int tileX = (int)(npc.Center.X + i) / 16;
                            int tileY = (int)(npc.Center.Y + j) / 16;

                            //out of bounds checks
                            if (tileX > -1 && tileX < Main.maxTilesX && tileY > -1 && tileY < Main.maxTilesY)
                            {
                                Tile tile = Framing.GetTileSafely(tileX, tileY);
                                if (tile.type != 0 || tile.wall != 0)
                                {
                                    WorldGen.KillTile(tileX, tileY, noItem: true);
                                    WorldGen.KillWall(tileX, tileY);
                                    if (Main.netMode == NetmodeID.Server)
                                    {
                                        NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, tileX, tileY);
                                    }
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    if (Main.npc[i].active && Main.npc[i].type != npc.type && npc.Distance(Main.npc[i].Center) < fullSize / 2)
                    {
                        if (Main.netMode == NetmodeID.SinglePlayer)
                        {
                            Main.NewText(":echdeath:", Color.Red);
                        }
                        else if (Main.netMode == NetmodeID.Server)
                        {
                            NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(":echdeath:"), Color.Red);
                        }

                        Main.npc[i].StrikeNPC(npc.damage, 99f, npc.Center.X < Main.npc[i].Center.X ? 1 : -1);
                        for (int j = 0; j < 100; j++)
                        {
                            CombatText.NewText(Main.npc[i].Hitbox, Color.Red, Main.rand.Next(npc.damage), true);
                        }
                    }
                }
            }

            if (Main.LocalPlayer.active && !Main.LocalPlayer.dead && !Main.LocalPlayer.ghost &&
                npc.Hitbox.Intersects(Main.LocalPlayer.Hitbox))
            {
                Main.NewText(":echdeath:", Color.Red);
                Main.LocalPlayer.ResetEffects();
                Main.LocalPlayer.ghost = true;
                Main.LocalPlayer.KillMe(PlayerDeathReason.ByNPC(npc.whoAmI), npc.damage, 0);
                for (int i = 0; i < 100; i++)
                {
                    CombatText.NewText(Main.LocalPlayer.Hitbox, Color.Red, Main.rand.Next(npc.damage), true);
                }
            }

            if (npc.ai[1] == 1)
            {
                if (!Main.dedServ && Main.LocalPlayer.active)
                {
                    Main.LocalPlayer.GetModPlayer <FargoPlayer>().Screenshake = 2;
                }

                if (npc.localAI[0] == 0)
                {
                    Main.NewText("Echdeath has enraged.", Color.DarkRed);
                    npc.localAI[0] = 1;
                    for (int i = 0; i < npc.buffImmune.Length; i++)
                    {
                        npc.buffImmune[i] = true;
                    }
                }
                while (npc.buffType[0] != 0)
                {
                    npc.DelBuff(0);
                }
                if (npc.ai[2] == 0) //force life back to max until it works
                {
                    if (npc.life == npc.lifeMax)
                    {
                        npc.ai[2] = 1;
                    }
                    npc.life = npc.lifeMax;
                }
            }
            else
            {
                if (npc.ai[0] > 30)
                {
                    npc.ai[0] = 30;
                }
            }
        }
Beispiel #16
0
        private void PutItemsInSuperBannerTE(BannerRackTE superBannerTE, List <int> indexes, Player player)
        {
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                // uh oh
                return;
            }
            bool added = false;

            foreach (int invIndex in indexes)
            {
                Item item = player.inventory[invIndex];
                if (!item.IsAir && BannerRackTE.itemToBanner.ContainsKey(item.type))
                {
                    if (!superBannerTE.bannerItems.Any(x => x.type == item.type))
                    {
                        added = true;
                        string message = $"Banner for {item.Name} added to Banner Rack";
                        NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(message), Color.White);
                        //Main.NewText($"Banner for {item.Name} added to Banner Rack");
                        Item clone = item.Clone();
                        clone.stack = 1;
                        item.stack--;
                        if (item.IsAir)
                        {
                            item.SetDefaults(0);
                        }
                        //bool updateNeeded = superBannerTE.bannerItems.Count < 1;
                        superBannerTE.bannerItems.Add(clone);
                        //superBannerTE.stringUpToDate = false;
                        //if(updateNeeded)
                        //	superBannerTE.UpdateDrawItemIndexes();
                    }
                }
            }
            if (!added)
            {
                string message = $"No new Banners to add to Banner Rack";
                //Main.NewText($"No new Banners to add to Banner Rack");
                NetMessage.SendChatMessageToClient(NetworkText.FromLiteral(message), Color.White, player.whoAmI);
                // find closest npc that I don't have banner for.
                //player.NPCBannerBuff
                int nextNPCToKill     = -1;
                int nextNPCToKillLeft = 9999;
                for (int npctype = -10; npctype < NPCLoader.NPCCount; npctype++)
                {
                    int vanillaBannerID = Terraria.Item.NPCtoBanner(npctype);
                    if (vanillaBannerID > 0 && !NPCID.Sets.ExcludedFromDeathTally[NPCID.FromNetId(npctype)])
                    {
                        int vanillaBannerItemID = Item.BannerToItem(vanillaBannerID);
                        if (ItemID.Sets.BannerStrength[vanillaBannerItemID].Enabled)
                        {
                            int killsToBanner = ItemID.Sets.KillsToBanner[vanillaBannerItemID];
                            int killsLeft     = killsToBanner - (NPC.killCount[vanillaBannerID] % killsToBanner);

                            if (killsLeft < nextNPCToKillLeft && !superBannerTE.bannerItems.Any(x => x.type == vanillaBannerItemID))
                            {
                                nextNPCToKillLeft = killsLeft;
                                nextNPCToKill     = npctype;
                            }
                        }
                    }
                }
                if (nextNPCToKill != -1)
                {
                    message = $"Try killing {nextNPCToKillLeft} more {Lang.GetNPCNameValue(nextNPCToKill)}";
                    NetMessage.SendChatMessageToClient(NetworkText.FromLiteral(message), Color.White, player.whoAmI);
                    //Main.NewText($"Try killing {nextNPCToKillLeft} more {Lang.GetNPCNameValue(nextNPCToKill)}");
                }
            }
            else
            {
                superBannerTE.updateNeeded = true;
            }
        }
Beispiel #17
0
 public NetworkText GetDeathText(string deadPlayerName)
 {
     return(this.SourceCustomReason != null?NetworkText.FromLiteral(this.SourceCustomReason) : Lang.CreateDeathMessage(deadPlayerName, this.SourcePlayerIndex, this.SourceNPCIndex, this.SourceProjectileIndex, this.SourceOtherIndex, this.SourceProjectileType, this.SourceItemType));
 }
Beispiel #18
0
 public void ProcessIncomingMessage(string text, byte clientId)
 {
     ChatHelper.BroadcastChatMessageAs(clientId, NetworkText.FromLiteral(text), Main.player[clientId].ChatColor());
     Console.WriteLine("<{0}> {1}", Main.player[clientId].name, text);
 }
Beispiel #19
0
        public static NetworkText CreateDeathMessage(string deadPlayerName, int plr = -1, int npc = -1, int proj = -1, int other = -1, int projType = 0, int plrItemType = 0)
        {
            NetworkText networkText  = NetworkText.Empty;
            NetworkText networkText2 = NetworkText.Empty;
            NetworkText networkText3 = NetworkText.Empty;
            NetworkText networkText4 = NetworkText.Empty;

            if (proj >= 0)
            {
                networkText = NetworkText.FromKey(GetProjectileName(projType).Key);
            }
            if (npc >= 0)
            {
                networkText2 = Main.npc[npc].GetGivenOrTypeNetName();
            }
            if (plr >= 0 && plr < 255)
            {
                networkText3 = NetworkText.FromLiteral(Main.player[plr].name);
            }
            if (plrItemType >= 0)
            {
                networkText4 = NetworkText.FromKey(GetItemName(plrItemType).Key);
            }
            bool        flag   = networkText != NetworkText.Empty;
            bool        flag2  = plr >= 0 && plr < 255;
            bool        flag3  = networkText2 != NetworkText.Empty;
            NetworkText result = NetworkText.Empty;
            NetworkText empty  = NetworkText.Empty;

            empty = NetworkText.FromKey(Language.RandomFromCategory("DeathTextGeneric").Key, deadPlayerName, Main.worldName);
            if (flag2)
            {
                result = NetworkText.FromKey("DeathSource.Player", empty, networkText3, flag ? networkText : networkText4);
            }
            else if (flag3)
            {
                result = NetworkText.FromKey("DeathSource.NPC", empty, networkText2);
            }
            else if (flag)
            {
                result = NetworkText.FromKey("DeathSource.Projectile", empty, networkText);
            }
            else
            {
                switch (other)
                {
                case 0:
                    result = NetworkText.FromKey("DeathText.Fell_" + (Main.rand.Next(2) + 1), deadPlayerName);
                    break;

                case 1:
                    result = NetworkText.FromKey("DeathText.Drowned_" + (Main.rand.Next(4) + 1), deadPlayerName);
                    break;

                case 2:
                    result = NetworkText.FromKey("DeathText.Lava_" + (Main.rand.Next(4) + 1), deadPlayerName);
                    break;

                case 3:
                    result = NetworkText.FromKey("DeathText.Default", empty);
                    break;

                case 4:
                    result = NetworkText.FromKey("DeathText.Slain", deadPlayerName);
                    break;

                case 5:
                    result = NetworkText.FromKey("DeathText.Petrified_" + (Main.rand.Next(4) + 1), deadPlayerName);
                    break;

                case 6:
                    result = NetworkText.FromKey("DeathText.Stabbed", deadPlayerName);
                    break;

                case 7:
                    result = NetworkText.FromKey("DeathText.Suffocated", deadPlayerName);
                    break;

                case 8:
                    result = NetworkText.FromKey("DeathText.Burned", deadPlayerName);
                    break;

                case 9:
                    result = NetworkText.FromKey("DeathText.Poisoned", deadPlayerName);
                    break;

                case 10:
                    result = NetworkText.FromKey("DeathText.Electrocuted", deadPlayerName);
                    break;

                case 11:
                    result = NetworkText.FromKey("DeathText.TriedToEscape", deadPlayerName);
                    break;

                case 12:
                    result = NetworkText.FromKey("DeathText.WasLicked", deadPlayerName);
                    break;

                case 13:
                    result = NetworkText.FromKey("DeathText.Teleport_1", deadPlayerName);
                    break;

                case 14:
                    result = NetworkText.FromKey("DeathText.Teleport_2_Male", deadPlayerName);
                    break;

                case 15:
                    result = NetworkText.FromKey("DeathText.Teleport_2_Female", deadPlayerName);
                    break;

                case 16:
                    result = NetworkText.FromKey("DeathText.Inferno", deadPlayerName);
                    break;

                case 254:
                    result = NetworkText.Empty;
                    break;

                case 255:
                    result = NetworkText.FromKey("DeathText.Slain", deadPlayerName);
                    break;
                }
            }
            return(result);
        }
Beispiel #20
0
 public static void 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 != 1)
     {
         if (NPC.AnyNPCs(bossType))
         {
             return;
         }
         int npcID = NPC.NewNPC((int)npcCenter.X, (int)npcCenter.Y, bossType, 0);
         Main.npc[npcID].ai[3]      = -1;
         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 || npcName.Equals("")) && Main.npc[npcID].modNPC != null)
             {
                 npcName = Main.npc[npcID].modNPC.DisplayName.GetDefault();
             }
             if (namePlural)
             {
                 if (Main.netMode == NetmodeID.SinglePlayer)
                 {
                     if (Main.netMode != 1)
                     {
                         BaseUtility.Chat(npcName + Language.GetTextValue("Mods.AAMod.Common.BosshasAwoken"), 175, 75, 255, false);
                     }
                 }
                 else
                 if (Main.netMode == NetmodeID.Server)
                 {
                     NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(npcName + Language.GetTextValue("Mods.AAMod.Common.BosshasAwoken")), new Color(175, 75, 255), -1);
                 }
             }
             else
             {
                 if (Main.netMode == NetmodeID.SinglePlayer)
                 {
                     if (Main.netMode != 1)
                     {
                         BaseUtility.Chat(Language.GetTextValue("Announcement.HasAwoken", npcName), 175, 75, 255, false);
                     }
                 }
                 else
                 if (Main.netMode == NetmodeID.Server)
                 {
                     NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[]
                     {
                         NetworkText.FromLiteral(npcName)
                     }), new Color(175, 75, 255), -1);
                 }
             }
         }
     }
     else
     {
         AANet.SendNetMessage(AANet.SummonNPCFromClient, (byte)player.whoAmI, (short)bossType, spawnMessage, (int)npcCenter.X, (int)npcCenter.Y, overrideDisplayName, namePlural);
     }
 }
        public override bool UseItem(Player player)
        {
            Fargowiltas.SwarmActive = true;
            Fargowiltas.SwarmTotal  = 10 * player.inventory[player.selectedItem].stack;
            Fargowiltas.SwarmKills  = 0;

            if (Fargowiltas.SwarmTotal < 100)
            {
                Fargowiltas.SwarmSpawned = 10;
            }
            else
            {
                //energizer swarms
                Fargowiltas.SwarmSpawned = maxSpawn;
            }

            //DG special case
            if (npcType == NPCID.SkeletronHead && Main.dayTime)
            {
                npcType = NPCID.DungeonGuardian;
            }
            //twins special case
            else if (npcType == NPCID.Retinazer)
            {
                Fargowiltas.SwarmTotal *= 2;
            }

            //wof mega special case
            if (npcType == NPCID.WallofFlesh)
            {
                FargoGlobalNPC.SpawnWalls(player);
                counter++;

                if (counter < 10)
                {
                    return(true);
                }
            }
            else
            {
                //spawn the bosses
                for (int i = 0; i < Fargowiltas.SwarmSpawned; i++)
                {
                    //spawn the other twin as well
                    if (npcType == NPCID.Retinazer)
                    {
                        int twin = NPC.NewNPC((int)player.position.X + Main.rand.Next(-1000, 1000), (int)player.position.Y + Main.rand.Next(-1000, -400), NPCID.Spazmatism);
                        Main.npc[twin].GetGlobalNPC <FargoGlobalNPC>().SwarmActive = true;
                    }

                    int boss = NPC.NewNPC((int)player.position.X + Main.rand.Next(-1000, 1000), (int)player.position.Y + Main.rand.Next(-1000, -400), npcType);
                    Main.npc[boss].GetGlobalNPC <FargoGlobalNPC>().SwarmActive = true;
                }
            }

            // Kill whole stack
            player.inventory[player.selectedItem].stack = 0;

            if (Main.netMode == 2)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(spawnMessage), new Color(175, 75, 255));
            }
            else
            {
                Main.NewText(spawnMessage, 175, 75, 255);
            }

            Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
            return(true);
        }
        private void OnServerChat(ServerChatEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            var player = TShock.Players[e.Who];

            if (player == null || !player.IsLoggedIn)
            {
                return;
            }

            if (!player.HasPermission(TShockAPI.Permissions.canchat) || player.mute)
            {
                return;
            }

            if (e.Text.StartsWith(TShock.Config.CommandSpecifier) ||
                e.Text.StartsWith(TShock.Config.CommandSilentSpecifier))
            {
                return;
            }

            var playerData = _database.Get(player.Account);

            if (playerData == null)
            {
                return;
            }

            var prefix    = playerData.ChatData.Prefix ?? player.Group.Prefix;
            var suffix    = playerData.ChatData.Suffix ?? player.Group.Suffix;
            var chatColor = playerData.ChatData.Color?.ParseColor() ?? player.Group.ChatColor.ParseColor();

            if (!TShock.Config.EnableChatAboveHeads)
            {
                // byDD
                String text    = e.Text;
                string pattern = "\\bтз\\b";
                text = Regex.Replace(text, pattern, "ТБ", RegexOptions.IgnoreCase);
                //Terraria.Chat.ChatMessage.

                var message = string.Format(TShock.Config.ChatFormat, player.Group.Name, prefix, player.Name, suffix,
                                            text); //byDD
                TSPlayer.All.SendMessage(message, chatColor);
                TSPlayer.Server.SendMessage(message, chatColor);
                TShock.Log.Info($"Broadcast: {message}");
            }
            else
            {
                var playerName = player.TPlayer.name;
                player.TPlayer.name = string.Format(TShock.Config.ChatAboveHeadsFormat, player.Group.Name, prefix,
                                                    player.Name,
                                                    suffix);
                NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(player.TPlayer.name),
                                    e.Who);

                player.TPlayer.name = playerName;

                var packet =
                    NetTextModule.SerializeServerMessage(NetworkText.FromLiteral(e.Text), chatColor, (byte)e.Who);
                NetManager.Instance.Broadcast(packet, e.Who);

                NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(playerName), e.Who);

                var msg =
                    $"<{string.Format(TShock.Config.ChatAboveHeadsFormat, player.Group.Name, prefix, player.Name, suffix)}> {e.Text}";

                player.SendMessage(msg, chatColor);
                TSPlayer.Server.SendMessage(msg, chatColor);
                TShock.Log.Info($"Broadcast: {msg}");
            }

            e.Handled = true;
        }
Beispiel #23
0
        private void ClearInventory(TSPlayer player)         //The inventory clearing method from ClearInvSSC
        {
            for (int i = 0; i < NetItem.MaxInventory; i++)
            {
                if (i < NetItem.InventorySlots)                 //Main Inventory
                {
                    player.TPlayer.inventory[i].netDefaults(0);
                }
                else if (i < NetItem.InventorySlots + NetItem.ArmorSlots)                 //Armor&Accessory slots
                {
                    var index = i - NetItem.InventorySlots;
                    player.TPlayer.armor[index].netDefaults(0);
                }
                else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots)                 //Dye Slots
                {
                    var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots);
                    player.TPlayer.dye[index].netDefaults(0);
                }
                else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots)                 //Misc Equip slots
                {
                    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)
                {
                    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)                 //piggy Bank
                {
                    //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)                 //safe Bank
                {
                    //var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots);
                    //player.TPlayer.bank2.item[index].netDefaults(0);
                }
                else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots + NetItem.ForgeSlots)                 //Defender's Forge
                {
                    //var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots);
                    //player.TPlayer.bank3.item[index].netDefaults(0);
                }
                else
                {
                    player.TPlayer.trashItem.netDefaults(0);
                }
            }

            for (int k = 0; k < NetItem.MaxInventory - (NetItem.SafeSlots + NetItem.PiggySlots + NetItem.ForgeSlots); k++)             //clear all slots excluding bank slots, bank slots cleared in ResetBanks method
            {
                NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, player.Index, (float)k, 0f, 0f, 0);
            }

            var trashSlot = NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots;

            NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, player.Index, (float)trashSlot, 0f, 0f, 0);             //trash slot

            for (int k = 0; k < Player.maxBuffs; k++)
            {
                player.TPlayer.buffType[k] = 0;
            }

            NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerMana, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerHp, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerBuff, -1, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);

            for (int k = 0; k < NetItem.MaxInventory - (NetItem.SafeSlots + NetItem.PiggySlots); k++)
            {
                NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.Empty, player.Index, (float)k, 0f, 0f, 0);
            }
            NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.Empty, player.Index, (float)trashSlot, 0f, 0f, 0);

            for (int k = 0; k < Player.maxBuffs; k++)
            {
                player.TPlayer.buffType[k] = 0;
            }

            NetMessage.SendData((int)PacketTypes.PlayerInfo, player.Index, -1, NetworkText.FromLiteral(player.Name), player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerMana, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerHp, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);
            NetMessage.SendData((int)PacketTypes.PlayerBuff, player.Index, -1, NetworkText.Empty, player.Index, 0f, 0f, 0f, 0);
        }
 public void ProcessMessage(string text, byte clientId)
 {
     NetMessage.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);
 }
Beispiel #25
0
        public override bool NewRightClick(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 = Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18;
                left %= 3;
                left  = Player.tileTargetX - left;
                int top = Player.tileTargetY - 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, 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();
            }
            return(true);
        }
Beispiel #26
0
        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(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, (float)top, 0f, 0f, 0, 0, 0);
                    Main.stackSplit = 600;
                    // Spawning a Grenade projectile that dies quickly is the simplest way to get this effect
                    int projectile = Projectile.NewProjectile(left * 16 + 8, top * 16 + 8, 0, 0, ProjectileType <GraniteChestExplode>(), 300, 1, Main.myPlayer);
                    Main.projectile[projectile].scale     = 2f;
                    Main.projectile[projectile].timeLeft  = 2;
                    Main.projectile[projectile].netUpdate = true;
                    //MessageHelper.SendExplode(new Vector2(left, top) * 16f, new Vector2(80f), 300, -1, -1, 2, 3);
                }
            }
            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);
                        // Spawning a Grenade projectile that dies quickly is the simplest way to get this effect
                        int projectile = Projectile.NewProjectile(left * 16 + 8, top * 16 + 8, 0, 0, ProjectileType <GraniteChestExplode>(), 300, 1, Main.myPlayer);
                        Main.projectile[projectile].scale     = 2f;
                        Main.projectile[projectile].timeLeft  = 2;
                        Main.projectile[projectile].netUpdate = true;
                        //Entrogic.Explode(new Vector2(left, top) * 16f, new Vector2(80f), 300, 2, 3);
                    }
                    Recipe.FindRecipes();
                }
            }
            return(true);
        }
Beispiel #27
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];
            }

            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);
        }
Beispiel #28
0
        // 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 override void RightClick(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 == 1)
            {
                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
            {
                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();
                }
            }
        }
Beispiel #30
0
 public static void PlayerTextPopup(PvPPlayer player, PvPPlayer target, string message, Color color)
 {
     NetMessage.SendData(119, player.Index, -1, NetworkText.FromLiteral(message), (int)color.PackedValue, target.X, target.Y + 10);
 }