Skip to content

Commit

Permalink
resolving conversations and changed 'gsub("^%s*(.-)$", "%1")' to 'tri…
Browse files Browse the repository at this point in the history
…mSpace()' in talkactions.
  • Loading branch information
elsongabriel committed May 9, 2024
1 parent 767579e commit 513f242
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"BUILD_STATIC_LIBRARY": "ON",
"SPEED_UP_BUILD_UNITY": "ON",
"SPEED_UP_BUILD_UNITY": "OFF",
"OPTIONS_ENABLE_SCCACHE": "ON",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
Expand Down
3 changes: 1 addition & 2 deletions data/scripts/talkactions/god/add_skill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function addSkill.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace() -- Trim left

local count = 1
if split[3] then
Expand Down
8 changes: 4 additions & 4 deletions data/scripts/talkactions/god/charms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function addCharm.onSay(player, words, param)
player:sendCancelMessage("A player with that name is not online.")
return true
end
--trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")

split[2] = split[2]:trimSpace() -- Trim left

player:sendCancelMessage("Added " .. split[2] .. " charm points to character '" .. target:getName() .. "'.")
target:sendCancelMessage("Received " .. split[2] .. " charm points!")
Expand Down Expand Up @@ -133,8 +133,8 @@ function setBestiary.onSay(player, words, param)
return true
end

split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left
split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left
split[2] = split[2]:trimSpace() --Trim left
split[3] = split[3]:trimSpace() --Trim left

local monsterName = split[2]
local mType = MonsterType(monsterName)
Expand Down
6 changes: 3 additions & 3 deletions data/scripts/talkactions/god/create_monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ function createMonster.onSay(player, words, param)
local monsterName = split[1]
local monsterCount = 0
if split[2] then
split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left
split[2] = split[2]:trimSpace() -- Trim left
monsterCount = tonumber(split[2])
end

local monsterForge = nil
if split[3] then
split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left
split[3] = split[3]:trimSpace() -- Trim left
monsterForge = split[3]
end

