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

Project1

 找回密码
 注册会员
搜索
楼主: VIPArcher
打印 上一主题 下一主题

[原创发布] 【玩家|事件吹出气泡式对话框】ver 1.0

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2779
在线时间
613 小时
注册时间
2018-1-17
帖子
1293
31
发表于 2018-4-1 17:21:34 | 只看该作者
promebrooks 发表于 2018-4-1 13:22
萌新询问,怎么使用这个插件命令。  大佬有截图么

作者说了是:
「对话内容中【文本中】使用\bm[ID](事件) 或者\bmf[ID] (角色) 吹出气泡。」
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
48
在线时间
4 小时
注册时间
2018-3-28
帖子
9
32
发表于 2018-4-3 09:20:31 | 只看该作者
2256538860 发表于 2018-4-1 17:20
兄弟 是这样使用的

还得麻烦大哥一下, 我试了一下还是不行,我把事件的设置、插件的设置、最终效果截图了。大佬能帮忙看看问题出在哪里吗?  
PS:我还开着YEP的messageCore 和这个有关系么

微信截图_20180403091509.png (88.61 KB, 下载次数: 26)

事件里设置如下

事件里设置如下

微信截图_20180403091638.png (148.11 KB, 下载次数: 26)

插件打开且设置如图所示

插件打开且设置如图所示

微信截图_20180403091624.png (109.03 KB, 下载次数: 26)

最终效果

最终效果
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2779
在线时间
613 小时
注册时间
2018-1-17
帖子
1293
33
发表于 2018-4-3 21:11:11 | 只看该作者
promebrooks 发表于 2018-4-3 09:20
还得麻烦大哥一下, 我试了一下还是不行,我把事件的设置、插件的设置、最终效果截图了。大佬能帮忙看看 ...

和那个没关系。设置来看应该是没错的。如果你真的想用这个的话就得
一个一个排查了.............论坛还有另外2个对话框插件。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
48
在线时间
4 小时
注册时间
2018-3-28
帖子
9
34
发表于 2018-4-8 08:24:39 | 只看该作者
2256538860 发表于 2018-4-3 21:11
和那个没关系。设置来看应该是没错的。如果你真的想用这个的话就得
一个一个排查了.............论坛还有 ...

好的  多谢 我再重新建立工程试试
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1044
在线时间
251 小时
注册时间
2016-9-2
帖子
126
35
发表于 2018-4-16 21:43:50 | 只看该作者
本帖最后由 雪在燃 于 2018-4-17 20:19 编辑


哇靠
这都能翻出来…
我居然遗忘了这个事,毕竟社畜 1个星期内必定撸个出来



更新,从js库翻出了这个版本,使用上有bug直接论坛呼我
版权当然是楼主大大所有
更新在楼下

点评

你终于看到了···谢谢!  发表于 2018-4-16 23:15
只支持横屏战斗,bm改为战斗角色,bmf仍然是普通角色  发表于 2018-4-16 22:29

评分

参与人数 1+1 收起 理由
2256538860 + 1 认可答案

查看全部评分

回复 支持 1 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2779
在线时间
613 小时
注册时间
2018-1-17
帖子
1293
36
发表于 2018-4-16 23:38:52 | 只看该作者
本帖最后由 2256538860 于 2018-4-16 23:39 编辑

@雪在燃 尝试了各种使用方法 绝对对话框还是处于底部 , 并未修改过js数据 复制35楼提供的原版的粘贴的
插件也只使用了这一个插件  请问这是什么问题~

N.png (101.83 KB, 下载次数: 24)

N.png

QQ截图20180416233654.png (163.05 KB, 下载次数: 20)

QQ截图20180416233654.png

- =.png (457.36 KB, 下载次数: 24)

- =.png

评分

参与人数 1+1 收起 理由
雪在燃 + 1 塞!

查看全部评分

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1044
在线时间
251 小时
注册时间
2016-9-2
帖子
126
37
发表于 2018-4-17 20:19:14 | 只看该作者
2256538860 发表于 2018-4-16 23:38
@雪在燃 尝试了各种使用方法 绝对对话框还是处于底部 , 并未修改过js数据 复制35楼提供的原版的粘贴的
插 ...

这个版本是从历史记录里面拿出来的,有问题很正常,直接call我就是
如果不回复的话可以尝试加我qq1396336279(一些脚本问题可以问我)

把原本的显示剔除了!
  1. //=============================================================================
  2. // VIPArcher_Bubble_Message.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc VIPArcher_气泡对话框
  6. * @author VIPArcher
  7. *
  8. * @param BubbleTagName
  9. * @desc 使用的气泡箭头素材文件名(请保存在 /img/system文件夹下)
  10. * @default BubbleTag
  11. *
  12. * @param TopMessageReviseY
  13. * @desc 气泡在人物上方时对话框Y轴的修正量(可以为负)
  14. * @default 0
  15. *
  16. * @param TopTagReviseY
  17. * @desc 气泡在人物上方时气泡箭头Y轴的修正量(可以为负)
  18. * @default 0
  19. *
  20. * @param BottomMessageReviseY
  21. * @desc 气泡在人物下方时对话框Y轴的修正量(可以为负)
  22. * @default 0
  23. *
  24. * @param BottomTagReviseY
  25. * @desc 气泡在人物下方时气泡箭头Y轴的修正量(可以为负)
  26. * @default 0
  27. *
  28. * @help 使用\BM[ID]来指定吹出气泡的事件ID。大小写不敏感。
  29. * ID 为 0 时代表本事件,为其他值时代表对应编号ID的事件。
  30. * 请确保吹出气泡的事件是存在的。
  31. *
  32. * 使用\BMF[ID]来指定吹出气泡的角色。大小写不敏感。
  33. * ID 为 0 时代表玩家,为其他值时代表对应编号跟随队员。
  34. * 请确保吹出气泡的角色是存在的。
  35. *
  36. * ver 1.0.0 最后更新于2015/12/19 最新版地址见:
  37. * https://github.com/VIPArcher/RMMV-JS
  38. */
  39. (function () {
  40.     var parameters = PluginManager.parameters('VIPArcher_Bubble_Message');
  41.     var topTagReviseY = String(parameters['TopTagReviseY'] || '0');
  42.     var bottomTagReviseY = String(parameters['BottomTagReviseY'] || '0');
  43.     var topMessageReviseY = String(parameters['TopMessageReviseY'] || '0');
  44.     var bottomMessageReviseY = String(parameters['BottomMessageReviseY'] || '0');
  45.     var bubbleTagName = String(parameters['BubbleTagName'] || 'BubbleTag');
  46.     function Window_Message_Face() {
  47.         this.initialize.apply(this, arguments);
  48.     };
  49.     Window_Message_Face.prototype = Object.create(Window_Base.prototype);
  50.     Window_Message_Face.prototype.constructor = Window_Message_Face;
  51.     Window_Message_Face.prototype.initialize = function (messageWindow) {
  52.         var width = this.windowWidth();
  53.         var height = this.windowHeight();
  54.         this._messageWindow = messageWindow;
  55.         Window_Base.prototype.initialize.call(this, 0, 0, width, height);
  56.         this._faceBitmap = null;
  57.         this.visible = false;
  58.         this.opacity = 0;
  59.     };
  60.     Window_Message_Face.prototype.windowWidth = function () {
  61.         return 180;
  62.     };
  63.     Window_Message_Face.prototype.windowHeight = function () {
  64.         return 180;
  65.     };
  66.     Window_Message_Face.prototype.updateLoading = function () {
  67.         if (this._faceBitmap) {
  68.             if (ImageManager.isReady()) {
  69.                 this.drawMessageFace();
  70.                 this._faceBitmap = null;
  71.                 return false;
  72.             } else { return true; };
  73.         } else { return false; };
  74.     };
  75.     Window_Message_Face.prototype.loadMessageFace = function () {
  76.         this._faceBitmap = ImageManager.loadFace($gameMessage.faceName());
  77.     };
  78.     Window_Message_Face.prototype.drawMessageFace = function () {
  79.         this.drawFace($gameMessage.faceName(), $gameMessage.faceIndex(), 0, 0);
  80.     };
  81.     Window_Message_Face.prototype.update = function () {
  82.         Window_Base.prototype.update.call(this);
  83.         this.updateLoading();
  84.         if (this.contentsOpacity < 255) { this.contentsOpacity += 15 };
  85.         if (this.move_x >= 0) {
  86.             this.x += 4;
  87.             this.move_x -= 4;
  88.         }
  89.     };
  90.     Window_Message_Face.prototype.setFace = function () {
  91.         this.contents.clear();
  92.         if (!!this._messageWindow && $gameMessage.faceName() != '') {
  93.             this.loadMessageFace();
  94.             this.setPosition();
  95.             this.show();
  96.             this.open();
  97.         } else { this.hide(); };
  98.     };
  99.     Window_Message_Face.prototype.setPosition = function () {
  100.         this.y = this._messageWindow.height - this.windowHeight();
  101.         this.contentsOpacity = 0;
  102.         if (this.face_name != $gameMessage.faceName() || this.face_index != $gameMessage.faceIndex()) {
  103.             if (!!this._messageWindow._event_pop_id || this._messageWindow._event_pop_id === 0) {
  104.                 this.x = -60;
  105.                 this.move_x = 60;
  106.             };
  107.             this.face_name = $gameMessage.faceName();
  108.             this.face_index = $gameMessage.faceIndex();
  109.         };
  110.     };
  111.     var _messageWindowUpdateOpen = Window_Message.prototype.updateOpen;
  112.     Window_Message.prototype.updateOpen = function () {
  113.         if (SceneManager._scene.constructor === Scene_Map || SceneManager._scene.constructor === Scene_Battle) { //判断地图
  114.             if (this._opening) { //判断是否正在打开
  115.                 this.openness += 32;
  116.                 if (this.isOpen()) {
  117.                     this._opening = false;
  118.                     if (this._messageBubbleTag._isShow) {
  119.                         this._messageBubbleTag.visible = true;
  120.                         this._messageBubbleTag._isShow = false;
  121.                     };
  122.                 };
  123.             };
  124.         } else {
  125.             _messageWindowUpdateOpen.call(this);
  126.         };
  127.     };
  128.     var _messageWindowClose = Window_Message.prototype.close;
  129.     Window_Message.prototype.close = function () {//关闭资源
  130.         _messageWindowClose.call(this);
  131.         if (SceneManager._scene.constructor === Scene_Map || SceneManager._scene.constructor === Scene_Battle) {
  132.             this._messageBubbleTag.visible = false;
  133.             this._faceWindow.contents.clear();
  134.             this._faceWindow.close();
  135.         };
  136.     };
  137.     var _messageWindowInitialize = Window_Message.prototype.initialize
  138.     Window_Message.prototype.initialize = function () {//初始化
  139.         _messageWindowInitialize.call(this);
  140.         this._faceWindow = new Window_Message_Face(this);
  141.         this.addChild(this._faceWindow);
  142.     };
  143.     var _messageWindowUpdate = Window_Message.prototype.update
  144.     Window_Message.prototype.update = function () { //更新
  145.         _messageWindowUpdate.call(this);
  146.         if (this._faceWindow) { this._faceWindow.update() };
  147.     };
  148.     var _createMessageWindowBubbleTag = Scene_Map.prototype.createMessageWindow
  149.     Scene_Map.prototype.createMessageWindow = function () {        //创建对话窗口
  150.         _createMessageWindowBubbleTag.call(this);
  151.         //创建精灵类
  152.         var bubbleTag = new Sprite();
  153.         bubbleTag.bitmap = ImageManager.loadSystem(bubbleTagName);
  154.         this._messageWindow._messageBubbleTag = bubbleTag;
  155.         this.addChild(bubbleTag);
  156.         this._messageWindow._messageBubbleTag.visible = false;
  157.     };
  158.     var _battleCreateWindowBubbleTag = Scene_Battle.prototype.createMessageWindow;
  159.     Scene_Battle.prototype.createMessageWindow = function () {
  160.         _battleCreateWindowBubbleTag.call(this);
  161.         var bubbleTag = new Sprite();
  162.         bubbleTag.bitmap = ImageManager.loadSystem(bubbleTagName);
  163.         this._messageWindow._messageBubbleTag = bubbleTag;
  164.         this.addChild(bubbleTag);
  165.         this._messageWindow._messageBubbleTag.visible = false;
  166.     }
  167.     var _convertEscapeCharacters = Window_Message.prototype.convertEscapeCharacters;
  168.     Window_Message.prototype.convertEscapeCharacters = function (text) {
  169.         this.resetWindowMessage();
  170.         text = _convertEscapeCharacters.call(this, text);
  171.         text = text.replace(/\x1bBM\[(\d+)\]/gi, function () {
  172.             console.log("测试1");
  173.             return this.event_pop_message_setup(parseInt(arguments[1]));
  174.         }.bind(this));
  175.         text = text.replace(/\x1bBMF\[(\d+)\]/gi, function () {
  176.             return this.event_pop_message_setup(parseInt(arguments[1]), true);
  177.         }.bind(this));
  178.         text = text.replace(/\x1bCBM/gi, function () {
  179.             return this.event_pop_message_setup(false, true);
  180.         }.bind(this));
  181.         return text;
  182.     };
  183.     function getCharacter(id, isActor) {
  184.         function obj_fun(c){
  185.             this.x = 0;
  186.             this.y = 0;
  187.         }
  188.         obj_fun.prototype.screenX = function(){
  189.             return this.x;
  190.         }
  191.         obj_fun.prototype.screenY = function(){
  192.             return this.y;
  193.         }
  194.         if (isActor) {
  195.             var temp = SceneManager._scene._spriteset._actorSprites[id];
  196.             var obj = new obj_fun(temp);
  197.             obj.x = temp._homeX;
  198.             obj.y = temp._homeY;
  199.             obj.height = 85;
  200.             return obj;
  201.         } else {
  202.             var temp = SceneManager._scene._spriteset._enemySprites[id];
  203.             var obj = new obj_fun(temp);
  204.             obj.x = temp._homeX;
  205.             obj.y = temp._homeY;
  206.             obj.height = temp.height;
  207.             return obj;
  208.         }
  209.     }
  210.     var _updatePlacement = Window_Message.prototype.updatePlacement;
  211.     Window_Message.prototype.updatePlacement = function () {
  212.         if (SceneManager._scene.constructor === Scene_Map) {
  213.             if (this._event_pop_id === 0) {
  214.                 this._character = !!this._follower ? $gamePlayer : $gameMap.event($gameMap._interpreter.eventId());
  215.                 this.popSetPopPlacement(this._character);
  216.             } else if (this._event_pop_id > 0) {
  217.                 if (!!this._follower) {
  218.                     this._character = $gamePlayer.followers().follower(this._event_pop_id - 1);
  219.                 } else {
  220.                     this._character = $gameMap.event(this._event_pop_id);
  221.                 }; this.popSetPopPlacement(this._character);
  222.             } else {
  223.                 _updatePlacement.call(this);
  224.             };
  225.         } else if (SceneManager._scene.constructor === Scene_Battle) {
  226.             if (this._event_pop_id === 0 || this._event_pop_id > 0) {
  227.                 this._character = getCharacter(this._event_pop_id, !!this._follower);
  228.                 this.popSetPopPlacement(this._character,true);
  229.             } else {
  230.                 _updatePlacement.call(this);
  231.             };
  232.         }
  233.         else {
  234.             _updatePlacement.call(this);
  235.         };
  236.         if (this._faceWindow) {
  237.             this._faceWindow.setFace();
  238.         };
  239.     };
  240.     Window_Message.prototype.resetWindowMessage = function () {
  241.         this.x = 0;
  242.         this._follower = false;
  243.         this._character = false;
  244.         this._event_pop_id = false;
  245.         this.width = this.windowWidth();
  246.         this.height = this.windowHeight();
  247.     }
  248.     Window_Message.prototype.event_pop_message_setup = function (event_id, follower) {
  249.         if (follower && !$gamePlayer.followers().follower(event_id - 1)) {
  250.             this._event_pop_id = follower ? 0 : false;
  251.             this._follower = true;
  252.         } else {
  253.             this._event_pop_id = event_id;
  254.             this._follower = follower;
  255.         }; return "";
  256.     };
  257.     Window_Message.prototype.popSetPopPlacement = function (character, isBattle) {
  258.         var setHeight = 60;
  259.         if (isBattle) {
  260.             setHeight = character.height;
  261.         }
  262.         this.popcaltextStateHW($gameMessage.allText());
  263.         this._messageBubbleTag._isShow = true;
  264.         var x = character.screenX() - this.width / 2;
  265.         var endX = character.screenX() + this.width / 2;
  266.         this.x = x > 0 ? x : 0;
  267.         if (endX > Graphics.boxWidth) { this.x = Graphics.boxWidth - this.width };
  268.         this._bubblePosTag = character.screenY() > Graphics.boxHeight / 2 ? true : false;
  269.         if (this._bubblePosTag) {
  270.             this.y = character.screenY() - this.height - setHeight + parseInt(topMessageReviseY);
  271.             this._messageBubbleTag.y = character.screenY() - (setHeight+5) + parseInt(topTagReviseY);
  272.         } else {
  273.             this.y = character.screenY() + 14 + parseInt(bottomMessageReviseY);
  274.             this._messageBubbleTag.y = character.screenY() + parseInt(bottomTagReviseY);
  275.         };
  276.         this.setBubbleTag(character);
  277.     };
  278.     Window_Message.prototype.setBubbleTag = function (character) {
  279.         var width = this._messageBubbleTag.width;
  280.         var height = this._messageBubbleTag.bitmap.height / 2;
  281.         var y = !this._bubblePosTag ? height : 0;
  282.         this._opening = true;
  283.         this._messageBubbleTag.setFrame(0, y, width, height);
  284.         this._messageBubbleTag.x = character.screenX() - width / 2;
  285.     };
  286.     Window_Message.prototype.popcaltextStateHW = function (text) {
  287.         var leftX = $gameMessage.faceName() === '' ? 0 : 172;
  288.         var textState = { index: 0, x: leftX, y: 0, width: 0, left: leftX };
  289.         textState.text = this.convertEscapeCharacters(text);
  290.         textState.y = this.calcTextHeight(textState, false);
  291.         while (textState.index < textState.text.length) {
  292.             this.popReadCharacter(textState);
  293.         };
  294.         this.resetFontSettings();
  295.         this.height = textState.height + 36;
  296.         this.width = textState.width + 36;
  297.     };
  298.     Window_Message.prototype.popReadCharacter = function (textState) {
  299.         switch (textState.text[textState.index]) {
  300.             case '\n':
  301.                 textState.x = textState.left;
  302.                 textState.y += this.calcTextHeight(textState, false);
  303.                 textState.index++;
  304.                 break;
  305.             case '\f':
  306.                 textState.index++;
  307.                 break;
  308.             case '\x1b':
  309.                 switch (this.obtainEscapeCode(textState)) {
  310.                     case 'C':
  311.                         this.obtainEscapeParam(textState);
  312.                         break;
  313.                     case 'I':
  314.                         this.obtainEscapeParam(textState);
  315.                         textState.x += Window_Base._iconWidth + 4;
  316.                         break;
  317.                     case '{':
  318.                         if (this.contents.fontSize <= 96) { this.contents.fontSize += 12; };
  319.                         break;
  320.                     case '}':
  321.                         if (this.contents.fontSize >= 24) { this.contents.fontSize -= 12; };
  322.                         break;
  323.                 };
  324.                 break;
  325.             default:
  326.                 textState.x += this.textWidth(textState.text[textState.index++]);
  327.                 textState.width = textState.width > textState.x ? textState.width : textState.x;
  328.                 textState.height = textState.height > textState.y ? textState.height : textState.y;
  329.                 break;
  330.         };
  331.     };
  332.     var _drawMessageFace = Window_Message.prototype.drawMessageFace;
  333.     Window_Message.prototype.drawMessageFace = function () { };
  334. })();
复制代码
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1486
在线时间
148 小时
注册时间
2017-8-18
帖子
116
38
发表于 2018-4-21 15:05:23 | 只看该作者
对话弹出来的时候,猪脚不能移动,这个怎么办呢?可否在npc弹出对话框时,
猪脚可以自由移动呢?
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1486
在线时间
148 小时
注册时间
2017-8-18
帖子
116
39
发表于 2018-4-23 18:26:26 | 只看该作者
本帖最后由 lqsg123 于 2018-4-23 18:28 编辑

