コード例 #1
0
        private MappedBot CreateMappedBot(BoonBotBase bot)
        {
            var result = new MappedBot(bot);

            result.Position = Point.Empty;
            result.IsActive = false;
            mappedObjects.Add(result);
            CreateNewBotMamagementReference(bot, result.EngineId);
            return(result);
        }
コード例 #2
0
 private void SetBotInitialValues(MappedBot mo)
 {
     mo.LifeRemaining   = 100;
     mo.Position        = activeWorld.ReturnNextStartLocation();
     mo.Speed           = 0;
     mo.Heading         = 0;
     mo.IsActive        = true;
     mo.ChargeRemaining = 0;
     mo.PowerRemaining  = 0;
 }
コード例 #3
0
        private void ApplyWeaponfireHit(MappedBot victim, CombatResult cr)
        {
            ApplyDamageToObject(victim.EngineId, cr.TotalDamage, DamageType.Projectile);

            bd2TickAction ta = new bd2TickAction();

            ta.ActionType = LastTickEventType.Shot;

            CreateNextTurnNotificationMessage(victim.EngineId, ta);
        }
コード例 #4
0
        private void PerformEngineInitOnBot(MappedBot mo)
        {
            SetBotInitialValues(mo);

            b.Verbose.Log("Lanching engine init UI messages, engine informing UI of position etc");

            BotEnterWorldContext bewC = new BotEnterWorldContext();

            bewC.BotName    = mo.Bot.Name;
            bewC.ObjectId   = mo.EngineId;
            bewC.BotVersion = mo.Bot.Version;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.BotEnterWorld)
            {
                RequestContext = bewC,
            });

            MapObjectPositionChangeContext mopcc = new MapObjectPositionChangeContext();

            mopcc.Destination    = mo.Position;
            mopcc.ObjectIdentity = mo.EngineId;
            hub.Launch <Message_Game>(new Message_Game(MainMessageKind.MapObjectMovementChange, KnownSubkinds.BotPositionChange)
            {
                RequestContext = mopcc
            });

#if DEBUG
            b.Info.Log("Extended diagnostics, checking to see whether one bot sits on another one");
            if (!activeWorld.IsFreeWorldSpace(mo.Position))
            {
                b.Info.Log("Object " + mo.EngineId.ToString() + " on top of boundary at " + mo.Position.ToString());
                throw new BdBaseException("Mapped object on top of world boundary (" + mo.Position.ToString() + "), fault.");
            }

            foreach (var v in mappedObjects)
            {
                if (v.EngineId == mo.EngineId)
                {
                    continue;
                }

                if (v.Position == mo.Position)
                {
                    throw new BdBaseException("Cant add a bot on top of an existing mapped object");
                }
            }
#endif
        }
コード例 #5
0
        private void PerformBotDeath(MappedBot bt, BotEndReason bdr)
        {
            b.Assert.True(!bt.DeathNotificationOccured, "You shouldn't notify of a bots death twice.  Notification for " + bt.Bot.Name + " already sent");
            bt.DeathNotificationOccured = true;

            BotEndContext bdc = new BotEndContext();

            bdc.BotId  = bt.EngineId;
            bdc.Reason = bdr;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.BotEndOccured)
            {
                RequestContext = bdc
            });
            bt.Speed    = 0;
            bt.IsActive = false;
        }
コード例 #6
0
        private void PerformBotInitialisation(MappedBot mappedBot)
        {
            b.Info.Log("Preparing Bot " + mappedBot.Bot.Name);
            b.Assert.True(equipment != null, "An Equipment support must be available before bots are initialised");

            var pp = mappedBot.Bot.GetPowerPack();

            if (pp == null)
            {
                throw new BdBaseException("All bots must have a powerpack.");
            }
            var powerPackTemplate = (PowerPackEquipmentItem)equipment.GetEquipmentTypeById(pp.EquipmentId);

            mappedBot.PowerRemaining  = powerPackTemplate.TotalPower;
            mappedBot.ChargeRemaining = powerPackTemplate.ChargePerTurn;
            mappedBot.TurnsAccelerationActionsRemaining = powerPackTemplate.Acceleration;
        }
コード例 #7
0
        private void ChangeObjectHeading(Message_BotPerformAction actionMessage, MappedBot bt)
        {
            bt.Heading = actionMessage.DParameter;
            NavigationInfoContext nic = new NavigationInfoContext();

            nic.SetBot(bt);
            nic.BotId      = bt.EngineId;
            nic.NewHeading = bt.Heading;


            //nic.Kind = MainMessageKind.MapObjectMovementChange;
            //nic.SubKind = KnownSubkinds.DirectionChange;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.MapObjectMovementChange, KnownSubkinds.DirectionChange)
            {
                RequestContext = nic
            });
        }
コード例 #8
0
        private bool CheckForDepletedBot(MappedBot bt)
        {
            if (bt.PowerRemaining <= 0)
            {
                DeactivateBot(bt);
                BotEndContext bec = new BotEndContext();
                bec.BotId  = bt.EngineId;
                bec.Reason = BotEndReason.Depleted;

                hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.BotEndOccured)
                {
                    //ObjectIdentity = bt.EngineId
                    RequestContext = bec
                });
                return(true);
            }
            return(false);
        }
コード例 #9
0
        public int AddBot(BoonBotBase bot)
        {
            if (activeWorld == null)
            {
                throw new BdBaseException("No world loaded");
            }

            if (botReferences.Count >= activeWorld.Map.MaxSupportedBots)
            {
                throw new BdBaseException("Too many bots");
            }

            MappedBot mo = CreateMappedBot(bot);

            this.CanBattleStart = true;

            return(mo.EngineId);
        }
