コード例 #1
0
    void Awake()
    {
        hirePeasant.onClick.AddListener(() =>
        {
            Commander com = Controller.Instance.commanders[CommanderID.Player];

            if (Config.prices.peasant <= com.wheat)
            {
                Tile t = Controller.Instance.grid.FindClosestTileWithEntity <Townhall>(new Pos(), CommanderID.Player);
                Hatchery.SpawnPeasant(t.pos.x, t.pos.y, CommanderID.Player);

                Task.Run().Time(0.03f).Random(0.015f).Loop(Config.prices.peasant).OnRepeat(_ =>
                {
                    Controller.Instance.commanders[CommanderID.Player].RemoveWheat();

                    Controller.Instance.UI.AddResourceBit(
                        Resource.Wheat,
                        Controller.Instance.UI.Wheat.position,
                        t.transform.position,
                        () => { }
                        );
                });
            }
        });

        constructHouse.onClick.AddListener(() => StartBuilding(Building.House));
        constructLumberyard.onClick.AddListener(() => StartBuilding(Building.Lumberyard));
        constructWindmill.onClick.AddListener(() => StartBuilding(Building.Windmill));
        constructTower.onClick.AddListener(() => StartBuilding(Building.Tower));
        constructCastle.onClick.AddListener(() => StartBuilding(Building.Castle));
    }
コード例 #2
0
ファイル: House.cs プロジェクト: iggyzuk/swords-and-forks
 public override void Init()
 {
     updateTask = Task.Run().Time(15).Random(15).Loop(-1).OnRepeat(_ =>
     {
         if (peasant == null)
         {
             peasant = Hatchery.SpawnPeasant(tile.pos.x, tile.pos.y, comID);
         }
     });
 }
コード例 #3
0
ファイル: Townhall.cs プロジェクト: iggyzuk/swords-and-forks
    public override void Init()
    {
        Hatchery.SpawnPeasant(tile.pos.x, tile.pos.y, comID);

        lumberProductionTask = Task.Run().Name("Townhall(produce)").Time(25f - Mathf.Clamp(level, 0, 20)).Loop(-1).OnRepeat(_ =>
        {
            if (comID == CommanderID.Player)
            {
                Task.Run().Time(0.03f).Random(0.015f).Loop(level).OnRepeat(__ =>
                {
                    Controller.Instance.UI.AddResourceBit(
                        Resource.Lumber,
                        tile.transform.position,
                        Controller.Instance.UI.Lumber.position,
                        () => Controller.Instance.commanders[comID].AddLumber()
                        );
                });
            }
            else
            {
                Controller.Instance.commanders[comID].AddLumber(level);
            }
        });

        wheatProductionTask = Task.Run().Time(10f - Mathf.Clamp(level, 0, 8)).Loop(-1).OnRepeat(_ =>
        {
            if (comID == CommanderID.Player)
            {
                Task.Run().Time(0.03f).Random(0.015f).Loop(level).OnRepeat(__ =>
                {
                    Controller.Instance.UI.AddResourceBit(
                        Resource.Wheat,
                        tile.transform.position,
                        Controller.Instance.UI.Wheat.position,
                        () => Controller.Instance.commanders[comID].AddWheat()
                        );
                });
            }
            else
            {
                Controller.Instance.commanders[comID].AddWheat(level);
            }
        });
    }