L2Attackable.java 90 KB

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