Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Nov 10, 2024
1 parent e632db2 commit 1fe02b0
Show file tree
Hide file tree
Showing 155 changed files with 7,003 additions and 7,317 deletions.
5 changes: 3 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "canary_server.hpp"

#include "core.hpp"
#include "config/configmanager.hpp"
#include "creatures/npcs/npcs.hpp"
#include "creatures/players/grouping/familiars.hpp"
Expand All @@ -31,8 +32,7 @@
#include "server/network/protocol/protocollogin.hpp"
#include "server/network/protocol/protocolstatus.hpp"
#include "server/network/webhook/webhook.hpp"

#include "core.hpp"
#include "creatures/players/vocations/vocation.hpp"

CanaryServer::CanaryServer(
Logger &logger,
Expand Down Expand Up @@ -322,6 +322,7 @@ void CanaryServer::initializeDatabase() {
&& !DatabaseManager::optimizeTables()) {
logger.debug("No tables were optimized");
}
g_logger().info("Database connection established!");
}

void CanaryServer::loadModules() {
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include "creatures/monsters/monster.hpp"
#include "creatures/monsters/monsters.hpp"
#include "creatures/players/grouping/party.hpp"
#include "creatures/players/player.hpp"
#include "creatures/players/imbuements/imbuements.hpp"
#include "creatures/players/wheel/player_wheel.hpp"
#include "game/game.hpp"
#include "game/scheduling/dispatcher.hpp"
#include "io/iobestiary.hpp"
#include "io/ioprey.hpp"
#include "creatures/players/vocations/vocation.hpp"
#include "items/weapons/weapons.hpp"
#include "lib/metrics/metrics.hpp"
#include "lua/callbacks/event_callback.hpp"
Expand Down
98 changes: 69 additions & 29 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#include "game/game.hpp"
#include "lua/global/lua_variant.hpp"
#include "lua/scripts/lua_environment.hpp"
#include "lua/scripts/luascript.hpp"
#include "lua/scripts/scripts.hpp"
#include "lib/di/container.hpp"

std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };
Expand Down Expand Up @@ -156,7 +157,7 @@ bool Spells::registerRuneLuaEvent(const std::shared_ptr<RuneSpell> &rune) {
"[{}] duplicate registered rune with id: {}, for script: {}",
__FUNCTION__,
id,
rune->getScriptInterface()->getLoadingScriptName()
rune->getRuneSpellScriptInterface()->getLoadingScriptName()
);
}
return inserted;
Expand Down Expand Up @@ -277,29 +278,45 @@ Position Spells::getCasterPosition(const std::shared_ptr<Creature> &creature, Di
return getNextPosition(dir, creature->getPosition());
}

LuaScriptInterface* BaseSpell::getScriptInterface() const {
return &g_scripts().getScriptInterface();
}

bool BaseSpell::loadScriptId() {
LuaScriptInterface &luaInterface = g_scripts().getScriptInterface();
m_spellScriptId = luaInterface.getEvent();
if (m_spellScriptId == -1) {
g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName());
return false;
}

return true;
}

int32_t BaseSpell::getScriptId() const {
return m_spellScriptId;
}

void BaseSpell::setScriptId(int32_t newScriptId) {
m_spellScriptId = newScriptId;
}

bool BaseSpell::isLoadedScriptId() const {
return m_spellScriptId != 0;
}

CombatSpell::CombatSpell(const std::shared_ptr<Combat> &newCombat, bool newNeedTarget, bool newNeedDirection) :
Script(&g_spells().getScriptInterface()),
m_combat(newCombat),
needDirection(newNeedDirection),
needTarget(newNeedTarget) {
// Empty
}

bool CombatSpell::loadScriptCombat() {
m_combat = g_luaEnvironment().getCombatObject(g_luaEnvironment().lastCombatId);
return m_combat != nullptr;
}

std::shared_ptr<Combat> CombatSpell::getCombat() const {
return m_combat;
}

std::string CombatSpell::getScriptTypeName() const {
return "onCastSpell";
}

