-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_map_objects.py
More file actions
765 lines (631 loc) · 29.4 KB
/
my_map_objects.py
File metadata and controls
765 lines (631 loc) · 29.4 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
from .imports import MapObject, KeybindInterface, DisplayStatsMessage, DialogueMessage, Player
from .scoreboard import Scoreboard
from .pizza_logic import Pizza, final_score
from .trash_can import TrashCan
from .pizza_toppings import ToppingDecorator
from .imports import ServerMessage, Message, GridMessage, Coord
import time
from .pizza_strategy import PizzaStrategy, SafeStrategy, RiskyStrategy, TimeAttackStrategy
from typing import TYPE_CHECKING
from collections.abc import Callable
from .pizza_logic import final_score
from .enums import Ingredient, DoughState, BakingState, Images, PlayerAttributes
from .custom_dialogue import CustomDialogue
class ToppingOverlay(MapObject):
"""
A class that represents an overlay for a pizza topping.
"""
LAYER_MAP = {
"sauce": 4,
"cheese": 5,
# everything else (pepperoni, mushrooms, peppers, pineapples) on top
}
def __init__(self, ingredient: str):
"""
Initializes the topping overlay with the specified ingredient.
Parameters
----------
ingredient : str
The ingredient to be added as a topping overlay (e.g., 'sauce', 'cheese').
Preconditions
----------
- 'ingredient' must be a valid string representing a topping (e.g., "sauce", "cheese").
Postconditions
----------
- A new 'ToppingOverlay' object is created for the specified ingredient and added to the map.
Invariant
----------
- The 'ingredient' must correspond to one of the valid toppings in the 'LAYER_MAP'.
"""
if isinstance(ingredient, str):
ingredient = Ingredient(ingredient.lower())
self.ingredient = ingredient
#pull the raw string out of the enum
name = ingredient.value # e.g. "sauce" or "cheese"
image_name = f"pizza_{name.lower()}"
# pick layer from map, default to 6
z = ToppingOverlay.LAYER_MAP.get(name.lower(), 6)
super().__init__(image_name, passable=True, z_index=z)
self.ingredient = ingredient
# no get_z_index override!
class DoughSpawnStation(MapObject, KeybindInterface):
"""
A class representing a station where dough is spawned and picked up.
"""
def __init__(self, image_name= Images.DOUGH_BUTTON.value, passable=False, z_index=2):
super().__init__(image_name, passable=passable, z_index=z_index)
def player_interacted(self, player):
# ensure the player has the right attributes
if not hasattr(player, PlayerAttributes.PIZZA_LIST.value):
player.pizza_list = []
if not hasattr(player, PlayerAttributes.CURR_PIZZA.value):
player.current_pizza = None
# only spawn if hand is empty
if player.current_pizza is None:
new_pizza = Pizza()
player.pizza_list.append(new_pizza)
player.current_pizza = new_pizza
return [
ServerMessage( player,
"Raw dough spawned and picked up! \nPlace on a station or oven [SPACE].",)
]
else:
return [ServerMessage( player, "You're already holding a pizza. Place it first.")]
class PizzaStation(MapObject, KeybindInterface):
def __init__(self, image_name, passable=False, z_index=2, place_offset: Coord = Coord(0,0)):
super().__init__(image_name, passable=passable, z_index=z_index)
self._pizza_on_station: Pizza | None = None
self._pizza_obj: PizzaMapObject | None = None
# offset from this tile where we actually draw the pizza wrapper
self._place_offset = place_offset
def _get_keybinds(self):
return {'space': self.player_interacted}
def player_interacted(self, player):
"""
Handles player interaction with the pizza station.
Parameters
----------
player : Player
The player interacting with the station.
Returns
-------
list[Message]
A list of messages to be shown to the player.
Preconditions
----------
- 'player' must be a valid 'Player' object.
- The player must either be placing or picking up a pizza.
Postconditions
----------
- If the player is placing a pizza, the pizza is placed on the station.
- If the player is picking up a pizza, the pizza is picked up and returned to the player's hand.
Invariant
----------
- The player cannot place or pick up a pizza if the station is already occupied or if the player is not holding a pizza.
"""
# Preconditions: Check if the player has a pizza and if the station is empty or not
assert isinstance(player, Player), "Precondition failed: player must be a valid Player object."
#assert (player.current_pizza is not None), "Precondition failed: player must be holding a pizza to place it."
room = player.get_current_room()
# ─── Prevent stacking ───
if player.current_pizza and self._pizza_on_station:
return [ ServerMessage( player, "There's already a pizza on that station!") ]
# ─── PLACE ───
if player.current_pizza and not self._pizza_on_station:
pizza = player.current_pizza
player.current_pizza = None
self._pizza_on_station = pizza
print(f"pizza_on_station is: {self._pizza_on_station}")
# choose sprite
base_img = Images.DOUGH.value if pizza.dough_state==DoughState.RAW else Images.DOUGH_KNEADED.value
wrapper = PizzaMapObject(pizza, image_name=base_img)
# compute where to draw
pos = self.get_position()
draw_pos = Coord(pos.y + self._place_offset.y,
pos.x + self._place_offset.x)
room.add_to_grid(wrapper, draw_pos)
wrapper.map = room
wrapper.coord = draw_pos
wrapper.update_visual()
self._pizza_obj = wrapper
return [
ServerMessage( player, "Pizza placed on station. \nPress [ENTER]"),
GridMessage(player, send_desc=False)
]
# ─── PICK UP ───
if not player.current_pizza and self._pizza_on_station:
player.current_pizza = self._pizza_on_station
self._pizza_on_station = None
if self._pizza_obj:
# tear down overlays
for ov in list(self._pizza_obj._overlays.values()):
room.remove_from_grid(ov, self._pizza_obj.coord)
# remove base
room.remove_from_grid(self._pizza_obj, self._pizza_obj.coord)
self._pizza_obj = None
return [
ServerMessage( player, "Picked up pizza from station."),
GridMessage(player, send_desc=False)
]
# ─── NOTHING ELSE ───
return [ ServerMessage( player, "Cannot place or pick up here.") ]
def process(self, player):
"""Default no-op; override in subclasses."""
return [ ServerMessage( player, "Nothing happens.") ]
class KneadingStation(PizzaStation):
def __init__(self):
super().__init__(Images.TABLE.value, passable=False)
self._knead_count = 0
def process(self, player):
"""
Processes the kneading action when a player interacts with the kneading station.
Parameters
----------
player : Player
The player interacting with the kneading station.
Returns
-------
list[Message]
A list of messages to be shown to the player upon interacting with the station.
Preconditions
----------
- 'player' must be a valid 'Player' object.
- The player must have placed a pizza at the kneading station.
Postconditions
----------
- If the pizza is placed on the station, the dough state of the pizza is updated after kneading.
- If the kneading count reaches 5, the dough state is changed to 'KNEADED'.
Invariant
----------
- The kneading count should always be incremented until it reaches 5, after which the pizza dough should be set to 'KNEADED'.
"""
assert isinstance(player, Player), "Precondition failed: player must be a valid Player object."
if not self._pizza_on_station:
return [ServerMessage( player, "No pizza here to knead.")]
self._knead_count += 1
if self._knead_count >= 5:
# flip dough state
self._pizza_on_station.knead_dough()
self._knead_count = 0
# update wrapper’s base image
if self._pizza_obj:
self._pizza_obj.set_image_name(Images.DOUGH_KNEADED.value)
return [
ServerMessage( player, "Dough is now kneaded!"),
GridMessage(player, send_desc=False)
]
else:
return [ ServerMessage( player, f"Kneading... {self._knead_count}/5")]
class IngredientStation(PizzaStation):
"""
A PizzaStation that adds exactly one Ingredient.
Subclasses just pass the enum member.
"""
def __init__(
self,
ingredient: Ingredient,
image_name: str = Images.TABLE.value,
passable: bool = False,
z_index: int = 2,
add_text: str | None = None
):
super().__init__(image_name, passable=passable, z_index=z_index)
self.ingredient = ingredient
# default message: "Sauce added!", "Cheese added!", etc.
self.add_text = add_text or f"{ingredient.value} added!"
def process(self, player):
"""
Processes the addition of an ingredient to a pizza when a player interacts with the ingredient station.
Parameters
----------
player : Player
The player interacting with the ingredient station.
Returns
-------
list[Message]
A list of messages to be shown to the player upon interacting with the station.
Preconditions
----------
- 'player' must be a valid 'Player' object.
- The player must have placed a pizza at the station.
Postconditions
----------
- If the pizza is placed on the station, the specified ingredient is added to the pizza.
- The pizza's topping list is updated, and a message is shown to the player.
Invariant
----------
- The pizza's 'ingredients' dictionary and 'topping_order' should always reflect the newly added topping.
"""
assert isinstance(player, Player), "Precondition failed: player must be a valid Player object."
# no pizza → error
if not self._pizza_on_station:
name = self.ingredient.value.lower()
return [ ServerMessage( player, f"No pizza here to add {name}.") ]
# decorate the pizza
ToppingDecorator(self._pizza_on_station, self.ingredient)
if self._pizza_obj:
self._pizza_obj.update_visual()
# success → message + grid update
return [
ServerMessage( player, self.add_text),
GridMessage(player, send_desc=False)
]
class SauceStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.SAUCE)
class CheeseStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.CHEESE)
class PineappleStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.PINEAPPLES)
class MushroomStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.MUSHROOMS)
class PeppersStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.PEPPERS)
class PepperoniStation(IngredientStation):
def __init__(self):
super().__init__(Ingredient.PEPPERONI)
class OvenStation(MapObject, KeybindInterface):
def __init__(self, image_name=Images.OVEN.value, passable=False, z_index=1):
super().__init__(image_name, passable=passable, z_index=z_index)
self._pizza_on_station = None # the pizza currently in the oven
self._baking_start_time = None # when the current bake session began
self._is_baking = False
self._accumulated_time = 0 # total seconds baked so far
def _get_keybinds(self):
# X = pick/place (via player.interact), Enter = toggle bake
return {
'return': self.process,
}
def player_interacted(self, player):
msgs = []
# place pizza into empty oven
if player.current_pizza and self._pizza_on_station is None:
self._pizza_on_station = player.current_pizza
player.current_pizza = None
# reset bake state for this pizza
self._is_baking = False
self._baking_start_time= None
self._accumulated_time = 0
msgs.append(ServerMessage( player, "Pizza placed in the oven. \n[ENTER] to bake."))
# pick up if not baking
elif (player.current_pizza is None and
self._pizza_on_station and
not self._is_baking):
player.current_pizza = self._pizza_on_station
self._pizza_on_station = None
msgs.append(ServerMessage( player, "Picked up pizza from the oven."))
else:
msgs.append(ServerMessage( player, "Cannot pick/place right now."))
return msgs
def process(self, player):
"""
Processes the baking action when a player interacts with the oven station.
Parameters
----------
player : Player
The player interacting with the oven station.
Returns
-------
list[Message]
A list of messages to be shown to the player upon interacting with the oven station.
Preconditions
----------
- 'player' must be a valid 'Player' object.
- The player must have placed a pizza in the oven.
Postconditions
----------
- If the player places a pizza in the oven, the baking process starts.
- If the player presses the action button again, the pizza is baked for the accumulated time, and its baking state is updated.
Invariant
----------
- The pizza's baking state must always reflect the current time elapsed in the oven.
- The pizza's baking state is updated to either 'UNDERCOOKED', 'PERFECT', or 'OVERCOOKED' based on the elapsed time.
"""
assert isinstance(player, Player), "Precondition failed: player must be a valid Player object."
# nothing in the oven?
if self._pizza_on_station is None:
return [ServerMessage( player, "No pizza in the oven to bake.")]
# start baking
if not self._is_baking:
self._baking_start_time = time.time()
self._is_baking = True
return [ServerMessage( player, "Baking started! \nBake for 5-10 seconds for the PERFECT pizza!")]
# stop baking
else:
# session elapsed
elapsed = time.time() - self._baking_start_time
# accumulate
self._accumulated_time += elapsed
# update pizza’s state based on total bake time :contentReference[oaicite:0]{index=0}
self._pizza_on_station.update_baking(self._accumulated_time)
state = self._pizza_on_station.baking_state
# reset session
self._is_baking = False
self._baking_start_time = None
return [ServerMessage(
player,
f"Pizza baked for {self._accumulated_time:.1f}s total. It is {state}. \nPlace on ORDER station"
)]
class TrashCanStation(MapObject):
def __init__(
self,
image_name: str = Images.TRASH_CAN.value,
passable: bool = False,
z_index: int = 1
) -> None:
super().__init__(image_name, passable=passable, z_index=z_index)
# set up the Subject/Observer for scoring
self._subject = TrashCan()
self._subject.attach(Scoreboard())
def player_interacted(self, player) -> list["Message"]:
pizza = getattr(player, PlayerAttributes.CURR_PIZZA.value, None)
if pizza is not None and pizza in player.pizza_list:
# remove the pizza and deduct points
player.pizza_list.remove(pizza)
player.current_pizza = None
self._subject.discard_pizza(pizza) # notifies Scoreboard observer :contentReference[oaicite:0]{index=0}
# fetch the new score
new_score = Scoreboard().get_score() # Scoreboard singleton :contentReference[oaicite:1]{index=1}
# send both confirmation and updated score in chat
return [
ServerMessage( player, "Pizza discarded!"),
ServerMessage( player, f"Score: {new_score}")
]
else:
return [ServerMessage( player, "You're not holding any pizza.")]
class Flour(MapObject):
def __init__(self, image_name: str = Images.KNEAD_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class TomatoSauce(MapObject):
def __init__(self, image_name: str = Images.SAUCE_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class Cheese(MapObject):
def __init__(self, image_name: str = Images.CHEESE_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class Mushroom(MapObject):
def __init__(self, image_name: str = Images.MUSHROOM_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class Pepperoni(MapObject):
def __init__(self, image_name: str = Images.PEPPERONI_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class Pepper(MapObject):
def __init__(self, image_name: str = Images.PEPPER_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class Pineapple(MapObject):
def __init__(self, image_name: str = Images.PINEAPPLE_STATION.value, passable: bool = False, z_index: int = 2):
super().__init__(image_name, passable=passable)
class ServingTable(PizzaStation):
def __init__(
self,
image_name: str = Images.SERVING_TABLE.value,
correct_pizza: Pizza | None = None,
default_strategy: PizzaStrategy | None = None,
passable: bool = False,
z_index: int = 2
):
# place_offset=(1,0) so pizza draws one tile below
super().__init__(image_name, passable, z_index, place_offset=Coord(2,0))
self.correct_pizza = correct_pizza #or Pizza()
self._default_strategy = default_strategy or SafeStrategy()
def process(self, player):
"""
Processes the action when a player interacts with the serving table.
The player either serves the pizza or checks the correctness of the pizza on the serving table.
Parameters
----------
player : Player
The player interacting with the serving table.
Returns
-------
list[Message]
A list of messages to be shown to the player upon interaction with the serving table.
Preconditions
----------
- 'player' must be a valid 'Player' object.
- The player must have a pizza placed on the serving table.
Postconditions
----------
- If the pizza is correctly made, the player is served with the pizza, and points are awarded.
- If the pizza is incorrect, the player is notified and no points are awarded.
- The serving table's pizza is removed after serving.
Invariant
----------
- The pizza’s ingredients, dough state, and baking state should be checked to determine correctness.
- The correct pizza should be matched against the pizza placed on the table.
"""
assert isinstance(player, Player), "Precondition failed: player must be a valid Player object."
if not self._pizza_on_station:
return [ServerMessage( player, "No pizza here to serve.")]
room = player.get_current_room()
pizza = self._pizza_on_station
correct = self.correct_pizza
# Debugging player.pizza_list and correct
print(f"Player's pizza list: {player.pizza_list}")
print(f"Correct pizza: {correct}")
# Ensure pizza list is not empty
if not player.pizza_list:
return [ServerMessage( player, "No pizzas in your list to process.")]
# Ensure the correct pizza is valid
if correct is None:
return [ServerMessage( player, "No correct pizza to compare against.")]
strat = getattr(player, PlayerAttributes.STRAT.value, self._default_strategy)
if strat is None:
return [ServerMessage( player, "Invalid strategy.")]
name = type(strat).__name__
#TIME ATTACK
if name == "TimeAttackStrategy" and hasattr(player, PlayerAttributes.END_TIME_TA.value):
# 1) add this pizza to the running list
player.ta_pizzas.append(pizza)
# 2) call evaluate on all pizzas served so far
new_total = strat.evaluate(player.ta_pizzas, correct)
# 3) incremental points = delta since last serve
earned = new_total - player.ta_score_running
player.ta_score_running = new_total
# ⏱ build a combo/bonus message
combo = len(player.ta_pizzas) # 1 pizza → x1, 2 pizzas → x2 …
combo_txt = f"(x{combo} combo)"
earned_txt = f"+{earned:.1f} pts"
else:
# normal safe and risky strategy flow
print(f"Correct pizza: {correct}")
topping_score = strat.evaluate(pizza, correct)
earned = final_score(pizza, correct, topping_score)
# Compute extras/missing
extras, missing = [], []
for ing, c_cnt in correct.ingredients.items():
p_cnt = pizza.ingredients.get(ing, 0)
if isinstance(c_cnt, bool):
diff = (1 if p_cnt else 0) - (1 if c_cnt else 0)
else:
diff = p_cnt - c_cnt
if diff > 0:
extras.append((ing.value, diff))
elif diff < 0:
missing.append((ing.value, -diff))
# # Evaluate topping score & final score
# topping_score = strat.evaluate(pizza, correct)
# earned = final_score(pizza, correct, topping_score)
# *** AWARD POINTS ONCE ***
sb = Scoreboard()
sb.add_points(earned)
new_total = sb.get_score()
# Build feedback
if name == "TimeAttackStrategy":
msg1 = f"{earned_txt} {combo_txt}"
elif name == "RiskyStrategy":
if extras:
desc = " and ".join(f"{cnt} {ing}" for ing, cnt in extras)
if earned < 0:
msg1 = (f"Risky backfired! Customer hated the {desc}, "
f"you lost {abs(earned)} points.")
else:
msg1 = (f"Risky paid off! Customer loved the {desc}, "
f"you gained {earned} points.")
else:
if missing:
desc = " and ".join(f"{cnt} {ing}" for ing, cnt in missing)
msg1 = (f"You tried risky but missed {desc}, "
f"you lost {abs(earned)} points.")
else:
msg1 = f"You played it safe! You earned {earned} points."
else:
# SafeStrategy
if not extras and not missing:
msg1 = f"Perfect pizza! You earned {earned} points with {name}."
else:
parts = []
if missing:
parts.append("missing " + " and ".join(f"{cnt} {ing}" for ing, cnt in missing))
if extras:
parts.append("extra " + " and ".join(f"{cnt} {ing}" for ing, cnt in extras))
desc = " and ".join(parts)
penalty = sum(cnt for _, cnt in extras) + sum(cnt for _, cnt in missing)
msg1 = (f"Your pizza had {desc}. You lost {penalty} point"
f"{'s' if penalty>1 else ''}, net you earned {earned} points with {name}.")
msg2 = f"Your total score is now {new_total} points."
# cleanup sprite + state
if self._pizza_obj:
for ov in list(self._pizza_obj._overlays.values()):
room.remove_from_grid(ov, self._pizza_obj.coord)
room.remove_from_grid(self._pizza_obj, self._pizza_obj.coord)
self._pizza_obj = None
self._pizza_on_station = None
if pizza in player.pizza_list:
player.pizza_list.remove(pizza)
return [
ServerMessage( player, msg1),
ServerMessage( player, msg2),
GridMessage(player, send_desc=False)
]
class PizzaMapObject(MapObject):
def __init__(self, pizza, image_name=Images.DOUGH.value, passable=True, z_index=3):
super().__init__(image_name, passable=passable, z_index=z_index)
self._pizza = pizza
self._overlays: dict[str, ToppingOverlay] = {}
self._last_state = pizza.dough_state
def update(self) -> list["Message"]:
msgs = []
# 1) Base sprite change?
if self._pizza.dough_state != self._last_state:
self._last_state = self._pizza.dough_state
new_img = Images.DOUGH_KNEADED.value if self._pizza.dough_state == DoughState.KNEADED.value else Images.DOUGH.value
self.set_image_name(new_img)
# force redraw
# we need a GridMessage, but we don't know the player here—so the station will do it
# 2) Topping overlays
self.update_visual()
return msgs
def update_visual(self):
from .my_map_objects import ToppingOverlay
for ing, qty in self._pizza.ingredients.items():
should = bool(qty)
has = ing in self._overlays
if should and not has:
ov = ToppingOverlay(ing)
self.map.add_to_grid(ov, self.get_position())
self._overlays[ing] = ov
elif not should and has:
self.map.remove_from_grid(self._overlays[ing], self.get_position())
del self._overlays[ing]
import random
class OrderStation(MapObject, KeybindInterface):
"""Stepping on this spawns a random 'correct' pizza order and re-prompts strategy selection."""
def __init__(
self,
serving_table,
image_name: str = Images.ORDER_STATION.value,
passable: bool = False,
z_index: int = 2
):
super().__init__(image_name, passable=passable, z_index=z_index)
self.serving_table = serving_table
# list of all possible ingredient keys
self._topping_keys = list(Pizza().ingredients.keys())
def player_interacted(self, player):
msgs = []
# ─── Show the strategy menu only if *not* in an active Time‑Attack round ───
ta_active = (
isinstance(getattr(player, PlayerAttributes.STRAT.value, None), TimeAttackStrategy)
and getattr(player, PlayerAttributes.END_TIME_TA.value, 0) > time.time()
)
if not ta_active:
msgs.append(ServerMessage( player, "Select your pizza strategy:\n1: SafeStrategy\n2: RiskyStrategy\n3: TimeAttackStrategy\nPress 1, 2, or 3 to choose."))
msgs.append(ServerMessage(player, f"Welcome to @_chaewon.aura_'s pizzeria!"))
# msgs.append(ServerMessage( player, "1: SafeStrategy"))
# msgs.append(ServerMessage( player, "2: RiskyStrategy"))
# msgs.append(ServerMessage( player, "3: TimeAttackStrategy"))
# msgs.append(ServerMessage( player, "Press 1, 2, or 3 to choose."))
# 2) Build a new random 'correct' pizza
correct = Pizza()
correct.topping_order = []
correct.dough_state = DoughState.KNEADED
correct.baking_state = BakingState.PERFECT
for ing in self._topping_keys:
if isinstance(correct.ingredients[ing], bool):
has_it = random.choice([True, False])
correct.ingredients[ing] = has_it
if has_it:
correct.topping_order.append(ing)
else:
cnt = random.randint(0, 2)
correct.ingredients[ing] = cnt
correct.topping_order += [ing] * cnt
#debug to check if correct pizza is correct after interacting with serving station
print(f"Correct pizza after interacting with order station: {correct}")
# 3) Assign it to the serving table
self.serving_table.correct_pizza = correct
# 4) Print the new order
msgs.append(ServerMessage( player, "*** NEW ORDER! ***"))
for ing, val in correct.ingredients.items():
# ing is an Ingredient enum, so use .value to get the string
name = ing.value
if isinstance(val, bool):
if val:
msgs.append(ServerMessage(player, f"- {name}"))
elif val > 0:
msgs.append(ServerMessage(player, f"- {val}× {name}"))
return msgs