Merch chest activator, fixup buy and sell

Moved public chest to dummy cell and created activator with chest model to interact with in the shop cell instead. Fixed issues with buying and selling to shops.
This commit is contained in:
Tyler Hallada 2021-02-09 23:54:24 -05:00
parent f1cdd9baf5
commit b33fa4ec77
5 changed files with 41 additions and 24 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
scriptname BRMerchChestActivatorScript extends ObjectReference
Keyword property BRLinkMerchChest auto
Keyword property BRLinkPublicMerchChest auto
Actor property PlayerRef auto
Quest property BRQuest auto
event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef
Debug.Trace("BRMerchChestActivatorScript activator was activated")
BRQuestScript BRScript = BRQuest as BRQuestScript
if BRScript.ActiveShopId == BRScript.ShopId
ObjectReference privateChest = GetLinkedRef(BRLinkMerchChest)
privateChest.RegisterForMenu("ContainerMenu")
privateChest.Activate(akActionRef)
else
ObjectReference publicChest = GetLinkedRef(BRLinkPublicMerchChest)
publicChest.RegisterForMenu("ContainerMenu")
publicChest.Activate(akActionRef)
endif
endif
endEvent

View File

@ -1,13 +1,6 @@
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
Quest property BRQuest auto
MiscObject property Gold001 auto
@ -32,6 +25,19 @@ event OnMenuClose(string menuName)
debug.Trace("BRMerchChestScript barter menu closed, stop listending to add/remove events")
AddInventoryEventFilter(BREmptyFormList)
UnregisterForMenu("BarterMenu")
elseif menuName == "ContainerMenu"
debug.Trace("BRMerchChestScript container menu closed")
BRQuestScript BRScript = BRQuest as BRQuestScript
if BRScript.ActiveShopId == BRScript.ShopId
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, shopCell, BRScript.ActiveShopShelves, self)
if !result
Debug.MessageBox("Failed to save shop merchandise.\n\n" + BRScript.BugReportCopy)
endif
endif
UnregisterForMenu("ContainerMenu")
endif
endEvent
@ -39,6 +45,8 @@ event OnMenuOpen(string menuName)
if menuName == "BarterMenu"
debug.Trace("BRMerchChestScript barter menu opened, start listening to add/remove events")
RemoveAllInventoryEventFilters()
elseif menuName == "ContainerMenu"
debug.Trace("BRMerchChestScript container menu opened")
endif
endEvent

View File

@ -4,13 +4,13 @@ scriptname BRMerchandiseList
; bool function Toggle(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf) global native
bool function NextPage(ObjectReference merchantShelf) global native
bool function PrevPage(ObjectReference merchantShelf) global native
bool function Load(string apiUrl, string apiKey, int shop_id, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference merchantChest) global native
bool function Load(string apiUrl, string apiKey, int shop_id, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference privateMerchantChest) global native
; bool function Refresh(string apiUrl, string apiKey, int shop_id, ObjectReference merchantShelf) 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, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference merchantChest) global native
bool function Create(string apiUrl, string apiKey, int shopId, Cell shopCell, ObjectReference[] merchantShelves, ObjectReference privateMerchandiseChest) global native
int function GetQuantity(ObjectReference activator) global native
int function GetPrice(ObjectReference activator) global native

View File

@ -1,6 +1,5 @@
scriptname BRPublicMerchChestScript extends ObjectReference
Keyword property BRLinkMerchShelf auto
Keyword property BRLinkMerchChest auto
Actor property PlayerRef auto
Quest property BRQuest auto
@ -16,16 +15,6 @@ endEvent
event OnMenuClose(string menuName)
if menuName == "ContainerMenu"
Debug.Trace("BRPublicMerchChestScript container menu closed")
BRQuestScript BRScript = BRQuest as BRQuestScript
if BRScript.ActiveShopId == BRScript.ShopId
; TODO: the assumption that player is in shop cell may be incorrect
Cell shopCell = PlayerRef.GetParentCell()
bool result = BRMerchandiseList.Create(BRScript.ApiUrl, BRScript.ApiKey, BRScript.ShopId, shopCell, BRScript.ActiveShopShelves, self)
if !result
Debug.MessageBox("Failed to save shop merchandise.\n\n" + BRScript.BugReportCopy)
endif
endif
UnregisterForMenu("ContainerMenu")
AddInventoryEventFilter(BREmptyFormList)
endif
@ -44,8 +33,7 @@ endEvent
event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef
Debug.Trace("BRPublicMerchChestScript container was opened")
RegisterForMenu("ContainerMenu")
Debug.Trace("BRPublicMerchChestScript container was activated")
endif
endEvent
@ -54,8 +42,7 @@ Event OnItemAdded(Form baseItem, int itemCount, ObjectReference itemRef, ObjectR
BRQuestScript BRScript = BRQuest as BRQuestScript
Form selectedMerchandiseRepl = BRScript.SelectedMerchandise.GetBaseObject()
selectedMerchandiseRepl.SetName(baseItem.GetName())
ObjectReference shelf = self.GetLinkedRef(BRLinkMerchShelf)
ObjectReference privateChest = shelf.GetLinkedRef(BRLinkMerchChest)
ObjectReference privateChest = GetLinkedRef(BRLinkMerchChest)
int price = BRMerchandiseList.GetSellPrice(baseItem)
if BRSellMerchandise.Show(itemCount, price * itemCount, price) == 0
debug.Trace("BRPublicMerchChestScript creating sell transaction")