Пример #1
0
        public bool CanAct(Ability ability, Overrides overrides)
        {
            if (_durability <= 0 || _progress >= _recipe.Difficulty)
            {
                return(false);
            }
            var craftServiceState = new CraftServiceState(overrides?.Condition ?? _condition, _craftPointsLeft, _step, _buffCollector.GetBuffAccessor());

            return(ability.CanAct(craftServiceState));
        }
Пример #2
0
        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);
            }
        }