Esempio n. 1
0
        public Result <bool> ValidateBuyItemFromVendor(NetworkIdentity identity, RequestBuyItemFromVendorMessage data, out INetworkVendor <IItemInstance> outVendor, out INetworkItemInstance outItem)
        {
            outVendor = null;
            outItem   = null;
            if (CheckGuidBytes(data.vendorGuid.bytes) == false ||
                CheckGuidBytes(data.itemGuid.bytes) == false)
            {
                return(Failed());
            }

            outItem   = ServerItemRegistry.Get(data.itemGuid) as INetworkItemInstance;
            outVendor = ServerVendorRegistry.itemVendors.Get(data.vendorGuid);
            if (outItem == null || outVendor == null)
            {
                return(Failed());
            }

            var tempItem         = outItem;
            var vendorItemAmount = outVendor.itemCollection.GetAmount(o => o?.ID == tempItem.ID);

            if (vendorItemAmount < data.amount)
            {
                return(Failed());
            }

            // Check if player has read permission to vendor collection
            if (CheckClientVendorPermission(identity, outVendor, outItem) == false)
            {
                return(Failed());
            }

            return(true);
        }
        public void Cmd_RequestBuyItemFromVendor(RequestBuyItemFromVendorMessage data)
        {
            vendorReplicator.Cmd_RequestBuyItemFromVendor(data);

            // Update the entire collection of vendor products when the user buys something.
            var vendor = ServerVendorRegistry.itemVendors.Get(data.vendorGuid) as UNetVendor <IItemInstance>;

            if (vendor != null)
            {
                Server_SetItemVendorCollectionContentsOnClient(vendor.vendorGuid, vendor.vendorCollectionGuid, vendor.vendorCollection);
            }
        }
Esempio n. 3
0
        public void Cmd_RequestBuyItemFromVendor(RequestBuyItemFromVendorMessage data)
        {
            logger.LogVerbose($"[Server] Client requested to buy item {data.itemGuid} {data.amount}x from vendor {data.vendorGuid} with netID {bridge.netId}", bridge);

            INetworkItemInstance           item;
            INetworkVendor <IItemInstance> vendor;
            var error = inputValidator.ValidateBuyItemFromVendor(bridge.identity, data, out vendor, out item).error;

            if (error == null)
            {
                error = vendor.Server_BuyFromVendor(new Customer <IItemInstance>(Guid.NewGuid(), bridge.player, bridge.inventoryPlayer.itemCollectionGroup, bridge.inventoryPlayer.currencyCollectionGroup), item, data.amount).error;
            }

            HandleError(error);
        }