L2Attackable.java 91 KB

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