//TODO: 添加判断是否处于遭遇战以使用遭遇战胜利条件判断 //TODO: 等待胜利条件指定单位及战区接口 #region 遭遇战胜利条件 // 胜利条件先这样写着吧,胜利条件看的有点迷迷糊糊 // 里面的指定单位和战区都是遭遇战里面的吧,先空着等待接口 /// <summary> /// 护送某单位到指定战区 /// 判断单位位置是否在指定战区范围内 /// 己方单位先到战区则胜利 /// 敌方单位先到战区则失败 /// 都没到但是己方单位死亡也失败 /// </summary> public void EscortUnitToArea() { //TODO: 获取进入遭遇战后指定单位接口 const int success = 0; const int failure = 1; const int notUnit = -1; GameUnit.GameUnit player = null; // 被护送单位 GameUnit.GameUnit enemy = null; // 敌方单位 int AreaID = 0; // 指定战区id BattleMap.BattleMap battleMap = BattleMap.BattleMap.Instance(); // if (_battleAreaDictionary[AreaID].Contains(currentPos)) // 到达指定战区 // { // Gameplay.Instance().roundProcessController.Win(); // } // else if(player.IsDead()) // 未到达指定战区且死亡则失败 // { // Gameplay.Instance().roundProcessController.Lose(); // } if (battleMap.ProjectUnit(AreaID, player, enemy) == success) { Gameplay.Instance().roundProcessController.Win(); } else if (battleMap.ProjectUnit(AreaID, player, enemy) == failure) { Gameplay.Instance().roundProcessController.Lose(); } if (battleMap.ProjectUnit(AreaID, player, enemy) == notUnit && player.IsDead()) { Gameplay.Instance().roundProcessController.Lose(); } }
/// <summary> /// 击杀指定单位,指定单位死亡则胜利,否则失败 /// </summary> public void KillSpecifyUnit() { GameUnit.GameUnit BeKilledUnit = null; // 指定被击杀单位 //TODO:获取指定的单位的引用,等待接口 if (BeKilledUnit.IsDead()) { Gameplay.Instance().roundProcessController.Win(); } else { Gameplay.Instance().roundProcessController.Lose(); } }
/// <summary> /// 自动选择目标 /// </summary> /// <param name="battleUnitAction"></param> protected override void AutoSelectTarget() { int stopDistance = AtkStopDistance(); //从仇恨列表中确定目标 Unit hatredUnit = null; //地图导航 BattleMap.MapNavigator mapNavigator = BattleMap.BattleMap.Instance().MapNavigator; for (int i = 0; i < hatredRecorder.HatredCount; i++) { hatredUnit = hatredRecorder.GetHatredByIndex(i, i == 0); if (hatredUnit.IsDead()) { //已经排序过,且无法找到还能够行动的单位,就表示场上没有存活的敌方单位了 hatredUnit = null; continue; } //判断这个单位是否可以到达 bool catched = false; //如果这个单位就在攻击范围内,即身边 if (Distance(battleUnit, hatredUnit) <= stopDistance) { toTargetPath.Clear(); targetBattleUnit = hatredUnit; AutoUseAtk(); catched = true; } else { //if (catched = mapNavigator.PathSearch(battleUnit.CurPos, new Vector2(hatredUnit.CurPos.x, hatredUnit.CurPos.y + 1))) // toTargetPath = mapNavigator.Paths; //TODO 把被仇恨单位作为起点 //遍历4个相邻地图块儿,把对于当前单位最近的地图块儿作为终点 Node nodeStart = new Node(hatredUnit.CurPos, hatredUnit.CurPos); //获得A的周边MapBlock List <BattleMapBlock> neighbourBlock = BattleMap.BattleMap.Instance().GetNeighbourBlock(nodeStart); int prevPathCount = int.MaxValue; BattleMapBlock preBattleMapBlock = null; foreach (BattleMapBlock battleMapBlock in neighbourBlock) { if (mapNavigator.PathSearchForAI(battleUnit.CurPos, battleMapBlock.position, this is SingleAutoControllerAtker)) { //找到对于ai单位的最短路径 if (prevPathCount > mapNavigator.Paths.Count) { //更新路径 toTargetPath = mapNavigator.Paths; prevPathCount = mapNavigator.Paths.Count; if (preBattleMapBlock != null) { preBattleMapBlock.RemoveUnit(battleUnit); } battleMapBlock.units_on_me.Add(battleUnit); preBattleMapBlock = battleMapBlock; catched = true; } } } } //寻路不可达 if (!catched) { hatredUnit = null; continue; } else //找到了 { break; } } //没有目标 if (hatredUnit == null) { targetBattleUnit = null; return; } if (battleUnit != null && !hatredUnit.Equals(targetBattleUnit)) { targetBattleUnit = hatredUnit; } }