Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: add message when move towards is rejected (#1669)
Browse files Browse the repository at this point in the history
* feat: add message when move towards is rejected
  • Loading branch information
razvan-pro authored May 31, 2022
1 parent a802171 commit 4682692
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aimmo-game-worker/simulation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def serialise(self):
if not self.direction:
return {}
return {
"action_type": "move",
"action_type": "move_towards",
"options": {"direction": self.direction.serialise()},
}

Expand Down
19 changes: 17 additions & 2 deletions aimmo-game/simulation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def _reject(self):
return False


class MoveTowardsAction(MoveAction):
REJECT_MESSAGE = "Uh oh! Your avatar is blocked by another avatar! Try to move around it first."

def _reject(self):
self.avatar.logs.append(self.REJECT_MESSAGE)
return super()._reject()


class AttackAction(Action):
def __init__(self, avatar, direction):
self.direction = Direction(**direction)
Expand Down Expand Up @@ -184,6 +192,13 @@ def _reject(self):
self.avatar.clear_action()


ACTIONS = {"attack": AttackAction, "move": MoveAction, "wait": WaitAction, "pickup": PickupAction, "drop": DropAction}
ACTIONS = {
"attack": AttackAction,
"move": MoveAction,
"wait": WaitAction,
"pickup": PickupAction,
"drop": DropAction,
"move_towards": MoveTowardsAction,
}

PRIORITIES = {WaitAction: 0, PickupAction: 0, DropAction: 0, AttackAction: 1, MoveAction: 2}
PRIORITIES = {WaitAction: 0, PickupAction: 0, DropAction: 0, AttackAction: 1, MoveAction: 2, MoveTowardsAction: 2}
8 changes: 8 additions & 0 deletions aimmo-game/tests/test_simulation/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def test_failed_move_action(self):
assert self.avatar.location == ORIGIN
assert self.avatar.events == [event.FailedMoveEvent(ORIGIN, NORTH_OF_ORIGIN)]

def test_failed_move_towards_action(self):
game_state = GameState(EmptyMap(), self.avatar_manager)
action.MoveTowardsAction(self.avatar, {"x": 0, "y": 1}).process(game_state.world_map)

assert self.avatar.location == ORIGIN
assert self.avatar.events == [event.FailedMoveEvent(ORIGIN, NORTH_OF_ORIGIN)]
assert self.avatar.logs[-1] == action.MoveTowardsAction.REJECT_MESSAGE

def test_successful_attack_action(self):
game_state = GameState(AvatarMap(self.other_avatar), self.avatar_manager)
action.AttackAction(self.avatar, {"x": 0, "y": 1}).process(game_state.world_map)
Expand Down

0 comments on commit 4682692

Please sign in to comment.