private static string GetStatHazardConditionTypeClientString(SurvivalStatType type) { switch (type) { case SurvivalStatType.Health: return("Wound"); case SurvivalStatType.Satiety: return("Hunger"); case SurvivalStatType.Hydration: return("Thrist"); case SurvivalStatType.Intoxication: return("Intoxication"); case SurvivalStatType.Undefined: Debug.Fail("Undefined condition."); return("Empty"); default: Debug.Fail($"Unknown condition type {type}."); return("Empty"); } }
private static SurvivalStatHazardCondition GetCurrentСondition(IConditionsModule сonditionModule, SurvivalStatType statType) { return(сonditionModule.Items .OfType <SurvivalStatHazardCondition>() .SingleOrDefault(x => x.Type == statType)); }
public void Init(SurvivalStatType type, SurvivalStatHazardLevel level) { Type = type; Level = level; SelectIcon(type); HighlightLevel(level); }
private static SurvivalStatHazardEffect GetCurrentEffect(IEffectsModule currentEffects, SurvivalStatType statType) { return(currentEffects.Items .OfType <SurvivalStatHazardEffect>() .SingleOrDefault(x => x.Type == statType)); }
private void DecreaseSurvivalStatInner(SurvivalStatType statType, PersonRuleLevel level) { switch (level) { case PersonRuleLevel.Lesser: Person.Survival.DecreaseStat(statType, PropMetrics.SurvivalLesserRestoreValue - 1); break; case PersonRuleLevel.Normal: Person.Survival.DecreaseStat(statType, PropMetrics.SurvivalNormalRestoreValue - 1); break; case PersonRuleLevel.Grand: Person.Survival.DecreaseStat(statType, PropMetrics.SurvivalGrandRestoreValue - 1); break; case PersonRuleLevel.None: throw new NotSupportedException(); case PersonRuleLevel.Absolute: throw new NotSupportedException(); default: throw new InvalidOperationException($"Неизвестный уровень влияния правила {level}."); } }
public SurvivalStatHazardEffect(SurvivalStatType type, SurvivalStatHazardLevel level) { Type = type; Level = level; Rules = CalcRules(); }
/// <summary> /// Помещает в список бонус на ХП. /// </summary> /// <param name="level"> Уровень бонуса. </param> /// <param name="direction"> Направление бонуса. </param> /// <param name="bonuses"> /// Аккумулирующий список бонусов. /// Отмечен ref, чтобы показать, что изменяется внутри метода. /// </param> private void BonusToHealth(PersonRuleLevel level, PersonRuleDirection direction, ref List <SurvivalStatBonus> bonuses) { const SurvivalStatType HP_STAT_TYPE = SurvivalStatType.Health; var hpStat = Stats.SingleOrDefault(x => x.Type == HP_STAT_TYPE); if (hpStat != null) { var bonus = 0; bonus = GetBonusByLevel(level); if (direction == PersonRuleDirection.Negative) { bonus *= -1; } var currentBonus = bonuses.SingleOrDefault(x => x.SurvivalStatType == HP_STAT_TYPE); if (currentBonus == null) { currentBonus = new SurvivalStatBonus(HP_STAT_TYPE); bonuses.Add(currentBonus); } currentBonus.ValueBonus += bonus; } }
private static SurvivalStat CreateStat( SurvivalStatType type, PersonSurvivalStatType schemeStatType, IPersonSurvivalStatSubScheme[] survivalStats) { var statScheme = survivalStats.SingleOrDefault(x => x.Type == schemeStatType); if (statScheme is null) { return(null); } var keySegmentList = new List <SurvivalStatKeySegment>(); if (statScheme.KeyPoints != null) { AddKeyPointFromScheme(SurvivalStatHazardLevel.Max, PersonSurvivalStatKeypointLevel.Max, statScheme.KeyPoints, keySegmentList); AddKeyPointFromScheme(SurvivalStatHazardLevel.Strong, PersonSurvivalStatKeypointLevel.Strong, statScheme.KeyPoints, keySegmentList); AddKeyPointFromScheme(SurvivalStatHazardLevel.Lesser, PersonSurvivalStatKeypointLevel.Lesser, statScheme.KeyPoints, keySegmentList); } var stat = new SurvivalStat(statScheme.StartValue, statScheme.MinValue, statScheme.MaxValue) { Type = type, Rate = 1, KeySegments = keySegmentList.ToArray(), DownPassRoll = statScheme.DownPassRoll.GetValueOrDefault(SurvivalStat.DEFAULT_DOWN_PASS_VALUE) }; return(stat); }
private static SurvivalStat CreateStat(SurvivalStatType type) { var stat = new SurvivalStat(50) { Type = type, Range = new Range <int>(-100, 100), Rate = 1, KeyPoints = new[] { new SurvivalStatKeyPoint { Level = SurvivalStatHazardLevel.Lesser, Value = 0 }, new SurvivalStatKeyPoint { Level = SurvivalStatHazardLevel.Strong, Value = -25 }, new SurvivalStatKeyPoint { Level = SurvivalStatHazardLevel.Max, Value = -50 } } }; return(stat); }
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 int Update_ModifiedDownPass_StatDownCorrectly(int statDownPass, int downPassRoll) { // ARRANGE const int STAT_RATE = 1; const int MIN_STAT_VALUE = 0; const int MAX_STAT_VALUE = 1; const int START_STAT_VALUE = MAX_STAT_VALUE; const SurvivalStatType STAT_TYPE = SurvivalStatType.Satiety; var survivalRandomSourceMock = new Mock <ISurvivalRandomSource>(); survivalRandomSourceMock.Setup(x => x.RollSurvival(It.IsAny <SurvivalStat>())) .Returns(downPassRoll); var survivalRandomSource = survivalRandomSourceMock.Object; var survivalStats = new[] { new SurvivalStat(START_STAT_VALUE, MIN_STAT_VALUE, MAX_STAT_VALUE) { Type = STAT_TYPE, Rate = STAT_RATE, DownPassRoll = statDownPass } }; var survivalData = new HumanSurvivalModule(survivalStats, survivalRandomSource); // ACT survivalData.Update(); // ASSERT return(survivalStats[0].Value); }
private static SurvivalStat CreateStatFromScheme(IPersonSurvivalStatSubScheme[] survivalStats, SurvivalStatType statType, PersonSurvivalStatType schemeStatType) { var stat = CreateStat(statType, schemeStatType, survivalStats); return(stat ?? null); }
public void Update_StatNearKeyPoint_RaiseEventWithCorrectValues() { // ARRANGE const SurvivalStatType STAT_TYPE = SurvivalStatType.Satiety; const int MIN_STAT_VALUE = 0; const int MAX_STAT_VALUE = 1; const int START_STAT_VALUE = MAX_STAT_VALUE; const int LESSER_SURVIVAL_STAT_KEYPOINT = 0; const SurvivalStatHazardLevel LESSER_SURVIVAL_STAT_KEYPOINT_TYPE = SurvivalStatHazardLevel.Lesser; const int STAT_RATE = 1; const int EXPECTED_SURVIVAL_STAT_KEYPOINT = LESSER_SURVIVAL_STAT_KEYPOINT; const int FAKE_ROLL_SURVIVAL_RESULT = 6; var survivalRandomSourceMock = new Mock <ISurvivalRandomSource>(); survivalRandomSourceMock.Setup(x => x.RollSurvival(It.IsAny <SurvivalStat>())) .Returns(FAKE_ROLL_SURVIVAL_RESULT); var survivalRandomSource = survivalRandomSourceMock.Object; var survivalStats = new SurvivalStat[] { new SurvivalStat(START_STAT_VALUE, MIN_STAT_VALUE, MAX_STAT_VALUE) { Type = STAT_TYPE, Rate = STAT_RATE, KeyPoints = new[] { new SurvivalStatKeyPoint( LESSER_SURVIVAL_STAT_KEYPOINT_TYPE, LESSER_SURVIVAL_STAT_KEYPOINT) } } }; var survivalData = new HumanSurvivalData(_personScheme, survivalStats, survivalRandomSource); // ACT using (var monitor = survivalData.Monitor()) { survivalData.Update(); // ASSERT monitor.Should().Raise(nameof(ISurvivalData.StatCrossKeyValue)) .WithArgs <SurvivalStatChangedEventArgs>(args => args.Stat.Type == STAT_TYPE && args.KeyPoints.FirstOrDefault().Level == LESSER_SURVIVAL_STAT_KEYPOINT_TYPE && args.KeyPoints.FirstOrDefault().Value == EXPECTED_SURVIVAL_STAT_KEYPOINT); } }
public void RestoreStat(SurvivalStatType type, int value) { var stat = Stats.SingleOrDefault(x => x.Type == type); if (stat != null) { ChangeStatInner(stat, value); } }
/// <summary>Форсированно установить запас здоровья.</summary> /// <param name="type">Тип характеритсики, которая будет произведено влияние.</param> /// <param name="value">Целевое значение запаса характеристики.</param> public void SetStatForce(SurvivalStatType type, int value) { var stat = Stats.SingleOrDefault(x => x.Type == type); if (stat != null) { stat.Value = value; } }
/// <summary>Снижение характеристики.</summary> /// <param name="type">Тип характеритсики, которая будет произведено влияние.</param> /// <param name="value">Значение, на которое снижается текущий запас.</param> public void DecreaseStat(SurvivalStatType type, int value) { ValidateStatChangeValue(value); var stat = Stats.SingleOrDefault(x => x.Type == type); if (stat != null) { ChangeStatInner(stat, -value); } }
private static SurvivalStat CreateUselessStat(SurvivalStatType statType) { var stat = new SurvivalStat(100, 0, 100) { Type = statType, Rate = 1, DownPassRoll = 0 }; return(stat); }
public SurvivalStatHazardEffect(SurvivalStatType type, SurvivalStatHazardLevel level, [NotNull] ISurvivalRandomSource survivalRandomSource) { Type = type; Level = level; _survivalRandomSource = survivalRandomSource ?? throw new ArgumentNullException(nameof(survivalRandomSource)); _rules = CalcRules(); }
/// <summary>Форсированно установить запас здоровья.</summary> /// <param name="type">Тип характеритсики, которая будет произведено влияние.</param> /// <param name="value">Целевое значение запаса характеристики.</param> public void SetStatForce(SurvivalStatType type, int value) { var stat = Stats.SingleOrDefault(x => x.Type == type); if (stat != null) { stat.Value = value; ProcessIfHealth(stat, valueDiff: 0); ProcessIfWound(stat); } }
private Texture2D GetStatHazardConditionTypeClient(SurvivalStatType type) { if (_survivalStatConditionIcons is null) { throw new InvalidOperationException("Survival condition icons is not loaded."); } if (!_survivalStatConditionIcons.TryGetValue(type, out var iconTexture)) { Debug.Fail("Every stat must has its own icon."); } return(iconTexture); }
/// <summary>Пополнение запаса характеристики.</summary> /// <param name="type">Тип характеритсики, которая будет произведено влияние.</param> /// <param name="value">Значение, на которое восстанавливается текущий запас.</param> public void RestoreStat(SurvivalStatType type, int value) { ValidateStatChangeValue(value); var stat = Stats.SingleOrDefault(x => x.Type == type); if (stat != null) { if (stat.Value < stat.Range.Max) { ChangeStatInner(stat, value); } } }
/// <summary> /// Помещает в список бонус на ХП. /// </summary> /// <param name="level"> Уровень бонуса. </param> /// <param name="direction"> Направление бонуса. </param> /// <param name="bonuses"> /// Аккумулирующий список бонусов. /// Отмечен ref, чтобы показать, что изменяется внутри метода. /// </param> private void BonusToHealth(PersonRuleLevel level, PersonRuleDirection direction, ref List <SurvivalStatBonus> bonuses) { const SurvivalStatType HP_STAT_TYPE = SurvivalStatType.Health; var hpStat = Stats.SingleOrDefault(x => x.Type == HP_STAT_TYPE); if (hpStat != null) { var bonus = 0; switch (level) { case PersonRuleLevel.Lesser: bonus = 1; break; case PersonRuleLevel.Normal: bonus = 3; break; case PersonRuleLevel.Grand: bonus = 5; break; case PersonRuleLevel.Absolute: bonus = 10; break; case PersonRuleLevel.None: throw new InvalidOperationException("Неопределённое правило."); default: throw new InvalidOperationException($"Правило {level} не обрабатывается."); } if (direction == PersonRuleDirection.Negative) { bonus *= -1; } var currentBonus = bonuses.SingleOrDefault(x => x.SurvivalStatType == HP_STAT_TYPE); if (currentBonus == null) { currentBonus = new SurvivalStatBonus(HP_STAT_TYPE); bonuses.Add(currentBonus); } currentBonus.ValueBonus += bonus; } }
private static SurvivalStat CreateStat(SurvivalStatType type) { var stat = new SurvivalStat(START_SURVIVAL_STAT, MIN_SURVIVAL_STAT, MAX_SURVIVAL_STAT) { Type = type, Rate = 1, KeyPoints = new[] { new SurvivalStatKeyPoint(SurvivalStatHazardLevel.Max, MAX_SURVIVAL_STAT_KEYPOINT), new SurvivalStatKeyPoint(SurvivalStatHazardLevel.Strong, STRONG_SURVIVAL_STAT_KEYPOINT), new SurvivalStatKeyPoint(SurvivalStatHazardLevel.Lesser, LESSER_SURVIVAL_STAT_KEYPOINT) } }; return(stat); }
private void DecreaseStat(SurvivalStatType statType, PersonRuleLevel level) { switch (statType) { case SurvivalStatType.Satiety: case SurvivalStatType.Hydration: case SurvivalStatType.Intoxication: DecreaseSurvivalStatInner(statType, level); break; case SurvivalStatType.Health: DecreaseHp(level); break; } }
public void Init(SurvivalStatType type, SurvivalStatHazardLevel level) { var currentLanguage = _uiSettingService.CurrentLanguage; Type = type; Level = level; SelectIcon(type); HighlightLevel(level); if (UiElementTooltip != null) { var effectText = GetEffectText(currentLanguage); UiElementTooltip.text = effectText; } }
private void SelectIcon(SurvivalStatType type) { switch (type) { case SurvivalStatType.Satiety: EffectIcon.sprite = HungerSprite; break; case SurvivalStatType.Water: EffectIcon.sprite = ThristSprite; break; default: throw new InvalidOperationException(); } }
private void DecreaseStat(SurvivalStatType statType, PersonRuleLevel level) { switch (statType) { case SurvivalStatType.Satiety: DecreaseSurvivalStatInner(SurvivalStatType.Satiety, level); break; case SurvivalStatType.Water: DecreaseSurvivalStatInner(SurvivalStatType.Water, level); break; case SurvivalStatType.Health: DecreaseHp(level); break; } }
private static bool CheckConditionWithMaxLevel(IActor actor, SurvivalStatType effectType) { var isRestricted = false; var сonditionModule = actor.Person.GetModuleSafe <IConditionsModule>(); if (сonditionModule != null) { var searchingСondition = сonditionModule.Items.OfType <SurvivalStatHazardCondition>() .SingleOrDefault(x => x.Type == effectType && x.Level == SurvivalStatHazardLevel.Max); if (searchingСondition != null) { isRestricted = true; } } return(isRestricted); }
private static void GetEffectStatAndLevelByName(string effectName, out SurvivalStatType stat, out SurvivalStatHazardLevel level) { switch (effectName) { case "нет": level = SurvivalStatHazardLevel.Undefined; stat = SurvivalStatType.Undefined; break; case "Слабый голод": level = SurvivalStatHazardLevel.Lesser; stat = SurvivalStatType.Satiety; break; case "Голод": level = SurvivalStatHazardLevel.Strong; stat = SurvivalStatType.Satiety; break; case "Голодание": level = SurvivalStatHazardLevel.Max; stat = SurvivalStatType.Satiety; break; case "Слабая жажда": level = SurvivalStatHazardLevel.Lesser; stat = SurvivalStatType.Water; break; case "Жажда": level = SurvivalStatHazardLevel.Strong; stat = SurvivalStatType.Water; break; case "Обезвоживание": level = SurvivalStatHazardLevel.Max; stat = SurvivalStatType.Water; break; default: throw new NotSupportedException("Неизветный тип ожидаемого эффекта."); } }
private static void BonusToDownPass( SurvivalStatType statType, PersonRuleLevel level, PersonRuleDirection direction, ref List <SurvivalStatBonus> bonuses) { var currentBonusValue = 0; var directionQuaff = direction == PersonRuleDirection.Negative ? -1 : 1; switch (level) { case PersonRuleLevel.Lesser: currentBonusValue = 1 * directionQuaff; break; case PersonRuleLevel.Normal: currentBonusValue = 2 * directionQuaff; break; case PersonRuleLevel.Grand: currentBonusValue = 5 * directionQuaff; break; case PersonRuleLevel.Absolute: currentBonusValue = 10 * directionQuaff; break; case PersonRuleLevel.None: Debug.Fail("Предположительно, это ошибка."); break; default: Debug.Fail("Предположительно, это ошибка."); break; } var currentBonus = new SurvivalStatBonus(statType) { DownPassBonus = currentBonusValue }; bonuses.Add(currentBonus); }