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 void CheckPropAllowedByRestrictions_HasMaxSurivalHazardEffect_UsageIsNoAllowed( SurvivalStatType effectStatType, UsageRestrictionRule usageRule) { // ARRANGE var personMock = new Mock <IPerson>(); var сonditionsModuleMock = new Mock <IConditionsModule>(); var сonditions = new[] { new SurvivalStatHazardCondition(effectStatType, SurvivalStatHazardLevel.Max, Mock.Of <ISurvivalRandomSource>()) }; сonditionsModuleMock.Setup(x => x.Items).Returns(сonditions); personMock.Setup(x => x.GetModule <IConditionsModule>(nameof(IConditionsModule))) .Returns(сonditionsModuleMock.Object); personMock.Setup(x => x.HasModule(nameof(IConditionsModule))).Returns(true); var actor = Mock.Of <IActor>(x => x.Person == personMock.Object); var propScheme = new TestPropScheme { Use = new TestPropUseSubScheme { Restrictions = Mock.Of <IUsageRestrictions>(x => x.Items == new[] { Mock.Of <IUsageRestrictionItem>(item => item.Type == usageRule) }) } }; var prop = new Resource(propScheme, 1); var context = Mock.Of <IActorTaskContext>(); // ACT var fact = UsePropHelper.CheckPropAllowedByRestrictions(prop, actor, context); // ASSERT fact.Should().BeFalse(); }