【Javascript】HP等ステータスの動作について

アバター
かいとりせんこう
記事: 26
登録日時: 2016年8月28日(日) 00:15
お住まい: 日本の真ん中から西寄り
連絡を取る:

【Javascript】HP等ステータスの動作について

投稿記事by かいとりせんこう » 2017年3月03日(金) 23:34

プラグイン製作についての質問です。

アクターにHPのような数字を新たに追加するプラグインを作ろうとしています。

Object.defineProperties(Game_BattlerBase.prototype, {…}の部分が関係することは分かりましたが、その中の
hp: { get: function() { return this._hp; }, configurable: true }
のthis._hp部分などの本体部分がどこにあるのかが分かりません。

._hpの本体がどこなのか、もしくはもっと簡単にやりたいことを実現する方法をご教示いただければと思います。

↓現在作ろうとしているプラグインのコードです

コード: 全て選択

//=============================================================================
// K_Fullness.js
//=============================================================================

/*:ja
 * @plugindesc ver1.00 満腹、水分、睡眠のゲージを追加。
 * @author かいとりせんこう
 *
 * @param fullness
 * @desc 追加ゲージ2つ目
 * @default 満腹
 *
 * @param hydration
 * @desc 追加ゲージ2つ目
 * @default 水分
 *
 * @param sleep
 * @desc 追加ゲージ3つ目
 * @default 睡眠
 *
 * @param HPIcon
 * @desc HPのアイコンインデックス
 * @default 84
 *
 * @param MPIcon
 * @desc MPのアイコンインデックス
 * @default 78
 *
 * @param TPIcon
 * @desc TPのアイコンインデックス
 * @default 77
 *
 * @param FullnessIcon
 * @desc 満腹度のアイコンインデックス
 * @default 266
 *
 * @param HydrationIcon
 * @desc 水分のアイコンインデックス
 * @default 67
 *
 * @param SleepIcon
 * @desc 睡眠のアイコンインデックス
 * @default 8
 *
 * @param max
 * @desc ゲージの最大値
 * @default 100
 *
 * @param TPwrite
 * @desc TPを表示するかどうか true or false
 * @default true
 *
 * @param writeIcon
 * @desc trueだとアイコン、falseだとテキストになる
 * @default true
 *
 * @help
 * 機能:
 * ・満腹、水分、睡眠のゲージを追加します(名称をコンフィグで変更可)
 * ・メニュー画面で各種ゲージを小さくして表示します
 * ・ゲージでテキストの代わりにアイコンを表示します(コンフィグで変更可)
 *
 */

(function() {

    var parameters = PluginManager.parameters('K_Fullness');
    var fuW = String(parameters['fullness']);
    var hydW = String(parameters['hydration']);
    var slpW = String(parameters['sleep']);
    var hpicon = Number(parameters['HPIcon']);
    var mpicon = Number(parameters['MPIcon']);
    var tpicon = Number(parameters['TPIcon']);
    var fulicon = Number(parameters['FullnessIcon']);
    var hydicon = Number(parameters['HydrationIcon']);
    var slpicon = Number(parameters['SleepIcon']);
    var maxparam = Number(parameters['max']);
    var tpwrite = String(parameters['TPwrite']);
    var writeicon = String(parameters['writeIcon']);
   
//HP、MP、TPゲージ書き換え
   
Window_Base.prototype.drawActorHp = function(actor, x, y, width) {
    width = width || 186;
    var color1 = this.hpGaugeColor1();
    var color2 = this.hpGaugeColor2();
    this.drawGauge(x, y, width, actor.hpRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
    this.drawIcon(hpicon,x,y)
    }else{
    this.drawText(TextManager.hpA, x, y, 44); }
    this.drawCurrentAndMax(actor.hp, actor.mhp, x, y, width,
                           this.hpColor(actor), this.normalColor());
};

Window_Base.prototype.drawActorMp = function(actor, x, y, width) {
    width = width || 186;
    var color1 = this.mpGaugeColor1();
    var color2 = this.mpGaugeColor2();
    this.drawGauge(x, y, width, actor.mpRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
    this.drawIcon(mpicon,x,y)
    }else{
    this.drawText(TextManager.mpA, x, y, 44);}
    this.drawCurrentAndMax(actor.mp, actor.mmp, x, y, width,
                           this.mpColor(actor), this.normalColor());
};

Window_Base.prototype.drawActorTp = function(actor, x, y, width) {
    width = width || 96;
    var color1 = this.tpGaugeColor1();
    var color2 = this.tpGaugeColor2();
    this.drawGauge(x, y, width, actor.tpRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
    this.drawIcon(tpicon,x,y)
    }else{
    this.drawText(TextManager.tpA, x, y, 44);}
    this.changeTextColor(this.tpColor(actor));
    this.drawText(actor.tp, x + width - 64, y, 64, 'right');
};
 
//満腹、水分、睡眠を追加   
Object.defineProperties(Game_BattlerBase.prototype, {
    // Hit Points
    hp: { get: function() { return this._hp; }, configurable: true },
    // Magic Points
    mp: { get: function() { return this._mp; }, configurable: true },
    // Tactical Points
    tp: { get: function() { return this._tp; }, configurable: true },
    // Maximum Hit Points
    mhp: { get: function() { return this.param(0); }, configurable: true },
    // Maximum Magic Points
    mmp: { get: function() { return this.param(1); }, configurable: true },
    // ATtacK power
    atk: { get: function() { return this.param(2); }, configurable: true },
    // DEFense power
    def: { get: function() { return this.param(3); }, configurable: true },
    // Magic ATtack power
    mat: { get: function() { return this.param(4); }, configurable: true },
    // Magic DeFense power
    mdf: { get: function() { return this.param(5); }, configurable: true },
    // AGIlity
    agi: { get: function() { return this.param(6); }, configurable: true },
    // LUcK
    luk: { get: function() { return this.param(7); }, configurable: true },
    // HIT rate
    hit: { get: function() { return this.xparam(0); }, configurable: true },
    // EVAsion rate
    eva: { get: function() { return this.xparam(1); }, configurable: true },
    // CRItical rate
    cri: { get: function() { return this.xparam(2); }, configurable: true },
    // Critical EVasion rate
    cev: { get: function() { return this.xparam(3); }, configurable: true },
    // Magic EVasion rate
    mev: { get: function() { return this.xparam(4); }, configurable: true },
    // Magic ReFlection rate
    mrf: { get: function() { return this.xparam(5); }, configurable: true },
    // CouNTer attack rate
    cnt: { get: function() { return this.xparam(6); }, configurable: true },
    // Hp ReGeneration rate
    hrg: { get: function() { return this.xparam(7); }, configurable: true },
    // Mp ReGeneration rate
    mrg: { get: function() { return this.xparam(8); }, configurable: true },
    // Tp ReGeneration rate
    trg: { get: function() { return this.xparam(9); }, configurable: true },
    // TarGet Rate
    tgr: { get: function() { return this.sparam(0); }, configurable: true },
    // GuaRD effect rate
    grd: { get: function() { return this.sparam(1); }, configurable: true },
    // RECovery effect rate
    rec: { get: function() { return this.sparam(2); }, configurable: true },
    // PHArmacology
    pha: { get: function() { return this.sparam(3); }, configurable: true },
    // Mp Cost Rate
    mcr: { get: function() { return this.sparam(4); }, configurable: true },
    // Tp Charge Rate
    tcr: { get: function() { return this.sparam(5); }, configurable: true },
    // Physical Damage Rate
    pdr: { get: function() { return this.sparam(6); }, configurable: true },
    // Magical Damage Rate
    mdr: { get: function() { return this.sparam(7); }, configurable: true },
    // Floor Damage Rate
    fdr: { get: function() { return this.sparam(8); }, configurable: true },
    // EXperience Rate
    exr: { get: function() { return this.sparam(9); }, configurable: true },
    //↓問題の部分 今はとりあえずthis._hpにしてる
    ful: { get: function() { return this._hp; }, configurable: true },
    hyd: { get: function() { return this._hp; }, configurable: true },
    slp: { get: function() { return this._hp; }, configurable: true },
    //↑問題の部分
});
   
Game_BattlerBase.prototype.fulRate = function() {
    return this.ful / maxparam;
};
   
Game_BattlerBase.prototype.hydRate = function() {
    return this.hyd / maxparam;
};
   
Game_BattlerBase.prototype.slpRate = function() {
    return this.slp / maxparam;
};

   
Window_Base.prototype.drawActorFullness = function(actor, x, y, width) {
    width = width || 96;
    var color1 = this.hpGaugeColor1();
    var color2 = this.hpGaugeColor2();
    this.drawGauge(x, y, width, actor.fulRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
        this.drawIcon(fulicon,x,y);
    }else{
    this.drawText(fuW, x, y, 44);}
    this.drawCurrentAndMax(actor.ful, maxparam, x, y, width,
                           this.hpColor(actor), this.normalColor());
};
    Window_Base.prototype.drawActorHydration = function(actor, x, y, width) {
    width = width || 96;
    var color1 = this.mpGaugeColor1();
    var color2 = this.mpGaugeColor2();
    this.drawGauge(x, y, width, actor.hydRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
        this.drawIcon(hydicon,x,y);
    }else{
    this.drawText(hydW, x, y, 44);}
    this.drawCurrentAndMax(actor.hyd, maxparam, x, y, width,
                           this.mpColor(actor), this.normalColor());
};
    Window_Base.prototype.drawActorSleep = function(actor, x, y, width) {
    width = width || 96;
    var color1 = this.tpGaugeColor1();
    var color2 = this.tpGaugeColor2();
    this.drawGauge(x, y, width, actor.slpRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    if(writeicon == 'true'){
        this.drawIcon(slpicon,x,y);
    }else{
    this.drawText(slpW, x, y, 44);}
    this.drawCurrentAndMax(actor.slp, maxparam, x, y, width,
                           this.tpColor(actor), this.normalColor());
};
   
//メニュー書き換え
Window_Base.prototype.drawActorSimpleStatus = function(actor, x, y, width) {
    var lineHeight = this.lineHeight();
    var x2 = x + 180;
    var width2 = Math.min(200, width - 180 - this.textPadding())/2;
    var x3 = x2 + width2 + 5;
    this.drawActorName(actor, x, y);
    this.drawActorLevel(actor, x, y + lineHeight * 1);
    this.drawActorIcons(actor, x, y + lineHeight * 2);
    this.drawActorClass(actor, x2, y - lineHeight/2 * 1);
    this.drawActorHp(actor, x2, y + lineHeight/2 * 1, width2);
    this.drawActorMp(actor, x2, y + lineHeight/2 * 3, width2);
    if(tpwrite == 'true'){
    this.drawActorTp(actor, x2, y + lineHeight/2 * 5, width2);
    }
    this.drawActorFullness(actor, x3, y + lineHeight/2 * 1, width2);
    this.drawActorHydration(actor, x3, y + lineHeight/2 * 3, width2);
    this.drawActorSleep(actor, x3, y + lineHeight/2 * 5, width2);
};   
})();

今のところエラーなどは出ません

-------------------------------------------------------------------------
以前はXP、現在はウディタとMVを使用しています
技術はそこそこありますが公開した作品が少ない頭でっかちです

たまにドット絵を描きます
素材も投稿してるのでよかったらどうぞ
アバター
まっつUP
記事: 1155
登録日時: 2016年8月11日(木) 15:38
お住まい: タケノコ王国

Re: 【Javascript】HP等ステータスの動作について

投稿記事by まっつUP » 2017年3月04日(土) 00:11

かいとりせんこう様
お世話になります。

Game_BattlerBaseの
initMembersや
setHpやら
refreshやらを真似て
追加ステータスの処理をぶちこめば最低限の動作はなんとかなりそうです。
(実際にこの辺り弄ったらそれっぽい動きになったっぽいので)
RPGで笑顔を・・・

ツイッター(ツクラーの巣窟)(閲覧は自己責任でお願いします)
https://twitter.com/mattuup

github
https://github.com/mattuup/RPGMakerMZ
アバター
トリアコンタン
記事: 2311
登録日時: 2015年11月10日(火) 21:13
お住まい: きのこ王国
連絡を取る:

Re: 【Javascript】HP等ステータスの動作について

投稿記事by トリアコンタン » 2017年3月04日(土) 00:15

こんばんは!
フィールドの初期化は、「Game_BattlerBase.prototype.initMembers」で行っています。
試しに追加してみました。

コード: 全て選択

    //満腹、水分、睡眠を追加
    Object.defineProperties(Game_BattlerBase.prototype, {
        // 中略
        //↓問題の部分
        ful: { get: function() { return this._ful; }, configurable: true },
        hyd: { get: function() { return this._hyd; }, configurable: true },
        slp: { get: function() { return this._slp; }, configurable: true },
        //↑問題の部分
    });

    var _Game_BattlerBase_initMembers = Game_BattlerBase.prototype.initMembers;
    Game_BattlerBase.prototype.initMembers = function() {
        _Game_BattlerBase_initMembers.apply(this, arguments);
        this._ful = maxparam;
        this._hyd = maxparam;
        this._slp = maxparam;
    };

    Game_BattlerBase.prototype.setFul = function(ful) {
        this._ful = ful.clamp(0, maxparam);
    };

    Game_BattlerBase.prototype.setHyd = function(hyd) {
        this._hyd = hyd.clamp(0, maxparam);
    };

    Game_BattlerBase.prototype.setSlp = function(slp) {
        this._slp = slp.clamp(0, maxparam);
    };


値を設定したい場合は以下のスクリプトを実行します。(n:アクターID m:満腹度)

コード: 全て選択

$gameActors.actor(n).setFul(m);
プラグイン関連のトラブルが発生した際の切り分けと報告の方法です。
http://qiita.com/triacontane/items/2e227e5b5ce9503a2c30

[Blog] : http://triacontane.blogspot.jp/
[Twitter]: https://twitter.com/triacontane/
[GitHub] : https://github.com/triacontane/
アバター
かいとりせんこう
記事: 26
登録日時: 2016年8月28日(日) 00:15
お住まい: 日本の真ん中から西寄り
連絡を取る:

Re: 【Javascript】HP等ステータスの動作について

投稿記事by かいとりせんこう » 2017年3月04日(土) 00:50

回答ありがとうございます!
トリアコンタン様の通りにやってみたところ無事追加できました!

これからプラグインコマンドやメモ欄に関することを追加してプラグインが完成したら、公開することを考えています。
-------------------------------------------------------------------------
以前はXP、現在はウディタとMVを使用しています
技術はそこそこありますが公開した作品が少ない頭でっかちです

たまにドット絵を描きます
素材も投稿してるのでよかったらどうぞ

“MV:質問” へ戻る