L2SkillSummon.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.templates.StatsSet;
  31. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  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. public L2SkillSummon(StatsSet set)
  60. {
  61. super(set);
  62. _npcId = set.getInteger("npcId", 0); // default for undescribed skills
  63. _expPenalty = set.getFloat ("expPenalty", 0.f);
  64. _isCubic = set.getBool("isCubic", false);
  65. _activationtime= set.getInteger("activationtime", 8);
  66. _activationchance= set.getInteger("activationchance", 30);
  67. _maxcount= set.getInteger("maxcount", -1);
  68. _summonTotalLifeTime= set.getInteger("summonTotalLifeTime", 1200000); // 20 minutes default
  69. _summonTimeLostIdle= set.getInteger("summonTimeLostIdle", 0);
  70. _summonTimeLostActive= set.getInteger("summonTimeLostActive", 0);
  71. _itemConsumeOT = set.getInteger("itemConsumeCountOT", 0);
  72. _itemConsumeIdOT = set.getInteger("itemConsumeIdOT", 0);
  73. _itemConsumeTime = set.getInteger("itemConsumeTime", 0);
  74. _itemConsumeSteps = set.getInteger("itemConsumeSteps", 0);
  75. }
  76. public boolean checkCondition(L2Character activeChar)
  77. {
  78. if (activeChar instanceof L2PcInstance)
  79. {
  80. L2PcInstance player = (L2PcInstance)activeChar;
  81. if (isCubic())
  82. {
  83. if (getTargetType() != L2Skill.SkillTargetType.TARGET_SELF)
  84. {
  85. return true; //Player is always able to cast mass cubic skill
  86. }
  87. int mastery = player.getSkillLevel(SKILL_CUBIC_MASTERY);
  88. if (mastery < 0)
  89. mastery = 0;
  90. int count = player.getCubics().size();
  91. if (count > mastery)
  92. {
  93. activeChar.sendMessage("You already have "+count+" cubic(s).");
  94. return false;
  95. }
  96. }
  97. else
  98. {
  99. if (player.inObserverMode())
  100. return false;
  101. if (player.getPet() != null)
  102. {
  103. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_ALREADY_HAVE_A_PET));
  104. return false;
  105. }
  106. }
  107. }
  108. return super.checkCondition(activeChar, null, false);
  109. }
  110. @Override
  111. public void useSkill(L2Character caster, L2Object[] targets)
  112. {
  113. if (caster.isAlikeDead() || !(caster instanceof L2PcInstance))
  114. return;
  115. L2PcInstance activeChar = (L2PcInstance) caster;
  116. if (_npcId == 0)
  117. {
  118. activeChar.sendMessage("Summon skill "+getId()+" not described yet");
  119. return;
  120. }
  121. if (_isCubic)
  122. {
  123. // Gnacik :
  124. // If skill is enchanted calculate cubic skill level based on enchant
  125. // 8 at 101 (+1 Power)
  126. // 12 at 130 (+30 Power)
  127. // Because 12 is max 5115-5117 skills
  128. // TODO: make better method of calculation, dunno how its calculated on offi
  129. int _cubicSkillLevel = getLevel();
  130. if (_cubicSkillLevel > 100)
  131. {
  132. _cubicSkillLevel = Math.round(((getLevel()-100)/7)+8);
  133. }
  134. if (targets.length > 1) // Mass cubic skill
  135. {
  136. for (L2Object obj: targets)
  137. {
  138. if (!(obj instanceof L2PcInstance)) continue;
  139. L2PcInstance player = ((L2PcInstance)obj);
  140. int mastery = player.getSkillLevel(SKILL_CUBIC_MASTERY);
  141. if (mastery < 0)
  142. mastery = 0;
  143. if (mastery == 0 && !player.getCubics().isEmpty())
  144. {
  145. // Player can have only 1 cubic - we shuld replace old cubic with new one
  146. for (L2CubicInstance c: player.getCubics().getValues(new L2CubicInstance[player.getCubics().size()]))
  147. {
  148. c.stopAction();
  149. c = null;
  150. }
  151. player.getCubics().clear();
  152. }
  153. // TODO: Should remove first cubic summoned and replace with new cubic
  154. if (player.getCubics().containsKey(_npcId))
  155. {
  156. L2CubicInstance cubic = player.getCubic(_npcId);
  157. cubic.stopAction();
  158. cubic.cancelDisappear();
  159. player.delCubic(_npcId);
  160. }
  161. if (player.getCubics().size() > mastery) continue;
  162. if (player == activeChar)
  163. player.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, false);
  164. else // given by other player
  165. player.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, true);
  166. player.broadcastUserInfo();
  167. }
  168. }
  169. else // Normal cubic skill
  170. {
  171. int mastery = activeChar.getSkillLevel(SKILL_CUBIC_MASTERY);
  172. if (mastery < 0)
  173. mastery = 0;
  174. if (activeChar.getCubics().containsKey(_npcId))
  175. {
  176. L2CubicInstance cubic = activeChar.getCubic(_npcId);
  177. cubic.stopAction();
  178. cubic.cancelDisappear();
  179. activeChar.delCubic(_npcId);
  180. }
  181. if (activeChar.getCubics().size() > mastery) {
  182. if (Config.DEBUG)
  183. _log.fine("player can't summon any more cubics. ignore summon skill");
  184. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CUBIC_SUMMONING_FAILED));
  185. return;
  186. }
  187. activeChar.addCubic(_npcId, _cubicSkillLevel, getPower(), _activationtime, _activationchance, _maxcount, _summonTotalLifeTime, false);
  188. activeChar.broadcastUserInfo();
  189. }
  190. return;
  191. }
  192. if (activeChar.getPet() != null || activeChar.isMounted()) {
  193. if (Config.DEBUG)
  194. _log.fine("player has a pet already. ignore summon skill");
  195. return;
  196. }
  197. L2SummonInstance summon;
  198. L2NpcTemplate summonTemplate = NpcTable.getInstance().getTemplate(_npcId);
  199. if (summonTemplate == null)
  200. {
  201. _log.warning("Summon attempt for nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
  202. return; // npcID doesn't exist
  203. }
  204. if (summonTemplate.type.equalsIgnoreCase("L2SiegeSummon"))
  205. summon = new L2SiegeSummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  206. else if (summonTemplate.type.equalsIgnoreCase("L2MerchantSummon"))
  207. summon = new L2MerchantSummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  208. else
  209. summon = new L2SummonInstance(IdFactory.getInstance().getNextId(), summonTemplate, activeChar, this);
  210. summon.setName(summonTemplate.name);
  211. summon.setTitle(activeChar.getName());
  212. summon.setExpPenalty(_expPenalty);
  213. if (summon.getLevel() >= ExperienceTable.getInstance().getMaxPetLevel())
  214. {
  215. summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(ExperienceTable.getInstance().getMaxPetLevel()-1));
  216. _log.warning("Summon (" + summon.getName() + ") NpcID: " + summon.getNpcId() + " has a level above "+ExperienceTable.getInstance().getMaxPetLevel()+". Please rectify.");
  217. }
  218. else
  219. {
  220. summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(summon.getLevel() % ExperienceTable.getInstance().getMaxPetLevel()));
  221. }
  222. summon.setCurrentHp(summon.getMaxHp());
  223. summon.setCurrentMp(summon.getMaxMp());
  224. summon.setHeading(activeChar.getHeading());
  225. summon.setRunning();
  226. if (!(summon instanceof L2MerchantSummonInstance))
  227. activeChar.setPet(summon);
  228. //L2World.getInstance().storeObject(summon);
  229. summon.spawnMe(activeChar.getX()+20, activeChar.getY()+20, activeChar.getZ());
  230. }
  231. public final boolean isCubic()
  232. {
  233. return _isCubic;
  234. }
  235. public final int getTotalLifeTime()
  236. {
  237. return _summonTotalLifeTime;
  238. }
  239. public final int getTimeLostIdle()
  240. {
  241. return _summonTimeLostIdle;
  242. }
  243. public final int getTimeLostActive()
  244. {
  245. return _summonTimeLostActive;
  246. }
  247. /**
  248. * @return Returns the itemConsume count over time.
  249. */
  250. public final int getItemConsumeOT()
  251. {
  252. return _itemConsumeOT;
  253. }
  254. /**
  255. * @return Returns the itemConsumeId over time.
  256. */
  257. public final int getItemConsumeIdOT()
  258. {
  259. return _itemConsumeIdOT;
  260. }
  261. public final int getItemConsumeSteps()
  262. {
  263. return _itemConsumeSteps;
  264. }
  265. /**
  266. * @return Returns the itemConsume time in milliseconds.
  267. */
  268. public final int getItemConsumeTime()
  269. {
  270. return _itemConsumeTime;
  271. }
  272. public final int getNpcId()
  273. {
  274. return _npcId;
  275. }
  276. public final float getExpPenalty()
  277. {
  278. return _expPenalty;
  279. }
  280. }