Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. package net.runelite.client.plugins.hydra;
  2.  
  3. import com.google.inject.Provides;
  4. import lombok.AccessLevel;
  5. import lombok.Getter;
  6. import net.runelite.api.*;
  7. import net.runelite.api.coords.LocalPoint;
  8. import net.runelite.api.coords.WorldPoint;
  9. import net.runelite.api.events.*;
  10. import net.runelite.client.config.ConfigManager;
  11. import net.runelite.client.eventbus.Subscribe;
  12. import java.util.*;
  13. import net.runelite.client.plugins.Plugin;
  14. import net.runelite.client.plugins.PluginDescriptor;
  15. import net.runelite.client.ui.overlay.OverlayManager;
  16. import javax.inject.Inject;
  17. import java.util.List;
  18.  
  19. @PluginDescriptor(
  20. name = " Hydra",
  21. description = "Helps you kill hydra",
  22. tags = {"hydra", "slayer", "pvm"},
  23. enabledByDefault =false
  24. )
  25. public class HydraPlugin extends Plugin {
  26.  
  27. @Inject
  28. private Client client;
  29.  
  30. @Getter(AccessLevel.PUBLIC)
  31. @Inject
  32. private OverlayManager overlayManager;
  33.  
  34. @Inject
  35. private HydraConfig config;
  36.  
  37. @Inject
  38. private HydraOverlay overlay;
  39.  
  40. public boolean isMage = false;
  41. public int HydraCounter = 0;
  42. private boolean lastphase = false;
  43. private int NumberAttacks = 0;
  44. public Set<Integer> HydraID = new HashSet<>();
  45.  
  46. NPC hydra = null;
  47.  
  48. @Provides
  49. HydraConfig provideConfig(ConfigManager configManager)
  50. {
  51. return configManager.getConfig(HydraConfig.class);
  52. }
  53.  
  54. @Override
  55. protected void startUp() throws Exception
  56. {
  57. HydraID.add(8615);HydraID.add(8619);HydraID.add(8620);HydraID.add(8621);
  58. overlayManager.add(overlay);
  59. }
  60.  
  61. @Override
  62. protected void shutDown() throws Exception
  63. {
  64. overlayManager.remove(overlay);
  65. }
  66.  
  67. @Subscribe
  68. public void onGameTick(GameTick tick) {
  69.  
  70. List<NPC> npcs = client.getNpcs();
  71. if (npcs == null) { return; }
  72. //if (!client.isInInstancedRegion()) { return; }
  73. for (NPC npc : npcs) {
  74. if (HydraID.contains(npc.getId())) {
  75. this.hydra = npc;
  76. if (this.hydra.getHealth() <= 275) {
  77. lastphase = true;
  78. }
  79. }
  80. }
  81.  
  82. List<Projectile> p = client.getProjectiles();
  83. for ( Projectile P: p ) {
  84. int id = P.getId();
  85. HandleCounter(id);
  86. }
  87.  
  88. this.HydraCounter--;
  89. if (HydraCounter < 0) {
  90. HydraCounter = 0;
  91. }
  92. }
  93.  
  94. private void HandleCounter(int projid) {
  95.  
  96. if (projid == ProjectileID.HYDRA_MAGE || projid == ProjectileID.HYDRA_RANGE) {
  97. if (NumberAttacks==0) {
  98. if (projid == ProjectileID.HYDRA_MAGE) {
  99. this.NumberAttacks++;
  100. this.isMage = true;
  101. HydraCounter = 7;
  102. }
  103. }
  104. if (HydraCounter < 2) {
  105. this.NumberAttacks++;
  106. if (lastphase) {
  107. this.isMage = !this.isMage;
  108. }
  109. else if (this.NumberAttacks-1 % 3 == 0) {
  110. this.isMage = !this.isMage;
  111. }
  112. HydraCounter = 7;
  113. }
  114.  
  115. }
  116.  
  117. else {
  118. if (HydraCounter < 2) {
  119. HydraCounter = 7;
  120. }
  121. }
  122. }
  123.  
  124. @Subscribe
  125. public void onNpcDespawned(NpcDespawned despawned){
  126. NumberAttacks = 0;
  127. }
  128. }
  129.  
  130. ******** HydraOverlay.java ********
  131.  
  132.  
  133. package net.runelite.client.plugins.hydra;
  134.  
  135. import net.runelite.api.*;
  136. import net.runelite.api.Point;
  137. import net.runelite.api.coords.LocalPoint;
  138. import net.runelite.client.ui.overlay.*;
  139. import javax.inject.Inject;
  140. import java.awt.*;
  141.  
  142. public class HydraOverlay extends Overlay {
  143.  
  144. private Client client;
  145. private final HydraPlugin plugin;
  146.  
  147. @Inject
  148. public HydraOverlay(Client client, HydraPlugin plugin)
  149. {
  150. this.client = client;
  151. this.plugin = plugin;
  152. setPosition(OverlayPosition.DYNAMIC);
  153. setLayer(OverlayLayer.ABOVE_SCENE);
  154. }
  155.  
  156. @Override
  157. public Dimension render(Graphics2D graphics)
  158. {
  159. graphics.setFont(new Font("Arial", Font.BOLD, 20));
  160. NPC npc = plugin.hydra;
  161.  
  162. if((npc == null) || !client.isInInstancedRegion()){
  163. return null;
  164. }
  165.  
  166. if (plugin.HydraCounter >= 0) {
  167.  
  168. String str = Integer.toString(plugin.HydraCounter);
  169. LocalPoint lp = npc.getLocalLocation();
  170.  
  171. //Point textLocation = Perspective.getCanvasTextLocation(client, graphics, lp, str, 0);
  172.  
  173. Point textLocation = npc.getCanvasTextLocation(graphics, npc.getName(), 0);
  174.  
  175. if (plugin.isMage) {
  176. OverlayUtil.renderTextLocation(graphics, textLocation, str, Color.BLUE);
  177. } else {
  178. OverlayUtil.renderTextLocation(graphics, textLocation, str, Color.GREEN);
  179. }
  180. }
  181. return null;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement