public void FindBattleCellsNeighbors() { foreach (GameObject tile in battleCellArray.cellGameObjectArray) { BattleCell t = tile.GetComponent <BattleCell>(); t.FindNeighbors(); } }
public void ResetSelect() { neighborCellsList.Clear(); selectable = false; visited = false; parent = null; distance = 0; }
public void ResetSelectableCells() { foreach (GameObject tile in battleCellArray.cellGameObjectArray) { BattleCell t = tile.GetComponent <BattleCell>(); t.ResetSelect(); } }
public void ExchangePos(BattleCell cellA, BattleCell cellB) { var myPos = MatchManager.Instance.GetCell(cellA.Id).Pos; var tarPos = MatchManager.Instance.GetCell(cellB.Id).Pos; cellA.MoveTo(tarPos); cellB.MoveTo(myPos); MatchManager.Instance.ExchangePos(cellA.Id, cellB.Id); }
public void GetCurrentCell(int i) { foreach (var item in battleCellArray.cellGameObjectArray) { if (item.GetComponent <BattleCell>().heightIndex == EnemiesArray.array[i].enemyHeightIndex && item.GetComponent <BattleCell>().widthIndex == EnemiesArray.array[i].enemyWidthIndex) { currentCell = item.GetComponent <BattleCell>(); } } }
public void EnemyMoves(BattleCell cell) { battleCellArray.cellGameObjectArray[enemyHeightIndex, enemyWidthIndex].GetComponent <BattleCell>().enemyOnCell = false; battleCellArray.cellGameObjectArray[enemyHeightIndex, enemyWidthIndex].GetComponent <BattleCell>().walkable = true; enemyHeightIndex = cell.heightIndex; enemyWidthIndex = cell.widthIndex; gameObject.transform.position = new Vector3(cell.transform.position.x, cell.transform.position.y, -3); cell.enemyOnCell = true; cell.walkable = false; }
private IEnumerator LossHp(BattleCell attacker, BattleCell defender) { yield return(new WaitForSeconds(0.4f)); var damage = ConfigData.GetMonsterConfig(attacker.MonsterId).Atk; if (defender.LossHp(damage)) { ExchangePos(attacker, defender); //死亡直接交换位置 } }
public void MovePlayer() { BattleCell PlayerBattleCellScript = PlayerBattleCell.value.GetComponent <BattleCell>(); ChooseDirection(); gameObject.transform.position = PlayerBattleCell.value.transform.position; playerHeightIndex = PlayerBattleCellScript.heightIndex; playerWidthIndex = PlayerBattleCellScript.widthIndex; playerMoves.ParameterValue = 0; battlePhase.value = "attack"; }
public void Fight(BattleCell attacker, BattleCell defender) { var midPoint = attacker.transform.position * 1 / 4 + defender.transform.position * 3 / 4; Hashtable args = new Hashtable(); args.Add("easeType", iTween.EaseType.easeInOutExpo); //移动的整体时间。如果与speed共存那么优先speed args.Add("time", 0.7f); args.Add("delay", 0.1f); //最终让改对象开始移动 Vector3[] paths = new Vector3[] { midPoint, attacker.transform.position }; args.Add("path", paths); iTween.MoveTo(attacker.gameObject, args); paths = new Vector3[] { midPoint, defender.transform.position }; args["path"] = paths; iTween.MoveTo(defender.gameObject, args); StartCoroutine(LossHp(attacker, defender)); }
public void FindSelectableCells() { if (turn.value == "player") { ResetSelectableCells(); FindBattleCellsNeighbors(); FindPlayerCell(); Queue <BattleCell> process = new Queue <BattleCell>(); process.Enqueue(playerCell); PlayerBattleCell.value.GetComponent <BattleCell>().visited = true; while (process.Count > 0) { BattleCell t = process.Dequeue(); if (!t.playerOnCell) { t.selectable = true; } if (t.distance < playerMoves.ParameterValue) { foreach (BattleCell cell in t.neighborCellsList) { if (!cell.visited) { cell.parent = t; cell.visited = true; cell.distance = 1 + t.distance; process.Enqueue(cell); } } } } } else if (turn.value == "enemies") { for (int i = 0; i < EnemiesArray.array.Count; i++) { ResetSelectableCells(); FindBattleCellsNeighbors(); FindPlayerCell(); GetCurrentCell(i); Queue <BattleCell> process = new Queue <BattleCell>(); process.Enqueue(currentCell); currentCell.GetComponent <BattleCell>().visited = true; while (process.Count > 0) { BattleCell t = process.Dequeue(); foreach (BattleCell cell in t.neighborCellsList) { if (!cell.visited && !cell.enemyOnCell) { cell.parent = t; cell.visited = true; cell.distance = 1 + t.distance; process.Enqueue(cell); } } } List <BattleCell> cellsAroundPlayer = new List <BattleCell>(); if (playerCell.heightIndex != 12) { if (battleCellArray.cellGameObjectArray[playerCell.heightIndex + 1, playerCell.widthIndex].GetComponent <BattleCell>().walkable == true) { cellsAroundPlayer.Add(battleCellArray.cellGameObjectArray[playerCell.heightIndex + 1, playerCell.widthIndex].GetComponent <BattleCell>()); } } if (playerCell.heightIndex != 0) { if (battleCellArray.cellGameObjectArray[playerCell.heightIndex - 1, playerCell.widthIndex].GetComponent <BattleCell>().walkable == true) { cellsAroundPlayer.Add(battleCellArray.cellGameObjectArray[playerCell.heightIndex - 1, playerCell.widthIndex].GetComponent <BattleCell>()); } } if (playerCell.widthIndex != 6) { if (battleCellArray.cellGameObjectArray[playerCell.heightIndex, playerCell.widthIndex + 1].GetComponent <BattleCell>().walkable == true) { cellsAroundPlayer.Add(battleCellArray.cellGameObjectArray[playerCell.heightIndex, playerCell.widthIndex + 1].GetComponent <BattleCell>()); } } if (playerCell.widthIndex != 0) { if (battleCellArray.cellGameObjectArray[playerCell.heightIndex, playerCell.widthIndex - 1].GetComponent <BattleCell>().walkable == true) { cellsAroundPlayer.Add(battleCellArray.cellGameObjectArray[playerCell.heightIndex, playerCell.widthIndex - 1].GetComponent <BattleCell>()); } } if (cellsAroundPlayer.Count > 0) { int tempMin = cellsAroundPlayer[0].distance; BattleCell minDistanceCell = cellsAroundPlayer[0]; for (int x = 0; x < cellsAroundPlayer.Count; x++) { if (tempMin > cellsAroundPlayer[x].distance) { tempMin = cellsAroundPlayer[x].distance; minDistanceCell = cellsAroundPlayer[x]; } } bool farCellFound = false; BattleCell parentCell = minDistanceCell; while (!farCellFound) { if (parentCell.distance > EnemiesArray.array[0].enemyMoves) { parentCell = parentCell.parent; } else { farCellFound = true; } } EnemiesArray.array[i].EnemyMoves(parentCell); } EnemiesArray.array[i].EnemyAttack(); } battlePhase.value = "move"; blockRollDice.Raise(); } }
public void FindPlayerCell() { playerCell = PlayerBattleCell.value.GetComponent <BattleCell>(); }
public void ChooseDirection() { BattleCell PlayerBattleCellScript = PlayerBattleCell.value.GetComponent <BattleCell>(); int tempHeight; int tempWidth; tempHeight = PlayerBattleCellScript.heightIndex - playerHeightIndex; tempWidth = PlayerBattleCellScript.widthIndex - playerWidthIndex; if (Mathf.Abs(tempHeight) > Mathf.Abs(tempWidth)) { if (tempHeight < 0) { RotatePlayerDirection("back"); } else if (tempHeight > 0) { RotatePlayerDirection("front"); } } else if (Mathf.Abs(tempHeight) < Mathf.Abs(tempWidth)) { if (tempWidth < 0) { RotatePlayerDirection("left"); } else if (tempWidth > 0) { RotatePlayerDirection("right"); } } else { if (tempHeight < 0 && tempWidth < 0) { if (playerDirection == "left") { RotatePlayerDirection("left"); } else if (playerDirection == "back") { RotatePlayerDirection("back"); } else { if (Random.Range(0, 2) == 0) { RotatePlayerDirection("left"); } else { RotatePlayerDirection("back"); } } } else if (tempHeight > 0 && tempWidth > 0) { if (playerDirection == "right") { RotatePlayerDirection("right"); } else if (playerDirection == "front") { RotatePlayerDirection("front"); } else { if (Random.Range(0, 2) == 0) { RotatePlayerDirection("right"); } else { RotatePlayerDirection("front"); } } } else if (tempHeight < 0 && tempWidth > 0) { if (playerDirection == "right") { RotatePlayerDirection("right"); } else if (playerDirection == "back") { RotatePlayerDirection("back"); } else { if (Random.Range(0, 2) == 0) { RotatePlayerDirection("right"); } else { RotatePlayerDirection("back"); } } } else if (tempHeight > 0 && tempWidth < 0) { if (playerDirection == "left") { RotatePlayerDirection("left"); } else if (playerDirection == "front") { RotatePlayerDirection("front"); } else { if (Random.Range(0, 2) == 0) { RotatePlayerDirection("left"); } else { RotatePlayerDirection("front"); } } } } }
private void InitPos() { float screenWidth = (transform.root as RectTransform).sizeDelta.x; float screenHeight = (transform.root as RectTransform).sizeDelta.y; float width = screenWidth / BattleConst.MAP_WIDTH; for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int id = i * BattleConst.MAP_WIDTH + m; BattleCell go = Instantiate(mPosRes); go.gameObject.SetActive(true); go.SetHintVisible(false); float scale = width / (go.transform as RectTransform).sizeDelta.x; go.transform.localScale = new Vector3(scale, scale, 1); go.transform.SetParent(battleContainer, false); mPosArr[id] = go; (go.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + m * width, -0.5f * turrentGap - 0.5f * width - i * width + yFix); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickMyPos(id); }; SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele); } } mBase = Instantiate(baseRes); mBase.transform.SetParent(battleContainer, false); mBase.gameObject.SetActive(true); (mBase.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, -0.5f * turrentGap - 0.5f * width - BattleConst.MAP_HEIGHT * width + yFix); for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int id = i * BattleConst.MAP_WIDTH + m; BattleClickGo go = Instantiate(oPosRes); go.gameObject.SetActive(true); float scale = width / (go.transform as RectTransform).sizeDelta.x; go.transform.localScale = new Vector3(scale, scale, 1); go.transform.SetParent(battleContainer, false); oPosArr[id] = go; (go.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - m * width, 0.5f * turrentGap + 0.5f * width + i * width + yFix); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickOppPos(id); }; SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele); } } oBase = Instantiate(baseRes); oBase.transform.SetParent(battleContainer, false); oBase.gameObject.SetActive(true); (oBase.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, 0.5f * turrentGap + 0.5f * width + BattleConst.MAP_HEIGHT * width + yFix); }