Exemplo n.º 1
0
 protected override void NetworkCallback(NetworkMessage message)
 {
     if (message.type == 62)
     {
         EnemyHurtMessge hurt = EnemyHurtMessge.GetMessage(message.message);
         enemy.ReduceHP(hurt.hurt);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 发送小怪受到伤害
        /// </summary>
        /// <param name="hurt"></param>
        /// <param name="id"></param>
        /// <param name="listNum"></param>
        public void SendEnemyHurtMsg(float hurt, int id, int listNum)
        {
            byte[] by = EnemyHurtMessge.GetBytes(
                new EnemyHurtMessge(hurt, id, listNum));
            NetworkMessage message = new NetworkMessage(62, NetworkTools.GetLocalIP(), by);

            byte[] bytes = NetworkMessage.GetBytes(message);
            SendMsg(RoomSingle.roomIP, NetworkConstent.UDPServerPort, bytes);
        }
Exemplo n.º 3
0
 public static byte[] GetBytes(EnemyHurtMessge t)
 {
     byte[] bx    = BitConverter.GetBytes(t.hurt);
     byte[] btype = BitConverter.GetBytes(t.enemyType);
     byte[] bnum  = BitConverter.GetBytes(t.num);
     byte[] bytes = new byte[bx.Length + btype.Length + bnum.Length];
     bx.CopyTo(bytes, 0);
     btype.CopyTo(bytes, 4);
     bnum.CopyTo(bytes, 8);
     return(bytes);
 }
Exemplo n.º 4
0
        protected override void GetNetworkMsgCallBack(params object[] obj_arr)
        {
            NetworkMessage message = (NetworkMessage)obj_arr[0];

            if (message.type == 62 && !NetworkTools.GetLocalIP().Equals(message.ip))
            {
                EnemyHurtMessge hurt = EnemyHurtMessge.GetMessage(message.message);
                if (hurt.enemyType == enemy.enemyData.ID && hurt.num == enemy.enemyData.Listnum)
                {
                    AddMessage((NetworkMessage)obj_arr[0]);
                }
            }
        }
Exemplo n.º 5
0
 protected override void NetworkCallback(NetworkMessage message)
 {
     if (message.type == 60)
     {
         EnemyInfoMessage info = EnemyInfoMessage.GetMessage(message.message);
         string           key  = info.enemyType.ToString() + info.num.ToString();
         if (!enemyDic.ContainsKey(key))
         {
             GameObject prefab = Resources.Load <GameObject>("Prefab/Enemy/Enemy_AI_" + info.enemyType);
             GameObject obj    = Instantiate <GameObject>(prefab,
                                                          new Vector3(info.x, info.y, info.z), Quaternion.Euler(info.angleX, info.angleY, info.angleZ), transform);
             NetEnemyBase net = obj.GetComponent <NetEnemyBase>();
             net.SetIDandListNum(info.enemyType, info.num);
             net.SetTarget(info);
             enemyDic.Add(key, net);
         }
     }
     else if (message.type == 61)
     {
         //Debug.Log("同步小怪状态");
         EnemyStateMessage info = EnemyStateMessage.GetMessage(message.message);
         string            key  = info.enemyType.ToString() + info.num.ToString();
         if (enemyDic.ContainsKey(key))
         {
             enemyDic[key].SwitchEnemyState((EnemyState)info.state);
             if (info.state == (int)(EnemyState.Death))
             {
                 enemyDic.Remove(key);
             }
         }
     }
     else if (message.type == 62 && !NetworkTools.GetLocalIP().Equals(message.ip))
     {
         EnemyHurtMessge info = EnemyHurtMessge.GetMessage(message.message);
         string          key  = info.enemyType.ToString() + info.num.ToString();
         if (enemyDic.ContainsKey(key))
         {
             enemyDic[key].ReduceHP(info.hurt);
         }
     }
 }