private void ReservationHandler(ref MyAiTargetManager.ReservedEntityData reservedEntity, bool success) { if (Bot == null || Bot.HumanoidLogic == null || Bot.Player == null || Bot.Player.Id.SerialId != reservedEntity.ReserverId.SerialId) { return; } var logic = Bot.HumanoidLogic; logic.EntityReservationStatus = Logic.MyEntityReservationStatus.FAILURE; if (!success) { return; } if (reservedEntity.EntityId != logic.ReservationEntityData.EntityId) { return; } if (reservedEntity.Type == MyReservedEntityType.ENVIRONMENT_ITEM && reservedEntity.LocalId != logic.ReservationEntityData.LocalId) { return; } if (reservedEntity.Type == MyReservedEntityType.VOXEL && reservedEntity.GridPos != logic.ReservationEntityData.GridPos) { return; } logic.EntityReservationStatus = Logic.MyEntityReservationStatus.SUCCESS; }
private void ReservationHandler(ref MyAiTargetManager.ReservedEntityData reservedEntity, bool success) { if (((this.Bot != null) && ((this.Bot.HumanoidLogic != null) && (this.Bot.Player != null))) && (this.Bot.Player.Id.SerialId == reservedEntity.ReserverId.SerialId)) { MyHumanoidBotLogic humanoidLogic = this.Bot.HumanoidLogic; humanoidLogic.ReservationStatus = MyReservationStatus.FAILURE; if (((success && (reservedEntity.EntityId == humanoidLogic.ReservationEntityData.EntityId)) && ((reservedEntity.Type != MyReservedEntityType.ENVIRONMENT_ITEM) || (reservedEntity.LocalId == humanoidLogic.ReservationEntityData.LocalId))) && ((reservedEntity.Type != MyReservedEntityType.VOXEL) || (reservedEntity.GridPos == humanoidLogic.ReservationEntityData.GridPos))) { humanoidLogic.ReservationStatus = MyReservationStatus.SUCCESS; } } }
protected MyBehaviorTreeState TryReserveEntity([BTIn] ref MyBBMemoryTarget inTarget, [BTParam] int timeMs) { if ((this.Bot != null) && (this.Bot.Player != null)) { MyHumanoidBotLogic humanoidLogic = this.Bot.HumanoidLogic; if (((inTarget != null) && ((inTarget.EntityId != null) && (inTarget.TargetType != MyAiTargetEnum.POSITION))) && (inTarget.TargetType != MyAiTargetEnum.NO_TARGET)) { switch (humanoidLogic.ReservationStatus) { case MyReservationStatus.NONE: MyAiTargetManager.ReservedEntityData data; switch (inTarget.TargetType) { case MyAiTargetEnum.GRID: case MyAiTargetEnum.CUBE: case MyAiTargetEnum.CHARACTER: case MyAiTargetEnum.ENTITY: humanoidLogic.ReservationStatus = MyReservationStatus.WAITING; data = new MyAiTargetManager.ReservedEntityData { Type = MyReservedEntityType.ENTITY, EntityId = inTarget.EntityId.Value, ReservationTimer = timeMs, ReserverId = new MyPlayer.PlayerId(this.Bot.Player.Id.SteamId, this.Bot.Player.Id.SerialId) }; humanoidLogic.ReservationEntityData = data; MyAiTargetManager.OnReservationResult += new Sandbox.Game.AI.MyAiTargetManager.ReservationHandler(this.ReservationHandler); MyAiTargetManager.Static.RequestEntityReservation(humanoidLogic.ReservationEntityData.EntityId, humanoidLogic.ReservationEntityData.ReservationTimer, this.Bot.Player.Id.SerialId); break; case MyAiTargetEnum.ENVIRONMENT_ITEM: humanoidLogic.ReservationStatus = MyReservationStatus.WAITING; data = new MyAiTargetManager.ReservedEntityData { Type = MyReservedEntityType.ENVIRONMENT_ITEM, EntityId = inTarget.EntityId.Value, LocalId = inTarget.TreeId.Value, ReservationTimer = timeMs, ReserverId = new MyPlayer.PlayerId(this.Bot.Player.Id.SteamId, this.Bot.Player.Id.SerialId) }; humanoidLogic.ReservationEntityData = data; MyAiTargetManager.OnReservationResult += new Sandbox.Game.AI.MyAiTargetManager.ReservationHandler(this.ReservationHandler); MyAiTargetManager.Static.RequestEnvironmentItemReservation(humanoidLogic.ReservationEntityData.EntityId, humanoidLogic.ReservationEntityData.LocalId, humanoidLogic.ReservationEntityData.ReservationTimer, this.Bot.Player.Id.SerialId); break; case MyAiTargetEnum.VOXEL: humanoidLogic.ReservationStatus = MyReservationStatus.WAITING; data = new MyAiTargetManager.ReservedEntityData { Type = MyReservedEntityType.VOXEL, EntityId = inTarget.EntityId.Value, GridPos = inTarget.VoxelPosition, ReservationTimer = timeMs, ReserverId = new MyPlayer.PlayerId(this.Bot.Player.Id.SteamId, this.Bot.Player.Id.SerialId) }; humanoidLogic.ReservationEntityData = data; MyAiTargetManager.OnReservationResult += new Sandbox.Game.AI.MyAiTargetManager.ReservationHandler(this.ReservationHandler); MyAiTargetManager.Static.RequestVoxelPositionReservation(humanoidLogic.ReservationEntityData.EntityId, humanoidLogic.ReservationEntityData.GridPos, humanoidLogic.ReservationEntityData.ReservationTimer, this.Bot.Player.Id.SerialId); break; default: humanoidLogic.ReservationStatus = MyReservationStatus.FAILURE; break; } this.m_reservationTimeOut = MySandboxGame.Static.TotalTime + MyTimeSpan.FromSeconds(3.0); break; case MyReservationStatus.WAITING: if (this.m_reservationTimeOut < MySandboxGame.Static.TotalTime) { humanoidLogic.ReservationStatus = MyReservationStatus.FAILURE; } break; default: break; } } switch (humanoidLogic.ReservationStatus) { case MyReservationStatus.WAITING: return(MyBehaviorTreeState.RUNNING); case MyReservationStatus.SUCCESS: return(MyBehaviorTreeState.SUCCESS); } } return(MyBehaviorTreeState.FAILURE); }