Skip to content

Commit a983aa1

Browse files
authored
Merge pull request #11 from meta53:cached-properties
Cached-properties
2 parents b233595 + 5743c01 commit a983aa1

15 files changed

+129
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ common/packs.inc
127127
common/sell.inc
128128
sql.mac
129129
muffins.mac
130+
bot_pull.mac

bot_brd.mac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Sub Main(string _tank1Name, string _tank2Name, string _tank3Name, int _healPoint
115115

116116
:MainLoop
117117
/if (${Me.Hovering} || ${Window[tradewnd].Open} || ${Window[lootwnd].Open}) /goto :MainLoop
118+
118119
|-- Check all Events
119120
/call RunAllEvents
120121

xiris_common/xiris_casting.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ Sub chkSnare
580580

581581
/if (${Cast.Result.Equal[CAST_IMMUNE]}) {
582582
/echo \ar ${str_snareSpell} ${Cast.Result}
583-
/ini "${IniFile}" "SnareImmunes.${Zone.ShortName}" "SnareImmune" "${list_immuneSnare}${Target.CleanName}|"
584-
/varset list_immuneSnare ${Ini[${ignoreINI},"SnareImmunes.${Zone.ShortName}","SnareImmune"]}
583+
/ini "${IniFile}" "SnareImmunes.${cache_zoneShort}" "SnareImmune" "${list_immuneSnare}${Target.CleanName}|"
584+
/varset list_immuneSnare ${Ini[${ignoreINI},"SnareImmunes.${cache_zoneShort}","SnareImmune"]}
585585
/varset bln_snareActive TRUE
586586
}
587587
/call RunRaidEvents

xiris_common/xiris_charm.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Sub CastCharm(string _charm, string _gem, int _maxTries, int _targetID, bool _fo
152152
/goto :CharmFailure
153153
}
154154
|pre-check before attempt
155-
/if (${Target.PctHPs} == 0 || !${Target.ID} || (${Target.ID} != ${tgtID}) || ${Target.Name.Find['s_corpse']} || ${Target.Type.Equal[corpse]} || ${Target.Type.Equal[pc]}) {
155+
/if (${Target.PctHPs} == 0 || !${Target.ID} || (${Target.ID} != ${tgtID}) || ${Target.Name.Find['s_corpse']} || ${cache_targetIsCorpse} || ${Target.Type.Equal[pc]}) {
156156
/echo \ar Charm Failure\aw Target Error
157157
/varset rslt TARGET_ERROR
158158
/goto :CharmFailure

xiris_common/xiris_common.inc

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

389436
Sub 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

526573
Sub 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

682733
Sub 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
9831036
Sub 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

9981051
Sub 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

10081061
Sub 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

10181071
Sub 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
10341087
Sub 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

10451098
Sub 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
10851139
Sub 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)
12991354
Sub 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

xiris_common/xiris_debuffing.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Sub CastDebuff(string _debuff, string _gem, int _maxTries, int _targetID, bool
241241
/goto :DebuffFailure
242242
}
243243
|pre-check before attempt
244-
/if (${Target.PctHPs} == 0 || !${Target.ID} || (${Target.ID} != ${tgtID}) || ${Target.Name.Find['s_corpse']} || ${Target.Type.Equal[corpse]} || ${Target.Type.Equal[pc]}) {
244+
/if (${Target.PctHPs} == 0 || !${Target.ID} || (${Target.ID} != ${tgtID}) || ${Target.Name.Find['s_corpse']} || ${cache_targetIsCorpse} || ${Target.Type.Equal[pc]}) {
245245
/echo \ar Debuff Failure\aw Target Error
246246
/varset rslt TARGET_ERROR
247247
/goto :DebuffFailure

xiris_common/xiris_events.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Sub xbot_initialize_events
4444
|--Check for Special Events
4545

4646
|- Gates of Discord
47-
/if (${Select[${Zone.ShortName},barindu,snpool,snlair,sncrematory,snplant,vxed,tipt]}) /call InitEvents_GoD_Barindu
47+
/if (${Select[${cache_zoneShort},barindu,snpool,snlair,sncrematory,snplant,vxed,tipt]}) /call InitEvents_GoD_Barindu
4848
/if (${Zone.ShortName.Equal[uqua]}) /call InitEvents_GoD_Uqua
4949
/if (${Zone.ShortName.Equal[ikkinz]}) /call InitEvents_GoD_Uqua
5050
/if (${Zone.ShortName.Equal[inktuta]}) /call InitEvents_GoD_Inktuta
@@ -215,6 +215,7 @@ Sub TrimRapidEvents(int _count)
215215
216216
217217
Sub RunBackgroundEvents
218+
/call UpdateEnvironmentCache
218219
/if (${BackgroundEvents.Size} == 0) /return
219220
/declare i int local 1
220221
/for i 1 to ${BackgroundEvents.Size}
@@ -225,6 +226,7 @@ Sub RunBackgroundEvents
225226
/return
226227
227228
Sub RunRaidEvents
229+
/call UpdateEnvironmentCache
228230
/if (${RaidEvents.Size} == 0) /return
229231
/declare j int local 1
230232
/for j 1 to ${RaidEvents.Size}
@@ -235,6 +237,7 @@ Sub RunRaidEvents
235237
/return
236238
237239
Sub RunClassEvents
240+
/call UpdateEnvironmentCache
238241
/if (${ClassEvents.Size} == 0) /return
239242
/declare k int local 1
240243
/for k 1 to ${ClassEvents.Size}
@@ -245,6 +248,7 @@ Sub RunClassEvents
245248
/return
246249
247250
Sub RunRapidEvents
251+
/call UpdateEnvironmentCache
248252
/if (${RapidEvents.Size} == 0) /return
249253
/declare k int local 1
250254
/for k 1 to ${RapidEvents.Size}
@@ -256,6 +260,7 @@ Sub RunRapidEvents
256260
257261
258262
Sub RunAllEvents
263+
/call UpdateEnvironmentCache
259264
/call RunBackgroundEvents
260265
/call RunRaidEvents
261266
/call RunClassEvents

0 commit comments

Comments
 (0)