Advertisement
Senaia

Mobius Ertheia - TriggerForce

May 23rd, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.68 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20.  
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.concurrent.ScheduledFuture;
  24.  
  25. import com.l2jserver.gameserver.ThreadPoolManager;
  26. import com.l2jserver.gameserver.datatables.SkillData;
  27. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  28. import com.l2jserver.gameserver.handler.TargetHandler;
  29. import com.l2jserver.gameserver.model.L2Object;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.L2Character;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.model.conditions.Condition;
  34. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  35. import com.l2jserver.gameserver.model.holders.SkillHolder;
  36. import com.l2jserver.gameserver.model.skills.BuffInfo;
  37. import com.l2jserver.gameserver.model.skills.Skill;
  38. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  39.  
  40. /**
  41. * Force Skill effect implementation.
  42. * @author Mobius
  43. */
  44. public final class TriggerForce extends AbstractEffect
  45. {
  46. private final SkillHolder _skill;
  47. private final L2TargetType _targetType;
  48. private ScheduledFuture<?> _partyForceCheckTask = null;
  49. private List<L2PcInstance> _affectedPlayers = new ArrayList<>();
  50.  
  51. private final static int SIGEL_AURA = 1927;
  52. private final static int TYRR_AURA = 1929;
  53. private final static int OTHELL_AURA = 1931;
  54. private final static int YUL_AURA = 1933;
  55. private final static int FEOH_AURA = 1935;
  56. private final static int WYNN_AURA = 1937;
  57. private final static int AEORE_AURA = 1939;
  58. private final static int SIGEL_FORCE = 1928;
  59. private final static int TYRR_FORCE = 1930;
  60. private final static int OTHELL_FORCE = 1932;
  61. private final static int YUL_FORCE = 1934;
  62. private final static int FEOH_FORCE = 1936;
  63. private final static int WYNN_FORCE = 1938;
  64. private final static int AEORE_FORCE = 1940;
  65. private final static int PARTY_SOLIDARITY = 1955;
  66.  
  67. /**
  68. * @param attachCond
  69. * @param applyCond
  70. * @param set
  71. * @param params
  72. */
  73. public TriggerForce(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  74. {
  75. super(attachCond, applyCond, set, params);
  76.  
  77. _skill = new SkillHolder(params.getInt("skillId", 0), params.getInt("skillLevel", 0));
  78. _targetType = params.getEnum("targetType", L2TargetType.class, L2TargetType.ONE);
  79. }
  80.  
  81. @Override
  82. public void onStart(BuffInfo info)
  83. {
  84. final L2PcInstance effector = info.getEffector().getActingPlayer();
  85. final L2PcInstance effected = info.getEffected().getActingPlayer();
  86.  
  87. if (effected.isDead() || (effector == null))
  88. {
  89. return;
  90. }
  91.  
  92. if ((_skill.getSkillId() == 0) || (_skill.getSkillLvl() == 0))
  93. {
  94. return;
  95. }
  96.  
  97. final ITargetTypeHandler targetHandler = TargetHandler.getInstance().getHandler(_targetType);
  98. if (targetHandler == null)
  99. {
  100. _log.warning("Handler for target type: " + _targetType + " does not exist.");
  101. return;
  102. }
  103.  
  104. final Skill triggerSkill = _skill.getSkill();
  105. final L2Object[] targets = targetHandler.getTargetList(triggerSkill, effector, false, effected);
  106.  
  107. for (L2Object triggerTarget : targets)
  108. {
  109. if ((triggerTarget == null) || !triggerTarget.isCharacter())
  110. {
  111. continue;
  112. }
  113.  
  114. final L2Character targetChar = (L2Character) triggerTarget;
  115. if (!targetChar.isInvul())
  116. {
  117. effector.makeTriggerCast(triggerSkill, targetChar);
  118. }
  119. }
  120.  
  121. if (effector.getParty() != null)
  122. {
  123. _affectedPlayers = effector.getParty().getMembers();
  124. }
  125. else
  126. {
  127. _affectedPlayers.add(effector);
  128. }
  129. managePartySolidarity();
  130. _partyForceCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(() ->
  131. {
  132. partyForceCheckTask(effector, triggerSkill);
  133. }, 1000, 5000);
  134. }
  135.  
  136. @Override
  137. public void onExit(BuffInfo info)
  138. {
  139. final L2PcInstance effected = info.getEffected().getActingPlayer();
  140.  
  141. if ((effected.getEffectList().getBuffInfoBySkillId(SIGEL_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(SIGEL_FORCE) != null))
  142. {
  143. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(SIGEL_FORCE));
  144. }
  145. if ((effected.getEffectList().getBuffInfoBySkillId(TYRR_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(TYRR_FORCE) != null))
  146. {
  147. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(TYRR_FORCE));
  148. }
  149. if ((effected.getEffectList().getBuffInfoBySkillId(OTHELL_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(OTHELL_FORCE) != null))
  150. {
  151. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(OTHELL_FORCE));
  152. }
  153. if ((effected.getEffectList().getBuffInfoBySkillId(YUL_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(YUL_FORCE) != null))
  154. {
  155. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(YUL_FORCE));
  156. }
  157. if ((effected.getEffectList().getBuffInfoBySkillId(FEOH_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(FEOH_FORCE) != null))
  158. {
  159. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(FEOH_FORCE));
  160. }
  161. if ((effected.getEffectList().getBuffInfoBySkillId(WYNN_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(WYNN_FORCE) != null))
  162. {
  163. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(WYNN_FORCE));
  164. }
  165. if ((effected.getEffectList().getBuffInfoBySkillId(AEORE_AURA) == null) && (effected.getEffectList().getBuffInfoBySkillId(AEORE_FORCE) != null))
  166. {
  167. effected.getEffectList().remove(true, effected.getEffectList().getBuffInfoBySkillId(AEORE_FORCE));
  168. }
  169. }
  170.  
  171. private void partyForceCheckTask(L2PcInstance effector, Skill triggerSkill)
  172. {
  173. if (!_affectedPlayers.contains(effector) || (effector == null) || (effector.getEffectList().getBuffInfoBySkillId(triggerSkill.getId() - 1) == null))
  174. {
  175. boolean stillExists = false;
  176. for (L2PcInstance member : _affectedPlayers)
  177. {
  178. if (member == null)
  179. {
  180. continue;
  181. }
  182. if (member.getEffectList().getBuffInfoBySkillId(triggerSkill.getId() - 1) != null)
  183. {
  184. stillExists = true;
  185. }
  186. }
  187.  
  188. if (!stillExists)
  189. {
  190. for (L2PcInstance member : _affectedPlayers)
  191. {
  192. if (member == null)
  193. {
  194. continue;
  195. }
  196. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(triggerSkill.getId()));
  197. }
  198. managePartySolidarity();
  199. }
  200.  
  201. _partyForceCheckTask.cancel(true);
  202. return;
  203. }
  204. if (effector.getParty() == null)
  205. {
  206. for (L2PcInstance member : _affectedPlayers)
  207. {
  208. if ((member == null) || (member == effector))
  209. {
  210. continue;
  211. }
  212. _affectedPlayers.remove(member);
  213. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(triggerSkill.getId()));
  214. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(PARTY_SOLIDARITY));
  215. }
  216. }
  217. else if (effector.getParty().getMembers() != _affectedPlayers)
  218. {
  219. for (L2PcInstance member : effector.getParty().getMembers())
  220. {
  221. if (!_affectedPlayers.contains(member))
  222. {
  223. _affectedPlayers.add(member);
  224. effector.makeTriggerCast(triggerSkill, member);
  225. }
  226. }
  227. for (L2PcInstance member : _affectedPlayers)
  228. {
  229. if ((member == null) || (member == effector))
  230. {
  231. continue;
  232. }
  233. if (!effector.getParty().getMembers().contains(member))
  234. {
  235. _affectedPlayers.remove(member);
  236. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(triggerSkill.getId()));
  237. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(PARTY_SOLIDARITY));
  238. }
  239. }
  240. managePartySolidarity();
  241. }
  242. }
  243.  
  244. private void managePartySolidarity()
  245. {
  246. for (L2PcInstance member : _affectedPlayers)
  247. {
  248. int activeForces = 0;
  249. if (member.getEffectList().getBuffInfoBySkillId(SIGEL_FORCE) != null)
  250. {
  251. activeForces++;
  252. }
  253. if (member.getEffectList().getBuffInfoBySkillId(TYRR_FORCE) != null)
  254. {
  255. activeForces++;
  256. }
  257. if (member.getEffectList().getBuffInfoBySkillId(OTHELL_FORCE) != null)
  258. {
  259. activeForces++;
  260. }
  261. if (member.getEffectList().getBuffInfoBySkillId(YUL_FORCE) != null)
  262. {
  263. activeForces++;
  264. }
  265. if (member.getEffectList().getBuffInfoBySkillId(FEOH_FORCE) != null)
  266. {
  267. activeForces++;
  268. }
  269. if (member.getEffectList().getBuffInfoBySkillId(WYNN_FORCE) != null)
  270. {
  271. activeForces++;
  272. }
  273. if (member.getEffectList().getBuffInfoBySkillId(AEORE_FORCE) != null)
  274. {
  275. activeForces++;
  276. }
  277.  
  278. if (activeForces < 4)
  279. {
  280. member.getEffectList().remove(true, member.getEffectList().getBuffInfoBySkillId(PARTY_SOLIDARITY));
  281. }
  282. if ((activeForces >= 4) && (member.getEffectList().getBuffInfoBySkillId(AEORE_FORCE) != null) && (member.getEffectList().getBuffInfoBySkillId(SIGEL_FORCE) != null))
  283. {
  284. member.makeTriggerCast(SkillData.getInstance().getSkill(PARTY_SOLIDARITY, Math.min((activeForces - 3), 3)), member);
  285. }
  286. }
  287. }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement