public bool moveDragon(int prevx, int prevy, int newx, int newy, Vector3 newdragonposition) { Dragon_GameController dcontroller = getDragonController((int)prevx, (int)prevy); //calculate a max range of motion for the given dragon int minx = prevx - (int)dcontroller.dragonattribs.movementfredom; int maxx = prevx + (int)dcontroller.dragonattribs.movementfredom; int miny = prevy - (int)dcontroller.dragonattribs.movementfredom; int maxy = prevy + (int)dcontroller.dragonattribs.movementfredom; //check if the given new pos is well within range if (!(newx >= minx && newx <= maxx && newy >= miny && newy <= maxy)) { return(false); } //reposition dragon in matrix and in its transforms fielddragons[newx, newy] = dcontroller; fielddragons[prevx, prevy] = null; Transform dtransform = dcontroller.gameObject.transform; dtransform.position = newdragonposition; return(true); }
public void SetDragon(int x, int y, Dragon_GameController dragon) { //checking if the index is well within range if (x >= 0 && y >= 0 && x < this.x && y < this.y) { //if occupied then show message if (fielddragons [x, y] == null) { fielddragons [x, y] = dragon; } else { Debug.Log("Will Not overwrite dragon at same place"); } } else { Debug.Log("BattleField_GameData: Index Out of Bound"); } }
public void addDragonToPlayer(Dragon_GameController dragon) { dragon.gameObject.transform.rotation = dragonrotation; dragon.setDragonsPlayer(playerindex); }
private void poolMouseClicks() { //detect mouse click(for spawn) if (!Input.GetMouseButtonDown(0)) { return; } //act upon the current state of the play switch (gstate) { case GameStates.SPAWN: if (battlefield.isMouseInBoard()) { //check if the current dragon index is a valid index if ((uint)currentdragontype >= 0 && (uint)currentdragontype < dragonprefab.dragons.Length) { //the hit point of grid Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); //check if the selected plate is part of spawn plates for player if (!players [turnmanager.currentplayer - 1].isPlateASpawn((uint)gridindex.x, (uint)gridindex.y)) { break; } //if correct then deploy the dragon Dragon_GameController dragoncontroller = dragondeployer.deployDragon(dragonprefab.dragons [(uint)currentdragontype], currentdragontype, battlefield.getMouseWorldposonBoard()); //add dragon to the player players [turnmanager.currentplayer - 1].addDragonToPlayer(dragoncontroller); //update chancges to the battlefield data battlefieldgamedata.SetDragon((int)gridindex.x, (int)gridindex.y, dragoncontroller); } } break; case GameStates.SPELL_DRAGONSELECT: if (battlefield.isMouseInBoard()) { //get the dragon at the clicked point on board(nothing if null) //not checking for repition right now Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); Dragon dragon = null; if (spelldeployer.isSpellSelfEffecting()) { dragon = battlefieldgamedata.getDragonOfPlayer((int)gridindex.x, (int)gridindex.y, (uint)(turnmanager.currentplayer - 1)); } else { dragon = battlefieldgamedata.getDragonNotOfPlayer((int)gridindex.x, (int)gridindex.y, (uint)(turnmanager.currentplayer - 1)); } if (dragon != null) { utility_listofdragons.Add(dragon); //terminate spell dragon selection proocess if (utility_listofdragons.Count >= spelldeployer.getExpectedEffectedDragonCount()) { gstate = GameStates.NONE; Debug.Log("Max selected"); } } } break; case GameStates.MOVEMENT_DRAGONSELECT: if (battlefield.isMouseInBoard()) { //select a single dragon on board Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); Dragon dragon = battlefieldgamedata.getDragonOfPlayer((int)gridindex.x, (int)gridindex.y, (uint)(turnmanager.currentplayer - 1)); if (dragon != null) { utility_tileindex = gridindex; gstate = GameStates.MOVEMENT_FINALTILESELECT; } } break; case GameStates.MOVEMENT_FINALTILESELECT: if (battlefield.isMouseInBoard()) { //select a final tile to move the previous dragon to on board Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); if (battlefieldgamedata.moveDragon((int)utility_tileindex.x, (int)utility_tileindex.y, (int)gridindex.x, (int)gridindex.y, battlefield.getMouseWorldposonBoard())) { gstate = GameStates.NONE; } } break; case GameStates.ATTACK_DRAGONSELECT: if (battlefield.isMouseInBoard()) { //select a single dragon on board Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); Dragon dragon = battlefieldgamedata.getDragonOfPlayer((int)gridindex.x, (int)gridindex.y, (uint)(turnmanager.currentplayer - 1)); if (dragon != null) { utility_tileindex = gridindex; gstate = GameStates.NONE; //pass the message to ui controls buttoncontrols.showAttackPane(); } } break; case GameStates.ATTACK_AFFECTEDDRAGONSELECT: if (battlefield.isMouseInBoard()) { //select a single dragon on board Vector3 mousehitpoint = battlefield.getRayCastHitPoint(); Vector2 gridindex = battlefield.getGridIndex(mousehitpoint); Dragon dragon = null; //only get dragons that are in range if (battlefieldgamedata.isTileInRange((int)gridindex.x, (int)gridindex.y, (int)utility_tileindex.x, (int)utility_tileindex.y, (int)attackdeployer.getRange())) { dragon = battlefieldgamedata.getDragonNotOfPlayer((int)gridindex.x, (int)gridindex.y, (uint)(turnmanager.currentplayer - 1)); } if (dragon != null) { utility_listofdragons.Add(dragon); if (utility_listofdragons.Count >= attackdeployer.getAffectedDragonCount()) { gstate = GameStates.NONE; deployAttack(); } } } break; } }