コード例 #10
0
        private void ChangeBotSpeed(MappedBot bt, int p)
        {
            if (bt.TurnsAccelerationActionsRemaining > 0)
            {
                var ppi = (PowerPackEquipmentItem)equipment.GetEquipmentTypeById(bt.Bot.GetPowerPack().EquipmentId);

                bt.TurnsAccelerationActionsRemaining--;
                int tSpeed = bt.Speed + p;
                if ((tSpeed >= 0) && (tSpeed <= ppi.MaxSpeed))
                {
                    bt.Speed = tSpeed;

                    NavigationInfoContext nic = new NavigationInfoContext();
                    nic.SetBot(bt);
                    nic.SpeedDelta = tSpeed;

                    hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.MapObjectMovementChange, KnownSubkinds.ChangeSpeed)
                    {
                        RequestContext = nic
                    });
                }
            }
        }
コード例 #11
0
 private void DeactivateBot(MappedBot bt)
 {
     bt.IsActive        = false;
     bt.Speed           = 0;
     bt.ChargeRemaining = 0;
 }
コード例 #12
0
        private EquipmentUseResult PerformScannerUsage(ScannerEquipmentItem equipTemplate, ActiveEquipment activeEquipmentInstance, MappedBot owningBot)
        {
            ScanEquipmentUseResult result = new ScanEquipmentUseResult();

            if (!owningBot.ConsumeCharge(equipTemplate.ChargeConsumed))
            {
                result.State = UsageEndState.Fail_NoCharge;
                return(result);
            }

            Point mapOffset = owningBot.Position;

            foreach (var vSrc in equipTemplate.GetAllScanPoints())
            {
                Point v = new Point(vSrc.X + mapOffset.X, vSrc.Y + mapOffset.Y);

                ScanTileResult str = ScanTileResult.Unscanned;
                MapTile        mt  = MapTile.DefaultGround;

                if (activeWorld.IsValidSpace(v))
                {
                    var tileOccupant = GetTileOccupantByLocation(v);
                    if (tileOccupant != null)
                    {
                        if (tileOccupant.EngineId == owningBot.EngineId)
                        {
                            str = ScanTileResult.You;
                        }
                        else
                        {
                            int ctk = CreateTemporaryScanKey(owningBot.EngineId, tileOccupant.EngineId);
                            result.AddPointOfInterest(v, ctk);
                            str = tileOccupant.IsAlive() ? ScanTileResult.Bot : ScanTileResult.Wreckage;
                        }
                    }
                    else
                    {
                        mt = activeWorld.Map.GetTileAtPosition(v);
                    }
                }
                else
                {
                    mt = MapTile.BoundaryWall1;
                }

                if (str == ScanTileResult.Unscanned)
                {
                    // If there was not an active occupant, then look to the map.
                    switch (mt)
                    {
                    case MapTile.BoundaryWall1: str = ScanTileResult.SolidWall; break;

                    case MapTile.DefaultGround: str = ScanTileResult.Unoccupied; break;

                    default: throw new BdBaseException("DEFAULT - invalid tile mapping - " + mt.ToString());
                    }
                }

                result.SetDimensions(equipTemplate.MinimumXScanned, equipTemplate.MinimumYScanned, equipTemplate.TotalWidthScanned, equipTemplate.TotalHeightScanned);
                result.SetScanResultAtPosition(vSrc, str);
            }

            return(result);
        }
コード例 #13
0
        private EquipmentUseResult PerformFireWeapon(OffensiveWeaponEquipmentItem owi, ActiveEquipment activeEquipmentInstance, MappedBot attacker, EquipmentUseRequestContext ctxt)
        {
            EquipmentUseResult result = new EquipmentUseResult();

            if (activeEquipmentInstance.CooldownTicksRemaining > 0)
            {
                result.State = UsageEndState.Fail_CooldownActive;
                return(result);
            }

            MappedBot victim = ConvertTemporaryScanKeyToBot(attacker.EngineId, ctxt.IParam);

            if (victim == null)
            {
                result.State = UsageEndState.Fail_InvalidTarget;
                b.Warning.Log("The bot tried to target an invalid key.  This shouldnt happen");
                return(result);
            }

            b.Assert.True(attacker.EngineId != victim.EngineId, "You cant shoot at yourself.");

            activeEquipmentInstance.RoundsRemaining -= 1;
            if (activeEquipmentInstance.RoundsRemaining <= 0)
            {
                result.State = UsageEndState.Fail_NoAmmo;
                return(result);
            }

            if (!attacker.ConsumeCharge(owi.BaseChargeCost))
            {
                result.State = UsageEndState.Fail_NoCharge;
                return(result);
            }

            CombatAttack ca = new CombatAttack();

            ca.Attacker       = attacker;
            ca.Victim         = victim;
            ca.Weapon         = owi;
            ca.WeaponInstance = activeEquipmentInstance;
            CombatResult cr = combatCore.ResolveAttack(ca);

            UICombatContext context = new UICombatContext();

            context.AggressorId  = attacker.EngineId;
            context.VictimId     = victim.EngineId;
            context.WeaponTypeId = owi.UniqueId;
            context.DidHit       = cr.DidHit;
            context.Damage       = cr.TotalDamage;

            hub.Launch <Message_Ui>(new Message_Ui(MainMessageKind.UIMessage, KnownSubkinds.WeaponFire)
            {
                RequestContext = context
            });

            if (cr.DidHit)
            {
                ApplyWeaponfireHit(victim, cr);
            }

            result.State = UsageEndState.Success;
            return(result);
        }
コード例 #14
0
 public void SetBot(MappedBot bt)
 {
     this.BotId       = bt.EngineId;
     this.PublicBotId = bt.Bot.PublicId;
 }