public Tile[,] loadChunkFromText(TextAsset file, int chunkX, int chunkY) { Tile[,] chunk = new Tile[chunkSize, chunkSize]; string[] lines = file.text.Split('\n'); for (int y = 0; y < chunkSize; y++) { for (int x = 0; x < chunkSize; x++) { char thisChar = lines [chunkSize - y - 1][x]; //in unity, higher Y means up, but in text higher y means down so we need ot reverse it //cover Tile.Cover cover = Tile.Cover.None; if (thisChar == '#') { cover = Tile.Cover.Full; } if (thisChar == '*') { cover = Tile.Cover.Part; } chunk [x, y] = new Tile(cover, Tile.SpawnProperty.None, GameManagerTacticsInterface.instance.gm); } } return(chunk); }
public void setPotentialTargetInfoTextForAttack(Unit unit, int base_damage) { string text = "Card +" + base_damage + "\n"; //check my charms for (int i = Owner.Charms.Count - 1; i >= 0; i--) { text += Owner.Charms [i].getDamageModifierText(this, unit); } //check if the unit has any charms that would alter damage values int totalPrevention = 0; for (int i = unit.Charms.Count - 1; i >= 0; i--) { text += unit.Charms [i].getDamagePreventionText(this, Owner); totalPrevention += unit.Charms [i].getDamageTakenMod(this, Owner); } //calculate cover Tile.Cover coverVal = Owner.board.getCover(Owner, unit); text += getInfoStringForCover(coverVal); //print the total int totalDamage = calculateAttackDamageToUnit(unit, base_damage) + totalPrevention; //set the target info text Owner.GM.targetInfoText.turnOn(text, totalDamage, unit); }
public Tile[,] loadLevelFromText(TextAsset file) { string[] lines = file.text.Split('\n'); int gridW = lines [0].Length; int gridH = lines.Length; Tile[,] grid = new Tile[gridW, gridH]; for (int y = 0; y < gridH; y++) { for (int x = 0; x < gridW; x++) { char thisChar = lines [gridH - y - 1][x]; //in unity, higher Y means up, but in text higher y means down so we need ot reverse it //cover Tile.Cover cover = Tile.Cover.None; if (thisChar == '#') { cover = Tile.Cover.Full; } if (thisChar == '*') { cover = Tile.Cover.Part; } //should anything be able to spawn on this tiles? (or is it the exit?) Tile.SpawnProperty spawnProperty = Tile.SpawnProperty.None; if (thisChar == 'P') { spawnProperty = Tile.SpawnProperty.Player; } if (thisChar == 'F') { spawnProperty = Tile.SpawnProperty.Foe; } if (thisChar == 'G') { spawnProperty = Tile.SpawnProperty.Exit; } if (thisChar == '$') { spawnProperty = Tile.SpawnProperty.StoreKey; } //make the tile grid [x, y] = new Tile(cover, spawnProperty, GameManagerTacticsInterface.instance.gm); grid [x, y].finalizeSetup(x, y); } } return(grid); }
public string getInfoStringForCover(Tile.Cover coverVal) { if (coverVal == Tile.Cover.Full) { return("Full Cover: x0.5"); } if (coverVal == Tile.Cover.Part) { return("Part Cover: -1"); } return("No Cover"); }
void turnOnCoverIcons() { //do nothing if this tile is cover if ((int)tile.CoverVal > 0) { return; } //go through and check adjacent tiles for (int i = 0; i < coverIconSpriteRend.Length; i++) { if (tile.Adjacent [i] != null) { if ((int)tile.Adjacent [i].CoverVal > 0) { coverIconSpriteRend [i].enabled = true; coverIconSpriteRend [i].sprite = coverIconSprites [(int)tile.Adjacent [i].CoverVal]; } } } //if the lowest cover (from AI units) to this spot is none, than we are exposed List <Unit> enemies = GameManagerTacticsInterface.instance.gm.getAIUnits(); int lowestCover = (int)Tile.Cover.Full; foreach (Unit enemy in enemies) { if (enemy.getIsVisibleToPlayer()) { List <Tile> visible = GameManagerTacticsInterface.instance.gm.board.getTilesInVisibleRange(enemy.CurTile, enemy.getSightRange() + 1); if (visible.Contains(tile)) { Tile.Cover thisCover = GameManagerTacticsInterface.instance.gm.board.getCover(enemy.CurTile, tile); if ((int)thisCover < lowestCover) { lowestCover = (int)thisCover; } } } } Color colToUse = lowestCover == (int)Tile.Cover.None ? coverColExposed : coverColorGood; for (int i = 0; i < coverIconSpriteRend.Length; i++) { coverIconSpriteRend [i].color = colToUse; } }
void AddCover(TileInput tileInput) { Tile tile = GetTile(Vector3Int.RoundToInt(tileInput.transform.position)); tile.TileObject = tileInput.gameObject; if (tile == null) { Debug.Log(tileInput.transform.position); } Tile.Cover c = tile.cover; c.negativeX = Math.Max(c.negativeX, tileInput.negativeX); c.positiveX = Math.Max(c.positiveX, tileInput.positiveX); c.negativeY = Math.Max(c.negativeY, tileInput.negativeY); c.positiveY = Math.Max(c.positiveY, tileInput.positiveY); c.negativeZ = Math.Max(c.negativeX, tileInput.negativeZ); c.positiveZ = Math.Max(c.positiveZ, tileInput.positiveZ); }
public int calculateAttackDamageToUnit(Unit unit, int base_damage) { int damageVal = base_damage; for (int i = Owner.Charms.Count - 1; i >= 0; i--) { damageVal += Owner.Charms [i].getDamageMod(this, unit); } Tile.Cover coverVal = Owner.board.getCover(Owner, unit); damageVal = Owner.board.getNewDamageValFromCover(damageVal, coverVal); if (damageVal < 0) { damageVal = 0; } //Debug.Log ("cover: " + coverVal + " damage: " + damageVal); return(damageVal); }
//checking move values public int GenericMovementCardCheckMoveVal(MoveInfo move, Board board, float maxRange) { Unit unit = board.units [move.unitID]; int moveVal = 0; Tile targetTile = board.Grid [move.targetTilePos.x, move.targetTilePos.y]; float highestPreferedDist = unit.aiProfile.preferedDistToClosestEnemy + unit.aiProfile.acceptableDistanceRangeToClosestEnemy; //let's figure out who our enemies are Profiler.BeginSample("sorting allies and foes for move"); List <Unit> enemies = new List <Unit> (); bool rootingForAI = !unit.isPlayerControlled; foreach (Unit u in board.units) { if (u.isPlayerControlled == rootingForAI) { enemies.Add(u); } } Profiler.EndSample(); //let's get the closest distance for this target float newCloseDist = 99999; float curCloseDist = 99999; foreach (Unit foe in enemies) { float dist = board.dm.getDist(move.targetTilePos, foe.CurTile.Pos); if (dist < newCloseDist) { newCloseDist = dist; } float curDist = board.dm.getDist(unit.CurTile.Pos, foe.CurTile.Pos); if (curDist < curCloseDist) { curCloseDist = curDist; } } //avoid moves that are further away than the max prefered dist and further away than we are now //no cowards! if (!(newCloseDist > highestPreferedDist && newCloseDist > curCloseDist)) { moveVal++; } //if the move would put us at just about the maximum distance, that's cool too. Again, no cowards float moveDist = owner.board.dm.getDist(unit.CurTile.Pos, move.targetTilePos); if (moveDist > maxRange - 1 && newCloseDist < curCloseDist) { moveVal++; } //is there cover (or would the move put us very close to a foe since many units like that) Tile.Cover lowestCover = targetTile.getHighestAdjacentCover(); bool nextToFoe = newCloseDist < 2.5f; if ((int)lowestCover > (int)Tile.Cover.None || nextToFoe) { moveVal++; } //testing // if (moveVal == 2) { // targetTile.setHighlighted (true, Color.green); // } // if (moveVal == 1) { // targetTile.setHighlighted (true, Color.yellow); // } // if (moveVal == 0) { // targetTile.setHighlighted (true, Color.red); // } return(moveVal); }