Skip to content

Commit

Permalink
feat: attacheffect mehah
Browse files Browse the repository at this point in the history
  • Loading branch information
kokekanon committed Apr 5, 2024
1 parent 20115e5 commit 8782a81
Show file tree
Hide file tree
Showing 23 changed files with 462 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ allowWalkthrough = true
serverName = "Forgotten"
statusTimeout = 5000
replaceKickOnLogin = true
maxPacketsPerSecond = 25
maxPacketsPerSecond = 50

-- Deaths
-- NOTE: Leave deathLosePercent as -1 if you want to use the default
Expand Down
2 changes: 1 addition & 1 deletion data/monster/monsters/orc.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Orc" nameDescription="an orc" race="blood" experience="25" speed="150" manacost="300" raceId="5">
<monster name="Orc" nameDescription="an orc" race="blood" experience="25" speed="150" manacost="300" raceId="5" shaderEffect = "Outfit - Rainbow" auraEffect = "8" wignsEffect ="11" rayosEffect="7" >
<health now="70" max="70" />
<look type="5" corpse="5966" />
<targetchange interval="4000" chance="0" />
Expand Down
92 changes: 92 additions & 0 deletions data/scripts/OTCMehah/talkactions/Attachedeffect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
local mehah = {
talkactions = {
attacheffect = "!attacheffect",
detachEffect = "!detacheffect",
playerSetShader = "!playerSetShader",
itemSetShader = "!itemSetShader",
mapShader = "!mapShader"
},
}

local events = {}

local function processCommand(player, words, param, type, action)
if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
player:sendCancelMessage("No tienes acceso a este comando.")
return false
end

local params, arg
if param:find("\"") then
params = { param:match("\"(.+)\",*(.*)") }
arg = params[1]
print(params)
print(arg)
pdump(params)
else
params = param:split(", ")
arg = params[1]
print("2",params)
print("2",arg)
end

if not arg then
player:sendCancelMessage("Parámetro inválido. Por favor proporciona un argumento válido.")
return false
end

local creature
if params[2] and params[2] ~= "" then
creature = Player(params[2])
if not creature then
player:sendCancelMessage("El nombre del jugador proporcionado no es válido.")
return false
end
else
creature = player
end

action(creature, arg)
return false
end

local attachEffect = TalkAction(mehah.talkactions.attacheffect)
function attachEffect.onSay(player, words, param, type)
return processCommand(player, words, param, type, function(creature, effect)
creature:attachEffectById(tonumber(effect), false)
end)
end
table.insert(events, attachEffect)

local detachEffect = TalkAction(mehah.talkactions.detachEffect)
function detachEffect.onSay(player, words, param, type)
return processCommand(player, words, param, type, function(creature, effect)
creature:detachEffectById(tonumber(effect))
end)
end
table.insert(events, detachEffect)

local setShader = TalkAction(mehah.talkactions.playerSetShader)
function setShader.onSay(player, words, param, type)
return processCommand(player, words, param, type, function(creature, shader)
creature:setShader(shader)
end)
end
table.insert(events, setShader)

local mapShader = TalkAction(mehah.talkactions.mapShader)
function mapShader.onSay(player, words, param, type)
return processCommand(player, words, param, type, function(creature, shader)
if creature:getMapShader() ~= shader then
creature:setMapShader(shader, true)
end
end)
end
table.insert(events, mapShader)

for _, event in ipairs(events) do
event:accountType(ACCOUNT_TYPE_GOD)
event:access(true)
event:separator(" ")
event:register()
end
3 changes: 3 additions & 0 deletions data/world/forgotten-spawn.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?xml version="1.0"?>
<spawns>
<spawn centerx="94" centery="127" centerz="7" radius="1">
<monster name="Orc" x="0" y="0" z="7" spawntime="60" direction="2" />
</spawn>
</spawns>
2 changes: 1 addition & 1 deletion src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool ConfigManager::load()
integers[ConfigKeysInteger::WHITE_SKULL_TIME] = getGlobalInteger(L, "whiteSkullTime", 15 * 60);
integers[ConfigKeysInteger::STAIRHOP_DELAY] = getGlobalInteger(L, "stairJumpExhaustion", 2000);
integers[ConfigKeysInteger::EXP_FROM_PLAYERS_LEVEL_RANGE] = getGlobalInteger(L, "expFromPlayersLevelRange", 75);
integers[ConfigKeysInteger::MAX_PACKETS_PER_SECOND] = getGlobalInteger(L, "maxPacketsPerSecond", 25);
integers[ConfigKeysInteger::MAX_PACKETS_PER_SECOND] = getGlobalInteger(L, "maxPacketsPerSecond", 50);
integers[ConfigKeysInteger::SERVER_SAVE_NOTIFY_DURATION] = getGlobalInteger(L, "serverSaveNotifyDuration", 5);
integers[ConfigKeysInteger::YELL_MINIMUM_LEVEL] = getGlobalInteger(L, "yellMinimumLevel", 2);
integers[ConfigKeysInteger::MINIMUM_LEVEL_TO_SEND_PRIVATE] = getGlobalInteger(L, "minimumLevelToSendPrivate", 1);
Expand Down
2 changes: 1 addition & 1 deletion src/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef FS_CONST_H
#define FS_CONST_H

