-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.lua
More file actions
1387 lines (1216 loc) · 36.1 KB
/
actions.lua
File metadata and controls
1387 lines (1216 loc) · 36.1 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
--
--Copyright (C) 2022 Matthias Gatto
--
--This program is free software: you can redistribute it and/or modify
--it under the terms of the GNU Lesser 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 Lesser General Public License
--along with this program. If not, see <http://www.gnu.org/licenses/>.
--
local sleep_time = 0
fight_script = nil
dialogue_npc = nil
local use_time_point_action = Entity.new_string("phq.use_time_point")
function next_time()
local ret = Entity.new_array()
ret.day = phq.env.day
ret.week = phq.env.week
if phq.env.time:to_string() == "night" then
ret.time = "morning"
ret.day = phq.env.day + 1
if phq.env.day > 6 then
ret.day = 0
ret.week = phq.env.week + 1
end
elseif phq.env.time:to_string() == "morning" then
ret.time = "day"
else
ret.time = "night"
end
return ret
end
function is_npc_ally(pj, npcname)
local anpc = yeGet(pj.allies, npcname)
return yIsNNil(anpc)
end
function read_book(b, b_key)
local ts = Entity.new_array()
ts["<type>"] = "text-screen"
ts.text = "BOOK: " .. yeGetString(b_key) .. "\n" .. b.summary:to_string()
ts.background = "rgba: 255 255 200 255"
ts.actions = Entity.new_func(backToGameOnEnter)
ywPushNewWidget(main_widget, ts)
if yIsNNil(b.action) then
if b.usable_once > 0 then
if yIsNil(phq.pj.used_items[b_key:to_string()]) then
phq.pj.used_items[b_key:to_string()] = 1
ywidAction(b.action, main_widget, nil)
end
else
ywidAction(b.action, main_widget, nil)
end
end
return YEVE_ACTION
end
function use_time_point(box)
box = Entity.wrapp(box)
if phq.env.time_point:to_int() == 0 then
if yIsNil(box) or box.is_dialogue_condition == nil
or box.is_dialogue_condition < 1 then
printMessage(main_widget, nil, "Not enough time point")
end
return Y_FALSE
end
if box and box.is_dialogue_condition then
local answer = Entity.wrapp(yDialogueCurAnswer(box))
local actions = answer.actions
if yeDoesInclude(actions, use_time_point_action) == false then
yeInsertAt(actions, use_time_point_action, 0)
end
else
phq.env.time_point = phq.env.time_point - 1
end
return Y_TRUE
end
function quest_try_Call_script(quest, qi_scripts, cur)
for j = 0, yeLen(qi_scripts) - 1 do
local at = yeGet(qi_scripts[j], "at")
local callable = yeGetStringAt(qi_scripts[j], "call")
if yIsNNil(at) and cur == yeGetInt(at) then
if (yIsNNil(callable)) then
yesCall(ygGet(callable))
else
scripts[yeGetStringAt(qi_scripts[j], "script")](main_widget)
end
elseif yIsNNil(qi_scripts[j].after) and
cur > yeGetIntAt(qi_scripts[j], "after") and
cur < yeLenAt(quest, "descriptions") then
if (yIsNNil(callable)) then
yesCall(ygGet(callable))
else
scripts[yeGetStringAt(qi_scripts[j], "script")](main_widget)
end
end
end
end
function quest_update(original, _copy, arg)
local main = yeGet(arg, 0)
local quest_name = yeGet(arg, 1)
quest_name = yeGetString(quest_name)
local quest = quests_info[quest_name]
local rewards = quest.rewards
local r_idx = yeGetInt(original)
local reward = yeGetIntAt(rewards, r_idx)
local qi_scripts = quest.scripts
local set_at = quest["set-at"]
for j = 0, yeLen(set_at) - 1 do
local setter_at = set_at[j]
local at = yeGet(setter_at, "at")
if yIsNNil(at) and r_idx == yeGetInt(at) then
local what = yeGetStringAt(setter_at, "what")
if (yIsNil(ygGet(what))) then
print(what, " is not a valide path to ygGet")
else
yeSetInt(ygGet(what), yeGetIntAt(setter_at, "val"))
end
end
end
quest_try_Call_script(quest, qi_scripts, r_idx)
if reward ~= 0 then
increaseStat(main, phq.pj, "xp", reward)
end
end
function walkDoStep(_wid, character)
if (math.abs(yeGetFloat(character.move.left_right)) > 0 or
math.abs(yeGetFloat(character.move.up_down)) > 0) then
ylpcsHandlerNextStep(character)
ylpcsHandlerRefresh(character)
end
end
function backToGameOnEnter(wid, eve)
eve = Event.wrapp(eve)
while eve:is_end() == false do
if eve:type() == YKEY_DOWN and (eve:key() == Y_ENTER_KEY or
eve:key() == Y_ESC_KEY) then
backToGame(wid)
end
eve = eve:next()
end
return YEVE_NOTHANDLE
end
function getMainWid(wid)
wid = Entity.wrapp(wid)
if wid:cent() == main_widget:cent() then
return wid
end
if wid.isDialogue then
wid = Entity.wrapp(yDialogueGetMain(wid))
end
if yeGetInt(wid.in_subcontained) == 1 then
wid = Entity.wrapp(ywCntWidgetFather(wid))
end
local main = Entity.wrapp(ywCntWidgetFather(wid))
return main
end
local function backToGameReset(main)
local TIME_RESET = 2000000
main.pj.move.up_down = 0
main.pj.move.left_right = 0
main.no_chktime_t = TIME_RESET
end
function backToGameDirOut()
ygModDirOut()
-- this need to be done in case submodule cange that
tiled.setAssetPath("./tileset")
return backToGame2()
end
function backToGame2()
local main = main_widget
local target = 2
local c_t = 0
if phq_only_fight > 0 then
target = 3
c_t = 2
end
while yeLen(main.entries) > target do
ywCntPopLastEntry(main)
end
main.current = c_t
backToGameReset(main)
return YEVE_ACTION
end
function backToGame(wid)
if yIsNil(wid) or phq_only_fight > 0 then
return backToGame2()
end
wid = Entity.wrapp(wid)
if wid:cent() == main_widget:cent() then
return
end
if wid.isDialogue then
wid = Entity.wrapp(yDialogueGetMain(wid))
wid.main = nil
if wid.src then
wid.src.isBlock = wid.isBlock
wid.src.block = wid.block
wid.src = nil
end
end
while yeGetInt(wid.in_subcontained) == 1 do
wid = Entity.wrapp(ywCntWidgetFather(wid))
end
local main = Entity.wrapp(ywCntWidgetFather(wid))
-- if not bailing out
if yeGetStringAt(main, "<type>") ~= "phq" then
return backToGame2()
end
if wid.oldTimer then
main["turn-length"] = wid.oldTimer
end
local nb_layers = yeGetInt(wid.nb_layers)
while nb_layers > 1 do
ywCntPopLastEntry(main)
nb_layers = nb_layers - 1
end
ywCntPopLastEntry(main)
main.current = yeLen(main.entries) - 1
backToGameReset(main)
return YEVE_ACTION
end
function end_game()
print("end_game !!!!!")
print("end_game !!!!!")
print("end_game !!!!!")
print("end_game !!!!!")
backToGame2()
main_widget.next = "phq:menus.the end"
yesCall(ygGet("callNext"), main_widget);
end
function CombatEnd(wid, _main, winner_id)
local main = main_widget
wid = Entity.wrapp(wid)
local upcanvas = Canvas.wrapp(main.upCanvas)
local winner = Entity.wrapp(yJrpgGetWinner(wid, winner_id))
local looser = Entity.wrapp(yJrpgGetLooser(wid, winner_id))
ySoundPause(main.soundcallgirl)
ySoundPause(main.soundfrenetic)
ySoundPause(main.soundgoodf)
wid.main = nil
if yLovePtrToNumber(winner_id) == 3 then
-- you lose
backToGame(wid)
yNextLose(main:cent())
return
end
upcanvas:remove(main.life_nb)
main.life_nb = ywCanvasNewTextExt(upcanvas.ent, 410, 10,
Entity.new_string(math.floor(phq.pj.life:to_int())),
"rgba: 255 255 255 255")
local fsstr = fight_script
if fsstr == "CombatDialogueNext" or fsstr == "CombatDialogueGoto"
or fsstr == "CombatDialogueStay" then
ywCntPopLastEntry(main)
else
backToGame(wid)
end
return pushNewVictoryScreen(main, winner, looser)
--print("end:", main, winner)
end
function npcDefaultInit(npc, enemy_type)
if npc.is_generic then
npc = Entity.new_copy(npc)
end
if yIsNil(npc.clothes) and yIsNNil(npc.equipement) then
dressup.dressUp(npc)
end
if yIsNil(npc.name) then
npc.name = enemy_type
end
if yIsNil(npc.max_life) then
npc.max_life = 1
end
npc.life = npc.max_life
npc.weapon = phq.combots[yeGetString(npc.attack)]
print("NPC", npc.name, " WEAPON !!!!: ", npc.attack, npc.weapon, phq.combots )
return npc
end
function give_invok(_wid_, _eve_, invok_name)
local invoks = yeTryCreateArray(phq.pj, "invok")
invok_name = yeGetString(invok_name)
invoks = Entity.wrapp(invoks)
print(invok)
print("in give invock !!")
if yIsNNil(yeGet(invoks, invok_name)) then
return
end
printMessage(main_widget, nil, "Got new invock: " .. invok_name)
yePushBack(invoks, npcs[invok_name], invok_name)
end
function StartFight(wid, eve, enemy_type, script)
local main = getMainWid(wid)
local fWid = Entity.new_array()
local npc
local music_rand = yuiRand() % 3
print(music_rand, main_widget.soundcallgirl:to_int(),
main_widget.soundfrenetic, main_widget.soundgoodf)
if music_rand == 0 then
ySoundPlayLoop(main_widget.soundcallgirl:to_int())
elseif music_rand == 1 then
ySoundPlayLoop(yeGetInt(main_widget.soundfrenetic));
else
ySoundPlayLoop(yeGetInt(main_widget.soundgoodf));
end
fight_script = nil
if yIsNNil(script) then
if (yeType(script)) == YARRAY then
script = Entity.wrapp(script)
fight_script = yeGetString(script[0])
else
fight_script = yeGetString(script)
end
end
phq.pj.weapon = phq.combots[yeGetString(phq.pj.attack)]
if (yIsNil(enemy_type)) then
local swid = yDialogueGetMain(wid)
swid = Entity.wrapp(swid)
npc = main.npcs[swid.npc_nb:to_int()].char
npc = npcDefaultInit(npc, "???")
else
if yeType(enemy_type) == YARRAY then
local i = 0
npc = Entity.new_array()
while i < yeLen(enemy_type) do
local enemy_type_i = yeGet(enemy_type, i)
npc[i] = npcs[yeGetString(enemy_type_i)]
npc[i] = npcDefaultInit(npc[i], enemy_type_i)
i = i + 1
end
else
npc = npcs[yeGetString(enemy_type)]
if npc == nil then
npc = Entity.wrapp(ygGet(yeGetString(enemy_type)))
enemy_type = npc.name
end
npc = npcDefaultInit(npc, enemy_type)
end
end
local player_array = Entity.new_array()
local allies = phq.pj.allies
player_array[0] = phq.pj
if allies[0] then
player_array[1] = allies[0]
allies[0] = npcDefaultInit(allies[0], yeGetKeyAt(allies, 0))
if allies[1] then
player_array[2] = allies[1]
allies[1] = npcDefaultInit(allies[1], yeGetKeyAt(allies, 1))
end
end
fWid["<type>"] = "jrpg-fight"
fWid.endCallback = Entity.new_func(CombatEnd)
fWid.ychar_start = 80
fWid.endCallbackArg = main
fWid.player = player_array
if yIsNNil(main_widget.cur_scene.fight_background) then
fWid.fight_background = main_widget.cur_scene.fight_background
end
if yIsNNil(main_widget.cur_scene.fight_half_background) then
fWid.half_background = main_widget.cur_scene.fight_half_background
end
if yIsNNil(main_widget.cur_scene.fight_fill_backgrounf) then
fWid.background = main_widget.cur_scene.fight_fill_backgrounf
end
local usabel_items = Entity.new_array(phq.pj, "usable_items")
local i = 0
local inv = phq.pj.inventory
while i < yeLen(inv) do
local obj = phq.objects[yeGetKeyAt(inv, i)]
if obj and yeGetStringAt(obj, "type") == "usable" then
usabel_items[yeGetKeyAt(inv, i)] = inv[i]
end
i = i + 1
end
fWid.enemy = npc
if fight_script == "CombatDialogueNext" then
dialogue_mod.gotoNext(wid, eve)
elseif fight_script == "RemoveEnemy" then
local npc_a = main_widget.npc_act
print("=dbg=")
print(script)
print(Entity.wrapp(script))
print("-\\dbg-")
local obj = main_widget.mainScreen.objects[script[1].obj_idx]
if obj.no_respawn then
obj.dead = 1
end
if yIsNNil(obj.victory_action) then
npc.victory_action = obj.victory_action
if yIsNNil(obj.vapath) then
npc.vapath = obj.vapath
end
end
if obj.ai then
for j = 0, yeLen(npc_a) do
if yIsNNil(npc_a[j]) and script[1] == npc_a[j][ACTION_NPC] then
yeRemoveChild(wid.npc_act, j)
break
end
end
yGenericHandlerNullify(script[1])
else
yGenericHandlerNullify(script[1])
yeRemoveChild(main.enemies, script[1])
end
elseif fight_script == "CombatDialogueGoto" then
dialogue_mod["goto"](wid, eve, script[1])
elseif fight_script ~= "CombatDialogueStay" then
backToGame(wid, eve)
end
ywPushNewWidget(main, fWid)
return YEVE_ACTION
end
function addObject(main, character, objStr, nb)
local obj = character.inventory[objStr]
local msg = "get "
if yIsLuaNum(nb) == false and yeType(nb) == YARRAY then
nb = Entity.wrapp(nb)
local operation = yeGetString(nb[0]);
local el0 = nb[1];
local el1 = nb[2];
if yeType(el0) == YSTRING then
el0 = ygGetInt(ygGet(yeGetString(el0)))
end
if yeType(el1) == YSTRING then
el1 = ygGet(yeGetString(el1))
end
el0 = yeGetInt(el0)
el1 = yeGetInt(el1)
if operation == "+" then
nb = el0 + el1
elseif operation == "-" then
nb = el0 - el1
elseif operation == "*" then
nb = el0 * el1
elseif operation == "/" then
nb = el0 / el1
end
end
if obj then
local o_nb = yeGetInt(obj) + nb
if o_nb == 0 then
character.inventory[objStr] = nil
else
yeSetInt(obj, o_nb)
end
elseif nb > 0 then
character.inventory[objStr] = nb
else
return YEVE_NOACTION
end
if (nb < 0) then
msg = "lose "
nb = nb * -1
end
return printMessage(main, obj, msg .. math.floor(nb) .. " " .. objStr)
end
function recive(_wid, _eve, objStr, nb)
if yeType(nb) ~= YARRAY then
nb = yeGetInt(nb)
if nb == 0 then
nb = 1
end
end
addObject(main_widget, phq.pj, yeGetString(objStr), nb)
end
function remove(_wid, _eve, objStr, nb)
wid = main_widget
nb = yeGetInt(nb)
if nb == 0 then
nb = -1
else
nb = -nb
end
addObject(wid, phq.pj, yeGetString(objStr), nb)
end
function equip_skate()
main_widget.pj['skate_acel'] = Pos.new(0, 0).ent
end
function takeObject(main, actionable_obj, what, nb)
actionable_obj = Entity.wrapp(actionable_obj)
if actionable_obj.is_used then
return YEVE_ACTION
end
addObject(main, phq.pj, yeGetString(what), yeGetInt(nb))
actionable_obj.is_used = true
end
function leave_team(who)
printMessage(main_widget, nil, who .. " leave the Team !")
yeRemoveChild(phq.pj.allies, who)
end
function leave_team_callback(_wid, _eves, who)
leave_team(yeGetString(who))
end
function join_team(wid, _eves, who)
local npcname = yeGetString(who)
local npcidx = nil
if yIsNil(who) then
local m = yDialogueGetMain(wid)
npcname = yeGetStringAt(m, "name")
npcidx = yeGet(m, "npc_nb")
end
printMessage(main_widget, nil, npcname .. " have join the Team !")
yePushBack(phq.pj.allies, npcs[npcname], npcname)
if yIsNNil(npcidx) then
npcidx = yeGetInt(npcidx)
NpcGoTo(main_widget.npcs[npcidx], ylpcsHandePos(main_widget.pj))
end
end
function go_under(_unused_wid, _unused_eve, entry)
local wid = Entity.new_array()
wid["<type>"] = "raycasting"
wid.background = "rgba: 140 150 155 255";
Entity.from_lua_arrray({
"#########",
"#......##",
"#..#...##",
"#..#...##",
"#.#.....#",
"#.#..#.##",
"#.#..#..#",
"#.#..#.##",
"#.#.....#",
"###.##..#",
"#....##.#",
"####.#..#",
"#########"
}, wid, "map")
wid.quit = Entity.new_func("backToGame")
wid.pc = phq.pj
wid.exit_action = Entity.new_func(changeScene)
wid.enemies = {}
local e_pos = Pos.new(5200, 2200).ent
wid.enemies[0] = {e_pos, "rat"}
wid.exits = {}
wid.exits[0] = {1300, 8500, "up", "st_1", "street1", 7}
wid.exits[1] = {1300, 10500, "up", "st_1_b", "hiden_house", 0}
--wid.exits[1] = {1300, 6500, "up", "st_1_b", "hiden_house", 0}
wid.entry = entry
print(wid)
ywPushNewWidget(main_widget, wid)
return YEVE_ACTION
end
function pay(wid, eve, cost, okAction, noDialogue)
cost = yeGetInt(cost)
if phq.pj.inventory.money >= cost then
local money = phq.pj.inventory.money
yeSetInt(money, money:to_int() - cost)
return ywidAction(okAction, wid, eve)
end
return dialogue_mod["change-text"](wid, eve, noDialogue)
end
function increaseStat(wid, stats_container, stat, nb, max_min)
local s = Entity.wrapp(yeGetByStr(stats_container, stat))
local opStr = "increase"
yeSetInt(s, s:to_int() + nb)
if nb < 0 then
opStr = "decrease"
if max_min and s < max_min then
yeSetInt(s, max_min)
end
else
if max_min and s > max_min then
yeSetInt(s, max_min)
end
end
return printMessage(wid, stats_container,
Entity.new_string(stat .. " " .. opStr .. " to " ..
math.floor(yeGetInt(s))))
end
function increase(_wid, _eve, whatType, what, val)
local wid = main_widget
if yeType(what) == YINT then
val = what
what = whatType
return increaseStat(wid, phq.pj, yeGetString(what), yeGetInt(val))
end
local stat_container = phq.pj[yeGetString(whatType)]
what = yeGetString(what)
if stat_container[what] == nil then
stat_container[what] = 0
end
return increaseStat(wid, stat_container, what, yeGetInt(val))
end
function new_pj_tmp_stat(name)
if yIsNil(phq.pj.tmp_stats) then
phq.pj.tmp_stats = {}
end
return Entity.new_array(phq.pj.tmp_stats, name)
end
function tmp_increase(_wid, actionable_obj, what, val)
actionable_obj = Entity.wrapp(actionable_obj)
if actionable_obj.t and
actionable_obj.t.d == phq.env.day and
actionable_obj.t.t == phq.env.time and
actionable_obj.t.w == phq.env.week
then
return YEVE_ACTION
end
val = yeGetInt(val)
local tsts = new_pj_tmp_stat()
tsts[0] = what
tsts[1] = -val
local s = "Increase: " .. yeGetString(what) .. " temporary of: " .. val
printMessage(main_widget, nil, s)
actionable_obj.t = {}
actionable_obj.t.t = phq.env.time
actionable_obj.t.d = phq.env.day
actionable_obj.t.w = phq.env.week
ygIncreaseInt(yeGetString(what), val)
end
function DrinkBeer(ent, obj)
ent = Entity.wrapp(ent)
local upcanvas = Canvas.wrapp(ent.upCanvas)
local m = Entity.wrapp(main_widget)
increaseStat(ent, phq.pj, "drunk", 9, 100)
increaseStat(ent, phq.pj, "life", 2, phq.pj.max_life:to_int())
upcanvas:remove(ent.life_nb)
ent.life_nb = ywCanvasNewTextExt(upcanvas.ent, 410, 10,
Entity.new_string(math.floor(phq.pj.life:to_int())),
"rgba: 255 255 255 255")
if phq.pj.drunk > 99 then
local indoorStr = ""
if m.cur_scene.exterior then
indoorStr = "it has weird colors, maybe it's because you're indoor\n"
end
return printMessage(m, obj,
Entity.new_string(
-- TODO: fix borken english
"you lift up you head, look at the stared sky\n" ..
indoorStr ..
"it's funny how it move"))
end
return printMessage(m, obj, Entity.new_string("Glou Glou !"))
end
function GetDrink(wid, eve)
local ent = Entity.wrapp(ywCntWidgetFather(yDialogueGetMain(wid)))
addObject(ent, phq.pj, "beer", 1)
return backToGame(wid, eve)
end
function call_quest_script(wid, _eve, script)
scripts[yeGetString(script)](main_widget, wid)
return YEVE_ACTION
end
function slack_off()
if advance_time() == false then
backToGame2()
return
end
advance_time()
advance_time()
increaseStat(nil, phq.pj.trait, "lazy", 1)
backToGame2()
end
cant_skip_time_reason = nil
-- in fact, this function do 2 things: adancing time and start sleep animation
function advance_time(_main, next_loc, force_skip_time, next_pos)
main = main_widget
if main.sleep_script then
scripts[main.sleep_script:to_string()](main)
end
if force_skip_time then
main.cant_skip_time = 0
end
if main.cant_skip_time and main.cant_skip_time > 0 then
printMessage(main, nil, "Can't skip time: " .. cant_skip_time_reason)
return false
end
if yeType(next_loc) == YSTRING or type(next_loc) == "string" then
main.sleep_loc = next_loc
main.sleep_loc_pos = next_pos
end
npcAdvenceTime()
local tmp_stats = phq.pj.tmp_stats
for i = 0, yeLen(tmp_stats) - 1 do
local st = tmp_stats[i]
ygIncreaseInt(yeGetStringAt(st, 0), yeGetIntAt(st, 1))
end
yeClearArray(tmp_stats)
if phq.env.time:to_string() == "night" then
phq.env.time = "morning"
phq.env.daytmp = {}
phq.env.dayrand = yuiRand()
phq.env.day = phq.env.day + 1
if yeGetInt(phq.events.is_blockus) > 0 then
phq.events.is_blockus = nil
end
if phq.env.day > 6 then
phq.env.day = 0
phq.env.week = phq.env.week + 1
end
elseif phq.env.time:to_string() == "morning" then
phq.env.time = "day"
else
phq.env.time = "night"
end
-- I must handle season now
local is_raining = 0
if (yuiRand() % 3) == 0 then
is_raining = 1
end
if is_raining then
if phq.env.is_raining and is_raining > 0 then
phq.env.is_raining = phq.env.is_raining + 1
else
phq.env.is_raining = is_raining
end
end
phq.env.time_point = 1
main.sleep = 1
main.require_ret = 1
return true
end
function sleep(_main, _obj)
advance_time(main_widget)
phq.pj.life = phq.pj.max_life
phq.pj.drunk = 0
end
function printMessage(_main, _obj, msg)
local txt = yLuaString(msg)
local TIME_RESET = 2000000
main = main_widget
if (#txt > 30) then
TIME_RESET = TIME_RESET * #txt / 30
end
if (yIsNil(main)) then
return
end
if main.box then
local txt_tmp = yeGetString(dialogue_box.get_text(main.box))
if yIsNil(txt_tmp) then
return
end
if #txt_tmp > 1000 then
local i = txt_tmp:find("\n-------------------------------\n", 1, true)
if i and i > 1 then
i = i + #"\n-------------------------------\n"
print("sub", txt_tmp:sub(i))
txt_tmp = txt_tmp:sub(i)
end
end
txt = txt_tmp ..
"\n-------------------------------\n" .. txt
dialogue_box.rm(main.upCanvas, main.box)
main.box = nil
end
dialogue_box.new_text(main.upCanvas, 0, 0,
txt, main, "box")
if main.box_t and (main.box_t < 2000000 or main.box_t < TIME_RESET) then
main.box_t = main.box_t + TIME_RESET
else
main.box_t = TIME_RESET
end
if box_loading_bar then
ywCanvasRemoveObj(main_widget.upCanvas, box_loading_bar)
end
box_loading_bar = loading_bar.create(main.upCanvas, 0, 0)
end
local TMP_OBJ_SMALL_TALK = 0
local TMP_OBJ_CANVAS_OBJ = 1
function pushTmpCanvasObj(img, start_time)
local tmp_objs = yeTryCreateArray(main_widget.upCanvas, "tmp-objs")
local box = Entity.new_array(tmp_objs)
if yIsNNil(start_time) then
yeCreateInt(start_time, box)
else
yeCreateInt(0, box)
end
yeCreateInt(TMP_OBJ_CANVAS_OBJ, box)
yePushBack(box, img)
end
function pushSmallTalk(txt, x, y, start_time)
if type(txt) == "string" then
txt = Entity.new_string(txt)
end
if yeType(txt) == YARRAY then
if yeGetStringAt(txt, 0) == "rand" then
txt = yeGet(txt, yuiRand() % (yeLen(txt) - 1) + 1)
else
txt = yeGet(txt, 0)
end
end
local main = main_widget
local uc = main.upCanvas
local small_texts = yeTryCreateArray(uc, "tmp-objs")
local txt_box = Entity.new_array(small_texts)
local nb_nl = yeCountCharacters(txt, "\n", -1) + 1
if yIsNNil(start_time) then
yeCreateInt(start_time, txt_box)
else
yeCreateInt(0, txt_box)
end
yeCreateInt(TMP_OBJ_SMALL_TALK, txt_box)
dialogue_box.new_text(uc, x - 40, y - (40 * nb_nl),
yeGetString(txt), txt_box)
end
function smallTalk(_main, c)
--local n = npcs[yeGetInt(c.current)]
local p = ywCanvasObjPos(c)
local txt = c.small_talk
pushSmallTalk(txt, ywPosX(p), ywPosY(p))
end
function tmpObjsRemover(main)
local i = 0
local uc = main.upCanvas
local small_texts = yeGet(uc, "tmp-objs")
local time = ywidTurnTimer() / 1000
while (i < yeLen(small_texts)) do
local sti = yeGet(small_texts, i)
if yeGetIntAt(sti, 0) > 500 then
if yeGetIntAt(sti, 1) == TMP_OBJ_SMALL_TALK then
dialogue_box.rm(uc, yeGet(sti, 2))
elseif yeGetIntAt(sti, 1) == TMP_OBJ_CANVAS_OBJ then
ywCanvasRemoveObj(uc, yeGet(sti, 2))
else
print("can't remove obj of type: ", yeGetIntAt(sti, 1))
end
yeRemoveChild(small_texts, i)
else
yeSetAt(sti, 0, yeGetIntAt(sti, 0) + time)
end
i = i + 1
end
end
function npc_handler_from_canva(c)
return main_widget.npcs[c.current:to_int()]
end
function startDialogue(_main, obj, dialogue)
dialogue = Entity.wrapp(dialogue)
if dialogue and dialogues[dialogue:to_string()] then
obj = Entity.wrapp(obj)
local condition = obj.dialogue_condition
if yIsNNil(condition) and yeCheckCondition(condition) == false then
goto out
end
local dialogueWid = Entity.new_array()
local npc
local npc_nb = -1
if obj.current then
npc = npc_handler_from_canva(obj).char
npc_nb = obj.current
else
npc = obj
end
dialogue = dialogues[dialogue:to_string()]
dialogue_npc = npc
if dialogue.dialogue then
yeCopy(dialogue, dialogueWid)
dialogueWid.src = dialogue
else
dialogueWid.dialogue = dialogue
end
dialogueWid.npc_nb = npc_nb
dialogueWid["<type>"] = "dialogue-canvas"
dialogueWid.image = npc.image
dialogueWid.image_rotate = npc.image_rotate
dialogueWid.name = npc.name
dialogueWid.endAction = "phq.backToGame"
main_widget.dialogue_npc = npc
main_widget.require_ret = 1
ywPushNewWidget(main_widget, dialogueWid)
return YEVE_ACTION
end
:: out ::
return YEVE_NOTHANDLE
end
function actionOrPrint(main, obj)
obj = Entity.wrapp(obj)
local condition = Entity.new_array()
yeCreateString(yeGetString(obj.CheckOperation), condition)
yePushBack(condition, obj.Check0)
yePushBack(condition, obj.Check1)
local ret = yeCheckCondition(condition)
if ret then
return yesCall(ygGet(obj.SucessAction:to_string()),
main, obj, obj.ActionArg0,
obj.ActionArg1, obj.ActionArg2)