見出し画像

ロートル元ゲーム開発者がツクールでゲームを作る|プラグインを作る(5)

いろいろいじってみたんですが、結局 convertParam は整理できず。仕方がないのでその辺は放置して、ここを

var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command == N) {
        for (var i = 0, len = Fishlist.length; i < len; i++){
           if (Fishlist[i].Region == args[0]){
               Fishlist[i].List.forEach (function(value){
                   var k = value.ID;
                   var v = value.Rate;
                   fishes[k] = v;
               });
           }

        }
        var fish = fishing(fishes);
        $gameVariables.setValue(param.getFish, fish);
    }
};

こうじゃ。

var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command == pluginName) {
        for (let i = 0, len = Fishlist.length; i < len; i++) {
            if (Fishlist[i].Region == args[0]) {
                fishes = Fishlist[i].List;
                break;
            }
        }
        const fish = itemGet(fishes);
        $gameVariables.setValue(param.getFish, fish);
    }
};

んでもってこうじゃ。

const fishboard = (fishes, hit) => {
    let area = 0;
    for (let i = 0, len = fishes.length; i < len; i++) {
        area += Number(fishes[i].Rate);
        if (hit && (area >= hit)) return fishes[i].ID;
    }
    return area;
}

これでとりあえず完成! 最後に汎用性をより高める為、魚(fish)となっていた部分を全部(item)に差し替え、関数や変数の宣言なんかを整理して、動作確認。無事にアジが釣れたりタイが釣れたり、たまにタツノオトシゴが釣れるようになりました。という訳で、わずか130行あまりの簡素なものではありますが、プラグイン完成です。ツクール公式フォーラムで配布してみましたので、興味のある方はどうぞ!

#ゲーム #雑記 #開発 #JavaScript #RPGツクール #RPGツクールMV #プラグイン

コーヒー代でも投げてくれると、作者が喜びます。