Downloads containing academy_utils.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Anniversary Bash 21 Levels Jazz2Online Multiple N/A Download file

File preview

namespace acUtils {

	bool checkIfPlayerIsInRange(jjPLAYER@ source, jjPLAYER@ potentialTarget, float scaledRadius) {
		float xDistance = potentialTarget.xPos - source.xPos;
		float yDistance = potentialTarget.yPos - source.yPos;
		return xDistance*xDistance + yDistance*yDistance < scaledRadius*scaledRadius;
	}
	
	bool checkIfPlayerIsVulnerable(jjPLAYER@ caster, jjPLAYER@ potentialTarget, Spell@ spell) {
		if (spell.enumValue == SPELL_DEATH_RIPPLE && potentialTarget.isZombie) return false; 
		if (spell.damagesAll) return true;
		return potentialTarget.isEnemy(caster);
	}
	
	void closeOtherBoxes(BOX activeBox, Player@ asPlayer) {
		if (activeBox != BOX_SPELL_BOOK && @asPlayer != null) {
			asPlayer.unSetChanneledSpellKey();
			spellBookOpen = false;
		}
		if (activeBox != BOX_INFO) infoOpen = false;
		if (activeBox != BOX_SKILLS) skillsOpen = false;
		if (activeBox != BOX_TREE && treeState == 2) treeState = 1;
		if (activeBox != BOX_KEY_MENU) keyMenuState = keyMenuState >= 1 ? 1 : 0;
		if (activeBox != BOX_WIZARD && wizardState == 2) wizardState = 1;
	}
	
	void disableDemoMode() {
		for (uint i = 0; i < 32; i++) {
			players[i].unSetChanneledSpellKey();
		}
		ownSpells.removeRange(0, ownSpells.length);
		ownSpells = acInit::loadSpells(LOWEST_TIER, HIGHEST_STARTING_TIER);
	}
	
	bool findFromChainLightningTargets(array<ChainLightningTarget@> chainLightningTargets, int8 playerID) {
		for (uint i = 0; i < chainLightningTargets.length; i++) {
			if (chainLightningTargets[i].playerID == playerID) {
				return true;
			}
		}
		return false;
	}
	
	ChainLightningTarget@ findParentTarget(array<ChainLightningTarget@> chainLightningTargets, int8 id) {
		for (uint i = 0; i < chainLightningTargets.length; i++) {
			ChainLightningTarget@ target = chainLightningTargets[i];
			if (target.id == id) {
				return target;
			}
		}
		return null;
	}

	bool gameIsRunning() {
		return jjGameState == GAME::STARTED || jjGameState == GAME::OVERTIME || !jjNoMovement;
	}
	
	int getBulletPointerDistance(float xOrigin, float yOrigin, int direction) {
		int distance = 0;
		if (direction >= 0) {
			for (float x = xOrigin; x < xOrigin+BULLET_POINTER_MAX_DISTANCE*TILE; x++) {
				if (jjMaskedVLine(int(x+TILE), int(yOrigin), 1)) {
					return distance;
				}
				distance++;
			}
		}
		else {
			for (float x = xOrigin; x > xOrigin-BULLET_POINTER_MAX_DISTANCE*TILE; x--) {
				if (jjMaskedVLine(int(x-TILE), int(yOrigin), 1)) {
					return distance;
				}
				distance++;
			}
		}
		return distance;
	}
	
	int getDamageModifier(Player@ attacker, Player@ victim) {
		int damageModifier = 0;
		for (uint i = 0; i < attacker.activeEffects.length; i++) {
			SPELL effect = attacker.activeEffects[i].enumValue;
			damageModifier += getDamageModifierByAttacker(effect);
		}
		for (uint i = 0; i < victim.activeEffects.length; i++) {
			SPELL effect = victim.activeEffects[i].enumValue;
			damageModifier += getDamageModifierByVictim(effect);
		}
		return damageModifier;
	}

	int getDamageModifierByAttacker(SPELL effect) {
		switch (effect) {
			case SPELL_BLESS: return 1;
			case SPELL_WEAKNESS: return -1;
			case SPELL_PRECISION: return 2;
			case SPELL_FRENZY: return 4;
		}
		return 0;
	}

