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

Issues/285 transition bug #287

Merged
merged 1 commit into from
May 21, 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
14 changes: 9 additions & 5 deletions dlgr/griduniverse/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,11 +1613,15 @@ def handle_item_transition(self, msg):

# The player's item type has changed
if transition["actor_end"] != actor_key:
new_player_item = Item(
id=len(self.grid.item_locations) + len(self.grid.items_consumed),
item_config=self.item_config[transition["actor_end"]],
)
player.current_item = new_player_item
if transition["actor_end"] is not None:
replacement_item_config = self.item_config.get(transition["actor_end"])
replacement_item = Item(
id=len(self.grid.item_locations) + len(self.grid.items_consumed),
item_config=replacement_item_config,
)
else:
replacement_item = None
player.current_item = replacement_item
self.grid.items_updated = True

# The location's item type has changed
Expand Down
26 changes: 26 additions & 0 deletions test/test_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ def test_handle_item_transition_combine_items(self, mocked_exp, player):
assert len(mocked_exp.grid.item_locations) == 1
assert list(mocked_exp.grid.item_locations.values())[0].name == "Big Hard Rock"

def test_handle_item_transition_transforms_items(self, mocked_exp, player):
mocked_exp.transition_config[("stone", "big_hard_rock")] = {
"actor_start": "stone",
"actor_end": None,
"target_start": "big_hard_rock",
"target_end": "sharp_stone",
"last_use": False,
"modify_uses": [0, 0],
"visible": "always",
}
big_hard_rock = create_item(**mocked_exp.item_config["big_hard_rock"])
stone = create_item(**mocked_exp.item_config["stone"])
mocked_exp.grid.item_locations[(0, 0)] = big_hard_rock
player.current_item = stone

mocked_exp.handle_item_transition(
msg={"player_id": player.id, "position": (0, 0)}
)

# The Stone and the Big Hard Rock have been transformed into a
# Sharp Stone on the square where the Big Hard Rock was before
assert player.current_item is None
assert len(mocked_exp.grid.items_consumed) == 2
assert len(mocked_exp.grid.item_locations) == 1
assert list(mocked_exp.grid.item_locations.values())[0].name == "Sharp Stone"

def test_handle_item_transition_reduces_items_remaining(self, mocked_exp, player):
gooseberry_bush = create_item(**mocked_exp.item_config["gooseberry_bush"])
assert gooseberry_bush.name == "Gooseberry Bush"
Expand Down
Loading