-
Notifications
You must be signed in to change notification settings - Fork 130
/
itms_manager.script
1538 lines (1297 loc) · 43.3 KB
/
itms_manager.script
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
--[[
itms_manager
by Alundaio
Copyright (C) 2012 Alundaio
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Modified by Tronex:
2018/7/18 - Added support for new usable items (maps,craft)
2018/7/21 - Added the ability to gather/separate muti-use items
2018/7/26 - Added the ability to disassemble misc items
2018/7/26 - Rewrote a lot of function with better codes
2018/7/31 - Added new items, battery consumption for geiger counter and gps tracker
2018/8/2 - Drag artefacts on containers to put them in, container tool is no longer used
2019/2/16 - Organized the items in tables for global use
2019/9/19 - Bolt count manager
2020/3/18 - Cleaning
--]]
-- local uses = obj:get_remaining_uses()
-- local max_uses = obj:get_max_uses()
-- obj:set_remaining_uses(num)
-- Prepare ini files
ini_manager = ini_file("items\\settings\\itms_manager.ltx")
ini_container = ini_file("items\\settings\\arty_container.ltx")
ini_parts = ini_file("items\\settings\\parts.ltx")
ini_craft = ini_file("items\\settings\\craft.ltx")
ini_death = ini_file("items\\settings\\death_generic.ltx")
ini_reward = ini_file("items\\settings\\item_rewards.ltx")
ini_ammo = ini_file("items\\ammo\\ammo_vanilla.ltx")
ini_ammo_bas = ini_file("items\\ammo\\ammo_bas.ltx")
local n = 0
local result,id,value = "","",""
local string_find = string.find
local string_gsub = string.gsub
-- Collect item sections of main tools
itms_arty_container = utils_data.collect_section(ini_container,"containers",true) or {}
local empty_syringe_items = {}
n = ini_manager:line_count("empty_syringe_items")
for i=0,n-1 do
result, id, value = ini_manager:r_line_ex("empty_syringe_items",i,"","")
if ini_sys:section_exist(id) then
empty_syringe_items[id] = true
end
end
item_rewards = {}
ini_reward:section_for_each(function(section)
if (not item_rewards[section]) then
item_rewards[section] = {}
end
n = ini_reward:line_count(section)
for i=0,n-1 do
result, id, value = ini_reward:r_line_ex(section,i,"","")
if ini_sys:section_exist(id) then
item_rewards[section][id] = ini_sys:r_float_ex(id,"tier") or 1
end
end
end)
item_combine = {}
n = ini_craft:line_count("item_combination")
for i=0,n-1 do
result, id, value = ini_craft:r_line_ex("item_combination",i,"","")
if id and value then
local str = str_explode(id,":")
if str[1] and str[2] and ini_sys:section_exist(str[1]) and ini_sys:section_exist(str[2]) and ini_sys:section_exist(value) then
if (not item_combine[str[1]]) then
item_combine[str[1]] = {}
end
item_combine[str[1]][str[2]] = value
else
printe("!ERROR item_combination | wrong section names")
end
end
end
-------------------------------
-- CALLBACKS
-------------------------------
function on_game_start()
RegisterScriptCallback("actor_on_item_before_use",actor_on_item_before_use)
RegisterScriptCallback("actor_on_first_update",actor_on_first_update)
RegisterScriptCallback("actor_on_item_drop",actor_on_item_drop)
RegisterScriptCallback("actor_on_item_use",actor_on_item_use)
RegisterScriptCallback("actor_on_item_take",actor_on_item_take)
RegisterScriptCallback("ActorMenu_on_item_drag_drop",ActorMenu_on_item_drag_drop)
RegisterScriptCallback("ActorMenu_on_item_focus_receive",ActorMenu_on_item_focus_receive)
RegisterScriptCallback("save_state",save_state)
end
local old_booster = {}
local boost_min = 0.00005
local booster_string = {
["pwr"] = "ui_inv_power",
["psy"] = "ui_inv_outfit_telepatic_protection",
["bld"] = "ui_inv_bleeding",
["hp"] = "ui_inv_health",
["rad"] = "ui_inv_radiation",
}
function actor_on_item_before_use(obj,flags)
local sec = obj:section()
-- no need to check for tools
if IsItem("tool",sec) then
--printf("- actor_on_item_before_use [%s] | ignore utility item", sec)
flags.ret_value = true
return
end
local curr_booster = {}
local time_g = time_global()
local str = ""
local pass = true
-- read important boosts
local period = ini_sys:r_float_ex(sec, "boost_time") or 0
local rad_boost = ini_sys:r_float_ex(sec, "boost_radiation_restore") or 0
local psy_boost = ini_sys:r_float_ex(sec, "boost_telepat_protection") or 0
local bld_boost = ini_sys:r_float_ex(sec, "boost_bleeding_restore") or 0
local hp_boost = ini_sys:r_float_ex(sec, "boost_health_restore") or 0
local pwr_boost = ini_sys:r_float_ex(sec, "boost_power_restore") or 0
-- if an item is required
local require_tool = ini_sys:r_string_ex(sec, "required_tool")
local obj_tool = require_tool and ini_sys:section_exist(require_tool) and db.actor:object(require_tool)
-- store boosts in a table
curr_booster["section"] = sec
curr_booster["period"] = (period > 0) and (time_g + period*1000) or time_g
curr_booster["pwr"] = (pwr_boost > boost_min) and pwr_boost or 0
curr_booster["psy"] = (psy_boost > boost_min) and psy_boost or 0
curr_booster["bld"] = (bld_boost > boost_min) and bld_boost or 0
curr_booster["hp"] = (hp_boost > boost_min) and hp_boost or 0
curr_booster["rad"] = (rad_boost > boost_min) and rad_boost or 0
-- A required tool is missing -> no eat
if require_tool and (not obj_tool) then
--printf("~ actor_on_item_before_use [%s] | require_tool [%s] is missing", sec, require_tool)
str = strformat(game.translate_string("st_itm_manager_missing_requirements"), ui_item.get_sec_name(require_tool))
pass = false
-- older booster is still active
-- elseif old_booster["period"] and (old_booster["period"] > time_g) then
--printf("~ on_before_item_use [%s] | older booster [%s] is still active", sec, old_booster['section'])
-- local weaker_effect
-- local stronger_effect
-- for k,v in pairs(curr_booster) do
-- if (k ~= "section") and (k ~= "period") then
-- local v2 = old_booster[k]
-- if v2 and (v > boost_min) and (v2 > boost_min) then
-- if (v <= v2) then
-- weaker_effect = k
-- else
-- stronger_effect = k
-- end
-- elseif (v2 == 0) and (v > boost_min) then
-- stronger_effect = k
-- end
-- end
-- end
-- older booster has some stronger effect, while new one doesn't have any stronger effect
-- if weaker_effect and (not stronger_effect) then
--printf("~ on_before_item_use [%s] | older booster [%s] has stronger effect: %s", sec, old_booster['section'], weaker_effect)
-- local boost_str = game.translate_string(booster_string[weaker_effect])
-- str = strformat(game.translate_string("st_itm_manager_greater_effect"),boost_str)
-- pass = false
-- end
end
-- to eat or not to eat
if pass then
--printf("- on_before_item_use [%s] | pass = true", sec)
flags.ret_value = true
copy_table(old_booster, curr_booster)
if obj_tool then
utils_item.discharge(obj_tool)
end
else
--printf("! actor_on_item_before_use [%s] | pass = false", sec)
flags.ret_value = false
--alife_release(obj)
--alife_create_item(sec,db.actor)
utils_xml.hide_menu()
actor_menu.set_msg(1, str,3)
end
end
function actor_on_first_update()
-- Delete base pda
local sim = alife()
local obj, se_obj
--[[
for i=1,65534 do
se_obj = sim:object(i)
if se_obj and (se_obj:section_name() == "device_pda") then
sim:release(se_obj,true)
end
end
--]]
-- Delete animation items on actor
for sec,_ in pairs(GetItemList("release")) do
obj = db.actor:object(sec)
if obj then
alife_release(obj)
end
end
-- Spawn bolts
local m_data = alife_storage_manager.get_state()
local bolt_first = m_data.bolt_first
if bolt_first then
alife_create_item(bolt_first, db.actor)
m_data.bolt_first = nil
end
local bolt_slot = m_data.bolt_slot
if bolt_slot then
alife_create_item(bolt_slot, db.actor)
end
local bolts = m_data.bolts
if bolts then
for sec,cnt in pairs(bolts) do
for i=1,cnt do
alife_create_item(sec, db.actor)
end
end
end
-- Damage equipment
if (not has_alife_info("start_equippment_handled")) and (not IsTestMode()) then
CreateTimeEvent(0,"delay_new_game_autosave",4,new_game_equippment)
end
-- Bolt manager
CreateTimeEvent("cycle","bolt_manager",60,bolt_manager)
end
function actor_on_item_drop(obj)
if not (obj) then
return
end
if (db.actor:has_info("actor_made_wish_for_riches")) then
db.actor:transfer_item(obj,db.actor)
elseif IsWeapon(obj) then
se_save_var(obj:id(), nil, "strapped_item", obj:condition())
end
end
function actor_on_item_use(obj)
if (db.actor:has_info("actor_made_wish_for_riches")) then
return
end
local sec = obj:section()
-- Strelok Notes
if (sec == "mlr_strelok_item_01") then
txr_routes.open_route("val","x18")
return
-- Deployable mgun
elseif (sec == "itm_deployable_mgun") then
use_deployable_mgun(obj)
return
-- Watch
elseif (sec == "hand_watch") then
use_watch(obj)
return
-- Chocolate Bar
elseif (sec == "chocolate") then
alife_create_item("chocolate_p", db.actor)
return
-- Bolts pack
elseif (sec == "bolts_pack") then
local bolts = {}
local n = math.random(20,30)
for i=1,n do
local actor = db.actor
if math.random(1,100) > 50 then
bolts[#bolts + 1] = "bolt"
else
bolts[#bolts + 1] = "bolt_bullet"
end
end
utils_item.delay_event(bolts, nil, "bolts_pack", false, 5)
return
-- give empty syringe on using some medical items
elseif empty_syringe_items[sec] then
alife_create_item("e_syringe", db.actor)
-- weather radar
elseif (sec == "device_weather_radar") then
ui_debug_weather.activate()
return
end
-- don't discharge items with no removal
if IsItem("multiuse_r",sec) then
local uses = obj:get_remaining_uses()
local max_uses = obj:get_max_uses()
if uses and max_uses and (uses < max_uses) then
obj:set_remaining_uses(uses + 1)
end
end
end
local str_itm_taken = game.translate_string("st_item_taken")
function actor_on_item_take(obj)
local sec = obj:section()
-- Play sound effect for item taking
play_item_sound(obj)
if IsWeapon(obj) and se_load_var(item_id, nil, "strapped_item") then
se_save_var(obj:id(), nil, "strapped_item", nil)
-- Explosive barrels
elseif (sec == "explosive_mobiltank") or (sec == "explosive_tank") then
local se_obj = alife_object(obj:id())
local fuel = tostring(math.random(6,8))
if se_obj then
alife_release(se_obj)
alife_create_item("explo_jerrycan_fuel", db.actor, {uses = 2})
end
-- Story special
elseif (sec == "main_story_1_quest_case") and (not has_alife_info("agr_u_bloodsucker_on_case")) then
db.actor:give_info_portion("agr_u_bloodsucker_on_case")
xr_effects.create_squad(nil,nil,{"agr_u_bloodsucker_3_squad","agr_u_bloodsucker"})
end
-- Show notification
--local str = strformat(str_itm_taken, ui_item.get_sec_name(sec))
--actor_menu.set_msg(2, str)
end
function dropdrop_ArtyContainer(obj_1, obj_2, sec_1, sec_2) -- Put artefact in container
local cont = sec_2
local arty = sec_1
if ini_sys:section_exist(arty .. "_" .. cont) then
local cond = obj_1 and obj_1:condition()
actor_effects.play_item_fx("container_tool_" .. cont .. "_dummy")
alife_create_item(arty .. "_" .. cont, db.actor, { cond = cond } )
alife_release(obj_1)
alife_release(obj_2)
end
end
function dropdrop_Basic_Combination(obj_1, obj_2, sec_1, sec_2) -- Combine basic items
local sec_new = item_combine[sec_1][sec_2]
actor_effects.play_item_fx("item_combination")
alife_create_item(sec_new, db.actor)
alife_release(obj_1)
alife_release(obj_2)
end
function ActorMenu_on_item_drag_drop(obj_1, obj_2, slot_from, slot_to)
-- Check capability
if not (slot_from == EDDListType.iActorBag and slot_to == EDDListType.iActorBag) then
return
end
local sec_1 = obj_1:section()
local sec_2 = obj_2:section()
if itms_arty_container[sec_2] then
if (ini_sys:r_string_ex(sec_1,"class") == "ARTEFACT") or (ini_sys:r_string_ex(sec_1,"class") == "SCRPTART") then
dropdrop_ArtyContainer(obj_1, obj_2, sec_1, sec_2)
end
elseif item_combine[sec_1] and item_combine[sec_1][sec_2] then
dropdrop_Basic_Combination(obj_1, obj_2, sec_1, sec_2)
end
end
local focus_last_sec
local focus_tbl = {}
local focus_upgr = {}
function ActorMenu_on_item_focus_receive(obj) -- highlight compatible items
--[[
local parent = obj:parent()
if not (parent and parent:id() == AC_ID) then
return
end
--]]
local sec_focus = obj:section()
if (focus_last_sec ~= sec_focus) then
local id = obj:id()
focus_last_sec = sec_focus
empty_table(focus_tbl)
local parent_sec = ini_sys:r_string_ex(sec_focus,"parent_section") or sec_focus
-- For weapons
if IsWeapon(obj) then
-- Ammo
local ammo = utils_item.get_ammo(sec_focus, id)
for i=1,#ammo do
focus_tbl[#focus_tbl + 1] = ammo[i]
end
-- Scopes
local scopes = parse_list(ini_sys, parent_sec, "scopes")
for i=1,#scopes do
focus_tbl[#focus_tbl + 1] = scopes[i]
end
local scope = utils_item.get_wpn_param(obj, sec_focus, "scopes_sect")
if scope and (obj:weapon_scope_status() == 2) then
focus_tbl[#focus_tbl + 1] = scope
end
-- Silencer
local sil = utils_item.get_wpn_param(obj, sec_focus, "silencer_name")
if sil and (obj:weapon_silencer_status() == 2) then
focus_tbl[#focus_tbl + 1] = sil
end
-- Grenade Launcher
local gl = utils_item.get_wpn_param(obj, sec_focus, "grenade_launcher_name")
if gl and (obj:weapon_grenadelauncher_status() == 2) then
focus_tbl[#focus_tbl + 1] = gl
end
end
-- Parts
local parts_str = ini_parts:r_string_ex("con_parts_list",parent_sec)
local parts = parts_str and (parts_str ~= "") and str_explode(parts_str,",")
if IsItem("ammo", parent_sec) then
local ammo_parts_str = ini_ammo:r_string_ex("ammo_vanilla",parent_sec) or ini_ammo_bas:r_string_ex("ammo_bas",parent_sec)
if ammo_parts_str and ammo_parts_str ~= "" then
parts = str_explode(ammo_parts_str,",")
end
end
if parts then
for i=1,#parts do
focus_tbl[#focus_tbl + 1] = parts[i]
end
end
-- Repair kits
local repair_type = ini_sys:r_string_ex(parent_sec,"repair_type")
if repair_type and repair_type ~= "" then
for kit,v in pairs(GetItemList("repair")) do
if v[repair_type] then
focus_tbl[#focus_tbl + 1] = kit
end
end
--[[
for kit,v in pairs(GetItemList("workshop")) do
if v[repair_type] then
focus_tbl[#focus_tbl + 1] = kit
end
end
--]]
end
-- Upgrade parts
local upgr_str = ini_sys:r_string_ex(parent_sec,"upgrades")
if upgr_str and upgr_str ~= "" then
if (not focus_upgr[parent_sec]) then
local upgr = parse_list(ini_sys,parent_sec,"upgrades")
focus_upgr[parent_sec] = {}
for i=1,#upgr do
extract_upgr_tools(focus_upgr[parent_sec], upgr[i])
end
end
for tool,_ in pairs(focus_upgr[parent_sec]) do
--printf("- upgrade part for [%s] -> [%s]", parent_sec, tool)
focus_tbl[#focus_tbl + 1] = tool
end
end
end
local inventory = GetActorMenu()
if not ((#focus_tbl > 0) or (inventory and inventory:IsShown())) then
return
end
for i=1,#focus_tbl do
inventory:highlight_section_in_slot(focus_tbl[i],EDDListType.iActorBag)
inventory:highlight_section_in_slot(focus_tbl[i],EDDListType.iPartnerTradeBag)
inventory:highlight_section_in_slot(focus_tbl[i],EDDListType.iDeadBodyBag)
inventory:highlight_section_in_slot(focus_tbl[i],EDDListType.iActorTrade)
inventory:highlight_section_in_slot(focus_tbl[i],EDDListType.iPartnerTrade)
end
end
function save_state(m_data) --// NOTE: bolts aren't saved in alife, so this is a temp solution
local bolts = {}
local function itr(obj)
local sec = obj:section()
if (sec == "bolt") or (sec == "bolt_bullet") then
if (not bolts[sec]) then
bolts[sec] = 0
end
bolts[sec] = bolts[sec] + 1
end
return false
end
db.actor:inventory_for_each(itr)
m_data.bolts = bolts
m_data.bolt_slot = db.actor:item_in_slot(6) and db.actor:item_in_slot(6):section() or nil
end
-------------------------------
-- ITEM OPTIONS (MENU)
-------------------------------
function menu_open(itm) -- return "open" name
local p = itm:parent()
if not (p and p:id() == AC_ID) then return end
if itms_arty_container[itm:section()] then return end -- default containers
return game.translate_string("st_item_open")
end
function menu_unpack(itm) -- return "unpack" name
local p = itm:parent()
if not (p and p:id() == AC_ID) then return end
return game.translate_string("st_item_unpack")
end
function menu_play(itm) -- return "Play" name
local p = itm:parent()
if not (p and p:id() == AC_ID) then return end
return game.translate_string("st_item_play")
end
function menu_place(obj) -- return "Place" name
return game.translate_string("st_item_place")
end
-------------------------------
-- ITEM OPTIONS (FUNCTOR)
-------------------------------
function use_package(obj)
local sec = obj:section()
local content = parse_list(ini_manager, "package_content", sec)
if #content > 0 then
utils_item.delay_event(content, {obj:id()}, "package_content", false, 5)
end
end
function use_package_random(obj)
local sec = obj:section()
local content = ini_manager:r_string_ex("package_content",sec)
if not content then return end
local t = str_explode(content,",")
local pick = {}
for i=1,#t do
if (#pick < 6) and (math.random(100) < 50) then
pick[#pick+1] = t[i]
end
end
pick = #pick > 1 and pick or {t[1],t[2],t[3],t[4]}
utils_item.delay_event(pick, {obj:id()}, "package_content", true, 5)
end
function use_deployable_mgun(obj)
local pos = vector():set(device().cam_pos)
pos:add(device().cam_dir:mul(3))
alife_create("deployable_mgun",pos,level.vertex_id(pos),db.actor:game_vertex_id())
end
function use_guitar(obj)
local n = math.random(28)
local snd = sound_object("music\\guitar_" .. tostring(n))
if (not snd) then return end
local period = snd:length()
snd:play_no_feedback(db.actor, 0, 0, db.actor:position(), 1.0, 1.0)
actor_effects.play_continuous_effect(period)
end
function use_harmonica(obj)
local n = math.random(5)
local snd = sound_object("music\\harmonica_" .. tostring(n))
if (not snd) then return end
local period = snd:length()
snd:play_no_feedback(db.actor, 0, 0, db.actor:position(), 1.0, 1.0)
actor_effects.play_continuous_effect(period)
end
function use_arty_container(obj)
local break_con
local break_arty
local sec = obj:section()
if (string.find(sec, "(lead.-_box)",3)) then
break_con = "lead_box"
break_arty = sec:gsub("_lead_box", "")
elseif (string.find(sec, "(af.-_iam)",3)) then
break_con = "af_iam"
break_arty = sec:gsub("_af_iam", "")
elseif (string.find(sec, "(af.-_aac)",3)) then
break_con = "af_aac"
break_arty = sec:gsub("_af_aac", "")
elseif (string.find(sec, "(af.-_aam)",3)) then
break_con = "af_aam"
break_arty = sec:gsub("_af_aam", "")
end
if break_con and break_arty and ini_sys:section_exist(break_con) and ini_sys:section_exist(break_arty) then
local cond = obj:condition()
_G.ARTY_FROM_CONT = true -- Hack to prevent player from exploting Artefacts Containers (gaining rank by recieving artefacts)
actor_effects.play_item_fx(break_con .. "_dummy")
alife_create_item(break_con, db.actor)
alife_create_item(break_arty, db.actor, { cond = cond } )
alife_release(obj)
end
end
function use_watch(obj)
local Y, M, D, h, mint, sec, ms = game.get_game_time():get()
local pharse = game.translate_string("st_dyn_news_day_part_am")
local mints = tostring(mint)
if (h > 12) then
h = h - 12
pharse = game.translate_string("st_dyn_news_day_part_pm")
elseif (h == 12) then
pharse = game.translate_string("st_dyn_news_day_part_pm")
elseif (h == 0) then
h = 12
end
if (mint < 10) then
mints = "0" .. tostring(mint)
end
utils_xml.hide_menu()
actor_menu.set_msg(1, tostring(h) .. ":" .. mints .. " " .. pharse , 3)
end
function use_place(obj)
local p = obj:parent()
if not (p and p:id() == AC_ID) then
return
end
local section = obj:section()
alife_release_id(obj:id())
local pos = db.actor:position()
pos:add(device().cam_dir:mul(1.2))
pos.y = db.actor:position().y + 1
local lvid = db.actor:level_vertex_id()
local gvid = db.actor:game_vertex_id()
local se_obj = alife_create(section,pos,lvid,gvid)
local rot = device().cam_dir:getH()
se_obj.angle = vector():set(0,rot,0)
end
-------------------------------
-- OTHERS
-------------------------------
function actor_on_trade(obj,sell_bye,money) -- bind_stalker on_trade
end
function actor_item_take(obj) -- bind_stalker on_item_take
end
function npc_on_item_take_from_box(npc,box,item)
end
function new_game_equippment()
-- Damage equipment
local function damage_items(actor,itm)
-- local sec = itm:section()
-- if (IsWeapon(itm) and (sec ~= "wpn_binoc_inv")) or IsOutfit(itm) or IsHeadgear(itm) or IsItem("device",sec) then
-- itm:set_condition(math.random(75,85)/100)
-- end
end
db.actor:iterate_inventory(damage_items,db.actor)
give_info("start_equippment_handled")
-- Override autosave
exec_console_cmd("save " .. user_name() .. " - autosave")
printf("- Autosaved new game")
-- Override ammo type if required
local start_wpn_tbl = alife_storage_manager.get_state().start_wpn_ammo
if start_wpn_tbl then
for id, ammo_sec in pairs(start_wpn_tbl) do
local wpn = level.object_by_id(id)
if wpn then
local ammo_list = utils_item.get_ammo(wpn:section(), wpn:id())
local ammo_type
for i=1,#ammo_list do
if (ammo_list[i] == ammo_sec) then
ammo_type = i-1
break
end
end
if ammo_type then
local wpn_ammo_mag_size = ini_sys:r_u32(wpn:section(), "ammo_mag_size")
if wpn_ammo_mag_size then
wpn:unload_magazine()
wpn:set_ammo_type(ammo_type)
wpn:set_ammo_elapsed(wpn_ammo_mag_size )
printdbg("- New game weapon | [%s] - ammo type used: %s", wpn:section(), ammo_type)
end
end
end
end
end
return true
end
function bolt_manager() -- limit bolt count in actor inventory
ResetTimeEvent("cycle","bolt_manager",60)
local sim = alife()
local bolt_max_num = ini_manager:r_float_ex("settings","bolt_max_num") or 99
local cnt = 0
local id, sec, se_obj
local function itr(temp, obj)
sec = obj:section()
if (sec == "bolt") or (sec == "bolt_bullet") then
cnt = cnt + 1
if (cnt > bolt_max_num) then
local se_obj = alife_object(obj:id())
if se_obj then
alife_release(se_obj)
end
end
end
end
db.actor:iterate_ruck(itr, nil)
return false
end
function give_item_reward(num_of_items)
num_of_items = num_of_items or 1
local prior = {
["health"] = 2,
["rad"] = 2,
["drink"] = 2,
["food"] = 2,
["ammo"] = 2,
["battery"] = 0,
}
local tot_power,tot_devices = 0,0
local ammo_suitable = {}
local ammo_avail = {}
local function itr(obj)
local sec = obj:section()
-- Evaluate medkits
if item_rewards["items_health"][sec] then
prior["health"] = prior["health"] - 1
end
-- Evaluate anti-rads
if item_rewards["items_rad"][sec] then
prior["rad"] = prior["rad"] - 1
end
-- Evaluate drink
if item_rewards["items_drink"][sec] then
prior["drink"] = prior["drink"] - 1
end
-- Evaluate food
if item_rewards["items_food"][sec] then
prior["food"] = prior["food"] - 1
end
-- Evaluate devices power
if IsItem("device",sec) then
tot_devices = tot_devices + 1
tot_power = tot_power + (obj:condition() * 100)
end
-- Evaluate weapons and ammo
if (sec ~= "wpn_binoc") and IsWeapon(obj) and (not IsMelee(obj)) then
local ammo = utils_item.get_ammo(obj:section(), obj:id())
if ammo and #ammo > 1 then
for i=1,#ammo do
local sec_ammo = ammo[i]
if item_rewards["items_ammo"][sec_ammo] then
ammo_suitable[sec_ammo] = true
end
end
end
end
if IsItem("ammo",sec) then
ammo_avail[sec] = { cnt = obj:ammo_get_count() , box = IsItem("ammo",sec) }
--printf("ammo_avail[%s] = { cnt = %s | box = %s", sec, ammo_avail[sec].cnt, ammo_avail[sec].box)
end
return false
end
db.actor:inventory_for_each(itr)
-- Total power of devices is less than %50 -> need battery
if (tot_power < (50 * tot_devices)) then
prior["battery"] = 1
end
-- No enough ammo found for existing weapons -> need ammo
for sec,_ in pairs(ammo_suitable) do
local ammo = ammo_avail[sec]
if ammo and (ammo.cnt >= ammo.box) then
prior["ammo"] = prior["ammo"] - 1
end
end
--[[
for k,p in pairs(prior) do
printf("- Prior[%s] = %s",k,p)
end
--]]
-- Give actor items
for i=1,num_of_items do
-- Search from higher to lower priority
local picker = {}
local pick_prior
local functor = function(t,a,b) return t[a] > t[b] end
for k,p in spairs(prior,functor) do
if (p > 0) then
if (not pick_prior) or (pick_prior == p) then
pick_prior = p
picker[#picker + 1] = k
end
end
end
if pick_prior and (#picker > 0) then
-- Pick random type of this priority
local item_reward
local k = picker[math.random(#picker)]
-- Pick random item
if k == "health" then
item_reward = random_key_table(item_rewards["items_health"])
elseif k == "rad" then
item_reward = random_key_table(item_rewards["items_rad"])
elseif k == "drink" then
item_reward = random_key_table(item_rewards["items_drink"])
elseif k == "food" then
item_reward = random_key_table(item_rewards["items_food"])
elseif k == "battery" then
item_reward = item_device.device_battery
elseif k == "ammo" then
item_reward = random_key_table(ammo_suitable)
end
if item_reward then
-- Reduce priority
prior[k] = prior[k] - 1
local amount = 1
-- Give items
local box_size = IsItem("ammo",item_reward)
local max_uses = IsItem("multiuse",item_reward)
local uses = max_uses and (max_uses >= 2) and 2 or 1
if uses then
amount = math.random(1,uses)
end
alife_create_item(item_reward, db.actor, {uses = amount , ammo = box_size})
-- Send news
news_manager.relocate_item(db.actor, "in", item_reward, amount)
end
break
end
end
end
function send_itm_msg(sec)
local str = strformat(game.translate_string("st_item_taken"), ui_item.get_sec_name(sec))
actor_menu.set_msg(2, str)
end
local upg_gr = {
["first"] = 1,
["secon"] = 2,
["third"] = 3,
["fourt"] = 4,
["fifth"] = 5,
}
local upg_ind = {
["a"] = 1,
["b"] = 2,
["c"] = 3,
["d"] = 4,
["e"] = 5,
["f"] = 6,
}
function extract_upgr_tools(t1, current_grp)
local elements = parse_list(ini_sys, current_grp, "elements")
-- Gather groups and indexes
for i=1,#elements do -- search in upgrade group elements
for k,v in pairs(upg_gr) do
if string_find(elements[i],k) then -- if we found a legit element
local indx = elements[i]:sub(9,9) -- get the index
local upg_idx = indx and upg_ind[indx]
if upg_idx then
local prop = ini_sys:r_string_ex(elements[i],"property")
if prop then
local pr = str_explode(prop,",")
local tool = utils_item.get_upgrade_prop_tool(pr[1])
local num = ((upg_idx <= 2) and 1) or ((upg_idx <= 4) and 2) or 3
local sec_tool = tool and tool:gsub("%^d", tostring(num)) or nil
if sec_tool then
t1[sec_tool] = true
else
local sec = ini_sys:r_string_ex(elements[i],"section")
printdbg("! extract_upgr | can't generate tool for upgrade [%s], property: %s", sec, pr[1])
end
end
end
end
end
end
-- Repeat
for i=1,#elements do
local next_grp = ini_sys:r_string_ex(elements[i],"effects")
if next_grp and (next_grp ~= "") then
extract_upgr_tools(t1,next_grp)
end
end
end
-------------------------------
-- MULTI-USE ITEMS
-------------------------------
function relocate_item_to_actor(actor, npc, section, amount)
if (not actor) then
return
end
amount = amount or 1
local npc_inv = npc and (not IsItem("anim",section)) and utils_item.collect_amount(npc, section, 1) or {}
local sim = alife()
local cnt = amount
local max_uses = IsItem("multiuse",section) or 1
while cnt > 0 do
-- Create or transfer object from npc
local id
if not is_empty(npc_inv) then
local id_pick = random_key_table(npc_inv)
local obj = id_pick and level.object_by_id(id_pick)
if obj then
npc:transfer_item(obj, actor)
npc_inv[id_pick] = nil
id = id_pick
end
else