예제 #1
0
    // 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);
    }
예제 #2
0
    /* 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);
            }
        }
    }
예제 #3
0
 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);
 }
예제 #4
0
    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));
    }
예제 #5
0
 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());
 }
예제 #6
0
    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();
    }
예제 #7
0
    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);
    }
예제 #8
0
    /* 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);
    }