MediaWiki:BreedingCalculator.js

 

contentSection = ""; contentSections = ["content_breedingdragons"];

function onLoadHandler {	setMenuOptions; }

function setMenuOptions {	var menu1 = document.getElementById("breeddragons_dragon1choices"); var menu2 = document.getElementById("breeddragons_dragon2choices"); for (var i = 0; i < dragon_names.length; i++) {		var dragonName = dragon_names[i].substring(0, 1).toUpperCase + dragon_names[i].substring(1, dragon_names[i].length).toLowerCase; var newOption1 = document.createElement("option"); newOption1.text = dragonName; menu1.add(newOption1); var newOption2 = document.createElement("option"); newOption2.text = dragonName; menu2.add(newOption2); } }

function printText(text) {  var newNode = document.createElement("p"); newNode.innerHTML = text; document.getElementById(contentSection).appendChild(newNode); }

function clearTextField(name) {  document.getElementById(name).value = ""; }

function clearContentField(name) {	var contentField = document.getElementById(name); while (contentField.hasChildNodes) {		contentField.removeChild(contentField.firstChild); } }

function getMergedList(list1, list2) {		var data = ""; for (var i = 0; i < list1.length; i++) {		data += data == "" ? list1[i] : "_" + list1[i]; }

for (var i = 0; i < list2.length; i++) {		if (!(data.indexOf("_" + list2[i] + "_") > -1 || data.indexOf(list2[i] + "_") == 0 || data.indexOf("_" + list2[i]) + list2[i].length + 1 == data.length)) {			data += "_" + list2[i]; }	}	return data.split("_"); }

function breedButtonClicked {	getBreedingOutcome; }

