Game.lua
62.9 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.GameTurnBased"
require "engine.interface.GameMusic"
require "engine.interface.GameSound"
require "engine.interface.GameTargeting"
local KeyBind = require "engine.KeyBind"
local Savefile = require "engine.Savefile"
local DamageType = require "engine.DamageType"
local Zone = require "engine.Zone"
local Tiles = require "engine.Tiles"
local Map = require "engine.Map"
local Level = require "engine.Level"
local Birther = require "mod.dialogs.Birther"
local Astar = require "engine.Astar"
local DirectPath = require "engine.DirectPath"
local Shader = require "engine.Shader"
local HighScores = require "engine.HighScores"
local NicerTiles = require "mod.class.NicerTiles"
local GameState = require "mod.class.GameState"
local Store = require "mod.class.Store"
local Trap = require "mod.class.Trap"
local Grid = require "mod.class.Grid"
local Actor = require "mod.class.Actor"
local Party = require "mod.class.Party"
local Player = require "mod.class.Player"
local NPC = require "mod.class.NPC"
local DebugConsole = require "engine.DebugConsole"
local FlyingText = require "engine.FlyingText"
local Tooltip = require "mod.class.Tooltip"
local Calendar = require "engine.Calendar"
local Gestures = require "engine.ui.Gestures"
local Dialog = require "engine.ui.Dialog"
local MapMenu = require "mod.dialogs.MapMenu"
module(..., package.seeall, class.inherit(engine.GameTurnBased, engine.interface.GameMusic, engine.interface.GameSound, engine.interface.GameTargeting))
-- Difficulty settings
DIFFICULTY_EASY = 1
DIFFICULTY_NORMAL = 2
DIFFICULTY_NIGHTMARE = 3
DIFFICULTY_INSANE = 4
PERMADEATH_INFINITE = 1
PERMADEATH_MANY = 2
PERMADEATH_ONE = 3
-- Tell the engine that we have a fullscreen shader that supports gamma correction
support_shader_gamma = true
function _M:init()
engine.GameTurnBased.init(self, engine.KeyBind.new(), 1000, 100)
engine.interface.GameMusic.init(self)
engine.interface.GameSound.init(self)
-- Pause at birth
self.paused = true
-- Same init as when loaded from a savefile
self:loaded()
self.visited_zones = {}
end
function _M:run()
self.delayed_log_damage = {}
self.calendar = Calendar.new("/data/calendar_allied.lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167, 11)
self.uiset:activate()
local flysize = ({normal=14, small=12, big=16})[config.settings.tome.fonts.size]
self.tooltip = Tooltip.new(self.uiset.init_font_mono, self.uiset.init_size_mono, {255,255,255}, {30,30,30,230})
self.tooltip2 = Tooltip.new(self.uiset.init_font_mono, self.uiset.init_size_mono, {255,255,255}, {30,30,30,230})
self.flyers = FlyingText.new("/data/font/INSULA__.ttf", flysize, "/data/font/INSULA__.ttf", flysize + 3)
self.flyers:enableShadow(0.6)
game:setFlyingText(self.flyers)
self.nicer_tiles = NicerTiles.new()
-- Ok everything is good to go, activate the game in the engine!
self:setCurrent()
-- Start time
self.real_starttime = os.time()
self:setupDisplayMode(false, "postinit")
if self.level and self.level.data.day_night then self.state:dayNightCycle() end
if self.level and self.player then self.calendar = Calendar.new("/data/calendar_"..(self.player.calendar or "allied")..".lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167, 11) end
-- Setup inputs
self:setupCommands()
self:setupMouse()
-- Starting from here we create a new game
if self.player and self.player.dead then
print("Player is dead, rebooting")
util.showMainMenu()
return
end
if not self.player then self:newGame() end
engine.interface.GameTargeting.init(self)
self.uiset.hotkeys_display.actor = self.player
self.uiset.npcs_display.actor = self.player
-- Run the current music if any
self:onTickEnd(function()
self:playMusic()
if self.level then
self.level.map:moveViewSurround(self.player.x, self.player.y, config.settings.tome.scroll_dist, config.settings.tome.scroll_dist)
end
end)
-- Create the map scroll text overlay
local lfont = core.display.newFont("/data/font/Vera.ttf", 30)
lfont:setStyle("bold")
local s = core.display.drawStringBlendedNewSurface(lfont, "<Scroll mode, press keys to scroll, caps lock to exit>", unpack(colors.simple(colors.GOLD)))
lfont:setStyle("normal")
self.caps_scroll = {s:glTexture()}
self.caps_scroll.w, self.caps_scroll.h = s:getSize()
self.zone_font = core.display.newFont("/data/font/Vera.ttf", 12)
self.inited = true
end
--- Resize the hotkeys
function _M:resizeIconsHotkeysToolbar()
self.uiset:resizeIconsHotkeysToolbar()
end
--- Checks if the current character is "tainted" by cheating
function _M:isTainted()
if config.settings.cheat then return true end
return (game.player and game.player.__cheated) and true or false
end
--- Sets the player name
function _M:setPlayerName(name)
self.save_name = name
self.player_name = name
if self.party and self.party:findMember{main=true} then
self.party:findMember{main=true}.name = name
end
end
function _M:newGame()
self.party = Party.new{}
local player = Player.new{name=self.player_name, game_ender=true}
self.party:addMember(player, {
control="full",
type="player",
title="Main character",
main=true,
orders = {target=true, anchor=true, behavior=true, leash=true, talents=true},
})
self.party:setPlayer(player)
-- Create the entity to store various game state things
self.state = GameState.new{}
local birth_done = function()
if self.player.__allow_rod_recall then game.state:allowRodRecall(true) self.player.__allow_rod_recall = nil end
if self.player.__allow_transmo_chest and profile.mod.allow_build.birth_transmo_chest then
self.player.__allow_transmo_chest = nil
local chest = game.zone:makeEntityByName(game.level, "object", "TRANSMO_CHEST")
if chest then
game.zone:addEntity(game.level, chest, "object")
self.player:addObject(self.player:getInven("INVEN"), chest)
end
end
for i = 1, 50 do
local o = self.state:generateRandart(true)
self.zone.object_list[#self.zone.object_list+1] = o
end
if config.settings.cheat then self.player.__cheated = true end
self.player:recomputeGlobalSpeed()
-- Force the hotkeys to be sorted.
self.player:sortHotkeys()
-- Register the character online if possible
self.player:getUUID()
self:updateCurrentChar()
end
self.always_target = true
local nb_unlocks, max_unlocks = self:countBirthUnlocks()
self.creating_player = true
local birth; birth = Birther.new("Character Creation ("..nb_unlocks.."/"..max_unlocks.." unlocked birth options)", self.player, {"base", "world", "difficulty", "permadeath", "race", "subrace", "sex", "class", "subclass" }, function(loaded)
if not loaded then
self.calendar = Calendar.new("/data/calendar_"..(self.player.calendar or "allied")..".lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167, 11)
self.player:check("make_tile")
self.player.make_tile = nil
self.player:check("before_starting_zone")
self.player:check("class_start_check")
-- Configure & create the worldmap
self.player.last_wilderness = self.player.default_wilderness[3] or "wilderness"
game:onLevelLoad(self.player.last_wilderness.."-1", function(zone, level)
game.player.wild_x, game.player.wild_y = game.player.default_wilderness[1], game.player.default_wilderness[2]
if type(game.player.wild_x) == "string" and type(game.player.wild_y) == "string" then
local spot = level:pickSpot{type=game.player.wild_x, subtype=game.player.wild_y} or {x=1,y=1}
game.player.wild_x, game.player.wild_y = spot.x, spot.y
end
end)
-- Generate
if self.player.__game_difficulty then self:setupDifficulty(self.player.__game_difficulty) end
self:setupPermadeath(self.player)
self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, nil, self.player.starting_level_force_down)
print("[PLAYER BIRTH] resolve...")
self.player:resolve()
self.player:resolve(nil, true)
self.player.energy.value = self.energy_to_act
Map:setViewerFaction(self.player.faction)
self.player:updateModdableTile()
self.paused = true
print("[PLAYER BIRTH] resolved!")
local birthend = function()
local d = require("engine.dialogs.ShowText").new("Welcome to ToME", "intro-"..self.player.starting_intro, {name=self.player.name}, nil, nil, function()
self.player:resetToFull()
self.player:registerCharacterPlayed()
self.player:onBirth(birth)
-- For quickbirth
savefile_pipe:push(self.player.name, "entity", self.party, "engine.CharacterVaultSave")
self.creating_player = false
self.player:grantQuest(self.player.starting_quest)
birth_done()
self.player:check("on_birth_done")
if __module_extra_info.birth_done_script then loadstring(__module_extra_info.birth_done_script)() end
end, true)
self:registerDialog(d)
if __module_extra_info.no_birth_popup then d.key:triggerVirtual("EXIT") end
end
if self.player.no_birth_levelup or __module_extra_info.no_birth_popup then birthend()
else self.player:playerLevelup(birthend, true) end
-- Player was loaded from a premade
else
self.calendar = Calendar.new("/data/calendar_"..(self.player.calendar or "allied")..".lua", "Today is the %s %s of the %s year of the Age of Ascendancy of Maj'Eyal.\nThe time is %02d:%02d.", 122, 167, 11)
Map:setViewerFaction(self.player.faction)
if self.player.__game_difficulty then self:setupDifficulty(self.player.__game_difficulty) end
self:setupPermadeath(self.player)
-- Configure & create the worldmap
self.player.last_wilderness = self.player.default_wilderness[3] or "wilderness"
game:onLevelLoad(self.player.last_wilderness.."-1", function(zone, level)
game.player.wild_x, game.player.wild_y = game.player.default_wilderness[1], game.player.default_wilderness[2]
if type(game.player.wild_x) == "string" and type(game.player.wild_y) == "string" then
local spot = level:pickSpot{type=game.player.wild_x, subtype=game.player.wild_y} or {x=1,y=1}
game.player.wild_x, game.player.wild_y = spot.x, spot.y
end
end)
-- Tell the level gen code to add all the party
self.to_re_add_actors = {}
for act, _ in pairs(self.party.members) do if self.player ~= act then self.to_re_add_actors[act] = true end end
self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, nil, self.player.starting_level_force_down)
self.player:grantQuest(self.player.starting_quest)
self.creating_player = false
-- Add all items so they regen correctly
self.player:inventoryApplyAll(function(inven, item, o) game:addEntity(o) end)
birth_done()
self.player:check("on_birth_done")
end
end, quickbirth, 800, 600)
self:registerDialog(birth)
end
function _M:setupDifficulty(d)
self.difficulty = d
end
function _M:setupPermadeath(p)
if p:attr("infinite_lifes") then self.permadeath = PERMADEATH_INFINITE
elseif p:attr("easy_mode_lifes") then self.permadeath = PERMADEATH_MANY
else self.permadeath = PERMADEATH_ONE
end
end
function _M:loaded()
engine.GameTurnBased.loaded(self)
engine.interface.GameMusic.loaded(self)
engine.interface.GameSound.loaded(self)
Actor.projectile_class = "mod.class.Projectile"
Zone:setup{
npc_class="mod.class.NPC", grid_class="mod.class.Grid", object_class="mod.class.Object", trap_class="mod.class.Trap",
on_setup = function(zone)
-- Increases zone level for higher difficulties
if not zone.__applied_difficulty then
zone.__applied_difficulty = true
if self.difficulty == self.DIFFICULTY_INSANE then
zone.base_level_range = table.clone(zone.level_range, true)
zone.specific_base_level.object = -10 -zone.level_range[1]
zone.level_range[1] = zone.level_range[1] * 2 + 10
zone.level_range[2] = zone.level_range[2] * 2 + 10
end
end
end,
}
Zone.check_filter = function(...) return self.state:entityFilter(...) end
Zone.default_prob_filter = true
Zone.default_filter = function(...) return self.state:defaultEntityFilter(...) end
Zone.alter_filter = function(...) return self.state:entityFilterAlter(...) end
Zone.post_filter = function(...) return self.state:entityFilterPost(...) end
Zone.ego_filter = function(...) return self.state:egoFilter(...) end
self.uiset = (require("mod.class.uiset."..(config.settings.tome.uiset_mode or "Minimalist"))).new()
Map:setViewerActor(self.player)
self:setupDisplayMode(false, "init")
self:setupDisplayMode(false, "postinit")
if self.player then self.player.changed = true end
self.key = engine.KeyBind.new()
if self.always_target == true then Map:setViewerFaction(self.player.faction) end
if self.player and config.settings.cheat then self.player.__cheated = true end
self:updateCurrentChar()
end
function _M:setupDisplayMode(reboot, mode)
if not mode or mode == "init" then
local gfx = config.settings.tome.gfx
self:saveSettings("tome.gfx", ('tome.gfx = {tiles=%q, size=%q, tiles_custom_dir=%q, tiles_custom_moddable=%s, tiles_custom_adv=%s}\n'):format(gfx.tiles, gfx.size, gfx.tiles_custom_dir or "", gfx.tiles_custom_moddable and "true" or "false", gfx.tiles_custom_adv and "true" or "false"))
if reboot then
self.change_res_dialog = true
self:saveGame()
util.showMainMenu(false, nil, nil, self.__mod_info.short_name, self.save_name, false)
end
Map:resetTiles()
end
if not mode or mode == "postinit" then
local gfx = config.settings.tome.gfx
-- Select tiles
Tiles.prefix = "/data/gfx/"..gfx.tiles.."/"
if config.settings.tome.gfx.tiles == "customtiles" then
Tiles.prefix = "/data/gfx/"..config.settings.tome.gfx.tiles_custom_dir.."/"
end
print("[DISPLAY MODE] Tileset: "..gfx.tiles)
print("[DISPLAY MODE] Size: "..gfx.size)
local do_bg = gfx.tiles == "ascii_full"
local _, _, tw, th = gfx.size:find("^([0-9]+)x([0-9]+)$")
tw, th = tonumber(tw), tonumber(th)
if not tw then tw, th = 64, 64 end
local pot_th = math.pow(2, math.ceil(math.log(th-0.1) / math.log(2.0)))
local fsize = math.floor( pot_th/th*(0.7 * th + 5) )
local map_x, map_y, map_w, map_h = self.uiset:getMapSize()
if th <= 20 then
Map:setViewPort(map_x, map_y, map_w, map_h, tw, th, "/data/font/FSEX300.ttf", pot_th, do_bg)
else
Map:setViewPort(map_x, map_y, map_w, map_h, tw, th, nil, fsize, do_bg)
end
-- Show a count for stacked objects
Map.object_stack_count = true
Map.tiles.use_images = true
if gfx.tiles == "ascii" then
Map.tiles.use_images = false
Map.tiles.force_back_color = {r=0, g=0, b=0, a=255}
Map.tiles.no_moddable_tiles = true
elseif gfx.tiles == "ascii_full" then
Map.tiles.use_images = false
Map.tiles.no_moddable_tiles = true
elseif gfx.tiles == "shockbolt" then
Map.tiles.nicer_tiles = true
elseif gfx.tiles == "oldrpg" then
Map.tiles.nicer_tiles = true
elseif gfx.tiles == "customtiles" then
Map.tiles.no_moddable_tiles = not config.settings.tome.gfx.tiles_custom_moddable
Map.tiles.nicer_tiles = config.settings.tome.gfx.tiles_custom_adv
end
if self.level then
if self.level.map.finished then
self.level.map:recreate()
self.level.map:moveViewSurround(self.player.x, self.player.y, 8, 8)
end
engine.interface.GameTargeting.init(self)
end
self:setupMiniMap()
self:createFBOs()
end
end
function _M:createFBOs()
-- Create the framebuffer
self.fbo = core.display.newFBO(Map.viewport.width, Map.viewport.height)
if self.fbo then self.fbo_shader = Shader.new("main_fbo") if not self.fbo_shader.shad then self.fbo = nil self.fbo_shader = nil end end
if self.player then self.player:updateMainShader() end
self.full_fbo = core.display.newFBO(self.w, self.h)
if self.full_fbo then self.full_fbo_shader = Shader.new("full_fbo") if not self.full_fbo_shader.shad then self.full_fbo = nil self.full_fbo_shader = nil end end
-- self.mm_fbo = core.display.newFBO(200, 200)
-- if self.mm_fbo then self.mm_fbo_shader = Shader.new("mm_fbo") if not self.mm_fbo_shader.shad then self.mm_fbo = nil self.mm_fbo_shader = nil end end
end
function _M:resizeMapViewport(w, h)
w = math.floor(w)
h = math.floor(h)
Map.viewport.width = w
Map.viewport.height = h
Map.viewport.mwidth = math.floor(w / Map.tile_w)
Map.viewport.mheight = math.floor(h / Map.tile_h)
self:createFBOs()
if self.level then
self.level.map:makeCMap()
self.level.map:redisplay()
if self.player then
self.player:updateMainShader()
self.level.map:moveViewSurround(self.player.x, self.player.y, config.settings.tome.scroll_dist, config.settings.tome.scroll_dist)
end
end
end
function _M:setupMiniMap()
if self.level and self.level.map and self.level.map.finished then self.uiset:setupMinimap(self.level) end
end
function _M:save()
self.total_playtime = (self.total_playtime or 0) + (os.time() - (self.last_update or self.real_starttime))
self.last_update = os.time()
return class.save(self, self:defaultSavedFields{difficulty=true, permadeath=true, to_re_add_actors=true, party=true, _chronoworlds=true, total_playtime=true, on_level_load_fcts=true, visited_zones=true, bump_attack_disabled=true, show_npc_list=true}, true)
end
function _M:updateCurrentChar()
if not self.party then return end
local player = self.party:findMember{main=true}
profile:currentCharacter(self.__mod_info.full_version_string, ("%s the level %d %s %s"):format(player.name, player.level, player.descriptor.subrace, player.descriptor.subclass), player.__te4_uuid)
end
function _M:getSaveDescription()
local player = self.party:findMember{main=true}
return {
name = player.name,
description = ([[%s the level %d %s %s.
Difficulty: %s / %s
Campaign: %s
Exploring level %d of %s.]]):format(
player.name, player.level, player.descriptor.subrace, player.descriptor.subclass,
player.descriptor.difficulty, player.descriptor.permadeath,
player.descriptor.world,
self.level.level, self.zone.name
),
}
end
function _M:getVaultDescription(e)
e = e:findMember{main=true} -- Because vault "chars" are actualy parties for tome
return {
name = ([[%s the %s %s]]):format(e.name, e.descriptor.subrace, e.descriptor.subclass),
descriptors = e.descriptor,
description = ([[%s the %s %s.
Difficulty: %s / %s
Campaign: %s]]):format(
e.name, e.descriptor.subrace, e.descriptor.subclass,
e.descriptor.difficulty, e.descriptor.permadeath,
e.descriptor.world
),
}
end
function _M:getStore(def)
return Store.stores_def[def]:clone()
end
function _M:leaveLevel(level, lev, old_lev)
self.to_re_add_actors = self.to_re_add_actors or {}
if level:hasEntity(self.player) then
level.exited = level.exited or {}
if lev > old_lev then
level.exited.down = {x=self.player.x, y=self.player.y}
else
level.exited.up = {x=self.player.x, y=self.player.y}
end
end
level.last_turn = self.turn
for act, _ in pairs(self.party.members) do
if self.player ~= act and level:hasEntity(act) then
level:removeEntity(act)
self.to_re_add_actors[act] = true
end
end
if level:hasEntity(self.player) then level:removeEntity(self.player) end
end
function _M:onLevelLoad(id, fct, data)
if self.zone and self.level and id == self.zone.short_name.."-"..self.level.level then
print("Direct execute of on level load", id, fct, data)
fct(self.zone, self.level, data)
return
end
self.on_level_load_fcts = self.on_level_load_fcts or {}
self.on_level_load_fcts[id] = self.on_level_load_fcts[id] or {}
local l = self.on_level_load_fcts[id]
l[#l+1] = {fct=fct, data=data}
print("Registering on level load", id, fct, data)
end
function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
if not self.player.can_change_level then
self.logPlayer(self.player, "#LIGHT_RED#You may not change level without your own body!")
return
end
if zone and not self.player.can_change_zone then
self.logPlayer(self.player, "#LIGHT_RED#You may not leave the zone with this character!")
return
end
if self.player:hasEffect(self.player.EFF_PARADOX_CLONE) or self.player:hasEffect(self.player.EFF_IMMINENT_PARADOX_CLONE) then
self.logPlayer(self.player, "#LIGHT_RED#You cannot escape your fate by leaving the level!")
return
end
-- Transmo!
local p = self:getPlayer(true)
if p:attr("has_transmo") and p:transmoGetNumberItems() > 0 then
local d
local titleupdator = self.player:getEncumberTitleUpdator("Transmogrification Chest")
d = self.player:showEquipInven(titleupdator(), nil, function(o, inven, item, button, event)
if not o then return end
local ud = require("mod.dialogs.UseItemDialog").new(event == "button", self.player, o, item, inven, function(_, _, _, stop)
d:generate()
d:generateList()
d:updateTitle(titleupdator())
if stop then self:unregisterDialog(d) end
end)
self:registerDialog(ud)
end)
d.unload = function()
local inven = p:getInven("INVEN")
for i = #inven, 1, -1 do
local o = inven[i]
if o.__transmo then
p:transmoInven(inven, i, o)
end
end
end
-- Select the chest tab
d.c_inven.dont_update_last_tabs = true
d.c_inven:switchTab{kind="transmo"}
d:simplePopup("Transmogrification Chest", "When you close the inventory window, all items in the chest will be transmogrified.")
end
-- Finish stuff registered for the previous level
self:onTickEndExecute()
if self.zone and self.level then self.party:leftLevel() end
if self.player:isTalentActive(self.player.T_JUMPGATE) then
self.player:forceUseTalent(self.player.T_JUMPGATE, {ignore_energy=true})
end
if self.player:isTalentActive(self.player.T_JUMPGATE_TWO) then
self.player:forceUseTalent(self.player.T_JUMPGATE_TWO, {ignore_energy=true})
end
-- clear chrono worlds and their various effects
if self._chronoworlds then self._chronoworlds = nil end
local left_zone = self.zone
if self.zone and self.zone.on_leave then
local nl, nz, stop = self.zone.on_leave(lev, old_lev, zone)
if stop then return end
if nl then lev = nl end
if nz then zone = nz end
end
if self.zone and self.level then self.player:onLeaveLevel(self.zone, self.level) end
local old_lev = (self.level and not zone) and self.level.level or -1000
if keep_old_lev then old_lev = self.level.level end
if zone then
if self.zone then
self.zone:leaveLevel(false, lev, old_lev)
self.zone:leave()
end
if type(zone) == "string" then
self.zone = Zone.new(zone)
else
self.zone = zone
end
if type(self.zone.save_per_level) == "nil" then self.zone.save_per_level = config.settings.tome.save_zone_levels and true or false end
end
local _, is_new = self.zone:getLevel(self, lev, old_lev)
self.visited_zones[self.zone.short_name] = true
-- Post process walls
self.nicer_tiles:postProcessLevelTiles(self.level)
-- Post process if needed once the nicer tiles are done
if self.level.data and self.level.data.post_nicer_tiles then self.level.data.post_nicer_tiles(self.level) end
-- Check if we need to switch the current guardian
self.state:zoneCheckBackupGuardian()
-- Check if we must do some special things on load of this level
self.on_level_load_fcts = self.on_level_load_fcts or {}
print("Running on level loads", self.zone.short_name.."-"..self.level.level)
for i, fct in ipairs(self.on_level_load_fcts[self.zone.short_name.."-"..self.level.level] or {}) do
fct.fct(self.zone, self.level, fct.data)
end
self.on_level_load_fcts[self.zone.short_name.."-"..self.level.level] = nil
-- Decay level ?
if self.level.last_turn and self.level.data.decay and self.level.last_turn + self.level.data.decay[1] * 10 < self.turn then
local only = self.level.data.decay.only or nil
if not only or only.actor then
-- local nb_actor, remain_actor = self.level:decay(Map.ACTOR, function(e) return not e.unique and not e.lore and not e.quest and self.level.last_turn + rng.range(self.level.data.decay[1], self.level.data.decay[2]) < self.turn * 10 end)
-- if not self.level.data.decay.no_respawn then
-- local gen = self.zone:getGenerator("actor", self.level)
-- if gen.regenFrom then gen:regenFrom(remain_actor) end
-- end
end
if not only or only.object then
local nb_object, remain_object = self.level:decay(Map.OBJECT, function(e) return not e.unique and not e.lore and not e.quest and self.level.last_turn + rng.range(self.level.data.decay[1], self.level.data.decay[2]) < self.turn * 10 end)
-- if not self.level.data.decay.no_respawn then
-- local gen = self.zone:getGenerator("object", self.level)
-- if gen.regenFrom then gen:regenFrom(remain_object) end
-- end
end
end
-- Move back to old wilderness position
if self.zone.wilderness then
self.player:move(self.player.wild_x, self.player.wild_y, true)
self.player.last_wilderness = self.zone.short_name
else
local x, y = nil, nil
if auto_zone_stair and left_zone then
-- Dirty but quick
local list = {}
for i = 0, self.level.map.w - 1 do for j = 0, self.level.map.h - 1 do
local idx = i + j * self.level.map.w
if self.level.map.map[idx][Map.TERRAIN] and self.level.map.map[idx][Map.TERRAIN].change_zone == left_zone.short_name then
list[#list+1] = {i, j}
end
end end
if #list > 0 then x, y = unpack(rng.table(list)) end
end
-- Default to stairs
if not x then
if lev > old_lev and not force_down then x, y = self.level.default_up.x, self.level.default_up.y
else x, y = self.level.default_down.x, self.level.default_down.y
end
end
-- Check if there is already an actor at that location, if so move it
x = x or 1 y = y or 1
local blocking_actor = self.level.map(x, y, engine.Map.ACTOR)
if blocking_actor then
local newx, newy = util.findFreeGrid(x, y, 20, true, {[Map.ACTOR]=true})
if newx and newy then blocking_actor:move(newx, newy, true)
else blocking_actor:teleportRandom(x, y, 200) end
end
self.player:move(x, y, true)
end
self.player.changed = true
if self.to_re_add_actors and not self.zone.wilderness then for act, _ in pairs(self.to_re_add_actors) do
local x, y = util.findFreeGrid(self.player.x, self.player.y, 20, true, {[Map.ACTOR]=true})
if x then act:move(x, y, true) end
end end
-- Re add entities
self.level:addEntity(self.player)
if self.to_re_add_actors and not self.zone.wilderness then
for act, _ in pairs(self.to_re_add_actors) do
self.level:addEntity(act)
act:setTarget(nil)
if act.ai_state and act.ai_state.tactic_leash_anchor then
act.ai_state.tactic_leash_anchor = self.player
end
end
self.to_re_add_actors = nil
end
if self.zone.on_enter then
self.zone.on_enter(lev, old_lev, zone)
end
self.player:onEnterLevel(self.zone, self.level)
self.player:resetMoveAnim()
local musics = {}
local keep_musics = false
if self.level.data.ambient_music then
if self.level.data.ambient_music ~= "last" then
if type(self.level.data.ambient_music) == "string" then musics[#musics+1] = self.level.data.ambient_music
elseif type(self.level.data.ambient_music) == "table" then for i, name in ipairs(self.level.data.ambient_music) do musics[#musics+1] = name end
elseif type(self.level.data.ambient_music) == "function" then for i, name in ipairs{self.level.data.ambient_music()} do musics[#musics+1] = name end
end
elseif self.level.data.ambient_music == "last" then
keep_musics = true
end
end
if not keep_musics then self:playAndStopMusic(unpack(musics)) end
-- Update the minimap
self:setupMiniMap()
-- Tell the map to use path strings to speed up path calculations
for uid, e in pairs(self.level.entities) do
if e.getPathString then
self.level.map:addPathString(e:getPathString())
end
end
self.zone_name_s = nil
-- Special stuff
for uid, act in pairs(self.level.entities) do
if act.setEffect then
if self.level.data.zero_gravity then act:setEffect(act.EFF_ZERO_GRAVITY, 1, {})
else act:removeEffect(act.EFF_ZERO_GRAVITY, nil, true) end
end
end
-- Level feeling
local feeling
if self.level.special_feeling then
feeling = self.level.special_feeling
else
local lev = self.zone.base_level + self.level.level - 1
if self.zone.level_adjust_level then lev = self.zone:level_adjust_level(self.level) end
local diff = lev - self.player.level
if diff >= 5 then feeling = "You feel a thrill of terror and your heart begins to pound in your chest. You feel terribly threatened upon entering this area."
elseif diff >= 2 then feeling = "You feel mildly anxious, and walk with caution."
elseif diff >= -2 then feeling = nil
elseif diff >= -5 then feeling = "You feel very confident walking into this place."
else feeling = "You stride into this area without a second thought, while stifling a yawn. You feel your time might be better spent elsewhere."
end
end
if feeling then self.log("#TEAL#%s", feeling) end
-- Autosave
if config.settings.tome.autosave and not config.settings.cheat and ((left_zone and left_zone.short_name ~= "wilderness") or self.zone.save_per_level) and (left_zone and left_zone.short_name ~= self.zone.short_name) then self:saveGame() end
self.player:onEnterLevelEnd(self.zone, self.level)
-- Day/Night cycle
if self.level.data.day_night then self.state:dayNightCycle() end
self.level.map:redisplay()
self.level.map:reopen()
-- Anti stairscum
if self.level.last_turn and self.level.last_turn < self.turn then
local perc = util.bound(math.floor((self.turn - self.level.last_turn) / 10), 0, 10)
for uid, target in pairs(self.level.entities) do
if target.life and target.max_life and self.player:reactionToward(target) < 0 then
target.life = util.bound(target.life + target.max_life * perc / 10, 0, target.max_life)
target.changed = true
target.talents_cd = {}
local todel = {}
for eff_id, p in pairs(target.tmp) do
local e = target.tempeffect_def[eff_id]
if e.status == "detrimental" then todel[#todel+1] = eff_id end
end
while #todel > 0 do
target:removeEffect(table.remove(todel))
end
end
end
end
end
function _M:getPlayer(main)
if main then
return self.party:findMember{main=true}
else
return self.player
end
end
--- Says if this savefile is usable or not
function _M:isLoadable()
return not self:getPlayer(true).dead
end
--- Clones the game world for chronomancy spells
function _M:chronoClone(name)
local d = Dialog:simpleWaiter("Chronomancy", "Folding the space time structure...")
local to_reload = {}
for uid, e in pairs(self.level.entities) do
if type(e.project) == "table" and e.project.def and e.project.def.typ and e.project.def.typ.line_function then
e.project.def.typ.line_function.line = { game.level.map.w, game.level.map.h, e.project.def.typ.line_function:export() }
to_reload[#to_reload + 1] = e
end
end
local ret = self:cloneFull()
for uid, e in pairs(to_reload) do e:loaded() end
if name then
self._chronoworlds = self._chronoworlds or {}
self._chronoworlds[name] = ret
ret = nil
end
d:done()
return ret
end
--- Restores a chronomancy clone
function _M:chronoRestore(name, remove)
local ngame
if type(name) == "string" then
ngame = self._chronoworlds[name]
if remove then self._chronoworlds[name] = nil end
else ngame = name end
if not ngame then return false end
local d = Dialog:simpleWaiter("Chronomancy", "Unfolding the space time structure...")
ngame:cloneReloaded()
_G.game = ngame
game.inited = nil
game:run()
game.key:setCurrent()
game.mouse:setCurrent()
profile.chat:setupOnGame()
core.wait.disable() -- "game" changed, we cant just unload the dialog, it doesnt exist anymore
return true
end
--- Update the zone name, if needed
function _M:updateZoneName()
local name
if self.zone.display_name then
name = self.zone.display_name()
else
local lev = self.level.level
if self.level.data.reverse_level_display then lev = 1 + self.level.data.max_level - lev end
name = ("%s (%d)"):format(self.zone.name, lev)
end
if self.zone_name_s and self.old_zone_name == name then return end
self.zone_font:setStyle("bold")
local s = core.display.drawStringBlendedNewSurface(self.zone_font, name, unpack(colors.simple(colors.GOLD)))
self.zone_font:setStyle("normal")
self.zone_name_w, self.zone_name_h = s:getSize()
self.zone_name_s, self.zone_name_tw, self.zone_name_th = s:glTexture()
self.old_zone_name = name
print("Updating zone name", name)
end
function _M:tick()
if self.level then
self:targetOnTick()
engine.GameTurnBased.tick(self)
-- Fun stuff: this can make the game realtime, although calling it in display() will make it work better
-- (since display is on a set FPS while tick() ticks as much as possible
-- engine.GameEnergyBased.tick(self)
else
engine.Game.tick(self)
end
-- Check damages to log
self:displayDelayedLogDamage()
if savefile_pipe.saving then self.player.changed = true end
if self.paused and not savefile_pipe.saving then return true end
end
function _M:displayDelayedLogDamage()
for src, tgts in pairs(self.delayed_log_damage) do
for target, dams in pairs(tgts) do
if #dams.descs > 1 then
self.logSeen(target, "%s hits %s for %s damage (total %0.2f).", src.name:capitalize(), target.name, table.concat(dams.descs, ", "), dams.total)
else
self.logSeen(target, "%s hits %s for %s damage.", src.name:capitalize(), target.name, table.concat(dams.descs, ", "))
end
local rsrc = src.resolveSource and src:resolveSource() or src
local rtarget = target.resolveSource and target:resolveSource() or target
local x, y = target.x or -1, target.y or -1
local sx, sy = self.level.map:getTileToScreen(x, y)
if target.dead then
if self.level.map.seens(x, y) and (rsrc == self.player or rtarget == self.player or self.party:hasMember(rsrc) or self.party:hasMember(rtarget)) then
self.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, rng.float(-2.5, -1.5), ("Kill (%d)!"):format(dams.total), {255,0,255}, true)
end
else
if self.level.map.seens(x, y) and (rsrc == self.player or self.party:hasMember(rsrc)) then
self.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, rng.float(-3, -2), tostring(-math.ceil(dams.total)), {0,255,0})
elseif self.level.map.seens(x, y) and (rtarget == self.player or self.party:hasMember(rtarget)) then
self.flyers:add(sx, sy, 30, (rng.range(0,2)-1) * 0.5, -rng.float(-3, -2), tostring(-math.ceil(dams.total)), {255,0,0})
end
end
end
end
self.delayed_log_damage = {}
end
function _M:delayedLogDamage(src, target, dam, desc)
self.delayed_log_damage[src] = self.delayed_log_damage[src] or {}
self.delayed_log_damage[src][target] = self.delayed_log_damage[src][target] or {total=0, descs={}}
local t = self.delayed_log_damage[src][target]
t.descs[#t.descs+1] = desc
t.total = t.total + dam
end
--- Called every game turns
-- Does nothing, you can override it
function _M:onTurn()
if self.zone then
if self.zone.on_turn then self.zone:on_turn() end
end
-- The following happens only every 10 game turns (once for every turn of 1 mod speed actors)
if self.turn % 10 ~= 0 then return end
-- Day/Night cycle
if self.level.data.day_night then self.state:dayNightCycle() end
-- Process overlay effects
self.level.map:processEffects()
if not self.day_of_year or self.day_of_year ~= self.calendar:getDayOfYear(self.turn) then
self.log(self.calendar:getTimeDate(self.turn))
self.day_of_year = self.calendar:getDayOfYear(self.turn)
end
end
function _M:updateFOV()
self.player:playerFOV()
end
function _M:displayMap(nb_keyframes)
-- Now the map, if any
if self.level and self.level.map and self.level.map.finished then
local map = self.level.map
-- Display the map and compute FOV for the player if needed
local changed = map.changed
if changed then self:updateFOV() end
-- Display using Framebuffer, so that we can use shaders and all
if self.fbo then
self.fbo:use(true)
if self.level.data.background then self.level.data.background(self.level, 0, 0, nb_keyframes) end
map:display(0, 0, nb_keyframes, config.settings.tome.smooth_fov)
if self.level.data.foreground then self.level.data.foreground(self.level, 0, 0, nb_keyframes) end
if self.level.data.weather_particle then self.state:displayWeather(self.level, self.level.data.weather_particle, nb_keyframes) end
if config.settings.tome.smooth_fov then map._map:drawSeensTexture(0, 0, nb_keyframes) end
self.fbo:use(false, self.full_fbo)
_2DNoise:bind(1, false)
self.fbo:toScreen(map.display_x, map.display_y, map.viewport.width, map.viewport.height, self.fbo_shader.shad)
if self.target then self.target:display() end
-- Basic display; no FBOs
else
if self.level.data.background then self.level.data.background(self.level, map.display_x, map.display_y, nb_keyframes) end
map:display(nil, nil, nb_keyframes, config.settings.tome.smooth_fov)
if self.target then self.target:display() end
if self.level.data.foreground then self.level.data.foreground(self.level, map.display_x, map.display_y, nb_keyframes) end
if self.level.data.weather_particle then self.state:displayWeather(self.level, self.level.data.weather_particle, nb_keyframes) end
if config.settings.tome.smooth_fov then map._map:drawSeensTexture(map.display_x, map.display_y, nb_keyframes) end
end
-- Handle ambient sounds
if self.level.data.ambient_bg_sounds then self.state:playAmbientSounds(self.level, self.level.data.ambient_bg_sounds, nb_keyframes) end
if not self.zone_name_s then self:updateZoneName() end
-- emotes display
map:displayEmotes(nb_keyframe or 1)
-- Mouse gestures
self.gestures:update()
self.gestures:display(map.display_x, map.display_y + map.viewport.height - self.gestures.font_h - 5)
-- Inform the player that map is in scroll mode
if core.key.modState("caps") then
local w = map.viewport.width * 0.5
local h = w * self.caps_scroll.h / self.caps_scroll.w
self.caps_scroll[1]:toScreenFull(
map.display_x + (map.viewport.width - w) / 2,
map.display_y + (map.viewport.height - h) / 2,
w, h,
self.caps_scroll[2] * w / self.caps_scroll.w, self.caps_scroll[3] * h / self.caps_scroll.h,
1, 1, 1, 0.5
)
end
end
end
--- Called when screen resolution changes
function _M:checkResolutionChange(w, h, ow, oh)
self:createFBOs()
return self.uiset:handleResolutionChange(w, h, ow, oh)
end
function _M:display(nb_keyframes)
-- If switching resolution, blank everything but the dialog
if self.change_res_dialog then engine.GameTurnBased.display(self, nb_keyframes) return end
if self.full_fbo then self.full_fbo:use(true) end
-- Now the ui
self.uiset:display(nb_keyframes)
if self.player then self.player.changed = false end
engine.GameTurnBased.display(self, nb_keyframes)
-- Tooltip is displayed over all else, even dialogs
local mx, my, button = core.mouse.get()
if self.tooltip.w and mx > self.w - self.tooltip.w and my > self.h - self.tooltip.h then
self:targetDisplayTooltip(Map.display_x, self.h)
else
self:targetDisplayTooltip(self.w, self.h)
end
if self.full_fbo then
self.full_fbo:use(false)
self.full_fbo:toScreen(0, 0, self.w, self.h, self.full_fbo_shader.shad)
end
end
--- Called when a dialog is registered to appear on screen
function _M:onRegisterDialog(d)
-- Clean up tooltip
self.tooltip_x, self.tooltip_y = nil, nil
self.tooltip2_x, self.tooltip2_y = nil, nil
if self.player then self.player:updateMainShader() end
end
function _M:onUnregisterDialog(d)
-- Clean up tooltip
self.tooltip_x, self.tooltip_y = nil, nil
self.tooltip2_x, self.tooltip2_y = nil, nil
if self.player then self.player:updateMainShader() self.player.changed = true end
end
function _M:setupCommands()
-- Make targeting work
self.normal_key = self.key
self:targetSetupKey()
-- Activate profiler keybinds
self.key:setupProfiler()
-- Activate mouse gestures
self.gestures = Gestures.new("Gesture: ", self.key, true)
-- Helper function to not allow some actions on the wilderness map
local not_wild = function(f) return function(...) if self.zone and not self.zone.wilderness then f(...) else self.logPlayer(self.player, "You cannot do that on the world map.") end end end
-- Debug mode
self.key:addCommands{
[{"_d","ctrl"}] = function() if config.settings.cheat then
local g = self.level.map(self.player.x, self.player.y, Map.TERRAIN)
print(g.define_as, g.image, g.z)
for i, a in ipairs(g.add_mos or {}) do print(" => ", a.image) end
local add = g.add_displays
if add then for i, e in ipairs(add) do
print(" -", e.image, e.z)
for i, a in ipairs(e.add_mos or {}) do print(" => ", a.image) end
end end
end end,
[{"_g","ctrl"}] = function() if config.settings.cheat then
-- for id, _ in pairs(game.party.__ingredients_def) do game.party:collectIngredient(id, rng.range(1, 3)) end
local m = game.zone:makeEntity(game.level, "actor", {random_elite=true}, nil, true)
game.zone:addEntity(game.level, m, "actor", game.player.x,game.player.y-1)
end end,
[{"_f","ctrl"}] = function() if config.settings.cheat then
self.player.quests["love-melinda"] = nil
self.player:grantQuest("love-melinda")
self.player:hasQuest("love-melinda"):melindaCompanion(self.player, "Defiler", "Corruptor")
end end,
}
self.key.any_key = function(sym)
-- Control resets the tooltip
if sym == self.key._LCTRL or sym == self.key._RCTRL then
self.player.changed = true
self.tooltip.old_tmx = nil
elseif sym == self.key._LSHIFT or sym == self.key._RSHIFT then
self.player.changed = true
end
end
self.key:unicodeInput(true)
self.key:addBinds
{
-- Movements
MOVE_LEFT = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(4) else self.player:moveDir(4) end end,
MOVE_RIGHT = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(6) else self.player:moveDir(6) end end,
MOVE_UP = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(8) else self.player:moveDir(8) end end,
MOVE_DOWN = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(2) else self.player:moveDir(2) end end,
MOVE_LEFT_UP = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(7) else self.player:moveDir(7) end end,
MOVE_LEFT_DOWN = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(1) else self.player:moveDir(1) end end,
MOVE_RIGHT_UP = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(9) else self.player:moveDir(9) end end,
MOVE_RIGHT_DOWN = function() if core.key.modState("caps") and self.level then self.level.map:scrollDir(3) else self.player:moveDir(3) end end,
MOVE_STAY = function() if core.key.modState("caps") and self.level then self.level.map:centerViewAround(self.player.x, self.player.y) else if self.player:enoughEnergy() then self.player:describeFloor(self.player.x, self.player.y) self.player:useEnergy() end end end,
RUN = function()
self.log("Run in which direction?")
local co = coroutine.create(function()
local x, y = self.player:getTarget{type="hit", no_restrict=true, range=1, immediate_keys=true, default_target=self.player}
if x and y then self.player:runInit(util.getDir(x, y, self.player.x, self.player.y)) end
end)
local ok, err = coroutine.resume(co)
if not ok and err then print(debug.traceback(co)) error(err) end
end,
RUN_AUTO = function()
if self.level and self.zone then
local seen = {}
-- Check for visible monsters. Only see LOS actors, so telepathy wont prevent it
core.fov.calc_circle(self.player.x, self.player.y, self.level.map.w, self.level.map.h, self.player.sight or 10,
function(_, x, y) return self.level.map:opaque(x, y) end,
function(_, x, y)
local actor = self.level.map(x, y, self.level.map.ACTOR)
if actor and actor ~= self.player and self.player:reactionToward(actor) < 0 and
self.player:canSee(actor) and self.level.map.seens(x, y) then seen[#seen + 1] = {x=x, y=y, actor=actor} end
end, nil)
if self.zone.no_autoexplore or self.level.no_autoexplore then
self.log("You may not auto-explore this level.")
elseif #seen > 0 then
self.log("You may not auto-explore with enemies in sight!")
for _, node in ipairs(seen) do
node.actor:addParticles(engine.Particles.new("notice_enemy", 1))
end
elseif not self.player:autoExplore() then
self.log("There is nowhere left to explore.")
end
end
end,
RUN_LEFT = function() self.player:runInit(4) end,
RUN_RIGHT = function() self.player:runInit(6) end,
RUN_UP = function() self.player:runInit(8) end,
RUN_DOWN = function() self.player:runInit(2) end,
RUN_LEFT_UP = function() self.player:runInit(7) end,
RUN_LEFT_DOWN = function() self.player:runInit(1) end,
RUN_RIGHT_UP = function() self.player:runInit(9) end,
RUN_RIGHT_DOWN = function() self.player:runInit(3) end,
ATTACK_OR_MOVE_LEFT = function() self.player:attackOrMoveDir(4) end,
ATTACK_OR_MOVE_RIGHT = function() self.player:attackOrMoveDir(6) end,
ATTACK_OR_MOVE_UP = function() self.player:attackOrMoveDir(8) end,
ATTACK_OR_MOVE_DOWN = function() self.player:attackOrMoveDir(2) end,
ATTACK_OR_MOVE_LEFT_UP = function() self.player:attackOrMoveDir(7) end,
ATTACK_OR_MOVE_LEFT_DOWN = function() self.player:attackOrMoveDir(1) end,
ATTACK_OR_MOVE_RIGHT_UP = function() self.player:attackOrMoveDir(9) end,
ATTACK_OR_MOVE_RIGHT_DOWN = function() self.player:attackOrMoveDir(3) end,
-- Hotkeys
-- bindings done after
HOTKEY_PREV_PAGE = not_wild(function() self.player:prevHotkeyPage() self.log("Hotkey page %d is now displayed.", self.player.hotkey_page) end),
HOTKEY_NEXT_PAGE = not_wild(function() self.player:nextHotkeyPage() self.log("Hotkey page %d is now displayed.", self.player.hotkey_page) end),
-- Party commands
SWITCH_PARTY_1 = not_wild(function() self.party:select(1) end),
SWITCH_PARTY_2 = not_wild(function() self.party:select(2) end),
SWITCH_PARTY_3 = not_wild(function() self.party:select(3) end),
SWITCH_PARTY_4 = not_wild(function() self.party:select(4) end),
SWITCH_PARTY_5 = not_wild(function() self.party:select(5) end),
SWITCH_PARTY_6 = not_wild(function() self.party:select(6) end),
SWITCH_PARTY_7 = not_wild(function() self.party:select(7) end),
SWITCH_PARTY_8 = not_wild(function() self.party:select(8) end),
SWITCH_PARTY = not_wild(function() self:registerDialog(require("mod.dialogs.PartySelect").new()) end),
ORDER_PARTY_1 = not_wild(function() self.party:giveOrders(1) end),
ORDER_PARTY_2 = not_wild(function() self.party:giveOrders(2) end),
ORDER_PARTY_3 = not_wild(function() self.party:giveOrders(3) end),
ORDER_PARTY_4 = not_wild(function() self.party:giveOrders(4) end),
ORDER_PARTY_5 = not_wild(function() self.party:giveOrders(5) end),
ORDER_PARTY_6 = not_wild(function() self.party:giveOrders(6) end),
ORDER_PARTY_7 = not_wild(function() self.party:giveOrders(7) end),
ORDER_PARTY_8 = not_wild(function() self.party:giveOrders(8) end),
-- Actions
CHANGE_LEVEL = function()
local e = self.level.map(self.player.x, self.player.y, Map.TERRAIN)
if self.player:enoughEnergy() and e.change_level then
if self.player:attr("never_move") then self.log("You cannot currently leave the level.") return end
local stop = {}
for eff_id, p in pairs(self.player.tmp) do
local e = self.player.tempeffect_def[eff_id]
if e.status == "detrimental" and not e.no_stop_enter_worlmap then stop[#stop+1] = e.desc end
end
if e.change_zone and #stop > 0 and e.change_zone:find("^wilderness") then
self.log("You cannot go into the wilds with the following effects: %s", table.concat(stop, ", "))
else
-- Do not unpause, the player is allowed first move on next level
if e.change_level_check and e:change_level_check(self.player) then return end
self:changeLevel(e.change_zone and e.change_level or self.level.level + e.change_level, e.change_zone, e.keep_old_lev, e.force_down, e.change_zone_auto_stairs)
end
else
self.log("There is no way out of this level here.")
end
end,
REST = function()
self.player:restInit()
end,
PICKUP_FLOOR = not_wild(function()
if self.player.no_inventory_access then return end
self.player:playerPickup()
end),
DROP_FLOOR = function()
if self.player.no_inventory_access then return end
self.player:playerDrop()
end,
SHOW_INVENTORY = function()
if self.player.no_inventory_access then return end
local d
local titleupdator = self.player:getEncumberTitleUpdator("Inventory")
d = self.player:showEquipInven(titleupdator(), nil, function(o, inven, item, button, event)
if not o then return end
local ud = require("mod.dialogs.UseItemDialog").new(event == "button", self.player, o, item, inven, function(_, _, _, stop)
d:generate()
d:generateList()
d:updateTitle(titleupdator())
if stop then self:unregisterDialog(d) end
end)
self:registerDialog(ud)
end)
end,
SHOW_EQUIPMENT = "SHOW_INVENTORY",
WEAR_ITEM = function()
if self.player.no_inventory_access then return end
self.player:playerWear()
end,
TAKEOFF_ITEM = function()
if self.player.no_inventory_access then return end
self.player:playerTakeoff()
end,
USE_ITEM = not_wild(function()
if self.player.no_inventory_access then return end
self.player:playerUseItem()
end),
QUICK_SWITCH_WEAPON = function()
if self.player.no_inventory_access then return end
self.player:quickSwitchWeapons()
end,
USE_TALENTS = not_wild(function()
self:registerDialog(require("mod.dialogs.UseTalents").new(self.player))
end),
LEVELUP = function()
self.player:playerLevelup(nil, false)
end,
SAVE_GAME = function()
self:saveGame()
end,
SHOW_QUESTS = function()
self:registerDialog(require("engine.dialogs.ShowQuests").new(self.party:findMember{main=true}))
end,
SHOW_CHARACTER_SHEET = function()
self:registerDialog(require("mod.dialogs.CharacterSheet").new(self.player))
end,
SHOW_MESSAGE_LOG = function()
self:registerDialog(require("mod.dialogs.ShowChatLog").new("Message Log", 0.6, self.uiset.logdisplay, profile.chat))
end,
-- Show time
SHOW_TIME = function()
self.log(self.calendar:getTimeDate(self.turn))
end,
-- Exit the game
QUIT_GAME = function()
self:onQuit()
end,
-- Lua console
LUA_CONSOLE = function()
if config.settings.cheat then
self:registerDialog(DebugConsole.new())
end
end,
-- Debug dialog
DEBUG_MODE = function()
if config.settings.cheat then
self:registerDialog(require("mod.dialogs.debug.DebugMain").new())
end
end,
-- Toggle monster list
TOGGLE_NPC_LIST = function()
self.show_npc_list = not self.show_npc_list
self.player.changed = true
if (self.show_npc_list) then
self.log("Displaying creatures.")
else
self.log("Displaying talents.")
end
end,
SCREENSHOT = function() self:saveScreenshot() end,
HELP = "EXIT",
EXIT = function()
local l = {
"resume",
"achievements",
{ "Show known Lore", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.ShowLore").new("Tales of Maj'Eyal Lore", self.player)) end },
{ "Show ingredients", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.ShowIngredients").new(self.party)) end },
"highscores",
{ "Inventory", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_INVENTORY") end },
{ "Character Sheet", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_CHARACTER_SHEET") end },
"keybinds",
{"Graphic Mode", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GraphicMode").new()) end},
{"Game Options", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GameOptions").new()) end},
"video",
"sound",
"save",
"quit"
}
local adds = self.uiset:getMainMenuItems()
for i = #adds, 1, -1 do table.insert(l, 10, adds[i]) end
local menu menu = require("engine.dialogs.GameMenu").new(l)
self:registerDialog(menu)
end,
TACTICAL_DISPLAY = function()
if self.always_target == true then
self.always_target = "health"
Map:setViewerFaction(nil)
self.log("Showing healthbars only.")
elseif self.always_target == nil then
self.always_target = true
Map:setViewerFaction(self.player.faction)
self.log("Showing healthbars and tactical borders.")
elseif self.always_target == "health" then
self.always_target = nil
Map:setViewerFaction(nil)
self.log("Showing no tactical information.")
end
end,
LOOK_AROUND = function()
self.log("Looking around... (direction keys to select interesting things, shift+direction keys to move freely)")
local co = coroutine.create(function()
local x, y = self.player:getTarget{type="hit", no_restrict=true, range=2000}
if x and y then
local tmx, tmy = self.level.map:getTileToScreen(x, y)
self:registerDialog(MapMenu.new(tmx, tmy, x, y))
end
end)
local ok, err = coroutine.resume(co)
if not ok and err then print(debug.traceback(co)) error(err) end
end,
SHOW_MAP = function()
game:registerDialog(require("mod.dialogs.ShowMap").new())
end,
USERCHAT_SHOW_TALK = function()
self.show_userchat = not self.show_userchat
end,
TOGGLE_UI = function()
self.uiset:toggleUI()
end,
TOGGLE_BUMP_ATTACK = function()
local game_or_player = not config.settings.tome.actor_based_movement_mode and self or game.player
if game_or_player.bump_attack_disabled then
self.log("Movement Mode: #LIGHT_GREEN#Default#LAST#.")
game_or_player.bump_attack_disabled = false
else
self.log("Movement Mode: #LIGHT_RED#Passive#LAST#.")
game_or_player.bump_attack_disabled = true
end
end
}
engine.interface.PlayerHotkeys:bindAllHotkeys(self.key, not_wild(function(i) self.player:activateHotkey(i) end))
self.key:setCurrent()
end
function _M:setupMouse(reset)
if reset == nil or reset then self.mouse:reset() end
self.mouse:registerZone(Map.display_x, Map.display_y, Map.viewport.width, Map.viewport.height, function(button, mx, my, xrel, yrel, bx, by, event, extra)
self.tooltip.add_map_str = extra and extra.log_str
-- Handle targeting
if self:targetMouse(button, mx, my, xrel, yrel, event) then return end
-- Cheat kill
if config.settings.cheat and button == "right" and core.key.modState("ctrl") and core.key.modState("shift") and not xrel and not yrel and event == "button" and self.zone and not self.zone.wilderness then
local tmx, tmy = game.level.map:getMouseTile(mx, my)
local target = game.level.map(tmx, tmy, Map.ACTOR)
target:die(game.player)
return
end
-- Handle Use menu
if button == "right" then
if event == "motion" then
self.gestures:changeMouseButton(true)
self.gestures:mouseMove(mx, my)
elseif event == "button" then
if not self.gestures:isGesturing() then
if not xrel and not yrel then
-- Handle Use menu
self:mouseRightClick(mx, my, extra)
return
end
else
self.gestures:changeMouseButton(false)
self.gestures:useGesture()
self.gestures:reset()
end
end
end
-- Default left button action
if button == "left" and not xrel and not yrel and event == "button" and self.zone and not self.zone.wilderness then if self:mouseLeftClick(mx, my) then return end end
-- Default middle button action
if button == "middle" and not xrel and not yrel and event == "button" and self.zone and not self.zone.wilderness then if self:mouseMiddleClick(mx, my) then return end end
-- Handle the mouse movement/scrolling
self.player:mouseHandleDefault(self.key, self.key == self.normal_key, button, mx, my, xrel, yrel, event)
end, nil, "playmap")
self.uiset:setupMouse(self.mouse)
if not reset then self.mouse:setCurrent() end
end
--- Left mouse click on the map
function _M:mouseLeftClick(mx, my)
local tmx, tmy = self.level.map:getMouseTile(mx, my)
local p = self.player
local a = self.level.map(tmx, tmy, Map.ACTOR)
if not p:canSee(a) then return end
if not p.auto_shoot_talent then return end
local t = p:getTalentFromId(p.auto_shoot_talent)
if not t then return end
local target_dist = core.fov.distance(p.x, p.y, a.x, a.y)
if p:enoughEnergy() and p:reactionToward(a) < 0 and not p:isTalentCoolingDown(t) and p:preUseTalent(t, true, true) and target_dist <= p:getTalentRange(t) and p:canProject({type="hit"}, a.x, a.y) then
p:useTalent(t.id, nil, nil, nil, a)
return true
end
end
--- Middle mouse click on the map
function _M:mouseMiddleClick(mx, my)
local tmx, tmy = self.level.map:getMouseTile(mx, my)
local p = self.player
local a = self.level.map(tmx, tmy, Map.ACTOR)
if not p:canSee(a) then return end
if not p.auto_shoot_midclick_talent then return end
local t = p:getTalentFromId(p.auto_shoot_midclick_talent)
if not t then return end
local target_dist = core.fov.distance(p.x, p.y, a.x, a.y)
if p:enoughEnergy() and p:reactionToward(a) < 0 and not p:isTalentCoolingDown(t) and p:preUseTalent(t, true, true) and target_dist <= p:getTalentRange(t) and p:canProject({type="hit"}, a.x, a.y) then
p:useTalent(t.id, nil, nil, nil, a)
return true
end
end
--- Right mouse click on the map
function _M:mouseRightClick(mx, my, extra)
local tmx, tmy = self.level.map:getMouseTile(mx, my)
self:registerDialog(MapMenu.new(mx, my, tmx, tmy, extra and extra.add_map_action))
end
--- Ask if we really want to close, if so, save the game first
function _M:onQuit()
self.player:runStop("quitting")
self.player:restStop("quitting")
if not self.quit_dialog and not self.player.dead and not self:hasDialogUp() then
self.quit_dialog = Dialog:yesnoPopup("Save and exit?", "Save and exit?", function(ok)
if ok then
-- savefile_pipe is created as a global by the engine
self:saveGame()
util.showMainMenu()
end
self.quit_dialog = nil
end)
end
end
--- Called when we leave the module
function _M:onDealloc()
local time = os.time() - self.real_starttime
print("Played ToME for "..time.." seconds")
end
--- When a save is being made, stop running/resting
function _M:onSavefilePush()
self.player:runStop("saving")
self.player:restStop("saving")
end
--- Saves the highscore of the current char
function _M:registerHighscore()
local player = self:getPlayer(true)
local campaign = player.descriptor.world
local details = {
world = player.descriptor.world,
subrace = player.descriptor.subrace,
subclass = player.descriptor.subclass,
difficulty = player.descriptor.difficulty,
level = player.level,
name = player.name,
where = self.zone and self.zone.name or "???",
dlvl = self.level and self.level.level or 1
}
if campaign == 'Arena' then
details.score = self.level.arena.score
else
-- fallback score based on xp, this is a placeholder
details.score = math.floor(10 * (player.level + (player.exp / player:getExpChart(player.level)))) + math.floor(player.money / 100)
end
if player.dead then
details.killedby = player.killedBy and player.killedBy.name or "???"
HighScores.registerScore(campaign, details)
else
HighScores.noteLivingScore(campaign, player.name, details)
end
end
--- Requests the game to save
function _M:saveGame()
self:registerHighscore()
if self.party then for actor, _ in pairs(self.party.members) do engine.interface.PlayerHotkeys:updateQuickHotkeys(actor) end end
-- savefile_pipe is created as a global by the engine
savefile_pipe:push(self.save_name, "game", self)
world:saveWorld()
if not self.creating_player then
local oldplayer = self.player
self.party:setPlayer(self:getPlayer(true), true)
local party = self.party:cloneFull()
party.__te4_uuid = self:getPlayer(true).__te4_uuid
for m, _ in pairs(party.members) do
m:stripForExport()
end
party:stripForExport()
self.player:saveUUID(party)
self.party:setPlayer(oldplayer, true)
end
self.log("Saving game...")
end
--- Take a screenshot of the game
-- @param for_savefile The screenshot will be used for savefile display
function _M:takeScreenshot(for_savefile)
if for_savefile then
self.suppressDialogs = true
core.display.forceRedraw()
local x, y = self.w / 4, self.h / 4
if self.level then
x, y = self.level.map:getTileToScreen(self.player.x, self.player.y)
x, y = x - self.w / 4, y - self.h / 4
x, y = util.bound(x, 0, self.w / 2), util.bound(y, 0, self.h / 2)
end
local sc = core.display.getScreenshot(x, y, self.w / 2, self.h / 2)
self.suppressDialogs = nil
core.display.forceRedraw()
return sc
else
return core.display.getScreenshot(0, 0, self.w, self.h)
end
end
function _M:setAllowedBuild(what, notify)
-- Do not unlock things in easy mode
--if self.difficulty == self.DIFFICULTY_EASY then return end
local old = profile.mod.allow_build[what]
profile:saveModuleProfile("allow_build", {name=what})
if old then return end
if notify then
self.state:checkDonation() -- They gained someting nice, they could be more receptive
self:registerDialog(require("mod.dialogs.UnlockDialog").new(what))
end
return true
end
function _M:playSoundNear(who, name)
if who and self.level.map.seens(who.x, who.y) then
local pos = {x=0,y=0,z=0}
if self.player and self.player.x then pos.x, pos.y = who.x - self.player.x, who.y - self.player.y end
self:playSound(name, pos)
end
end
--- Create a random lore object and place it
function _M:placeRandomLoreObjectScale(base, nb, level)
local dist = ({
[5] = { {1}, {2,3}, {4,5} }, -- 5 => 3
korpul = { {1,2}, {3,4} }, -- 5 => 3
maze = { {1,2,3,4},{5,6,7} }, -- 5 => 3
daikara = { {1}, {2}, {3}, {4,5} },
[7] = { {1,2}, {3,4}, {5,6}, {7} }, -- 7 => 4
})[nb][level]
if not dist then return end
for _, i in ipairs(dist) do self:placeRandomLoreObject(base..i) end
end
--- Create a random lore object and place it
function _M:placeRandomLoreObject(define, zone)
if type(define) == "table" then define = rng.table(define) end
local o = self.zone:makeEntityByName(self.level, "object", define)
if not o then return end
if o.checkFilter and not o:checkFilter({}) then return end
local x, y = rng.range(0, self.level.map.w-1), rng.range(0, self.level.map.h-1)
local tries = 0
while (self.level.map:checkEntity(x, y, Map.TERRAIN, "block_move") or self.level.map(x, y, Map.OBJECT) or self.level.map.room_map[x][y].special) and tries < 100 do
x, y = rng.range(0, self.level.map.w-1), rng.range(0, self.level.map.h-1)
tries = tries + 1
end
if tries < 100 then
self.zone:addEntity(self.level, o, "object", x, y)
print("Placed lore", o.name, x, y)
o:identify(true)
end
end
--- Returns the current number of birth unlocks and the max
function _M:countBirthUnlocks()
local nb = 0
local max = 0
local list = {
birth_transmo_chest = true,
campaign_infinite_dungeon = true,
campaign_arena = true,
undead_ghoul = true,
undead_skeleton = true,
yeek = true,
mage = true,
mage_tempest = true,
mage_geomancer = true,
mage_pyromancer = true,
mage_cryomancer = true,
mage_necromancer = true,
rogue_marauder = true,
rogue_poisons = true,
divine_anorithil = true,
divine_sun_paladin = true,
wilder_wyrmic = true,
wilder_summoner = true,
corrupter_reaver = true,
corrupter_corruptor = true,
afflicted_cursed = true,
afflicted_doomed = true,
chronomancer_temporal_warden = true,
chronomancer_paradox_mage = true,
psionic_mindslayer = true,
warrior_brawler = true,
}
for name, _ in pairs(list) do
max = max + 1
if profile.mod.allow_build[name] then nb = nb + 1 end
end
return nb, max
end