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

feat: features OTCR natively in canary #3061

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4c54d85
1/6 feature: Creature : AttachedEffect, Shader
kokekanon Nov 4, 2024
745b7b8
2/7 feature: Map Shader
kokekanon Nov 4, 2024
ee26730
3/7 feature: TypingIcon
kokekanon Nov 5, 2024
23e166a
review: mehah
kokekanon Nov 5, 2024
eae4112
4/7 feature: Item Shader
kokekanon Nov 5, 2024
74ea55f
5/7 send disableFeature / enableFeature
kokekanon Nov 5, 2024
b09547e
review: dudantas
kokekanon Nov 5, 2024
9484492
fix sonarcloud bot
kokekanon Nov 5, 2024
f490ce4
fix sonarcloud bot 2
kokekanon Nov 5, 2024
1437b7e
fix: wrong review
dudantas Nov 5, 2024
67777a9
Code format - (Clang-format)
github-actions[bot] Nov 5, 2024
6766389
fix: itemShader old protocol otcr
kokekanon Nov 5, 2024
7c45b97
clean variable
kokekanon Nov 6, 2024
bd1854c
fix return get shader
kokekanon Nov 6, 2024
0ff915e
missing content player:getAttachedEffects
kokekanon Nov 6, 2024
f538950
simple test Talkations. delete when finished
kokekanon Nov 6, 2024
0217e80
Lua code format - (Stylua)
github-actions[bot] Nov 6, 2024
4b5fbad
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 6, 2024
9fe26c5
format
kokekanon Nov 6, 2024
7956f08
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 6, 2024
8d6961d
improve: variable name
kokekanon Nov 6, 2024
558b212
Merge branch 'kokekanon/all-feature-redemption' of https://github.com…
kokekanon Nov 6, 2024
3744f16
game_outfit functional version, not cleaned or optimized
kokekanon Nov 6, 2024
789354a
this requires review canary team .no break v8 and cipsoft
kokekanon Nov 7, 2024
6a23e40
Lua code format - (Stylua)
github-actions[bot] Nov 7, 2024
36da43e
fix: review sonarcloud ?
kokekanon Nov 7, 2024
8e939e5
Code format - (Clang-format)
github-actions[bot] Nov 7, 2024
c551152
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 7, 2024
5b5dc84
Merge branch 'kokekanon/all-feature-redemption' of https://github.com…
kokekanon Nov 7, 2024
9e763f7
simple test
kokekanon Nov 7, 2024
300f92c
Lua code format - (Stylua)
github-actions[bot] Nov 7, 2024
3bb868b
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 8, 2024
ef754d0
Merge branch 'kokekanon/all-feature-redemption' of https://github.com…
kokekanon Nov 8, 2024
6b27bb9
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 10, 2024
6097de3
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 10, 2024
ec0bd43
murge
kokekanon Nov 10, 2024
e30fd35
fix: compilation windows
kokekanon Nov 10, 2024
29919ed
Code format - (Clang-format)
github-actions[bot] Nov 10, 2024
6ed239c
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 13, 2024
2c46d0a
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 16, 2024
687d0b2
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 18, 2024
dce1886
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 25, 2024
f44bf10
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Nov 29, 2024
8350458
Merge remote-tracking branch 'upstream/main' into kokekanon/all-featu…
kokekanon Dec 12, 2024
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
8 changes: 8 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,11 @@ metricsPrometheusAddress = "0.0.0.0:9464"
--- OStream
metricsEnableOstream = false
metricsOstreamInterval = 1000
OTCRFeatures = { -- posible*
["enable"] = {
102, -- GameCreatureAttachedEffect
103 -- GameCreatureShader
},
["disable"] = { -- for example in 13.10 g_game.enableFeature(GameSequencedPackets)
}
}
17 changes: 17 additions & 0 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,3 +2002,20 @@ void Creature::sendAsyncTasks() {
},
TaskGroup::WalkParallel);
}

void Creature::attachEffectById(uint16_t id) {
auto it = std::find(attachedEffectList.begin(), attachedEffectList.end(), id);
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (it != attachedEffectList.end()) {
return;
}
attachedEffectList.push_back(id);
g_game().sendAttachedEffect(static_self_cast<Creature>(), id);
}
void Creature::detachEffectById(uint16_t id) {
auto it = std::find(attachedEffectList.begin(), attachedEffectList.end(), id);
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (it == attachedEffectList.end()) {
return;
}
attachedEffectList.erase(it);
g_game().sendDetachEffect(static_self_cast<Creature>(), id);
}
13 changes: 13 additions & 0 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ class Creature : virtual public Thing, public SharedObject {
void setCharmChanceModifier(int8_t value) {
charmChanceModifier = value;
}
std::string getShader() const {
return shader;
}
void setShader(const std::string &shaderName) {
dudantas marked this conversation as resolved.
Show resolved Hide resolved
shader = shaderName;
}
void attachEffectById(uint16_t id);
void detachEffectById(uint16_t id);
const std::vector<uint16_t> getAttachedEffectList() const {
return attachedEffectList;
}

protected:
enum FlagAsyncClass_t : uint8_t {
Expand Down Expand Up @@ -881,4 +892,6 @@ class Creature : virtual public Thing, public SharedObject {
}

uint8_t m_flagAsyncTask = 0;
std::vector<uint16_t> attachedEffectList;
std::string shader;
};
47 changes: 47 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9572,6 +9572,53 @@ void Player::sendLootContainers() const {
}
}

// OTCR Features

void Player::sendAttachedEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) const {
if (!client || !creature) {
return;
}
if (creature->getPlayer()) {
if (client) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
client->sendAttachedEffect(creature, effectId);
}
}
}

void Player::sendDetachEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) const {
if (!client || !creature) {
return;
}
if (creature->getPlayer()) {
if (client) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
client->sendDetachEffect(creature, effectId);
}
}
}

void Player::sendShader(const std::shared_ptr<Creature> &creature, const std::string &shaderName) const {
if (!client || !creature) {
return;
}
if (creature->getPlayer()) {
if (client) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
client->sendShader(creature, shaderName);
}
}
}

void Player::sendMapShader(const std::string &shaderName) const {
if (client) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
client->sendMapShader(shaderName);
}
}

void Player::sendPlayerTyping(const std::shared_ptr<Creature> &creature, uint8_t typing) const {
if (client) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
client->sendPlayerTyping(creature, typing);
}
}

void Player::sendSingleSoundEffect(const Position &pos, SoundEffect_t id, SourceEffect_t source) const {
if (client) {
client->sendSingleSoundEffect(pos, id, source);
Expand Down
13 changes: 13 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,18 @@ class Player final : public Creature, public Cylinder, public Bankable {

uint16_t getPlayerVocationEnum() const;

void sendAttachedEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) const;
void sendDetachEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) const;
void sendShader(const std::shared_ptr<Creature> &creature, const std::string &shaderName) const;
void sendMapShader(const std::string &shaderName) const;
const std::string &getMapShader() const {
return mapShader;
}
void setMapShader(const std::string &shaderName) {
this->mapShader = shaderName;
}
void sendPlayerTyping(const std::shared_ptr<Creature> &creature, uint8_t typing) const;

private:
friend class PlayerLock;
std::mutex mutex;
Expand Down Expand Up @@ -1371,6 +1383,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
std::string name;
std::string guildNick;
std::string loyaltyTitle;
std::string mapShader;

Skill skills[SKILL_LAST + 1];
LightInfo itemsLight;
Expand Down
44 changes: 44 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10852,3 +10852,47 @@ void Game::updatePlayersOnline() const {
g_logger().error("[Game::updatePlayersOnline] Failed to update players online.");
}
}

void Game::sendAttachedEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) {
auto spectators = Spectators().find<Creature>(creature->getPosition(), true);
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
for (const auto &spectator : spectators) {
auto player = spectator->getPlayer();
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (player) {
player->sendAttachedEffect(creature, effectId);
}
}
}
void Game::sendDetachEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId) {
auto spectators = Spectators().find<Creature>(creature->getPosition(), true);
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
for (const auto &spectator : spectators) {
auto player = spectator->getPlayer();
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (player) {
player->sendDetachEffect(creature, effectId);
}
}
}
void Game::updateCreatureShader(const std::shared_ptr<Creature> &creature) {
auto spectators = Spectators().find<Creature>(creature->getPosition(), true);
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
for (const auto &spectator : spectators) {
auto player = spectator->getPlayer();
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (player) {
player->sendShader(creature, creature->getShader());
}
}
}

void Game::playerSetTyping(uint32_t playerId, uint8_t typing) {
const auto &player = getPlayerByID(playerId);
if (!player) {
return;
}
auto spectators = Spectators().find<Creature>(player->getPosition(), true);
auto playersSpectators = spectators.filter<Player>();
for (const auto &spectator : spectators) {
kokekanon marked this conversation as resolved.
Show resolved Hide resolved
if (const auto &tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendPlayerTyping(player, typing);
}
}
}


5 changes: 5 additions & 0 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ class Game {
const std::map<uint8_t, std::string> &getBlessingNames();
const std::unordered_map<uint16_t, std::string> &getHirelingSkills();
const std::unordered_map<uint16_t, std::string> &getHirelingOutfits();
void sendAttachedEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId);
void sendDetachEffect(const std::shared_ptr<Creature> &creature, uint16_t effectId);
void updateCreatureShader(const std::shared_ptr<Creature> &creature);
void playerSetTyping(uint32_t playerId, uint8_t typing);


private:
std::map<uint16_t, Achievement> m_achievements;
Expand Down
59 changes: 59 additions & 0 deletions src/lua/functions/creatures/creature_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,3 +1107,62 @@ int CreatureFunctions::luaCreatureClearIcons(lua_State* L) {
pushBoolean(L, true);
return 1;
}

int CreatureFunctions::luaCreatureAttachEffectById(lua_State* L) {
// creature:attachEffectById(effectId, [temporary])
const auto &creature = getUserdataShared<Creature>(L, 1);
if (!creature) {
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}
uint16_t id = getNumber<uint16_t>(L, 2);
bool temp = getBoolean(L, 3, false);
if (temp) {
g_game().sendAttachedEffect(creature, id);
} else {
creature->attachEffectById(id);
}
return 1;
}

int CreatureFunctions::luaCreatureDetachEffectById(lua_State* L) {
// creature:detachEffectById(effectId)
const auto &creature = getUserdataShared<Creature>(L, 1);
if (!creature) {
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}
uint16_t id = getNumber<uint16_t>(L, 2);
creature->detachEffectById(id);
return 1;
}

int CreatureFunctions::luaCreatureGetShader(lua_State* L) {
// creature:getShader()
const auto &creature = getUserdataShared<Creature>(L, 1);
if (!creature) {
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushString(L, creature->getShader());

return 1;
}

int CreatureFunctions::luaCreatureSetShader(lua_State* L) {
// creature:setShader(shaderName)
const auto &creature = getUserdataShared<Creature>(L, 1);
if (!creature) {
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}
creature->setShader(getString(L, 2));
g_game().updateCreatureShader(creature);
pushBoolean(L, true);
return 1;
}
8 changes: 8 additions & 0 deletions src/lua/functions/creatures/creature_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class CreatureFunctions final : LuaScriptInterface {
registerMethod(L, "Creature", "getIcons", CreatureFunctions::luaCreatureGetIcons);
registerMethod(L, "Creature", "removeIcon", CreatureFunctions::luaCreatureRemoveIcon);
registerMethod(L, "Creature", "clearIcons", CreatureFunctions::luaCreatureClearIcons);
registerMethod(L, "Creature", "attachEffectById", CreatureFunctions::luaCreatureAttachEffectById);
registerMethod(L, "Creature", "detachEffectById", CreatureFunctions::luaCreatureDetachEffectById);
registerMethod(L, "Creature", "getShader", CreatureFunctions::luaCreatureGetShader);
registerMethod(L, "Creature", "setShader", CreatureFunctions::luaCreatureSetShader);

CombatFunctions::init(L);
MonsterFunctions::init(L);
Expand Down Expand Up @@ -196,4 +200,8 @@ class CreatureFunctions final : LuaScriptInterface {
static int luaCreatureGetIcon(lua_State* L);
static int luaCreatureRemoveIcon(lua_State* L);
static int luaCreatureClearIcons(lua_State* L);
static int luaCreatureAttachEffectById(lua_State* L);
static int luaCreatureDetachEffectById(lua_State* L);
static int luaCreatureGetShader(lua_State* L);
static int luaCreatureSetShader(lua_State* L);
};
28 changes: 28 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4462,3 +4462,31 @@ int PlayerFunctions::luaPlayerSendCreatureAppear(lua_State* L) {
pushBoolean(L, true);
return 1;
}

int PlayerFunctions::luaPlayerGetMapShader(lua_State* L) {
// player:getMapShader()
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
pushBoolean(L, false);
return 0;
}

pushString(L, player->getMapShader());
return 1;
}


int PlayerFunctions::luaPlayerSetMapShader(lua_State* L) {
// player:setMapShader(shaderName, [temporary])
const auto &player = getUserdataShared<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
pushBoolean(L, false);
return 0;
}
const auto shaderName = getString(L, 2);
player->sendMapShader(shaderName);
pushBoolean(L, true);
return 1;
}
7 changes: 7 additions & 0 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ class PlayerFunctions final : LuaScriptInterface {
registerMethod(L, "Player", "removeIconBakragore", PlayerFunctions::luaPlayerRemoveIconBakragore);
registerMethod(L, "Player", "sendCreatureAppear", PlayerFunctions::luaPlayerSendCreatureAppear);

// OTCR Features
registerMethod(L, "Player", "getMapShader", PlayerFunctions::luaPlayerGetMapShader);
registerMethod(L, "Player", "setMapShader", PlayerFunctions::luaPlayerSetMapShader);

GroupFunctions::init(L);
GuildFunctions::init(L);
MountFunctions::init(L);
Expand Down Expand Up @@ -755,6 +759,9 @@ class PlayerFunctions final : LuaScriptInterface {
static int luaPlayerRemoveIconBakragore(lua_State* L);

static int luaPlayerSendCreatureAppear(lua_State* L);

static int luaPlayerGetMapShader(lua_State* L);
static int luaPlayerSetMapShader(lua_State* L);

friend class CreatureFunctions;
};
Loading
Loading