CursedSliver

fua

Nov 25th, 2023 (edited)
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Game.registerMod("funny mod",{
  2.     init:function(){
  3.        
  4.         this.overrideGarden = function() {
  5.             var garden = Game.ObjectsById[2].minigame;
  6.             var M = garden;
  7.             var dragonBoost = 1;
  8.             var weedMult = 0.1;
  9.             garden.logic = function() {
  10.                     //run each frame
  11.             var now=Date.now();
  12.            
  13.             if (!M.freeze)
  14.             {
  15.                     var loops=1;
  16.                     if (M.soilsById[M.soil].key=='woodchips') loops=3;
  17.                     loops*=M.loopsMult;
  18.                     M.loopsMult=1;
  19.                
  20.                     for (var y=0;y<6;y++)
  21.                     {
  22.                         for (var x=0;x<6;x++)
  23.                         {
  24.                         if (M.isTileUnlocked(x,y))
  25.                         {
  26.                             var tile=M.plot[y][x];
  27.                             var me=M.plantsById[tile[0]-1];
  28.                             if (tile[0]>0)
  29.                             {
  30.                                 //age
  31.                                 tile[1]+=randomFloor((me.ageTick+me.ageTickR*Math.random())*M.plotBoost[y][x][0]*dragonBoost);
  32.                                 tile[1]=Math.max(tile[1],0);
  33.                                 if (me.immortal) tile[1]=Math.min(me.mature+1,tile[1]);
  34.                                 else if (tile[1]>=100)
  35.                                 {
  36.                                     //die of old age
  37.                                     M.plot[y][x]=[0,0];
  38.                                     if (me.onDie) me.onDie(x,y);
  39.                                     if (M.soilsById[M.soil].key=='pebbles' && Math.random()<0.35)
  40.                                     {
  41.                                         if (M.unlockSeed(me)) Game.Popup(loc("Unlocked %1 seed.",me.name),Game.mouseX,Game.mouseY);
  42.                                     }
  43.                                 }
  44.                                 else if (!me.noContam)
  45.                                 {
  46.                                     //other plant contamination
  47.                                     //only occurs in cardinal directions
  48.                                     //immortal plants and plants with noContam are immune
  49.                                    
  50.                                     var list=[];
  51.                                     for (var i in M.plantContam)
  52.                                     {
  53.                                         if (Math.random()<M.plantContam[i] && (!M.plants[i].weed || Math.random()<weedMult)) list.push(i);
  54.                                     }
  55.                                     var contam=choose(list);
  56.  
  57.                                     if (contam && me.key!=contam)
  58.                                     {
  59.                                         if ((!M.plants[contam].weed && !M.plants[contam].fungus) || Math.random()<M.plotBoost[y][x][2])
  60.                                         {
  61.                                             var any=0;
  62.                                             var neighs={};//all surrounding plants
  63.                                             var neighsM={};//all surrounding mature plants
  64.                                             for (var i in M.plants){neighs[i]=0;}
  65.                                             for (var i in M.plants){neighsM[i]=0;}
  66.                                             var neigh=M.getTile(x,y-1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  67.                                             var neigh=M.getTile(x,y+1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  68.                                             var neigh=M.getTile(x-1,y);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  69.                                             var neigh=M.getTile(x+1,y);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  70.                                            
  71.                                             if (neighsM[contam]>=1) M.plot[y][x]=[M.plants[contam].id+1,0];
  72.                                         }
  73.                                     }
  74.                                 }
  75.                             }
  76.                             else
  77.                             {
  78.                                 //plant spreading and mutation
  79.                                 //happens on all 8 tiles around this one
  80.                                 for (var loop=0;loop<loops;loop++)
  81.                                 {
  82.                                     var any=0;
  83.                                     var neighs={};//all surrounding plants
  84.                                     var neighsM={};//all surrounding mature plants
  85.                                     for (var i in M.plants){neighs[i]=0;}
  86.                                     for (var i in M.plants){neighsM[i]=0;}
  87.                                     var neigh=M.getTile(x,y-1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  88.                                     var neigh=M.getTile(x,y+1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  89.                                     var neigh=M.getTile(x-1,y);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  90.                                     var neigh=M.getTile(x+1,y);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  91.                                     var neigh=M.getTile(x-1,y-1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  92.                                     var neigh=M.getTile(x-1,y+1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  93.                                     var neigh=M.getTile(x+1,y-1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  94.                                     var neigh=M.getTile(x+1,y+1);if (neigh[0]>0){var age=neigh[1];neigh=M.plantsById[neigh[0]-1];any++;neighs[neigh.key]++;if (age>=neigh.mature){neighsM[neigh.key]++;}}
  95.                                     if (any>0)
  96.                                     {
  97.                                         var muts=M.getMuts(neighs,neighsM);
  98.                                        
  99.                                         var list=[];
  100.                                         for (var ii=0;ii<muts.length;ii++)
  101.                                         {
  102.                                             if (Math.random()<muts[ii][1] && (!M.plants[muts[ii][0]].weed || Math.random()<weedMult) && ((!M.plants[muts[ii][0]].weed && !M.plants[muts[ii][0]].fungus) || Math.random()<M.plotBoost[y][x][2])) list.push(muts[ii][0]);
  103.                                         }
  104.                                         if (list.length>0) M.plot[y][x]=[M.plants[choose(list)].id+1,0];
  105.                                     }
  106.                                     else if (loop==0)
  107.                                     {
  108.                                         //weeds in empty tiles (no other plants must be nearby)
  109.                                         var chance=0.002*weedMult*M.plotBoost[y][x][2];
  110.                                         if (Math.random()<chance) M.plot[y][x]=[M.plants['meddleweed'].id+1,0];
  111.                                     }
  112.                                 }
  113.                             }
  114.                         }
  115.                     }
  116.                
  117.                 M.toRebuild=true;
  118.                 M.toCompute=true;
  119.             }
  120.         }
  121.         if (M.toRebuild) M.buildPlot();
  122.         if (M.toCompute) M.computeEffs();
  123.        
  124.         if (Game.keys[27])//esc
  125.         {
  126.             if (M.seedSelected>-1) M.plantsById[M.seedSelected].l.classList.remove('on');
  127.             M.seedSelected=-1;
  128.         }
  129.             }
  130.         }
  131.  
  132.         if (!Game.ready) { Game.registerHook('create', this.overrideGarden) } else { this.overrideGarden(); }
  133.     },
  134.     save: function(){
  135.         let str = "";
  136.         return str;
  137.     },
  138.     load: function(str){
  139.  
  140.     }
  141. })
Add Comment
Please, Sign In to add comment