albibong 1.0.6__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. albibong/__init__.py +58 -0
  2. albibong/classes/dungeon.py +39 -32
  3. albibong/classes/event_handler/__init__.py +10 -0
  4. albibong/classes/event_handler/handle_event_character_equipment_changed.py +2 -10
  5. albibong/classes/event_handler/handle_event_party.py +6 -13
  6. albibong/classes/event_handler/handle_operation_change_cluster.py +17 -22
  7. albibong/classes/event_handler/handle_operation_farmable_harvest.py +17 -0
  8. albibong/classes/event_handler/handle_operation_join.py +12 -29
  9. albibong/classes/event_handler/world_data_utils.py +78 -25
  10. albibong/classes/item.py +19 -4
  11. albibong/classes/location.py +137 -34
  12. albibong/gui_dist/assets/index-C4r00CBk.js +168 -0
  13. albibong/gui_dist/assets/index-DKbORdbN.css +1 -0
  14. albibong/gui_dist/index.html +2 -2
  15. albibong/models/__init__.py +0 -0
  16. albibong/models/models.py +12 -0
  17. albibong/requirements.txt +1 -0
  18. albibong/resources/EventCode.py +527 -522
  19. albibong/resources/OperationCode.py +287 -284
  20. albibong/resources/event_code.json +527 -522
  21. albibong/resources/{items.json → items_by_id.json} +21767 -21108
  22. albibong/resources/items_by_unique_name.json +55282 -0
  23. albibong/resources/maps.json +755 -514
  24. albibong/resources/operation_code.json +287 -284
  25. albibong/threads/websocket_server.py +64 -41
  26. {albibong-1.0.6.dist-info → albibong-1.1.0.dist-info}/METADATA +2 -1
  27. {albibong-1.0.6.dist-info → albibong-1.1.0.dist-info}/RECORD +30 -28
  28. albibong/gui_dist/assets/index-DZvgNqlG.css +0 -1
  29. albibong/gui_dist/assets/index-Dt6hyZiS.css +0 -1
  30. albibong/gui_dist/assets/index-E7pha23k.js +0 -161
  31. albibong/gui_dist/assets/index-WIuC9Mnh.js +0 -161
  32. {albibong-1.0.6.dist-info → albibong-1.1.0.dist-info}/WHEEL +0 -0
  33. {albibong-1.0.6.dist-info → albibong-1.1.0.dist-info}/entry_points.txt +0 -0
  34. {albibong-1.0.6.dist-info → albibong-1.1.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,48 +1,151 @@
1
1
  import json
2
2
  import os
3
+ import stat
4
+ import uuid
5
+ from datetime import date, datetime, timedelta
6
+
7
+ from peewee import CharField, DateTimeField, UUIDField, fn
8
+ from playhouse.sqlite_ext import JSONField
9
+
10
+ from albibong.classes.dungeon import Dungeon
11
+ from albibong.classes.item import Item
12
+ from albibong.models.models import BaseModel
3
13
 
4
14
  mapsJsonPath = os.path.join(os.path.dirname(__file__), "../resources/maps.json")
5
15
  with open(mapsJsonPath) as json_file:
6
16
  map_data = json.load(json_file)
7
17
 
8
18
 
9
- class Location:
10
-
11
- def __init__(self, id: str, name: str, type: str):
12
- self.id = id
13
- self.name = name
14
- self.type = type
15
-
16
- def is_black_zone(self):
17
- if self.type == "OPENPVP_BLACK":
18
- return True
19
- elif self.type == "DUNGEON_BLACK":
20
- return True
21
- elif self.type == "PASSAGE_BLACK":
22
- return True
23
- elif self.type == "TUNNEL":
24
- return True
25
- else:
26
- return False
27
-
28
- def is_red_zone(self):
29
- if self.type == "OPENPVP_RED":
30
- return True
31
- elif self.type == "DUNGEON_RED":
32
- return True
33
- elif self.type == "PASSAGE_RED":
34
- return True
35
- else:
36
- return False
37
-
38
- def is_safe_zone(self):
39
- if self.is_black_zone() == False and self.is_red_zone() == False:
40
- return True
41
- else:
42
- return False
19
+ class Location(BaseModel):
20
+
21
+ uuid = UUIDField(unique=True, default=uuid.uuid4)
22
+ id = CharField()
23
+ name = CharField()
24
+ type = CharField()
43
25
 
44
26
  @classmethod
45
27
  def get_location_from_code(cls, code: str):
46
28
  location = map_data[code]
47
29
 
48
30
  return cls(id=location["id"], name=location["name"], type=location["type"])
31
+
32
+
33
+ class Island(Location, BaseModel):
34
+
35
+ uuid = UUIDField(unique=True, default=uuid.uuid4)
36
+ id = CharField()
37
+ name = CharField()
38
+ type = CharField()
39
+ start_time = DateTimeField(default=datetime.now)
40
+ crops = JSONField(default=dict)
41
+ animals = JSONField(default=dict)
42
+
43
+ def add_crop(self, unique_name, quantity):
44
+ crop = Item.get_item_from_unique_name(unique_name)
45
+
46
+ if crop.name not in self.crops:
47
+ self.crops[crop.name] = Item.serialize(crop)
48
+
49
+ self.crops[crop.name]["quantity"] += quantity
50
+
51
+ def add_animal(self, unique_name, quantity):
52
+ animal = Item.get_item_from_unique_name(unique_name)
53
+
54
+ if animal.name not in self.animals:
55
+ self.animals[animal.name] = Item.serialize(animal)
56
+
57
+ self.animals[animal.name]["quantity"] += quantity
58
+
59
+ @staticmethod
60
+ def serialize(island):
61
+ data = {
62
+ "id": str(island.uuid),
63
+ "name": island.name,
64
+ "type": island.type,
65
+ "date_time": island.start_time.strftime("%a %d %b %Y, %I:%M%p"),
66
+ "crops": island.serialize_crops(),
67
+ "animals": island.serialize_animals(),
68
+ }
69
+ return data
70
+
71
+ def serialize_animals(self):
72
+ serialized = []
73
+
74
+ for key, value in self.animals.items():
75
+ serialized.append(value)
76
+
77
+ return serialized
78
+
79
+ def serialize_crops(self):
80
+ serialized = []
81
+
82
+ for key, value in self.crops.items():
83
+ serialized.append(value)
84
+
85
+ return serialized
86
+
87
+ @staticmethod
88
+ def get_all_island():
89
+ query = Island.select().order_by(Island.start_time.desc())
90
+ a = [Island.serialize(island) for island in query]
91
+ return a
92
+
93
+ @staticmethod
94
+ def get_total_harvest_by_date(date=datetime.today()):
95
+
96
+ date = date
97
+ tomorrow = date + timedelta(days=1)
98
+
99
+ query = Island.select().where(
100
+ Island.start_time >= date.date(),
101
+ Island.start_time < tomorrow.date(),
102
+ )
103
+
104
+ total_crops = {}
105
+ total_animals = {}
106
+
107
+ for island in query:
108
+
109
+ crops = island.crops
110
+ for key, value in crops.items():
111
+ if key not in total_crops:
112
+ total_crops[key] = {
113
+ "name": key,
114
+ "quantity": value["quantity"],
115
+ "image": value["image"],
116
+ }
117
+ else:
118
+ total_crops[key]["quantity"] += value["quantity"]
119
+
120
+ animals = island.animals
121
+ for key, value in animals.items():
122
+ if key not in total_animals:
123
+ total_animals[key] = {
124
+ "name": key,
125
+ "quantity": value["quantity"],
126
+ "image": value["image"],
127
+ }
128
+ else:
129
+ total_animals[key]["quantity"] += value["quantity"]
130
+
131
+ crops_result = []
132
+ for key, value in total_crops.items():
133
+ crops_result.append(value)
134
+
135
+ animals_result = []
136
+ for key, value in total_animals.items():
137
+ animals_result.append(value)
138
+
139
+ return {
140
+ "crops": crops_result,
141
+ "animals": animals_result,
142
+ "date": str(date.date()),
143
+ }
144
+
145
+ @staticmethod
146
+ def get_island_from_code(code: str):
147
+ island = map_data[code]
148
+
149
+ obj = Island(id=island["id"], name=island["name"], type=island["type"])
150
+
151
+ return obj