Advertisement
jerry2810

BreedingSystem

Nov 25th, 2015
2,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var COLD = COLD || {};
  2.  
  3. COLD.BREED = COLD.BREED || {};
  4.  
  5.  /*:
  6.  * @plugindesc Makes a breeding system.
  7.  * @author Jeremy Cannady
  8.  *
  9.  * @param StatsIncrease
  10.  * @desc How much to increase the base stats. Number not percentage.For now...
  11.  * @default 10
  12.  *
  13.  * @param Hatch Animation
  14.  * @desc Animation to play when hatching an egg.
  15.  * @default 1
  16.  *
  17.  * @param Hatch Final Animation
  18.  * @desc Animation to play after the main hatching animation.
  19.  * @default 2
  20.  *
  21.  * @param Hatch Ani Repeats
  22.  * @desc How many times to repeat the animation.
  23.  * @default 2
  24.  *
  25.  * @param Notification Text
  26.  * @desc Text to notify that your egg is about to hatch.
  27.  * @default Oh...?
  28.  *
  29.  * @param Second Notification Text
  30.  * @desc Text indicating that your egg is hatching.
  31.  * @default Your egg appears to be hatching!
  32.  *
  33.  * @param Third Notification Text
  34.  * @desc Text to notify that your egg hatched.
  35.  * @default Your egg hatched! Would you like to name it?
  36.  *
  37.  * @param First Egg Text
  38.  * @desc Egg description of a new egg.
  39.  * @default A new egg.
  40.  *
  41.  * @param Second Egg Text
  42.  * @desc Egg description of egg not close to hatching.
  43.  * @default The egg is nowhere close to hatching.
  44.  *
  45.  * @param Third Egg Text
  46.  * @desc Egg description of egg near hatching
  47.  * @default The egg moves occasionally.
  48.  *
  49.  * @param Fourth Egg Text
  50.  * @desc Egg description of egg very close to hatching.
  51.  * @default Sounds can be heard inside!
  52.  *
  53.  * @param Monster Races
  54.  * @desc List of races and there egg Icon index,and steps to hatch, each separated by a comma.
  55.  * @default Dragon,150,10,Elf,160,50
  56.  *
  57.  * @param Breeding Pairs
  58.  * @desc List of monsters that can breed with each other.
  59.  * @default {"Dragon":"Elf","Elf":"Dragon,Elf"}
  60.  *
  61.  * @help
  62.  * Version 1.0
  63.  Note tag <race:Dragon> Everything is case sensitive.
  64.  PluginCommand: makeEgg 1 3, where 1 is actor id of the father and 3 is actor id of mother.
  65.  *
  66. */
  67.  
  68. aliasDM_extractSaveContents = DataManager.extractSaveContents;
  69. DataManager.extractSaveContents = function(contents) {
  70.     aliasDM_extractSaveContents.call(this,contents)
  71.     for(var i = 0; i < $gameSystem.generatedActors.length;i++){
  72.         $dataActors.push($gameSystem.generatedActors[i]);
  73.     };
  74.     for(var i = 0; i < $gameSystem.generatedItems.length;i++){
  75.         $dataItems.push($gameSystem.generatedItems[i]);
  76.     };
  77. };
  78.  
  79. COLD.BREED.Parameters = PluginManager.parameters('BreedingSystem');
  80. COLD.Param = COLD.Param || {};
  81. COLD.Param.BSystemStatsIncrease = Number(COLD.BREED.Parameters['StatsIncrease'] || 10);
  82. COLD.Param.BSystemAnimation = Number(COLD.BREED.Parameters['Hatch Animation'] || 1);
  83. COLD.Param.BSystemAnimationR = Number(COLD.BREED.Parameters['Hatch Ani Repeats'] || 2);
  84. COLD.Param.BSystemFAnimation = Number(COLD.BREED.Parameters['Hatch Final Animation'] || 2);
  85. COLD.Param.BSystem1Text = COLD.BREED.Parameters['Notification Text'];
  86. COLD.Param.BSystem2Text = COLD.BREED.Parameters['Second Notification Text'];
  87. COLD.Param.BSystem3Text = COLD.BREED.Parameters['Third Notification Text'];
  88. COLD.Param.BSystem1EggText = COLD.BREED.Parameters['First Egg Text'];
  89. COLD.Param.BSystem2EggText = COLD.BREED.Parameters['Second Egg Text'];
  90. COLD.Param.BSystem3EggText = COLD.BREED.Parameters['Third Egg Text'];
  91. COLD.Param.BSystem4EggText = COLD.BREED.Parameters['Fourth Egg Text'];
  92. COLD.Param.BSystemRaces = COLD.BREED.Parameters['Monster Races'].split(',');
  93. COLD.Param.BSystemPairs = JSON.parse(COLD.BREED.Parameters['Breeding Pairs']);
  94.    
  95. (function(){
  96.    
  97.     COLD.Param.BSystemConvertedPairs = {};
  98.  
  99.     for(var key in COLD.Param.BSystemPairs) {
  100.             COLD.Param.BSystemConvertedPairs[key] = (COLD.Param.BSystemPairs[key].split(','));
  101.     }
  102.    
  103.     COLD.BREED.storeGenerated = Game_System.prototype.initialize;
  104.     Game_System.prototype.initialize = function() {
  105.         COLD.BREED.storeGenerated.call(this);
  106.         this.generatedActors = [];
  107.         this.generatedItems = [];
  108.     };
  109.    
  110.     var newEgg_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  111.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  112.         newEgg_pluginCommand.call(this, command, args);
  113.         if (command === "newEgg") {
  114.             COLD.BREED.makeEgg($dataActors[(args[0])], $dataActors[(args[1])]);
  115.         };
  116.     };
  117.        
  118.     COLD.BREED.makeChild = function(egg){  
  119.         var mother = $dataActors[egg.meta.mother];
  120.         var father = $dataActors[egg.meta.father];
  121.         var sex = (egg.sex === "female") ? true : false;
  122.        
  123.         child = {
  124.             "id":$dataActors.length,
  125.             "traits":[],
  126.             "initialLevel":1,
  127.             "maxLevel":99,
  128.             "profile":"",
  129.             "mother":{"id":mother.id,"lvl":egg.motherLvl, "stats":egg.motherStats},
  130.             "father":{"id":father.id,"lvl": egg.fatherLvl, "stats":egg.fatherStats},
  131.             "sex":egg.sex,
  132.             "battlerName":(sex) ? mother["battlerName"] : father["battlerName"],
  133.             "characterIndex":(sex) ? mother["characterIndex"]:father["characterIndex"],
  134.             "characterName": (sex) ? mother["characterName"]:father["characterName"],
  135.             "faceIndex":(sex) ? mother["faceIndex"]:father["faceIndex"],
  136.             "faceName":(sex) ? mother["faceName"]:father["faceName"],
  137.             "name":(sex) ? mother["name"]:father["name"],
  138.             "nickname":(sex) ? mother["nickname"]:father["nickname"],
  139.             "note":(sex) ? mother["note"]:father["note"],
  140.             "classId":(sex) ? mother["classId"]:father["classId"],
  141.             "equips": [],
  142.             "intialStatBoost":false
  143.             };
  144.         $dataActors.push(child)
  145.         $gameSystem.generatedActors.push(child);
  146.         return child;
  147.     };
  148.    
  149.     COLD.BREED.makeSex = function(){
  150.         var sex = (Math.random() < 0.5) ? "female":"male";
  151.         return sex;
  152.     };
  153.    
  154.     COLD.BREED.makeEgg = function(father, mother){
  155.    
  156.         if( COLD.Param.BSystemConvertedPairs[mother.meta.race].indexOf(father.meta.race) != -1 ||
  157.             COLD.Param.BSystemConvertedPairs[father.meta.race].indexOf(mother.meta.race) != -1 ||
  158.             father.meta.race == mother.meta.race){
  159.             egg = {"id":null,
  160.             "animationId":120,
  161.             "consumable":false,
  162.             "damage":{"critical":false,"elementId":0,"formula":"0","type":0,"variance":0},
  163.             "steps":0,
  164.             "effects":[{"code":11, "dataId":0, "value1":0, "value2":0}],
  165.             "hitType":0,
  166.             "itypeId":1,
  167.             "name":"Egg",
  168.             "meta":{
  169.                     "hatchEgg":true,
  170.                     "father" :father.id,
  171.                     "mother":mother.id
  172.                     },
  173.             "note":"",
  174.             "occasion":0,
  175.             "price":0,
  176.             "repeats":1,
  177.             "scope":0,
  178.             "speed":0,
  179.             "successRate":100,
  180.             "sex":COLD.BREED.makeSex(),
  181.             "motherLvl": mother._level,
  182.             "fatherLvl": father._level,
  183.             "tpGain":0,
  184.             "maxItem":99};
  185.             var iconIfFemale = COLD.Param.BSystemRaces[(COLD.Param.BSystemRaces.indexOf(mother.meta.race) + 1)];
  186.             var iconIfMale = COLD.Param.BSystemRaces[(COLD.Param.BSystemRaces.indexOf(father.meta.race) + 1)];
  187.             var stepsIfFemale = COLD.Param.BSystemRaces[(COLD.Param.BSystemRaces.indexOf(mother.meta.race) + 2)];
  188.             var stepsIfMale = COLD.Param.BSystemRaces[(COLD.Param.BSystemRaces.indexOf(father.meta.race) + 2)];
  189.             egg.stepsToHatch = egg.sex ? stepsIfFemale : stepsIfMale;
  190.             egg["id"] = $dataItems.length;
  191.             egg["description"] = COLD.BREED.hatchStatus(egg);
  192.             egg["iconIndex"] = egg.sex ? iconIfFemale : iconIfMale;
  193.             $dataItems.push(egg);
  194.             $gameSystem.generatedItems.push(egg);
  195.             $gameParty.gainItem($dataItems[egg.id],1);
  196.         };
  197.     };
  198.    
  199.     COLD.BREED.hatchStatus = function(egg){
  200.         var text;
  201.         var progress = egg.steps / egg.stepsToHatch;
  202.         if(progress > 0.75){
  203.             text = COLD.Param.BSystem4EggText;
  204.         }else if(progress > 0.50){
  205.             text = COLD.Param.BSystem3EggText;
  206.         }else if(progress > 0.25){
  207.             text = COLD.Param.BSystem2EggText;
  208.         }else{
  209.             text = COLD.Param.BSystem1EggText;
  210.         }
  211.         egg.description = text;
  212.     }
  213.    
  214.     Object.defineProperties(Game_BattlerBase.prototype, {
  215.     // Maximum Hit Points
  216.     mhp: { get: function() {if(this.hatched == true){
  217.             return Math.round(this.param(0) + COLD.Param.BSystemStatsIncrease);
  218.         }else return this.param(0); }, configurable: true },
  219.     // Maximum Magic Points
  220.     mmp: { get: function() { if(this.hatched == true){
  221.             return Math.round(this.param(1) + COLD.Param.BSystemStatsIncrease);
  222.         }else return this.param(1); }, configurable: true },
  223.     // ATtacK power
  224.     atk: { get: function() { if(this.hatched == true){
  225.             return Math.round(this.param(2) + COLD.Param.BSystemStatsIncrease);
  226.         }else return this.param(2); }, configurable: true },
  227.     // DEFense power
  228.     def: { get: function() { if(this.hatched == true){
  229.             return Math.round(this.param(3) + COLD.Param.BSystemStatsIncrease);
  230.         }else return this.param(3);}, configurable: true },
  231.     // Magic ATtack power
  232.     mat: { get: function() {if(this.hatched == true){
  233.             return Math.round(this.param(4) + COLD.Param.BSystemStatsIncrease);
  234.         }else return this.param(4); }, configurable: true },
  235.     // Magic DeFense power
  236.     mdf: { get: function() { if(this.hatched == true){
  237.             return Math.round(this.param(5) + COLD.Param.BSystemStatsIncrease);
  238.         }else return this.param(5); }, configurable: true },
  239.     // AGIlity
  240.     agi: { get: function() { if(this.hatched == true){
  241.             return Math.round(this.param(6) + COLD.Param.BSystemStatsIncrease);
  242.         }else return this.param(6); }, configurable: true },
  243.     // LUcK
  244.     luk: { get: function() { if(this.hatched == true){
  245.             return Math.round(this.param(7) + COLD.Param.BSystemStatsIncrease);
  246.         }else return this.param(4); }, configurable: true }
  247.     });
  248.  
  249.     COLD.BREED.aliasSMapIsBusy = Scene_Map.prototype.isBusy;
  250.    
  251.     COLD.BREED.newisBusy = function(){
  252.         return $gameMessage.isBusy();
  253.     };
  254.    
  255.     COLD.BREED.changeSMapisBusy = function(value){
  256.         if(value == true){
  257.             Scene_Map.prototype.isBusy = COLD.BREED.newisBusy;
  258.         }else{
  259.             Scene_Map.prototype.isBusy = COLD.BREED.aliasSMapIsBusy;   
  260.         };
  261.     };
  262.    
  263.     COLD.BREED.hatchEgg = function(egg){
  264.         var child = this.makeChild(egg);
  265.         COLD.BREED.hatchingActorID = child.id;
  266.         COLD.BREED.hatchEggCurrent = egg;
  267.         $gameParty.gainItem(egg, -1);
  268.         COLD.BREED.changeSMapisBusy(true);
  269.         $gameMessage.add(COLD.Param.BSystem1Text);
  270.         SceneManager.push(COLD.BREED.Scene_Hatch);
  271.     };
  272.  
  273.     COLD.BREED.hatchEggCurrent = null;
  274.     COLD.BREED.hatchingActorID = null;
  275.    
  276.     Game_Party.prototype.increaseSteps = function() {
  277.         this._steps++;
  278.         var items = $gameParty.items().length;
  279.         for(var i = 0; i < items ; i++){
  280.             if($gameParty.items()[i].meta.hatchEgg == true){
  281.                 COLD.BREED.hatchStatus($gameParty.items()[i]);
  282.                 if($gameParty.items()[i].steps >= $gameParty.items()[i].stepsToHatch ){
  283.                     COLD.BREED.hatchEgg($gameParty.items()[i]);
  284.                     break;
  285.                 };
  286.                 $gameParty.items()[i].steps += 1;
  287.             };
  288.         };
  289.     };
  290.    
  291.     /**
  292.     * Create a scene for hatching.
  293.     */
  294.  
  295.     COLD.BREED.Scene_Hatch = function() {
  296.         this.initialize.apply(this, arguments);
  297.     }
  298.  
  299.     COLD.BREED.Scene_Hatch.prototype = Object.create(Scene_MenuBase.prototype);
  300.     COLD.BREED.Scene_Hatch.prototype.constructor = COLD.BREED.Scene_Hatch;
  301.  
  302.     COLD.BREED.Scene_Hatch.prototype.initialize = function() {
  303.         Scene_MenuBase.prototype.initialize.call(this);
  304.     };
  305.     COLD.BREED.Scene_Hatch.prototype.create = function() {
  306.         Scene_MenuBase.prototype.create.call(this);
  307.         this.createBackground();
  308.         this.createAnimation();
  309.         this.createNewActor();
  310.         this.createWindowLayer();
  311.         this.createAllWindows();
  312.     };
  313.  
  314.     COLD.BREED.Scene_Hatch.prototype.createAllWindows = function() {
  315.         this.createMessageWindow();
  316.     };
  317.    
  318.     COLD.BREED.Scene_Hatch.prototype.createMessageWindow = function() {
  319.         this._messageWindow = new Window_Message();
  320.         this.addWindow(this._messageWindow);
  321.         this._messageWindow.subWindows().forEach(function(window) {
  322.             this.addWindow(window);
  323.         }, this);
  324.     };
  325.  
  326.     COLD.BREED.Scene_Hatch.prototype.isBusy = function(){
  327.         return $gameMessage.isBusy();
  328.     };
  329.    
  330.     COLD.BREED.Scene_Hatch.prototype.counter = 0;
  331.     COLD.BREED.Scene_Hatch.prototype.startCounter = false;
  332.     COLD.BREED.Scene_Hatch.prototype.startAnimation = false;
  333.    
  334.     COLD.BREED.Scene_Hatch.prototype.update = function() {
  335.         Scene_Base.prototype.update.call(this);
  336.         if(this.counter == 0 && this.startCounter == false){
  337.             $gameMessage.add(COLD.Param.BSystem2Text)
  338.             this.startCounter = true;
  339.             this.startAnimation = true;
  340.         };
  341.        
  342.         if(this.startAnimation == true && !this.isBusy()){
  343.             this.activateAnimations()
  344.             this.startAnimation = false;
  345.         };
  346.        
  347.         if(this.startCounter == true && !this.isBusy()){
  348.             if(this.counter == this.hatchTime){
  349.                 this.startCounter = false;
  350.                 this.bitmap3.opacity = 255;
  351.                 var actorId = $gameActors._data.length - 1
  352.                 $gameParty.addActor(actorId);
  353.                 $gameActors.actor(actorId)["hatched"] = true;
  354.                 $gameMessage.add(COLD.Param.BSystem3Text)
  355.                 this.activateNameChange();
  356.             }
  357.             this.counter++;
  358.         };
  359.     };
  360.    
  361.     COLD.BREED.Scene_Hatch.prototype.createBackground = function() {
  362.         this._backSprite1 = new Sprite(ImageManager.loadBattleback1($gameMap.battleback1Name()));
  363.         this._backSprite2 = new Sprite(ImageManager.loadBattleback2($gameMap.battleback2Name()));
  364.         this.addChild(this._backSprite1);
  365.         this.addChild(this._backSprite2);
  366.     };
  367.    
  368.     COLD.BREED.Scene_Hatch.prototype.createNewActor = function() {
  369.         var characterName = $gameActors.actor(COLD.BREED.hatchingActorID)._characterName;
  370.         var characterIndex = $gameActors.actor(COLD.BREED.hatchingActorID)._characterIndex;
  371.         this.bitmap3 = new Sprite(ImageManager.loadCharacter(characterName));
  372.         this.bitmap3.move(Graphics.width / 2 - 24,Graphics.height / 2 -24);
  373.         var n = characterIndex;
  374.         var sx = (n % 4 * 3 + 1) * 48;
  375.         var sy = (Math.floor(n / 4) * 4) * 48;
  376.         this.bitmap3.setFrame(sx, sy, 48, 48);
  377.         this.bitmap3.opacity = 0;
  378.         this.addChild(this.bitmap3);
  379.     };
  380.    
  381.     COLD.BREED.Scene_Hatch.prototype.createAnimation = function() {
  382.         this._animation = new Sprite_Base();
  383.         this._animation.x = Graphics.width / 2;
  384.         this._animation.y = Graphics.height / 2;
  385.         this.addChild(this._animation);
  386.     };
  387.    
  388.     COLD.BREED.Scene_Hatch.prototype.activateAnimations = function(){
  389.         var animation = $dataAnimations[COLD.Param.BSystemAnimation];
  390.         var finishingAnimation = $dataAnimations[COLD.Param.BSystemFAnimation];
  391.         var animationFrames = animation.frames.length;
  392.         var fAnimationFrames = finishingAnimation.frames.length;
  393.         var repeats = COLD.Param.BSystemAnimationR;
  394.         for(var i = 0; i < repeats; i++){
  395.             this._animation.startAnimation(animation, false, i * animationFrames * 4);
  396.         };
  397.         this._animation.startAnimation(finishingAnimation, false, (4 * repeats * animationFrames))
  398.         this.hatchTime = (4 * repeats * animationFrames) + (4 * fAnimationFrames);
  399.     };
  400.    
  401.     COLD.BREED.Scene_Hatch.prototype.activateNameChange = function(){
  402.         SceneManager.goto(Scene_Name);
  403.         SceneManager.prepareNextScene(COLD.BREED.hatchingActorID, 8);
  404.         COLD.BREED.changeSMapisBusy(false);
  405.     };
  406.    
  407. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement