private bool OnCreateAuctionConfirm()
        {
            var cmp    = Composers["tradercreateauction"];
            int monehs = InventoryTrader.GetPlayerAssets(capi.World.Player.Entity);
            int weeks  = cmp.GetDropDown("duration").SelectedValue.ToInt(1);
            int price  = (int)cmp.GetNumberInput("price").GetValue();

            if (price < 1)
            {
                capi.TriggerIngameError(this, "atleast1gear", Lang.Get("Must sell item for at least 1 gear"));
                return(true);
            }

            if (monehs < auctionSys.GetDepositCost(auctionSlotInv[0]) * weeks / auctionSys.DurationWeeksMul)
            {
                capi.TriggerIngameError(this, "notenoughgears", Lang.Get("Not enough gears to pay the deposit"));
                return(true);
            }



            auctionSys.PlaceAuctionClient(owningEntity, price, weeks);
            OnCreateAuctionClose();

            lastPrice = price;

            auctionSlotInv[0].Itemstack = null;

            capi.Gui.PlaySound(new AssetLocation("effect/receptionbell.ogg"));


            return(true);
        }
Exemplo n.º 2
0
        void CalcAndUpdateAssetsDisplay()
        {
            int playerAssets = InventoryTrader.GetPlayerAssets(capi.World.Player.Entity);

            SingleComposer.GetDynamicText("playerMoneyText")?.SetNewText(Lang.Get("You have {0} Gears", playerAssets));

            int traderAssets = traderInventory.GetTraderAssets();

            SingleComposer.GetDynamicText("traderMoneyText")?.SetNewText(Lang.Get("{0} has {1} Gears", owningEntity.GetBehavior <EntityBehaviorNameTag>().DisplayName, traderAssets));
        }
Exemplo n.º 3
0
        public void PurchaseAuction(long auctionId, EntityAgent buyerEntity, Entity auctioneerEntity, bool withDelivery, out string failureCode)
        {
            if (auctions.TryGetValue(auctionId, out var auction))
            {
                if ((buyerEntity as EntityPlayer)?.PlayerUID == auction.SellerUid)
                {
                    failureCode = "ownauction";
                    return;
                }

                // Already purchased
                if (auction.BuyerName != null)
                {
                    failureCode = "alreadypurchased";
                    return;
                }

                int monehs        = InventoryTrader.GetPlayerAssets(buyerEntity);
                int deliveryCosts = withDelivery ? DeliveryCostsByDistance(auctioneerEntity.Pos.XYZ, auction.SrcAuctioneerEntityPos) : 0;

                int totalcost = auction.Price + deliveryCosts;

                if (monehs < totalcost)
                {
                    failureCode = "notenoughgears";
                    return;
                }

                InventoryTrader.DeductFromEntity(sapi, buyerEntity, totalcost);
                (auctioneerEntity as EntityTrader).Inventory?.GiveToTrader((int)(auction.Price * SalesCutRate + deliveryCosts));

                string buyerName = buyerEntity.GetBehavior <EntityBehaviorNameTag>()?.DisplayName;
                if (buyerName == null)
                {
                    buyerName = buyerEntity.Properties.Code.ToShortString();
                }

                auction.BuyerName              = buyerName;
                auction.WithDelivery           = withDelivery;
                auction.BuyerUid               = (buyerEntity as EntityPlayer)?.PlayerUID;
                auction.RetrievableTotalHours  = sapi.World.Calendar.TotalHours + 1 + 3 * deliveryCosts;
                auction.DstAuctioneerEntityId  = withDelivery ? auctioneerEntity.EntityId : auction.SrcAuctioneerEntityId;
                auction.DstAuctioneerEntityPos = withDelivery ? auctioneerEntity.Pos.XYZ : auction.SrcAuctioneerEntityPos;
                auction.State = EnumAuctionState.Sold;

                sendAuctions(new Auction[] { auction }, null);

                failureCode = null;
                return;
            }

            failureCode = "nosuchauction";
            return;
        }
Exemplo n.º 4
0
        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);
        }