Skip to content

Commit

Permalink
Merge branch 'main' into feature/badge-system
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored Apr 26, 2024
2 parents 452bc5f + e133c33 commit 05b9c0b
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 137 deletions.
14 changes: 13 additions & 1 deletion data-otservbr-global/lib/core/quests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5592,7 +5592,7 @@ if not Quests then
},
[41] = {
name = "Adventurers Guild",
startStorageId = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton,
startStorageId = Storage.AdventurersGuild.QuestLine,
startStorageValue = 1,
missions = {
[1] = {
Expand All @@ -5606,6 +5606,18 @@ if not Quests then
But the dragon hoards might justify the risks. You killed %d/50 dragons and dragon lords."):format(math.max(player:getStorageValue(Storage.AdventurersGuild.GreatDragonHunt.DragonCounter), 0))
end,
},
[2] = {
name = "The Lost Brother",
storageId = Storage.AdventurersGuild.TheLostBrother,
missionId = 11000,
startValue = 1,
endValue = 3,
states = {
[1] = "At the Kha'zeel Mountains you met the merchant Tarun. His brother has gone missing and was last seen following a beautiful woman into a palace. Tarun fears this woman might have been a demon.",
[2] = "You found the remains of Tarun's brother containing a message. Go back to Tarun and report his brother's last words.",
[3] = "You told Tarun about his brother's sad fate. He was very downhearted but gave you his sincere thanks. The beautiful asuri have taken a young man's life and the happiness of another one.",
},
},
},
},
[42] = {
Expand Down
3 changes: 2 additions & 1 deletion data-otservbr-global/lib/core/storages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,8 @@ Storage = {
WarriorSkeleton = 52146,
DragonCounter = 52147,
},
QuestLine = 52148,
TheLostBrother = 52149,
},
DreamersChallenge = {
-- Reserved storage from 52160 - 52199
Expand Down Expand Up @@ -2534,7 +2536,6 @@ Storage = {
NightmareTeddy = {},
PoacherCavesMiniWorldChange = {},
TheGreatDragonHunt = {},
TheLostBrother = {},
TheTaintedSouls = {},
},
U10_90 = { -- update 10.90 - Reserved Storages 45201 - 45350
Expand Down
68 changes: 68 additions & 0 deletions data-otservbr-global/npc/tarun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,74 @@ npcType.onCloseChannel = function(npc, creature)
npcHandler:onCloseChannel(npc, creature)
end

local function creatureSayCallback(npc, creature, type, message)
local player = Player(creature)
if not player then
return false
end
local playerId = player:getId()

if not npcHandler:checkInteraction(npc, creature) then
return false
end

local theLostBrotherStorage = player:getStorageValue(Storage.AdventurersGuild.TheLostBrother)
if MsgContains(message, "mission") then
if theLostBrotherStorage < 1 then
npcHandler:say({
"My brother is missing. I fear, he went to this evil palace north of here. A place of great beauty, certainly filled with riches and luxury. But in truth it is a threshold to hell and demonesses are after his blood. ...",
"He is my brother, and I am deeply ashamed to admit but I don't dare to go there. Perhaps your heart is more courageous than mine. Would you go to see this place and search for my brother?",
}, npc, creature)
npcHandler:setTopic(playerId, 1)
elseif theLostBrotherStorage == 1 then
npcHandler:say("I hope you will find my brother.", npc, creature)
npcHandler:setTopic(playerId, 0)
elseif theLostBrotherStorage == 2 then
npcHandler:say({
"So, he is dead as I feared. I warned him not to go with this woman, but he gave in to temptation. My heart darkens and moans. But you have my sincere thanks. ...",
"Without your help I would have stayed in the dark about his fate. Please, take this as a little recompense.",
}, npc, creature)
player:addItem(3039, 1)
player:addExperience(3000, true)
player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 3)
npcHandler:setTopic(playerId, 0)
end
elseif npcHandler:getTopic(playerId) == 1 then
if MsgContains(message, "yes") then
npcHandler:say("I thank you! This is more than I could hope!", npc, creature)
if theLostBrotherStorage < 1 then
player:setStorageValue(Storage.AdventurersGuild.QuestLine, 1)
end
player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 1)
elseif MsgContains(message, "no") then
npcHandler:say("As you wish.", npc, creature)
end
npcHandler:setTopic(playerId, 0)
end

return true
end

