TheUnproPro

Quest TUT 1

Sep 10th, 2020
1,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** /*:
  2.  * @author William Ramsey
  3.  * @plugindesc A quest plugin!
  4.  *
  5.  * @target MZ
  6.  *
  7.  * @help
  8.  * This is the help section. There is a limited amount of characters you can use
  9.  * before you need to create a new line.
  10.  *
  11.  */
  12.  
  13. /**
  14.  * @class Quest
  15.  * Creates a quest!
  16.  *
  17.  * @param {String} name Name of the quest
  18.  * @param {String} description Description of the quest
  19.  * @param {Object} condition Condition object
  20.  *
  21.  * @param {Object[]} rewards Rewards for completing
  22.  *
  23.  */
  24. class Quest {
  25.     constructor(name = 'QUEST', description = '...', condition = { flag: 1, var: 0, max: 0 }, rewards = []) {
  26.         this.name = name;
  27.         this.description = description;
  28.         this.condition = {
  29.             flag: condition.flag,
  30.             var: condition.var,
  31.             max: condition.max
  32.         }
  33.         this.rewards = rewards;
  34.  
  35.         this.complete = false;
  36.     }
  37.  
  38.     /**
  39.      * @method complete
  40.      * Marks the quest as complete
  41.      */
  42.     complete() {
  43.         this.complete = true;
  44.         for (let i of this.rewards) {
  45.             switch (i.type) {
  46.                 case 'item':
  47.                     $gameParty.gainItem(i.index, i.amount);
  48.                     break;
  49.                 case 'exp':
  50.                     for (let j in $gameActors) {
  51.                         $gameActors[j].gainExp(i.amount);
  52.                     }
  53.                     break;
  54.                 case 'gold':
  55.                     $gameParty.gainGold(i.amount);
  56.                     break;
  57.             }
  58.         }
  59.     }
  60.  
  61.     /**
  62.      * @method addReward
  63.      * Adds a reward.
  64.      *
  65.      * @param {Object} o {type: 'item', index: 1, amount: 1}
  66.      */
  67.     addReward(o) {
  68.         this.rewards.push(o);
  69.     }
  70. }
  71.  
  72. class Window_QuestData extends Window_Base {
  73.     constructor(rect) {
  74.         super(rect);
  75.         this.scrollY = 0;
  76.         this.questId = null;
  77.         this.rewards = '';
  78.     }
  79.  
  80.     /**
  81.      * @method setRewards
  82.      * Sets the rewards text.
  83.      * @param {Number} questId
  84.      */
  85.     setRewards(questId) {
  86.         this.rewards = this.getRewards(questId);
  87.     }
  88.  
  89.     /**
  90.      * @method refresh
  91.      * Draws the text data.
  92.      * @param {Number} questId
  93.      */
  94.     refresh() {
  95.         const questId = this.questId;
  96.  
  97.         this.contents.clear();
  98.         this.drawTextEx(`${questId.name}\n\n${questId.description}\n\nRewards:\n${this.rewards}`, 0, this.scrollY);
  99.         this.bitmap.fillRect(0, this.lineHeight() - this.scrollY, this.contents.width, 2, '#00000090');
  100.     }
  101.  
  102.     /**
  103.      * Updates every frame
  104.      */
  105.     update() {
  106.         let scrolling = Number(Input.isPressed('pageup')) - Number(Input.isPressed('pagedown'))
  107.         if (scrolling != 0) {
  108.             this.scrollY -= scrolling;
  109.  
  110.             let lines = 5 + (this.rewards.split('\n').length) * this.lineHeight();
  111.             this.scrollY = Math.min(Math.max(this.scrollY, 0), lines - this.contents.height);
  112.  
  113.             this.refresh();
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * @method getRewards
  119.      * Gets rewards and returns them as a string.
  120.      * @param {Object} questId
  121.      */
  122.     getRewards(questId) {
  123.         let exp = 0;
  124.         let gold = 0;
  125.         let items = ``;
  126.  
  127.         for (let i of questId.rewards) {
  128.             switch (i.type) {
  129.                 case 'item':
  130.                     items += ` • ${$dataItems[i.index].name} x${i.amount}\n`
  131.                     break;
  132.                 case 'exp':
  133.                     exp += i.amount;
  134.                     break;
  135.  
  136.                 case 'gold':
  137.                     gold += i.amount;
  138.                     break;
  139.             }
  140.         }
  141.  
  142.         return `EXP: ${exp}\nGold: ${gold}\nItems: ${items}`;
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment