public void BuyOrderFulfilledToCharacter(Character seller, bool useSellersCorporationWallet, MarketOrder buyOrder, int boughtQuantity, Container container, Item boughtItem, Character buyer) { var forCorporation = buyOrder.forMembersOf != null; buyOrder.quantity = buyOrder.quantity - boughtQuantity; //the container is null -> automatic sell order process //the container is NOT null -> a player started a request to sell an item from a container //dont remove fresh fraction items, they are NOT in the container if (boughtItem.Parent != 0) { container?.RemoveItemOrThrow(boughtItem); } var publicContainer = GetDockingBase().GetPublicContainer(); //put the new item to the local public container, set the owner the buyer boughtItem.Parent = publicContainer.Eid; boughtItem.Owner = buyer.Eid; //ez azert kell, mert a megvett item nem abban a kontenerben van mar, tehat a save nem fogja elmenteni //a masik pedig ha az item egy fraction -unstack csinalta- akkor el kell menteni mindenkeppen boughtItem.Save(); if (buyOrder.quantity == 0) { //buy completely order fulfilled, delete it _orderRepository.Delete(buyOrder); } else { //update the buy order's quantity, and leave the rest on the market _orderRepository.UpdateQuantity(buyOrder); } //pay out the fulfilled amount immediately using the price of the found buyorder to the seller PayOutToSeller(seller, useSellersCorporationWallet, boughtItem.Definition, buyOrder.price, boughtItem.Quantity, TransactionType.marketSell, buyOrder.IsAffectsAverage(), forCorporation); _centralBank.SubAmount(buyOrder.price * boughtItem.Quantity, TransactionType.marketSell); Market.SendMarketItemBoughtMessage(buyer, boughtItem); Message.Builder.SetCommand(Commands.MarketBuyOrderUpdate) .WithData(new Dictionary <string, object> { { k.buyOrder, buyOrder.ToDictionary() } }) .ToCharacters(seller, buyer) .Send(); }
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 void AddToWallet(Character character, TransactionType transactionType, double amount) { var wallet = _walletFactory(character, transactionType); wallet.Balance += amount; var b = TransactionLogEvent.Builder() .SetTransactionType(transactionType) .SetCreditBalance(wallet.Balance) .SetCreditChange(amount) .SetCharacter(character); character.LogTransaction(b); _centralBank.SubAmount(amount, transactionType); }
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); }