//// Random_Scrolls.js//// Require: Random_Spells.js//// Class ScrollGen(aSpellType, aTreasureType, aFrRate)//   aSpellType : "arcane" or "divine"//   aTreasureType : "minor", "medium", or "major"//   aFrRate : 0-100; no FRCS spells if 0// Method//   toString() : for debug//   genScroll() : generate Scroll object//// Class Scroll(aSpellType, anArySpells)//   aSpellType : "arcane" or "divine"//   anArySpells : a Spell Array// Method//   toString() : for debug//   getPrice() : price of scroll//   toDisp() : formatted string for display; "Type: description (xxx gp)"//// Probability for FR spells based on FRCS p.301//   minor  : (82-65)/(82-47) = 49%//   medium : (67-59)/(67-51) = 50%//   major  : (56-51)/(56-46) = 50%////function ScrollGen(aSpellType, aTreasureType, aFrRate) {  this.spellType = aSpellType; // "arcane" or "divine"  this.treasureType = aTreasureType; // "minor", "medium", or "major"  this.frRate = aFrRate; // "core" or "FR"  //debugln("treasureType="+this.treasureType);  //debugln("this.fNumSpell[this.treasureType]="+this.fNumSpell[this.treasureType]);}ScrollGen.prototype.toString = function() {  return "ScrollGen("  + "Type="+this.spellType+","+this.treasureType+","+this.rule  + ")";}ScrollGen.prototype.fNumSpell = {minor:D3, medium:D4, major:D6};ScrollGen.prototype.SplLv = {  minor: new RT(D100, [    new RTE(5, 0), new RTE(50, 1), new RTE(95, 2), new RTE(100, 3)    ]),  medium: new RT(D100, [    new RTE(5, 2), new RTE(65, 3), new RTE(95, 4), new RTE(100, 5)    ]),  major: new RT(D100, [    new RTE(5, 4), new RTE(50, 5), new RTE(70, 6), new RTE(85, 7), new RTE(95, 8), new RTE(100, 9)	])};ScrollGen.prototype.genScroll = function() {  var numSpell = getValue(this.fNumSpell[this.treasureType]);  var splLvs = new Array(numSpell);  var spells = new Array(numSpell);  for(var i=0;i<numSpell;i++) {    var lv = this.SplLv[this.treasureType].getValue();	debugln("lv="+lv);    splLvs[i] = lv;	// core rule spell	var tbl = this.randomTable[this.spellType];	var p = D100();	debugln("p="+p);    if (p<=this.frRate) {	  // FRCS spell	  tbl = this.randomFrTable[this.spellType];	}    var spell = tbl[lv].getValue();	debugln("spell="+spell);    spells[i] = spell;  }  var scr = new Scroll(this.spellType, spells, splLvs);  return scr;}ScrollGen.prototype.randomFrTable = {  arcane: [    // 0-Lv	new CH([	  // From FRCS & MoF	  "acid splash", "electric jolt", "Horizikaul\'s cough", "silent portal", "launch bolt"	]),    // 1-Lv	new CH([	  // From FRCS & MoF	  "iron guts", "corrosive grasp", "summon undead I", "know protections", "Nybor\'s gentle reminder",	  "forcewave", "Horizikaul\'s boom", "ice dagger", "Sheigarn\'s persistent blade",	  "net of shadows", "spirit worm", "Kaupaer\'s skittish nerves", "Laeral\'s cutting hand",	  "launch item", "low-light vision", "scatterspray", "speed swim"	]),    // 2-Lv	new CH([	  // From FRCS &MoF	  "create magic tatoo", "Igedrazaa\'s miasma", "summon monster II", "Aganazzar\'s scorcher",	  "battering ram", "cloud of bewilderment", "combust", "flame dagger", "force ladder",	  "Gedlee\'s electrip loop", "Snilloc\'s snowball swarm", "claws of darkness",	  "disguise undead", "shadow mask", "shadow spray", "death armor", "life bolt",	  "shroud of undeath", "Balagarn\'s iron horn", "scent", "stone bones"	]),    // 3-Lv	new CH([	  "reverse arrows", "Mestil\'s acid breath", "summon undead III", "analyze portal",	  "Nybor\'s mild admonishment", "blacklight", "flashburst", "scintillating sphere",	  "shatterfloor", "steeldance", "Khelben\'s suspended silence", "healing touch",	  "spider pioson", "undead lieutenant", "undead torch", "amanuensis", "blindsight",	  "greater mage hand", "weapon of impact"	]),    null	  ],  divine: [    null  ]};ScrollGen.prototype.randomTable = {  arcane: [    // 0-Lv    new RT(D100, [	  new RTE(4, "acid splash"),	  new RTE(8, "arcane mark"),	  new RTE(13, "dancing light"),	  new RTE(17, "daze"),	  new RTE(24, "detect magic"),	  new RTE(28, "detect poison"),	  new RTE(32, "disrupt undead"),	  new RTE(37, "flare"),	  new RTE(42, "ghost sound"),	  new RTE(44, "know direction"),	  new RTE(50, "light"),	  new RTE(52, "lullaby"),	  new RTE(57, "mage hand"),	  new RTE(62, "mage hand"),	  new RTE(67, "mending"),	  new RTE(72, "open/close"),	  new RTE(77, "prestigitation"),	  new RTE(81, "ray of frost"),	  new RTE(87, "read magic"),	  new RTE(94, "resistance"),	  new RTE(96, "summon instruments"),	  new RTE(100, "touch of fatigue")	]),    // 1-Lv    new RT(D100, [	  new RTE( 3, "alarm"),	  new RTE( 5, "animate rope"),	  new RTE( 7, "burning hands"),	  new RTE( 9, "cause fear"),	  new RTE(12, "charm person"),	  new RTE(14, "chill touch"),	  new RTE(16, "color splay"),	  new RTE(19, "comprehend languages"),	  new RTE(20, "confusion, lesser"),	  new RTE(21, "cure light wounds"),	  new RTE(24, "detect secret doors"),	  new RTE(26, "detect undead"),	  new RTE(29, "disguise self"),	  new RTE(32, "endure elements"),	  new RTE(35, "enlarge person"),	  new RTE(37, "erase"),	  new RTE(40, "expeditious retreat"),	  new RTE(41, "feather fall"),	  new RTE(43, "grease"),	  new RTE(45, "hold portal"),	  new RTE(47, "hypnotism"),	  new RTE(49, "identify"),	  new RTE(51, "jump"),	  new RTE(54, "mage armor"),	  new RTE(56, "magic missile"),	  new RTE(59, "magic weapon"),	  new RTE(62, "mount"),	  new RTE(64, "Nystul\'s magic aura"),	  new RTE(66, "obscuring mist"),	  new RTE(74, "protection from chaos/evil/good/law"),	  new RTE(76, "ray of enfeeblement"),	  new RTE(78, "reduce person"),	  new RTE(80, "remove fear"),	  new RTE(82, "shield"),	  new RTE(84, "shocking grasp"),	  new RTE(86, "silent image"),	  new RTE(88, "sleep"),	  new RTE(90, "summon monster I"),	  new RTE(93, "Tenser\'s floating disk"),	  new RTE(95, "true strike"),	  new RTE(96, "undetectable alignment"),	  new RTE(98, "unseen servant"),	  new RTE(100,"ventriloquism")	]),	new RT(D100, [	  new RTE( 1, "animal messanger"),	  new RTE( 2, "animal trance"),	  new RTE( 3, "arcane lock"),	  new RTE( 6, "bear\'s endurance"),	  new RTE( 8, "blindness/deafness"),	  new RTE(10, "blur"),	  new RTE(13, "bull\'s strength"),	  new RTE(14, "calm emotion"),	  new RTE(17, "cat\'s grace"),	  new RTE(19, "command undead"),	  new RTE(20, "continual flame"),	  new RTE(21, "cure moderate wounds"),	  new RTE(22, "darkness"),	  new RTE(25, "darkvision"),	  new RTE(26, "daze monster"),	  new RTE(27, "delay poison"),	  new RTE(29, "detect thoughts"),	  new RTE(31, "disguise self"),	  new RTE(34, "eagle\'s splendor"),	  new RTE(35, "enthrall"),	  new RTE(37, "false life"),	  new RTE(39, "flaming sphere"),	  new RTE(40, "fog cloud"),	  new RTE(43, "fox\'s cunning"),	  new RTE(44, "ghoul touch"),	  new RTE(46, "glitterdust"),	  new RTE(47, "gust of wind"),	  new RTE(49, "hypnotic pattern"),	  new RTE(52, "invisibility"),	  new RTE(55, "knock"),	  new RTE(56, "Leomund\'s trap"),	  new RTE(58, "levitate"),	  new RTE(59, "locate object"),	  new RTE(60, "magic mouth"),	  new RTE(62, "Melf\'s acid arrow"),	  new RTE(63, "minor image"),	  new RTE(65, "mirror image"),	  new RTE(66, "misdirection"),	  new RTE(67, "owl\'s wisdom"),	  new RTE(73, "protection from arrows"),	  new RTE(75, "pyrotechnics"),	  new RTE(78, "resist energy"),	  new RTE(79, "rope trick"),	  new RTE(80, "scare"),	  new RTE(82, "scorching ray"),	  new RTE(85, "see invisibility"),	  new RTE(86, "shatter"),	  new RTE(87, "silence"),	  new RTE(88, "sound burst"),	  new RTE(89, "spectral hand"),	  new RTE(91, "spider climb"),	  new RTE(93, "summon monster II"),	  new RTE(95, "summon swarm"),	  new RTE(96, "Tasha\'s hideous laughter"),	  new RTE(97, "touch of idiocy"),	  new RTE(99, "web"),	  new RTE(100,"whispering wind")	]),	new RT(D100, [	  new RTE( 2, "arcane sight"),	  new RTE( 4, "blink"),	  new RTE( 6, "clairaudience/clairvoyance"),	  new RTE( 7, "cure serious wounds"),	  new RTE(10, "daylight"),	  new RTE(12, "deep slumber"),	  new RTE(15, "dispel magic"),	  new RTE(17, "displacement"),	  new RTE(18, "explosive runes"),	  new RTE(20, "fireball"),	  new RTE(22, "flame arrow"),	  new RTE(25, "fly"),	  new RTE(27, "gaseous form"),	  new RTE(29, "gentle repose"),	  new RTE(30, "glibness"),	  new RTE(31, "good hope"),	  new RTE(33, "halt undead"),	  new RTE(36, "haste"),	  new RTE(38, "heroism"),	  new RTE(40, "hold person"),	  new RTE(41, "illusiory script"),	  new RTE(44, "invisibility sphere"),	  new RTE(47, "keen edge"),	  new RTE(49, "Leomund\'s tiny hut"),	  new RTE(51, "lightning bolt"),	  new RTE(59, "magic circle against chaos/evil/good/law"),	  new RTE(62, "magic weapon, greater"),	  new RTE(64, "major image"),	  new RTE(66, "nondetection"),	  new RTE(68, "phantom steed"),	  new RTE(71, "protection from energy"),	  new RTE(73, "rage"),	  new RTE(75, "ray of exhausion"),	  new RTE(76, "sculpt sound"),	  new RTE(77, "secret page"),	  new RTE(78, "sepia snake sigil"),	  new RTE(79, "shrink item"),	  new RTE(81, "sleet storm"),	  new RTE(83, "slow"),	  new RTE(84, "speek with animals"),	  new RTE(86, "stinking cloud"),	  new RTE(88, "suggestion"),	  new RTE(90, "summon monster III"),	  new RTE(93, "tongues"),	  new RTE(95, "vampilic touch"),	  new RTE(98, "water breathing"),	  new RTE(100,"wind wall")	]),	null  ],  divine: [    new RTE(D100, [	  new RTE(100, "[0Lv spell]")	]),    new RTE(D100, [	  new RTE(100, "[1Lv spell]")	]),    new RTE(D100, [	  new RTE(100, "[2Lv spell]")	]),    new RTE(D100, [	  new RTE(100, "[3Lv spell]")	]),    null  ]};//function Scroll(aSpellType, anArySpells, anArySpellLvs) {  this.spellType = aSpellType; // "arcane" or "divine"  this.arySpells = anArySpells; // Array of Spell;  this.arySpellLvs = anArySpellLvs; // Array of Spell Level;}Scroll.prototype.toString = function() {  return "Scroll("  + "Type="+this.spellType  + " Spells="+this.arySpells  + " SpellLvs="+this.arySpellLvs  + ")";}Scroll.prototype.getPrice = function() {  var priceSum = 0;  if (this.arySpells==null || this.arySpells.length==0) {return 0;}  for(var i=0;i<this.arySpells.length;i++) {    var pList = this.priceList[this.spellType];	if (pList.hasOwnProperty(this.arySpells[i])) {	  priceSum += pList[this.arySpells[i]];	} else {      priceSum += this.scrollPrice[this.arySpellLvs[i]];	}  }  return priceSum;}Scroll.prototype.scrollPrice = [12.5, 25, 150, 375, 700, 1125, 1650, 2275, 3000, 3825];Scroll.prototype.priceList = new Array();Scroll.prototype.priceList["arcane"] = {  "confusion, lesser": 50,  "cure light wounds": 50,  "identify": 125,  "remove fear": 50,  "undetectable alignment": 50,  "animal messanger": 200,  "animal trance": 200,  "arcane lock": 175,  "calm emotion": 200,  "continual flame": 200,  "cure moderate wounds": 200,  "delay poison": 200,  "enthrall": 200,  "Leomund\'s trap": 200,  "magic mouth": 160,  "silence": 200,  "sound burst": 200,  "cure serious wounds": 525,  "daylight": 525,  "glibness": 525,  "good hope": 525,  "illusiory script": 425,  "nondetection": 425,  "sculpt sound": 525,  "sepia snake sigil": 875,  "speek with animals": 525};Scroll.prototype.toItalic = function(s) {  return "<i>"+s+"</i>";}Scroll.prototype.toDisp = function() {  var str = "";  switch(this.spellType) {    case "arcane": str="Arcane Scroll: "; break;    case "divine": str="Divine Scroll: "; break;	default: str=this.spellType+" Scroll: "; break;  }  if (this.arySpells.length==1) {    str += ( "<i>"+this.arySpells[0]+"</i> ("+this.arySpellLvs[0]+"Lv)" );  } else {    for(var i=0;i<this.arySpells.length-1;i++) {	  str += ( "<i>"+this.arySpells[i]+"</i> ("+this.arySpellLvs[i]+"Lv), " );	}	var i = this.arySpells.length-1;	str += ( "<i>"+this.arySpells[i]+"</i> ("+this.arySpellLvs[i]+"Lv); " );  }  //str += opAry(this.arySpells, this.toItalic, ", ") +" ";  str += "("+this.getPrice()+" gp)";  return str;}