Example #1
0
 public static void SendBaseNetMessage(int msg, params object[] param)
 {
     if (Main.netMode == NetmodeID.SinglePlayer)
     {
         return;
     }                                                                   //nothing to sync in SP
     BaseNet.WriteToPacket(CSkies.inst.GetPacket(), (byte)msg, param).Send();
 }
Example #2
0
        public override void HandlePacket(BinaryReader bb, int whoAmI)
        {
            MsgType msg = (MsgType)bb.ReadByte();

            if (msg == MsgType.ProjectileHostility) //projectile hostility and ownership
            {
                int  owner    = bb.ReadInt32();
                int  projID   = bb.ReadInt32();
                bool friendly = bb.ReadBoolean();
                bool hostile  = bb.ReadBoolean();
                if (Main.projectile[projID] != null)
                {
                    Main.projectile[projID].owner    = owner;
                    Main.projectile[projID].friendly = friendly;
                    Main.projectile[projID].hostile  = hostile;
                }
                if (Main.netMode == NetmodeID.Server)
                {
                    MNet.SendBaseNetMessage(0, owner, projID, friendly, hostile);
                }
            }
            else
            if (msg == MsgType.SyncAI) //sync AI array
            {
                int     classID     = bb.ReadByte();
                int     id          = bb.ReadInt16();
                int     aitype      = bb.ReadByte();
                int     arrayLength = bb.ReadByte();
                float[] newAI       = new float[arrayLength];
                for (int m = 0; m < arrayLength; m++)
                {
                    newAI[m] = bb.ReadSingle();
                }
                if (classID == 0 && Main.npc[id] != null && Main.npc[id].active && Main.npc[id].modNPC != null && Main.npc[id].modNPC is ParentNPC)
                {
                    ((ParentNPC)Main.npc[id].modNPC).SetAI(newAI, aitype);
                }
                else
                if (classID == 1 && Main.projectile[id] != null && Main.projectile[id].active && Main.projectile[id].modProjectile != null && Main.projectile[id].modProjectile is ParentProjectile)
                {
                    ((ParentProjectile)Main.projectile[id].modProjectile).SetAI(newAI, aitype);
                }
                if (Main.netMode == NetmodeID.Server)
                {
                    BaseNet.SyncAI(classID, id, newAI, aitype);
                }
            }
        }