Advertisement
DarkHorseDre

precast.js - for precastchrgedskill

Sep 21st, 2020
1,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   Precast.js
  3. *   @author     noah-, kolton
  4. *   @desc       handle player prebuff sequence
  5. */
  6. include("common/precastChargedSkill.js");
  7.  
  8. var Precast = new function () {
  9.     this.haveCTA = -1;
  10.     this.BODuration = 0;
  11.     this.BOTick = 0;
  12.     this.bestSlot = {};
  13.  
  14.     this.precastCTA = function (force) {
  15.         if (!force && me.getState(32)) {
  16.             return true;
  17.         }
  18.  
  19.         if (me.gametype === 0 || me.classid === 4 || me.inTown) {
  20.             return false;
  21.         }
  22.  
  23.         if (this.checkCTA()) {
  24.             var slot = me.weaponswitch;
  25.  
  26.             PrecastChargedSkill(!me.getState(149) && (getTickCount() - this.BOTick >= 30 - 30000)); //dhd added - cast charged skill (oak) before cta BO
  27.  
  28.             Attack.weaponSwitch(this.haveCTA);
  29.             //D2Bot.printToConsole("**** DHD - state before CTA, BO: " + me.getState(32) + ", BC: " + me.getState(51) + ", Shout: " + me.getState(26) + ", MaxLife: " + me.getStat(7) + "***", 5);
  30.             Skill.cast(155, 0); // Battle Command
  31.             Skill.cast(149, 0); // Battle Orders
  32.             //D2Bot.printToConsole("**** DHD - state after CTA, BO: " + me.getState(32) + ", BC: " + me.getState(51) + ", Shout: " + me.getState(26) + ", MaxLife: " + me.getStat(7) + "***", 5);
  33.  
  34.             this.BODuration = (20 + me.getSkill(149, 1) * 10 + (me.getSkill(138, 0) + me.getSkill(155, 0)) * 5) * 1000;
  35.             this.BOTick = getTickCount();
  36.  
  37.             Attack.weaponSwitch(slot);
  38.  
  39.             return true;
  40.         }
  41.  
  42.         return false;
  43.     };
  44.  
  45.     this.getBetterSlot = function (skillId) {
  46.         if (this.bestSlot[skillId] !== undefined) {
  47.             return this.bestSlot[skillId];
  48.         }
  49.  
  50.         var item, classid, skillTab,
  51.             sumCurr = 0,
  52.             sumSwap = 0;
  53.  
  54.         switch (skillId) {
  55.         case 40: // Frozen Armor
  56.         case 50: // Shiver Armor
  57.         case 60: // Chilling Armor
  58.             classid = 1;
  59.             skillTab = 10;
  60.  
  61.             break;
  62.         case 52: // Enchant
  63.             classid = 1;
  64.             skillTab = 8;
  65.  
  66.             break;
  67.         case 57: // Thunder Storm
  68.         case 58: // Energy Shield
  69.             classid = 1;
  70.             skillTab = 9;
  71.  
  72.             break;
  73.         case 68: // Bone Armor
  74.             classid = 2;
  75.             skillTab = 17;
  76.  
  77.             break;
  78.         case 117: // Holy Shield
  79.             classid = 3;
  80.             skillTab = 24;
  81.  
  82.             break;
  83.         case 138: // Shout
  84.         case 149: // Battle Orders
  85.         case 155: // Battle Command
  86.             classid = 4;
  87.             skillTab = 34;
  88.  
  89.             break;
  90.         case 235: // Cyclone Armor
  91.             classid = 5;
  92.             skillTab = 42;
  93.  
  94.             break;
  95.         case 258: // Burst of Speed
  96.         case 267: // Fade
  97.             classid = 6;
  98.             skillTab = 49;
  99.  
  100.             break;
  101.         case 277: // Blade Shield
  102.             classid = 6;
  103.             skillTab = 48;
  104.  
  105.             break;
  106.         default:
  107.             return me.weaponswitch;
  108.         }
  109.  
  110.         item = me.getItem();
  111.  
  112.         if (item) {
  113.             do {
  114.                 if (item.bodylocation === 4 || item.bodylocation === 5) {
  115.                     sumCurr += (item.getStat(127) + item.getStat(83, classid) + item.getStat(188, skillTab) + item.getStat(107, skillId) + item.getStat(97, skillId));
  116.                 }
  117.  
  118.                 if (item.bodylocation === 11 || item.bodylocation === 12) {
  119.                     sumSwap += (item.getStat(127) + item.getStat(83, classid) + item.getStat(188, skillTab) + item.getStat(107, skillId) + item.getStat(97, skillId));
  120.                 }
  121.             } while (item.getNext());
  122.         }
  123.  
  124.         this.bestSlot[skillId] = (sumSwap > sumCurr) ? me.weaponswitch ^ 1 : me.weaponswitch;
  125.         return this.bestSlot[skillId];
  126.     };
  127.  
  128.     this.precastSkill = function (skillId) {
  129.         var swap = me.weaponswitch;
  130.  
  131.         Attack.weaponSwitch(this.getBetterSlot(skillId));
  132.         Skill.cast(skillId, 0);
  133.         Attack.weaponSwitch(swap);
  134.  
  135.         return true;
  136.     };
  137.  
  138.     this.doPrecast = function (force) {
  139.         var buffSummons = false;
  140.  
  141.         // Force BO 30 seconds before it expires
  142.         PrecastChargedSkill(!me.getState(149) && (getTickCount() - this.BOTick >= 30 - 30000)); //dhd added - cast charged skill (oak) before cta BO
  143.         this.precastCTA(!me.getState(32) || force || (getTickCount() - this.BOTick >= this.BODuration - 30000));
  144.  
  145.             switch (me.classid) {
  146.                 case 0: // Amazon
  147.                     if (Config.SummonValkyrie) {
  148.                         this.summon(32); // Valkyrie
  149.                 }
  150.  
  151.                 break;
  152.             case 1: // Sorceress
  153.             //dhd if (me.getSkill(57, 0) && (!me.getState(38) || force)) {
  154.             if (me.getSkill(57, 1) && (!me.getState(38) || force)) {
  155.                 this.precastSkill(57); // Thunder Storm
  156.             }
  157.             //dhd if (me.getSkill(58, 0) && (!me.getState(30) || force)) {
  158.             if (me.getSkill(58, 1) && (!me.getState(30) || force)) {
  159.                 this.precastSkill(58); // Energy Shield
  160.             }
  161.  
  162.             //dhd if (me.getSkill(50, 0)) {
  163.             if (me.getSkill(50, 1)) {   //added ,1 for check for oskill when no hard skill
  164.                 if (!me.getState(88) || force) {
  165.                     this.precastSkill(50); // Shiver Armor
  166.                 }
  167.             //dhd} else if (me.getSkill(60, 0)) {
  168.                 } else if (me.getSkill(60, 1)) {    //added ,1 for check for oskill when no hard skill
  169.                 if (!me.getState(20) || force) {
  170.                     this.precastSkill(60); // Chilling Armor
  171.                 }
  172.             //dhd} else if (me.getSkill(40, 0)) {
  173.             } else if (me.getSkill(40, 1)) {        //added ,1 for check for oskill when no hard skill
  174.                 if (!me.getState(10) || force) {
  175.                     this.precastSkill(40); // Frozen Armor
  176.                 }
  177.             }
  178.  
  179.             if (me.getSkill(52, 0) && (!me.getState(16) || force)) {
  180.                 this.enchant();
  181.             }
  182.  
  183.             break;
  184.         case 2: // Necromancer
  185.             if (me.getSkill(68, 0) && (!me.getState(14) || force)) {
  186.                 this.precastSkill(68); // Bone Armor
  187.             }
  188.  
  189.             switch (Config.Golem) {
  190.             case 0:
  191.             case "None":
  192.                 break;
  193.             case 1:
  194.             case "Clay":
  195.                 this.summon(75);
  196.                 break;
  197.             case 2:
  198.             case "Blood":
  199.                 this.summon(85);
  200.                 break;
  201.             case 3:
  202.             case "Fire":
  203.                 this.summon(94);
  204.                 break;
  205.             }
  206.  
  207.             break;
  208.         case 3: // Paladin
  209.             //dhd if (me.getSkill(117, 0) && (!me.getState(101) || force)) {
  210.             if (me.getSkill(117, 1) && (!me.getState(101) || force)) {
  211.                 this.precastSkill(117); // Holy Shield
  212.             }
  213.  
  214.             break;
  215.         case 4: // Barbarian - TODO: BO duration
  216.             if (!me.getState(32) || !me.getState(51) || !me.getState(26) || force) {
  217.                 var swap = me.weaponswitch;
  218.  
  219.                 Attack.weaponSwitch(this.getBetterSlot(149));
  220.                 PrecastChargedSkill(!me.getState(149)  && (getTickCount() - this.BOTick >= 30 - 30000)); //dhd added - cast charged skill (oak) before cta BO
  221.  
  222.                 if (!me.getState(51) || force) {
  223.                     Skill.cast(155, 0); // Battle Command
  224.                 }
  225.  
  226.                 if (!me.getState(32) || force) {
  227.                     Skill.cast(149, 0); // Battle Orders
  228.                 }
  229.  
  230.                 if (!me.getState(26) || force) {
  231.                     Skill.cast(138, 0); // Shout
  232.                 }
  233.  
  234.                 Attack.weaponSwitch(swap);
  235.             }
  236.  
  237.             break;
  238.         case 5: // Druid
  239.             if (me.getSkill(235, 0) && (!me.getState(151) || force)) {
  240.                 this.precastSkill(235); // Cyclone Armor
  241.             }
  242.  
  243.             if (Config.SummonRaven) {
  244.                 this.summon(221); // Raven
  245.             }
  246.  
  247.             switch (Config.SummonAnimal) {
  248.             case 1:
  249.             case "Spirit Wolf":
  250.                 buffSummons = this.summon(227) || buffSummons; // Summon Spirit Wolf
  251.  
  252.                 break;
  253.             case 2:
  254.             case "Dire Wolf":
  255.                 buffSummons = this.summon(237) || buffSummons; // Summon Dire Wolf
  256.  
  257.                 break;
  258.             case 3:
  259.             case "Grizzly":
  260.                 buffSummons = this.summon(247) || buffSummons; // Summon Grizzly
  261.  
  262.                 break;
  263.             }
  264.  
  265.             switch (Config.SummonVine) {
  266.             case 1:
  267.             case "Poison Creeper":
  268.                 buffSummons = this.summon(222) || buffSummons; // Poison Creeper
  269.  
  270.                 break;
  271.             case 2:
  272.             case "Carrion Vine":
  273.                 buffSummons = this.summon(231) || buffSummons; // Carrion Vine
  274.  
  275.                 break;
  276.             case 3:
  277.             case "Solar Creeper":
  278.                 buffSummons = this.summon(241) || buffSummons; // Solar Creeper
  279.  
  280.                 break;
  281.             }
  282.  
  283.             switch (Config.SummonSpirit) {
  284.             case 1:
  285.             case "Oak Sage":
  286.                 buffSummons = this.summon(226) || buffSummons; // Oak Sage
  287.  
  288.                 break;
  289.             case 2:
  290.             case "Heart of Wolverine":
  291.                 buffSummons = this.summon(236) || buffSummons; // Heart of Wolverine
  292.  
  293.                 break;
  294.             case 3:
  295.             case "Spirit of Barbs":
  296.                 buffSummons = this.summon(246) || buffSummons; // Spirit of Barbs
  297.  
  298.                 break;
  299.             }
  300.  
  301.             if (me.getSkill(250, 0) && (!me.getState(144) || force)) {
  302.                 Skill.cast(250, 0); // Hurricane
  303.             }
  304.  
  305.             if (Config.SummonSpirit === 1 && me.getSkill(226, 1) && (!me.getState(149) || force)) {
  306.                 Skill.cast(226, 0); // Oak Sage
  307.             }
  308.  
  309.             if (Config.SummonSpirit === 2 && me.getSkill(236, 1) && (!me.getState(148) || force)) {
  310.                 Skill.cast(236, 0); // Heart of Wolverine
  311.             }
  312.  
  313.             if (Config.SummonSpirit === 3 && me.getSkill(246, 1) && (!me.getState(147) || force)) {
  314.                 Skill.cast(246, 0); // Spirit of Barbs
  315.             }
  316.  
  317.             if (buffSummons) {
  318.                 PrecastChargedSkill(!me.getState(149) && (getTickCount() - this.BOTick >= 30 - 30000)); //dhd added - cast charged skill (oak) before cta BO
  319.                 this.precastCTA(force);
  320.             }
  321.  
  322.             break;
  323.         case 6: // Assassin
  324.             if (me.getSkill(267, 0) && Config.UseFade && (!me.getState(159) || force)) {
  325.                 this.precastSkill(267); // Fade
  326.             }
  327.  
  328.             if (me.getSkill(278, 0) && Config.UseVenom && (!me.getState(31) || force)) {
  329.                 Skill.cast(278, 0); // Venom
  330.             }
  331.  
  332.             if (me.getSkill(277, 0) && (!me.getState(158) || force)) {
  333.                 this.precastSkill(277); // Blade Shield
  334.             }
  335.  
  336.             if (me.getSkill(258, 0) && !Config.UseFade && Config.UseBoS && (!me.getState(157) || force)) {
  337.                 this.precastSkill(258); // Burst of Speed
  338.             }
  339.  
  340.             switch (Config.SummonShadow) {
  341.             case 1:
  342.             case "Warrior":
  343.                 this.summon(268); // Shadow Warrior
  344.                 break;
  345.             case 2:
  346.             case "Master":
  347.                 this.summon(279); // Shadow Master
  348.                 break;
  349.             }
  350.  
  351.             break;
  352.         }
  353.  
  354.         Attack.weaponSwitch(Attack.getPrimarySlot());
  355.     };
  356.  
  357.     this.checkCTA = function () {
  358.         var item;
  359.  
  360.         if (this.haveCTA > -1) {
  361.             return true;
  362.         }
  363.  
  364.         item = me.getItem(-1, 1);
  365.  
  366.         if (item) {
  367.             do {
  368.                 if (item.getPrefix(20519)) { // Call to Arms
  369.                     switch (item.bodylocation) {
  370.                     case 4:
  371.                     case 5:
  372.                         this.haveCTA = me.weaponswitch;
  373.  
  374.                         return true;
  375.                     case 11:
  376.                     case 12:
  377.                         this.haveCTA = me.weaponswitch ^ 1;
  378.  
  379.                         return true;
  380.                     }
  381.                 }
  382.             } while (item.getNext());
  383.         }
  384.  
  385.         return false;
  386.     };
  387.  
  388.     this.summon = function (skillId) {
  389.         if (!me.getSkill(skillId, 1)) {
  390.             return false;
  391.         }
  392.  
  393.         var minion, rv,
  394.             count = 1;
  395.  
  396.         switch (skillId) {
  397.         case 32: // Valkyrie
  398.             minion = 2;
  399.  
  400.             break;
  401.         case 75: // Clay Golem
  402.         case 85: // Blood Golem
  403.         case 94: // Fire Golem
  404.             minion = 3;
  405.  
  406.             break;
  407.         case 221: // Raven
  408.             minion = 10;
  409.             count = Math.min(me.getSkill(221, 1), 5);
  410.  
  411.             break;
  412.         case 226: // Oak Sage
  413.         case 236: // Heart of Wolverine
  414.         case 246: // Spirit of Barbs
  415.             minion = 13;
  416.  
  417.             break;
  418.         case 222: // Poison Creeper
  419.         case 231: // Carrion Vine
  420.         case 241: // Solar Creeper
  421.             minion = 14;
  422.  
  423.             break;
  424.         case 227: // Spirit Wolf
  425.             minion = 11;
  426.             count = Math.min(me.getSkill(227, 1), 5);
  427.  
  428.             break;
  429.         case 237: // Dire Wolf
  430.             minion = 12;
  431.             count = Math.min(me.getSkill(237, 1), 3);
  432.  
  433.             break;
  434.         case 247: // Grizzly
  435.             minion = 15;
  436.  
  437.             break;
  438.         case 268: // Shadow Warrior
  439.         case 279: // Shadow Master
  440.             minion = 16;
  441.  
  442.             break;
  443.         }
  444.  
  445.         while (me.getMinionCount(minion) < count) {
  446.             rv = true;
  447.  
  448.             Skill.cast(skillId, 0);
  449.             delay(200);
  450.         }
  451.  
  452.         return !!rv;
  453.     };
  454.  
  455.     this.enchant = function () {
  456.         var unit, slot = me.weaponswitch, chanted = [];
  457.  
  458.         Attack.weaponSwitch(this.getBetterSlot(52));
  459.  
  460.         // Player
  461.         unit = getUnit(0);
  462.  
  463.         if (unit) {
  464.             do {
  465.                 if (!unit.dead && Misc.inMyParty(unit.name) && getDistance(me, unit) <= 40) {
  466.                     Skill.cast(52, 0, unit);
  467.                     chanted.push(unit.name);
  468.                 }
  469.             } while (unit.getNext());
  470.         }
  471.  
  472.         // Minion
  473.         unit = getUnit(1);
  474.  
  475.         if (unit) {
  476.             do {
  477.                 if (unit.getParent() && chanted.indexOf(unit.getParent().name) > -1 && getDistance(me, unit) <= 40) {
  478.                     Skill.cast(52, 0, unit);
  479.                 }
  480.             } while (unit.getNext());
  481.         }
  482.  
  483.         Attack.weaponSwitch(slot);
  484.  
  485.         return true;
  486.     };
  487. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement