@@ -338,14 +338,31 @@ Sub xbot_initialize(string _tank1Name, string _tank2Name, string _tank3Name, int
338338 /declare int_campY int outer ${Me.Y }
339339 /declare int_campZ int outer ${Me.Z }
340340 /declare int_campRadius int outer 85
341- /declare str_startZone string outer ${Zone. ShortName }
341+ /declare str_startZone string outer ${cache_zoneShort }
342342
343343 |--include the custom event initializations & other things
344344 /declare bln_outside bool outer TRUE
345345 /declare bln_slowUse bool outer FALSE
346346 /declare bln_slowed bool outer FALSE
347347 /declare int_slowResisted int outer 0
348348 /declare int_slowMaxTries int outer 3
349+
350+
351+ |-------------------------------------------------
352+ | Environment cache (update ~5x/sec, or on target change)
353+ |-------------------------------------------------
354+ /declare timer_envCache timer outer 0
355+ /declare cache_zoneShort string outer
356+ /declare cache_boundZone string outer
357+ /declare cache_npcR200 int outer
358+ /declare cache_npcR400 int outer
359+ /declare cache_hasXTarget bool outer
360+ /declare cache_targetIsCorpse bool outer
361+ /declare cache_targetID int outer
362+ /declare cache_targetType string outer
363+ /declare cache_targetName string outer
364+ /declare cache_now string outer
365+
349366
350367 :init_naked_wait
351368 /call chkNaked
@@ -385,6 +402,36 @@ Sub xbot_initialize(string _tank1Name, string _tank2Name, string _tank3Name, int
385402/return
386403
387404
405+ Sub InvalidateEnvironmentCache
406+ /varset timer_envCache 0
407+ /return
408+
409+ Sub UpdateEnvironmentCache
410+ | fast-path: if target changed, force refresh now
411+ /if (${Target.ID } != ${cache_targetID}) /varset timer_envCache 0
412+ /if (${timer_envCache}) /return
413+
414+ /varset cache_zoneShort ${Zone.ShortName }
415+ /varset cache_boundZone ${Me.BoundLocation [0 ]}
416+ /varset cache_npcR200 ${SpawnCount[npc radius 200 ]}
417+ /varset cache_npcR400 ${SpawnCount[npc radius 400 ]}
418+ /varset cache_hasXTarget ${Me.XTarget }
419+ /varset cache_now ${Time.Time24 }
420+
421+ /if (${Target.ID }) {
422+ /varset cache_targetID ${Target.ID }
423+ /varset cache_targetType ${Target.Type }
424+ /varset cache_targetName ${Target.DisplayName }
425+ /varset cache_targetIsCorpse ${Target.Type .Equal [corpse]}
426+ } else {
427+ /varset cache_targetID 0
428+ /varset cache_targetType
429+ /varset cache_targetName
430+ /varset cache_targetIsCorpse FALSE
431+ }
432+
433+ /varset timer_envCache 20 | ~0 .2s at ~100 tps
434+ /return
388435
389436Sub createGroupList
390437 /declare g int local 0
@@ -491,11 +538,11 @@ Sub EngageTarget(int _targetID)
491538 /varset int_targetID ${_targetID}
492539 /varset str_targetName ${Spawn[id ${_targetID}].Name }
493540 /varset bln_engaged TRUE
541+ /call InvalidateEnvironmentCache
494542
495543 /if (${Select[${Me.Class .ShortName },CLR,DRU]} || (${Me.Class .ShortName .Equal [CLR]} && !${bln_battleCleric})) /return
496544
497545
498-
499546 | Target NPC
500547 /call TrueTarget ${_targetID}
501548 /if (${bln_meleeOverride} || ${str_classArchetype.Equal [MELEE_END]} || ${str_classArchetype.Equal [MELEE_MANA]} || ${str_classArchetype.Equal [TANK]}) /call EngageTargetMelee
@@ -525,6 +572,9 @@ Sub EngageTarget(int _targetID)
525572
526573Sub chkTargetStatus
527574 /declare reason string local TARGET_VALID
575+ /call InvalidateEnvironmentCache
576+ /call UpdateEnvironmentCache
577+
528578 /if (!${bln_engaged}) /goto :return
529579
530580 | Target doesnt exist
@@ -534,7 +584,7 @@ Sub chkTargetStatus
534584 }
535585
536586 | No target, or I am at my bound zone, if engaged, kill
537- /if (${int_targetID} == 0 || !${Target. ID } || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]}) {
587+ /if (${int_targetID} == 0 || !${cache_targetID} || ${cache_zoneShort. Equal [${cache_boundZone }]}) {
538588 /varset reason NOTARGET_or_ATBIND
539589 /goto :disengage
540590 }
@@ -549,21 +599,21 @@ Sub chkTargetStatus
549599 }
550600
551601 | Check to see if my target is NPC and there is no NPCs around
552- /if (${Target. ID } && ${Target. ID } == ${int_MTID} && (!${SpawnCount[npc id ${int_targetID} radius 200 ]} || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]})) {
602+ /if (${cache_targetID } && ${cache_targetID } == ${int_MTID} && (!${SpawnCount[npc id ${int_targetID} radius 200 ]} || ${cache_zoneShort. Equal [${cache_boundZone }]})) {
553603 /echo \awTarget is MT, and No NPC in radius 200 (or at bind) \aoDisengaging!
554604 /varset reason TARGETMT_or_ATBIND
555605 /goto :disengage
556606 }
557607
558608 | Check to see if there are any NPCs on XTarget and Radius
559- /if ((${Me. XTarget }== 0 && !${SpawnCount[npc radius 200 ]}) ) {
609+ /if (!${cache_hasXTarget} && !${cache_npcR200} ) {
560610 /echo \awNo Targets within 200 , or on XTarget \aoDisengaging!
561611 /varset reason NOTARGETSWITHIN200_AND_NOXTARGET
562612 /goto :disengage
563613 }
564614
565615 | If there is something on XTarget, and its over 400 away, ignore it.
566- /if (${Me. XTarget } && (!${SpawnCount[npc radius 400 ]} || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]})) {
616+ /if (${cache_hasXTarget } && (!${cache_npcR400} || ${cache_zoneShort. Equal [${cache_boundZone }]})) {
567617 /echo \awNo Targets within 400 , even if they are on XTarget \aoDisengaging!
568618 /varset reason NOTARGETWITHIN400_AND_HASXTARGET
569619 /goto :disengage
@@ -607,11 +657,11 @@ Sub chkTargetStatus
607657 }
608658 } else /if (${str_classArchetype.Equal [MELEE_END]} || ${str_classArchetype.Equal [MELEE_MANA]} || ${str_classArchetype.Equal [TANK]}) {
609659 /declare use_riposte bool local FALSE
610- /if (${Zone. ShortName .Equal [tacvi]} && (${Target.Name .Find [Pirik]} || ${Target.Name .Find [Yihst]} || ${Target.Name .Find [Tunat]})) {
660+ /if (${cache_zoneShort .Equal [tacvi]} && (${Target.Name .Find [Pirik]} || ${Target.Name .Find [Yihst]} || ${Target.Name .Find [Tunat]})) {
611661 /varset use_riposte TRUE
612- } else /if (${Zone. ShortName .Equal [anguish]} && (${Target.Name .Find [Keldovan]} || ${Target.Name .Find [Ture]} || ${Target.Name .Find [Vangl]} || ${Target.Name .Find [Zun]} || ${Target.Name .Find [Hanvar]} || ${Target.Name .Find [Overlord]})) {
662+ } else /if (${cache_zoneShort .Equal [anguish]} && (${Target.Name .Find [Keldovan]} || ${Target.Name .Find [Ture]} || ${Target.Name .Find [Vangl]} || ${Target.Name .Find [Zun]} || ${Target.Name .Find [Hanvar]} || ${Target.Name .Find [Overlord]})) {
613663 /varset use_riposte TRUE
614- } else /if (${Zone. ShortName .Find [chambers]} && ${Target.Name .Find [Master]}) {
664+ } else /if (${cache_zoneShort .Find [chambers]} && ${Target.Name .Find [Master]}) {
615665 /varset use_riposte TRUE
616666 }
617667 /if (${Me.Class .ShortName .Equal [SHD]}) {
@@ -663,6 +713,7 @@ Sub Disengage
663713 /varset str_targetName NULL
664714 /varset str_debuffedTargets NULL
665715 /varset bln_forceNamed FALSE
716+ /call InvalidateEnvironmentCache
666717
667718 /call RunRapidEvents
668719 | Priests have nothing left to do here;
@@ -680,8 +731,9 @@ Sub Disengage
680731
681732
682733Sub chkMobDead
683- /if ((${SpawnCount[npc radius 200 ]} == 0 || ${Me.XTarget } == 0 ) && ${bln_engaged} ) {
684- /echo chkMobDead triggered XTarget:${Me.XTarget } || SpawnCount:!${SpawnCount[npc id ${int_targetID} radius 250 ]} && engaged:${bln_engaged}
734+ /call UpdateEnvironmentCache
735+ /if ((!${cache_npcR200} || !${cache_hasXTarget}) && ${bln_engaged}) {
736+ /echo chkMobDead triggered XTarget:${cache_hasXTarget} || SpawnCount:!${SpawnCount[npc id ${int_targetID} radius 250 ]} && engaged:${bln_engaged}
685737 /call Disengage
686738 }
687739/return
@@ -701,6 +753,7 @@ Sub TrueTarget(int _targetID)
701753 }
702754 }
703755 }
756+ /call InvalidateEnvironmentCache
704757/return
705758
706759
@@ -982,7 +1035,7 @@ Sub Event_EndMac
9821035| AA Special Events
9831036Sub EVENT_UseStaunchRecovery
9841037 | Do not use if at bind point (ie: dead)
985- /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]}) /return
1038+ /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${cache_zoneShort. Equal [${cache_boundZone }]}) /return
9861039
9871040 /if ((${str_classArchetype.Equal [MELEE_END]} || ${str_classArchetype.Equal [TANK]}) && ${Me.PctEndurance } < 20 ) {
9881041 /casting " Staunch Recovery" alt
@@ -997,7 +1050,7 @@ Sub EVENT_UseStaunchRecovery
9971050
9981051Sub EVENT_UseIntensity
9991052 | Do not use if at bind point (ie: dead)
1000- /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]}) /return
1053+ /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${cache_zoneShort. Equal [${cache_boundZone }]}) /return
10011054 /if (${Me.Class .ShortName .Equal [BRD]}) {
10021055 /call MQ2Medley ALT " Intensity of the Resolute" ${int_targetID} TRUE
10031056 } else {
@@ -1007,7 +1060,7 @@ Sub EVENT_UseIntensity
10071060
10081061Sub EVENT_UseServants
10091062 | Do not use if at bind point (ie: dead)
1010- /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]}) /return
1063+ /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${cache_zoneShort. Equal [${cache_boundZone }]}) /return
10111064 /if (${Me.Class .ShortName .Equal [BRD]}) {
10121065 /call MQ2Medley ALT " Steadfast Servant" ${int_targetID} FALSE
10131066 } else {
@@ -1017,7 +1070,7 @@ Sub EVENT_UseServants
10171070
10181071Sub EVENT_UseInfusion
10191072 | Do not use if at bind point (ie: dead)
1020- /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${Zone. ShortName . Equal [${Me. BoundLocation [ 0 ] }]}) /return
1073+ /if (${Zone.ID } == 340 || ${Zone.ID } == 344 || ${Zone.ID } == 345 || ${cache_zoneShort. Equal [${cache_boundZone }]}) /return
10211074 /if (${Me.Class .ShortName .Equal [BRD]}) {
10221075 /call MQ2Medley ALT " Infusion of the Faithful" ${int_targetID} FALSE
10231076 } else {
@@ -1032,22 +1085,22 @@ Sub EVENT_UseInfusion
10321085
10331086
10341087Sub Event_RageOn(string line)
1035- /if (!${mq2meleeEnabled} && !${Stick.Behind} && (${line.Find[${Spawn[${int_targetID}].DisplayName}]} || ${line.Find[${Target.DisplayName }]}) && (${str_classArchetype.Equal[MELEE_END]} || ${str_classArchetype.Equal[MELEE_MANA]} || ${str_classArchetype.Equal[TANK]})) {
1088+ /if (!${mq2meleeEnabled} && !${Stick.Behind} && (${line.Find[${Spawn[${int_targetID}].DisplayName}]} || ${line.Find[${cache_targetName }]}) && (${str_classArchetype.Equal[MELEE_END]} || ${str_classArchetype.Equal[MELEE_MANA]} || ${str_classArchetype.Equal[TANK]})) {
10361089 /attack off
10371090 }
1038- /if (((${line.Find[${Spawn[${int_targetID}].DisplayName}]} || ${line.Find[${Target.DisplayName }]}) && ${Pet.ID}) && !${Me.PetBuff[Master' s Aura Effect]}) {
1091+ /if (((${line.Find[${Spawn[${int_targetID}].DisplayName}]} || ${line.Find[${cache_targetName }]}) && ${Pet.ID}) && !${Me.PetBuff[Master' s Aura Effect]}) {
10391092 /echo Enrage detected! Backing pet off.
10401093 /pet back off
10411094 /varset bln_enraged TRUE
10421095 }
10431096/return
10441097
10451098Sub Event_RageOff (string line)
1046- /if (!${mq2meleeEnabled} && (${line.Find [${Spawn[${int_targetID}].DisplayName }]} || ${line.Find [${Target. DisplayName }]}) && (${str_classArchetype.Equal [MELEE_END]} || ${str_classArchetype.Equal [MELEE_MANA]} || ${str_classArchetype.Equal [TANK]}) && ${Target. ID }) {
1099+ /if (!${mq2meleeEnabled} && (${line.Find [${Spawn[${int_targetID}].DisplayName }]} || ${line.Find [${cache_targetName }]}) && (${str_classArchetype.Equal [MELEE_END]} || ${str_classArchetype.Equal [MELEE_MANA]} || ${str_classArchetype.Equal [TANK]}) && ${cache_targetID }) {
10471100 /echo \awRageOff :tryKill \ag Attacking
10481101 /attack on
10491102 }
1050- /if ((${line.Find [${Spawn[${int_targetID}].DisplayName }]} || ${line.Find [${Target. DisplayName }]}) && ${Pet.ID }) {
1103+ /if ((${line.Find [${Spawn[${int_targetID}].DisplayName }]} || ${line.Find [${cache_targetName }]}) && ${Pet.ID }) {
10511104 /pet attack
10521105 /varset bln_enraged FALSE
10531106 }
@@ -1064,6 +1117,7 @@ Sub EVENT_DUCKON
10641117 /duck
10651118 :ducking
10661119 /if (!${Me.Ducking }) /keypress x
1120+ /call UpdateEnvironmentCache
10671121 /call RunRaidEvents
10681122 /if (${bln_ducking}) {
10691123 /delay 1s
@@ -1085,6 +1139,7 @@ Sub EVENT_DUCKOFF
10851139Sub Event_Zoned
10861140 /echo \awEvent_Zoned ${Time.Time24 }
10871141 /call setExclusions
1142+ /call InvalidateEnvironmentCache
10881143 /if (${MacroQuest.GameState .Equal [CHARSELECT]}) /end
10891144/return
10901145
@@ -1299,11 +1354,11 @@ Sub EVENT_ForceNamed(_line, _chatSender, _eventParams)
12991354Sub TargetNamedCheck(_id)
13001355 /if (${bln_forceNamed}) /return TRUE
13011356 /if ((${Spawn[npc id ${_id}].Named} || ${Spawn[npc id ${_id}].Name.Find[#]}) && ${Target.Level} >= 75) /return TRUE
1302- /if (${Zone.ShortName .Equal[tacvi]} && ${Target.Level} >= 70) /return TRUE
1303- /if (${Zone.ShortName. Equal[chambersa]} || ${Zone.ShortName. Equal[chambersb]} || ${Zone.ShortName. Equal[chambersc]} || ${Zone.ShortName. Equal[chambersd]} || ${Zone.ShortName .Equal[chamberse]} && ${Target.Level} >= 70) /return TRUE
1304- /if (${Zone.ShortName .Equal[anguish]} && ${Target.Level} >= 75) /return TRUE
1305- /if (${Zone.ShortName .Equal[arena]}) /return TRUE
1306- /if (${Zone.ShortName .Equal[thundercrest]}) /return TRUE
1357+ /if (${cache_zoneShort .Equal[tacvi]} && ${Target.Level} >= 70) /return TRUE
1358+ /if (${cache_zoneShort. Equal[chambersa]} || ${cache_zoneShort. Equal[chambersb]} || ${cache_zoneShort. Equal[chambersc]} || ${cache_zoneShort. Equal[chambersd]} || ${cache_zoneShort .Equal[chamberse]} && ${Target.Level} >= 70) /return TRUE
1359+ /if (${cache_zoneShort .Equal[anguish]} && ${Target.Level} >= 75) /return TRUE
1360+ /if (${cache_zoneShort .Equal[arena]}) /return TRUE
1361+ /if (${cache_zoneShort .Equal[thundercrest]}) /return TRUE
13071362/return FALSE
13081363
13091364
0 commit comments