设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3946|回复: 20
打印 上一主题 下一主题

[交流讨论] 都在用TerraxLighting没有用CommunityLighting的吗?

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6930
在线时间
708 小时
注册时间
2021-3-5
帖子
814
跳转到指定楼层
1
发表于 2021-5-13 10:17:44 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 RyanYe 于 2021-5-21 22:37 编辑



原帖地址在
https://forums.rpgmakerweb.com/i ... hting-mv-mz.124274/

这个TerraxLighting被各位大佬合力深度优化了(包括我认识的一位巴西密友,LOL)
如果没有人用的话,我给搬运到这边好了(好用很多很多)
我发现CommunityLighting后立马就放弃了Terrax

有人有需求吗?

edit:
今天(5-21)已更新到4.2版本
Community_Lighting.rar (19.24 KB, 下载次数: 103)

评分

参与人数 1+1 收起 理由
白嫩白嫩的 + 1 塞糖

查看全部评分

Lv4.逐梦者

梦石
0
星屑
7349
在线时间
945 小时
注册时间
2019-5-21
帖子
536

极短24参与极短21参与

2
发表于 2021-5-13 11:13:14 | 只看该作者
这是那个可以实现实时动态光照的插件咩?XD
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6930
在线时间
708 小时
注册时间
2021-3-5
帖子
814
3
 楼主| 发表于 2021-5-13 11:28:45 | 只看该作者
黛惠 发表于 2021-5-13 11:13
这是那个可以实现实时动态光照的插件咩?XD

4242
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
18572
在线时间
1029 小时
注册时间
2019-3-5
帖子
1418
4
发表于 2021-5-16 22:41:26 | 只看该作者
楼主帮忙帮一下吧,下载地址的git地址内陆无法打开,另外看到目前插件仍然有bug(大地图会闪耀?),有些不太放心使用。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
8624
在线时间
978 小时
注册时间
2016-8-22
帖子
58

开拓者

5
发表于 2021-5-17 08:25:40 | 只看该作者
我帮楼主上传一下吧
JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // Community Plugins - Lighting system
  3. // Community_Lighting.js
  4. /*=============================================================================
  5. Forked from Terrax Lighting
  6. =============================================================================*/
  7. var Community = Community || {};
  8. Community.Lighting = Community.Lighting || {};
  9. Community.Lighting.parameters = PluginManager.parameters('Community_Lighting');
  10. Community.Lighting.version = 2.6;
  11. var Imported = Imported || {};
  12. Imported.Community_Lighting = true;
  13. /*:
  14. * @plugindesc v2.6 Creates an extra layer that darkens a map and adds lightsources! Released under the MIT license!
  15. * @author Terrax, iVillain, Aesica, Eliaquim, Alexandre, Nekohime1989
  16. *
  17. * @param ---General Settings---
  18. * @default
  19. *
  20. * @param Options Menu Entry
  21. * @parent ---General Settings---
  22. * @desc Adds an option to disable this plugin's lighting effects to the options menu (leave blank to omit)
  23. * @default Lighting Effects
  24. *
  25. * @param Light event required
  26. * @parent ---General Settings---
  27. * @desc At least one light event on the current is needed to make the plugin active (as in original TerraxLighting)
  28. * @type boolean
  29. * @default false
  30. *
  31. * @param Lights Active Radius
  32. * @parent ---Offset and Sizes---
  33. * @desc The number of grid spaces away from the player that lights are turned on.
  34. * Default: 20
  35. * @default 20
  36. *
  37. * @param Reset Lights
  38. * @parent ---General Settings---
  39. * @desc Resets the conditional lights on map change
  40. * @type boolean
  41. * @default false
  42. *
  43. * @param Kill Switch
  44. * @parent ---General Settings---
  45. * @desc Possible values A,B,C,D. If Selfswitch X is switched ON, the event's lightsource will be disabled.
  46. * @type select
  47. * @option None
  48. * @option A
  49. * @option B
  50. * @option C
  51. * @option D
  52. * @default None
  53. *
  54. * @param Kill Switch Auto
  55. * @parent ---General Settings---
  56. * @desc If a conditional light is OFF(ON), lock the Kill Switch to ON(OFF)?
  57. * @type boolean
  58. * @default false
  59. *
  60. * @param Note Tag Key
  61. * @parent ---General Settings---
  62. * @desc Specify a key (<Key: Light 25 ...>) to be used with all note tags or leave blank for Terrax compatibility (Light 25 ...)
  63. * @default cl
  64. *
  65. * @param ---DayNight Settings---
  66. * @default
  67. *
  68. * @param Save DaynightHours
  69. * @parent ---DayNight Settings---
  70. * @desc Game variable the time of day (0-23) can be stored in.  Disable: 0
  71. * @type number
  72. * @min 0
  73. * @default 0
  74. *
  75. * @param Save DaynightMinutes
  76. * @parent ---DayNight Settings---
  77. * @desc Game variable the time of day (0-59) can be stored in.  Disable: 0
  78. * @type number
  79. * @min 0
  80. * @default 0
  81. *
  82. * @param Save DaynightSeconds
  83. * @parent ---DayNight Settings---
  84. * @desc Game variable the time of day (0-59) can be stored in.  Disable: 0
  85. * @type number
  86. * @min 0
  87. * @default 0
  88. *
  89. * @param Save Night Switch
  90. * @parent ---DayNight Settings---
  91. * @desc Game switch to set as ON during night and OFF during day.  Disable: 0
  92. * @type number
  93. * @min 0
  94. * @default 0
  95. *
  96. * @param Night Hours
  97. * @parent ---DayNight Settings---
  98. * @desc Comma-separated list of night hours.  Not used/relevant if Save Night Switch set to 0.
  99. * @default 0, 1, 2, 3, 4, 5, 6, 19, 20, 21, 22, 23
  100. *
  101. * @param DayNight Colors
  102. * @parent ---DayNight Settings---
  103. * @desc Set DayNight colors. Each color represents 1 hour of the day
  104. * @default ["#6666ff","#6666ff","#6666ff","#6666ff","#6666ff","#6666ff","#9999ff","#ccccff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffcc88","#9999ff","#6666ff","#6666ff","#6666ff","#6666ff"]
  105. * @type text[]
  106. *
  107. * @param ---Offset and Sizes---
  108. * @default
  109. *
  110. * @param Player radius
  111. * @parent ---Offset and Sizes---
  112. * @desc Adjust the light radius around the player
  113. * Default: 300
  114. * @type number
  115. * @min 0
  116. * @default 300
  117. *
  118. * @param Flashlight offset
  119. * @parent ---Offset and Sizes---
  120. * @desc Increase this setting to move up the flashlight for double height characters.
  121. * Default: 0
  122. * @type number
  123. * @min -100
  124. * @max 100
  125. * @default 0
  126. *
  127. * @param Screensize X
  128. * @parent ---Offset and Sizes---
  129. * @desc Increase if your using a higher screen resolution then the default
  130. * Default : 866
  131. * @default 866
  132. * @type number
  133. * @min 0
  134. *
  135. * @param Screensize Y
  136. * @parent ---Offset and Sizes---
  137. * @desc Increase if your using a higher screen resolution then the default
  138. * Default : 630
  139. * @default 630
  140. * @type number
  141. * @min 0
  142. *
  143. * @param Lightmask Padding
  144. * @parent ---Offset and Sizes---
  145. * @desc Offscreen x-padding size for the light mask
  146. * @type number
  147. * @min 0
  148. * @default 40
  149. *
  150. * @param ---Battle Settings---
  151. * @default
  152. *
  153. * @param Battle Tinting
  154. * @parent ---Battle Settings---
  155. * @desc Add a tint layer to the battle screen? If set to false, no light effect will occur during battles.
  156. * @type boolean
  157. * @default true
  158. *
  159. * @param Light Mask Position
  160. * @parent ---Battle Settings---
  161. * @desc Place the light mask above the battlers, or between the battleground and the battlers?
  162. * @type select
  163. * @option Above Battlers
  164. * @value Above Background and Battler
  165. * @option Between Background and Battlers
  166. * @value Between
  167. * @default Above
  168. *
  169. * @help
  170. *
  171. * --------------------------------------------------------------------------
  172. * Important info about note tags and the note tag key plugin paramter:  This
  173. * plugin features an optional note tag key that lets this plugin's note tags
  174. * work alongside those of other plugins--a feature not found in the original
  175. * Terrax Lighting plugin. If a note tag key is set in the plugin paramters,
  176. * all of these commands must be enclosed in a note tag with that particular
  177. * key in in order to be recognized.
  178. *
  179. * This note tag key applies to anything this plugin would have placed inside
  180. * a note box, such as "DayNight" on a map or "Light/Fire/etc on an event.
  181. *
  182. * Examples:
  183. *
  184. * With the default note tag key, "CL" (not case sensitive):
  185. * <CL: Light 250 #ffffff>
  186. * <CL: Daynight>
  187. * ...etc
  188. *
  189. * Without a note tag key set:
  190. * Light 250 #ffffff
  191. * Daynight
  192. * ...etc
  193. *
  194. * Using a note tag key is recommended since it allows for other things
  195. * (plugins, or even you rown personal notes) to make use of the note box
  196. * without breaking things.  Omiting the key is intended primarily as legacy
  197. * support, allowing this plugin to be used with older projects that use Terrax
  198. * Lighting so they don't have to go back and change a bunch of event and map
  199. * notes.
  200. *
  201. * Notation characters:
  202. * []   Values are optional (the brightness parameter in light, etc)
  203. * |    Select the value from the specified list (on|off, etc)
  204. *
  205. * Do not include these in the actual plugin commands.
  206. * --------------------------------------------------------------------------
  207. * List of Note Tags
  208. * --------------------------------------------------------------------------
  209. * Events
  210. * --------------------------------------------------------------------------
  211. * DayNight
  212. * - Activates day/night cycle.  Put in map note or event note
  213. *
  214. * Light radius color [brightness] [direction] [x] [y] [id]
  215. * - Light
  216. * - radius      100, 250, etc
  217. * - color       #ffffff, #ff0000, etc
  218. * - brightness  B50, B25, etc [optional]
  219. * - direction   D1: n.wall, D2: e.wall, D3: s.wall, D4: w.wall
  220. *               D5 n.+e. walls, D6 s.+e. walls, D7 s.+w. walls,
  221. *               D8 n.+w. walls, D9 n.-e. corner, D10 s.-e. corner
  222. *               D11 s.-w. corner, D12 n.-w. corner  [optional]
  223. * - x           x offset [optional] (0.5: half tile, 1 = full tile, etc)
  224. * - y           y offset [optional]
  225. * - id          1, 2, 2345, etc--an id number for plugin commands [optional]
  226. *
  227. * Light radius cycle color dur color dur [color dur]  [x] [y]  [color dur]
  228. * Cycles the specified light colors and durations.  Min 2, max 4
  229. * - radius      Same as standard Light command above
  230. * - color       Color (#ff8800, etc)
  231. * - dur         Duration in ms
  232. *
  233. * Fire ...params
  234. * - Same as Light params above, but adds a subtle flicker
  235. *
  236. * Flashlight [bl] [bw] [c] [onoff]  [x] [y]  [sdir]
  237. * - Sets the light as a flashlight with beam length (bl) beam width (bw) color (c),
  238. *      0|1 (onoff), and 1=up, 2=right, 3=down, 4=left for static direction (sdir)
  239. *
  240. * -------------------------------------------------------------------------------
  241. * Maps
  242. * -------------------------------------------------------------------------------
  243. * DayNight [speed]
  244. * Activates day/night cycle.  Put in map note or event note
  245. * - speed     Optional parameter to alter the speed at which time passes.  10 is
  246.                                  the default speed, higher numbers are slower, lower numbers are
  247.                                  faster, and 0 stops the flow of time entirely.  If speed is not
  248.                                  specified, then the current speed is used.
  249. *
  250. * -------------------------------------------------------------------------------
  251. * Plugin Commands
  252. * -------------------------------------------------------------------------------
  253. * Light deactivate|activate
  254. * - Completely disables the lighting effects of this plugin
  255. *
  256. * Light on id
  257. * - Turn on light with matching id number
  258. *
  259. * Light off id
  260. * - Turn off light with matching id number
  261. *
  262. * Light color id c
  263. * - Change the color (c) of lightsource with id (id)
  264. * - Work even if the associated light is currently off.
  265. * - Will be in effect until conditional lights are resetted
  266. * - If c is set to 'defaultcolor' (without the quotes),
  267. *      it will reset the light back to its initial color.
  268. *
  269. * Light switch reset
  270. * - Reset all conditional lights.
  271. *
  272. * Light radius r c b
  273. * - Change player light radius (r), color (c), and brightness (b)
  274. *
  275. * Light radiusgrow r c b
  276. * - Same as above, but apply changes over time
  277. *
  278. * Setfire r s
  279. * - Alters fire settings with radius shift (r) and red/yellow color shift (s)
  280. *
  281. * Flashlight on bl bw c bd
  282. * - turn on flashlight for player with beam length (bl), beam width (hw), color (c),
  283. *      and beam density (bd)
  284. *
  285. * Flashlight off
  286. * - Turn off the flashlight.  yup.
  287. *
  288. * Daynight speed n
  289. * - Changes the speec by which hours pass ingame in relation to real life seconds
  290. *
  291. * Daynight hour h m
  292. * - Sets the ingame time to hh:mm
  293. *
  294. * Daynight color h c
  295. * - Sets the hour (h) to use color (c)
  296. *
  297. * Daynight add h m
  298. * - Adds the specified hours (h) and minutes (m) to the ingame clock
  299. *
  300. * Daynight debug
  301. * - Shows current ingame time
  302. *
  303. * Daynight hoursinday h
  304. * - Sets the number of hours in a day to [h] (set hour colors  if doing this)
  305. *
  306. * Tint set c
  307. * - Sets the current screen tint to the color (c)
  308. *
  309. * Tint fade c s
  310. * - Same as above, but fades (1 = fast, 20 = very slow)
  311. *
  312. * Tint daylight
  313. * - Set to the daylight corresponding to the current time
  314. *
  315. * TileLight   id ON c r
  316. * RegionLight id ON c r
  317. * - Turns on lights for tile tag or region tag (id) using color (c) and radius (r)
  318. * - Replace ON with OFF to turn them off
  319. *
  320. * TileFire, TileGlow, RegionFire, RegionGlow
  321. * - Same as above, but different lighting effects
  322. *
  323. * TileBlock id ON color
  324. * - Turns on light blocking for tile with tiletag id (id) using color (color)
  325. *
  326. * TileBlock id OFF
  327. * - Turns off light blocking for tile with tiletag id (id)
  328. *
  329. * RegionBlock id ON color
  330. * - Turns on light blocking for tile with region id (id) using color (color)
  331. *
  332. * RegionBlock id OFF
  333. * - Turns off light blocking for tile with region id (id)
  334. *
  335. * RegionBlock id ON color shape xoffset yoffset width height
  336. * - id                        id of region
  337. * - color                color of block (usually #000000)
  338. * - shape                1=square, 2=oval
  339. * - xoffset        x offset
  340. * - yoffset        y offset
  341. * - width                width of shape
  342. * - height                height of shape
  343. *
  344. * effect_on_event id radius color frames
  345. * - id                        event id
  346. * - radius                radius
  347. * - color                color
  348. * - frames                frames to persist
  349. *
  350. * effect_on_xy x y radius color frames
  351. * - x                        x coord
  352. * - y                        y coord
  353. * - radius                radius
  354. * - color                color
  355. * - frames                frames to persist
  356. *
  357. * --------------------------------------------------------------------------
  358. * Kill Switch and conditional lighting
  359. * --------------------------------------------------------------------------
  360. *
  361. * If the 'Kill Switch Auto' parameter has been set to true, any event with
  362. * a (non) active conditional light have their killswitch locked to ON(OFF).
  363. * You can use this difference to give alternate apparences to these events.
  364. * For example, a conditional light event can have a page where it shows a
  365. * burning candle, and second page (active only when the kill switch is ON)
  366. * who shows an unlit candle
  367. *
  368. * -------------------------------------------------------------------------------
  369. * Plugin in battle
  370. * -------------------------------------------------------------------------------
  371. *
  372. * If the plugin is active while a battle begin, the battle screen will
  373. * be tinted like it was on the map. Too dark color will be automatically set
  374. * to '#666666' (dark gray).
  375. *
  376. * If there is no map to take the tint from (ex: battle test),
  377. * the screen will not be tinted.
  378. *
  379. * You can manually tint the battle screen with the following plugin commands.
  380. * Note that these commands affect only the current battle,
  381. * and will have no effect on the map.
  382. *
  383. * -------------------------------------------------------------------------------
  384. * Plugin Commands - Battle
  385. * -------------------------------------------------------------------------------
  386. *
  387. * TintBattle set [color]
  388. * - Tint the battle screen to the color used as argument.
  389. * - Automatically set too dark color to '#666666' (dark gray).
  390. *
  391. * TintBattle reset
  392. * - Reset the battle screen to its original color.
  393. *
  394. * TintBattle fade [color] [speed]
  395. * - Fade the battle screen to the color used as first argument.
  396. * - The second argument is speed of the fade (1 very fast, 20 more slow)
  397. * - Still automatically set too dark color to '#666666' (dark gray).
  398. *
  399. * --------------------------------------------------------------------------
  400. * Lights Active Radius
  401. * --------------------------------------------------------------------------
  402. * This allows you to decide how far away from the player lights are active,
  403. * anything beyond this range will not light up until the player gets
  404. * closer to it.
  405. *
  406. * It can be changed in the plugin parameters, or using the script call...
  407. *
  408. * $gameVariables.SetActiveRadius(#)
  409. *
  410. * ....where # is the max distance you want in tiles.
  411. */
  412.  
  413. (function ($$) {
  414.         let Community_tint_speed = 60;
  415.         let Community_tint_target = '#000000';
  416.         let colorcycle_count = [1000];
  417.         let colorcycle_timer = [1000];
  418.         let event_note = [];
  419.         let event_id = [];
  420.         let event_x = [];
  421.         let event_y = [];
  422.         let event_dir = [];
  423.         let event_moving = [];
  424.         let event_stacknumber = [];
  425.         let event_eventcount = 0;
  426.         let tiletype = 0;
  427.         let tile_lights = [];
  428.         let tile_blocks = [];
  429.  
  430.         let parameters = $$.parameters;
  431.         let lightMaskPadding = +parameters["Lightmask Padding"] || 0;
  432.         let light_event_required = eval(parameters["Light event required"]) || false;
  433.         let player_radius = Number(parameters['Player radius']);
  434.         let reset_each_map = eval(String(parameters['Reset Lights'])) || false;
  435.         let noteTagKey = parameters["Note Tag Key"] !== "" ? parameters["Note Tag Key"] : false;
  436.         let dayNightSaveHours = Number(parameters['Save DaynightHours'] || 0);
  437.         let dayNightSaveMinutes = Number(parameters['Save DaynightMinutes'] || 0);
  438.         let dayNightSaveSeconds = Number(parameters['Save DaynightSeconds'] || 0);
  439.         let dayNightSaveNight = +parameters["Save Night Switch"] || 0;
  440.         let dayNightList = parseDayNightParams(parameters["DayNight Colors"], parameters["Night Hours"]);
  441.         let flashlightoffset = Number(parameters['Flashlight offset'] || 0);
  442.         let killswitch = parameters['Kill Switch'] || 'None';
  443.         if (killswitch !== 'A' && killswitch !== 'B' && killswitch !== 'C' && killswitch !== 'D') {
  444.                 killswitch = 'None'; //Set any invalid value to no switch
  445.         }
  446.         let killSwitchAuto = eval(String(parameters['Kill Switch Auto']));
  447.         let optionText = parameters["Options Menu Entry"] || "";
  448.         let lightInBattle = eval(String(parameters['Battle Tinting']));
  449.         let battleMaskPosition = parameters['Light Mask Position'] || 'Above';
  450.         if (battleMaskPosition !== 'Above' && battleMaskPosition !== 'Between') {
  451.                 battleMaskPosition = 'Above'; //Get rid of any invalid value
  452.         }
  453.  
  454.         let options_lighting_on = true;
  455.         let maxX = Number(parameters['Screensize X'] || 866);
  456.         let maxY = Number(parameters['Screensize Y'] || 630);
  457.         let tint_oldseconds = 0;
  458.         let tint_timer = 0;
  459.         let oldseconds = 0;
  460.         let daynightdebug = false;
  461.         let event_reload_counter = 0;
  462.         let Community_tint_speed_old = 60;
  463.         let Community_tint_target_old = '#000000';
  464.         let tileglow = 0;
  465.         let glow_oldseconds = 0;
  466.         let glow_dir = 1;
  467.         let cyclecolor_counter = 0;
  468.         //let darkcount = 0;
  469.         //let daynightset = false;
  470.         //let averagetime = [];
  471.         //let averagetimecount = 0;
  472.         let notetag_reg = RegExp("<" + noteTagKey + ":[ ]*([^>]+)>", "i");
  473.  
  474.         function getTag() {
  475.                 let result;
  476.                 let note = this.note;
  477.                 if (typeof note === "string") {
  478.                         if (noteTagKey) {
  479.                                 result = note.match(notetag_reg);
  480.                                 result = result ? result[1].trim() : "";
  481.                         }
  482.                         else result = note.trim();
  483.                 }
  484.                 return result;
  485.         };
  486.         function parseDayNightParams(dayNight, nightHours) {
  487.                 let result = [];
  488.                 try {
  489.                         dayNight = JSON.parse(dayNight);
  490.                         nightHours = nightHours.split(",").map(x => x = +x);
  491.                         result = [];
  492.                         for (let i = 0; i < dayNight.length; i++)
  493.                                 result[i] = { "color": dayNight[i], "isNight": nightHours.contains(i) };
  494.                 }
  495.                 catch (e) {
  496.                         console.log("CommunitiyLighting: Night Hours and/or DayNight Colors contain invalid JSON data - cannot parse.");
  497.                         result = new Array(24).fill(undefined).map(x => x = { "color": "#000000", "isNight": false });
  498.                 }
  499.                 return result;
  500.         };
  501.         $$.getDayNightList = function () {
  502.                 return dayNightList;
  503.         };
  504.         function saveTime(hh, mm, ss = null) {
  505.                 let dayNightList = $gameVariables.GetDaynightColorArray();
  506.                 if (dayNightSaveHours > 0) $gameVariables.setValue(dayNightSaveHours, hh);
  507.                 if (dayNightSaveMinutes > 0) $gameVariables.setValue(dayNightSaveMinutes, mm);
  508.                 if (dayNightSaveSeconds > 0 && ss !== null) $gameVariables.setValue(dayNightSaveSeconds, ss);
  509.                 if (dayNightSaveNight > 0 && dayNightList[hh] instanceof Object) $gameSwitches.setValue(dayNightSaveNight, dayNightList[hh].isNight);
  510.         };
  511.  
  512.         let _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  513.         Game_Interpreter.prototype.pluginCommand = function (command, args) {
  514.                 _Game_Interpreter_pluginCommand.call(this, command, args);
  515.                 if (typeof command != 'undefined') {
  516.                         this.communityLighting_Commands(command, args);
  517.                 }
  518.         };
  519.  
  520.         Game_Interpreter.prototype.communityLighting_Commands = function (command, args) {
  521.                 command = command.toLowerCase();
  522.  
  523.                 const allCommands = {
  524.                         tileblock: 'tileType', regionblock: 'tileType', tilelight: 'tileType', regionlight: 'tileType', tilefire: 'tileType', regionfire: 'tileType',
  525.                         tileglow: 'tileType', regionglow: 'tileType', tint: 'tint', daynight: 'dayNight', flashlight: 'flashLight', setfire: 'setFire', fire: 'fire', light: 'light',
  526.                         effect_on_event: 'effectOnEvent', effect_on_xy: 'effectOnXy', script: 'scriptF', reload: 'reload', tintbattle: 'tintbattle'
  527.                 };
  528.                 const result = allCommands[command];
  529.                 if (result) {
  530.                         this[result](command, args);
  531.                 }
  532.         };
  533.  
  534.         Game_Interpreter.prototype.tileType = function (command, args) {
  535.                 const cmdArr = ['', 'tileblock', 'regionblock', 'tilelight', 'regionlight', 'tilefire', 'regionfire', 'tileglow', 'regionglow'];
  536.                 tiletype = cmdArr.indexOf(command);
  537.                 if (tiletype > 0) $$.tile(args);
  538.         };
  539.  
  540.         Game_Interpreter.prototype.tint = function (command, args) {
  541.                 $$.tint(args);
  542.         };
  543.  
  544.         Game_Interpreter.prototype.dayNight = function (command, args) {
  545.                 $$.DayNight(args);
  546.         };
  547.  
  548.         Game_Interpreter.prototype.flashLight = function (command, args) {
  549.                 $$.flashlight(args);
  550.         };
  551.  
  552.         Game_Interpreter.prototype.setFire = function (command, args) {
  553.                 flickerradiusshift = args[0];
  554.                 flickercolorshift = args[1];
  555.                 $gameVariables.SetFireRadius(flickerradiusshift);
  556.                 $gameVariables.SetFireColorshift(flickercolorshift);
  557.         };
  558.  
  559.         Game_Interpreter.prototype.fire = function (command, args) {
  560.                 if (args.contains("radius") || args.contains("radiusgrow")) $gameVariables.SetFire(true);
  561.                 if (args[0] === "deactivate") {
  562.                         $gameVariables.SetScriptActive(false);
  563.                 } else {
  564.                         $gameVariables.SetScriptActive(true);
  565.                 }
  566.                 console.log(args);
  567.                 $$.fireLight(args);
  568.         };
  569.  
  570.         Game_Interpreter.prototype.light = function (command, args) {
  571.                 if (args.contains("radius") || args.contains("radiusgrow")) $gameVariables.SetFire(false);
  572.                 if (args[0] === "deactivate") {
  573.                         $gameVariables.SetScriptActive(false);
  574.                 } else {
  575.                         $gameVariables.SetScriptActive(true);
  576.                 }
  577.                 $$.fireLight(args);
  578.         };
  579.  
  580.         Game_Interpreter.prototype.effectOnEvent = function (command, args) {
  581.                 $$.effectOnEvent(args);
  582.         };
  583.  
  584.         Game_Interpreter.prototype.effectOnXy = function (command, args) {
  585.                 $$.effectXy(args);
  586.         };
  587.  
  588.         Game_Interpreter.prototype.scriptF = function (command, args) {
  589.                 if (args[0] === "deactivate") {
  590.                         $gameVariables.SetScriptActive(true);
  591.                 } else if (args[0] === "activate") {
  592.                         $gameVariables.SetScriptActive(false);
  593.                 }
  594.         };
  595.  
  596.         Game_Interpreter.prototype.reload = function (command, args) {
  597.                 if (args[0] === "events") {
  598.                         $$.ReloadMapEvents();
  599.                 }
  600.         };
  601.  
  602.         Game_Interpreter.prototype.tintbattle = function (command, args) {
  603.                 if ($gameParty.inBattle()) {
  604.  
  605.                         if (args[0].toLowerCase() === 'reset') {
  606.                                 $gameTemp._BattleTint = $gameTemp._MapTint;
  607.                                 $gameTemp._BattleTintSpeed = 0;
  608.                         } else if (args[0] === "set") {
  609.                                 $gameTemp._BattleTint = this.determineBattleTint(args[1]);
  610.                                 $gameTemp._BattleTintSpeed = 0;
  611.  
  612.                         } else if (args[0].toLowerCase() === 'fade') {
  613.  
  614.                                 $gameTemp._BattleTintFade = $gameTemp._BattleTint;
  615.                                 $gameTemp._BattleTintTimer = 0;
  616.                                 $gameTemp._BattleTint = this.determineBattleTint(args[1]);
  617.                                 $gameTemp._BattleTintSpeed = args[2];
  618.                         }
  619.                 }
  620.         };
  621.  
  622.         Game_Interpreter.prototype.determineBattleTint = function (tintColor) {
  623.                 if (!tintColor || tintColor.length < 7) {
  624.                         return '#666666' // Not an hex color strintg
  625.                 }
  626.                 var redhex = tintColor.substring(1, 3);
  627.                 var greenhex = tintColor.substring(3, 5);
  628.                 var bluehex = tintColor.substring(5);
  629.                 var red = parseInt(redhex, 16);
  630.                 var green = parseInt(greenhex, 16);
  631.                 var blue = parseInt(bluehex, 16);
  632.                 var color = red + green + blue;
  633.                 if (color < 300 && red < 100 && green < 100 && blue < 100) { // Check for NaN values or too dark colors
  634.                         return '#666666' // The player have to see something
  635.                 }
  636.                 return tintColor;
  637.         }
  638.  
  639.         Spriteset_Map.prototype.createLightmask = function () {
  640.                 this._lightmask = new Lightmask();
  641.                 this.addChild(this._lightmask);
  642.         };
  643.  
  644.         function Lightmask() {
  645.                 this.initialize.apply(this, arguments);
  646.         }
  647.  
  648.         Lightmask.prototype = Object.create(PIXI.Container.prototype);
  649.         Lightmask.prototype.constructor = Lightmask;
  650.  
  651.         Lightmask.prototype.initialize = function () {
  652.                 PIXI.Container.call(this);
  653.                 this._width = Graphics.width;
  654.                 this._height = Graphics.height;
  655.                 this._sprites = [];
  656.                 this._createBitmap();
  657.         };
  658.  
  659.         //Updates the Lightmask for each frame.
  660.  
  661.         Lightmask.prototype.update = function () {
  662.                 this._updateMask();
  663.         };
  664.  
  665.         //@method _createBitmaps
  666.  
  667.         Lightmask.prototype._createBitmap = function () {
  668.                 this._maskBitmap = new Bitmap(maxX + lightMaskPadding, maxY);   // one big bitmap to fill the intire screen with black
  669.                 let canvas = this._maskBitmap.canvas;             // a bit larger then setting to take care of screenshakes
  670.         };
  671.  
  672.         /**
  673.          * @method _updateAllSprites
  674.          * @private
  675.          */
  676.         Lightmask.prototype._updateMask = function () {
  677.                 // ****** DETECT MAP CHANGES ********
  678.                 let map_id = $gameMap.mapId();
  679.                 if (map_id != $gameVariables.GetOldMapId()) {
  680.                         $gameVariables.SetOldMapId(map_id);
  681.  
  682.                         // recalc tile and region tags.
  683.                         $$.ReloadTagArea();
  684.  
  685.                         //clear color cycle arrays
  686.                         for (let i = 0; i < 1000; i++) {
  687.                                 colorcycle_count[i] = 0;
  688.                                 colorcycle_timer[i] = 0;
  689.                         }
  690.  
  691.                         $$.ReloadMapEvents();  // reload map events on map chance
  692.  
  693.                         if (reset_each_map) {
  694.                                 $gameVariables.SetLightArrayId([]);
  695.                                 $gameVariables.SetLightArrayState([]);
  696.                                 $gameVariables.SetLightArrayColor([]);
  697.                         }
  698.                 }
  699.  
  700.                 // reload mapevents if event_data has chanced (deleted or spawned events/saves)
  701.                 if (event_eventcount != $gameMap.events().length) {
  702.                         $$.ReloadMapEvents();
  703.                 }
  704.  
  705.                 // remove old sprites
  706.                 for (let i = 0, len = this._sprites.length; i < len; i++) {          // remove all old sprites
  707.                         this._removeSprite();
  708.                 }
  709.  
  710.                 if (map_id <= 0) return;                                                                // No lighting on map 0
  711.                 if (options_lighting_on !== true) return;                                // Plugin deactivated in the option
  712.                 if ($gameVariables.GetScriptActive() !== true) return;        // Plugin deactivated by plugin command
  713.  
  714.  
  715.                 event_reload_counter++;  // reload map events every 200 cycles just in case.
  716.                 if (event_reload_counter > 200) {
  717.                         event_reload_counter = 0;
  718.                         $$.ReloadMapEvents()
  719.                 }
  720.  
  721.                 if (light_event_required && event_note.length <= 0) return; // If no lightsources on this map, no lighting if light_event_required set to true.
  722.  
  723.                 this._addSprite(-lightMaskPadding, 0, this._maskBitmap);
  724.  
  725.                 // ******** GROW OR SHRINK GLOBE PLAYER *********
  726.                 let firstrun = $gameVariables.GetFirstRun();
  727.                 if (firstrun === true) {
  728.                         Community_tint_speed = 60;
  729.                         Community_tint_target = '#000000';
  730.                         Community_tint_speed_old = 60;
  731.                         Community_tint_target_old = '#000000';
  732.                         $gameVariables.SetFirstRun(false);
  733.                         player_radius = Number(parameters['Player radius']);
  734.                         $gameVariables.SetRadius(player_radius);
  735.                 } else {
  736.                         player_radius = $gameVariables.GetRadius();
  737.                 }
  738.                 let lightgrow_value = player_radius;
  739.                 let lightgrow_target = $gameVariables.GetRadiusTarget();
  740.                 let lightgrow_speed = $gameVariables.GetRadiusSpeed();
  741.  
  742.                 if (lightgrow_value < lightgrow_target) {
  743.                         lightgrow_value = lightgrow_value + lightgrow_speed;
  744.                         if (lightgrow_value > lightgrow_target) {
  745.                                 //other wise it can keep fliping back and forth between > and <
  746.                                 lightgrow_value = lightgrow_target;
  747.                         }
  748.                         player_radius = lightgrow_value;
  749.                 }
  750.                 if (lightgrow_value > lightgrow_target) {
  751.                         lightgrow_value = lightgrow_value - lightgrow_speed;
  752.                         if (lightgrow_value < lightgrow_target) {
  753.                                 //other wise it can keep fliping back and forth between > and <
  754.                                 lightgrow_value = lightgrow_target;
  755.                         }
  756.                         player_radius = lightgrow_value;
  757.                 }
  758.  
  759.                 $gameVariables.SetRadius(player_radius);
  760.  
  761.                 // ****** PLAYER LIGHTGLOBE ********
  762.  
  763.                 let canvas = this._maskBitmap.canvas;
  764.                 let ctx = canvas.getContext("2d");
  765.                 this._maskBitmap.fillRect(0, 0, maxX + lightMaskPadding, maxY, '#000000');
  766.  
  767.                 ctx.globalCompositeOperation = 'lighter';
  768.                 let pw = $gameMap.tileWidth();
  769.                 let ph = $gameMap.tileHeight();
  770.                 let dx = $gameMap.displayX();
  771.                 let dy = $gameMap.displayY();
  772.                 let px = $gamePlayer._realX;
  773.                 let py = $gamePlayer._realY;
  774.                 let pd = $gamePlayer._direction;
  775.                 let x1 = (pw / 2) + ((px - dx) * pw);
  776.                 let y1 = (ph / 2) + ((py - dy) * ph);
  777.                 let paralax = false;
  778.                 // paralax does something weird with coordinates.. recalc needed
  779.                 if (dx > $gamePlayer.x) {
  780.                         let xjump = $gameMap.width() - Math.floor(dx - px);
  781.                         x1 = (pw / 2) + (xjump * pw);
  782.                 }
  783.                 if (dy > $gamePlayer.y) {
  784.                         let yjump = $gameMap.height() - Math.floor(dy - py);
  785.                         y1 = (ph / 2) + (yjump * ph);
  786.                 }
  787.  
  788.                 let playerflashlight = $gameVariables.GetFlashlight();
  789.                 let playercolor = $gameVariables.GetPlayerColor();
  790.                 let flashlightlength = $gameVariables.GetFlashlightLength();
  791.                 let flashlightwidth = $gameVariables.GetFlashlightWidth();
  792.                 let playerflicker = $gameVariables.GetFire();
  793.                 let playerbrightness = $gameVariables.GetPlayerBrightness();
  794.  
  795.  
  796.                 let iplayer_radius = Math.floor(player_radius);
  797.  
  798.                 if (iplayer_radius > 0) {
  799.                         if (playerflashlight == true) {
  800.                                 this._maskBitmap.radialgradientFillRect2(x1, y1, lightMaskPadding, iplayer_radius, playercolor, '#000000', pd, flashlightlength, flashlightwidth);
  801.                         }
  802.                         y1 = y1 - flashlightoffset;
  803.                         if (iplayer_radius < 100) {
  804.                                 // dim the light a bit at lower lightradius for a less focused effect.
  805.                                 let r = hexToRgb(playercolor).r;
  806.                                 let g = hexToRgb(playercolor).g;
  807.                                 let b = hexToRgb(playercolor).b;
  808.                                 g = g - 50;
  809.                                 r = r - 50;
  810.                                 b = b - 50;
  811.                                 if (g < 0) {
  812.                                         g = 0;
  813.                                 }
  814.                                 if (r < 0) {
  815.                                         r = 0;
  816.                                 }
  817.                                 if (b < 0) {
  818.                                         b = 0;
  819.                                 }
  820.                                 let newcolor = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  821.  
  822.                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, iplayer_radius, newcolor, '#000000', playerflicker, playerbrightness);
  823.                         } else {
  824.                                 this._maskBitmap.radialgradientFillRect(x1, y1, lightMaskPadding, iplayer_radius, playercolor, '#000000', playerflicker, playerbrightness);
  825.                         }
  826.  
  827.                 }
  828.  
  829.  
  830.                 // *********************************** DAY NIGHT CYCLE TIMER **************************
  831.  
  832.                 let daynightspeed = $gameVariables.GetDaynightSpeed();
  833.  
  834.                 if (daynightspeed > 0 && daynightspeed < 5000) {
  835.  
  836.                         let datenow = new Date();
  837.                         let seconds = Math.floor(datenow.getTime() / 10);
  838.                         if (seconds > oldseconds) {
  839.  
  840.                                 let daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  841.                                 let daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  842.                                 let daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24
  843.  
  844.                                 oldseconds = seconds;
  845.                                 daynighttimer = daynighttimer + 1;
  846.                                 let daynightminutes = Math.floor(daynighttimer / daynightspeed);
  847.                                 let daynighttimeover = daynighttimer - (daynightspeed * daynightminutes);
  848.                                 let daynightseconds = Math.floor(daynighttimeover / daynightspeed * 60);
  849.                                 if (daynightdebug == true) {
  850.                                         let daynightseconds2 = daynightseconds;
  851.                                         if (daynightseconds < 10) {
  852.                                                 daynightseconds2 = '0' + daynightseconds;
  853.                                         }
  854.                                         let hourvalue = '-';
  855.                                         let hourset = 'Not set';
  856.                                         if (daynightsavehours > 0) {
  857.                                                 hourvalue = $gameVariables.value(daynightsavehours);
  858.                                                 hourset = daynightsavehours
  859.                                         }
  860.                                         let minutevalue = '-';
  861.                                         let minuteset = 'Not set';
  862.                                         if (daynightsavemin > 0) {
  863.                                                 minutevalue = $gameVariables.value(daynightsavemin);
  864.                                                 minuteset = daynightsavemin
  865.                                         }
  866.                                         let secondvalue = '-';
  867.                                         let secondset = 'Not set';
  868.                                         if (daynightsavesec > 0) {
  869.                                                 secondvalue = $gameVariables.value(daynightsavesec);
  870.                                                 secondset = daynightsavesec
  871.                                         }
  872.  
  873.                                         minutecounter = $gameVariables.value(daynightsavemin);
  874.                                         secondcounter = $gameVariables.value(daynightsavesec);
  875.                                         Graphics.Debug('Debug Daynight system', daynightcycle + ' ' + daynightminutes + ' ' + daynightseconds2 +
  876.                                                 '<br>' + 'Hours  -> Variable: ' + hourset + '  Value: ' + hourvalue +
  877.                                                 '<br>' + 'Minutes-> Variable: ' + minuteset + '  Value: ' + minutevalue +
  878.                                                 '<br>' + 'Seconds-> Variable: ' + secondset + '  Value: ' + secondvalue);
  879.  
  880.                                 }
  881.  
  882.                                 if (daynighttimer >= (daynightspeed * 60)) {
  883.                                         daynightcycle = daynightcycle + 1;
  884.                                         if (daynightcycle >= daynighthoursinday) daynightcycle = 0;
  885.                                         daynighttimer = 0;
  886.                                 }
  887.                                 saveTime(daynightcycle, daynightminutes, daynightseconds);
  888.                                 $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  889.                                 $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours
  890.                         }
  891.                 }
  892.  
  893.                 // ********** OTHER LIGHTSOURCES **************
  894.  
  895.                 for (let i = 0, len = event_note.length; i < len; i++) {
  896.                         let note = event_note[i];
  897.                         let evid = event_id[i];
  898.  
  899.                         let note_args = note.split(" ");
  900.                         let note_command = note_args.shift().toLowerCase();
  901.  
  902.                         let lightsOnRadius = $gameVariables.GetActiveRadius();
  903.                         let distanceApart = Math.round(Community.Lighting.distance($gamePlayer.x, $gamePlayer.y, $gameMap.events()[event_stacknumber[i]]._realX, $gameMap.events()[event_stacknumber[i]]._realY));
  904.                         if (distanceApart <= lightsOnRadius) {
  905.                                 if (note_command == "light" || note_command == "fire" || note_command == "flashlight") {
  906.  
  907.                                         let objectflicker = false;
  908.                                         if (note_command == "fire") {
  909.                                                 objectflicker = true;
  910.                                         }
  911.  
  912.                                         let light_radius = 1;
  913.                                         let flashlength = 8;
  914.                                         let flashwidth = 12;
  915.                                         if (note_command == "flashlight") {
  916.                                                 flashlength = Number(note_args.shift());
  917.                                                 flashwidth = Number(note_args.shift());
  918.                                                 if (flashlength == 0) {
  919.                                                         flashlightlength = 8
  920.                                                 }
  921.                                                 if (flashwidth == 0) {
  922.                                                         flashlightlength = 12
  923.                                                 }
  924.                                         } else {
  925.                                                 light_radius = note_args.shift();
  926.                                         }
  927.                                         // light radius
  928.                                         if (light_radius >= 0) {
  929.  
  930.                                                 // light color
  931.                                                 let colorvalue = note_args.shift();
  932.  
  933.                                                 // Cycle colors
  934.  
  935.  
  936.                                                 if (colorvalue == 'cycle' && evid < 1000) {
  937.  
  938.                                                         let cyclecolor0 = note_args.shift();
  939.                                                         let cyclecount0 = Number(note_args.shift());
  940.                                                         let cyclecolor1 = note_args.shift();
  941.                                                         let cyclecount1 = Number(note_args.shift());
  942.                                                         let cyclecolor2 = '#000000';
  943.                                                         let cyclecount2 = 0;
  944.                                                         let cyclecolor3 = '#000000';
  945.                                                         let cyclecount3 = 0;
  946.  
  947.                                                         let morecycle = note_args.shift();
  948.                                                         if (typeof morecycle != 'undefined') {
  949.                                                                 if (morecycle.substring(0, 1) == "#") {
  950.                                                                         cyclecolor2 = morecycle;
  951.                                                                         cyclecount2 = Number(note_args.shift());
  952.                                                                         morecycle = note_args.shift();
  953.                                                                         if (typeof morecycle != 'undefined') {
  954.                                                                                 if (morecycle.substring(0, 1) == "#") {
  955.                                                                                         cyclecolor3 = morecycle;
  956.                                                                                         cyclecount3 = Number(note_args.shift());
  957.  
  958.                                                                                 } else {
  959.                                                                                         note_args.unshift(morecycle);
  960.                                                                                 }
  961.                                                                         }
  962.                                                                 } else {
  963.                                                                         note_args.unshift(morecycle);
  964.                                                                 }
  965.                                                         }
  966.  
  967.                                                         let switch0 = '0';
  968.                                                         let switch1 = '0';
  969.                                                         let switch2 = '0';
  970.                                                         let switch3 = '0';
  971.  
  972.                                                         let switches = note_args.shift();
  973.                                                         if (typeof switches != 'undefined') {
  974.                                                                 if (switches.length == 7) {
  975.                                                                         if (switches.substring(0, 3) == "SS:") {
  976.                                                                                 switch0 = switches.substring(3, 4);
  977.                                                                                 switch1 = switches.substring(4, 5);
  978.                                                                                 switch2 = switches.substring(5, 6);
  979.                                                                                 switch3 = switches.substring(6, 7);
  980.                                                                         } else {
  981.                                                                                 note_args.unshift(switches);
  982.                                                                         }
  983.                                                                 } else {
  984.                                                                         note_args.unshift(switches);
  985.                                                                 }
  986.                                                         }
  987.  
  988.                                                         // set cycle color
  989.                                                         switch (colorcycle_count[evid]) {
  990.                                                                 case 0:
  991.                                                                         colorvalue = cyclecolor0;
  992.                                                                         break;
  993.                                                                 case 1:
  994.                                                                         colorvalue = cyclecolor1;
  995.                                                                         break;
  996.                                                                 case 2:
  997.                                                                         colorvalue = cyclecolor2;
  998.                                                                         break;
  999.                                                                 case 3:
  1000.                                                                         colorvalue = cyclecolor3;
  1001.                                                                         break;
  1002.                                                                 default:
  1003.                                                                         colorvalue = '#FFFFFF';
  1004.                                                         }
  1005.  
  1006.                                                         // cycle timing
  1007.                                                         //let datenow = new Date();
  1008.                                                         //let seconds = Math.floor(datenow.getTime() / 100);
  1009.                                                         cyclecolor_counter = cyclecolor_counter + 1;
  1010.  
  1011.                                                         if (cyclecolor_counter > 10) {
  1012.                                                                 cyclecolor_counter = 0;
  1013.  
  1014.                                                                 //reset all switches
  1015.                                                                 if (switch0 != '0') {
  1016.                                                                         key = [map_id, evid, switch0];
  1017.                                                                         $gameSelfSwitches.setValue(key, false);
  1018.                                                                 }
  1019.                                                                 if (switch1 != '0') {
  1020.                                                                         key = [map_id, evid, switch1];
  1021.                                                                         $gameSelfSwitches.setValue(key, false);
  1022.                                                                 }
  1023.                                                                 if (switch2 != '0') {
  1024.                                                                         key = [map_id, evid, switch2];
  1025.                                                                         $gameSelfSwitches.setValue(key, false);
  1026.                                                                 }
  1027.                                                                 if (switch3 != '0') {
  1028.                                                                         key = [map_id, evid, switch3];
  1029.                                                                         $gameSelfSwitches.setValue(key, false);
  1030.                                                                 }
  1031.  
  1032.  
  1033.                                                                 if (colorcycle_count[evid] == 0) {
  1034.                                                                         colorcycle_timer[evid]++;
  1035.  
  1036.                                                                         if (colorcycle_timer[evid] > cyclecount0) {
  1037.                                                                                 colorcycle_count[evid] = 1;
  1038.                                                                                 colorcycle_timer[evid] = 0;
  1039.                                                                                 if (switch1 != '0') {
  1040.                                                                                         key = [map_id, evid, switch1];
  1041.                                                                                         $gameSelfSwitches.setValue(key, true);
  1042.                                                                                 }
  1043.                                                                         } else {
  1044.                                                                                 if (switch0 != '0') {
  1045.                                                                                         key = [map_id, evid, switch0];
  1046.                                                                                         $gameSelfSwitches.setValue(key, true);
  1047.                                                                                 }
  1048.                                                                         }
  1049.  
  1050.                                                                 }
  1051.                                                                 if (colorcycle_count[evid] == 1) {
  1052.                                                                         colorcycle_timer[evid]++;
  1053.                                                                         if (colorcycle_timer[evid] > cyclecount1) {
  1054.                                                                                 colorcycle_count[evid] = 2;
  1055.                                                                                 colorcycle_timer[evid] = 0;
  1056.                                                                                 if (switch2 != '0') {
  1057.                                                                                         key = [map_id, evid, switch2];
  1058.                                                                                         $gameSelfSwitches.setValue(key, true);
  1059.                                                                                 }
  1060.                                                                         } else {
  1061.                                                                                 if (switch1 != '0') {
  1062.                                                                                         key = [map_id, evid, switch1];
  1063.                                                                                         $gameSelfSwitches.setValue(key, true);
  1064.                                                                                 }
  1065.                                                                         }
  1066.                                                                 }
  1067.                                                                 if (colorcycle_count[evid] == 2) {
  1068.                                                                         colorcycle_timer[evid]++;
  1069.                                                                         if (colorcycle_timer[evid] > cyclecount2) {
  1070.                                                                                 colorcycle_count[evid] = 3;
  1071.                                                                                 colorcycle_timer[evid] = 0;
  1072.                                                                                 if (switch3 != '0') {
  1073.                                                                                         key = [map_id, evid, switch3];
  1074.                                                                                         $gameSelfSwitches.setValue(key, true);
  1075.                                                                                 }
  1076.                                                                         } else {
  1077.                                                                                 if (switch2 != '0') {
  1078.                                                                                         key = [map_id, evid, switch2];
  1079.                                                                                         $gameSelfSwitches.setValue(key, true);
  1080.                                                                                 }
  1081.                                                                         }
  1082.                                                                 }
  1083.                                                                 if (colorcycle_count[evid] == 3) {
  1084.                                                                         colorcycle_timer[evid]++;
  1085.                                                                         if (colorcycle_timer[evid] > cyclecount3) {
  1086.                                                                                 colorcycle_count[evid] = 0;
  1087.                                                                                 colorcycle_timer[evid] = 0;
  1088.                                                                                 if (switch0 != '0') {
  1089.                                                                                         key = [map_id, evid, switch0];
  1090.                                                                                         $gameSelfSwitches.setValue(key, true);
  1091.                                                                                 }
  1092.                                                                         } else {
  1093.                                                                                 if (switch3 != '0') {
  1094.                                                                                         key = [map_id, evid, switch3];
  1095.                                                                                         $gameSelfSwitches.setValue(key, true);
  1096.                                                                                 }
  1097.                                                                         }
  1098.                                                                 }
  1099.                                                         }
  1100.  
  1101.                                                 } else {
  1102.                                                         let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorvalue);
  1103.                                                         if (!isValidColor) {
  1104.                                                                 colorvalue = '#FFFFFF'
  1105.                                                         }
  1106.                                                 }
  1107.  
  1108.                                                 // brightness and direction
  1109.                                                 let brightness = 0.0;
  1110.                                                 let direction = 0;
  1111.  
  1112.                                                 // offsets
  1113.                                                 let lightXOffset = 0.0;
  1114.                                                 let lightYOffset = 0.0;
  1115.  
  1116.                                                 let next_arg = note_args.shift();
  1117.  
  1118.                                                 if (typeof next_arg != 'undefined') {
  1119.                                                         let key = next_arg.substring(0, 1);
  1120.                                                         if (key == 'b' || key == 'B') {
  1121.                                                                 brightness = Number(next_arg.substring(1)) / 100;
  1122.                                                                 next_arg = note_args.shift();
  1123.                                                                 if (typeof next_arg != 'undefined') {
  1124.                                                                         key = next_arg.substring(0, 1);
  1125.                                                                 }
  1126.                                                         }
  1127.                                                         if (key == 'd' || key == 'D') {
  1128.                                                                 direction = next_arg.substring(1);
  1129.                                                                 next_arg = note_args.shift();
  1130.                                                                 if (typeof next_arg != 'undefined') {
  1131.                                                                         key = next_arg.substring(0, 1);
  1132.                                                                 }
  1133.                                                         }
  1134.                                                         if (key == 'x' || key == 'X') {
  1135.                                                                 lightXOffset = +next_arg.substring(1) * $gameMap.tileWidth();
  1136.                                                                 next_arg = note_args.shift();
  1137.                                                                 if (typeof next_arg != 'undefined') {
  1138.                                                                         key = next_arg.substring(0, 1);
  1139.                                                                 }
  1140.                                                         }
  1141.                                                         if (key == 'y' || key == 'Y') {
  1142.                                                                 lightYOffset = +next_arg.substring(1) * $gameMap.tileHeight();
  1143.                                                                 console.log("y offset confirmed: " + lightYOffset);
  1144.                                                                 next_arg = note_args.shift();
  1145.                                                         }
  1146.                                                 }
  1147.  
  1148.  
  1149.                                                 // conditional lighting
  1150.                                                 let lightid = 0;
  1151.                                                 if (typeof next_arg != 'undefined') {
  1152.                                                         lightid = next_arg;
  1153.                                                 }
  1154.  
  1155.                                                 let state = true;
  1156.                                                 if (lightid > 0) {
  1157.                                                         state = false;
  1158.  
  1159.                                                         let lightarray_id = $gameVariables.GetLightArrayId();
  1160.                                                         let lightarray_state = $gameVariables.GetLightArrayState();
  1161.                                                         let lightarray_color = $gameVariables.GetLightArrayColor();
  1162.  
  1163.                                                         for (let j = 0, jlen = lightarray_id.length; j < jlen; j++) {
  1164.                                                                 if (lightarray_id[j] == lightid) {
  1165.                                                                         // idfound = true;
  1166.                                                                         state = lightarray_state[j];
  1167.  
  1168.                                                                         let newcolor = lightarray_color[j];
  1169.  
  1170.                                                                         if (newcolor != 'defaultcolor') {
  1171.                                                                                 colorvalue = newcolor;
  1172.                                                                         }
  1173.                                                                 }
  1174.                                                         }
  1175.  
  1176.                                                         // Set kill switch to ON if the conditional light is deactivated,
  1177.                                                         // or to OFF if it is active.
  1178.                                                         if (killSwitchAuto && killswitch !== 'None') {
  1179.                                                                 key = [map_id, evid, killswitch];
  1180.                                                                 if ($gameSelfSwitches.value(key) === state) {
  1181.                                                                         $gameSelfSwitches.setValue(key, !state);
  1182.                                                                 }
  1183.                                                         }
  1184.                                                 }
  1185.  
  1186.  
  1187.                                                 // kill switch
  1188.                                                 if (killswitch !== 'None' && state) {
  1189.                                                         key = [map_id, evid, killswitch];
  1190.                                                         if ($gameSelfSwitches.value(key) === true) {
  1191.                                                                 state = false;
  1192.                                                         }
  1193.                                                 }
  1194.  
  1195.  
  1196.                                                 // show light
  1197.                                                 if (state == true) {
  1198.                                                         let ldir = 0;
  1199.                                                         if (event_moving[i] > 0) {
  1200.                                                                 ldir = $gameMap.events()[event_stacknumber[i]]._direction;
  1201.  
  1202.                                                         } else {
  1203.                                                                 ldir = event_dir[i];
  1204.                                                         }
  1205.  
  1206.                                                         // moving lightsources
  1207.                                                         let flashlight = false;
  1208.                                                         if (note_command == "flashlight") {
  1209.                                                                 flashlight = true;
  1210.  
  1211.                                                                 let walking = event_moving[i];
  1212.                                                                 if (walking == false) {
  1213.                                                                         let tldir = Number(note_args.shift());
  1214.                                                                         if (!isNaN(tldir)) {
  1215.                                                                                 if (tldir < 0 || ldir >= 5) {
  1216.                                                                                         ldir = 4
  1217.                                                                                 }
  1218.                                                                                 if (tldir == 1) {
  1219.                                                                                         ldir = 8
  1220.                                                                                 }
  1221.                                                                                 if (tldir == 2) {
  1222.                                                                                         ldir = 6
  1223.                                                                                 }
  1224.                                                                                 if (tldir == 3) {
  1225.                                                                                         ldir = 2
  1226.                                                                                 }
  1227.                                                                                 if (tldir == 4) {
  1228.                                                                                         ldir = 4
  1229.                                                                                 }
  1230.                                                                         }
  1231.                                                                 }
  1232.  
  1233.  
  1234.                                                         }
  1235.                                                         let lx1 = $gameMap.events()[event_stacknumber[i]].screenX();
  1236.                                                         let ly1 = $gameMap.events()[event_stacknumber[i]].screenY() - 24;
  1237.  
  1238.                                                         lx1 += +lightXOffset;
  1239.                                                         ly1 += +lightYOffset;
  1240.  
  1241.                                                         if (flashlight == true) {
  1242.                                                                 this._maskBitmap.radialgradientFillRect2(lx1, ly1, 0, light_radius, colorvalue, '#000000', ldir, flashlength, flashwidth);
  1243.                                                         } else {
  1244.                                                                 this._maskBitmap.radialgradientFillRect(lx1, ly1, 0, light_radius, colorvalue, '#000000', objectflicker, brightness, direction);
  1245.                                                         }
  1246.  
  1247.  
  1248.                                                 }
  1249.  
  1250.  
  1251.  
  1252.                                         }
  1253.                                 }
  1254.                         }
  1255.                 }
  1256.  
  1257.  
  1258.  
  1259.                 // *************************** TILE TAG *********************
  1260.                 //glow/colorfade
  1261.                 let glowdatenow = new Date();
  1262.                 let glowseconds = Math.floor(glowdatenow.getTime() / 100);
  1263.  
  1264.                 if (glowseconds > glow_oldseconds) {
  1265.                         glow_oldseconds = glowseconds;
  1266.                         tileglow = tileglow + glow_dir;
  1267.  
  1268.                         if (tileglow > 120) {
  1269.                                 glow_dir = -1;
  1270.                         }
  1271.                         if (tileglow < 1) {
  1272.                                 glow_dir = 1;
  1273.                         }
  1274.                 }
  1275.  
  1276.                 tile_lights = $gameVariables.GetLightTags();
  1277.                 tile_blocks = $gameVariables.GetBlockTags();
  1278.  
  1279.                 for (let i = 0, len = tile_lights.length; i < len; i++) {
  1280.                         let tilestr = tile_lights[i];
  1281.  
  1282.                         let tileargs = tilestr.split(";");
  1283.                         let x = tileargs[0];
  1284.                         let y = tileargs[1];
  1285.                         let tile_type = tileargs[2];
  1286.                         let tile_radius = tileargs[3];
  1287.                         let tile_color = tileargs[4];
  1288.                         let brightness = tileargs[5];
  1289.  
  1290.                         let x1 = (pw / 2) + (x - dx) * pw;
  1291.                         let y1 = (ph / 2) + (y - dy) * ph;
  1292.  
  1293.                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  1294.                                 if (dx - 5 > x) {
  1295.                                         let lxjump = $gameMap.width() - (dx - x);
  1296.                                         x1 = (pw / 2) + (lxjump * pw);
  1297.                                 }
  1298.                         }
  1299.                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  1300.                                 if (dy - 5 > y) {
  1301.                                         let lyjump = $gameMap.height() - (dy - y);
  1302.                                         y1 = (ph / 2) + (lyjump * ph);
  1303.                                 }
  1304.                         }
  1305.  
  1306.                         if (tile_type == 3 || tile_type == 4) {
  1307.                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, tile_color, '#000000', false, brightness); // Light
  1308.                         } else if (tile_type == 5 || tile_type == 6) {
  1309.                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, tile_color, '#000000', true, brightness);  // Fire
  1310.                         } else {
  1311.  
  1312.                                 let r = hexToRgb(tile_color).r;
  1313.                                 let g = hexToRgb(tile_color).g;
  1314.                                 let b = hexToRgb(tile_color).b;
  1315.  
  1316.  
  1317.                                 r = Math.floor(r + (60 - tileglow));
  1318.                                 g = Math.floor(g + (60 - tileglow));
  1319.                                 b = Math.floor(b + (60 - tileglow));
  1320.  
  1321.                                 if (r < 0) {
  1322.                                         r = 0;
  1323.                                 }
  1324.                                 if (g < 0) {
  1325.                                         g = 0;
  1326.                                 }
  1327.                                 if (b < 0) {
  1328.                                         b = 0;
  1329.                                 }
  1330.                                 if (r > 255) {
  1331.                                         r = 255;
  1332.                                 }
  1333.                                 if (g > 255) {
  1334.                                         g = 255;
  1335.                                 }
  1336.                                 if (b > 255) {
  1337.                                         b = 255;
  1338.                                 }
  1339.  
  1340.                                 let newtile_color = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  1341.                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, newtile_color, '#000000', false, brightness);
  1342.                         }
  1343.  
  1344.  
  1345.                 }
  1346.  
  1347.  
  1348.  
  1349.                 ctx.globalCompositeOperation = "multiply";
  1350.                 for (let i = 0, len = tile_blocks.length; i < len; i++) {
  1351.                         let tilestr = tile_blocks[i];
  1352.                         let tileargs = tilestr.split(";");
  1353.  
  1354.                         let x = tileargs[0];
  1355.                         let y = tileargs[1];
  1356.                         let shape = tileargs[2];
  1357.                         let xo1 = tileargs[3];
  1358.                         let yo1 = tileargs[4];
  1359.                         let xo2 = tileargs[5];
  1360.                         let yo2 = tileargs[6];
  1361.                         let tile_color = tileargs[7];
  1362.  
  1363.  
  1364.                         let x1 = (x - dx) * pw;
  1365.                         let y1 = (y - dy) * ph;
  1366.  
  1367.                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  1368.                                 if (dx - 5 > x) {
  1369.                                         let lxjump = $gameMap.width() - (dx - x);
  1370.                                         x1 = (lxjump * pw);
  1371.                                 }
  1372.                         }
  1373.                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  1374.                                 if (dy - 5 > y) {
  1375.                                         let lyjump = $gameMap.height() - (dy - y);
  1376.                                         y1 = (lyjump * ph);
  1377.                                 }
  1378.                         }
  1379.                         if (shape == 0) {
  1380.                                 this._maskBitmap.FillRect(x1, y1, pw, ph, tile_color);
  1381.                         }
  1382.                         if (shape == 1) {
  1383.                                 x1 = x1 + Number(xo1);
  1384.                                 y1 = y1 + Number(yo1);
  1385.                                 this._maskBitmap.FillRect(x1, y1, Number(xo2), Number(yo2), tile_color);
  1386.                         }
  1387.                         if (shape == 2) {
  1388.                                 x1 = x1 + Number(xo1);
  1389.                                 y1 = y1 + Number(yo1);
  1390.                                 this._maskBitmap.FillCircle(x1, y1, Number(xo2), Number(yo2), tile_color);
  1391.                         }
  1392.                 }
  1393.                 ctx.globalCompositeOperation = 'lighter';
  1394.  
  1395.  
  1396.                 // *********************************** DAY NIGHT CYCLE FILTER **************************
  1397.                 if ($$.daynightset) {
  1398.  
  1399.                         let daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  1400.                         let daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  1401.                         let daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24
  1402.                         let daynightcolors = $gameVariables.GetDaynightColorArray();
  1403.                         let r, g, b;
  1404.                         let color1 = daynightcolors[daynightcycle].color;
  1405.  
  1406.                         if (daynightspeed > 0) {
  1407.                                 let nextcolor = daynightcycle + 1;
  1408.                                 if (nextcolor >= daynighthoursinday) {
  1409.                                         nextcolor = 0;
  1410.                                 }
  1411.                                 let color2 = daynightcolors[nextcolor].color;
  1412.                                 let rgb = hexToRgb(color1);
  1413.                                 r = rgb.r;
  1414.                                 g = rgb.g;
  1415.                                 b = rgb.b;
  1416.  
  1417.                                 rgb = hexToRgb(color2);
  1418.                                 let r2 = rgb.r;
  1419.                                 let g2 = rgb.g;
  1420.                                 let b2 = rgb.b;
  1421.  
  1422.                                 let stepR = (r2 - r) / (60 * daynightspeed);
  1423.                                 let stepG = (g2 - g) / (60 * daynightspeed);
  1424.                                 let stepB = (b2 - b) / (60 * daynightspeed);
  1425.  
  1426.                                 r = Math.floor(r + (stepR * daynighttimer));
  1427.                                 g = Math.floor(g + (stepG * daynighttimer));
  1428.                                 b = Math.floor(b + (stepB * daynighttimer));
  1429.                         }
  1430.                         color1 = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  1431.  
  1432.                         this._maskBitmap.FillRect(-lightMaskPadding, 0, maxX + lightMaskPadding, maxY, color1);
  1433.                 }
  1434.                 // *********************************** TINT **************************
  1435.                 else {
  1436.                         let tint_value = $gameVariables.GetTint();
  1437.                         let tint_target = $gameVariables.GetTintTarget();
  1438.                         let tint_speed = $gameVariables.GetTintSpeed();
  1439.  
  1440.  
  1441.                         if (Community_tint_target != Community_tint_target_old) {
  1442.                                 Community_tint_target_old = Community_tint_target;
  1443.                                 tint_target = Community_tint_target;
  1444.                                 $gameVariables.SetTintTarget(tint_target);
  1445.                         }
  1446.                         if (Community_tint_speed != Community_tint_speed_old) {
  1447.                                 Community_tint_speed_old = Community_tint_speed;
  1448.                                 tint_speed = Community_tint_speed;
  1449.                                 $gameVariables.SetTintSpeed(tint_speed);
  1450.                         }
  1451.                         let tcolor = tint_value;
  1452.                         if (tint_value != tint_target) {
  1453.  
  1454.                                 let tintdatenow = new Date();
  1455.                                 let tintseconds = Math.floor(tintdatenow.getTime() / 10);
  1456.                                 if (tintseconds > tint_oldseconds) {
  1457.                                         tint_oldseconds = tintseconds;
  1458.                                         tint_timer++;
  1459.                                 }
  1460.  
  1461.                                 let r = hexToRgb(tint_value).r;
  1462.                                 let g = hexToRgb(tint_value).g;
  1463.                                 let b = hexToRgb(tint_value).b;
  1464.  
  1465.                                 let r2 = hexToRgb(tint_target).r;
  1466.                                 let g2 = hexToRgb(tint_target).g;
  1467.                                 let b2 = hexToRgb(tint_target).b;
  1468.  
  1469.                                 let stepR = (r2 - r) / (60 * tint_speed);
  1470.                                 let stepG = (g2 - g) / (60 * tint_speed);
  1471.                                 let stepB = (b2 - b) / (60 * tint_speed);
  1472.  
  1473.                                 let r3 = Math.floor(r + (stepR * tint_timer));
  1474.                                 let g3 = Math.floor(g + (stepG * tint_timer));
  1475.                                 let b3 = Math.floor(b + (stepB * tint_timer));
  1476.                                 if (r3 < 0) {
  1477.                                         r3 = 0
  1478.                                 }
  1479.                                 if (g3 < 0) {
  1480.                                         g3 = 0
  1481.                                 }
  1482.                                 if (b3 < 0) {
  1483.                                         b3 = 0
  1484.                                 }
  1485.                                 if (r3 > 255) {
  1486.                                         r3 = 255
  1487.                                 }
  1488.                                 if (g3 > 255) {
  1489.                                         g3 = 255
  1490.                                 }
  1491.                                 if (b3 > 255) {
  1492.                                         b3 = 255
  1493.                                 }
  1494.                                 let reddone = false;
  1495.                                 let greendone = false;
  1496.                                 let bluedone = false;
  1497.                                 if (stepR >= 0 && r3 >= r2) {
  1498.                                         reddone = true;
  1499.                                 }
  1500.                                 if (stepR <= 0 && r3 <= r2) {
  1501.                                         reddone = true;
  1502.                                 }
  1503.                                 if (stepG >= 0 && g3 >= g2) {
  1504.                                         greendone = true;
  1505.                                 }
  1506.                                 if (stepG <= 0 && g3 <= g2) {
  1507.                                         greendone = true;
  1508.                                 }
  1509.                                 if (stepB >= 0 && b3 >= b2) {
  1510.                                         bluedone = true;
  1511.                                 }
  1512.                                 if (stepB <= 0 && b3 <= b2) {
  1513.                                         bluedone = true;
  1514.                                 }
  1515.                                 if (reddone == true && bluedone == true && greendone == true) {
  1516.                                         $gameVariables.SetTint(tint_target);
  1517.                                 }
  1518.                                 tcolor = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  1519.                         } else {
  1520.                                 tint_timer = 0;
  1521.                         }
  1522.                         this._maskBitmap.FillRect(-lightMaskPadding, 0, maxX + lightMaskPadding, maxY, tcolor);
  1523.                 }
  1524.  
  1525.                 // reset drawmode to normal
  1526.                 ctx.globalCompositeOperation = 'source-over';
  1527.         };
  1528.  
  1529.         /**
  1530.          * @method _addSprite
  1531.          * @private
  1532.          */
  1533.         Lightmask.prototype._addSprite = function (x1, y1, selectedbitmap) {
  1534.  
  1535.                 let sprite = new Sprite(this.viewport);
  1536.                 sprite.bitmap = selectedbitmap;
  1537.                 sprite.opacity = 255;
  1538.                 sprite.blendMode = 2;
  1539.                 sprite.x = x1;
  1540.                 sprite.y = y1;
  1541.                 this._sprites.push(sprite);
  1542.                 this.addChild(sprite);
  1543.                 sprite.rotation = 0;
  1544.                 sprite.ax = 0;
  1545.                 sprite.ay = 0;
  1546.                 sprite.opacity = 255;
  1547.         };
  1548.  
  1549.         /**
  1550.          * @method _removeSprite
  1551.          * @private
  1552.          */
  1553.         Lightmask.prototype._removeSprite = function () {
  1554.                 this.removeChild(this._sprites.pop());
  1555.         };
  1556.  
  1557.  
  1558.         // *******************  NORMAL BOX SHAPE ***********************************
  1559.  
  1560.         Bitmap.prototype.FillRect = function (x1, y1, x2, y2, color1) {
  1561.                 x1 = x1 + lightMaskPadding;
  1562.                 //x2=x2+lightMaskPadding;
  1563.                 let context = this._context;
  1564.                 context.save();
  1565.                 context.fillStyle = color1;
  1566.                 context.fillRect(x1, y1, x2, y2);
  1567.                 context.restore();
  1568.                 this._setDirty();
  1569.         };
  1570.  
  1571.         // *******************  CIRCLE/OVAL SHAPE ***********************************
  1572.         // from [url]http://scienceprimer.com/draw-oval-html5-canvas[/url]
  1573.         Bitmap.prototype.FillCircle = function (centerX, centerY, xradius, yradius, color1) {
  1574.                 centerX = centerX + lightMaskPadding;
  1575.  
  1576.                 let context = this._context;
  1577.                 context.save();
  1578.                 context.fillStyle = color1;
  1579.                 context.beginPath();
  1580.                 let rotation = 0;
  1581.                 let start_angle = 0;
  1582.                 let end_angle = 2 * Math.PI;
  1583.                 for (let i = start_angle * Math.PI; i < end_angle * Math.PI; i += 0.01) {
  1584.                         xPos = centerX - (yradius * Math.sin(i)) * Math.sin(rotation * Math.PI) + (xradius * Math.cos(i)) * Math.cos(rotation * Math.PI);
  1585.                         yPos = centerY + (xradius * Math.cos(i)) * Math.sin(rotation * Math.PI) + (yradius * Math.sin(i)) * Math.cos(rotation * Math.PI);
  1586.  
  1587.                         if (i == 0) {
  1588.                                 context.moveTo(xPos, yPos);
  1589.                         } else {
  1590.                                 context.lineTo(xPos, yPos);
  1591.                         }
  1592.                 }
  1593.                 context.fill();
  1594.                 context.closePath();
  1595.                 context.restore();
  1596.                 this._setDirty();
  1597.         };
  1598.  
  1599.         // *******************  NORMAL LIGHT SHAPE ***********************************
  1600.         // Fill gradient circle
  1601.  
  1602.         Bitmap.prototype.radialgradientFillRect = function (x1, y1, r1, r2, color1, color2, flicker, brightness, direction) {
  1603.  
  1604.                 let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
  1605.                 if (!isValidColor) {
  1606.                         color1 = '#000000'
  1607.                 }
  1608.                 let isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
  1609.                 if (!isValidColor2) {
  1610.                         color2 = '#000000'
  1611.                 }
  1612.  
  1613.                 x1 = x1 + lightMaskPadding;
  1614.                 //y1 += 5; // What the fuck?  Seriously?
  1615.  
  1616.                 // clipping
  1617.                 let nx1 = Number(x1);
  1618.                 let ny1 = Number(y1);
  1619.                 let nr2 = Number(r2);
  1620.  
  1621.                 let clip = false;
  1622.  
  1623.                 if (nx1 - nr2 > maxX) {
  1624.                         clip = true;
  1625.                 }
  1626.                 if (ny1 - nr2 > maxY) {
  1627.                         clip = true;
  1628.                 }
  1629.                 if (nx1 + nr2 < 0) {
  1630.                         clip = true;
  1631.                 }
  1632.                 if (nx1 + nr2 < 0) {
  1633.                         clip = true;
  1634.                 }
  1635.  
  1636.                 if (clip == false) {
  1637.  
  1638.                         if (!brightness) {
  1639.                                 brightness = 0.0;
  1640.                         }
  1641.                         if (!direction) {
  1642.                                 direction = 0;
  1643.                         }
  1644.                         let context = this._context;
  1645.                         let grad;
  1646.                         let wait = Math.floor((Math.random() * 8) + 1);
  1647.                         if (flicker == true && wait == 1) {
  1648.                                 let flickerradiusshift = $gameVariables.GetFireRadius();
  1649.                                 let flickercolorshift = $gameVariables.GetFireColorshift();
  1650.                                 let gradrnd = Math.floor((Math.random() * flickerradiusshift) + 1);
  1651.                                 let colorrnd = Math.floor((Math.random() * flickercolorshift) - (flickercolorshift / 2));
  1652.  
  1653.                                 let r = hexToRgb(color1).r;
  1654.                                 let g = hexToRgb(color1).g;
  1655.                                 let b = hexToRgb(color1).b;
  1656.                                 g = g + colorrnd;
  1657.                                 if (g < 0) {
  1658.                                         g = 0;
  1659.                                 }
  1660.                                 if (g > 255) {
  1661.                                         g = 255;
  1662.                                 }
  1663.                                 color1 = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  1664.                                 r2 = r2 - gradrnd;
  1665.                                 if (r2 < 0) r2 = 0;
  1666.                         }
  1667.  
  1668.                         grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  1669.                         if (brightness) {
  1670.                                 grad.addColorStop(0, '#FFFFFF');
  1671.                         }
  1672.                         grad.addColorStop(brightness, color1);
  1673.  
  1674.                         grad.addColorStop(1, color2);
  1675.  
  1676.                         context.save();
  1677.                         context.fillStyle = grad;
  1678.                         direction = Number(direction);
  1679.                         let pw = $gameMap.tileWidth() / 2;
  1680.                         let ph = $gameMap.tileHeight() / 2;
  1681.                         let hackishFix = 0; // I'm not proud of having to do this...
  1682.                         switch (direction) {
  1683.                                 case 0:
  1684.                                         context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  1685.                                         break;
  1686.                                 case 1:
  1687.                                         context.fillRect(x1 - r2, y1 - ph, r2 * 2, r2 * 2);
  1688.                                         break;
  1689.                                 case 2:
  1690.                                         context.fillRect(x1 - r2, y1 - r2, r2 * 1 + pw, r2 * 2);
  1691.                                         break;
  1692.                                 case 3:
  1693.                                         context.fillRect(x1 - r2, y1 - r2 + hackishFix, r2 * 2, r2 * 1 + ph);
  1694.                                         break;
  1695.                                 case 4:
  1696.                                         context.fillRect(x1 - pw, y1 - r2, r2 * 2, r2 * 2);
  1697.                                         break;
  1698.                                 case 5:
  1699.                                         context.fillRect(x1 - r2, y1 - ph, r2 * 1 + pw, r2 * 1 + ph);
  1700.                                         break;
  1701.                                 case 6:
  1702.                                         context.fillRect(x1 - r2, y1 - r2 + hackishFix, r2 * 1 + pw, r2 * 1 + ph);
  1703.                                         break;
  1704.                                 case 7:
  1705.                                         context.fillRect(x1 - pw, y1 - r2 + hackishFix, r2 * 1 + pw, r2 * 1 + ph);
  1706.                                         break;
  1707.                                 case 8:
  1708.                                         context.fillRect(x1 - pw, y1 - ph, r2 * 1 + pw, r2 * 1 + ph);
  1709.                                         break;
  1710.                                 case 9:
  1711.                                         context.fillRect(x1 - r2, y1 - ph + hackishFix, r2 * 2, r2 * 2);
  1712.                                         context.fillRect(x1 - r2, y1 - r2 + hackishFix, r2 * 1 - pw, r2 * 1 - ph);
  1713.                                         break;
  1714.                                 case 10:
  1715.                                         context.fillRect(x1 - r2, y1 - r2 + hackishFix, r2 * 2, r2 * 1 + ph);
  1716.                                         context.fillRect(x1 - r2, y1 + pw + hackishFix, r2 * 1 - pw, r2 * 1 - ph);
  1717.                                         break;
  1718.                                 case 11:
  1719.                                         context.fillRect(x1 - r2, y1 - r2 + hackishFix, r2 * 2, r2 * 1 + ph);
  1720.                                         context.fillRect(x1 + pw, y1 + pw + hackishFix, r2 * 1 - pw, r2 * 1 - ph);
  1721.                                         break;
  1722.                                 case 12:
  1723.                                         context.fillRect(x1 - r2, y1 - ph + hackishFix, r2 * 2, r2 * 2);
  1724.                                         context.fillRect(x1 + pw, y1 - r2 + hackishFix, r2 * 1 - pw, r2 * 1 - ph);
  1725.                                         break;
  1726.                         }
  1727.                         context.restore();
  1728.                         this._setDirty();
  1729.                 }
  1730.         };
  1731.  
  1732.  
  1733.         // ********************************** FLASHLIGHT *************************************
  1734.         // Fill gradient Cone
  1735.  
  1736.         Bitmap.prototype.radialgradientFillRect2 = function (x1, y1, r1, r2, color1, color2, direction, flashlength, flashwidth) {
  1737.                 x1 = x1 + lightMaskPadding;
  1738.  
  1739.                 let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
  1740.                 if (!isValidColor) {
  1741.                         color1 = '#000000'
  1742.                 }
  1743.                 let isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
  1744.                 if (!isValidColor2) {
  1745.                         color2 = '#000000'
  1746.                 }
  1747.  
  1748.                 let context = this._context;
  1749.                 let grad;
  1750.  
  1751.                 // smal dim glove around player
  1752.                 context.save();
  1753.                 y1 = y1 - flashlightoffset;
  1754.  
  1755.                 r1 = 1;
  1756.                 r2 = 40;
  1757.                 grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  1758.                 grad.addColorStop(0, '#999999');
  1759.                 grad.addColorStop(1, color2);
  1760.  
  1761.                 context.fillStyle = grad;
  1762.                 context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  1763.  
  1764.                 // flashlight
  1765.  
  1766.                 for (let cone = 0; cone < flashlength; cone++) {
  1767.                         let flashlightdensity = $gameVariables.GetFlashlightDensity();
  1768.                         r1 = cone * flashlightdensity;
  1769.                         r2 = cone * flashwidth;
  1770.  
  1771.                         switch (direction) {
  1772.                                 case 6:
  1773.                                         x1 = x1 + cone * 6;
  1774.                                         break;
  1775.                                 case 4:
  1776.                                         x1 = x1 - cone * 6;
  1777.                                         break;
  1778.                                 case 2:
  1779.                                         y1 = y1 + cone * 6;
  1780.                                         break;
  1781.                                 case 8:
  1782.                                         y1 = y1 - cone * 6;
  1783.                                         break;
  1784.                         }
  1785.  
  1786.  
  1787.                         grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  1788.                         grad.addColorStop(0, color1);
  1789.                         grad.addColorStop(1, color2);
  1790.  
  1791.                         context.fillStyle = grad;
  1792.                         context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  1793.                 }
  1794.                 context.fillStyle = grad;
  1795.                 context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  1796.  
  1797.                 context.restore();
  1798.                 this._setDirty();
  1799.         };
  1800.  
  1801.  
  1802.         function hexToRgb(hex) {
  1803.                 let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  1804.                 result = result ? {
  1805.                         r: parseInt(result[1], 16),
  1806.                         g: parseInt(result[2], 16),
  1807.                         b: parseInt(result[3], 16)
  1808.                 } : null;
  1809.                 return result;
  1810.         }
  1811.  
  1812.         // ALIASED Begin battle: prepare battle lighting
  1813.  
  1814.         let Community_Lighting_BattleManager_setup = BattleManager.setup;
  1815.         BattleManager.setup = function (troopId, canEscape, canLose) {
  1816.                 $gameTemp._MapTint = '#FFFFFF';                                                                                                                                // By default, no darkness during battle
  1817.                 if (!DataManager.isBattleTest() && !DataManager.isEventTest() && $gameMap.mapId() >= 0) {        // If we went there from a map...
  1818.                         if ($gameVariables.GetScriptActive() === true) {                                                                                // If the script is active...
  1819.                                 if (options_lighting_on && lightInBattle) {                                                                                        // If configuration autorise using lighting effects
  1820.                                         if (event_note.length > 0) {                                                                                                        // If there is lightsource on this map...
  1821.                                                 $gameTemp._MapTint = $gameVariables.GetTint();                                                                // ... Use the tint of the map.
  1822.                                         }
  1823.                                 }
  1824.                                 // Add daylight tint?
  1825.                         }
  1826.                 }
  1827.                 Community_Lighting_BattleManager_setup.call(this, troopId, canEscape, canLose);
  1828.         };
  1829.  
  1830.         // ALIASED Scene_Battle initialisation: create the light mask.
  1831.  
  1832.         let Community_Lighting_Spriteset_Battle_createLowerLayer = Spriteset_Battle.prototype.createLowerLayer;
  1833.         Spriteset_Battle.prototype.createLowerLayer = function () {
  1834.                 Community_Lighting_Spriteset_Battle_createLowerLayer.call(this);
  1835.                 if (battleMaskPosition === 'Above') {
  1836.                         this.createBattleLightmask();
  1837.                 }
  1838.         };
  1839.  
  1840.         let Community_Lighting_Spriteset_Battle_createBattleback = Spriteset_Battle.prototype.createBattleback;
  1841.         Spriteset_Battle.prototype.createBattleback = function () {
  1842.                 Community_Lighting_Spriteset_Battle_createBattleback.call(this);
  1843.                 if (battleMaskPosition === 'Between') {
  1844.                         this.createBattleLightmask();
  1845.                 }
  1846.         };
  1847.  
  1848.         Spriteset_Battle.prototype.createBattleLightmask = function () {
  1849.                 if ($gameVariables.GetScriptActive()) {                                        // If the script is active
  1850.                         if (lightInBattle) {                                                                // If is active during battles.
  1851.                                 this._battleLightmask = new BattleLightmask();        // ... Create the light mask.
  1852.                                 if (battleMaskPosition === 'Above') {
  1853.                                         this.addChild(this._battleLightmask);
  1854.                                 } else if (battleMaskPosition === 'Between') {
  1855.                                         this._back2Sprite.addChild(this._battleLightmask);
  1856.                                 }
  1857.                         }
  1858.                 }
  1859.         };
  1860.  
  1861.         function BattleLightmask() {
  1862.                 this.initialize.apply(this, arguments);
  1863.         };
  1864.  
  1865.         BattleLightmask.prototype = Object.create(PIXI.Container.prototype);
  1866.         BattleLightmask.prototype.constructor = BattleLightmask;
  1867.  
  1868.         BattleLightmask.prototype.initialize = function () {
  1869.                 PIXI.Container.call(this);
  1870.                 this._width = Graphics.width;
  1871.                 this._height = Graphics.height;
  1872.                 this._sprites = [];
  1873.                 this._createBitmap();
  1874.  
  1875.                 //Initialize the bitmap
  1876.                 this._addSprite(-lightMaskPadding, 0, this._maskBitmap);
  1877.                 var redhex = $gameTemp._MapTint.substring(1, 3);
  1878.                 var greenhex = $gameTemp._MapTint.substring(3, 5);
  1879.                 var bluehex = $gameTemp._MapTint.substring(5);
  1880.                 var red = parseInt(redhex, 16);
  1881.                 var green = parseInt(greenhex, 16);
  1882.                 var blue = parseInt(bluehex, 16);
  1883.                 var color = red + green + blue;
  1884.                 if (color < 200 && red < 66 && green < 66 && blue < 66) {
  1885.                         $gameTemp._MapTint = '#666666' // Prevent the battle scene from being too dark.
  1886.                 }
  1887.                 $gameTemp._BattleTint = $$.daynightset ? $gameVariables.GetTintByTime() : $gameTemp._MapTint;
  1888.                 this._maskBitmap.FillRect(-lightMaskPadding, 0, maxX + lightMaskPadding, maxY, $gameTemp._BattleTint);
  1889.                 $gameTemp._BattleTintSpeed = 0;
  1890.         };
  1891.  
  1892.         //@method _createBitmaps
  1893.  
  1894.         BattleLightmask.prototype._createBitmap = function () {
  1895.                 this._maskBitmap = new Bitmap(maxX + lightMaskPadding, maxY);   // one big bitmap to fill the intire screen with black
  1896.                 var canvas = this._maskBitmap.canvas;          // a bit larger then setting to take care of screenshakes
  1897.         };
  1898.  
  1899.         BattleLightmask.prototype.update = function () {
  1900.                 var color1 = $gameTemp._BattleTint;
  1901.                 if ($gameTemp._BattleTintSpeed > 0) {
  1902.  
  1903.                         $gameTemp._BattleTintTimer += 1;
  1904.  
  1905.                         var r = hexToRgb($gameTemp._BattleTintFade).r;
  1906.                         var g = hexToRgb($gameTemp._BattleTintFade).g;
  1907.                         var b = hexToRgb($gameTemp._BattleTintFade).b;
  1908.  
  1909.                         var r2 = hexToRgb($gameTemp._BattleTint).r;
  1910.                         var g2 = hexToRgb($gameTemp._BattleTint).g;
  1911.                         var b2 = hexToRgb($gameTemp._BattleTint).b;
  1912.  
  1913.                         var stepR = (r2 - r) / (60 * $gameTemp._BattleTintSpeed);
  1914.                         var stepG = (g2 - g) / (60 * $gameTemp._BattleTintSpeed);
  1915.                         var stepB = (b2 - b) / (60 * $gameTemp._BattleTintSpeed);
  1916.  
  1917.                         var r3 = Math.floor(r + (stepR * $gameTemp._BattleTintTimer));
  1918.                         var g3 = Math.floor(g + (stepG * $gameTemp._BattleTintTimer));
  1919.                         var b3 = Math.floor(b + (stepB * $gameTemp._BattleTintTimer));
  1920.                         if (r3 < 0) { r3 = 0 }
  1921.                         if (g3 < 0) { g3 = 0 }
  1922.                         if (b3 < 0) { b3 = 0 }
  1923.                         if (r3 > 255) { r3 = 255 }
  1924.                         if (g3 > 255) { g3 = 255 }
  1925.                         if (b3 > 255) { b3 = 255 }
  1926.                         var reddone = false;
  1927.                         var greendone = false;
  1928.                         var bluedone = false;
  1929.                         if (stepR >= 0 && r3 >= r2) {
  1930.                                 reddone = true;
  1931.                         }
  1932.                         if (stepR <= 0 && r3 <= r2) {
  1933.                                 reddone = true;
  1934.                         }
  1935.                         if (stepG >= 0 && g3 >= g2) {
  1936.                                 greendone = true;
  1937.                         }
  1938.                         if (stepG <= 0 && g3 <= g2) {
  1939.                                 greendone = true;
  1940.                         }
  1941.                         if (stepB >= 0 && b3 >= b2) {
  1942.                                 bluedone = true;
  1943.                         }
  1944.                         if (stepB <= 0 && b3 <= b2) {
  1945.                                 bluedone = true;
  1946.                         }
  1947.                         if (reddone == true && bluedone == true && greendone == true) {
  1948.                                 $gameTemp._BattleTintFade = $gameTemp._BattleTint;
  1949.                                 $gameTemp._BattleTintSpeed = 0;
  1950.                                 $gameTemp._BattleTintTimer = 0;
  1951.                         }
  1952.                         color1 = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  1953.                         $gameTemp._BattleTintFade = color1;
  1954.                 }
  1955.                 this._maskBitmap.FillRect(-lightMaskPadding, 0, maxX + lightMaskPadding, maxY, color1);
  1956.         };
  1957.  
  1958.         /**
  1959.          * @method _addSprite
  1960.          * @private
  1961.          */
  1962.         BattleLightmask.prototype._addSprite = function (x1, y1, selectedbitmap) {
  1963.  
  1964.                 var sprite = new Sprite(this.viewport);
  1965.                 sprite.bitmap = selectedbitmap;
  1966.                 sprite.opacity = 255;
  1967.                 sprite.blendMode = 2;
  1968.                 sprite.x = x1;
  1969.                 sprite.y = y1;
  1970.                 this._sprites.push(sprite);
  1971.                 this.addChild(sprite);
  1972.                 sprite.rotation = 0;
  1973.                 sprite.ax = 0;
  1974.                 sprite.ay = 0
  1975.                 sprite.opacity = 255;
  1976.         };
  1977.  
  1978.         /**
  1979.          * @method _removeSprite
  1980.          * @private
  1981.          */
  1982.         BattleLightmask.prototype._removeSprite = function () {
  1983.                 this.removeChild(this._sprites.pop());
  1984.         };
  1985.  
  1986.         // ALLIASED Move event location => reload map.
  1987.  
  1988.         let Alias_Game_Interpreter_command203 = Game_Interpreter.prototype.command203;
  1989.         Game_Interpreter.prototype.command203 = function () {
  1990.                 Alias_Game_Interpreter_command203.call(this);
  1991.                 $$.ReloadMapEvents();
  1992.                 return true;
  1993.         };
  1994.  
  1995.  
  1996.         // ALIASED FROM RPG OBJECTS TO ADD LIGHTING TO CONFIG MENU
  1997.  
  1998.         ConfigManager.cLighting = true;
  1999.  
  2000.         Object.defineProperty(ConfigManager, 'cLighting', {
  2001.                 get: function () {
  2002.                         return options_lighting_on;
  2003.                 },
  2004.                 set: function (value) {
  2005.                         options_lighting_on = value;
  2006.                 },
  2007.                 configurable: true
  2008.         });
  2009.  
  2010.         let Alias_ConfigManager_makeData = ConfigManager.makeData;
  2011.         ConfigManager.makeData = function () {
  2012.                 let config = Alias_ConfigManager_makeData.call(this);
  2013.                 config.cLighting = options_lighting_on;
  2014.                 return config;
  2015.         };
  2016.  
  2017.         let Alias_ConfigManager_applyData = ConfigManager.applyData;
  2018.         ConfigManager.applyData = function (config) {
  2019.                 Alias_ConfigManager_applyData.call(this, config);
  2020.                 this.cLighting = this.readFlag2(config, 'cLighting');
  2021.         };
  2022.  
  2023.         let Window_Options_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
  2024.         Window_Options.prototype.addGeneralOptions = function () {
  2025.                 Window_Options_addGeneralOptions.call(this);
  2026.                 if (optionText !== "") this.addCommand(optionText, 'cLighting');
  2027.         };
  2028.  
  2029.         ConfigManager.readFlag2 = function (config, name) {
  2030.                 let value = config[name];
  2031.                 if (value !== undefined) {
  2032.                         return !!config[name];
  2033.                 } else {
  2034.                         return true;
  2035.                 }
  2036.         };
  2037.  
  2038.         $$.ReloadMapEvents = function () {
  2039.                 //**********************fill up new map-array *************************
  2040.                 event_note = [];
  2041.                 event_id = [];
  2042.                 event_x = [];
  2043.                 event_y = [];
  2044.                 event_dir = [];
  2045.                 event_moving = [];
  2046.                 event_stacknumber = [];
  2047.                 event_eventcount = $gameMap.events().length;
  2048.  
  2049.                 for (let i = 0; i < event_eventcount; i++) {
  2050.                         if ($gameMap.events()[i]) {
  2051.                                 if ($gameMap.events()[i].event()) {
  2052.                                         let note = getTag.call($gameMap.events()[i].event());
  2053.  
  2054.                                         let note_args = note.split(" ");
  2055.                                         let note_command = note_args.shift().toLowerCase();
  2056.  
  2057.                                         if (note_command == "light" || note_command == "fire" || note_command == "flashlight") {
  2058.  
  2059.                                                 event_note.push(note);
  2060.                                                 event_id.push($gameMap.events()[i]._eventId);
  2061.                                                 event_x.push($gameMap.events()[i]._realX);
  2062.                                                 event_y.push($gameMap.events()[i]._realY);
  2063.                                                 event_dir.push($gameMap.events()[i]._direction);
  2064.                                                 event_moving.push($gameMap.events()[i]._moveType || $gameMap.events()[i]._moveRouteForcing);
  2065.                                                 event_stacknumber.push(i);
  2066.  
  2067.                                         }
  2068.                                         // else if (note_command == "daynight") daynightset = true;
  2069.                                 }
  2070.                         }
  2071.                 }
  2072.                 // *********************************** DAY NIGHT Setting **************************
  2073.                 $$.daynightset = false;
  2074.                 let mapnote = getTag.call($dataMap);
  2075.                 if (mapnote) {
  2076.                         mapnote = mapnote.toLowerCase();
  2077.                         if (mapnote.match(/^daynight/i)) {
  2078.                                 $$.daynightset = true;
  2079.                                 let dnspeed = mapnote.match(/\d+/);
  2080.                                 if (dnspeed) {
  2081.                                         daynightspeed = +dnspeed[0];
  2082.                                         if (daynightspeed < 1) daynightspeed = 5000;
  2083.                                         $gameVariables.SetDaynightSpeed(daynightspeed);
  2084.                                 }
  2085.                         }
  2086.                 }
  2087.         };
  2088.  
  2089.  
  2090.         $$.ReloadTagArea = function () {
  2091.                 // *************************** TILE TAG LIGHTSOURCES *********
  2092.  
  2093.                 // clear arrays
  2094.                 tile_lights = [];
  2095.                 tile_blocks = [];
  2096.  
  2097.                 // refill arrays
  2098.                 let tilearray = $gameVariables.GetTileArray();
  2099.                 for (let i = 0, len = tilearray.length; i < len; i++) {
  2100.  
  2101.                         let tilestr = tilearray[i];
  2102.                         let tileargs = tilestr.split(";");
  2103.                         let tile_type = tileargs[0];
  2104.                         let tile_number = tileargs[1];
  2105.                         let tile_on = tileargs[2];
  2106.                         let tile_color = tileargs[3];
  2107.                         let tile_radius = 0;
  2108.                         let brightness = 0.0;
  2109.                         let shape = 0;
  2110.                         let xo1 = 0.0;
  2111.                         let yo1 = 0.0;
  2112.                         let xo2 = 0.0;
  2113.                         let yo2 = 0.0;
  2114.  
  2115.                         if (tile_type == 1 || tile_type == 2) {
  2116.  
  2117.                                 let b_arg = tileargs[4];
  2118.                                 if (typeof b_arg != 'undefined') {
  2119.                                         shape = b_arg;
  2120.                                 }
  2121.                                 b_arg = tileargs[5];
  2122.                                 if (typeof b_arg != 'undefined') {
  2123.                                         xo1 = b_arg;
  2124.                                 }
  2125.                                 b_arg = tileargs[6];
  2126.                                 if (typeof b_arg != 'undefined') {
  2127.                                         yo1 = b_arg;
  2128.                                 }
  2129.                                 b_arg = tileargs[7];
  2130.                                 if (typeof b_arg != 'undefined') {
  2131.                                         xo2 = b_arg;
  2132.                                 }
  2133.                                 b_arg = tileargs[8];
  2134.                                 if (typeof b_arg != 'undefined') {
  2135.                                         yo2 = b_arg;
  2136.                                 }
  2137.  
  2138.  
  2139.                         } else {
  2140.                                 tile_radius = tileargs[4];
  2141.                                 let b_arg = tileargs[5];
  2142.                                 if (typeof b_arg != 'undefined') {
  2143.                                         let key = b_arg.substring(0, 1);
  2144.                                         if (key == 'b' || key == 'B') {
  2145.                                                 brightness = Number(b_arg.substring(1)) / 100;
  2146.                                         }
  2147.                                 }
  2148.                         }
  2149.  
  2150.                         if (tile_on == 1) {
  2151.  
  2152.                                 if (tile_type >= 3) {
  2153.                                         // *************************** TILE TAG LIGHTSOURCES *********
  2154.                                         for (let y = 0, mapHeight = $dataMap.height; y < mapHeight; y++) {
  2155.                                                 for (let x = 0, mapWidth = $dataMap.width; x < mapWidth; x++) {
  2156.                                                         let tag = 0;
  2157.                                                         if (tile_type == 3 || tile_type == 5 || tile_type == 7) {
  2158.                                                                 tag = $gameMap.terrainTag(x, y);
  2159.                                                         }          // tile light
  2160.                                                         if (tile_type == 4 || tile_type == 6 || tile_type == 8) {
  2161.                                                                 tag = $dataMap.data[(5 * $dataMap.height + y) * $dataMap.width + x];
  2162.                                                         }  // region light
  2163.                                                         if (tag == tile_number) {
  2164.                                                                 let tilecode = x + ";" + y + ";" + tile_type + ";" + tile_radius + ";" + tile_color + ";" + brightness;
  2165.                                                                 tile_lights.push(tilecode);
  2166.                                                         }
  2167.                                                 }
  2168.                                         }
  2169.                                 }
  2170.  
  2171.  
  2172.                                 // *************************** REDRAW MAPTILES FOR ROOFS ETC *********
  2173.                                 if (tile_type == 1 || tile_type == 2) {
  2174.                                         for (let y = 0, mapHeight = $dataMap.height; y < mapHeight; y++) {
  2175.                                                 for (let x = 0, mapWidth = $dataMap.width; x < mapWidth; x++) {
  2176.                                                         let tag = 0;
  2177.                                                         if (tile_type == 1) {
  2178.                                                                 tag = $gameMap.terrainTag(x, y);
  2179.                                                         }                  // tile block
  2180.                                                         if (tile_type == 2) {
  2181.                                                                 tag = $dataMap.data[(5 * $dataMap.height + y) * $dataMap.width + x];
  2182.                                                         }  // region block
  2183.                                                         if (tag == tile_number) {
  2184.                                                                 let tilecode = x + ";" + y + ";" + shape + ";" + xo1 + ";" + yo1 + ";" + xo2 + ";" + yo2 + ";" + tile_color;
  2185.                                                                 tile_blocks.push(tilecode);
  2186.                                                         }
  2187.                                                 }
  2188.                                         }
  2189.                                 }
  2190.                         }
  2191.  
  2192.                 }
  2193.                 $gameVariables.SetLightTags(tile_lights);
  2194.                 $gameVariables.SetBlockTags(tile_blocks);
  2195.         };
  2196.  
  2197.         $$.flashlight = function (args) {
  2198.                 if (args[0] == 'on') {
  2199.  
  2200.                         let flashlightlength = $gameVariables.GetFlashlightLength();
  2201.                         let flashlightwidth = $gameVariables.GetFlashlightWidth();
  2202.                         let flashlightdensity = $gameVariables.GetFlashlightDensity();
  2203.                         let playercolor = $gameVariables.GetPlayerColor();
  2204.  
  2205.                         if (args.length >= 1) {
  2206.                                 flashlightlength = args[1];
  2207.                         }
  2208.                         if (args.length >= 2) {
  2209.                                 flashlightwidth = args[2];
  2210.                         }
  2211.                         if (args.length >= 3) {
  2212.                                 playercolor = args[3];
  2213.                                 let isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  2214.                                 if (!isValidPlayerColor) {
  2215.                                         playercolor = '#FFFFFF'
  2216.                                 }
  2217.                         }
  2218.                         if (args.length >= 4) {
  2219.                                 flashlightdensity = args[4]; // density
  2220.                         }
  2221.  
  2222.                         if (flashlightlength == 0 || isNaN(flashlightlength)) {
  2223.                                 flashlightlength = 8
  2224.                         }
  2225.                         if (flashlightwidth == 0 || isNaN(flashlightwidth)) {
  2226.                                 flashlightwidth = 12
  2227.                         }
  2228.                         if (flashlightdensity == 0 || isNaN(flashlightdensity)) {
  2229.                                 flashlightdensity = 3
  2230.                         }
  2231.  
  2232.                         $gameVariables.SetFlashlight(true);
  2233.                         $gameVariables.SetPlayerColor(playercolor);
  2234.                         $gameVariables.SetFlashlightWidth(flashlightwidth);
  2235.                         $gameVariables.SetFlashlightLength(flashlightlength);
  2236.                         $gameVariables.SetFlashlightDensity(flashlightdensity);
  2237.  
  2238.                 }
  2239.                 if (args[0] === 'off') {
  2240.                         $gameVariables.SetFlashlight(false);
  2241.                 }
  2242.         };
  2243.  
  2244.         $$.effectXy = function (args) {
  2245.                 let x1 = args[0];
  2246.                 if (x1.substring(0, 1) == '#') {
  2247.                         x1 = $gameVariables.value(Number(x1.substring(1)));
  2248.                 }
  2249.                 let y1 = args[1];
  2250.                 if (y1.substring(0, 1) == '#') {
  2251.                         y1 = $gameVariables.value(Number(y1.substring(1)));
  2252.                 }
  2253.                 let radius = args[2];
  2254.                 if (radius.substring(0, 1) == '#') {
  2255.                         radius = $gameVariables.value(Number(radius.substring(1)));
  2256.                 }
  2257.                 let color = args[3];
  2258.                 let time = args[4];
  2259.                 if (time.substring(0, 1) == '#') {
  2260.                         time = $gameVariables.value(Number(time.substring(1)));
  2261.                 }
  2262.                 let def = radius + "," + color + "," + time;
  2263.                 if (args.length >= 6) {
  2264.                         let command = args[5];
  2265.                         let ctime = args[6];
  2266.                         if (ctime.substring(0, 1) == '#') {
  2267.                                 ctime = $gameVariables.value(Number(ctime.substring(1)));
  2268.                         }
  2269.                         def = def + "," + command + "," + ctime;
  2270.                 }
  2271.         };
  2272.  
  2273.         $$.effectOnEvent = function (args) {
  2274.                 x1 = 0;
  2275.                 y1 = 0;
  2276.                 let evid = -1;
  2277.                 for (let i = 0, len = $gameMap.events().length; i < len; i++) {
  2278.                         if ($gameMap.events()[i]) {
  2279.                                 evid = $gameMap.events()[i]._eventId;
  2280.                                 if (evid == args[0]) {
  2281.                                         x1 = $gameMap.events()[i]._realX * $gameMap.tileWidth();
  2282.                                         y1 = $gameMap.events()[i]._realY * $gameMap.tileHeight();
  2283.                                 }
  2284.                         }
  2285.                 }
  2286.                 // def = radius,color,duration(,keyword,speed)
  2287.                 // 0. Radius
  2288.                 // 1. Color
  2289.                 // 2. Time in Frames
  2290.                 // 3. Keyword (optional)   FADEIN FADEOUT FADEBOTH GROW SHRINK GROWSHRINK BIO
  2291.                 // 4. Fade/Grow Speed in frames
  2292.  
  2293.                 let radius = args[1];
  2294.                 if (radius.substring(0, 1) == '#') {
  2295.                         radius = $gameVariables.value(Number(radius.substring(1)));
  2296.                 }
  2297.                 let color = args[2];
  2298.                 let time = args[3];
  2299.                 if (time.substring(0, 1) == '#') {
  2300.                         time = $gameVariables.value(Number(time.substring(1)));
  2301.                 }
  2302.                 let def = radius + "," + color + "," + time;
  2303.                 if (args.length >= 5) {
  2304.                         let command = args[4];
  2305.                         let ctime = args[5];
  2306.                         if (ctime.substring(0, 1) == '#') {
  2307.                                 ctime = $gameVariables.value(Number(ctime.substring(1)));
  2308.                         }
  2309.                         def = def + "," + command + "," + ctime;
  2310.                 }
  2311.         };
  2312.  
  2313.         $$.fireLight = function (args) {
  2314.                 //******************* Light radius 100 #FFFFFF ************************
  2315.                 if (args[0] == 'radius') {
  2316.                         let newradius = Number(args[1]);
  2317.                         if (newradius >= 0) {
  2318.                                 $gameVariables.SetRadius(newradius);
  2319.                                 $gameVariables.SetRadiusTarget(newradius);
  2320.  
  2321.                         }
  2322.                         if (args.length > 2) {
  2323.                                 playercolor = args[2];
  2324.                                 let isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  2325.                                 if (!isValidPlayerColor) {
  2326.                                         playercolor = '#FFFFFF'
  2327.                                 }
  2328.                                 $gameVariables.SetPlayerColor(playercolor);
  2329.                         }
  2330.                         // player brightness
  2331.                         if (args.length > 3) {
  2332.                                 let brightness = 0.0;
  2333.                                 let b_arg = args[3];
  2334.                                 if (typeof b_arg != 'undefined') {
  2335.                                         let key = b_arg.substring(0, 1);
  2336.                                         if (key == 'b' || key == 'B') {
  2337.                                                 brightness = ((+b_arg.substring(1) || 0) / 100).clamp(0, 1);
  2338.                                                 $gameVariables.SetPlayerBrightness(brightness);
  2339.                                         }
  2340.                                 }
  2341.                         }
  2342.                 }
  2343.  
  2344.                 //******************* Light radiusgrow 100 #FFFFFF ************************
  2345.                 if (args[0] === 'radiusgrow') {
  2346.                         let newradius = Number(args[1]);
  2347.                         if (newradius >= 0) {
  2348.  
  2349.                                 let lightgrow_value = $gameVariables.GetRadius();
  2350.                                 let lightgrow_target = newradius;
  2351.                                 let lightgrow_speed = 0.0;
  2352.                                 if (args.length >= 4) {
  2353.                                         if (player_radius > newradius) {
  2354.                                                 //shrinking
  2355.                                                 lightgrow_speed = (player_radius * 0.012) / Number(args[4]);
  2356.                                         } else {
  2357.                                                 //growing
  2358.                                                 lightgrow_speed = (newradius * 0.012) / Number(args[4]);
  2359.                                         }
  2360.                                 } else {
  2361.                                         lightgrow_speed = (Math.abs(newradius - player_radius)) / 500;
  2362.                                 }
  2363.                                 $gameVariables.SetRadius(lightgrow_value);
  2364.                                 $gameVariables.SetRadiusTarget(lightgrow_target);
  2365.                                 $gameVariables.SetRadiusSpeed(lightgrow_speed);
  2366.                         }
  2367.                         // player color
  2368.                         if (args.length > 2) {
  2369.                                 playercolor = args[2];
  2370.                                 let isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  2371.                                 if (!isValidPlayerColor) {
  2372.                                         playercolor = '#FFFFFF'
  2373.                                 }
  2374.                                 $gameVariables.SetPlayerColor(playercolor);
  2375.                         }
  2376.                         // player brightness
  2377.                         if (args.length > 3) {
  2378.                                 let brightness = 0.0;
  2379.                                 let b_arg = args[3];
  2380.                                 if (typeof b_arg != 'undefined') {
  2381.                                         let key = b_arg.substring(0, 1);
  2382.                                         if (key == 'b' || key == 'B') {
  2383.                                                 brightness = ((+b_arg.substring(1) || 0) / 100).clamp(0, 1);
  2384.                                                 $gameVariables.SetPlayerBrightness(brightness);
  2385.                                         }
  2386.                                 }
  2387.                         }
  2388.  
  2389.                 }
  2390.  
  2391.                 // *********************** TURN SPECIFIC LIGHT ON *********************
  2392.                 if (args[0] === 'on') {
  2393.  
  2394.                         let lightarray_id = $gameVariables.GetLightArrayId();
  2395.                         let lightarray_state = $gameVariables.GetLightArrayState();
  2396.                         let lightarray_color = $gameVariables.GetLightArrayColor();
  2397.  
  2398.                         let lightid = Number(args[1]);
  2399.                         let idfound = false;
  2400.                         for (let i = 0, len = lightarray_id.length; i < len; i++) {
  2401.                                 if (lightarray_id[i] == lightid) {
  2402.                                         idfound = true;
  2403.                                         lightarray_state[i] = true;
  2404.                                 }
  2405.                         }
  2406.                         if (idfound === false) {
  2407.                                 lightarray_id.push(lightid);
  2408.                                 lightarray_state.push(true);
  2409.                                 lightarray_color.push('defaultcolor');
  2410.                         }
  2411.                         $gameVariables.SetLightArrayId(lightarray_id);
  2412.                         $gameVariables.SetLightArrayState(lightarray_state);
  2413.                         $gameVariables.SetLightArrayColor(lightarray_color);
  2414.                 }
  2415.  
  2416.                 // *********************** TURN SPECIFIC LIGHT OFF *********************
  2417.                 if (args[0] === 'off') {
  2418.  
  2419.                         let lightarray_id = $gameVariables.GetLightArrayId();
  2420.                         let lightarray_state = $gameVariables.GetLightArrayState();
  2421.                         let lightarray_color = $gameVariables.GetLightArrayColor();
  2422.  
  2423.                         let lightid = Number(args[1]);
  2424.                         let idfound = false;
  2425.                         for (let i = 0, len = lightarray_id.length; i < len; i++) {
  2426.                                 if (lightarray_id[i] == lightid) {
  2427.                                         idfound = true;
  2428.                                         lightarray_state[i] = false;
  2429.                                 }
  2430.                         }
  2431.                         if (idfound === false) {
  2432.                                 lightarray_id.push(lightid);
  2433.                                 lightarray_state.push(false);
  2434.                                 lightarray_color.push('defaultcolor');
  2435.                         }
  2436.                         $gameVariables.SetLightArrayId(lightarray_id);
  2437.                         $gameVariables.SetLightArrayState(lightarray_state);
  2438.                         $gameVariables.SetLightArrayColor(lightarray_color);
  2439.                 }
  2440.  
  2441.                 // *********************** SET COLOR *********************
  2442.  
  2443.                 if (args[0] === 'color') {
  2444.  
  2445.                         let newcolor = args[2];
  2446.                         if (newcolor && newcolor.toLowerCase() === 'defaultcolor') {
  2447.                                 newcolor = 'defaultcolor';
  2448.                         }
  2449.  
  2450.                         let lightarray_id = $gameVariables.GetLightArrayId();
  2451.                         let lightarray_state = $gameVariables.GetLightArrayState();
  2452.                         let lightarray_color = $gameVariables.GetLightArrayColor();
  2453.  
  2454.                         let lightid = Number(args[1]);
  2455.                         idfound = false;
  2456.                         for (let i = 0, len = lightarray_id.length; i < len; i++) {
  2457.                                 if (lightarray_id[i] == lightid) {
  2458.                                         idfound = true;
  2459.                                         lightarray_color[i] = newcolor;
  2460.                                 }
  2461.                         }
  2462.                         if (idfound === false) {
  2463.                                 lightarray_id.push(lightid);
  2464.                                 lightarray_state.push(false);
  2465.                                 lightarray_color.push(newcolor);
  2466.                         }
  2467.                         $gameVariables.SetLightArrayId(lightarray_id);
  2468.                         $gameVariables.SetLightArrayState(lightarray_state);
  2469.                         $gameVariables.SetLightArrayColor(lightarray_color);
  2470.                 }
  2471.  
  2472.  
  2473.                 // **************************** RESET ALL SWITCHES ***********************
  2474.                 if (args[0] === 'switch' && args[1] === 'reset') {
  2475.                         $gameVariables.SetLightArrayId([]);
  2476.                         $gameVariables.SetLightArrayState([]);
  2477.                         $gameVariables.SetLightArrayColor([]);
  2478.                 }
  2479.         };
  2480.  
  2481.         $$.tile = function (args) {
  2482.                 let tilearray = $gameVariables.GetTileArray();
  2483.                 let tilenumber = Number(eval(args[0]));
  2484.                 let tile_on = 0;
  2485.                 if (args[1] === "on") {
  2486.                         tile_on = 1;
  2487.                 }
  2488.                 let tilecolor = args[2];
  2489.                 let isValidColor1 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(tilecolor);
  2490.                 if (!isValidColor1) {
  2491.                         if (tiletype === 1 || tiletype === 2) {
  2492.                                 tilecolor = '#000000';
  2493.                         } else {
  2494.                                 tilecolor = '#FFFFFF';
  2495.                         }
  2496.                 }
  2497.  
  2498.                 let tileradius = 100;
  2499.                 let tilebrightness = 0.0;
  2500.                 let shape = 0;
  2501.                 let x1 = 0;
  2502.                 let y1 = 0;
  2503.                 let x2 = 0;
  2504.                 let y2 = 0;
  2505.                 if (tiletype === 1 || tiletype === 2) {
  2506.                         if (args.length > 3) {
  2507.                                 shape = args[3];
  2508.                         }
  2509.                         if (args.length > 4) {
  2510.                                 x1 = args[4];
  2511.                         }
  2512.                         if (args.length > 5) {
  2513.                                 y1 = args[5];
  2514.                         }
  2515.                         if (args.length > 6) {
  2516.                                 x2 = args[6];
  2517.                         }
  2518.                         if (args.length > 7) {
  2519.                                 y2 = args[7];
  2520.                         }
  2521.                 } else {
  2522.                         if (args.length > 3) {
  2523.                                 tileradius = args[3];
  2524.                         }
  2525.                         if (args.length > 4) {
  2526.                                 tilebrightness = args[4];
  2527.                         }
  2528.                 }
  2529.  
  2530.                 let tilefound = false;
  2531.  
  2532.                 for (let i = 0, len = tilearray.length; i < len; i++) {
  2533.                         let tilestr = tilearray[i];
  2534.                         let tileargs = tilestr.split(";");
  2535.                         if (tileargs[0] == tiletype && tileargs[1] == tilenumber) {
  2536.                                 tilefound = true;
  2537.                                 if (tiletype === 1 || tiletype === 2) {
  2538.                                         tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
  2539.                                 } else {
  2540.                                         tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
  2541.                                 }
  2542.                         }
  2543.                 }
  2544.  
  2545.                 if (tilefound === false) {
  2546.                         let tiletag = "";
  2547.                         if (tiletype === 1 || tiletype === 2) {
  2548.                                 tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
  2549.                         } else {
  2550.                                 tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
  2551.                         }
  2552.                         tilearray.push(tiletag);
  2553.                 }
  2554.                 $gameVariables.SetTileArray(tilearray);
  2555.                 $$.ReloadTagArea();
  2556.         };
  2557.  
  2558.         $$.tint = function (args) {
  2559.                 if (args[0] === 'set') {
  2560.                         $gameVariables.SetTint(args[1]);
  2561.                         $gameVariables.SetTintTarget(args[1]);
  2562.                 }
  2563.                 if (args[0] === 'fade') {
  2564.                         $gameVariables.SetTintTarget(args[1]);
  2565.                         $gameVariables.SetTintSpeed(args[2]);
  2566.                 }
  2567.                 else if (args[0] === "daylight") {
  2568.                         let currentColor = $gameVariables.GetTintByTime();
  2569.                         $gameVariables.SetTint(currentColor);
  2570.                         $gameVariables.SetTintTarget(currentColor);
  2571.                 }
  2572.         };
  2573.  
  2574.         $$.DayNight = function (args) {
  2575.                 let daynightspeed = $gameVariables.GetDaynightSpeed();
  2576.                 let daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  2577.                 let daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  2578.                 let daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24
  2579.                 //let daynightcolors = $gameVariables.GetDaynightColorArray();
  2580.  
  2581.                 if (args[0] === 'speed') {
  2582.                         daynightspeed = Number(args[1]);
  2583.                         if (daynightspeed <= 0) {
  2584.                                 daynightspeed = 5000;
  2585.                         }
  2586.                         $gameVariables.SetDaynightSpeed(daynightspeed);
  2587.                 }
  2588.  
  2589.                 if (args[0] === 'add') {
  2590.                         let houradd = Number(args[1]);
  2591.                         let minuteadd = 0;
  2592.                         if (args.length > 2) {
  2593.                                 minuteadd = Number(args[2]);
  2594.                         }
  2595.  
  2596.                         let daynightminutes = Math.floor(daynighttimer / daynightspeed);
  2597.                         daynightminutes = daynightminutes + minuteadd;
  2598.                         if (daynightminutes > 60) {
  2599.                                 daynightminutes = daynightminutes - 60;
  2600.                                 daynightcycle = daynightcycle + 1;
  2601.                         }
  2602.                         daynightcycle = daynightcycle + houradd;
  2603.                         daynighttimer = daynightminutes * daynightspeed;
  2604.  
  2605.                         if (daynightcycle < 0) daynightcycle = 0;
  2606.                         if (daynightcycle >= daynighthoursinday) daynightcycle = daynightcycle - daynighthoursinday;
  2607.                         saveTime(daynightcycle, daynightminutes);
  2608.  
  2609.                         $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  2610.                         $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours
  2611.  
  2612.                 }
  2613.  
  2614.  
  2615.                 if (args[0] === 'hour') {
  2616.                         daynightcycle = Number(args[1]);
  2617.                         if (args.length > 2) {
  2618.                                 daynightminutes = Number(args[2]);
  2619.                         } else {
  2620.                                 daynightminutes = 0;
  2621.                         }
  2622.                         daynighttimer = daynightminutes * daynightspeed;
  2623.  
  2624.                         if (daynightcycle < 0) daynightcycle = 0;
  2625.                         if (daynightcycle >= daynighthoursinday) daynightcycle = daynighthoursinday - 1;
  2626.                         saveTime(daynightcycle, daynightminutes);
  2627.  
  2628.                         $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  2629.                         $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours
  2630.  
  2631.                 }
  2632.  
  2633.                 if (args[0] === 'hoursinday') {
  2634.  
  2635.                         let old_value = daynighthoursinday;
  2636.                         daynighthoursinday = Number(args[1]);
  2637.                         if (daynighthoursinday < 0) {
  2638.                                 daynighthoursinday = 0;
  2639.                         }
  2640.                         if (daynighthoursinday > old_value) {
  2641.                                 for (let i = old_value; i < daynighthoursinday; i++) {
  2642.                                         daynightcolors.push({ "color": "#ffffff", "isNight": false });
  2643.                                 }
  2644.                         }
  2645.                         $gameVariables.setDayNightColorArray(daynightcolors);
  2646.                         $gameVariables.setDayNightHoursInDay(daynighthoursinday);
  2647.                 }
  2648.  
  2649.                 if (args[0] === 'debug') {
  2650.                         daynightdebug = true;
  2651.                 }
  2652.  
  2653.  
  2654.                 if (args[0] === 'color') {
  2655.  
  2656.                         let hour = Number(args[1]);
  2657.                         if (hour < 0) {
  2658.                                 hour = 0;
  2659.                         }
  2660.                         if (hour >= daynighthoursinday) {
  2661.                                 hour = (daynighthoursinday - 1);
  2662.                         }
  2663.                         let hourcolor = args[2];
  2664.                         let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hourcolor);
  2665.                         if (isValidColor) {
  2666.                                 daynightcolors[hour].color = hourcolor;
  2667.                         }
  2668.                         $gameVariables.SetDaynightColorArray(daynightcolors);
  2669.                 }
  2670.         };
  2671.  
  2672.  
  2673.  
  2674.  
  2675. })(Community.Lighting);
  2676.  
  2677. Community.Lighting.distance = function(x1, y1, x2, y2) {
  2678.     return Math.abs(Math.sqrt(Math.pow(x1 - x2,2) + Math.pow(y1 - y2,2)));
  2679. };
  2680.  
  2681. Game_Variables.prototype.SetActiveRadius = function (value) {
  2682.     this._Player_Light_Radius = value;
  2683. };
  2684. Game_Variables.prototype.GetActiveRadius = function () {
  2685.     return this._Player_Light_Radius || Number(Community.Lighting.parameters['Lights Active Radius']);
  2686. };
  2687.  
  2688. Game_Variables.prototype.GetFirstRun = function () {
  2689.         if (typeof this._Community_Lighting_FirstRun == 'undefined') {
  2690.                 this._Community_Lighting_FirstRun = true;
  2691.         }
  2692.         return this._Community_Lighting_FirstRun;
  2693. };
  2694. Game_Variables.prototype.SetFirstRun = function (value) {
  2695.         this._Community_Lighting_FirstRun = value;
  2696. };
  2697. Game_Variables.prototype.GetScriptActive = function () {
  2698.         if (typeof this._Community_Lighting_ScriptActive == 'undefined') {
  2699.                 this._Community_Lighting_ScriptActive = true;
  2700.         }
  2701.         return this._Community_Lighting_ScriptActive;
  2702. };
  2703. Game_Variables.prototype.SetScriptActive = function (value) {
  2704.         this._Community_Lighting_ScriptActive = value;
  2705. };
  2706.  
  2707. Game_Variables.prototype.GetOldMapId = function () {
  2708.         if (typeof this._Community_Lighting_OldMapId == 'undefined') {
  2709.                 this._Community_Lighting_OldMapId = 0;
  2710.         }
  2711.         return this._Community_Lighting_OldMapId;
  2712. };
  2713. Game_Variables.prototype.SetOldMapId = function (value) {
  2714.         this._Community_Lighting_OldMapId = value;
  2715. };
  2716.  
  2717. Game_Variables.prototype.SetTint = function (value) {
  2718.         this._Community_Tint_Value = value;
  2719. };
  2720. Game_Variables.prototype.GetTint = function () {
  2721.         return this._Community_Tint_Value || '#000000';
  2722. };
  2723. Game_Variables.prototype.GetTintByTime = function () {
  2724.         let result = this.GetDaynightColorArray()[this.GetDaynightCycle()];
  2725.         return result ? (result.color || "#000000") : "#000000";
  2726. };
  2727. Game_Variables.prototype.SetTintTarget = function (value) {
  2728.         this._Community_TintTarget_Value = value;
  2729. };
  2730. Game_Variables.prototype.GetTintTarget = function () {
  2731.         return this._Community_TintTarget_Value || '#000000';
  2732. };
  2733. Game_Variables.prototype.SetTintSpeed = function (value) {
  2734.         this._Community_TintSpeed_Value = value;
  2735. };
  2736. Game_Variables.prototype.GetTintSpeed = function () {
  2737.         return this._Community_TintSpeed_Value || 60;
  2738. };
  2739.  
  2740. Game_Variables.prototype.SetFlashlight = function (value) {
  2741.         this._Community_Lighting_Flashlight = value;
  2742. };
  2743. Game_Variables.prototype.GetFlashlight = function () {
  2744.         return this._Community_Lighting_Flashlight || false;
  2745. };
  2746. Game_Variables.prototype.SetFlashlightDensity = function (value) {
  2747.         this._Community_Lighting_FlashlightDensity = value;
  2748. };
  2749. Game_Variables.prototype.GetFlashlightDensity = function () {
  2750.         return this._Community_Lighting_FlashlightDensity || 3;
  2751. };
  2752. Game_Variables.prototype.SetFlashlightLength = function (value) {
  2753.         this._Community_Lighting_FlashlightLength = value;
  2754. };
  2755. Game_Variables.prototype.GetFlashlightLength = function () {
  2756.         return this._Community_Lighting_FlashlightLength || 8;
  2757. };
  2758. Game_Variables.prototype.SetFlashlightWidth = function (value) {
  2759.         this._Community_Lighting_FlashlightWidth = value;
  2760. };
  2761. Game_Variables.prototype.GetFlashlightWidth = function () {
  2762.         return this._Community_Lighting_FlashlightWidth || 12;
  2763. };
  2764.  
  2765. Game_Variables.prototype.SetPlayerColor = function (value) {
  2766.         this._Community_Lighting_PlayerColor = value;
  2767. };
  2768. Game_Variables.prototype.GetPlayerColor = function () {
  2769.         return this._Community_Lighting_PlayerColor || '#FFFFFF';
  2770. };
  2771. Game_Variables.prototype.SetPlayerBrightness = function (value) {
  2772.         this._Community_Lighting_PlayerBrightness = value;
  2773. };
  2774. Game_Variables.prototype.GetPlayerBrightness = function () {
  2775.         return this._Community_Lighting_PlayerBrightness || 0;
  2776. };
  2777. Game_Variables.prototype.SetRadius = function (value) {
  2778.         this._Community_Lighting_Radius = value;
  2779. };
  2780. Game_Variables.prototype.GetRadius = function () {
  2781.         if (this._Community_Lighting_Radius === undefined) {
  2782.                 return 150;
  2783.         } else {
  2784.                 return this._Community_Lighting_Radius;
  2785.         }
  2786. };
  2787. Game_Variables.prototype.SetRadiusTarget = function (value) {
  2788.         this._Community_Lighting_RadiusTarget = value;
  2789. };
  2790. Game_Variables.prototype.GetRadiusTarget = function () {
  2791.         if (this._Community_Lighting_RadiusTarget === undefined) {
  2792.                 return 150;
  2793.         } else {
  2794.                 return this._Community_Lighting_RadiusTarget;
  2795.         }
  2796. };
  2797. Game_Variables.prototype.SetRadiusSpeed = function (value) {
  2798.         this._Community_Lighting_RadiusSpeed = value;
  2799. };
  2800. Game_Variables.prototype.GetRadiusSpeed = function () {
  2801.         return this._Community_Lighting_RadiusSpeed || 0;
  2802. };
  2803.  
  2804. Game_Variables.prototype.SetDaynightColorArray = function (value) {
  2805.         this._Community_Lighting_DayNightColorArray = value;
  2806. };
  2807. Game_Variables.prototype.GetDaynightColorArray = function () {
  2808.         let result = this._Community_Lighting_DayNightColorArray || Community.Lighting.getDayNightList();
  2809.         if (!result) {
  2810.                 result = ['#000000', '#000000', '#000000', '#000000',
  2811.                         '#000000', '#000000', '#666666', '#AAAAAA',
  2812.                         '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
  2813.                         '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
  2814.                         '#FFFFFF', '#FFFFFF', '#AAAAAA', '#666666',
  2815.                         '#000000', '#000000', '#000000', '#000000'].map(x => x = { "color": x, "isNight": false });
  2816.                 this._Community_Lighting_DayNightColorArray = result;
  2817.         }
  2818.         if (!this._Community_Lighting_DayNightColorArray) this.SetDaynightColorArray(result);
  2819.         return result;
  2820. };
  2821. Game_Variables.prototype.SetDaynightSpeed = function (value) {
  2822.         this._Community_Lighting_DaynightSpeed = value;
  2823. };
  2824. Game_Variables.prototype.GetDaynightSpeed = function () {
  2825.         return this._Community_Lighting_DaynightSpeed || 10;
  2826. };
  2827. Game_Variables.prototype.SetDaynightCycle = function (value) {
  2828.         this._Community_Lighting_DaynightCycle = value;
  2829. };
  2830. Game_Variables.prototype.GetDaynightCycle = function () {
  2831.         return this._Community_Lighting_DaynightCycle || 0;
  2832. };
  2833. Game_Variables.prototype.SetDaynightTimer = function (value) {
  2834.         this._Community_Lighting_DaynightTimer = value;
  2835. };
  2836. Game_Variables.prototype.GetDaynightTimer = function () {
  2837.         return this._Community_Lighting_DaynightTimer || 0;
  2838. };
  2839. Game_Variables.prototype.SetDaynightHoursinDay = function (value) {
  2840.         this._Community_Lighting_DaynightHoursinDay = value;
  2841. };
  2842. Game_Variables.prototype.GetDaynightHoursinDay = function () {
  2843.         return this._Community_Lighting_DaynightHoursinDay || 24;
  2844. };
  2845.  
  2846. Game_Variables.prototype.SetFireRadius = function (value) {
  2847.         this._Community_Lighting_FireRadius = value;
  2848. };
  2849. Game_Variables.prototype.GetFireRadius = function () {
  2850.         return this._Community_Lighting_FireRadius || 7;
  2851. };
  2852. Game_Variables.prototype.SetFireColorshift = function (value) {
  2853.         this._Community_Lighting_FireColorshift = value;
  2854. };
  2855. Game_Variables.prototype.GetFireColorshift = function () {
  2856.         return this._Community_Lighting_FireColorshift || 10;
  2857. };
  2858. Game_Variables.prototype.SetFire = function (value) {
  2859.         this._Community_Lighting_Fire = value;
  2860. };
  2861. Game_Variables.prototype.GetFire = function () {
  2862.         return this._Community_Lighting_Fire || false;
  2863. };
  2864.  
  2865. Game_Variables.prototype.SetLightArrayId = function (value) {
  2866.         this._Community_Lighting_LightArrayId = value;
  2867. };
  2868. Game_Variables.prototype.GetLightArrayId = function () {
  2869.         let default_LAI = [];
  2870.         return this._Community_Lighting_LightArrayId || default_LAI;
  2871. };
  2872. Game_Variables.prototype.SetLightArrayState = function (value) {
  2873.         this._Community_Lighting_LightArrayState = value;
  2874. };
  2875. Game_Variables.prototype.GetLightArrayState = function () {
  2876.         let default_LAS = [];
  2877.         return this._Community_Lighting_LightArrayState || default_LAS;
  2878. };
  2879. Game_Variables.prototype.SetLightArrayColor = function (value) {
  2880.         this._Community_Lighting_LightArrayColor = value;
  2881. };
  2882. Game_Variables.prototype.GetLightArrayColor = function () {
  2883.         let default_LAS = [];
  2884.         return this._Community_Lighting_LightArrayColor || default_LAS;
  2885. };
  2886.  
  2887. Game_Variables.prototype.SetTileArray = function (value) {
  2888.         this._Community_Lighting_TileArray = value;
  2889. };
  2890. Game_Variables.prototype.GetTileArray = function () {
  2891.         let default_TA = [];
  2892.         return this._Community_Lighting_TileArray || default_TA;
  2893. };
  2894. Game_Variables.prototype.SetLightTags = function (value) {
  2895.         this._Community_Lighting_LightTags = value;
  2896. };
  2897. Game_Variables.prototype.GetLightTags = function () {
  2898.         let default_TA = [];
  2899.         return this._Community_Lighting_LightTags || default_TA;
  2900. };
  2901. Game_Variables.prototype.SetBlockTags = function (value) {
  2902.         this._Community_Lighting_BlockTags = value;
  2903. };
  2904. Game_Variables.prototype.GetBlockTags = function () {
  2905.         let default_TA = [];
  2906.         return this._Community_Lighting_BlockTags || default_TA;
  2907. };
  2908.  
  2909. Community.Lighting.Spriteset_Map_prototype_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
  2910. Spriteset_Map.prototype.createLowerLayer = function () {
  2911.         Community.Lighting.Spriteset_Map_prototype_createLowerLayer.call(this);
  2912.         this.createLightmask();
  2913. };

