2
0

L2Attackable.java 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417
  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.model.actor;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.logging.Level;
  19. import javolution.util.FastList;
  20. import javolution.util.FastMap;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.ItemsAutoDestroy;
  23. import com.l2jserver.gameserver.ThreadPoolManager;
  24. import com.l2jserver.gameserver.ai.CtrlEvent;
  25. import com.l2jserver.gameserver.ai.CtrlIntention;
  26. import com.l2jserver.gameserver.ai.L2AttackableAI;
  27. import com.l2jserver.gameserver.ai.L2CharacterAI;
  28. import com.l2jserver.gameserver.ai.L2FortSiegeGuardAI;
  29. import com.l2jserver.gameserver.ai.L2SiegeGuardAI;
  30. import com.l2jserver.gameserver.datatables.EventDroplist;
  31. import com.l2jserver.gameserver.datatables.EventDroplist.DateDrop;
  32. import com.l2jserver.gameserver.datatables.HerbDropTable;
  33. import com.l2jserver.gameserver.datatables.ItemTable;
  34. import com.l2jserver.gameserver.datatables.SkillTable;
  35. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  36. import com.l2jserver.gameserver.model.L2CharPosition;
  37. import com.l2jserver.gameserver.model.L2CommandChannel;
  38. import com.l2jserver.gameserver.model.L2DropCategory;
  39. import com.l2jserver.gameserver.model.L2DropData;
  40. import com.l2jserver.gameserver.model.L2ItemInstance;
  41. import com.l2jserver.gameserver.model.L2Manor;
  42. import com.l2jserver.gameserver.model.L2Object;
  43. import com.l2jserver.gameserver.model.L2Party;
  44. import com.l2jserver.gameserver.model.L2Skill;
  45. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  46. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  47. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  48. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  49. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  50. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  51. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  52. import com.l2jserver.gameserver.model.actor.knownlist.AttackableKnownList;
  53. import com.l2jserver.gameserver.model.actor.status.AttackableStatus;
  54. import com.l2jserver.gameserver.model.quest.Quest;
  55. import com.l2jserver.gameserver.network.SystemMessageId;
  56. import com.l2jserver.gameserver.network.clientpackets.Say2;
  57. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  58. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  59. import com.l2jserver.gameserver.skills.Stats;
  60. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  61. import com.l2jserver.gameserver.templates.item.L2EtcItemType;
  62. import com.l2jserver.gameserver.util.Util;
  63. import com.l2jserver.util.Rnd;
  64. public class L2Attackable extends L2Npc
  65. {
  66. private boolean _isRaid = false;
  67. private boolean _isRaidMinion = false;
  68. private boolean _champion = false;
  69. /**
  70. * This class contains all AggroInfo of the L2Attackable against the attacker L2Character.
  71. *
  72. * Data:
  73. * attacker : The attacker L2Character concerned by this AggroInfo of this L2Attackable
  74. * hate : Hate level of this L2Attackable against the attacker L2Character (hate = damage)
  75. * damage : Number of damages that the attacker L2Character gave to this L2Attackable
  76. *
  77. */
  78. public static final class AggroInfo
  79. {
  80. private final L2Character _attacker;
  81. private int _hate = 0;
  82. private int _damage = 0;
  83. AggroInfo(L2Character pAttacker)
  84. {
  85. _attacker = pAttacker;
  86. }
  87. public final L2Character getAttacker()
  88. {
  89. return _attacker;
  90. }
  91. public final int getHate()
  92. {
  93. return _hate;
  94. }
  95. public final int checkHate(L2Character owner)
  96. {
  97. if (_attacker.isAlikeDead()
  98. || !_attacker.isVisible()
  99. || !owner.getKnownList().knowsObject(_attacker))
  100. _hate = 0;
  101. return _hate;
  102. }
  103. public final void addHate(int value)
  104. {
  105. _hate = (int)Math.min(_hate + (long)value, 999999999);
  106. }
  107. public final void stopHate()
  108. {
  109. _hate = 0;
  110. }
  111. public final int getDamage()
  112. {
  113. return _damage;
  114. }
  115. public final void addDamage(int value)
  116. {
  117. _damage = (int)Math.min(_damage + (long)value, 999999999);
  118. }
  119. @Override
  120. public final boolean equals(Object obj)
  121. {
  122. if (this == obj)
  123. return true;
  124. if (obj instanceof AggroInfo)
  125. return (((AggroInfo)obj).getAttacker() == _attacker);
  126. return false;
  127. }
  128. @Override
  129. public final int hashCode()
  130. {
  131. return _attacker.getObjectId();
  132. }
  133. }
  134. /**
  135. * This class contains all RewardInfo of the L2Attackable against the any attacker L2Character, based on amount of damage done.
  136. *
  137. * Data:
  138. * attacker : The attacker L2Character concerned by this RewardInfo of this L2Attackable
  139. * dmg : Total amount of damage done by the attacker to this L2Attackable (summon + own)
  140. *
  141. */
  142. protected static final class RewardInfo
  143. {
  144. protected L2Character _attacker;
  145. protected int _dmg = 0;
  146. public RewardInfo(L2Character pAttacker, int pDmg)
  147. {
  148. _attacker = pAttacker;
  149. _dmg = pDmg;
  150. }
  151. public void addDamage(int pDmg)
  152. {
  153. _dmg += pDmg;
  154. }
  155. @Override
  156. public boolean equals(Object obj)
  157. {
  158. if (this == obj)
  159. return true;
  160. if (obj instanceof RewardInfo)
  161. return (((RewardInfo)obj)._attacker == _attacker);
  162. return false;
  163. }
  164. @Override
  165. public int hashCode()
  166. {
  167. return _attacker.getObjectId();
  168. }
  169. }
  170. /**
  171. * This class contains all AbsorberInfo of the L2Attackable against the absorber L2Character.
  172. *
  173. * Data:
  174. * absorber : The attacker L2Character concerned by this AbsorberInfo of this L2Attackable
  175. */
  176. public static final class AbsorberInfo
  177. {
  178. public int _objId;
  179. public double _absorbedHP;
  180. AbsorberInfo(int objId, double pAbsorbedHP)
  181. {
  182. _objId = objId;
  183. _absorbedHP = pAbsorbedHP;
  184. }
  185. @Override
  186. public boolean equals(Object obj)
  187. {
  188. if (this == obj)
  189. return true;
  190. if (obj instanceof AbsorberInfo)
  191. return (((AbsorberInfo)obj)._objId == _objId);
  192. return false;
  193. }
  194. @Override
  195. public int hashCode()
  196. {
  197. return _objId;
  198. }
  199. }
  200. public static final class RewardItem
  201. {
  202. protected int _itemId;
  203. protected int _count;
  204. public RewardItem(int itemId, int count)
  205. {
  206. _itemId = itemId;
  207. _count = count;
  208. }
  209. public int getItemId() { return _itemId;}
  210. public int getCount() { return _count;}
  211. }
  212. private FastMap<L2Character, AggroInfo> _aggroList = new FastMap<L2Character, AggroInfo>().shared();
  213. public final FastMap<L2Character, AggroInfo> getAggroList()
  214. {
  215. return _aggroList;
  216. }
  217. private boolean _isReturningToSpawnPoint = false;
  218. public final boolean isReturningToSpawnPoint()
  219. {
  220. return _isReturningToSpawnPoint;
  221. }
  222. public final void setisReturningToSpawnPoint(boolean value)
  223. {
  224. _isReturningToSpawnPoint = value;
  225. }
  226. private boolean _canReturnToSpawnPoint = true;
  227. public final boolean canReturnToSpawnPoint()
  228. {
  229. return _canReturnToSpawnPoint;
  230. }
  231. public final void setCanReturnToSpawnPoint(boolean value)
  232. {
  233. _canReturnToSpawnPoint = value;
  234. }
  235. private boolean _seeThroughSilentMove = false;
  236. public boolean canSeeThroughSilentMove() { return _seeThroughSilentMove; }
  237. public void setSeeThroughSilentMove(boolean val) { _seeThroughSilentMove = val; }
  238. private RewardItem[] _sweepItems;
  239. private RewardItem[] _harvestItems;
  240. private boolean _seeded;
  241. private int _seedType = 0;
  242. private int _seederObjId = 0;
  243. private boolean _overhit;
  244. private double _overhitDamage;
  245. private L2Character _overhitAttacker;
  246. private L2CommandChannel _firstCommandChannelAttacked = null;
  247. private CommandChannelTimer _commandChannelTimer = null;
  248. private long _commandChannelLastAttack = 0;
  249. private boolean _absorbed;
  250. private FastMap<Integer, AbsorberInfo> _absorbersList = new FastMap<Integer, AbsorberInfo>().shared();
  251. private boolean _mustGiveExpSp;
  252. /** True if a Dwarf has used Spoil on this L2NpcInstance */
  253. private boolean _isSpoil = false;
  254. private int _isSpoiledBy = 0;
  255. private int _onKillDelay = 5000;
  256. /**
  257. * Constructor of L2Attackable (use L2Character and L2NpcInstance constructor).
  258. *
  259. * Actions:
  260. * Call the L2Character constructor to set the _template of the L2Attackable (copy skills from template to object and link _calculators to NPC_STD_CALCULATOR)
  261. * Set the name of the L2Attackable
  262. * Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it
  263. *
  264. * @param objectId Identifier of the object to initialized
  265. * @param L2NpcTemplate Template to apply to the NPC
  266. */
  267. public L2Attackable(int objectId, L2NpcTemplate template)
  268. {
  269. super(objectId, template);
  270. setInstanceType(InstanceType.L2Attackable);
  271. setIsInvul(false);
  272. _mustGiveExpSp = true;
  273. }
  274. @Override
  275. public AttackableKnownList getKnownList()
  276. {
  277. return (AttackableKnownList)super.getKnownList();
  278. }
  279. @Override
  280. public void initKnownList()
  281. {
  282. setKnownList(new AttackableKnownList(this));
  283. }
  284. @Override
  285. public AttackableStatus getStatus()
  286. {
  287. return (AttackableStatus) super.getStatus();
  288. }
  289. @Override
  290. public void initCharStatus()
  291. {
  292. setStatus(new AttackableStatus(this));
  293. }
  294. /**
  295. * Return the L2Character AI of the L2Attackable and if its null create a new one.
  296. */
  297. @Override
  298. public L2CharacterAI getAI()
  299. {
  300. L2CharacterAI ai = _ai;
  301. if (ai == null)
  302. {
  303. synchronized(this)
  304. {
  305. if (_ai == null) _ai = new L2AttackableAI(new AIAccessor());
  306. return _ai;
  307. }
  308. }
  309. return ai;
  310. }
  311. /**
  312. * Not used.
  313. * get condition to hate, actually isAggressive() is checked by monster and karma by guards in motheds that overwrite this one.
  314. *
  315. * @deprecated
  316. */
  317. @Deprecated
  318. public boolean getCondition2(L2Character target)
  319. {
  320. if (target instanceof L2NpcInstance || target instanceof L2DoorInstance)
  321. return false;
  322. if
  323. (
  324. target.isAlikeDead()
  325. || !isInsideRadius(target, getAggroRange(), false, false)
  326. || Math.abs(getZ()-target.getZ()) > 100
  327. )
  328. return false;
  329. return !target.isInvul();
  330. }
  331. public void useMagic(L2Skill skill)
  332. {
  333. if (skill == null || isAlikeDead())
  334. return;
  335. if (skill.isPassive())
  336. return;
  337. if (isCastingNow())
  338. return;
  339. if (isSkillDisabled(skill))
  340. return;
  341. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  342. return;
  343. if (getCurrentHp() <= skill.getHpConsume())
  344. return;
  345. if (skill.isMagic())
  346. {
  347. if (isMuted())
  348. return;
  349. }
  350. else
  351. {
  352. if (isPhysicalMuted())
  353. return;
  354. }
  355. L2Object target = skill.getFirstOfTargetList(this);
  356. if (target == null)
  357. return;
  358. getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  359. }
  360. /**
  361. * Reduce the current HP of the L2Attackable.
  362. *
  363. * @param damage The HP decrease value
  364. * @param attacker The L2Character who attacks
  365. */
  366. @Override
  367. public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill)
  368. {
  369. reduceCurrentHp(damage, attacker, true, false, skill);
  370. }
  371. /**
  372. * Reduce the current HP of the L2Attackable, update its _aggroList and launch the doDie Task if necessary.
  373. *
  374. * @param i The HP decrease value
  375. * @param attacker The L2Character who attacks
  376. * @param awake The awake state (If True : stop sleeping)
  377. */
  378. @Override
  379. public void reduceCurrentHp(double damage, L2Character attacker, boolean awake, boolean isDOT, L2Skill skill)
  380. {
  381. if (isRaid() && !isMinion() && attacker != null && attacker.getParty() != null
  382. && attacker.getParty().isInCommandChannel() && attacker.getParty().getCommandChannel().meetRaidWarCondition(this))
  383. {
  384. if (_firstCommandChannelAttacked == null) //looting right isn't set
  385. {
  386. synchronized (this)
  387. {
  388. if (_firstCommandChannelAttacked == null)
  389. {
  390. _firstCommandChannelAttacked = attacker.getParty().getCommandChannel();
  391. if (_firstCommandChannelAttacked != null)
  392. {
  393. _commandChannelTimer = new CommandChannelTimer(this);
  394. _commandChannelLastAttack = System.currentTimeMillis();
  395. ThreadPoolManager.getInstance().scheduleGeneral(_commandChannelTimer, 10000); // check for last attack
  396. _firstCommandChannelAttacked.broadcastToChannelMembers(new CreatureSay(0, Say2.PARTYROOM_ALL, "", "You have looting rights!")); //TODO: retail msg
  397. }
  398. }
  399. }
  400. }
  401. else if (attacker.getParty().getCommandChannel().equals(_firstCommandChannelAttacked)) //is in same channel
  402. {
  403. _commandChannelLastAttack = System.currentTimeMillis(); // update last attack time
  404. }
  405. }
  406. if (isEventMob) return;
  407. // Add damage and hate to the attacker AggroInfo of the L2Attackable _aggroList
  408. if (attacker != null)
  409. addDamage(attacker, (int)damage, skill);
  410. // If this L2Attackable is a L2MonsterInstance and it has spawned minions, call its minions to battle
  411. if (this instanceof L2MonsterInstance)
  412. {
  413. L2MonsterInstance master = (L2MonsterInstance) this;
  414. if (master.hasMinions())
  415. master.getMinionList().onAssist(this, attacker);
  416. master = master.getLeader();
  417. if (master != null && master.hasMinions())
  418. master.getMinionList().onAssist(this, attacker);
  419. }
  420. // Reduce the current HP of the L2Attackable and launch the doDie Task if necessary
  421. super.reduceCurrentHp(damage, attacker, awake, isDOT, skill);
  422. }
  423. public synchronized void setMustRewardExpSp(boolean value)
  424. {
  425. _mustGiveExpSp = value;
  426. }
  427. public synchronized boolean getMustRewardExpSP()
  428. {
  429. return _mustGiveExpSp;
  430. }
  431. /**
  432. * Kill the L2Attackable (the corpse disappeared after 7 seconds), distribute rewards (EXP, SP, Drops...) and notify Quest Engine.
  433. *
  434. * Actions:
  435. * Distribute Exp and SP rewards to L2PcInstance (including Summon owner) that hit the L2Attackable and to their Party members
  436. * Notify the Quest Engine of the L2Attackable death if necessary
  437. * Kill the L2NpcInstance (the corpse disappeared after 7 seconds)
  438. *
  439. * Caution: This method DOESN'T GIVE rewards to L2PetInstance
  440. *
  441. * @param killer The L2Character that has killed the L2Attackable
  442. */
  443. @Override
  444. public boolean doDie(L2Character killer)
  445. {
  446. // Kill the L2NpcInstance (the corpse disappeared after 7 seconds)
  447. if (!super.doDie(killer))
  448. return false;
  449. // Notify the Quest Engine of the L2Attackable death if necessary
  450. try
  451. {
  452. L2PcInstance player = null;
  453. if (killer != null)
  454. player = killer.getActingPlayer();
  455. if (player != null)
  456. {
  457. if (getTemplate().getEventQuests(Quest.QuestEventType.ON_KILL) != null)
  458. for (Quest quest: getTemplate().getEventQuests(Quest.QuestEventType.ON_KILL))
  459. ThreadPoolManager.getInstance().scheduleEffect(new OnKillNotifyTask(this, quest, player, killer instanceof L2Summon), _onKillDelay);
  460. }
  461. }
  462. catch (Exception e) { _log.log(Level.SEVERE, "", e); }
  463. return true;
  464. }
  465. private static class OnKillNotifyTask implements Runnable
  466. {
  467. private L2Attackable _attackable;
  468. private Quest _quest;
  469. private L2PcInstance _killer;
  470. private boolean _isPet;
  471. public OnKillNotifyTask(L2Attackable attackable, Quest quest, L2PcInstance killer, boolean isPet)
  472. {
  473. _attackable = attackable;
  474. _quest = quest;
  475. _killer = killer;
  476. _isPet = isPet;
  477. }
  478. public void run()
  479. {
  480. _quest.notifyKill(_attackable, _killer, _isPet);
  481. }
  482. }
  483. /**
  484. * Distribute Exp and SP rewards to L2PcInstance (including Summon owner) that hit the L2Attackable and to their Party members.
  485. *
  486. * Actions:
  487. * Get the L2PcInstance owner of the L2SummonInstance (if necessary) and L2Party in progress
  488. * Calculate the Experience and SP rewards in function of the level difference
  489. * Add Exp and SP rewards to L2PcInstance (including Summon penalty) and to Party members in the known area of the last attacker
  490. *
  491. * Caution : This method DOESN'T GIVE rewards to L2PetInstance
  492. *
  493. * @param lastAttacker The L2Character that has killed the L2Attackable
  494. */
  495. @Override
  496. protected void calculateRewards(L2Character lastAttacker)
  497. {
  498. // Creates an empty list of rewards
  499. FastMap<L2Character, RewardInfo> rewards = new FastMap<L2Character, RewardInfo>().shared();
  500. try
  501. {
  502. if (getAggroList().isEmpty())
  503. return;
  504. // Manage Base, Quests and Sweep drops of the L2Attackable
  505. doItemDrop(lastAttacker);
  506. // Manage drop of Special Events created by GM for a defined period
  507. doEventDrop(lastAttacker);
  508. if (!getMustRewardExpSP())
  509. return;
  510. int damage;
  511. L2Character attacker, ddealer;
  512. RewardInfo reward;
  513. // While Interating over This Map Removing Object is Not Allowed
  514. //synchronized (getAggroList())
  515. {
  516. // Go through the _aggroList of the L2Attackable
  517. for (AggroInfo info : getAggroList().values())
  518. {
  519. if (info == null)
  520. continue;
  521. // Get the L2Character corresponding to this attacker
  522. attacker = info.getAttacker();
  523. // Get damages done by this attacker
  524. damage = info.getDamage();
  525. // Prevent unwanted behavior
  526. if (damage > 1)
  527. {
  528. if ((attacker instanceof L2SummonInstance) || ((attacker instanceof L2PetInstance) && ((L2PetInstance)attacker).getPetLevelData().getOwnerExpTaken() > 0))
  529. ddealer = ((L2Summon)attacker).getOwner();
  530. else
  531. ddealer = info.getAttacker();
  532. // Check if ddealer isn't too far from this (killed monster)
  533. if (!Util.checkIfInRange(Config.ALT_PARTY_RANGE, this, ddealer, true))
  534. continue;
  535. // Calculate real damages (Summoners should get own damage plus summon's damage)
  536. reward = rewards.get(ddealer);
  537. if (reward == null)
  538. reward = new RewardInfo(ddealer, damage);
  539. else
  540. reward.addDamage(damage);
  541. rewards.put(ddealer, reward);
  542. }
  543. }
  544. }
  545. if (!rewards.isEmpty())
  546. {
  547. L2Party attackerParty;
  548. long exp;
  549. int levelDiff, partyDmg, partyLvl, sp;
  550. float partyMul, penalty;
  551. RewardInfo reward2;
  552. int[] tmp;
  553. for (FastMap.Entry<L2Character, RewardInfo> entry = rewards.head(), end = rewards.tail(); (entry = entry.getNext()) != end;)
  554. {
  555. if (entry == null)
  556. continue;
  557. reward = entry.getValue();
  558. if (reward == null)
  559. continue;
  560. // Penalty applied to the attacker's XP
  561. penalty = 0;
  562. // Attacker to be rewarded
  563. attacker = reward._attacker;
  564. // Total amount of damage done
  565. damage = reward._dmg;
  566. // If the attacker is a Pet, get the party of the owner
  567. if (attacker instanceof L2PetInstance)
  568. attackerParty = ((L2PetInstance)attacker).getParty();
  569. else if (attacker instanceof L2PcInstance)
  570. attackerParty = ((L2PcInstance)attacker).getParty();
  571. else
  572. return;
  573. // If this attacker is a L2PcInstance with a summoned L2SummonInstance, get Exp Penalty applied for the current summoned L2SummonInstance
  574. if (attacker instanceof L2PcInstance && ((L2PcInstance)attacker).getPet() instanceof L2SummonInstance)
  575. penalty = ((L2SummonInstance)((L2PcInstance)attacker).getPet()).getExpPenalty();
  576. // We must avoid "over damage", if any
  577. if (damage > getMaxHp())
  578. damage = getMaxHp();
  579. // If there's NO party in progress
  580. if (attackerParty == null)
  581. {
  582. // Calculate Exp and SP rewards
  583. if (attacker.getKnownList().knowsObject(this))
  584. {
  585. // Calculate the difference of level between this attacker (L2PcInstance or L2SummonInstance owner) and the L2Attackable
  586. // mob = 24, atk = 10, diff = -14 (full xp)
  587. // mob = 24, atk = 28, diff = 4 (some xp)
  588. // mob = 24, atk = 50, diff = 26 (no xp)
  589. levelDiff = attacker.getLevel() - getLevel();
  590. tmp = calculateExpAndSp(levelDiff, damage);
  591. exp = tmp[0];
  592. exp *= 1 - penalty;
  593. sp = tmp[1];
  594. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
  595. {
  596. exp *= Config.L2JMOD_CHAMPION_REWARDS;
  597. sp *= Config.L2JMOD_CHAMPION_REWARDS;
  598. }
  599. // Check for an over-hit enabled strike
  600. if (attacker instanceof L2PcInstance)
  601. {
  602. L2PcInstance player = (L2PcInstance)attacker;
  603. if (isOverhit() && attacker == getOverhitAttacker())
  604. {
  605. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.OVER_HIT));
  606. exp += calculateOverhitExp(exp);
  607. }
  608. }
  609. // Distribute the Exp and SP between the L2PcInstance and its L2Summon
  610. if (!attacker.isDead())
  611. {
  612. long addexp = Math.round(attacker.calcStat(Stats.EXPSP_RATE, exp, null, null));
  613. int addsp = (int)attacker.calcStat(Stats.EXPSP_RATE, sp, null, null);
  614. if (attacker instanceof L2PcInstance)
  615. {
  616. if (((L2PcInstance)attacker).getSkillLevel(467) > 0)
  617. {
  618. L2Skill skill = SkillTable.getInstance().getInfo(467,((L2PcInstance)attacker).getSkillLevel(467));
  619. if (skill.getExpNeeded() <= addexp)
  620. ((L2PcInstance)attacker).absorbSoul(skill,this);
  621. }
  622. ((L2PcInstance)attacker).addExpAndSp(addexp,addsp, useVitalityRate());
  623. if (addexp > 0)
  624. ((L2PcInstance)attacker).updateVitalityPoints(getVitalityPoints(damage), true, false);
  625. }
  626. else
  627. attacker.addExpAndSp(addexp,addsp);
  628. }
  629. }
  630. }
  631. else
  632. {
  633. //share with party members
  634. partyDmg = 0;
  635. partyMul = 1.f;
  636. partyLvl = 0;
  637. // Get all L2Character that can be rewarded in the party
  638. List<L2Playable> rewardedMembers = new FastList<L2Playable>();
  639. // Go through all L2PcInstance in the party
  640. List<L2PcInstance> groupMembers;
  641. if (attackerParty.isInCommandChannel())
  642. groupMembers = attackerParty.getCommandChannel().getMembers();
  643. else
  644. groupMembers = attackerParty.getPartyMembers();
  645. for (L2PcInstance pl : groupMembers)
  646. {
  647. if (pl == null || pl.isDead())
  648. continue;
  649. // Get the RewardInfo of this L2PcInstance from L2Attackable rewards
  650. reward2 = rewards.get(pl);
  651. // If the L2PcInstance is in the L2Attackable rewards add its damages to party damages
  652. if (reward2 != null)
  653. {
  654. if (Util.checkIfInRange(Config.ALT_PARTY_RANGE, this, pl, true))
  655. {
  656. partyDmg += reward2._dmg; // Add L2PcInstance damages to party damages
  657. rewardedMembers.add(pl);
  658. if (pl.getLevel() > partyLvl)
  659. {
  660. if (attackerParty.isInCommandChannel())
  661. partyLvl = attackerParty.getCommandChannel().getLevel();
  662. else
  663. partyLvl = pl.getLevel();
  664. }
  665. }
  666. rewards.remove(pl); // Remove the L2PcInstance from the L2Attackable rewards
  667. }
  668. else
  669. {
  670. // Add L2PcInstance of the party (that have attacked or not) to members that can be rewarded
  671. // and in range of the monster.
  672. if (Util.checkIfInRange(Config.ALT_PARTY_RANGE, this, pl, true))
  673. {
  674. rewardedMembers.add(pl);
  675. if (pl.getLevel() > partyLvl)
  676. {
  677. if (attackerParty.isInCommandChannel())
  678. partyLvl = attackerParty.getCommandChannel().getLevel();
  679. else
  680. partyLvl = pl.getLevel();
  681. }
  682. }
  683. }
  684. L2Playable summon = pl.getPet();
  685. if (summon != null && summon instanceof L2PetInstance)
  686. {
  687. reward2 = rewards.get(summon);
  688. if (reward2 != null) // Pets are only added if they have done damage
  689. {
  690. if (Util.checkIfInRange(Config.ALT_PARTY_RANGE, this, summon, true))
  691. {
  692. partyDmg += reward2._dmg; // Add summon damages to party damages
  693. rewardedMembers.add(summon);
  694. if (summon.getLevel() > partyLvl)
  695. partyLvl = summon.getLevel();
  696. }
  697. rewards.remove(summon); // Remove the summon from the L2Attackable rewards
  698. }
  699. }
  700. }
  701. // If the party didn't killed this L2Attackable alone
  702. if (partyDmg < getMaxHp())
  703. partyMul = ((float)partyDmg / (float)getMaxHp());
  704. // Avoid "over damage"
  705. if (partyDmg > getMaxHp())
  706. partyDmg = getMaxHp();
  707. // Calculate the level difference between Party and L2Attackable
  708. levelDiff = partyLvl - getLevel();
  709. // Calculate Exp and SP rewards
  710. tmp = calculateExpAndSp(levelDiff, partyDmg);
  711. exp = tmp[0];
  712. sp = tmp[1];
  713. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
  714. {
  715. exp *= Config.L2JMOD_CHAMPION_REWARDS;
  716. sp *= Config.L2JMOD_CHAMPION_REWARDS;
  717. }
  718. exp *= partyMul;
  719. sp *= partyMul;
  720. // Check for an over-hit enabled strike
  721. // (When in party, the over-hit exp bonus is given to the whole party and splitted proportionally through the party members)
  722. if (attacker instanceof L2PcInstance)
  723. {
  724. L2PcInstance player = (L2PcInstance)attacker;
  725. if (isOverhit() && attacker == getOverhitAttacker())
  726. {
  727. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.OVER_HIT));
  728. exp += calculateOverhitExp(exp);
  729. }
  730. }
  731. // Distribute Experience and SP rewards to L2PcInstance Party members in the known area of the last attacker
  732. if (partyDmg > 0)
  733. attackerParty.distributeXpAndSp(exp, sp, rewardedMembers, partyLvl, partyDmg, this);
  734. }
  735. }
  736. }
  737. rewards = null;
  738. }
  739. catch (Exception e) { _log.log(Level.SEVERE, "", e); }
  740. }
  741. /**
  742. *
  743. * @see com.l2jserver.gameserver.model.actor.L2Character#addAttackerToAttackByList(com.l2jserver.gameserver.model.actor.L2Character)
  744. */
  745. @Override
  746. public void addAttackerToAttackByList (L2Character player)
  747. {
  748. if (player == null || player == this || getAttackByList().contains(player))
  749. return;
  750. getAttackByList().add(player);
  751. }
  752. /**
  753. * Add damage and hate to the attacker AggroInfo of the L2Attackable _aggroList.
  754. *
  755. * @param attacker The L2Character that gave damages to this L2Attackable
  756. * @param damage The number of damages given by the attacker L2Character
  757. *
  758. */
  759. public void addDamage(L2Character attacker, int damage, L2Skill skill)
  760. {
  761. if (attacker == null)
  762. return;
  763. // Notify the L2Attackable AI with EVT_ATTACKED
  764. if (!isDead())
  765. {
  766. try
  767. {
  768. L2PcInstance player = attacker.getActingPlayer();
  769. if (player != null)
  770. {
  771. if (getTemplate().getEventQuests(Quest.QuestEventType.ON_ATTACK) !=null)
  772. for (Quest quest: getTemplate().getEventQuests(Quest.QuestEventType.ON_ATTACK))
  773. quest.notifyAttack(this, player, damage, attacker instanceof L2Summon, skill);
  774. }
  775. // for now hard code damage hate caused by an L2Attackable
  776. else
  777. {
  778. getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, attacker);
  779. addDamageHate(attacker, damage, (damage*100)/(getLevel()+7));
  780. }
  781. }
  782. catch (Exception e) { _log.log(Level.SEVERE, "", e); }
  783. }
  784. }
  785. /**
  786. * Add damage and hate to the attacker AggroInfo of the L2Attackable _aggroList.
  787. *
  788. * @param attacker The L2Character that gave damages to this L2Attackable
  789. * @param damage The number of damages given by the attacker L2Character
  790. * @param aggro The hate (=damage) given by the attacker L2Character
  791. *
  792. */
  793. public void addDamageHate(L2Character attacker, int damage, int aggro)
  794. {
  795. if (attacker == null)
  796. return;
  797. L2PcInstance targetPlayer = attacker.getActingPlayer();
  798. // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
  799. AggroInfo ai = getAggroList().get(attacker);
  800. if (ai == null)
  801. {
  802. ai = new AggroInfo(attacker);
  803. getAggroList().put(attacker, ai);
  804. }
  805. ai.addDamage(damage);
  806. // traps does not cause aggro
  807. // making this hack because not possible to determine if damage made by trap
  808. // so just check for triggered trap here
  809. if (targetPlayer == null
  810. || targetPlayer.getTrap() == null
  811. || !targetPlayer.getTrap().isTriggered())
  812. ai.addHate(aggro);
  813. if (targetPlayer != null && aggro == 0)
  814. {
  815. if (getTemplate().getEventQuests(Quest.QuestEventType.ON_AGGRO_RANGE_ENTER) !=null)
  816. for (Quest quest: getTemplate().getEventQuests(Quest.QuestEventType.ON_AGGRO_RANGE_ENTER))
  817. quest.notifyAggroRangeEnter(this, targetPlayer, (attacker instanceof L2Summon));
  818. }
  819. else if (targetPlayer == null && aggro == 0)
  820. {
  821. aggro = 1;
  822. ai.addHate(1);
  823. }
  824. // Set the intention to the L2Attackable to AI_INTENTION_ACTIVE
  825. if (aggro > 0 && getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
  826. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  827. }
  828. public void reduceHate(L2Character target, int amount)
  829. {
  830. if (getAI() instanceof L2SiegeGuardAI || getAI() instanceof L2FortSiegeGuardAI)
  831. {
  832. // TODO: this just prevents error until siege guards are handled properly
  833. stopHating(target);
  834. setTarget(null);
  835. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  836. return;
  837. }
  838. if (target == null) // whole aggrolist
  839. {
  840. L2Character mostHated = getMostHated();
  841. if (mostHated == null) // makes target passive for a moment more
  842. {
  843. ((L2AttackableAI)getAI()).setGlobalAggro(-25);
  844. return;
  845. }
  846. else
  847. {
  848. for(L2Character aggroed : getAggroList().keySet())
  849. {
  850. AggroInfo ai = getAggroList().get(aggroed);
  851. if (ai == null)
  852. return;
  853. ai.addHate(-amount);
  854. }
  855. }
  856. amount = getHating(mostHated);
  857. if (amount <= 0)
  858. {
  859. ((L2AttackableAI)getAI()).setGlobalAggro(-25);
  860. clearAggroList();
  861. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  862. setWalking();
  863. }
  864. return;
  865. }
  866. AggroInfo ai = getAggroList().get(target);
  867. if (ai == null)
  868. return;
  869. ai.addHate(-amount);
  870. if (ai.getHate() <= 0)
  871. {
  872. if (getMostHated() == null)
  873. {
  874. ((L2AttackableAI)getAI()).setGlobalAggro(-25);
  875. clearAggroList();
  876. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  877. setWalking();
  878. }
  879. }
  880. }
  881. /**
  882. * Clears _aggroList hate of the L2Character without removing from the list.
  883. */
  884. public void stopHating(L2Character target)
  885. {
  886. if (target == null)
  887. return;
  888. AggroInfo ai = getAggroList().get(target);
  889. if (ai != null)
  890. ai.stopHate();
  891. }
  892. /**
  893. * Return the most hated L2Character of the L2Attackable _aggroList.
  894. */
  895. public L2Character getMostHated()
  896. {
  897. if (getAggroList().isEmpty() || isAlikeDead()) return null;
  898. L2Character mostHated = null;
  899. int maxHate = 0;
  900. // While Interating over This Map Removing Object is Not Allowed
  901. //synchronized (getAggroList())
  902. {
  903. // Go through the aggroList of the L2Attackable
  904. for (AggroInfo ai : getAggroList().values())
  905. {
  906. if (ai == null)
  907. continue;
  908. if (ai.checkHate(this) > maxHate)
  909. {
  910. mostHated = ai.getAttacker();
  911. maxHate = ai.getHate();
  912. }
  913. }
  914. }
  915. return mostHated;
  916. }
  917. /**
  918. * Return the 2 most hated L2Character of the L2Attackable _aggroList.
  919. */
  920. public List<L2Character> get2MostHated()
  921. {
  922. if (getAggroList().isEmpty() || isAlikeDead())
  923. return null;
  924. L2Character mostHated = null;
  925. L2Character secondMostHated = null;
  926. int maxHate = 0;
  927. List<L2Character> result = new FastList<L2Character>();
  928. // While iterating over this map removing objects is not allowed
  929. //synchronized (getAggroList())
  930. {
  931. // Go through the aggroList of the L2Attackable
  932. for (AggroInfo ai : getAggroList().values())
  933. {
  934. if (ai == null)
  935. continue;
  936. if (ai.checkHate(this) > maxHate)
  937. {
  938. secondMostHated = mostHated;
  939. mostHated = ai.getAttacker();
  940. maxHate = ai.getHate();
  941. }
  942. }
  943. }
  944. result.add(mostHated);
  945. if (getAttackByList().contains(secondMostHated))
  946. result.add(secondMostHated);
  947. else
  948. result.add(null);
  949. return result;
  950. }
  951. public List<L2Character> getHateList()
  952. {
  953. if (getAggroList().isEmpty() || isAlikeDead()) return null;
  954. List<L2Character> result = new FastList<L2Character>();
  955. //synchronized (getAggroList())
  956. {
  957. for (AggroInfo ai : getAggroList().values())
  958. {
  959. if (ai == null)
  960. continue;
  961. ai.checkHate(this);
  962. result.add(ai.getAttacker());
  963. }
  964. }
  965. return result;
  966. }
  967. /**
  968. * Return the hate level of the L2Attackable against this L2Character contained in _aggroList.
  969. *
  970. * @param target The L2Character whose hate level must be returned
  971. */
  972. public int getHating(final L2Character target)
  973. {
  974. if (getAggroList().isEmpty() || target == null)
  975. return 0;
  976. AggroInfo ai = getAggroList().get(target);
  977. if (ai == null)
  978. return 0;
  979. if (ai.getAttacker() instanceof L2PcInstance)
  980. {
  981. L2PcInstance act = (L2PcInstance)ai.getAttacker();
  982. if(act.getAppearance().getInvisible() || ai.getAttacker().isInvul()
  983. || act.isSpawnProtected())
  984. {
  985. //Remove Object Should Use This Method and Can be Blocked While Interating
  986. getAggroList().remove(target);
  987. return 0;
  988. }
  989. }
  990. if (!ai.getAttacker().isVisible())
  991. {
  992. getAggroList().remove(target);
  993. return 0;
  994. }
  995. if (ai.getAttacker().isAlikeDead())
  996. {
  997. ai.stopHate();
  998. return 0;
  999. }
  1000. return ai.getHate();
  1001. }
  1002. /**
  1003. * Calculates quantity of items for specific drop acording to current situation
  1004. *
  1005. * @param drop The L2DropData count is being calculated for
  1006. * @param lastAttacker The L2PcInstance that has killed the L2Attackable
  1007. * @param deepBlueDrop Factor to divide the drop chance
  1008. * @param levelModifier level modifier in %'s (will be subtracted from drop chance)
  1009. */
  1010. private RewardItem calculateRewardItem(L2PcInstance lastAttacker, L2DropData drop, int levelModifier, boolean isSweep)
  1011. {
  1012. // Get default drop chance
  1013. float dropChance = drop.getChance();
  1014. int deepBlueDrop = 1;
  1015. if ((!isRaid() && Config.DEEPBLUE_DROP_RULES)
  1016. || (isRaid() && Config.DEEPBLUE_DROP_RULES_RAID))
  1017. {
  1018. if (levelModifier > 0)
  1019. {
  1020. // We should multiply by the server's drop rate, so we always get a low chance of drop for deep blue mobs.
  1021. // NOTE: This is valid only for adena drops! Others drops will still obey server's rate
  1022. deepBlueDrop = 3;
  1023. if (drop.getItemId() == 57)
  1024. deepBlueDrop *= isRaid() && !isRaidMinion()? (int)Config.RATE_DROP_ITEMS_BY_RAID : (int)Config.RATE_DROP_ITEMS;
  1025. }
  1026. }
  1027. // Avoid dividing by 0
  1028. if (deepBlueDrop == 0)
  1029. deepBlueDrop = 1;
  1030. // Check if we should apply our maths so deep blue mobs will not drop that easy
  1031. if ((!isRaid() && Config.DEEPBLUE_DROP_RULES)
  1032. || (isRaid() && Config.DEEPBLUE_DROP_RULES_RAID))
  1033. dropChance = ((drop.getChance() - ((drop.getChance() * levelModifier)/100)) / deepBlueDrop);
  1034. // Applies Drop rates
  1035. if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
  1036. dropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
  1037. else if (isSweep)
  1038. dropChance *= Config.RATE_DROP_SPOIL;
  1039. else
  1040. dropChance *= isRaid() && !isRaidMinion() ? Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS;
  1041. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
  1042. dropChance *= Config.L2JMOD_CHAMPION_REWARDS;
  1043. // Round drop chance
  1044. dropChance = Math.round(dropChance);
  1045. // Set our limits for chance of drop
  1046. if (dropChance < 1)
  1047. dropChance = 1;
  1048. // Get min and max Item quantity that can be dropped in one time
  1049. int minCount = drop.getMinDrop();
  1050. int maxCount = drop.getMaxDrop();
  1051. int itemCount = 0;
  1052. // Count and chance adjustment for high rate servers
  1053. if (dropChance > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
  1054. {
  1055. int multiplier = (int)dropChance / L2DropData.MAX_CHANCE;
  1056. if (minCount < maxCount)
  1057. itemCount += Rnd.get(minCount * multiplier, maxCount * multiplier);
  1058. else if (minCount == maxCount)
  1059. itemCount += minCount * multiplier;
  1060. else
  1061. itemCount += multiplier;
  1062. dropChance = dropChance % L2DropData.MAX_CHANCE;
  1063. }
  1064. // Check if the Item must be dropped
  1065. int random = Rnd.get(L2DropData.MAX_CHANCE);
  1066. while (random < dropChance)
  1067. {
  1068. // Get the item quantity dropped
  1069. if (minCount < maxCount)
  1070. itemCount += Rnd.get(minCount, maxCount);
  1071. else if (minCount == maxCount)
  1072. itemCount += minCount;
  1073. else itemCount++;
  1074. // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
  1075. dropChance -= L2DropData.MAX_CHANCE;
  1076. }
  1077. if (Config.L2JMOD_CHAMPION_ENABLE)
  1078. // TODO (April 11, 2009): Find a way not to hardcode these values.
  1079. if ((drop.getItemId() == 57 || (drop.getItemId() >= 6360 && drop.getItemId() <= 6362)) && isChampion())
  1080. itemCount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  1081. if (itemCount > 0)
  1082. return new RewardItem(drop.getItemId(), itemCount);
  1083. else if (itemCount == 0 && Config.DEBUG)
  1084. _log.fine("Roll produced no drops.");
  1085. return null;
  1086. }
  1087. /**
  1088. * Calculates quantity of items for specific drop CATEGORY according to current situation
  1089. * Only a max of ONE item from a category is allowed to be dropped.
  1090. *
  1091. * @param drop The L2DropData count is being calculated for
  1092. * @param lastAttacker The L2PcInstance that has killed the L2Attackable
  1093. * @param deepBlueDrop Factor to divide the drop chance
  1094. * @param levelModifier level modifier in %'s (will be subtracted from drop chance)
  1095. */
  1096. private RewardItem calculateCategorizedRewardItem(L2PcInstance lastAttacker, L2DropCategory categoryDrops, int levelModifier)
  1097. {
  1098. if (categoryDrops == null)
  1099. return null;
  1100. // Get default drop chance for the category (that's the sum of chances for all items in the category)
  1101. // keep track of the base category chance as it'll be used later, if an item is drop from the category.
  1102. // for everything else, use the total "categoryDropChance"
  1103. int basecategoryDropChance = categoryDrops.getCategoryChance() ;
  1104. int categoryDropChance = basecategoryDropChance;
  1105. int deepBlueDrop = 1;
  1106. if ((!isRaid() && Config.DEEPBLUE_DROP_RULES)
  1107. || (isRaid() && Config.DEEPBLUE_DROP_RULES_RAID))
  1108. {
  1109. // We should multiply by the server's drop rate, so we always get a low chance of drop for deep blue mobs.
  1110. // NOTE: This is valid only for adena drops! Others drops will still obey server's rate
  1111. if (levelModifier > 0)
  1112. deepBlueDrop = 3;
  1113. }
  1114. // Avoid dividing by 0
  1115. if (deepBlueDrop == 0)
  1116. deepBlueDrop = 1;
  1117. // Check if we should apply our maths so deep blue mobs will not drop that easy
  1118. if ((!isRaid() && Config.DEEPBLUE_DROP_RULES)
  1119. || (isRaid() && Config.DEEPBLUE_DROP_RULES_RAID))
  1120. categoryDropChance = ((categoryDropChance - ((categoryDropChance * levelModifier)/100)) / deepBlueDrop);
  1121. // Applies Drop rates
  1122. categoryDropChance *= isRaid() && !isRaidMinion() ? Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS;
  1123. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
  1124. categoryDropChance *= Config.L2JMOD_CHAMPION_REWARDS;
  1125. // Round drop chance
  1126. categoryDropChance = Math.round(categoryDropChance);
  1127. // Set our limits for chance of drop
  1128. if (categoryDropChance < 1)
  1129. categoryDropChance = 1;
  1130. // Check if an Item from this category must be dropped
  1131. if (Rnd.get(L2DropData.MAX_CHANCE) < categoryDropChance)
  1132. {
  1133. L2DropData drop = categoryDrops.dropOne(isRaid() && !isRaidMinion());
  1134. if (drop == null)
  1135. return null;
  1136. // Now decide the quantity to drop based on the rates and penalties. To get this value
  1137. // simply divide the modified categoryDropChance by the base category chance. This
  1138. // results in a chance that will dictate the drops amounts: for each amount over 100
  1139. // that it is, it will give another chance to add to the min/max quantities.
  1140. // For example, If the final chance is 120%, then the item should drop between
  1141. // its min and max one time, and then have 20% chance to drop again. If the final
  1142. // chance is 330%, it will similarly give 3 times the min and max, and have a 30%
  1143. // chance to give a 4th time.
  1144. // At least 1 item will be dropped for sure. So the chance will be adjusted to 100%
  1145. // if smaller.
  1146. int dropChance = drop.getChance();
  1147. if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
  1148. dropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
  1149. else
  1150. dropChance *= isRaid() && !isRaidMinion() ? Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS;
  1151. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
  1152. dropChance *= Config.L2JMOD_CHAMPION_REWARDS;
  1153. dropChance = Math.round(dropChance);
  1154. if (dropChance < L2DropData.MAX_CHANCE)
  1155. dropChance = L2DropData.MAX_CHANCE;
  1156. // Get min and max Item quantity that can be dropped in one time
  1157. int min = drop.getMinDrop();
  1158. int max = drop.getMaxDrop();
  1159. // Get the item quantity dropped
  1160. int itemCount = 0;
  1161. // Count and chance adjustment for high rate servers
  1162. if (dropChance > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
  1163. {
  1164. int multiplier = dropChance / L2DropData.MAX_CHANCE;
  1165. if (min < max)
  1166. itemCount += Rnd.get(min * multiplier, max * multiplier);
  1167. else if (min == max)
  1168. itemCount += min * multiplier;
  1169. else
  1170. itemCount += multiplier;
  1171. dropChance = dropChance % L2DropData.MAX_CHANCE;
  1172. }
  1173. // Check if the Item must be dropped
  1174. int random = Rnd.get(L2DropData.MAX_CHANCE);
  1175. while (random < dropChance)
  1176. {
  1177. // Get the item quantity dropped
  1178. if (min < max)
  1179. itemCount += Rnd.get(min, max);
  1180. else if (min == max)
  1181. itemCount += min;
  1182. else
  1183. itemCount++;
  1184. // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
  1185. dropChance -= L2DropData.MAX_CHANCE;
  1186. }
  1187. if (Config.L2JMOD_CHAMPION_ENABLE)
  1188. // TODO (April 11, 2009): Find a way not to hardcode these values.
  1189. if ((drop.getItemId() == 57 || (drop.getItemId() >= 6360 && drop.getItemId() <= 6362)) && isChampion())
  1190. itemCount *= Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  1191. if (!Config.MULTIPLE_ITEM_DROP && !ItemTable.getInstance().getTemplate(drop.getItemId()).isStackable() && itemCount > 1)
  1192. itemCount = 1;
  1193. if (itemCount > 0)
  1194. return new RewardItem(drop.getItemId(), itemCount);
  1195. else if (itemCount == 0 && Config.DEBUG)
  1196. _log.fine("Roll produced no drops.");
  1197. }
  1198. return null;
  1199. }
  1200. /**
  1201. * Calculates the level modifier for drop
  1202. *
  1203. * @param lastAttacker The L2PcInstance that has killed the L2Attackable
  1204. */
  1205. private int calculateLevelModifierForDrop(L2PcInstance lastAttacker)
  1206. {
  1207. if ((!isRaid() && Config.DEEPBLUE_DROP_RULES)
  1208. || (isRaid() && Config.DEEPBLUE_DROP_RULES_RAID))
  1209. {
  1210. int highestLevel = lastAttacker.getLevel();
  1211. // Check to prevent very high level player to nearly kill mob and let low level player do the last hit.
  1212. if (!getAttackByList().isEmpty())
  1213. {
  1214. for (L2Character atkChar: getAttackByList())
  1215. if (atkChar != null && atkChar.getLevel() > highestLevel)
  1216. highestLevel = atkChar.getLevel();
  1217. }
  1218. // According to official data (Prima), deep blue mobs are 9 or more levels below players
  1219. if (highestLevel - 9 >= getLevel())
  1220. return ((highestLevel - (getLevel() + 8)) * 9);
  1221. }
  1222. return 0;
  1223. }
  1224. private RewardItem calculateCategorizedHerbItem(L2PcInstance lastAttacker, L2DropCategory categoryDrops)
  1225. {
  1226. if (categoryDrops == null)
  1227. return null;
  1228. // Get default drop chance for the category (that's the sum of chances for all items in the category)
  1229. // keep track of the base category chance as it'll be used later, if an item is drop from the category.
  1230. // for everything else, use the total "categoryDropChance"
  1231. int basecategoryDropChance = categoryDrops.getCategoryChance() ;
  1232. int categoryDropChance = basecategoryDropChance;
  1233. // Applies Drop rates
  1234. switch(categoryDrops.getCategoryType())
  1235. {
  1236. case 0:
  1237. if (Config.ENABLE_DROP_VITALITY_HERBS)
  1238. categoryDropChance *= Config.RATE_DROP_VITALITY_HERBS;
  1239. else
  1240. return null;
  1241. break;
  1242. case 1:
  1243. categoryDropChance *= Config.RATE_DROP_HP_HERBS;
  1244. break;
  1245. case 2:
  1246. categoryDropChance *= Config.RATE_DROP_MP_HERBS;
  1247. break;
  1248. case 3:
  1249. categoryDropChance *= Config.RATE_DROP_SPECIAL_HERBS;
  1250. break;
  1251. default:
  1252. categoryDropChance *= Config.RATE_DROP_COMMON_HERBS;
  1253. }
  1254. // Round drop chance
  1255. categoryDropChance = Math.round(categoryDropChance);
  1256. // Set our limits for chance of drop
  1257. if (categoryDropChance < 1)
  1258. categoryDropChance = 1;
  1259. // Check if an Item from this category must be dropped
  1260. if (Rnd.get(L2DropData.MAX_CHANCE) < categoryDropChance)
  1261. {
  1262. L2DropData drop = categoryDrops.dropOne(false);
  1263. if (drop == null)
  1264. return null;
  1265. // Now decide the quantity to drop based on the rates and penalties. To get this value
  1266. // simply divide the modified categoryDropChance by the base category chance. This
  1267. // results in a chance that will dictate the drops amounts: for each amount over 100
  1268. // that it is, it will give another chance to add to the min/max quantities.
  1269. // For example, If the final chance is 120%, then the item should drop between
  1270. // its min and max one time, and then have 20% chance to drop again. If the final
  1271. // chance is 330%, it will similarly give 3 times the min and max, and have a 30%
  1272. // chance to give a 4th time.
  1273. // At least 1 item will be dropped for sure. So the chance will be adjusted to 100%
  1274. // if smaller.
  1275. int dropChance = drop.getChance();
  1276. switch(categoryDrops.getCategoryType())
  1277. {
  1278. case 0:
  1279. dropChance *= Config.RATE_DROP_VITALITY_HERBS;
  1280. break;
  1281. case 1:
  1282. dropChance *= Config.RATE_DROP_HP_HERBS;
  1283. break;
  1284. case 2:
  1285. dropChance *= Config.RATE_DROP_MP_HERBS;
  1286. break;
  1287. case 3:
  1288. dropChance *= Config.RATE_DROP_SPECIAL_HERBS;
  1289. break;
  1290. default:
  1291. dropChance *= Config.RATE_DROP_COMMON_HERBS;
  1292. }
  1293. dropChance = Math.round(dropChance);
  1294. if (dropChance < L2DropData.MAX_CHANCE)
  1295. dropChance = L2DropData.MAX_CHANCE;
  1296. // Get min and max Item quantity that can be dropped in one time
  1297. int min = drop.getMinDrop();
  1298. int max = drop.getMaxDrop();
  1299. // Get the item quantity dropped
  1300. int itemCount = 0;
  1301. // Count and chance adjustment for high rate servers
  1302. if (dropChance > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
  1303. {
  1304. int multiplier = dropChance / L2DropData.MAX_CHANCE;
  1305. if (min < max)
  1306. itemCount += Rnd.get(min * multiplier, max * multiplier);
  1307. else if (min == max)
  1308. itemCount += min * multiplier;
  1309. else
  1310. itemCount += multiplier;
  1311. dropChance = dropChance % L2DropData.MAX_CHANCE;
  1312. }
  1313. // Check if the Item must be dropped
  1314. int random = Rnd.get(L2DropData.MAX_CHANCE);
  1315. while (random < dropChance)
  1316. {
  1317. // Get the item quantity dropped
  1318. if (min < max)
  1319. itemCount += Rnd.get(min, max);
  1320. else if (min == max)
  1321. itemCount += min;
  1322. else
  1323. itemCount++;
  1324. // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
  1325. dropChance -= L2DropData.MAX_CHANCE;
  1326. }
  1327. if (itemCount > 0)
  1328. return new RewardItem(drop.getItemId(), itemCount);
  1329. else if (itemCount == 0 && Config.DEBUG)
  1330. _log.fine("Roll produced no drops.");
  1331. }
  1332. return null;
  1333. }
  1334. public void doItemDrop(L2Character lastAttacker)
  1335. {
  1336. doItemDrop(getTemplate(),lastAttacker);
  1337. }
  1338. /**
  1339. * Manage Base, Quests and Special Events drops of L2Attackable (called by calculateRewards).
  1340. *
  1341. * Concept:
  1342. * During a Special Event all L2Attackable can drop extra Items.
  1343. * Those extra Items are defined in the table allNpcDateDrops of the EventDroplist.
  1344. * Each Special Event has a start and end date to stop to drop extra Items automaticaly.
  1345. *
  1346. * Actions:
  1347. * Manage drop of Special Events created by GM for a defined period
  1348. * Get all possible drops of this L2Attackable from L2NpcTemplate and add it Quest drops
  1349. * For each possible drops (base + quests), calculate which one must be dropped (random)
  1350. * Get each Item quantity dropped (random)
  1351. * Create this or these L2ItemInstance corresponding to each Item Identifier dropped
  1352. * If the autoLoot mode is actif and if the L2Character that has killed the L2Attackable is a L2PcInstance, Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1353. * If the autoLoot mode isn't actif or if the L2Character that has killed the L2Attackable is not a L2PcInstance, add this or these item(s) in the world as a visible object at the position where mob was last
  1354. *
  1355. * @param lastAttacker The L2Character that has killed the L2Attackable
  1356. */
  1357. public void doItemDrop(L2NpcTemplate npcTemplate, L2Character lastAttacker)
  1358. {
  1359. if (lastAttacker == null)
  1360. return;
  1361. L2PcInstance player = lastAttacker.getActingPlayer();
  1362. // Don't drop anything if the last attacker or owner isn't L2PcInstance
  1363. if (player == null)
  1364. return;
  1365. // level modifier in %'s (will be subtracted from drop chance)
  1366. int levelModifier = calculateLevelModifierForDrop(player);
  1367. CursedWeaponsManager.getInstance().checkDrop(this, player);
  1368. // now throw all categorized drops and handle spoil.
  1369. if (npcTemplate.getDropData()!=null)
  1370. {
  1371. for(L2DropCategory cat:npcTemplate.getDropData())
  1372. {
  1373. RewardItem item = null;
  1374. if (cat.isSweep())
  1375. {
  1376. // according to sh1ny, seeded mobs CAN be spoiled and swept.
  1377. if ( isSpoil()/* && !isSeeded() */)
  1378. {
  1379. FastList<RewardItem> sweepList = new FastList<RewardItem>();
  1380. for(L2DropData drop: cat.getAllDrops() )
  1381. {
  1382. item = calculateRewardItem(player, drop, levelModifier, true);
  1383. if (item == null)
  1384. continue;
  1385. if (Config.DEBUG)
  1386. _log.fine("Item id to spoil: " + item.getItemId() + " amount: " + item.getCount());
  1387. sweepList.add(item);
  1388. }
  1389. // Set the table _sweepItems of this L2Attackable
  1390. if (!sweepList.isEmpty())
  1391. _sweepItems = sweepList.toArray(new RewardItem[sweepList.size()]);
  1392. }
  1393. }
  1394. else
  1395. {
  1396. if (isSeeded())
  1397. {
  1398. L2DropData drop = cat.dropSeedAllowedDropsOnly();
  1399. if (drop == null)
  1400. continue;
  1401. item = calculateRewardItem(player, drop, levelModifier, false);
  1402. }
  1403. else
  1404. item = calculateCategorizedRewardItem(player, cat, levelModifier);
  1405. if (item != null)
  1406. {
  1407. if (Config.DEBUG)
  1408. _log.fine("Item id to drop: " + item.getItemId() + " amount: " + item.getCount());
  1409. // Check if the autoLoot mode is active
  1410. if (isFlying()
  1411. || (!isRaid() && Config.AUTO_LOOT)
  1412. || (isRaid() && Config.AUTO_LOOT_RAIDS))
  1413. player.doAutoLoot(this, item); // Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1414. else
  1415. dropItem(player, item); // drop the item on the ground
  1416. // Broadcast message if RaidBoss was defeated
  1417. if (isRaid() && !isRaidMinion())
  1418. {
  1419. SystemMessage sm;
  1420. sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DIED_DROPPED_S3_S2);
  1421. sm.addCharName(this);
  1422. sm.addItemName(item.getItemId());
  1423. sm.addItemNumber(item.getCount());
  1424. broadcastPacket(sm);
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. // Apply Special Item drop with random(rnd) quantity(qty) for champions.
  1431. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && (Config.L2JMOD_CHAMPION_REWARD_LOWER_LVL_ITEM_CHANCE > 0 || Config.L2JMOD_CHAMPION_REWARD_HIGHER_LVL_ITEM_CHANCE > 0))
  1432. {
  1433. int champqty = Rnd.get(Config.L2JMOD_CHAMPION_REWARD_QTY);
  1434. RewardItem item = new RewardItem(Config.L2JMOD_CHAMPION_REWARD_ID,++champqty);
  1435. if (player.getLevel() <= getLevel() && (Rnd.get(100) < Config.L2JMOD_CHAMPION_REWARD_LOWER_LVL_ITEM_CHANCE))
  1436. {
  1437. if (Config.AUTO_LOOT || isFlying())
  1438. player.addItem("ChampionLoot", item.getItemId(), item.getCount(), this, true); // Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1439. else
  1440. dropItem(player, item);
  1441. }
  1442. else if (player.getLevel() > getLevel() && (Rnd.get(100) < Config.L2JMOD_CHAMPION_REWARD_HIGHER_LVL_ITEM_CHANCE))
  1443. {
  1444. if (Config.AUTO_LOOT || isFlying())
  1445. player.addItem("ChampionLoot", item.getItemId(), item.getCount(), this, true); // Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1446. else
  1447. dropItem(player, item);
  1448. }
  1449. }
  1450. //Instant Item Drop :>
  1451. if (getTemplate().dropherbgroup > 0)
  1452. {
  1453. for(L2DropCategory cat : HerbDropTable.getInstance().getHerbDroplist(getTemplate().dropherbgroup))
  1454. {
  1455. RewardItem item = calculateCategorizedHerbItem(player, cat);
  1456. if (item != null)
  1457. {
  1458. // more than one herb cant be auto looted!
  1459. int count = item.getCount();
  1460. if (count > 1)
  1461. {
  1462. item._count = 1;
  1463. for(int i = 0; i < count; i++)
  1464. dropItem(player, item);
  1465. }
  1466. else if (isFlying() || Config.AUTO_LOOT_HERBS)
  1467. player.addItem("Loot", item.getItemId(), count, this, true);
  1468. else
  1469. dropItem(player, item);
  1470. }
  1471. }
  1472. }
  1473. }
  1474. /**
  1475. * Manage Special Events drops created by GM for a defined period.
  1476. *
  1477. * Concept:
  1478. * During a Special Event all L2Attackable can drop extra Items.
  1479. * Those extra Items are defined in the table allNpcDateDrops of the EventDroplist.
  1480. * Each Special Event has a start and end date to stop to drop extra Items automaticaly.
  1481. *
  1482. * Actions: <I>If an extra drop must be generated</I>
  1483. * Get an Item Identifier (random) from the DateDrop Item table of this Event
  1484. * Get the Item quantity dropped (random)
  1485. * Create this or these L2ItemInstance corresponding to this Item Identifier
  1486. * If the autoLoot mode is actif and if the L2Character that has killed the L2Attackable is a L2PcInstance, Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1487. * If the autoLoot mode isn't actif or if the L2Character that has killed the L2Attackable is not a L2PcInstance, add this or these item(s) in the world as a visible object at the position where mob was last
  1488. *
  1489. * @param lastAttacker The L2Character that has killed the L2Attackable
  1490. */
  1491. public void doEventDrop(L2Character lastAttacker)
  1492. {
  1493. if (lastAttacker == null)
  1494. return;
  1495. L2PcInstance player = lastAttacker.getActingPlayer();
  1496. // Don't drop anything if the last attacker or owner isn't L2PcInstance
  1497. if (player == null)
  1498. return;
  1499. if (player.getLevel() - getLevel() > 9)
  1500. return;
  1501. // Go through DateDrop of EventDroplist allNpcDateDrops within the date range
  1502. for (DateDrop drop : EventDroplist.getInstance().getAllDrops())
  1503. {
  1504. if (Rnd.get(L2DropData.MAX_CHANCE) < drop.chance)
  1505. {
  1506. RewardItem item = new RewardItem(drop.items[Rnd.get(drop.items.length)], Rnd.get(drop.min, drop.max));
  1507. if (Config.AUTO_LOOT || isFlying())
  1508. player.doAutoLoot(this, item); // Give the item(s) to the L2PcInstance that has killed the L2Attackable
  1509. else
  1510. dropItem(player, item); // drop the item on the ground
  1511. }
  1512. }
  1513. }
  1514. /**
  1515. * Drop reward item.
  1516. */
  1517. public L2ItemInstance dropItem(L2PcInstance lastAttacker, RewardItem item)
  1518. {
  1519. int randDropLim = 70;
  1520. L2ItemInstance ditem = null;
  1521. for (int i = 0; i < item.getCount(); i++)
  1522. {
  1523. // Randomize drop position
  1524. int newX = getX() + Rnd.get(randDropLim * 2 + 1) - randDropLim;
  1525. int newY = getY() + Rnd.get(randDropLim * 2 + 1) - randDropLim;
  1526. int newZ = Math.max(getZ(), lastAttacker.getZ()) + 20; // TODO: temp hack, do somethign nicer when we have geodatas
  1527. if (ItemTable.getInstance().getTemplate(item.getItemId()) != null)
  1528. {
  1529. // Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
  1530. ditem = ItemTable.getInstance().createItem("Loot", item.getItemId(), item.getCount(), lastAttacker, this);
  1531. ditem.dropMe(this, newX, newY, newZ);
  1532. // Add drop to auto destroy item task
  1533. if (!Config.LIST_PROTECTED_ITEMS.contains(item.getItemId()))
  1534. {
  1535. if ((Config.AUTODESTROY_ITEM_AFTER > 0 && ditem.getItemType() != L2EtcItemType.HERB) || (Config.HERB_AUTO_DESTROY_TIME > 0 && ditem.getItemType() == L2EtcItemType.HERB))
  1536. ItemsAutoDestroy.getInstance().addItem(ditem);
  1537. }
  1538. ditem.setProtected(false);
  1539. // If stackable, end loop as entire count is included in 1 instance of item
  1540. if (ditem.isStackable() || !Config.MULTIPLE_ITEM_DROP)
  1541. break;
  1542. }
  1543. else
  1544. _log.log(Level.SEVERE, "Item doesn't exist so cannot be dropped. Item ID: " + item.getItemId());
  1545. }
  1546. return ditem;
  1547. }
  1548. public L2ItemInstance dropItem(L2PcInstance lastAttacker, int itemId, int itemCount)
  1549. {
  1550. return dropItem(lastAttacker, new RewardItem(itemId, itemCount));
  1551. }
  1552. /**
  1553. * Return the active weapon of this L2Attackable (= null).
  1554. */
  1555. public L2ItemInstance getActiveWeapon()
  1556. {
  1557. return null;
  1558. }
  1559. /**
  1560. * Return True if the _aggroList of this L2Attackable is Empty.
  1561. */
  1562. public boolean noTarget()
  1563. {
  1564. return getAggroList().isEmpty();
  1565. }
  1566. /**
  1567. * Return True if the _aggroList of this L2Attackable contains the L2Character.
  1568. *
  1569. * @param player The L2Character searched in the _aggroList of the L2Attackable
  1570. */
  1571. public boolean containsTarget(L2Character player)
  1572. {
  1573. return getAggroList().containsKey(player);
  1574. }
  1575. /**
  1576. * Clear the _aggroList of the L2Attackable.
  1577. */
  1578. public void clearAggroList()
  1579. {
  1580. getAggroList().clear();
  1581. // clear overhit values
  1582. _overhit = false;
  1583. _overhitDamage = 0;
  1584. _overhitAttacker = null;
  1585. }
  1586. /**
  1587. * Return True if a Dwarf use Sweep on the L2Attackable and if item can be spoiled.
  1588. */
  1589. public boolean isSweepActive()
  1590. {
  1591. return _sweepItems != null;
  1592. }
  1593. /**
  1594. * Return table containing all L2ItemInstance that can be spoiled.
  1595. */
  1596. public synchronized RewardItem[] takeSweep()
  1597. {
  1598. RewardItem[] sweep = _sweepItems;
  1599. _sweepItems = null;
  1600. return sweep;
  1601. }
  1602. /**
  1603. * Return table containing all L2ItemInstance that can be harvested.
  1604. */
  1605. public synchronized RewardItem[] takeHarvest()
  1606. {
  1607. RewardItem[] harvest = _harvestItems;
  1608. _harvestItems = null;
  1609. return harvest;
  1610. }
  1611. /**
  1612. * Set the over-hit flag on the L2Attackable.
  1613. *
  1614. * @param status The status of the over-hit flag
  1615. *
  1616. */
  1617. public void overhitEnabled(boolean status)
  1618. {
  1619. _overhit = status;
  1620. }
  1621. /**
  1622. * Set the over-hit values like the attacker who did the strike and the amount of damage done by the skill.
  1623. *
  1624. * @param attacker The L2Character who hit on the L2Attackable using the over-hit enabled skill
  1625. * @param damage The ammount of damage done by the over-hit enabled skill on the L2Attackable
  1626. *
  1627. */
  1628. public void setOverhitValues(L2Character attacker, double damage)
  1629. {
  1630. // Calculate the over-hit damage
  1631. // Ex: mob had 10 HP left, over-hit skill did 50 damage total, over-hit damage is 40
  1632. double overhitDmg = ((getCurrentHp() - damage) * (-1));
  1633. if (overhitDmg < 0)
  1634. {
  1635. // we didn't killed the mob with the over-hit strike. (it wasn't really an over-hit strike)
  1636. // let's just clear all the over-hit related values
  1637. overhitEnabled(false);
  1638. _overhitDamage = 0;
  1639. _overhitAttacker = null;
  1640. return;
  1641. }
  1642. overhitEnabled(true);
  1643. _overhitDamage = overhitDmg;
  1644. _overhitAttacker = attacker;
  1645. }
  1646. /**
  1647. * Return the L2Character who hit on the L2Attackable using an over-hit enabled skill.
  1648. *
  1649. * @return L2Character attacker
  1650. */
  1651. public L2Character getOverhitAttacker()
  1652. {
  1653. return _overhitAttacker;
  1654. }
  1655. /**
  1656. * Return the ammount of damage done on the L2Attackable using an over-hit enabled skill.
  1657. *
  1658. * @return double damage
  1659. */
  1660. public double getOverhitDamage()
  1661. {
  1662. return _overhitDamage;
  1663. }
  1664. /**
  1665. * Return True if the L2Attackable was hit by an over-hit enabled skill.
  1666. */
  1667. public boolean isOverhit()
  1668. {
  1669. return _overhit;
  1670. }
  1671. /**
  1672. * Activate the absorbed soul condition on the L2Attackable.
  1673. */
  1674. public void absorbSoul()
  1675. {
  1676. _absorbed = true;
  1677. }
  1678. /**
  1679. * Return True if the L2Attackable had his soul absorbed.
  1680. */
  1681. public boolean isAbsorbed()
  1682. {
  1683. return _absorbed;
  1684. }
  1685. /**
  1686. * Adds an attacker that successfully absorbed the soul of this L2Attackable into the _absorbersList.
  1687. *
  1688. * Params:
  1689. * attacker - a valid L2PcInstance
  1690. * condition - an integer indicating the event when mob dies. This should be:
  1691. * = 0 - "the crystal scatters";
  1692. * = 1 - "the crystal failed to absorb. nothing happens";
  1693. * = 2 - "the crystal resonates because you got more than 1 crystal on you";
  1694. * = 3 - "the crystal cannot absorb the soul because the mob level is too low";
  1695. * = 4 - "the crystal successfuly absorbed the soul";
  1696. */
  1697. public void addAbsorber(L2PcInstance attacker)
  1698. {
  1699. // If we have no _absorbersList initiated, do it
  1700. AbsorberInfo ai = _absorbersList.get(attacker.getObjectId());
  1701. // If the L2Character attacker isn't already in the _absorbersList of this L2Attackable, add it
  1702. if (ai == null)
  1703. {
  1704. ai = new AbsorberInfo(attacker.getObjectId(), getCurrentHp());
  1705. _absorbersList.put(attacker.getObjectId(), ai);
  1706. }
  1707. else
  1708. {
  1709. ai._objId = attacker.getObjectId();
  1710. ai._absorbedHP = getCurrentHp();
  1711. }
  1712. // Set this L2Attackable as absorbed
  1713. absorbSoul();
  1714. }
  1715. public void resetAbsorbList()
  1716. {
  1717. _absorbed = false;
  1718. _absorbersList.clear();
  1719. }
  1720. public FastMap<Integer, AbsorberInfo> getAbsorbersList()
  1721. {
  1722. return _absorbersList;
  1723. }
  1724. /**
  1725. * Calculate the Experience and SP to distribute to attacker (L2PcInstance, L2SummonInstance or L2Party) of the L2Attackable.
  1726. *
  1727. * @param diff The difference of level between attacker (L2PcInstance, L2SummonInstance or L2Party) and the L2Attackable
  1728. * @param damage The damages given by the attacker (L2PcInstance, L2SummonInstance or L2Party)
  1729. *
  1730. */
  1731. private int[] calculateExpAndSp(int diff, int damage)
  1732. {
  1733. double xp;
  1734. double sp;
  1735. if (diff < -5)
  1736. diff = -5; // makes possible to use ALT_GAME_EXPONENT configuration
  1737. xp = (double)getExpReward() * damage / getMaxHp();
  1738. if (Config.ALT_GAME_EXPONENT_XP != 0)
  1739. xp *= Math.pow(2., -diff / Config.ALT_GAME_EXPONENT_XP);
  1740. sp = (double)getSpReward() * damage / getMaxHp();
  1741. if (Config.ALT_GAME_EXPONENT_SP != 0)
  1742. sp *= Math.pow(2., -diff / Config.ALT_GAME_EXPONENT_SP);
  1743. if (Config.ALT_GAME_EXPONENT_XP == 0 && Config.ALT_GAME_EXPONENT_SP == 0)
  1744. {
  1745. if (diff > 5) // formula revised May 07
  1746. {
  1747. double pow = Math.pow((double)5/6, diff-5);
  1748. xp = xp*pow;
  1749. sp = sp*pow;
  1750. }
  1751. if (xp <= 0)
  1752. {
  1753. xp = 0;
  1754. sp = 0;
  1755. }
  1756. else if (sp <= 0)
  1757. sp = 0;
  1758. }
  1759. int[] tmp = { (int)xp, (int)sp };
  1760. return tmp;
  1761. }
  1762. public long calculateOverhitExp(long normalExp)
  1763. {
  1764. // Get the percentage based on the total of extra (over-hit) damage done relative to the total (maximum) ammount of HP on the L2Attackable
  1765. double overhitPercentage = ((getOverhitDamage() * 100) / getMaxHp());
  1766. // Over-hit damage percentages are limited to 25% max
  1767. if (overhitPercentage > 25)
  1768. overhitPercentage = 25;
  1769. // Get the overhit exp bonus according to the above over-hit damage percentage
  1770. // (1/1 basis - 13% of over-hit damage, 13% of extra exp is given, and so on...)
  1771. double overhitExp = ((overhitPercentage / 100) * normalExp);
  1772. // Return the rounded ammount of exp points to be added to the player's normal exp reward
  1773. long bonusOverhit = Math.round(overhitExp);
  1774. return bonusOverhit;
  1775. }
  1776. /**
  1777. * Return True.
  1778. */
  1779. @Override
  1780. public boolean isAttackable()
  1781. {
  1782. return true;
  1783. }
  1784. @Override
  1785. public void onSpawn()
  1786. {
  1787. super.onSpawn();
  1788. // Clear mob spoil, seed
  1789. setSpoil(false);
  1790. // Clear all aggro char from list
  1791. clearAggroList();
  1792. // Clear Harvester Rewrard List
  1793. _harvestItems = null;
  1794. // Clear mod Seeded stat
  1795. _seeded = false;
  1796. _seedType = 0;
  1797. _seederObjId = 0;
  1798. // Clear overhit value
  1799. overhitEnabled(false);
  1800. _sweepItems = null;
  1801. resetAbsorbList();
  1802. setWalking();
  1803. // check the region where this mob is, do not activate the AI if region is inactive.
  1804. if (!isInActiveRegion())
  1805. {
  1806. if (hasAI())
  1807. getAI().stopAITask();
  1808. }
  1809. }
  1810. /**
  1811. * Return True if this L2NpcInstance has drops that can be sweeped.<BR><BR>
  1812. */
  1813. public boolean isSpoil()
  1814. {
  1815. return _isSpoil;
  1816. }
  1817. /**
  1818. * Set the spoil state of this L2NpcInstance.<BR><BR>
  1819. */
  1820. public void setSpoil(boolean isSpoil)
  1821. {
  1822. _isSpoil = isSpoil;
  1823. }
  1824. public final int getIsSpoiledBy()
  1825. {
  1826. return _isSpoiledBy;
  1827. }
  1828. public final void setIsSpoiledBy(int value)
  1829. {
  1830. _isSpoiledBy = value;
  1831. }
  1832. /**
  1833. * Sets state of the mob to seeded. Paramets needed to be set before.
  1834. */
  1835. public void setSeeded(L2PcInstance seeder)
  1836. {
  1837. if (_seedType != 0 && _seederObjId == seeder.getObjectId())
  1838. setSeeded(_seedType, seeder.getLevel());
  1839. }
  1840. /**
  1841. * Sets the seed parameters, but not the seed state
  1842. * @param id - id of the seed
  1843. * @param seeder - player who is sowind the seed
  1844. */
  1845. public void setSeeded(int id, L2PcInstance seeder)
  1846. {
  1847. if (!_seeded)
  1848. {
  1849. _seedType = id;
  1850. _seederObjId = seeder.getObjectId();
  1851. }
  1852. }
  1853. private void setSeeded(int id, int seederLvl)
  1854. {
  1855. _seeded = true;
  1856. _seedType = id;
  1857. int count = 1;
  1858. Map<Integer, L2Skill> skills = getTemplate().getSkills();
  1859. if (skills != null)
  1860. {
  1861. for (int skillId : skills.keySet())
  1862. {
  1863. switch (skillId)
  1864. {
  1865. case 4303: //Strong type x2
  1866. count *= 2;
  1867. break;
  1868. case 4304: //Strong type x3
  1869. count *= 3;
  1870. break;
  1871. case 4305: //Strong type x4
  1872. count *= 4;
  1873. break;
  1874. case 4306: //Strong type x5
  1875. count *= 5;
  1876. break;
  1877. case 4307: //Strong type x6
  1878. count *= 6;
  1879. break;
  1880. case 4308: //Strong type x7
  1881. count *= 7;
  1882. break;
  1883. case 4309: //Strong type x8
  1884. count *= 8;
  1885. break;
  1886. case 4310: //Strong type x9
  1887. count *= 9;
  1888. break;
  1889. }
  1890. }
  1891. }
  1892. int diff = (getLevel() - (L2Manor.getInstance().getSeedLevel(_seedType) - 5));
  1893. // hi-lvl mobs bonus
  1894. if (diff > 0)
  1895. count += diff;
  1896. FastList<RewardItem> harvested = new FastList<RewardItem>();
  1897. harvested.add(new RewardItem(L2Manor.getInstance().getCropType(_seedType), count* Config.RATE_DROP_MANOR));
  1898. _harvestItems = harvested.toArray(new RewardItem[harvested.size()]);
  1899. }
  1900. public int getSeederId()
  1901. {
  1902. return _seederObjId;
  1903. }
  1904. public int getSeedType()
  1905. {
  1906. return _seedType;
  1907. }
  1908. public boolean isSeeded()
  1909. {
  1910. return _seeded;
  1911. }
  1912. /**
  1913. * Set delay for onKill() call, in ms
  1914. * Default: 5000 ms
  1915. * @param delay
  1916. */
  1917. public final void setOnKillDelay(int delay)
  1918. {
  1919. _onKillDelay = delay;
  1920. }
  1921. /**
  1922. * Check if the server allows Random Animation.
  1923. */
  1924. // This is located here because L2Monster and L2FriendlyMob both extend this class. The other non-pc instances extend either L2NpcInstance or L2MonsterInstance.
  1925. @Override
  1926. public boolean hasRandomAnimation()
  1927. {
  1928. return ((Config.MAX_MONSTER_ANIMATION > 0) && !(this instanceof L2GrandBossInstance));
  1929. }
  1930. @Override
  1931. public boolean isMob()
  1932. {
  1933. return true; // This means we use MAX_MONSTER_ANIMATION instead of MAX_NPC_ANIMATION
  1934. }
  1935. protected void setCommandChannelTimer(CommandChannelTimer commandChannelTimer)
  1936. {
  1937. _commandChannelTimer = commandChannelTimer;
  1938. }
  1939. public CommandChannelTimer getCommandChannelTimer()
  1940. {
  1941. return _commandChannelTimer;
  1942. }
  1943. public L2CommandChannel getFirstCommandChannelAttacked()
  1944. {
  1945. return _firstCommandChannelAttacked;
  1946. }
  1947. public void setFirstCommandChannelAttacked(L2CommandChannel firstCommandChannelAttacked)
  1948. {
  1949. _firstCommandChannelAttacked = firstCommandChannelAttacked;
  1950. }
  1951. /**
  1952. * @return the _commandChannelLastAttack
  1953. */
  1954. public long getCommandChannelLastAttack()
  1955. {
  1956. return _commandChannelLastAttack;
  1957. }
  1958. /**
  1959. * @param channelLastAttack the _commandChannelLastAttack to set
  1960. */
  1961. public void setCommandChannelLastAttack(long channelLastAttack)
  1962. {
  1963. _commandChannelLastAttack = channelLastAttack;
  1964. }
  1965. private static class CommandChannelTimer implements Runnable
  1966. {
  1967. private L2Attackable _monster;
  1968. public CommandChannelTimer(L2Attackable monster)
  1969. {
  1970. _monster = monster;
  1971. }
  1972. /**
  1973. * @see java.lang.Runnable#run()
  1974. */
  1975. public void run()
  1976. {
  1977. if ((System.currentTimeMillis() - _monster.getCommandChannelLastAttack()) > Config.LOOT_RAIDS_PRIVILEGE_INTERVAL)
  1978. {
  1979. _monster.setCommandChannelTimer(null);
  1980. _monster.setFirstCommandChannelAttacked(null);
  1981. _monster.setCommandChannelLastAttack(0);
  1982. }
  1983. else
  1984. ThreadPoolManager.getInstance().scheduleGeneral(this, 10000); // 10sec
  1985. }
  1986. }
  1987. public void returnHome()
  1988. {
  1989. clearAggroList();
  1990. if (hasAI() && getSpawn() != null)
  1991. getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(getSpawn().getLocx(), getSpawn().getLocy(), getSpawn().getLocz(), 0));
  1992. }
  1993. /*
  1994. * Return vitality points decrease (if positive)
  1995. * or increase (if negative) based on damage.
  1996. * Maximum for damage = maxHp.
  1997. */
  1998. public float getVitalityPoints(int damage)
  1999. {
  2000. // sanity check
  2001. if (damage <= 0)
  2002. return 0;
  2003. final float divider = getTemplate().baseVitalityDivider;
  2004. if (divider == 0)
  2005. return 0;
  2006. // negative value - vitality will be consumed
  2007. return - Math.min(damage, getMaxHp()) / divider;
  2008. }
  2009. /*
  2010. * True if vitality rate for exp and sp should be applied
  2011. */
  2012. public boolean useVitalityRate()
  2013. {
  2014. if (isChampion() && !Config.L2JMOD_CHAMPION_ENABLE_VITALITY)
  2015. return false;
  2016. return true;
  2017. }
  2018. /** Return True if the L2Character is RaidBoss or his minion. */
  2019. @Override
  2020. public boolean isRaid()
  2021. {
  2022. return _isRaid;
  2023. }
  2024. /**
  2025. * Set this Npc as a Raid instance.<BR><BR>
  2026. * @param isRaid
  2027. */
  2028. public void setIsRaid(boolean isRaid)
  2029. {
  2030. _isRaid = isRaid;
  2031. }
  2032. /**
  2033. * Set this Npc as a Minion instance.<BR><BR>
  2034. * @param val
  2035. */
  2036. public void setIsRaidMinion(boolean val)
  2037. {
  2038. _isRaid = val;
  2039. _isRaidMinion = val;
  2040. }
  2041. @Override
  2042. public boolean isRaidMinion()
  2043. {
  2044. return _isRaidMinion;
  2045. }
  2046. @Override
  2047. public boolean isMinion()
  2048. {
  2049. return getLeader() != null;
  2050. }
  2051. /**
  2052. * Return leader of this minion or null.
  2053. */
  2054. public L2Attackable getLeader()
  2055. {
  2056. return null;
  2057. }
  2058. public void setChampion(boolean champ)
  2059. {
  2060. _champion = champ;
  2061. }
  2062. @Override
  2063. public boolean isChampion()
  2064. {
  2065. return _champion;
  2066. }
  2067. }