Allow selling items to the public merch chest

This commit is contained in:
Tyler Hallada 2021-02-06 00:29:47 -05:00
parent 5e36e7bb6b
commit c986c14754
3 changed files with 28 additions and 7 deletions

View File

@ -87,9 +87,9 @@ function MaybeCreateTransaction()
elseif soldAmount > 0 && soldItemBase && soldItemQuantity > 0
debug.Trace("BRMerchChestScript MaybeCreateTransaction creating sell transaction")
BRQuestScript BRScript = BRQuest as BRQuestScript
bool result = BRTransaction.CreateFromVendorSale(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, false, boughtItemQuantity, soldAmount, soldItemBase, self)
bool result = BRTransaction.CreateFromVendorSale(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, true, soldItemQuantity, soldAmount, soldItemBase, self)
if !result
Debug.MessageBox("Failed to buy merchandise.\n\n" + BRScript.BugReportCopy)
Debug.MessageBox("Failed to sell merchandise.\n\n" + BRScript.BugReportCopy)
endif
soldAmount = 0
soldItemBase = None

View File

@ -13,4 +13,5 @@ bool function ReplaceAll3D(Cell shopCell) global native
bool function Create(string apiUrl, string apiKey, int shopId, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference merchantChest) global native
int function GetQuantity(ObjectReference activator) global native
int function GetPrice(ObjectReference activator) global native
int function GetPrice(ObjectReference activator) global native
int function GetSellPrice(Form form) global native

View File

@ -1,9 +1,12 @@
scriptname BRPublicMerchChestScript extends ObjectReference
Keyword property BRLinkMerchShelf auto
Keyword property BRLinkMerchChest auto
Actor property PlayerRef auto
Quest property BRQuest auto
FormList property BREmptyFormList auto
Message property BRSellMerchandise auto
MiscObject property Gold001 auto
event OnInit()
Debug.Trace("BRPublicMerchChestScript OnInit")
@ -48,10 +51,27 @@ endEvent
Event OnItemAdded(Form baseItem, int itemCount, ObjectReference itemRef, ObjectReference sourceContainer)
if sourceContainer == PlayerRef
; TODO: implement selling, for now it rejects all additions
debug.Notification("Trade rejected")
RemoveAllItems()
PlayerRef.AddItem(baseItem, 1)
BRQuestScript BRScript = BRQuest as BRQuestScript
Form selectedMerchandiseRepl = BRScript.SelectedMerchandise.GetBaseObject()
selectedMerchandiseRepl.SetName(baseItem.GetName())
ObjectReference shelf = self.GetLinkedRef(BRLinkMerchShelf)
ObjectReference privateChest = shelf.GetLinkedRef(BRLinkMerchChest)
int price = BRMerchandiseList.GetSellPrice(baseItem)
if BRSellMerchandise.Show(itemCount, price * itemCount, price) == 0
debug.Trace("BRPublicMerchChestScript creating sell transaction")
bool result = BRTransaction.CreateFromVendorSale(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, true, itemCount, price * itemCount, baseItem, privateChest)
if !result
Debug.MessageBox("Failed to sell merchandise.\n\n" + BRScript.BugReportCopy)
else
RemoveAllItems()
PlayerRef.AddItem(Gold001, price * itemCount)
endif
else
debug.Notification("Trade cancelled")
RemoveAllItems()
PlayerRef.AddItem(baseItem, itemCount)
endif
; TODO: trade rejection
endif
endEvent