L2Attackable.java 79 KB

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