// In MP, other clients need accurate information about your player or else bugs happen.
        // clientClone, SyncPlayer, and SendClientChanges, ensure that information is correct.
        // We only need to do this for data that is changed by code not executed by all clients,
        // or data that needs to be shared while joining a world.
        // For example, examplePet doesn't need to be synced because all clients know that the player is wearing the ExamplePet item in an equipment slot.
        // The examplePet bool is set for that player on every clients computer independently (via the Buff.Update), keeping that data in sync.
        // ExampleLifeFruits, however might be out of sync. For example, when joining a server, we need to share the exampleLifeFruits variable with all other clients.
        // In addition, in ExampleUI we have a button that toggles "Non-Stop Party". We need to sync this whenever it changes.
        public override void clientClone(ModPlayer clientClone)
        {
            HighlanderPlayer clone = clientClone as HighlanderPlayer;

            // Here we would make a backup clone of values that are only correct on the local players Player instance.
            // Some examples would be RPG stats from a GUI, Hotkey states, and Extra Item Slots
            clone.unboxed = unboxed;
        }
        public override void SendClientChanges(ModPlayer clientPlayer)
        {
            // Here we would sync something like an RPG stat whenever the player changes it.
            HighlanderPlayer clone = clientPlayer as HighlanderPlayer;
            // Send a Mod Packet with the changes.
            var packet = mod.GetPacket();

            packet.Write((byte)HighlanderMessageType.HighlanderPlayerSyncPlayer);
            packet.Write((byte)player.whoAmI);
            packet.Write(unboxed);
            packet.Send();
        }
Example #3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            HighlanderMessageType msgType = (HighlanderMessageType)reader.ReadByte();

            switch (msgType)
            {
            case HighlanderMessageType.HighlanderPlayerSyncPlayer:
                byte             playernumber = reader.ReadByte();
                HighlanderPlayer modPlayer    = Main.player[playernumber].GetModPlayer <HighlanderPlayer>();
                int unboxed = reader.ReadInt32();
                modPlayer.unboxed = unboxed;
                // SyncPlayer will be called automatically, so there is no need to forward this data to other clients.
                break;

            default:
                Logger.WarnFormat("Highlander: Unknown Message type: {0}", msgType);
                break;
            }
        }