Path: blob/main/assets/javascript/cookieclicker/dungeons.js
15352 views
var LaunchDungeons=function()1{2Game.GetWord=function(type)3{4if (type=='secret') return choose(['hidden','secret','mysterious','forgotten','forbidden','lost','sunk','buried','concealed','shrouded','invisible','elder']);5if (type=='ruined') return choose(['ancient','old','ruined','ravaged','destroyed','collapsed','demolished','burnt','torn-down','shattered','dilapidated','abandoned','crumbling','derelict','decaying']);6if (type=='magical') return choose(['arcane','magical','mystical','sacred','honed','banished','unholy','holy','demonic','enchanted','necromantic','bewitched','haunted','occult','astral']);7return '';8}910/*=====================================================================================11DUNGEONS12=======================================================================================*/13Game.DungeonTypes=[];14Game.DungeonType=function(name)15{16this.name=name;17this.nameGenerator=function(){return 'Mysterious dungeon';};18this.roomTypes=[];19Game.DungeonTypes[this.name]=this;20return this;21};2223/*=====================================================================================24CREATE DUNGEON TYPES25=======================================================================================*/26new Game.DungeonType('Factory').27nameGenerator=function(){28var str='';29str+=Game.GetWord(choose(['secret','ruined','magical']))+' '+choose(['factory','factories','bakery','bakeries','confectionery','laboratory','research center','chocolate forge','chocolate foundry','manufactory','warehouse','machinery','works','bakeworks','workshop','assembly line']);30return str;31};3233new Game.DungeonType('Mine').34nameGenerator=function(){35var str='';36str+=Game.GetWord(choose(['secret','ruined','magical']))+' '+choose(['chocolate','chocolate','chocolate','white chocolate','sugar','cacao'])+' '+choose(['mine','mines','pit','pits','quarry','excavation','tunnel','shaft','lode','trench','mountain','vein','cliff','peak','dome','crater','abyss','chasm','hole','burrow']);37return str;38};3940new Game.DungeonType('Portal').41nameGenerator=function(){42var str='';43str+=Game.GetWord(choose(['secret','ruined','magical']))+' '+choose(['portal','gate','dimension','warpgate','door']);44return str;45};4647new Game.DungeonType('Secret zebra level').48nameGenerator=function(){49var str='';50str+=Game.GetWord(choose(['secret']))+' '+choose(['zebra level']);51return str;52};535455/*=====================================================================================56CREATE TILE TYPES57=======================================================================================*/5859var D=new DungeonGen();60D.loadTiles([61['wall',[1,0],'join'],62['wall corner',[1,0]],63['floor',[1,1],'random3'],64['tiled floor',[1,2],'join'],65['round pillar',[1,4]],66['square pillar',[2,4]],67['potted plant',[3,4]],68['bookshelf',[4,5],'join'],69['door',[1,3],'join'],70['alt wall',[4,0],'join'],71['alt wall corner',[4,0]],72['alt floor',[4,1],'random3'],73['alt tiled floor',[4,2],'join'],74['alt round pillar',[4,4]],75['alt square pillar',[5,4]],76['alt potted plant',[6,4]],77['alt bookshelf',[4,6],'join'],78['alt door',[4,3],'join'],79['water',[1,5]],80['green water',[2,5]],81['dark water',[3,5]],82['wooden wall',[1,7],'join'],83['wooden floor',[1,6],'random3'],84['conveyor belt',[4,7],'join'],85['entrance',[0,1]],86['alt entrance',[0,3]],87['exit',[0,2]],88['alt exit',[0,4]]89]);909192/*=====================================================================================93CREATE MONSTER TYPES94=======================================================================================*/9596/*97An explanation of stats :98-hp : health points99-speed : determines who attacks first in a fight; bypasses dodging; determines how fast heroes auto-run dungeons100-might : determines how much damage is done to opponents101-guard : lowers incoming damage102-dodge : chance of avoiding incoming attacks completely (affected by the opponent's speed)103-luck : heroes only, determines drops and rare encounters104-rarity : monsters only, determines how often a monster is added to the spawn table105-level : monsters only, determines which average room depth the monster is more likely to spawn in (also determines the loot amount)106*/107Game.monsterIconY=10;//offset for dungeonItems.png monsters108Game.Monsters=[];109Game.Monster=function(name,pic,icon,level,stats,loot)110{111this.name=name;112this.pic=pic;113this.icon=icon;114this.level=level;115this.stats={};116for (var i in stats)117{this.stats[i]=stats[i];}118this.stats.hpm=this.stats.hp;119this.stats.rarity=stats.rarity||1;120this.loot=loot||{};121this.boss=0;122this.quotes={};123Game.Monsters[this.name]=this;124}125var basicLoot={cookies:{min:1,max:5,prob:0.5}};126var goodLoot={cookies:{min:3,max:8,prob:1},gear:{prob:0.05}};127var bossLoot={gear:{prob:1}};128var chestLoot={cookies:{min:2,max:20,prob:1},gear:{prob:0.1}};129var bossLoot={cookies:{min:10,max:50,prob:1},gear:{prob:0.2}};130131//general monsters132new Game.Monster('Doughling','doughling',[0,0],1,{hp:5,might:2,guard:2,speed:6,dodge:6,rarity:0.7},basicLoot);133new Game.Monster('Elder doughling','elderDoughling',[1,0],7,{hp:20,might:7,guard:7,speed:4,dodge:4,rarity:0.7},goodLoot);134new Game.Monster('Angry sentient cookie','angrySentientCookie',[5,0],5,{hp:16,might:8,guard:4,speed:5,dodge:5,rarity:1},basicLoot);135new Game.Monster('Baby sentient cookie','babySentientCookie',[4,0],1,{hp:3,might:1,guard:1,speed:7,dodge:7,rarity:1},basicLoot);136new Game.Monster('Burnt sentient cookie','burntSentientCookie',[6,0],5,{hp:16,might:12,guard:2,speed:3,dodge:2,rarity:0.2},basicLoot);137new Game.Monster('Raw sentient cookie','rawSentientCookie',[5,0],5,{hp:16,might:6,guard:4,speed:7,dodge:7,rarity:0.2},basicLoot);138new Game.Monster('Sugar bunny','sugarBunny',[8,0],5,{hp:10,might:3,guard:8,speed:12,dodge:9,rarity:0.001},{cookies:{min:1000,max:10000}});139Game.Monsters['Sugar bunny'].onKill=function(){Game.Win('Follow the white rabbit');};Game.Monsters['Sugar bunny'].AI='flee';140141//factory monsters142new Game.Monster('Crazed kneader','crazedKneader',[0,2],6,{hp:18,might:6,guard:8,speed:3,dodge:2,rarity:0.5},goodLoot);143new Game.Monster('Crazed chip-spurter','crazedDoughSpurter',[0,2],6,{hp:15,might:6,guard:8,speed:5,dodge:3,rarity:0.5},goodLoot);144new Game.Monster('Alarm bot','alarmTurret',[3,2],2,{hp:6,might:3,guard:5,speed:8,dodge:8,rarity:0.5},basicLoot);145new Game.Monster('Chirpy','chirpy',[4,2],3,{hp:7,might:4,guard:6,speed:9,dodge:9,rarity:0.01},{cookies:{min:500,max:5000}});146Game.Monsters['Chirpy'].onKill=function(){Game.Win('Chirped out');};Game.Monsters['Chirpy'].quotes={fight:'oh, hello <3'};147new Game.Monster('Disgruntled worker','disgruntledWorker',[1,2],4,{hp:14,might:5,guard:5,speed:6,dodge:4,rarity:0.6},basicLoot);148new Game.Monster('Disgruntled overseer','disgruntledOverseer',[1,2],7,{hp:22,might:7,guard:5,speed:6,dodge:4,rarity:0.5},basicLoot);149new Game.Monster('Disgruntled cleaning lady','disgruntledCleaningLady',[2,2],4,{hp:13,might:4,guard:5,speed:7,dodge:6,rarity:0.3},basicLoot);150151new Game.Monster('Sentient Furnace','sentientFurnace',[0,3],0,{hp:60,might:14,guard:12,speed:4,dodge:0,rarity:1},bossLoot);//boss152Game.Monsters['Sentient Furnace'].onKill=function(){Game.Win('Getting even with the oven');};Game.Monsters['Sentient Furnace'].AI='static';Game.Monsters['Sentient Furnace'].boss=1;Game.Monsters['Sentient Furnace'].quotes={fight:'YOU ARE NOT READY!',defeat:'OH... BURN.'};153new Game.Monster('Ascended Baking Pod','ascendedBakingPod',[1,3],0,{hp:60,might:12,guard:14,speed:4,dodge:0,rarity:0.7},bossLoot);//boss154Game.Monsters['Ascended Baking Pod'].onKill=function(){Game.Win('Now this is pod-smashing');};Game.Monsters['Ascended Baking Pod'].AI='static';Game.Monsters['Ascended Baking Pod'].boss=1;Game.Monsters['Ascended Baking Pod'].quotes={fight:'rrrrrrrise.',defeat:'blrglblg.'};155156157Game.BossMonsters=[];158for (var i in Game.Monsters)159{160if (Game.Monsters[i].boss) Game.BossMonsters.push(Game.Monsters[i]);161}162163/*=====================================================================================164ENTITY MECHANICS165=======================================================================================*/166167Game.Entity=function(type,subtype,dungeon,pic,stats)//objects you could find on the map : doors, mobs, interactables, items, player, exits...168{169this.type=type;170this.subtype=subtype||'';171this.dungeon=dungeon;172this.pic=pic||[0,0];173this.stats={};174for (var i in stats)175{this.stats[i]=stats[i];}176177this.x=-1;178this.y=-1;179this.obstacle=0;180this.zIndex=1;181if (this.type=='monster')182{183this.obstacle=1;184this.pic=[Game.Monsters[this.subtype].icon[0],Game.Monsters[this.subtype].icon[1]];185this.pic[1]+=Game.monsterIconY;186this.targets=[];187this.stuck=0;188this.zIndex=10;189this.fighting=0;190this.AI=Game.Monsters[this.subtype].AI||'normal';191this.onKill=Game.Monsters[this.subtype].onKill||function(){};192for (var i in Game.Monsters[this.subtype].stats){this.stats[i]=Game.Monsters[this.subtype].stats[i];}193}194else if (this.type=='hero')195{196this.obstacle=1;197this.pic=[Game.Heroes[this.subtype].icon[0],Game.Heroes[this.subtype].icon[1]];198this.targets=[];199this.stuck=0;200this.zIndex=100;201this.fighting=0;202for (var i in Game.Heroes[this.subtype].stats){this.stats[i]=Game.Heroes[this.subtype].stats[i];}203204//increase stats by amount of matching building (change that later to use gear instead)205var mult=Math.max(0,(Game.Objects[this.dungeon.type].amount/20-1));206this.stats.hpm+=Math.ceil(mult*2);207this.stats.hp=this.stats.hpm;208this.stats.might+=mult;209this.stats.guard+=mult;210this.stats.speed+=mult;211this.stats.dodge+=mult;212}213else if (this.type=='item')214{215this.zIndex=5;216this.value=0;217}218else if (this.type=='destructible')//crates, doors219{220this.obstacle=1;221this.life=3;222this.zIndex=15;223if (this.subtype=='door') this.pic=[0,7];224else this.pic=[Math.floor(Math.random()*4+2),7];225226this.onKill=function()227{228if (this.subtype=='random')229{230var value=Math.round(Math.pow(Math.random(),6)*(10+this.dungeon.level));231if (value>0)232{233var entity=this.dungeon.AddEntity('item','cookies',this.x,this.y);234entity.value=value;235}236}237}238}239else if (this.type=='special')240{241this.zIndex=5;242this.value='';243this.obstacle=1;244}245246this.Say=function(what)247{248if (this.type=='monster')249{250if (Game.Monsters[this.subtype].quotes[what]) this.dungeon.Log(this.subtype+' : "<span style="color:#f96;">'+choose(Game.Monsters[this.subtype].quotes[what].split('|'))+'</span>"');251}252}253this.Draw=function()//return the string to draw this254{255var name='?';256if (this.subtype=='random') name='clutter'; else name=this.subtype;257if (this.type=='item' && this.subtype=='cookies' && this.value>0)258{259if (this.value<2) this.pic=[0,5];260else if (this.value<3) this.pic=[1,5];261else if (this.value<4) this.pic=[2,5];262else if (this.value<6) this.pic=[3,5];263else if (this.value<10) this.pic=[4,5];264else if (this.value<20) this.pic=[5,5];265else if (this.value<30) this.pic=[7,5];266else if (this.value<70) this.pic=[6,5];267else if (this.value<200) this.pic=[8,5];268else this.pic=[6,6];// if (this.value<1000) this.pic=[1,5];269}270else if (this.type=='special' && this.subtype=='upgrade')271{272if (this.value!='') this.pic=[7,6]; else this.pic=[8,6];273}274return '<div class="thing" title="'+name+'" style="z-index:'+(200+this.zIndex)+';left:'+(this.x*16)+'px;top:'+(this.y*16)+'px;background-position:'+(-this.pic[0]*16)+'px '+(-this.pic[1]*16)+'px;"></div>';275}276this.Wander=function()//AI to move around aimlessly277{278this.targets=[];279this.targets.push([-1,0],[1,0],[0,-1],[0,1]);280this.Move();281}282this.GoTo=function(x,y)//AI to move to a specific point283{284this.targets=[];285if (this.x<x) this.targets.push([1,0]);286if (this.x>x) this.targets.push([-1,0]);287if (this.y<y) this.targets.push([0,1]);288if (this.y>y) this.targets.push([0,-1]);289if (!this.Move())//really stuck? try to maneuver laterally!290{291this.targets=[];292if (this.x==x) this.targets.push([1,0],[-1,0]);//somehow this feels inverted... but it doesn't work the other way293if (this.y==y) this.targets.push([0,1],[0,-1]);//hypothesis : *MAGIC*294this.Move();295}296}297this.Flee=function(x,y)//AI to run away from a specific point298{299this.targets=[];300if (this.x>x) this.targets.push([1,0]);301if (this.x<x) this.targets.push([-1,0]);302if (this.y>y) this.targets.push([0,1]);303if (this.y<y) this.targets.push([0,-1]);304if (!this.Move())//really stuck? try to maneuver laterally!305{306this.targets=[];307if (this.x==x) this.targets.push([1,0],[-1,0]);//somehow this feels inverted... but it doesn't work the other way308if (this.y==y) this.targets.push([0,1],[0,-1]);//hypothesis : *MAGIC*309this.Move();310}311}312this.Move=function()//AI to move to the target313{314if (this.targets.length>0)315{316var goodTargets=[];317if (this.type=='hero') goodTargets=this.targets;318else319{320for (var i in this.targets)321{322var thisTarget=this.targets[i];323if (this.dungeon.CheckObstacle(this.x+thisTarget[0],this.y+thisTarget[1])!=-1) goodTargets.push([thisTarget[0],thisTarget[1]]);324}325}326if (goodTargets.length>0)327{328var target=choose(goodTargets);329var obstacle=this.dungeon.CheckObstacle(this.x+target[0],this.y+target[1]);330if (obstacle==this) obstacle=0;331if (obstacle==0 && this.AI!='static')332{333this.x+=target[0];334this.y+=target[1];335}336else this.stuck+=2;337if (obstacle!=0 && obstacle!=-1)338{339obstacle.HitBy(this);340}341if (obstacle==-1) return 0;342}343else {this.stuck+=2;return 0;}344if (this.AI=='static') this.stuck=0;345return 1;346}347return 0;348}349this.HitBy=function(by)//attacked by another entity350{351if (this.type=='destructible' && by.type=='hero')//break destructibles352{353by.stuck=0;354this.life--;355if (this.life<=0)356{357if (this.onKill) this.onKill();358this.Destroy();359}360else this.pic=[this.pic[0],this.pic[1]+1];361}362else if (this.type=='special' && this.subtype=='upgrade')//upgrade relic363{364this.obstacle=0;365if (Game.Upgrades[this.value]) Game.Upgrades[this.value].earn();366this.value='';367}368else if ((this.type=='monster' && by.type=='hero') || (this.type=='hero' && by.type=='monster') && this.stats.hp>0)//it's a fight!369{370by.stuck=0;371372var monster=(this.type=='hero'?by:this);373var hero=(this.type=='hero'?this:by);374this.dungeon.currentOpponent=monster;375376if (monster.fighting==0)//first meeting377{378Game.Heroes[hero.subtype].Say('meet '+Game.Monsters[monster.subtype].name);379this.Say('fight');380}381if (this.fighting==0)382{383this.fighting=1;384by.fighting=1;385}386387var attackStr='';388var attackerName='';389var defenderName='';390if (by.type=='hero') attackerName=Game.Heroes[by.subtype].name;391else if (by.type=='monster') attackerName=Game.Monsters[by.subtype].name;392if (this.type=='hero') defenderName=Game.Heroes[this.subtype].name;393else if (this.type=='monster') defenderName=Game.Monsters[this.subtype].name;394395//battle formulas (have fun with these)396attackStr+=attackerName+' swings at '+defenderName+'!';397var damage=Math.round(Math.max(1,Math.min(by.stats.might,Math.pow(((by.stats.might+2.5)/Math.max(1,this.stats.guard)),2)))*(0.8+Math.random()*0.4+Math.pow(Math.random()*0.8,6)));398var dodge=Math.random()>(by.stats.speed/Math.max(1,this.stats.dodge+2.5));399if (dodge)400{401attackStr+=' '+defenderName+' dodged the attack.';402}403else404{405if (by.stats.luck && by.type=='hero' && Math.random()<by.stats.luck*0.01) {damage*=2;attackStr+=' <b>It\'s a critical!</b>';}//very rare critical based on luck406attackStr+=' <b>'+damage+'</b> damage!';407408this.stats.hp-=damage;409this.stats.hp=Math.max(this.stats.hp,0);410if (this.stats.luck && this.type=='hero')411{412if (this.stats.hp==0 && Math.random()<this.stats.luck*0.01) {this.stats.hp=1;attackStr+=' '+defenderName+' was saved from certain death!';}//very rare life-saving based on luck413}414}415416if (this.type=='hero') attackStr='<span style="color:#f99;">'+attackStr+'</span>';417if (attackStr!='') this.dungeon.Log(attackStr);418419if (this.stats.hp<=0)//die420{421this.dungeon.Log(attackerName+' crushed '+defenderName+'!');422if (this.type=='hero')423{424Game.Heroes[this.subtype].Say('defeat');425this.dungeon.Log('<span style="color:#f66;">'+Game.Heroes[this.subtype].name+' has been defeated.</span>');426this.dungeon.FailLevel();427}428if (this.type=='monster' && by.type=='hero')429{430l('monsterSlot'+this.dungeon.id).style.visibility='hidden';431this.dungeon.monstersKilledThisRun+=1;432if (Math.random()<0.05) Game.Heroes[by.subtype].Say('win');433Game.Heroes[by.subtype].Say('win against '+Game.Monsters[this.subtype].name);434this.Say('defeat');435if (Game.Monsters[this.subtype].loot)436{437var loot=Game.Monsters[this.subtype].loot;438if (loot.gear && (!loot.gear.prob || Math.random()<loot.gear.prob)) {}//drop gear439if (loot.cookies && (!loot.cookies.prob || Math.random()<loot.cookies.prob))440{441var entity=this.dungeon.AddEntity('item','cookies',this.x,this.y);//drop cookies442entity.value=Math.round(loot.cookies.min+Math.random()*(loot.cookies.max-loot.cookies.min));443}444}445if (this.onKill) this.onKill();446this.Destroy();447}448}449}450}451this.Turn=function()//do this every turn (walk around, heal up...)452{453if (this.type=='monster')454{455var howManyTurns=this.GetInitiative();456for (var i=0;i<howManyTurns;i++)457{458if (1==1)//this.AI!='static')459{460if (this.AI=='flee') this.Flee(this.dungeon.heroEntity.x,this.dungeon.heroEntity.y);//flee from the player461else462{463this.GoTo(this.dungeon.heroEntity.x,this.dungeon.heroEntity.y);//track the player464if (this.stuck || this.targets.length==[]) this.Wander();//can't reach the player? walk around randomly465}466}467}468}469if (this.type=='monster' || this.type=='hero')470{471if (this.stuck>0) this.stuck--;472this.stuck=Math.min(10,this.stuck);473this.targets=[];474}475if ((this.type=='hero' || this.type=='monster') && this.fighting==0 && this.stats.hp<this.stats.hpm) this.stats.hp++;//heal up476if (this.type=='hero')//collect items and cookies477{478var entities=this.dungeon.GetEntities(this.x,this.y);479for (var i in entities)480{481if (entities[i].type=='item' && entities[i].subtype=='cookies')482{483var entity=entities[i];484var value=Math.ceil(entity.value*Game.Objects[this.dungeon.type].amount*50*(1+Math.random()*((this.stats.luck)/20)));//temporary; scale with matching building CpS later485if (value>0)486{487this.dungeon.Log('<span style="color:#9f9;">Found <b>'+Beautify(value)+'</b> cookie'+(value==1?'':'s')+'!</span>');488this.dungeon.cookiesMadeThisRun+=value;489Game.Earn(value);490}491entity.Destroy();492}493}494}495if (this.type=='hero') this.fighting=0;496}497this.Destroy=function()498{499this.dungeon.entities.splice(this.dungeon.entities.indexOf(this),1);500}501this.GetInitiative=function()502{503return randomFloor((this.stats.speed/5)*(1/Math.max(1,(this.dungeon.heroEntity.stats.speed/5))));504}505}506507/*=====================================================================================508DUNGEON MECHANICS509=======================================================================================*/510511Game.Dungeons=[];512Game.Dungeon=function(type,id)513{514this.type=type;515this.id=id;516Game.Dungeons[this.id]=this;517this.log=[];518this.logNew=0;519this.name=Game.DungeonTypes[this.type].nameGenerator();520this.hero=null;521this.currentOpponent=0;522this.level=0;523this.auto=1;524this.portalPic='';525526this.cookiesMadeThisRun=0;527this.monstersKilledThisRun=0;528529this.Log=function(what,nested)530{531if (typeof what==='string')532{533this.log.unshift(what);534this.logNew++;535}536else {for (var i in what) {this.Log(what[i],1);}}537//if (!nested) this.UpdateLog();538}539540this.UpdateLog=function()541{542this.log=this.log.slice(0,30);543var str='';544for (var i in this.log)545{546if (i<this.logNew) str+='<div class="new">'+this.log[i]+'</div>';547else str+='<div>'+this.log[i]+'</div>';548}549this.logNew=0;550l('dungeonLog'+this.id).innerHTML=str;551}552553this.entities=[];554this.GetEntities=function(x,y)//returns the first entity found on tile x,y555{556var entities=[];557for (var i in this.entities) {if (this.entities[i].x==x && this.entities[i].y==y) entities.push(this.entities[i]);}558return entities;559}560this.AddEntity=function(type,subtype,x,y)561{562//this.RemoveEntities(x,y);563var entity=new Game.Entity(type,subtype,this);564entity.x=x;565entity.y=y;566entity.dungeon=this;567this.entities.push(entity);568return entity;569}570this.RemoveEntities=function(x,y)571{572var entities=this.GetEntities(x,y);573for (var i in entities)574{575entities[i].Destroy();576}577}578this.DrawEntities=function()579{580var str='';581for (var i in this.entities) {str+=this.entities[i].Draw();}582return str;583}584585this.CheckObstacle=function(x,y)//returns 0 for no obstacle; -1 for a wall; an entity if there's at least one entity on this tile586{587if (x<0 || x>=this.map.w || y<0 || y>=this.map.h) return -1;588var entities=this.GetEntities(x,y);589for (var i in entities)590{591if (entities[i].obstacle) return entities[i];592}593return this.map.isObstacle(x,y)?-1:0;594}595596597this.map={};598this.Generate=function()599{600if (this.level==0) this.name=Game.DungeonTypes[this.type].nameGenerator();601this.entities=[];602var M=new D.Map(40,40,Math.random(),{603roomSize:10,604corridorSize:5,605fillRatio:1/2,606corridorRatio:0.3,607pillarRatio:Math.random()*0.8+0.2,608waterRatio:Math.random(),609branching:Math.ceil(Math.random()*6),610sizeVariance:0.4611});612r=0;613while (r!=1)614{615r=M.dig();616}617//all done! decorate and render.618M.finish();619//spawn treasure620/*621for (var i in M.rooms)622{623if (M.rooms[i].freeTiles>1)624{625for (var ii=0;ii<Math.ceil(Math.sqrt(M.rooms[i].freeTiles*(M.rooms[i].gen*0.25+0.1))/2);ii++)626{627if (Math.random()<0.95 && M.rooms[i].freeTiles>1)628{629var spot=M.getBestSpotInRoom(M.rooms[i]);630M.data[spot.x][spot.y][0]=0;631spot.score=0;632M.rooms[i].freeTiles--;633}634}635}636}*/637638for (var i in M.doors)//place door entities on door positions639{640//M.data[M.doors[i][0]][M.doors[i][1]][0]=TILE_FLOOR_EDGE;641this.AddEntity('destructible','door',M.doors[i][0],M.doors[i][1]);642}643//set tile graphics644for (var i in M.rooms)645{646var altStr=choose(['alt ','','']);647var tiles={648'void':altStr+'void',649'wall':altStr+'wall',650'wall corner':altStr+'wall corner',651'floor':altStr+'tiled floor',652'floor edges':altStr+'floor',//choose([altStr+'floor',altStr+'floor edges']),653'door':altStr+'door',654'water':choose(['water','green water','dark water']),655'pillar':choose([altStr+'wall',altStr+'round pillar',altStr+'square pillar',altStr+'potted plant','conveyor belt']),656'entrance':altStr+'entrance',657'exit':altStr+'exit',658};659if (Math.random()<0.1) {tiles['wall corner']='wooden wall';tiles['wall']='wooden wall';tiles['floor edges']='wooden floor';tiles['pillar']='wooden wall';}660if (Math.random()<0.1) {tiles['wall corner']=altStr+'bookshelf';tiles['wall']=altStr+'bookshelf';tiles['pillar']=altStr+'bookshelf';}661M.assignTiles(M.rooms[i],tiles);662}663this.map=M;664this.map.str=this.map.getStr();665666//place a boss667var tile=this.map.exit;668var monsters=[];669for (var ii in Game.BossMonsters)670{671var me=Game.BossMonsters[ii];672if (me.level<=(depth+this.level) && Math.random()<(me.stats.rarity||1)) monsters.push(me.name);673}674if (monsters.length==0) monsters=[choose(Game.BossMonsters).name];675if (monsters.length>0)676{677this.AddEntity('monster',choose(monsters),tile[0],tile[1]);678this.map.removeFreeTile(tile[0],tile[1]);679}680681//place relics682/*683var tile=this.map.getBestSpotInRoom(this.map.getRoom(this.map.exit[0],this.map.exit[1]));684var entity=this.AddEntity('special','upgrade',tile.x,tile.y);685entity.value='Dungeon cookie upgrade';686this.map.removeFreeTile(tile.x,tile.y);687for (var i=0;i<Math.floor(Math.pow(Math.random(),2)*3);i++)688{689var room=choose(this.map.rooms);690if (room.freeTiles.length>10)691{692var tile=this.map.getBestSpotInRoom(room);693var entity=this.AddEntity('special','upgrade',tile.x,tile.y);694entity.value='Dungeon cookie upgrade';695this.map.removeFreeTile(tile.x,tile.y);696}697}*/698699//sprinkle monsters and treasure700for (var i=0;i<Math.ceil(this.map.freeTiles.length*0.7);i++)//let's fill this up with A LOT of stuff701{702var tile=choose(this.map.freeTiles);703if (tile!=-1)704{705var room=this.map.getRoom(tile[0],tile[1]);706var depth=room.gen+1;707if (Math.random()<0.2)//2 in 10 spawns are monsters708{709var monsters=[];710for (var ii in Game.Monsters)711{712var me=Game.Monsters[ii];713if (me.level!=0 && me.level<=(depth+this.level) && Math.random()<(me.stats.rarity||1)) monsters.push(me.name);//spawn type depending on monster level and rarity714}715if (monsters.length>0)716{717this.AddEntity('monster',choose(monsters),tile[0],tile[1]);718this.map.removeFreeTile(tile[0],tile[1]);719}720}721else//the rest of the spawns are destructibles or loot722{723if (Math.random()<0.6)724{725var value=Math.round(Math.pow(Math.random(),6)*(10+this.level));726if (value>0)727{728var entity=this.AddEntity('item','cookies',tile[0],tile[1]);//random cookies729entity.value=value;730}731}732else this.AddEntity('destructible','random',tile[0],tile[1]);//random crates etc733this.map.removeFreeTile(tile[0],tile[1]);734}735}736}737}738739this.onTile=-1;740741this.Draw=function()742{743var str='';744var x=-this.hero.x;745var y=-this.hero.y;746str+='<div id="map'+this.id+'" class="map" style="width:'+(9*16)+'px;height:'+(9*16)+'px;"><div class="mapContainer" id="mapcontainer'+this.id+'" style="position:absolute;left:'+(x*16)+'px;top:'+(y*16)+'px;"><div id="mapitems'+this.id+'"></div>'+this.map.str+'</div></div>';747str+='<div style="position:absolute;left:'+(9*16+16)+'px;">'+748'<a class="control west" onclick="Game.HeroesById['+this.hero.id+'].Move(-1,0);"></a><br>'+749'<a class="control east" onclick="Game.HeroesById['+this.hero.id+'].Move(1,0);"></a><br>'+750'<a class="control north" onclick="Game.HeroesById['+this.hero.id+'].Move(0,-1);"></a><br>'+751'<a class="control south" onclick="Game.HeroesById['+this.hero.id+'].Move(0,1);"></a><br>'+752'<a class="control middle" onclick="Game.HeroesById['+this.hero.id+'].Move(0,0);"></a><br>'+753'</div>';754str+='<div style="position:absolute;left:'+(9*16+16+48*3)+'px;bottom:16px;height:100%;">'+755'<div class="dungeonName"><a onclick="Game.ObjectsById['+this.id+'].setSpecial(0);">Exit</a> - <span class="title" style="font-size:12px;">'+this.name+'</span> lvl.'+(this.level+1)+'</div>'+756'<div id="heroSlot'+this.id+'" class="mobSlot"><div id="picHero'+this.id+'" class="mobPic"></div><div id="nameHero'+this.id+'" class="title mobName"></div><div class="hpmBar"><div id="hpHero'+this.id+'" class="hpBar"></div></div></div>'+757'<div id="monsterSlot'+this.id+'" class="mobSlot" style="left:128px;"><div id="picMonster'+this.id+'" class="mobPic"></div><div id="nameMonster'+this.id+'" class="title mobName"></div><div class="hpmBar"><div id="hpMonster'+this.id+'" class="hpBar"></div></div></div>'+758'</div>'+759'<div id="dungeonLog'+this.id+'" class="dungeonLog"></div>';760l('rowSpecial'+this.id).innerHTML='<div style="width:100%;height:100%;z-index:10000;position:absolute;left:0px;top:0px;">'+str+'</div>';761762l('picHero'+this.id).style.backgroundImage='url(img/'+this.hero.portrait+'.png)';763l('nameHero'+this.id).innerHTML=this.hero.name;764}765this.Refresh=function()766{767if (!l('mapcontainer'+this.id)) this.Draw();768var x=4-this.hero.x;769var y=4-this.hero.y;770l('mapcontainer'+this.id).style.left=(x*16)+'px';771l('mapcontainer'+this.id).style.top=(y*16)+'px';772l('mapitems'+this.id).innerHTML=this.DrawEntities();773}774this.RedrawMap=function()775{776this.map.str=this.map.getStr();777this.Draw();778}779this.Turn=function()780{781for (var i in this.entities)782{783if (this.entities[i] && this.entities[i].type) this.entities[i].Turn();784}785if (this.currentOpponent)786{787l('monsterSlot'+this.id).style.visibility='visible';788l('hpMonster'+this.id).style.width=Math.round((this.currentOpponent.stats.hp/this.currentOpponent.stats.hpm)*100)+'%';789l('picMonster'+this.id).style.backgroundImage='url(img/'+Game.Monsters[this.currentOpponent.subtype].pic+'.png)';790l('nameMonster'+this.id).innerHTML=Game.Monsters[this.currentOpponent.subtype].name;791l('picHero'+this.id).style.backgroundImage='url(img/'+this.hero.pic+'.png)';792}793else794{795l('monsterSlot'+this.id).style.visibility='hidden';796l('hpMonster'+this.id).style.width='100%';797l('picHero'+this.id).style.backgroundImage='url(img/'+this.hero.portrait+'.png)';798}799this.currentOpponent=0;800l('hpHero'+this.id).style.width=Math.round((this.heroEntity.stats.hp/this.heroEntity.stats.hpm)*100)+'%';801802this.Refresh();803this.UpdateLog();804805if (this.hero.x==this.map.exit[0] && this.hero.y==this.map.exit[1])806{807this.CompleteLevel();808}809}810811this.DrawButton=function()812{813var str='';814//str+='<div style="text-align:center;margin:48px auto;color:#999;"><a onclick="Game.ObjectsById['+this.id+'].setSpecial(1);">Enter</a></div>';815str+='<div style="width:144px;height:144px;position:absolute;left:0px;bottom:0px;"><a class="specialButtonPic" style="background-image:url(img/'+this.portalPic+'.png);" onclick="Game.ObjectsById['+this.id+'].setSpecial(1);"><div class="specialButtonText">Enter dungeons</div></a></div>';816return str;817}818819this.CompleteLevel=function()820{821this.hero.Say('completion');822this.level++;823this.Generate();824Game.HeroesById[0].EnterDungeon(this,this.map.entrance[0],this.map.entrance[1]);825this.Draw();826}827this.FailLevel=function()828{829this.Log('Cookies made this run : '+Beautify(this.cookiesMadeThisRun)+' | Monsters defeated this run : '+Beautify(this.monstersKilledThisRun));830this.cookiesMadeThisRun=0;831this.monstersKilledThisRun=0;832this.level=0;833this.Generate();834Game.HeroesById[0].EnterDungeon(this,this.map.entrance[0],this.map.entrance[1]);835this.Draw();836}837}838839Game.DungeonLocationChain=function(map,x,y)//return an array of the rooms between the root room and this tile's room, inclusive840{//we shouldn't need all this if we used A*...841var room=map.getRoom(x,y);842var chain=[];843if (room!=-1)844{845while (room.parent)846{847chain.push(room);848room=room.parent;849}850}851chain.reverse();852return chain;853}854Game.DungeonLinkLocationChains=function(start,end)//return the room in which the first location chain should go to to get closer to the second location chain855{856/*8574 cases858-we're already in the same room859-the target is in a different branch860-the target is above in the same branch861-the target is below in the same branch862*/863start.reverse();864end.reverse();865if (start[0].id==end[0].id) return start[start.length-1];//same room866for (var i in end)867{868if (start[0]==end[i].parent) return end[i];//inferior branch, go to the inferior room869}870if (start.length>1) return start[1];//different or superior branch, go to the superior room871return start[0];//eeeh, let's just stay in the same room872}873874/*=====================================================================================875CREATE DUNGEONS876=======================================================================================*/877Game.Objects['Factory'].special=function()878{879this.dungeon=new Game.Dungeon('Factory',this.id);880this.dungeon.Generate();881this.specialDrawFunction=function(){this.dungeon.Refresh();};882this.drawSpecialButton=function(){return this.dungeon.DrawButton();};883this.dungeon.timer=0;884this.dungeon.timerWarmup=5;885this.dungeon.portalPic='dungeonFactory';886887this.EachFrame=function()888{889if (this.dungeon.auto)890{891if (this.dungeon.timer>0) this.dungeon.timer--;892if (this.dungeon.timer==0)893{894this.dungeon.timer=Game.fps*(Math.max(0.1,2-(this.dungeon.hero.stats.speed*0.2))+Math.max(this.dungeon.timerWarmup,0));895if (this.dungeon.timerWarmup>0) this.dungeon.timerWarmup--;896897var dungeon=this.dungeon;898var hero=dungeon.heroEntity;899900var targetRoom=Game.DungeonLinkLocationChains(Game.DungeonLocationChain(dungeon.map,hero.x,hero.y),Game.DungeonLocationChain(dungeon.map,dungeon.map.exit[0],dungeon.map.exit[1]));901var targetTile=(targetRoom.gen==0 || targetRoom.id==dungeon.map.getRoom(hero.x,hero.y).id)?[dungeon.map.exit[0],dungeon.map.exit[1]]:targetRoom.door;902hero.GoTo(targetTile[0],targetTile[1]);903if (hero.stuck) hero.Wander();904dungeon.hero.x=hero.x;905dungeon.hero.y=hero.y;906dungeon.Turn();907}908}909}910911if (document.addEventListener)//clean this up later912{913l('rowSpecial'+this.dungeon.id).removeEventListener('keydown',arguments.callee,false);914l('rowSpecial'+this.dungeon.id).addEventListener('keydown',function(event)915{916var dungeon=Game.Objects['Factory'].dungeon;917var control=0;918if (event.keyCode==37) {dungeon.hero.Move(-1,0);control=1;}919else if (event.keyCode==38) {dungeon.hero.Move(0,-1);control=1;}920else if (event.keyCode==39) {dungeon.hero.Move(1,0);control=1;}921else if (event.keyCode==40) {dungeon.hero.Move(0,1);control=1;}922else if (event.keyCode==32) {dungeon.hero.Move(0,0);control=1;}//space923else if (event.keyCode==65)//A (auto)924{925if (dungeon.auto)926{927dungeon.auto=0;928dungeon.timerWarmup=-1;929}930else931{932dungeon.auto=1;933dungeon.timer=0;934dungeon.timerWarmup=0;935}936event.preventDefault();937}938939if (control)940{941event.preventDefault();942dungeon.timer=Game.fps*10;943dungeon.timerWarmup=5;944}945}946);947}948949var hero=choose(Game.HeroesById);950hero.EnterDungeon(this.dungeon,this.dungeon.map.entrance[0],this.dungeon.map.entrance[1]);951}952953/*=====================================================================================954HEROES955=======================================================================================*/956Game.Heroes=[];957Game.HeroesById=[];958Game.Hero=function(name,pic,portrait,icon)959{960this.name=name;961this.pic=pic;962this.portrait=portrait;963this.icon=icon;964this.stats={965hp:25,966hpm:25,967might:5,968guard:5,969speed:5,970dodge:5,971luck:5972};973this.dialogue={974'greeting':'Oh hey.|Sup.',975'entrance':'Here we go.|So exciting.',976'completion':'That was easy.|All done here.',977'defeat':'Welp.|Better luck next time.'978};979this.gear={980'armor':-1,981'weapon':-1982};983this.inDungeon=-1;984this.completedDungeons=0;985986this.x=0;987this.y=0;988989this.EnterDungeon=function(dungeon,x,y)990{991this.inDungeon=dungeon.id;992dungeon.hero=this;993this.x=x;994this.y=y;995dungeon.heroEntity=dungeon.AddEntity('hero',dungeon.hero.name,x,y);996var room=dungeon.map.getRoom(this.x,this.y);997if (room!=-1 && room.hidden) {room.hidden=0;dungeon.RedrawMap();}998Game.Dungeons[this.inDungeon].Refresh();999dungeon.Log('--------------------');1000if (dungeon.level==0) this.Say('greeting');1001this.Say('entrance');1002l('monsterSlot'+dungeon.id).style.visibility='hidden';1003}1004this.Move=function(x,y)1005{1006var dungeon=Game.Dungeons[this.inDungeon];1007dungeon.heroEntity.targets=[[x,y]];1008if (dungeon.heroEntity.Move())1009{1010this.x=dungeon.heroEntity.x;1011this.y=dungeon.heroEntity.y;1012dungeon.Turn();1013}1014}10151016this.Say=function(what)1017{1018if (this.dialogue[what]) Game.Dungeons[this.inDungeon].Log(this.name+' : "<span style="color:#99f;">'+choose(this.dialogue[what].split('|'))+'</span>"');1019}10201021this.save=function()1022{1023var str='';1024str+=1025this.inDungeon+','+1026this.completedDungeons+','+1027this.gear.armor+','+1028this.gear.weapon1029;1030return str;1031}1032this.load=function(data)1033{1034var str=data.split(',');1035this.inDungeon=parseInt(str[0]);1036this.completedDungeons=parseInt(str[1]);1037this.gear.armor=parseInt(str[2]);1038this.gear.weapon=parseInt(str[3]);1039}1040this.id=Game.HeroesById.length;1041Game.HeroesById.push(this);1042Game.Heroes[this.name]=this;1043}10441045/*=====================================================================================1046CREATE HEROES1047=======================================================================================*/1048var hero=new Game.Hero('Chip','girlscoutChip','portraitChip',[1,0]);1049hero.dialogue={1050'intro':'I\'m Chip! I just really like exploring stuff. Let\'s go have an adventure!',1051'greeting':'Hello there!|I\'m ready!|Where are we going today?|Adventure!',1052'win':'Take that!|Hah!|That\'s right.',1053'entrance':'Chipping in!|Welp, here goes nothing!|I wonder what I\'ll find!|Hey, this place is new!|This place seems familiar.|Let\'s make it happen.',1054'completion':'I\'m one smart cookie.|Oh yeah!|Let\'s explore some more!|That was easy!|That sure was fun!|I\'m not lost, am I?|More exploring? Sure, why not!',1055'defeat':'B-better luck next time.|That really hurt!|I yield! I yield!|That went badly.|No half-baked excuses next time.|I think I scraped my knee!|Owie.|Woopsie!',1056'win against Sentient Furnace':'The irony, it burns! (...it\'s funny because it was burning. And made of iron. ...Moving on.)',1057'win against Ascended Baking Pod':'Where is your pod now?|That was disturbing.'1058};1059hero.stats={1060hp:30,1061hpm:30,1062might:5,1063guard:5,1064speed:5,1065dodge:5,1066luck:51067};1068var hero=new Game.Hero('Crumb','girlscoutCrumb','portraitCrumb',[2,0]);1069hero.dialogue={1070'intro':'I\'m Crumb. I look like this because of a baking accident when I was little. Big deal. At least now I don\'t get hurt as easily as others, I guess.',1071'greeting':'Hi there.|Ready for adventure, I guess.|Reporting for duty.',1072'win':'Oh sorry, did that hurt?|Should have moved out of the way.|Oops. My bad.',1073'entrance':'Let\'s do this, I guess.|Well, let\'s go...|I gotta go in there?|Are we really doing this?|I hope I won\'t get lost like last time.|Let\'s get this over with.',1074'completion':'I... I did it...|I\'m glad that\'s over.|What, there\'s more?|In I go, I guess.|It doesn\'t end, does it?|But it\'s dark in there.',1075'defeat':'I, uh, ouch.|Why does that always happen to me?|I\'m just no good, am I?|Oh no.|I\'m... I\'m not crying.|Well that wasn\'t fun at all.|I\'m sorry I failed you.|Please... make them go away...',1076'meet Ascended Baking Pod':'That thing shouldn\'t even be alive.|Is that where they all came from?',1077'win against Ascended Baking Pod':'Hm. Fascinating.'1078};1079hero.stats={1080hp:25,1081hpm:25,1082might:5,1083guard:7,1084speed:4,1085dodge:4,1086luck:51087};1088var hero=new Game.Hero('Doe','girlscoutDoe','portraitDoe',[3,0]);1089hero.dialogue={1090'intro':'H-hey. Name\'s Doe. I\'m pretty fast. I uh, I promise I\'ll do my best.',1091'greeting':'H-hey.|Oh, uh, h-hi there.|C-can I join?',1092'win':'Th-that looks like it hurt... awesome...|D-did I do that?|N-neat... there\'s pieces everywhere.',1093'entrance':'Alright, let\'s do this!|I-if I really have to.|I-in there? By myself?|...won\'t you come with me this time?|H-here I go!',1094'completion':'Oh... oh my.|That\'s... I uh, I\'m glad.|Y-yeah that was real easy. Piece of pie!|T-too easy, right?|S-so many cookies...|Ooh? F-fascinating.',1095'defeat':'I-if you can\'t beat them... join them.|I-it\'s because I stutter, isn\'t it?|W-well that\'s just no good at all.|I, uh, I meant for that to happen.|H-how embarrassing.',1096'meet Ascended Baking Pod':'W-whoah... it\'s... magnificent...',1097'win against Ascended Baking Pod':'I\'m sorry, buddy.|I... I think I hurt it...|Oh no... I-I think I broke it...'1098};1099hero.stats={1100hp:25,1101hpm:25,1102might:4,1103guard:4,1104speed:7,1105dodge:5,1106luck:51107};1108var hero=new Game.Hero('Lucky','girlscoutLucky','portraitLucky',[4,0]);1109hero.dialogue={1110'intro':'Oh joy! My name\'s Lucky. Guess what I\'m good at?',1111'greeting':'I\'m feeling lucky!|It\'s a bright day today!|Let\'s do great things together.',1112'win':'Ooh lucky shot!|Pow! One more.|Damn straight!',1113'entrance':'Glad to be of service!|Oooh this one\'ll be interesting.|This will be a good one, I can feel it!|Here I come!',1114'completion':'Over already?|Let\'s explore some more!|That was lucky!|That was no luck, I\'m just that good.|Alright, let\'s move on!|I\'m just getting warmed up!',1115'defeat':'I can\'t believe it!|...This is a joke, right?|Hey! No fair!|B-but...|I\'m gonna need a bandaid. And some hot chocolate.|I\'ll, uh, try again later.|Bad luck! Bad luck!',1116'win against Ascended Baking Pod':'Golly, that was peculiar.'1117};1118hero.stats={1119hp:25,1120hpm:25,1121might:5,1122guard:4,1123speed:4,1124dodge:5,1125luck:71126};11271128};112911301131