MediaWiki:Javascript-ungames-TestGame.js/database.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes.

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
var ABILITY_DATABASE = {
	// Should be kept blank
	none: new Ability({}),
	// Abilities
/*%fold%*/	sturdy: new Ability({
		// The sturdy ability will keep a creature safe from dying if it is on full health
		getRealDamage: (damage, creature) => {
			if (creature.maxHealth === creature.health) {
				if (damage.amount >= creature.health) {
					creature.sturdyAbilityEnduredHit = true;
					return creature.health - 1;
				}
			}
		},
		afterGettingHit: async (damage, creature, attacker) => {
			if (creature.sturdyAbilityEnduredHit) {
				await showDialogue(`${creature.isPlayerControlled ? "Your " : creature.isAlly ? "Your allied " : "The opposing "}${creature.name} endured the hit!`, 2700, 10);
				delete creature.sturdyAbilityEnduredHit;
			}
		}
	}),
/*%fold%*/	storyEating: new Ability({
		// The story eating ability makes it take less damage from attacks which would kill it, and take almost no damage from attacks which wouldn't
		getRealDamage: (damage, creature) => {
			if (damage.amount > creature.health) {
				creature.storyEatingAbilityMode = 1;
				return Math.ceil(damage.amount / 7);
			} else {
				creature.storyEatingAbilityMode = 2;
				return Math.ceil(damage.amount / 25);
			}
		},
		afterGettingHit: async (damage, creature, attacker) => {
			if (damage.attack.damageType === Attack.DamageTypeStatus) {
				delete creature.storyEatingAbilityMode;
				return;
			}
			await showDialogue(`${creature.isPlayerControlled ? "Your " : creature.isAlly ? "Your allied " : "The opposing "}${creature.name} ate the attack, and took ${creature.storyEatingAbilityMode === 1 ? "" : "significantly"} less damage!`, 2700, 10);
			delete creature.storyEatingAbilityMode;
		}
	}),
};


var ATTACK_DATABASE = {
/*%fold%*/	scratch: new Attack({
		name: "Scratch",
		description: "The user scratches the target with claws, dealing a small amount of damage.",
		damage: 30,
		accuracy: 100,
		priority: 1,
		damageType: Attack.DamageTypePhysical,
		getAttackWantPriority: (thisCreature) => {
			return 30
		}
	}),
/*%fold%*/	agility: new Attack({
		name: "Agility",
		description: "The user increases their agility, increasing their evasiveness.",
		damage: 0,
		accuracy: 0,
		priority: 1,
		targetSelf: true,
		damageType: Attack.DamageTypeStatus,
		onHitTarget: async (damage, target, attacker) => {
			await attacker.buffStat("dodge", 1);
		},
		getAttackWantPriority: (thisCreature) => {
			return thisCreature.getStatValue("dodge") < 5 ? [70,70,65,65,60,55,50,45,35,25,10][thisCreature.getStatValue("dodge") + 5] / 2 : -100
		}
	}),
	growlIntimidating: new Attack({
		name: "Intimidating Growl",
		description: "The user emits an intimidating growl towards the target, slightly lowering their attack.",
		damage: 0,
		accuracy: 100,
		priority: 1,
		damageType: Attack.DamageTypeStatus,
		onHitTarget: async (damage, target, attacker) => {
			await target.debuffStat("attack", 1);
		},
		getAttackWantPriority: (thisCreature) => {
			if (thisCreature.AIInteligence < 3 && Math.random() > 0.7) return -100;
			
			// Don't use the attack if low on health
			if (thisCreature.AIInteligence > 4 && thisCreature.health < thisCreature.maxHealth * 0.6 && Math.random() > 0.2) return -100;
			if (thisCreature.AIInteligence > 2 && thisCreature.health < thisCreature.maxHealth * 0.4 && Math.random() > 0.7) return -100;
			
			return thisCreature.targetCreature.getStatValue("attack") > -5 ? [5,8,10,15,25,45,50,65,70,80,90][thisCreature.targetCreature.getStatValue("attack") + 5] : -100
		}
	}),
	growlCute: new Attack({
		name: "Cute Growl",
		description: "The user emits a cute growl towards the target, slightly lowering their defence.",
		damage: 0,
		accuracy: 100,
		priority: 1,
		damageType: Attack.DamageTypeStatus,
		onHitTarget: async (damage, target, attacker) => {
			await target.debuffStat("defence", 1);
		},
		getAttackWantPriority: (thisCreature) => {
			if (thisCreature.AIInteligence < 3 && Math.random() > 0.7) return -100;
			
			// Don't use the attack if low on health
			if (thisCreature.AIInteligence > 4 && thisCreature.health < thisCreature.maxHealth * 0.6 && Math.random() > 0.2) return -100;
			if (thisCreature.AIInteligence > 2 && thisCreature.health < thisCreature.maxHealth * 0.4 && Math.random() > 0.7) return -100;
			
			return thisCreature.targetCreature.getStatValue("defence") > -5 ? [5,8,10,15,25,45,50,65,70,80,90][thisCreature.targetCreature.getStatValue("defence") + 5] : -100
		}
	}),
/*%fold%*/	headbutt: new Attack({
		name: "Headbutt",
		description: "Hit the target with a hard head, dealing a small amount of damage. Critical hits are slightly easier to land.",
		damage: 30,
		accuracy: 100,
		priority: 1,
		criticalChance: 9,
		damageType: Attack.DamageTypePhysical,
		getAttackWantPriority: (thisCreature) => {
			return 32
		}
	}),
/*%fold%*/	huff: new Attack({
		name: "Huff",
		description: "Huff this creaure and buff the next creature which comes out.",
		damage: 0,
		accuracy: 0,
		priority: 1,
		targetSelf: true,
		damageType: Attack.DamageTypeStatus,
		onUsed: async (thisCreature) => {
			thisCreature.takeRawDamage(thisCreature.health);
			await showDialogue(`${thisCreature.isPlayerControlled ? "Your " : thisCreature.isAlly ? "Your allied " : "The opposing "}${thisCreature.name} was huffed to strengthen an ally!`, 2500, 500);
			
			thisCreature.onSwitchedOut = async (newCreature) => {
				newCreature.changeStat("attack", 1 + thisCreature.getStatValue("attack"));
				newCreature.changeStat("spAttack", 1 + thisCreature.getStatValue("spAttack"));
				newCreature.changeStat("defence", 1 + thisCreature.getStatValue("defence"));
				newCreature.changeStat("spDefence", 1 + thisCreature.getStatValue("spDefence"));
				newCreature.changeStat("speed", 1 + thisCreature.getStatValue("speed"));
				newCreature.changeStat("accuracy", thisCreature.getStatValue("accuracy"));
				newCreature.changeStat("dodge", thisCreature.getStatValue("dodge"));
				await showDialogue(`${thisCreature.isPlayerControlled ? "Your " : thisCreature.isAlly ? "Your allied " : "The opposing "}${newCreature.name}'s stats rose!`, 2500, 500);
			}
		},
		getAttackWantPriority: (thisCreature) => {
			return thisCreature.health < thisCreature.maxHealth ? 150 : 60
		}
	}),
};


