コード例 #1
0
    public void OnPointerClick(PointerEventData eventData)
    {
        Commander com = Controller.Instance.commanders[CommanderID.Player];

        if (com.building != Building.None)
        {
            com.TryBuild(Builder.BuildingToEntity(com.building), pos.x, pos.y);
            com.building = Building.None;

            Controller.Instance.UI.Buttons.EnableAll();
        }
        else if (entity != null && entity.comID == CommanderID.Player)
        {
            int price = entity.GetPrice() * entity.level;
            if (price <= com.lumber)
            {
                Hatchery.SpawnEffect(pos.x, pos.y, Config.colors.purple);

                entity.level++;
                Level = entity.level;

                Task.Run().Time(0.03f).Random(0.015f).Loop(price).OnRepeat(_ =>
                {
                    Controller.Instance.UI.AddResourceBit(
                        Resource.Lumber,
                        Controller.Instance.UI.Lumber.position,
                        this.transform.position,
                        () => Controller.Instance.commanders[CommanderID.Player].RemoveLumber()
                        );
                });
            }
        }
    }
コード例 #2
0
ファイル: Peasant.cs プロジェクト: iggyzuk/swords-and-forks
    public void Init(int x, int y, CommanderID comID)
    {
        pos.x = x;
        pos.y = y;

        this.comID = comID;

        body.color = Controller.Instance.commanders[comID].color;

        resourceImage.enabled = false;

        List <Pos> path = new List <Pos>();

        updateTask = Task.Run().Name("Peasant(tick)").Loop(-1).OnRepeat(t =>
        {
            if (movementTask != null)
            {
                return;
            }

            if (path.Count > 0)
            {
                MoveTo(path[0]);
                path.RemoveAt(0);
                return;
            }

            path = PickNextPath();

            if (path.Count > 0)
            {
                MoveTo(path[0]);
                path.RemoveAt(0);
                return;
            }

            MoveToRandomNeighbour();

            if (!isActive)
            {
                Core.Juggler.Remove(updateTask);
                if (movementTask != null)
                {
                    Core.Juggler.Remove(movementTask);
                }
                Object.Destroy(this.gameObject);

                Hatchery.SpawnEffect(pos.x, pos.y, Config.colors.pink);
            }
        });
    }
コード例 #3
0
ファイル: Commander.cs プロジェクト: iggyzuk/swords-and-forks
    public bool TryBuild(Entity entity, int x, int y)
    {
        entity.comID = comID;

        if (entity.GetPrice() <= lumber)
        {
            Tile tile = Builder.Build(entity, x, y);
            if (tile != null)
            {
                lumber -= entity.GetPrice();

                tile.Border = color;
                tile.SetEntityColor(color);

                Hatchery.SpawnEffect(x, y, Config.colors.white);
            }

            Controller.Instance.UI.UpdateLumber();

            return(true);
        }
        return(false);
    }