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

Added intro to teamwork questline #582

Merged
merged 8 commits into from
May 10, 2020
Merged
Changes from 7 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
187 changes: 179 additions & 8 deletions scripts/zones/West_Ronfaure/npcs/Vilatroire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,200 @@
-- "Advanced Teamwork"
-- !pos -260.361 -70.999 423.420 100
-----------------------------------
local ID = require("scripts/zones/West_Ronfaure/IDs")
require("scripts/globals/quests")
require("scripts/globals/titles")
require("scripts/globals/status")
require("scripts/globals/npc_util")
-----------------------------------

function onTrade(player, npc, trade)
end

function onTrigger(player, npc)
--player:startEvent(129) -- starts the ready check for all three quests
--player:startEvent(130) -- post third quest dialog
--player:startEvent(131) -- Same job
--player:startEvent(132) -- You don't have the requirements to start the second quest
--player:startEvent(133) -- Same race
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these events are all implemented into the script now, we no longer need the comments describing them as separate lines~! 😉

(But do keep the comments describing them when you start them later in the file 😄 )

local intermedTmwrk = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK)
local sFame = player:getFameLevel(SANDORIA)
--player:startEvent(134) -- You don't have the requirements to start the first quest
--player:startEvent(135) -- Starts first quest - 6 members same alliance
--player:startEvent(136) -- Default - before quests

if intermedTmwrk == QUEST_AVAILABLE and sFame >= 2 then
player:startEvent(135) -- Starts first quest - 6 members same alliance
elseif intermedTmwrk == QUEST_ACCEPTED then
player:startEvent(134) -- You don't have the requirements to finish
-- get players fame for this quest region
local sandyFame = player:getFameLevel(SANDORIA)

-- get quest statuses
local questIntroToTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK)
local questIntermediateTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.INTERMEDIATE_TEAMWORK)
local questAdvancedTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.ADVANCED_TEAMWORK)

if questIntroToTeamwork == QUEST_AVAILABLE and sandyFame >= 2 then
-- start the event that starts the quest
player:startEvent(135)
elseif questIntroToTeamwork == QUEST_AVAILABLE and sandyFame < 2 then
-- don't meet fame requirements
player:startEvent(134)
elseif questIntroToTeamwork == QUEST_ACCEPTED then
-- start the event that asks them if they are ready to check
player:startEvent(129, 0, 1)
elseif questIntroToTeamwork == QUEST_COMPLETED and questIntermediateTeamwork == QUEST_AVAILABLE and sandyFame >= 3 and player:getMainLvl() >= 10 then
-- they've completed the first quest, the second quest is available, and they have thee required fame,
-- start event that starts the next quest
player:startEvent(133)
elseif questIntroToTeamwork == QUEST_COMPLETED and questIntermediateTeamwork == QUEST_AVAILABLE and sandyFame < 3 and player:getMainLvl() < 10 then
-- don't meet fame requirements
player:startEvent(132)
elseif questIntermediateTeamwork == QUEST_ACCEPTED then
-- start the event that asks them if they are ready to check
player:startEvent(129, 0, 2)
elseif questIntermediateTeamwork == QUEST_COMPLETED and questAdvancedTeamwork == QUEST_AVAILABLE and sandyFame >= 4 and player:getMainLvl() >= 10 then
-- they've completed the second quest, the third quest is available, and they have thee required fame,
-- start event that starts the next quest
player:startEvent(131)
elseif questIntermediateTeamwork == QUEST_COMPLETED and questAdvancedTeamwork == QUEST_AVAILABLE and sandyFame < 4 and player:getMainLvl() < 10 then
-- don't meet fame requirements
player:startEvent(130)
elseif questAdvancedTeamwork == QUEST_ACCEPTED then
-- start the event that asks them if they are ready to check
player:startEvent(129, 0, 3)
elseif questAdvancedTeamwork == QUEST_COMPLETED then
player:startEvent(130)
else
player:startEvent(136) -- Default - before quests
player:startEvent(136)
end
end

function onEventUpdate(player, csid, option)
-- csid 129 happens for both quests
if csid == 129 then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an outgoing event option that the player selects to confirm that they're ready for the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe it or not, both options are 0. The 'automated message' packet is what differentiates the response.

local questIntroToTeamwork = player:getQuestStatus(SANDORIA,tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK)
local questIntermediateTeamwork = player:getQuestStatus(SANDORIA,tpz.quest.id.sandoria.INTERMEDIATE_TEAMWORK)
local questAdvancedTeamwork = player:getQuestStatus(SANDORIA,tpz.quest.id.sandoria.ADVANCED_TEAMWORK)

-- newer versions of these quests only require a party of 2.
-- older versions require all 6
local partySizeRequirement = 2

-- get party
local party = player:getParty()

-- since we loop through the party to check zone and distance, may as well check these in the same loop
local partySameNationCount = 0
local partySameRaceCount = 0
local partySameJobCount = 0

-- make sure the party is at least the right partySizeRequirement
if #party >= partySizeRequirement then

-- make sure everyone in the party is in the same zone and nearby
for key, member in pairs(party) do
if member:getZoneID() ~= player:getZoneID() or member:checkDistance(player) > 15 then
-- member not in zone or range
player:updateEvent(1)
return
else
-- check nation for first quest
if member:getNation() == player:getNation() then
partySameNationCount = partySameNationCount + 1
end

