public void SetBattleUnit(int unitId, int slotId)
        {
            //_scorers.State.Values[scorerId] = value;

            if (!_contextLogic.BattleMode)
            {
                return;
            }

            var unit = -1;

            foreach (var temp in _battle.State.Data.Allies)
            {
                if (temp.Value.Position == slotId)
                {
                    unit = temp.Key;
                }
            }
            if (unit != -1)
            {
                if (_units.TryGetUnit(unit, true, out var data1))
                {
                    data1.ExplorerPosition = -1;
                }
                _battle.State.Data.Allies.Remove(unit);
            }
            if (unitId == -1)
            {
                return;
            }

            if (!_units.TryGetUnit(unitId, true, out var data))
            {
                _units.AddUnitShard(unitId, 100);
                _units.TryGetUnit(unitId, true, out data);
                _units.UpgradeNullRatity(data);
            }
            data.ExplorerPosition             = slotId;
            _battle.State.Data.Allies[unitId] = _battleLogic.CreateBattleUnit(data, false);
        }
Esempio n. 2
0
        public override void Execute(IImpactUnitAdd impactData)
        {
            if (impactData.Unit.Assist)
            {
                if (_units.State.Assist != null)
                {
                    Logger.Error($"The helper has already been added. Existing unit id = {_units.State.Assist.Id}", this);
                    return;
                }
                if (_units.TryGetUnit(impactData.Unit.Id, false, out var find))
                {
                    Logger.Error($"A helper cannot be added because such a unit is already in the state. id = {impactData.Unit.Id}", this);
                    return;
                }
                var unit = _units.CreateUnit(impactData.Unit);
                //_impact.ExecuteImpact(_units.Units[unit.Id].ImpactInit);
                unit.ExplorerPosition = HardCodeIds.BattleAssistSlot;
                _units.State.Assist   = unit;
                if (_context.BattleMode)
                {
                    var battleUnit = _logic.CreateBattleUnit(unit, true);
                    _battle.State.Data.Allies[unit.Id] = battleUnit;
                    battleUnit.CurrentHp = (float)battleUnit.HpMax.Value;
                    unit.CurrentHp       = battleUnit.CurrentHp;
                }
                else
                {
                    _context.SetContextFormula(unit.Id);
                    unit.CurrentHp = (int)_units.CalculateMaxHp(unit, _formula).Value;
                    _context.SetContextFormula(null);
                }
            }
            else
            {
                //var addedCommand = _explorer.State.LastTeam.Count < 3;

                if (!_units.AddUnit(impactData.Unit))
                {
                    _units.AddUnitShard(impactData.Unit.Id, _settings.Settings.PlayerSettings.UnitDuplicateCost);
                }
                else
                {
                    _impact.ExecuteImpact(_units.Units[impactData.Unit.Id].ImpactInit);
                    var data = _units.GetUnit(impactData.Unit.Id).data;
                    _context.SetContextFormula(data.Id);
                    data.CurrentHp = (int)_units.CalculateMaxHp(data, _formula).Value;
                    _context.SetContextFormula(null);
                }
                _units.UpdateLastTeamSlots();

                //var free = _explorer.GetFreeSlot();
                //if (impactData.Unit.SlotExplorer > 0 && !_units.State.LastTeam.Select(x => x.Value).Contains(impactData.Unit.SlotExplorer))
                //{
                //    _units.State.LastTeam[impactData.Unit.Id] = impactData.Unit.SlotExplorer;
                //}
                //else if (free != null)
                //{
                //    _units.State.LastTeam[impactData.Unit.Id] = free.Value;
                //}
            }
            LogicLog.UnitAdd(impactData.Unit.Id, impactData.Unit.Assist);
        }