Load and update shop keywords, update shop gold

This commit is contained in:
Tyler Hallada 2021-02-13 17:51:34 -05:00
parent b33fa4ec77
commit 4b6c1570ac
5 changed files with 120 additions and 38 deletions

View File

@ -142,7 +142,7 @@ state SHOP_NAME
event OnInputAcceptST(string textInput)
Debug.Trace("BRMCMConfigMenu BRQuest properties: ShopId: " + BR.ShopId + " ShopName: " + BR.ShopName + " ShopDescription: " + BR.ShopDescription)
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, textInput, BR.ShopDescription)
BR.UpdateShop(BR.ShopId, textInput, BR.ShopDescription, BR.ShopGold, BR.ShopType, BR.ShopKeywords, BR.ShopKeywordsExclude)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
@ -163,7 +163,7 @@ state SHOP_NAME
event OnDefaultST()
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, Game.GetPlayer().GetBaseObject().GetName() + "'s Shop", BR.ShopDescription)
BR.UpdateShop(BR.ShopId, Game.GetPlayer().GetBaseObject().GetName() + "'s Shop", BR.ShopDescription, BR.ShopGold, BR.ShopType, BR.ShopKeywords, BR.ShopKeywordsExclude)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
@ -186,7 +186,7 @@ state SHOP_DESC
event OnInputAcceptST(string textInput)
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, BR.ShopName, textInput)
BR.UpdateShop(BR.ShopId, BR.ShopName, textInput, BR.ShopGold, BR.ShopType, BR.ShopKeywords, BR.ShopKeywordsExclude)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100
@ -207,7 +207,7 @@ state SHOP_DESC
event OnDefaultST()
SetInputOptionValueST("Updating...")
BR.UpdateShop(BR.ShopId, BR.ShopName, "")
BR.UpdateShop(BR.ShopId, BR.ShopName, "", BR.ShopGold, BR.ShopType, BR.ShopKeywords, BR.ShopKeywordsExclude)
int attempts = 0
while !BR.UpdateShopComplete && attempts < 100

View File