local function onTradeRequest(npc, creature)
local player = Player(creature)
if not player then
return false
end
local playerId = player:getId()

if player:getStorageValue(Storage.AdventurersGuild.TheLostBrother) ~= 3 then
return false
end

return true
end

npcHandler:setMessage(MESSAGE_GREET, "Greetings!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell.")
npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just have a look.")
npcHandler:setCallback(CALLBACK_ON_TRADE_REQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell.")
npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true)

npcConfig.shop = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ function adventurersWarriorSkeleton.onUse(player, item, fromPosition, target, to
if player:getStorageValue(Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton) < 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have discovered a deceased warrior's skeleton. It seems he tried to hunt the dragons around here - and failed.")
player:addItem(5882, 1) -- red dragon scale

if player:getStorageValue(Storage.AdventurersGuild.QuestLine) < 1 then
player:setStorageValue(Storage.AdventurersGuild.QuestLine, 1)
end

player:setStorageValue(Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, 1)
player:setStorageValue(Storage.AdventurersGuild.GreatDragonHunt.DragonCounter, 0)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,26 @@ function teleportBoss.onStepIn(creature, item, position, fromPosition)
end
local player = creature
if player:getLevel() < config.requiredLevel then
player:teleportTo(fromPosition, true)
player:teleportTo(exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level " .. config.requiredLevel .. " or higher.")
return true
end
if locked then
player:teleportTo(fromPosition, true)
player:teleportTo(exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's already someone fighting with " .. config.bossName .. ".")
return false
end
if zone:countPlayers(IgnoredByMonsters) >= 5 then
player:teleportTo(fromPosition, true)
player:teleportTo(exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The boss room is full.")
return false
end
local timeLeft = player:getBossCooldown(config.bossName) - os.time()
if timeLeft > 0 then
player:teleportTo(fromPosition, true)
player:teleportTo(exitPosition, true)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to wait " .. getTimeInWords(timeLeft) .. " to face " .. config.bossName .. " again!")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ local questTable = {
{ storage = Storage.Quest.U11_40.ThreatenedDreams.QuestLine, storageValue = 1 },
{ storage = Storage.Quest.U11_40.ThreatenedDreams.Mission01[1], storageValue = 16 },
{ storage = Storage.Quest.U11_40.ThreatenedDreams.Mission02.KroazurAccess, storageValue = 1 },
{ storage = Storage.AdventurersGuild.QuestLine, storageValue = 1 },
{ storage = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, storageValue = 1 },
{ storage = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, storageValue = 2 },
{ storage = Storage.AdventurersGuild.TheLostBrother, storageValue = 3 },
{ storage = Storage.Quest.U10_55.Dawnport.Questline, storageValue = 1 },
{ storage = Storage.Quest.U10_55.Dawnport.GoMain, storageValue = 1 },
{ storage = Storage.ForgottenKnowledge.AccessDeath, storageValue = 1 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local findRemains = MoveEvent()

function findRemains.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end

if player:getStorageValue(Storage.AdventurersGuild.TheLostBrother) == 1 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You stumble over some old bones. Something is carved into the stone wall here: 'Tarun, my brother, you were right. She's evil.'")
player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 2)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
end

return true
end

findRemains:position(Position(32959, 32674, 4))
findRemains:register()
1 change: 1 addition & 0 deletions data/scripts/talkactions/god/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local reloadTypes = {
["scripts"] = RELOAD_TYPE_SCRIPTS,
["stage"] = RELOAD_TYPE_CORE,
["stages"] = RELOAD_TYPE_CORE,
["vocations"] = RELOAD_TYPE_VOCATIONS,
}

local reload = TalkAction("/reload")
Expand Down
1 change: 1 addition & 0 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,5 @@ void CanaryServer::shutdown() {
g_dispatcher().shutdown();
g_metrics().shutdown();
inject<ThreadPool>().shutdown();
std::exit(0);
}
56 changes: 19 additions & 37 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Player::~Player() {
}

bool Player::setVocation(uint16_t vocId) {
Vocation* voc = g_vocations().getVocation(vocId);
const auto &voc = g_vocations().getVocation(vocId);
if (!voc) {
return false;
}
Expand Down Expand Up @@ -2415,7 +2415,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool
++level;
// Player stats gain for vocations level <= 8
if (vocation->getId() != VOCATION_NONE && level <= 8) {
const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE);
const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE);
healthMax += noneVocation->getHPGain();
health += noneVocation->getHPGain();
manaMax += noneVocation->getManaGain();
Expand Down Expand Up @@ -2510,7 +2510,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) {
--level;
// Player stats loss for vocations level <= 8
if (vocation->getId() != VOCATION_NONE && level <= 8) {
const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE);
const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE);
healthMax = std::max<int32_t>(0, healthMax - noneVocation->getHPGain());
manaMax = std::max<int32_t>(0, manaMax - noneVocation->getManaGain());
capacity = std::max<int32_t>(0, capacity - noneVocation->getCapGain());
Expand Down Expand Up @@ -6948,8 +6948,9 @@ std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Posi
return nullptr;
}

std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>> Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
if (depotLocker == nullptr) {
std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>>
Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const {
if (!depotLocker) {
g_logger().error("{} - Depot locker is nullptr", __FUNCTION__);
return {};
}
Expand All @@ -6958,62 +6959,43 @@ std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_
std::vector<std::shared_ptr<Item>> itemVector;
std::vector<std::shared_ptr<Container>> containers { depotLocker };

size_t size = 0;
do {
std::shared_ptr<Container> container = containers[size];
size++;
for (size_t i = 0; i < containers.size(); ++i) {
std::shared_ptr<Container> container = containers[i];

for (std::shared_ptr<Item> item : container->getItemList()) {
for (const auto &item : container->getItemList()) {
std::shared_ptr<Container> lockerContainers = item->getContainer();
if (lockerContainers && !lockerContainers->empty()) {
containers.push_back(lockerContainers);
continue;
}

if (item->isStoreItem()) {
continue;
}

const ItemType &itemType = Item::items[item->getID()];
if (itemType.wareId == 0) {
if (item->isStoreItem() || itemType.wareId == 0) {
continue;
}

if (lockerContainers && (!itemType.isContainer() || lockerContainers->capacity() != itemType.maxItems)) {
continue;
}

if (!item->hasMarketAttributes()) {
continue;
}

if (!sendToClient && item->getTier() != tier) {
if (!item->hasMarketAttributes() || (!sendToClient && item->getTier() != tier)) {
continue;
}

(lockerItems[itemType.wareId])[item->getTier()] += Item::countByType(item, -1);
lockerItems[itemType.wareId][item->getTier()] += Item::countByType(item, -1);
itemVector.push_back(item);
}
} while (size < containers.size());
StashItemList stashToSend = getStashItems();
uint32_t countSize = 0;
for (auto [itemId, itemCount] : stashToSend) {
countSize += itemCount;
}

do {
for (auto [itemId, itemCount] : stashToSend) {
const ItemType &itemType = Item::items[itemId];
if (itemType.wareId == 0) {
continue;
}

countSize = countSize - itemCount;
(lockerItems[itemType.wareId])[0] += itemCount;
StashItemList stashToSend = getStashItems();
for (const auto &[itemId, itemCount] : stashToSend) {
const ItemType &itemType = Item::items[itemId];
if (itemType.wareId != 0) {
lockerItems[itemType.wareId][0] += itemCount;
}
} while (countSize > 0);
}

return std::make_pair(itemVector, lockerItems);
return { itemVector, lockerItems };
}

std::pair<std::vector<std::shared_ptr<Item>>, uint16_t> Player::getLockerItemsAndCountById(const std::shared_ptr<DepotLocker> &depotLocker, uint8_t tier, uint16_t itemId) {
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

bool isBossOnBosstiaryTracker(const std::shared_ptr<MonsterType> &monsterType) const;

Vocation* getVocation() const {
std::shared_ptr<Vocation> getVocation() const {
return vocation;
}

Expand Down Expand Up @@ -2537,7 +2537,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

// Concoction system
void updateConcoction(uint16_t itemId, uint16_t timeLeft) {
if (timeLeft < 0) {
if (timeLeft == 0) {
activeConcoctions.erase(itemId);
} else {
activeConcoctions[itemId] = timeLeft;
Expand Down Expand Up @@ -2804,7 +2804,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
ProtocolGame_ptr client;
std::shared_ptr<Task> walkTask;
std::shared_ptr<Town> town;
Vocation* vocation = nullptr;
std::shared_ptr<Vocation> vocation = nullptr;
std::shared_ptr<RewardChest> rewardChest = nullptr;

uint32_t inventoryWeight = 0;
Expand Down
Loading

0 comments on commit 05b9c0b

Please sign in to comment.