inline constexpr int32_t NETWORKMESSAGE_MAXSIZE = 24590;
inline constexpr int32_t NETWORKMESSAGE_MAXSIZE = 65500;

enum MagicEffectClasses : uint8_t
{
Expand Down
18 changes: 18 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,3 +1676,21 @@ std::optional<int64_t> Creature::getStorageValue(uint32_t key) const
}
return std::make_optional(it->second);
}


void Creature::attachEffectById(uint16_t id)
{
auto it = std::find(attachedEffectList.begin(), attachedEffectList.end(), id);
if (it != attachedEffectList.end()) return;

attachedEffectList.push_back(id);
g_game.sendAttachedEffect(this, id);
}
void Creature::detachEffectById(uint16_t id)
{
auto it = std::find(attachedEffectList.begin(), attachedEffectList.end(), id);
if (it == attachedEffectList.end()) return;

attachedEffectList.erase(it);
g_game.sendDetachEffect(this, id);
}
12 changes: 12 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ class Creature : virtual public Thing
int32_t maxTargetDist, bool fullPathSearch = true, bool clearSight = true,
int32_t maxSearchDist = 0) const;

std::string getShader() const { return shader; }
void setShader(const std::string& shaderName) { shader = shaderName; }


void incrementReferenceCounter() { ++referenceCounter; }
void decrementReferenceCounter()
{
Expand All @@ -353,6 +357,11 @@ class Creature : virtual public Thing

const auto& getDamageMap() const { return damageMap; }

void attachEffectById(uint16_t id);
void detachEffectById(uint16_t id);
const std::vector<uint16_t> getAttachedEffectList() const { return attachedEffectList; }


protected:
virtual bool useCacheMap() const { return false; }

Expand All @@ -371,6 +380,7 @@ class Creature : virtual public Thing

using CountMap = std::map<uint32_t, CountBlock_t>;
CountMap damageMap;
std::string shader;

std::list<Creature*> summons;
CreatureEventList eventsList;
Expand Down Expand Up @@ -409,6 +419,8 @@ class Creature : virtual public Thing
Direction direction = DIRECTION_SOUTH;
Skulls_t skull = SKULL_NONE;

std::vector<uint16_t> attachedEffectList;

bool localMapCache[mapWalkHeight][mapWalkWidth] = {{false}};
bool isInternalRemoved = false;
bool isMapLoaded = false;
Expand Down
49 changes: 49 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5345,3 +5345,52 @@ bool Game::reload(ReloadTypes_t reloadType)
}
return true;
}





void Game::sendAttachedEffect(const Creature* creature, uint16_t effectId)
{
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), false, true, 8, 8, 6, 6);
for (Creature* spectator : spectators) {
if (Player* spectatorPlayer = spectator->getPlayer()) {
if (spectatorPlayer->getOperatingSystem() >= CLIENTOS_OTCLIENT_LINUX) {
spectatorPlayer->sendAttachedEffect(creature, effectId);
}
} else {
spectator->attachEffectById(effectId);
}
}
}

void Game::sendDetachEffect(const Creature* creature, uint16_t effectId)
{
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), false, true, 8, 8, 6, 6);
for (Creature* spectator : spectators) {
if (Player* spectatorPlayer = spectator->getPlayer()) {
if (spectatorPlayer->getOperatingSystem() >= CLIENTOS_OTCLIENT_LINUX) {
spectatorPlayer->sendDetachEffect(creature, effectId);
}
} else {
spectator->detachEffectById(effectId);
}
}
}

void Game::updateCreatureShader(const Creature* creature)
{
SpectatorVec spectators;
map.getSpectators(spectators, creature->getPosition(), false, true, 8, 8, 6, 6);
for (Creature* spectator : spectators) {
if (Player* spectatorPlayer = spectator->getPlayer()) {
if (spectatorPlayer->getOperatingSystem() >= CLIENTOS_OTCLIENT_LINUX) {
spectatorPlayer->sendShader(creature, creature->getShader());
}
} else {
spectator->setShader(creature->getShader());
}
}
}
3 changes: 3 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ class Game
void addDistanceEffect(const Position& fromPos, const Position& toPos, uint8_t effect);
static void addDistanceEffect(const SpectatorVec& spectators, const Position& fromPos, const Position& toPos,
uint8_t effect);
void sendAttachedEffect(const Creature* creature, uint16_t effectId);
void sendDetachEffect(const Creature* creature, uint16_t effectId);
void updateCreatureShader(const Creature* creature);