function getBreedingOutcome {		contentSection = "content_breeddragons"; clearContentField(contentSection); var menu1 = document.getElementById("breeddragons_dragon1choices"); var menu2 = document.getElementById("breeddragons_dragon2choices"); var dragon1Name = menu1.options[menu1.selectedIndex].text; var dragon2Name = menu2.options[menu2.selectedIndex].text; printText("Breeding " + dragon1Name + " with " + dragon2Name + " can result in: "); var possible_offspring = buildBreedListByRules(dragon1Name, dragon2Name); var formattedText = ""; for (var i = 0; i < possible_offspring.length; i++) {		formattedText += ((formattedText == "" ? "" : " ") + "" + possible_offspring[i] + " Dragon"); var colors = dragon_data[possible_offspring[i].toLowerCase].colors; for (var j = 0; j < colors.length; j++) {			formattedText += " "; }		formattedText += " "; //printText("" + possible_offspring[i] + " Dragon (" + dragon_data[possible_offspring[i].toLowerCase].colors + ")"); }		printText(formattedText); }

function buildBreedListByRules(dragon1Name, dragon2Name) {	var possible_offspring = new Array; var dragon1Type = dragon_data[dragon1Name.toLowerCase].breedtype; var dragon2Type = dragon_data[dragon2Name.toLowerCase].breedtype; var dragon1Colors = dragon_data[dragon1Name.toLowerCase].colors; var dragon2Colors = dragon_data[dragon2Name.toLowerCase].colors; var rules = ""; if (dragon1Type.indexOf("special") > -1 || dragon2Type.indexOf("special") > -1) {		rules = "special"; }	else if (dragon1Type == "basic" && dragon2Type == "basic") {		if (dragon1Colors[0] == dragon2Colors[0]) {			rules = "basic"; }		else {			rules = "hybrid"; }	}	else if (dragon1Type == "hybrid" || dragon2Type == "hybrid") {		rules = "hybrid"; }	if (rules == "hybrid") {		possible_offspring = getValidHybridOutcomes(dragon1Colors, dragon2Colors, true); }	else if (rules == "basic") {		possible_offspring.push(dragon1Name); }	else if (rules == "special") {		if (dragon1Type == "special_diamond" || dragon2Type == "special_diamond") {			if ((dragon1Type == dragon2Type) && dragon1Colors.length == 1 && dragon2Colors.length == 1) {				for (var i = 0; i < pure_outcomes.length; i++) {					var name = pure_outcomes[i].substring(0, 1).toUpperCase + pure_outcomes[i].substring(1, pure_outcomes[i].length).toLowerCase; possible_offspring.push(name); }			}			else {					var colorPool = getMergedList(dragon1Colors, dragon2Colors); if (colorPool.length > 2) {					possible_offspring = getValidHybridOutcomes(dragon1Colors, dragon2Colors, true); }				else {					possible_offspring = getMergedList(getValidBasicOutcomes(colorPool), getValidHybridOutcomes(dragon1Colors, dragon2Colors, false)); }			}		}	}	return possible_offspring; }

function getValidBasicOutcomes(colorPool) {	var possible_offspring = new Array; var basicColors = new Array; for (var i = 0; i < colorPool.length; i++) {		if (!(colorPool[i] == "diamond")) {			basicColors.push(colorPool[i]); }	}	for (var i = 0; i < basicColors.length; i++) {		for (var j = 0; j < pure_outcomes.length; j++) {			if (basicColors[i] == dragon_data[pure_outcomes[j]].colors[0]) {				var name = pure_outcomes[j].substring(0, 1).toUpperCase + pure_outcomes[j].substring(1, pure_outcomes[j].length).toLowerCase; possible_offspring.push(name); break; }		}	}		return possible_offspring; }

function getValidHybridOutcomes(dragon1Colors, dragon2Colors, considerDiamond) {	var possible_offspring = new Array; var colorPool = getMergedList(dragon1Colors, dragon2Colors);

for (var i = 0; i < hybrid_outcomes.length; i++) {				if (comboContainsColors(colorPool, dragon_data[hybrid_outcomes[i]].requiredcolors)) {			var name = hybrid_outcomes[i].substring(0, 1).toUpperCase + hybrid_outcomes[i].substring(1, hybrid_outcomes[i].length).toLowerCase; possible_offspring.push(name); }	}	if (considerDiamond && colorPool.length >= 4) {		for (var j = 0; j < diamond_outcomes.length; j++) {			var name = diamond_outcomes[j].substring(0, 1).toUpperCase + diamond_outcomes[j].substring(1, diamond_outcomes[j].length).toLowerCase; possible_offspring.push(name); }	}	return possible_offspring; }

function comboContainsColors(colorList, requiredColors) {	for (var i = 0; i < requiredColors.length; i++) {		var found = false; for (var j = 0; j < colorList.length; j++) {			if (colorList[j] == requiredColors[i]) {				found = true; break; }		}		if (!found) {			return false; }	}	return true; }

dragon_data = { air: { colors: ["yellow"], breedtype: "basic" },	athletic: { colors: ["red", "blue"], breedtype: "hybrid", requiredcolors: ["red", "blue"] },	atlantis: { colors: ["blue", "green"], breedtype: "hybrid", requiredcolors: ["blue", "green"] },	charm: { colors: ["red", "purple"], breedtype: "hybrid", requiredcolors: ["red", "purple"] },	coral: { colors: ["blue", "purple"], breedtype: "hybrid", requiredcolors: ["blue", "purple"] },	crusader: { colors: ["diamond", "red"], breedtype: "special_diamond", requiredcolors: ["diamond", "red"] },	diamond: { colors: ["diamond"], breedtype: "special_diamond", },	eagle: { colors: ["yellow", "red"], breedtype: "hybrid", requiredcolors: ["yellow", "red"] },	fairy: { colors: ["green", "yellow"], breedtype: "hybrid", requiredcolors: ["green", "yellow"] },	familiar: { colors: ["green", "purple"], breedtype: "hybrid", requiredcolors: ["green", "purple"] },	fire: { colors: ["red"], breedtype: "basic" },	firestorm: { colors: ["red", "yellow"], breedtype: "hybrid", requiredcolors: ["red", "yellow"] },	forest: { colors: ["green"], breedtype: "basic" },		forestfire: { colors: ["red", "green"], breedtype: "hybrid", requiredcolors: ["red", "green"] },	fruitful: { colors: ["green", "yellow"], breedtype: "hybrid", requiredcolors: ["green", "yellow"] },	genie: { colors: ["yellow", "purple"], breedtype: "hybrid", requiredcolors: ["yellow", "purple"] },	gold: { colors: ["diamond", "yellow"], breedtype: "special_diamond", requiredcolors: ["diamond", "yellow"] },		infinity: { colors: ["diamond"], breedtype: "special_diamond", },	island: { colors: ["blue", "green"], breedtype: "hybrid", requiredcolors: ["blue", "green"] },	life: { colors: ["green", "red"], breedtype: "hybrid", requiredcolors: ["green", "red"] },	magic: { colors: ["purple"], breedtype: "basic", requiredcolors: ["red", "blue"] },	mindvolt: { colors: ["yellow", "blue"], breedtype: "hybrid", requiredcolors: ["yellow", "blue"] },	mist: { colors: ["blue", "yellow"], breedtype: "hybrid", requiredcolors: ["blue", "yellow"] },	mistmoth: { colors: ["blue", "purple"], breedtype: "hybrid", requiredcolors: ["blue", "purple"] },	parakeet: { colors: ["yellow", "green"], breedtype: "hybrid", requiredcolors: ["yellow", "green"] },	planet: { colors: ["red", "purple"], breedtype: "hybrid", requiredcolors: ["red", "purple"] },	poison: { colors: ["green", "purple"], breedtype: "hybrid", requiredcolors: ["green", "purple"] },	quetzal: { colors: ["diamond", "green"], breedtype: "special_diamond", requiredcolors: ["diamond", "green"] },	scorpion: { colors: ["red", "yellow"], breedtype: "hybrid", requiredcolors: ["red", "yellow"] },	seabreeze: { colors: ["yellow", "blue"], breedtype: "hybrid", requiredcolors: ["yellow", "blue"] },	serpent: { colors: ["blue", "green"], breedtype: "hybrid", requiredcolors: ["blue", "green"] },	titan: { colors: ["red", "purple"], breedtype: "hybrid", requiredcolors: ["red", "purple"] },	trickster: { colors: ["purple", "yellow"], breedtype: "hybrid", requiredcolors: ["purple", "yellow"] },		water: { colors: ["blue"], breedtype: "basic" },		wild: { colors: ["green", "red"], breedtype: "hybrid", requiredcolors: ["green", "red"] },	wizard: { colors: ["blue", "purple"], breedtype: "hybrid", requiredcolors: ["blue", "purple"] },	end: { } };

dragon_names = ["air", "athletic", "atlantis", "charm", "coral", "crusader", "diamond", "eagle", "fairy", "familiar", "fire", "firestorm", "forest", "forestfire", "fruitful", "genie", "gold", "infinity", "island", "life", "magic", "mindvolt", "mist", "mistmoth", "parakeet", "planet", "poison", "quetzal", "scorpion", "seabreeze", "serpent", "titan", "trickster", "water", "wild", "wizard"]; pure_outcomes = ["air", "fire", "forest", "water", "magic"];

hybrid_outcomes = ["athletic", "atlantis", "charm", "coral", "crusader", "eagle", "fairy", "familiar", "firestorm", "forestfire", "fruitful", "genie", "gold", "island", "life", "magic", "mindvolt", "mist", "mistmoth", "parakeet", "planet", "poison", "quetzal", "scorpion", "seabreeze", "serpent", "titan", "trickster", "wild", "wizard"]; diamond_outcomes = ["diamond", "infinity"];



 

 