From 57fd0bbf755640ab492634908ba4a4c5d8471ae6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Koris" Date: Sun, 22 Dec 2019 23:04:17 -0700 Subject: [PATCH 1/3] PR: Added the C++ backbone for updating Digging Zones --- src/map/lua/luautils.cpp | 17 +++++++++++++++++ src/map/lua/luautils.h | 1 + src/map/time_server.cpp | 7 +++++++ src/map/vana_time.h | 1 + 4 files changed, 26 insertions(+) diff --git a/src/map/lua/luautils.cpp b/src/map/lua/luautils.cpp index d80e7478423..1fb6bb0685b 100644 --- a/src/map/lua/luautils.cpp +++ b/src/map/lua/luautils.cpp @@ -4428,6 +4428,23 @@ namespace luautils return canDig; } + int32 UpdateDigZones() + { + lua_prepscript("scripts/globals/chocobo_digging.lua"); + + if (prepFile(File, "updateDigZones")) + return false; + + if (lua_pcall(LuaHandle, 0, 0, 0)) + { + ShowError("luautils::UpdateDigZones: %s\n", lua_tostring(LuaHandle, -1)); + lua_pop(LuaHandle, 1); + return false; + } + + return 0; + } + /************************************************************************ * Loads a Lua function with a fallback hierarchy * * * diff --git a/src/map/lua/luautils.h b/src/map/lua/luautils.h index 23f89e59730..ab267053214 100644 --- a/src/map/lua/luautils.h +++ b/src/map/lua/luautils.h @@ -281,6 +281,7 @@ namespace luautils int32 OnPlayerLevelDown(CCharEntity* PChar); bool OnChocoboDig(CCharEntity* PChar, bool pre); // chocobo digging, pre = check + int32 UpdateDigZones(); // updating chocobo digging zones with items bool LoadEventScript(CCharEntity* PChar, const char* functionName); // Utility method: checks for and loads a lua function for events uint16 GetDespoilDebuff(uint16 itemId); // Ask the database for an effectId based on Item despoiled (returns 0 if not in db) diff --git a/src/map/time_server.cpp b/src/map/time_server.cpp index 92ee07acb07..64cc4c507db 100644 --- a/src/map/time_server.cpp +++ b/src/map/time_server.cpp @@ -76,9 +76,16 @@ int32 time_server(time_point tick,CTaskMgr::CTask* PTask) CVanaTime::getInstance()->lastVHourlyUpdate = tick; } + } + // every irl minute + if (tick > (CVanaTime::getInstance()->lastMinute + 60s)) + { + luautils::UpdateDigZones(); + CVanaTime::getInstance()->lastMinute = tick; } + //Midnight if (CVanaTime::getInstance()->getSysHour() == 0 && CVanaTime::getInstance()->getSysMinute() == 0) { diff --git a/src/map/vana_time.h b/src/map/vana_time.h index f8b9fa33536..caed849f3aa 100644 --- a/src/map/vana_time.h +++ b/src/map/vana_time.h @@ -93,6 +93,7 @@ class CVanaTime time_point lastVDailyUpdate; time_point lastConquestTally; time_point lastMidnight; + time_point lastMinute; private: From 7a354ebb5ee6b92624728fd81ee1ba104120ac05 Mon Sep 17 00:00:00 2001 From: "Daniel R. Koris" Date: Fri, 20 Dec 2019 09:20:59 -0700 Subject: [PATCH 2/3] PR: Updated the Chocobo Digging script Added the lua function bound to the call for luautils::UpdateDigZones() Tweaked zoneItemsDug to have a higher level --- scripts/globals/chocobo_digging.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/globals/chocobo_digging.lua b/scripts/globals/chocobo_digging.lua index 03a7b96f398..ba5072934fd 100644 --- a/scripts/globals/chocobo_digging.lua +++ b/scripts/globals/chocobo_digging.lua @@ -842,10 +842,11 @@ local function canDig(player) updatePlayerDigCount(player, 0) digCount = 0 end - -- neither player nor zone have reached their dig limit - if (digCount < 100 and zoneItemsDug < 20) or DIG_FATIGUE == 0 then + -- https://ffxiclopedia.fandom.com/wiki/Chocobo_Digging_Guide + -- states 20-50... lets just go with 50? + if (digCount < 100 and zoneItemsDug < 50) or DIG_FATIGUE == 0 then -- pesky delays if (zoneInTime + areaDigDelay) <= currentTime and (lastDigTime + digDelay) <= currentTime then return true @@ -986,7 +987,7 @@ dsp.chocoboDig.start = function(player, precheck) end updatePlayerDigCount(player, 1) - -- updateZoneDigCount(zoneId, 1) -- TODO: implement mechanic for resetting zone dig count. until then, leave this commented out + updateZoneDigCount(zoneId, 1) -- TODO: learn abilities from chocobo raising end @@ -994,4 +995,23 @@ dsp.chocoboDig.start = function(player, precheck) return true end +end + +-- https://ffxiclopedia.fandom.com/wiki/Chocobo_Digging_Guide +-- 2 - 8 items depending on MoonPhase +function updateDigZones() + for zoneId, _ in pairs(digInfo) do + local serverVar = '[DIG]ZONE' .. zoneId .. '_ITEMS' + local zoneItemsDug = GetServerVariable(serverVar) + + if zoneItemsDug ~= 0 then + local newItems = 2 + math.floor((6*(VanadielMoonPhase()/100))) + + zoneItemsDug = zoneItemsDug - newItems + if zoneItemsDug < 0 then + zoneItemsDug = 0 + end + SetServerVariable(serverVar, zoneItemsDug) + end + end end \ No newline at end of file From c5af5061930ba11b38499db017fcb148176fc941 Mon Sep 17 00:00:00 2001 From: "Daniel R. Koris" Date: Mon, 23 Dec 2019 20:44:12 -0700 Subject: [PATCH 3/3] PR: Fixed bug where zoning would reset the Fatigue, and it is not supposed to --- scripts/globals/chocobo_digging.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/globals/chocobo_digging.lua b/scripts/globals/chocobo_digging.lua index ba5072934fd..bcda302bda6 100644 --- a/scripts/globals/chocobo_digging.lua +++ b/scripts/globals/chocobo_digging.lua @@ -808,7 +808,7 @@ local function updatePlayerDigCount(player, increment) player:setCharVar('[DIG]DigCount', player:getCharVar('[DIG]DigCount') + increment) end - player:setLocalVar('[DIG]LastDigTime', os.time()) + player:setCharVar('[DIG]LastDigTime', os.time()) end @@ -825,7 +825,7 @@ end local function canDig(player) local digCount = player:getCharVar('[DIG]DigCount') - local lastDigTime = player:getLocalVar('[DIG]LastDigTime') + local lastDigTime = player:getCharVar('[DIG]LastDigTime') local zoneItemsDug = GetServerVariable('[DIG]ZONE'..player:getZoneID()..'_ITEMS') local zoneInTime = player:getLocalVar('ZoneInTime') local currentTime = os.time()