-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.py
More file actions
64 lines (56 loc) · 1.57 KB
/
entity.py
File metadata and controls
64 lines (56 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from dataclasses import dataclass, field
import json
import sys
from typing import List, NewType
import uuid
EntityId = NewType("EntityId", str)
EntityName = NewType("EntityName", str)
@dataclass
class Entity:
id: EntityId = str(uuid.uuid4())
name: str = ""
inventory: List[str] = field(default_factory=lambda: [])
location: EntityId = ""
description_long: str = ""
description_short: str = ""
hit_points: int = sys.maxsize
unlocked_by: EntityId = ""
destination: EntityId = ""
dialogue: str = ""
takeable: bool = False
lootable: bool = False
spawnable: bool = False
spawns: EntityId = ""
damage: List[int] = field(default_factory=list)
combat_level: int = None
combat_experience: int = None
loot_level: int = 0
loot_experience: int = 0
equiped: EntityId = None
equipable: bool = False
drinkable: bool = False
discovered: bool = False
color: str = ""
crouched: bool = False
ingredient: EntityId = None
produces: EntityId = None
use: str = ""
usable: bool = False
take: str = ""
go_interrupt: str =""
north: EntityId = None
south: EntityId = None
east: EntityId = None
west: EntityId = None
def __callable__(self):
pass
def to_json(self):
return json.dumps(self, indent=4, cls=EntityEncoder)
@classmethod
def from_json(cls, payload):
return cls(**json.loads(payload))
class EntityEncoder(json.JSONEncoder):
def default(self, obj):
obj_dict = obj.__dict__
obj_dict.pop("inventory")
return obj_dict