예제 #1
0
 /// <summary>
 /// 移动自己的单位
 /// </summary>
 /// <param name="originalCtral"></param>
 /// <param name="movepointctrl"></param>
 /// <param name="armyCard"></param>
 /// <param name="armyPrefab"></param>
 private void moveArmy(ref MapPointCtrl originalCtral, ref MapPointCtrl movepointctrl, CardDto armyCard, ref GameObject armyPrefab)
 {
     if (armyCard.MoveType == ArmyMoveType.LAND)
     {
         //如果是陆地单位
         //设置陆地单位
         //movepointctrl.SetLandArmy(armyPrefab);
         movepointctrl.MoveLandArmy(ref armyPrefab, armyCard.Race, armyCard.Name, true);
         //movepointctrl.LandArmyRace = armyCard.Race;
         //movepointctrl.LandArmyName = armyCard.Name;
         //移除原来地块上的兵种
         removeArmy(ref originalCtral, armyCard);
         //向服务器发送消息
         mapMoveDto.Change(originalCtral.mapPoint, movepointctrl.mapPoint, armyCard.MoveType);
         socketMsg.Change(OpCode.FIGHT, FightCode.MAP_ARMY_MOVE_CREQ, mapMoveDto);
         Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
     }
     else if (armyCard.MoveType == ArmyMoveType.SKY)
     {
         //如果是飞行单位
         //设置飞行单位
         //movepointctrl.SetSkyArmy(armyPrefab);
         movepointctrl.MoveSkyArmy(ref armyPrefab, armyCard.Race, armyCard.Name, true);
         //movepointctrl.SkyArmyRace = armyCard.Race;
         //movepointctrl.SkyArmyName = armyCard.Name;
         //移除原来地块上的兵种
         removeArmy(ref originalCtral, armyCard);
         //向服务器发送消息
         mapMoveDto.Change(originalCtral.mapPoint, movepointctrl.mapPoint, armyCard.MoveType);
         socketMsg.Change(OpCode.FIGHT, FightCode.MAP_ARMY_MOVE_CREQ, mapMoveDto);
         Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
     }
 }
예제 #2
0
    /// <summary>
    /// 处理其他人的兵种移动
    /// </summary>
    /// <param name="mapMoveDto"></param>
    private void processMoveOtherArmy(MapMoveDto mapMoveDto)
    {
        //镜像对称
        int totalX = 12;
        int totalZ = 8;

        int Originalx = mapMoveDto.OriginalMapPoint.X;
        int Originalz = mapMoveDto.OriginalMapPoint.Z;

        int MoveX = mapMoveDto.MoveMapPoint.X;
        int MoveZ = mapMoveDto.MoveMapPoint.Z;

        int OtherOriginalx = totalX - Originalx;
        int OtherOriginalz = totalZ - Originalz;//对方兵种真实位置
        int OtherMoveX     = totalX - MoveX;
        int OtherMoveZ     = totalZ - MoveZ;

        MapPointCtrl  OriginalPointCtrl = null;
        MapPointCtrl  MovePointCtrl     = null;
        GameObject    Army          = null;
        OtherArmyCtrl otherArmyCtrl = null;

        foreach (var item in MapManager.mapPointCtrls)
        {
            if (item.mapPoint.X == OtherOriginalx && item.mapPoint.Z == OtherOriginalz)
            {
                OriginalPointCtrl = item;
            }
            else if (item.mapPoint.X == OtherMoveX && item.mapPoint.Z == OtherMoveZ)
            {
                MovePointCtrl = item;
            }

            if (OriginalPointCtrl != null && MovePointCtrl != null)
            {
                break;
            }
        }


        //fixbug已解决 只通过坐标选择了敌方单位
        foreach (var item in OtherArmyCtrlManager.OtherArmyCtrlList)
        {
            if (item.transform.position.x == OtherOriginalx && item.transform.position.z == OtherOriginalz &&
                item.armyState.MoveType == mapMoveDto.MoveType)
            {
                Army          = item.gameObject;
                otherArmyCtrl = Army.GetComponent <OtherArmyCtrl>();
            }
        }

        if (mapMoveDto.MoveType == ArmyMoveType.LAND)
        {
            //如果是陆地单位
            OriginalPointCtrl.RemoveLandArmy();
            MovePointCtrl.MoveLandArmy(ref Army, otherArmyCtrl.armyState.Race, otherArmyCtrl.armyState.Name, false);
            otherArmyCtrl.Move(MovePointCtrl.mapPoint, MovePointCtrl);
        }
        else if (mapMoveDto.MoveType == ArmyMoveType.SKY)
        {
            OriginalPointCtrl.RemoveSkyArmy();
            MovePointCtrl.MoveSkyArmy(ref Army, otherArmyCtrl.armyState.Race, otherArmyCtrl.armyState.Name, false);
            otherArmyCtrl.Move(MovePointCtrl.mapPoint, MovePointCtrl);
        }
    }