Esempio n. 1
0
        public override void SendClientChanges(ModPlayer clientPlayer)
        {
            // Here we would sync something like an RPG stat whenever the player changes it.
            LPlayer clone = clientPlayer as LPlayer;
            bool    send  = false;

            for (int i = 0; i < LansToggleableBuffs.instance.getBuffLength(); i++)
            {
                if (clone.boughtbuffsavail[i] != boughtbuffsavail[i])
                {
                    send = true;
                    break;
                }
                if (clone.buffsavail[i] != buffsavail[i])
                {
                    send = true;
                    break;
                }
            }

            if (send)
            {
                var packet = mod.GetPacket();
                packet.Write((byte)ModMessageType.Change);
                packet.Write((byte)player.whoAmI);
                for (int i = 0; i < LansToggleableBuffs.instance.getBuffLength(); i++)
                {
                    packet.Write(boughtbuffsavail[i]);
                    packet.Write(buffsavail[i]);
                }
                packet.Send();
            }
        }
Esempio n. 2
0
        public override void clientClone(ModPlayer clientClone)
        {
            LPlayer clone = clientClone as LPlayer;

            var size = LansToggleableBuffs.instance.getBuffLength();

            for (int i = 0; i < size; i++)
            {
                clone.boughtbuffsavail[i] = boughtbuffsavail[i];
                clone.buffsavail[i]       = buffsavail[i];
            }
        }
Esempio n. 3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ModMessageType msgType = (ModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the server to initialize the Volcano Tremor on clients
            case ModMessageType.SyncPlayer:
            {
                byte playernumber = reader.ReadByte();

                LPlayer examplePlayer = Main.player[playernumber].GetModPlayer <LPlayer>();

                if (examplePlayer.boughtbuffsavail == null)
                {
                    examplePlayer.boughtbuffsavail = new bool[LansToggleableBuffs.instance.getBuffLength()];
                    examplePlayer.buffsavail       = new bool[LansToggleableBuffs.instance.getBuffLength()];
                }

                for (int i = 0; i < this.getBuffLength(); i++)
                {
                    examplePlayer.boughtbuffsavail[i] = reader.ReadBoolean();
                    examplePlayer.buffsavail[i]       = reader.ReadBoolean();
                }
                break;
            }

            case ModMessageType.Change:
            {
                byte playernumber = reader.ReadByte();


                LPlayer examplePlayer = Main.player[playernumber].GetModPlayer <LPlayer>();


                if (examplePlayer.boughtbuffsavail == null)
                {
                    examplePlayer.boughtbuffsavail = new bool[LansToggleableBuffs.instance.getBuffLength()];
                    examplePlayer.buffsavail       = new bool[LansToggleableBuffs.instance.getBuffLength()];
                }

                for (int i = 0; i < this.getBuffLength(); i++)
                {
                    examplePlayer.boughtbuffsavail[i] = reader.ReadBoolean();
                    examplePlayer.buffsavail[i]       = reader.ReadBoolean();
                }

                if (Main.netMode == NetmodeID.Server)
                {
                    var packet = GetPacket();
                    packet.Write((byte)ModMessageType.Change);
                    packet.Write((byte)playernumber);
                    for (int i = 0; i < this.getBuffLength(); i++)
                    {
                        packet.Write(examplePlayer.boughtbuffsavail[i]);
                        packet.Write(examplePlayer.buffsavail[i]);
                    }
                    packet.Send(-1, playernumber);
                }

                break;
            }
            }
        }