L2SkillSummon.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.skills.l2skills;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.ExperienceTable;
  18. import com.l2jserver.gameserver.datatables.NpcTable;
  19. import com.l2jserver.gameserver.idfactory.IdFactory;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Skill;
  22. import com.l2jserver.gameserver.model.StatsSet;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  31. import com.l2jserver.gameserver.templates.skills.L2TargetType;
  32. public class L2SkillSummon extends L2Skill
  33. {
  34. public static final int SKILL_CUBIC_MASTERY = 143;
  35. private int _npcId;
  36. private float _expPenalty;
  37. private final boolean _isCubic;
  38. // cubic AI
  39. // Activation time for a cubic
  40. private final int _activationtime;
  41. // Activation chance for a cubic.
  42. private final int _activationchance;
  43. // Maximum casts made by the cubic until it goes idle.
  44. private final int _maxcount;
  45. // What is the total lifetime of summons (in millisecs)
  46. private final int _summonTotalLifeTime;
  47. // How much lifetime is lost per second of idleness (non-fighting)
  48. private final int _summonTimeLostIdle;
  49. // How much time is lost per second of activity (fighting)
  50. private final int _summonTimeLostActive;
  51. // item consume time in milliseconds
  52. private final int _itemConsumeTime;
  53. // item consume count over time
  54. private final int _itemConsumeOT;
  55. // item consume id over time
  56. private final int _itemConsumeIdOT;
  57. // how many times to consume an item
  58. private final int _itemConsumeSteps;
  59. // Inherit elementals from master
  60. private final boolean _inheritElementals;
  61. private final double _elementalSharePercent;
  62. public L2SkillSummon(StatsSet set)
  63. {
  64. super(set);
  65. _npcId = set.getInteger("npcId", 0); // default for undescribed skills
  66. _expPenalty = set.getFloat ("expPenalty", 0.f);
  67. _isCubic = set.getBool("isCubic", false);
  68. _activationtime= set.getInteger("activationtime", 8);
  69. _activationchance= set.getInteger("activationchance", 30);
  70. _maxcount= set.getInteger("maxcount", -1);
  71. _summonTotalLifeTime= set.getInteger("summonTotalLifeTime", 1200000); // 20 minutes default
  72. _summonTimeLostIdle= set.getInteger("summonTimeLostIdle", 0);
  73. _summonTimeLostActive= set.getInteger("summonTimeLostActive", 0);
  74. _itemConsumeOT = set.getInteger("itemConsumeCountOT", 0);
  75. _itemConsumeIdOT = set.getInteger("itemConsumeIdOT", 0);
  76. _itemConsumeTime = set.getInteger("itemConsumeTime", 0);
  77. _itemConsumeSteps = set.getInteger("itemConsumeSteps", 0);
  78. _inheritElementals = set.getBool("inheritElementals", false);
  79. _elementalSharePercent = set.getDouble("inheritPercent", 1);
  80. }
  81. public boolean checkCondition(L2Character activeChar)
  82. {
  83. if (activeChar instanceof L2PcInstance)
  84. {
  85. L2PcInstance player = (L2PcInstance)activeChar;
  86. if (isCubic())
  87. {
  88. if (getTargetType() != L2TargetType.TARGET_SELF)
  89. {
  90. return true; //Player is always able to cast mass cubic skill
  91. }
  92. int mastery = player.getSkillLevel(SKILL_CUBIC_MASTERY);
  93. if (mastery < 0)
  94. mastery = 0;
  95. int count = player.getCubics().size();
  96. if (count > mastery)
  97. {
  98. activeChar.sendMessage("You already have "+count+" cubic(s).");
  99. return false;
  100. }
  101. }
  102. else
  103. {
  104. if (player.inObserverMode())
  105. return false;
  106. if (player.getPet() != null)
  107. {
  108. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_HAVE_A_PET);
  109. return false;
  110. }
  111. }
  112. }
  113. return super.checkCondition(activeChar, null, false);
  114. }
  115. @Override
  116. public void useSkill(L2Character caster, L2Object[] targets)
  117. {
  118. if (caster.isAlikeDead() || !(caster instanceof L2PcInstance))
  119. return;
  120. L2PcInstance activeChar = (L2PcInstance) caster;
  121. if (_npcId == 0)
  122. {
  123. activeChar.sendMessage("Summon skill "+getId()+" not described yet");
  124. return;
  125. }
  126. if (_isCubic)
  127. {
  128. // Gnacik :
  129. // If skill is enchanted calculate cubic skill level based on enchant
  130. // 8 at 101 (+1 Power)
  131. // 12 at 130 (+30 Power)
  132. // Because 12 is max 5115-5117 skills
  133. // TODO: make better method of calculation, dunno how its calculated on offi
  134. int _cubicSkillLevel = getLevel();
  135. if (_cubicSkillLevel > 100)
  136. {
  137. _cubicSkillLevel = Math.round(((getLevel()-100)/7)+8);
  138. }
  139. if (targets.length > 1) // Mass cubic skill
  140. {
  141. for (L2Object obj: targets)
  142. {
  143. if (!(obj instanceof L2PcInstance)) continue;
  144. L2PcInstance player = ((L2PcInstance)obj);
  145. int mastery = player.getSkillLevel(SKILL_CUBIC_MASTERY);
  146. if (mastery < 0)
  147. mastery = 0;
  148. if (mastery == 0 && !player.getCubics().isEmpty())
  149. {
  150. // Player can have only 1 cubic - we should replace old cubic with new one
  151. for (L2CubicInstance c: player.getCubics().values(new L2CubicInstance[0]))
  152. {
  153. c.stopAction();
  154. c = null;
  155. }
  156. player.getCubics().clear();
  157. }
  158. // TODO: Should remove first cubic summoned and replace with new cubic
  159. if (player.getCubics().containsKey(_npcId))
  160. {
  161. L2CubicInstance cubic = player.getCubic(_npcId);
  162. cubic.stopAction();
  163. cubic.cancelDisappear();
  164. player.delCubic(_npcId);
  165. }
  166. if (player.getCubics().size() > mastery) continue;
  167. if (player == activeChar)
  168. player.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, false);
  169. else // given by other player
  170. player.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, true);
  171. player.broadcastUserInfo();
  172. }
  173. }
  174. else // Normal cubic skill
  175. {
  176. int mastery = activeChar.getSkillLevel(SKILL_CUBIC_MASTERY);
  177. if (mastery < 0)
  178. mastery = 0;
  179. if (activeChar.getCubics().containsKey(_npcId))
  180. {
  181. L2CubicInstance cubic = activeChar.getCubic(_npcId);
  182. cubic.stopAction();
  183. cubic.cancelDisappear();
  184. activeChar.delCubic(_npcId);
  185. }
  186. if (activeChar.getCubics().size() > mastery) {
  187. if (Config.DEBUG)
  188. _log.fine("player can't summon any more cubics. ignore summon skill");
  189. activeChar.sendPacket(SystemMessageId.CUBIC_SUMMONING_FAILED);
  190. return;
  191. }
  192. activeChar.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, false);
  193. activeChar.broadcastUserInfo();
  194. }
  195. return;
  196. }
  197. if (activeChar.getPet() != null || activeChar.isMounted()) {
  198. if (Config.DEBUG)
  199. _log.fine("player has a pet already. ignore summon skill");
  200. return;
  201. }
  202. L2SummonInstance summon;
  203. L2NpcTemplate summonTemplate = NpcTable.getInstance().getTemplate(_npcId);
  204. if (summonTemplate == null)
  205. {
  206. _log.warning("Summon attempt for nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
  207. return; // npcID doesn't exist
  208. }
  209. final int id = IdFactory.getInstance().getNextId();
  210. if (summonTemplate.isType("L2SiegeSummon"))
  211. summon = new L2SiegeSummonInstance(id, summonTemplate, activeChar, this);
  212. else if (summonTemplate.isType("L2MerchantSummon"))
  213. summon = new L2MerchantSummonInstance(id, summonTemplate, activeChar, this);
  214. else
  215. summon = new L2SummonInstance(id, summonTemplate, activeChar, this);
  216. summon.setName(summonTemplate.getName());
  217. summon.setTitle(activeChar.getName());
  218. summon.setExpPenalty(_expPenalty);
  219. summon.setSharedElementals(_inheritElementals);
  220. summon.setSharedElementalsValue(_elementalSharePercent);
  221. if (summon.getLevel() >= ExperienceTable.getInstance().getMaxPetLevel())
  222. {
  223. summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(ExperienceTable.getInstance().getMaxPetLevel()-1));
  224. _log.warning("Summon (" + summon.getName() + ") NpcID: " + summon.getNpcId() + " has a level above "+ExperienceTable.getInstance().getMaxPetLevel()+". Please rectify.");
  225. }
  226. else
  227. {
  228. summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(summon.getLevel() % ExperienceTable.getInstance().getMaxPetLevel()));
  229. }
  230. summon.setCurrentHp(summon.getMaxHp());
  231. summon.setCurrentMp(summon.getMaxMp());
  232. summon.setHeading(activeChar.getHeading());
  233. summon.setRunning();
  234. if (!(summon instanceof L2MerchantSummonInstance))
  235. activeChar.setPet(summon);
  236. //L2World.getInstance().storeObject(summon);
  237. summon.spawnMe(activeChar.getX()+20, activeChar.getY()+20, activeChar.getZ());
  238. }
  239. public final boolean isCubic()
  240. {
  241. return _isCubic;
  242. }
  243. public final int getTotalLifeTime()
  244. {
  245. return _summonTotalLifeTime;
  246. }
  247. public final int getTimeLostIdle()
  248. {
  249. return _summonTimeLostIdle;
  250. }
  251. public final int getTimeLostActive()
  252. {
  253. return _summonTimeLostActive;
  254. }
  255. /**
  256. * @return Returns the itemConsume count over time.
  257. */
  258. public final int getItemConsumeOT()
  259. {
  260. return _itemConsumeOT;
  261. }
  262. /**
  263. * @return Returns the itemConsumeId over time.
  264. */
  265. public final int getItemConsumeIdOT()
  266. {
  267. return _itemConsumeIdOT;
  268. }
  269. public final int getItemConsumeSteps()
  270. {
  271. return _itemConsumeSteps;
  272. }
  273. /**
  274. * @return Returns the itemConsume time in milliseconds.
  275. */
  276. public final int getItemConsumeTime()
  277. {
  278. return _itemConsumeTime;
  279. }
  280. public final int getNpcId()
  281. {
  282. return _npcId;
  283. }
  284. public final float getExpPenalty()
  285. {
  286. return _expPenalty;
  287. }
  288. }