Пример #1
0
        /// <summary>
        /// Handles reading a packet and setting variables regarding the rendering of the NPC
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="gNpc"></param>
        /// <param name="npc"></param>
        public static void readColorPacket(BinaryReader reader, out WoMDNPC gNpc, out NPC npc)
        {
            int npcId   = reader.ReadInt32();
            int npcType = reader.ReadInt32();

            npc  = getNPC(npcId);
            gNpc = npc.GetGlobalNPC <WoMDNPC>();
            int    paintColor      = reader.ReadInt32();
            string customPaintName = reader.ReadString();
            bool   sprayPainted    = reader.ReadBoolean();
            float  paintedTime     = (float)reader.ReadDouble();

            if (npc != null && npc.type == npcType && gNpc != null && npc.active)
            {
                gNpc.painted = true;
                PaintData data = new PaintData();
                data.PaintColor = paintColor;
                if (customPaintName == "null")
                {
                    data.CustomPaint = null;
                }
                else
                {
                    data.CustomPaint = (CustomPaint)Activator.CreateInstance(Type.GetType("WeaponsOfMassDecoration.Items." + customPaintName));
                    data.TimeScale   = npcCyclingTimeScale;
                }
                data.sprayPaint = sprayPainted;
                data.TimeOffset = paintedTime;
            }
        }
Пример #2
0
        /// <summary>
        /// Sends a packet to sync variables regarding the rendering of the NPC
        /// </summary>
        /// <param name="gNpc"></param>
        /// <param name="npc"></param>
        /// <param name="toClient"></param>
        /// <param name="ignoreClient"></param>
        public static void sendColorPacket(WoMDNPC gNpc, NPC npc, int toClient = -1, int ignoreClient = -1)
        {
            if (!gNpc.painted)
            {
                return;
            }
            PaintData data = gNpc.paintData;

            if (server() || multiplayer())
            {
                ModPacket packet = gNpc.mod.GetPacket();
                packet.Write(WoMDMessageTypes.SetNPCColors);
                packet.Write(npc.whoAmI);
                packet.Write(npc.type);
                packet.Write(data.PaintColor);
                packet.Write(data.CustomPaint == null ? "null" : data.CustomPaint.GetType().Name);
                packet.Write(data.sprayPaint);
                packet.Write((double)data.TimeOffset);
                packet.Send(toClient, ignoreClient);
            }
        }