void setAccountStorageValue(const uint32_t accountId, const uint32_t key, const int32_t value);
int32_t getAccountStorageValue(const uint32_t accountId, const uint32_t key) const;
Expand Down
71 changes: 71 additions & 0 deletions src/luacreature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,72 @@ int luaCreatureSendCreatureSquare(lua_State* L)
}
} // namespace


int luaCreatureAttachEffectById(lua_State* L)
{
// creature:attachEffectById(effectId, [temporary])
Creature* creature = getUserdata<Creature>(L, 1);
if (!creature) {
lua_pushnil(L);
return 1;
}

uint16_t id = getInteger<uint16_t>(L, 2);
bool temp = getBoolean(L, 3, false);

if (temp)
g_game.sendAttachedEffect(creature, id);
else
creature->attachEffectById(id);

return 1;
}

int luaCreatureDetachEffectById(lua_State* L)
{
// creature:detachEffectById(effectId)
Creature* creature = getUserdata<Creature>(L, 1);
if (!creature) {
lua_pushnil(L);
return 1;
}

uint16_t id = getInteger<uint16_t>(L, 2);
creature->detachEffectById(id);

return 1;
}

int luaCreatureGetShader(lua_State* L)
{
// creature:getShader()
const auto* creature = getUserdata<const Creature>(L, 1);
if (creature) {
pushString(L, creature->getShader());
} else {
lua_pushnil(L);
}

return 1;
}

int luaCreatureSetShader(lua_State* L)
{
// creature:setShader(shaderName)
auto* creature = getUserdata<Creature>(L, 1);
if (!creature) {
lua_pushnil(L);
return 1;
}

creature->setShader(getString(L, 2));
g_game.updateCreatureShader(creature);

pushBoolean(L, true);
return 1;
}


void LuaScriptInterface::registerCreature()
{
// Creature
Expand Down Expand Up @@ -1111,6 +1177,9 @@ void LuaScriptInterface::registerCreature()
registerMethod("Creature", "getLight", luaCreatureGetLight);
registerMethod("Creature", "setLight", luaCreatureSetLight);

registerMethod("Creature", "getShader", luaCreatureGetShader);
registerMethod("Creature", "setShader", luaCreatureSetShader);

registerMethod("Creature", "getSpeed", luaCreatureGetSpeed);
registerMethod("Creature", "getBaseSpeed", luaCreatureGetBaseSpeed);
registerMethod("Creature", "changeSpeed", luaCreatureChangeSpeed);
Expand Down Expand Up @@ -1161,4 +1230,6 @@ void LuaScriptInterface::registerCreature()
registerMethod("Creature", "setStorageValue", luaCreatureSetStorageValue);

registerMethod("Creature", "sendCreatureSquare", luaCreatureSendCreatureSquare);
registerMethod("Creature", "attachEffectById", luaCreatureAttachEffectById);
registerMethod("Creature", "detachEffectById", luaCreatureDetachEffectById);
}
15 changes: 15 additions & 0 deletions src/luagame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,21 @@ int luaGameCreateMonster(lua_State* L)
if (g_game.placeCreature(monster, position, extended, force, magicEffect)) {
pushUserdata<Monster>(L, monster);
setMetatable(L, -1, "Monster");

if (monster->rayosEffect() != 0) {
monster->attachEffectById(monster->rayosEffect());
}
if (monster->wignsEffect() != 0) {
monster->attachEffectById(monster->wignsEffect());
}
if (monster->auraEffect() != 0) {
monster->attachEffectById(monster->auraEffect());
}
if (monster->shaderEffect() != "") {
monster->setShader(monster->shaderEffect());
g_game.updateCreatureShader(monster);
}

} else {
delete monster;
lua_pushnil(L);
Expand Down
14 changes: 14 additions & 0 deletions src/luamonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ int luaMonsterCreate(lua_State* L)
if (monster) {
pushUserdata<Monster>(L, monster);
setMetatable(L, -1, "Monster");

if (monster->rayosEffect() != 0) {
monster->attachEffectById(monster->rayosEffect());
}
if (monster->wignsEffect() != 0) {
monster->attachEffectById(monster->wignsEffect());
}
if (monster->auraEffect() != 0) {
monster->attachEffectById(monster->auraEffect());
}
if (monster->shaderEffect() != "") {
monster->setShader(monster->shaderEffect());
g_game.updateCreatureShader(monster);
}
} else {
lua_pushnil(L);
}
Expand Down
Loading

0 comments on commit 8782a81

Please sign in to comment.