Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions modules/game_shop/game_shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ function selectOffer(self)

self:setChecked(true)
selectedOffer = self

if not selectedOffer.categoryId then
selectedOffer.categoryId = selected:getId()
end

updateDescription(self)
end
Expand Down Expand Up @@ -457,12 +461,17 @@ function updateDescription(self)
widget = g_ui.createWidget("OfferDescriptionLabel", descriptionPanel)
end

local categoryToUse = self.data.originalCategory or self.categoryId
if self.categoryId == searchResultCategoryId and not self.data.originalCategory then
categoryToUse = self.data.parent
end

g_game.getProtocolGame():sendExtendedOpcode(
GAME_SHOP_CODE,
json.encode({
action = "getDescription",
data = {
category = self.categoryId,
category = categoryToUse,
name = self.data.name
}
})
Expand Down Expand Up @@ -521,7 +530,7 @@ function updateDescription(self)
image:show()
image:setImageSource("/game_shop/images/" .. self.data.id)
elseif type(self.data.id) == "number" then
local categoryId = self.offerCategoryId
local categoryId = self.offerCategoryId or self.data.offerCategoryId
if categoryId == CATEGORY_ITEM then
item:show()
item:setItemId(self.data.id)
Expand All @@ -537,7 +546,17 @@ function updateDescription(self)
end

function onGameShopFetchDescription(data)
if not selectedOffer or selectedOffer.data.name ~= data.name then
if not selectedOffer then
return
end

if selectedOffer.data.name ~= data.name then
return
end

if selectedOffer.categoryId == searchResultCategoryId and
data.category and selectedOffer.data.originalCategory and
data.category ~= selectedOffer.data.originalCategory then
return
end

Expand Down Expand Up @@ -621,7 +640,8 @@ function buyConfirmed()
price = msgWindow.price,
name = selectedOffer.data.name,
id = selectedOffer.data.id,
parent = selectedOffer.data.parent
parent = selectedOffer.data.parent,
originalCategory = selectedOffer.data.originalCategory
}
}
)
Expand Down Expand Up @@ -833,9 +853,14 @@ function onSearch()
local searchTerm = text:lower()

for categoryId, offerData in pairs(offers) do
for _, offer in pairs(offerData) do
if string.find(offer.name:lower(), searchTerm) then
table.insert(results, offer)
if categoryId ~= searchResultCategoryId then
for _, offer in pairs(offerData) do
if string.find(offer.name:lower(), searchTerm) then
local offerCopy = table.copy(offer)
offerCopy.originalCategory = categoryId
offerCopy.offerCategoryId = offer.categoryId
table.insert(results, offerCopy)
end
end
end
end
Expand Down
59 changes: 48 additions & 11 deletions modules/game_shop/serverSIDE/data/scripts/game_shop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function gameShopInitialize()
addItem("Premium Time", "180 Days of Premium Time", "180_days", 1500, false, 180, PREMIUM_DESCRIPTION)
addItem("Premium Time", "360 Days of Premium Time", "360_days", 3000, false, 360, PREMIUM_DESCRIPTION)

addCategory(nil, "Rookgaard Items", 12, CATEGORY_ITEM)
addItem("Rookgaard Items", "Health Potion", 7618, 6, false, 5, HEALTH_POTION_DESCRIPTION)
addItem("Rookgaard Items", "Mana Potion", 7620, 6, false, 5, MANA_POTION_DESCRIPTION)

addCategory(nil, "Consumables", 6, CATEGORY_NONE)
addCategory("Consumables", "Blessings", 8, CATEGORY_BLESSING)
addItem("Blessings", "All regular Blessings", "All_regular_Blessings", 130, false, -1, BLESSING_DESCRIPTION)
Expand Down Expand Up @@ -274,8 +278,8 @@ function gameShopInitialize()

