Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor vocations: Reload, extracted into tfs::game::vocations namespace and code improvements #4807

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions data/cpplinter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ RELOAD_TYPE_SCRIPTS = 14
RELOAD_TYPE_SPELLS = 15
RELOAD_TYPE_TALKACTIONS = 16
RELOAD_TYPE_WEAPONS = 17
RELOAD_TYPE_VOCATIONS = 18

PlayerFlag_CannotUseCombat = 1 * 2 ^ 0
PlayerFlag_CannotAttackPlayer = 1 * 2 ^ 1
Expand Down
3 changes: 3 additions & 0 deletions data/talkactions/scripts/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ local reloadTypes = {
["weapon"] = RELOAD_TYPE_WEAPONS,
["weapons"] = RELOAD_TYPE_WEAPONS,

["vocation"] = RELOAD_TYPE_VOCATIONS,
["vocations"] = RELOAD_TYPE_VOCATIONS,

["scripts"] = RELOAD_TYPE_SCRIPTS,
["libs"] = RELOAD_TYPE_GLOBAL
}
Expand Down
2 changes: 1 addition & 1 deletion src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ bool Combat::isProtected(const Player* attacker, const Player* target)
return true;
}

if (!attacker->getVocation()->allowsPvp() || !target->getVocation()->allowsPvp()) {
if (!attacker->getVocation()->allowPvp || !target->getVocation()->allowPvp) {
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ enum ReloadTypes_t : uint8_t
RELOAD_TYPE_SPELLS,
RELOAD_TYPE_TALKACTIONS,
RELOAD_TYPE_WEAPONS,
RELOAD_TYPE_VOCATIONS,
};

enum MonsterIcon_t : uint8_t
Expand Down
12 changes: 11 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extern Actions* g_actions;
extern Chat* g_chat;
extern TalkActions* g_talkActions;
extern Spells* g_spells;
extern Vocations g_vocations;
extern GlobalEvents* g_globalEvents;
extern CreatureEvents* g_creatureEvents;
extern Events* g_events;
Expand Down Expand Up @@ -5848,6 +5847,17 @@ bool Game::reload(ReloadTypes_t reloadType)
return results;
}

case RELOAD_TYPE_VOCATIONS: {
if (tfs::game::vocations::load_from_xml(true)) {
// Reload players vocations
for (const auto& [_, player] : players) {
player->updateVocation();
}
return true;
}
return false;
}

case RELOAD_TYPE_SCRIPTS: {
// commented out stuff is TODO, once we approach further in revscriptsys
g_actions->clear(true);
Expand Down
5 changes: 2 additions & 3 deletions src/http/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <fmt/format.h>

extern Game g_game;
extern Vocations g_vocations;

namespace beast = boost::beast;
namespace json = boost::json;
Expand Down Expand Up @@ -99,14 +98,14 @@ std::pair<status, json::value> tfs::http::handle_login(const json::object& body,
uint32_t lastLogin = 0;
if (result) {
do {
auto vocation = g_vocations.getVocation(result->getNumber<uint32_t>("vocation"));
auto vocation = tfs::game::vocations::get_vocation_by_id(result->getNumber<uint32_t>("vocation"));
assert(vocation);

characters.push_back({
{"worldid", 0}, // not implemented
{"name", result->getString("name")},
{"level", result->getNumber<uint32_t>("level")},
{"vocation", vocation->getVocName()},
{"vocation", vocation->name},
{"lastlogin", result->getNumber<uint64_t>("lastlogin")},
{"ismale", result->getNumber<uint16_t>("sex") == PLAYERSEX_MALE},
{"ishidden", false}, // not implemented
Expand Down
6 changes: 4 additions & 2 deletions src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
condition = Condition::createCondition(propStream);
}

if (!player->setVocation(result->getNumber<uint16_t>("vocation"))) {
auto vocation = tfs::game::vocations::get_vocation_by_id(result->getNumber<uint16_t>("vocation"));
if (!vocation) {
std::cout << "[Error - IOLoginData::loadPlayer] " << player->name << " has Vocation ID "
<< result->getNumber<uint16_t>("vocation") << " which doesn't exist" << std::endl;
return false;
}
player->setVocation(vocation);

player->mana = result->getNumber<uint32_t>("mana");
player->manaMax = result->getNumber<uint32_t>("manamax");
Expand Down Expand Up @@ -648,7 +650,7 @@ bool IOLoginData::savePlayer(Player* player)
query << "UPDATE `players` SET ";
query << "`level` = " << player->level << ',';
query << "`group_id` = " << player->group->id << ',';
query << "`vocation` = " << player->getVocationId() << ',';
query << "`vocation` = " << player->getVocation()->id << ',';
query << "`health` = " << player->health << ',';
query << "`healthmax` = " << player->healthMax << ',';
query << "`experience` = " << player->experience << ',';
Expand Down
1 change: 0 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Spells;

extern Game g_game;
extern Spells* g_spells;
extern Vocations g_vocations;

Items Item::items;

Expand Down
Loading
Loading