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

  1. namespace acUtils {
  2.  
  3.         bool checkIfPlayerIsInRange(jjPLAYER@ source, jjPLAYER@ potentialTarget, float scaledRadius) {
  4.                 float xDistance = potentialTarget.xPos - source.xPos;
  5.                 float yDistance = potentialTarget.yPos - source.yPos;
  6.                 return xDistance*xDistance + yDistance*yDistance < scaledRadius*scaledRadius;
  7.         }
  8.        
  9.         bool checkIfPlayerIsVulnerable(jjPLAYER@ caster, jjPLAYER@ potentialTarget, Spell@ spell) {
  10.                 if (spell.enumValue == SPELL_DEATH_RIPPLE && potentialTarget.isZombie) return false;
  11.                 if (spell.damagesAll) return true;
  12.                 return potentialTarget.isEnemy(caster);
  13.         }
  14.        
  15.         void closeOtherBoxes(BOX activeBox, Player@ asPlayer) {
  16.                 if (activeBox != BOX_SPELL_BOOK && @asPlayer != null) {
  17.                         asPlayer.unSetChanneledSpellKey();
  18.                         spellBookOpen = false;
  19.                 }
  20.                 if (activeBox != BOX_INFO) infoOpen = false;
  21.                 if (activeBox != BOX_SKILLS) skillsOpen = false;
  22.                 if (activeBox != BOX_TREE && treeState == 2) treeState = 1;
  23.                 if (activeBox != BOX_KEY_MENU) keyMenuState = keyMenuState >= 1 ? 1 : 0;
  24.                 if (activeBox != BOX_WIZARD && wizardState == 2) wizardState = 1;
  25.         }
  26.        
  27.         void disableDemoMode() {
  28.                 for (uint i = 0; i < 32; i++) {
  29.                         players[i].unSetChanneledSpellKey();
  30.                 }
  31.                 ownSpells.removeRange(0, ownSpells.length);
  32.                 ownSpells = acInit::loadSpells(LOWEST_TIER, HIGHEST_STARTING_TIER);
  33.         }
  34.        
  35.         bool findFromChainLightningTargets(array<ChainLightningTarget@> chainLightningTargets, int8 playerID) {
  36.                 for (uint i = 0; i < chainLightningTargets.length; i++) {
  37.                         if (chainLightningTargets[i].playerID == playerID) {
  38.                                 return true;
  39.                         }
  40.                 }
  41.                 return false;
  42.         }
  43.        
  44.         ChainLightningTarget@ findParentTarget(array<ChainLightningTarget@> chainLightningTargets, int8 id) {
  45.                 for (uint i = 0; i < chainLightningTargets.length; i++) {
  46.                         ChainLightningTarget@ target = chainLightningTargets[i];
  47.                         if (target.id == id) {
  48.                                 return target;
  49.                         }
  50.                 }
  51.                 return null;
  52.         }
  53.  
  54.         bool gameIsRunning() {
  55.                 return jjGameState == GAME::STARTED || jjGameState == GAME::OVERTIME || !jjNoMovement;
  56.         }
  57.        
  58.         int getBulletPointerDistance(float xOrigin, float yOrigin, int direction) {
  59.                 int distance = 0;
  60.                 if (direction >= 0) {
  61.                         for (float x = xOrigin; x < xOrigin+BULLET_POINTER_MAX_DISTANCE*TILE; x++) {
  62.                                 if (jjMaskedVLine(int(x+TILE), int(yOrigin), 1)) {
  63.                                         return distance;
  64.                                 }
  65.                                 distance++;
  66.                         }
  67.                 }
  68.                 else {
  69.                         for (float x = xOrigin; x > xOrigin-BULLET_POINTER_MAX_DISTANCE*TILE; x--) {
  70.                                 if (jjMaskedVLine(int(x-TILE), int(yOrigin), 1)) {
  71.                                         return distance;
  72.                                 }
  73.                                 distance++;
  74.                         }
  75.                 }
  76.                 return distance;
  77.         }
  78.        
  79.         int getDamageModifier(Player@ attacker, Player@ victim) {
  80.                 int damageModifier = 0;
  81.                 for (uint i = 0; i < attacker.activeEffects.length; i++) {
  82.                         SPELL effect = attacker.activeEffects[i].enumValue;
  83.                         damageModifier += getDamageModifierByAttacker(effect);
  84.                 }
  85.                 for (uint i = 0; i < victim.activeEffects.length; i++) {
  86.                         SPELL effect = victim.activeEffects[i].enumValue;
  87.                         damageModifier += getDamageModifierByVictim(effect);
  88.                 }
  89.                 return damageModifier;
  90.         }
  91.  
  92.         int getDamageModifierByAttacker(SPELL effect) {
  93.                 switch (effect) {
  94.                         case SPELL_BLESS: return 1;
  95.                         case SPELL_WEAKNESS: return -1;
  96.                         case SPELL_PRECISION: return 2;
  97.                         case SPELL_FRENZY: return 4;
  98.                 }
  99.                 return 0;
  100.         }
  101.  
  102.         int getDamageModifierByVictim(SPELL effect) {
  103.                 switch (effect) {
  104.                         case SPELL_STONE_SKIN: return -1;
  105.                         case SPELL_DISRUPTING_RAY: return 2;
  106.                         case SPELL_FRENZY: return 4;
  107.                 }
  108.                 return 0;
  109.         }
  110.        
  111.         string getFirstLearnableSpell() {
  112.                 for (uint i = 0; i < learnableSpells.length; i++) {
  113.                         string learnableSpell = learnableSpells[i];
  114.                         if (ownSpells.find(learnableSpell) >= 0) continue;
  115.                         else return learnableSpell;
  116.                 }
  117.                 return "";
  118.         }
  119.        
  120.         float getScaledRadius(float radius, ANIM::Set animSet, int frameCount, int animCount = 0) {
  121.                 jjANIMFRAME@ sprite = jjAnimFrames[jjAnimations[jjAnimSets[animSet].firstAnim + animCount].firstFrame + frameCount];
  122.                 return float(sprite.width * radius / 2);
  123.         }
  124.        
  125.         string getSpellKeyByNumpadIndex(uint numpadIndex) {
  126.                 array<string> spellKeys = spells.getKeys();
  127.                 for (uint i = 0; i < spellKeys.length; i++) {
  128.                         Spell@ spell = cast<Spell@>(spells[spellKeys[i]]);
  129.                         if (spell.numpad == numpadIndex) return spell.key;
  130.                 }
  131.                 return "";
  132.         }
  133.        
  134.         int getSpellPriceByTier(uint tier) {
  135.                 if (tier == 3) return SPELL_COST_TIER_3;
  136.                 if (tier == 4) return SPELL_COST_TIER_4;
  137.                 if (tier == 5) return SPELL_COST_TIER_5;
  138.                 return 0;
  139.         }
  140.        
  141.         int8[] getTargets(jjPLAYER@ source, Spell@ spell, float scaledRadius) {
  142.                 int8[] targets;
  143.                 for (int8 i = 0; i < 32; i++) {
  144.                         if (jjPlayers[i].isInGame) {
  145.                                 jjPLAYER@ potentialTarget = jjPlayers[i];
  146.                                 bool inRange = acUtils::checkIfPlayerIsInRange(source, potentialTarget, scaledRadius);
  147.                                 if (inRange) {
  148.                                         bool isVulnerable = acUtils::checkIfPlayerIsVulnerable(source, potentialTarget, spell);
  149.                                         if (isVulnerable) {
  150.                                                 targets.insertLast(i);
  151.                                         }
  152.                                 }
  153.                         }
  154.                 }
  155.                 return targets;
  156.         }
  157.        
  158.         uint getTierChanceByRoasts(int roasts) {
  159.                 uint chance = 5;
  160.                 if (jjMaxScore <= SHORT_GAME_THRESHOLD) {
  161.                         chance = roasts;
  162.                 }
  163.                 else {
  164.                         chance = uint(roasts / 2);
  165.                 }
  166.                 if (debugModeOn) {
  167.                         jjAlert("roasts: " + roasts);
  168.                         jjAlert("chance: " + chance);
  169.                 }
  170.                 if (chance < 1) {
  171.                         chance = 1;
  172.                 }
  173.                 else if (chance > 5) {
  174.                         chance = 5;
  175.                 }
  176.                 return chance;
  177.         }
  178.  
  179.         int getWallOfFireHeightInTiles(float xOrigin, float yOrigin) {
  180.                 int height = 0;
  181.                 for (float x = xOrigin; x < xOrigin + 64; x++) {
  182.                         if (!jjMaskedHLine(int(x), 1, int(yOrigin+8))) {
  183.                                 return 0;
  184.                         }
  185.                 }
  186.                 for (float y = yOrigin; y > yOrigin - WALL_OF_FIRE_MAX_HEIGHT*TILE; y--) {
  187.                         for (float x = xOrigin; x < xOrigin + 64; x++) {
  188.                                 if (jjMaskedHLine(int(x), 1, int(y-TILE))) {
  189.                                         return int(height/TILE);
  190.                                 }
  191.                         }
  192.                         height++;
  193.                 }
  194.                 return int(height/TILE);
  195.         }
  196.        
  197.         bool infoViewIsAboveBottom() {
  198.                 int spellsLength = spells.getKeys().length;
  199.                 if (spellsLength % 2 == 1) spellsLength++;
  200.                 return infoScrollY > -(spellsLength / 2 * INFO_BOX_HEIGHT -
  201.                                 (jjSubscreenHeight-(SPELL_BOXES_INIT_Y+HINT_BOX_HEIGHT)+4));
  202.         }
  203.        
  204.         bool mouseIsInSelection(int x, int y, int width, int height) {
  205.                 return jjMouseX >= x && jjMouseY >= y && jjMouseX <= x+width && jjMouseY <= y+height;
  206.         }
  207.  
  208.         bool mouseIsOutsideKeyMenu() {
  209.                 return (jjMouseX < jjSubscreenWidth / 4 || jjMouseX > jjSubscreenWidth / 4 * 3) ||
  210.                                 jjMouseY < jjSubscreenHeight / 4 || jjMouseY > jjSubscreenHeight / 4 * 3;
  211.         }
  212.  
  213.         bool mouseIsWithinKeyMenuChoices() {
  214.                 return (jjMouseX > jjSubscreenWidth / 4 && jjMouseX < jjSubscreenWidth / 4 * 3)
  215.                                 && (jjMouseY > jjSubscreenHeight / 4 + 102
  216.                                 && jjMouseY < jjSubscreenHeight / 4 + 102 + keyBindings.length*16 );
  217.         }
  218.        
  219.         int parseNumpadIndex(array<uint> buffer) {
  220.                 string numberString = "";
  221.                 for (uint j = 0; j < buffer.length; j++) {
  222.                         numberString += ("" + buffer[j]);
  223.                 }
  224.                 if (numberString.length >= 1) return parseInt(numberString);
  225.                 else return -1;
  226.         }
  227.        
  228.         void playLightningSound(float x, float y) {
  229.                 jjSample(x, y, SOUND::BILSBOSS_THUNDER, 63, 8000);
  230.         }
  231.        
  232.         void saveHotkeyToFile(int selection, uint keyIndex) {
  233.                 jjSTREAM file(HOTKEY_FILENAME);
  234.                 file.push(selection);
  235.                 file.push(keyIndex);
  236.                 file.save(HOTKEY_FILENAME);
  237.         }
  238.        
  239.         void setHotkey(int selection, uint keyIndex, bool overwrite = false) {
  240.                 if (!overwrite) {
  241.                         array<int> hotkeys = {
  242.                                         hotkeyInfo, hotkeySkills, hotkeyCycleSpells,
  243.                                         hotkeySpellbook, hotkeyKeyMenu, hotkeyResources};
  244.                         if (hotkeys.find(keyIndex) >= 0) {
  245.                                 hotkeyInUse = true;
  246.                                 return;
  247.                         }
  248.                 }
  249.                
  250.                 switch (selection) {
  251.                         case 0:
  252.                         {
  253.                                 hotkeyInfo = keyIndex;
  254.                         }
  255.                         break;
  256.                         case 1:
  257.                         {
  258.                                 hotkeySkills = keyIndex;
  259.                         }
  260.                         break;
  261.                         case 2:
  262.                         {
  263.                                 hotkeyCycleSpells = keyIndex;
  264.                         }
  265.                         break;
  266.                         case 3:
  267.                         {
  268.                                 hotkeySpellbook = keyIndex;
  269.                         }
  270.                         break;
  271.                         case 4:
  272.                         {
  273.                                 hotkeyKeyMenu = keyIndex;
  274.                         }
  275.                         break;
  276.                         case 5:
  277.                         {
  278.                                 hotkeyResources = keyIndex;
  279.                         }
  280.                         break;
  281.                 }
  282.                 if (!overwrite) {
  283.                         saveHotkeyToFile(selection, keyIndex);
  284.                 }
  285.                 hotkeyInUse = false;
  286.                 acInit::loadKeyBindings();
  287.         }
  288.        
  289.         void setSkillBonus(Player@ asPlayer, SKILL skill, int8 playerID) {
  290.                 switch (skill) {
  291.                         case SKILL_MAX_MANA:
  292.                         {
  293.                                 asPlayer.maxMana += 100;
  294.                         }
  295.                         break;
  296.                         case SKILL_MANA_REGEN:
  297.                         {
  298.                                 asPlayer.manaRegenRate++;
  299.                         }
  300.                         break;
  301.                         case SKILL_SPELL_DAMAGE:
  302.                         {
  303.                                 acNetworking::sendSkillPacket(playerID, PACKET_SKILL_DAMAGE);
  304.                                 if (jjIsServer) asPlayer.spellDamageBonus++;
  305.                         }
  306.                         break;
  307.                         case SKILL_SPELL_DURATION:
  308.                         {
  309.                                 acNetworking::sendSkillPacket(playerID, PACKET_SKILL_DURATION);
  310.                                 if (jjIsServer) asPlayer.spellDurationBonus += 10;
  311.                         }
  312.                         break;
  313.                         case SKILL_MAGIC_RESIST:
  314.                         {
  315.                                 asPlayer.magicResist++;
  316.                         }
  317.                         break;
  318.                 }
  319.         }
  320.        
  321.         array<string> sortSpellKeys(array<string> spellKeys) {
  322.                 array<string> sortedKeys;
  323.                 array<Spell@> spellArray;
  324.                 for (uint i = 0; i < spellKeys.length; i++) {
  325.                         string key = spellKeys[i];
  326.                         spellArray.insertLast(cast<Spell@>(spells[spellKeys[i]]));
  327.                 }
  328.                 spellArray.sortAsc();
  329.                 for (uint i = 0; i < spellArray.length; i++) {
  330.                         sortedKeys.insertLast(spellArray[i].key);
  331.                 }
  332.                 return sortedKeys;
  333.         }
  334.        
  335.         string splitText(string textToSplit, int rowWidth) {
  336.                 string newText = "";
  337.                 int lines = 1;
  338.                 for (uint i = 0; i < textToSplit.length(); i++) {
  339.                         newText += textToSplit.substr(i, 1);
  340.                         if (jjGetStringWidth(newText, STRING::SMALL, STRING::NORMAL) >= lines * rowWidth
  341.                                         && textToSplit.substr(i+1, 1) == " ") {
  342.                                 newText += "\n";
  343.                                 lines++;
  344.                                 i++;
  345.                         }
  346.                 }
  347.                 return newText;
  348.         }
  349. }