查看: 5734|回复: 18

[讨论] MV的代码解析【持续更新】

[复制链接]

唯一的信徒

梦石
0
星屑
1697
在线时间
1359 小时
注册时间
2013-1-29
回帖
1537
发表于 2015-10-1 14:32:11 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 LBQ 于 2015-10-3 10:27 编辑

10月3日:
有了TextManager你说我们要不要i18n
binary json可以试试
10月2日:
没有预想的那么恶心233
[pre lang="coffeescript"]class Scene_Crafting extends Scene_MenuBase
  initialize: ->
    super()
  create: ->
    super()
    this.createBackground()
    this.createWindowLayer()
    this.createGoldWindow()
  start: ->
    super()
  createGoldWindow: ->
    @goldWindow = new Window_Gold(0,0)
    this.addWindow(@goldWindow)[/pre]

我没法用Plugin更改plugin manager
我选择死亡

pixi.js用的v2感觉很不爽,应该移植到v3的


其实重点是pixi.js啊
想想看这些可能性啊
捕获.JPG
捕获2.JPG
捕获3.JPG


Google closure compiler的advance编译别想了,mv代码没有预先准备最终产物没法运行
UglifyJs之类的还是可以用
Desktop版本会用Nw.js作为Js后端,可以直接开node
binary json估计是可以用


原网页:http://preorder.rpgmakerweb.com/rpg-maker-mv/



毕竟有游戏了所以解析一下吧:

1:Yanfly下手好快,现在就有脚本了是怎么回事,黑幕吗
2:渲染用的Pixi.js,我很开心

继续读代码中,游戏不知道为何玩不了只能读代码了

3:没有用npm或者commonjs之类的,直接采用的html引用脚本,这个到时候得修一下
4:主题代码被minify或者obfuscate了,不好读

5:core.js:https://www.refheap.com/110141
6:managers.js:https://www.refheap.com/110142

很明显数据库用的json
好评

7:objects.js:https://www.refheap.com/110143,太长了,refheap不知道为何不行。
objects.7z (36.89 KB, 下载次数: 60)
8:scenes.js:https://www.refheap.com/110144
9:sprites.js : https://www.refheap.com/110145
Window.prototype.initialize是什么鬼

看得出来代码是中规中矩的ruby式js....?

本来Js比Ruby更加Functional一些的,但是为了保持惯例继续用Ruby的法则...?
10:window.js:https://www.refheap.com/110146

感觉有点像用Js写Ruby代码233
还是猴子补丁,一堆猴子补丁

[pre lang="javascript"]Window_BattleLog.prototype.callNextMethod = function() {
    if (this._methods.length > 0) {
        var method = this._methods.shift();
        if (method.name && this[method.name]) {
            this[method.name].apply(this, method.params)
        } else {
            throw new Error('Method not found: ' + method.name)
        }
    }
};[/pre]

这段代码真心诡异

全部代码打包:
mv-core-src.7z (103.88 KB, 下载次数: 78)

Scene与Scene之间切换都没有什么鬼

数据库json文件打包: data.zip (19.89 KB, 下载次数: 86)

这行走图和脸图让我蛋疼的不行

Sprite的代码:
[pre lang="javascript"]Sprite.prototype._renderWebGL = function(renderSession) {
    if (this.visible && this.alpha > 0) {
        var spriteBatch = renderSession.spriteBatch;
        if (this._filters) {
            spriteBatch.flush();
            renderSession.filterManager.pushFilter(this._filterBlock);
            if (this.opaque) {
                renderSession.gl.clearColor(0, 0, 0, 1);
                renderSession.gl.clear(renderSession.gl.COLOR_BUFFER_BIT)
            }
        }
        if (this._mask) {
            spriteBatch.stop();
            renderSession.maskManager.pushMask(this.mask, renderSession);
            spriteBatch.start()
        }
        spriteBatch.render(this);
        for (var i = 0, j = this.children.length; i < j; i++) {
            this.children._renderWebGL(renderSession)
        }
        if (this._mask) {
            spriteBatch.stop();
            renderSession.maskManager.popMask(this._mask, renderSession);
            spriteBatch.start()
        }
        if (this._filters) {
            spriteBatch.stop();
            renderSession.filterManager.popFilter();
            spriteBatch.start()
        }
    }
};[/pre]

