conversion of spell_routines.inc for ISXEQ
Posted: Mon Apr 25, 2005 6:16 pm
Still a work in progress, but thought I'd post it for comment/derision/yuks.
Code: Select all
function sr_cast(string spellName, string spellType, timer giveupTimer, string functocall)
{
if "!${Variable[sr_casting]} "
declare sr_casting bool script 0
if "!${Variable[sr_cast_return]}"
declare sr_cast_return string script CAST_SUCCESS
if "!${Variable[spellType]}"
declare spellType string local spell
if "!${Variable[sr_giveupTimer]}"
declare sr_giveupTimer timer script
if "!${Variable[sr_GUTvalid]}"
declare sr_GUTvalid bool script
if "!${Variable[sr_fizzleIsInterrupt]}"
declare sr_fizzleIsInterrupt bool script false
if "!${Variable[sr_itemRefreshTime]}"
declare sr_itemRefreshTime float script 0
if "!${Variable[sr_castEndTime]}"
declare sr_castEndTime timer script 0
if "${spellType.Equal[alt]}"
call sr_cast_alt "${spellName}" ${giveupTimer} ${functocall}
if "${spellType.Equal[item]}"
call sr_cast_item "${spellName}" ${giveupTimer} ${functocall}
if "${spellType.Left[3].Equal[gem]}"
call sr_cast_spell "${spellName}" ${spellType.Right[1]} ${giveupTimer} ${functocall}
if "${spellType.Equal[spell]}"
call sr_cast_spell "${spellName}" 0 ${giveupTimer} ${functocall}
return ${sr_cast_return}
}
function sr_cast_spell(string spellName, int gem, timer giveupTimer, string functocall)
{
varset sr_GUTvalid false
varset sr_cast_return CAST_SUCCESS
varset sr_giveupTimer ${giveupTimer}
if "${sr_giveupTimer}"
varset sr_GUTvalid true
else
varset sr_giveupTimer 60s
if "${Me.Invis} && ${noInvis}"
{
varset sr_cast_return CAST_INVIS
return CAST_INVIS
}
do
{
WaitFrame
}
while "${Me.Casting.ID} || ${Me.Speed} || ${Me.Moving} "
If "${Me.Ducking}"
keypress duck
If "!${Me.Standing}"
EQExecute /stand
if "${Window[SpellBookWnd].Open}"
keypress spellbook
If "!${Me.Book[${spellName}]}"
{
Echo Spell: "${spellName}" was not found in your book
varset sr_cast_return CAST_UNKNOWNSPELL
Return "CAST_UNKNOWNSPELL"
}
if "!${Me.Gem[${spellName}]}"
{
if "${gem}==0"
{
varset sr_cast_return CAST_NOTMEMMED
return ${sr_cast_return}
}
memspell ${gem} "${spellName}"
wait 10 ${Window[SpellBookWnd].Open}
do
{
if ( ${sr_GUTvalid} )
{
if ( !${sr_giveupTimer} )
return CAST_TIMEOUT
}
WaitFrame
}
while "${Window[SpellBookWnd].Open}"
wait 10 ${Me.Gem[${spellName}]}
if "!${Me.Gem[${spellName}]}"
{
echo Spell Memorization interrupted
return "CAST_INTERRUPTED"
}
if "${sr_GUTvalid}"
{
varset sr_giveupTimer ${sr_giveupTimer.OriginalValue}
; echo sr_giveupTimer is ${sr_giveupTimer}
}
}
do
{
if "${sr_GUTvalid}"
{
; echo waiting for ready, sr_giveupTimer is ${sr_giveupTimer}
if "!${sr_giveupTimer}"
return CAST_TIMEOUT
}
WaitFrame
}
while "!${Me.SpellReady[${spellName}]} && ${sr_giveupTimer}"
call sr_cast_add_triggers
cast ${spellName}
do
{
WaitFrame
if "${Me.Casting.ID}"
{
varcalc sr_castEndTime ${Me.Casting.MyCastTime}*10
echo Casting: ${Me.Casting.Name}${If[!${Me.Casting.TargetType.Equal[PB AE]} && !${Me.Casting.TargetType.Equal[self]} && ${Target.ID}, on >> ${Target.CleanName} <<,]}
}
call sr_waitcast ${functocall}
if "${sr_cast_return.Equal[CAST_FIZZLE]}"
{
echo sr_cast_spell Cast fizzled, recasting
varset sr_cast_return CAST_SUCCESS
cast ${spellName}
wait 1 ${Me.Casting.ID}
}
}
while ${Me.Casting.ID}
WaitFrame
ExecuteQueued
call sr_cast_remove_triggers
return ${sr_cast_return}
}
function sr_cast_item(string spellName, timer giveupTimer, string functocall)
{
declare sr_swapItemBack bool local false
declare sr_slotName int local
declare sr_oldItemName string local
declare sr_slotID int local
declare sr_oldSlotID int local
varset sr_GUTvalid false
varset sr_cast_return CAST_SUCCESS
varset sr_giveupTimer ${giveupTimer}
if "${sr_giveupTimer}"
varset sr_GUTvalid true
else
varset sr_giveupTimer 60s
; echo sr_GUTValid is ${sr_GUTvalid}, sr_giveupTimer is ${sr_giveupTimer}, functocall is ${functocall}
if "!${FindItem[${spellName}].InvSlot}"
{
echo Cannot find item: ${spellName}
varset sr_cast_return CAST_UNKNOWNSPELL
return CAST_UNKNOWNSPELL
}
if "${FindItem[${spellName}].InvSlot}>29"
{
echo Cant cast item that isn't equipped or in main invslot
varset sr_cast_return CAST_FAILED
return CAST_FAILED
; TODO implement item swapping
varset sr_swapItemBack true
if "${FindItem[${spellName}].WornSlot[1]}"
{
varset sr_slotName ${FindItem[${spellName}].WornSlot[1]}
}
else
{
varset sr_slotName 29
}
varset sr_slotID ${InvSlot[${sr_slotName}].ID}
varset sr_oldSlotID ${FindItem[${spellName}].InvSlot.ID}
varset sr_oldItemName ${InvSlot[${sr_slotID}].Item.Name}
call sr_SwapItem "${spellName}" ${sr_slotID}
}
do
{
WaitFrame
}
while "${sr_itemRefreshTime} > ${MacroQuest.Running}"
varset sr_itemRefreshTime ${Math.Calc[${MacroQuest.Running}+200]}
call sr_cast_add_triggers
cast item "${spellName}"
do
{
WaitFrame
if "${Me.Casting.ID}"
{
varcalc sr_castEndTime ${FindItem[${spellName}].CastTime}*10
echo Casting: ${FindItem[${spellName}].Spell.Name}${If[!${FindItem[${spellName}].Spell.TargetType.Equal[PB AE]} && !${FindItem[${spellName}].Spell.TargetType.Equal[self]} && ${Target.ID}, on >> ${Target.CleanName} <<,]}
}
call sr_waitcast ${functocall}
if "${sr_swapItemBack}"
{
if "${FindItem[${sr_oldItemName}].ID}"
call sr_SwapItem "${sr_oldItemName}" ${sr_slotID}
else if ( ${FindItem[${spellName}].ID} ) {
call sr_SwapItem "${spellName}" ${oldSlotID}
}
if "${sr_cast_return.Equal[CAST_CANCELLED]}"
{
echo Spell was cancelled...
return CAST_CANCELLED
}
if "!${sr_cast_return.Equal[CAST_SUCCESS]}"
{
if "${sr_cast_return.Equal[CAST_NOTREADY]}"
return CAST_NOTREADY
if "${sr_cast_return.Equal[CAST_RESTART]}"
cast item "${spellName}"
if "${sr_cast_return.Equal[CAST_STUNNED]}"
{
if "${Me.Stunned}"
{
wait 30 !${Me.Stunned}
}
else
{
wait 7
}
cast item "${spellName}"
wait 1 ${Me.Casting.ID}
}
if "${sr_cast_return.Equal[CAST_INTERRUPTED]}"
{
if "${sr_GUTvalid}"
{
if "${sr_giveupTimer}"
{
echo Interrupted, trying to recast
cast item "${spellName}"
wait 1 ${Me.Casting.ID}
}
}
else
{
echo Spell was interrupted...
return CAST_INTERRUPTED
}
}
if "${sr_cast_return.Equal[CAST_COLLAPSE]}"
{
varset sr_giveupTimer 200
cast item "${spellName}"
wait 1 ${Me.Casting.ID}
}
}
}
while ${Me.Casting.ID}
WaitFrame
ExecuteQueued
call sr_cast_remove_triggers
return ${sr_cast_return}
}
function sr_waitcast(string functocall)
{
declare currentTarget int local ${Target.ID}
declare currentTargetType string local ${Target.Type}
do
{
if "!${QueuedCommands}"
{
if "${sr_GUTvalid}"
{
if "!${sr_giveupTimer}"
return CAST_TIMEOUT
}
WaitFrame
if "${functocall.Length}>0"
call ${functocall} ${sr_castEndTime}
}
else
{
ExecuteQueued
}
if "${currentTarget} && !${Spawn[${currentTarget}].Type.Equal[${currentTargetType}]}"
{
if "!${Me.Casting.TargetType.Equal[PB AE]} && !${Me.Casting.TargetType.Equal[self]} && !${moveBack} && ( !${Me.Mount.ID} || !${noInterrupt} )"
{
if "!${Me.Mount.ID} || ${sr_castEndTime}>70"
{
call sr_Interrupt
}
else if "${Me.Casting.RecastTime}>3"
{
keypress forward hold
delay 6
keypress forward
varset sr_moveBack true
varset sr_cast_return CAST_CANCELLED
}
}
}
if "${Me.State.Equal[DUCK]}"
varset sr_cast_return CAST_CANCELLED
}
while "${Me.Casting.ID}"
WaitFrame
if "${QueuedCommands}"
ExecuteQueued
return ${sr_cast_return}
}
function sr_Interrupt()
{
if "${Me.Mount.ID}"
EQExecute /dismount
if "!${Me.Ducking}"
{
keypress duck
keypress duck
}
do
{
WaitFrame
}
while "${Me.Casting.ID}"
varset sr_cast_return CAST_CANCELLED
return CAST_CANCELLED
}
function sr_cast_add_triggers()
{
AddTrigger sr_cast_interrupted "Your spell is interrupted."
AddTrigger sr_cast_interrupted "Your casting has been interrupted!"
AddTrigger sr_cast_interrupted "Aborting memorization of spell."
AddTrigger sr_cast_begin "You begin casting @SPELL@."
AddTrigger sr_cast_fizzle "Your spell fizzles!"
AddTrigger sr_cast_collapse "Your gate is too unstable, and collapses."
AddTrigger sr_cast_immune "Your target is immune to changes in its @WHAT@ speed."
AddTrigger sr_cast_immune "Your target cannot be mesmerized@rest@"
AddTrigger sr_cast_nohold "Your spell did not take hold."
AddTrigger sr_cast_recover "You haven't recovered yet..."
AddTrigger sr_cast_recover "Spell recovery time not yet met."
AddTrigger sr_cast_nolos "You cannot see your target."
AddTrigger sr_cast_notarget "You must first select a target for this spell!"
AddTrigger sr_cast_notready "Spell recast time not yet met."
AddTrigger sr_cast_outofmana "Insufficient Mana to cast this spell!"
AddTrigger sr_cast_outofrange "Your target is out of range, get closer!"
AddTrigger sr_cast_resisted "Your target resisted the @NAME@ spell."
AddTrigger sr_cast_standing "You must be standing to cast a spell."
AddTrigger sr_cast_stunned "You are stunned!"
AddTrigger sr_cast_stunned "You cannot cast spells while stunned!"
AddTrigger sr_cast_stunned "You *CANNOT* cast spells, you have been silenced!"
}
function sr_cast_remove_triggers()
{
RemoveTrigger sr_cast_interrupted
RemoveTrigger sr_cast_begin
RemoveTrigger sr_cast_fizzle
RemoveTrigger sr_cast_collapse
RemoveTrigger sr_cast_immune
RemoveTrigger sr_cast_nohold
RemoveTrigger sr_cast_recover
RemoveTrigger sr_cast_nolos
RemoveTrigger sr_cast_notarget
RemoveTrigger sr_cast_notready
RemoveTrigger sr_cast_outofmana
RemoveTrigger sr_cast_outofrange
RemoveTrigger sr_cast_resisted
RemoveTrigger sr_cast_standing
RemoveTrigger sr_cast_stunned
}
function sr_cast_interrupted(string FullLine)
{
if "${sr_cast_return.NotEqual[CAST_CANCELLED]}"
varset sr_cast_return CAST_INTERRUPTED
}
function sr_cast_begin(string FullLine)
{
; echo cast begin got : ${FullLine}
; varset sr_cast_return CAST_STARTED
}
function sr_cast_fizzle(string FullLine)
{
; DEBUGGING
; echo Got a fizzle trigger
if "${sr_fizzleIsInterrupt}"
varset sr_cast_return CAST_INTERRUPTED
else
varset sr_cast_return CAST_FIZZLE
; echo sr_cast_return set to ${sr_cast_return} in sr_cast_fizzle Trigger
}
function sr_cast_collapse(string FullLine)
{
varset sr_cast_return CAST_COLLAPSE
}
function sr_cast_immune(string FullLine)
{
varset sr_cast_return CAST_IMMUNE
}
function sr_cast_nohold(string FullLine)
{
varset sr_cast_return CAST_NOHOLD
}
function sr_cast_recover(string FullLine)
{
varset sr_cast_return CAST_NOTREADY
}
function sr_cast_nolos(string FullLine)
{
varset sr_cast_return CAST_NOLOS
}
function sr_cast_notarget(string FullLine)
{
varset sr_cast_return CAST_NOTARGET
}
function sr_cast_notready(string FullLine)
{
varset sr_cast_return CAST_NOTREADY
}
function sr_cast_outofmana(string FullLine)
{
varset sr_cast_return CAST_OUTOFMANA
}
function sr_cast_outofrange(string FullLine)
{
varset sr_cast_return CAST_OUTOFRANGE
}
function sr_cast_resisted(string FullLine)
{
varset sr_cast_return CAST_RESISTED
}
function sr_cast_standing(string FullLine)
{
varset sr_cast_return CAST_NOTSTANDING
}
function sr_cast_stunned(string FullLine)
{
varset sr_cast_return CAST_STUNNED
}