public void TargetPicked(GameObject target)
    {
        if (target.tag == "Unit" && !possTargets.Contains(target.GetComponent <UnitInfo>()))
        {
            Debug.Log("Invalid target");
            return;
        }

        Debug.Log("target name: " + target.name);

        CancelAction();

        foreach (UnitInfo possTar in possTargets)
        {
            possTar.transform.Find("Pointer").gameObject.SetActive(false);
        }

        string shape  = currAct.shape;
        int    radius = currAct.rad;

        if (unit.status.ContainsKey("widen"))
        {
            radius++;
        }

        UnitInfo   targIn = new UnitInfo();
        GameObject center;

        if (target.tag == "Unit")
        {
            targIn = target.GetComponent <UnitInfo>();
            center = targIn.currentTile;
        }

        else
        {
            center = target;
        }

        if (unit.status.ContainsKey("widen"))
        {
            unit.SpendMP(currAct.cost * 2);
        }
        else
        {
            unit.SpendMP(currAct.cost);
        }

        List <UnitInfo> units = new List <UnitInfo>();

        List <GameObject> tiles = new List <GameObject>();

        List <string> cond = new List <string>();

        cond.Add("noElevation");
        cond.Add("noTerrain");
        cond.Add("enemy");
        cond.Add("player");


        switch (shape)
        {
        case "single":
            units.Add(targIn);
            tiles.Add(center);
            Debug.Log("single action: " + currAct.name);
            StartCoroutine(actHand.ActionInterpreter(unit, currAct.name, units, tiles));
            break;

        case "blast":
            tiles.Add(center);
            moveCalc.HighlightClear();
            moveCalc.MoveFinder(radius, center, cond);
            tiles.AddRange(moveCalc.selectedTiles);
            moveCalc.HighlightClear();
            units.AddRange(moveCalc.BlastTargetFinder(radius, center));
            foreach (UnitInfo unit in units)
            {
                tiles.Add(unit.currentTile);
            }
            StartCoroutine(actHand.ActionInterpreter(unit, currAct.name, units, tiles));
            break;

        default:
            Debug.Log("shape not set");
            break;
        }

        this.Hide();
    }
Exemple #2
0
    public IEnumerator TakeAction(UnitInfo unit)
    {
        bool actionTaken = false;

        //if (unit.faction == "enemy")
        //{

        string actionName = "";

        List <string> actionNames = unit.actionNames;

        for (int i = 0; i < unit.actionNames.Count; i++)
        {
            actionName = actionNames[0];
            UnitInfo.Action thisAction = actDesc.actions[actionName];
            if (thisAction.target == "self")
            {
                MoveClosestEnemy(unit);

                yield return(new WaitForSeconds(2.0f));

                List <UnitInfo> self = new List <UnitInfo>();
                self.Add(unit);
                List <GameObject> selfTile = new List <GameObject>();
                selfTile.Add(unit.currentTile);

                yield return(actHand.ActionInterpreter(unit, actionNames[0], self, selfTile));

                turnHistory.AddMessage(unit.name + " used " + actionName);
                actionTaken = true;
                break;
            }
            if (thisAction.target == "enemy")
            {
                if (CanReach(unit, thisAction.range, thisAction.rad, "enemy"))
                {
                    List <UnitInfo> targ = new List <UnitInfo>();
                    targ.Add(targetUnit);

                    List <GameObject> tile = new List <GameObject>();
                    tile.Add(targetUnit.currentTile);

                    cubeClick.MoveToTile(moveTile, unit.gameObject);
                    yield return(new WaitForSeconds(2.0f));

                    turnHistory.AddMessage(unit.name + " used " + actionName + " on " + targetUnit.name);
                    yield return(actHand.ActionInterpreter(unit, actionName, targ, tile));


                    actionTaken = true;
                    break;
                }
            }
            if (thisAction.target == "ally")
            {
                if (CanReach(unit, thisAction.range, thisAction.rad, "ally"))
                {
                    List <UnitInfo> targ = new List <UnitInfo>();
                    targ.Add(targetUnit);

                    List <GameObject> tile = new List <GameObject>();
                    tile.Add(targetUnit.currentTile);

                    cubeClick.MoveToTile(moveTile, unit.gameObject);
                    yield return(new WaitForSeconds(2.0f));

                    yield return(actHand.ActionInterpreter(unit, actionName, targ, tile));

                    actionTaken = true;
                    break;
                }
            }
            else
            {
                if (CanReach(unit, thisAction.range, thisAction.rad, thisAction.target))
                {
                    List <GameObject> tile = listTiles;

                    foreach (UnitInfo targ in allTargets)
                    {
                        turnHistory.AddMessage(unit.name + " uses " + thisAction.name + " on " + targ.name);
                        tile.Add(targ.currentTile);
                    }

                    cubeClick.MoveToTile(moveTile, unit.gameObject);

                    yield return(new WaitForSeconds(2.0f));

                    yield return(actHand.ActionInterpreter(unit, actionName, allTargets, tile));

                    actionTaken = true;
                    break;
                }
            }

            actionNames.Remove(actionName);
            actionNames.Add(actionName);
        }

        if (actionTaken == true)
        {
            actionNames.Remove(actionName);
            actionNames.Add(actionName);
            unit.actionNames = actionNames;
        }
        else
        {
            turnHistory.AddMessage(unit.name + " moves");
            MoveClosestEnemy(unit);
            yield return(new WaitForSeconds(2.0f));
        }
        // }
    }