// USAGE: if there is a nearby enemy of the attached unit, attack it
    //        return true if there was a successful attack
    public bool attackNearby(HashSet <Cell> nearbyCells, Unit u)
    {
        bool madeAttack = false;

        if (nearbyCells.Count == 0)
        {
            return(madeAttack);
        }

        foreach (Cell c in nearbyCells)
        {
            if (!c.getOccupied())
            {
                continue;
            }

            Unit.Faction f = c.getUnit().unitFaction;
            if (f == Unit.Faction.Player || f == Unit.Faction.Allied)                // found an enemy --> let's attack it!
            {
                IntfActionModule attack = findBestAttack(u);
                attack.executeAction(u.currentCell, u.currentDir);
                madeAttack = true;
                break;
            }
        }
        return(madeAttack);
    }
Exemple #2
0
    // Execute gets the corresponding component of the current unit
    // requests said action be executed
    // it also makes the popup menu disappear
    public void execute(System.Type action)
    {
        Unit             unit   = GameObject.Find("GameLogic").GetComponent <TurnHandler>().getCurrentUnit();
        IntfActionModule module = (IntfActionModule)unit.GetComponent(action.ToString());

        module.executeAction(unit.currentCell, unit.currentDir);
        unit.togglePopUp();
    }
    // USAGE: finds the attack action with the highest damage value, if such exists
    public IntfActionModule findBestAttack(Unit u)
    {
        IntfActionModule[] allActions = u.GetComponents <IntfActionModule> ();
        IntfActionModule   bestAttack = null;
        int attackVal = 0;

        foreach (IntfActionModule a in allActions)
        {
            if (a.isAttack() > attackVal)
            {
                bestAttack = a;
            }
        }
        return(bestAttack);
    }
Exemple #4
0
    // USAGE: wtf (jk)
    public void highlightThing(Unit unit, IntfActionModule action)
    {
        HashSet <Cell> targetCells     = action.findTargetCells(unit.currentCell, unit.currentDir);
        HashSet <Cell> occupiedCells   = new HashSet <Cell>();
        HashSet <Cell> unoccupiedCells = new HashSet <Cell>();

        foreach (Cell cell in targetCells)
        {
            if (cell.getOccupied())
            {
                occupiedCells.Add(cell);
            }
            else
            {
                unoccupiedCells.Add(cell);
            }
        }

        highlightCells(occupiedCells, (Sprite)Resources.Load <Sprite>("sprites/highlightMarker"));
        highlightCells(unoccupiedCells, (Sprite)Resources.Load <Sprite>("sprites/attackMarker"));
    }