Item owners are correctly set

This commit is contained in:
Yohann D'ANELLO 2021-01-16 00:26:33 +01:00
parent e233243b81
commit 87e896bd06
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 4 additions and 2 deletions

View File

@ -848,7 +848,6 @@ class InventoryHolder(Entity):
for i in range(len(inventory)):
if isinstance(inventory[i], dict):
inventory[i] = self.dict_to_item(inventory[i])
inventory[i].held_by = self
return inventory
def dict_to_item(self, item_dict: dict) -> Entity:
@ -859,7 +858,9 @@ class InventoryHolder(Entity):
entity_classes = self.get_all_entity_classes_in_a_dict()
item_class = entity_classes[item_dict["type"]]
return item_class(**item_dict)
item = item_class(**item_dict)
item.held_by = self
return item
def save_state(self) -> dict:
"""
@ -875,6 +876,7 @@ class InventoryHolder(Entity):
Adds an object to the inventory.
"""
if obj not in self.inventory:
obj.held_by = self
self.inventory.append(obj)
def remove_from_inventory(self, obj: Any) -> None: