Beispiel #1
0
        void EventForCreatingAnother()
        {
            Event.Register(EventType.MineralsChanged, argsA =>
            {
                if (argsA.Minerals > 50)
                {
                    // After he collected minerals, another worker will be built
                    var baseCenter = BuildingHelper.GetBuildings <BaseCenter>()[0];
                    baseCenter.CreateWorker();

                    // After creating (it means after few seconds), he will need to go gather too
                    Event.Register(EventType.UnitCreated, argsB =>
                    {
                        if (argsB.MyUnit.GetType().Equals(typeof(Worker)))
                        {
                            Worker worker = (Worker)argsB.MyUnit;
                            worker.SendGather(MaterialHelper.GetNearestMineralsTo(worker));
                            argsB.ThisEvent.UnregisterEvent();
                        }
                    });
                }
                argsA.ThisEvent.UnregisterEvent();

                // This event will work only while there are not enough workers.
                // After that, minerals will be left to go over 150.
                if (UnitHelper.GetUnits <Worker>().Length >= 5)
                {
                    argsA.ThisEvent.UnregisterEvent();
                }
            });
        }
        public void BuildingStage(Runner.NextStageStarter startNextStage)
        {
            // A first building
            Event.Register(EventType.MineralsChanged, args =>
            {
                if (args.Minerals > 150)
                {
                    var baseCenter = BuildingHelper.GetBuildings <BaseCenter>()[0];
                    var position   = BuildingHelper.ClosestEmptySpaceTo(baseCenter);
                    FindWorkerThatGathers().CreateBuilding(BuildingType.NubianArmory, position);

                    // We only need one army production building for now
                    args.ThisEvent.UnregisterEvent();
                }
            });

            // Worker will return to work afterwards
            Event.Register(EventType.BuildingCreated, args =>
            {
                if (
                    args.MyBuilding.GetType().Equals(typeof(NubianArmory))
                    &&
                    args.MyUnit.GetType().Equals(typeof(Worker))
                    )
                {
                    var worker = (Worker)args.MyUnit;
                    worker.SendGather(MaterialHelper.GetNearestMineralsTo(worker));
                    BuildArmy(startNextStage);
                }
                args.ThisEvent.UnregisterEvent();
            });
        }
 void BuildArmy(Runner.NextStageStarter startNextStage)
 {
     var buildingArmy = Event.Register(EventType.MineralsChanged, args =>
     {
         if (args.Minerals > 100)
         {
             foreach (NubianArmory armory in BuildingHelper.GetBuildings <NubianArmory>())
             {
                 if (armory.CreateUnit(UnitType.DonkeyGun))
                 {
                     if (MyBot.Army++ >= 5)
                     {
                         args.ThisEvent.UnregisterEvent();
                         startNextStage();
                     }
                     break;
                 }
             }
         }
     });
 }