评分

参与人数 2+2 收起 理由
Zeldashu + 1 塞糖
RyanYe + 1 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6930
在线时间
708 小时
注册时间
2021-3-5
帖子
814
6
 楼主| 发表于 2021-5-17 08:49:16 | 只看该作者
Zeldashu 发表于 2021-5-16 22:41
楼主帮忙帮一下吧,下载地址的git地址内陆无法打开,另外看到目前插件仍然有bug(大地图会闪耀? ...

多大的地图会闪耀啊

你说的目前插件有问题,是terrax还是community啊?
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
8624
在线时间
978 小时
注册时间
2016-8-22
帖子
58

开拓者

7
发表于 2021-5-17 11:29:33 | 只看该作者
RyanYe 发表于 2021-5-17 08:49
多大的地图会闪耀啊

你说的目前插件有问题,是terrax还是community啊?

是指这个吧



是插件自带的,看翻译应该是“在大地图下和ultra 7模式下闪烁”
是大地图 或 ultra 7模式下都会闪烁
还是在大地图和ultra 7模式都有的情况下闪烁
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
6930
在线时间
708 小时
注册时间
2021-3-5
帖子
814
8
 楼主| 发表于 2021-5-17 11:59:12 | 只看该作者

我在世界地图上试过,不会闪烁

但我不知道他说的大地图,是大到什么程度,世界地图算不算大地图
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
18572
在线时间
1029 小时
注册时间
2019-3-5
帖子
1418
9
发表于 2021-5-17 12:44:47 | 只看该作者
RyanYe 发表于 2021-5-17 11:59
我在世界地图上试过,不会闪烁

但我不知道他说的大地图,是大到什么程度,世界地图算不算大地图 ...

超7模式应该是指另一个插件(3D)渲染,就是不知道这个大地图是不是也是指另外一个插件……
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3426
在线时间
480 小时
注册时间
2010-8-21
帖子
81
10
发表于 2021-5-17 16:42:15 | 只看该作者
我剛用了一下
你所謂的閃爍指的應該是他裡面有一種設定,你可以設定光的顏色循環
因為這樣的方事夏你就會看起來像閃爍一樣的效果吧

点评

有这个设定,虽然渐变过程不太自然。不过上面说的闪耀是作者在帖子里写明的“已知bug”,显然不是指默认的设定了  发表于 2021-5-17 16:52
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-29 00:36

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表