Exemple #1
0
        public override void Execute(IUnitImpactExp impactData)
        {
            int currentTarget = _context.ContextImpact.CurrentTarget;

            if (_context.BattleMode)
            {
                if (_context.ContextImpact.IsEnemy)
                {
                    Logger.Error($"The enemy cannot receive exp target = {_context.ContextImpact.CurrentTarget}", this);
                    return;
                }
            }
            var(data, unit) = _units.GetUnit(currentTarget);

            var oldLevel = data.Level;
            var exp      = (int)_formula.Calculate(impactData.Value);

            if (exp < 1)
            {
                return;
            }
            var newLevel = _units.UpgradeUnitLevel(data.Id, exp, _player.State.Level);

            var updateLevel = oldLevel != newLevel;

            while (oldLevel != newLevel)
            {
                oldLevel++;
                var levelData = _units.Static.UnitLevels.Values.FirstOrDefault(x => x.Level == oldLevel);
                _logic.ExecuteImpact(levelData?.Impact);
                _logic.ExecuteImpact(unit.ImpactUpdrade);
            }

            if (updateLevel && _context.BattleMode)
            {
                _context.SetContextFormula(unit.Id);
                _context.NeedExploreParam = true;

                var member = _battle.GetMember(currentTarget);
                member.HpMax      = _units.CalculateMaxHp(data, _formula);
                member.Strength   = _units.CalculateStrength(data, _formula);
                member.Initiative = _units.CalculateInitiative(data, _formula);

                _context.SetContextFormula(null);
                _context.NeedExploreParam = false;
            }
        }
        public IMemberBattleData CreateBattleUnit(IUnitData unit, bool assist)
        {
            _context.NeedExploreParam = true;
            _context.SetContextFormula(unit.Id);
            var data = _battle.Factory.CreateBattleMember(
                unit.Id,
                unit.ExplorerPosition,
                _units.CalculateMaxHp(unit, _formula),
                _units.CalculateStrength(unit, _formula),
                _units.CalculateInitiative(unit, _formula),
                BattleMemberType.Unit
                );

            _context.SetContextFormula(null);
            _context.NeedExploreParam = false;
            data.Assist    = assist;
            data.CurrentHp = unit.CurrentHp;
            var abilities = _units.Static.Abilities.Values.Where(x => x.Params.UnitId == unit.Id).ToArray();

            UpdateParams(data, abilities);

            return(data);
        }