public void PayOut(InsuranceDescription insurance, int definition)
        {
            if (!insurance.IsInsured)
            {
                return;
            }

            var b = TransactionLogEvent.Builder().SetTransactionType(TransactionType.InsurancePayOut)
                    .SetCreditChange(insurance.payOutPrice)
                    .SetCharacter(insurance.character)
                    .SetItem(definition, 0);

            IWallet <double> wallet;

            if (insurance.corporationEid != null)
            {
                var corporation = Corporation.GetOrThrow((long)insurance.corporationEid);
                wallet          = new CorporationWallet(corporation);
                wallet.Balance += insurance.payOutPrice;
                b.SetCreditBalance(wallet.Balance).SetCorporation(corporation);
                corporation.LogTransaction(b);
                Logger.Info($"insurance paid to corp:{insurance.corporationEid} amount:{insurance.payOutPrice}");
            }
            else
            {
                wallet          = insurance.character.GetWallet(TransactionType.InsurancePayOut);
                wallet.Balance += insurance.payOutPrice;
                b.SetCreditBalance(wallet.Balance);
                insurance.character.LogTransaction(b);
                Logger.Info($"insurance paid to character:{insurance.character.Id} amount:{insurance.payOutPrice}");
            }

            _centralBank.SubAmount(insurance.payOutPrice, TransactionType.InsurancePayOut);
        }
示例#2
0
        public void DeleteAndInform(InsuranceDescription insurance, long eid)
        {
            if (insurance == null)
            {
                return;
            }

            DeleteInsurance(eid);

            if (insurance.corporationEid != null)
            {
                var corporation = Corporation.GetOrThrow((long)insurance.corporationEid);
                corporation.SendInsuranceList();
            }
            else
            {
                SendInsuranceListToCharacter(insurance.character);
            }
        }
示例#3
0
        public InsuranceDescription GetInsurance(long itemEid)
        {
            var record = Db.Query().CommandText("select eid,insurancetype,enddate,characterid,corporationeid,payout from insurance where eid=@EID and enddate > getdate()")
                         .SetParameter("@EID", itemEid)
                         .ExecuteSingleRow();

            if (record == null)
            {
                return(null);
            }

            var d = new InsuranceDescription();

            // eid,insurancetype,enddate,characterid,corporationeid,payout
            d.eid            = record.GetValue <long>(0);
            d.type           = (InsuranceType)record.GetValue <int>(1);
            d.endDate        = record.GetValue <DateTime>(2);
            d.character      = Character.Get(record.GetValue <int>(3));
            d.corporationEid = record.GetValue <long?>(4);
            d.payOutPrice    = record.GetValue <double>(5);

            return(d);
        }
示例#4
0
        public ErrorCodes GetConditions(Character character, Item item, InsuranceDescription insurance, long corporationEid, int insuranceDays, int maxInsurances, int currentInsurances, ref DateTime endDate, ref bool useCorporationWallet)
        {
            var ec = ErrorCodes.NoError;

            if (insurance != null)
            {
                //a robot mar biztositva van

                Logger.Info("robot already insured. " + insurance);

                if (insurance.corporationEid != null)
                {
                    Logger.Info("corp insured robot. ");

                    if (insurance.corporationEid == corporationEid)
                    {
                        Logger.Info("insured by my corp, extend");

                        //extend date
                        endDate = insurance.endDate.AddDays(insuranceDays);
                        useCorporationWallet = true;

                        if (insurance.character != character)
                        {
                            Logger.Info("wasnt isured by me, extension check");

                            if (maxInsurances <= currentInsurances)
                            {
                                return(ErrorCodes.MaximumInsurancesExceeded);
                            }
                        }
                    }
                    else
                    {
                        Logger.Info("new insurance for me, check extension");


                        if (maxInsurances <= currentInsurances)
                        {
                            return(ErrorCodes.MaximumInsurancesExceeded);
                        }

                        Logger.Info("insured by other corp, delete insurance");

                        DeleteAndInform(insurance, item.Eid);

                        if (item.Owner == corporationEid)
                        {
                            Logger.Info("belongs to corp, use corpwallet");

                            useCorporationWallet = true;
                        }
                    }
                }
                else
                {
                    Logger.Info("privately insured robot");

                    if (insurance.character == character)
                    {
                        Logger.Info("i&i insured it.");


                        if (item.Owner == corporationEid)
                        {
                            Logger.Info("owner is my corp, private insurance in corp storage");

                            useCorporationWallet = true;
                            endDate = insurance.endDate.AddDays(insuranceDays);
                        }
                        else
                        {
                            Logger.Info("owner is me, extend date");

                            endDate = insurance.endDate.AddDays(insuranceDays);
                        }
                    }
                    else
                    {
                        Logger.Info("someone else insured it.");

                        DeleteAndInform(insurance, item.Eid);

                        if (item.Owner == corporationEid)
                        {
                            useCorporationWallet = true;
                            endDate = insurance.endDate.AddDays(insuranceDays);
                        }



                        if (maxInsurances <= currentInsurances)
                        {
                            return(ErrorCodes.MaximumInsurancesExceeded);
                        }
                    }
                }
            }
            else
            {
                if (item.Owner == corporationEid)
                {
                    useCorporationWallet = true;
                }


                //this will be a new insurance, so check the extension amount
                if (maxInsurances <= currentInsurances)
                {
                    return(ErrorCodes.MaximumInsurancesExceeded);
                }
            }


            return(ec);
        }