#include #include #include #include #include #include #include #include #include #include MagicService::MagicService(World& aWorld, entt::dispatcher& aDispatcher) noexcept : m_world(aWorld) { m_spellCastConnection = aDispatcher.sink>().connect<&MagicService::OnSpellCastRequest>(this); m_interruptCastConnection = aDispatcher.sink>().connect<&MagicService::OnInterruptCastRequest>(this); m_addTargetConnection = aDispatcher.sink>().connect<&MagicService::OnAddTargetRequest>(this); m_removeSpellConnection = aDispatcher.sink>().connect<&MagicService::OnRemoveSpellRequest>(this); } void MagicService::OnSpellCastRequest(const PacketEvent& acMessage) const noexcept { auto& message = acMessage.Packet; NotifySpellCast notify; notify.CasterId = message.CasterId; notify.SpellFormId = message.SpellFormId; notify.CastingSource = message.CastingSource; notify.IsDualCasting = message.IsDualCasting; notify.DesiredTarget = message.DesiredTarget; const auto entity = static_cast(message.CasterId); if (!GameServer::Get()->SendToPlayersInRange(notify, entity, acMessage.GetSender())) spdlog::error("{}: SendToPlayersInRange failed", __FUNCTION__); } void MagicService::OnInterruptCastRequest(const PacketEvent& acMessage) const noexcept { auto& message = acMessage.Packet; NotifyInterruptCast notify; notify.CasterId = message.CasterId; notify.CastingSource = message.CastingSource; const auto entity = static_cast(message.CasterId); if (!GameServer::Get()->SendToPlayersInRange(notify, entity, acMessage.GetSender())) spdlog::error("{}: SendToPlayersInRange failed", __FUNCTION__); } void MagicService::OnAddTargetRequest(const PacketEvent& acMessage) const noexcept { auto& message = acMessage.Packet; NotifyAddTarget notify; notify.TargetId = message.TargetId; notify.CasterId = message.CasterId; notify.SpellId = message.SpellId; notify.EffectId = message.EffectId; notify.Magnitude = message.Magnitude; notify.IsDualCasting = message.IsDualCasting; notify.ApplyHealPerkBonus = message.ApplyHealPerkBonus; notify.ApplyStaminaPerkBonus = message.ApplyStaminaPerkBonus; const auto entity = static_cast(message.TargetId); if (!GameServer::Get()->SendToPlayersInRange(notify, entity, acMessage.GetSender())) spdlog::error("{}: SendToPlayersInRange failed", __FUNCTION__); } void MagicService::OnRemoveSpellRequest(const PacketEvent& acMessage) const noexcept { const auto& message = acMessage.Packet; NotifyRemoveSpell notify; notify.TargetId = message.TargetId; notify.SpellId = message.SpellId; //spdlog::info(__FUNCTION__ ": TargetId: {}, Spell baseId: {}", notify.TargetId, notify.SpellId.BaseId); const auto entity = static_cast(message.TargetId); if (!GameServer::Get()->SendToPlayersInRange(notify, entity, acMessage.GetSender())) spdlog::error("{}: SendToPlayersInRange failed", __FUNCTION__); }