//移動可能なセルを表示して、攻撃可能かの判定を同時に行う private void HighlightMovableCells() { if (deltaTime <= wait) { return; } deltaTime = 0; //移動可能かつプレイヤーに攻撃可能なセル表示 List <DestinationAndAttackDto> DestinationAndAttackDtoList = mainMap.ActiveEnemy.HighlightMovableCells(); if (DestinationAndAttackDtoList.Count == 0) { //攻撃可能範囲にプレイヤーが見つからないので探索モード isAttackable = false; Debug.Log("攻撃不可"); } else { //攻撃範囲にプレイヤーが居るので攻撃モード isAttackable = true; //TODO とりあえず適当な要素を取得するので、また優先順位の判定を作成する DestinationAndAttackDto = DestinationAndAttackDtoList[0]; Debug.Log("攻撃可"); } enemyAIPhase = EnemyAIPhase.MOVING; Debug.Log("enemyAIPhase : " + enemyAIPhase); }
//210211 敵が攻撃可能なセルを取得 private DestinationAndAttackDto GetAttackableCells(int x, int y, Weapon weapon, int enemyId) { //現在のセルを取得 var startCell = cells.First(c => c.X == x && c.Y == y); DestinationAndAttackDto destinationAndAttackDto = null; //現在のセル攻撃可能範囲 取得 第三引数 : 攻撃時なので、敵のセルを選択可能 foreach (var info in GetAttackRenge(startCell, weapon.range, weapon.isCloseAttack)) { //Debug.Log($"プレイヤーを攻撃出来るか確認するセル : X={info.coordinate.x}, Y={info.coordinate.y}"); //210219 攻撃可能セルの色を赤色にする var attackableCell = cells.First(c => c.X == info.coordinate.x && c.Y == info.coordinate.y); //セルが存在して移動可能でなければ(移動可能なセルは赤色にしない) if (attackableCell != null && attackableCell.IsMovable == false) { attackableCell.IsAttackable = true; } //攻撃可能なユニットが存在するか確認 PlayerModel destinationUnit = unitContainer.GetComponentsInChildren <PlayerModel>().FirstOrDefault( c => c.x == info.coordinate.x && c.z == info.coordinate.y); //移動可能範囲に攻撃可能なユニットが居れば if (destinationUnit != null) { Debug.Log($"攻撃可能な座標 :X = {startCell.X} , Y = {startCell.Y} "); Debug.Log("攻撃対象 : " + destinationUnit.unit.name); //攻撃可能なセルを返す //攻撃可能な座標をセット destinationAndAttackDto = new DestinationAndAttackDto(x, y); //攻撃対象のセルをセット Coordinate attackCoordinate = new Coordinate(info.coordinate.x, info.coordinate.y); destinationAndAttackDto.AttackCoordinate = attackCoordinate; } } //移動可能範囲に攻撃可能なユニットが居ない場合はnullが返ってくる return(destinationAndAttackDto); }
/// <summary> /// 敵関連 /// </summary> /// <summary> /// 210212 敵専用移動可能セルを表示しながら、攻撃可能かどうかを判定 /// </summary> /// <param name="x">X座標</param> /// <param name="y">Y座標</param> /// <param name="moveAmount">移動力</param> /// <param name="weapon">武器</param> /// <param name="isWarning">警戒範囲表示モード(紫表示)か</param> /// <param name="enemyId">敵のID</param> /// <returns></returns> public List <DestinationAndAttackDto> HighlightEnemyMovableCells(int x, int y, int moveAmount, Weapon weapon, bool isWarning, int enemyId) { //まず移動可能なセルのハイライトを消す ResetMovableCells(); //200724 渡された座標が最初のセルとなる //FirstはNullが返って来ない物に使うこと var startCell = cells.First(c => c.X == x && c.Y == y); //攻撃可能なセル一覧 List <DestinationAndAttackDto> attackableCellList = new List <DestinationAndAttackDto>(); //移動可能なセルを取得してハイライト処理を行う MoveAmountInfo[] enemyMoveableInfo = GetRemainingMoveAmountInfos(startCell, moveAmount, CalculationMode.ENEMY_MOVE); //移動可能セルは攻撃可能表示したくないので、まず移動可能セルのみ青色にハイライトする foreach (var info in enemyMoveableInfo) { if (isWarning) { //味方ターンで、敵の攻撃可能範囲を表示する時は紫で表示する cells.First(c => c.X == info.coordinate.x && c.Y == info.coordinate.y).SetIsWarning(enemyId); } else { //敵ターンに実際移動する時 //移動可能にしていく trueになるとハイライトが青になる cells.First(c => c.X == info.coordinate.x && c.Y == info.coordinate.y).IsMovable = true; } } //移動可能セルから攻撃対象が存在するか確認を行う処理 foreach (var info in enemyMoveableInfo) { //ここで移動先に既に自分以外の敵がいる場合は、ハイライトはされるが実際は移動しないよう、対象に含まない //でも、自分自身の座標には移動可能にしないとその場から攻撃が出来ない EnemyModel destinationEnemy = enemyContainer.GetComponentsInChildren <EnemyModel>().FirstOrDefault( c => c.x == info.coordinate.x && c.y == info.coordinate.y); //移動先に敵がいる場合、自分自身以外ならそのセルには移動しない if (destinationEnemy != null) { if (destinationEnemy != ActiveEnemy) { Debug.Log($"既に敵が存在するので移動しないセル X={info.coordinate.x}, Y={info.coordinate.y}"); continue; } } //それぞれの移動可能なセルに対して攻撃可能なセルを確認 DestinationAndAttackDto destinationAndAttackDto = GetAttackableCells(info.coordinate.x, info.coordinate.y, weapon, enemyId); if (destinationAndAttackDto != null) { //それぞれのセルから攻撃可能なセルを取得を表示 attackableCellList.Add(destinationAndAttackDto); } } Debug.Log("攻撃可能なセルの数 : " + attackableCellList.Count()); return(attackableCellList); }