Skip to content

Commit

Permalink
* Moved emote spells to kv instead of storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Dec 28, 2024
1 parent 6555e09 commit 720e408
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
1 change: 1 addition & 0 deletions data/libs/systems/features.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Features = {
AutoLoot = "autoloot",
ChainSystem = "chainSystem",
EmoteSpells = "emoteSpells",
}

local function validateFeature(feature)
Expand Down
1 change: 1 addition & 0 deletions data/scripts/talkactions/player/chain_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local validValues = {

function feature.onSay(player, words, param)
if not configManager.getBoolean(configKeys.TOGGLE_CHAIN_SYSTEM) then
player:sendTextMessage(MESSAGE_FAILURE, "Chain system have been disabled by the administrator.")
return true
end

Expand Down
19 changes: 12 additions & 7 deletions data/scripts/talkactions/player/emote_spell.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
-- Usage talkaction: "!emote on" or "!emote off"
local emoteSpell = TalkAction("!emote")

local validValues = {
"on",
"off",
}

function emoteSpell.onSay(player, words, param)
if configManager.getBoolean(configKeys.EMOTE_SPELLS) == false then
player:sendTextMessage(MESSAGE_LOOK, "Emote spells have been disabled by the administrator.")
if not configManager.getBoolean(configKeys.EMOTE_SPELLS) then
player:sendTextMessage(MESSAGE_FAILURE, "Emote spells have been disabled by the administrator.")
return true
end

if param == "" then
player:sendCancelMessage("Please specify the parameter: 'on' to activate or 'off' to deactivate.")
if not table.contains(validValues, param) then
local validValuesStr = table.concat(validValues, "/")
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Invalid param specified. Usage: !emote [" .. validValuesStr .. "]")
return true
end

if param == "on" then
player:setStorageValue(STORAGEVALUE_EMOTE, 1)
player:setFeature(Features.EmoteSpells, 1)
player:sendTextMessage(MESSAGE_LOOK, "You have activated emote spells.")
elseif param == "off" then
player:setStorageValue(STORAGEVALUE_EMOTE, 0)
player:setFeature(Features.EmoteSpells, 0)
player:sendTextMessage(MESSAGE_LOOK, "You have deactivated emote spells.")
end
return true
Expand Down
8 changes: 6 additions & 2 deletions markdowns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Optimized the `onPlayerSellAllLoot` code to prevent prolonged freezes. ([Tryller](https://github.com/jprzimba))
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`. ([Tryller](https://github.com/jprzimba))
- Added a new command for players: `!randomoutfit`. ([Tryller](https://github.com/jprzimba))
- Moved emote spells to `kv` instead of `storage`. ([Tryller](https://github.com/jprzimba))

## Added files

Expand All @@ -22,10 +23,9 @@

- crystalserver.exe
- config.lua
- data-global/world/world.otbm (7z file)
- data-global/world/world-house.xml
- data/items/assets.dat
- data/items/items.xml
- data/libs/systems/features.lua
- data/scripts/creaturescripts/player/login.lua
- data/scripts/movements/special_tiles.lua
- data/scripts/movements/swimming.lua
Expand All @@ -34,6 +34,10 @@
- data/scripts/talkactions/god/manage_monster.lua
- data/scripts/talkactions/god/create_summon.lua
- data/scripts/talkactions/god/create_npc.lua
- data/scripts/talkactions/player/chain_system.lua
- data/scripts/talkactions/player/emote_spell.lua
- data-global/world/world.otbm (7z file)
- data-global/world/world-house.xml
- data-global/scripts/quests/ferumbras_ascension/actions_flower_puzzle_lever.lua
- data-global/scripts/quests/ferumbras_ascension/movements_flower_puzzle.lua
- data-global/scripts/lib/register_actions.lua
Expand Down
24 changes: 19 additions & 5 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5002,6 +5002,24 @@ bool Player::checkChainSystem() const {
return false;
}

bool Player::checkEmoteSpells() const {
if (!g_configManager().getBoolean(EMOTE_SPELLS)) {
return false;
}

auto featureKV = kv()->scoped("features")->get("emoteSpells");
if (featureKV.has_value()) {
auto value = featureKV->getNumber();
if (value == 1) {
return true;
} else if (value == 0) {
return false;
}
}

return false;
}

QuickLootFilter_t Player::getQuickLootFilter() const {
return quickLootFilter;
}
Expand Down Expand Up @@ -8821,15 +8839,11 @@ bool Player::saySpell(SpeakClasses type, const std::string &text, bool isGhostMo
spectators = (*spectatorsPtr);
}

int32_t valueEmote = 0;
// Send to client
for (const auto &spectator : spectators) {
if (const auto &tmpPlayer = spectator->getPlayer()) {
if (g_configManager().getBoolean(EMOTE_SPELLS)) {
valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE);
}
if (!isGhostMode || tmpPlayer->canSeeCreature(static_self_cast<Player>())) {
if (valueEmote == 1) {
if (checkEmoteSpells()) {
tmpPlayer->sendCreatureSay(static_self_cast<Player>(), TALKTYPE_MONSTER_SAY, text, pos);
} else {
tmpPlayer->sendCreatureSay(static_self_cast<Player>(), TALKTYPE_SPELL_USE, text, pos);
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 @@ -1211,6 +1211,7 @@ class Player final : public Creature, public Cylinder, public Bankable {

bool checkAutoLoot(bool isBoss) const;
bool checkChainSystem() const;
bool checkEmoteSpells() const;

QuickLootFilter_t getQuickLootFilter() const;

Expand Down
1 change: 0 additions & 1 deletion src/lua/functions/core/game/lua_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ void LuaEnums::initOthersEnums(lua_State* L) {
registerEnum(L, LIGHT_STATE_NIGHT);
registerEnum(L, LIGHT_STATE_SUNSET);
registerEnum(L, LIGHT_STATE_SUNRISE);
registerEnum(L, STORAGEVALUE_EMOTE);

registerEnum(L, IMMOVABLE_ACTION_ID);

Expand Down
1 change: 0 additions & 1 deletion src/utils/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ static constexpr int32_t CHANNEL_PRIVATE = 0xFFFF;
static constexpr int32_t EVENT_IMBUEMENT_INTERVAL = 1000;
static constexpr uint8_t IMBUEMENT_MAX_TIER = 3;

static constexpr int32_t STORAGEVALUE_EMOTE = 30008;
static constexpr int32_t STORAGEVALUE_PODIUM = 30020;
static constexpr int32_t STORAGEVALUE_BESTIARYKILLCOUNT = 61305000; // Can get up to 2000 storages!

Expand Down

0 comments on commit 720e408

Please sign in to comment.