コード例 #1
0
ファイル: ExampleMod.cs プロジェクト: shasta246/tModLoader
        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:
                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>().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;

            default:
                Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType);
                break;
            }
        }
コード例 #2
0
ファイル: ExampleMod.cs プロジェクト: xxSephiroth/tModLoader
        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;

            default:
                ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType);
                break;
            }
        }
コード例 #3
0
ファイル: ExampleMod.cs プロジェクト: nilfisk/tModLoader
        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      = (ExampleWorld)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.SpawnNPC:
                NPC.NewNPC(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                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)
                {
                    string text = player.name + " has " + lives;
                    if (lives == 1)
                    {
                        text += " life left!";
                    }
                    else
                    {
                        text += " lives left!";
                    }
                    NetMessage.SendData(25, -1, -1, text, 255, 255, 25, 25);
                }
                break;

            default:
                ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType);
                break;
            }
        }