public void PlaceAuction(ItemSlot slot, int quantity, int price, double durationHours, int depositCost, EntityAgent sellerEntity, Entity auctioneerEntity, out string failureCode) { if (slot.StackSize < quantity) { failureCode = "notenoughitems"; return; } if (GetAuctionsFrom((sellerEntity as EntityPlayer).Player).Count > 30) { failureCode = "toomanyauctions"; return; } int monehs = InventoryTrader.GetPlayerAssets(sellerEntity); if (monehs < GetDepositCost(slot) * depositCost) { failureCode = "notenoughgears"; return; } failureCode = null; InventoryTrader.DeductFromEntity(sapi, sellerEntity, depositCost); (auctioneerEntity as EntityTrader).Inventory?.GiveToTrader(depositCost); long id = ++auctionsData.nextAuctionId; string sellerName = sellerEntity.GetBehavior <EntityBehaviorNameTag>()?.DisplayName; if (sellerName == null) { sellerName = sellerEntity.Properties.Code.ToShortString(); } float debt; string uid = (sellerEntity as EntityPlayer)?.PlayerUID ?? ""; auctionsData.DebtToTraderByPlayer.TryGetValue(uid, out debt); float traderCutGears = price * SalesCutRate + debt; auctionsData.DebtToTraderByPlayer[uid] = traderCutGears - (int)traderCutGears; var auction = new Auction() { AuctionId = id, ExpireTotalHours = sapi.World.Calendar.TotalHours + durationHours, ItemStack = slot.TakeOut(quantity), PostedTotalHours = sapi.World.Calendar.TotalHours, Price = price, TraderCut = (int)traderCutGears, SellerName = sellerName, SellerUid = (sellerEntity as EntityPlayer)?.PlayerUID, SellerEntityId = sellerEntity.EntityId, SrcAuctioneerEntityPos = auctioneerEntity.Pos.XYZ, SrcAuctioneerEntityId = auctioneerEntity.EntityId }; auctions.Add(id, auction); slot.MarkDirty(); sendAuctions(new Auction[] { auction }, null); }
public GuiDialogConfirmPurchase(ICoreClientAPI capi, EntityAgent buyerEntity, EntityAgent auctioneerEntity, Auction auction) : base(capi) { this.buyerEntity = buyerEntity; this.traderEntity = auctioneerEntity; this.auction = auction; auctionSys = capi.ModLoader.GetModSystem <ModSystemAuction>(); Init(); }