// Use this for initialization void Start() { Bind(MapEvent.SELECT_ARMYCARD); Bind(MapEvent.CANCEL_SELECT_ARMYCARD); Bind(MapEvent.SET_OTHER_ARMY); Bind(MapEvent.MOVE_MY_ARMY); Bind(MapEvent.MOVE_OTHER_ARMY); myCharacterCtrl = GetComponent <MyCharacterCtrl>(); myArmyCtrls = GetComponent <MyArmyCtrlManager>(); socketMsg = new SocketMsg(); pointDto = new MapPointDto(); mapMoveDto = new MapMoveDto(); }
/// <summary> /// 处理兵种移动请求 /// </summary> private void processArmyMove(ClientPeer clientPeer, MapMoveDto mapMoveDto) { SingleExecute.Instance.processSingle( () => { if (!UserCache.Instance.IsOnline(clientPeer)) { return; } int uid = UserCache.Instance.GetId(clientPeer); FightRoom fightRoom = FightRoomCache.Instance.GetRoomByUid(uid); //向房间内其他人传送移动信息 fightRoom.Broadcast(OpCode.FIGHT, FightCode.MAP_ARMY_MOVE_SBOD, mapMoveDto, clientPeer); } ); }
/// <summary> /// 处理其他人的兵种移动 /// </summary> /// <param name="mapMoveDto"></param> private void processArmyMove(MapMoveDto mapMoveDto) { Dispatch(AreoCode.MAP, MapEvent.MOVE_OTHER_ARMY, mapMoveDto); }
/// <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); } }