46 lines
2.7 KiB
Lua
46 lines
2.7 KiB
Lua
-- Bounded native gameplay counters. Flush once a minute, never per loot item.
|
|
AuthDBExecute([[CREATE TABLE IF NOT EXISTS azerothai_outcomes (
|
|
guid INT UNSIGNED PRIMARY KEY,quests INT UNSIGNED NOT NULL DEFAULT 0,
|
|
abandoned INT UNSIGNED NOT NULL DEFAULT 0,loot_events INT UNSIGNED NOT NULL DEFAULT 0,
|
|
loot_items INT UNSIGNED NOT NULL DEFAULT 0,party_kills INT UNSIGNED NOT NULL DEFAULT 0,
|
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)]])
|
|
AuthDBExecute([[CREATE TABLE IF NOT EXISTS azerothai_currency (
|
|
guid INT UNSIGNED PRIMARY KEY,looted_copper BIGINT UNSIGNED NOT NULL DEFAULT 0)]])
|
|
local money={}
|
|
RegisterPlayerEvent(37,function(_,p,amount)
|
|
if p:IsPlayerbot() and amount and amount>0 then local id=p:GetGUIDLow();money[id]=(money[id] or 0)+amount end
|
|
end)
|
|
local pending={}
|
|
local function add(p,key,amount)
|
|
if not p:IsPlayerbot() then return end
|
|
local guid=p:GetGUIDLow()
|
|
local row=pending[guid] or {quests=0,abandoned=0,loot_events=0,loot_items=0,party_kills=0}
|
|
row[key]=row[key]+(amount or 1);pending[guid]=row
|
|
end
|
|
RegisterPlayerEvent(54,function(_,p) add(p,'quests') end)
|
|
RegisterPlayerEvent(38,function(_,p) add(p,'abandoned') end)
|
|
RegisterPlayerEvent(32,function(_,p,item,count) add(p,'loot_events');add(p,'loot_items',count) end)
|
|
RegisterPlayerEvent(7,function(_,p,killed)
|
|
if not p:IsPlayerbot() then return end
|
|
local g=p:GetGroup();if not g then return end
|
|
for _,other in pairs(g:GetMembers()) do
|
|
if other~=p and other:IsPlayerbot() and not other:IsDead() and other:IsInCombat()
|
|
and other:GetVictim() and other:GetVictim():GetGUID()==killed:GetGUID() and p:GetDistance(other)<=35 then
|
|
add(p,'party_kills');break
|
|
end
|
|
end
|
|
end)
|
|
local function flush()
|
|
for guid,r in pairs(pending) do
|
|
AuthDBExecute('INSERT INTO azerothai_outcomes(guid,quests,abandoned,loot_events,loot_items,party_kills) VALUES ('..guid..','..r.quests..','..r.abandoned..','..r.loot_events..','..r.loot_items..','..r.party_kills..') ON DUPLICATE KEY UPDATE quests=quests+VALUES(quests),abandoned=abandoned+VALUES(abandoned),loot_events=loot_events+VALUES(loot_events),loot_items=loot_items+VALUES(loot_items),party_kills=party_kills+VALUES(party_kills),updated_at=NOW()')
|
|
end
|
|
for guid,amount in pairs(money) do
|
|
AuthDBExecute('INSERT INTO azerothai_currency(guid,looted_copper) VALUES ('..guid..','..amount..') ON DUPLICATE KEY UPDATE looted_copper=looted_copper+VALUES(looted_copper)')
|
|
end
|
|
money={};pending={}
|
|
end
|
|
CreateLuaEvent(flush,60000,0)
|
|
-- Native profiler JSON is generated every five minutes; enabling it is an operator setting.
|
|
CreateLuaEvent(function()RunCommand('playerbots pmon tick')end,300000,0)
|
|
PrintInfo('[AzerothAI] Gameplay counters enabled; one-minute flush, five-minute profiler export')
|