Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//=============================================================================
// TK Sell Shop.js
//=============================================================================
/*:
* @plugindesc Create a store where you can only sell items.
* @author Takkun
*
* @help To call the Shop Sell Scene just use the following command:
* SceneManager.push(Scene_SellShop);
*/
//-----------------------------------------------------------------------------
// Window_SellShopCommand
//
// The window for selecting sell on the shop screen.
function Window_SellShopCommand() {
this.initialize.apply(this, arguments);
}
Window_SellShopCommand.prototype = Object.create(Window_HorzCommand.prototype);
Window_SellShopCommand.prototype.constructor = Window_SellShopCommand;
Window_SellShopCommand.prototype.initialize = function(width, purchaseOnly) {
this._windowWidth = width;
Window_HorzCommand.prototype.initialize.call(this, 0, 0);
};
Window_SellShopCommand.prototype.windowWidth = function() {
return this._windowWidth;
};
Window_SellShopCommand.prototype.maxCols = function() {
return 2;
};
Window_SellShopCommand.prototype.makeCommandList = function() {
this.addCommand(TextManager.sell, 'sell');
this.addCommand(TextManager.cancel, 'cancel');
};
//-----------------------------------------------------------------------------
// //-----------------------------------------------------------------------------
// Scene_SellShop
//
// The scene class of the sell shop screen.
function Scene_SellShop() {
this.initialize.apply(this, arguments);
}
Scene_SellShop.prototype = Object.create(Scene_MenuBase.prototype);
Scene_SellShop.prototype.constructor = Scene_SellShop;
Scene_SellShop.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_SellShop.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createHelpWindow();
this.createGoldWindow();
this.createCommandWindow();
this.createDummyWindow();
this.createNumberWindow();
this.createStatusWindow();
this.createCategoryWindow();
this.createSellWindow();
};
Scene_SellShop.prototype.createGoldWindow = function() {
this._goldWindow = new Window_Gold(0, this._helpWindow.height);
this._goldWindow.x = Graphics.boxWidth - this._goldWindow.width;
this.addWindow(this._goldWindow);
};
Scene_SellShop.prototype.createCommandWindow = function() {
this._commandWindow = new Window_SellShopCommand(this._goldWindow.x);
this._commandWindow.y = this._helpWindow.height;
this._commandWindow.setHandler('sell', this.commandSell.bind(this));
this._commandWindow.setHandler('cancel', this.popScene.bind(this));
this.addWindow(this._commandWindow);
};
Scene_SellShop.prototype.createDummyWindow = function() {
var wy = this._commandWindow.y + this._commandWindow.height;
var wh = Graphics.boxHeight - wy;
this._dummyWindow = new Window_Base(0, wy, Graphics.boxWidth, wh);
this.addWindow(this._dummyWindow);
};
Scene_SellShop.prototype.createNumberWindow = function() {
var wy = this._dummyWindow.y;
var wh = this._dummyWindow.height;
this._numberWindow = new Window_ShopNumber(0, wy, wh);
this._numberWindow.hide();
this._numberWindow.setHandler('ok', this.onNumberOk.bind(this));
this._numberWindow.setHandler('cancel', this.onNumberCancel.bind(this));
this.addWindow(this._numberWindow);
};
Scene_SellShop.prototype.createStatusWindow = function() {
var wx = this._numberWindow.width;
var wy = this._dummyWindow.y;
var ww = Graphics.boxWidth - wx;
var wh = this._dummyWindow.height;
this._statusWindow = new Window_ShopStatus(wx, wy, ww, wh);
this._statusWindow.hide();
this.addWindow(this._statusWindow);
};
Scene_SellShop.prototype.createCategoryWindow = function() {
this._categoryWindow = new Window_ItemCategory();
this._categoryWindow.setHelpWindow(this._helpWindow);
this._categoryWindow.y = this._dummyWindow.y;
this._categoryWindow.hide();
this._categoryWindow.deactivate();
this._categoryWindow.setHandler('ok', this.onCategoryOk.bind(this));
this._categoryWindow.setHandler('cancel', this.onCategoryCancel.bind(this));
this.addWindow(this._categoryWindow);
};
Scene_SellShop.prototype.createSellWindow = function() {
var wy = this._categoryWindow.y + this._categoryWindow.height;
var wh = Graphics.boxHeight - wy;
this._sellWindow = new Window_ShopSell(0, wy, Graphics.boxWidth, wh);
this._sellWindow.setHelpWindow(this._helpWindow);
this._sellWindow.hide();
this._sellWindow.setHandler('ok', this.onSellOk.bind(this));
this._sellWindow.setHandler('cancel', this.onSellCancel.bind(this));
this._categoryWindow.setItemWindow(this._sellWindow);
this.addWindow(this._sellWindow);
};
Scene_SellShop.prototype.activateSellWindow = function() {
this._categoryWindow.show();
this._sellWindow.refresh();
this._sellWindow.show();
this._sellWindow.activate();
this._statusWindow.hide();
};
Scene_SellShop.prototype.commandSell = function() {
this._dummyWindow.hide();
this._categoryWindow.show();
this._categoryWindow.activate();
this._sellWindow.show();
this._sellWindow.deselect();
this._sellWindow.refresh();
};
Scene_SellShop.prototype.onCategoryOk = function() {
this.activateSellWindow();
this._sellWindow.select(0);
};
Scene_SellShop.prototype.onCategoryCancel = function() {
this._commandWindow.activate();
this._dummyWindow.show();
this._categoryWindow.hide();
this._sellWindow.hide();
};
Scene_SellShop.prototype.onSellOk = function() {
this._item = this._sellWindow.item();
this._categoryWindow.hide();
this._sellWindow.hide();
this._numberWindow.setup(this._item, this.maxSell(), this.sellingPrice());
this._numberWindow.setCurrencyUnit(this.currencyUnit());
this._numberWindow.show();
this._numberWindow.activate();
this._statusWindow.setItem(this._item);
this._statusWindow.show();
};
Scene_SellShop.prototype.onSellCancel = function() {
this._sellWindow.deselect();
this._categoryWindow.activate();
this._statusWindow.setItem(null);
this._helpWindow.clear();
};
Scene_SellShop.prototype.onNumberOk = function() {
SoundManager.playShop();
switch (this._commandWindow.currentSymbol()) {
case 'sell':
this.doSell(this._numberWindow.number());
break;
}
this.endNumberInput();
this._goldWindow.refresh();
this._statusWindow.refresh();
};
Scene_SellShop.prototype.onNumberCancel = function() {
SoundManager.playCancel();
this.endNumberInput();
};
Scene_SellShop.prototype.doSell = function(number) {
$gameParty.gainGold(number * this.sellingPrice());
$gameParty.loseItem(this._item, number);
};
Scene_SellShop.prototype.endNumberInput = function() {
this._numberWindow.hide();
switch (this._commandWindow.currentSymbol()) {
case 'sell':
this.activateSellWindow();
break;
}
};
Scene_SellShop.prototype.maxBuy = function() {
var max = $gameParty.maxItems(this._item) - $gameParty.numItems(this._item);
var price = this.buyingPrice();
if (price > 0) {
return Math.min(max, Math.floor(this.money() / price));
} else {
return max;
}
};
Scene_SellShop.prototype.maxSell = function() {
return $gameParty.numItems(this._item);
};
Scene_SellShop.prototype.money = function() {
return this._goldWindow.value();
};
Scene_SellShop.prototype.currencyUnit = function() {
return this._goldWindow.currencyUnit();
};
Scene_SellShop.prototype.buyingPrice = function() {
return this._buyWindow.price(this._item);
};
Scene_SellShop.prototype.sellingPrice = function() {
return Math.floor(this._item.price / 2);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.