ChatGPT 4oでプラグインを作っています。
デフォルトだと複数のステートにかかった場合、1つのアイコンの表示が切り替わり複数のステートを表示してくれます。
しかし、戦闘画面で新しいステータスを追加するプラグインを作って使用した所、
添付した画像のようにステートアイコンが複数表示されるようになりました。
コード: 全て選択
this.drawActorIcons(actor, rect.x + 100, rect.y);
分からないなりにAIに命令した所
コード: 全て選択
// デフォルトのステートアイコン表示を復元
Window_BattleStatus.prototype.placeStateIcon = function(actor, x, y) {
this.drawActorIcons(actor, x, y);
};
// Window_BattleStatusにおける位置をデフォルトに戻す
Window_BattleStatus.prototype.drawItemStatus = function(index) {
const actor = this.actor(index);
const rect = this.itemRectWithPadding(index);
const nameX = this.nameX(rect);
const nameY = rect.y;
this.placeActorName(actor, nameX, nameY);
const iconsX = nameX + 180;
const iconsY = rect.y;
this.placeStateIcon(actor, iconsX, iconsY);
const gaugesX = nameX + 200;
const gaugesY = rect.y;
this.placeBasicGauges(actor, gaugesX, gaugesY);
};
})()
これ以上は分からなくなったので、コードの手直しか間違っている所、AIへの命令の仕方などを教えてほしいです。
ひとまず全てのコードを記載してプラグインも添付します。
コード: 全て選択
/*:
* @target MZ
* @plugindesc ステータスメニューに空腹度、睡眠度、水分度のゲージを追加します。
*
* @param ActorVariableMapping
* @text アクター変数のマッピング
* @desc アクターIDを空腹度、睡眠度、水分度の変数IDにマッピングします。
* @type struct<ActorVariablePair>[]
* @default []
*
* @param HungerGaugeName
* @text 空腹度ゲージ名
* @desc 空腹度ゲージに表示される名前です。
* @type text
* @default 空腹度
*
* @param SleepGaugeName
* @text 睡眠度ゲージ名
* @desc 睡眠度ゲージに表示される名前です。
* @type text
* @default 睡眠度
*
* @param HydrationGaugeName
* @text 水分度ゲージ名
* @desc 水分度ゲージに表示される名前です。
* @type text
* @default 水分度
*
* @param HungerGaugeColor1
* @text 空腹度ゲージ色1
* @desc 空腹度ゲージの色1です。
* @type number
* @min 0
* @max 31
* @default 17
*
* @param HungerGaugeColor2
* @text 空腹度ゲージ色2
* @desc 空腹度ゲージの色2です。
* @type number
* @min 0
* @max 31
* @default 18
*
* @param SleepGaugeColor1
* @text 睡眠度ゲージ色1
* @desc 睡眠度ゲージの色1です。
* @type number
* @min 0
* @max 31
* @default 19
*
* @param SleepGaugeColor2
* @text 睡眠度ゲージ色2
* @desc 睡眠度ゲージの色2です。
* @type number
* @min 0
* @max 31
* @default 20
*
* @param HydrationGaugeColor1
* @text 水分度ゲージ色1
* @desc 水分度ゲージの色1です。
* @type number
* @min 0
* @max 31
* @default 21
*
* @param HydrationGaugeColor2
* @text 水分度ゲージ色2
* @desc 水分度ゲージの色2です。
* @type number
* @min 0
* @max 31
* @default 22
*
* @help
* このプラグインは、ステータスメニューに空腹度、睡眠度、水分度のゲージを追加します。
* プラグインパラメータでアクター変数のマッピングを設定してください。
* また、空腹度、睡眠度、水分度のゲージの色を設定することもできます。
*/
/*~struct~ActorVariablePair:
* @param ActorID
* @text アクターID
* @desc アクターIDです。
* @type actor
*
* @param HungerVariableID
* @text 空腹度変数ID
* @desc 空腹度値に使用する変数IDです。
* @type variable
*
* @param SleepVariableID
* @text 睡眠度変数ID
* @desc 睡眠度値に使用する変数IDです。
* @type variable
*
* @param HydrationVariableID
* @text 水分度変数ID
* @desc 水分度値に使用する変数IDです。
* @type variable
*/
(() => {
const parameters = PluginManager.parameters('New Parameter4');
const ActorVariableMapping = JSON.parse(parameters['ActorVariableMapping']);
const HungerGaugeName = String(parameters['HungerGaugeName'] || "空腹度");
const SleepGaugeName = String(parameters['SleepGaugeName'] || "睡眠度");
const HydrationGaugeName = String(parameters['HydrationGaugeName'] || "水分度");
const HungerGaugeColor1 = Number(parameters['HungerGaugeColor1'] || 17);
const HungerGaugeColor2 = Number(parameters['HungerGaugeColor2'] || 18);
const SleepGaugeColor1 = Number(parameters['SleepGaugeColor1'] || 19);
const SleepGaugeColor2 = Number(parameters['SleepGaugeColor2'] || 20);
const HydrationGaugeColor1 = Number(parameters['HydrationGaugeColor1'] || 21);
const HydrationGaugeColor2 = Number(parameters['HydrationGaugeColor2'] || 22);
const actorVariableMap = {};
ActorVariableMapping.forEach(mapping => {
const map = JSON.parse(mapping);
actorVariableMap[map.ActorID] = {
hunger: Number(map.HungerVariableID),
sleep: Number(map.SleepVariableID),
hydration: Number(map.HydrationVariableID)
};
});
function getVariableValue(actorId, type) {
const variableIds = actorVariableMap[actorId];
if (variableIds) {
switch (type) {
case "hunger":
return $gameVariables.value(variableIds.hunger);
case "sleep":
return $gameVariables.value(variableIds.sleep);
case "hydration":
return $gameVariables.value(variableIds.hydration);
}
}
return 0;
}
const _Window_StatusBase_placeBasicGauges = Window_StatusBase.prototype.placeBasicGauges;
Window_StatusBase.prototype.placeBasicGauges = function(actor, x, y) {
const scene = SceneManager._scene.constructor.name;
let gaugeY = y - this.gaugeLineHeight() * 0; // 上にさらに上げる
this.placeGauge(actor, "hp", x, gaugeY);
gaugeY += this.gaugeLineHeight();
this.placeGauge(actor, "mp", x, gaugeY);
gaugeY += this.gaugeLineHeight();
this.placeGauge(actor, "tp", x, gaugeY);
if (scene === 'Scene_Battle') {
gaugeY += this.gaugeLineHeight();
this.placeGauge(actor, "hunger", x, gaugeY);
gaugeY += this.gaugeLineHeight();
this.placeGauge(actor, "sleep", x, gaugeY);
gaugeY += this.gaugeLineHeight();
this.placeGauge(actor, "hydration", x, gaugeY);
} else if (scene === 'Scene_Menu' || scene === 'Scene_Item') {
this.placeGauge(actor, "hunger", x + 130, y);
this.placeGauge(actor, "sleep", x + 130, y + this.gaugeLineHeight());
this.placeGauge(actor, "hydration", x + 130, y + this.gaugeLineHeight() * 2);
}
};
// 名前の位置を調整する関数を追加
Window_BattleStatus.prototype.drawItem = function(index) {
const actor = $gameParty.battleMembers()[index];
const rect = this.itemRectWithPadding(index);
const nameX = rect.x + 0;
const nameY = rect.y - this.lineHeight() * 0; // 名前を上に移動
this.drawActorName(actor, nameX, nameY, 180);
this.placeBasicGauges(actor, rect.x, rect.y - this.gaugeLineHeight() * -1.5); // 戦闘画面でゲージを上に移動;
this.drawActorIcons(actor, rect.x + 100, rect.y); // ステートアイコンをデフォルト位置に戻す
};
// Sprite_Gaugeメソッドをオーバーライドして空腹度、睡眠度、水分度のゲージをサポート
const _Sprite_Gauge_currentValue = Sprite_Gauge.prototype.currentValue;
Sprite_Gauge.prototype.currentValue = function() {
if (this._battler) {
switch (this._statusType) {
case "hunger":
return getVariableValue(this._battler.actorId(), "hunger");
case "sleep":
return getVariableValue(this._battler.actorId(), "sleep");
case "hydration":
return getVariableValue(this._battler.actorId(), "hydration");
default:
return _Sprite_Gauge_currentValue.call(this);
}
}
return NaN;
};
const _Sprite_Gauge_currentMaxValue = Sprite_Gauge.prototype.currentMaxValue;
Sprite_Gauge.prototype.currentMaxValue = function() {
if (this._battler) {
switch (this._statusType) {
case "hunger":
return 100;
case "sleep":
return 100;
case "hydration":
return 100;
default:
return _Sprite_Gauge_currentMaxValue.call(this);
}
}
return NaN;
};
const _Sprite_Gauge_label = Sprite_Gauge.prototype.label;
Sprite_Gauge.prototype.label = function() {
switch (this._statusType) {
case "hunger":
return HungerGaugeName;
case "sleep":
return SleepGaugeName;
case "hydration":
return HydrationGaugeName;
default:
return _Sprite_Gauge_label.call(this);
}
};
// ゲージの色をオーバーライド
const _Sprite_Gauge_gaugeColor1 = Sprite_Gauge.prototype.gaugeColor1;
Sprite_Gauge.prototype.gaugeColor1 = function() {
switch (this._statusType) {
case "hunger":
return ColorManager.textColor(HungerGaugeColor1);
case "sleep":
return ColorManager.textColor(SleepGaugeColor1);
case "hydration":
return ColorManager.textColor(HydrationGaugeColor1);
default:
return _Sprite_Gauge_gaugeColor1.call(this);
}
};
const _Sprite_Gauge_gaugeColor2 = Sprite_Gauge.prototype.gaugeColor2;
Sprite_Gauge.prototype.gaugeColor2 = function() {
switch (this._statusType) {
case "hunger":
return ColorManager.textColor(HungerGaugeColor2);
case "sleep":
return ColorManager.textColor(SleepGaugeColor2);
case "hydration":
return ColorManager.textColor(HydrationGaugeColor2);
default:
return _Sprite_Gauge_gaugeColor2.call(this);
}
};
// Window_Status.prototype.drawExpInfoをオーバーライドしてEXP情報を表示
Window_Status.prototype.drawExpInfo = function(x, y) {
const lineHeight = this.lineHeight();
const expTotal = this._actor.currentExp();
const expNext = this._actor.nextRequiredExp();
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.expTotal.format(TextManager.exp), x, y + lineHeight * 0, 200);
this.drawText(TextManager.expNext.format(TextManager.exp), x, y + lineHeight * 2, 200);
this.resetTextColor();
this.drawText(expTotal, x, y + lineHeight * 1, 200, 'right');
this.drawText(expNext, x, y + lineHeight * 3, 200, 'right');
};
// Window_Status.prototype.refreshをオーバーライドしてdrawExpInfoを含める
const _Window_Status_refresh = Window_Status.prototype.refresh;
Window_Status.prototype.refresh = function() {
if (this._actor) {
_Window_Status_refresh.call(this);
const x = this.colSpacing();
const y = this.lineHeight() * 6;
this.drawExpInfo(x, y);
}
};
// デフォルトのステートアイコン表示を復元
Window_BattleStatus.prototype.placeStateIcon = function(actor, x, y) {
this.drawActorIcons(actor, x, y);
};
// Window_BattleStatusにおける位置をデフォルトに戻す
Window_BattleStatus.prototype.drawItemStatus = function(index) {
const actor = this.actor(index);
const rect = this.itemRectWithPadding(index);
const nameX = this.nameX(rect);
const nameY = rect.y;
this.placeActorName(actor, nameX, nameY);
const iconsX = nameX + 180;
const iconsY = rect.y;
this.placeStateIcon(actor, iconsX, iconsY);
const gaugesX = nameX + 200;
const gaugesY = rect.y;
this.placeBasicGauges(actor, gaugesX, gaugesY);
};
})();
Window_BattleStatus.prototype.drawItemStatus = function(index) {
const actor = this.actor(index);
const rect = this.itemRectWithPadding(index);
const nameX = this.nameX(rect);
const nameY = rect.y;
this.placeActorName(actor, nameX, nameY);
this.placeStateIcon(actor, rect.x, rect.y + this.lineHeight());
const gaugesX = rect.x;
const gaugesY = rect.y + this.lineHeight() * 2;
this.placeBasicGauges(actor, gaugesX, gaugesY);
};
Window_BattleStatus.prototype.placeStateIcon = function(actor, x, y) {
const iconWidth = ImageManager.iconWidth;
const icons = actor.allIcons().slice(0, Math.floor(this.contents.width / iconWidth));
for (let i = 0; i < icons.length; i++) {
this.drawIcon(icons[i], x + i * iconWidth, y);
}
};