// Start is called before the first frame update void Start() { // start at whatever game control says we should start FactionControl.Instance.turn = GameControl.Instance.startingPlayer; FactionControl.Instance.players = factions.Count; GameControl.Instance.Initialize(players - 1); playerTurns = new int[players]; playerChars = new List <int> [players]; // give everyone their elader for (int i = 0; i < playerChars.Length; i++) { if (factions[i].leader != null) { Transform instance = GameControl.Instance.Spawn(factions[i].leader); Chararcter leader = instance.GetComponent <Chararcter>(); instance.name = "unit" + leader.id; leader.owner = i; // make sure the leader now points to instance not prefab factions[i].leader = leader; AddChararcter(i, leader); } } startPlayerTurn(turn); }
/* Tile selection */ void Select() { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider != null) { // clear previous selection if (lastTileClicked != null) { resetTileColor(lastTileClicked); } lastTileClicked = hit.collider.transform.GetComponent <GameTile>(); hit.collider.transform.GetComponent <SpriteRenderer>().color = Color.red; if (lastTileClicked.occupier >= 0) { Chararcter unit = GameObject.Find("unit" + lastTileClicked.occupier).GetComponent <Chararcter>(); setSelection(unit); } else { ChillLastPath(); selected = null; selectionMenu.HideSkills(); selectionMenu.showHide(false); } } }
private void AddChararcter(int ownerIndex, Chararcter recruit) { // adding to the list of existing characters if (playerChars[ownerIndex] == null) { playerChars[ownerIndex] = new List <int>(); } playerChars[ownerIndex].Add(recruit.id); }
public Transform Spawn(Chararcter character, ICoordenate at = null) { GameTile target = at != null?hexGrid.GetTileByCoordenates(at) : hexGrid.GetRandomTile(GroundType.Walkable); character.Begin(); target.occupier = character.id; character.steppingOn = target; return(Instantiate(character.transform, target.transform.position, Quaternion.identity)); }
public void ShowSelection(Chararcter selected) { showHide(true); name.text = selected.name + " Lvl: " + selected.level; steps.text = selected.actionsLeft.ToString(); stepsPlanned.text = "Planned for " + selected.plottedSteps.ToString() + (selected.plottedSteps > 1 ? " steps" : " step"); healthBar.value = selected.lifePoints / selected.getMaxLife(); resetBttn.onClick.AddListener(() => { Chararcter select = GameObject.Find("unit" + selected.id).GetComponent <Chararcter>(); select.plottedTilePath = null; select.plottedSteps = 0; GameControl.Instance.ClearLastPath(); }); skillContent.ShowSkills(selected.skills.ToArray()); }
IEnumerator TimeStep(string unitName, int repeats) { Chararcter unit = GameObject.Find(unitName).GetComponent <Chararcter>(); unit.speed = 1 + .2f * repeats; for (int j = 0; j < repeats; j++) // for every move to be made { if (unit.plottedTilePath != null && unit.plottedTilePath.Length >= 1) { movementHappening = true; unit.Move(); yield return(new WaitForSeconds(.3f)); } movementHappening = false; } UpdateStepButtons(); }
public void setSelection(Chararcter select) { selected = select; if (selected.owner == startingPlayer) { // owned unit selected if (isPlotValid(selected.plottedTilePath)) { DrawPath(selected.plottedTilePath); } selected.steppingOn.transform.GetComponent <SpriteRenderer>().color = Color.blue; } else { // not-owned unit selected selectionMenu.HideSkills(); // cant see their skills? } selected.steppingOn = lastTileClicked; selectionMenu.ShowSelection(selected); }
/* return the shortest amount of plottedsteps from given list of unit ids */ private int getStepButtons(List <int> units) { if (units == null || units.Count <= 0 || movementHappening) { return(0); } int shortestLength = -1; for (int i = 0; i < units.Count; i++) { Chararcter unit = GameObject.Find("unit" + units[i]).GetComponent <Chararcter>(); if (unit.plottedTilePath == null || unit.plottedTilePath.Length < 1) { return(0); } else if (shortestLength == -1 || unit.plottedTilePath.Length < shortestLength) { shortestLength = unit.plottedTilePath.Length; } } return(shortestLength); }