Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. package net.runelite.client.plugins.tickcounter;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import javax.inject.Inject;
  9.  
  10. import net.runelite.api.Actor;
  11. import net.runelite.api.Player;
  12. import net.runelite.api.events.*;
  13. import net.runelite.api.kit.KitType;
  14. import net.runelite.client.eventbus.Subscribe;
  15. import net.runelite.client.plugins.Plugin;
  16. import net.runelite.client.plugins.PluginDescriptor;
  17. import net.runelite.client.ui.overlay.OverlayManager;
  18.  
  19. import static net.runelite.api.widgets.WidgetID.THEATRE_OF_BLOOD_REWARD_GROUP_ID;
  20.  
  21. @PluginDescriptor(name = "Tick Counter",
  22. description = "Counts combat activity for nearby players",
  23. enabledByDefault = false
  24. )
  25. public class TickCounterPlugin extends Plugin
  26. {
  27.  
  28. @Inject
  29. private OverlayManager overlayManager;
  30.  
  31. @Inject
  32. private TickCounterOverlay overlay;
  33.  
  34. Map<String, Integer> activity = new HashMap<>();
  35.  
  36. private List<Player> blowpiping = new ArrayList<>();
  37.  
  38. private HashMap<String,Integer> blowpipeAnimationTicks = new HashMap<>();
  39.  
  40. @Override
  41. protected void startUp() throws Exception
  42. {
  43. overlayManager.add(overlay);
  44. }
  45.  
  46. @Override
  47. protected void shutDown() throws Exception
  48. {
  49. overlayManager.remove(overlay);
  50. activity.clear();
  51. }
  52.  
  53. @Subscribe
  54. public void onNpcSpawned(NpcSpawned npcSpawned){
  55. if (npcSpawned.getNpc().getId() == 8360){
  56. overlayManager.remove(overlay);
  57. activity.clear();
  58. overlayManager.add(overlay);
  59. }
  60. }
  61.  
  62. @Subscribe
  63. public void onAnimationChanged(AnimationChanged e)
  64. {
  65.  
  66. if (!(e.getActor() instanceof Player))
  67. return;
  68. Player p = (Player) e.getActor();
  69.  
  70. int weapon = -1;
  71. if (p.getPlayerComposition() != null)
  72. weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON);
  73. int delta = 0;
  74.  
  75. String name = p.getName();
  76. int activity = this.activity.getOrDefault(name, 0).intValue();
  77.  
  78. if(p.getAnimation() != 5061 && blowpipeAnimationTicks.containsKey(name)) {
  79. int ticksToAdd = blowpipeAnimationTicks.get(name)/2;
  80. int ticksToAdd2 = ticksToAdd * 2;
  81. this.activity.put(name, activity + ticksToAdd2);
  82. blowpipeAnimationTicks.put(name,0);
  83. }
  84.  
  85. switch (p.getAnimation())
  86. {
  87. case 5061: // blowpipe
  88. // delta = 2;
  89. blowpiping.add(p);
  90. break;
  91. case 2323: // rpg
  92. case 7618: // chin
  93. delta = 3;
  94. break;
  95. case 426: // bow shoot
  96. if (weapon == 20997) // twisted bow
  97. delta = 5;
  98. else // shortbow
  99. delta = 3;
  100. break;
  101. case 422: //punch
  102. case 423: //kick
  103. case 386: // lunge
  104. case 390: // generic slash
  105. case 1067: // claw stab
  106. case 1074: // msb spec
  107. case 1167: // trident cast
  108. case 1658: // whip
  109. case 7514: // claw spec
  110. case 8145: // rapier stab
  111. case 8288: // dhl
  112. delta = 4;
  113. break;
  114. case 393: // staff bash
  115. if (weapon == 13652)
  116. { // claw scratch
  117. delta = 4;
  118. break;
  119. }
  120. case 395: // axe autos
  121. case 400: // pick smash
  122. case 1379: //burst or blitz
  123. case 1979: // barrage spell cast
  124. case 8056: // scythe swing
  125. delta = 5;
  126. break;
  127. case 401:
  128. if (weapon == 13576) // dwh bop
  129. delta = 6;
  130. else // used by pickaxe and axe
  131. delta = 5;
  132. break;
  133. case 1378:
  134. case 7045:
  135. case 7054:
  136. case 7055: // godsword autos
  137. case 7638: // zgs spec
  138. case 7640: // sgs spec
  139. case 7642: // bgs spec
  140. case 7643: // bgs spec
  141. case 7644: // ags spec
  142. delta = 6;
  143. break;
  144. case 428: // chally swipe
  145. case 440: // chally jab
  146. case 1203: // chally spec
  147. delta = 7;
  148. break;
  149. case -1:
  150. blowpiping.remove(p);
  151. break;
  152. }
  153. if (delta > 0)
  154. {
  155. //String name = p.getName();
  156. this.activity.put(name, this.activity.getOrDefault(name, 0) + delta);
  157. }
  158. }
  159.  
  160.  
  161.  
  162.  
  163. @Subscribe
  164. public void onGameTick(GameTick e)
  165. {
  166. /*
  167. * Hack for blowpipe since the AnimationChanged event doesn't fire when using a
  168. * blowpipe because of its speed. If blowpipe animation restarts, then add 2
  169. */
  170. for (Player p : blowpiping)
  171. {
  172. Actor rsp = p;
  173. //if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1)
  174. if (rsp.getAnimation() == 5061)
  175. {
  176. String name = p.getName();
  177. if(blowpipeAnimationTicks.containsKey(name) == false)
  178. blowpipeAnimationTicks.put(name,1);
  179. else blowpipeAnimationTicks.put(name,blowpipeAnimationTicks.get(name)+1);
  180. }
  181. }
  182. }
  183.  
  184. @Subscribe
  185. public void onWidgetLoaded(WidgetLoaded event)
  186. {
  187. int groupId = event.getGroupId();
  188.  
  189. if (groupId == THEATRE_OF_BLOOD_REWARD_GROUP_ID)
  190. {
  191. overlayManager.remove(overlay);
  192. activity.clear();
  193. overlayManager.add(overlay);
  194. }
  195. }
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement