/// <summary>
        /// Applies a shader for the provided PaintingProjectile. Possible results are the Painted, GSPainted, and PaintedNegative shaders.
        /// </summary>
        /// <param name="projectile"></param>
        /// <returns></returns>
        public static MiscShaderData applyShader(PaintingProjectile projectile, PaintData data)
        {
            MiscShaderData shader = getShader(projectile, data);

            if (shader != null)
            {
                shader.Apply();
            }
            return(shader);
        }
 /// <summary>
 /// Sends a ModPacket to sync the npc owner of a PaintingProjectile
 /// </summary>
 /// <param name="p"></param>
 /// <param name="toClient"></param>
 /// <param name="ignoreClient"></param>
 public static void sendProjNPCOwnerPacket(PaintingProjectile p, int toClient = -1, int ignoreClient = -1)
 {
     if (server() || multiplayer())
     {
         ModPacket packet = p.mod.GetPacket();
         packet.Write(WoMDMessageTypes.SetProjNPCOwner);
         packet.Write(p.projectile.whoAmI);
         packet.Write(p.projectile.type);
         packet.Write(p.npcOwner);
         packet.Send(toClient, ignoreClient);
     }
 }
示例#3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            switch (reader.ReadByte())
            {
            case WoMDMessageTypes.SetNPCColors:
                if (multiplayer() || server())
                {
                    WoMDNPC.readColorPacket(reader, out WoMDNPC gNpc, out NPC npc);
                    if (server())
                    {
                        WoMDNPC.sendColorPacket(gNpc, npc);
                    }
                }
                break;

            case WoMDMessageTypes.SetProjectileColor:
                if (multiplayer())
                {
                    WoMDProjectile.readProjectileColorPacket(reader, out _, out _);
                }
                break;

            case WoMDMessageTypes.SetProjNPCOwner:
                if (multiplayer())
                {
                    PaintingProjectile.readProjNPCOwnerPacket(reader);
                }
                break;

            case WoMDMessageTypes.SetMultiProjNPCOwner:
                if (multiplayer())
                {
                    PaintingProjectile.readMultiProjNPCOwnerPacket(reader);
                }
                break;

            case WoMDMessageTypes.SetPPOverrideData:
                if (multiplayer() || server())
                {
                    PaintingProjectile.readPPOverrideDataPacket(reader, out PaintingProjectile proj);
                    if (server() && proj != null)
                    {
                        PaintingProjectile.sendPPOverrideDataPacket(proj);
                    }
                }
                break;
            }
        }
        /// <summary>
        /// Sets the npc owner of the projectile specified in ModPacket
        /// </summary>
        /// <param name="reader"></param>
        public static void readProjNPCOwnerPacket(BinaryReader reader)
        {
            int        projId   = reader.ReadInt32();
            int        projType = reader.ReadInt32();
            int        owner    = reader.ReadInt32();
            Projectile proj     = getProjectile(projId);

            if (proj != null && proj.type == projType && proj.active)
            {
                PaintingProjectile p = proj.modProjectile as PaintingProjectile;
                if (p != null)
                {
                    p.npcOwner = owner;
                }
            }
        }
 public static void sendPPOverrideDataPacket(PaintingProjectile p, int toClient = -1, int ignoreClient = -1)
 {
     if (server() || multiplayer())
     {
         ModPacket packet = p.mod.GetPacket();
         packet.Write(WoMDMessageTypes.SetPPOverrideData);
         packet.Write(p.projectile.whoAmI);
         packet.Write(p.projectile.type);
         packet.Write(p._overridePaintData.PaintColor);
         packet.Write(p._overridePaintData.CustomPaint == null ? "null" : p._overridePaintData.CustomPaint.GetType().Name);
         packet.Write((double)p._overridePaintData.TimeScale);
         packet.Write((double)p._overridePaintData.TimeOffset);
         packet.Write(p._overridePaintData.sprayPaint);
         packet.Write(p._overridePaintData.paintMethod.ToString("F"));
         packet.Send(toClient, ignoreClient);
     }
 }
        /// <summary>
        /// Sets the npc owner of the multiple projectiles specified in ModPacket
        /// </summary>
        /// <param name="reader"></param>
        public static void readMultiProjNPCOwnerPacket(BinaryReader reader)
        {
            int owner = reader.ReadInt32();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                int        projId   = reader.ReadInt32();
                int        projType = reader.ReadInt32();
                Projectile p        = getProjectile(projId);
                if (p != null && p.type == projType)
                {
                    PaintingProjectile proj = p.modProjectile as PaintingProjectile;
                    if (proj != null)
                    {
                        proj.npcOwner = owner;
                    }
                }
            }
        }
 /// <summary>
 /// Gets a shader for the provided PaintingProjectile. Possible results are the Painted, GSPainted, and PaintedNegative shaders.
 /// </summary>
 /// <param name="projectile"></param>
 /// <returns></returns>
 public static MiscShaderData getShader(PaintingProjectile projectile, PaintData data)
 {
     if (projectile == null)
     {
         return(null);
     }
     if ((data.PaintColor == -1 && data.CustomPaint == null) || data.paintMethod == PaintMethods.RemovePaint)
     {
         return(null);
     }
     if (data.PaintColor == PaintID.Negative || data.CustomPaint is NegativeSprayPaint)
     {
         return(getNegativeShader());
     }
     if (projectile.usesGSShader)
     {
         return(getGSShader(data.RenderColor));
     }
     return(getPaintedShader(data.RenderColor));
 }
        public static void readPPOverrideDataPacket(BinaryReader reader, out PaintingProjectile projectile)
        {
            projectile = null;
            int        projId          = reader.ReadInt32();
            int        projType        = reader.ReadInt32();
            int        paintColor      = reader.ReadInt32();
            string     customPaintName = reader.ReadString();
            float      timeScale       = (float)reader.ReadDouble();
            float      timeOffset      = (float)reader.ReadDouble();
            bool       sprayPaint      = reader.ReadBoolean();
            string     method          = reader.ReadString();
            Projectile proj            = getProjectile(projId);

            if (proj != null && proj.type == projType)
            {
                projectile = proj.modProjectile as PaintingProjectile;
                if (projectile != null)
                {
                    CustomPaint  customPaint = customPaintName == "null" ? null : (CustomPaint)Activator.CreateInstance(Type.GetType("WeaponsOfMassDecoration.Items." + customPaintName));
                    PaintMethods paintMethod = (PaintMethods)Enum.Parse(typeof(PaintMethods), method);
                    projectile._overridePaintData = new PaintData(timeScale, paintColor, customPaint, sprayPaint, timeOffset, paintMethod);
                }
            }
        }