public void Transfer(PrivateCorporation target, double amount, Character issuer) { if (Eid == target.Eid) { return; } CanTransfer(issuer).ThrowIfFalse(ErrorCodes.InsufficientPrivileges); target.IsActive.ThrowIfFalse(ErrorCodes.CorporationMustBeActive); var sourceWallet = new CorporationWallet(this); sourceWallet.Balance -= amount; LogTransaction(TransactionLogEvent.Builder() .SetTransactionType(TransactionType.corporationTransfer_to) .SetCreditBalance(sourceWallet.Balance) .SetCreditChange(-amount) .SetCorporation(this) .SetInvolvedCorporation(target).Build()); var targetWallet = new CorporationWallet(target); targetWallet.Balance += amount; target.LogTransaction(TransactionLogEvent.Builder() .SetTransactionType(TransactionType.corporationTransfer_from) .SetCreditBalance(targetWallet.Balance) .SetCreditChange(amount) .SetCorporation(target) .SetInvolvedCorporation(this).Build()); }
public void PayOut(Character member, double amount, Character issuer) { if (amount <= 0) { return; } CanPayOut(issuer).ThrowIfFalse(ErrorCodes.InsufficientPrivileges); IsMember(member).ThrowIfFalse(ErrorCodes.NotMemberOfCorporation); var ceo = CEO; if (ceo != issuer) { CorporationManager.IsJoinPeriodExpired(member, Eid).ThrowIfFalse(ErrorCodes.corporationTransactionsFrozen); } var builder = TransactionLogEvent.Builder().SetCorporation(this).SetTransactionType(TransactionType.characterPayOut); var corporationWallet = new CorporationWallet(this); corporationWallet.Balance -= amount; LogTransaction(builder.SetCreditBalance(corporationWallet.Balance) .SetCreditChange(-amount) .SetCharacter(issuer) .SetInvolvedCharacter(member).Build()); var memberWallet = _characterWalletFactory(member, TransactionType.characterPayOut); memberWallet.Balance += amount; member.LogTransaction(builder.SetCreditBalance(memberWallet.Balance) .SetCreditChange(amount) .SetCharacter(member) .SetInvolvedCharacter(issuer).Build()); }
private static void CollectHangarRent(IStandingHandler standingHandler) { var storage = EntityDefault.GetByName(DefinitionNames.PUBLIC_CORPORATE_HANGARS_STORAGE); var hangarEids = Db.Query().CommandText("select eid from entities where parent in (SELECT eid FROM dbo.getLiveDockingbaseChildren() WHERE definition=@hangarDef) order by parent") .SetParameter("@hangarDef", storage.Definition) .Execute() .Select(h => (CorporateHangar)GetOrThrow(h.GetValue <long>(0))) .ToArray(); Logger.Info("--- hangars collected for rent check: " + hangarEids.Count()); using (var scope = Db.CreateTransaction()) { try { foreach (var hangar in hangarEids) { var hangarStorage = hangar.GetHangarStorage(); switch (hangarStorage.GetParentDockingBase()) { case Outpost outpost: { var siteInfo = outpost.GetIntrusionSiteInfo(); if (siteInfo?.Owner != null) { //it has an owner if (hangar.Owner != siteInfo.Owner) { //the owner is not the hangar's owner var dockingStandingLimit = siteInfo.DockingStandingLimit; if (dockingStandingLimit != null) { //the outpost has standing limit set var standingTowardsOwner = standingHandler.GetStanding((long)siteInfo.Owner, hangar.Owner); if (standingTowardsOwner < dockingStandingLimit) { //the hangar is inaccessible Logger.Info("hangar is inaccessible for corp. " + hangar.Owner + " hangaried:" + hangar.Eid + " standing:" + standingTowardsOwner + " dockingStandingLimit:" + dockingStandingLimit); continue; } } } } break; } case PBSDockingBase pbsDockingBase: { if (pbsDockingBase.StandingEnabled) { var standingTowardsOwner = standingHandler.GetStanding(pbsDockingBase.Owner, hangar.Owner); if (standingTowardsOwner < pbsDockingBase.StandingLimit) { Logger.Info("hangar is inaccessible for corp. " + hangar.Owner + " hangaried:" + hangar.Eid + " standing:" + standingTowardsOwner + " dockingStandingLimit:" + pbsDockingBase.StandingLimit); continue; } } break; } } var rentInfo = hangarStorage.GetCorporationHangarRentInfo(); // rent expired? if (hangar.IsLeaseExpired) { continue; } if (DateTime.Now > hangar.LeaseEnd) { var corporation = hangar.GetCorporation(); Logger.Info("--- hangar rent process started for hangarEID:" + hangar.Eid + " hangarName:" + hangar.Name + " corporaration:" + corporation.Eid + " corpname:" + corporation.Description.name); var wallet = new CorporationWallet(corporation); if (wallet.Balance < rentInfo.price) { Logger.Info("--- corporation is broken. corporationEID:" + corporation.Eid + " hangar closed. EID:" + hangar.Eid); //corporation broken hangar.IsLeaseExpired = true; //block the hangar's content //alert accountants var info = new Dictionary <string, object> { { k.containerEID, hangar.Eid } }; Message.Builder.SetCommand(Commands.CorporationHangarRentExpired) .WithData(info) .ToCorporation(corporation, CorporationRole.Accountant) .Send(); } else { wallet.Balance -= rentInfo.price; var b = TransactionLogEvent.Builder() .SetCorporation(corporation) .SetTransactionType(TransactionType.hangarRentAuto) .SetCreditBalance(wallet.Balance) .SetCreditChange(-rentInfo.price); corporation.LogTransaction(b); hangarStorage.GetParentDockingBase().AddCentralBank(TransactionType.hangarRentAuto, rentInfo.price); hangar.LeaseStart = DateTime.Now; hangar.LeaseEnd = DateTime.Now + rentInfo.period; hangar.IsLeaseExpired = false; Logger.Info("--- hangar price paid. hangarEID: " + hangar.Eid + " lease ended:" + hangar.LeaseEnd + " lease extened:" + hangar.LeaseEnd); } hangar.Save(); } else { Logger.Info("--- hangar still paid. eid:" + hangar.Eid + " lease end:" + hangar.LeaseEnd); } } scope.Complete(); } catch (Exception ex) { Logger.Exception(ex); } } }