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); }
public CorporationWallet CreateOrUpdateCorporationWallet(int corpId = 0, decimal amount = 0, string name = "unknown corporation", string logoUrl = "") { CorporationWallet corporation = null; if (corpId > 0) { corporation = Get <CorporationWallet>(w => w.Id == corpId, c => c.Wallet); } if (corporation == null) { var newWallet = CreateOrUpdateWallet(WalletTypes.Corporation); corporation = new CorporationWallet { Wallet = newWallet, Id = corpId, CorporationLogoUrl = UrlNotFound }; Add(corporation); } if (!string.IsNullOrEmpty(logoUrl)) { corporation.CorporationLogoUrl = logoUrl; } if (!string.IsNullOrEmpty(name)) { corporation.Name = name; } if (amount > 0) { corporation.Wallet.Balance = amount; } SaveContext(); return(corporation); }
public CorporationDto(CorporationWallet corporation) : base(0, corporation) { CorporationUrl = corporation.CorporationLogoUrl; CurrentKPI = corporation.CurrentKPI; LastKPI = corporation.LastKPI; CurrentSkuSold = corporation.SkuSold; LastSkuSold = corporation.LastSkuSold; }
public void HandleRequest(IRequest request) { using (var scope = Db.CreateTransaction()) { var baseEID = request.Data.GetOrDefault <long>(k.baseEID); var character = request.Session.Character; character.IsDocked.ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked); var dockingBase = character.GetCurrentDockingBase(); if (dockingBase.Eid != baseEID) { throw new PerpetuumException(ErrorCodes.FacilityOutOfReach); } var corporation = character.GetPrivateCorporationOrThrow(); var role = corporation.GetMemberRole(character); role.IsAnyRole(CorporationRole.CEO, CorporationRole.HangarOperator, CorporationRole.DeputyCEO).ThrowIfFalse(ErrorCodes.InsufficientPrivileges); if (!role.IsAnyRole(CorporationRole.CEO)) { _corporationManager.IsInJoinOrLeave(character).ThrowIfError(); } var mainHangar = dockingBase.GetPublicCorporationHangarStorage(); var rentInfo = mainHangar.GetCorporationHangarRentInfo(); var wallet = new CorporationWallet(corporation); wallet.Balance -= rentInfo.price; var b = TransactionLogEvent.Builder() .SetCorporation(corporation) .SetTransactionType(TransactionType.hangarRent) .SetCreditBalance(wallet.Balance) .SetCreditChange(-rentInfo.price); corporation.LogTransaction(b); var corporateHangar = CorporateHangar.Create(); corporateHangar.Owner = corporation.Eid; mainHangar.AddChild(corporateHangar); //set lease start time corporateHangar.LeaseStart = DateTime.Now; corporateHangar.LeaseEnd = DateTime.Now + rentInfo.period; corporateHangar.IsLeaseExpired = false; corporateHangar.SetLogging(true, character); //set logging on by default mainHangar.Save(); dockingBase.AddCentralBank(TransactionType.hangarRent, rentInfo.price); Message.Builder.FromRequest(request).WithData(corporateHangar.ToDictionary()).Send(); scope.Complete(); } }
public void HandleRequest(IRequest request) { using (var scope = Db.CreateTransaction()) { var character = request.Session.Character; var hangarEID = request.Data.GetOrDefault <long>(k.eid); var corporation = character.GetCorporation(); var corporateHangar = corporation.GetHangar(hangarEID, character, ContainerAccess.LogList); var hangarStorage = corporateHangar.GetHangarStorage(); var rentInfo = hangarStorage.GetCorporationHangarRentInfo(); var wallet = new CorporationWallet(corporation); wallet.Balance -= rentInfo.price; var b = TransactionLogEvent.Builder().SetCorporation(corporation).SetTransactionType(TransactionType.hangarRent).SetCreditBalance(wallet.Balance).SetCreditChange(-rentInfo.price); corporation.LogTransaction(b); if (corporateHangar.IsLeaseExpired) { corporateHangar.LeaseStart = DateTime.Now; corporateHangar.LeaseEnd = DateTime.Now + rentInfo.period; } else { corporateHangar.LeaseStart += rentInfo.period; corporateHangar.LeaseEnd += rentInfo.period; } corporateHangar.IsLeaseExpired = false; corporateHangar.Save(); hangarStorage.GetParentDockingBase().AddCentralBank(TransactionType.hangarRent, rentInfo.price); var result = new Dictionary <string, object> { { k.eid, hangarEID }, { k.name, corporateHangar.Name }, { k.price, rentInfo.price }, { k.rentPeriod, (int)rentInfo.period.TotalDays }, { k.leaseStart, corporateHangar.LeaseStart }, { k.leaseEnd, corporateHangar.LeaseEnd }, { k.leaseExpired, 0 } }; Message.Builder.FromRequest(request).WithData(result).Send(); scope.Complete(); } }
private decimal GetDividends(CorporationWallet mortagee, decimal percent, decimal defaultValue) { decimal sum = 0; if (mortagee != null) { sum = mortagee.LastSkuSold * percent; } if (sum < defaultValue) { sum = defaultValue; } return(sum); }
internal AuthCorporationMain(ESIEve EasyEve) : base(EasyEve) { EasyObject = (ESIEve.Authenticated)EasyEve; Assets = new CorporationAssets(EasyObject); Bookmarks = new CorporationBookmarks(EasyObject); Contacts = new CorporationContacts(EasyObject); Contracts = new CorporationContracts(EasyObject); FactionWarfare = new CorporationFactionWarfare(EasyObject); Industry = new CorporationIndustry(EasyObject); Killmails = new CorporationKillmails(EasyObject); Market = new CorporationMarket(EasyObject); Wallet = new CorporationWallet(EasyEve); }
/// <summary> /// This function is called periodically and pays the owned base's income to a corporation /// </summary> private static void DoSiegeCorporationSharePayOut() { using (var scope = Db.CreateTransaction()) { try { var timeBehind = DateTime.Now.AddHours(-5); //real var records = Db.Query().CommandText("select corporationeid,amount from ownerincome where lastflush < @dayBehind") .SetParameter("@dayBehind", timeBehind) .Execute() .Select(r => new { corporation = Corporation.GetOrThrow(r.GetValue <long>(0)), amount = r.GetValue <double>(1) }) .Where(r => r.amount > 0.0); foreach (var record in records) { var corporation = record.corporation; var wallet = new CorporationWallet(corporation); wallet.Balance += record.amount; corporation.LogTransaction(TransactionLogEvent.Builder() .SetCorporation(corporation) .SetTransactionType(TransactionType.BaseIncome) .SetCreditBalance(wallet.Balance) .SetCreditChange(record.amount)); Db.Query().CommandText("update ownerincome set amount=0,lastflush=@now where corporationeid=@corpEID") .SetParameter("@now", DateTime.Now) .SetParameter("@corpEID", corporation.Eid) .ExecuteNonQuery(); Logger.Info("owner income added to corp: " + corporation.Eid + " amount: " + record.amount); } scope.Complete(); } catch (Exception ex) { Logger.Exception(ex); } } }
public void HandleRequest(IRequest request) { using (var scope = Db.CreateTransaction()) { var character = request.Session.Character; var amount = request.Data.GetOrDefault <long>(k.amount); if (amount <= 0) { return; } character.IsInTraining().ThrowIfTrue(ErrorCodes.TrainingCharacterInvolved); character.IsPrivilegedTransactionsAllowed().ThrowIfError(); Corporation corporation = character.GetPrivateCorporationOrThrow(); corporation.IsActive.ThrowIfFalse(ErrorCodes.CorporationNotExists); var ceo = corporation.CEO; if (ceo != character) { _corporationManager.IsJoinPeriodExpired(character, corporation.Eid).ThrowIfFalse(ErrorCodes.corporationTransactionsFrozen); } var characterWallet = _characterWalletFactory(character, TransactionType.characterDonate); characterWallet.Balance -= amount; var builder = TransactionLogEvent.Builder() .SetCharacter(character) .SetTransactionType(TransactionType.characterDonate) .SetCreditBalance(characterWallet.Balance) .SetCreditChange(-amount) .SetCorporation(corporation); character.LogTransaction(builder); var corporationWallet = new CorporationWallet(corporation); corporationWallet.Balance += amount; builder.SetCreditBalance(corporationWallet.Balance) .SetCreditChange(amount); corporation.LogTransaction(builder); scope.Complete(); } }
private void PayBackBuyOrder() { var submitter = Character.GetByEid(submitterEID); //use corporation wallet based on the order and not on the current corp of the character PrivateCorporation corporation = null; if (forMembersOf != null) { corporation = PrivateCorporation.Get((long)forMembersOf); } IWallet <double> wallet; if (corporation != null && useCorporationWallet) { wallet = new CorporationWallet(corporation); } else { wallet = submitter.GetWallet(false, TransactionType.buyOrderPayBack); } wallet.Balance += FullPrice; var b = TransactionLogEvent.Builder() .SetTransactionType(TransactionType.buyOrderPayBack) .SetCreditBalance(wallet.Balance) .SetCreditChange(FullPrice) .SetCharacter(submitter) .SetItem(itemDefinition, quantity); var corpWallet = wallet as CorporationWallet; if (corpWallet != null) { b.SetCorporation(corpWallet.Corporation); corpWallet.Corporation.LogTransaction(b); } else { submitter.LogTransaction(b); } _centralBank.SubAmount(FullPrice, TransactionType.MarketTax); }
public PriceShopDto(PriceDto dto, CorporationWallet corp) { this.PriceId = dto.PriceId; this.DateCreated = dto.DateCreated; this.ShopName = dto.ShopName; this.ShopComission = dto.ShopComission; this.DateTill = dto.DateTill; this.FinalPrice = dto.FinalPrice; this.SkuName = dto.SkuName; this.Count = dto.Count; this.CorporationLogo = corp.CorporationLogoUrl; this.CorporationName = corp.Name; this.NomenklaturaName = dto.NomenklaturaName; this.LifeStyle = dto.LifeStyle; this.Description = dto.Description; this.UrlPicture = dto.PictureUrl; this.ProductTypeName = dto.Name; this.InstantConsume = dto.InstantConsume; }
public void HandleRequest(IRequest request) { var character = request.Session.Character; var offsetInDays = request.Data.GetOrDefault <int>(k.offset); Corporation corporation = character.GetPrivateCorporationOrThrow(); corporation.IsAnyRole(character, CorporationRole.CEO, CorporationRole.Accountant, CorporationRole.DeputyCEO).ThrowIfFalse(ErrorCodes.InsufficientPrivileges); var wallet = new CorporationWallet(corporation); var result = new Dictionary <string, object> { { k.corporationEID, corporation.Eid }, { k.history, corporation.GetTransactionHistory(offsetInDays) }, { k.wallet, (long)wallet.Balance } }; Message.Builder.FromRequest(request) .WithData(result) .WrapToResult() .Send(); }
public SkuDto CreateOrUpdateSku(int id, int nomenklaturaid, int count, int corporationid, string name, bool enabled, int?skubaseprice = null, int?skubasecount = null) { Sku sku = null; if (id > 0) { sku = Get <Sku>(s => s.Id == id); } if (sku == null) { sku = new Sku(); Add(sku); } sku.Enabled = enabled; sku.SkuBasePrice = skubaseprice; sku.SkuBaseCount = skubasecount; if (count > 0) { sku.Count = count; } if (!string.IsNullOrEmpty(name)) { sku.Name = name; } CorporationWallet corporation = null; if (corporationid > 0) { corporation = Get <CorporationWallet>(c => c.Id == corporationid); } else { corporation = Get <CorporationWallet>(c => c.Id == sku.CorporationId); } if (corporation == null) { throw new BillingException("Corporation not found"); } sku.CorporationId = corporation.Id; Nomenklatura nomenklatura = null; if (nomenklaturaid > 0) { nomenklatura = Get <Nomenklatura>(n => n.Id == nomenklaturaid); } else { nomenklatura = Get <Nomenklatura>(n => n.Id == sku.NomenklaturaId); } if (nomenklatura == null) { throw new BillingException("Nomenklatura not found"); } sku.NomenklaturaId = nomenklatura.Id; SaveContext(); sku = GetAsNoTracking <Sku>(s => s.Id == sku.Id, s => s.Nomenklatura.Specialisation.ProductType); if (sku == null) { throw new Exception("создать sku не получилось"); } return(new SkuDto(sku, true)); }
public CorporationDetailedDto(CorporationWallet corporation, List <Specialisation> specialisations, List <CorporationSpecialisation> corpspecs) : base(corporation) { Specialisations = specialisations.Select(s => new SpecialisationDto(s, true, (corpspecs.FirstOrDefault(c => c.SpecialisationId == s.Id)?.Ratio) ?? 0)).ToList(); }