Pixi.js的同样的方法
[pre lang="javascript"]PIXI.Sprite.prototype._renderWebGL = function(renderSession)
{
    // if the sprite is not visible or the alpha is 0 then no need to render this element
    if(!this.visible || this.alpha <= 0)return;

    var i,j;

    // do a quick check to see if this element has a mask or a filter.
    if(this._mask || this._filters)
    {
        var spriteBatch =  renderSession.spriteBatch;

        // push filter first as we need to ensure the stencil buffer is correct for any masking
        if(this._filters)
        {
            spriteBatch.flush();
            renderSession.filterManager.pushFilter(this._filterBlock);
        }

        if(this._mask)
        {
            spriteBatch.stop();
            renderSession.maskManager.pushMask(this.mask, renderSession);
            spriteBatch.start();
        }

        // add this sprite to the batch
        spriteBatch.render(this);

        // now loop through the children and make sure they get rendered
        for(i=0,j=this.children.length; i<j; i++)
        {
            this.children._renderWebGL(renderSession);
        }

        // time to stop the sprite batch as either a mask element or a filter draw will happen next
        spriteBatch.stop();

        if(this._mask)renderSession.maskManager.popMask(this._mask, renderSession);
        if(this._filters)renderSession.filterManager.popFilter();

        spriteBatch.start();
    }
    else
    {
        renderSession.spriteBatch.render(this);

        // simple render children!
        for(i=0,j=this.children.length; i<j; i++)
        {
            this.children._renderWebGL(renderSession);
        }

    }
};[/pre]

MV这个代码真的可以去死了,


现在我才意识到Scene是Stage的一种,EB你去死吧

Pixi用的v2,应该无大碍,先这样OTL

评分

参与人数 1星屑 +45 收起 理由
Tink + 45

查看全部评分

『我只是一个正在潜心修炼的渣乐师罢了』
Dear Time\(^o^)/~


假如上面的图片挂了的话麻烦各位去发个帖 @ 一下 orzFly 让他修复 deartime

梦石
1
星屑
23246
在线时间
9564 小时
注册时间
2012-6-19
回帖
7018

开拓者短篇九导演组冠军

发表于 2015-10-1 15:13:33 | 显示全部楼层
本帖最后由 喵呜喵5 于 2015-10-1 17:21 编辑
  1. $gameParty.gainGold(65535)
复制代码
无比炸裂的加钱代码果然有效……防作弊迫在眉睫

不止Yanfly,Yami、Galenmerth、Neonblack等国外比较有名的脚本都有出现,并且它们写的脚本将作为首波DLC公开

======================

RMVA有的RMMV都有,不如说RMMV的脚本简直就是RMVA脚本的JS化,看着非常眼熟

相比RMVA功能上有变动的地方:

使用 TouchInput.isTriggered() / TouchInput.isPressed()  响应点击事件



Manager
Cache 改名为 ImageManager,然而实际上做的还是Cache的事,图片素材上只增加了SvActor和SvEnemy这两个用在SideView模式的素材文件夹
Vocab 改名为 TextManager,各种改名Manager等,Audio也分出来作为Manager了……
插件脚本作为新节点贴在body上
  1. PluginManager.loadScript = function(name) {
  2.     var url = this._path + name;
  3.     var script = document.createElement('script');
  4.     script.type = 'text/javascript';
  5.     script.src = url;
  6.     script.async = false;
  7.     script.onerror = this.onError.bind(this);
  8.     script._url = url;
  9.     document.body.appendChild(script)
  10. };
复制代码


Scene

初始界面为Scene_Boot,负责加载并检查资源是否全部加载完毕
SceneManager.run(Scene_Boot);

SceneManager.call 由 push 代替,return由pop代替,goto仍然不变
  1. SceneManager.pop()
  2. SceneManager.goto(Scene_Gameover)
  3. SceneManager.push(Scene_Save)
复制代码
存读档界面布局调整
捕获.PNG

……………………囧
  1. this._rangeWindow.setHandler('cancel', this.popScene.bind(this));
复制代码


Game

某种程度的中文支持?还是说要出官方中文版了?
[pre lang="javascript"]Game_System.prototype.isChinese = function() {
    return $dataSystem.locale.match(/^zh/)
};[/pre]

Game_Character支持寻路了,算法为A*,没有使用二叉堆等进行优化,因此为了提高效率默认设置了寻路的限制,突破限制时停止寻路,但是可以去除[pre lang="javascript"]Game_Character.prototype.findDirectionTo = function(goalX, goalY) {
    var searchLimit = this.searchLimit();
    var mapWidth = $gameMap.width();
    var nodeList = [];
    var openList = [];
    var closedList = [];
    var start = {};
    var best = start;
    if (this.x === goalX && this.y === goalY) {
        return 0
    }
    start.parent = null;
    start.x = this.x;
    start.y = this.y;
    start.g = 0;
    start.f = $gameMap.distance(start.x, start.y, goalX, goalY);
    nodeList.push(start);
    openList.push(start.y * mapWidth + start.x);
    while (nodeList.length > 0) {
        var bestIndex = 0;
        for (var i = 0; i < nodeList.length; i++) {
            if (nodeList.f < nodeList[bestIndex].f) {
                bestIndex = i
            }
        }
        var current = nodeList[bestIndex];
        var x1 = current.x;
        var y1 = current.y;
        var pos1 = y1 * mapWidth + x1;
        var g1 = current.g;
        nodeList.splice(bestIndex, 1);
        openList.splice(openList.indexOf(pos1), 1);
        closedList.push(pos1);
        if (current.x === goalX && current.y === goalY) {
            best = current;
            goaled = true;
            break
        }
        if (g1 >= searchLimit) {
            continue
        }
        for (var j = 0; j < 4; j++) {
            var direction = 2 + j * 2;
            var x2 = $gameMap.roundXWithDirection(x1, direction);
            var y2 = $gameMap.roundYWithDirection(y1, direction);
            var pos2 = y2 * mapWidth + x2;
            if (closedList.contains(pos2)) {
                continue
            }
            if (!this.canPass(x1, y1, direction)) {
                continue
            }
            var g2 = g1 + 1;
            var index2 = openList.indexOf(pos2);
            if (index2 < 0 || g2 < nodeList[index2].g) {
                var neighbor;
                if (index2 >= 0) {
                    neighbor = nodeList[index2]
                } else {
                    neighbor = {};
                    nodeList.push(neighbor);
                    openList.push(pos2)
                }
                neighbor.parent = current;
                neighbor.x = x2;
                neighbor.y = y2;
                neighbor.g = g2;
                neighbor.f = g2 + $gameMap.distance(x2, y2, goalX, goalY);
                if (!best || neighbor.f - neighbor.g < best.f - best.g) {
                    best = neighbor
                }
            }
        }
    }
    var node = best;
    while (node.parent && node.parent !== start) {
        node = node.parent
    }
    var deltaX1 = $gameMap.deltaX(node.x, start.x);
    var deltaY1 = $gameMap.deltaY(node.y, start.y);
    if (deltaY1 > 0) {
        return 2
    } else if (deltaX1 < 0) {
        return 4
    } else if (deltaX1 > 0) {
        return 6
    } else if (deltaY1 < 0) {
        return 8
    }
    var deltaX2 = this.deltaXFrom(goalX);
    var deltaY2 = this.deltaYFrom(goalY);
    if (Math.abs(deltaX2) > Math.abs(deltaY2)) {
        return deltaX2 > 0 ? 4 : 6
    } else if (deltaY2 !== 0) {
        return deltaY2 > 0 ? 8 : 2
    }
    return 0
};
Game_Character.prototype.searchLimit = function() {
    return 12
};[/pre]视频格式可以使用webm和mp4了(需设备支持)
[pre lang="javascript"]Game_Interpreter.prototype.videoFileExt = function() {
    if (Graphics.canPlayVideoType('video/webm') && !Utils.isMobileDevice()) {
        return '.webm'
    } else {
        return '.mp4'
    }
};[/pre]

可以通过事件指令直接获取玩家的战斗胜利和逃跑次数了

用来扩展事件指令功能增加任意个新指令的?
[pre lang="javascript"]Game_Interpreter.prototype.command356 = function() {
    var args = this._params[0].split(" ");
    var command = args.shift();
    this.pluginCommand(command, args);
    return true
};
Game_Interpreter.prototype.pluginCommand = function(command, args) {};[/pre]

……

读累了,之后再去看还没读的Window代码吧

点评

同求  发表于 2015-10-2 14:29
请问mv是在哪下得?好多大神都有。  发表于 2015-10-1 17:38

评分

参与人数 2星屑 +320 收起 理由
Tink + 20
taroxd + 300 头像丧失!(重点错

查看全部评分

回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2015-10-1 15:15:01 | 显示全部楼层
喵呜喵5 发表于 2015-9-30 22:13

$gameParty?那角色用$gameActor?
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-10-1 15:23:07 | 显示全部楼层
不知道为什么,看着代码就完全没有入手的欲望了

评分

参与人数 1星屑 +1 收起 理由
chd114 + 1 这代码看起来可以掰弯直男

查看全部评分

回复

使用道具 举报

梦石
1
星屑
23246
在线时间
9564 小时
注册时间
2012-6-19
回帖
7018

开拓者短篇九导演组冠军

发表于 2015-10-1 15:46:48 | 显示全部楼层
本帖最后由 喵呜喵5 于 2015-10-1 15:47 编辑

下载了全代码打包看了半天忽然意识到你漏了Game啊

====================

哦不对,原来Game你打包放到另一个附件里了
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-10-1 20:59:02 | 显示全部楼层
喵呜喵5 发表于 2015-10-1 15:13
无比炸裂的加钱代码果然有效……防作弊迫在眉睫

不止Yanfly,Yami、Galenmerth、Neonblack等国外比较有名 ...

关于作弊啥的,你可以直接把 cookie 拿出来,base64 解了随便改
回复

使用道具 举报

梦石
0
星屑
50
在线时间
1281 小时
注册时间
2006-8-27
回帖
550
发表于 2015-10-2 03:58:54 | 显示全部楼层
数据库没任何加密或压缩吗?
txt打开就能随便改啊

点评

参考二楼第一段代码,至少在目前官方提供的demo中,它可以顺畅的直接运行并立刻增加65535点金钱  发表于 2015-10-2 09:18
基本上rmmv制作的游戏在网页端运行时你就别指望加密了,不过也没人会去改数据库  发表于 2015-10-2 09:17
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-10-2 08:03:44 | 显示全部楼层
wbsy8241 发表于 2015-10-2 03:58
数据库没任何加密或压缩吗?
txt打开就能随便改啊

数据库在服务器端,你怎么改

当然你可以把包抓下来黑了
回复

使用道具 举报

路人党员

梦石
0
星屑
52
在线时间
2276 小时
注册时间
2010-12-30
回帖
3011
发表于 2015-10-2 10:13:20 | 显示全部楼层
真心觉得不想用MV,虽然跨平台这一点很不错,但是比起ruby,js有很多不方便的地方

点评

比如呢(纯好奇)  发表于 2015-10-2 10:33
本人擅长XP,如果有脚本或者Ruby方面的问题欢迎发电邮到engshun@1ppl.me咨询,本人很少检查电邮所以不一定会及时回复,本人不会直接出手解决问题只会提供一个方向,所以谢绝伸手党
回复

使用道具 举报

精灵族の天使<

梦石
0
星屑
1712
在线时间
3039 小时
注册时间
2007-3-16
回帖
33092

开拓者贵宾

发表于 2015-10-2 10:25:15 | 显示全部楼层
我目前ACE就足够使用了。
MV对我来说还很早。
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部