Esempio n. 1
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ModMessageType msgType = (ModMessageType)reader.ReadByte();

            switch (msgType)
            {
            case ModMessageType.SyncPlayer:
                byte             playernumber = reader.ReadByte();
                SpellbladePlayer player       = Main.player[playernumber].GetModPlayer <SpellbladePlayer>();
                int current = reader.ReadInt32();
                int max     = reader.ReadInt32();
                int max2    = reader.ReadInt32();
                player.arcanePowerCurrent = current;
                player.arcanePowerMax     = max;
                player.arcanePowerMax2    = max2;
                player.altWeaponFunc      = reader.ReadBoolean();
                player.arcaneCurse        = reader.ReadBoolean();
                player.swordProtect       = reader.ReadBoolean();
                // SyncPlayer will be called automatically, so there is no need to forward this data to other clients.
                break;

            case ModMessageType.AltFuncUpdate:
                playernumber         = reader.ReadByte();
                player               = Main.player[playernumber].GetModPlayer <SpellbladePlayer>();
                player.altWeaponFunc = reader.ReadBoolean();
                if (Main.netMode == NetmodeID.Server)
                {
                    var packet = GetPacket();
                    packet.Write((byte)ModMessageType.AltFuncUpdate);
                    packet.Write(playernumber);
                    packet.Write(player.altWeaponFunc);
                    packet.Send(-1, playernumber);
                }
                break;

            case ModMessageType.ForceAltUse:
                playernumber = reader.ReadByte();
                player       = Main.player[playernumber].GetModPlayer <SpellbladePlayer>();
                player.ForceAltUse();
                if (Main.netMode == NetmodeID.Server)
                {
                    var packet = GetPacket();
                    packet.Write((byte)ModMessageType.ForceAltUse);
                    packet.Write(playernumber);
                    packet.Send(-1, playernumber);
                }
                break;

            default:
                Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType);
                break;
            }
        }
        public override void clientClone(ModPlayer clientClone)
        {
            SpellbladePlayer clone = clientClone as SpellbladePlayer;

            // 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.arcanePowerCurrent = arcanePowerCurrent;
            clone.arcanePowerMax     = arcanePowerMax;
            clone.arcanePowerMax2    = arcanePowerMax2;
            clone.altWeaponFunc      = altWeaponFunc;
            clone.arcaneCurse        = arcaneCurse;
            clone.swordProtect       = swordProtect;
        }
        public static void SwapItemAltUse(Player player, bool forcePush)
        {
            SpellbladePlayer p = player.GetModPlayer <SpellbladePlayer>();

            p.altWeaponFunc = !p.altWeaponFunc;

            if (Main.netMode != NetmodeID.SinglePlayer)
            {
                ModPacket packet = p.mod.GetPacket();
                packet.Write((byte)ModMessageType.AltFuncUpdate);
                packet.Write((byte)player.whoAmI);
                packet.Write(p.altWeaponFunc);
                packet.Send();

                if (forcePush && p.altWeaponFunc)
                {
                    packet = p.mod.GetPacket();
                    packet.Write((byte)ModMessageType.ForceAltUse);
                    packet.Write((byte)player.whoAmI);
                    packet.Send();
                }
            }
        }