var CREATURE_DATABASE = {
/*%fold%*/	"orangeKitten": {
		name: "Orange Kitten",
		description: "The orange ones fuck you up REAL good.",
		ability: ABILITY_DATABASE.none,
		image: "https://images.uncyclomedia.co/uncyclopedia/en/3/38/Orange_kitten-transparent.png",
		stats: {
			health: 6,
			attack: 3,
			defence: 4,
			spAttack: 3,
			spDefence: 2,
			speed: 3
		},
		defaultAttackChooser: defaultAttackChooser_random,
		attacks: [
			ATTACK_DATABASE.scratch,
			ATTACK_DATABASE.agility,
			ATTACK_DATABASE.growlCute,
			ATTACK_DATABASE.huff,
		]
	},
/*%fold%*/	"moccasin": {
		name: "MOCCASIN",
		description: "MOCCASINS MOCCASINS MOCCASINS MOCCASINS MOCCASINS",
		ability: ABILITY_DATABASE.none,
		image: "https://images.uncyclomedia.co/uncyclopedia/en/f/f1/Moccasin_creature.png",
		stats: {
			health: 7,
			attack: 4,
			defence: 3,
			spAttack: 3,
			spDefence: 5,
			speed: 4
		},
		defaultAttackChooser: defaultAttackChooser_random,
		attacks: [
			ATTACK_DATABASE.headbutt,
			ATTACK_DATABASE.growlIntimidating,
		]
	},
/*%fold%*/	"nikoOneshot": {
		name: "Niko Oneshot",
		description: "",
		image: "https://images.uncyclomedia.co/uncyclopedia/en/4/49/Niko_oneshot.png",
		ability: ABILITY_DATABASE.none,
		stats: {
			health: 6,
			attack: 2,
			defence: 3,
			spAttack: 2,
			spDefence: 3,
			speed: 5
		},
		defaultAttackChooser: defaultAttackChooser_random,
		attacks: [
			ATTACK_DATABASE.scratch,
		]
	},
/*%fold%*/	"storyEatingCat": {
		name: "Story-Eating Cat",
		description: "Eater of stories, will eat everything. Including your face.",
		image: "https://images.uncyclomedia.co/uncyclopedia/en/7/7e/Eating.gif",
		ability: ABILITY_DATABASE.storyEating,
		stats: {
			health: 8,
			attack: 4,
			defence: 6,
			spAttack: 4,
			spDefence: 5,
			speed: 6
		},
		defaultAttackChooser: defaultAttackChooser_random,
		attacks: [
			ATTACK_DATABASE.scratch,
			ATTACK_DATABASE.growlIntimidating,
		]
	},
};



/*%fold%*/function defaultAttackChooser_random(creature, requiredAttacks = [], numOfAttacks = 4) {
	if (numOfAttacks > 4) numOfAttacks = 4;
	
	let output = requiredAttacks;
	let possibleAttacks = [];
	for (let i of CREATURE_DATABASE[creature.typeId].attacks) {
		if (!output.includes(i)) possibleAttacks.push(i);
	}
	
	while (output.length < numOfAttacks) {
		if (possibleAttacks.length <= 0) {
			break;
		}
		
		let chosenAttack = Math.floor(Math.random() * possibleAttacks.length);
		output.push(possibleAttacks[chosenAttack]);
		possibleAttacks.splice(chosenAttack, 1);
	}
	
	return output;
}


// Everything has loaded
onLoaded();