const donateBoxes = {
10:{7:5, 8:2}
}
function Scene_Donate() {
this.initialize(...arguments);
}
Scene_Donate.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Donate.prototype.constructor = Scene_Donate;
Scene_Donate.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_Donate.prototype.helpAreaHeight = function() {
return 0;
};
Scene_Donate.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createBoxWindow();
this.createTargetWindow();
this.createDonateListWindow();
this.createNumberWindow();
};
Scene_Donate.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);
this._donateListWindow.refresh();
this._donateTargetWindow.refresh();
this._donateBoxWindow.refresh();
this._donateListWindow.select(0);
this._donateListWindow.activate();
};
Scene_Donate.prototype.createDonateListWindow = function() {
const rect = this.donateListWindowRect();
const donateListWindow = new Window_DonateList(rect);
this.addWindow(donateListWindow);
this._donateListWindow = donateListWindow;
this._donateListWindow.setHandler("ok", this.onItemOk.bind(this));
this._donateListWindow.setHandler("cancel", this.onItemCancel.bind(this));
};
Scene_Donate.prototype.createNumberWindow = function() {
const rect = this.numberWindowRect();
this._numberWindow = new Window_DonateListNumber(rect);
this._numberWindow.hide();
this._numberWindow.setHandler("ok", this.onNumberOk.bind(this));
this._numberWindow.setHandler("cancel", this.onNumberCancel.bind(this));
this.addWindow(this._numberWindow);
};
Scene_Donate.prototype.createBoxWindow = function() {
const rect = this.donateBoxWindowRect();
const boxWindow = new Window_DonateBox(rect);
this.addWindow(boxWindow);
this._donateBoxWindow = boxWindow;
};
Scene_Donate.prototype.createTargetWindow = function() {
const rect = this.donateTargetWindowRect();
const donateTargetWindow = new Window_DonateTarget(rect);
this.addWindow(donateTargetWindow);
this._donateTargetWindow = donateTargetWindow;
};
Scene_Donate.prototype.donateListWindowRect = function() {
return new Rectangle(0, 0, 600, Graphics.boxHeight);
};
Scene_Donate.prototype.numberWindowRect = function() {
const wx = 0;
const wy = Graphics.boxHeight/2;
const ww = 600;
const wh = 200;
return new Rectangle(wx, wy, ww, wh);
};
Scene_Donate.prototype.donateBoxWindowRect = function() {
return new Rectangle(600, 400, 300, 300);
};
Scene_Donate.prototype.donateTargetWindowRect = function() {
return new Rectangle(600, 0, 300, 300);
};
Scene_Donate.prototype.onItemOk = function() {
this._item = this._donateListWindow.item();
if(this._item){
if($gameParty.numItems(this._item) === 1) {
SoundManager.playShop();
this.doDonation(1);
this._donateListWindow.refresh();
this._donateTargetWindow.refresh();
this._donateBoxWindow.refresh();
this._donateListWindow.activate();
} else {
this._numberWindow.setup(this._item, this.maxSell(), 0);
this._numberWindow.show();
this._numberWindow.activate();
}
} else {
SoundManager.playBuzzer();
this._donateListWindow.activate();
}
};
Scene_Donate.prototype.onItemCancel = function() {
this.popScene();
};
Scene_Donate.prototype.onNumberOk = function() {
SoundManager.playShop();
this.doDonation(this._numberWindow.number());
this._numberWindow.hide();
this._donateListWindow.refresh();
this._donateTargetWindow.refresh();
this._donateBoxWindow.refresh();
this._donateListWindow.activate();
};
Scene_Donate.prototype.onNumberCancel = function() {
SoundManager.playCancel();
this._numberWindow.hide();
this._donateListWindow.activate();
};
Scene_Donate.prototype.doDonation = function(number) {
const item = this._donateListWindow.item();
$gameParty.loseItem(item, number);
this.donate(item, number);
this.checkAllDonated();
};
Scene_Donate.prototype.checkAllDonated = function() {
const boxContent = donateBoxes[$gameTemp._donateBoxId];
const arrayValues = Object.values(boxContent);
const varValue = $gameVariables.value($gameTemp._donateBoxId);
const varValuesFilter = varValue.filter(value => Number(value));
if (arrayValues.length === varValuesFilter.length &&
arrayValues.every((value, index) => value === varValuesFilter[index])) {
SoundManager.playRecovery();
}
};
Scene_Donate.prototype.maxSell = function() {
const boxContent = donateBoxes[$gameTemp._donateBoxId];
const varValue = $gameVariables.value($gameTemp._donateBoxId);
const target = boxContent[this._item.id];
const donated = varValue[this._item.id];
const number = target - donated;
return number;
};
Scene_Donate.prototype.donate = function(item, number) {
const id = $gameTemp._donateBoxId;
$gameVariables.value(id)[item.id] += number;
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Window_DonateList() {
this.initialize(...arguments);
}
Window_DonateList.prototype = Object.create(Window_ItemList.prototype);
Window_DonateList.prototype.constructor = Window_DonateList;
Window_DonateList.prototype.initialize = function(rect) {
Window_ItemList.prototype.initialize.call(this, rect);
this._category = "none";
this._data = [];
};
Window_DonateList.prototype.setCategory = function(category) {
this.refresh();
this.scrollTo(0, 0);
};
Window_DonateList.prototype.maxCols = function() {
return 8;
};
Window_DonateList.prototype.isCurrentItemEnabled = function() {
const boxContent = donateBoxes[$gameTemp._donateBoxId];
const varValue = $gameVariables.value($gameTemp._donateBoxId);
if (this.item()) {
const target = boxContent[this.item().id];
const donated = varValue[this.item().id];
return donated < target;
} else {
return false
}
};
Window_DonateList.prototype.needsNumber = function() {
return true;
};
Window_DonateList.prototype.makeItemList = function() {
this._data = $gameParty.items();
};
Window_DonateList.prototype.itemRect = function(index) {
const maxCols = this.maxCols();
const itemWidth = this.itemWidth();
const itemHeight = this.itemHeight();
const colSpacing = this.colSpacing();
const rowSpacing = this.rowSpacing();
const col = index % maxCols;
const row = Math.floor(index / maxCols);
const x = col * itemWidth + colSpacing / 2 - this.scrollBaseX();
const y = row * itemHeight + rowSpacing / 2 - this.scrollBaseY();
const width = itemWidth - colSpacing;
const height = itemHeight - rowSpacing;
return new Rectangle(x, y, width, height);
};
Window_DonateList.prototype.drawItemBackground = function(index) {
};
Window_DonateList.prototype.drawItem = function(index) {
const item = this.itemAt(index);
if (item) {
const numberWidth = this.numberWidth();
const rect = this.itemLineRect(index);
this.changePaintOpacity(this.isEnabled(item));
this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
this.contents.fontSize = 12;
if ($gameParty.numItems(item) > 1)
this.drawItemNumber(item, rect.x, rect.y + rect.height/3, rect.width);
this.resetFontSettings();
this.changePaintOpacity(1);
}
};
Window_DonateList.prototype.drawItemName = function(item, x, y, width) {
if (item) {
const iconY = y + (this.lineHeight() - ImageManager.iconHeight) / 2;
const textMargin = ImageManager.iconWidth + 4;
const itemWidth = Math.max(0, width - textMargin);
this.resetTextColor();
this.drawIcon(item.iconIndex, x, iconY);
}
};
Window_DonateList.prototype.drawItemNumber = function(item, x, y, width) {
this.drawText($gameParty.numItems(item), x, y, width, "right");
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Window_DonateListNumber() {
this.initialize(...arguments);
}
Window_DonateListNumber.prototype = Object.create(Window_ShopNumber.prototype);
Window_DonateListNumber.prototype.constructor = Window_DonateListNumber;
Window_DonateListNumber.prototype.refresh = function() {
Window_Selectable.prototype.refresh.call(this);
this.drawItemBackground(0);
this.drawCurrentItemName();
this.drawMultiplicationSign();
this.drawNumber();
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Window_DonateTarget() {
this.initialize(...arguments);
}
Window_DonateTarget.prototype = Object.create(Window_DonateList.prototype);
Window_DonateTarget.prototype.constructor = Window_DonateTarget;
Window_DonateTarget.prototype.initialize = function(rect) {
Window_DonateList.prototype.initialize.call(this, rect);
this._category = "none";
this._data = [];
};
Window_DonateTarget.prototype.maxCols = function() {
return 4;
};
Window_DonateTarget.prototype.isCurrentItemEnabled = function() {
return true;
};
Window_DonateTarget.prototype.makeItemList = function() {
const boxContent = donateBoxes[$gameTemp._donateBoxId];
this._data = Object.keys(boxContent).map(id => $dataItems[id]);
};
Window_DonateTarget.prototype.drawItem = function(index) {
const item = this.itemAt(index);
if (item) {
const numberWidth = this.numberWidth();
const rect = this.itemLineRect(index);
this.changePaintOpacity(this.isEnabled(item));
this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
this.contents.fontSize = 12;
this.drawItemNumber(item, rect.x, rect.y + rect.height/3, rect.width);
this.resetFontSettings();
this.changePaintOpacity(1);
}
};
Window_DonateTarget.prototype.drawItemNumber = function(item, x, y, width) {
const boxContent = donateBoxes[$gameTemp._donateBoxId];
const number = boxContent[item.id];
this.drawText(number, x, y, width, "right");
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function Window_DonateBox() {
this.initialize(...arguments);
}
Window_DonateBox.prototype = Object.create(Window_DonateList.prototype);
Window_DonateBox.prototype.constructor = Window_DonateBox;
Window_DonateBox.prototype.initialize = function(rect) {
Window_DonateList.prototype.initialize.call(this, rect);
this._category = "none";
this._data = [];
};
Window_DonateBox.prototype.maxCols = function() {
return 4;
};
Window_DonateBox.prototype.makeItemList = function() {
const varValue = $gameVariables.value($gameTemp._donateBoxId);
for (let i = 0; i < varValue.length; i++) {
if (varValue[i] != undefined && varValue[i] > 0) {
if (!this._data.includes($dataItems[i]))
this._data.push($dataItems[i]);
}
}
};
Window_DonateBox.prototype.drawItem = function(index) {
const item = this.itemAt(index);
if (item) {
const numberWidth = this.numberWidth();
const rect = this.itemLineRect(index);
this.changePaintOpacity(this.isEnabled(item));
this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
this.contents.fontSize = 12;
this.drawItemNumber(item, rect.x, rect.y + rect.height/3, rect.width);
this.resetFontSettings();
this.changePaintOpacity(1);
}
};
Window_DonateBox.prototype.drawItemNumber = function(item, x, y, width) {
const varValue = $gameVariables.value($gameTemp._donateBoxId);
const number = varValue[item.id];
this.drawText(number, x, y, width, "right");
};