-- check race for second
if (player:getRace() == tpz.race.HUME_M or player:getRace() == tpz.race.HUME_F) and (member:getRace() == tpz.race.HUME_M or member:getRace() == tpz.race.HUME_F) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could save a few CPU cycles (and line space) by assigning locals of the player's race (right after the party size requirement succeeds) and the member's race (inside the for loop), and then check those cached values in the if instead of calling member:getRace() each time:

local mRace = member:getRace()
if (pRace == tpz.race.HUME_M or pRace == tpz.race.HUME_F) and (mRace == tpz.race.HUME_M or mRace == tpz.race.HUME_F) then

partySameRaceCount = partySameRaceCount + 1
elseif (player:getRace() == tpz.race.ELVAAN_M or player:getRace() == tpz.race.ELVAAN_F) and (member:getRace() == tpz.race.ELVAAN_M or member:getRace() == tpz.race.ELVAAN_F) then
partySameRaceCount = partySameRaceCount + 1
elseif (player:getRace() == tpz.race.TARU_M or player:getRace() == tpz.race.TARU_F) and (member:getRace() == tpz.race.TARU_M or member:getRace() == tpz.race.TARU_F) then
partySameRaceCount = partySameRaceCount + 1
elseif player:getRace() == tpz.race.GALKA and member:getRace() == tpz.race.GALKA then
partySameRaceCount = partySameRaceCount + 1
elseif player:getRace() == tpz.race.MITHRA and member:getRace() == tpz.race.MITHRA then
partySameRaceCount = partySameRaceCount + 1
end

-- job for third
if member:getMainJob() == player:getMainJob() then
partySameJobCount = partySameJobCount + 1
end
end
end

if questIntroToTeamwork == QUEST_ACCEPTED then
-- https://www.bg-wiki.com/bg/Introduction_to_Teamwork
if partySameNationCount == partySizeRequirement then
-- nation requirements met
player:setLocalVar("introToTmwrk_pass", 1)
player:updateEvent(15, 1)
else
-- not the same nation
player:updateEvent(3)
end
elseif questIntermediateTeamwork == QUEST_ACCEPTED then
-- https://www.bg-wiki.com/bg/Intermediate_Teamwork
if partySameRaceCount == partySizeRequirement then
-- race requirements met
player:setLocalVar("intermedTmwrk_pass", 1)
player:updateEvent(15, 2)
else
-- not the same race
player:updateEvent(4)
end
elseif questAdvancedTeamwork == QUEST_ACCEPTED then
-- https://www.bg-wiki.com/bg/Advanced_Teamwork
if partySameJobCount == partySameJobCount then
-- race requirements met
player:setLocalVar("advTmwrk_pass", 1)
player:updateEvent(15, 3)
else
-- not the same job
player:updateEvent(5)
end
end
else
-- need more party members
player:updateEvent(1)
end
end
end

function onEventFinish(player, csid, option)
end
-- csid 129 is the event for when they have selected ready/not ready

if csid == 129 and option == 0 then
local questIntroToTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK);
local questIntermediateTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.INTERMEDIATE_TEAMWORK);
local questAdvancedTeamwork = player:getQuestStatus(SANDORIA, tpz.quest.id.sandoria.ADVANCED_TEAMWORK);

if questIntroToTeamwork == QUEST_ACCEPTED and player:getLocalVar("introToTmwrk_pass") == 1 then
-- check their inventory
npcUtil.completeQuest(player, SANDORIA, tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK, {
item = 13442,
fame = 80, -- fame defaults to 30 if not set
title = tpz.title.THIRDRATE_ORGANIZER,
})
elseif questIntermediateTeamwork == QUEST_ACCEPTED and player:getLocalVar("intermedTmwrk_pass") == 1 then
-- check their inventory
npcUtil.completeQuest(player, SANDORIA, tpz.quest.id.sandoria.INTERMEDIATE_TEAMWORK, {
item = 4994,
fame = 80, -- fame defaults to 30 if not set
title = tpz.title.SECONDRATE_ORGANIZER,
})
elseif questAdvancedTeamwork == QUEST_ACCEPTED and player:getLocalVar("advTmwrk_pass") == 1 then
-- check their inventory
npcUtil.completeQuest(player, SANDORIA, tpz.quest.id.sandoria.ADVANCED_TEAMWORK, {
item = 13459,
fame = 80, -- fame defaults to 30 if not set
title = tpz.title.FIRSTRATE_ORGANIZER,
})
end
elseif csid == 131 and option == 1 then
cocosolos marked this conversation as resolved.
Show resolved Hide resolved
-- 131 is the third and last quest
player:addQuest(SANDORIA,tpz.quest.id.sandoria.ADVANCED_TEAMWORK)
elseif csid == 133 and option == 1 then
-- 133 is the second quest
player:addQuest(SANDORIA,tpz.quest.id.sandoria.INTERMEDIATE_TEAMWORK)
elseif csid == 135 and option == 1 then
-- 135 is the first quest
player:addQuest(SANDORIA,tpz.quest.id.sandoria.INTRODUCTION_TO_TEAMWORK)
end
end