Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Game.registerMod("funny mod",{
- init:function(){
- this.overrideGarden = function() {
- var garden = Game.ObjectsById[2].minigame;
- var M = garden;
- var dragonBoost = 1;
- var weedMult = 0.1;
- garden.logic = function() {
- //run each frame
- var now=Date.now();
- if (!M.freeze)
- {
- var loops=1;
- if (M.soilsById[M.soil].key=='woodchips') loops=3;
- loops*=M.loopsMult;
- M.loopsMult=1;
- for (var y=0;y<6;y++)
- {
- for (var x=0;x<6;x++)
- {
- if (M.isTileUnlocked(x,y))
- {
- var tile=M.plot[y][x];
- var me=M.plantsById[tile[0]-1];
- if (tile[0]>0)
- {
- //age
- tile[1]+=randomFloor((me.ageTick+me.ageTickR*Math.random())*M.plotBoost[y][x][0]*dragonBoost);
- tile[1]=Math.max(tile[1],0);
- if (me.immortal) tile[1]=Math.min(me.mature+1,tile[1]);
- else if (tile[1]>=100)
- {
- //die of old age
- M.plot[y][x]=[0,0];
- if (me.onDie) me.onDie(x,y);
- if (M.soilsById[M.soil].key=='pebbles' && Math.random()<0.35)
- {
- if (M.unlockSeed(me)) Game.Popup(loc("Unlocked %1 seed.",me.name),Game.mouseX,Game.mouseY);
- }
- }
- else if (!me.noContam)
- {
- //other plant contamination
- //only occurs in cardinal directions
- //immortal plants and plants with noContam are immune
- var list=[];
- for (var i in M.plantContam)
- {
- if (Math.random()<M.plantContam[i] && (!M.plants[i].weed || Math.random()<weedMult)) list.push(i);
- }
- var contam=choose(list);
- if (contam && me.key!=contam)
- {
- if ((!M.plants[contam].weed && !M.plants[contam].fungus) || Math.random()<M.plotBoost[y][x][2])
- {
- var any=0;
- var neighs={};//all surrounding plants
- var neighsM={};//all surrounding mature plants
- for (var i in M.plants){neighs[i]=0;}
- for (var i in M.plants){neighsM[i]=0;}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- if (neighsM[contam]>=1) M.plot[y][x]=[M.plants[contam].id+1,0];
- }
- }
- }
- }
- else
- {
- //plant spreading and mutation
- //happens on all 8 tiles around this one
- for (var loop=0;loop<loops;loop++)
- {
- var any=0;
- var neighs={};//all surrounding plants
- var neighsM={};//all surrounding mature plants
- for (var i in M.plants){neighs[i]=0;}
- for (var i in M.plants){neighsM[i]=0;}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- 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]++;}}
- if (any>0)
- {
- var muts=M.getMuts(neighs,neighsM);
- var list=[];
- for (var ii=0;ii<muts.length;ii++)
- {
- 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]);
- }
- if (list.length>0) M.plot[y][x]=[M.plants[choose(list)].id+1,0];
- }
- else if (loop==0)
- {
- //weeds in empty tiles (no other plants must be nearby)
- var chance=0.002*weedMult*M.plotBoost[y][x][2];
- if (Math.random()<chance) M.plot[y][x]=[M.plants['meddleweed'].id+1,0];
- }
- }
- }
- }
- }
- M.toRebuild=true;
- M.toCompute=true;
- }
- }
- if (M.toRebuild) M.buildPlot();
- if (M.toCompute) M.computeEffs();
- if (Game.keys[27])//esc
- {
- if (M.seedSelected>-1) M.plantsById[M.seedSelected].l.classList.remove('on');
- M.seedSelected=-1;
- }
- }
- }
- if (!Game.ready) { Game.registerHook('create', this.overrideGarden) } else { this.overrideGarden(); }
- },
- save: function(){
- let str = "";
- return str;
- },
- load: function(str){
- }
- })
Add Comment
Please, Sign In to add comment