public override IActorTask GetTask(IActor actor, ILogicStrategyData strategyData) { var hpStat = actor.Person.Survival.Stats.SingleOrDefault(x => x.Type == SurvivalStatType.Health); 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.Inventory.CalcActualItems(); var resources = props.OfType <Resource>(); var bestResource = ResourceFinder.FindBestConsumableResourceByRule(resources, ConsumeCommonRuleType.Health); if (bestResource == null) { Complete = true; return(null); } return(new UsePropTask(actor, bestResource)); }
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)); }
private UsePropTask CheckHazard(IActor actor, SurvivalStatType hazardType, ConsumeCommonRuleType resourceType) { var hazardEffect = actor.Person.Effects.Items.OfType <SurvivalStatHazardEffect>() .SingleOrDefault(x => x.Type == hazardType); if (hazardEffect == null) { return(null); } var props = actor.Person.Inventory.CalcActualItems(); var resources = props.OfType <Resource>(); var bestResource = ResourceFinder.FindBestConsumableResourceByRule(resources, resourceType); if (bestResource == null) { return(null); } return(new UsePropTask(actor, bestResource)); }