	int getDamageModifierByVictim(SPELL effect) {
		switch (effect) {
			case SPELL_STONE_SKIN: return -1;
			case SPELL_DISRUPTING_RAY: return 2;
			case SPELL_FRENZY: return 4;
		}
		return 0;
	}
	
	string getFirstLearnableSpell() {
		for (uint i = 0; i < learnableSpells.length; i++) {
			string learnableSpell = learnableSpells[i];
			if (ownSpells.find(learnableSpell) >= 0) continue;
			else return learnableSpell;
		}
		return "";
	}
	
	float getScaledRadius(float radius, ANIM::Set animSet, int frameCount, int animCount = 0) {
		jjANIMFRAME@ sprite = jjAnimFrames[jjAnimations[jjAnimSets[animSet].firstAnim + animCount].firstFrame + frameCount];
		return float(sprite.width * radius / 2);
	}
	
	string getSpellKeyByNumpadIndex(uint numpadIndex) {
		array<string> spellKeys = spells.getKeys();
		for (uint i = 0; i < spellKeys.length; i++) {
			Spell@ spell = cast<Spell@>(spells[spellKeys[i]]);
			if (spell.numpad == numpadIndex) return spell.key;
		}
		return "";
	}
	
	int getSpellPriceByTier(uint tier) {
		if (tier == 3) return SPELL_COST_TIER_3;
		if (tier == 4) return SPELL_COST_TIER_4;
		if (tier == 5) return SPELL_COST_TIER_5;
		return 0;
	}
	
	int8[] getTargets(jjPLAYER@ source, Spell@ spell, float scaledRadius) {
		int8[] targets;
		for (int8 i = 0; i < 32; i++) {
			if (jjPlayers[i].isInGame) {
				jjPLAYER@ potentialTarget = jjPlayers[i];
				bool inRange = acUtils::checkIfPlayerIsInRange(source, potentialTarget, scaledRadius);
				if (inRange) {
					bool isVulnerable = acUtils::checkIfPlayerIsVulnerable(source, potentialTarget, spell);
					if (isVulnerable) {
						targets.insertLast(i);
					}
				}
			}
		}
		return targets;
	}
	
	uint getTierChanceByRoasts(int roasts) {
		uint chance = 5;
		if (jjMaxScore <= SHORT_GAME_THRESHOLD) {
			chance = roasts;
		}
		else {
			chance = uint(roasts / 2);
		}
		if (debugModeOn) {
			jjAlert("roasts: " + roasts);
			jjAlert("chance: " + chance);
		}
		if (chance < 1) {
			chance = 1;
		}
		else if (chance > 5) {
			chance = 5;
		}
		return chance;
	}

	int getWallOfFireHeightInTiles(float xOrigin, float yOrigin) {
		int height = 0;
		for (float x = xOrigin; x < xOrigin + 64; x++) {
			if (!jjMaskedHLine(int(x), 1, int(yOrigin+8))) {
				return 0;
			}
		}
		for (float y = yOrigin; y > yOrigin - WALL_OF_FIRE_MAX_HEIGHT*TILE; y--) {
			for (float x = xOrigin; x < xOrigin + 64; x++) {
				if (jjMaskedHLine(int(x), 1, int(y-TILE))) {
					return int(height/TILE);
				}
			}
			height++;
		}
		return int(height/TILE);
	}
	
	bool infoViewIsAboveBottom() {
		int spellsLength = spells.getKeys().length;
		if (spellsLength % 2 == 1) spellsLength++;
		return infoScrollY > -(spellsLength / 2 * INFO_BOX_HEIGHT -
				(jjSubscreenHeight-(SPELL_BOXES_INIT_Y+HINT_BOX_HEIGHT)+4));
	}
	
	bool mouseIsInSelection(int x, int y, int width, int height) {
		return jjMouseX >= x && jjMouseY >= y && jjMouseX <= x+width && jjMouseY <= y+height;
	}

	bool mouseIsOutsideKeyMenu() {
		return (jjMouseX < jjSubscreenWidth / 4 || jjMouseX > jjSubscreenWidth / 4 * 3) ||
				jjMouseY < jjSubscreenHeight / 4 || jjMouseY > jjSubscreenHeight / 4 * 3;
	}

