void CastHandle() {
// we got the casting request cookies, request immobilize/memorize if needed.
if(CastF==FLAG_REQUEST) {
if(DEBUGGING)
WriteChatf("[%d] MQ2Cast:[Casting]: Request.",(long)GetTickCount());
CastF=FLAG_PROGRESS1;
if(StopF==FLAG_COMPLETE) StopF=DONE_SUCCESS;
if(StopF==FLAG_COMPLETE && CastT>100 && !BardClass()) StopF=FLAG_REQUEST;
if(MemoF!=FLAG_COMPLETE) MemoHandle();
else if(StopF!=FLAG_COMPLETE) StopHandle();
}
// waiting on the casting results to take actions.
if(CastF==FLAG_PROGRESS3 && CastingE!=DONE_PROGRESS) {
CastF=FLAG_PROGRESS4;
if(CastR) CastR--;
if(CastR) {
if((CastingE==CAST_SUCCESS && CastW!=RECAST_LAND) ||
(CastingE==CAST_COLLAPSE) ||
(CastingE==CAST_FIZZLE) ||
(CastingE==CAST_INTERRUPTED) ||
(CastingE==CAST_RECOVER) ||
(CastingE==CAST_RESIST)) {
if(DEBUGGING)
WriteChatf("[%d] MQ2Cast:[Casting]: AutoRecast [%d].",(long)GetTickCount(),CastingE);
if(CastW!=RECAST_ZERO && !TargC) TargC=(pTarget)?((PSPAWNINFO)pTarget)->SpawnID:0;
[COLOR="Red"]CastM=(long)GetTickCount()+DELAY_CAST;[/COLOR]
CastF=FLAG_REQUEST;
}
}
}
// casting is over, grab latest casting results and exit.
if(CastF==FLAG_PROGRESS4) {
if(CastE>CastingE) CastingE=CastE;
CastF=FLAG_COMPLETE;
}
// evaluate if we are taking too long, or immobilize/memorize event failed.
if(CastF!=FLAG_COMPLETE) {
[COLOR="Red"]if(StopE==DONE_ABORTED || MemoE==DONE_ABORTED || (long)GetTickCount()>CastM) {[/COLOR]
WriteChatf("[%d] MQ2Cast:[Casting]: Aborting! (%s)",(long)GetTickCount(), StopE==DONE_ABORTED?"StopE":(MemoE==DONE_ABORTED?"MemoE":"CastM"));
CastF=FLAG_PROGRESS4;
CastE=CAST_NOTREADY;
}
}
// waiting for opportunity to start casting, end if conditions not favorables.
if(CastF==FLAG_PROGRESS1) {
if(pCastingWnd && (PCSIDLWND)pCastingWnd->dShow) return; // casting going on
CastingC=CastS->ID;
CastF=FLAG_PROGRESS4;
if(TargC && (!pTarget || (pTarget && ((PSPAWNINFO)pTarget)->SpawnID!=TargC))) {
if(CastW==RECAST_DEAD) CastE=CAST_NOTARGET;
else if(CastW==RECAST_LAND) CastE=CAST_ABORTED;
} else if(Invisible && GetCharInfo()->pSpawn->HideMode) { CastE=CAST_INVISIBLE;
} else if(GetCharInfo()->Stunned) { CastE=CAST_STUNNED;
} else if(StopF!=FLAG_COMPLETE || MemoF!=FLAG_COMPLETE) { CastF=FLAG_PROGRESS1;
} else {
[COLOR="Red"]long TimeReady=SpellTimer(CastK,CastI); // get estimate time before it's ready.
if(TimeReady>3000) CastE=CAST_NOTREADY; // if estimate higher then 3 seconds aborts.[/COLOR]
else if(!TimeReady) CastF=FLAG_PROGRESS2; // estimate says it's ready so cast it
else CastF=FLAG_PROGRESS1; // otherwise give it some time to be ready.
}
}
// we got the final approbation to cast, so lets do it.
if(CastF==FLAG_PROGRESS2) {
if(DEBUGGING)
WriteChatf("[%d] MQ2Cast:[Casting]: Cast.",(long)GetTickCount());
Success(CastS);
ItemHandle(true);
CastF=FLAG_PROGRESS3;
CastE=DONE_PROGRESS;
CastingT=(long)GetTickCount()+CastT+250+(pConnection->Last)*4;
CastingE=DONE_PROGRESS;
CastingC=CastS->ID;
if((long)GetCharInfo()->pSpawn->CastingData.SpellID>0) {
CastingX=(CastingE<CAST_SUCCESS)?CAST_SUCCESS:CastingE;
CastingL=CastingC;
if(CastK==TYPE_SPELL) Execute("/multiline ; /stopsong ; /cast \"%s\"",CastN);
else if(CastK==TYPE_ITEM) {
if(!BardBeta) {
if (!stricmp(CastN,"Fellowship Registration Insignia"))
Execute("/multiline ; /stopsong ; /nomodkey /itemnotify ${FindItem[=%s].InvSlot} rightmouseup",CastN);
else
Execute("/multiline ; /stopsong ; /nomodkey /cast item \"%s\"",CastN);
}
else {
if (!stricmp(CastN,"Fellowship Registration Insignia"))
Execute("/nomodkey /itemnotify ${FindItem[=%s].InvSlot} rightmouseup",CastN);
else
Execute("/nomodkey /cast item \"%s\"",CastN);
}
}
else if(CastK==TYPE_ALT) {
if(!BardBeta)
Execute("/multiline ; /stopsong ; /alt activate %d",((PALTABILITY)CastI)->ID);
else
Execute("/alt activate %d",((PALTABILITY)CastI)->ID);
}
} else {
if(CastK==TYPE_SPELL) Cast("\"%s\"",CastN);
else if(CastK==TYPE_ITEM) {
if (!stricmp(CastN,"Fellowship Registration Insignia")) Execute("/nomodkey /itemnotify ${FindItem[=%s].InvSlot} rightmouseup",CastN);
else Execute("/nomodkey /cast item \"%s\"",CastN);
}
else if(CastK==TYPE_ALT) Execute("/alt activate %d",((PALTABILITY)CastI)->ID);
}
}
}