大佬,和这个半身像的插件冲突啊!

  1. //=============================================================================
  2. // Terrax Plugins - Lighting system
  3. // TerraxLighting.js
  4. // Version: 1.5.1
  5. //=============================================================================
  6. //
  7. // This script overwrites the following core scripts.
  8. //
  9. // Spriteset_Map.prototype.createLowerLayer
  10. //
  11. //=============================================================================
  12. /*:
  13. * @plugindesc v1.5.1 Creates an extra layer that darkens a map and adds lightsources!
  14. * @author Terrax
  15. *
  16. * @param Player radius
  17. * @desc Adjust the light radius around the player
  18. * Default: 300
  19. * @default 300
  20. *
  21. * @param Add to options
  22. * @desc Adds switching the script on of off to the options menu
  23. * Default: Yes
  24. * @default Yes
  25. *
  26. * @param Option menu entry
  27. * @desc Text item used in the option menu (change for different language)
  28. * Default: Lighting effects
  29. * @default Lighting effects
  30. *
  31. * @param Reset Lights
  32. * @desc Resets the light switches each map
  33. * Default: No
  34. * @default No
  35. *
  36. * @param Save DaynightHours
  37. * @desc Game variable the time of day (0-23) can be stored in
  38. * Default: 0
  39. * @default 0
  40. *
  41. * @param Save DaynightMinutes
  42. * @desc Game variable the time of day (0-59) can be stored in
  43. * Default: 0
  44. * @default 0
  45. *
  46. * @param Save DaynightSeconds
  47. * @desc Game variable the time of day (0-59) can be stored in
  48. * Default: 0
  49. * @default 0
  50. *
  51. * @param Flashlight offset
  52. * @desc Increase this setting to move up the flashlight for double height characters.
  53. * Default: 0
  54. * @default 0
  55. *
  56. * @param Screensize X
  57. * @desc Increase if your using a higher screen resolution then the default
  58. * Default : 866
  59. * @default 866
  60. *
  61. * @param Screensize Y
  62. * @desc Increase if your using a higher screen resolution then the default
  63. * Default : 630
  64. * @default 630
  65. *
  66. * @param Kill Switch
  67. * @desc Possible values A,B,C,D. If Selfswitch X is switched ON, the events lightsource will be disabled.
  68. * Default : No
  69. * @default No
  70. *
  71. * @help
  72. * To activate the script in an area, do the following:
  73. * 1. Put an event switch into the map.
  74. * 2. In the 'Note' field (Next to the name) put the following text :
  75. * Light 250 #FFFFFF
  76. * - Light activates the script
  77. * - 250 is the lightradius of the object
  78. * - #FFFFFF is the lightcolor (white in this case)
  79. * 3. You're done, its that simple.
  80. *
  81. * You can add two optional commands for brightness and direction
  82. * Light 200 #FFFFFF B50 increases the brightness with 50%. Value between 0 and 99.
  83. * Light 200 #FFFFFF D1 will give half a lightglobe for lightsources placed on walls.
  84. * 1. For lights on north walls, light will face down.
  85. * 2. For lights on east walls, light will face west.
  86. * 3. For lights on south walls, light will face north.
  87. * 4. For lights on west walls, light will face east.
  88. *
  89. * To alter the player radius in game use the following plugin command :
  90. * Light radius 200 #FFFFFF  (to change the radius and the color)
  91. * If you want to change the player radius slowly over time (like a dying torch)
  92. * use the command 'Light radiusgrow 200 #FFFFFF'
  93. * You can alter the brightness of the players lightsource by adding:
  94. * 'Light radius 200 #FFFFFF B70' (Brightness values between 0 and 99, 0 is default)
  95. *
  96. * To turn on and off lightsources in the game, do the following:
  97. * Give the lightsource the normal def :  Light 250 #FFFFFF and an extra number
  98. * so it becomes 'Light 250 #FFFFFF 1'
  99. * (If your using the optional brightness and direction place it after those (Light 250 #FFFFFF B50 D2 1)
  100. * To turn on this light use plugin command : 'Light on 1'.
  101. * The plugin command will also trigger SelfSwitch 'D' on the targeted light(s).
  102. * To turn off the light use plugin command : 'Light off 1'.
  103. * You can reset the switches each map with the option or manualy by
  104. * the plugin command 'Light switch reset'
  105. * You can also turn off lights with the kill-selfswitch defined in the parameters.
  106. * You can change the color of the lightsources that have a id. Use plugin call
  107. * 'Light color 1 #FF0000'
  108. *
  109. * You can let the light color cycle automaticly with the following note-tag
  110. * Light cycle #FF0000 50 #00FF00 50 #0000FF 50
  111. * This will let the color cycle from red to green to blue, each 50 miliseconds.
  112. * Minimum of 2 colors, maximum of 4 colors.
  113. *
  114. * Replacing the 'Light' keyworld with 'Fire' will give the lights a subtle flicker
  115. * You can configure the fire effect with the plugin command 'SetFire 7 10'
  116. * Where 7 is the radius change and 10 is the shift in color from red to yellow.
  117. *
  118. * To completly turn off the script use : 'Light deactivate'
  119. * To turn it on again use the command: 'Light activate'
  120. *
  121. * To activate a day-night cycle on a map, put in a trigger with 'DayNight' in an event note
  122. * or in the map note.
  123. * Plugin command 'Daynight speed 10' changes the speed.
  124. * Speed 10 means it takes 10 seconds to to pass one hour in game (probably to fast)
  125. * Plugin command 'Daynight hour 16 30' sets the hour to 16:30 hours
  126. * Each hour has its own color value.
  127. * Plugin command 'Daynight color 0 #222222' changes 0:00 hours to color value '#222222'
  128. * You can add time with the plugin command 'Daynight add 8 30' (this adds 8 hours and 30 minutes)
  129. *
  130. * If you want to use the time of day to trigger effects (like turning on lights when it gets dark)
  131. * you can use the parameters 'Save DaynightHours','Save DaynightMinutes','Save DaynightSeconds'
  132. * The default is 0, which means its off.
  133. * If you set it to a value,5 for example, it will store the daynight value inside game variable 5.
  134. * You can then use that variable to trigger lights.
  135. * To help syncing/debugging the time system you can use scriptcommand 'daynight debug' to display the current time.
  136. * If you want to go 'alien world' and stuff, you can change the number of hours in a day with
  137. * script command 'daynight hoursinday 48' (for 48 hours in day, don't forget to fill in the hour values)
  138. *
  139. * As an alternative to the daynight cycle you can use the tint system. If you want to use another plugin for the
  140. * day/night cycle, the tint option is probably best to use.
  141. * The plugin command 'Tint set #333333' will make the room less dark.
  142. * The plugin command 'Tint fade #777777 5' will fade the color from the current color to the new, the last
  143. * number (5) is the speed of the fade, were 1 is a fast fade and 20 is a very slow one.
  144. * If an area has a daynight cycle system, the tint system is disabled.
  145. *
  146. * To use a flashlight effect use 'Flashlight on 8 12 #FFFFFF 3' and 'Flashlight off'
  147. * The arguments are optional (8=beamlength, 12=beamwidth, #FFFFFF=color, 3=beam density)
  148. * Events can also use the flashlight effect. Use 'Flashlight 8 12 #888888 1 2' in the note-tag.
  149. * where 8 is the length of the flashlights beam and 12 is the width of the beam. The last numbers are
  150. * optional and can be used to turn the NPC's flashlight on or off and set the direction of the beam
  151. * if the event is not moving (1=up, 2=right, 3=down, 4=left) the default is down.
  152. *
  153. * TileLight and RegionLight settings
  154. * To create lightsources without using events you can use the following plugin command.
  155. * TileLight 1 ON #FFFFFF 150  Will create a lightsource (color #FFFFFF radius 150) on all tiles with tile-tag 1.
  156. * TileRegion 1 ON #FFFFFF 150 Will create a lightsource on all tiles with region-number 1.
  157. * You can increase the brightness of a lightsource with the optional TileRegion 1 ON #FFFFFF 150 B50  (for 50% increased brightness)
  158. * TileLight 1 OFF will turn off the lights on tile-tag 1 again
  159. * TileRegion 1 OFF will turn off the lights on region-number 1 again  
  160. * TileFire and RegionFire works the same as TileLight, but with fire effect.
  161. * TileGlow and RegionGlow works the same as TileLight, but with a slight pulsing effect.
  162. * Make sure your map still has at least one event with lights in it, otherwise the script will not run.
  163. *
  164. * TileBlock and RegionBlock settings
  165. * To block lights on certain tiles (roofs for instance) you can use the following plugin command.
  166. * TileBlock 1 ON #000000  Will block light on tiles with tile-tag 1.
  167. * RegionBlock 1 ON #000000 Will block lights on tiles with region-number 1.
  168. * TileBlock 1 OFF and TileRegion 1 OFF turns off the blocking again.
  169. * To darken but not completly block light use a slightly higher color setting (#333333) for instance.
  170. * This function does not raytrace. If the players lightradius is bigger then the blocking tiles the
  171. * light will show on the other side. For the best effect keep the lightradius a bit smaller then the block section.
  172. * for advance users, if you want to block more or less of the tile you can do the following
  173. * RegionBlock 1 ON #000000 shape xoffset yoffset width height
  174. * RegionBlock 1 ON #000000 1 20 20 10 10   -> this will block a box starting at 20,20 with width and height 10,10
  175. * RegionBlock 1 ON #000000 2 20 20 10 10   -> this will block a oval starting at 20,20 with xradius 10 and yradius 10
  176. *
  177. * You can use the following plugin calls to create short duration light effects for explosions or spells.
  178. * plugin command: effect_on_event 003 200 #FFAAAA 50
  179. * -> Will create a lightglobe on event with id 003, Radius 200, color #FFAAAA, duration 50 frames
  180. * plugin command: effect_on_xy 560 500 50 #FFAAAA 25
  181. * -> Will create a lightglobe on coordinates 560,500, Radius 50, color #FFAAAA, duration 25 frames
  182. * A number of special effects can be added, explained in the manual
  183. * Terrax lighting system is compatible with the Moghunter time system, for specifics see the read-me.
  184. *
  185. * Released under the MIT license,
  186. * if used for commercial projects feel free to make a donation or
  187. * better yet, give me a free version of what you have created.
  188. * e-mail : fox(AT)caiw.nl / terraxz2 on steam.
  189. *
  190. * Thanks to everyone in the rpgmakerweb community for idea's, support and interest.
  191. * Special thanks to Galv for solving some problems.
  192. */
  193. //=============================================================================
  194. //  ps.. if my code looks funky, i'm an old guy..
  195. // object orientated programming bugs the hell out of me.
  196. var Imported = Imported || {};
  197. Imported.TerraxLighting = true;

  198.         // These are global variables so they can be used by other plugins

  199.         var Terrax_tint_speed = 60;
  200.         var Terrax_tint_target = '#000000';

  201.         var Terrax_ABS_skill_x = [];
  202.         var Terrax_ABS_skill_y = [];
  203.         var Terrax_ABS_skill = [];

  204.         var Terrax_ABS_blast_x = [];
  205.         var Terrax_ABS_blast_y = [];
  206.         var Terrax_ABS_blast = [];
  207.         var Terrax_ABS_blast_duration = [];
  208.         var Terrax_ABS_blast_fade = [];
  209.         var Terrax_ABS_blast_grow = [];
  210.         var Terrax_ABS_blast_mapid = [];


  211. (function() {

  212.         var colorcycle_count = [1000];
  213.         var colorcycle_timer = [1000];

  214.         var event_note = [];
  215.         var event_id = [];
  216.         var event_x = [];
  217.         var event_y = [];
  218.         var event_dir = [];
  219.         var event_moving = [];
  220.         var event_stacknumber = [];
  221.         var event_eventcount = 0;

  222.         var tile_lights = [];
  223.         var tile_blocks = [];


  224.         var parameters = PluginManager.parameters('TerraxLighting');
  225.     var player_radius = Number(parameters['Player radius']);
  226.         var reset_each_map = parameters['Reset Lights'] || 'No';
  227.         var daynightsavehours = Number(parameters['Save DaynightHours'] || 10);
  228.         var daynightsavemin = Number(parameters['Save DaynightMinutes'] || 11);
  229.         var daynightsavesec = Number(parameters['Save DaynightSeconds'] || 12);
  230.         var flashlightoffset = Number(parameters['Flashlight offset'] || 0);
  231.         var killswitch = parameters['Kill Switch'] || 'No';
  232.         var add_to_options = parameters['Add to options'] || 'Yes';
  233.         var optiontext = parameters['Option menu entry'] || 'Lighting effects';
  234.         var options_lighting_on = true;

  235.         var maxX = Number(parameters['Screensize X'] || 866);
  236.         var maxY = Number(parameters['Screensize Y'] || 630);

  237.         // global timing variables
  238.         var tint_oldseconds=0;
  239.         var tint_timer=0;
  240.         var moghunter_phase = -1;
  241.         var oldmap = 0;
  242.         var oldseconds = 0;
  243.         var oldseconds2 = 0;
  244.         var daynightdebug = false;
  245.         var speeddebug = false;
  246.         var gamedebug = false;
  247.         var debugtimer = 0;
  248.         var event_reload_counter = 0;
  249.         var mogdebug = false;
  250.         var terrax_tint_speed_old = 60;
  251.         var terrax_tint_target_old = '#000000'
  252.         var tileglow = 0;
  253.         var glow_oldseconds =0;
  254.         var glow_dir = 1;
  255.         var cyclecolor_counter = 0;
  256.         var darkcount = 0;
  257.         var daynightset = false;
  258.         var averagetime = [];
  259.         var averagetimecount = 0;

  260.     var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  261.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  262.         _Game_Interpreter_pluginCommand.call(this, command, args);
  263.                 if (typeof command != 'undefined') {
  264.                         command = command.toLowerCase();


  265.                         // ************* TILE TAGS ***************
  266.                         if (command === 'tileblock' || command === 'regionblock' || command === 'tilelight' || command === 'regionlight' || command === 'tilefire' || command === 'regionfire' || command === 'tileglow' || command === 'regionglow') {

  267.                                 var tilearray = $gameVariables.GetTileArray();

  268.                                 var tiletype = 0;
  269.                                 if (command === 'tileblock') {
  270.                                         tiletype = 1;
  271.                                 }
  272.                                 if (command === 'regionblock') {
  273.                                         tiletype = 2;
  274.                                 }
  275.                                 if (command === 'tilelight') {
  276.                                         tiletype = 3;
  277.                                 }
  278.                                 if (command === 'regionlight') {
  279.                                         tiletype = 4;
  280.                                 }
  281.                                 if (command === 'tilefire') {
  282.                                         tiletype = 5;
  283.                                 }
  284.                                 if (command === 'regionfire') {
  285.                                         tiletype = 6;
  286.                                 }
  287.                                 if (command === 'tileglow') {
  288.                                         tiletype = 7;
  289.                                 }
  290.                                 if (command === 'regionglow') {
  291.                                         tiletype = 8;
  292.                                 }

  293.                                 //var tilenumber = Number(args[0]);
  294.                                 var tilenumber = Number(eval(args[0]));
  295.                                 var tile_on = 0;
  296.                                 if (args[1] === 'on' || args[1] === 'ON') {
  297.                                         tile_on = 1;
  298.                                 }
  299.                                 var tilecolor = args[2];
  300.                                 var isValidColor1 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(tilecolor);
  301.                                 if (!isValidColor1) {
  302.                                         if (tiletype === 1 || tiletype === 2) {
  303.                                                 tilecolor = '#000000';
  304.                                         } else {
  305.                                                 tilecolor = '#FFFFFF';
  306.                                         }
  307.                                 }

  308.                                 var tileradius = 100;
  309.                                 var tilebrightness = 0.0;
  310.                                 var shape = 0;
  311.                                 var x1 = 0;
  312.                                 var y1 = 0;
  313.                                 var x2 = 0;
  314.                                 var y2 = 0;
  315.                                 if (tiletype === 1 || tiletype === 2) {
  316.                                         if (args.length > 3) {
  317.                                                 shape = args[3];
  318.                                         }
  319.                                         if (args.length > 4) {
  320.                                                 x1 = args[4];
  321.                                         }
  322.                                         if (args.length > 5) {
  323.                                                 y1 = args[5];
  324.                                         }
  325.                                         if (args.length > 6) {
  326.                                                 x2 = args[6];
  327.                                         }
  328.                                         if (args.length > 7) {
  329.                                                 y2 = args[7];
  330.                                         }
  331.                                 } else {
  332.                                         if (args.length > 3) {
  333.                                                 tileradius = args[3];
  334.                                         }
  335.                                         if (args.length > 4) {
  336.                                                 tilebrightness = args[4];
  337.                                         }
  338.                                 }

  339.                                 var tilefound = false;

  340.                                 for (var i = 0; i < tilearray.length; i++) {
  341.                                         var tilestr = tilearray[i];
  342.                                         var tileargs = tilestr.split(";");
  343.                                         if (tileargs[0] == tiletype && tileargs[1] == tilenumber) {
  344.                                                 tilefound = true;
  345.                                                 if (tiletype === 1 || tiletype === 2) {
  346.                                                         tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
  347.                                                 } else {
  348.                                                         tilearray[i] = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
  349.                                                 }
  350.                                                 //Graphics.Debug('Set',tilearray[i]);
  351.                                         }
  352.                                 }

  353.                                 if (tilefound === false) {
  354.                                         var tiletag = "";
  355.                                         if (tiletype === 1 || tiletype === 2) {
  356.                                                 tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + shape + ";" + x1 + ";" + y1 + ";" + x2 + ";" + y2;
  357.                                         } else {
  358.                                                 tiletag = tiletype + ";" + tilenumber + ";" + tile_on + ";" + tilecolor + ";" + tileradius + ";" + tilebrightness;
  359.                                         }
  360.                                         tilearray.push(tiletag);
  361.                                         //Graphics.Debug('Push',tiletag);
  362.                                 }
  363.                                 $gameVariables.SetTileArray(tilearray);
  364.                                 ReloadTagArea();
  365.                                 //Graphics.Debug('tile length',tile_lights.length);
  366.                         }
  367.                         // ************* TINT  *******************
  368.                         if (command === 'tint') {

  369.                                 if (args[0] === 'set') {
  370.                                         //var tint_value = args[1];
  371.                                         $gameVariables.SetTint(args[1]);
  372.                                         $gameVariables.SetTintTarget(args[1]);
  373.                                 }
  374.                                 if (args[0] === 'fade') {
  375.                                         //var Tint_target = args[1];
  376.                                         //var Tint_speed = args[2];
  377.                                         $gameVariables.SetTintTarget(args[1]);
  378.                                         $gameVariables.SetTintSpeed(args[2]);
  379.                                 }

  380.                                  //Graphics.Debug('TINT',args[1]+' '+args[1]+' '+args[2]);
  381.                         }

  382.                         // ************* MOGHUNTER TIMESYSTEM COMPATIBLE  *******************
  383.                         if (command === 'tls_moghunter') {
  384.                                 if (args[0] === 'on') {
  385.                                         //moghunter = true;
  386.                                         $gameVariables.SetMog(true);
  387.                                 }
  388.                                 if (args[0] === 'off') {
  389.                                         //moghunter = false
  390.                                         $gameVariables.SetTint('#000000');
  391.                                         $gameVariables.SetMog(false);
  392.                                 }
  393.                                 if (args[0] === 'tint') {

  394.                                         if (args.length == 7) {
  395.                                                 var mogtint = $gameVariables.GetMogTintArray();
  396.                                                 for (var i = 0; i <= 5; i++) {
  397.                                                         var tintcolor = args[i];
  398.                                                         var isValidColor3 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(tintcolor);
  399.                                                         if (isValidColor3 == true) {
  400.                                                                 mogtint[i] = tintcolor;
  401.                                                                 //Graphics.Debug('TEST',tintcolor);
  402.                                                                 $gameVariables.SetMogTintArray(mogtint);
  403.                                                         }
  404.                                                 }
  405.                                         }
  406.                                 }
  407.                                 if (args[0] === 'debug') {
  408.                                         mogdebug = true;
  409.                                 }
  410.                         }

  411.                         // ************* DAYNIGHT *******************
  412.                         if (command === 'daynight') {

  413.                                 var daynightspeed = $gameVariables.GetDaynightSpeed();
  414.                                 var daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  415.                                 var daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  416.                                 var daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24
  417.                                 var daynightcolors = $gameVariables.GetDaynightColorArray();

  418.                                 if (args[0] === 'speed') {
  419.                                         daynightspeed = Number(args[1]);
  420.                                         if (daynightspeed <= 0) {
  421.                                                 daynightspeed = 5000;
  422.                                         }
  423.                                         $gameVariables.SetDaynightSpeed(daynightspeed);
  424.                                 }

  425.                                 if (args[0] === 'add') {
  426.                                         var houradd = Number(args[1]);
  427.                                         var minuteadd = 0;
  428.                                         if (args.length > 2) {
  429.                                                 minuteadd = Number(args[2]);
  430.                                         }

  431.                                         var daynightminutes = Math.floor(daynighttimer / daynightspeed);
  432.                                         daynightminutes = daynightminutes + minuteadd;
  433.                                         if (daynightminutes > 60) {
  434.                                                 daynightminutes = daynightminutes - 60;
  435.                                                 daynightcycle = daynightcycle + 1;
  436.                                         }
  437.                                         daynightcycle = daynightcycle + houradd;
  438.                                         daynighttimer = daynightminutes * daynightspeed;

  439.                                         if (daynightsavemin > 0) {
  440.                                                 $gameVariables.setValue(daynightsavemin, daynightminutes);
  441.                                         }
  442.                                         if (daynightcycle < 0) {
  443.                                                 daynightcycle = 0;
  444.                                         }
  445.                                         if (daynightcycle >= daynighthoursinday) {
  446.                                                 daynightcycle = daynightcycle - daynighthoursinday;
  447.                                         }
  448.                                         if (daynightsavehours > 0) {
  449.                                                 $gameVariables.setValue(daynightsavehours, daynightcycle);
  450.                                         }

  451.                                         $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  452.                                         $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours

  453.                                 }


  454.                                 if (args[0] === 'hour') {
  455.                                         daynightcycle = Number(args[1]);
  456.                                         if (args.length > 2) {
  457.                                                 daynightminutes = Number(args[2]);
  458.                                         } else {
  459.                                                 daynightminutes = 0;
  460.                                         }
  461.                                         daynighttimer = daynightminutes * daynightspeed;

  462.                                         if (daynightsavemin > 0) {
  463.                                                 $gameVariables.setValue(daynightsavemin, daynightminutes);
  464.                                         }
  465.                                         if (daynightcycle < 0) {
  466.                                                 daynightcycle = 0;
  467.                                         }
  468.                                         if (daynightcycle >= daynighthoursinday) {
  469.                                                 daynightcycle = (daynighthoursinday - 1);
  470.                                         }
  471.                                         if (daynightsavehours > 0) {
  472.                                                 $gameVariables.setValue(daynightsavehours, daynightcycle);
  473.                                         }

  474.                                         $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  475.                                         $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours

  476.                                 }

  477.                                 if (args[0] === 'hoursinday') {

  478.                                         var old_value = daynighthoursinday;
  479.                                         daynighthoursinday = Number(args[1]);
  480.                                         if (daynighthoursinday < 0) {
  481.                                                 daynighthoursinday = 0;
  482.                                         }
  483.                                         if (daynighthoursinday > old_value) {
  484.                                                 for (var i = old_value; i < daynighthoursinday; i++) {
  485.                                                         daynightcolors.push('#FFFFFF');
  486.                                                 }
  487.                                         }
  488.                                         $gameVariables.setDayNightColorArray(daynightcolors);
  489.                                         $gameVariables.setDayNightHoursInDay(daynighthoursinday);
  490.                                 }

  491.                                 if (args[0] === 'debug') {
  492.                                         daynightdebug = true;
  493.                                 }


  494.                                 if (args[0] === 'color') {

  495.                                         var hour = Number(args[1]);
  496.                                         if (hour < 0) {
  497.                                                 hour = 0;
  498.                                         }
  499.                                         if (hour >= daynighthoursinday) {
  500.                                                 hour = (daynighthoursinday - 1);
  501.                                         }
  502.                                         var hourcolor = args[2];
  503.                                         var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hourcolor);
  504.                                         if (isValidColor) {
  505.                                                 daynightcolors[hour] = hourcolor;
  506.                                         }
  507.                                         $gameVariables.SetDaynightColorArray(daynightcolors);
  508.                                 }


  509.                         }

  510.                         // ************* FLASHLIGHT *******************
  511.                         if (command === 'flashlight') {
  512.                                 if (args[0] == 'on') {

  513.                                         var flashlightlength = $gameVariables.GetFlashlightLength();
  514.                                         var flashlightwidth = $gameVariables.GetFlashlightWidth();
  515.                                         var flashlightdensity = $gameVariables.GetFlashlightDensity();
  516.                                         var playercolor = $gameVariables.GetPlayerColor();

  517.                                         if (args.length >= 1) {
  518.                                                 flashlightlength = args[1];
  519.                                         }
  520.                                         if (args.length >= 2) {
  521.                                                 flashlightwidth = args[2];
  522.                                         }
  523.                                         if (args.length >= 3) {
  524.                                                 playercolor = args[3];
  525.                                                 var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  526.                                                 if (!isValidPlayerColor) {
  527.                                                         playercolor = '#FFFFFF'
  528.                                                 }
  529.                                         }
  530.                                         if (args.length >= 4) {
  531.                                                 flashlightdensity = args[4]; // density
  532.                                         }

  533.                                         if (flashlightlength == 0 || isNaN(flashlightlength)) {
  534.                                                 flashlightlength = 8
  535.                                         }
  536.                                         if (flashlightwidth == 0 || isNaN(flashlightwidth)) {
  537.                                                 flashlightwidth = 12
  538.                                         }
  539.                                         if (flashlightdensity == 0 || isNaN(flashlightdensity)) {
  540.                                                 flashlightdensity = 3
  541.                                         }

  542.                                         $gameVariables.SetFlashlight(true);
  543.                                         $gameVariables.SetPlayerColor(playercolor);
  544.                                         $gameVariables.SetFlashlightWidth(flashlightwidth);
  545.                                         $gameVariables.SetFlashlightLength(flashlightlength);
  546.                                         $gameVariables.SetFlashlightDensity(flashlightdensity);

  547.                                 }
  548.                                 if (args[0] === 'off') {
  549.                                         $gameVariables.SetFlashlight(false);
  550.                                 }

  551.                         }

  552.                         // ******************* SET FIRE *******************
  553.                         if (command === 'setfire') {

  554.                                 flickerradiusshift = args[0];
  555.                                 flickercolorshift = args[1];
  556.                                 $gameVariables.SetFireRadius(flickerradiusshift);
  557.                                 $gameVariables.SetFireColorshift(flickercolorshift);
  558.                         }

  559.                         // ******************* FIRE *******************
  560.                         if (command === 'fire') {
  561.                                 $gameVariables.SetFire(true);
  562.                         } else {
  563.                                 $gameVariables.SetFire(false);
  564.                         }

  565.                         // ******************** MAIN PLAYER SETTINGS ***************
  566.                         if (command === 'light' || command === 'fire') {

  567.                                 //******************* Light radius 100 #FFFFFF ************************
  568.                                 if (args[0] == 'radius') {
  569.                                         var newradius = Number(args[1]);
  570.                                         if (newradius >= 0) {
  571.                                                 $gameVariables.SetRadius(newradius);
  572.                                                 $gameVariables.SetRadiusTarget(newradius);

  573.                                         }
  574.                                         if (args.length > 2) {
  575.                                                 playercolor = args[2];
  576.                                                 var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  577.                                                 if (!isValidPlayerColor) {
  578.                                                         playercolor = '#FFFFFF'
  579.                                                 }
  580.                                                 $gameVariables.SetPlayerColor(playercolor);
  581.                                         }
  582.                                         // player brightness
  583.                                         if (args.length > 3) {
  584.                                                 var brightness = 0.0;
  585.                                                 var b_arg = args[3];
  586.                                                 if (typeof b_arg != 'undefined') {
  587.                                                         var key = b_arg.substring(0, 1);
  588.                                                         if (key == 'b' || key == 'B') {
  589.                                                                 var brightness = Number(b_arg.substring(1)) / 100;
  590.                                                                 $gameVariables.SetPlayerBrightness(brightness);
  591.                                                         }
  592.                                                 }
  593.                                         }
  594.                                 }

  595.                                 //******************* Light radiusgrow 100 #FFFFFF ************************
  596.                                 if (args[0] === 'radiusgrow') {
  597.                                         var evid = this._eventId;
  598.                                         //Graphics.printError('test',evid);
  599.                                         var newradius = Number(args[1]);
  600.                                         if (newradius >= 0) {

  601.                                                 var lightgrow_value = $gameVariables.GetRadius();
  602.                                                 var lightgrow_target = newradius;
  603.                                                 var lightgrow_speed = 0.0;
  604.                                                 if (args.length >= 4) {
  605.                                                         if (player_radius > newradius) {
  606.                                                                 //shrinking
  607.                                                                 lightgrow_speed = (player_radius * 0.012) / Number(args[4]);
  608.                                                         } else {
  609.                                                                 //growing
  610.                                                                 lightgrow_speed = (newradius * 0.012) / Number(args[4]);
  611.                                                         }
  612.                                                 } else {
  613.                                                         lightgrow_speed = (Math.abs(newradius - player_radius)) / 500;
  614.                                                 }

  615.                                                 //Graphics.Debug('RADIUS GROW',player_radius+' '+lightgrow_value+' '+lightgrow_target+' '+lightgrow_speed);


  616.                                                 $gameVariables.SetRadius(lightgrow_value);
  617.                                                 $gameVariables.SetRadiusTarget(lightgrow_target);
  618.                                                 $gameVariables.SetRadiusSpeed(lightgrow_speed);
  619.                                         }
  620.                                         // player color
  621.                                         if (args.length > 2) {
  622.                                                 playercolor = args[2];
  623.                                                 var isValidPlayerColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);
  624.                                                 if (!isValidPlayerColor) {
  625.                                                         playercolor = '#FFFFFF'
  626.                                                 }
  627.                                                 $gameVariables.SetPlayerColor(playercolor);
  628.                                         }
  629.                                         // player brightness
  630.                                         if (args.length > 3) {
  631.                                                 var brightness = 0.0;
  632.                                                 var b_arg = args[3];
  633.                                                 if (typeof b_arg != 'undefined') {
  634.                                                         var key = b_arg.substring(0, 1);
  635.                                                         if (key == 'b' || key == 'B') {
  636.                                                                 brightness = Number(b_arg.substring(1)) / 100;
  637.                                                                 $gameVariables.SetPlayerBrightness(brightness);
  638.                                                         }
  639.                                                 }
  640.                                         }

  641.                                 }

  642.                                 // *********************** TURN SPECIFIC LIGHT ON *********************
  643.                                 if (args[0] === 'on') {

  644.                                         var lightarray_id = $gameVariables.GetLightArrayId();
  645.                                         var lightarray_state = $gameVariables.GetLightArrayState();
  646.                                         var lightarray_color = $gameVariables.GetLightArrayColor();

  647.                                         var lightid = Number(args[1]);
  648.                                         var idfound = false;
  649.                                         for (var i = 0; i < lightarray_id.length; i++) {
  650.                                                 if (lightarray_id[i] == lightid) {
  651.                                                         idfound = true;
  652.                                                         lightarray_state[i] = true;
  653.                                                         //Graphics.Debug('state id',i);
  654.                                                 }
  655.                                         }
  656.                                         if (idfound == false) {
  657.                                                 lightarray_id.push(lightid);
  658.                                                 lightarray_state.push(true);
  659.                                                 lightarray_color.push('defaultcolor');
  660.                                                 //Graphics.Debug('new state id',i);
  661.                                         }

  662.                                         //Graphics.Debug("lightarrays",lightarray_id.length+' '+lightarray_state.length+' '+lightarray_color.length )

  663.                                         $gameVariables.SetLightArrayId(lightarray_id);
  664.                                         $gameVariables.SetLightArrayState(lightarray_state);
  665.                                         $gameVariables.SetLightArrayColor(lightarray_color);
  666.                                 }

  667.                                 // *********************** TURN SPECIFIC LIGHT OFF *********************
  668.                                 if (args[0] === 'off') {

  669.                                         var lightarray_id = $gameVariables.GetLightArrayId();
  670.                                         var lightarray_state = $gameVariables.GetLightArrayState();
  671.                                         var lightarray_color = $gameVariables.GetLightArrayColor();

  672.                                         var lightid = Number(args[1]);
  673.                                         var idfound = false;
  674.                                         for (var i = 0; i < lightarray_id.length; i++) {
  675.                                                 if (lightarray_id[i] == lightid) {
  676.                                                         idfound = true;
  677.                                                         lightarray_state[i] = false;
  678.                                                 }
  679.                                         }
  680.                                         if (idfound == false) {
  681.                                                 lightarray_id.push(lightid);
  682.                                                 lightarray_state.push(false);
  683.                                                 lightarray_color.push('defaultcolor');
  684.                                         }
  685.                                         $gameVariables.SetLightArrayId(lightarray_id);
  686.                                         $gameVariables.SetLightArrayState(lightarray_state);
  687.                                         $gameVariables.SetLightArrayColor(lightarray_color);
  688.                                 }

  689.                                 // *********************** SET COLOR *********************

  690.                                 if (args[0] === 'color') {

  691.                                         var newcolor = args[2];

  692.                                         var lightarray_id = $gameVariables.GetLightArrayId();
  693.                                         var lightarray_state = $gameVariables.GetLightArrayState();
  694.                                         var lightarray_color = $gameVariables.GetLightArrayColor();

  695.                                         var lightid = Number(args[1]);
  696.                                         var idfound = false;
  697.                                         for (var i = 0; i < lightarray_id.length; i++) {
  698.                                                 if (lightarray_id[i] == lightid) {
  699.                                                         idfound = true;
  700.                                                         //lightarray_state[i] = true;
  701.                                                         lightarray_color[i] = newcolor;
  702.                                                 }
  703.                                         }

  704.                                         $gameVariables.SetLightArrayId(lightarray_id);
  705.                                         $gameVariables.SetLightArrayState(lightarray_state);
  706.                                         $gameVariables.SetLightArrayColor(lightarray_color);
  707.                                 }


  708.                                 // **************************** RESET ALL SWITCHES ***********************
  709.                                 if (args[0] === 'switch' && args[1] === 'reset') {

  710.                                         var lightarray_id = $gameVariables.GetLightArrayId();
  711.                                         var lightarray_state = $gameVariables.GetLightArrayState();
  712.                                         // reset switches to false
  713.                                         for (var i = 0; i < $gameMap.events().length; i++) {
  714.                                                 if ($gameMap.events()[i]) {
  715.                                                         for (var j = 0; j < lightarray_id.length; j++) {
  716.                                                                 if (lightarray_id[j] == lightid) {
  717.                                                                         var mapid = $gameMap.mapId();
  718.                                                                         var eventid = $gameMap.events()[i]._eventId;
  719.                                                                         var key = [mapid, eventid, 'D'];
  720.                                                                         $gameSelfSwitches.setValue(key, false);
  721.                                                                 }
  722.                                                         }
  723.                                                 }
  724.                                         }
  725.                                         lightarray_id = [];
  726.                                         lightarray_state = [];
  727.                                         lightarray_color = [];
  728.                                         $gameVariables.SetLightArrayId(lightarray_id);
  729.                                         $gameVariables.SetLightArrayState(lightarray_state);
  730.                                         $gameVariables.SetLightArrayColor(lightarray_color);
  731.                                 }
  732.                         }

  733.                         // *********************** TURN SCRIPT ON/OFF *********************
  734.                         if (command === 'light' && args[0] == 'deactivate') {
  735.                                 //scriptactive = false;
  736.                                 $gameVariables.SetScriptActive(false);
  737.                         }
  738.                         if (command === 'light' && args[0] == 'activate') {
  739.                                 //scriptactive = true;
  740.                                 $gameVariables.SetScriptActive(true);
  741.                         }

  742.                         // *********************** TURN SCRIPT ON/OFF *********************
  743.                         if (command === 'script' && args[0] == 'deactivate') {
  744.                                 //scriptactive = false;
  745.                                 $gameVariables.SetStopScript(true);
  746.                         }
  747.                         if (command === 'script' && args[0] == 'activate') {
  748.                                 //scriptactive = true;
  749.                                 $gameVariables.SetStopScript(false);
  750.                         }
  751.                         //************************** SPEED/DEBUG TEST ****************************
  752.                         if (command === 'script' && args[0] == 'speedtest'  && args[1]== 'on') {
  753.                                 speeddebug = true ;
  754.                         }
  755.                         if (command === 'script' && args[0] == 'speedtest'  && args[1]== 'off') {
  756.                                 gamedebug = false ;
  757.                         }
  758.                         if (command === 'script' && args[0] == 'debug'  && args[1]== 'on') {
  759.                                 gamedebug = true ;
  760.                         }
  761.                         if (command === 'script' && args[0] == 'debug'  && args[1]== 'off') {
  762.                                 gamedebug = false ;
  763.                         }

  764.                         //************************** RELOAD MAP EVENTS ****************************
  765.                         if (command === 'reload' && args[0] == 'events' ) {
  766.                                 ReloadMapEvents();
  767.                                 //Graphics.Debug('Reload','Reload');
  768.                         }

  769.                         // *********************** EFFECTS *********************
  770.                         if (command === 'effect_on_event') {
  771.                                 var x1 = 0;
  772.                                 var y1 = 0;
  773.                                 var evid = -1;
  774.                                 for (var i = 0; i < $gameMap.events().length; i++) {
  775.                                         if ($gameMap.events()[i]) {
  776.                                                 evid = $gameMap.events()[i]._eventId;
  777.                                                 if (evid == args[0]) {
  778.                                                         x1 = $gameMap.events()[i]._realX * $gameMap.tileWidth();
  779.                                                         y1 = $gameMap.events()[i]._realY * $gameMap.tileHeight();
  780.                                                 }
  781.                                         }
  782.                                 }
  783.                                 // def = radius,color,duration(,keyword,speed)
  784.                                 // 0. Radius
  785.                                 // 1. Color
  786.                                 // 2. Time in Frames
  787.                                 // 3. Keyword (optional)   FADEIN FADEOUT FADEBOTH GROW SHRINK GROWSHRINK BIO
  788.                                 // 4. Fade/Grow Speed in frames

  789.                                 var radius = args[1];
  790.                                 if (radius.substring(0,1) == '#') {
  791.                                         radius = $gameVariables.value(Number(radius.substring(1)));
  792.                                 }
  793.                                 var color = args[2];
  794.                                 var time = args[3];
  795.                                 if (time.substring(0, 1) == '#') {
  796.                                         time = $gameVariables.value(Number(time.substring(1)));
  797.                                 }
  798.                                 var def = radius+","+color+","+time;
  799.                                 if (args.length >=5 ) {
  800.                                         var command = args[4];
  801.                                         var ctime = args[5];
  802.                                         if (ctime.substring(0, 1) == '#') {
  803.                                                 ctime = $gameVariables.value(Number(ctime.substring(1)));
  804.                                         }
  805.                                         def = def + "," + command + "," + ctime;
  806.                                 }
  807.                                 Terrax_ABS_blast_x.push(String(x1));
  808.                                 Terrax_ABS_blast_y.push(String(y1));
  809.                                 Terrax_ABS_blast.push(def);
  810.                                 Terrax_ABS_blast_duration.push(-1);
  811.                                 Terrax_ABS_blast_fade.push(-1);
  812.                                 Terrax_ABS_blast_grow.push(-1);
  813.                                 Terrax_ABS_blast_mapid.push($gameMap.mapId());
  814.                         }
  815.                         if (command === 'effect_on_xy') {
  816.                                 //Graphics.Debug('ARGS',args.length);
  817.                                 var x1 = args[0];
  818.                                 if (x1.substring(0, 1) == '#') {
  819.                                         x1 = $gameVariables.value(Number(x1.substring(1)));
  820.                                 }
  821.                                 var y1 = args[1];
  822.                                 if (y1.substring(0, 1) == '#') {
  823.                                         y1 = $gameVariables.value(Number(y1.substring(1)));
  824.                                 }
  825.                                 var radius = args[2];
  826.                                 if (radius.substring(0,1) == '#') {
  827.                                         radius = $gameVariables.value(Number(radius.substring(1)));
  828.                                 }
  829.                                 var color = args[3];
  830.                                 var time = args[4];
  831.                                 if (time.substring(0, 1) == '#') {
  832.                                         time = $gameVariables.value(Number(time.substring(1)));
  833.                                 }
  834.                                 var def = radius+","+color+","+time;
  835.                                 if (args.length >=6 ) {
  836.                                         var command = args[5];
  837.                                         var ctime = args[6];
  838.                                         if (ctime.substring(0, 1) == '#') {
  839.                                                 ctime = $gameVariables.value(Number(ctime.substring(1)));
  840.                                         }
  841.                                         def = def + "," + command + "," + ctime;
  842.                                 }
  843.                                 Terrax_ABS_blast_x.push(x1);
  844.                                 Terrax_ABS_blast_y.push(y1);
  845.                                 Terrax_ABS_blast.push(def);
  846.                                 Terrax_ABS_blast_duration.push(-1);
  847.                                 Terrax_ABS_blast_fade.push(-1);
  848.                                 Terrax_ABS_blast_grow.push(-1);
  849.                                 Terrax_ABS_blast_mapid.push($gameMap.mapId());
  850.                         }
  851.                 }


  852.         };

  853.         Spriteset_Map.prototype.createLightmask = function() {
  854.                 this._lightmask = new Lightmask();
  855.                 this.addChild(this._lightmask);
  856.         };
  857.        
  858.         function Lightmask() {
  859.             this.initialize.apply(this, arguments);
  860.         }


  861.         //OLD DEFINTION
  862.         //Lightmask.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
  863.         //NEW DEFINITION
  864.         //Lightmask.prototype = Object.create(PIXI.Container.prototype);

  865.         var pixitest = PIXI.VERSION.substring(0,2) == 'v2'?"PIXI.DisplayObjectContainer.prototype":"PIXI.Container.prototype";
  866.         Lightmask.prototype = Object.create(eval(pixitest));

  867.         Lightmask.prototype.constructor = Lightmask;
  868.        
  869.         Lightmask.prototype.initialize = function() {


  870.                 if (PIXI.VERSION.substring(0,2) == 'v2') {
  871.                         PIXI.DisplayObjectContainer.call(this);
  872.                 } else {
  873.                         PIXI.Container.call(this);
  874.                 }
  875.                 // OLD DEFINITION
  876.                 //PIXI.DisplayObjectContainer.call(this);
  877.             // NEW DEFINITION
  878.                 //PIXI.Container.call(this);

  879.                 this._width = Graphics.width;
  880.             this._height = Graphics.height;
  881.             this._sprites = [];
  882.             this._createBitmap();
  883.         };
  884.        
  885.         //Updates the Lightmask for each frame.
  886.        
  887.         Lightmask.prototype.update = function() {
  888.                           this._updateMask();
  889.         };
  890.        
  891.         //@method _createBitmaps
  892.        
  893.         Lightmask.prototype._createBitmap = function() {
  894.             this._maskBitmap = new Bitmap(maxX+20,maxY);   // one big bitmap to fill the intire screen with black
  895.             var canvas = this._maskBitmap.canvas;             // a bit larger then setting to take care of screenshakes

  896.         };

  897.         function ReloadMapEvents() {
  898.                 //**********************fill up new map-array *************************
  899.                 event_note = [];
  900.                 event_id = [];
  901.                 event_x = [];
  902.                 event_y = [];
  903.                 event_dir = [];
  904.                 event_moving = [];
  905.                 event_stacknumber = [];
  906.                 event_eventcount = $gameMap.events().length;

  907.                 //Graphics.Debug('Reload','Reload map events ' + event_eventcount);

  908.                 for (var i = 0; i < event_eventcount; i++) {
  909.                         if ($gameMap.events()[i]) {
  910.                                 if($gameMap.events()[i].event()) {
  911.                                         var note = $gameMap.events()[i].event().note;

  912.                                         var note_args = note.split(" ");
  913.                                         var note_command = note_args.shift().toLowerCase();

  914.                                         if (note_command == "light" || note_command == "fire" || note_command == "flashlight" || note_command == "daynight") {

  915.                                                 event_note.push(note);
  916.                                                 event_id.push($gameMap.events()[i]._eventId);
  917.                                                 event_x.push($gameMap.events()[i]._realX);
  918.                                                 event_y.push($gameMap.events()[i]._realY);
  919.                                                 event_dir.push($gameMap.events()[i]._direction);
  920.                                                 event_moving.push($gameMap.events()[i]._moveType || $gameMap.events()[i]._moveRouteForcing);
  921.                                                 event_stacknumber.push(i);
  922.                                         }
  923.                                         //Graphics.Debug('Reload movetype',$gameMap.events()[i]._moveRouteForcing)
  924.                                         // *********************************** DAY NIGHT Setting **************************
  925.                                         daynightset = false;
  926.                                         var mapnote = $dataMap.note.toLowerCase();
  927.                                         var searchnote = mapnote.search("daynight");
  928.                                         if (searchnote >= 0 || note_command == "daynight") {
  929.                                                 daynightset = true;
  930.                                         }
  931.                                 }
  932.                         }
  933.                 }
  934.         }

  935.         function ReloadTagArea() {
  936.                 // *************************** TILE TAG LIGHTSOURCES *********

  937.                 // clear arrays
  938.                 tile_lights = [];
  939.                 tile_blocks = [];

  940.                 // refill arrays

  941.                 var tilearray = $gameVariables.GetTileArray();
  942.                 for (var i = 0; i < tilearray.length; i++) {

  943.                         var tilestr = tilearray[i];
  944.                         var tileargs = tilestr.split(";");
  945.                         var tile_type = tileargs[0];
  946.                         var tile_number = tileargs[1];
  947.                         var tile_on = tileargs[2];
  948.                         var tile_color = tileargs[3];
  949.                         var tile_radius = 0;
  950.                         var brightness = 0.0;
  951.                         var shape = 0;
  952.                         var xo1 = 0.0;
  953.                         var yo1 = 0.0;
  954.                         var xo2 = 0.0;
  955.                         var yo2 = 0.0;

  956.                         if (tile_type == 1 || tile_type == 2) {

  957.                                 var b_arg = tileargs[4];
  958.                                 if (typeof b_arg != 'undefined') {
  959.                                         shape = b_arg;
  960.                                 }
  961.                                 b_arg = tileargs[5];
  962.                                 if (typeof b_arg != 'undefined') {
  963.                                         xo1 = b_arg;
  964.                                 }
  965.                                 b_arg = tileargs[6];
  966.                                 if (typeof b_arg != 'undefined') {
  967.                                         yo1 = b_arg;
  968.                                 }
  969.                                 b_arg = tileargs[7];
  970.                                 if (typeof b_arg != 'undefined') {
  971.                                         xo2 = b_arg;
  972.                                 }
  973.                                 b_arg = tileargs[8];
  974.                                 if (typeof b_arg != 'undefined') {
  975.                                         yo2 = b_arg;
  976.                                 }


  977.                         } else {
  978.                                 tile_radius = tileargs[4];
  979.                                 var b_arg = tileargs[5];
  980.                                 if (typeof b_arg != 'undefined') {
  981.                                         var key = b_arg.substring(0, 1);
  982.                                         if (key == 'b' || key == 'B') {
  983.                                                 brightness = Number(b_arg.substring(1)) / 100;
  984.                                         }
  985.                                 }
  986.                         }

  987.                         if (tile_on == 1) {

  988.                                 if (tile_type >= 3) {
  989.                                         // *************************** TILE TAG LIGHTSOURCES *********
  990.                                         for (var y = 0; y < $dataMap.height; y++) {
  991.                                                 for (var x = 0; x < $dataMap.width; x++) {
  992.                                                         var tag = 0;
  993.                                                         if (tile_type == 3 || tile_type == 5 || tile_type == 7) {
  994.                                                                 tag = $gameMap.terrainTag(x, y);
  995.                                                         }          // tile light
  996.                                                         if (tile_type == 4 || tile_type == 6 || tile_type == 8) {
  997.                                                                 tag = $dataMap.data[(5 * $dataMap.height + y) * $dataMap.width + x];
  998.                                                         }  // region light
  999.                                                         if (tag == tile_number) {
  1000.                                                                 var tilecode = x+";"+y+";"+tile_type+";"+tile_radius+";"+tile_color+";"+brightness;
  1001.                                                                 tile_lights.push(tilecode);
  1002.                                                                 //Graphics.Debug('Tilecode',tilecode+" "+tile_lights.length);
  1003.                                                                 //Graphics.Debug('tile length',tile_lights.length);
  1004.                                                         }
  1005.                                                 }
  1006.                                         }
  1007.                                 }


  1008.                                 // *************************** REDRAW MAPTILES FOR ROOFS ETC *********
  1009.                                 if (tile_type == 1 || tile_type == 2) {
  1010.                                         for (var y = 0; y < $dataMap.height; y++) {
  1011.                                                 for (var x = 0; x < $dataMap.width; x++) {
  1012.                                                         //var tag = $gameMap.terrainTag(x,y);
  1013.                                                         var tag = 0;
  1014.                                                         if (tile_type == 1) {
  1015.                                                                 tag = $gameMap.terrainTag(x, y);
  1016.                                                         }                  // tile block
  1017.                                                         if (tile_type == 2) {
  1018.                                                                 tag = $dataMap.data[(5 * $dataMap.height + y) * $dataMap.width + x];
  1019.                                                         }  // region block
  1020.                                                         if (tag == tile_number) {
  1021.                                                                 var tilecode = x + ";" + y + ";" + shape + ";" + xo1 + ";" + yo1 + ";" + xo2 + ";" + yo2 + ";" + tile_color;
  1022.                                                                 tile_blocks.push(tilecode);
  1023.                                                                 //Graphics.Debug('Tilecode', tilecode + " " + tile_blocks.length);

  1024.                                                         }
  1025.                                                 }
  1026.                                         }
  1027.                                 }
  1028.                         }

  1029.                 }
  1030.                 $gameVariables.SetLightTags(tile_lights);
  1031.                 $gameVariables.SetBlockTags(tile_blocks);

  1032.         }

  1033.         /**
  1034.          * @method _updateAllSprites
  1035.          * @private
  1036.          */
  1037.         Lightmask.prototype._updateMask = function() {

  1038.                 StartTiming();

  1039.                 // ****** DETECT MAP CHANGES ********
  1040.                 var map_id = $gameMap.mapId();
  1041.                 if (map_id != oldmap) {
  1042.                         oldmap = map_id;

  1043.                         // set mog-tints on map change
  1044.                         if ($gameVariables.GetMog() == true) {
  1045.                                 var searchdaynight = "";
  1046.                                 if (typeof $dataMap.note != 'undefined') {
  1047.                                         searchdaynight = $dataMap.note.toLowerCase();
  1048.                                 }
  1049.                                 if (searchdaynight.search('mogtime') >= 0) {
  1050.                                         var new_phase = 0;
  1051.                                         if ($gameSwitches.value(21)) {        new_phase = 0; }
  1052.                                         if ($gameSwitches.value(22)) {        new_phase = 1; }
  1053.                                         if ($gameSwitches.value(23)) {        new_phase = 2; }
  1054.                                         if ($gameSwitches.value(24)) {        new_phase = 3; }
  1055.                                         if ($gameSwitches.value(25)) {        new_phase = 4; }
  1056.                                         if ($gameSwitches.value(26)) {        new_phase = 5; }
  1057.                                         moghunter_phase = new_phase;
  1058.                                         var newtint = '#000000';
  1059.                                         var mogtint = $gameVariables.GetMogTintArray();
  1060.                                         if (new_phase == 0) { newtint = mogtint[0]; }
  1061.                                         if (new_phase == 1) { newtint = mogtint[1]; }
  1062.                                         if (new_phase == 2) { newtint = mogtint[2]; }
  1063.                                         if (new_phase == 3) { newtint = mogtint[3]; }
  1064.                                         if (new_phase == 4) { newtint = mogtint[4]; }
  1065.                                         if (new_phase == 5) { newtint = mogtint[5]; }
  1066.                                         $gameVariables.SetTintTarget(newtint);
  1067.                                         $gameVariables.SetTint(newtint);
  1068.                                 } else {
  1069.                                         $gameVariables.SetTintTarget('#000000');
  1070.                                         $gameVariables.SetTint('#000000');
  1071.                                 }
  1072.                         }


  1073.                         // recalc tile and region tags.
  1074.                         ReloadTagArea();

  1075.                         //clear color cycle arrays
  1076.                         for (var i = 0; i < 1000; i++) {
  1077.                                 colorcycle_count[i] = 0;
  1078.                                 colorcycle_timer[i] = 0;
  1079.                         }

  1080.                         ReloadMapEvents();  // reload map events on map chance

  1081.                         if (reset_each_map == 'Yes' || reset_each_map == 'yes') {
  1082.                                 // reset switches to false

  1083.                                 var lightarray_id = $gameVariables.GetLightArrayId();
  1084.                                 var lightarray_state = $gameVariables.GetLightArrayState();
  1085.                                 var lightarray_color = $gameVariables.GetLightArrayColor();

  1086.                                 for (var i = 0; i < $gameMap.events().length; i++) {
  1087.                                         if ($gameMap.events()[i]) {
  1088.                                                 for (var j = 0; j < lightarray_id.length; j++) {
  1089.                                                         if (lightarray_id[j] == lightid) {
  1090.                                                                 var mapid = $gameMap.mapId();
  1091.                                                                 var eventid = $gameMap.events()[i]._eventId;
  1092.                                                                 var key = [mapid, eventid, 'D'];
  1093.                                                                 $gameSelfSwitches.setValue(key, false);
  1094.                                                         }
  1095.                                                 }
  1096.                                         }
  1097.                                 }
  1098.                                 lightarray_id = [];
  1099.                                 lightarray_state = [];
  1100.                                 lightarray_color = [];
  1101.                                 $gameVariables.SetLightArrayId(lightarray_id);
  1102.                                 $gameVariables.SetLightArrayState(lightarray_state);
  1103.                                 $gameVariables.SetLightArrayColor(lightarray_color);
  1104.                         }
  1105.                 }

  1106.                 // reload mapevents if event_data has chanced (deleted or spawned events/saves)
  1107.                 if (event_eventcount != $gameMap.events().length) {
  1108.                         ReloadMapEvents();
  1109.                         //Graphics.Debug('EventSpawn', $gameMap.events().length);
  1110.                 }

  1111.                 // remove old sprites
  1112.                 for (var i = 0; i < this._sprites.length; i++) {          // remove all old sprites
  1113.                         this._removeSprite();
  1114.                 }

  1115.                 if (options_lighting_on == true) {

  1116.                         if ($gameVariables.GetStopScript() == false) {

  1117.                                 if ($gameVariables.GetScriptActive() == true && $gameMap.mapId() >= 0) {

  1118.                                         // moghunter timesystem compatibility

  1119.                                         var searchdaynight = "";
  1120.                                         if (typeof $dataMap.note != 'undefined') {
  1121.                                                 searchdaynight = $dataMap.note.toLowerCase();
  1122.                                         }


  1123.                                         if ($gameVariables.GetMog() == true) {

  1124.                                                 if (searchdaynight.search('mogtime') >= 0) {

  1125.                                                         var debugline = "";
  1126.                                                         var new_phase = 0;
  1127.                                                         if ($gameSwitches.value(21)) {
  1128.                                                                 new_phase = 0;
  1129.                                                                 debugline = debugline + " SW21:DAWN "
  1130.                                                         } //Dawn
  1131.                                                         if ($gameSwitches.value(22)) {
  1132.                                                                 new_phase = 1;
  1133.                                                                 debugline = debugline + " SW22:RISE "
  1134.                                                         } //Rise
  1135.                                                         if ($gameSwitches.value(23)) {
  1136.                                                                 new_phase = 2;
  1137.                                                                 debugline = debugline + " SW23:DAY "
  1138.                                                         } //Day
  1139.                                                         if ($gameSwitches.value(24)) {
  1140.                                                                 new_phase = 3;
  1141.                                                                 debugline = debugline + " SW24:SUNSET "
  1142.                                                         } //Set
  1143.                                                         if ($gameSwitches.value(25)) {
  1144.                                                                 new_phase = 4;
  1145.                                                                 debugline = debugline + " SW25:DUSK "
  1146.                                                         } //Dusk
  1147.                                                         if ($gameSwitches.value(26)) {
  1148.                                                                 new_phase = 5;
  1149.                                                                 debugline = debugline + " SW26:NIGHT "
  1150.                                                         } //Night

  1151.                                                         if (debugline == "") {
  1152.                                                                 debugline = "No switches (21-26) active, Mog is probably not loaded"
  1153.                                                         }

  1154.                                                         if (new_phase != moghunter_phase) {
  1155.                                                                 moghunter_phase = new_phase;
  1156.                                                                 var newtint = '#000000';
  1157.                                                                 var mogtint = $gameVariables.GetMogTintArray();
  1158.                                                                 if (new_phase == 0) {
  1159.                                                                         newtint = mogtint[0];
  1160.                                                                 }
  1161.                                                                 if (new_phase == 1) {
  1162.                                                                         newtint = mogtint[1];
  1163.                                                                 }
  1164.                                                                 if (new_phase == 2) {
  1165.                                                                         newtint = mogtint[2];
  1166.                                                                 }
  1167.                                                                 if (new_phase == 3) {
  1168.                                                                         newtint = mogtint[3];
  1169.                                                                 }
  1170.                                                                 if (new_phase == 4) {
  1171.                                                                         newtint = mogtint[4];
  1172.                                                                 }
  1173.                                                                 if (new_phase == 5) {
  1174.                                                                         newtint = mogtint[5];
  1175.                                                                 }

  1176.                                                                 //Terrax_tint_target = newtint;
  1177.                                                                 //Terrax_tint_speed = 10;
  1178.                                                                 //$gameVariables.setTintValue(Terrax_tint_target);
  1179.                                                                 $gameVariables.SetTintTarget(newtint);
  1180.                                                                 $gameVariables.SetTintSpeed(10);

  1181.                                                         }
  1182.                                                         if (mogdebug) {
  1183.                                                                 var tinttarget = $gameVariables.GetTintTarget();
  1184.                                                                 debugline = debugline + " Tintcolor: " + tinttarget;
  1185.                                                                 Graphics.Debug('MogTimeSystem Debug', debugline);
  1186.                                                         }
  1187.                                                 }
  1188.                                         }

  1189.                                         event_reload_counter++;  // reload map events every 200 cycles just in case.
  1190.                                         if (event_reload_counter > 200){
  1191.                                                 event_reload_counter = 0;
  1192.                                                 ReloadMapEvents()
  1193.                                         }



  1194.                                         // are there lightsources on this map?
  1195.                                         var darkenscreen = false;

  1196.                                         if (searchdaynight.search('daynight') >= 0) {
  1197.                                                 this._addSprite(-20, 0, this._maskBitmap); // daynight tag? yes.. then turn off the lights
  1198.                                                 darkenscreen = true;
  1199.                                         } else {
  1200.                                                 for (var i = 0; i < event_note.length; i++) {
  1201.                                                         //if ($gameMap.events()[i]) {
  1202.                                                                 var note = event_note[i];
  1203.                                                                 var note_args = note.split(" ");
  1204.                                                                 var note_command = note_args.shift().toLowerCase();
  1205.                                                                 if (note_command == "light" || note_command == "fire" || note_command == "daynight" || note_command == "flashlight") {
  1206.                                                                         this._addSprite(-20, 0, this._maskBitmap); // light event? yes.. then turn off the lights
  1207.                                                                         darkenscreen = true;
  1208.                                                                         break;
  1209.                                                                 }
  1210.                                                         //}
  1211.                                                 }
  1212.                                         }


  1213.                                         if (darkenscreen == true) {


  1214.                                                 // ******** GROW OR SHRINK GLOBE PLAYER *********

  1215.                                                 var firstrun = $gameVariables.GetFirstRun();
  1216.                                                 if (firstrun === true) {
  1217.                                                         Terrax_tint_speed = 60;
  1218.                                                         Terrax_tint_target = '#000000';
  1219.                                                         terrax_tint_speed_old = 60;
  1220.                                                         terrax_tint_target_old = '#000000';
  1221.                                                         $gameVariables.SetFirstRun(false);
  1222.                                                         player_radius = Number(parameters['Player radius']);
  1223.                                                         $gameVariables.SetRadius(player_radius);
  1224.                                                         //Graphics.Debug('FIRSTRUN',player_radius);
  1225.                                                 } else {
  1226.                                                         player_radius = $gameVariables.GetRadius();
  1227.                                                 }
  1228.                                                 var lightgrow_value = player_radius;
  1229.                                                 var lightgrow_target = $gameVariables.GetRadiusTarget();
  1230.                                                 var lightgrow_speed = $gameVariables.GetRadiusSpeed();

  1231.                                                 //Graphics.Debug('RADIUS',player_radius+' '+lightgrow_value+' '+lightgrow_target+' '+lightgrow_speed);

  1232.                                                 if (lightgrow_value < lightgrow_target) {
  1233.                                                         lightgrow_value = lightgrow_value + lightgrow_speed;
  1234.                                                         if (lightgrow_value > lightgrow_target) {
  1235.                                                                 //other wise it can keep fliping back and forth between > and <
  1236.                                                                 lightgrow_value = lightgrow_target;
  1237.                                                         }
  1238.                                                         player_radius = lightgrow_value;
  1239.                                                 }
  1240.                                                 if (lightgrow_value > lightgrow_target) {
  1241.                                                         lightgrow_value = lightgrow_value - lightgrow_speed;
  1242.                                                         if (lightgrow_value < lightgrow_target) {
  1243.                                                                 //other wise it can keep fliping back and forth between > and <
  1244.                                                                 lightgrow_value = lightgrow_target;
  1245.                                                         }
  1246.                                                         player_radius = lightgrow_value;
  1247.                                                 }

  1248.                                                 $gameVariables.SetRadius(player_radius);
  1249.                                                 $gameVariables.SetRadiusTarget(lightgrow_target);

  1250.                                                 // ****** PLAYER LIGHTGLOBE ********

  1251.                                                 var canvas = this._maskBitmap.canvas;
  1252.                                                 var ctx = canvas.getContext("2d");
  1253.                                                 this._maskBitmap.fillRect(0, 0, maxX + 20, maxY, '#000000');


  1254.                                                 ctx.globalCompositeOperation = 'lighter';
  1255.                                                 //Graphics.Debug('Lighter',player_radius';
  1256.                                                 //        ctx.globalCompositeOperation = 'screen';
  1257.                                                 //        Graphics.Debug('Screen',player_radius);

  1258.                                                 var pw = $gameMap.tileWidth();
  1259.                                                 var ph = $gameMap.tileHeight();
  1260.                                                 var dx = $gameMap.displayX();
  1261.                                                 var dy = $gameMap.displayY();
  1262.                                                 var px = $gamePlayer._realX;
  1263.                                                 var py = $gamePlayer._realY;
  1264.                                                 var pd = $gamePlayer._direction;

  1265.                                                 //Graphics.Debug('Screen',pw+" "+ph+" "+dx+" "+dy+" "+px+" "+py);


  1266.                                                 var x1 = (pw / 2) + ( (px - dx) * pw);
  1267.                                                 var y1 = (ph / 2) + ( (py - dy) * ph);
  1268.                                                 var paralax = false;
  1269.                                                 // paralax does something weird with coordinates.. recalc needed
  1270.                                                 if (dx > $gamePlayer.x) {
  1271.                                                         var xjump = $gameMap.width() - Math.floor(dx - px);
  1272.                                                         x1 = (pw / 2) + (xjump * pw);
  1273.                                                 }
  1274.                                                 if (dy > $gamePlayer.y) {
  1275.                                                         var yjump = $gameMap.height() - Math.floor(dy - py);
  1276.                                                         y1 = (ph / 2) + (yjump * ph);
  1277.                                                 }

  1278.                                                 var playerflashlight = $gameVariables.GetFlashlight();
  1279.                                                 var playercolor = $gameVariables.GetPlayerColor();
  1280.                                                 var flashlightlength = $gameVariables.GetFlashlightLength();
  1281.                                                 var flashlightwidth = $gameVariables.GetFlashlightWidth();
  1282.                                                 var playerflicker = $gameVariables.GetFire();
  1283.                                                 var playerbrightness = $gameVariables.GetPlayerBrightness();


  1284.                                                 var iplayer_radius = Math.floor(player_radius);

  1285.                                                 if (iplayer_radius > 0) {
  1286.                                                         if (playerflashlight == true) {
  1287.                                                                 this._maskBitmap.radialgradientFillRect2(x1, y1, 20, iplayer_radius, playercolor, '#000000', pd, flashlightlength, flashlightwidth);
  1288.                                                         }
  1289.                                                         y1 = y1 - flashlightoffset;
  1290.                                                         if (iplayer_radius < 100) {
  1291.                                                                 // dim the light a bit at lower lightradius for a less focused effect.
  1292.                                                                 var r = hexToRgb(playercolor).r;
  1293.                                                                 var g = hexToRgb(playercolor).g;
  1294.                                                                 var b = hexToRgb(playercolor).b;
  1295.                                                                 g = g - 50;
  1296.                                                                 r = r - 50;
  1297.                                                                 b = b - 50;
  1298.                                                                 if (g < 0) {
  1299.                                                                         g = 0;
  1300.                                                                 }
  1301.                                                                 if (r < 0) {
  1302.                                                                         r = 0;
  1303.                                                                 }
  1304.                                                                 if (b < 0) {
  1305.                                                                         b = 0;
  1306.                                                                 }
  1307.                                                                 var newcolor = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);

  1308.                                                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, iplayer_radius, newcolor, '#000000', playerflicker, playerbrightness);
  1309.                                                         } else {
  1310.                                                                 this._maskBitmap.radialgradientFillRect(x1, y1, 20, iplayer_radius, playercolor, '#000000', playerflicker, playerbrightness);
  1311.                                                         }

  1312.                                                 }


  1313.                                                 // *********************************** DAY NIGHT CYCLE TIMER **************************

  1314.                                                 var daynightspeed = $gameVariables.GetDaynightSpeed();

  1315.                                                 if (daynightspeed > 0 && daynightspeed < 5000) {

  1316.                                                         var datenow = new Date();
  1317.                                                         var seconds = Math.floor(datenow.getTime() / 10);
  1318.                                                         if (seconds > oldseconds) {

  1319.                                                                 var daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  1320.                                                                 var daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  1321.                                                                 var daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24

  1322.                                                                 oldseconds = seconds;
  1323.                                                                 daynighttimer = daynighttimer + 1;
  1324.                                                                 var daynightminutes = Math.floor(daynighttimer / daynightspeed);
  1325.                                                                 var daynighttimeover = daynighttimer - (daynightspeed * daynightminutes);
  1326.                                                                 var daynightseconds = Math.floor(daynighttimeover / daynightspeed * 60);
  1327.                                                                 if (daynightdebug == true) {
  1328.                                                                         var daynightseconds2 = daynightseconds;
  1329.                                                                         if (daynightseconds < 10) {
  1330.                                                                                 daynightseconds2 = '0' + daynightseconds;
  1331.                                                                         }
  1332.                                                                         var hourvalue ='-';
  1333.                                                                         var hourset = 'Not set';
  1334.                                                                         if (daynightsavehours>0) {
  1335.                                                                                 hourvalue = $gameVariables.value(daynightsavehours);
  1336.                                                                                 hourset = daynightsavehours
  1337.                                                                         }
  1338.                                                                         var minutevalue ='-';
  1339.                                                                         var minuteset = 'Not set';
  1340.                                                                         if (daynightsavemin>0) {
  1341.                                                                                 minutevalue = $gameVariables.value(daynightsavemin);
  1342.                                                                                 minuteset = daynightsavemin
  1343.                                                                         }
  1344.                                                                         var secondvalue ='-';
  1345.                                                                         var secondset = 'Not set';
  1346.                                                                         if (daynightsavesec>0) {
  1347.                                                                                 secondvalue = $gameVariables.value(daynightsavesec);
  1348.                                                                                 secondset = daynightsavesec
  1349.                                                                         }

  1350.                                                                         var minutecounter = $gameVariables.value(daynightsavemin);
  1351.                                                                         var secondcounter = $gameVariables.value(daynightsavesec);
  1352.                                                                         Graphics.Debug('Debug Daynight system', daynightcycle + ' ' + daynightminutes + ' ' + daynightseconds2+
  1353.                                                                                        '<br>' +'Hours  -> Variable: '+hourset+ '  Value: '+hourvalue+
  1354.                                                                                        '<br>' +'Minutes-> Variable: '+minuteset+ '  Value: '+minutevalue+
  1355.                                                                                        '<br>' +'Seconds-> Variable: '+secondset+ '  Value: '+secondvalue);

  1356.                                                                 }
  1357.                                                                 if (daynightsavemin > 0) {
  1358.                                                                         $gameVariables.setValue(daynightsavemin, daynightminutes);
  1359.                                                                 }
  1360.                                                                 if (daynightsavesec > 0) {
  1361.                                                                         $gameVariables.setValue(daynightsavesec, daynightseconds);
  1362.                                                                 }

  1363.                                                                 if (daynighttimer >= (daynightspeed * 60)) {

  1364.                                                                         daynightcycle = daynightcycle + 1;
  1365.                                                                         if (daynightcycle >= daynighthoursinday) {
  1366.                                                                                 daynightcycle = 0;
  1367.                                                                         }
  1368.                                                                         if (daynightsavehours > 0) {
  1369.                                                                                 $gameVariables.setValue(daynightsavehours, daynightcycle);
  1370.                                                                         }
  1371.                                                                         daynighttimer = 0;
  1372.                                                                 }
  1373.                                                                 $gameVariables.SetDaynightTimer(daynighttimer);     // timer = minutes * speed
  1374.                                                                 $gameVariables.SetDaynightCycle(daynightcycle);     // cycle = hours
  1375.                                                         }
  1376.                                                 }

  1377.                                                 // EFFECTS AND QUASI ABS SUPPORT


  1378.                                                 // SKILLS/MISSLES (effects without duration)

  1379.                                                 for (var i = 0; i < Terrax_ABS_skill_x.length; i++) {
  1380.                                                         var settings = Terrax_ABS_skill[i];
  1381.                                                         if (settings) {
  1382.                                                                 if (settings != 'undefined') {
  1383.                                                                         var setstring = settings.toString();
  1384.                                                                         var lightset = setstring.split(",");
  1385.                                                                         //Graphics.Debug('Test',setstring+" "+lightset[0]+" "+lightset[1]);

  1386.                                                                         var px = Terrax_ABS_skill_x[i];
  1387.                                                                         var py = Terrax_ABS_skill_y[i];
  1388.                                                                         var x1 = px - (dx * pw);
  1389.                                                                         var y1 = py - (dy * ph);

  1390.                                                                         this._maskBitmap.radialgradientFillRect(x1, y1, 0, lightset[0], lightset[1], '#000000', false);
  1391.                                                                 }
  1392.                                                         }
  1393.                                                 }

  1394.                                                 // clear arrays after draw
  1395.                                                 Terrax_ABS_skill_x = [];
  1396.                                                 Terrax_ABS_skill_y = [];
  1397.                                                 Terrax_ABS_skill = [];

  1398.                                                 // BLASTS (effect with duration)



  1399.                                                 for (var i = 0; i < Terrax_ABS_blast_x.length; i++) {
  1400.                                                         var settings = Terrax_ABS_blast[i];
  1401.                                                         if (settings) {
  1402.                                                                 if (settings != 'undefined') {
  1403.                                                                         var setstring = settings.toString();

  1404.                                                                         // Settings : Lightset[]
  1405.                                                                         // 0. Radius
  1406.                                                                         // 1. Color
  1407.                                                                         // 2. Time in Frames
  1408.                                                                         // 3. Keyword (optional)   FADEIN FADEOUT FADEBOTH GROW SHRINK GROWSHRINK BIO
  1409.                                                                         // 4. Fade/Grow Speed in frames

  1410.                                                                         var lightset = setstring.split(",");

  1411.                                                                         if (Number(lightset[2]) > 0 && Terrax_ABS_blast_duration[i] == -1) {
  1412.                                                                                 Terrax_ABS_blast_duration[i] = lightset[2]
  1413.                                                                         }

  1414.                                                                         var fcolor = lightset[1];
  1415.                                                                         var fradius = lightset[0];

  1416.                                                                         if (setstring.length > 2) {  // SPECIALS  FADE/GROW ETC.

  1417.                                                                                 if (lightset[3] == 'FADEIN' || lightset[3] == 'FADEINOUT' || lightset[3] == 'BIO') {

  1418.                                                                                         var fadelength = Number(lightset[4]);   // number of frames to fade in

  1419.                                                                                         if (Terrax_ABS_blast_fade[i] == -1) {
  1420.                                                                                                 Terrax_ABS_blast_fade[i] = 0;
  1421.                                                                                         }
  1422.                                                                                         if (Terrax_ABS_blast_fade[i] < fadelength) {
  1423.                                                                                                 Terrax_ABS_blast_fade[i] = Terrax_ABS_blast_fade[i] + 1;

  1424.                                                                                                 var startcolor = "#000000";
  1425.                                                                                                 var targetcolor = lightset[1];
  1426.                                                                                                 var fadecount = Terrax_ABS_blast_fade[i];

  1427.                                                                                                 var r = hexToRgb(startcolor).r;
  1428.                                                                                                 var g = hexToRgb(startcolor).g;
  1429.                                                                                                 var b = hexToRgb(startcolor).b;

  1430.                                                                                                 var r2 = hexToRgb(targetcolor).r;
  1431.                                                                                                 var g2 = hexToRgb(targetcolor).g;
  1432.                                                                                                 var b2 = hexToRgb(targetcolor).b;

  1433.                                                                                                 var stepR = (r2 - r) / (fadelength);
  1434.                                                                                                 var stepG = (g2 - g) / (fadelength);
  1435.                                                                                                 var stepB = (b2 - b) / (fadelength);

  1436.                                                                                                 var r3 = Math.floor(r + (stepR * fadecount));
  1437.                                                                                                 var g3 = Math.floor(g + (stepG * fadecount));
  1438.                                                                                                 var b3 = Math.floor(b + (stepB * fadecount));
  1439.                                                                                                 if (r3 < 0) {
  1440.                                                                                                         r3 = 0
  1441.                                                                                                 }
  1442.                                                                                                 if (g3 < 0) {
  1443.                                                                                                         g3 = 0
  1444.                                                                                                 }
  1445.                                                                                                 if (b3 < 0) {
  1446.                                                                                                         b3 = 0
  1447.                                                                                                 }
  1448.                                                                                                 if (r3 > 255) {
  1449.                                                                                                         r3 = 255
  1450.                                                                                                 }
  1451.                                                                                                 if (g3 > 255) {
  1452.                                                                                                         g3 = 255
  1453.                                                                                                 }
  1454.                                                                                                 if (b3 > 255) {
  1455.                                                                                                         b3 = 255
  1456.                                                                                                 }
  1457.                                                                                                 fcolor = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  1458.                                                                                                 //Graphics.Debug('FADEIN COLOR', fcolor + " " + r + " " + r2 + " " + stepR + " " + r3);

  1459.                                                                                                 if (Terrax_ABS_blast_fade[i] == fadelength) {
  1460.                                                                                                         Terrax_ABS_blast_fade[i] = 100000;  // for fadeinout
  1461.                                                                                                 }
  1462.                                                                                         }
  1463.                                                                                 }

  1464.                                                                                 if (lightset[3] == 'FADEOUT') {

  1465.                                                                                         var fadelength = Number(lightset[4]);   // number of frames to fade out
  1466.                                                                                         if (Terrax_ABS_blast_fade[i] == -1 && Terrax_ABS_blast_duration[i] < fadelength) {
  1467.                                                                                                 // start fading when blastduration equals fadelength
  1468.                                                                                                 Terrax_ABS_blast_fade[i] = 0;
  1469.                                                                                         }
  1470.                                                                                         if (Terrax_ABS_blast_fade[i] < fadelength && Terrax_ABS_blast_fade[i] >= 0) {
  1471.                                                                                                 Terrax_ABS_blast_fade[i] = Terrax_ABS_blast_fade[i] + 1;
  1472.                                                                                                 //Graphics.Debug('FADEOUT',Terrax_ABS_blast_fade[i]);
  1473.                                                                                                 var startcolor = lightset[1];
  1474.                                                                                                 var targetcolor = "#000000";
  1475.                                                                                                 var fadecount = Terrax_ABS_blast_fade[i];

  1476.                                                                                                 var r = hexToRgb(startcolor).r;
  1477.                                                                                                 var g = hexToRgb(startcolor).g;
  1478.                                                                                                 var b = hexToRgb(startcolor).b;

  1479.                                                                                                 var r2 = hexToRgb(targetcolor).r;
  1480.                                                                                                 var g2 = hexToRgb(targetcolor).g;
  1481.                                                                                                 var b2 = hexToRgb(targetcolor).b;

  1482.                                                                                                 var stepR = (r2 - r) / (fadelength);
  1483.                                                                                                 var stepG = (g2 - g) / (fadelength);
  1484.                                                                                                 var stepB = (b2 - b) / (fadelength);

  1485.                                                                                                 var r3 = Math.floor(r + (stepR * fadecount));
  1486.                                                                                                 var g3 = Math.floor(g + (stepG * fadecount));
  1487.                                                                                                 var b3 = Math.floor(b + (stepB * fadecount));
  1488.                                                                                                 if (r3 < 0) {
  1489.                                                                                                         r3 = 0
  1490.                                                                                                 }
  1491.                                                                                                 if (g3 < 0) {
  1492.                                                                                                         g3 = 0
  1493.                                                                                                 }
  1494.                                                                                                 if (b3 < 0) {
  1495.                                                                                                         b3 = 0
  1496.                                                                                                 }
  1497.                                                                                                 if (r3 > 255) {
  1498.                                                                                                         r3 = 255
  1499.                                                                                                 }
  1500.                                                                                                 if (g3 > 255) {
  1501.                                                                                                         g3 = 255
  1502.                                                                                                 }
  1503.                                                                                                 if (b3 > 255) {
  1504.                                                                                                         b3 = 255
  1505.                                                                                                 }
  1506.                                                                                                 fcolor = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  1507.                                                                                                 //Graphics.Debug('FADEIN COLOR', fcolor + " " + r + " " + r2 + " " + stepR + " " + r3);
  1508.                                                                                         }
  1509.                                                                                 }

  1510.                                                                                 if (lightset[3] == 'FADEINOUT' || lightset[3] == 'BIO') {
  1511.                                                                                         // fadeout only, fadein is handled by fadein
  1512.                                                                                         var fadelength = Number(lightset[4]);   // number of frames to fade out
  1513.                                                                                         if (Terrax_ABS_blast_fade[i] == 100000 && Terrax_ABS_blast_duration[i] < fadelength) {
  1514.                                                                                                 // start fading when blastduration equals fadelength
  1515.                                                                                                 Terrax_ABS_blast_fade[i] = 100001;
  1516.                                                                                         }
  1517.                                                                                         if (Terrax_ABS_blast_fade[i] - 100000 < fadelength && Terrax_ABS_blast_fade[i] > 100000) {
  1518.                                                                                                 Terrax_ABS_blast_fade[i] = Terrax_ABS_blast_fade[i] + 1;
  1519.                                                                                                 //Graphics.Debug('FADEOUT',Terrax_ABS_blast_fade[i]);
  1520.                                                                                                 var startcolor = lightset[1];
  1521.                                                                                                 var targetcolor = "#000000";
  1522.                                                                                                 var fadecount = Terrax_ABS_blast_fade[i] - 100000;

  1523.                                                                                                 var r = hexToRgb(startcolor).r;
  1524.                                                                                                 var g = hexToRgb(startcolor).g;
  1525.                                                                                                 var b = hexToRgb(startcolor).b;

  1526.                                                                                                 var r2 = hexToRgb(targetcolor).r;
  1527.                                                                                                 var g2 = hexToRgb(targetcolor).g;
  1528.                                                                                                 var b2 = hexToRgb(targetcolor).b;

  1529.                                                                                                 var stepR = (r2 - r) / (fadelength);
  1530.                                                                                                 var stepG = (g2 - g) / (fadelength);
  1531.                                                                                                 var stepB = (b2 - b) / (fadelength);

  1532.                                                                                                 var r3 = Math.floor(r + (stepR * fadecount));
  1533.                                                                                                 var g3 = Math.floor(g + (stepG * fadecount));
  1534.                                                                                                 var b3 = Math.floor(b + (stepB * fadecount));
  1535.                                                                                                 if (r3 < 0) {
  1536.                                                                                                         r3 = 0
  1537.                                                                                                 }
  1538.                                                                                                 if (g3 < 0) {
  1539.                                                                                                         g3 = 0
  1540.                                                                                                 }
  1541.                                                                                                 if (b3 < 0) {
  1542.                                                                                                         b3 = 0
  1543.                                                                                                 }
  1544.                                                                                                 if (r3 > 255) {
  1545.                                                                                                         r3 = 255
  1546.                                                                                                 }
  1547.                                                                                                 if (g3 > 255) {
  1548.                                                                                                         g3 = 255
  1549.                                                                                                 }
  1550.                                                                                                 if (b3 > 255) {
  1551.                                                                                                         b3 = 255
  1552.                                                                                                 }
  1553.                                                                                                 fcolor = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  1554.                                                                                                 //Graphics.Debug('FADEIN COLOR', fcolor + " " + r + " " + r2 + " " + stepR + " " + r3);
  1555.                                                                                         }

  1556.                                                                                 }

  1557.                                                                                 if (lightset[3] == 'GROW' || lightset[3] == 'GROWSHRINK' || lightset[3] == 'BIO') {

  1558.                                                                                         var growlength = Number(lightset[4]);   // number of frames to grow

  1559.                                                                                         if (Terrax_ABS_blast_grow[i] == -1) {
  1560.                                                                                                 Terrax_ABS_blast_grow[i] = 0;
  1561.                                                                                         }
  1562.                                                                                         if (Terrax_ABS_blast_grow[i] < growlength) {

  1563.                                                                                                 if (lightset[3] == 'BIO') {
  1564.                                                                                                         Terrax_ABS_blast_grow[i] = Terrax_ABS_blast_grow[i] + 0.5;
  1565.                                                                                                 } else {
  1566.                                                                                                         Terrax_ABS_blast_grow[i] = Terrax_ABS_blast_grow[i] + 1;
  1567.                                                                                                 }

  1568.                                                                                                 var startradius = 0;
  1569.                                                                                                 var targetradius = lightset[0];
  1570.                                                                                                 var radiuscount = Terrax_ABS_blast_grow[i];

  1571.                                                                                                 var step = (targetradius - startradius) / (growlength);

  1572.                                                                                                 fradius = Math.floor(step * radiuscount);

  1573.                                                                                         }
  1574.                                                                                         if (Terrax_ABS_blast_grow[i] == growlength) {
  1575.                                                                                                 Terrax_ABS_blast_grow[i] = 100000;
  1576.                                                                                         }
  1577.                                                                                 }

  1578.                                                                                 if (lightset[3] == 'SHRINK') {

  1579.                                                                                         var shrinklength = Number(lightset[4]);   // number of frames to shrink

  1580.                                                                                         if (Terrax_ABS_blast_grow[i] == -1 && Terrax_ABS_blast_duration[i] < shrinklength) {
  1581.                                                                                                 Terrax_ABS_blast_grow[i] = 0;
  1582.                                                                                         }
  1583.                                                                                         if (Terrax_ABS_blast_grow[i] < shrinklength && Terrax_ABS_blast_grow[i] >= 0) {
  1584.                                                                                                 Terrax_ABS_blast_grow[i] = Terrax_ABS_blast_grow[i] + 1;

  1585.                                                                                                 var startradius = lightset[0];
  1586.                                                                                                 var targetradius = 0;
  1587.                                                                                                 var radiuscount = Terrax_ABS_blast_grow[i];

  1588.                                                                                                 var step = (startradius - targetradius ) / (shrinklength);
  1589.                                                                                                 fradius = Number(lightset[0]) - Math.floor(step * radiuscount);

  1590.                                                                                         }

  1591.                                                                                 }

  1592.                                                                                 if (lightset[3] == 'GROWSHRINK') {
  1593.                                                                                         // GROW is handled in grow
  1594.                                                                                         var shrinklength = Number(lightset[4]);   // number of frames to shrink

  1595.                                                                                         //Graphics.Debug('GROWSHRINK',Terrax_ABS_blast_grow[i]);

  1596.                                                                                         if (Terrax_ABS_blast_grow[i] == 100000 && Terrax_ABS_blast_duration[i] < shrinklength) {
  1597.                                                                                                 Terrax_ABS_blast_grow[i] = 100001;
  1598.                                                                                         }
  1599.                                                                                         if (Terrax_ABS_blast_grow[i] - 100000 < shrinklength && Terrax_ABS_blast_grow[i] > 100000) {
  1600.                                                                                                 Terrax_ABS_blast_grow[i] = Terrax_ABS_blast_grow[i] + 1;

  1601.                                                                                                 var startradius = lightset[0];
  1602.                                                                                                 var targetradius = 0;
  1603.                                                                                                 var radiuscount = Terrax_ABS_blast_grow[i] - 100000;

  1604.                                                                                                 var step = (startradius - targetradius ) / (shrinklength);
  1605.                                                                                                 fradius = Number(lightset[0]) - Math.floor(step * radiuscount);

  1606.                                                                                         }
  1607.                                                                                 }

  1608.                                                                         }


  1609.                                                                         if (Terrax_ABS_blast_duration[i] > 0) {
  1610.                                                                                 Terrax_ABS_blast_duration[i]--;
  1611.                                                                                 //Graphics.Debug('Test',i+" "+lightset[0]+" "+lightset[1]+" "+Terrax_ABS_blast_duration[i]);
  1612.                                                                                 if (Terrax_ABS_blast_mapid[i] == $gameMap.mapId()) {
  1613.                                                                                         var px = Terrax_ABS_blast_x[i];
  1614.                                                                                         var py = Terrax_ABS_blast_y[i];

  1615.                                                                                         var x1 = px - (dx * pw);
  1616.                                                                                         var y1 = py - (dy * ph);

  1617.                                                                                         // paralaxloop does something weird with coordinates.. recalc needed

  1618.                                                                                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  1619.                                                                                                 if (dx - 10 > px / pw) {
  1620.                                                                                                         var lxjump = $gameMap.width() - (dx - px / pw);
  1621.                                                                                                         x1 = (lxjump * pw);
  1622.                                                                                                 }
  1623.                                                                                         }
  1624.                                                                                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  1625.                                                                                                 if (dy - 10 > py / ph) {
  1626.                                                                                                         var lyjump = $gameMap.height() - (dy - py / ph);
  1627.                                                                                                         y1 = (lyjump * ph);
  1628.                                                                                                 }
  1629.                                                                                         }
  1630.                                                                                         x1 = x1 + (pw / 2);
  1631.                                                                                         y1 = y1 + (ph / 2);

  1632.                                                                                         //Graphics.Debug('Test',dy+" "+py+" "+y1+" "+$gameMap.height()+" "+lyjump);
  1633.                                                                                         this._maskBitmap.radialgradientFillRect(x1, y1, 0, fradius, fcolor, '#000000', false);
  1634.                                                                                 }
  1635.                                                                         } else {
  1636.                                                                                 Terrax_ABS_blast[i] = "DELETE";
  1637.                                                                         }
  1638.                                                                 }
  1639.                                                         }
  1640.                                                 }

  1641.                                                 // remove all expired items (not done in previous loop because it cases flickering)
  1642.                                                 for (var i = 0; i < Terrax_ABS_blast_x.length; i++) {
  1643.                                                         var settings = Terrax_ABS_blast[i];
  1644.                                                         if (settings) {
  1645.                                                                 if (settings != 'undefined') {
  1646.                                                                         var setstring = settings.toString();
  1647.                                                                         if (setstring == "DELETE") {
  1648.                                                                                 Terrax_ABS_blast_x.splice(i, 1);
  1649.                                                                                 Terrax_ABS_blast_y.splice(i, 1);
  1650.                                                                                 Terrax_ABS_blast.splice(i, 1);
  1651.                                                                                 Terrax_ABS_blast_duration.splice(i, 1);
  1652.                                                                                 Terrax_ABS_blast_mapid.splice(i, 1);
  1653.                                                                                 Terrax_ABS_blast_fade.splice(i, 1);
  1654.                                                                                 Terrax_ABS_blast_grow.splice(i, 1);
  1655.                                                                         }
  1656.                                                                 }
  1657.                                                         }
  1658.                                                 }


  1659.                                                 // ********** OTHER LIGHTSOURCES **************

  1660.                                                 for (var i = 0; i < event_note.length; i++) {
  1661.                                                         //if ($gameMap.events()[i]) {

  1662.                                                                 //var note = $gameMap.events()[i].event().note;
  1663.                                                                 //var evid = $gameMap.events()[i]._eventId;
  1664.                                                                 var note = event_note[i];
  1665.                                                                 var evid = event_id[i];

  1666.                                                                 var note_args = note.split(" ");
  1667.                                                                 var note_command = note_args.shift().toLowerCase();


  1668.                                                                 if (note_command == "light" || note_command == "fire" || note_command == "flashlight") {

  1669.                                                                         var objectflicker = false;
  1670.                                                                         if (note_command == "fire") {
  1671.                                                                                 objectflicker = true;
  1672.                                                                         }

  1673.                                                                         var light_radius = 1;
  1674.                                                                         var flashlength = 8;
  1675.                                                                         var flashwidth = 12;
  1676.                                                                         if (note_command == "flashlight") {
  1677.                                                                                 flashlength = Number(note_args.shift());
  1678.                                                                                 flashwidth = Number(note_args.shift());
  1679.                                                                                 if (flashlength == 0) {
  1680.                                                                                         flashlightlength = 8
  1681.                                                                                 }
  1682.                                                                                 if (flashwidth == 0) {
  1683.                                                                                         flashlightlength = 12
  1684.                                                                                 }
  1685.                                                                         } else {
  1686.                                                                                 light_radius = note_args.shift();
  1687.                                                                         }
  1688.                                                                         // light radius
  1689.                                                                         if (light_radius >= 0) {

  1690.                                                                                 // light color
  1691.                                                                                 var colorvalue = note_args.shift();

  1692.                                                                                 // Cycle colors


  1693.                                                                                 if (colorvalue == 'cycle' && evid < 1000) {

  1694.                                                                                         var cyclecolor0 = note_args.shift();
  1695.                                                                                         var cyclecount0 = Number(note_args.shift());
  1696.                                                                                         var cyclecolor1 = note_args.shift();
  1697.                                                                                         var cyclecount1 = Number(note_args.shift());
  1698.                                                                                         var cyclecolor2 = '#000000';
  1699.                                                                                         var cyclecount2 = 0;
  1700.                                                                                         var cyclecolor3 = '#000000';
  1701.                                                                                         var cyclecount3 = 0;

  1702.                                                                                         var morecycle = note_args.shift();
  1703.                                                                                         if (typeof morecycle != 'undefined') {
  1704.                                                                                                 if (morecycle.substring(0, 1) == "#") {
  1705.                                                                                                         cyclecolor2 = morecycle;
  1706.                                                                                                         cyclecount2 = Number(note_args.shift());
  1707.                                                                                                         morecycle = note_args.shift();
  1708.                                                                                                         if (typeof morecycle != 'undefined') {
  1709.                                                                                                                 if (morecycle.substring(0, 1) == "#") {
  1710.                                                                                                                         cyclecolor3 = morecycle;
  1711.                                                                                                                         cyclecount3 = Number(note_args.shift());

  1712.                                                                                                                 } else {
  1713.                                                                                                                         note_args.unshift(morecycle);
  1714.                                                                                                                 }
  1715.                                                                                                         }
  1716.                                                                                                 } else {
  1717.                                                                                                         note_args.unshift(morecycle);
  1718.                                                                                                 }
  1719.                                                                                         }

  1720.                                                                                         var switch0 = '0';
  1721.                                                                                         var switch1 = '0';
  1722.                                                                                         var switch2 = '0';
  1723.                                                                                         var switch3 = '0';

  1724.                                                                                         var switches = note_args.shift();
  1725.                                                                                         if (typeof switches != 'undefined') {
  1726.                                                                                                 if (switches.length == 7) {
  1727.                                                                                                         if (switches.substring(0, 3) == "SS:") {
  1728.                                                                                                                 switch0 = switches.substring(3, 4);
  1729.                                                                                                                 switch1 = switches.substring(4, 5);
  1730.                                                                                                                 switch2 = switches.substring(5, 6);
  1731.                                                                                                                 switch3 = switches.substring(6, 7);
  1732.                                                                                                         } else {
  1733.                                                                                                                 note_args.unshift(switches);
  1734.                                                                                                         }
  1735.                                                                                                 } else {
  1736.                                                                                                         note_args.unshift(switches);
  1737.                                                                                                 }
  1738.                                                                                         }

  1739.                                                                                         // set cycle color
  1740.                                                                                         switch (colorcycle_count[evid]) {
  1741.                                                                                                 case 0:
  1742.                                                                                                         colorvalue = cyclecolor0;
  1743.                                                                                                         break;
  1744.                                                                                                 case 1:
  1745.                                                                                                         colorvalue = cyclecolor1;
  1746.                                                                                                         break;
  1747.                                                                                                 case 2:
  1748.                                                                                                         colorvalue = cyclecolor2;
  1749.                                                                                                         break;
  1750.                                                                                                 case 3:
  1751.                                                                                                         colorvalue = cyclecolor3;
  1752.                                                                                                         break;
  1753.                                                                                                 default:
  1754.                                                                                                         colorvalue = '#FFFFFF';
  1755.                                                                                         }

  1756.                                                                                         // cycle timing
  1757.                                                                                         //var datenow = new Date();
  1758.                                                                                         //var seconds = Math.floor(datenow.getTime() / 100);
  1759.                                                                                         cyclecolor_counter = cyclecolor_counter + 1;

  1760.                                                                                         if (cyclecolor_counter > 10) {
  1761.                                                                                                 cyclecolor_counter = 0;

  1762.                                                                                                 //reset all switches
  1763.                                                                                                 if (switch0 != '0') {
  1764.                                                                                                         key = [map_id, evid, switch0];
  1765.                                                                                                         $gameSelfSwitches.setValue(key, false);
  1766.                                                                                                 }
  1767.                                                                                                 if (switch1 != '0') {
  1768.                                                                                                         key = [map_id, evid, switch1];
  1769.                                                                                                         $gameSelfSwitches.setValue(key, false);
  1770.                                                                                                 }
  1771.                                                                                                 if (switch2 != '0') {
  1772.                                                                                                         key = [map_id, evid, switch2];
  1773.                                                                                                         $gameSelfSwitches.setValue(key, false);
  1774.                                                                                                 }
  1775.                                                                                                 if (switch3 != '0') {
  1776.                                                                                                         key = [map_id, evid, switch3];
  1777.                                                                                                         $gameSelfSwitches.setValue(key, false);
  1778.                                                                                                 }


  1779.                                                                                                 if (colorcycle_count[evid] == 0) {
  1780.                                                                                                         colorcycle_timer[evid]++;

  1781.                                                                                                         if (colorcycle_timer[evid] > cyclecount0) {
  1782.                                                                                                                 colorcycle_count[evid] = 1;
  1783.                                                                                                                 colorcycle_timer[evid] = 0;
  1784.                                                                                                                 if (switch1 != '0') {
  1785.                                                                                                                         key = [map_id, evid, switch1];
  1786.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1787.                                                                                                                 }
  1788.                                                                                                         } else {
  1789.                                                                                                                 if (switch0 != '0') {
  1790.                                                                                                                         key = [map_id, evid, switch0];
  1791.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1792.                                                                                                                 }
  1793.                                                                                                         }

  1794.                                                                                                 }
  1795.                                                                                                 if (colorcycle_count[evid] == 1) {
  1796.                                                                                                         colorcycle_timer[evid]++;
  1797.                                                                                                         if (colorcycle_timer[evid] > cyclecount1) {
  1798.                                                                                                                 colorcycle_count[evid] = 2;
  1799.                                                                                                                 colorcycle_timer[evid] = 0;
  1800.                                                                                                                 if (switch2 != '0') {
  1801.                                                                                                                         key = [map_id, evid, switch2];
  1802.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1803.                                                                                                                 }
  1804.                                                                                                         } else {
  1805.                                                                                                                 if (switch1 != '0') {
  1806.                                                                                                                         key = [map_id, evid, switch1];
  1807.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1808.                                                                                                                 }
  1809.                                                                                                         }
  1810.                                                                                                 }
  1811.                                                                                                 if (colorcycle_count[evid] == 2) {
  1812.                                                                                                         colorcycle_timer[evid]++;
  1813.                                                                                                         if (colorcycle_timer[evid] > cyclecount2) {
  1814.                                                                                                                 colorcycle_count[evid] = 3;
  1815.                                                                                                                 colorcycle_timer[evid] = 0;
  1816.                                                                                                                 if (switch3 != '0') {
  1817.                                                                                                                         key = [map_id, evid, switch3];
  1818.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1819.                                                                                                                 }
  1820.                                                                                                         } else {
  1821.                                                                                                                 if (switch2 != '0') {
  1822.                                                                                                                         key = [map_id, evid, switch2];
  1823.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1824.                                                                                                                 }
  1825.                                                                                                         }
  1826.                                                                                                 }
  1827.                                                                                                 if (colorcycle_count[evid] == 3) {
  1828.                                                                                                         colorcycle_timer[evid]++;
  1829.                                                                                                         if (colorcycle_timer[evid] > cyclecount3) {
  1830.                                                                                                                 colorcycle_count[evid] = 0;
  1831.                                                                                                                 colorcycle_timer[evid] = 0;
  1832.                                                                                                                 if (switch0 != '0') {
  1833.                                                                                                                         key = [map_id, evid, switch0];
  1834.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1835.                                                                                                                 }
  1836.                                                                                                         } else {
  1837.                                                                                                                 if (switch3 != '0') {
  1838.                                                                                                                         key = [map_id, evid, switch3];
  1839.                                                                                                                         $gameSelfSwitches.setValue(key, true);
  1840.                                                                                                                 }
  1841.                                                                                                         }
  1842.                                                                                                 }
  1843.                                                                                                 //Graphics.Debug('cycleswitch',switch0 + " "+ switch1+ " "+ switch2+ " "+ switch3);

  1844.                                                                                         }

  1845.                                                                                 } else {
  1846.                                                                                         var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorvalue);
  1847.                                                                                         if (!isValidColor) {
  1848.                                                                                                 colorvalue = '#FFFFFF'
  1849.                                                                                         }
  1850.                                                                                 }

  1851.                                                                                 // brightness and direction

  1852.                                                                                 var brightness = 0.0;
  1853.                                                                                 var direction = 0;
  1854.                                                                                 var next_arg = note_args.shift();

  1855.                                                                                 if (typeof next_arg != 'undefined') {
  1856.                                                                                         var key = next_arg.substring(0, 1);
  1857.                                                                                         if (key == 'b' || key == 'B') {
  1858.                                                                                                 brightness = Number(next_arg.substring(1)) / 100;
  1859.                                                                                                 next_arg = note_args.shift();
  1860.                                                                                                 if (typeof next_arg != 'undefined') {
  1861.                                                                                                         key = next_arg.substring(0, 1);
  1862.                                                                                                 }
  1863.                                                                                         }
  1864.                                                                                         if (key == 'd' || key == 'D') {
  1865.                                                                                                 direction = next_arg.substring(1);
  1866.                                                                                                 next_arg = note_args.shift();
  1867.                                                                                         }
  1868.                                                                                 }

  1869.                                                                                 // conditional lighting
  1870.                                                                                 var lightid = 0;
  1871.                                                                                 if (typeof next_arg != 'undefined') {
  1872.                                                                                         lightid = next_arg;
  1873.                                                                                 }

  1874.                                                                                 var state = true;
  1875.                                                                                 if (lightid > 0) {
  1876.                                                                                         state = false;

  1877.                                                                                         var lightarray_id = $gameVariables.GetLightArrayId();
  1878.                                                                                         var lightarray_state = $gameVariables.GetLightArrayState();
  1879.                                                                                         var lightarray_color = $gameVariables.GetLightArrayColor();

  1880.                                                                                         for (var j = 0; j < lightarray_id.length; j++) {
  1881.                                                                                                 if (lightarray_id[j] == lightid) {
  1882.                                                                                                         // idfound = true;
  1883.                                                                                                         state = lightarray_state[j];

  1884.                                                                                                         var newcolor = lightarray_color[j];

  1885.                                                                                                         if (newcolor != 'defaultcolor') {
  1886.                                                                                                                 colorvalue = newcolor;
  1887.                                                                                                         }

  1888.                                                                                                         //Graphics.Debug("lightarrays",lightarray_id.length+' '+lightarray_state.length+' '+lightarray_color.length )

  1889.                                                                                                         //var mapid = $gameMap.mapId();
  1890.                                                                                                         //var eventid = $gameMap.events()[i]._eventId;

  1891.                                                                                                         //Graphics.printError('test',mapid+' '+eventid);
  1892.                                                                                                         key = [map_id, evid , 'D'];
  1893.                                                                                                         if (state == true) {
  1894.                                                                                                                 $gameSelfSwitches.setValue(key, true);
  1895.                                                                                                         } else {
  1896.                                                                                                                 $gameSelfSwitches.setValue(key, false);
  1897.                                                                                                         }
  1898.                                                                                                 }
  1899.                                                                                         }
  1900.                                                                                 }

  1901.                                                                                 // kill switch
  1902.                                                                                 if (killswitch == 'A' || killswitch == 'B' || killswitch == 'C' || killswitch == 'D') {
  1903.                                                                                         key = [map_id, evid, killswitch];
  1904.                                                                                         if ($gameSelfSwitches.value(key) == true) {
  1905.                                                                                                 state = false;
  1906.                                                                                                 //Graphics.Debug('Deathswitch',killswitch);
  1907.                                                                                         }
  1908.                                                                                 }



  1909.                                                                                 // show light
  1910.                                                                                 if (state == true) {

  1911.                                                                                         var lpx = 0;
  1912.                                                                                         var lpy = 0;
  1913.                                                                                         var ldir = 0;
  1914.                                                                                         if (event_moving[i] >0) {
  1915.                                                                                                 lpx = $gameMap.events()[event_stacknumber[i]]._realX;
  1916.                                                                                                 lpy = $gameMap.events()[event_stacknumber[i]]._realY;
  1917.                                                                                                 ldir = $gameMap.events()[event_stacknumber[i]]._direction;

  1918.                                                                                         //        lpx = event_x[i];
  1919.                                                                                         //        lpy = event_y[i];
  1920.                                                                                         //        ldir = event_dir[i];

  1921.                                                                                         } else {
  1922.                                                                                                 lpx = event_x[i];
  1923.                                                                                                 lpy = event_y[i];
  1924.                                                                                                 ldir = event_dir[i];
  1925.                                                                                         }

  1926.                                                                                         //var lpx = $gameMap.events()[i]._realX;
  1927.                                                                                         //var lpy = $gameMap.events()[i]._realY;
  1928.                                                                                         //var ldir = $gameMap.events()[i]._direction;

  1929.                                                                                         // moving lightsources
  1930.                                                                                         var flashlight = false;
  1931.                                                                                         if (note_command == "flashlight") {
  1932.                                                                                                 flashlight = true;

  1933.                                                                                                 var walking = event_moving[i];
  1934.                                                                                                 if (walking == false) {
  1935.                                                                                                         var tldir = Number(note_args.shift());
  1936.                                                                                                         if (!isNaN(tldir)) {
  1937.                                                                                                                 if (tldir < 0 || ldir >= 5) {
  1938.                                                                                                                         ldir = 4
  1939.                                                                                                                 }
  1940.                                                                                                                 if (tldir == 1) {
  1941.                                                                                                                         ldir = 8
  1942.                                                                                                                 }
  1943.                                                                                                                 if (tldir == 2) {
  1944.                                                                                                                         ldir = 6
  1945.                                                                                                                 }
  1946.                                                                                                                 if (tldir == 3) {
  1947.                                                                                                                         ldir = 2
  1948.                                                                                                                 }
  1949.                                                                                                                 if (tldir == 4) {
  1950.                                                                                                                         ldir = 4
  1951.                                                                                                                 }
  1952.                                                                                                         }
  1953.                                                                                                 }


  1954.                                                                                         }

  1955.                                                                                         //Graphics.Debug('ldir',ldir);

  1956.                                                                                         var lx1 = (pw / 2) + ( (lpx - dx) * pw);
  1957.                                                                                         var ly1 = (ph / 2) + ( (lpy - dy) * ph);
  1958.                                                                                         // paralaxloop does something weird with coordinates.. recalc needed

  1959.                                                                                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  1960.                                                                                                 if (dx - 10 > lpx) {
  1961.                                                                                                         var lxjump = $gameMap.width() - (dx - lpx);
  1962.                                                                                                         lx1 = (pw / 2) + (lxjump * pw);
  1963.                                                                                                 }
  1964.                                                                                         }
  1965.                                                                                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  1966.                                                                                                 if (dy - 10 > lpy) {
  1967.                                                                                                         var lyjump = $gameMap.height() - (dy - lpy);
  1968.                                                                                                         ly1 = (ph / 2) + (lyjump * ph);
  1969.                                                                                                 }
  1970.                                                                                         }

  1971.                                                                                         if (flashlight == true) {
  1972.                                                                                                 this._maskBitmap.radialgradientFillRect2(lx1, ly1, 0, light_radius, colorvalue, '#000000', ldir, flashlength, flashwidth);
  1973.                                                                                         } else {
  1974.                                                                                                 this._maskBitmap.radialgradientFillRect(lx1, ly1, 0, light_radius, colorvalue, '#000000', objectflicker, brightness, direction);
  1975.                                                                                         }

  1976.                                                                                 }



  1977.                                                                         }
  1978.                                                                 }



  1979.                                                         //}
  1980.                                                 }



  1981.                                                 // *************************** TILE TAG *********************
  1982.                                                 //

  1983.                                                 //var tilearray = $gameVariables.GetTileArray();

  1984.                                                 //glow/colorfade
  1985.                                                 var glowdatenow = new Date();
  1986.                                                 var glowseconds = Math.floor(glowdatenow.getTime() / 100);

  1987.                                                 if (glowseconds > glow_oldseconds) {
  1988.                                                         //Graphics.Debug('GLOW',tileglow);
  1989.                                                         glow_oldseconds = glowseconds;
  1990.                                                         tileglow = tileglow + glow_dir;

  1991.                                                         if (tileglow > 120) {
  1992.                                                                 glow_dir = -1;
  1993.                                                         }
  1994.                                                         if (tileglow < 1) {
  1995.                                                                 glow_dir = 1;
  1996.                                                         }
  1997.                                                 }

  1998.                                                 tile_lights = $gameVariables.GetLightTags();
  1999.                                                 tile_blocks = $gameVariables.GetBlockTags();

  2000.                                                 //Graphics.Debug('tile length',tile_lights.length);
  2001.                                                 for (var i = 0; i < tile_lights.length; i++) {
  2002.                                                         var tilestr = tile_lights[i];

  2003.                                                         var tileargs = tilestr.split(";");
  2004.                                                         var x = tileargs[0];
  2005.                                                         var y = tileargs[1];
  2006.                                                         var tile_type = tileargs[2];
  2007.                                                         var tile_radius = tileargs[3];
  2008.                                                         var tile_color = tileargs[4];
  2009.                                                         var brightness = tileargs[5];

  2010.                                                         //Graphics.Debug('tile',x+" "+y+" "+tile_type+" "+tile_radius+" "+tile_color+" "+brightness);

  2011.                                                         var x1 = (pw / 2) + (x - dx) * pw;
  2012.                                                         var y1 = (ph / 2) + (y - dy) * ph;

  2013.                                                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  2014.                                                                 if (dx - 5 > x) {
  2015.                                                                         var lxjump = $gameMap.width() - (dx - x);
  2016.                                                                         x1 = (pw / 2) + (lxjump * pw);
  2017.                                                                 }
  2018.                                                         }
  2019.                                                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  2020.                                                                 if (dy - 5 > y) {
  2021.                                                                         var lyjump = $gameMap.height() - (dy - y);
  2022.                                                                         y1 = (ph / 2) + (lyjump * ph);
  2023.                                                                 }
  2024.                                                         }

  2025.                                                         if (tile_type == 3 || tile_type == 4) {
  2026.                                                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, tile_color, '#000000', false, brightness); // Light
  2027.                                                         } else if (tile_type == 5 || tile_type == 6) {
  2028.                                                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, tile_color, '#000000', true, brightness);  // Fire
  2029.                                                         } else {

  2030.                                                                 //Graphics.Debug('Tiletype',tile_type);
  2031.                                                                 var r = hexToRgb(tile_color).r;
  2032.                                                                 var g = hexToRgb(tile_color).g;
  2033.                                                                 var b = hexToRgb(tile_color).b;


  2034.                                                                 r = Math.floor(r + (60 - tileglow));
  2035.                                                                 g = Math.floor(g + (60 - tileglow));
  2036.                                                                 b = Math.floor(b + (60 - tileglow));
  2037.                                                                 //Graphics.Debug('Tiletype',tileglow+' '+r+' '+g+' '+b);
  2038.                                                                 if (r < 0) {
  2039.                                                                         r = 0;
  2040.                                                                 }
  2041.                                                                 if (g < 0) {
  2042.                                                                         g = 0;
  2043.                                                                 }
  2044.                                                                 if (b < 0) {
  2045.                                                                         b = 0;
  2046.                                                                 }
  2047.                                                                 if (r > 255) {
  2048.                                                                         r = 255;
  2049.                                                                 }
  2050.                                                                 if (g > 255) {
  2051.                                                                         g = 255;
  2052.                                                                 }
  2053.                                                                 if (b > 255) {
  2054.                                                                         b = 255;
  2055.                                                                 }

  2056.                                                                 var newtile_color = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  2057.                                                                 //Graphics.Debug('Tiletype',tileglow+' '+r+' '+g+' '+b+' '+newtile_color);
  2058.                                                                 this._maskBitmap.radialgradientFillRect(x1, y1, 0, tile_radius, newtile_color, '#000000', false, brightness);
  2059.                                                         }


  2060.                                                 }



  2061.                                                 ctx.globalCompositeOperation = "multiply";
  2062.                                                 for (var i = 0; i < tile_blocks.length; i++) {
  2063.                                                         var tilestr = tile_blocks[i];
  2064.                                                         var tileargs = tilestr.split(";");

  2065.                                                         var x = tileargs[0];
  2066.                                                         var y = tileargs[1];
  2067.                                                         var shape = tileargs[2];
  2068.                                                         var xo1 = tileargs[3];
  2069.                                                         var yo1 = tileargs[4];
  2070.                                                         var xo2 = tileargs[5];
  2071.                                                         var yo2 = tileargs[6];
  2072.                                                         var tile_color = tileargs[7];


  2073.                                                         var x1 = (x - dx) * pw;
  2074.                                                         var y1 = (y - dy) * ph;

  2075.                                                         if ($dataMap.scrollType === 2 || $dataMap.scrollType === 3) {
  2076.                                                                 if (dx - 5 > x) {
  2077.                                                                         var lxjump = $gameMap.width() - (dx - x);
  2078.                                                                         x1 = (lxjump * pw);
  2079.                                                                 }
  2080.                                                         }
  2081.                                                         if ($dataMap.scrollType === 1 || $dataMap.scrollType === 3) {
  2082.                                                                 if (dy - 5 > y) {
  2083.                                                                         var lyjump = $gameMap.height() - (dy - y);
  2084.                                                                         y1 = (lyjump * ph);
  2085.                                                                 }
  2086.                                                         }
  2087.                                                         if (shape == 0) {
  2088.                                                                 this._maskBitmap.FillRect(x1, y1, pw, ph, tile_color);
  2089.                                                         }
  2090.                                                         if (shape == 1) {
  2091.                                                                 x1 = x1 + Number(xo1);
  2092.                                                                 y1 = y1 + Number(yo1);
  2093.                                                                 this._maskBitmap.FillRect(x1, y1, Number(xo2), Number(yo2), tile_color);
  2094.                                                         }
  2095.                                                         if (shape == 2) {
  2096.                                                                 x1 = x1 + Number(xo1);
  2097.                                                                 y1 = y1 + Number(yo1);
  2098.                                                                 //this._maskBitmap.FillRect(x1,y1,pw,ph,tile_color);
  2099.                                                                 this._maskBitmap.FillCircle(x1, y1, Number(xo2), Number(yo2), tile_color);
  2100.                                                         }
  2101.                                                 }
  2102.                                                 ctx.globalCompositeOperation = 'lighter';


  2103.                                                 // *********************************** DAY NIGHT CYCLE FILTER **************************

  2104.                                                 if (daynightset == true) {

  2105.                                                         var daynighttimer = $gameVariables.GetDaynightTimer();     // timer = minutes * speed
  2106.                                                         var daynightcycle = $gameVariables.GetDaynightCycle();     // cycle = hours
  2107.                                                         var daynighthoursinday = $gameVariables.GetDaynightHoursinDay();   // 24
  2108.                                                         var daynightcolors = $gameVariables.GetDaynightColorArray();

  2109.                                                         var color1 = daynightcolors[daynightcycle];

  2110.                                                         if (daynightspeed > 0 && daynightspeed < 5000) {
  2111.                                                                 var nextcolor = daynightcycle + 1;
  2112.                                                                 if (nextcolor >= daynighthoursinday) {
  2113.                                                                         nextcolor = 0;
  2114.                                                                 }
  2115.                                                                 var color2 = daynightcolors[nextcolor];

  2116.                                                                 var r = hexToRgb(color1).r;
  2117.                                                                 var g = hexToRgb(color1).g;
  2118.                                                                 var b = hexToRgb(color1).b;

  2119.                                                                 var r2 = hexToRgb(color2).r;
  2120.                                                                 var g2 = hexToRgb(color2).g;
  2121.                                                                 var b2 = hexToRgb(color2).b;

  2122.                                                                 var stepR = (r2 - r) / (60 * daynightspeed);
  2123.                                                                 var stepG = (g2 - g) / (60 * daynightspeed);
  2124.                                                                 var stepB = (b2 - b) / (60 * daynightspeed);

  2125.                                                                 r = Math.floor(r + (stepR * daynighttimer));
  2126.                                                                 g = Math.floor(g + (stepG * daynighttimer));
  2127.                                                                 b = Math.floor(b + (stepB * daynighttimer));

  2128.                                                         }
  2129.                                                         color1 = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);

  2130.                                                         this._maskBitmap.FillRect(0, 0, maxX + 20, maxY, color1);
  2131.                                                 }

  2132.                                                 // *********************************** TINT **************************


  2133.                                                 if (daynightset == false) {

  2134.                                                         var tint_value = $gameVariables.GetTint();
  2135.                                                         var tint_target = $gameVariables.GetTintTarget();
  2136.                                                         var tint_speed = $gameVariables.GetTintSpeed();


  2137.                                                         if (Terrax_tint_target != terrax_tint_target_old) {
  2138.                                                                 terrax_tint_target_old = Terrax_tint_target;
  2139.                                                                 tint_target = Terrax_tint_target;
  2140.                                                                 $gameVariables.SetTintTarget(tint_target);
  2141.                                                         }
  2142.                                                         if (Terrax_tint_speed != terrax_tint_speed_old) {
  2143.                                                                 terrax_tint_speed_old = Terrax_tint_speed;
  2144.                                                                 tint_speed = Terrax_tint_speed;
  2145.                                                                 $gameVariables.SetTintSpeed(tint_speed);
  2146.                                                         }

  2147.                                                         //Graphics.Debug('TINT',tint_value+' '+tint_target+' '+tint_speed);

  2148.                                                         var tcolor = tint_value;
  2149.                                                         if (tint_value != tint_target) {

  2150.                                                                 var tintdatenow = new Date();
  2151.                                                                 var tintseconds = Math.floor(tintdatenow.getTime() / 10);
  2152.                                                                 if (tintseconds > tint_oldseconds) {
  2153.                                                                         tint_oldseconds = tintseconds;
  2154.                                                                         tint_timer++;
  2155.                                                                 }

  2156.                                                                 var r = hexToRgb(tint_value).r;
  2157.                                                                 var g = hexToRgb(tint_value).g;
  2158.                                                                 var b = hexToRgb(tint_value).b;

  2159.                                                                 var r2 = hexToRgb(tint_target).r;
  2160.                                                                 var g2 = hexToRgb(tint_target).g;
  2161.                                                                 var b2 = hexToRgb(tint_target).b;

  2162.                                                                 var stepR = (r2 - r) / (60 * tint_speed);
  2163.                                                                 var stepG = (g2 - g) / (60 * tint_speed);
  2164.                                                                 var stepB = (b2 - b) / (60 * tint_speed);

  2165.                                                                 var r3 = Math.floor(r + (stepR * tint_timer));
  2166.                                                                 var g3 = Math.floor(g + (stepG * tint_timer));
  2167.                                                                 var b3 = Math.floor(b + (stepB * tint_timer));
  2168.                                                                 if (r3 < 0) {
  2169.                                                                         r3 = 0
  2170.                                                                 }
  2171.                                                                 if (g3 < 0) {
  2172.                                                                         g3 = 0
  2173.                                                                 }
  2174.                                                                 if (b3 < 0) {
  2175.                                                                         b3 = 0
  2176.                                                                 }
  2177.                                                                 if (r3 > 255) {
  2178.                                                                         r3 = 255
  2179.                                                                 }
  2180.                                                                 if (g3 > 255) {
  2181.                                                                         g3 = 255
  2182.                                                                 }
  2183.                                                                 if (b3 > 255) {
  2184.                                                                         b3 = 255
  2185.                                                                 }
  2186.                                                                 var reddone = false;
  2187.                                                                 var greendone = false;
  2188.                                                                 var bluedone = false;
  2189.                                                                 if (stepR >= 0 && r3 >= r2) {
  2190.                                                                         reddone = true;
  2191.                                                                 }
  2192.                                                                 if (stepR <= 0 && r3 <= r2) {
  2193.                                                                         reddone = true;
  2194.                                                                 }
  2195.                                                                 if (stepG >= 0 && g3 >= g2) {
  2196.                                                                         greendone = true;
  2197.                                                                 }
  2198.                                                                 if (stepG <= 0 && g3 <= g2) {
  2199.                                                                         greendone = true;
  2200.                                                                 }
  2201.                                                                 if (stepB >= 0 && b3 >= b2) {
  2202.                                                                         bluedone = true;
  2203.                                                                 }
  2204.                                                                 if (stepB <= 0 && b3 <= b2) {
  2205.                                                                         bluedone = true;
  2206.                                                                 }
  2207.                                                                 if (reddone == true && bluedone == true && greendone == true) {
  2208.                                                                         $gameVariables.SetTint(tint_target);
  2209.                                                                 }
  2210.                                                                 tcolor = "#" + ((1 << 24) + (r3 << 16) + (g3 << 8) + b3).toString(16).slice(1);
  2211.                                                         } else {
  2212.                                                                 tint_timer = 0;
  2213.                                                         }

  2214.                                                         //Graphics.Debug('TINT',tint_value+' '+tint_target+' '+tint_speed+' '+tcolor);

  2215.                                                         this._maskBitmap.FillRect(-20, 0, maxX + 20, maxY, tcolor);
  2216.                                                 }

  2217.                                                 // reset drawmode to normal
  2218.                                                 ctx.globalCompositeOperation = 'source-over';

  2219.                                         }
  2220.                                 }
  2221.                         }
  2222.                 }
  2223.                 StopTiming();
  2224.         };

  2225.         /**
  2226.          * @method _addSprite
  2227.          * @private
  2228.          */
  2229.         Lightmask.prototype._addSprite = function(x1,y1,selectedbitmap) {
  2230.                
  2231.             var sprite = new Sprite(this.viewport);
  2232.             sprite.bitmap = selectedbitmap;
  2233.             sprite.opacity = 255;
  2234.             sprite.blendMode = 2;
  2235.             sprite.x = x1;
  2236.                  sprite.y = y1;
  2237.             this._sprites.push(sprite);
  2238.             this.addChild(sprite);
  2239.             sprite.rotation = 0;
  2240.             sprite.ax = 0;
  2241.             sprite.ay = 0;
  2242.                  sprite.opacity = 255;
  2243.         };
  2244.        
  2245.         /**
  2246.          * @method _removeSprite
  2247.          * @private
  2248.          */
  2249.         Lightmask.prototype._removeSprite = function() {
  2250.             this.removeChild(this._sprites.pop());
  2251.         };
  2252.        

  2253.         // *******************  NORMAL BOX SHAPE ***********************************
  2254.        
  2255.         Bitmap.prototype.FillRect = function(x1, y1, x2, y2, color1) {
  2256.                 x1=x1+20;
  2257.                 //x2=x2+20;
  2258.             var context = this._context;
  2259.             context.save();
  2260.             context.fillStyle = color1;
  2261.             context.fillRect(x1, y1, x2, y2);
  2262.             context.restore();
  2263.             this._setDirty();
  2264.         };
  2265.        
  2266.         // *******************  CIRCLE/OVAL SHAPE ***********************************
  2267.         // from http://scienceprimer.com/draw-oval-html5-canvas
  2268.         Bitmap.prototype.FillCircle = function(centerX, centerY, xradius, yradius, color1) {
  2269.                 centerX=centerX+20;

  2270.             var context = this._context;
  2271.             context.save();
  2272.             context.fillStyle = color1;
  2273.                    context.beginPath();
  2274.                    var rotation = 0;
  2275.                    var start_angle = 0;
  2276.                    var end_angle = 2 * Math.PI;
  2277.                 for (var i = start_angle * Math.PI; i < end_angle * Math.PI; i += 0.01 ) {
  2278.                     xPos = centerX - (yradius * Math.sin(i)) * Math.sin(rotation * Math.PI) + (xradius * Math.cos(i)) * Math.cos(rotation * Math.PI);
  2279.                     yPos = centerY + (xradius * Math.cos(i)) * Math.sin(rotation * Math.PI) + (yradius * Math.sin(i)) * Math.cos(rotation * Math.PI);

  2280.                     if (i == 0) {
  2281.                         context.moveTo(xPos, yPos);
  2282.                     } else {
  2283.                         context.lineTo(xPos, yPos);
  2284.                     }
  2285.                 }
  2286.                 context.fill();
  2287.                 context.closePath();
  2288.             context.restore();
  2289.             this._setDirty();
  2290.         };

  2291.         // *******************  NORMAL LIGHT SHAPE ***********************************
  2292.         // Fill gradient circle
  2293.        
  2294.         Bitmap.prototype.radialgradientFillRect = function(x1, y1, r1, r2, color1, color2, flicker, brightness, direction) {

  2295.                 var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
  2296.                 if (!isValidColor) {
  2297.                         color1 = '#000000'
  2298.                 }
  2299.                 var isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
  2300.                 if (!isValidColor2) {
  2301.                         color2 = '#000000'
  2302.                 }

  2303.                 x1=x1+20;

  2304.                 // clipping
  2305.                 var nx1 = Number(x1);
  2306.                 var ny1 = Number(y1);
  2307.                 var nr2 = Number(r2);

  2308.                 var clip = false;

  2309.                 if (nx1-nr2>maxX) {
  2310.                         clip = true;
  2311.                 }
  2312.                 if (ny1-nr2>maxY) {
  2313.                         clip = true;
  2314.                 }
  2315.                 if (nx1+nr2<0) {
  2316.                         clip = true;
  2317.                 }
  2318.                 if (nx1+nr2<0) {
  2319.                         clip = true;
  2320.                 }

  2321.                 //Graphics.Debug('Screen',startx+" "+starty+" "+endx+" "+endy+" "+nx1+" "+ny1+" "+nr2);

  2322.                 if (clip == false) {

  2323.                         if (!brightness) {
  2324.                                 brightness = 0.0;
  2325.                         }
  2326.                         if (!direction) {
  2327.                                 direction = 0;
  2328.                         }
  2329.                         var context = this._context;
  2330.                         var grad;
  2331.                         var wait = Math.floor((Math.random() * 8) + 1);
  2332.                         if (flicker == true && wait == 1) {
  2333.                                 var flickerradiusshift = $gameVariables.GetFireRadius();
  2334.                                 var flickercolorshift = $gameVariables.GetFireColorshift();
  2335.                                 var gradrnd = Math.floor((Math.random() * flickerradiusshift) + 1);
  2336.                                 var colorrnd = Math.floor((Math.random() * flickercolorshift) - (flickercolorshift / 2));

  2337.                                 var r = hexToRgb(color1).r;
  2338.                                 var g = hexToRgb(color1).g;
  2339.                                 var b = hexToRgb(color1).b;
  2340.                                 g = g + colorrnd;
  2341.                                 if (g < 0) {
  2342.                                         g = 0;
  2343.                                 }
  2344.                                 if (g > 255) {
  2345.                                         g = 255;
  2346.                                 }
  2347.                                 color1 = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
  2348.                                 r2 = r2 - gradrnd;
  2349.                                 if (r2 < 0) r2 = 0;
  2350.                         }

  2351.                         grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  2352.                         if (brightness) {
  2353.                                 grad.addColorStop(0, '#FFFFFF');
  2354.                         }
  2355.                         grad.addColorStop(brightness, color1);

  2356.                         grad.addColorStop(1, color2);

  2357.                         context.save();
  2358.                         context.fillStyle = grad;
  2359.                         direction = Number(direction);
  2360.                         var pw = $gameMap.tileWidth() / 2;
  2361.                         var ph = $gameMap.tileHeight() / 2;
  2362.                         switch (direction) {
  2363.                                 case 0:
  2364.                                         context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  2365.                                         break;
  2366.                                 case 1:
  2367.                                         context.fillRect(x1 - r2, y1 - ph, r2 * 2, r2 * 2);
  2368.                                         break;
  2369.                                 case 2:
  2370.                                         context.fillRect(x1 - r2, y1 - r2, r2 * 1 + pw, r2 * 2);
  2371.                                         break;
  2372.                                 case 3:
  2373.                                         context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 1 + ph);
  2374.                                         break;
  2375.                                 case 4:
  2376.                                         context.fillRect(x1 - pw, y1 - r2, r2 * 2, r2 * 2);
  2377.                                         break;
  2378.                         }


  2379.                         // context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
  2380.                         context.restore();
  2381.                         this._setDirty();
  2382.                 }
  2383.         };
  2384.        
  2385.         // ********************************** FLASHLIGHT *************************************
  2386.         // Fill gradient Cone
  2387.        
  2388.         Bitmap.prototype.radialgradientFillRect2 = function(x1, y1, r1, r2, color1, color2, direction, flashlength, flashwidth) {
  2389.                 x1=x1+20;

  2390.                 var isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
  2391.                 if (!isValidColor) {
  2392.                         color1 = '#000000'
  2393.                 }
  2394.                 var isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
  2395.                 if (!isValidColor2) {
  2396.                         color2 = '#000000'
  2397.                 }

  2398.             var context = this._context;
  2399.             var grad;       
  2400.             
  2401.             // smal dim glove around player
  2402.                    context.save();
  2403.             y1 = y1 - flashlightoffset;
  2404.              
  2405.             r1 = 1;
  2406.                   r2 = 40;
  2407.                 grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  2408.                 grad.addColorStop(0, '#999999');
  2409.                 grad.addColorStop(1, color2);
  2410.        
  2411.                 context.fillStyle = grad;
  2412.                 context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
  2413.             
  2414.             // flashlight
  2415.             
  2416.                 for (var cone = 0; cone < flashlength; cone++) {
  2417.                         var flashlightdensity =  $gameVariables.GetFlashlightDensity();
  2418.                            r1 = cone * flashlightdensity;
  2419.                           r2 = cone * flashwidth;
  2420.                          
  2421.                           switch(direction) {
  2422.                             case 6:
  2423.                                     x1 = x1 + cone*6;
  2424.                                    break;
  2425.                                    case 4:
  2426.                                            x1 = x1 - cone*6;
  2427.                                    break;
  2428.                                    case 2:
  2429.                                            y1 = y1 + cone*6;
  2430.                                    break;
  2431.                     case 8:
  2432.                             y1 = y1 - cone*6;
  2433.                                    break;
  2434.                         }
  2435.                                            

  2436.                           grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  2437.                     grad.addColorStop(0, color1);
  2438.                     grad.addColorStop(1, color2);
  2439.        
  2440.                     context.fillStyle = grad;
  2441.                     context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
  2442.             }
  2443.             context.fillStyle = grad;
  2444.                 context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
  2445.                
  2446.             context.restore();            
  2447.             this._setDirty();
  2448.         };
  2449.        
  2450.        
  2451.         function hexToRgb(hex) {
  2452.             var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  2453.             return result ? {
  2454.                 r: parseInt(result[1], 16),
  2455.                 g: parseInt(result[2], 16),
  2456.                 b: parseInt(result[3], 16)
  2457.             } : null;
  2458.         }


  2459.         Game_Variables.prototype.GetFirstRun = function() {
  2460.                 if (typeof this._Terrax_Lighting_FirstRun == 'undefined') {
  2461.                         this._Terrax_Lighting_FirstRun = true;
  2462.                 }
  2463.                 return this._Terrax_Lighting_FirstRun;
  2464.         };
  2465.         Game_Variables.prototype.SetFirstRun = function(value) {
  2466.                 this._Terrax_Lighting_FirstRun = value;
  2467.         };
  2468.         Game_Variables.prototype.GetScriptActive = function() {
  2469.                 if (typeof this._Terrax_Lighting_ScriptActive == 'undefined') {
  2470.                         this._Terrax_Lighting_ScriptActive = true;
  2471.                 }
  2472.                 return this._Terrax_Lighting_ScriptActive;
  2473.         };
  2474.         Game_Variables.prototype.SetScriptActive = function(value) {
  2475.                 this._Terrax_Lighting_ScriptActive = value;
  2476.         };
  2477.         Game_Variables.prototype.GetStopScript = function() {
  2478.                 if (typeof this._Terrax_Lighting_StopScript == 'undefined') {
  2479.                         this._Terrax_Lighting_StopScript = false;
  2480.                 }
  2481.                 return this._Terrax_Lighting_StopScript;
  2482.         };
  2483.         Game_Variables.prototype.SetStopScript = function(value) {
  2484.                 this._Terrax_Lighting_StopScript = value;
  2485.         };

  2486.         Game_Variables.prototype.SetMog = function(value) {
  2487.                 this._Terrax_Lighting_Mog = value;
  2488.         };
  2489.         Game_Variables.prototype.GetMog = function() {
  2490.                 return this._Terrax_Lighting_Mog || false;
  2491.         };
  2492.         Game_Variables.prototype.SetMogTintArray = function(value) {
  2493.                 this._Terrax_Lighting_MogTintArray = value;
  2494.         };
  2495.         Game_Variables.prototype.GetMogTintArray = function() {
  2496.                 var default_MT = [ '#555555', '#FFEFD5', '#FFFFFF', '#EEE8AA', '#555555', '#111111' ];
  2497.                 return this._Terrax_Lighting_MogTintArray || default_MT;
  2498.         };

  2499.         Game_Variables.prototype.SetTint = function(value) {
  2500.                 this._Terrax_Tint_Value = value;
  2501.         };
  2502.         Game_Variables.prototype.GetTint = function() {
  2503.                 return this._Terrax_Tint_Value || '#000000';
  2504.         };
  2505.         Game_Variables.prototype.SetTintTarget = function(value) {
  2506.                 this._Terrax_TintTarget_Value = value;
  2507.         };
  2508.         Game_Variables.prototype.GetTintTarget = function() {
  2509.                 return this._Terrax_TintTarget_Value || '#000000';
  2510.         };
  2511.         Game_Variables.prototype.SetTintSpeed = function(value) {
  2512.                 this._Terrax_TintSpeed_Value = value;
  2513.         };
  2514.         Game_Variables.prototype.GetTintSpeed = function() {
  2515.                 return this._Terrax_TintSpeed_Value || 60;
  2516.         };

  2517.         Game_Variables.prototype.SetFlashlight = function(value) {
  2518.                 this._Terrax_Lighting_Flashlight = value;
  2519.         };
  2520.         Game_Variables.prototype.GetFlashlight = function() {
  2521.                 return this._Terrax_Lighting_Flashlight || false;
  2522.         };
  2523.         Game_Variables.prototype.SetFlashlightDensity = function(value) {
  2524.                 this._Terrax_Lighting_FlashlightDensity = value;
  2525.         };
  2526.         Game_Variables.prototype.GetFlashlightDensity = function() {
  2527.                 return this._Terrax_Lighting_FlashlightDensity || 3;
  2528.         };
  2529.         Game_Variables.prototype.SetFlashlightLength = function(value) {
  2530.                 this._Terrax_Lighting_FlashlightLength = value;
  2531.         };
  2532.         Game_Variables.prototype.GetFlashlightLength = function() {
  2533.                 return this._Terrax_Lighting_FlashlightLength || 8;
  2534.         };
  2535.         Game_Variables.prototype.SetFlashlightWidth = function(value) {
  2536.                 this._Terrax_Lighting_FlashlightWidth = value;
  2537.         };
  2538.         Game_Variables.prototype.GetFlashlightWidth = function() {
  2539.                 return this._Terrax_Lighting_FlashlightWidth || 12;
  2540.         };

  2541.         Game_Variables.prototype.SetPlayerColor = function(value) {
  2542.                 this._Terrax_Lighting_PlayerColor = value;
  2543.         };
  2544.         Game_Variables.prototype.GetPlayerColor = function() {
  2545.                 return this._Terrax_Lighting_PlayerColor || '#FFFFFF';
  2546.         };
  2547.         Game_Variables.prototype.SetPlayerBrightness = function(value) {
  2548.                 this._Terrax_Lighting_PlayerBrightness = value;
  2549.         };
  2550.         Game_Variables.prototype.GetPlayerBrightness = function(value) {
  2551.                 this._Terrax_Lighting_PlayerBrightness = value || 0.0;
  2552.         };
  2553.         Game_Variables.prototype.SetRadius = function(value) {
  2554.                 this._Terrax_Lighting_Radius = value;
  2555.         };
  2556.         Game_Variables.prototype.GetRadius = function() {
  2557.                 //return this._Terrax_Lighting_Radius || 150;
  2558.                 if (this._Terrax_Lighting_Radius === undefined) {
  2559.                         return 150;
  2560.                 }else {
  2561.                         return this._Terrax_Lighting_Radius;
  2562.                 }
  2563.         };
  2564.         Game_Variables.prototype.SetRadiusTarget = function(value) {
  2565.                 this._Terrax_Lighting_RadiusTarget = value;
  2566.         };
  2567.         Game_Variables.prototype.GetRadiusTarget = function() {
  2568.                 //return this._Terrax_Lighting_RadiusTarget || 150;
  2569.                 if (this._Terrax_Lighting_RadiusTarget === undefined) {
  2570.                         return 150;
  2571.                 }else {
  2572.                         return this._Terrax_Lighting_RadiusTarget;
  2573.                 }
  2574.         };
  2575.         Game_Variables.prototype.SetRadiusSpeed = function(value) {
  2576.                 this._Terrax_Lighting_RadiusSpeed = value;
  2577.         };
  2578.         Game_Variables.prototype.GetRadiusSpeed = function() {
  2579.                 return this._Terrax_Lighting_RadiusSpeed || 0;
  2580.         };

  2581.         Game_Variables.prototype.SetDaynightColorArray = function(value) {
  2582.                 this._Terrax_Lighting_DayNightColorArray = value;
  2583.         };
  2584.         Game_Variables.prototype.GetDaynightColorArray = function() {
  2585.                 var default_color = [  '#000000', '#000000', '#000000', '#000000',
  2586.                                                               '#000000', '#000000', '#666666', '#AAAAAA',
  2587.                                                                   '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
  2588.                                                                   '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF',
  2589.                                                                   '#FFFFFF', '#FFFFFF', '#AAAAAA', '#666666',
  2590.                                                                   '#000000', '#000000', '#000000', '#000000' ];
  2591.                 return this._Terrax_Lighting_DayNightColorArray || default_color;
  2592.         };
  2593.         Game_Variables.prototype.SetDaynightSpeed = function(value) {
  2594.                 this._Terrax_Lighting_DaynightSpeed = value;
  2595.         };
  2596.         Game_Variables.prototype.GetDaynightSpeed = function() {
  2597.                 return this._Terrax_Lighting_DaynightSpeed || 10;
  2598.         };
  2599.         Game_Variables.prototype.SetDaynightCycle = function(value) {
  2600.                 this._Terrax_Lighting_DaynightCycle = value;
  2601.         };
  2602.         Game_Variables.prototype.GetDaynightCycle = function() {
  2603.                 return this._Terrax_Lighting_DaynightCycle || 0;
  2604.         };
  2605.         Game_Variables.prototype.SetDaynightTimer = function(value) {
  2606.                 this._Terrax_Lighting_DaynightTimer = value;
  2607.         };
  2608.         Game_Variables.prototype.GetDaynightTimer = function() {
  2609.                 return this._Terrax_Lighting_DaynightTimer || 0;
  2610.         };
  2611.         Game_Variables.prototype.SetDaynightHoursinDay = function(value) {
  2612.                 this._Terrax_Lighting_DaynightHoursinDay = value;
  2613.         };
  2614.         Game_Variables.prototype.GetDaynightHoursinDay = function() {
  2615.                 return this._Terrax_Lighting_DaynightHoursinDay || 24;
  2616.         };

  2617.         Game_Variables.prototype.SetFireRadius = function(value) {
  2618.                 this._Terrax_Lighting_FireRadius = value;
  2619.         };
  2620.         Game_Variables.prototype.GetFireRadius = function() {
  2621.                 return this._Terrax_Lighting_FireRadius || 7;
  2622.         };
  2623.         Game_Variables.prototype.SetFireColorshift = function(value) {
  2624.                 this._Terrax_Lighting_FireColorshift = value;
  2625.         };
  2626.         Game_Variables.prototype.GetFireColorshift = function() {
  2627.                 return this._Terrax_Lighting_FireColorshift || 10;
  2628.         };
  2629.         Game_Variables.prototype.SetFire = function(value) {
  2630.                 this._Terrax_Lighting_Fire = value;
  2631.         };
  2632.         Game_Variables.prototype.GetFire = function() {
  2633.                 return this._Terrax_Lighting_Fire || false;
  2634.         };

  2635.         Game_Variables.prototype.SetLightArrayId = function(value) {
  2636.                 this._Terrax_Lighting_LightArrayId = value;
  2637.         };
  2638.         Game_Variables.prototype.GetLightArrayId = function() {
  2639.                 var default_LAI = [];
  2640.                 return this._Terrax_Lighting_LightArrayId || default_LAI;
  2641.         };
  2642.         Game_Variables.prototype.SetLightArrayState = function(value) {
  2643.                 this._Terrax_Lighting_LightArrayState = value;
  2644.         };
  2645.         Game_Variables.prototype.GetLightArrayState = function() {
  2646.                 var default_LAS = [];
  2647.                 return this._Terrax_Lighting_LightArrayState || default_LAS;
  2648.         };
  2649.         Game_Variables.prototype.SetLightArrayColor = function(value) {
  2650.                 this._Terrax_Lighting_LightArrayColor = value;
  2651.         };
  2652.         Game_Variables.prototype.GetLightArrayColor = function() {
  2653.                 var default_LAS = [];
  2654.                 return this._Terrax_Lighting_LightArrayColor || default_LAS;
  2655.         };

  2656.         Game_Variables.prototype.SetTileArray = function(value) {
  2657.                 this._Terrax_Lighting_TileArray = value;
  2658.         };
  2659.         Game_Variables.prototype.GetTileArray = function() {
  2660.                 var default_TA = [];
  2661.                 return this._Terrax_Lighting_TileArray || default_TA;
  2662.         };
  2663.         Game_Variables.prototype.SetLightTags = function(value) {
  2664.                 this._Terrax_Lighting_LightTags = value;
  2665.         };
  2666.         Game_Variables.prototype.GetLightTags = function() {
  2667.                 var default_TA = [];
  2668.                 return this._Terrax_Lighting_LightTags || default_TA;
  2669.         };
  2670.         Game_Variables.prototype.SetBlockTags = function(value) {
  2671.                 this._Terrax_Lighting_BlockTags = value;
  2672.         };
  2673.         Game_Variables.prototype.GetBlockTags = function() {
  2674.                 var default_TA = [];
  2675.                 return this._Terrax_Lighting_BlockTags || default_TA;
  2676.         };

  2677.         // dummy for compatiblity with push.
  2678.         function SaveLightingVariables() {
  2679.         }

  2680.         function StartTiming() {
  2681.                 // Timing function for debugging
  2682.                 var datenow = new Date();
  2683.                 debugtimer = datenow.getTime();
  2684.         }

  2685.         function StopTiming() {
  2686.                 // speedtest function
  2687.                 if (speeddebug == true) {
  2688.                         var datenow = new Date();
  2689.                         var debugtimer2 = datenow.getTime();
  2690.                         averagetime[averagetimecount] = debugtimer2 - debugtimer;
  2691.                         averagetimecount++;
  2692.                         var totalcount = 0;
  2693.                         for (var y = 0; y < averagetime.length; y++) {
  2694.                                 totalcount = totalcount + averagetime[y];
  2695.                         }
  2696.                         if (averagetimecount > 500) {
  2697.                                 averagetimecount = 0;
  2698.                                 Graphics.Debug('Speedtest', totalcount / 500);
  2699.                         }
  2700.                 }
  2701.         }

  2702.         //****
  2703.         // Debug
  2704.         //****

  2705.         Graphics.Debug = function(name, message) {
  2706.             if (this._errorPrinter) {
  2707.                 this._errorPrinter.innerHTML = this._makeErrorHtml(name, message);
  2708.             }
  2709.         }


  2710.         //****
  2711.         // This function is overwritten from rpg_sprites.js
  2712.         //****

  2713.         Spriteset_Map.prototype.createLowerLayer = function() {
  2714.             Spriteset_Base.prototype.createLowerLayer.call(this);
  2715.             this.createParallax();
  2716.             this.createTilemap();
  2717.             this.createCharacters();
  2718.             this.createShadow();
  2719.             this.createDestination();
  2720.             this.createLightmask();
  2721.             this.createWeather();
  2722.        
  2723.         };

  2724.         // ALLIASED Move event location => reload map.

  2725.         var Alias_Game_Interpreter_command203 = Game_Interpreter.prototype.command203;
  2726.         Game_Interpreter.prototype.command203 = function() {
  2727.                 Alias_Game_Interpreter_command203.call(this);
  2728.                 ReloadMapEvents();
  2729.                 return true;
  2730.         };


  2731. // ALIASED FROM RPG OBJECTS TO ADD LIGHTING TO CONFIG MENU

  2732.         ConfigManager.TxLighting = true;

  2733.         Object.defineProperty(ConfigManager, 'TxLighting', {
  2734.                 get: function() {
  2735.                         return options_lighting_on;
  2736.                 },
  2737.                 set: function(value) {
  2738.                         options_lighting_on = value;
  2739.                 },
  2740.                 configurable: true
  2741.         });

  2742.         var Alias_ConfigManager_makeData = ConfigManager.makeData;
  2743.         ConfigManager.makeData = function() {
  2744.                 var config = Alias_ConfigManager_makeData.call(this);
  2745.                 config.TxLighting = options_lighting_on;
  2746.                 return config;
  2747.         };

  2748.         var Alias_ConfigManager_applyData = ConfigManager.applyData;
  2749.         ConfigManager.applyData = function(config) {
  2750.                 Alias_ConfigManager_applyData.call(this,config);
  2751.                 this.TxLighting = this.readFlag2(config, 'TxLighting');
  2752.         };

  2753.         var Window_Options_addGeneralOptions = Window_Options.prototype.addGeneralOptions;
  2754.         Window_Options.prototype.addGeneralOptions = function() {
  2755.                 Window_Options_addGeneralOptions.call(this);
  2756.                 if (add_to_options == "Yes") {
  2757.                         this.addCommand(optiontext, 'TxLighting');
  2758.                 }
  2759.         };

  2760.         ConfigManager.readFlag2 = function(config, name) {
  2761.                 var value = config[name];
  2762.                 if (value !== undefined) {
  2763.                         return !!config[name];
  2764.                 } else {
  2765.                         return true;
  2766.                 }
  2767.         };





  2768. })();

  2769.        
  2770.        
复制代码

Image 008.png (262.75 KB, 下载次数: 27)

Image 008.png

点评

求后面这张图...  发表于 2019-4-23 20:51
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
765
在线时间
90 小时
注册时间
2018-10-29
帖子
94
40
发表于 2019-1-14 15:26:46 | 只看该作者
不能和滚动地图使用,因为气泡是固定在地图上的,如果滚动的同时使用气泡对话会出现对话框消失的情况
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-19 14:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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