addCategory(nil, "Extras", 9, CATEGORY_NONE)
addCategory("Extras", "Extra Services", 7, CATEGORY_EXTRAS)
addItem("Extra Services", "Name Change", "Name_Change", 250, false, 1, "Tired of your current character name? Purchase a new one!\n\n\n- only usable by purchasing character\n- relog required after purchase to finalise the name change")
addItem("Extra Services", "Sex Change", "Sex_Change", 120, false, 1, "Turns your female character into a male one - or vice versa.\n\n\n- only usable by purchasing character\n- activated at purchase\n- you will keep all outfits you have purchased or earned in quest")
addItem("Extra Services", "Name Change", "Name_Change", 250, false, 1, "Tired of your current character name? Purchase a new one!\n\n- only usable by purchasing character\n- relog required after purchase to finalise the name change")
addItem("Extra Services", "Sex Change", "Sex_Change", 120, false, 1, "Turns your female character into a male one - or vice versa.\n\n- only usable by purchasing character\n- activated at purchase\n- you will keep all outfits you have purchased or earned in quest")

addCategory("Extras", "Useful Things", 24, CATEGORY_EXTRAS)
addItem("Useful Things", "Temple Teleport", "Temple_Teleport", 15, false, 1, "Teleports you instantly to your home temple.\n\n- only usable by purchasing character\n- use it to teleport you to your home temple\n- cannot be used while having a battle sign or a protection zone block")
Expand Down Expand Up @@ -665,20 +669,53 @@ function gameShopFetch(player)
gameShopUpdatePoints(player)
gameShopUpdateHistory(player)

player:sendExtendedOpcode(ExtendedOPCodes.CODE_GAMESHOP, json.encode({action = "fetchBase", data = {categories = GAME_SHOP.categories, url = DONATION_URL}}))
local isRookgaard = player:getVocation():getId() == 0
local filteredCategories = {}

for _, category in ipairs(GAME_SHOP.categories) do
if isRookgaard then
if category.title == "Rookgaard Items" or category.title == "Premium Time" then
table.insert(filteredCategories, category)
end
else
if category.title ~= "Rookgaard Items" then
table.insert(filteredCategories, category)
end
end
end

player:sendExtendedOpcode(ExtendedOPCodes.CODE_GAMESHOP, json.encode({action = "fetchBase", data = {categories = filteredCategories, url = DONATION_URL}}))

for category, offersTable in pairs(GAME_SHOP.offers) do
local offersWithoutDesc = {}
for _, offer in ipairs(offersTable) do
local offerCopy = {}
for k, v in pairs(offer) do
if k ~= "description" then
offerCopy[k] = v
if isRookgaard then
if category == "Rookgaard Items" or category == "Premium Time" then
local offersWithoutDesc = {}
for _, offer in ipairs(offersTable) do
local offerCopy = {}
for k, v in pairs(offer) do
if k ~= "description" then
offerCopy[k] = v
end
end
table.insert(offersWithoutDesc, offerCopy)
end
player:sendExtendedOpcode(ExtendedOPCodes.CODE_GAMESHOP, json.encode({action = "fetchOffers", data = {category = category, offers = offersWithoutDesc}}))
end
else
if category ~= "Rookgaard Items" then
local offersWithoutDesc = {}
for _, offer in ipairs(offersTable) do
local offerCopy = {}
for k, v in pairs(offer) do
if k ~= "description" then
offerCopy[k] = v
end
end
table.insert(offersWithoutDesc, offerCopy)
end
player:sendExtendedOpcode(ExtendedOPCodes.CODE_GAMESHOP, json.encode({action = "fetchOffers", data = {category = category, offers = offersWithoutDesc}}))
end
table.insert(offersWithoutDesc, offerCopy)
end
player:sendExtendedOpcode(ExtendedOPCodes.CODE_GAMESHOP, json.encode({action = "fetchOffers", data = {category = category, offers = offersWithoutDesc}}))
end
end

Expand Down
Loading