Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** /*:
- * @author William Ramsey
- * @plugindesc A quest plugin!
- *
- * @target MZ
- *
- * @help
- * This is the help section. There is a limited amount of characters you can use
- * before you need to create a new line.
- *
- */
- /**
- * @class Quest
- * Creates a quest!
- *
- * @param {String} name Name of the quest
- * @param {String} description Description of the quest
- * @param {Object} condition Condition object
- *
- * @param {Object[]} rewards Rewards for completing
- *
- */
- class Quest {
- constructor(name = 'QUEST', description = '...', condition = { flag: 1, var: 0, max: 0 }, rewards = []) {
- this.name = name;
- this.description = description;
- this.condition = {
- flag: condition.flag,
- var: condition.var,
- max: condition.max
- }
- this.rewards = rewards;
- this.complete = false;
- }
- /**
- * @method complete
- * Marks the quest as complete
- */
- complete() {
- this.complete = true;
- for (let i of this.rewards) {
- switch (i.type) {
- case 'item':
- $gameParty.gainItem(i.index, i.amount);
- break;
- case 'exp':
- for (let j in $gameActors) {
- $gameActors[j].gainExp(i.amount);
- }
- break;
- case 'gold':
- $gameParty.gainGold(i.amount);
- break;
- }
- }
- }
- /**
- * @method addReward
- * Adds a reward.
- *
- * @param {Object} o {type: 'item', index: 1, amount: 1}
- */
- addReward(o) {
- this.rewards.push(o);
- }
- }
- class Window_QuestData extends Window_Base {
- constructor(rect) {
- super(rect);
- this.scrollY = 0;
- this.questId = null;
- this.rewards = '';
- }
- /**
- * @method setRewards
- * Sets the rewards text.
- * @param {Number} questId
- */
- setRewards(questId) {
- this.rewards = this.getRewards(questId);
- }
- /**
- * @method refresh
- * Draws the text data.
- * @param {Number} questId
- */
- refresh() {
- const questId = this.questId;
- this.contents.clear();
- this.drawTextEx(`${questId.name}\n\n${questId.description}\n\nRewards:\n${this.rewards}`, 0, this.scrollY);
- this.bitmap.fillRect(0, this.lineHeight() - this.scrollY, this.contents.width, 2, '#00000090');
- }
- /**
- * Updates every frame
- */
- update() {
- let scrolling = Number(Input.isPressed('pageup')) - Number(Input.isPressed('pagedown'))
- if (scrolling != 0) {
- this.scrollY -= scrolling;
- let lines = 5 + (this.rewards.split('\n').length) * this.lineHeight();
- this.scrollY = Math.min(Math.max(this.scrollY, 0), lines - this.contents.height);
- this.refresh();
- }
- }
- /**
- * @method getRewards
- * Gets rewards and returns them as a string.
- * @param {Object} questId
- */
- getRewards(questId) {
- let exp = 0;
- let gold = 0;
- let items = ``;
- for (let i of questId.rewards) {
- switch (i.type) {
- case 'item':
- items += ` • ${$dataItems[i.index].name} x${i.amount}\n`
- break;
- case 'exp':
- exp += i.amount;
- break;
- case 'gold':
- gold += i.amount;
- break;
- }
- }
- return `EXP: ${exp}\nGold: ${gold}\nItems: ${items}`;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment