Allow selling items to the public merch chest
This commit is contained in:
parent
5e36e7bb6b
commit
c986c14754
@ -87,9 +87,9 @@ function MaybeCreateTransaction()
|
|||||||
elseif soldAmount > 0 && soldItemBase && soldItemQuantity > 0
|
elseif soldAmount > 0 && soldItemBase && soldItemQuantity > 0
|
||||||
debug.Trace("BRMerchChestScript MaybeCreateTransaction creating sell transaction")
|
debug.Trace("BRMerchChestScript MaybeCreateTransaction creating sell transaction")
|
||||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
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
|
if !result
|
||||||
Debug.MessageBox("Failed to buy merchandise.\n\n" + BRScript.BugReportCopy)
|
Debug.MessageBox("Failed to sell merchandise.\n\n" + BRScript.BugReportCopy)
|
||||||
endif
|
endif
|
||||||
soldAmount = 0
|
soldAmount = 0
|
||||||
soldItemBase = None
|
soldItemBase = None
|
||||||
|
@ -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
|
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 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
|
@ -1,9 +1,12 @@
|
|||||||
scriptname BRPublicMerchChestScript extends ObjectReference
|
scriptname BRPublicMerchChestScript extends ObjectReference
|
||||||
|
|
||||||
Keyword property BRLinkMerchShelf auto
|
Keyword property BRLinkMerchShelf auto
|
||||||
|
Keyword property BRLinkMerchChest auto
|
||||||
Actor property PlayerRef auto
|
Actor property PlayerRef auto
|
||||||
Quest property BRQuest auto
|
Quest property BRQuest auto
|
||||||
FormList property BREmptyFormList auto
|
FormList property BREmptyFormList auto
|
||||||
|
Message property BRSellMerchandise auto
|
||||||
|
MiscObject property Gold001 auto
|
||||||
|
|
||||||
event OnInit()
|
event OnInit()
|
||||||
Debug.Trace("BRPublicMerchChestScript OnInit")
|
Debug.Trace("BRPublicMerchChestScript OnInit")
|
||||||
@ -48,10 +51,27 @@ endEvent
|
|||||||
|
|
||||||
Event OnItemAdded(Form baseItem, int itemCount, ObjectReference itemRef, ObjectReference sourceContainer)
|
Event OnItemAdded(Form baseItem, int itemCount, ObjectReference itemRef, ObjectReference sourceContainer)
|
||||||
if sourceContainer == PlayerRef
|
if sourceContainer == PlayerRef
|
||||||
; TODO: implement selling, for now it rejects all additions
|
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||||
debug.Notification("Trade rejected")
|
Form selectedMerchandiseRepl = BRScript.SelectedMerchandise.GetBaseObject()
|
||||||
RemoveAllItems()
|
selectedMerchandiseRepl.SetName(baseItem.GetName())
|
||||||
PlayerRef.AddItem(baseItem, 1)
|
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
|
endif
|
||||||
endEvent
|
endEvent
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user