Ejemplo n.º 1
0
 private void AreaReservationHandler(ref MyAiTargetManager.ReservedAreaData reservedArea, bool success)
 {
     if (((this.Bot != null) && ((this.Bot.HumanoidLogic != null) && (this.Bot.Player != null))) && (this.Bot.Player.Id.SerialId == reservedArea.ReserverId.SerialId))
     {
         MyHumanoidBotLogic humanoidLogic = this.Bot.HumanoidLogic;
         humanoidLogic.ReservationStatus = MyReservationStatus.FAILURE;
         if (success && ((reservedArea.WorldPosition == humanoidLogic.ReservationAreaData.WorldPosition) && (reservedArea.Radius == humanoidLogic.ReservationAreaData.Radius)))
         {
             humanoidLogic.ReservationStatus = MyReservationStatus.SUCCESS;
         }
     }
 }
Ejemplo n.º 2
0
        protected MyBehaviorTreeState TryReserveAreaAroundEntity([BTParam] string areaName, [BTParam] float radius, [BTParam] int timeMs)
        {
            MyHumanoidBotLogic  humanoidLogic = this.Bot.HumanoidLogic;
            MyBehaviorTreeState fAILURE       = MyBehaviorTreeState.FAILURE;

            if (humanoidLogic != null)
            {
                switch (humanoidLogic.ReservationStatus)
                {
                case MyReservationStatus.NONE:
                {
                    humanoidLogic.ReservationStatus = MyReservationStatus.WAITING;
                    MyAiTargetManager.ReservedAreaData data = new MyAiTargetManager.ReservedAreaData {
                        WorldPosition    = this.Bot.HumanoidEntity.WorldMatrix.Translation,
                        Radius           = radius,
                        ReservationTimer = MyTimeSpan.FromMilliseconds((double)timeMs),
                        ReserverId       = new MyPlayer.PlayerId(this.Bot.Player.Id.SteamId, this.Bot.Player.Id.SerialId)
                    };
                    humanoidLogic.ReservationAreaData          = data;
                    MyAiTargetManager.OnAreaReservationResult += new Sandbox.Game.AI.MyAiTargetManager.AreaReservationHandler(this.AreaReservationHandler);
                    MyAiTargetManager.Static.RequestAreaReservation(areaName, this.Bot.HumanoidEntity.WorldMatrix.Translation, radius, (long)timeMs, this.Bot.Player.Id.SerialId);
                    this.m_reservationTimeOut       = MySandboxGame.Static.TotalTime + MyTimeSpan.FromSeconds(3.0);
                    humanoidLogic.ReservationStatus = MyReservationStatus.WAITING;
                    fAILURE = MyBehaviorTreeState.RUNNING;
                    break;
                }

                case MyReservationStatus.WAITING:
                    fAILURE = (this.m_reservationTimeOut >= MySandboxGame.Static.TotalTime) ? MyBehaviorTreeState.RUNNING : MyBehaviorTreeState.FAILURE;
                    break;

                case MyReservationStatus.SUCCESS:
                    fAILURE = MyBehaviorTreeState.SUCCESS;
                    break;

                case MyReservationStatus.FAILURE:
                    fAILURE = MyBehaviorTreeState.FAILURE;
                    break;

                default:
                    break;
                }
            }
            return(fAILURE);
        }
        private void AreaReservationHandler(ref MyAiTargetManager.ReservedAreaData reservedArea, bool success)
        {
            if (Bot == null || Bot.HumanoidLogic == null || Bot.Player == null || Bot.Player.Id.SerialId != reservedArea.ReserverId.SerialId)
            {
                return;
            }
            var logic = Bot.HumanoidLogic;

            logic.ReservationStatus = Logic.MyReservationStatus.FAILURE;
            if (!success)
            {
                return;
            }

            if (reservedArea.WorldPosition == logic.ReservationAreaData.WorldPosition && reservedArea.Radius == logic.ReservationAreaData.Radius)
            {
                logic.ReservationStatus = Logic.MyReservationStatus.SUCCESS;
            }
        }