Makes it so we emit an event for other plugins to read any time the target is changed, whether it's cleareed, set to a campaign/gquest/quest target, or set to an ad-hoc target like when you do qw/ht <mob name>. It also has a new method target_as_json that is to be called by other plugins to get details on the target. If we want we can add another method for getting the data in the serialize format but I'd much rather deal with json so that's what I started with.
All changes to the target should go through change_target so that events are broadcast. There's some helper methods, set_target_from_main_target_list, set_target_from_quest, set_adhoc_target, and clear_target to make this easy.
I refactored how targets are handled internally. Instead of having a few, separate pieces of global state (xcp_index, full_mob_name, short_mob_name) we now have a single table that tells us about the target. It's set to nil when there's no target, otherwise it's a structure that contains data relevant to the target. One nice thing about this is it means we don't have multiple pieces of state to change when the target changes, notably not having to clear out a bunch of state when clearing target. Instead we just replace the one current_target variable with the full table of the new target and we're done. It also means no more ugly checks like
if (short_mob_name == nil) or (short_mob_name == "") or (short_mob_name == "-1") or (short_mob_name == -1) then
This can be replaced by a has_target() method.
There's also some helper method to examine the current target for common patterns:
has_target(): returns true if there's any target
is_cp_or_gq_mob_targeted(): returns true if there's a target and it's part of a cp/gq
is_quest_mob_targeted(): returns true if the quest mob is currently targeted
has_activity_target(): returns true if the current target is a quest, cp, or gq target
Makes it so we emit an event for other plugins to read any time the target is changed, whether it's cleareed, set to a campaign/gquest/quest target, or set to an ad-hoc target like when you do
qw/ht <mob name>
. It also has a new methodtarget_as_json
that is to be called by other plugins to get details on the target. If we want we can add another method for getting the data in the serialize format but I'd much rather deal with json so that's what I started with.All changes to the target should go through
change_target
so that events are broadcast. There's some helper methods,set_target_from_main_target_list
,set_target_from_quest
,set_adhoc_target
, andclear_target
to make this easy.I refactored how targets are handled internally. Instead of having a few, separate pieces of global state (xcp_index, full_mob_name, short_mob_name) we now have a single table that tells us about the target. It's set to nil when there's no target, otherwise it's a structure that contains data relevant to the target. One nice thing about this is it means we don't have multiple pieces of state to change when the target changes, notably not having to clear out a bunch of state when clearing target. Instead we just replace the one
current_target
variable with the full table of the new target and we're done. It also means no more ugly checks likeif (short_mob_name == nil) or (short_mob_name == "") or (short_mob_name == "-1") or (short_mob_name == -1) then
This can be replaced by ahas_target()
method.There's also some helper method to examine the current target for common patterns:
has_target()
: returns true if there's any targetis_cp_or_gq_mob_targeted()
: returns true if there's a target and it's part of a cp/gqis_quest_mob_targeted()
: returns true if the quest mob is currently targetedhas_activity_target()
: returns true if the current target is a quest, cp, or gq target