public CraftTable(IBuffCollector buffCollector, IConditionService conditionService, IRandomService randomService, ICalculator calculator, ILookupService lookupService, ICraftQualityCalculator craftQualityCalculator, Recipe recipe, CraftMan craftMan, IProgressWatcher progressWatcher = null) { if (recipe == null) { throw new ArgumentNullException(nameof(recipe)); } if (craftMan == null) { throw new ArgumentNullException(nameof(craftMan)); } if (buffCollector == null) { throw new ArgumentNullException(nameof(buffCollector)); } if (conditionService == null) { throw new ArgumentNullException(nameof(conditionService)); } if (randomService == null) { throw new ArgumentNullException(nameof(randomService)); } if (calculator == null) { throw new ArgumentNullException(nameof(calculator)); } if (lookupService == null) { throw new ArgumentNullException(nameof(lookupService)); } if (craftQualityCalculator == null) { throw new ArgumentNullException(nameof(craftQualityCalculator)); } _progressWatcher = progressWatcher ?? new DefaultProgressWatcher(); _buffCollector = buffCollector; _conditionService = conditionService; _craftMan = craftMan; _progressWatcher = progressWatcher ?? new DefaultProgressWatcher(); _randomService = randomService; _calculator = calculator; _lookupService = lookupService; _craftQualityCalculator = craftQualityCalculator; _recipe = recipe; _craftPointsLeft = craftMan.MaxCraftPoints; _durability = recipe.Durability; _condition = _conditionService.GetCondition(null); _quality = recipe.StartQuality; }
public void Act(Ability ability, Overrides overrides = null) { _condition = overrides?.Condition ?? _condition; if (_durability <= 0 || _progress >= _recipe.Difficulty) { _progressWatcher.Log("Craft finished. No Actions Allowed."); throw new CraftAlreadyFinishedException(); } var abilityfailed = false; var craftServiceState = new CraftServiceState(_condition, _craftPointsLeft, _step, _buffCollector.GetBuffAccessor()); if (!ability.CanAct(craftServiceState)) { _progressWatcher.Log($"Use of {ability} is not allowed"); throw new AbilityNotAvailableException(); } _step++; _buffCollector.Step(this); _calculator.Reset(_condition); _buffCollector.BuildCalculator(new ActionInfo(ability.GetType(), _condition), _calculator.GetBuilder()); var chance = _calculator.CalculateChance(ability.Chance); var isSuccess = !overrides?.Failed ?? _randomService.Select(new[] { chance, 1000.0 }) == 0; if (!isSuccess) { abilityfailed = true; _calculator.Fail(); } _progressWatcher.Log($"You use {ability} : {(isSuccess ? "Success" : "Failed")} with chance {chance}%"); _progressWatcher.Log($" -> Condition is {_condition.ToString()}"); ability.Execute(this, !abilityfailed); _buffCollector.PostAction(this); _condition = _conditionService.GetCondition(_condition); _buffCollector.KillNotActive(); Validate(abilityfailed, chance); var copyOfAbilities = _abilityQueue.ToArray(); _abilityQueue.Clear(); foreach (var a in copyOfAbilities) { Act(a); } }