Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Progress on Chocobo Digging #6338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 25 additions & 5 deletions scripts/globals/chocobo_digging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -986,12 +987,31 @@ 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

calculateSkillUp(player)

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
17 changes: 17 additions & 0 deletions src/map/lua/luautils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down
1 change: 1 addition & 0 deletions src/map/lua/luautils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/map/time_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/map/vana_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class CVanaTime
time_point lastVDailyUpdate;
time_point lastConquestTally;
time_point lastMidnight;
time_point lastMinute;

private:

Expand Down