Partial refactor of merch for multiple shelves

Loads merch onto multiple shelves after loading interior refs.
This commit is contained in:
Tyler Hallada 2020-11-28 23:45:55 -05:00
parent 90087c3056
commit 8eeae0cf64
9 changed files with 81 additions and 80 deletions

Binary file not shown.

View File

@ -1,13 +1,7 @@
scriptname BRMerchActivatorScript extends ObjectReference scriptname BRMerchActivatorScript extends ObjectReference
Keyword property BRLinkMerchShelf auto Keyword property BRLinkMerchShelf auto
Keyword property BRLinkMerchChest auto
Keyword property BRLinkItemRef 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
MiscObject property Gold001 auto MiscObject property Gold001 auto
@ -63,9 +57,10 @@ endEvent
function RefreshMerchandise() function RefreshMerchandise()
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
ObjectReference merchantShelf = self.GetLinkedRef(BRLinkMerchShelf) 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("RefreshMerchandise not implemented yet!")
Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy) ; if !BRMerchandiseList.Refresh(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, merchantShelf)
endif ; Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy)
; endif
endFunction endFunction
event OnCreateTransactionSuccess(int id, int quantity, int amount) event OnCreateTransactionSuccess(int id, int quantity, int amount)

View File

@ -103,9 +103,10 @@ endFunction
function RefreshMerchandise() function RefreshMerchandise()
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
ObjectReference merchantShelf = self.GetLinkedRef(BRLinkMerchShelf) 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("RefreshMerchandise not implemented yet!")
Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy) ; if !BRMerchandiseList.Refresh(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, merchantShelf)
endif ; Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy)
; endif
endFunction endFunction
event OnCreateTransactionSuccess(int id, int quantity, int amount) event OnCreateTransactionSuccess(int id, int quantity, int amount)
@ -120,4 +121,23 @@ Event OnCreateTransactionFail(string error)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to buy merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy) Debug.MessageBox("Failed to buy merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
RefreshMerchandise() RefreshMerchandise()
endEvent
event OnLoadMerchandiseSuccess(bool result)
Debug.Trace("BRMerchChestScript OnLoadMerchandiseSuccess result: " + result)
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
debug.MessageBox("Successfully loaded shop merchandise")
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
while !BRMerchandiseList.ReplaceAll3D(shopCell)
Debug.Trace("BRMerchandiseList.Replace3D returned false, waiting and trying again")
Utility.Wait(0.05)
endWhile
endEvent
event OnLoadMerchandiseFail(string error)
Debug.Trace("BRMerchChestScript OnLoadMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent endEvent

View File

@ -1,13 +1,6 @@
scriptname BRMerchNextPageScript extends ObjectReference scriptname BRMerchNextPageScript extends ObjectReference
Keyword property BRLinkMerchShelf 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 Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
@ -15,10 +8,11 @@ event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
bool result = BRMerchandiseList.NextPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkActivatorRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) debug.MessageBox("BRMerchandiseList.NextPage not implemented yet!")
Debug.Trace("BRMerchandiseList.NextPage result: " + result) ; bool result = BRMerchandiseList.NextPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf)
if !result ; Debug.Trace("BRMerchandiseList.NextPage result: " + result)
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy) ; if !result
endif ; Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
; endif
endif endif
endEvent endEvent

View File

@ -1,13 +1,6 @@
scriptname BRMerchPrevPageScript extends ObjectReference scriptname BRMerchPrevPageScript extends ObjectReference
Keyword property BRLinkMerchShelf 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 Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
@ -15,10 +8,11 @@ event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
bool result = BRMerchandiseList.PrevPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkActivatorRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) debug.MessageBox("BRMerchandiseList.PrevPage not implemented yet!")
Debug.Trace("BRMerchandiseList.PrevPage result: " + result) ; bool result = BRMerchandiseList.PrevPage(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf)
if !result ; Debug.Trace("BRMerchandiseList.PrevPage result: " + result)
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy) ; if !result
endif ; Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
; endif
endif endif
endEvent endEvent

View File

