Esempio n. 1
0
        protected override int ActualGetCurrentSpeed(BoonBotBase targetBot)
        {
            var qry = new Message_Query(MainMessageKind.QueryBotStatus, KnownSubkinds.ReadSpeed);

            qry.PublicBotId = targetBot.PublicId;
            hub.Launch <Message_Query>(qry);
            NavigationInfoContext nic = (NavigationInfoContext)qry.ResponseContext;

            b.Assert.True(nic != null, "The response cant have a null value");
            return(nic.SpeedDelta);
        }
Esempio n. 2
0
        protected override void ActualChangeSpeed(BoonBotBase targetBot, int byThisMuch)
        {
            NavigationInfoContext nic = new NavigationInfoContext();

            nic.PublicBotId = targetBot.PublicId;
            nic.SpeedDelta  = byThisMuch;

            hub.Launch <Message_BotPerformAction>(new Message_BotPerformAction(MainMessageKind.MapObjectMovementChange, KnownSubkinds.ChangeSpeed)
            {
                RequestContext = nic
            });
        }
Esempio n. 3
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
            });
        }
Esempio n. 4
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
                    });
                }
            }
        }
Esempio n. 5
0
        public void RegisterForMessages()
        {
            b.Info.Log("Engine Message Registration Completes.");
            if (hasRegistered)
            {
                throw new InvalidOperationException("Engine is trying to register for messages a second time. This is invalid.");
            }
            hasRegistered = true;
            gameHandler   = hub.LookFor <Message_Game>(gameMessage => {
                b.Verbose.Log("Recieving Message_Game");
                //if (gameMessage.SubKind == GameMessageSubKind.)
            });

            actionHandler = hub.LookFor <Message_BotPerformAction>(actionMessage => {
                b.Verbose.Log("Recieving Message_Action");
                if (actionMessage.SubKind == KnownSubkinds.InstallEquipment)
                {
                    var res = PerformEquipmentInstallation(actionMessage);
                    actionMessage.ResponseContext = res;
                }
                if (actionMessage.SubKind == KnownSubkinds.UseEquipment)
                {
                    var res = PerformEquipmentUsage((EquipmentUseRequestContext)actionMessage.RequestContext);
                    actionMessage.ResponseContext = res;
                }

                if (actionMessage.SubKind == KnownSubkinds.ChangeSpeed)
                {
                    b.Verbose.Log("Recieving Message_Action - SpeedChange");

                    NavigationInfoContext nic = (NavigationInfoContext)actionMessage.RequestContext;
                    var bt = GetMappedBotByPublicId(nic.PublicBotId);
                    b.Assert.True(bt != null, "Error, unable to map bot by public id, code cant continue.");
                    ChangeBotSpeed(bt, nic.SpeedDelta);
                }

                if (actionMessage.SubKind == KnownSubkinds.ChangeDirection)
                {
                    b.Verbose.Log("Recieving Message_Action - DirectionChange");

                    var bt = GetMappedBotByPublicId(actionMessage.PublicBotId);
                    ChangeObjectHeading(actionMessage, bt);
                }
            });

            queryHandler = hub.LookFor <Message_Query>(queryMessage => {
                b.Assert.True(queryMessage.PublicBotId != Guid.Empty, "Cant query data for a non existant bot.");

                b.Verbose.Log("Recieving Message_Query - " + queryMessage.SubKind.ToString());
                if (queryMessage.SubKind == KnownSubkinds.ReadSpeed)
                {
                    var bt = GetMappedBotByPublicId(queryMessage.PublicBotId);
                    NavigationInfoContext nic = new NavigationInfoContext();
                    nic.SpeedDelta            = bt.Speed;
                    //queryMessage.IParam = bt.Speed;
                    queryMessage.ResponseContext = nic;
                }

                if (queryMessage.SubKind == KnownSubkinds.ReadHeading)
                {
                    var bt = GetMappedBotByPublicId(queryMessage.PublicBotId);
                    queryMessage.DParameter = bt.Heading;
                }
            });
        }