	bool mouseIsWithinKeyMenuChoices() {
		return (jjMouseX > jjSubscreenWidth / 4 && jjMouseX < jjSubscreenWidth / 4 * 3)
				&& (jjMouseY > jjSubscreenHeight / 4 + 102
				&& jjMouseY < jjSubscreenHeight / 4 + 102 + keyBindings.length*16 );
	}
	
	int parseNumpadIndex(array<uint> buffer) {
		string numberString = "";
		for (uint j = 0; j < buffer.length; j++) {
			numberString += ("" + buffer[j]);
		}
		if (numberString.length >= 1) return parseInt(numberString);
		else return -1;
	}
	
	void playLightningSound(float x, float y) {
		jjSample(x, y, SOUND::BILSBOSS_THUNDER, 63, 8000);
	}
	
	void saveHotkeyToFile(int selection, uint keyIndex) {
		jjSTREAM file(HOTKEY_FILENAME);
		file.push(selection);
		file.push(keyIndex);
		file.save(HOTKEY_FILENAME);
	}
	
	void setHotkey(int selection, uint keyIndex, bool overwrite = false) {
		if (!overwrite) {
			array<int> hotkeys = {
					hotkeyInfo, hotkeySkills, hotkeyCycleSpells,
					hotkeySpellbook, hotkeyKeyMenu, hotkeyResources};
			if (hotkeys.find(keyIndex) >= 0) {
				hotkeyInUse = true;
				return;
			}
		}
		
		switch (selection) {
			case 0:
			{
				hotkeyInfo = keyIndex;
			}
			break;
			case 1:
			{
				hotkeySkills = keyIndex;
			}
			break;
			case 2:
			{
				hotkeyCycleSpells = keyIndex;
			}
			break;
			case 3:
			{
				hotkeySpellbook = keyIndex;
			}
			break;
			case 4:
			{
				hotkeyKeyMenu = keyIndex;
			}
			break;
			case 5:
			{
				hotkeyResources = keyIndex;
			}
			break;
		}
		if (!overwrite) {
			saveHotkeyToFile(selection, keyIndex);
		}
		hotkeyInUse = false;
		acInit::loadKeyBindings();
	}
	
	void setSkillBonus(Player@ asPlayer, SKILL skill, int8 playerID) {
		switch (skill) {
			case SKILL_MAX_MANA:
			{
				asPlayer.maxMana += 100;
			}
			break;
			case SKILL_MANA_REGEN:
			{
				asPlayer.manaRegenRate++;
			}
			break;
			case SKILL_SPELL_DAMAGE:
			{
				acNetworking::sendSkillPacket(playerID, PACKET_SKILL_DAMAGE);
				if (jjIsServer) asPlayer.spellDamageBonus++;
			}
			break;
			case SKILL_SPELL_DURATION:
			{
				acNetworking::sendSkillPacket(playerID, PACKET_SKILL_DURATION);
				if (jjIsServer) asPlayer.spellDurationBonus += 10;
			}
			break;
			case SKILL_MAGIC_RESIST:
			{
				asPlayer.magicResist++;
			}
			break;
		}
	}
	
	array<string> sortSpellKeys(array<string> spellKeys) {
		array<string> sortedKeys;
		array<Spell@> spellArray;
		for (uint i = 0; i < spellKeys.length; i++) {
			string key = spellKeys[i];
			spellArray.insertLast(cast<Spell@>(spells[spellKeys[i]]));
		}
		spellArray.sortAsc();
		for (uint i = 0; i < spellArray.length; i++) {
			sortedKeys.insertLast(spellArray[i].key);
		}
		return sortedKeys;
	}
	
	string splitText(string textToSplit, int rowWidth) {
		string newText = "";
		int lines = 1;
		for (uint i = 0; i < textToSplit.length(); i++) {
			newText += textToSplit.substr(i, 1);
			if (jjGetStringWidth(newText, STRING::SMALL, STRING::NORMAL) >= lines * rowWidth
					&& textToSplit.substr(i+1, 1) == " ") {
				newText += "\n";
				lines++;
				i++;
			}
		}
		return newText;
	}
}