Exemplo n.º 1
0
    public bool PlantTree(LogicJack[] jacks, int player, TreeType treeSelected, int x, int y)
    {
        if (!ValidIndex(x, y))
        {
            Debug.LogError("wtf ? x,y= " + x + "," + y);
            return(false);
        }

        if (cellControl[x, y] != null)
        {
            Debug.LogError("there is already a tree at " + x + "," + y);
            return(false);
        }

        foreach (var j in jacks)
        {
            if (j.x == x & j.y == y)
            {
                return(false);
            }
        }

        if (treeSelected == TreeType.None)
        {
            return(false);
        }

        LogicJack logicJack = null;

        if (player >= 0)
        {
            logicJack = jacks[player];
            if (!logicJack.ValidPlantRange(x, y))
            {
                return(false);
            }

            int ac_remain    = logicJack.ac - 1; // default plant cost
            int priorityLock = 0;
            if (onPlayerTryPlant != null)
            {
                onPlayerTryPlant(logicJack, ref ac_remain, ref priorityLock);
            }

            if (ac_remain < 0)
            {
                return(false);
            }
            logicJack.ac = ac_remain;
        }

        LogicTree tree = GetTree(treeSelected);

        tree.Init(this, x, y, logicJack);
        cellControl[x, y] = tree;

        if (onPlayerPlantDone != null & player >= 0)
        {
            onPlayerPlantDone(logicJack);
        }
        return(true);
    }