forked from aaixy/rm-mvmz-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerraxLighting.js
1804 lines (1581 loc) · 62.7 KB
/
TerraxLighting.js
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
//=============================================================================
// Terrax Plugins - Lighting system
// TerraxLighting.js
// Version: 1.2.9
//=============================================================================
//
// This script overwrites the following core scripts.
// Scene_Load.prototype.onSavefileOk
// Game_CharacterBase.prototype.updateMove
// Spriteset_Map.prototype.createLowerLayer
//=============================================================================
/*:
* @plugindesc v1.2.9 Creates an extra layer that darkens a map and adds lightsources!
* @author Terrax
*
* @param Player radius
* @desc Adjust the light radius around the player
* Default: 300
* @default 300
*
* @param Reset Lights
* @desc Resets the light switches each map
* Default: No
* @default No
*
* @param Save DaynightHours
* @desc Game variable the time of day (0-23) can be stored in
* Default: 0
* @default 0
*
* @param Save DaynightMinutes
* @desc Game variable the time of day (0-59) can be stored in
* Default: 0
* @default 0
*
* @param Save DaynightSeconds
* @desc Game variable the time of day (0-59) can be stored in
* Default: 0
* @default 0
*
* @param Flashlight offset
* @desc Increase this setting to move up the flashlight for double height characters.
* Default: 0
* @default 0
*
* @param Screensize X
* @desc Increase if your using a higher screen resolution then the default
* Default : 866
* @default 866
*
* @param Screensize Y
* @desc Increase if your using a higher screen resolution then the default
* Default : 630
* @default 630
*
* @param Kill Switch
* @desc Possible values A,B,C,D. If Selfswitch X is switched ON, the events lightsource will be disabled.
* Default : No
* @default No
*
* @help
* To activate the script in an area, do the following:
* 1. Put an event switch into the map.
* 2. In the 'Note' field (Next to the name) put the following text :
* Light 250 #FFFFFF
* - Light activates the script
* - 250 is the lightradius of the object
* - #FFFFFF is the lightcolor (white in this case)
* 3. You're done, its that simple.
*
* You can add two optional commands for brightness and direction
* Light 200 #FFFFFF B50 increases the brightness with 50%. Value between 0 and 99.
* Light 200 #FFFFFF D1 will give half a lightglobe for lightsources placed on walls.
* 1. For lights on north walls, light will face down.
* 2. For lights on east walls, light will face west.
* 3. For lights on south walls, light will face north.
* 4. For lights on west walls, light will face east.
*
* To alter the player radius in game use the following plugin command :
* Light radius 200 #FFFFFF (to change the radius and the color)
* If you want to change the player radius slowly over time (like a dying torch)
* use the command 'Light radiusgrow 200 #FFFFFF'
* You can alter the brightness of the players lightsource by adding:
* 'Light radius 200 #FFFFFF B70' (Brightness values between 0 and 99, 0 is default)
*
* To turn on and off lightsources in the game, do the following:
* Give the lightsource the normal def : Light 250 #FFFFFF and an extra number
* so it becomes 'Light 250 #FFFFFF 1'
* (If your using the optional brightness and direction place it after those (Light 250 #FFFFFF B50 D2 1)
* To turn on this light use plugin command : 'Light on 1'.
* The plugin command will also trigger SelfSwitch 'D' on the targeted light(s).
* To turn off the light use plugin command : 'Light off 1'.
* You can reset the switches each map with the option or manualy by
* the plugin command 'Light switch reset'
* You can also turn off lights with the kill-selfswitch defined in the parameters.
*
* Replacing the 'Light' keyworld with 'Fire' will give the lights a subtle flicker
* You can configure the fire effect with the plugin command 'SetFire 7 10'
* Where 7 is the radius change and 10 is the shift in color from red to yellow.
*
* To completly turn off the script use : 'Light deactivate'
* To turn it on again use the command: 'Light activate'
*
* To activate a day-night cycle on a map, put in a trigger with 'DayNight' in an event note
* or in the map note.
* Plugin command 'Daynight speed 10' changes the speed.
* Speed 10 means it takes 10 seconds to to pass one hour in game (probably to fast)
* Plugin command 'Daynight hour 16 30' sets the hour to 16:30 hours
* Each hour has its own color value.
* Plugin command 'Daynight color 0 #222222' changes 0:00 hours to color value '#222222'
* You can add time with the plugin command 'Daynight add 8 30' (this adds 8 hours and 30 minutes)
*
* If you want to use the time of day to trigger effects (like turning on lights when it gets dark)
* you can use the parameters 'Save DaynightHours','Save DaynightMinutes','Save DaynightSeconds'
* The default is 0, which means its off.
* If you set it to a value,5 for example, it will store the daynight value inside game variable 5.
* You can then use that variable to trigger lights.
* To help syncing/debugging the time system you can use scriptcommand 'daynight debug' to display the current time.
* If you want to go 'alien world' and stuff, you can change the number of hours in a day with
* script command 'daynight hoursinday 48' (for 48 hours in day, don't forget to fill in the hour values)
*
* As an alternative to the daynight cycle you can use the tint system. If you want to use another plugin for the
* day/night cycle, the tint option is probably best to use.
* The plugin command 'Tint set #333333' will make the room less dark.
* The plugin command 'Tint fade #777777 5' will fade the color from the current color to the new, the last
* number (5) is the speed of the fade, were 1 is a fast fade and 20 is a very slow one.
* If an area has a daynight cycle system, the tint system is disabled.
*
* To use a flashlight effect use 'Flashlight on 8 12 #FFFFFF 3' and 'Flashlight off'
* The arguments are optional (8=beamlength, 12=beamwidth, #FFFFFF=color, 3=beam density)
* Events can also use the flashlight effect. Use 'Flashlight 8 12 #888888 1 2' in the note-tag.
* where 8 is the length of the flashlights beam and 12 is the width of the beam. The last numbers are
* optional and can be used to turn the NPC's flashlight on or off and set the direction of the beam
* if the event is not moving (1=up, 2=right, 3=down, 4=left) the default is down.
*
* TileLight and RegionLight settings
* To create lightsources without using events you can use the following plugin command.
* TileLight 1 ON #FFFFFF 150 Will create a lightsource (color #FFFFFF radius 150) on all tiles with tile-tag 1.
* TileRegion 1 ON #FFFFFF 150 Will create a lightsource on all tiles with region-number 1.
* You can increase the brightness of a lightsource with the optional TileRegion 1 ON #FFFFFF 150 B50 (for 50% increased brightness)
* TileLight 1 OFF will turn off the lights on tile-tag 1 again
* TileRegion 1 OFF will turn off the lights on region-number 1 again
* TileFire and RegionFire works the same as TileLight, but with fire effect.
* Make sure your map still has at least one event with lights in it, otherwise the script will not run.
*
* TileBlock and RegionBlock settings
* To block lights on certain tiles (roofs for instance) you can use the following plugin command.
* TileBlock 1 ON #000000 Will block light on tiles with tile-tag 1.
* RegionBlock 1 ON #000000 Will block lights on tiles with region-number 1.
* TileBlock 1 OFF and TileRegion 1 OFF turns off the blocking again.
* To darken but not completly block light use a slightly higher color setting (#333333) for instance.
* This function does not raytrace. If the players lightradius is bigger then the blocking tiles the
* light will show on the other side. For the best effect keep the lightradius a bit smaller then the block section.
* for advance users, if you want to block more or less of the tile you can do the following
* RegionBlock 1 ON #000000 shape xoffset yoffset width height
* RegionBlock 1 ON #000000 1 20 20 10 10 -> this will block a box starting at 20,20 with width and height 10,10
* RegionBlock 1 ON #000000 2 20 20 10 10 -> this will block a oval starting at 20,20 with xradius 10 and yradius 10
*
* Released under the MIT license,
* if used for commercial projects feel free to make a donation or
* better yet, give me a free version of what you have created.
* e-mail : fox(AT)caiw.nl / terraxz2 on steam.
*
* Special thanks to everyone in the rpgmakerweb community for idea's, support and interest.
*/
//=============================================================================
// ps.. if my code looks funky, i'm an old guy..
// object orientated programming bugs the hell out of me.
var Imported = Imported || {};
Imported.TerraxLighting = true;
// These are global variables so they can be used by other daynight plugins
var Terrax_tint_speed = 60;
var Terrax_tint_target = '#000000';
// Global so it can be called from other plugins (compatability)
(function() {
var lightarray_id = [];
var tilearray = [];
var lightarray_state = [];
var lightgrow_value;
var lightgrow_target;
var lightgrow_speed;
var oldmap = 0;
var oldseconds = 0;
var playercolor = '#FFFFFF';
var playerflicker = false;
var playerbrightness = 0.0;
var flickerradiusshift = 7;
var flickercolorshift = 10;
var playerflashlight = false;
var flashlightlength = 8;
var flashlightwidth = 12;
var flashlightdensity = 3;
var scriptactive = true;
var daynightspeed = 10;
var daynightcycle = 17;
var daynighttimer = 0;
var daynightstop = false;
var daynightcolors = [ '#000000', '#000000', '#000000', '#000000',
'#000000', '#000000', '#666666', '#AAAAAA',
'#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
'#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
'#FFFFFF', '#FFFFFF', '#AAAAAA', '#666666',
'#000000', '#000000', '#000000', '#000000' ];
var daynightHoursInDay = 24;
var parameters = PluginManager.parameters('TerraxLighting');
var player_radius = Number(parameters['Player radius'] || 300);
var reset_each_map = parameters['Reset Lights'] || No;
var daynightsave = Number(parameters['Save DaynightHours'] || 10);
var daynightsavemin = Number(parameters['Save DaynightMinutes'] || 11);
var daynightsavesec = Number(parameters['Save DaynightSeconds'] || 12);
var flashlightoffset = Number(parameters['Flashlight offset'] || 0);
var killswitch = parameters['Kill Switch'] || No;
var maxX = Number(parameters['Screensize X'] || 866);
var maxY = Number(parameters['Screensize Y'] || 630);
var daynightdebug = false;
var tint_value = '#000000';
var tint_timer = 0;
//var tint_speed = 60;
//var tint_target = '#000000';
var tint_oldseconds = 0;
var move_event_x = [];
var move_event_y = [];
var move_event_id = [];
var move_event_dir = [];
var tiletest = false;
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
command = command.toLowerCase();
// ************* TILE TAGS ***************
if (command === 'tileblock' || command === 'regionblock' || command === 'tilelight' || command === 'regionlight' || command === 'tilefire' || command === 'regionfire') {
var tiletype = 0;
if (command === 'tileblock') { tiletype = 1; }
if (command === 'regionblock') { tiletype = 2; }
if (command === 'tilelight') { tiletype = 3; }
if (command === 'regionlight') { tiletype = 4; }
if (command === 'tilefire') { tiletype = 5; }
if (command === 'regionfire') { tiletype = 6; }
var tilenumber = Number(args[0]);
var tile_on = 0;
if (args[1] === 'on' || args[1] === 'ON') {
var tile_on = 1;
}
var tilecolor = args[2];
var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(tilecolor);
if (!isValidColor) {
if ( tiletype === 1 || tiletype === 2) {
tilecolor = '#000000';
} else {
tilecolor = '#FFFFFF';
}
}
var tileradius = 100;
var tilebrightness = 0.0;
var shape = 0;
var x1 = 0;
var y1 = 0;
var x2 = 0;
var y2 = 0;
if ( tiletype === 1 || tiletype === 2) {
if (args.length > 3) { shape = args[3]; }
if (args.length > 4) { x1 = args[4]; }
if (args.length > 5) { y1 = args[5]; }
if (args.length > 6) { x2 = args[6]; }
if (args.length > 7) { y2 = args[7]; }
} else {
if (args.length > 3) { tileradius = args[3]; }
if (args.length > 4) { tilebrightness = args[4]; }
}
var tilefound = false;
for (var i = 0; i < tilearray.length; i++) {
tilestr = tilearray[i];
var tileargs = tilestr.split(";");
if (tileargs[0] == tiletype && tileargs[1] == tilenumber ) {
tilefound = true;
if ( tiletype === 1 || tiletype === 2) {
tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
} else {
tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
}
//Graphics.Debug('Set',tilearray[i]);
}
}
if (tilefound === false) {
if ( tiletype === 1 || tiletype === 2) {
tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
} else {
tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
}
tilearray.push(tiletag);
//Graphics.Debug('Push',tiletag);
}
$gameVariables.setTileArray(tilearray);
}
// ************* TINT *******************
if (command === 'tint') {
if (args[0] === 'set') {
tint_value = args[1];
Terrax_tint_target = tint_value;
$gameVariables.setTintValue(tint_value);
}
if (args[0] === 'fade') {
Terrax_tint_target = args[1];
Terrax_tint_speed = args[2];
$gameVariables.setTintValue(Terrax_tint_target);
}
//Graphics.Debug('TINT',tint_value+' '+tint_target+' '+tint_speed);
}
// ************* DAYNIGHT *******************
if (command === 'daynight') {
if (args[0] === 'speed') {
daynightspeed = Number(args[1]);
if (daynightspeed == 0) {
daynightspeed = 1000;
daynightstop = true;
} else {
daynightstop = false;
}
$gameVariables.setSpeedDayNightSave(daynightspeed);
}
if (args[0] === 'add') {
var houradd = Number(args[1]);
var minuteadd = 0;
if (args.length > 2) {
minuteadd = Number(args[2]);
}
var daynightminutes = Math.floor(daynighttimer/daynightspeed);
daynightminutes = daynightminutes + minuteadd;
if (daynightminutes > 60) {
daynightminutes = daynightminutes - 60;
daynightcycle = daynightcycle + 1;
}
daynightcycle = daynightcycle + houradd;
daynighttimer = daynightminutes * daynightspeed;
$gameVariables.setDayNightSaveMin(daynightminutes);
if (daynightsavemin > 0) {
$gameVariables.setValue(daynightsavemin, daynightminutes);
}
if (daynightcycle < 0) {
daynightcycle = 0;
}
if (daynightcycle >= daynightHoursInDay) {
daynightcycle = daynightcycle - daynightHoursInDay;
}
if (daynightsave > 0) {
$gameVariables.setValue(daynightsave, daynightcycle);
}
$gameVariables.setDayNightSave(daynightcycle);
}
if (args[0] === 'hour') {
daynightcycle = Number(args[1]);
if (args.length > 2) {
daynightminutes = Number(args[2]);
} else {
daynightminutes = 0;
}
daynighttimer = daynightminutes * daynightspeed;
$gameVariables.setDayNightSaveMin(daynightminutes);
if (daynightsavemin > 0) {
$gameVariables.setValue(daynightsavemin, daynightminutes);
}
if (daynightcycle < 0) {
daynightcycle = 0;
}
if (daynightcycle >= daynightHoursInDay) {
daynightcycle = (daynightHoursInDay-1);
}
if (daynightsave > 0) {
$gameVariables.setValue(daynightsave, daynightcycle);
}
$gameVariables.setDayNightSave(daynightcycle);
}
if (args[0] === 'hoursinday') {
var old_value = daynightHoursInDay ;
daynightHoursInDay = Number(args[1]);
if (daynightHoursInDay < 0) {
daynightHoursInDay = 0;
}
if (daynightHoursInDay > old_value) {
for (var i = old_value; i < daynightHoursInDay; i++) {
daynightcolors.push('#FFFFFF');
}
}
$gameVariables.setDayNightColorArray(daynightcolors);
$gameVariables.setDayNightHoursInDay(daynightHoursInDay);
}
if (args[0] === 'debug') {
daynightdebug = true;
}
if (args[0] === 'color') {
var hour = Number(args[1]);
if (hour < 0) {
hour = 0;
}
if (hour >= daynightHoursInDay) {
hour = (daynightHoursInDay-1);
}
hourcolor = args[2];
var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hourcolor);
if (isValidColor) {
daynightcolors[hour] = hourcolor;
}
$gameVariables.setDayNightColorArray(daynightcolors);
}
}
// ************* FLASHLIGHT *******************
if (command === 'flashlight') {
if (args[0] == 'on') {
playerflashlight = true;
if (args.length >= 1) { flashlightlength = args[1]; }
if (args.length >= 2) { flashlightwidth = args[2]; }
if (args.length >= 3) {
playercolor = args[3];
var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
if (!isValidPlayerColor) {
playercolor = '#FFFFFF'
}
}
if (args.length >= 4) {
flashlightdensity = args[4]; // density
}
if (flashlightlength == 0 || isNaN(flashlightlength)) { flashlightlength = 8 }
if (flashlightwidth == 0 || isNaN(flashlightwidth)) { flashlightwidth = 12 }
if (flashlightdensity == 0 || isNaN(flashlightdensity)) { flashlightdensity = 3 }
$gameVariables.setPlayerColor(playercolor);
$gameVariables.setFlashlightWidth(flashlightwidth);
$gameVariables.setFlashlightLength(flashlightlength);
$gameVariables.setFlashlightDensity(flashlightdensity);
}
if (args[0] === 'off') {
playerflashlight = false;
}
$gameVariables.setFlashLight(playerflashlight);
}
// ******************* SET FIRE *******************
if (command === 'setfire') {
flickerradiusshift = args[0];
flickercolorshift = args[1];
$gameVariables.setFireRadius(flickerradiusshift);
$gameVariables.setFireColorshift(flickercolorshift);
}
// ******************* FIRE *******************
if (command === 'fire') {
playerflicker = true;
$gameVariables.setFire(playerflicker);
$gameVariables.setFireRadius(flickerradiusshift);
$gameVariables.setFireColorshift(flickercolorshift);
} else {
playerflicker = false;
$gameVariables.setFire(playerflicker);
$gameVariables.setFireRadius(flickerradiusshift);
$gameVariables.setFireColorshift(flickercolorshift);
}
//var evid = this._eventId;
if (command === 'light' || command === 'fire') {
//******************* Light radius 100 #FFFFFF ************************
if (args[0] == 'radius') {
var newradius = Number(args[1]);
if (newradius >= 0) {
player_radius = newradius;
lightgrow_value = newradius;
lightgrow_target = newradius;
$gameVariables.setRadiusSave(player_radius);
}
if (args.length > 2) {
playercolor = args[2];
var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
if (!isValidPlayerColor) {
playercolor = '#FFFFFF'
}
$gameVariables.setPlayerColor(playercolor);
}
// player brightness
if (args.length > 3) {
var brightness = 0.0;
var b_arg = args[3];
if (typeof b_arg != 'undefined') {
var key = b_arg.substring(0,1);
if (key == 'b' || key == 'B') {
playerbrightness = Number(b_arg.substring(1))/100;
$gameVariables.setPlayerBrightness(playerbrightness);
}
}
}
}
//******************* Light radiusgrow 100 #FFFFFF ************************
if (args[0] === 'radiusgrow') {
var evid = this._eventId;
//Graphics.printError('test',evid);
var newradius = Number(args[1]);
if (newradius >= 0) {
//player_radius = newradius;
lightgrow_value = player_radius;
lightgrow_target = newradius;
if (args.length >= 4) {
if(player_radius > newradius) {
//shrinking
lightgrow_speed = (player_radius * 0.012) / Number(args[4]);
} else {
//growing
lightgrow_speed = (newradius * 0.012) / Number(args[4]);
}
}else {
lightgrow_speed = (Math.abs(newradius-player_radius))/500;
}
//lightgrow_speed = (Math.abs(newradius-player_radius))/500;
}
// player color
if (args.length > 2) {
playercolor = args[2];
var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
if (!isValidPlayerColor) {
playercolor = '#FFFFFF'
}
$gameVariables.setPlayerColor(playercolor);
}
// player brightness
if (args.length > 3) {
var brightness = 0.0;
var b_arg = args[3];
if (typeof b_arg != 'undefined') {
var key = b_arg.substring(0,1);
if (key == 'b' || key == 'B') {
playerbrightness = Number(b_arg.substring(1))/100;
$gameVariables.setPlayerBrightness(playerbrightness);
}
}
}
}
// *********************** TURN SPECIFIC LIGHT ON *********************
if (args[0] === 'on') {
var lightid = Number(args[1]);
var idfound = false;
for (var i = 0; i < lightarray_id.length; i++) {
if (lightarray_id[i] == lightid) {
idfound = true;
lightarray_state[i] = true;
}
}
if (idfound == false) {
lightarray_id.push(lightid);
lightarray_state.push(true);
}
//Graphics.printError('test',lightarray_id.length+' '+lightarray_state.length);
$gameVariables.setLightArrayId(lightarray_id);
$gameVariables.setLightArrayState(lightarray_state);
}
// *********************** TURN SPECIFIC LIGHT OFF *********************
if (args[0] === 'off') {
var lightid = Number(args[1]);
var idfound = false;
for (var i = 0; i < lightarray_id.length; i++) {
if (lightarray_id[i] == lightid) {
idfound = true;
lightarray_state[i] = false;
}
}
if (idfound == false) {
lightarray_id.push(lightid);
lightarray_state.push(false);
}
$gameVariables.setLightArrayId(lightarray_id);
$gameVariables.setLightArrayState(lightarray_state);
//Graphics.Debug('RESET3','RESET3');
}
// **************************** RESET ALL SWITCHES ***********************
if (args[0] === 'switch' && args[1] === 'reset') {
// reset switches to false
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
for (var j = 0; j < lightarray_id.length; j++) {
if (lightarray_id[j] == lightid) {
var mapid = $gameMap.mapId();
var eventid = $dataMap.events[i].id;
var key = [mapid,eventid,'D'];
$gameSelfSwitches.setValue(key, false);
}
}
}
}
lightarray_id = [];
lightarray_state = [];
$gameVariables.setLightArrayId(lightarray_id);
$gameVariables.setLightArrayState(lightarray_state);
}
}
// *********************** TURN SCRIPT ON/OFF *********************
if (command === 'light' && args[0] == 'deactivate') {
scriptactive = false;
$gameVariables.setScriptActive(false);
}
if (command === 'light' && args[0] == 'activate') {
scriptactive = true;
$gameVariables.setScriptActive(true);
}
}
Spriteset_Map.prototype.createLightmask = function() {
this._lightmask = new Lightmask();
this.addChild(this._lightmask);
};
function Lightmask() {
this.initialize.apply(this, arguments);
}
Lightmask.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
Lightmask.prototype.constructor = Lightmask;
Lightmask.prototype.initialize = function() {
PIXI.DisplayObjectContainer.call(this);
this._width = Graphics.width;
this._height = Graphics.height;
this._sprites = [];
this._createBitmap();
};
//Updates the Lightmask for each frame.
Lightmask.prototype.update = function() {
this._updateMask();
};
//@method _createBitmaps
Lightmask.prototype._createBitmap = function() {
this._maskBitmap = new Bitmap(maxX,maxY); // one big bitmap to fill the intire screen with black
var canvas = this._maskBitmap.canvas;
};
/**
* @method _updateAllSprites
* @private
*/
Lightmask.prototype._updateMask = function() {
// ****** DETECT MAP CHANGES ********
var map_id = $gameMap.mapId();
if (map_id != oldmap) {
oldmap = map_id;
// moving lightsources
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
for (var j = 0; j < move_event_id.length; j++) {
if (move_event_id[j] == i) {
move_event_x[j] = $dataMap.events[i].x;
move_event_y[j] = $dataMap.events[i].y;
move_event_dir[j] = 2;
}
}
}
}
if (reset_each_map == 'Yes' || reset_each_map == 'yes') {
// reset switches to false
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
for (var j = 0; j < lightarray_id.length; j++) {
if (lightarray_id[j] == lightid) {
var mapid = $gameMap.mapId();
var eventid = $dataMap.events[i].id;
var key = [mapid,eventid,'D'];
$gameSelfSwitches.setValue(key, false);
}
}
}
}
Lightarray_id = [];
lightarray_state = [];
$gameVariables.setLightArrayId(lightarray_id);
$gameVariables.setLightArrayState(lightarray_state);
}
}
// remove old sprites
for (var i = 0; i < this._sprites.length; i++) { // remove all old sprites
this._removeSprite();
}
if (scriptactive == true) {
// are there lightsources on this map?
if($dataMap.note == undefined) return; //modify by xy 2017.1.7
var searchdaynight = $dataMap.note.toLowerCase();
if (searchdaynight.search('daynight') > 0) {
this._addSprite(0,0,this._maskBitmap); // daynight tag? yes.. then turn off the lights
} else {
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
var note = $dataMap.events[i].note
var note_args = note.split(" ");
var note_command = note_args.shift().toLowerCase();
if (note_command == "light" || note_command == "fire" || note_command == "daynight" || note_command == "flashlight" ) {
this._addSprite(0,0,this._maskBitmap); // light event? yes.. then turn off the lights
break;
}
}
}
}
// ******** GROW OR SHRINK GLOBE *********
if (lightgrow_value < lightgrow_target) {
lightgrow_value = lightgrow_value + lightgrow_speed;
if(lightgrow_value > lightgrow_target) {
//other wise it can keep fliping back and forth between > and <
lightgrow_value = lightgrow_target;
}
player_radius = Math.floor(lightgrow_value)
$gameVariables.setRadiusSave(player_radius);
}
if (lightgrow_value > lightgrow_target) {
lightgrow_value = lightgrow_value - lightgrow_speed;
if(lightgrow_value < lightgrow_target) {
//other wise it can keep fliping back and forth between > and <
lightgrow_value = lightgrow_target;
}
player_radius = Math.floor(lightgrow_value)
$gameVariables.setRadiusSave(player_radius);
}
// ****** PLAYER LIGHTGLOBE ********
var canvas = this._maskBitmap.canvas;
var ctx = canvas.getContext("2d");
this._maskBitmap.fillRect(0, 0, maxX, maxY, 'black');
//ctx.globalCompositeOperation = 'lighten';
ctx.globalCompositeOperation = 'lighter';
var pw = $gameMap.tileWidth()
var ph = $gameMap.tileHeight();
var dx = $gameMap.displayX();
var dy = $gameMap.displayY();
var px = $gamePlayer._realX;
var py = $gamePlayer._realY;
var pd = $gamePlayer._direction;
var x1 = (pw/2)+( (px-dx)*pw);
var y1 = (ph/2)+( (py-dy)*ph);
var paralax = false;
// paralax does something weird with coordinates.. recalc needed
if (dx>$gamePlayer.x) {
var xjump = $gameMap.width() - Math.floor(dx-px);
x1 = (pw/2)+(xjump*pw);
}
if (dy>$gamePlayer.y) {
var yjump = $gameMap.height() - Math.floor(dy-py);
y1 = (ph/2)+(yjump*ph);
}
if (player_radius > 0) {
if (playerflashlight == true) {
this._maskBitmap.radialgradientFillRect2(x1,y1, 20, player_radius, playercolor, 'black', pd, flashlightlength, flashlightwidth);
}
if (player_radius < 100){
// dim the light a bit at lower lightradius for a less focused effect.
var r = hexToRgb(playercolor).r;
var g = hexToRgb(playercolor).g;
var b = hexToRgb(playercolor).b;
g = g - 60;
r = r - 60;
b = b - 60;
if (g<0) { g = 0; }
if (r<0) { r = 0; }
if (b<0) { b = 0; }
var newcolor = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
this._maskBitmap.radialgradientFillRect(x1,y1, 0, player_radius, newcolor, 'black', playerflicker,playerbrightness);
} else {
this._maskBitmap.radialgradientFillRect(x1,y1, 20, player_radius, playercolor, 'black', playerflicker,playerbrightness);
}
}
// *********************************** DAY NIGHT CYCLE TIMER **************************
if (daynightspeed > 0) {
if (daynightstop == false) {
var seconds;
var datenow = new Date();
var seconds = Math.floor(datenow.getTime()/10);
if (seconds > oldseconds) {
oldseconds = seconds;
daynighttimer = daynighttimer + 1;
var daynightminutes = Math.floor(daynighttimer/daynightspeed)
var daynighttimeover = daynighttimer-(daynightspeed*daynightminutes)
var daynightseconds = Math.floor(daynighttimeover/daynightspeed*60)
if (daynightdebug == true) {
var daynightseconds2 = daynightseconds;
if (daynightseconds < 10) {
daynightseconds2 = '0' + daynightseconds;
}
Graphics.Debug('Debug Daynight system',daynightcycle+' '+daynightminutes+' '+daynightseconds2);
}
if (daynightsavemin > 0) {
$gameVariables.setValue(daynightsavemin, daynightminutes);
}
if (daynightsavesec > 0) {
$gameVariables.setValue(daynightsavesec, daynightseconds);
}
$gameVariables.setDayNightSaveMin(daynightminutes);
if (daynighttimer >= (daynightspeed * 60)) {
daynightcycle = daynightcycle + 1;
if (daynightcycle >= daynightHoursInDay ) {
daynightcycle = 0;
}
if (daynightsave > 0) {
$gameVariables.setValue(daynightsave, daynightcycle);
}
$gameVariables.setDayNightSave(daynightcycle);
daynighttimer = 0;
}
}
}
}
// ********** OTHER LIGHTSOURCES **************
var daynightset = false;
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
var note = $dataMap.events[i].note;
var evid = $dataMap.events[i].id;
var note_args = note.split(" ");
var note_command = note_args.shift().toLowerCase();
if (note_command == "light" || note_command == "fire" || note_command == "flashlight") {
var objectflicker = false;
if (note_command == "fire") {
objectflicker = true;
}
var light_radius = 1;
var flashlength = 8;
var flashwidth = 12;
if (note_command == "flashlight") {
flashlength = Number(note_args.shift());
flashwidth = Number(note_args.shift());
if (flashlength == 0) { flashlightlenth = 8 }
if (flashwidth == 0) { flashlightlenth = 12 }
} else {
light_radius = note_args.shift();
}
// light radius
if (light_radius >= 0) {
// light color
var colorvalue = note_args.shift();
var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorvalue)
if (!isValidColor) {
colorvalue = '#FFFFFF'
}
// brightness and direction
var brightness = 0.0;
var direction = 0;
var next_arg = note_args.shift();
if (typeof next_arg != 'undefined') {
var key = next_arg.substring(0,1);
if (key == 'b' || key == 'B') {
brightness = Number(next_arg.substring(1))/100;
next_arg = note_args.shift();
if (typeof next_arg != 'undefined') {
key = next_arg.substring(0,1);
}
}
if (key == 'd' || key == 'D') {
direction = next_arg.substring(1);
next_arg = note_args.shift();
}
}
// conditional lighting
if (typeof next_arg != 'undefined') {
var lightid = next_arg;
}else {
var lightid = 0;
}
//var lightid = note_args.shift();
var state = true;
if (lightid > 0) {
var state = false;
for (var j = 0; j < lightarray_id.length; j++) {
if (lightarray_id[j] == lightid) {
idfound = true;
state = lightarray_state[j];
var mapid = $gameMap.mapId();
var eventid = $dataMap.events[i].id;
//Graphics.printError('test',mapid+' '+eventid);
key = [mapid,eventid,'D'];
if (state == true) {
$gameSelfSwitches.setValue(key, true);
} else {
$gameSelfSwitches.setValue(key, false);
}
}
}
}
// kill switch
if (killswitch == 'A' || killswitch == 'B' || killswitch == 'C' || killswitch == 'D') {
key = [$gameMap.mapId(),$dataMap.events[i].id,killswitch];
if ($gameSelfSwitches.value(key) == true) {
state = false;
//Graphics.Debug('Deathswitch',killswitch);
}
}
// show light
if (state == true) {
var lpx = $dataMap.events[i].x;
var lpy = $dataMap.events[i].y;
ldir = 4
// moving lightsources
var flashlight = false;
for (var j = 0; j < move_event_id.length; j++) {
if (move_event_id[j] == evid) {
lpx = move_event_x[j];
lpy = move_event_y[j];
ldir = move_event_dir[j];
if (note_command === "flashlight") {
flashlight = true;
}
}
}
if (note_command == "flashlight" && flashlight === false ) {
flashlight = true;
// flashlight direction
var tldir = Number(note_args.shift());
if (!isNaN(tldir)) {
if (tldir < 0 || ldir >= 5) {ldir = 4}
if (tldir == 1) {ldir = 8}
if (tldir == 2) {ldir = 6}
if (tldir == 3) {ldir = 2}