public void MoveAfterAttack() { BattleCharactersManager charactersManager = Global.charactersManager; TileMap mapSearch = Global.mapSearch; BattleTilesManager tilesManager = Global.battleManager.tilesManager; List <VTile> vTiles = tilesManager.currentMovingTiles; VTile vTile = mapSearch.GetTile(mCharacter.coordinate); VTile fTile = mapSearch.GetTile(Global.battleManager.oldCoordinate); vTiles.Sort((a, b) => { int vA = mapSearch.GetDistance(a, vTile); int vB = mapSearch.GetDistance(b, vTile); if (vA != vB) { return(vB - vA); } int fA = mapSearch.GetDistance(a, fTile); int fB = mapSearch.GetDistance(b, fTile); return(fA - fB); }); vTile = vTiles[0]; if (charactersManager.GetCharacter(vTile.coordinate) == null) { Global.battleManager.ClickMovingNode(vTile.coordinate); } else { AppManager.CurrentScene.StartCoroutine(Global.battleManager.ActionOverNext()); } }
public BattleManager() { tilesManager = new BattleTilesManager(); calculateManager = new BattleCalculateManager(); aiManager = new AIManager(); breadthFirst = new BreadthFirst(); }
private IEnumerator MoveToNearestTarget() { BattleCharactersManager charactersManager = Global.charactersManager; TileMap mapSearch = Global.mapSearch; BattleTilesManager tilesManager = Global.battleManager.tilesManager; List <VTile> tileList = null; foreach (MCharacter character in charactersManager.mCharacters) { if (character.hp == 0 || character.isHide) { continue; } if (charactersManager.IsSameBelong(mCharacter.belong, character.belong)) { continue; } VTile startTile = mapSearch.GetTile(mCharacter.coordinate); VTile endTile = mapSearch.GetTile(character.coordinate); List <VTile> tiles = Global.aStar.Search(mCharacter, startTile, endTile); if (tiles.Count == 0) { tiles = Global.aStar.Search(mCharacter, startTile, endTile, charactersManager.mCharacters); if (tiles.Count == 0) { Debug.LogError("MoveToNearestTarget search null"); yield return(new WaitForEndOfFrame()); } } if (tileList == null || tileList.Count > tiles.Count) { tileList = tiles; } } for (int i = tileList.Count - 1; i >= 0; i--) { VTile tile = tileList[i]; if (!tilesManager.IsInMovingCurrentTiles(tile.coordinate)) { continue; } MCharacter character = charactersManager.mCharacters.Find(chara => chara.hp > 0 && !chara.isHide && chara.coordinate.Equals(tile.coordinate)); if (character != null) { continue; } Global.battleManager.ClickMovingNode(tile.coordinate); break; } do { yield return(new WaitForEndOfFrame()); }while (Global.battleManager.battleMode == BattleMode.moving); yield return(new WaitForEndOfFrame()); }
private void FindHealTarget(out MCharacter healTarget, out VTile healTile) { BattleCharactersManager charactersManager = Global.charactersManager; BattleTilesManager tilesManager = Global.battleManager.tilesManager; healTarget = null; healTile = null; foreach (MCharacter character in charactersManager.mCharacters) { if (character.hp == 0 || character.isHide) { continue; } if (!charactersManager.IsSameBelong(mCharacter.belong, character.belong)) { continue; } if (character.hp * 1f / character.ability.hpMax > Global.Constant.weak_hp) { continue; } VTile vTile = GetNearestNode(character, tilesManager.currentMovingTiles); bool canAttack = charactersManager.IsInSkillDistance(character.coordinate, vTile.coordinate, mCharacter); if (!canAttack) { continue; } if (healTarget == null) { healTarget = character; healTile = vTile; continue; } if (character.hp < healTarget.hp) { healTarget = character; healTile = vTile; } } }
private void FindAttackTarget() { BattleCalculateManager calculateManager = Global.battleManager.calculateManager; BattleTilesManager tilesManager = Global.battleManager.tilesManager; BattleCharactersManager charactersManager = Global.charactersManager; attackTarget = null; targetTile = null; if (mCharacter.currentSkill == null) { return; } float tileAid = 0; foreach (MCharacter character in charactersManager.mCharacters) { if (character.hp == 0 || character.isHide) { continue; } if (charactersManager.IsSameBelong(mCharacter.belong, character.belong)) { continue; } VTile vTile = GetNearestNode(character, tilesManager.currentMovingTiles); //可否攻击 bool canAttack = charactersManager.IsInSkillDistance(character.coordinate, vTile.coordinate, mCharacter); if (!canAttack) { continue; } if (attackTarget == null) { attackTarget = character; targetTile = vTile; tileAid = 0; continue; } //是否可杀死 bool aCanKill = calculateManager.Hert(mCharacter, attackTarget, targetTile) - attackTarget.hp >= 0; if (aCanKill) { continue; } bool bCanKill = calculateManager.Hert(mCharacter, character, targetTile) - character.hp >= 0; if (!aCanKill && bCanKill) { attackTarget = character; targetTile = vTile; tileAid = 0; continue; } //是否反击 bool aCanCounter = calculateManager.CanCounterAttack(mCharacter, attackTarget, targetTile.coordinate, attackTarget.coordinate); bool bCanCounter = calculateManager.CanCounterAttack(mCharacter, character, vTile.coordinate, character.coordinate); if (!aCanCounter && bCanCounter) { continue; } else if (aCanCounter && !bCanCounter) { attackTarget = character; targetTile = vTile; tileAid = 0; continue; } //地形优势 float aTileAid = tileAid; if (Global.IsFloatZero(aTileAid)) { aTileAid = attackTarget.TileAid(targetTile); } float bTileAid = character.TileAid(vTile); if (aTileAid > bTileAid) { attackTarget = character; targetTile = vTile; tileAid = bTileAid; continue; } } }