правки для магазина

This commit is contained in:
2026-07-19 19:13:50 +04:00
parent 58dcb622f3
commit 737d7c756d
3 changed files with 109 additions and 57 deletions
+2 -2
View File
@@ -144,7 +144,7 @@ function SHOP_UI.MainFrame_Create()
shopFrame.Title:SetFont("Fonts\\FRIZQT__.TTF", 14)
shopFrame.Title:SetShadowOffset(1, -1)
shopFrame.Title:SetPoint("TOP", shopFrame, "TOP", 0, -3)
shopFrame.Title:SetText("|cffedd100Shop|r")
shopFrame.Title:SetText("|cffedd100Лавка Лунной Жрицы|r")
-- create navigation button placeholders, pass parent as arg
SHOP_UI.NavButtons_Create(shopFrame)
@@ -1193,7 +1193,7 @@ local function ModifyGameMenuFrame()
storeButton.Text:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
storeButton.Text:SetShadowOffset(1, -1)
storeButton.Text:SetPoint("CENTER", storeButton, "CENTER", 0, 1)
storeButton.Text:SetText("|cffdbe005Store");
storeButton.Text:SetText("|cffdbe005Лавка Лунной Жрицы");
-- on click open the shop frame and hide the escape menu
storeButton:SetScript("OnClick", function()
+58 -53
View File
@@ -7,7 +7,7 @@ local CONFIG = {
mailSenderGUID = 1, -- GUID of the character shown as sender of purchase mails
strings = {
-- Currency name is appended to the end of this string
insufficientFunds = "You don't have enough",
insufficientFunds = "Недостаточно средств на балансе",
-- Type is appended, ie. title, mount, pet etc.
alreadyKnown = "You already have this",
tooHighLevel = "Your level is too high",
@@ -22,11 +22,24 @@ local CONFIG = {
local AIO = AIO or require("AIO") and require("Store_DataStruct")
local CURRENCY_TYPES = {
[1] = "GOLD",
[2] = "ITEM_TOKEN",
[3] = "SERVER_HANDLED"
}
local purchaseReferenceSequence = 0
local function GetAccountBalance(player)
local query = AuthDBQuery(
"SELECT CAST(`balance` AS DOUBLE) FROM `account_balances` WHERE `account_id` = " ..
player:GetAccountId() .. " LIMIT 1;"
)
if not query then
return 0
end
return query:GetDouble(0)
end
local SHOP_UI = {
serviceHandlers = {
[1] = "ItemHandler", -- Okay
@@ -55,17 +68,8 @@ function StoreHandler.UpdateCurrencies(player)
local val = 0
local currencyTypeText = CURRENCY_TYPES[currency[KEYS.currency.currencyType]]
-- Handle the different currency types
if(currencyTypeText == "GOLD") then
val = math.floor(player:GetCoinage() / 10000)
end
if(currencyTypeText == "ITEM_TOKEN") then
val = player:GetItemCount(currency[KEYS.currency.data])
end
if(currencyTypeText == "SERVER_HANDLED") then
-- Add your custom handling here for retreiving your server handled currencies
val = GetAccountBalance(player)
end
-- If value is larger than 10k then truncate to make sure it fits within the shop frame
@@ -73,7 +77,9 @@ function StoreHandler.UpdateCurrencies(player)
val = "9999+"
end
table.insert(tmp, val)
-- Preserve the database currency id. A positional array silently breaks as
-- soon as ids have gaps or are reordered by MySQL.
tmp[currencyId] = val
end
AIO.Handle(player, "STORE_CLIENT", "UpdateCurrencies", tmp)
end
@@ -106,39 +112,38 @@ function StoreHandler.Purchase(player, serviceId)
end
-- Helper functions
function SHOP_UI.DeductCurrency(player, currencyId, amount)
function SHOP_UI.DeductCurrency(player, currencyId, amount, serviceId)
local currency = GetCurrencyData()
local currencyType = currency[currencyId][KEYS.currency.currencyType]
local currencyName = currency[currencyId][KEYS.currency.name]
local currencyData = currency[currencyId][KEYS.currency.data]
-- Gold handling
if(CURRENCY_TYPES[currencyType] == "GOLD") then
if(player:GetCoinage() < amount * 10000) then
player:SendAreaTriggerMessage("|cFFFF0000"..CONFIG.strings.insufficientFunds.." "..currencyName.."|r")
player:PlayDirectSound(GetSoundEffect("notEnoughMoney", player:GetRace(), player:GetGender()), player)
return false
end
player:SetCoinage(player:GetCoinage() - (amount * 10000))
end
-- Token handling
if(CURRENCY_TYPES[currencyType] == "ITEM_TOKEN") then
if not(player:HasItem(currencyData, amount)) then
player:SendAreaTriggerMessage("|cFFFF0000"..CONFIG.strings.insufficientFunds.." "..currencyName.."|r")
player:PlayDirectSound(GetSoundEffect("notEnoughMoney", player:GetRace(), player:GetGender()), player)
return false
end
player:RemoveItem(currencyData, amount)
end
-- Other special handlingm you have to add your own integration here.
if(CURRENCY_TYPES[currencyType] == "SERVER_HANDLED") then
if not currency[currencyId] then
return false
end
local currencyType = currency[currencyId][KEYS.currency.currencyType]
if CURRENCY_TYPES[currencyType] ~= "SERVER_HANDLED" then
return false
end
purchaseReferenceSequence = purchaseReferenceSequence + 1
local reference = string.format(
"game-store:%u:%u:%u:%u:%u",
player:GetAccountId(),
player:GetGUIDLow(),
serviceId or 0,
os.time(),
purchaseReferenceSequence
)
local result = AuthDBQuery(
"SELECT `store_deduct_balance`(" .. player:GetAccountId() .. ", " .. amount .. ", '" .. reference .. "', " ..
player:GetGUIDLow() .. ", " .. (serviceId or 0) .. ") AS `balance_after`;"
)
local balanceAfter = result and result:GetDouble(0) or -1
if balanceAfter < 0 then
player:SendAreaTriggerMessage("|cFFFF0000" .. CONFIG.strings.insufficientFunds .. "|r")
player:PlayDirectSound(GetSoundEffect("notEnoughMoney", player:GetRace(), player:GetGender()), player)
return false
end
return true
end
@@ -152,7 +157,7 @@ function SHOP_UI.ItemHandler(player, data)
local currency, amount = data[KEYS.service.currency], data[KEYS.service.price] - data[KEYS.service.discount]
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -178,7 +183,7 @@ function SHOP_UI.GoldHandler(player, data)
local currency, amount = data[KEYS.service.currency], data[KEYS.service.price] - data[KEYS.service.discount]
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -212,7 +217,7 @@ function SHOP_UI.MountHandler(player, data)
end
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -250,7 +255,7 @@ function SHOP_UI.PetHandler(player, data)
end
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -271,7 +276,7 @@ function SHOP_UI.BuffHandler(player, data)
local currency, amount = data[KEYS.service.currency], data[KEYS.service.price] - data[KEYS.service.discount]
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -292,7 +297,7 @@ function SHOP_UI.ServiceHandler(player, data)
local currency, amount = data[KEYS.service.currency], data[KEYS.service.price] - data[KEYS.service.discount]
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -319,7 +324,7 @@ function SHOP_UI.LevelHandler(player, data)
end
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -354,7 +359,7 @@ function SHOP_UI.TitleHandler(player, data)
end
-- Deduct currency
local deducted = SHOP_UI.DeductCurrency(player, currency, amount)
local deducted = SHOP_UI.DeductCurrency(player, currency, amount, data.ID)
-- If currency was not deducted from the player, abort and send message
if not(deducted) then
@@ -372,4 +377,4 @@ function SHOP_UI.UnusedHandler(player, data)
-- Since this is unused, always return false until the function is in use.
return false
end
end