Initial Upload
This commit is contained in:
commit
c49e39b70b
3
conf/mod-dmf-always.conf.dist
Normal file
3
conf/mod-dmf-always.conf.dist
Normal file
@ -0,0 +1,3 @@
|
||||
ModDMFAlways.Enable = 1
|
||||
ModDMFAlways.EventIDs = "4,71,376"
|
||||
ModDMFAlways.ReassertInterval = 600000
|
||||
119
src/mod_dmf_always.cpp
Normal file
119
src/mod_dmf_always.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
#include "Config.h"
|
||||
#include "GameEventMgr.h"
|
||||
#include "Log.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "World.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool sEnabled = true;
|
||||
std::vector<uint32> sEventIds;
|
||||
uint32 sTick = 0;
|
||||
uint32 sInterval = 600000;
|
||||
|
||||
std::vector<uint32> ParseIds(std::string raw)
|
||||
{
|
||||
std::vector<uint32> out;
|
||||
std::stringstream ss(raw);
|
||||
std::string tok;
|
||||
while (std::getline(ss, tok, ','))
|
||||
{
|
||||
tok.erase(std::remove_if(tok.begin(), tok.end(), ::isspace), tok.end());
|
||||
if (!tok.empty())
|
||||
out.push_back(uint32(std::stoul(tok)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void ForceStart(uint32 id)
|
||||
{
|
||||
if (!sGameEventMgr->IsActiveEvent(id))
|
||||
{
|
||||
sGameEventMgr->StartEvent(id, true); // force start
|
||||
LOG_INFO("module", "mod-dmf-always: started event {}", id);
|
||||
}
|
||||
}
|
||||
|
||||
void EnsureAll()
|
||||
{
|
||||
for (uint32 id : sEventIds)
|
||||
ForceStart(id);
|
||||
}
|
||||
}
|
||||
|
||||
class DMFAlways_Script : public WorldScript
|
||||
{
|
||||
public:
|
||||
DMFAlways_Script() : WorldScript("DMFAlways_Script") { }
|
||||
|
||||
void OnAfterConfigLoad(bool) override
|
||||
{
|
||||
sEnabled = sConfigMgr->GetOption<bool>("ModDMFAlways.Enable", true);
|
||||
sInterval = sConfigMgr->GetOption<uint32>("ModDMFAlways.ReassertInterval", 60000);
|
||||
|
||||
std::string ids = sConfigMgr->GetOption<std::string>("ModDMFAlways.EventIDs", "4,71,376");
|
||||
sEventIds = ParseIds(ids);
|
||||
|
||||
if (sEnabled)
|
||||
{
|
||||
LOG_INFO("module", "mod-dmf-always: enabled. Keeping events active: {}", ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("module", "mod-dmf-always: disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
void OnStartup() override
|
||||
{
|
||||
if (!sEnabled)
|
||||
return;
|
||||
|
||||
EnsureAll();
|
||||
}
|
||||
|
||||
void OnUpdate(uint32 diff) override
|
||||
{
|
||||
if (!sEnabled)
|
||||
return;
|
||||
|
||||
sTick += diff;
|
||||
if (sTick >= sInterval)
|
||||
{
|
||||
sTick = 0;
|
||||
EnsureAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DMFAlways_EventHook : public ScriptObject
|
||||
{
|
||||
public:
|
||||
DMFAlways_EventHook() : ScriptObject("DMFAlways_EventHook") { }
|
||||
|
||||
void OnGameEventStart(uint16 eventId) override
|
||||
{
|
||||
if (!sEnabled) return;
|
||||
if (std::find(sEventIds.begin(), sEventIds.end(), eventId) != sEventIds.end())
|
||||
EnsureAll();
|
||||
}
|
||||
|
||||
void OnGameEventStop(uint16 eventId) override
|
||||
{
|
||||
if (!sEnabled) return;
|
||||
if (std::find(sEventIds.begin(), sEventIds.end(), eventId) != sEventIds.end())
|
||||
{
|
||||
ForceStart(eventId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_mod_dmf_always()
|
||||
{
|
||||
new DMFAlways_Script();
|
||||
new DMFAlways_EventHook();
|
||||
}
|
||||
6
src/mod_dmf_always_loader.cpp
Normal file
6
src/mod_dmf_always_loader.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
void AddSC_mod_dmf_always();
|
||||
|
||||
void Addmod_dmf_alwaysScripts()
|
||||
{
|
||||
AddSC_mod_dmf_always();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user