@ -29,6 +29,10 @@ event OnMenuClose(string menuName)
debug.Trace("BRMerchChestScript container menu closed")
BRQuestScript BRScript = BRQuest as BRQuestScript
if BRScript.ActiveShopId == BRScript.ShopId
int gold = self.GetItemCount(Gold001)
if gold != BRScript.ShopGold
BRScript.UpdateShop(BRScript.ShopId, BRScript.ShopName, BRScript.ShopDescription, gold, BRScript.ShopType, BRScript.ShopKeywords, BRScript.ShopKeywordsExclude)
endif
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
@ -118,6 +122,22 @@ function RefreshMerchandise()
endif
endFunction
event OnCreateMerchandiseSuccess(bool created)
Debug.Trace("BRMerchChestScript OnCreateMerchandiseSuccess created: " + created)
if created
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.Notification("Saved merchandise successfully")
else
Debug.Trace("BRMerchChestScript no container changes to save to the server")
endif
endEvent
event OnCreateMerchandiseFail(string error)
Debug.Trace("BRMerchChestScript OnCreateMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to save shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent
event OnCreateTransactionSuccess(int id, int quantity, int amount)
debug.Trace("BRMerchChestScript OnCreateTransactionSuccess id: " + id + " quantity: " + quantity + " amount: " + amount)
ObjectReference merchRef = self.GetLinkedRef(BRLinkItemRef)
@ -135,6 +155,10 @@ endEvent
event OnLoadMerchandiseSuccess(bool result)
Debug.Trace("BRMerchChestScript OnLoadMerchandiseSuccess result: " + result)
debug.MessageBox("Successfully loaded shop merchandise")
BRQuestScript BRScript = BRQuest as BRQuestScript
if !BRShop.RefreshGold(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ActiveShopId, self)
Debug.MessageBox("Failed to refresh shop gold.\n\n" + BRScript.BugReportCopy)
endif
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
@ -165,4 +189,19 @@ event OnLoadShelfPageFail(string error)
Debug.Trace("BRMerchChestScript OnLoadShelfPageFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to load or clear page of shelf merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent
event OnRefreshShopGoldSuccess(int gold)
Debug.Trace("BRMerchChestScript OnRefreshShopGoldSuccess gold: " + gold)
BRQuestScript BRScript = BRQuest as BRQuestScript
BRScript.ActiveShopGold = gold
if BRScript.ActiveShopId == BRScript.ShopId
BRScript.ShopGold = gold
endif
endEvent
event OnRefreshShopGoldFail(string error)
Debug.Trace("BRMerchChestScript OnRefreshShopGoldFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to refresh shop gold.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent

View File

@ -60,21 +60,4 @@ Event OnItemAdded(Form baseItem, int itemCount, ObjectReference itemRef, ObjectR
endif
; TODO: trade rejection
endif
endEvent
event OnCreateMerchandiseSuccess(bool created)
Debug.Trace("BRPublicMerchChestScript OnCreateMerchandiseSuccess created: " + created)
if created
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.Notification("Saved merchandise successfully")
else
Debug.Trace("BRPublicMerchChestScript no container changes to save to the server")
endif
endEvent
event OnCreateMerchandiseFail(string error)
Debug.Trace("BRPublicMerchChestScript OnCreateMerchandiseFail error: " + error)
BRQuestScript BRScript = BRQuest as BRQuestScript
Debug.MessageBox("Failed to save shop merchandise.\n\n" + error + "\n\n" + BRScript.BugReportCopy)
endEvent

View File

@ -11,6 +11,10 @@ int property OwnerId auto
int property ShopId auto
string property ShopName auto
string property ShopDescription auto
int property ShopGold auto
string property ShopType auto
Keyword[] property ShopKeywords auto
bool property ShopKeywordsExclude auto
; TODO: look up interior refs and merch by shop id instead of saving this?
int property InteriorRefListId auto
; Active shop data (for the currently loaded shop)
@ -18,6 +22,10 @@ int property ActiveOwnerId auto
int property ActiveShopId auto
string property ActiveShopName auto
string property ActiveShopDescription auto
int property ActiveShopGold auto
string property ActiveShopType auto
Keyword[] property ActiveShopKeywords auto
bool property ActiveShopKeywordsExclude auto
ObjectReference[] property ActiveShopShelves auto
; references
Actor property PlayerRef auto
@ -109,11 +117,15 @@ event OnCreateOwnerFail(string error)
StartModFailed = true
endEvent
event OnCreateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnCreateShopSucess id: " + id + " name: " + name + " description: " + description)
event OnCreateShopSuccess(int id, string name, string description, int gold, string shop_type, Keyword[] keywords, bool keywords_exclude)
Debug.Trace("BRQuestScript OnCreateShopSucess id: " + id + " name: " + name + " description: " + description + " gold: " + gold + " shop_type: " + shop_type + " keywords: " + keywords + " keywords_exclude: " + keywords_exclude)
ShopId = id
ShopName = name
ShopDescription = description
ShopGold = gold
ShopType = shop_type
ShopKeywords = keywords
ShopKeywordsExclude = keywords_exclude
Debug.Notification("Initialized Bazaar Realm client")
endEvent
@ -157,6 +169,14 @@ bool function LoadInteriorRefs()
ActiveShopId = ShopId
ActiveShopName = ShopName
ActiveShopDescription = ShopDescription
ActiveShopGold = ShopGold
ActiveShopType = ShopType
ActiveShopKeywords = ShopKeywords
ActiveShopKeywordsExclude = ShopKeywordsExclude
result = BRShop.SetVendorKeywords(ActiveShopKeywords, ActiveShopKeywordsExclude)
if !result
Debug.MessageBox("Failed to set shop vendor keywords\n\n" + BugReportCopy)
endif
return true
else
Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy)
@ -171,6 +191,7 @@ event OnLoadInteriorRefListSuccess(bool result, ObjectReference[] shelves)
Debug.MessageBox("Successfully loaded shop")
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
; TODO: load vendors from API response here
if !BRMerchandiseList.Load(ApiUrl, ApiKey, ActiveShopId, shopCell, ActiveShopShelves, PrivateChest)
Debug.MessageBox("Failed to load shop merchandise.\n\n" + BugReportCopy)
@ -195,21 +216,33 @@ int function ListMerchandise()
UILib.ShowNotification("Chose " + options[selectedIndex], "#74C56D")
endFunction
function UpdateShop(int id, string name, string description)
Debug.Trace("BRQuestScript UpdateShop id: " + id + " name: " + name + " description: " + description)
function UpdateShop(int id, string name, string description, int gold, string shopType, Keyword[] keywords, bool keywordsExclude)
Debug.Trace("BRQuestScript UpdateShop id: " + id + " name: " + name + " description: " + description + " gold: " + gold + " shopType: " + shopType + " keywords: " + keywords + " keywordsExclude: " + keywordsExclude)
UpdateShopComplete = false
bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, self)
bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, gold, shopType, keywords, keywordsExclude, self)
if !result
Debug.MessageBox("Failed to update shop.\n\n" + BugReportCopy)
UpdateShopComplete = true
endif
endFunction
event OnUpdateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnUpdateShopSucess id: " + id + " name: " + name + " description: " + description)
event OnUpdateShopSuccess(int id, string name, string description, int gold, string shopType, Keyword[] keywords, bool keywordsExclude)
Debug.Trace("BRQuestScript OnUpdateShopSuccess id: " + id + " name: " + name + " description: " + description + " gold: " + gold + " shopType: " + shopType + " keywords: " + keywords + " keywordsExclude: " + keywordsExclude)
ShopId = id
ShopName = name
ShopDescription = description
ShopGold = gold
ShopType = shopType
ShopKeywords = keywords
ShopKeywordsExclude = keywordsExclude
if ActiveShopId == ShopId
ActiveShopName = name
ActiveShopDescription = description
ActiveShopGold = gold
ActiveShopType = shopType
ActiveShopKeywords = keywords
ActiveShopKeywordsExclude = keywordsExclude
endif
UpdateShopComplete = true
endEvent
@ -229,11 +262,25 @@ function GetShop(int id)
endif
endFunction
event OnGetShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnGetShopSucess id: " + id + " name: " + name + " description: " + description)
ShopId = id
ShopName = name
ShopDescription = description
event OnGetShopSuccess(int id, string name, string description, int gold, string shop_type, Keyword[] keywords, bool keywords_exclude)
Debug.Trace("BRQuestScript OnGetShopSucess id: " + id + " name: " + name + " description: " + description + " gold: " + gold + " shop_type: " + shop_type + " keywords: " + keywords + " keywords_exclude: " + keywords_exclude)
; TODO: is this logic right?
if ShopId == id
ShopName = name
ShopDescription = description
ShopGold = gold
ShopType = shop_type
ShopKeywords = keywords
ShopKeywordsExclude = keywords_exclude
else
ActiveShopId = id
ActiveShopName = name
ActiveShopDescription = description
ActiveShopGold = gold
ActiveShopType = shop_type
ActiveShopKeywords = keywords
ActiveShopKeywordsExclude = keywords_exclude
endIf
GetShopComplete = true
endEvent
@ -253,8 +300,9 @@ function ListShops()
endif
endFunction
event OnListShopsSuccess(int[] ids, string[] names, string[] descriptions)
Debug.Trace("BRQuestScript OnListShopsSuccess ids.length: " + ids.Length + " names.length: " + names.Length + " descriptions.length: " + descriptions.Length)
event OnListShopsSuccess(int[] ids, string[] names, string[] descriptions, int[] golds, string[] shop_types, Keyword[] keywords, bool[] keywords_excludes)
Debug.Trace("BRQuestScript OnListShopsSuccess ids.length: " + ids.Length + " names.length: " + names.Length + " descriptions.length: " + descriptions.Length + " golds.length: " + golds.length + \
" shop_types.length: " + shop_types.length + " keywords.length: " + keywords.length + " keywords_excludes: " + keywords_excludes.length)
int index = 0
int selectedIndex = UILib.ShowList("Shop Merchandise", names, 0, 0)
ListShopsComplete = true
@ -263,8 +311,17 @@ event OnListShopsSuccess(int[] ids, string[] names, string[] descriptions)
ActiveShopId = ids[selectedIndex]
ActiveShopName = names[selectedIndex]
ActiveShopDescription = descriptions[selectedIndex]
ActiveShopGold = golds[selectedIndex]
ActiveShopType = shop_types[selectedIndex]
ActiveShopKeywords = BRShop.GetKeywordsSubArray(keywords, selectedIndex)
Debug.Trace("BRQuestScript OnListShopsSuccess ActiveShopKeywords: " + ActiveShopKeywords)
ActiveShopKeywordsExclude = keywords_excludes[selectedIndex]
bool result = BRShop.SetVendorKeywords(ActiveShopKeywords, ActiveShopKeywordsExclude)
if !result
Debug.MessageBox("Failed to set shop vendor keywords\n\n" + BugReportCopy)
endif
ShopDetailMessage.SetName(names[selectedIndex])
bool result = BRInteriorRefList.ClearCell()
result = BRInteriorRefList.ClearCell()
if !result
Debug.MessageBox("Failed to clear existing shop before loading in new shop.\n\n" + BugReportCopy)
endif

View File

@ -1,6 +1,9 @@
scriptname BRShop
bool function Create(string apiUrl, string apiKey, string name, string description = "", quest quest) global native
bool function Update(string apiUrl, string apiKey, int id, string name, string description = "", quest quest) global native
bool function Update(string apiUrl, string apiKey, int id, string name, string description = "", int gold = 0, string shop_type = "general_store", Keyword[] keywords, bool keywords_excludes = true, quest quest) global native
bool function Get(string apiUrl, string apiKey, int id, quest quest) global native
bool function List(string apiUrl, string apiKey, quest quest) global native
bool function List(string apiUrl, string apiKey, quest quest) global native
Keyword[] function GetKeywordsSubArray(Keyword[] flatKeywordsArray, int subArrayIndex) global native
bool function SetVendorKeywords(Keyword[] keywords, bool keywordsExclude) global native
bool function RefreshGold(string apiUrl, string apiKey, int id, ObjectReference privateMerchantChest) global native