public static IEnumerable <ResourceSelection> FindConsumableResourcesByRule( IActor actor, IActorTaskContext context, IEnumerable <Resource> resources, ConsumeCommonRuleType ruleType) { foreach (var resource in resources) { var rule = resource.Scheme.Use?.CommonRules? .SingleOrDefault(x => x.Type == ruleType && x.Direction == PersonRuleDirection.Positive); if (rule != null) { var isAllow = UsePropHelper.CheckPropAllowedByRestrictions(resource, actor, context); if (!isAllow) { continue; } yield return(new ResourceSelection { Resource = resource, Rule = rule }); } } }
private static bool CheckPropAllowedByRestriction(UsageRestrictionRule restrictionType, IActor actor, IActorTaskContext context) { switch (restrictionType) { case UsageRestrictionRule.Undefined: throw new InvalidOperationException( $"Restriction type is {nameof(UsageRestrictionRule.Undefined)}."); case UsageRestrictionRule.NoStarvation: return(!IsRestrictedByStarvation(actor)); case UsageRestrictionRule.NoDehydration: return(!IsRestrictedByDehydration(actor)); case UsageRestrictionRule.NoOverdose: return(!IsRestrictedByOverdose(actor)); case UsageRestrictionRule.OnlySafeEnvironment: var hostilesinSector = context.Sector.ActorManager.Items .Where(x => x != actor && actor.Person.Fraction.GetRelation(x.Person.Fraction) == FractionRelation.Enmity); return(!hostilesinSector.Any()); default: throw new NotSupportedException($"Restriction {restrictionType} is unknown."); } }
public TransferPropsTask(IActor actor, IActorTaskContext context, IEnumerable <PropTransfer> transfers) : base(actor, context) { _transfers = transfers.ToArray(); }
public MoveTask(IActor actor, IActorTaskContext context, IGraphNode targetNode, ISectorMap map, int cost) : base(actor, context) { TargetNode = targetNode ?? throw new ArgumentNullException(nameof(targetNode)); _map = map ?? throw new ArgumentNullException(nameof(map)); Cost = cost; if (actor.Node == targetNode) { // Это может произойти, если источник команд выбрал целевую точку ту же, что и сам актёр // в результате рандома. IsComplete = true; _path = new List <IGraphNode>(0); } else { _path = new List <IGraphNode>(); CreatePath(); if (!_path.Any()) { IsComplete = true; } } }
public OpenContainerTask([NotNull] IActor actor, [NotNull] IActorTaskContext context, [NotNull] IStaticObject staticObject, [NotNull] IOpenContainerMethod method) : base(actor, context) { _staticObject = staticObject ?? throw new ArgumentNullException(nameof(staticObject)); _method = method ?? throw new ArgumentNullException(nameof(method)); }
public MineTask(IActor actor, IActorTaskContext context, IStaticObject staticObject, IMineDepositMethod method) : base(actor, context) { _staticObject = staticObject ?? throw new ArgumentNullException(nameof(staticObject)); _method = method ?? throw new ArgumentNullException(nameof(method)); }
public IdleTask(IActor actor, IActorTaskContext context, int duration) : base(actor, context) { if (actor is null) { throw new ArgumentNullException(nameof(actor)); } _counter = duration; }
public EquipTask(IActor actor, IActorTaskContext context, Equipment equipment, int slotIndex) : base(actor, context) { _equipment = equipment; _slotIndex = slotIndex; }
public static Resource FindBestConsumableResourceByRule( IActor actor, IActorTaskContext context, IEnumerable <Resource> resources, ConsumeCommonRuleType ruleType) { var foundResources = FindConsumableResourcesByRule(actor, context, resources, ruleType); var orderedResources = foundResources.OrderByDescending(x => x.Rule.Level); var bestResource = orderedResources.FirstOrDefault(); return(bestResource?.Resource); }
public IdleTask(IActor actor, IActorTaskContext context, IDecisionSource decisionSource) : base(actor, context) { if (actor is null) { throw new ArgumentNullException(nameof(actor)); } if (decisionSource is null) { throw new ArgumentNullException(nameof(decisionSource)); } _counter = decisionSource.SelectIdleDuration(IDLE_MIN, IDLE_MAX); }
public AttackTask(IActor actor, IActorTaskContext context, IAttackTarget target, ITacticalAct tacticalAct, ITacticalActUsageService actService) : base(actor, context) { _actService = actService; TargetObject = target ?? throw new ArgumentNullException(nameof(target)); TacticalAct = tacticalAct ?? throw new ArgumentNullException(nameof(tacticalAct)); TargetNode = target.Node; }
public AttackTask(IActor actor, IActorTaskContext context, IAttackTarget target, ICombatAct tacticalAct, ITacticalActUsageService actService) : base(actor, context) { _actService = actService; TargetObject = target ?? throw new ArgumentNullException(nameof(target)); TacticalAct = tacticalAct ?? throw new ArgumentNullException(nameof(tacticalAct)); TargetNode = target.Node; var combatActDuration = tacticalAct.Stats.Duration.GetValueOrDefault(1); var durationBonus = GetDurationBonus(actor); var durationWithBonus = (int)Math.Round(GlobeMetrics.OneIterationLength * combatActDuration * durationBonus); Cost = durationWithBonus; }
protected OneTurnActorTaskBase(IActor actor, IActorTaskContext context) : base(actor, context) { }
protected ActorTaskBase([NotNull] IActor actor, IActorTaskContext context) { Actor = actor ?? throw new ArgumentNullException(nameof(actor)); Context = context ?? throw new ArgumentNullException(nameof(context)); }
public MoveTask(IActor actor, IActorTaskContext context, IGraphNode targetNode, ISectorMap map) : this(actor, context, targetNode, map, GlobeMetrics.OneIterationLength) { }
/// <summary> /// Checks a prop allowed to use by restriction rules. /// </summary> /// <param name="usedProp">The prop to use.</param> /// <param name="actor">The actor using the prop.</param> /// <param name="context"> The context of usage. </param> /// <returns>Returns true if usage allowed. Otherwise - false.</returns> public static bool CheckPropAllowedByRestrictions(IProp usedProp, IActor actor, IActorTaskContext context) { var restrictions = usedProp.Scheme.Use?.Restrictions; if (restrictions is null) { // Prop without restrictions automaticcaly allowed. return(true); } if (restrictions.Items is null) { Debug.Fail("The restriction items can not be null."); // There are restrictions but items is null. This is incorrect. // We know it restricted but don't know how to check it. // So prop is now allowed at all. return(false); } foreach (var restriction in restrictions.Items) { if (restriction is null) { continue; } var isAllowed = CheckPropAllowedByRestriction(restriction.Type, actor, context); if (!isAllowed) { return(false); } } // No restrictions were fired means usage allowed. return(true); }
public SectorTransitTask(IActor actor, IActorTaskContext context) : base(actor, context) { }
public UsePropTask(IActor actor, IActorTaskContext context, IProp usedProp) : base(actor, context) { UsedProp = usedProp; }