Ejemplo n.º 1
0
        public BeatCharacterLocalDto ProcessCharacterBeat(int sinId, WorkModelDto workDto, decimal K, JobLifeStyleDto lastdto)
        {
            var sw = new Stopwatch();

            sw.Start();
            var localDto = new BeatCharacterLocalDto();
            var sin      = BlockCharacter(sinId, s => s.Wallet, s => s.Character, s => s.Passport, s => s.Scoring);

            SaveContext();
            var     mir      = GetMIR();
            decimal income   = 0;
            decimal outcome  = 0;
            var     mortagee = GetMortagee(sin.Passport);

            //ability
            if (workDto.Dividends1)
            {
                var def1 = _settings.GetDecimalValue(SystemSettingsEnum.dividents1_k);
                var sum  = GetDividends(mortagee, 0.01m, def1);
                AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды *");
                income += sum;
                localDto.SumDividends += sum;
            }
            if (workDto.Dividends2)
            {
                var def2 = _settings.GetDecimalValue(SystemSettingsEnum.dividents2_k);
                var sum  = GetDividends(mortagee, 0.03m, def2);
                AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды **");
                income += sum;
                localDto.SumDividends += sum;
            }
            if (workDto.Dividends3)
            {
                var def3 = _settings.GetDecimalValue(SystemSettingsEnum.dividents3_k);
                var sum  = GetDividends(mortagee, 0.05m, def3);
                AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды ***");
                income += sum;
                localDto.SumDividends += sum;
            }
            //karma
            if (workDto.KarmaCount > 0)
            {
                var     avg = lastdto.GetAvergeKarma();
                decimal x1  = 0;
                if (avg != 0)
                {
                    x1 = (lastdto.GetAvergeRents() * K) / lastdto.GetAvergeKarma();
                }
                else
                {
                    x1 = (lastdto.GetAvergeRents() * K) / 700;
                }
                if (x1 == 0)
                {
                    x1 = 0.3m;
                }
                var karmasum = x1 * workDto.KarmaCount;
                income            += karmasum;
                localDto.SumKarma += karmasum;
                AddNewTransfer(mir, sin.Wallet, karmasum, "Пассивный доход");
            }
            var swIncome = Cut(sw);
            //rentas
            var rentas = GetList <Renta>(r => r.SinId == sin.Id, r => r.Shop.Wallet, r => r.Sku.Corporation.Wallet, r => r.Sku.Nomenklatura);

            foreach (var renta in rentas)
            {
                ProcessRenta(renta, mir, sin);
            }
            var swRentas = Cut(sw);

            //overdrafts
            if (sin.Wallet.Balance > 0)
            {
                var allOverdrafts = GetList <Transfer>(t => t.Overdraft && t.WalletFromId == sin.Wallet.Id && t.RentaId > 0);
                foreach (var overdraft in allOverdrafts)
                {
                    overdraft.Overdraft = false;
                    var closingRenta = Get <Renta>(r => r.Id == overdraft.RentaId, r => r.Sku.Corporation, r => r.Shop.Wallet, r => r.Sku.Nomenklatura);
                    CloseOverdraft(closingRenta, mir, sin);
                }
            }
            var swoverdrafts = Cut(sw);

            //metatype
            if (sin.Passport.MetatypeId != sin.OldMetaTypeId)
            {
                var scoring = IoC.IocContainer.Get <IScoringManager>();
                scoring.OnMetatypeChanged(sin);
                sin.OldMetaTypeId = sin.Passport.MetatypeId;
            }
            //insurance
            var insurance = GetInsurance(sin.CharacterId);

            if (insurance?.LifeStyle != sin.OldInsurance)
            {
                if ((insurance?.LifeStyle ?? 0) > 0 != (sin.OldInsurance ?? 0) > 0)
                {
                    var scoring = IoC.IocContainer.Get <IScoringManager>();
                    scoring.OnInsuranceChanged(sin, (insurance?.LifeStyle ?? 0) > 0);
                }
                sin.OldInsurance = insurance?.LifeStyle;
            }
            //summary
            localDto.Scoringvalue = BillingHelper.GetFullScoring(sin.Scoring);
            //forecast
            outcome += rentas.Sum(r => BillingHelper.GetFinalPrice(r));
            if (workDto.StockGainPercentage > 0)
            {
                var stock = outcome * (workDto.StockGainPercentage / 100);
                income += stock;
                AddNewTransfer(mir, sin.Wallet, stock, "Игра на бирже");
            }
            localDto.SumRents       += outcome;
            sin.Wallet.IncomeOutcome = income - outcome;
            if (sin.Wallet.IsIrridium)
            {
                localDto.IsIrridium = true;
            }
            else
            {
                localDto.Balance  = sin.Wallet.Balance;
                localDto.Forecast = BillingHelper.GetForecast(sin.Wallet);
            }
            SaveContext();
            var swOther = Cut(sw);

            sw.Stop();
            sin.DebugTime = Serialization.Serializer.ToJSON(new { swIncome, swRentas, swoverdrafts, swOther });
            UnblockCharacter(sin);
            return(localDto);
        }