Пример #1
0
 /*
  * Used to sync custom ai float arrays. (the npc or projectile requires a method called 'public void SetAI(float[] ai, int type)' that sets the ai for this to work)
  */
 public static void SyncAI(int entType, int id, float[] ai, int aitype)
 {
     object[] ai2 = new object[ai.Length + 4];
     ai2[0] = (byte)entType;
     ai2[1] = (short)id;
     ai2[2] = (byte)aitype;
     ai2[3] = (byte)ai.Length;
     for (int m = 4; m < ai2.Length; m++)
     {
         ai2[m] = ai[m - 4];
     }
     MNet.SendBaseNetMessage(1, ai2);
 }
Пример #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);
                }
            }
        }