Repository navigation
[GearSwap] equip_sets_exit pretarget cleanup part 2 - #2586
Merged
Merged
Conversation
The current code path is a bit tangled and not cohesive, as demonstrated by the "This case should not be hittable - 2" being hit for any item trades where the target is greater than 6 yalms away, which is a very real scenario. The overall code path should be pretty straightforward, either we succeeded in assembling a proposed packet and will proceed into the precast event, or we didn't get a proposed packet and will do some cleanup before bailing out and letting the client handle the action. Assigning nil to storedcommand is not necessary as part of cleanup, as any subsequent outgoing text trigger is guaranteed to assign a new value to storedcommand before storedcommand is ever used, so it is not possible for a stale value to persist from a previous trigger and be utilized. The same cleanup steps are added to outgoing text for consistency. We shouldn't be doing the val1.target.name check because filter_precast already validates the target by checking .target.id and .target.index, so inside filter_precast code block is where we have a valid target and outside filter_precast code block is where we don't have a valid target, we don't need to check for valid target in multiple places. The debug message about "Change target was used to pick an invalid target" was modified because that debug message lies most of the time, most often change target was not exercised and the original command contained <t> without any target selected, for example. In order for an action to be a trade, the item must be in the inventory with a status of 0, so this find_inventory_item check should be baked into the trade determination. Before this commit, it was possible to have an item action_type labeled as a trade, but we still end up assembling an item use packet instead of a trade packet if the find_inventory_item check failed but the find_usable_item check succeeded. With this commit, we only set the action_type as trade if it really is a trade. As part of this commit's untangling of things, GearSwap will no longer fake out the "Target out of range" message for out of range trades, and will instead do the proper thing of letting the client handle that action and print out a native out of range message, along with the native feedback of echoing the input command that produced the out of range message. Outgoing text is also updated to no longer fake out these out of range trades to remain consistent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current code path is a bit tangled and not cohesive, as demonstrated by the "This case should not be hittable - 2" being hit for any item trades where the target is greater than 6 yalms away, which is a very real scenario.
The overall code path should be pretty straightforward, either we succeeded in assembling a proposed packet and will proceed into the precast event, or we didn't get a proposed packet and will do some cleanup before bailing out and letting the client handle the action.
Assigning nil to storedcommand is not necessary as part of cleanup, as any subsequent outgoing text trigger is guaranteed to assign a new value to storedcommand before storedcommand is ever used, so it is not possible for a stale value to persist from a previous trigger and be utilized.
The same cleanup steps are added to outgoing text for consistency.
We shouldn't be doing the val1.target.name check because filter_precast already validates the target by checking .target.id and .target.index, so inside filter_precast code block is where we have a valid target and outside filter_precast code block is where we don't have a valid target, we don't need to check for valid target in multiple places.
The debug message about "Change target was used to pick an invalid target" was modified because that debug message lies most of the time, most often change target was not exercised and the original command contained without any target selected, for example.
In order for an action to be a trade, the item must be in the inventory with a status of 0, so this find_inventory_item check should be baked into the trade determination. Before this commit, it was possible to have an item action_type labeled as a trade, but we still end up assembling an item use packet instead of a trade packet if the find_inventory_item check failed but the find_usable_item check succeeded. With this commit, we only set the action_type as trade if it really is a trade.
As part of this commit's untangling of things, GearSwap will no longer fake out the "Target out of range" message for out of range trades, and will instead do the proper thing of letting the client handle that action and print out a native out of range message, along with the native feedback of echoing the input command that produced the out of range message. Outgoing text is also updated to no longer fake out these out of range trades to remain consistent.