Advertisement
kolton

Untitled

Jan 17th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   Party.js
  3. *   @author     kolton
  4. *   @desc       handle party procedure ingame
  5. */
  6.  
  7. function main() {
  8.     include("OOG.js");
  9.     include("json2.js");
  10.     include("common/Config.js");
  11.     include("common/Cubing.js");
  12.     include("common/Runewords.js");
  13.     include("common/Misc.js");
  14.     include("common/Prototypes.js");
  15.     Config.init();
  16.  
  17.     var i, myPartyId, player, otherParty, shitList, currScript, scriptList,
  18.         classes = ["Amazon", "Sorceress", "Necromancer", "Paladin", "Barbarian", "Druid", "Assassin"],
  19.         playerLevels = {},
  20.         partyTick = getTickCount();
  21.  
  22.     addEventListener("gameevent",
  23.         function (mode, param1, param2, name1, name2) {
  24.             var player;
  25.  
  26.             switch (mode) {
  27.             case 0x02: // "%Name1(%Name2) joined our world. Diablo's minions grow stronger."
  28.                 if (Config.Greetings.length > 0) {
  29.                     try {
  30.                         player = getParty(name1);
  31.                     } catch (e1) {
  32.  
  33.                     }
  34.  
  35.                     if (player && player.name !== me.name) {
  36.                         say(Config.Greetings[rand(0, Config.Greetings.length - 1)].replace("$name", player.name).replace("$level", player.level).replace("$class", classes[player.classid]));
  37.                     }
  38.                 }
  39.  
  40.                 break;
  41.             case 0x06: // "%Name1 was Slain by %Name2"
  42.                 if (Config.DeathMessages.length > 0) {
  43.                     try {
  44.                         player = getParty(name1);
  45.                     } catch (e2) {
  46.  
  47.                     }
  48.  
  49.                     if (player && player.name !== me.name) {
  50.                         say(Config.DeathMessages[rand(0, Config.DeathMessages.length - 1)].replace("$name", player.name).replace("$level", player.level).replace("$class", classes[player.classid]).replace("$killer", name2));
  51.                     }
  52.                 }
  53.  
  54.                 break;
  55.             }
  56.         });
  57.     addEventListener("scriptmsg",
  58.         function (msg) {
  59.             var obj;
  60.  
  61.             try {
  62.                 obj = JSON.parse(msg);
  63.  
  64.                 if (obj && obj.hasOwnProperty("currScript")) {
  65.                     currScript = obj.currScript;
  66.                 }
  67.             } catch (e3) {
  68.  
  69.             }
  70.         });
  71.  
  72.     print("ΓΏc2Party thread loaded. Mode: " + (Config.PublicMode === 2 ? "Accept" : "Invite"));
  73.  
  74.     if (Config.ShitList || Config.UnpartyShitlisted) {
  75.         shitList = ShitList.read();
  76.  
  77.         print(shitList.length + " entries in shit list.");
  78.     }
  79.  
  80.     if (Config.PartyAfterScript) {
  81.         scriptList = [];
  82.  
  83.         for (i in Scripts) {
  84.             if (Scripts.hasOwnProperty(i) && !!Scripts[i]) {
  85.                 scriptList.push(i);
  86.             }
  87.         }
  88.     }
  89.  
  90.     // Main loop
  91.     while (true) {
  92.         if (me.gameReady && (!Config.PartyAfterScript || scriptList.indexOf(currScript) > scriptList.indexOf(Config.PartyAfterScript))) {
  93.             player = getParty();
  94.  
  95.             if (player) {
  96.                 myPartyId = player.partyid;
  97.  
  98.                 while (player.getNext()) {
  99.                     switch (Config.PublicMode) {
  100.                     case 1: // Invite others
  101.                     case 3: // Invite others but never accept
  102.                         if (getPlayerFlag(me.gid, player.gid, 8)) {
  103.                             if (Config.ShitList && shitList.indexOf(player.name) === -1) {
  104.                                 say(player.name + " has been shitlisted.");
  105.                                 shitList.push(player.name);
  106.                                 ShitList.add(player.name);
  107.                             }
  108.  
  109.                             if (player.partyflag === 4) {
  110.                                 clickParty(player, 2); // cancel invitation
  111.                                 delay(100);
  112.                             }
  113.  
  114.                             break;
  115.                         }
  116.  
  117.                         if (Config.ShitList && shitList.indexOf(player.name) > -1) {
  118.                             break;
  119.                         }
  120.  
  121.                         if (player.partyflag !== 4 && (Config.PublicMode === 1 || player.partyflag !== 2) && player.partyid === 65535) {
  122.                             clickParty(player, 2);
  123.                             delay(100);
  124.                         }
  125.  
  126.                         break;
  127.                     case 2: // Accept invites
  128.                         if (Config.Leader && player.name !== Config.Leader) {
  129.                             break;
  130.                         }
  131.  
  132.                         if (player.partyid !== 65535 && player.partyid !== myPartyId) {
  133.                             otherParty = player.partyid;
  134.                         }
  135.  
  136.                         if (player.partyflag === 2 && (!otherParty || player.partyid === otherParty) && (getTickCount() - partyTick >= 2000 || Config.FastParty)) {
  137.                             clickParty(player, 2);
  138.                             delay(100);
  139.                         }
  140.  
  141.                         break;
  142.                     }
  143.  
  144.                     if (Config.UnpartyShitlisted) {
  145.                         // Add new hostile players to temp shitlist, leader should have Config.ShitList set to true to update the permanent list.
  146.                         if (getPlayerFlag(me.gid, player.gid, 8) && shitList.indexOf(player.name) === -1) {
  147.                             shitList.push(player.name);
  148.                         }
  149.  
  150.                         if (shitList.indexOf(player.name) > -1 && myPartyId !== 65535 && player.partyid === myPartyId) {
  151.                             // Only the one sending invites should say this.
  152.                             if ([1, 3].indexOf(Config.PublicMode) > -1) {
  153.                                 say(player.name + " is shitlisted. Do not invite them.");
  154.                             }
  155.  
  156.                             clickParty(player, 3);
  157.                             delay(100);
  158.                         }
  159.                     }
  160.                 }
  161.             }
  162.  
  163.             if (Config.Congratulations.length > 0) {
  164.                 player = getParty();
  165.  
  166.                 if (player) {
  167.                     do {
  168.                         if (player.name !== me.name) {
  169.                             if (!playerLevels[player.name]) {
  170.                                 playerLevels[player.name] = player.level;
  171.                             }
  172.  
  173.                             if (player.level > playerLevels[player.name]) {
  174.                                 say(Config.Congratulations[rand(0, Config.Congratulations.length - 1)].replace("$name", player.name).replace("$level", player.level).replace("$class", classes[player.classid]));
  175.  
  176.                                 playerLevels[player.name] = player.level;
  177.                             }
  178.                         }
  179.                     } while (player.getNext());
  180.                 }
  181.             }
  182.         }
  183.  
  184.         delay(500);
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement