UiMenuShop
The UiMenuShop class manages the in-game shop menu. It renders purchasable items organized by tabs (Weapons, Armor, Hats, Pets, Utility), handles item purchases and equipment via RPCs, manages social media reward unlocks (Twitter, Facebook, YouTube), and displays in-shop advertisements.
UiMenuShop private
Extends UiComponent.
Properties
| Name | Type | Description |
|---|---|---|
ui | Ui | Current Ui instance. Inherited from UiComponent. |
componentElem | HTMLElement | The root #hud-menu-shop DOM element. Inherited from UiComponent. |
closeElem | HTMLElement | The .hud-menu-close button. |
gridElem | HTMLElement | The .hud-shop-grid container for shop item elements. |
adMedrecElem | HTMLElement | The .ad-unit-medrec-shop ad container. |
adLeaderboardElem | HTMLElement | The .ad-unit-leaderboard-shop ad container. |
tabElems | HTMLElement[] | Array of .hud-shop-tabs-link tab elements. |
shopItems | Record<string, UiShopItem \| UiShopHatItem \| UiShopPetItem> | Map of item IDs to their shop item component instances. |
medrecId | number | Incrementing ID for ad medrec container uniqueness. Starts at 1000. |
leaderboardId | number | Incrementing ID for ad leaderboard container uniqueness. Starts at 1000. |
activeType | string | The currently selected tab type. Defaults to 'Weapon'. |
twitterFollowed | boolean | Whether the user has followed on Twitter. Persisted via localStorage. |
twitterShared | boolean | Whether the user has shared on Twitter. Persisted via localStorage. |
facebookLiked | boolean | Whether the user has liked on Facebook. Persisted via localStorage. |
facebookShared | boolean | Whether the user has shared on Facebook. Persisted via localStorage. |
youTubeSubscribed | boolean | Whether the user has subscribed on YouTube. Persisted via localStorage. |
Methods
constructor()
function constructor(ui: Ui): voidInitializes the shop menu with tabs, creates UiShopItem, UiShopHatItem, or UiShopPetItem instances for each purchasable item in the schema, binds event listeners for purchase/equip/social actions, and registers for itemConsumed, wavePaused, shouldEquipItem events and the enterWorld network handler. Restores social link states from localStorage.
show()
function show(): voidOverrides UiComponent.show(). Creates fresh ad containers with unique IDs and initializes NitroAds units.
hide()
function hide(): voidOverrides UiComponent.hide(). Clears the ad container HTML.
getTwitterFollowed()
function getTwitterFollowed(): booleanReturns the Twitter follow state.
getTwitterShared()
function getTwitterShared(): booleanReturns the Twitter share state.
getFacebookLiked()
function getFacebookLiked(): booleanReturns the Facebook like state.
getFacebookShared()
function getFacebookShared(): booleanReturns the Facebook share state.
getYouTubeSubscribed()
function getYouTubeSubscribed(): booleanReturns the YouTube subscribe state.
update()
function update(): voidShows/hides shop items based on the currently active tab type.
setTab()
function setTab(type: string): voidSwitches the active tab, updates is-active classes on tab elements, and calls update().
checkSocialLinks()
function checkSocialLinks(): voidChecks social link completion states and auto-purchases reward items via BuyItem RPCs: HatHorns (requires Twitter follow + Facebook like), PetCARL (requires Twitter share + Facebook share), PetMiner (requires YouTube subscribe).
onTabChange()
function onTabChange(tabElem: HTMLElement): (event: MouseEvent) => voidReturns a click handler that reads data-type and calls setTab().
onItemConsumed()
function onItemConsumed(itemName: string, itemTier: number): voidHandles the itemConsumed event. Sets a 2000ms cooldown on both HealthPotion and PetHealthPotion shop items when either is consumed.
onWavePaused()
function onWavePaused(): voidHandles the wavePaused event. Sets the Pause item's cooldown from its schema purchaseCooldown.
onEnterWorld()
function onEnterWorld(data: { allowed: boolean }): voidHandles the enter world response. If allowed, calls checkSocialLinks().
onShopItemPurchase()
function onShopItemPurchase(itemId: string, itemTier: number): voidSends a BuyItem RPC for the given item.
onShopEquipItem()
function onShopEquipItem(itemId: string, itemTier: number): voidSends an EquipItem RPC and emits the itemEquippedOrUsed event on the Ui instance.
onTwitterFollow() / onTwitterShare() / onFacebookLike() / onFacebookShare() / onYouTubeSubscribe()
function onTwitterFollow(itemId: string): void
function onTwitterShare(itemId: string): void
function onFacebookLike(itemId: string): void
function onFacebookShare(itemId: string): void
function onYouTubeSubscribe(itemId: string): voidEach sets the corresponding social flag to true, persists it to localStorage, and calls checkSocialLinks().