-
Notifications
You must be signed in to change notification settings - Fork 183
/
pokete.py
executable file
·1691 lines (1528 loc) · 60.7 KB
/
pokete.py
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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""This software is licensed under the GPL3
You should have gotten an copy of the GPL3 license anlonside this software
Feel free to contribute what ever you want to this game
New Pokete contributions are especially welcome
For this see the comments in the definations area
You can contribute here: https://github.com/lxgr-linux/pokete
Thanks to MaFeLP for your code review and your great feedback"""
import time
import os
import sys
import threading
import math
import socket
import json
import logging
from pathlib import Path
from datetime import datetime
import scrap_engine as se
import pokete_data as p_data
import release
from pokete_classes import animations
from pokete_classes.pokestats import PokeStats
from pokete_classes.poke import Poke, upgrade_by_one_lvl
from pokete_classes.color import Color
from pokete_classes.ui_elements import ChooseBox, InfoBox, BetterChooseBox
from pokete_classes.classes import PlayMap
from pokete_classes.settings import settings, VisSetting, Slider
from pokete_classes.inv_items import invitems, LearnDisc
from pokete_classes.types import types
from pokete_classes.providers import ProtoFigure
from pokete_classes.buy import Buy, InvBox
from pokete_classes.audio import audio
from pokete_classes.tss import tss
from pokete_classes.side_loops import LoadingScreen, About, Help
from pokete_classes.input import text_input, ask_bool, ask_text, ask_ok
from pokete_classes.mods import ModError, ModInfo, DummyMods
from pokete_classes.pokete_care import PoketeCare, DummyFigure
from pokete_classes import deck, detail, game, timer, ob_maps as obmp, \
movemap as mvp, fightmap as fm
# import pokete_classes.generic_map_handler as gmh
from pokete_classes.landscape import Meadow, Water, Sand, HighGrass, Poketeball
from pokete_classes.doors import (
CenterDoor, Door, DoorToCenter, DoorToShop, ChanceDoor
)
from pokete_classes.learnattack import LearnAttack
from pokete_classes.roadmap import RoadMap
from pokete_classes.npcs import NPC, Trainer
from pokete_classes.notify import notifier
from pokete_classes.achievements import achievements, AchievementOverview
from pokete_classes.event import _ev
from pokete_classes.hotkeys import (
get_action, Action, ACTION_DIRECTIONS, hotkeys_save, hotkeys_from_save
)
from pokete_classes.dex import Dex
from pokete_classes.loops import std_loop
from pokete_classes.periodic_event_manager import PeriodicEventManager
from util import liner, sort_vers
from release import SPEED_OF_TIME
from release import VERSION, CODENAME, SAVEPATH
from util.command import RootCommand, Flag
__t = time.time()
# Class definition
##################
class NPCActions:
"""This class contains all functions callable by NPCs
All this methods follow the same pattern:
ARGS:
npc: The NPC the method belongs to"""
@staticmethod
def swap_poke(_):
"""Swap_poke wrapper"""
swap_poke()
@staticmethod
def heal(_):
"""Heal wrapper"""
figure.heal()
@staticmethod
def playmap_13_introductor(npc):
"""Interaction with introductor"""
if not obmp.ob_maps["playmap_14"].trainers[-1].used:
npc.text(
[
"To get to the other side of this building, "
"you have to win some epic fights against Deepest "
"Forests' best trainers!", "This won't be easy!"
]
)
else:
npc.text(
[
"It looks like you've been succesfull!",
"Congrats!"
]
)
npc.set_used()
@staticmethod
def playmap_17_boy(npc):
"""Interaction with boy"""
if "choka" in [i.identifier for i in figure.pokes[:6]]:
npc.text(["Oh, cool!", "You have a Choka!",
"I've never seen one before!",
"Here you go, have $200!"])
if ask_bool(
mvp.movemap,
"The young boy gifted you $200. Do you want to accept it?",
mvp.movemap
):
figure.add_money(200)
npc.set_used()
else:
npc.text(["In this region lives the Würgos Pokete.",
f"At level {p_data.pokes['würgos']['evolve_lvl']} \
It evolves into Choka.",
"I have never seen one before!"])
@staticmethod
def playmap_20_trader(npc):
"""Interaction with trader"""
if ask_bool(mvp.movemap, "Do you want to trade a Pokete?", mvp.movemap):
if (index := deck.deck(mvp.movemap, 6, "Your deck", True)) is None:
return
figure.add_poke(Poke("ostri", 500), index)
npc.set_used()
ask_ok(
mvp.movemap,
f"You received: {figure.pokes[index].name.capitalize()}"
f" at level {figure.pokes[index].lvl()}.",
mvp.movemap
)
mvp.movemap.text(npc.x, npc.y, ["Cool, huh?"])
@staticmethod
def playmap_50_npc_29(npc):
"""Interaction with npc_28"""
if pokete_care.poke is None:
npc.text(["Here you can leave one of your Poketes for some time \
and we will train it."])
if ask_bool(
mvp.movemap,
"Do you want to put a Pokete into the Pokete-Care?",
mvp.movemap
):
if (index := deck.deck(mvp.movemap, 6, "Your deck",
True)) is not None:
pokete_care.poke = figure.pokes[index]
pokete_care.entry = timer.time.time
figure.add_poke(Poke("__fallback__", 0), index)
npc.text(["We will take care of it."])
else:
add_xp = int((timer.time.time - pokete_care.entry) / 30)
pokete_care.entry = timer.time.time
pokete_care.poke.add_xp(add_xp)
npc.text(["Oh, you're back.", f"Your {pokete_care.poke.name} \
gained {add_xp}xp and reached level {pokete_care.poke.lvl()}!"])
if ask_bool(mvp.movemap, "Do you want it back?", mvp.movemap):
dummy = DummyFigure(pokete_care.poke)
while dummy.pokes[0].evolve(dummy, mvp.movemap):
continue
figure.add_poke(dummy.pokes[0])
figure.caught_pokes += dummy.caught_pokes
npc.text(["Here you go!", "Until next time!"])
pokete_care.poke = None
npc.text(["See you!"])
@staticmethod
def playmap_23_npc_8(npc):
"""Interaction with npc_8"""
if ask_bool(
mvp.movemap,
"The man gifted you $100. Do you want to accept it?", mvp.movemap
):
npc.set_used()
figure.add_money(100)
@staticmethod
def playmap_10_old_man(npc):
"""Interaction with ld_man"""
npc.give("Old man", "hyperball")
@staticmethod
def playmap_29_ld_man(npc):
"""Interaction with ld_man"""
npc.give("The man", "ld_flying")
@staticmethod
def playmap_32_npc_12(npc):
"""Interaction with npc_12"""
npc.give("Old man", "hyperball")
@staticmethod
def playmap_36_npc_14(npc):
"""Interaction with npc_14"""
npc.give("Old woman", "ap_potion")
@staticmethod
def playmap_37_npc_15(npc):
"""Interaction with npc_14"""
npc.give("Bert the bird", "super_potion")
@staticmethod
def playmap_39_npc_20(npc):
"""Interaction with npc_20"""
npc.give("Gerald the farmer", "super_potion")
@staticmethod
def playmap_47_npc_26(npc):
"""Interaction with npc_26"""
npc.give("Poor man", "healing_potion")
@staticmethod
def playmap_48_npc_27(npc):
"""Interaction with npc_27"""
npc.give("Old geezer", "ld_the_old_roots_hit")
@staticmethod
def playmap_49_npc_28(npc):
"""Interaction with npc_28"""
npc.give("Candy man", "treat")
@staticmethod
def playmap_42_npc_21(npc):
"""Interaction with npc_21"""
poke_list = [i for i in figure.pokes[:6]
if i.lvl() >= 50 and i.identifier == "mowcow"]
if len(poke_list) > 0:
poke = poke_list[0]
npc.text(["Oh great!", "You're my hero!",
f"You brought me a level {poke.lvl()} Mowcow!",
"I'm thanking you!",
"Now I can still serve the best MowCow-Burgers!",
"Can I have it?"])
if ask_bool(
mvp.movemap,
"Do you want to give your Mowcow to the cook?", mvp.movemap
):
figure.pokes[figure.pokes.index(poke)] = Poke("__fallback__", 0)
npc.text(["Here you go, have $1000!"])
if ask_bool(
mvp.movemap,
"The cook gifted you $1000. "
"Do you want to accept it?",
mvp.movemap
):
figure.add_money(1000)
npc.set_used()
else:
npc.text(["Ohhh man...", "All of our beef is empty...",
"How are we going to serve the best MowCow-Burgers "
"without beef?",
"If only someone here could bring me a fitting "
"Mowcow!?",
"But it has to be at least on level 50 to meet our "
"high quality standards.",
"I will pay a good price!"])
@staticmethod
def playmap_39_npc_25(npc):
"""Interaction with npc_25"""
if not NPC.get("Leader Sebastian").used:
npc.text(["I can't let you go!",
"You first have to defeat our arena leader!"])
figure.set(figure.x + 1, figure.y)
else:
npc.text(["Have a pleasant day."])
@staticmethod
def playmap_43_npc_23(npc):
"""Interaction with npc_23"""
if ask_bool(mvp.movemap, "Do you also want to have one?", mvp.movemap):
figure.pokes.append(Poke("mowcow", 2000))
npc.set_used()
@staticmethod
def chat(npc):
"""Starts a chat"""
npc.chat()
class CenterInteract(se.Object):
"""Triggers a conversation in the Pokete center"""
def action(self, ob):
"""Triggers the interaction in the Pokete center
ARGS:
ob: The object triggering this action"""
_ev.clear()
mvp.movemap.full_show()
mvp.movemap.text(
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8,
3,
[
"Welcome to the Pokete-Center",
"What do you want to do?",
"1: See your full deck\n 2: Heal all your Poketes\n 3: Cuddle with the Poketes"
]
)
while True:
action = get_action()
if action.triggers(Action.ACT_1):
while "__fallback__" in [p.identifier for p in figure.pokes]:
figure.pokes.pop([p.identifier for p in
figure.pokes].index("__fallback__"))
mvp.movemap.balls_label_rechar(figure.pokes)
deck.deck(mvp.movemap, len(figure.pokes))
break
elif action.triggers(Action.ACT_2):
figure.heal()
time.sleep(SPEED_OF_TIME * 0.5)
mvp.movemap.text(
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8, 3,
["...", "Your Poketes are now healed!"]
)
break
elif action.triggers(Action.CANCEL, Action.ACT_3):
break
std_loop(box=mvp.movemap)
mvp.movemap.full_show(init=True)
class ShopInteract(se.Object):
"""Triggers an conversation in the shop"""
def action(self, ob):
"""Triggers an interaction in the shop
ARGS:
ob: The object triggering this action"""
_ev.clear()
mvp.movemap.full_show()
mvp.movemap.text(mvp.movemap.bmap.inner.x - mvp.movemap.x + 9, 3,
["Welcome to the Pokete-Shop",
"Wanna buy something?"])
buy()
mvp.movemap.full_show(init=True)
mvp.movemap.text(mvp.movemap.bmap.inner.x - mvp.movemap.x + 9, 3,
["Have a great day!"])
class CenterMap(PlayMap):
"""Contains all relevant objects for centermap
ARGS:
_he: The maps height
_wi: The maps width"""
def __init__(self, _he, _wi):
super().__init__(_he, _wi, name="centermap",
pretty_name="Pokete-Center", song="Map.mp3")
self.inner = se.Text(""" ________________
|______________|
| |a | |
| ¯ ¯¯ |
| |
|______ ______|
|_____| |_____|""", ignore=" ")
self.interact = CenterInteract("¯", state="float")
self.dor_back1 = CenterDoor(" ", state="float")
self.dor_back2 = CenterDoor(" ", state="float")
self.trader = NPC("trader",
["I'm a trader.",
"Here you can trade one of your Poketes for \
one from another trainer."],
"swap_poke")
# adding
self.dor_back1.add(self, int(self.width / 2), 8)
self.dor_back2.add(self, int(self.width / 2) + 1, 8)
self.inner.add(self, int(self.width / 2) - 8, 1)
self.interact.add(self, int(self.width / 2), 4)
self.trader.add(self, int(self.width / 2) - 6, 3)
class ShopMap(PlayMap):
"""Contains all relevant objects for shopmap
ARGS:
_he: The maps height
_wi: The maps width """
def __init__(self, _he, _wi):
super().__init__(_he, _wi, name="shopmap",
pretty_name="Pokete-Shop", song="Map.mp3")
self.inner = se.Text(""" __________________
|________________|
| |a | |
| ¯ ¯¯ |
| |
|_______ _______|
|______| |______|""", ignore=" ")
self.interact = ShopInteract("¯", state="float")
self.dor_back1 = CenterDoor(" ", state="float")
self.dor_back2 = CenterDoor(" ", state="float")
# adding
self.dor_back1.add(self, int(self.width / 2), 8)
self.dor_back2.add(self, int(self.width / 2) + 1, 8)
self.inner.add(self, int(self.width / 2) - 9, 1)
self.interact.add(self, int(self.width / 2), 4)
class Figure(se.Object, ProtoFigure):
"""The figure that moves around on the map and represents the player
ARGS:
_si: session_info dict"""
def __init__(self, _si):
r_char = _si.get("represent_char", "a")
if len(r_char) != 1:
logging.info(
"[Figure] '%s' is no valid 'represent_char', resetting", r_char)
r_char = "a"
super().__init__(r_char, state="solid")
ProtoFigure.__init__(
self,
[Poke.from_dict(_si["pokes"][poke]) for poke in _si["pokes"]],
escapable=True,
xp_multiplier=2
)
self.__money = _si.get("money", 10)
self.inv = _si.get("inv", {"poketeballs": 10})
self.name = _si.get("user", "DEFAULT")
self.caught_pokes = _si.get("caught_poketes", [])
self.visited_maps = _si.get("visited_maps", ["playmap_1"])
self.used_npcs = _si.get("used_npcs", [])
self.last_center_map = obmp.ob_maps[_si.get("last_center_map",
"playmap_1")]
self.oldmap = obmp.ob_maps[_si.get("oldmap", "playmap_1")]
self.direction = "t"
def set_args(self, _si):
"""Processes data from save file
ARGS:
_si: session_info dict"""
try:
# Looking if figure would be in centermap,
# so the player may spawn out of the center
if _si["map"] in ["centermap", "shopmap"]:
_map = obmp.ob_maps[_si["map"]]
self.add(_map, _map.dor_back1.x, _map.dor_back1.y - 1)
else:
if self.add(obmp.ob_maps[_si["map"]], _si["x"], _si["y"]) == 1:
raise se.CoordinateError(self, obmp.ob_maps[_si["map"]],
_si["x"], _si["y"])
except se.CoordinateError:
self.add(obmp.ob_maps["playmap_1"], 6, 5)
mvp.movemap.name_label.rechar(self.name, esccode=Color.thicc)
mvp.movemap.code_label.rechar(self.map.pretty_name)
mvp.movemap.balls_label_rechar(self.pokes)
mvp.movemap.add_obs()
def add_money(self, money):
"""Adds money
ARGS:
money: Amount of money being added"""
self.set_money(self.__money + money)
def get_money(self):
"""Getter for __money
RETURNS:
The current money"""
return self.__money
def set_money(self, money):
"""Sets the money to a certain value
ARGS:
money: New value"""
assert money >= 0, "Money has to be positive."
logging.info("[Figure] Money set to $%d from $%d",
money, self.__money)
self.__money = money
for cls in [inv, buy]:
cls.money_label.rechar("$" + str(self.__money))
cls.box.set_ob(cls.money_label,
cls.box.width - 2 - len(cls.money_label.text), 0)
def add_poke(self, poke: Poke, idx=None, caught_with=None):
"""Adds a Pokete to the players Poketes
ARGS:
poke: Poke object beeing added
idx: Index of the Poke
caught_with: Name of ball which was used"""
poke.set_player(True)
poke.set_poke_stats(
PokeStats(poke.name, datetime.now(), caught_with=caught_with))
self.caught_pokes.append(poke.identifier)
if idx is None:
id_list = [i.identifier for i in self.pokes]
if "__fallback__" in id_list:
idx = id_list.index("__fallback__")
self.pokes[idx] = poke
else:
self.pokes.append(poke)
else:
self.pokes[idx] = poke
logging.info("[Figure] Added Poke %s", poke.name)
def give_item(self, item, amount=1):
"""Gives an item to the player"""
assert amount > 0, "Amounts have to be positive!"
if item not in self.inv:
self.inv[item] = amount
else:
self.inv[item] += amount
logging.info("[Figure] %d %s(s) given", amount, item)
def has_item(self, item):
"""Checks if an item is already present
ARGS:
item: Generic item name
RETURNS:
If the player has this item"""
return item in self.inv and self.inv[item] > 0
def remove_item(self, item, amount=1):
"""Removes a certain amount of an item from the inv
ARGS:
item: Generic item name
amount: Amount of items beeing removed"""
assert amount > 0, "Amounts have to be positive!"
assert item in self.inv, f"Item {item} is not in the inventory!"
assert self.inv[item] - amount >= 0, f"There are not enought {item}s \
in the inventory!"
self.inv[item] -= amount
logging.info("[Figure] %d %s(s) removed", amount, item)
class Debug:
"""Debug class"""
@classmethod
def pos(cls):
"""Prints the figures' position"""
print(figure.x, figure.y, figure.map.name)
class Inv:
"""Inventory to see and manage items in
ARGS:
_map: se.Map this will be shown on"""
def __init__(self, _map):
self.map = _map
self.box = ChooseBox(_map.height - 3, 35, "Inventory",
f"{Action.REMOVE.mapping}:remove")
self.box2 = InvBox(7, 21, overview=self)
self.money_label = se.Text(f"${figure.get_money()}")
self.desc_label = se.Text(" ")
# adding
self.box.add_ob(self.money_label,
self.box.width - 2 - len(self.money_label.text), 0)
self.box2.add_ob(self.desc_label, 1, 1)
def resize_view(self):
"""Manages recursive view resizing"""
self.box.remove()
self.map.resize_view()
self.box.resize(self.map.height - 3, 35)
self.box.add(self.map, self.map.width - self.box.width, 0)
mvp.movemap.full_show()
def __call__(self):
"""Opens the inventory"""
_ev.clear()
items = self.add()
self.box.resize(self.map.height - 3, 35)
with self.box.add(self.map, self.map.width - 35, 0):
while True:
action = get_action()
if action.triggers(Action.UP, Action.DOWN):
self.box.input(action)
elif action.triggers(Action.CANCEL):
break
elif action.triggers(Action.ACCEPT):
obj = items[self.box.index.index]
self.box2.name_label.rechar(obj.pretty_name)
self.desc_label.rechar(liner(obj.desc, 19))
self.box2.add(self.map, self.box.x - 19, 3)
while True:
action = get_action()
if (
action.triggers(Action.CANCEL)
or action.triggers(Action.ACCEPT)
):
self.box2.remove()
if obj.name == "treat":
if ask_bool(
self.map,
"Do you want to upgrade one of "
"your Poketes by a level?",
self
):
ex_cond = True
while ex_cond:
index = deck.deck(
mvp.movemap, 6, label="Your deck",
in_fight=True
)
if index is None:
ex_cond = False
self.map.show(init=True)
break
poke = figure.pokes[index]
break
if not ex_cond:
break
upgrade_by_one_lvl(poke, figure, self.map)
items = self.rem_item(obj.name, items)
ask_ok(
self.map,
f"{poke.name} reached level "
f"{poke.lvl()}!",
self
)
elif isinstance(obj, LearnDisc):
if ask_bool(
self.map,
f"Do you want to teach "
f"'{obj.attack_dict['name']}'?",
self
):
ex_cond = True
while ex_cond:
index = deck.deck(
mvp.movemap, 6, label="Your deck",
in_fight=True
)
if index is None:
ex_cond = False
self.map.show(init=True)
break
poke = figure.pokes[index]
if getattr(types,
obj.attack_dict['types'][0]) \
in poke.types:
break
ex_cond = ask_bool(
self.map,
"You can't teach "
f"'{obj.attack_dict['name']}' to "
f"'{poke.name}'! \n"
"Do you want to continue?",
self
)
if not ex_cond:
break
if LearnAttack(poke, self.map, self) \
(obj.attack_name):
items = self.rem_item(obj.name, items)
if len(items) == 0:
break
break
std_loop(box=self.box2)
self.map.show()
elif action.triggers(Action.REMOVE):
if ask_bool(
self.map,
"Do you really want to throw "
f"{items[self.box.index.index].pretty_name} away?",
self
):
items = self.rem_item(items[self.box.index.index].name,
items)
if len(items) == 0:
break
std_loop(box=self)
self.map.show()
self.box.remove_c_obs()
def rem_item(self, name, items):
"""Removes an item from the inv
ARGS:
name: Items name
items: List of Items
RETURNS:
List of Items"""
figure.remove_item(name)
for obj in self.box.c_obs:
obj.remove()
self.box.remove_c_obs()
items = self.add()
if not items:
return items
if self.box.index.index >= len(items):
self.box.set_index(len(items) - 1)
return items
def add(self):
"""Adds all items to the box
RETURNS:
List of Items"""
items = [getattr(invitems, i) for i in figure.inv if figure.inv[i] > 0]
self.box.add_c_obs(
[
se.Text(
f"{i.pretty_name}s : {figure.inv[i.name]}",
state="float"
)
for i in items
]
)
return items
class Menu:
"""Menu to manage settings and other stuff in
ARGS:
_map: se.Map this will be shown on"""
def __init__(self, _map):
self.map = _map
self.box = ChooseBox(_map.height - 3, 35, "Menu", overview=_map)
self.playername_label = se.Text("Playername: ", state="float")
self.represent_char_label = se.Text("Char: ", state="float")
self.mods_label = se.Text("Mods", state="float")
self.ach_label = se.Text("Achievements", state="float")
self.about_label = se.Text("About", state="float")
self.save_label = se.Text("Save", state="float")
self.exit_label = se.Text("Exit", state="float")
self.realname_label = se.Text(session_info["user"], state="float")
self.char_label = se.Text(figure.char, state="float")
self.box.add_c_obs([self.playername_label,
self.represent_char_label,
VisSetting("Autosave", "autosave",
{True: "On", False: "Off"}),
VisSetting("Animations", "animations",
{True: "On", False: "Off"}),
VisSetting("Save trainers", "save_trainers",
{True: "On", False: "Off"}),
VisSetting("Audio", "audio",
{True: "On", False: "Off"}),
Slider("Volume", "volume"),
VisSetting("Load mods", "load_mods",
{True: "On", False: "Off"}),
self.mods_label, self.ach_label,
self.about_label, self.save_label,
self.exit_label])
# adding
self.box.add_ob(self.realname_label,
self.playername_label.rx + self.playername_label.width,
self.playername_label.ry)
self.box.add_ob(self.char_label,
self.represent_char_label.rx
+ self.represent_char_label.width,
self.represent_char_label.ry)
def resize_view(self):
"""Manages recursive view resizing"""
self.box.remove()
self.box.overview.resize_view()
self.box.resize(self.map.height - 3, 35)
self.box.add(self.map, self.map.width - self.box.width, 0)
def __call__(self, pevm):
"""Opens the menu"""
self.box.resize(self.map.height - 3, 35)
self.realname_label.rechar(figure.name)
self.char_label.rechar(figure.char)
audio_before = settings("audio").val
volume_before = settings("volume").val
with self.box.add(self.map, self.map.width - self.box.width, 0):
_ev.clear()
while True:
action = get_action()
i = self.box.c_obs[self.box.index.index]
if (strength := action.get_x_strength()) != 0:
if isinstance(i, Slider):
i.change(strength)
elif action.triggers(Action.ACCEPT):
# Fuck python for not having case statements - lxgr
# but it does lmao - Magnus
if i == self.playername_label:
figure.name = text_input(self.realname_label, self.map,
figure.name, 18, 17)
self.map.name_label_rechar(figure.name)
elif i == self.represent_char_label:
inp = text_input(self.char_label, self.map,
figure.char, 18, 1)
# excludes bad unicode:
if (
len(inp.encode("utf-8")) != 1
and inp not in ["ä", "ö", "ü", "ß"]
):
inp = "a"
self.char_label.rechar(inp)
notifier.notify("Error", "Bad character",
"The chosen character has to be a \
valid single-space character!")
figure.rechar(inp)
elif i == self.mods_label:
ModInfo(mvp.movemap, mods.mod_info)()
elif i == self.save_label:
# When will python3.10 come out?
with InfoBox("Saving....", info="", _map=self.map):
# Shows a box displaying "Saving...." while saving
save()
time.sleep(SPEED_OF_TIME * 1.5)
elif i == self.exit_label:
save()
sys.exit()
elif i == self.about_label:
about()
elif i == self.ach_label:
AchievementOverview()(mvp.movemap)
elif isinstance(i, VisSetting):
i.change()
if (
audio_before != settings("audio").val
or volume_before != settings("volume").val
):
audio.switch(figure.map.song)
audio_before = settings("audio").val
volume_before = settings("volume").val
elif action.triggers(Action.UP, Action.DOWN):
self.box.input(action)
elif action.triggers(Action.CANCEL, Action.MENU):
break
std_loop(pevm=pevm, box=self)
self.map.full_show()
# General use functions
#######################
def autosave():
"""Autosaves the game every 5 mins"""
while True:
time.sleep(SPEED_OF_TIME * 300)
if settings("autosave").val:
save()
def save():
"""Saves all relevant data to savefile"""
_si = {
"user": figure.name,
"represent_char": figure.char,
"ver": VERSION,
"map": figure.map.name,
"oldmap": figure.oldmap.name,
"last_center_map": figure.last_center_map.name,
"x": figure.x,
"y": figure.y,
"achievements": achievements.achieved,
"pokes": {i: poke.dict() for i, poke in enumerate(figure.pokes)},
"inv": figure.inv,
"money": figure.get_money(),
"settings": settings.to_dict(),
"caught_poketes": list(dict.fromkeys(figure.caught_pokes
+ [i.identifier
for i in figure.pokes])),
"visited_maps": figure.visited_maps,
"startup_time": __t,
"hotkeys": hotkeys_save(),
# filters doublicates from figure.used_npcs
"used_npcs": list(dict.fromkeys(figure.used_npcs)),
"pokete_care": pokete_care.dict(),
"time": timer.time.time,
}
with open(SAVEPATH / "pokete.json", "w+") as file:
# writes the data to the save file in a nice format
json.dump(_si, file, indent=4)
logging.info("[General] Saved")
def read_save():
"""Reads from savefile
RETURNS:
session_info dict"""
Path(SAVEPATH).mkdir(parents=True, exist_ok=True)
# Default test session_info
_si = {
"user": "DEFAULT",
"represent_char": "a",
"ver": VERSION,
"map": "intromap",
"oldmap": "playmap_1",
"last_center_map": "playmap_1",
"x": 4,
"y": 5,
"achievements": [],
"pokes": {
"0": {"name": "steini", "xp": 50, "hp": "SKIP",
"ap": ["SKIP", "SKIP"]}
},
"inv": {"poketeball": 15, "healing_potion": 1},
"settings": {
"load_mods": False},
"figure.caught_pokes": ["steini"],
"visited_maps": ["playmap_1"],
"startup_time": 0,
"used_npcs": [],
"hotkeys": {},
"pokete_care": {
"entry": 0,
"poke": None,
},
"time": 0
}
if os.path.exists(SAVEPATH / "pokete.json"):
with open(SAVEPATH / "pokete.json") as _file:
_si = json.load(_file)
elif os.path.exists(HOME / ".cache" / "pokete" / "pokete.json"):
with open(HOME / ".cache" / "pokete" / "pokete.json") as _file:
_si = json.load(_file)
elif os.path.exists(HOME / ".cache" / "pokete" / "pokete.py"):
l_dict = {}
with open(HOME / ".cache" / "pokete" / "pokete.py", "r") as _file:
exec(_file.read(), {"session_info": _si}, l_dict)
_si = json.loads(json.dumps(l_dict["session_info"]))
return _si
def reset_terminal():
"""Resets the terminals state"""
if sys.platform == "linux":
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
def exiter():
"""Exit function"""
reset_terminal()
logging.info("[General] Exiting...")
print("\033[?1049l\033[1A")
if audio.curr is not None:
audio.kill()
# Functions needed for mvp.movemap
##############################
def codes(string):
"""Cheats"""
for i in string:
if i == "w":
save()
elif i == "!":
exec(string[string.index("!") + 2:])
return
elif i == "e":
try:
exec(string[string.index("e") + 2:])
except Exception as exc:
print(exc)
return
elif i == "q":
sys.exit()
# Playmap extra action functions
# Those are adding additional actions to playmaps
#################################################
class ExtraActions:
"""Extra actions class to keep track of extra actions"""
@staticmethod
def playmap_7():
"""Cave animation"""
_map = obmp.ob_maps["playmap_7"]
for obj in _map.get_obj("inner_walls").obs \
+ [i.main_ob for i in _map.trainers] \
+ [obmp.ob_maps["playmap_7"].get_obj(i)
for i in p_data.map_data["playmap_7"]["balls"] if
"playmap_7." + i not in figure.used_npcs
or not save_trainers]:
if obj.added and math.sqrt((obj.y - figure.y) ** 2
+ (obj.x - figure.x) ** 2) <= 3:
obj.rechar(obj.bchar)
else:
obj.rechar(" ")
# main functions
################
def teleport(poke):
"""Teleports the player to another towns pokecenter
ARGS:
poke: The Poke shown in the animation"""
if (obj := roadmap(mvp.movemap, None, choose=True)) is None:
return
if settings("animations").val:
animations.transition(mvp.movemap, poke)
cen_d = p_data.map_data[obj.name]["hard_obs"]["pokecenter"]
Door("", state="float", arg_proto={
"map": obj.name,
"x": cen_d["x"] + 5,
"y": cen_d["y"] + 6
}).action(figure)
def swap_poke():