Batclient triggers partyprots
From BatWiki
/************************************* * Party effects trigger set to * * display prots etc effects of all * * party members. * * * * Coded by Cielgi, contact if you * * need help or something * *************************************/ SCRIPT_NAME = "partyEffects"; SCRIPT_DESC = "Utilizing the party effects, this script shows bunch of prots of the party members"; SCRIPT_OFF = false; import java.util.*; List columns = null; Map aliases = null; int widest = 6; int MAX_ROW_LEN = 65; // Used internally to separate stuff, duh. String SEPARATOR = "######!!!!!!!!!######"; String COL_SEP = "|"; String[] DEFAULT_COLUMNS = {"war ensemble", "unstun", "aura of hate", "flex shield", "protection from evil", "heavy weight"}; List places = null; Map memberEffects = null; String currentPlayer = null; Object lock = null; boolean inputStarted = false; boolean inputEnded = false; void bootup() { columns = new LinkedList(); aliases = new HashMap(); memberEffects = new HashMap(); places = new LinkedList(); //add places places.add("1,1"); places.add("1,2"); places.add("1,3"); places.add("2,1"); places.add("2,2"); places.add("2,3"); places.add("3,1"); places.add("3,2"); places.add("3,3"); // Add short names for spells, taken from the protscript by Era, thanks! aliases.put("resist dispel", "RD"); aliases.put("armour of aether", "AoA"); aliases.put("shield of detoxification", "GPois"); aliases.put("repulsor aura", "GMana"); aliases.put("lightning shield", "GElec"); aliases.put("frost shield", "GCold"); aliases.put("flame shield", "GFire"); aliases.put("aura of wind", "GAsph"); aliases.put("acid shield", "GAcid"); aliases.put("psionic phalanx", "GPsi"); aliases.put("force absorption", "Fabs"); aliases.put("toxic dilution", "TD"); aliases.put("magic dispersion", "MD"); aliases.put("energy channeling", "EC"); aliases.put("frost insulation", "FI"); aliases.put("heat reduction", "HR"); aliases.put("ether boundary", "EB"); aliases.put("corrosion shield", "CS"); aliases.put("psychic sanctuary", "PS"); aliases.put("shield of protection", "SoP"); aliases.put("iron will", "IW"); aliases.put("quicksilver", "QSilv"); aliases.put("blurred image/displacement", "Blur"); aliases.put("haste", "Haste"); aliases.put("infravision", "Infr"); aliases.put("see invisible", "sinv"); aliases.put("see magic", "SeeMag"); aliases.put("enhanced vitality", "EV"); aliases.put("resist entropy", "REntr"); aliases.put("psionic shield", "PsiS"); aliases.put("force shield", "FSh"); aliases.put("floating", "Float"); aliases.put("mind development", "MindDeve"); aliases.put("protection from evil", "PfE"); aliases.put("resist temptation", "RT"); aliases.put("heavenly prot", "HProt"); aliases.put("soul shield", "SoulS"); aliases.put("mana shield", "ManaS"); aliases.put("unstun", "Us"); aliases.put("life link", "Link"); aliases.put("guardian angel", "GAngel"); aliases.put("unpain", "Unp"); aliases.put("blessing of tarmalen", "BoT"); aliases.put("water walking", "WW"); aliases.put("life link", "Link"); aliases.put("see the light", "Light"); aliases.put("regeneration", "Rege"); aliases.put("flex shield", "Flex"); aliases.put("earth power", "EPower"); aliases.put("earth blood", "EBlood"); aliases.put("vine mantle", "Vine"); aliases.put("earth skin", "ESkin"); aliases.put("war ensemble", "War"); aliases.put("arches favour", "Favour"); aliases.put("melodical embracement", "Melody"); aliases.put("clandestine thoughts", "Cland"); aliases.put("protection from good", "PfG"); aliases.put("aura of hate", "AoH"); aliases.put("shield of faith", "SoF"); aliases.put("personal force field", "PFF"); aliases.put("spider walk", "Walk"); aliases.put("spider touch", "Touch"); aliases.put("flame fists", "FFists"); aliases.put("minor protection", "MinorP"); aliases.put("zoological protection", "ZooP"); aliases.put("cryptozoological protection", "CryZooP"); aliases.put("kinemortological protection", "KineZooP"); aliases.put("racial protection", "RacP"); aliases.put("destructive rage", "Rage"); aliases.put("spirit drain", "SDrain"); aliases.put("spider touch", "Touch"); aliases.put("invisibility", "Invis"); aliases.put("stat curse/boost", "Curse"); aliases.put("suppress magic", "Suppress"); aliases.put("forget", "Forget"); aliases.put("hallucination", "Hallu"); aliases.put("enrage", "Rage"); aliases.put("pain threshold", "Pain"); aliases.put("glory of destruction", "Glory"); aliases.put("heavy weight", "HW"); // Add the prots you want to be displayed separately, in order resetColumns(); // Calculate the widest text that will be displayed on a column calculateWidest(); // Reset some variables currentPlayer = ""; clientGUI.printText("general", "LOADED: "+SCRIPT_NAME+" trigger by Cielgi\n"); } void run() { // when invoked by "$" + SCRIPT_NAME, do the check doEffectsCheck(); } /** * Main method that does most of the stuff. Adds some triggers, * reads the input and then forms the matrix out of the data. */ void doEffectsCheck() { lock = new Object(); inputStarted = false; inputEnded = false; // Add triggers to gag all stuff the commands used here produce triggerManager.newTrigger( "startLineGot", "^[,][-]+[.]$", "$" + SCRIPT_NAME + ".startLineGot", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "endLineGot", "^(`[-]+´)$", "$" + SCRIPT_NAME + ".endLineGot", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "gagMidline", "^[|][=]+[|]$", "", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "readEffects", "^[|]\\s+([A-Za-z ]*[A-Za-z])\\s+[|]\\s+(.*)\\s+[|]$", "$" + SCRIPT_NAME + ".addEffect %1" + SEPARATOR + "%2", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "gagNoEffects", "^No effects to show[.] \\([A-Za-z]+\\)$", "$" + SCRIPT_NAME + ".noEffects", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "readName", "^[|]\\s+Effects\\s+[(]([A-Za-z]+)[)].*$", "$" + SCRIPT_NAME + ".setPlayer %1", true, false, false, null, Font.PLAIN ); triggerManager.newTrigger( "noSuchPlayerGag", "^(No target in that position.)$", "$" + SCRIPT_NAME + ".noEffects", true, false, false, null, Font.PLAIN ); //Iterator membs = places.keySet().iterator(); // Get the effects of all members via show effects PLAYER // one at a time for(String place : places) { clientGUI.doCommand("show effects " + place); synchronized(lock) { // Wait until one members' all effects are read while(!(inputStarted && inputEnded)) { lock.wait(1000); } inputStarted = false; inputEnded = false; } } //Prevents java.util.ConcurrentModificationException Thread.sleep(10); // Take out the trigs so won't mess up anything triggerManager.removeTrigger("readName"); triggerManager.removeTrigger("gagNoEffects"); triggerManager.removeTrigger("readEffects"); triggerManager.removeTrigger("gagMidline"); triggerManager.removeTrigger("startLineGot"); triggerManager.removeTrigger("endLineGot"); triggerManager.removeTrigger("noSuchPlayerGag"); // Get the widest name of party members to get proper looking matrix int widestName = 0; for (String s : memberEffects.keySet()) { if(s.length() > widestName) widestName = s.length(); } StringBuilder row = new StringBuilder(); // Append space for names in the first column of the matrix for(int i = 0; i < widestName; i++) { row.append(' '); } row.append(COL_SEP); // Append the wanted "special" columns for (String cols : columns) { String c = (String)aliases.get(cols); if(c.length() < widest) { StringBuilder t = new StringBuilder(); t.append(c); while(t.length() < widest) { t.append(' '); } c = t.toString(); } row.append(c + COL_SEP); } // Misc column at the end, if we have room for it if(row.length() + 6 <= MAX_ROW_LEN) { row.append("Others"); while(row.length() <= MAX_ROW_LEN) { row.append(' '); } } int rowLen = row.length(); // Show the column headers and the separator printFunction(row.toString()); StringBuilder temp = new StringBuilder(); for(int i = 0; i < rowLen; i++) { temp.append("-"); } printFunction(temp.toString()); row.setLength(0); // Loop through the effects of all party members and display the // corresponding effectrows synchronized(memberEffects) { for(Map.Entry e : memberEffects.entrySet()) { List effs = (List)e.getValue(); String name = (String)e.getKey(); //clientGUI.doCommand("say name:"+name); // Clear the row row.setLength(0); row.append(name); if(name.length() < widestName) { int i = name.length(); while(i < widestName) { i++; row.append(' '); } } row.append(COL_SEP); for(String col : columns) { boolean found = false; for (String[] temp : effs) { if(col.equalsIgnoreCase(temp[0])) { String time = temp[1]; //clientGUI.doCommand("say time:"+time); if(time.equalsIgnoreCase("for now")) { time = "X"; } row.append(time); for(int i = time.length(); i < widest; i++) { row.append(' '); } row.append(COL_SEP); found = true; break; } } if(!found) { for(int i = 0; i < widest; i++) { row.append(' '); } row.append(COL_SEP); } } boolean otherProts = false; for(String[] eff : effs) { if(columns.contains(eff[0])) continue; row.append(aliases.get(eff[0]) + "[" + eff[1] + "],"); otherProts = true; } if(otherProts) row.setLength(row.length() - 1); String printableRow = row.toString(); if(printableRow.length() > rowLen) { printableRow = printableRow.substring(0, rowLen - 3) + "..."; } printFunction(printableRow); } } // Clear the variables used so nothing gets pissed currentPlayer = ""; synchronized(memberEffects) { memberEffects.clear(); } lock = null; inputStarted = false; inputEnded = false; } void addEffect() { String[] ss = argument.split(SEPARATOR); synchronized(memberEffects) { List effectList = (List)memberEffects.get(currentPlayer); if(effectList == null) { effectList = new LinkedList(); } ss[0] = ss[0].toLowerCase().trim(); ss[1] = ss[1].toLowerCase().trim().replace(" and ", "").replaceAll("min", "m"); effectList.add(ss); memberEffects.put(currentPlayer, effectList); } } void setPlayer() { currentPlayer = argument.toLowerCase().trim(); synchronized(memberEffects) { if (!memberEffects.containsKey(currentPlayer)) { memberEffects.put(currentPlayer, new LinkedList()); } } } void startLineGot() { synchronized(lock) { inputStarted = true; lock.notifyAll(); } } void endLineGot() { synchronized(lock) { inputEnded = true; lock.notifyAll(); } } void noEffects() { synchronized(lock) { inputStarted = true; inputEnded = true; lock.notifyAll(); } } void resetColumns() { columns.clear(); for(int i = 0; i < DEFAULT_COLUMNS.length; i++) { columns.add(DEFAULT_COLUMNS[i]); } calculateWidest(); } void setColumns() { String[] cols = argument.split(","); columns.clear(); for(int i = 0; i < cols.length; i++) { if(cols[i] == null || cols[i].length() == 0) continue; String column = cols[i].trim().toLowerCase(); boolean cont = false; for(String k : aliases.keySet()) { String v = (String)aliases.get(k); if(v.equalsIgnoreCase(column)) { columns.add(k); cont = true; break; } } if(cont) continue; if(!aliases.containsKey(column)) { aliases.put(column, column); } columns.add(column); } calculateWidest(); } void calculateWidest() { for(String s : columns) { s = (String)aliases.get(s); if(s.length() > widest) widest = s.length(); } } // TODO: add possibility to switch between emote and print to window void printFunction(String s) { clientGUI.doCommand("emote " + s); }