Skip to content

Commit bfb7585

Browse files
committed
add quest item functionality (closes #31)
1 parent a3a6902 commit bfb7585

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/fantasy_forge/item.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
class Item(Entity):
99
"""An Item is an entity which can be picked up by the player."""
1010

11-
12-
__attributes__ = {**Entity.__attributes__, "moveable": bool, "carryable": bool, "weight": int}
13-
__important_attributes__ = ("name", "moveable", "carryable", "weight")
11+
__attributes__ = {
12+
**Entity.__attributes__,
13+
"moveable": bool,
14+
"carryable": bool,
15+
"weight": int,
16+
"quest_item": bool,
17+
}
18+
__important_attributes__ = ("name", "moveable", "carryable", "weight", "quest_item")
1419

1520
moveable: bool
1621
carryable: bool
1722
weight: int
23+
quest_item: bool
1824

1925
def __init__(self: Self, messages: Messages, config_dict: dict[str, Any]) -> None:
2026
"""
@@ -31,10 +37,14 @@ def __init__(self: Self, messages: Messages, config_dict: dict[str, Any]) -> Non
3137
self.moveable = config_dict.pop("moveable", True)
3238
self.carryable = config_dict.pop("carryable", True)
3339
self.weight = config_dict.pop("weight", 1)
40+
self.quest_item = config_dict.pop("quest_item", False)
3441
super().__init__(messages, config_dict)
3542

43+
if self.quest_item:
44+
self.weight = 0
45+
3646
def __repr__(self: Self) -> str:
37-
return f"Item({self.name}, {self.description}, moveable={self.moveable}, carryable={self.carryable}, weight={self.weight})"
47+
return f"Item({self.name}, {self.description}, moveable={self.moveable}, carryable={self.carryable}, weight={self.weight}, quest_item={self.quest_item})"
3848

3949
def on_pickup(self: Self):
4050
# TODO
@@ -45,6 +55,7 @@ def to_dict(self: Self) -> dict:
4555
item_dict["moveable"] = self.moveable
4656
item_dict["carryable"] = self.carryable
4757
item_dict["weight"] = self.weight
58+
item_dict["quest_item"] = self.quest_item
4859
return item_dict
4960

5061
@staticmethod

src/fantasy_forge/l10n/en/main.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ armour-detail = {$type}: {EXISTS($item) ->
4949
}.
5050
drop-not-found = You can't drop { $item }.
5151
dropped = You dropped { INTER($item) }.
52+
cant-drop-quest-item = You can't drop { INTER($item) }, it's a quest item.
5253
enter-area-message = You are now in { $area }. You see:
5354
inventory-look-message = In the inventory you find { $items }.
5455
inventory-look-empty-message = Your inventory is empty.

src/fantasy_forge/player.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ def drop(self, item_name: str):
395395
item=item_name,
396396
)
397397
return
398+
if item.quest_item:
399+
self.inventory.add(item)
400+
self.messages.to(
401+
[self],
402+
"cant-drop-quest-item",
403+
item=item_name,
404+
)
405+
return
398406
self.area.contents[item.name] = item # adds item to current area
399407
if self.main_hand is item: # clears main hand if item was dropped from it
400408
self.main_hand = None

0 commit comments

Comments
 (0)