SHOW:
|
|
- or go back to the newest paste.
1 | Index: net.sf.l2j;Config.java | |
2 | =================================================================== | |
3 | --- net.sf.l2j;Config.java (revision 84) | |
4 | +++ net.sf.l2j;Config.java (working copy) | |
5 | ||
6 | + /** Auto potions settings */ | |
7 | + public static Map<Integer, Integer> AUTO_POTIONS = new HashMap<>(); | |
8 | + public static Map<Integer, String[]> AUTO_POTIONS_LIMITS = new HashMap<>(); | |
9 | ||
10 | ||
11 | ||
12 | + String ap = player.getProperty("AutoPotions", ""); | |
13 | + String[] ap_split = ap.split(";"); | |
14 | + for (String s : ap_split) | |
15 | + { | |
16 | + String[] ss = s.split(","); | |
17 | + AUTO_POTIONS.put(Integer.parseInt(ss[0]), Integer.parseInt(ss[1])); | |
18 | + } | |
19 | + String apl = player.getProperty("AutoPotionsLimits", ""); | |
20 | + String[] apl_split = apl.split(";"); | |
21 | + for (String s : apl_split) | |
22 | + { | |
23 | + String[] ss = s.split(","); | |
24 | + AUTO_POTIONS_LIMITS.put(Integer.parseInt(ss[0]), new String[] { ss[1], ss[2] }); | |
25 | + } | |
26 | ||
27 | ||
28 | Index: net.sf.l2j.gameserver.ban;AutoPotionTask.java | |
29 | =================================================================== | |
30 | --- net.sf.l2j.gameserver.ban;AutoPotionTask.java (revision 84) | |
31 | +++ net.sf.l2j.gameserver.l2jban.autopotion;AutoPotionTask.java (working copy) | |
32 | ||
33 | ||
34 | + package net.sf.l2j.gameserver.l2jban.autopotion; | |
35 | + | |
36 | + import net.sf.l2j.Config; | |
37 | + import net.sf.l2j.gameserver.model.L2Skill; | |
38 | + import net.sf.l2j.gameserver.model.actor.instance.Player; | |
39 | + import net.sf.l2j.gameserver.model.holder.IntIntHolder; | |
40 | + | |
41 | + public class AutoPotionTask implements Runnable | |
42 | + { | |
43 | + private int itemId; | |
44 | + private Player player; | |
45 | + | |
46 | + public AutoPotionTask(int itemId, Player player) | |
47 | + { | |
48 | + this.itemId = itemId; | |
49 | + this.player = player; | |
50 | + } | |
51 | + | |
52 | + @Override | |
53 | + public void run() | |
54 | + { | |
55 | + if (!player.isOnline()) | |
56 | + { | |
57 | + player.stopAutoPotion(itemId); | |
58 | + return; | |
59 | + } | |
60 | + if (player.isInOlympiadMode()) | |
61 | + { | |
62 | + player.sendMessage("You cannot that in olympiad mode."); | |
63 | + player.stopAutoPotion(itemId); | |
64 | + return; | |
65 | + } | |
66 | + | |
67 | + if (Config.AUTO_POTIONS_LIMITS.containsKey(itemId)) | |
68 | + { | |
69 | + String type = Config.AUTO_POTIONS_LIMITS.get(itemId)[0]; | |
70 | + int val = Integer.parseInt(Config.AUTO_POTIONS_LIMITS.get(itemId)[1]); | |
71 | + | |
72 | + switch (type) | |
73 | + { | |
74 | + case "CP": | |
75 | + { | |
76 | + if ((player.getCurrentCp() / player.getMaxCp()) * 100 > val) | |
77 | + return; | |
78 | + break; | |
79 | + } | |
80 | + case "HP": | |
81 | + { | |
82 | + if ((player.getCurrentHp() / player.getMaxHp()) * 100 > val) | |
83 | + return; | |
84 | + break; | |
85 | + } | |
86 | + case "MP": | |
87 | + { | |
88 | + if ((player.getCurrentMp() / player.getMaxMp()) * 100 > val) | |
89 | + return; | |
90 | + break; | |
91 | + } | |
92 | + } | |
93 | + } | |
94 | + | |
95 | + if (!player.destroyItemByItemId("auto potion use", itemId, 1, null, true)) | |
96 | + { | |
97 | + player.stopAutoPotion(itemId); | |
98 | + player.sendMessage("Incorrect item count."); | |
99 | + return; | |
100 | + } | |
101 | + | |
102 | + if (player.getInventory().getItemByItemId(itemId) == null) | |
103 | + { | |
104 | + player.stopAutoPotion(itemId); | |
105 | + return; | |
106 | + } | |
107 | + IntIntHolder[] skills = player.getInventory().getItemByItemId(itemId).getEtcItem().getSkills(); | |
108 | + if (skills == null) | |
109 | + return; | |
110 | + | |
111 | + for (IntIntHolder skill : skills) | |
112 | + { | |
113 | + if (skill == null) | |
114 | + continue; | |
115 | + | |
116 | + L2Skill sk = skill.getSkill(); | |
117 | + if (sk == null) | |
118 | + continue; | |
119 | + | |
120 | + player.doSimultaneousCast(sk); | |
121 | + } | |
122 | + } | |
123 | + | |
124 | + public int getItemId() | |
125 | + { | |
126 | + return itemId; | |
127 | + } | |
128 | + } | |
129 | ||
130 | Index: net.sf.l2j.gameserver.model.actor;player.java | |
131 | =================================================================== | |
132 | --- net.sf.l2j.gameserver.model.actor;player.java (revision 84) | |
133 | +++ net.sf.l2j.gameserver.model.actor;player.java (working copy) | |
134 | ||
135 | ||
136 | - import net.sf.l2j.gameserver.geoengine.GeoEngine; | |
137 | + import net.sf.l2j.gameserver.geoengine.GeoEngine; | |
138 | + import l2jban.autopotion.AutoPotionTask; | |
139 | ||
140 | ||
141 | + private Map<AutoPotionTask, ScheduledFuture<?>> autoPotionTasks = new HashMap<>(); | |
142 | ||
143 | + public void stopAutoPotion(int itemId) | |
144 | + { | |
145 | + AutoPotionTask temp = null; | |
146 | + for (AutoPotionTask atp : autoPotionTasks.keySet()) | |
147 | + { | |
148 | + if (atp.getItemId() == itemId) | |
149 | + { | |
150 | + temp = atp; | |
151 | + break; | |
152 | + } | |
153 | + } | |
154 | + | |
155 | + if (temp == null) | |
156 | + return; | |
157 | + | |
158 | + autoPotionTasks.get(temp).cancel(true); | |
159 | + autoPotionTasks.remove(temp); | |
160 | + sendPacket(new ExAutoSoulShot(itemId, 0)); | |
161 | + sendMessage("The automatic use of "+ItemTable.getInstance().getTemplate(itemId).getName()+" has been deactivated."); | |
162 | + } | |
163 | + | |
164 | + public void startAutoPotion(int itemId) | |
165 | + { | |
166 | + for (AutoPotionTask atp : autoPotionTasks.keySet()) | |
167 | + if (atp.getItemId() == itemId) | |
168 | + return; | |
169 | + | |
170 | + AutoPotionTask atp = new AutoPotionTask(itemId, this); | |
171 | + autoPotionTasks.put(atp, ThreadPool.scheduleAtFixedRate(atp, Config.AUTO_POTIONS.get(itemId)*1000, Config.AUTO_POTIONS.get(itemId)*1000)); | |
172 | + sendPacket(new ExAutoSoulShot(itemId, 1)); | |
173 | + sendMessage("You have activated the automatic use of "+ItemTable.getInstance().getTemplate(itemId).getName()+"."); | |
174 | + } | |
175 | ||
176 | Index: config/players.propertis | |
177 | =================================================================== | |
178 | --- config/players.propertis (revision 84) | |
179 | +++ config/players.propertis (working copy) | |
180 | ||
181 | + # Auto potions ids | |
182 | + # The ids of the potions you type here will be activated to be auto with right click. | |
183 | + # Use like: itemId,seconds;itemId,seconds | |
184 | + # Seconds represents every x seconds a potion will be added when auto is activated | |
185 | + AutoPotions = 6539,1;6540,1 | |
186 | + # Percentage (%) limitations. | |
187 | + # Use like: itemId,type,%;itemId,type,% | |
188 | + # For example, if you want mana potions to be used if MP is less than 80%, add 728,MP,80 | |
189 | + # If you don't add a limitation for a type of potion(for example cp potion), it will be used even if cp is fully restored. | |
190 | + AutoPotionsLimits = 6539,MP,75;6540,CP,95 |