コード例 #1
0
ファイル: BattleTest.cs プロジェクト: kyapp69/XposeCraft
 void ScheduleTacticsWhenLowHp()
 {
     GameEvent.Register(GameEventType.UnitReceivedFire, args =>
     {
         // If attacking, run away
         if (args.MyUnit.ActionQueue.CurrentAction is Attack ||
             args.MyUnit.ActionQueue.CurrentAction is AttackMove)
         {
             UnitActionQueue oldActions = args.MyUnit.ActionQueue;
             if (args.MyUnit.Health < args.MyUnit.MaxHealth / 2)
             {
                 // Any unit of course exposes its position in form of coordinates; MyBotData contains data
                 args.MyUnit.MoveTo(MyBotData.HealMeetPointUnit.Position);
                 BotRunner.Log("Unit " + args.MyUnit + " is waiting to be healed");
                 MyBotData.MeetPointEvent = GameEvent.Register(GameEventType.UnitGainedHealth,
                                                               argsB => { argsB.MyUnit.ActionQueue = oldActions; });
             }
         }
         // If hiding, defend
         else if (args.EnemyUnits.Length > 0)
         {
             EnqueueFirst(new Attack(args.EnemyUnits[0]), args.MyUnit);
         }
     });
 }
コード例 #2
0
        public static void Gather(Worker worker)
        {
            var resource = ResourceHelper.GetNearestMineralTo(worker);

            if (resource == null)
            {
                BotRunner.Log("Worker couldn't find another Resource");
                return;
            }
            if (CreateBaseIfNone(worker))
            {
                return;
            }
            worker.SendGather(resource).After(new CustomFunction(() => Gather(worker)));
        }
コード例 #3
0
ファイル: BuildingTest.cs プロジェクト: kyapp69/XposeCraft
 void BuildArmy(Action startNextStage)
 {
     GameEvent.Register(GameEventType.MineralsChanged, argsMinerals =>
     {
         // First wave starts at 5 units
         if (!MyBotData.Rushed && MyBotData.Army >= 5)
         {
             startNextStage();
             MyBotData.Rushed = true;
         }
         // Production ends after 20
         else if (MyBotData.Army >= 20)
         {
             argsMinerals.ThisGameEvent.UnregisterEvent();
             return;
         }
         if (_producingDonkeyGun != null || argsMinerals.Minerals <= 100)
         {
             return;
         }
         foreach (NubianArmory armory in BuildingHelper.GetMyBuildings <NubianArmory>())
         {
             if (armory.QueuedUnits >= 2)
             {
                 continue;
             }
             if (armory.CanNowProduceUnit(UnitType.DonkeyGun))
             {
                 armory.ProduceUnit(UnitType.DonkeyGun);
                 // Additional mineral sink: producing one more expensive Unit if too rich
                 if (armory.CanNowProduceUnit(UnitType.WraithRaider))
                 {
                     armory.ProduceUnit(UnitType.WraithRaider);
                 }
                 _producingDonkeyGun = GameEvent.Register(GameEventType.UnitProduced, argsUnit =>
                 {
                     if (argsUnit.MyUnit is DonkeyGun)
                     {
                         MyBotData.Army++;
                         BotRunner.Log("My army contains " + MyBotData.Army + " battle units");
                         argsUnit.ThisGameEvent.UnregisterEvent();
                         _producingDonkeyGun = null;
                     }
                 });
             }
         }
     });
 }
コード例 #4
0
ファイル: BattleTest.cs プロジェクト: kyapp69/XposeCraft
        public static void RegisterReceiveFire()
        {
            var receivedFire = new Action <Arguments>(args =>
            {
                foreach (var enemyUnit in args.EnemyUnits)
                {
                    BotRunner.Log(enemyUnit + " attacked me");
                    // The Unit defends itself
                    if (args.MyUnit != null)
                    {
                        EnqueueFirst(new Attack(enemyUnit), args.MyUnit);
                    }
                    // Another Unit helps
                    AttackUnit(enemyUnit);
                }
            });

            GameEvent.Register(GameEventType.UnitReceivedFire, args => receivedFire.Invoke(args));
            GameEvent.Register(GameEventType.BuildingReceivedFire, args => receivedFire.Invoke(args));
        }