if monsterCount > 1 then
local spawnRadius = 5
if split[4] then
split[4] = split[4]:gsub("^%s*(.-)$", "%1") --Trim left
split[4] = split[4]:trimSpace() -- Trim left
spawnRadius = split[4]
print(spawnRadius)
end
Expand Down
3 changes: 1 addition & 2 deletions data/scripts/talkactions/god/manage_badge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function addBadge.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace() -- Trim left
local id = tonumber(split[2])
target:addBadge(id)
return true
Expand Down
3 changes: 1 addition & 2 deletions data/scripts/talkactions/god/manage_storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function Player.getStorageValueTalkaction(self, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace() -- Trim left

-- Try to convert the second parameter to a number. If it's not a number, treat it as a storage name
local storageKey = tonumber(split[2])
Expand Down
6 changes: 2 additions & 4 deletions data/scripts/talkactions/god/manage_title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function addTitle.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace() -- Trim left
local id = tonumber(split[2])
target:addTitle(id)
return true
Expand Down Expand Up @@ -56,8 +55,7 @@ function setTitle.onSay(player, words, param)
return true
end

-- Trim left
split[2] = split[2]:gsub("^%s*(.-)$", "%1")
split[2] = split[2]:trimSpace() -- Trim left
local id = tonumber(split[2])
target:setCurrentTitle(id)
return true
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/cyclopedia/player_badge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "game/game_definitions.hpp"
#include "enums/player_cyclopedia.hpp"

class Player;
class KV;
Expand Down
32 changes: 2 additions & 30 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool PlayerTitle::add(uint8_t id, uint32_t timestamp /* = 0*/) {
return true;
}

std::vector<std::pair<Title, uint32_t>> PlayerTitle::getUnlockedTitles() const {
const std::vector<std::pair<Title, uint32_t>> &PlayerTitle::getUnlockedTitles() {
return m_titlesUnlocked;
}

Expand Down Expand Up @@ -196,7 +196,6 @@ bool PlayerTitle::checkLevel(uint32_t amount) {
bool PlayerTitle::checkHighscore(uint8_t skill) {
// todo cyclopledia
return false;
// return g_game().getH() m_player.getLevel() >= amount;
}

bool PlayerTitle::checkBestiary(uint16_t race) {
Expand All @@ -223,7 +222,7 @@ bool PlayerTitle::checkQuest(TitleStorage storage) {
: m_player.getStorageValue(storage.key) == storage.value;
}

bool PlayerTitle::checkOther(std::string name) {
bool PlayerTitle::checkOther(const std::string &name) {
if (name == "Admirer of the Crown") {
// todo
return false;
Expand All @@ -241,30 +240,3 @@ bool PlayerTitle::checkOther(std::string name) {
}
return false;
}

/*int GameFunctions::luaGameGetHighscoresLeaderId(lua_State* L) {
// Game.getHighscoresLeaderId(skill)
const auto highscoreVector = g_game().getHighscoreByCategory(static_cast<HighscoreCategories_t>(getNumber<uint16_t>(L, 1, 0)));
if (highscoreVector.size() != 0) {
lua_pushnumber(L, highscoreVector.front().id);
} else {
lua_pushnumber(L, 0);
}
return 1;
}
int GameFunctions::luaGameGetBestiaryRaceAmount(lua_State* L) {
// Game.getBestiaryRaceAmount(race)
uint16_t entries = 0;
BestiaryType_t race = static_cast<BestiaryType_t>(getNumber<uint16_t>(L, 1, 0));
for (const auto mType_it : g_game().getBestiaryList()) {
if (const MonsterType *mType = g_monsters().getMonsterType(mType_it.second);
mType && mType->info.bestiaryRace == race) {
entries++;
}
}
lua_pushnumber(L, entries);
return 1;
}*/
6 changes: 3 additions & 3 deletions src/creatures/players/cyclopedia/player_title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <utility>

#include "game/game_definitions.hpp"
#include "enums/player_cyclopedia.hpp"

class Player;
class KV;
Expand Down Expand Up @@ -83,7 +83,7 @@ class PlayerTitle {

[[nodiscard]] bool isTitleUnlocked(uint8_t id) const;
bool add(uint8_t id, uint32_t timestamp = 0);
[[nodiscard]] std::vector<std::pair<Title, uint32_t>> getUnlockedTitles() const;
const std::vector<std::pair<Title, uint32_t>> &getUnlockedTitles();
[[nodiscard]] uint8_t getCurrentTitle() const;
void setCurrentTitle(uint8_t id);
[[nodiscard]] std::string getCurrentTitleName() const;
Expand All @@ -102,7 +102,7 @@ class PlayerTitle {
bool checkTask(uint32_t amount);
bool checkMap(uint32_t amount);
bool checkQuest(TitleStorage storage);
bool checkOther(std::string name);
bool checkOther(const std::string &name);

private:
// {title ID, time when it was unlocked}
Expand Down
7 changes: 3 additions & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ std::string Player::getDescription(int32_t lookDistance) {
std::ostringstream s;
std::string subjectPronoun = getSubjectPronoun();
capitalizeWords(subjectPronoun);
auto playerTitle = title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName());

if (lookDistance == -1) {
s << "yourself" << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName())) << ".";
s << "yourself" << playerTitle << ".";

if (group->access) {
s << " You are " << group->name << '.';
Expand All @@ -146,9 +147,7 @@ std::string Player::getDescription(int32_t lookDistance) {
s << " (Level " << level << ')';
}

s << (title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName()));

s << ". " << subjectPronoun;
s << playerTitle << ". " << subjectPronoun;

if (group->access) {
s << " " << getSubjectVerb() << " " << group->name << '.';
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "creatures/npcs/npc.hpp"
#include "game/bank/bank.hpp"
#include "enums/object_category.hpp"
#include "enums/player_cyclopedia.hpp"
#include "creatures/players/cyclopedia/player_badge.hpp"
#include "creatures/players/cyclopedia/player_title.hpp"

Expand Down
38 changes: 38 additions & 0 deletions src/enums/player_cyclopedia.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 OpenTibiaBR <opentibiabr@outlook.com>
* Repository: https://github.com/opentibiabr/canary
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors
* Website: https://docs.opentibiabr.com/
*/

#pragma once

#ifndef USE_PRECOMPILED_HEADERS
#include <cstdint>
#endif

enum CyclopediaBadge_t : uint8_t {
ACCOUNT_AGE = 1,
LOYALTY,
ACCOUNT_ALL_LEVEL,
ACCOUNT_ALL_VOCATIONS,
TOURNAMENT_PARTICIPATION,
TOURNAMENT_POINTS,
};

enum CyclopediaTitle_t : uint8_t {
NOTHING = 0,
GOLD,
MOUNTS,
OUTFITS,
LEVEL,
HIGHSCORES,
BESTIARY,
LOGIN,
TASK,
MAP,
QUEST,
OTHERS,
};
24 changes: 0 additions & 24 deletions src/game/game_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,6 @@ enum LightState_t {
LIGHT_STATE_SUNRISE,
};

enum CyclopediaBadge_t : uint8_t {
ACCOUNT_AGE = 1,
LOYALTY,
ACCOUNT_ALL_LEVEL,
ACCOUNT_ALL_VOCATIONS,
TOURNAMENT_PARTICIPATION,
TOURNAMENT_POINTS,
};

enum CyclopediaTitle_t : uint8_t {
NOTHING = 0,
GOLD,
MOUNTS,
OUTFITS,
LEVEL,
HIGHSCORES,
BESTIARY,
LOGIN,
TASK,
MAP,
QUEST,
OTHERS,
};

enum CyclopediaCharacterInfoType_t : uint8_t {
CYCLOPEDIA_CHARACTERINFO_BASEINFORMATION = 0,
CYCLOPEDIA_CHARACTERINFO_GENERALSTATS = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4320,7 +4320,7 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) {
lua_createtable(L, static_cast<int>(playerTitles.size()), 0);

int index = 0;
for (auto title : playerTitles) {
for (const auto &title : playerTitles) {
lua_pushnumber(L, title.first.m_id);
lua_rawseti(L, -2, ++index);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/server_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct HighscoreCharacter {
rank(rank),
level(level),
vocation(vocation),
title(title) { }
title(std::move(title)) { }

std::string name;
uint64_t points;
Expand Down

0 comments on commit 513f242

Please sign in to comment.