Commit 304a36b6 authored by Dustin Niehoff's avatar Dustin Niehoff

[MQ2Cast] Fixed and tightened timeouts.

parent 9de9c571
......@@ -1097,11 +1097,12 @@ PLUGIN_API VOID OnPulse(VOID) {
auto pMySpawn = GetCharInfo()->pSpawn;
// check the timeout first. We know we aren't actually casting anything right now
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[OnPulse]: Command Executing.", MQGetTickCount64()); }
if ((pMySpawn && pMySpawn->TimeStamp < CastingState::instance().getTimeout()) || (CastingState::instance().getCurrentID() == NOID && CastingState::instance().getCmdSize() > 0)) {
if ((pMySpawn && pMySpawn->TimeStamp < CastingState::instance().getTimeout()) || (CastingState::instance().getCurrentResult() == CastResult::Idle && CastingState::instance().getCmdSize() > 0)) {
// we should be doing something right now, so let's do it.
if (auto cmd = CastingState::instance().getCmd()) {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[OnPulse]: Running Command Function.", MQGetTickCount64()); }
cmd->execute(); // do the function
CastingState::instance().updateTimeout();
}
} else if (!pMySpawn || pMySpawn->TimeStamp > CastingState::instance().getTimeout()) {
// the assumption here is that we had sufficient time to cast the spell, so we probably actually cast it
......@@ -1412,7 +1413,7 @@ bool CastingState::isCastableReady(PCHAR ID) {
}
const PSPELL CastingState::findMyRank(const PSPELL pSpell, const CastType cType) {
if (cType == CastType::AltAbility || (cType == CastType::None && GetAAIndexByName(pSpell->Name) > 0)) {
if (cType == CastType::AltAbility || (cType == CastType::None && GetAAIndexByName(pSpell->Name) > 0) || pSpell->SpellGroup == 0) {
return pSpell;
}
......@@ -1473,26 +1474,27 @@ ULONGLONG CastingState::updateTimeout() {
if (auto pMySpawn = pMyChar->pSpawn) {
LastTimestamp = pMySpawn->TimeStamp;
// TODO: Add in lag buffer to a configurable variable and make more extensive use of it
if (pMySpawn->CastingData.SpellETA > 0) {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: Found Spell ETA %d -> TimeStamp %d.", MQGetTickCount64(), pMySpawn->CastingData.SpellETA, pMySpawn->TimeStamp); }
// TODO: potentially account for lag here (+ MQGetTickCount64() + 450 + (pConnection->Last) * 4;)
Timeout = pMySpawn->TimeStamp + pMySpawn->CastingData.SpellETA;
Timeout = pMySpawn->TimeStamp + pMySpawn->CastingData.SpellETA + 1000;
} else if (getCurrentID() != NOID) {
if (auto pSpell = GetSpellByID(getCurrentID())) {
if (getCmdType() == CastType::Memorize) {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: Memming TimeStamp %d.", MQGetTickCount64(), pMySpawn->TimeStamp); }
// TODO: Can I get a memorization time? -- as long as we don't LD (timestamp stays more frequent than 1s), we will recheck this every pulse
Timeout = pMySpawn->TimeStamp + 1000;
// TODO: Can I get a memorization time?
Timeout = pMySpawn->TimeStamp + 5000;
} else {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: Casting Time %d TimeStamp %d.", MQGetTickCount64(), pSpell->CastTime, pMySpawn->TimeStamp); }
Timeout = pMySpawn->TimeStamp + pSpell->CastTime;
Timeout = pMySpawn->TimeStamp + pSpell->CastTime + 1000;
}
} else {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: No Spell Detected TimeStamp %d.", MQGetTickCount64(), pMySpawn->TimeStamp); }
Timeout = pMySpawn->TimeStamp - 100;
}
} else {
// if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: No Spell Casting TimeStamp %d.", MQGetTickCount64(), pMySpawn->TimeStamp); }
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Timeout]: No Spell Casting TimeStamp %d.", MQGetTickCount64(), pMySpawn->TimeStamp); }
// -100 to guarantee its in the past
Timeout = pMySpawn->TimeStamp - 100;
}
......
......@@ -287,7 +287,7 @@ namespace MQ2Cast {
const std::list<const ImmediateCommand*> PostQueue = std::list<const ImmediateCommand*>()
);
DWORD getID() const { return GemSlot; }
DWORD getID() const { return NOID; }
void execute() const;
};
......
......@@ -8,6 +8,7 @@ using namespace MQ2Cast;
MemCommand* MemCommand::Create(const PCHAR ID, const int GemSlot, const std::list<const ImmediateCommand*> PreQueue, const std::list<const ImmediateCommand*> PostQueue) {
if (!ID) return nullptr;
return new MemCommand(GemSlot, GetSpellByName(ID), PreQueue, PostQueue);
}
......@@ -34,7 +35,7 @@ void MemCommand::execute() const {
CHAR szBuffer[MAX_STRING] = { 0 };
sprintf_s(szBuffer, "%d \"%s\"", GemSlot, Spell->Name);
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Memorize]: Cast = %s : szBuffer %s -- MemSpell()", MQGetTickCount64(), GetCharInfo()->pSpawn, szBuffer); }
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Memorize]: Cast = %d : szBuffer %s -- MemSpell()", MQGetTickCount64(), GetCharInfo()->pSpawn, szBuffer); }
// set up a spellset that is all empty but the one we want
SPELLFAVORITE CastSpellFavorite;
......@@ -88,6 +89,7 @@ SpellCommand* SpellCommand::Create(const PCHAR ID, const int GemSlot, const bool
if (auto pFoundSpell = GetSpellByName(ID)) {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Cast]: Found Spell: \"%s\".", MQGetTickCount64(), pFoundSpell->Name); }
if (auto pSpell = CastingState::instance().findMyRank(pFoundSpell, CastType::Spell)) {
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Cast]: Found Rank: \"%s\".", MQGetTickCount64(), pSpell->Name); }
int gemIdx = GetGem(pSpell->ID);
if (gemIdx != -1) {
// we have the spell memorized
......
......@@ -19,7 +19,6 @@ void CastingState::pushCmd(const CastCommand* cmd) {
// last I heard, MSVC didn't do emplace very well, so just use push
if (DEBUGGING) { WriteChatf("[%I64u] MQ2Cast:[Queue]: Pushing a Command of Type %d to the Queue.", MQGetTickCount64(), cmd->Type); }
cmdQueue.push(cmd);
updateTimeout();
}
const CastCommand* CastingState::getCmd() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment