public Result <bool> ValidateSellItemToVendor(NetworkIdentity identity, RequestSellItemToVendorMessage 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()); } // Item has to be in a collection to be sellable. if (outItem.collectionEntry?.collection == null) { return(Failed()); } if (outItem.collectionEntry.amount < data.amount) { return(Failed()); } return(true); }
public void Cmd_RequestSellItemToVendor(RequestSellItemToVendorMessage data) { vendorReplicator.Cmd_RequestSellItemToVendor(data); // Update the entire collection of vendor products when the user sells something. var vendor = ServerVendorRegistry.itemVendors.Get(data.vendorGuid) as UNetVendor <IItemInstance>; if (vendor != null) { Server_SetItemVendorCollectionContentsOnClient(vendor.vendorGuid, vendor.vendorCollectionGuid, vendor.vendorCollection); } }
public void Cmd_RequestSellItemToVendor(RequestSellItemToVendorMessage data) { logger.LogVerbose($"[Server] Client requested to sell item {data.itemGuid} {data.amount}x to vendor {data.vendorGuid} with netID {bridge.netId}", bridge); INetworkItemInstance item; INetworkVendor <IItemInstance> vendor; var error = inputValidator.ValidateSellItemToVendor(bridge.identity, data, out vendor, out item).error; if (error == null) { var product = new VendorProduct <IItemInstance>(item, item.itemDefinition.buyPrice, item.itemDefinition.sellPrice); error = vendor.Server_SellToVendor(new Customer <IItemInstance>(Guid.NewGuid(), bridge.player, bridge.inventoryPlayer.itemCollectionGroup, bridge.inventoryPlayer.currencyCollectionGroup), product, data.amount).error; } HandleError(error); }