public BuyFromVendorResult(ICustomer <T> customer, IVendorProduct <T> item, int amount, CurrencyDecorator <double>[] currencies) { this.customer = customer; this.item = item; this.amount = amount; this.currencies = currencies; }
public sealed override void Repaint(IVendorProduct <IItemInstance> item, int amount) { if (current != null) { var def = current?.item.itemDefinition as IUnityItemDefinition; if (def == null) { logger.Warning($"Trying to add a item definition to collection that doesn't implement {nameof(IUnityItemDefinition)} - Can't add item to collection UI", this); return; } Set(_itemName, def.name); Set(_itemDescription, def.description); Set(_itemIcon, def.icon); SetActive(_cooldown, true); Set(_stackSize, string.Format(_stackSizeFormat, amount, def.maxStackSize)); SetActive(_buyPriceContainer, true); SetActive(_sellPriceContainer, true); } else { Set(_itemName, string.Empty); Set(_itemDescription, string.Empty); Set(_itemIcon, null); SetActive(_cooldown, false); Set(_stackSize, string.Empty); SetActive(_buyPriceContainer, false); SetActive(_sellPriceContainer, false); } base.Repaint(item, amount); }
protected virtual void RepaintBuyCurrencies(IVendorProduct <IItemInstance> item) { PrepareForCurrencyUIRepaint(expectedArrayLength: item.buyPrice.Length); for (int i = 0; i < item.buyPrice.Length; i++) { if (currencyUIs[i] == null) { currencyUIs[i] = Instantiate <CurrencyUI>(_currencyUIPrefab, _buyPriceContainer, false); } float multiplier = 1f; if (this.linkedVendor != null) { multiplier = this.linkedVendor.config.buyFromVendorPriceMultiplier; } currencyUIs[i].Repaint(item.buyPrice[i].amount * multiplier, item.buyPrice[i].currency); currencyUIs[i].gameObject.SetActive(true); } for (int i = item.buyPrice.Length; i < currencyUIs.Length; i++) { if (currencyUIs[i] == null) { continue; } currencyUIs[i].gameObject.SetActive(false); } }
public void Setup() { _vendorCollection = new Collection <IVendorProduct <IItemInstance> >(10); _vendorCurrencies = new CurrencyCollection(); _gold = new Currency(Guid.NewGuid(), "Gold", "GOLD", 2, 999f); _vendor = new Vendor <IItemInstance>(new VendorConfig(), _vendorCollection, _vendorCurrencies); _customerCollection = new Collection <IItemInstance>(10); _customerCurrencies = new CurrencyCollection(); _customer = new Customer <IItemInstance>(Guid.NewGuid(), null, new CollectionGroup <IItemInstance>(new [] { new CollectionGroup <IItemInstance> .Slot(_customerCollection), }), new CurrencyCollectionGroup <ICurrency>(_customerCurrencies)); _item1 = new ItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new[] { new CurrencyDecorator <double>(_gold, 1d) }, sellPrice = new[] { new CurrencyDecorator <double>(_gold, 0.6d) } }); _item2 = new ItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new[] { new CurrencyDecorator <double>(_gold, 2d) }, sellPrice = new[] { new CurrencyDecorator <double>(_gold, 1.6d) } }); _product1 = new VendorProduct <IItemInstance>(_item1, _item1.itemDefinition.buyPrice, _item1.itemDefinition.sellPrice); _product2 = new VendorProduct <IItemInstance>(_item2, _item2.itemDefinition.buyPrice, _item2.itemDefinition.sellPrice); }
public virtual Result <bool> CanSellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1) { if (product.sellPrice.Length == 0) { return(new Result <bool>(false, Errors.VendorProductHasNoPrice)); } // // Vendor // var canAdd = vendorCollection.CanAdd(product, amount); if (canAdd.result == false) { return(canAdd); } // Vendor doesn't have enough currency foreach (var c in product.sellPrice) { var canRemoveCurrency = vendorCurrencies.CanRemove(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier); if (canRemoveCurrency.result == false) { return(canRemoveCurrency); } } // // Customer // var canRemoveCustomer = customer.CanRemoveItem(product.item, amount); if (canRemoveCustomer.result == false) { return(canRemoveCustomer); } foreach (var c in product.sellPrice) { var canAddCurrency = customer.CanAddCurrency(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier); if (canAddCurrency.result == false) { return(canAddCurrency); } } return(true); }
public void Repaint(IVendorProduct <IItemInstance> product, int amount) { if (worldModelParent == null) { return; } var def = product?.item?.itemDefinition as IUnityItemDefinition; if (product != null && def != null) { Create3DModel(worldModelParent, def.worldModel); } else { Clean(); } }
public ItemVendorProductMessage(IVendorProduct <IItemInstance> product, int amount) { this.itemAmount = new ItemAmountMessage() { itemInstance = new RegisterItemInstanceMessage(product.item), amount = (ushort)amount }; buyPrice = new CurrencyDecoratorMessage[product.buyPrice.Length]; for (int i = 0; i < product.buyPrice.Length; i++) { buyPrice[i] = new CurrencyDecoratorMessage(product.buyPrice[i]); } sellPrice = new CurrencyDecoratorMessage[product.sellPrice.Length]; for (int i = 0; i < product.sellPrice.Length; i++) { sellPrice[i] = new CurrencyDecoratorMessage(product.sellPrice[i]); } }
public bool Equals(IVendorProduct <T> other) { if (Equals(null, other)) { return(false); } if (item.Equals(other.item) == false) { return(false); } if (buyPrice.Length != other.buyPrice.Length) { return(false); } if (sellPrice.Length != other.sellPrice.Length) { return(false); } for (int i = 0; i < buyPrice.Length; i++) { if (buyPrice[i].Equals(other.buyPrice[i]) == false) { return(false); } } for (int i = 0; i < sellPrice.Length; i++) { if (sellPrice[i].Equals(other.sellPrice[i]) == false) { return(false); } } return(true); }
public override Result <SellToVendorResult <T> > SellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1) { var c = customer.character as UnityEngine.Component; Assert.IsNotNull(c, "Customer character object is not a UnityEngine.Component type"); var bridge = c.GetComponent <UNetActionsBridge>(); Assert.IsNotNull(bridge, "No UNetActionsBridge found on customer character"); if (bridge.isClient) { var a = vendorCollection as IUNetCollection; Assert.IsNotNull(a, "UNet vendor's collection is not a IUNetCollection"); bridge.Cmd_RequestSellItemToVendor(new RequestSellItemToVendorMessage() { sellFromCollectionGuid = a.ID, vendorGuid = vendorGuid, itemGuid = product.ID, amount = (ushort)amount }); } else if (bridge.isServer) { return(Server_SellToVendor(customer, product, amount)); } return(new Result <SellToVendorResult <T> >(null, Errors.NetworkNoAuthority)); }
public Result <SellToVendorResult <T> > Server_SellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1) { return(base.SellToVendor(customer, product, amount)); }
protected override IUnityItemDefinition GetItemDefinition(IVendorProduct <IItemInstance> item) { return(item.item.itemDefinition as IUnityItemDefinition); }
public virtual Result <SellToVendorResult <T> > SellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1) { var canSell = CanSellToVendor(customer, product, amount); if (canSell.result == false) { return(new Result <SellToVendorResult <T> >(null, canSell.error)); } var originalAmount = product.collectionEntry?.amount; customer.RemoveItem(product.item, amount); var soldProduct = product; if (config.addSoldProductToVendor) { // NOTE: If we're removing the entire stack from the customer's collection it's safe the move everything over. // NOTE: If we're moving a part of the stack, duplicate it and move the duplicates. if (amount < originalAmount) { // Not selling the entire stack; Duplicate the item for the next slot. soldProduct = (IVendorProduct <T>)product.Clone(); } vendorCollection.Add(soldProduct, amount); } foreach (var c in product.sellPrice) { vendorCurrencies.Remove(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier); customer.AddCurrency(c.currency, c.amount * amount * config.sellToVendorPriceMultiplier); } var sellResult = new SellToVendorResult <T>(customer, soldProduct, amount, soldProduct.sellPrice); OnSoldToVendor?.Invoke(this, sellResult); return(sellResult); }
public override Result <SellToVendorResult <T> > SellToVendor(ICustomer <T> customer, IVendorProduct <T> product, int amount = 1) { var c = customer.character as UnityEngine.Component; Assert.IsNotNull(c, "Customer character object is not a UnityEngine.Component type"); var bridge = c.GetComponent <PUN2ActionsBridge>(); Assert.IsNotNull(bridge, "No PUN2ActionsBridge found on customer character"); //if (!bridge.photonView.IsServer() /*bridge.isClient*/) { var a = vendorCollection as IPUN2Collection; Assert.IsNotNull(a, "PUN2 vendor's collection is not a IPUN2Collection"); bridge.photonView.RPC(nameof(bridge.Cmd_RequestSellItemToVendor), PhotonNetwork.MasterClient, ///*sellFromCollectionGuid: */ a.ID.ToByteArray(), /*vendorGuid: */ vendorGuid.ToByteArray(), /*itemGuid: */ product.ID.ToByteArray(), /*amount: */ amount ); return(new Result <SellToVendorResult <T> >(null, null /*new Error(int.MinValue, "No result known yet")*/)); } //else if (bridge.photonView.IsServer() /*bridge.isServer*/) //{ // return Server_SellToVendor(customer, product, amount); //} //return new Result<SellToVendorResult<T>>(null, Errors.NetworkNoAuthority); }