Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better handling of target types in _give_units_same_order #151

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ares/behaviors/combat/group/path_group_to_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class PathGroupToTarget(CombatGroupBehavior):
prevent_duplicate: bool = True

def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> bool:
assert isinstance(
self.start, Point2
), f"{self.start} should be `Point2`, got {type(self.start)}"
assert isinstance(
self.target, Point2
), f"{self.target} should be `Point2`, got {type(self.target)}"

if len(self.group) == 0:
return False

Expand Down
16 changes: 14 additions & 2 deletions src/ares/custom_bot_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def _give_units_same_order(
self,
order: AbilityId,
unit_tags: Union[List[int], set[int]],
target: Optional[Union[Point2, int]] = None,
target: Optional[Union[Point2, Unit, int]] = None,
) -> None:
"""
Give units corresponding to the given tags the same order.
Expand Down Expand Up @@ -234,6 +234,18 @@ async def _give_units_same_order(
)
)
else:
tag: int
if isinstance(target, Unit):
tag = target.tag
elif isinstance(target, int):
tag = target
else:
logger.warning(
f"Got {target} argument, and not sure what to do with it. "
f" `_give_units_same_order` will not execute."
)
return

# noinspection PyProtectedMember
await self.client._execute(
action=sc_pb.RequestAction(
Expand All @@ -242,7 +254,7 @@ async def _give_units_same_order(
action_raw=raw_pb.ActionRaw(
unit_command=raw_pb.ActionRawUnitCommand(
ability_id=order.value,
target_unit_tag=target,
target_unit_tag=tag,
unit_tags=unit_tags,
)
)
Expand Down
Loading