/// <summary> /// Handles reading a packet to sync the variables regarding the rendering of the projectile /// </summary> /// <param name="reader"></param> /// <param name="gProj"></param> /// <param name="proj"></param> public static void readProjectileColorPacket(BinaryReader reader, out WoMDProjectile gProj, out Projectile proj) { int projId = reader.ReadInt32(); int projType = reader.ReadInt32(); proj = getProjectile(projId); gProj = proj.GetGlobalProjectile <WoMDProjectile>(); int paintColor = reader.ReadInt32(); string customPaintName = reader.ReadString(); float paintedTime = (float)reader.ReadDouble(); if (proj != null && proj.type == projType && gProj != null && proj.active) { gProj.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.TimeOffset = paintedTime; gProj._paintData = data; } }
public static void applyPainted(Projectile projectile, PaintData paintData) { WoMDProjectile proj = projectile.GetGlobalProjectile <WoMDProjectile>(); if (proj == null) { return; } proj.painted = true; proj._paintData = paintData.clone(); if (server()) { sendProjectileColorPacket(proj, projectile); } }
private static void applyPaintedFromProjectile(Projectile dest, Projectile src) { WoMDProjectile dProj = dest.GetGlobalProjectile <WoMDProjectile>(); WoMDProjectile sProj = src.GetGlobalProjectile <WoMDProjectile>(); if (dProj == null || sProj == null) { return; } dProj.painted = true; dProj._paintData = sProj.paintData.clone(); dProj.npcOwner = sProj.npcOwner; if (server()) { sendProjectileColorPacket(dProj, dest); } }
/// <summary> /// Sends a packet to sync the variables regarding the rendering of the projectile /// </summary> /// <param name="gProj"></param> /// <param name="proj"></param> /// <param name="toClient"></param> /// <param name="ignoreClient"></param> public static void sendProjectileColorPacket(WoMDProjectile gProj, Projectile proj, int toClient = -1, int ignoreClient = -1) { if (!gProj.painted) { return; } PaintData data = gProj.paintData; if (server() || multiplayer()) { ModPacket packet = gProj.mod.GetPacket(); packet.Write(WoMDMessageTypes.SetProjectileColor); packet.Write(proj.whoAmI); packet.Write(proj.type); packet.Write(data.PaintColor); packet.Write(data.CustomPaint == null ? "null" : data.CustomPaint.GetType().Name); packet.Write((double)data.TimeOffset); packet.Send(toClient, ignoreClient); } }
/// <summary> /// Copies the painted settings from the provided npc to the provided projectile /// </summary> /// <param name="projectile">The projectile to inherit the painted settings</param> /// <param name="npc">The npc to copy the painted settings from</param> private static void applyPaintedFromNpc(Projectile projectile, NPC npc) { WoMDNPC gNpc = npc.GetGlobalNPC <WoMDNPC>(); if (gNpc == null || !gNpc.painted) { return; } WoMDProjectile proj = projectile.GetGlobalProjectile <WoMDProjectile>(); if (proj == null) { return; } proj._paintData = gNpc.paintData.clone(); proj.npcOwner = npc.whoAmI; if (server()) { sendProjectileColorPacket(proj, projectile); } }