Implement buying merchandise off shelf
Refreshes the shelf after buying and after closing chest.
This commit is contained in:
parent
69b87517ec
commit
ece73fcf0e
BIN
Bazaar Realm.esp
BIN
Bazaar Realm.esp
Binary file not shown.
@ -1,10 +1,85 @@
|
|||||||
scriptname BRMerchActivatorScript extends ObjectReference
|
scriptname BRMerchActivatorScript extends ObjectReference
|
||||||
|
|
||||||
Actor Property PlayerRef Auto
|
Keyword property BRLinkMerchShelf auto
|
||||||
|
Keyword property BRLinkMerchChest auto
|
||||||
|
Keyword property BRLinkItemRef auto
|
||||||
|
Keyword property BRLinkActivatorRef auto
|
||||||
|
Keyword property BRLinkMerchToggle auto
|
||||||
|
Keyword property BRLinkMerchNext auto
|
||||||
|
Keyword property BRLinkMerchPrev auto
|
||||||
|
Activator property ActivatorStatic auto
|
||||||
|
Actor property PlayerRef auto
|
||||||
|
Quest property BRQuest auto
|
||||||
|
MiscObject property Gold001 auto
|
||||||
|
|
||||||
Event OnActivate(ObjectReference akActionRef)
|
event OnActivate(ObjectReference akActionRef)
|
||||||
if akActionRef == PlayerRef
|
if akActionRef == PlayerRef
|
||||||
Form merch = BRMerchandiseList.Buy(self)
|
debug.Trace("BRMerchActivatorScript OnActivate by PlayerRef")
|
||||||
PlayerRef.AddItem(merch, 1)
|
int totalQuantity = BRMerchandiseList.GetQuantity(self)
|
||||||
|
int price = BRMerchandiseList.GetPrice(self)
|
||||||
|
|
||||||
|
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||||
|
ObjectReference merchRef = self.GetLinkedRef(BRLinkItemRef)
|
||||||
|
Form selectedMerchandiseRepl = BRScript.SelectedMerchandise.GetBaseObject()
|
||||||
|
selectedMerchandiseRepl.SetName(merchRef.GetBaseObject().GetName())
|
||||||
|
bool inBuyMenu = true
|
||||||
|
int quantity = 1
|
||||||
|
while inBuyMenu
|
||||||
|
int amount = quantity * price
|
||||||
|
int choice = BRScript.BuyMerchandiseMessage.Show(quantity as float, totalQuantity as float, amount as float, price as float)
|
||||||
|
if choice == 0
|
||||||
|
bool result = BRTransaction.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, false, quantity, amount, BRLinkItemRef, self)
|
||||||
|
if !result
|
||||||
|
Debug.MessageBox("Failed to buy merchandise.\n\n" + BRScript.BugReportCopy)
|
||||||
|
endif
|
||||||
|
inBuyMenu = false
|
||||||
|
elseif choice == 1
|
||||||
|
bool result = BRTransaction.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, false, totalQuantity, totalQuantity * price, BRLinkItemRef, self)
|
||||||
|
if !result
|
||||||
|
Debug.MessageBox("Failed to buy merchandise.\n\n" + BRScript.BugReportCopy)
|
||||||
|
endif
|
||||||
|
inBuyMenu = false
|
||||||
|
elseif choice == 2
|
||||||
|
string enteredQuantity = BRScript.UILib.ShowTextInput("Enter Quantity", "")
|
||||||
|
if enteredQuantity as int == 0
|
||||||
|
debug.Notification("Failed to parse a valid quantity. Enter a number between 1 and " + totalQuantity)
|
||||||
|
elseif enteredQuantity < 1
|
||||||
|
debug.Notification("Entered quantity less than minimum quantity: 1. Setting quantity to 1")
|
||||||
|
quantity = 1
|
||||||
|
elseif enteredQuantity as int > totalQuantity
|
||||||
|
debug.Notification("Entered quantity greater than maximum quantity: " + totalQuantity + ". Setting quantity to " + totalQuantity)
|
||||||
|
quantity = totalQuantity
|
||||||
|
else
|
||||||
|
quantity = enteredQuantity as int
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
inBuyMenu = false
|
||||||
|
endif
|
||||||
|
endWhile
|
||||||
|
selectedMerchandiseRepl.SetName("Selected Merchandise")
|
||||||
endif
|
endif
|
||||||
EndEvent
|
endEvent
|
||||||
|
|
||||||
|
function RefreshMerchandise()
|
||||||
|
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||||
|
ObjectReference merchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||||
|
if !BRMerchandiseList.Refresh(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, merchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkActivatorRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev)
|
||||||
|
Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy)
|
||||||
|
endif
|
||||||
|
endFunction
|
||||||
|
|
||||||
|
event OnCreateTransactionSuccess(int id, int quantity, int amount)
|
||||||
|
debug.Trace("BRMerchActivatorScript OnCreateTransactionSuccess id: " + id + " quantity: " + quantity + " amount: " + amount)
|
||||||
|
ObjectReference merchRef = self.GetLinkedRef(BRLinkItemRef)
|
||||||
|
PlayerRef.RemoveItem(Gold001, amount)
|
||||||
|
PlayerRef.AddItem(merchRef.GetBaseObject(), quantity)
|
||||||
|
RefreshMerchandise()
|
||||||
|
endEvent
|
||||||
|
|
||||||
|
; TODO: gracefully handle expected error cases (e.g. someone else buys all of item before this player can buy them)
|
||||||
|
Event OnCreateTransactionFail(string error)
|
||||||
|
Debug.Trace("BRMerchActivatorScript OnCreateTransactionFail error: " + error)
|
||||||
|
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||||
|
Debug.MessageBox("Failed to buy merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
|
||||||
|
RefreshMerchandise()
|
||||||
|
endEvent
|
@ -1,5 +1,13 @@
|
|||||||
Scriptname BRMerchChestScript extends ObjectReference
|
Scriptname BRMerchChestScript extends ObjectReference
|
||||||
|
|
||||||
|
Keyword property BRLinkMerchShelf auto
|
||||||
|
Keyword property BRLinkMerchChest auto
|
||||||
|
Keyword property BRLinkItemRef auto
|
||||||
|
Keyword property BRLinkActivatorRef auto
|
||||||
|
Keyword property BRLinkMerchToggle auto
|
||||||
|
Keyword property BRLinkMerchNext auto
|
||||||
|
Keyword property BRLinkMerchPrev auto
|
||||||
|
Activator property ActivatorStatic auto
|
||||||
Actor Property PlayerRef Auto
|
Actor Property PlayerRef Auto
|
||||||
Quest Property BRQuest Auto
|
Quest Property BRQuest Auto
|
||||||
|
|
||||||
@ -28,6 +36,11 @@ event OnCreateMerchandiseSuccess(bool created, int id)
|
|||||||
BRQuestScript BRScript = BRQuest as BRQuestScript
|
BRQuestScript BRScript = BRQuest as BRQuestScript
|
||||||
BRScript.MerchandiseListId = id;
|
BRScript.MerchandiseListId = id;
|
||||||
Debug.Notification("Saved merchandise successfully")
|
Debug.Notification("Saved merchandise successfully")
|
||||||
|
|
||||||
|
ObjectReference merchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
|
||||||
|
if !BRMerchandiseList.Refresh(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, merchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkActivatorRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev)
|
||||||
|
Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy)
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
Debug.Trace("BRMerchChestScript no container changes to save to the server")
|
Debug.Trace("BRMerchChestScript no container changes to save to the server")
|
||||||
endif
|
endif
|
||||||
|
@ -4,9 +4,12 @@ scriptname BRMerchandiseList
|
|||||||
bool function Toggle(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
bool function Toggle(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
||||||
bool function NextPage(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
bool function NextPage(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
||||||
bool function PrevPage(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
bool function PrevPage(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
||||||
|
bool function Load(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
||||||
|
bool function Refresh(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword chestKeyword, Keyword itemKeyword, Keyword activatorKeyword, Keyword toggleKeyword, Keyword nextKeyword, Keyword prevKeyword) global native
|
||||||
|
|
||||||
bool function Replace3D(ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword itemKeyword) global native
|
bool function Replace3D(ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword itemKeyword) global native
|
||||||
|
|
||||||
Form function Buy(ObjectReference merchandiseActivator) global native
|
bool function Create(string apiUrl, string apiKey, int shopId, ObjectReference merchantChest) global native
|
||||||
|
|
||||||
bool function Create(string apiUrl, string apiKey, int shopId, ObjectReference merchantChest) global native
|
int function GetQuantity(ObjectReference activator) global native
|
||||||
|
int function GetPrice(ObjectReference activator) global native
|
@ -20,9 +20,13 @@ int property ActiveShopId auto
|
|||||||
string property ActiveShopName auto
|
string property ActiveShopName auto
|
||||||
string property ActiveShopDescription auto
|
string property ActiveShopDescription auto
|
||||||
; references
|
; references
|
||||||
actor property PlayerRef auto
|
Actor property PlayerRef auto
|
||||||
ObjectReference property ShopXMarker auto
|
ObjectReference property ShopXMarker auto
|
||||||
message property ShopDetailMessage auto
|
; messages
|
||||||
|
Message property ShopDetailMessage auto
|
||||||
|
Message property BuyMerchandiseMessage auto
|
||||||
|
; message replacement refs
|
||||||
|
ObjectReference property SelectedMerchandise auto
|
||||||
; UI sync properties
|
; UI sync properties
|
||||||
bool property StartModFailed = false auto
|
bool property StartModFailed = false auto
|
||||||
bool property UpdateShopComplete = false auto
|
bool property UpdateShopComplete = false auto
|
||||||
|
3
Source/Scripts/BRTransaction.psc
Normal file
3
Source/Scripts/BRTransaction.psc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
scriptname BRTransaction
|
||||||
|
|
||||||
|
bool function Create(string apiUrl, string apiKey, int shop_id, bool is_sell, int quantity, int amount, Keyword item_keyword, ObjectReference activator) global native
|
Loading…
Reference in New Issue
Block a user