@ -1,13 +1,6 @@
scriptname BRMerchToggleScript extends ObjectReference scriptname BRMerchToggleScript extends ObjectReference
Keyword property BRLinkMerchShelf 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 Actor property PlayerRef auto
Quest Property BRQuest Auto Quest Property BRQuest Auto
@ -15,25 +8,27 @@ event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef if akActionRef == PlayerRef
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
BRQuestScript BRScript = BRQuest as BRQuestScript BRQuestScript BRScript = BRQuest as BRQuestScript
bool result = BRMerchandiseList.Toggle(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkMerchChest, BRLinkItemRef, BRLinkActivatorRef, BRLinkMerchToggle, BRLinkMerchNext, BRLinkMerchPrev) debug.MessageBox("BRMerchandiseList.Toggle not implemented yet!")
Debug.Trace("BRMerchandiseList.Toggle result: " + result) ; bool result = BRMerchandiseList.Toggle(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, MerchantShelf)
if !result ; Debug.Trace("BRMerchandiseList.Toggle result: " + result)
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy) ; if !result
endif ; Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + BRScript.BugReportCopy)
; endif
endif endif
endEvent endEvent
event OnLoadMerchandiseSuccess(bool result) ; event OnLoadMerchandiseSuccess(bool result)
Debug.Trace("BRMerchToggleScript OnLoadMerchandiseSuccess result: " + result) ; Debug.Trace("BRMerchToggleScript OnLoadMerchandiseSuccess result: " + result)
ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf) ; ObjectReference MerchantShelf = self.GetLinkedRef(BRLinkMerchShelf)
while !BRMerchandiseList.Replace3D(MerchantShelf, ActivatorStatic, BRLinkMerchShelf, BRLinkItemRef) ; debug.MessageBox("BRMerchandiseList.Replace3D not implemented yet!")
Debug.Trace("BRMerchandiseList.Replace3D returned false, waiting and trying again") ; ; while !BRMerchandiseList.Replace3D(MerchantShelf)
Utility.Wait(0.05) ; ; Debug.Trace("BRMerchandiseList.Replace3D returned false, waiting and trying again")
endWhile ; ; Utility.Wait(0.05)
endEvent ; ; endWhile
; endEvent
event OnLoadMerchandiseFail(string error) ; event OnLoadMerchandiseFail(string error)
Debug.Trace("BRMerchToggleScript OnLoadMerchandiseFail error: " + error) ; Debug.Trace("BRMerchToggleScript OnLoadMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript ; BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy) ; Debug.MessageBox("Failed to load or clear shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent ; endEvent

View File

@ -1,13 +1,14 @@
scriptname BRMerchandiseList scriptname BRMerchandiseList
; TODO: a save function that saves the merch to the server, load should load from server ; TODO: a save function that saves the merch to the server, load should load from server
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) 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) 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) 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 Load(string apiUrl, string apiKey, int shop_id, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference merchantChest) 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 Refresh(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf) global native
bool function Replace3D(ObjectReference merchantShelf, Form activatorStatic, Keyword shelfKeyword, Keyword itemKeyword) global native bool function Replace3D(ObjectReference merchantShelf) global native
bool function ReplaceAll3D(Cell shopCell) 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

View File

@ -1,13 +1,6 @@
scriptname BRPublicMerchChestScript extends ObjectReference scriptname BRPublicMerchChestScript extends ObjectReference
Keyword property BRLinkMerchShelf 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 Actor property PlayerRef auto
Quest property BRQuest auto Quest property BRQuest auto
FormList property BREmptyFormList auto FormList property BREmptyFormList auto
@ -67,9 +60,10 @@ event OnCreateMerchandiseSuccess(bool created, int id)
Debug.Notification("Saved merchandise successfully") Debug.Notification("Saved merchandise successfully")
ObjectReference merchantShelf = self.GetLinkedRef(BRLinkMerchShelf) 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("BRMerchandiseList.Refresh not implemented yet!")
Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy) ; if !BRMerchandiseList.Refresh(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, merchantShelf)
endif ; Debug.MessageBox("Failed refresh merchandise.\n\n" + BRScript.BugReportCopy)
; endif
else else
Debug.Trace("BRPublicMerchChestScript no container changes to save to the server") Debug.Trace("BRPublicMerchChestScript no container changes to save to the server")
endif endif

View File

@ -19,6 +19,7 @@ int property ActiveOwnerId auto
int property ActiveShopId auto int property ActiveShopId auto
string property ActiveShopName auto string property ActiveShopName auto
string property ActiveShopDescription auto string property ActiveShopDescription auto
ObjectReference[] property ActiveShopShelves auto
; references ; references
Actor property PlayerRef auto Actor property PlayerRef auto
ObjectReference property ShopXMarker auto ObjectReference property ShopXMarker auto
@ -153,8 +154,7 @@ bool function LoadInteriorRefs()
endif endif
Debug.Trace("ClearCell result: " + result) Debug.Trace("ClearCell result: " + result)
result = BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, PrivateChest, PublicChest, self) if BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, PrivateChest, PublicChest, self)
if result
return true return true
else else
Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy) Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy)
@ -162,12 +162,20 @@ bool function LoadInteriorRefs()
endif endif
endFunction endFunction
event OnLoadInteriorRefListSuccess(bool result) event OnLoadInteriorRefListSuccess(bool result, ObjectReference[] shelves)
Debug.Trace("BRQuestScript OnLoadInteriorRefListSuccess result: " + result) Debug.Trace("BRQuestScript OnLoadInteriorRefListSuccess result: " + result)
ActiveShopId = ShopId ActiveShopId = ShopId
ActiveShopName = ShopName ActiveShopName = ShopName
ActiveShopDescription = ShopDescription ActiveShopDescription = ShopDescription
ActiveShopShelves = shelves
Debug.Trace("BRQuestScript OnLoadInteriorRefListSuccess ActiveShopShelves: " + ActiveShopShelves)
Debug.MessageBox("Successfully loaded shop") Debug.MessageBox("Successfully loaded shop")
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
if !BRMerchandiseList.Load(ApiUrl, ApiKey, ActiveShopId, shopCell, ActiveShopShelves, PrivateChest)
Debug.MessageBox("Failed to load shop merchandise.\n\n" + BugReportCopy)
endif
endEvent endEvent
event OnLoadInteriorRefListFail(string error) event OnLoadInteriorRefListFail(string error)