bool CombatSpell::castSpell(const std::shared_ptr<Creature> &creature) {
if (isLoadedCallback()) {
if (isLoadedScriptId()) {
LuaVariant var;
var.type = VARIANT_POSITION;

Expand Down Expand Up @@ -346,7 +363,7 @@ bool CombatSpell::castSpell(const std::shared_ptr<Creature> &creature, const std
return false;
}

if (isLoadedCallback()) {
if (isLoadedScriptId()) {
LuaVariant var;
if (combat->hasArea()) {
var.type = VARIANT_POSITION;
Expand Down Expand Up @@ -412,6 +429,8 @@ bool CombatSpell::executeCastSpell(const std::shared_ptr<Creature> &creature, co
return getScriptInterface()->callFunction(2);
}

Spell::Spell() = default;

bool Spell::playerSpellCheck(const std::shared_ptr<Player> &player) const {
if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) {
return false;
Expand Down Expand Up @@ -1030,6 +1049,8 @@ void Spell::setLockedPZ(bool b) {
pzLocked = b;
}

InstantSpell::InstantSpell() = default;

bool InstantSpell::playerCastInstant(const std::shared_ptr<Player> &player, std::string &param) const {
if (!playerSpellCheck(player)) {
return false;
Expand Down Expand Up @@ -1161,10 +1182,6 @@ bool InstantSpell::canThrowSpell(const std::shared_ptr<Creature> &creature, cons
return true;
}

std::string InstantSpell::getScriptTypeName() const {
return "onCastSpell";
}

bool InstantSpell::castSpell(const std::shared_ptr<Creature> &creature) {
LuaVariant var;
var.instantName = getName();
Expand Down Expand Up @@ -1294,6 +1311,33 @@ bool InstantSpell::canCast(const std::shared_ptr<Player> &player) const {
return false;
}

LuaScriptInterface* RuneSpell::getRuneSpellScriptInterface() const {
return &g_scripts().getScriptInterface();
}

bool RuneSpell::loadRuneSpellScriptId() {
LuaScriptInterface &luaInterface = g_scripts().getScriptInterface();
m_runeSpellScriptId = luaInterface.getEvent();
if (m_runeSpellScriptId == -1) {
g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName());
return false;
}

return true;
}

int32_t RuneSpell::getRuneSpellScriptId() const {
return m_runeSpellScriptId;
}

void RuneSpell::setRuneSpellScriptId(int32_t newScriptId) {
m_runeSpellScriptId = newScriptId;
}

bool RuneSpell::isRuneSpellLoadedScriptId() const {
return m_runeSpellScriptId != 0;
}

ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr<Player> &player, const Position &toPos) {
if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) {
return RETURNVALUE_CANNOTUSETHISOBJECT;
Expand Down Expand Up @@ -1329,7 +1373,7 @@ bool RuneSpell::executeUse(const std::shared_ptr<Player> &player, const std::sha
}

// If script not loaded correctly, return
if (!isLoadedCallback()) {
if (!isRuneSpellLoadedScriptId()) {
return false;
}

Expand Down Expand Up @@ -1391,13 +1435,9 @@ bool RuneSpell::castSpell(const std::shared_ptr<Creature> &creature, const std::
return internalCastSpell(creature, var, false);
}

std::string RuneSpell::getScriptTypeName() const {
return "onCastSpell";
}

bool RuneSpell::internalCastSpell(const std::shared_ptr<Creature> &creature, const LuaVariant &var, bool isHotkey) const {
bool result;
if (isLoadedCallback()) {
if (isRuneSpellLoadedScriptId()) {
result = executeCastSpell(creature, var, isHotkey);
} else {
result = false;
Expand All @@ -1415,11 +1455,11 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr<Creature> &creature, cons
}

ScriptEnvironment* env = LuaEnvironment::getScriptEnv();
env->setScriptId(getScriptId(), getScriptInterface());
env->setScriptId(getRuneSpellScriptId(), getRuneSpellScriptInterface());

lua_State* L = getScriptInterface()->getLuaState();
lua_State* L = getRuneSpellScriptInterface()->getLuaState();

getScriptInterface()->pushFunction(getScriptId());
getRuneSpellScriptInterface()->pushFunction(getRuneSpellScriptId());

LuaScriptInterface::pushUserdata<Creature>(L, creature);
LuaScriptInterface::setCreatureMetatable(L, -1, creature);
Expand All @@ -1428,7 +1468,7 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr<Creature> &creature, cons

LuaScriptInterface::pushBoolean(L, isHotkey);

return getScriptInterface()->callFunction(3);
return getRuneSpellScriptInterface()->callFunction(3);
}

bool RuneSpell::isInstant() const {
Expand Down
41 changes: 27 additions & 14 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
#pragma once

#include "lua/creature/actions.hpp"
#include "lua/scripts/scripts.hpp"

enum class WheelSpellBoost_t : uint8_t;
enum class WheelSpellGrade_t : uint8_t;

class InstantSpell;
class RuneSpell;
class Spell;
class Combat;
class Player;
class Creature;
class LuaScriptInterface;

struct LuaVariant;
struct Position;

using VocSpellMap = std::map<uint16_t, bool>;

class Spells final : public Scripts {
class Spells {
public:
Spells();
~Spells();
Expand Down Expand Up @@ -78,11 +82,20 @@ class BaseSpell {
virtual bool castSpell(const std::shared_ptr<Creature> &creature) = 0;
virtual bool castSpell(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Creature> &target) = 0;

LuaScriptInterface* getScriptInterface() const;
bool loadScriptId();
int32_t getScriptId() const;
void setScriptId(int32_t newScriptId);
bool isLoadedScriptId() const;

SoundEffect_t soundImpactEffect = SoundEffect_t::SILENCE;
SoundEffect_t soundCastEffect = SoundEffect_t::SPELL_OR_RUNE;

protected:
int32_t m_spellScriptId {};
};

class CombatSpell final : public Script, public BaseSpell, public std::enable_shared_from_this<CombatSpell> {
class CombatSpell final : public BaseSpell, public std::enable_shared_from_this<CombatSpell> {
public:
// Constructor
CombatSpell(const std::shared_ptr<Combat> &newCombat, bool newNeedTarget, bool newNeedDirection);
Expand All @@ -97,12 +110,9 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh
// Scripting spell
bool executeCastSpell(const std::shared_ptr<Creature> &creature, const LuaVariant &var) const;

bool loadScriptCombat();
std::shared_ptr<Combat> getCombat() const;

private:
std::string getScriptTypeName() const override;

std::shared_ptr<Combat> m_combat;

bool needDirection;
Expand All @@ -111,7 +121,7 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh

class Spell : public BaseSpell {
public:
Spell() = default;
Spell();

[[nodiscard]] const std::string &getName() const;
void setName(std::string n);
Expand Down Expand Up @@ -267,10 +277,9 @@ class Spell : public BaseSpell {
friend class SpellFunctions;
};

class InstantSpell final : public Script, public Spell {
class InstantSpell final : public Spell {
public:
using Script::Script;

InstantSpell();
bool playerCastInstant(const std::shared_ptr<Player> &player, std::string &param) const;

bool castSpell(const std::shared_ptr<Creature> &creature) override;
Expand All @@ -294,8 +303,6 @@ class InstantSpell final : public Script, public Spell {
bool canThrowSpell(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Creature> &target) const;

private:
[[nodiscard]] std::string getScriptTypeName() const override;

bool needDirection = false;
bool hasParam = false;
bool hasPlayerNameParam = false;
Expand All @@ -307,6 +314,12 @@ class RuneSpell final : public Action, public Spell {
public:
using Action::Action;

LuaScriptInterface* getRuneSpellScriptInterface() const;
bool loadRuneSpellScriptId();
int32_t getRuneSpellScriptId() const;
void setRuneSpellScriptId(int32_t newScriptId);
bool isRuneSpellLoadedScriptId() const;

ReturnValue canExecuteAction(const std::shared_ptr<Player> &player, const Position &toPos) override;
bool hasOwnErrorHandler() override;
std::shared_ptr<Thing> getTarget(const std::shared_ptr<Player> &, const std::shared_ptr<Creature> &targetCreature, const Position &, uint8_t) const override;
Expand All @@ -326,10 +339,10 @@ class RuneSpell final : public Action, public Spell {
void setCharges(uint32_t c);

private:
[[nodiscard]] std::string getScriptTypeName() const override;

bool internalCastSpell(const std::shared_ptr<Creature> &creature, const LuaVariant &var, bool isHotkey) const;

int32_t m_runeSpellScriptId = 0;

uint16_t runeId = 0;
uint32_t charges = 0;
bool hasCharges = false;
Expand Down
Loading

0 comments on commit 1fe02b0

Please sign in to comment.