2
0

L2Attackable.java 92 KB

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