L2SkillSummon.java 9.8 KB

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