2020-10-13 01:26:16 +00:00
scriptname BRQuestScript extends Quest
2020-10-20 05:26:49 +00:00
; Mod Data
2020-10-13 01:26:16 +00:00
int property ModVersion = 1 auto
2020-10-20 05:26:49 +00:00
; Client config
2020-10-13 01:26:16 +00:00
string property ApiUrl = "https://api.bazaarrealm.com" auto
string property ApiKey auto
2020-10-20 05:26:49 +00:00
; Owner data (for the shop the player owns)
2020-10-13 01:26:16 +00:00
int property OwnerId auto
2020-10-20 05:26:49 +00:00
; TODO: need to be able to create multiple shops (make these arrays?)
2020-10-13 01:26:16 +00:00
int property ShopId auto
2020-10-18 06:33:26 +00:00
string property ShopName auto
string property ShopDescription auto
2020-10-20 05:26:49 +00:00
; 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)
int property ActiveOwnerId auto
int property ActiveShopId auto
string property ActiveShopName auto
string property ActiveShopDescription auto
2020-11-29 04:45:55 +00:00
ObjectReference[] property ActiveShopShelves auto
2020-10-20 05:26:49 +00:00
; references
2020-11-02 06:39:45 +00:00
Actor property PlayerRef auto
2020-10-13 01:26:16 +00:00
ObjectReference property ShopXMarker auto
2020-11-21 06:37:41 +00:00
ObjectReference property PrivateChest auto
ObjectReference property PublicChest auto
2020-11-02 06:39:45 +00:00
; messages
Message property ShopDetailMessage auto
Message property BuyMerchandiseMessage auto
; message replacement refs
ObjectReference property SelectedMerchandise auto
2020-10-20 05:26:49 +00:00
; UI sync properties
2020-10-17 00:20:51 +00:00
bool property StartModFailed = false auto
2020-10-18 06:33:26 +00:00
bool property UpdateShopComplete = false auto
bool property GetShopComplete = false auto
2020-10-19 05:13:18 +00:00
bool property ListShopsComplete = false auto
2020-10-13 01:26:16 +00:00
UILIB_1 property UILib auto
2020-10-19 00:56:10 +00:00
string property BugReportCopy = "Please submit a bug on Nexus Mods with the contents of BazaarRealmPlugin.log and BazaarRealmClient.log usually located in C:\\Users\\<your user>\\Documents\\My Games\\Skyrim Special Edition\\SKSE." auto
2020-10-13 01:26:16 +00:00
int function GetVersion()
return 1
endFunction
event OnInit()
Debug.Trace("BRQuestScript OnInit")
Maintenance()
endEvent
function Maintenance()
Debug.Trace("BRQuestScript Maintenance")
UILib = (Self as Form) as UILIB_1
2020-10-17 23:23:57 +00:00
if !BRClient.Init()
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\nPlease ensure that the folder Documents\\My Games\\Skyrim Special Edition\\SKSE exists and is accessible by Skyrim.")
2020-10-17 23:23:57 +00:00
endif
2020-10-13 01:26:16 +00:00
int newVersion = GetVersion()
if ModVersion < newVersion
ModVersion = newVersion
; TODO: update tasks
Debug.Notification("Bazaar Realm upgraded to version: " + ModVersion)
endif
endFunction
bool function StartMod()
2020-10-17 00:20:51 +00:00
Debug.Trace("BRQuestScript StartMod")
StartModFailed = false
2020-10-16 03:42:57 +00:00
bool result = BRClient.StatusCheck(ApiUrl, self)
if !result
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\nThe API server might be down: " + ApiUrl)
2020-10-17 00:20:51 +00:00
StartModFailed = true
2020-10-16 03:42:57 +00:00
endif
return result
endFunction
2020-10-19 00:56:10 +00:00
event OnStatusCheckSuccess(bool result)
Debug.Trace("BRQuestScript OnStatusCheckSuccess result: " + result)
2020-10-13 01:26:16 +00:00
if result
ApiKey = BRClient.GenerateApiKey()
Debug.Trace("apiKey: " + ApiKey)
Debug.Trace("apiUrl: " + ApiUrl)
2020-10-16 03:42:57 +00:00
string playerName = PlayerRef.GetBaseObject().GetName()
bool ownerResult = BROwner.Create(ApiUrl, ApiKey, playerName, ModVersion, self)
if !ownerResult
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to create new owner in the API.\n\n" + BugReportCopy)
2020-10-17 00:20:51 +00:00
StartModFailed = true
2020-10-13 01:26:16 +00:00
endif
endif
2020-10-16 03:42:57 +00:00
endEvent
2020-10-19 00:56:10 +00:00
event OnStatusCheckFail(string error)
Debug.Trace("BRQuestScript OnStatusCheckFail error: " + error)
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\nThe API server might be down: " + ApiUrl)
StartModFailed = true
endEvent
event OnCreateOwnerSuccess(int id)
Debug.Trace("BRQuestScript OnCreateOwnerSuccess id: " + id)
2020-10-16 03:42:57 +00:00
string playerName = PlayerRef.GetBaseObject().GetName()
2020-10-19 00:56:10 +00:00
OwnerId = id
bool shopResult = BRShop.Create(ApiUrl, ApiKey, playerName + "'s Shop", "", self)
if !shopResult
Debug.MessageBox("Failed to create new shop in the API.\n\n" + BugReportCopy)
2020-10-17 00:20:51 +00:00
StartModFailed = true
2020-10-16 03:42:57 +00:00
endif
endEvent
2020-10-19 00:56:10 +00:00
event OnCreateOwnerFail(string error)
Debug.Trace("BRQuestScript OnCreateOwnerFail error: " + error)
Debug.MessageBox("Failed to create new owner in the API.\n\n" + error + "\n\n" + BugReportCopy)
StartModFailed = true
endEvent
2020-10-18 06:33:26 +00:00
event OnCreateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnCreateShopSucess id: " + id + " name: " + name + " description: " + description)
ShopId = id
ShopName = name
ShopDescription = description
Debug.Notification("Initialized Bazaar Realm client")
endEvent
event OnCreateShopFail(string error)
Debug.Trace("BRQuestScript OnCreateShopFail error: " + error)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to initialize Bazaar Realm client.\n\n" + error + "\n\n" + BugReportCopy)
2020-10-18 06:33:26 +00:00
StartModFailed = true
2020-10-16 03:42:57 +00:00
endEvent
2020-10-13 01:26:16 +00:00
bool function SaveInteriorRefs()
; TODO: this should not save anything if player is not currently in their shop
2020-10-16 03:42:57 +00:00
bool result = BRInteriorRefList.Create(ApiUrl, ApiKey, ShopId, self)
if result
2020-10-13 01:26:16 +00:00
return true
else
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to save shop.\n\n" + BugReportCopy)
2020-10-13 01:26:16 +00:00
return false
endif
endFunction
2020-10-19 00:56:10 +00:00
event OnCreateInteriorRefListSuccess(int id)
2020-11-19 04:31:41 +00:00
Debug.Trace("BRQuestScript OnCreateInteriorRefListSuccess id: " + id)
2020-10-19 00:56:10 +00:00
InteriorRefListId = id
Debug.MessageBox("Successfully saved shop.")
endEvent
event OnCreateInteriorRefListFail(string error)
2020-11-19 04:31:41 +00:00
Debug.Trace("BRQuestScript OnCreateInteriorRefListFail error: " + error)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to save shop.\n\n" + error + "\n\n" + BugReportCopy)
2020-10-16 03:42:57 +00:00
endEvent
2020-10-13 01:26:16 +00:00
bool function LoadInteriorRefs()
2020-10-19 00:56:10 +00:00
; TODO: this should not load anything if player is not currently in their shop
2020-10-16 03:42:57 +00:00
bool result = BRInteriorRefList.ClearCell()
if !result
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to clear existing shop before loading in new shop.\n\n" + BugReportCopy)
2020-10-16 03:42:57 +00:00
endif
Debug.Trace("ClearCell result: " + result)
2020-10-17 00:20:51 +00:00
2020-11-29 04:45:55 +00:00
if BRInteriorRefList.Load(ApiUrl, ApiKey, InteriorRefListId, ShopXMarker, PrivateChest, PublicChest, self)
2021-01-24 01:11:47 +00:00
ActiveShopId = ShopId
ActiveShopName = ShopName
ActiveShopDescription = ShopDescription
2020-10-13 01:26:16 +00:00
return true
else
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy)
2020-10-13 01:26:16 +00:00
return false
endif
endFunction
2020-11-29 04:45:55 +00:00
event OnLoadInteriorRefListSuccess(bool result, ObjectReference[] shelves)
2020-11-19 04:31:41 +00:00
Debug.Trace("BRQuestScript OnLoadInteriorRefListSuccess result: " + result)
2020-11-29 04:45:55 +00:00
ActiveShopShelves = shelves
Debug.Trace("BRQuestScript OnLoadInteriorRefListSuccess ActiveShopShelves: " + ActiveShopShelves)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Successfully loaded shop")
2020-11-29 04:45:55 +00:00
; 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
2020-10-19 00:56:10 +00:00
endEvent
event OnLoadInteriorRefListFail(string error)
2020-11-19 04:31:41 +00:00
Debug.Trace("BRQuestScript OnLoadInteriorRefListFail error: " + error)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to load shop.\n\n" + error + "\n\n" + BugReportCopy)
2020-10-16 03:42:57 +00:00
endEvent
2020-10-19 00:56:10 +00:00
; currently unused, was testing out UILib
2020-10-13 01:26:16 +00:00
int function ListMerchandise()
string[] options = new string[5]
options[0] = "First Item"
options[1] = "Second Item"
options[2] = "Third Item"
options[3] = "Fourth Item"
options[4] = "Fifth Item"
int selectedIndex = UILib.ShowList("Shop Merchandise", options, 0, 0)
UILib.ShowNotification("Chose " + options[selectedIndex], "#74C56D")
endFunction
2020-10-18 06:33:26 +00:00
function UpdateShop(int id, string name, string description)
Debug.Trace("BRQuestScript UpdateShop id: " + id + " name: " + name + " description: " + description)
UpdateShopComplete = false
bool result = BRShop.Update(ApiUrl, ApiKey, id, name, description, self)
if !result
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to update shop.\n\n" + BugReportCopy)
2020-10-18 06:33:26 +00:00
UpdateShopComplete = true
endif
endFunction
event OnUpdateShopSuccess(int id, string name, string description)
Debug.Trace("BRQuestScript OnUpdateShopSucess id: " + id + " name: " + name + " description: " + description)
ShopId = id
ShopName = name
ShopDescription = description
UpdateShopComplete = true
endEvent
event OnUpdateShopFail(string error)
Debug.Trace("BRQuestScript OnUpdateShopFail error: " + error)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to update shop.\n\n" + error + "\n\n" + BugReportCopy)
2020-10-18 06:33:26 +00:00
UpdateShopComplete = true
endEvent
function GetShop(int id)
Debug.Trace("BRQuestScript GetShop id: " + id)
GetShopComplete = false
bool result = BRShop.Get(ApiUrl, ApiKey, id, self)
if !result
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to get shop.\n\n" + BugReportCopy)
2020-10-18 06:33:26 +00:00
GetShopComplete = true
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
GetShopComplete = true
endEvent
event OnGetShopFail(string error)
Debug.Trace("BRQuestScript OnGetShopFail error: " + error)
2020-10-19 00:56:10 +00:00
Debug.MessageBox("Failed to get shop.\n\n" + error + "\n\n" + BugReportCopy)
2020-10-18 06:33:26 +00:00
GetShopComplete = true
2020-10-19 05:13:18 +00:00
endEvent
function ListShops()
Debug.Trace("BRQuestScript ListShops")
ListShopsComplete = false
bool result = BRShop.List(ApiUrl, ApiKey, self)
if !result
Debug.MessageBox("Failed to list shops.\n\n" + BugReportCopy)
ListShopsComplete = true
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)
int index = 0
int selectedIndex = UILib.ShowList("Shop Merchandise", names, 0, 0)
ListShopsComplete = true
2020-10-20 05:26:49 +00:00
if ShopDetailMessage.Show() == 0
2020-11-14 07:25:02 +00:00
Debug.MessageBox(names[selectedIndex] + " (ID: " + ids[selectedIndex] + ")\n\n" + descriptions[selectedIndex])
ActiveShopId = ids[selectedIndex]
ActiveShopName = names[selectedIndex]
ActiveShopDescription = descriptions[selectedIndex]
ShopDetailMessage.SetName(names[selectedIndex])
2020-10-20 05:26:49 +00:00
bool result = BRInteriorRefList.ClearCell()
if !result
Debug.MessageBox("Failed to clear existing shop before loading in new shop.\n\n" + BugReportCopy)
endif
Debug.Trace("ClearCell result: " + result)
2020-11-21 06:37:41 +00:00
result = BRInteriorRefList.LoadByShopId(ApiUrl, ApiKey, ActiveShopId, ShopXMarker, PrivateChest, PublicChest, self)
2020-10-20 05:26:49 +00:00
if !result
Debug.MessageBox("Failed to load shop.\n\n" + BugReportCopy)
endif
endif
2020-10-19 05:13:18 +00:00
endEvent
event OnListShopsFail(string error)
Debug.Trace("BRQuestScript OnListShopsFail error: " + error)
Debug.MessageBox("Failed to list shops.\n\n" + error + "\n\n" + BugReportCopy)
ListShopsComplete = true
2020-10-18 06:33:26 +00:00
endEvent