Skip to content

Commit

Permalink
Add SP promotion quest and hoofprint logic (#449)
Browse files Browse the repository at this point in the history
* Add SP promotion quest and hoofprint logic

* Remove unnecessary 0s

* Remove print

* Add text_table fix

* Check if hoofprint is visible before removing

* Improve logic for adding hoofprints
  • Loading branch information
InoUno authored and KnowOne134 committed Jan 28, 2025
1 parent 1adc896 commit 56e9d31
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 2 deletions.
182 changes: 182 additions & 0 deletions scripts/globals/dark_rider.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
require('scripts/globals/zone')
require('scripts/globals/keyitems')
require('scripts/globals/npc_util')

darkRider = {}
darkRider.MAX_HOOFPRINTS_PER_DAY = 2

local hoofprintIds = {
[dsp.zone.WAJAOM_WOODLANDS] = {
16986599,
16986600,
16986601,
},
[dsp.zone.BHAFLAU_THICKETS] = {
16990560,
16990561,
16990562,
},
[dsp.zone.MOUNT_ZHAYOLM] = {
17027510,
17027511,
17027512,
},
[dsp.zone.CAEDARVA_MIRE] = {
17101242,
17101243,
17101244,
},
}

local hoofprintPositions = {
[dsp.zone.WAJAOM_WOODLANDS] = {
{ 400, -24, 2 }, -- K-9
{ 345, -18, -41 }, -- J-9 E edge
{ 221, -18, -63 }, -- J-9 W edge
{ 217, -17.5, -140 }, -- J-10
{ 185, -20.25, -200 }, -- I-10 E edge
{ 121, -16, -241 }, -- I-10 S edge
{ 0, -18, -265 }, -- H-10 S edge
{ -80, -18, -546 }, -- H-12
{ -175, -20.25, -562 }, -- G-12
{ -378, -9, -580 }, -- F-12 S edge
{ -625, -19, -345 }, -- D-11
{ -642, -16, -160 }, -- D-10
{ -532, -8.5, -64 }, -- E-9
{ -500, -18, 176 }, -- E-8
{ -400, -24, 281 }, -- F-7
{ -400, -24, 281 }, -- F-7
{ -237, -24, 403 }, -- G-6 NE
{ -258, -25.5, 497 }, -- G-6 N
{ -302, -26, 580 }, -- F-5 SE corner
{ -360, -32, 680 }, -- F-5 behind tower
{ 105, -26, 320 }, -- I-7
},
[dsp.zone.BHAFLAU_THICKETS] = {
{ 447, -18, 266 }, -- I-8
{ 425, -20.25, 239 }, -- I-9
{ 298, -8.5, 211 }, -- H-8 center of open area
{ 338, -10, 255 }, -- H-8 E tunnel
{ 160, -16, 319 }, -- G-8
{ 20, -18.675, 240 }, -- F-8
{ 283, -23.75, 431 }, -- H-7 center
{ 240, -32, 480 }, -- H-7 NW
{ 185, -34, 514 }, -- G-7 top NE corner
{ 61, -34, 545 }, -- G-6 SW corner
{ 336, -18, 380 }, -- H-7 SE corner
{ 379, -17, 380 }, -- I-7 in tunnel
},
[dsp.zone.MOUNT_ZHAYOLM] = {
{ -401, -14.5, 374 }, -- D/E-6
{ -458, -13, 357 }, -- D-6
{ -350, -14, 330 }, -- E-6 near manhole cover
{ -401, -14.5, 372 }, -- E-6 tip of protruding wall
{ 161, -14, -206 }, -- H-9 (near the Pugils to the south)
{ 278, -18, -294 }, -- I-10 (on the mound with the Eruca)
{ 598, -14, -4 }, -- K-8
{ 762, -14.5, -55 }, -- L-8
},
[dsp.zone.CAEDARVA_MIRE] = {
{ -600, 4.5, -100 }, -- G-9 (2nd map)
{ 212, 0, -533 }, -- I-9
{ 280, -16, -357 }, -- J-8
{ 300, -15, -354 }, -- J-8 in north pool
{ 400, -7.5, -260 }, -- J-8 N at imp camp
{ 415, -10, -180 }, -- J-7
{ 160, -8, -320 }, -- I-8
},
}


local hoofprintZones = {}
for zoneId, _ in pairs(hoofprintPositions) do
hoofprintZones[#hoofprintZones+1] = zoneId
end

darkRider.zone = {}

-- Adds hoofprints if the current zone is the one picked for that day
function darkRider.zone.addHoofprints(zone)

-- We need a random number that's the same across servers,
-- so we add a bunch of vanadiel time values, which will be the same across servers, but should
-- result in a seemingly "random" area and positions each time when combined with the modulo operator.
local fakeRandomNum = VanadielMoonPhase() + VanadielDayElement() + VanadielDayOfTheMonth() + VanadielDayOfTheYear()

local areaIndex = math.fmod(fakeRandomNum, #hoofprintZones) + 1
local pickedZoneId = hoofprintZones[areaIndex]

if pickedZoneId ~= zone:getID() then
return
end

local possiblePositions = utils.shuffle(hoofprintPositions[zone:getID()])
local possibleHoofprintIds = hoofprintIds[zone:getID()]

local daysSinceEpoch = VanadielDaySinceEpoch()
local currentHoofprintCount = zone:getLocalVar("HoofprintCount")

local hoofprintsToAdd = math.fmod(fakeRandomNum, darkRider.MAX_HOOFPRINTS_PER_DAY) + 1

for i = 1, #possibleHoofprintIds do
if hoofprintsToAdd <= 0 then
break
end

local hoofprint = GetNPCByID(possibleHoofprintIds[i])
if hoofprint ~= nil and hoofprint:getStatus() ~= dsp.status.NORMAL then
hoofprint:setPos(possiblePositions[i])
hoofprint:setStatus(dsp.status.NORMAL)
hoofprint:untargetable(false)
hoofprint:setLocalVar("DaysSinceEpoch", daysSinceEpoch)
currentHoofprintCount = currentHoofprintCount + 1
hoofprintsToAdd = hoofprintsToAdd - 1
else
printf("Did not find hoofprint with ID: %d", possibleHoofprintIds[i])
end
end

zone:setLocalVar("HoofprintCount", currentHoofprintCount)
end

-- Remove hoofprints at 06:00 from previous day
function darkRider.zone.onGameHour(zone)
if VanadielHour() ~= 6 then
return
end

local hoofprintCount = zone:getLocalVar("HoofprintCount")
if hoofprintCount == 0 then
return
end

local daysSinceEpoch = VanadielDaySinceEpoch()
local possibleHoofprintIds = hoofprintIds[zone:getID()]
for i = 1, #possibleHoofprintIds do
local hoofprint = GetNPCByID(possibleHoofprintIds[i])

-- Hide hoofprint if it was shown in a previous day
if hoofprint ~= nil and
hoofprint:getStatus() == dsp.status.NORMAL and
hoofprint:getLocalVar("DaysSinceEpoch") < daysSinceEpoch
then
hoofprint:setStatus(dsp.status.DISAPPEAR)
hoofprint:untargetable(true)
hoofprint:resetLocalVars()
hoofprintCount = hoofprintCount - 1
end
end

zone:setLocalVar("HoofprintCount", hoofprintCount)
end


function darkRider.hoofprintTrigger(player, npc)
if not player:hasKeyItem(dsp.ki.SP_WILDCAT_BADGE) then
if player:hasKeyItem(dsp.ki.DARK_RIDER_HOOFPRINT) or player:getVar("[Assault]SP") == 0 then
return
end

npcUtil.giveKeyItem(player, dsp.ki.DARK_RIDER_HOOFPRINT)
end
end
9 changes: 8 additions & 1 deletion scripts/zones/Bhaflau_Thickets/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ zoneObject.onInitialize = function(zone)
GetMobByID(ID.mob.HARVESTMAN):setRespawnTime(math.random(900, 10800))

xi.helm.initZone(zone, xi.helmType.HARVESTING)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onZoneIn = function(player, prevZone)
Expand All @@ -36,7 +37,13 @@ zoneObject.afterZoneIn = function(player)
player:entityVisualPacket('2pb1')
end

zoneObject.onTriggerAreaEnter = function(player, triggerArea)
zoneObject.onGameHour = function(zone)
updateZoneDigItems(zone)
darkRider.zone.onGameHour(zone)
end

zoneObjectonGameDay = function(zone)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onEventUpdate = function(player, csid, option, npc)
Expand Down
9 changes: 9 additions & 0 deletions scripts/zones/Bhaflau_Thickets/npcs/Warhorse_Hoofprint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----------------------------------
-- Area: Bhaflau Thickets
-- NPC: Warhorse Hoofprint
-----------------------------------
require("scripts/globals/dark_rider")

function onTrigger(player, npc)
return darkRider.hoofprintTrigger(player, npc)
end
9 changes: 9 additions & 0 deletions scripts/zones/Caedarva_Mire/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ zoneObject.onInitialize = function(zone)
GetMobByID(ID.mob.KHIMAIRA):setRespawnTime(math.random(12, 36) * 3600) -- 12 to 36 hours after maintenance, in 1-hour increments

xi.helm.initZone(zone, xi.helmType.LOGGING)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onZoneIn = function(player, prevZone)
Expand Down Expand Up @@ -46,6 +47,14 @@ end
zoneObject.onTriggerAreaEnter = function(player, triggerArea)
end

zoneObject.onGameDay = function(zone)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onGameHour = function(zone)
darkRider.zone.onGameHour(zone)
end

zoneObject.onEventUpdate = function(player, csid, option, npc)
end

Expand Down
9 changes: 9 additions & 0 deletions scripts/zones/Caedarva_Mire/npcs/Warhorse_Hoofprint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----------------------------------
-- Area: Caedarva Mire
-- NPC: Warhorse Hoofprint
-----------------------------------
require("scripts/globals/dark_rider")

function onTrigger(player, npc)
return darkRider.hoofprintTrigger(player, npc)
end
8 changes: 7 additions & 1 deletion scripts/zones/Mount_Zhayolm/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ zoneObject.onInitialize = function(zone)
GetMobByID(ID.mob.CERBERUS):setRespawnTime(math.random(12, 36) * 3600)

xi.helm.initZone(zone, xi.helmType.MINING)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onZoneIn = function(player, prevZone)
Expand All @@ -36,8 +37,13 @@ end
zoneObject.onTriggerAreaEnter = function(player, triggerArea)
end

zoneObject.onGameDay = function()
zoneObject.onGameDay = function(zone)
xi.apkallu.updateHate(xi.zone.MOUNT_ZHAYOLM, -3)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onGameHour = function(zone)
darkRider.zone.onGameHour(zone)
end

zoneObject.onEventUpdate = function(player, csid, option, npc)
Expand Down
9 changes: 9 additions & 0 deletions scripts/zones/Mount_Zhayolm/npcs/Warhorse_Hoofprint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----------------------------------
-- Area: Mount Zhayolm
-- NPC: Warhorse Hoofprint
-----------------------------------
require("scripts/globals/dark_rider")

function onTrigger(player, npc)
return darkRider.hoofprintTrigger(player, npc)
end
9 changes: 9 additions & 0 deletions scripts/zones/Wajaom_Woodlands/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local zoneObject = {}
zoneObject.onInitialize = function(zone)
xi.helm.initZone(zone, xi.helmType.HARVESTING)
xi.chocobo.initZone(zone)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onZoneIn = function(player, prevZone)
Expand All @@ -26,6 +27,14 @@ end
zoneObject.onTriggerAreaEnter = function(player, triggerArea)
end

zoneObject.onGameDay = function(zone)
darkRider.zone.addHoofprints(zone)
end

zoneObject.onGameHour = function(zone)
darkRider.zone.onGameHour(zone)
end

zoneObject.onEventUpdate = function(player, csid, option, npc)
end

Expand Down
9 changes: 9 additions & 0 deletions scripts/zones/Wajaom_Woodlands/npcs/Warhorse_Hoofprint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----------------------------------
-- Area: Wajaom Woodlands
-- NPC: Warhorse Hoofprint
-----------------------------------
require("scripts/globals/dark_rider")

function onTrigger(player, npc)
return darkRider.hoofprintTrigger(player, npc)
end

0 comments on commit 56e9d31

Please sign in to comment.