void KillArmy(CombatMonsterGroup group) { int playerId = group.playerId; armies.Remove(group); TimelineTurn turn = GetTimelineItem(group.armyId); GameObject army = GetArmyObject(group.armyId); Destroy(army); Destroy(group.gameObject); Destroy(turn.gameObject); int count = CountPlayerArmies(playerId) - 1; if (count == 0) { combatOver = true; if (playerId == 0) { lostCanvas.SetActive(true); } else { wonCanvas.SetActive(true); } } }
void NextTurn() { TimelineTurn turn = timeline.transform.GetChild(0).GetComponent <TimelineTurn>(); currentPlayer = turn.group.playerId; turnTitle.GetComponent <Text>().text = GetTurnTitle(currentPlayer); if (currentArmy) { currentArmy.SetColor(new Color(1.0f, 1.0f, 1.0f, 1.0f)); } currentArmy = turn.group; currentArmy.SetColor(new Color(0.3f, 0.3f, 0.6f, 1.0f)); currentArmy.hasMoved = false; currentArmy.hasAttacked = false; Camera.main.GetComponent <CameraController>().MoveTo(currentArmy.transform.position + new Vector3(0.0f, 0.0f, -3.0f)); pathfinder.SetTerrain(terrainPassable); List <Vector2i> tilesInRange = pathfinder.GetInRange(currentArmy.gamePosition, Creatures.Get(currentArmy.creatureId).speed); ClearHighlightedTiles(); HighlightTiles(tilesInRange); pathfinder.SetTerrain(GetPassableTerrain()); if (currentPlayer != 0) { computerTurnStartDelay = true; computerTurnStartCurrent = 0.0f; } }
void PrepareArmies() { armies.Sort(delegate(CombatMonsterGroup a, CombatMonsterGroup b) { if (a.initiative > b.initiative) { return(-1); } if (b.initiative < a.initiative) { return(1); } return(0); }); for (int i = 0; i < armies.Count; i++) { TimelineTurn turn = Instantiate(timelineTurnPrefab, timeline.transform); turn.group = armies[i]; armies[i].armyId = i; turn.combatGroupId = i; turn.GetComponentInChildren <Text>().text = armies[i].count.ToString(); if (turn.group.playerId == 0) { turn.GetComponentInChildren <Text>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f); turn.GetComponentInChildren <Outline>().effectColor = new Color(0.0f, 0.0f, 0.0f, 0.5f); } else { turn.GetComponentInChildren <Text>().color = new Color(0.0f, 0.0f, 0.0f, 1.0f); turn.GetComponentInChildren <Outline>().effectColor = new Color(1.0f, 1.0f, 1.0f, 0.5f); } } }
void HoverTile() { Vector3 mousePosition = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Tile") { Tile tile = hit.collider.GetComponent <Tile>(); bool isthere = GetArmyAt(tile.gamePosition) == null; string has = isthere ? "true" : "false"; debugPosition.text = tile.gamePosition.ToString() + ": " + has; CombatMonsterGroup group = GetArmyAt(tile.gamePosition); if (group != null) { int armyId = group.armyId; TimelineTurn turn = GetTimelineItem(armyId); turn.SetColor(new Color(0.75f, 0.75f, 0.0f, 0.4f)); group.SetColor(new Color(0.75f, 0.75f, 0.0f)); string contextString = ""; Creature creature = Creatures.Get(group.creatureId); if (group.playerId != 0) { contextString = GetChanceToHit(Creatures.Get(currentArmy.creatureId).attack, creature.defense).ToString() + "%\n"; } contextString += "A: " + creature.attack + "\nD: " + creature.defense + "\nDMG: " + creature.damage + "\nSPD: " + creature.speed; ShowContext(contextString, group.transform.position); } else { HideContext(); } tile.GetComponent <Renderer>().material.color = new Color(0.2f, 0.2f, 0.2f, 1.0f); if (hoverTile && hoverTile.gamePosition != tile.gamePosition) { ClearHoverTile(); } hoverTile = tile; } else { ClearHoverTile(); HideContext(); } } else { ClearHoverTile(); HideContext(); } }
TimelineTurn GetTimelineItem(int armyId) { for (int i = 0; i < timeline.transform.childCount; i++) { TimelineTurn turn = timeline.transform.GetChild(i).GetComponent <TimelineTurn>(); if (turn.combatGroupId == armyId) { return(turn); } } return(null); }
void ClearHoverTile() { if (hoverTile == null) { return; } bool highlighted = false; for (int i = 0; i < highlightedTiles.Count; i++) { if (highlightedTiles[i] == hoverTile) { highlighted = true; break; } } if (highlighted) { hoverTile.GetComponent <Renderer>().material.color = new Color(0.3f, 0.3f, 0.3f, 1.0f); } else { hoverTile.GetComponent <Renderer>().material.color = new Color(0.375f, 0.375f, 0.375f, 1.0f); } CombatMonsterGroup group = GetArmyAt(hoverTile.gamePosition); hoverTile = null; debugPosition.text = ""; if (group == null) { return; } if (group.dead) { return; } TimelineTurn turn = GetTimelineItem(group.armyId); turn.SetColor(new Color(1.0f, 1.0f, 1.0f, 0.4f)); if (currentArmy == group) { group.SetColor(new Color(0.3f, 0.3f, 0.6f, 1.0f)); } else { group.SetColor(new Color(1.0f, 1.0f, 1.0f)); } }
void UpdateTimelineItem(CombatMonsterGroup group) { TimelineTurn turn = GetTimelineItem(group.armyId); if (!turn) { Debug.Log("No turn found for this army."); return; } turn.GetComponentInChildren <Text>().text = group.count.ToString(); if (group.dead) { turn.GetComponentInChildren <Image>().color = new Color(1.0f, 0.0f, 0.0f, 1.0f); } }