protected override void ExecuteTacticCommand() { if (SlotIndex is null) { throw new InvalidOperationException("Для команды не указан слот."); } var equipment = GetSelectedEquipmentInInventory(); var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); var intention = new Intention <EquipTask>(a => new EquipTask(a, taskContext, equipment, SlotIndex.Value)); var taskSource = PlayerState.TaskSource; if (taskSource is null) { throw new InvalidOperationException(); } var activeActor = PlayerState.ActiveActor?.Actor; if (activeActor is null) { throw new InvalidOperationException(); } taskSource.Intent(intention, activeActor); }
/// <summary> /// Выполнение команды на перемещение и обновление игрового цикла. /// </summary> protected override void ExecuteTacticCommand() { var taskContext = new ActorTaskContext(_player.SectorNode.Sector); var intention = new Intention <SectorTransitTask>(a => new SectorTransitTask(a, taskContext)); PlayerState.TaskSource.Intent(intention, PlayerState.ActiveActor.Actor); }
private MoveTask CreateBypassMoveTask(IActor actor, ILogicStrategyData strategyData, ISector sector) { var map = sector.Map; var frontNodes = WriteObservedNodesOrGetFromFow(actor, strategyData, sector).ToArray(); if (!frontNodes.Any()) { return(null); } var availableNodesArray = frontNodes as HexNode[] ?? frontNodes.ToArray(); if (availableNodesArray.Length == 0) { // There is no nodes available to roaming. // We can do nothing. return(null); } for (var i = 0; i < 3; i++) { var targetNode = DecisionSource.SelectTargetRoamingNode(availableNodesArray); if (map.IsPositionAvailableFor(targetNode, actor)) { var context = new ActorTaskContext(sector); var moveTask = new MoveTask(actor, context, targetNode, map); return(moveTask); } } return(null); }
public static bool TestHazardAndResource( IActor actor, ActorTaskContext taskContext, ILogicStrategyData strategyData, SurvivalStatType statType, ConsumeCommonRuleType ruleType) { var hasHazardEffect = HasCondition(actor, statType); if (!hasHazardEffect) { return(false); } var resource = ResourceToReduceHazard(actor, taskContext, ruleType); if (resource is null) { strategyData.ResourceToReduceHazard = null; return(false); } strategyData.ResourceToReduceHazard = resource; return(true); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { var inventory = actor.Person.GetModule <IInventoryModule>(); var currentInventoryProps = inventory.CalcActualItems(); var currentInventoryEquipments = currentInventoryProps.OfType <Equipment>().ToArray(); var equipmentCarrier = actor.Person.GetModule <IEquipmentModule>(); for (var slotIndex = 0; slotIndex < equipmentCarrier.Slots.Length; slotIndex++) { var slot = actor.Person.GetModule <IEquipmentModule>().Slots[slotIndex]; var equiped = actor.Person.GetModule <IEquipmentModule>()[slotIndex]; if (equiped == null) { var availableEquipments = currentInventoryEquipments .Where(equipment => (equipment.Scheme.Equip.SlotTypes[0] & slot.Types) > 0) .Where(equipment => EquipmentCarrierHelper.CanBeEquiped(equipmentCarrier, slotIndex, equipment)) .ToArray(); if (availableEquipments.Any()) { var targetEquipmentFromInventory = availableEquipments.First(); var targetSlotIndex = slotIndex; var taskContext = new ActorTaskContext(context.Sector); return(new EquipTask(actor, taskContext, targetEquipmentFromInventory, targetSlotIndex)); } } } Complete = true; return(null); }
/// <summary> /// Выполнение команды на перемещение и обновление игрового цикла. /// </summary> protected override void ExecuteTacticCommand() { var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); var intention = new Intention <SectorTransitTask>(a => new SectorTransitTask(a, taskContext)); var actor = PlayerState.ActiveActor?.Actor; if (actor is null) { throw new InvalidOperationException(); } var taskSource = PlayerState.TaskSource; if (taskSource is null) { throw new InvalidOperationException(); } taskSource.Intent(intention, actor); // Drop waiting because the globe must not wait the person which is not in a sector. taskSource.DropIntentionWaiting(); }
private MineTask CreateTaskByHands(IActor actor, IStaticObject staticObject) { var handMineDepositMethod = new HandMineDepositMethod(_mineDepositMethodRandomSource); var taskContext = new ActorTaskContext(_player.SectorNode.Sector); return(new MineTask(actor, taskContext, staticObject, handMineDepositMethod)); }
private MineTask CreateTaskByInstrument(IActor actor, IStaticObject staticObject, Equipment equipedTool) { var toolMineDepositMethod = new ToolMineDepositMethod(equipedTool, _mineDepositMethodRandomSource); var taskContext = new ActorTaskContext(_player.SectorNode.Sector); return(new MineTask(actor, taskContext, staticObject, toolMineDepositMethod)); }
private OpenContainerTask CreateTask(IActor actor, IStaticObject staticObject) { var openMethod = new HandOpenContainerMethod(); var taskContext = new ActorTaskContext(_player.SectorNode.Sector); return(new OpenContainerTask(actor, taskContext, staticObject, openMethod)); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { var triggerTarget = strategyData.TriggerIntuder; if (triggerTarget == null) { throw new InvalidOperationException( $"Assign {nameof(strategyData.TriggerIntuder)} with not null valie in related trigger."); } var targetCanBeDamaged = triggerTarget.CanBeDamaged(); if (!targetCanBeDamaged) { Complete = true; return(null); } var attackParams = CheckAttackAvailability(actor, triggerTarget, context.Sector.Map); if (attackParams.IsAvailable) { var act = attackParams.CombatAct; var taskContext = new ActorTaskContext(context.Sector); var attackTask = new AttackTask(actor, taskContext, triggerTarget, act, _actService); return(attackTask); } // Маршрут до цели обновляем каждые 3 хода. // Для оптимизации. // Эффект потери цели. if (_refreshCounter > 0 && _moveTask?.CanExecute() == true) { _refreshCounter--; return(_moveTask); } var map = context.Sector.Map; _refreshCounter = REFRESH_COUNTER_VALUE; var targetIsOnLine = map.TargetIsOnLine(actor.Node, triggerTarget.Node); if (targetIsOnLine) { var taskContext = new ActorTaskContext(context.Sector); var moveModule = actor.Person.GetModule <IMovingModule>(); var moveCost = moveModule.CalculateCost(); _moveTask = new MoveTask(actor, taskContext, triggerTarget.Node, map, moveCost); return(_moveTask); } // Цел за пределами видимости. Считается потерянной. return(null); }
protected override void ExecuteTacticCommand() { var propVm = _inventoryState.SelectedProp; var usableProp = propVm.Prop; var taskContext = new ActorTaskContext(_player.SectorNode.Sector); var intention = new Intention <UsePropTask>(actor => new UsePropTask(actor, taskContext, usableProp)); PlayerState.TaskSource.Intent(intention, PlayerState.ActiveActor.Actor); }
protected override bool TestInner(IActor actor, ISectorTaskSourceContext context, ILogicState currentState, ILogicStrategyData strategyData) { var taskContext = new ActorTaskContext(context.Sector); return(SurvivalHazardTriggerHelper.TestHazardAndResource( actor, taskContext, strategyData, SurvivalStatType.Satiety, ConsumeCommonRuleType.Satiety)); }
private IdleTask CreateIdleTask(IActor actor) { var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); return(new IdleTask(actor, taskContext, GlobeMetrics.OneIterationLength)); }
protected override void ExecuteTacticCommand() { var target = GetTarget(PlayerState); var tacticalAct = PlayerState.TacticalAct; var taskContext = new ActorTaskContext(_player.SectorNode.Sector); var intention = new Intention <AttackTask>(a => new AttackTask(a, taskContext, target, tacticalAct, _tacticalActUsageService)); PlayerState.TaskSource.Intent(intention, PlayerState.ActiveActor.Actor); }
public override CanExecuteCheckResult CanExecute() { var propVm = _inventoryState.SelectedProp; if (propVm == null) { return(new CanExecuteCheckResult { IsSuccess = false }); } var prop = propVm.Prop; if (prop == null) { throw new AppException("Для модели представления не задан предмет."); } if (prop.Scheme.Use == null) { throw new AppException("Попытка использовать предмет, для которого нет информации об использовании."); } var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); var actor = PlayerState.ActiveActor?.Actor; if (actor is null) { throw new InvalidOperationException(); } var isAllowed = UsePropHelper.CheckPropAllowedByRestrictions(prop, actor, taskContext); if (!isAllowed) { return(new CanExecuteCheckResult { IsSuccess = false }); } return(new CanExecuteCheckResult { IsSuccess = true }); }
private static IActorTask TakeAllFromContainerTask(IActor actor, IStaticObject container, ISector sector) { var inventoryTransfer = new PropTransfer(actor.Person.GetModule <IInventoryModule>(), container.GetModule <IPropContainer>().Content.CalcActualItems(), Array.Empty <IProp>()); var containerTransfer = new PropTransfer(container.GetModule <IPropContainer>().Content, Array.Empty <IProp>(), container.GetModule <IPropContainer>().Content.CalcActualItems()); var taskContext = new ActorTaskContext(sector); return(new TransferPropsTask(actor, taskContext, new[] { inventoryTransfer, containerTransfer })); }
private MineTask CreateTaskByHands(IActor actor, IStaticObject staticObject) { var handMineDepositMethod = new HandMineDepositMethod(_mineDepositMethodRandomSource); var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); return(new MineTask(actor, taskContext, staticObject, handMineDepositMethod)); }
private MineTask CreateTaskByInstrument(IActor actor, IStaticObject staticObject, Equipment equipedTool) { var toolMineDepositMethod = new ToolMineDepositMethod(equipedTool, _mineDepositMethodRandomSource); var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); return(new MineTask(actor, taskContext, staticObject, toolMineDepositMethod)); }
private OpenContainerTask CreateTask(IActor actor, IStaticObject staticObject) { var openMethod = new HandOpenContainerMethod(); var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); return(new OpenContainerTask(actor, taskContext, staticObject, openMethod)); }
public bool Test(IActor actor, ISectorTaskSourceContext context, ILogicState currentState, ILogicStrategyData strategyData) { if (actor is null) { throw new ArgumentNullException(nameof(actor)); } if (currentState is null) { throw new ArgumentNullException(nameof(currentState)); } if (strategyData is null) { throw new ArgumentNullException(nameof(strategyData)); } //TODO Здесь лучше проверять на наличие эффекта раны var hpStat = actor.Person.GetModule <ISurvivalModule>().Stats .SingleOrDefault(x => x.Type == SurvivalStatType.Health); var isLowHp = hpStat.ValueShare <= 0.5f; if (!isLowHp) { return(false); } // var props = actor.Person.GetModule <IInventoryModule>().CalcActualItems(); var resources = props.OfType <Resource>(); var taskContext = new ActorTaskContext(context.Sector); var bestResource = ResourceFinder.FindBestConsumableResourceByRule( actor, taskContext, resources, ConsumeCommonRuleType.Health); if (bestResource == null) { return(false); } return(true); }
private static UsePropTask CreateTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { if (strategyData.ResourceToReduceHazard is null) { throw new InvalidOperationException( $"Assign {nameof(strategyData.ResourceToReduceHazard)} value in the triggers first."); } var taskContxt = new ActorTaskContext(context.Sector); var prop = strategyData.ResourceToReduceHazard; // When prop was used it no need to store anymore. strategyData.ResourceToReduceHazard = null; return(new UsePropTask(actor, taskContxt, prop)); }
protected override void ExecuteTacticCommand() { var inventoryTransfer = new PropTransfer(TransferMachine.Inventory.PropStore, TransferMachine.Inventory.PropAdded, TransferMachine.Inventory.PropRemoved); var containerTransfer = new PropTransfer(TransferMachine.Container.PropStore, TransferMachine.Container.PropAdded, TransferMachine.Container.PropRemoved); var taskContext = new ActorTaskContext(_player.SectorNode.Sector); var intention = new Intention <TransferPropsTask>(actor => new TransferPropsTask(actor, taskContext, new[] { inventoryTransfer, containerTransfer })); PlayerState.TaskSource.Intent(intention, PlayerState.ActiveActor.Actor); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { if (actor is null) { throw new System.ArgumentNullException(nameof(actor)); } if (context is null) { throw new System.ArgumentNullException(nameof(context)); } var hpStat = actor.Person.GetModule <ISurvivalModule>().Stats .SingleOrDefault(x => x.Type == SurvivalStatType.Health); if (hpStat == null) { Complete = true; return(null); } var hpStatCoeff = (float)hpStat.Value / (hpStat.Range.Max - hpStat.Range.Min); var isLowHp = hpStatCoeff <= 0.5f; if (!isLowHp) { Complete = true; return(null); } var props = actor.Person.GetModule <IInventoryModule>().CalcActualItems(); var resources = props.OfType <Resource>(); var bestResource = ResourceFinder.FindBestConsumableResourceByRule(resources, ConsumeCommonRuleType.Health); if (bestResource == null) { Complete = true; return(null); } var taskContext = new ActorTaskContext(context.Sector); return(new UsePropTask(actor, taskContext, bestResource)); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { if (_idleTask == null) { var taskContext = new ActorTaskContext(context.Sector); _idleTask = new IdleTask(actor, taskContext, _decisionSource); } if (_idleTask.IsComplete) { Complete = true; return(null); } return(_idleTask); }
private static MoveTask CreateMoveTask(IActor actor, IGraphNode targetExitNode, ISector sector, ISectorMap map) { var targetNodeIsBlockedByObstacles = GetObstableInNode(sector, targetExitNode); Debug.Assert(!targetNodeIsBlockedByObstacles, "Узел с выходом не должен быть препятствием."); if (!map.IsPositionAvailableFor(targetExitNode, actor)) { return(null); } var context = new ActorTaskContext(sector); var moveTask = new MoveTask(actor, context, targetExitNode, map); return(moveTask); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { if (strategyData.TargetEquipment is null || strategyData.TargetEquipmentSlotIndex is null) { throw new InvalidOperationException("Assign TargetEquipment and TargetEquipmentSlot in trigger first."); } var targetEquipmentFromInventory = strategyData.TargetEquipment; var targetSlotIndex = strategyData.TargetEquipmentSlotIndex; var taskContext = new ActorTaskContext(context.Sector); var task = new EquipTask(actor, taskContext, targetEquipmentFromInventory, targetSlotIndex.Value); Complete = true; return(task); }
public override IActorTask GetTask(IActor actor, ISectorTaskSourceContext context, ILogicStrategyData strategyData) { if (MoveTask == null) { MoveTask = CreateBypassMoveTask(actor, strategyData, context.Sector); if (MoveTask != null) { return(MoveTask); } // Это может произойти, если актёр не выбрал следующий узел. // Тогда переводим актёра в режим ожидания. var taskContext = new ActorTaskContext(context.Sector); IdleTask = new IdleTask(actor, taskContext, DecisionSource); return(IdleTask); } if (!MoveTask.IsComplete) { // Если команда на перемещение к целевой точке патруля не закончена, // тогда продолжаем её. // Предварительно проверяем, не мешает ли что-либо её продолжить выполнять. if (!MoveTask.CanExecute()) { MoveTask = CreateBypassMoveTask(actor, strategyData, context.Sector); } if (MoveTask != null) { return(MoveTask); } var taskContext = new ActorTaskContext(context.Sector); IdleTask = new IdleTask(actor, taskContext, DecisionSource); return(IdleTask); } Complete = true; return(null); }
protected override void ExecuteTacticCommand() { var target = GetTarget(PlayerState); if (target is null) { throw new InvalidOperationException(); } var tacticalAct = PlayerState.TacticalAct; if (tacticalAct is null) { throw new InvalidOperationException(); } var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var taskContext = new ActorTaskContext(sector); var intention = new Intention <AttackTask>(a => new AttackTask(a, taskContext, target, tacticalAct, _tacticalActUsageService)); var actor = PlayerState.ActiveActor?.Actor; if (actor is null) { throw new InvalidOperationException(); } var taskSource = PlayerState.TaskSource; if (taskSource is null) { throw new InvalidOperationException(); } taskSource.Intent(intention, actor); }
private static Resource ResourceToReduceHazard(IActor actor, ActorTaskContext taskContext, ConsumeCommonRuleType ruleType) { if (actor is null) { throw new ArgumentNullException(nameof(actor)); } var props = actor.Person.GetModule <IInventoryModule>().CalcActualItems(); var resources = props.OfType <Resource>(); var bestResource = ResourceFinder.FindBestConsumableResourceByRule( actor, taskContext, resources, ruleType); return(bestResource); }
protected override void ExecuteTacticCommand() { if (TransferMachine is null) { throw new InvalidOperationException(); } var sector = _player.SectorNode.Sector; if (sector is null) { throw new InvalidOperationException(); } var inventoryTransfer = new PropTransfer(TransferMachine.Inventory.PropStore, TransferMachine.Inventory.PropAdded, TransferMachine.Inventory.PropRemoved); var containerTransfer = new PropTransfer(TransferMachine.Container.PropStore, TransferMachine.Container.PropAdded, TransferMachine.Container.PropRemoved); var taskContext = new ActorTaskContext(sector); var intention = new Intention <TransferPropsTask>(actor => new TransferPropsTask(actor, taskContext, new[] { inventoryTransfer, containerTransfer })); var actor = PlayerState.ActiveActor?.Actor; if (actor is null) { throw new InvalidOperationException(); } var taskSource = PlayerState.TaskSource; if (taskSource is null) { throw new InvalidOperationException(); } taskSource.Intent(intention, actor); }