L2Attackable.java 80 KB

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