Exemple #1
0
    //public void ShootBullet(BulletInfo bullet)
    //{
    //    //子弹的拥有者的旋转角度
    //    Vector3 bulletRotate = ActorList[bullet.userIndex].myRotationInfo.Rotation;
    //    Vector2 bullet2D = new Vector2(bullet.pos.x, bullet.pos.z);
    //    //子弹相对落地点(半径以内的x,y)
    //    Vector2 sPos = new Vector2(
    //        RoomActor.ShootRadius * Mathf.Sin((Mathf.PI / 180) * bulletRotate.y),
    //        RoomActor.ShootRadius * Mathf.Cos((Mathf.PI / 180) * bulletRotate.y));
    //    //子弹世界落地点
    //    Vector2 bulletWorldPos = sPos + bullet2D;


    //    foreach (var item in ActorList)//遍历是否射中其他玩家
    //    {
    //        bool isShooted = false;
    //        if (item.Value == null)
    //            continue;
    //        if (item.Value.UniqueID == bullet.userIndex)//子弹不检测自身
    //            continue;
    //        RoomActor actor = item.Value;
    //        //待碰撞人物的顶视图世界坐标
    //        Vector2 cP = new Vector2(actor.MyMoveInfo.Pos.x, actor.MyMoveInfo.Pos.z);
    //        //子弹发射点和待碰撞人物距离
    //        float bscDistance = Vector2.Distance(bullet2D, cP);

    //        //子弹射击方向世界角度
    //        float shootRotate = bulletRotate.y;
    //        shootRotate = 90 - shootRotate;//转换模型旋转角度到世界坐标角度
    //        BackPositiveOfAngle(ref shootRotate);//转换负数角度成正数角度
    //        //射击点到人物的世界角度
    //        float middleAngle = Mathf.Atan2(actor.MyMoveInfo.Pos.z - bullet.pos.z, actor.MyMoveInfo.Pos.x - bullet.pos.x) * 180 / Mathf.PI;
    //        BackPositiveOfAngle(ref middleAngle);
    //        //射击点到人物边缘的世界角度
    //        float sideAngle = Mathf.Atan2(RoomActor.ModelRadius, bscDistance) * 180 / Mathf.PI;
    //        BackPositiveOfAngle(ref sideAngle);
    //        float angleMin = (middleAngle - sideAngle) > (middleAngle + sideAngle) ? (middleAngle + sideAngle) : (middleAngle - sideAngle);
    //        float angleMax = (middleAngle - sideAngle) > (middleAngle + sideAngle) ? (middleAngle - sideAngle) : (middleAngle + sideAngle);


    //        //判断待射击人物的夹角(计算射击点到人物边缘的角度)子弹在朝向模型
    //        if (shootRotate > angleMin && shootRotate < angleMax)
    //        {
    //            if (bscDistance <= RoomActor.ShootRadius)//待检测人物的中心点在射击半径上或内
    //            {
    //                isShooted = true;
    //            }
    //            else if (bscDistance < RoomActor.ShootRadius + RoomActor.ModelRadius)//子弹落在2个人物之间,正好是射击待碰撞人物中心点,最短距离
    //            {
    //                //判断子弹落地点是否在待检测人物半径内
    //                if (Vector2.Distance(bulletWorldPos, cP) <= RoomActor.ModelRadius)
    //                {
    //                    isShooted = true;
    //                }
    //            }
    //        }
    //        //射中人物
    //        if (isShooted)
    //        {
    //            Log4Debug("射中人物:" + actor.UniqueID);
    //            TeamType bulletType = BackTeamTypeByUnique(bullet.userIndex);
    //            RoomActorUpdate hit = new RoomActorUpdate() { userIndex = actor.UniqueID, update = (int)bulletType + "" };
    //            byte[] message = SerializeHelper.ConvertToByte(hit.GetSendInfo());
    //            //广播
    //            BoardcastMessage(MessageConvention.shootBullet, message);
    //            return;
    //        }
    //    }
    //    //Log4Debug("子弹落地点:" + bulletWorldPos);
    //    //子弹碰撞方块
    //    foreach (KeyValuePair<int, BoxInfo> item in BoxList)
    //    {
    //        Vector2 boxPos = new Vector2(item.Value.position.x, item.Value.position.z);
    //        Vector2 boxScale = new Vector2(item.Value.scale.x, item.Value.scale.z);

    //        if (
    //            bulletWorldPos.x > boxPos.x - (float)(boxScale.x / 2) &&
    //            bulletWorldPos.x <= boxPos.x + (float)(boxScale.x / 2) &&
    //            bulletWorldPos.y > boxPos.y - (float)(boxScale.y / 2) &&
    //            bulletWorldPos.y <= boxPos.y + (float)(boxScale.y / 2)
    //            )//顶视图看是在方格内的
    //        {
    //            Log4Debug("子弹落点:(" + bulletWorldPos.x + "," + bulletWorldPos.y + ") 射中方块坐标:(" + item.Value.position.x + "," + item.Value.position.z + ")");
    //            //设置色块拥有者
    //            item.Value.ownerIndex = bullet.userIndex;
    //            //广播发送消息
    //            RoomActorUpdate hit = new RoomActorUpdate() { userIndex = bullet.userIndex, update = item.Key + "" };
    //            byte[] message = SerializeHelper.ConvertToByte(hit.GetSendInfo());
    //            //射中地板方块
    //            BoardcastMessage(MessageConvention.updateBox, message);
    //            return;
    //        }
    //    }
    //    //
    //}
    public void UpdateBulletInfo(BulletInfo bulletInfo)
    {
        byte[]       message  = null;
        MessageXieYi xieyi    = null;
        int          boxIndex = -1;

        //
        switch (bulletInfo.shootTag)
        {
        case ShootTag.Box:
            //设置色块拥有者
            lock (BoxList)
            {
                boxIndex = int.Parse(bulletInfo.shootInfo);

                BoxInfo boxInfo = new BoxInfo()
                {
                    ownerIndex = -1, myIndex = boxIndex
                };
                BoxList.AddOrUpdate(boxIndex, boxInfo, (key, oldValue) => boxInfo);

                if (BoxList[boxIndex].ownerIndex < 0)
                {
                    BoxList[boxIndex].ownerIndex = bulletInfo.userIndex;
                    //生成buff
                    BuffInfo buffInfo = new BuffInfo()
                    {
                        ownerIndex = -1, myIndex = BuffIndex
                    };
                    lock (BuffList)
                    {
                        buffInfo.boxIndex = boxIndex;
                        buffInfo.type     = RandomBuffType();//随机一个buff类型
                        BuffList.AddOrUpdate(BuffIndex, buffInfo, (key, oldValue) => buffInfo);
                        BuffIndex++;
                    }
                    Log4Debug("在盒子编号->" + boxIndex + " 掉落Buff,编号->" + buffInfo.myIndex + ",类型->" + buffInfo.type);
                    //保存子弹消息
                    message = SerializeHelper.Serialize <BulletInfo>(bulletInfo);
                    xieyi   = new MessageXieYi((byte)MessageConvention.bulletInfo, 0, message);
                    SetRecondFrame(xieyi.ToBytes());
                    //保存Buff消息
                    message = SerializeHelper.Serialize <BuffInfo>(buffInfo);
                    xieyi   = new MessageXieYi((byte)MessageConvention.createBuff, 0, message);
                    SetRecondFrame(xieyi.ToBytes());
                }
                else    //该色块已被其他人击碎
                {
                    return;
                }
            }
            break;

        case ShootTag.Character:
            //
            int shootedIndex = int.Parse(bulletInfo.shootInfo);
            if (ActorList[shootedIndex].MyTeam == ActorList[bulletInfo.userIndex].MyTeam)
            {
                return;
            }
            if (ActorList[shootedIndex].CurState == RoomActorState.Gaming)
            {
                //增加击杀数
                ActorList[bulletInfo.userIndex].KillCount++;
                if (CurState == RoomActorState.Gaming)
                {
                    message = SerializeHelper.Serialize <List <RoomActor> >(new List <RoomActor>(ActorList.Values));
                    BoardcastMessage(MessageConvention.getRoommateInfo, message);
                }
                //改变被射击者状态
                RoomActorUpdate dead = new RoomActorUpdate()
                {
                    userIndex = shootedIndex,
                    update    = (int)RoomActorState.Dead + ""
                };
                UpdateState(dead);
            }
            else if (ActorList[shootedIndex].CurState == RoomActorState.Invincible)
            {
                Log4Debug("射击者站位:" + bulletInfo.userIndex + " 攻击无敌站位:->" + shootedIndex);
            }
            else
            {
                Log4Debug("射击者站位:" + bulletInfo.userIndex + " 正在鞭尸位置->" + shootedIndex);
            }
            //保存子弹消息
            message = SerializeHelper.Serialize <BulletInfo>(bulletInfo);
            xieyi   = new MessageXieYi((byte)MessageConvention.bulletInfo, 0, message);
            SetRecondFrame(xieyi.ToBytes());
            break;

        case ShootTag.Wall:
            //打中墙的消息就不存了
            break;

        case ShootTag.Buff:
            int buffIndex = int.Parse(bulletInfo.shootInfo);
            //Log4Debug("站位:" + bulletInfo.userIndex + " 请求拾取Buff->" + buffIndex);
            lock (BuffList)
            {
                if (BuffList[buffIndex].ownerIndex < 0)
                {
                    BuffList[buffIndex].ownerIndex = bulletInfo.userIndex;
                    Log4Debug("站位:" + bulletInfo.userIndex + " 拾取了Buff->" + buffIndex);
                }
                else    //该buff已被其他人加成
                {
                    return;
                }
            }
            //保存Buff消息
            message = SerializeHelper.Serialize <BuffInfo>(BuffList[buffIndex]);
            xieyi   = new MessageXieYi((byte)MessageConvention.getBuff, 0, message);
            SetRecondFrame(xieyi.ToBytes());
            break;
        }


        //广播发送消息
        //byte[] message = SerializeHelper.ConvertToByte(bulletInfo));
        //BoardcastMessage(MessageConvention.bulletInfo, message);
    }