L2Attackable.java 78 KB

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