Guest User

Untitled

a guest
Feb 17th, 2016
1,739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 312.22 KB | None | 0 0
  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.actor.instance;
  16. // RnP (del pvp zonos)
  17.  
  18.  
  19. import custom.events.DMEvent;
  20. // RnP (tvt 1)
  21. import custom.events.TvTEvent;
  22.  
  23. import java.sql.Connection;
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.Calendar;
  29. import java.util.Collection;
  30. import java.util.HashMap;
  31. import java.util.LinkedHashMap;
  32. import java.util.List;
  33. import java.util.Map;
  34. import java.util.Set;
  35. import java.util.concurrent.ConcurrentHashMap;
  36. import java.util.concurrent.ConcurrentSkipListMap;
  37. import java.util.concurrent.Future;
  38. import java.util.concurrent.ScheduledFuture;
  39. import java.util.concurrent.TimeUnit;
  40. import java.util.concurrent.atomic.AtomicInteger;
  41. import java.util.concurrent.locks.ReentrantLock;
  42. import java.util.logging.Level;
  43.  
  44. import net.sf.l2j.Config;
  45. import net.sf.l2j.L2DatabaseFactory;
  46. import net.sf.l2j.commons.random.Rnd;
  47. import net.sf.l2j.gameserver.Announcements;
  48. import net.sf.l2j.gameserver.LoginServerThread;
  49. import net.sf.l2j.gameserver.ThreadPoolManager;
  50. import net.sf.l2j.gameserver.ai.CtrlEvent;
  51. import net.sf.l2j.gameserver.ai.CtrlIntention;
  52. import net.sf.l2j.gameserver.ai.NextAction;
  53. import net.sf.l2j.gameserver.ai.model.L2CharacterAI;
  54. import net.sf.l2j.gameserver.ai.model.L2PlayerAI;
  55. import net.sf.l2j.gameserver.ai.model.L2SummonAI;
  56. import net.sf.l2j.gameserver.communitybbs.BB.Forum;
  57. import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
  58. import net.sf.l2j.gameserver.datatables.AccessLevels;
  59. import net.sf.l2j.gameserver.datatables.CharNameTable;
  60. import net.sf.l2j.gameserver.datatables.CharTemplateTable;
  61. import net.sf.l2j.gameserver.datatables.ClanTable;
  62. import net.sf.l2j.gameserver.datatables.FishTable;
  63. import net.sf.l2j.gameserver.datatables.GmListTable;
  64. import net.sf.l2j.gameserver.datatables.HennaTable;
  65. import net.sf.l2j.gameserver.datatables.ItemTable;
  66. import net.sf.l2j.gameserver.datatables.MapRegionTable.TeleportWhereType;
  67. import net.sf.l2j.gameserver.datatables.NpcTable;
  68. import net.sf.l2j.gameserver.datatables.RecipeTable;
  69. import net.sf.l2j.gameserver.datatables.SkillTable;
  70. import net.sf.l2j.gameserver.datatables.SkillTable.FrequentSkill;
  71. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  72. import net.sf.l2j.gameserver.geoengine.GeoEngine;
  73. import net.sf.l2j.gameserver.handler.IItemHandler;
  74. import net.sf.l2j.gameserver.handler.ItemHandler;
  75. import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditChar;
  76. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  77. import net.sf.l2j.gameserver.instancemanager.CoupleManager;
  78. import net.sf.l2j.gameserver.instancemanager.CursedWeaponsManager;
  79. import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
  80. import net.sf.l2j.gameserver.instancemanager.DuelManager;
  81. import net.sf.l2j.gameserver.instancemanager.SevenSigns;
  82. import net.sf.l2j.gameserver.instancemanager.SevenSignsFestival;
  83. import net.sf.l2j.gameserver.instancemanager.SiegeManager;
  84. import net.sf.l2j.gameserver.instancemanager.ZoneManager;
  85. import net.sf.l2j.gameserver.model.BlockList;
  86. import net.sf.l2j.gameserver.model.FishData;
  87. import net.sf.l2j.gameserver.model.L2AccessLevel;
  88. import net.sf.l2j.gameserver.model.L2Clan;
  89. import net.sf.l2j.gameserver.model.L2ClanMember;
  90. import net.sf.l2j.gameserver.model.L2Effect;
  91. import net.sf.l2j.gameserver.model.L2Fishing;
  92. import net.sf.l2j.gameserver.model.L2Macro;
  93. import net.sf.l2j.gameserver.model.L2ManufactureList;
  94. import net.sf.l2j.gameserver.model.L2Object;
  95. import net.sf.l2j.gameserver.model.L2Party;
  96. import net.sf.l2j.gameserver.model.L2Party.MessageType;
  97. import net.sf.l2j.gameserver.model.L2Radar;
  98. import net.sf.l2j.gameserver.model.L2Request;
  99. import net.sf.l2j.gameserver.model.L2ShortCut;
  100. import net.sf.l2j.gameserver.model.L2Skill;
  101. import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
  102. import net.sf.l2j.gameserver.model.L2SkillLearn;
  103. import net.sf.l2j.gameserver.model.L2World;
  104. import net.sf.l2j.gameserver.model.Location;
  105. import net.sf.l2j.gameserver.model.MacroList;
  106. import net.sf.l2j.gameserver.model.PetDataEntry;
  107. import net.sf.l2j.gameserver.model.ShortCuts;
  108. import net.sf.l2j.gameserver.model.ShotType;
  109. import net.sf.l2j.gameserver.model.SpawnLocation;
  110. import net.sf.l2j.gameserver.model.actor.L2Attackable;
  111. import net.sf.l2j.gameserver.model.actor.L2Character;
  112. import net.sf.l2j.gameserver.model.actor.L2Npc;
  113. import net.sf.l2j.gameserver.model.actor.L2Playable;
  114. import net.sf.l2j.gameserver.model.actor.L2Summon;
  115. import net.sf.l2j.gameserver.model.actor.L2Vehicle;
  116. import net.sf.l2j.gameserver.model.actor.appearance.PcAppearance;
  117. import net.sf.l2j.gameserver.model.actor.knownlist.PcKnownList;
  118. import net.sf.l2j.gameserver.model.actor.stat.PcStat;
  119. import net.sf.l2j.gameserver.model.actor.status.PcStatus;
  120. import net.sf.l2j.gameserver.model.actor.template.PcTemplate;
  121. import net.sf.l2j.gameserver.model.actor.template.PetTemplate;
  122. import net.sf.l2j.gameserver.model.base.ClassId;
  123. import net.sf.l2j.gameserver.model.base.ClassRace;
  124. import net.sf.l2j.gameserver.model.base.ClassType;
  125. import net.sf.l2j.gameserver.model.base.Experience;
  126. import net.sf.l2j.gameserver.model.base.Sex;
  127. import net.sf.l2j.gameserver.model.base.SubClass;
  128. import net.sf.l2j.gameserver.model.entity.Castle;
  129. import net.sf.l2j.gameserver.model.entity.Duel.DuelState;
  130. import net.sf.l2j.gameserver.model.entity.Hero;
  131. import net.sf.l2j.gameserver.model.entity.Siege;
  132. import net.sf.l2j.gameserver.model.holder.IntIntHolder;
  133. import net.sf.l2j.gameserver.model.holder.SkillUseHolder;
  134. import net.sf.l2j.gameserver.model.item.Henna;
  135. import net.sf.l2j.gameserver.model.item.RecipeList;
  136. import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  137. import net.sf.l2j.gameserver.model.item.kind.Item;
  138. import net.sf.l2j.gameserver.model.item.kind.Weapon;
  139. import net.sf.l2j.gameserver.model.item.type.ActionType;
  140. import net.sf.l2j.gameserver.model.item.type.ArmorType;
  141. import net.sf.l2j.gameserver.model.item.type.EtcItemType;
  142. import net.sf.l2j.gameserver.model.item.type.WeaponType;
  143. import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  144. import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
  145. import net.sf.l2j.gameserver.model.itemcontainer.PcFreight;
  146. import net.sf.l2j.gameserver.model.itemcontainer.PcInventory;
  147. import net.sf.l2j.gameserver.model.itemcontainer.PcWarehouse;
  148. import net.sf.l2j.gameserver.model.itemcontainer.PetInventory;
  149. import net.sf.l2j.gameserver.model.itemcontainer.listeners.ItemPassiveSkillsListener;
  150. import net.sf.l2j.gameserver.model.memo.PlayerMemo;
  151. import net.sf.l2j.gameserver.model.multisell.PreparedListContainer;
  152. import net.sf.l2j.gameserver.model.olympiad.OlympiadGameManager;
  153. import net.sf.l2j.gameserver.model.olympiad.OlympiadGameTask;
  154. import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  155. import net.sf.l2j.gameserver.model.partymatching.PartyMatchRoom;
  156. import net.sf.l2j.gameserver.model.partymatching.PartyMatchRoomList;
  157. import net.sf.l2j.gameserver.model.partymatching.PartyMatchWaitingList;
  158. import net.sf.l2j.gameserver.model.tradelist.TradeList;
  159. import net.sf.l2j.gameserver.model.zone.ZoneId;
  160. import net.sf.l2j.gameserver.model.zone.type.L2BossZone;
  161. import net.sf.l2j.gameserver.model.zone.type.L2MultiFunctionZone;
  162. import net.sf.l2j.gameserver.network.L2GameClient;
  163. import net.sf.l2j.gameserver.network.SystemMessageId;
  164. import net.sf.l2j.gameserver.network.serverpackets.AbstractNpcInfo;
  165. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  166. import net.sf.l2j.gameserver.network.serverpackets.ChairSit;
  167. import net.sf.l2j.gameserver.network.serverpackets.ChangeWaitType;
  168. import net.sf.l2j.gameserver.network.serverpackets.CharInfo;
  169. import net.sf.l2j.gameserver.network.serverpackets.ConfirmDlg;
  170. import net.sf.l2j.gameserver.network.serverpackets.EtcStatusUpdate;
  171. import net.sf.l2j.gameserver.network.serverpackets.ExAutoSoulShot;
  172. import net.sf.l2j.gameserver.network.serverpackets.ExDuelUpdateUserInfo;
  173. import net.sf.l2j.gameserver.network.serverpackets.ExFishingEnd;
  174. import net.sf.l2j.gameserver.network.serverpackets.ExFishingStart;
  175. import net.sf.l2j.gameserver.network.serverpackets.ExOlympiadMode;
  176. import net.sf.l2j.gameserver.network.serverpackets.ExSetCompassZoneCode;
  177. import net.sf.l2j.gameserver.network.serverpackets.ExStorageMaxCount;
  178. import net.sf.l2j.gameserver.network.serverpackets.FriendList;
  179. import net.sf.l2j.gameserver.network.serverpackets.GetOnVehicle;
  180. import net.sf.l2j.gameserver.network.serverpackets.HennaInfo;
  181. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  182. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  183. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  184. import net.sf.l2j.gameserver.network.serverpackets.LeaveWorld;
  185. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  186. import net.sf.l2j.gameserver.network.serverpackets.MoveToPawn;
  187. import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
  188. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  189. import net.sf.l2j.gameserver.network.serverpackets.ObservationMode;
  190. import net.sf.l2j.gameserver.network.serverpackets.ObservationReturn;
  191. import net.sf.l2j.gameserver.network.serverpackets.PartySmallWindowUpdate;
  192. import net.sf.l2j.gameserver.network.serverpackets.PetInventoryUpdate;
  193. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  194. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListDelete;
  195. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListUpdate;
  196. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreListBuy;
  197. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreListSell;
  198. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreManageListBuy;
  199. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreManageListSell;
  200. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreMsgBuy;
  201. import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreMsgSell;
  202. import net.sf.l2j.gameserver.network.serverpackets.RecipeShopManageList;
  203. import net.sf.l2j.gameserver.network.serverpackets.RecipeShopMsg;
  204. import net.sf.l2j.gameserver.network.serverpackets.RecipeShopSellList;
  205. import net.sf.l2j.gameserver.network.serverpackets.RelationChanged;
  206. import net.sf.l2j.gameserver.network.serverpackets.Ride;
  207. import net.sf.l2j.gameserver.network.serverpackets.SendTradeDone;
  208. import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  209. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  210. import net.sf.l2j.gameserver.network.serverpackets.ShortBuffStatusUpdate;
  211. import net.sf.l2j.gameserver.network.serverpackets.ShortCutInit;
  212. import net.sf.l2j.gameserver.network.serverpackets.SkillCoolTime;
  213. import net.sf.l2j.gameserver.network.serverpackets.SkillList;
  214. import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  215. import net.sf.l2j.gameserver.network.serverpackets.StaticObject;
  216. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  217. import net.sf.l2j.gameserver.network.serverpackets.StopMove;
  218. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  219. import net.sf.l2j.gameserver.network.serverpackets.TargetSelected;
  220. import net.sf.l2j.gameserver.network.serverpackets.TargetUnselected;
  221. import net.sf.l2j.gameserver.network.serverpackets.TitleUpdate;
  222. import net.sf.l2j.gameserver.network.serverpackets.TradePressOtherOk;
  223. import net.sf.l2j.gameserver.network.serverpackets.TradePressOwnOk;
  224. import net.sf.l2j.gameserver.network.serverpackets.TradeStart;
  225. import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  226. import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
  227. import net.sf.l2j.gameserver.scripting.EventType;
  228. import net.sf.l2j.gameserver.scripting.Quest;
  229. import net.sf.l2j.gameserver.scripting.QuestState;
  230. import net.sf.l2j.gameserver.scripting.ScriptManager;
  231. import net.sf.l2j.gameserver.skills.Env;
  232. import net.sf.l2j.gameserver.skills.Formulas;
  233. import net.sf.l2j.gameserver.skills.Stats;
  234. import net.sf.l2j.gameserver.skills.effects.EffectTemplate;
  235. import net.sf.l2j.gameserver.skills.funcs.FuncHennaCON;
  236. import net.sf.l2j.gameserver.skills.funcs.FuncHennaDEX;
  237. import net.sf.l2j.gameserver.skills.funcs.FuncHennaINT;
  238. import net.sf.l2j.gameserver.skills.funcs.FuncHennaMEN;
  239. import net.sf.l2j.gameserver.skills.funcs.FuncHennaSTR;
  240. import net.sf.l2j.gameserver.skills.funcs.FuncHennaWIT;
  241. import net.sf.l2j.gameserver.skills.funcs.FuncMaxCpMul;
  242. import net.sf.l2j.gameserver.skills.l2skills.L2SkillSiegeFlag;
  243. import net.sf.l2j.gameserver.skills.l2skills.L2SkillSummon;
  244. import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  245. import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  246. import net.sf.l2j.gameserver.taskmanager.ItemsOnGroundTaskManager;
  247. import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
  248. import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
  249. import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
  250. import net.sf.l2j.gameserver.templates.skills.L2EffectFlag;
  251. import net.sf.l2j.gameserver.templates.skills.L2EffectType;
  252. import net.sf.l2j.gameserver.templates.skills.L2SkillType;
  253. import net.sf.l2j.gameserver.util.Broadcast;
  254. import net.sf.l2j.gameserver.util.Util;
  255.  
  256. /**
  257. * This class represents a player in the world.<br>
  258. * There is always a client-thread connected to this (except if a player-store is activated upon logout).
  259. */
  260. public final class L2PcInstance extends L2Playable
  261. {
  262. public enum StoreType
  263. {
  264. NONE(0),
  265. SELL(1),
  266. SELL_MANAGE(2),
  267. BUY(3),
  268. BUY_MANAGE(4),
  269. MANUFACTURE(5),
  270. PACKAGE_SELL(8);
  271.  
  272. private int _id;
  273.  
  274. private StoreType(int id)
  275. {
  276. _id = id;
  277. }
  278.  
  279. public int getId()
  280. {
  281. return _id;
  282. }
  283. }
  284.  
  285. public StoreType getStoreTypeId(int id)
  286. {
  287. switch(id)
  288. {
  289. case 0:
  290. return StoreType.NONE;
  291. case 1:
  292. return StoreType.SELL;
  293. case 2:
  294. return StoreType.SELL_MANAGE;
  295. case 3:
  296. return StoreType.BUY;
  297. case 4:
  298. return StoreType.BUY_MANAGE;
  299. case 5:
  300. return StoreType.MANUFACTURE;
  301. case 8:
  302. return StoreType.PACKAGE_SELL;
  303. }
  304. return StoreType.NONE;
  305. }
  306.  
  307. public enum PunishLevel
  308. {
  309. NONE(0, ""),
  310. CHAT(1, "chat banned"),
  311. JAIL(2, "jailed"),
  312. CHAR(3, "banned"),
  313. ACC(4, "banned");
  314.  
  315. private final int punValue;
  316. private final String punString;
  317.  
  318. PunishLevel(int value, String string)
  319. {
  320. punValue = value;
  321. punString = string;
  322. }
  323.  
  324. public int value()
  325. {
  326. return punValue;
  327. }
  328.  
  329. public String string()
  330. {
  331. return punString;
  332. }
  333. }
  334.  
  335. private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE char_obj_id=? AND class_index=?";
  336. private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (char_obj_id,skill_id,skill_level,class_index) VALUES (?,?,?,?)";
  337. private static final String UPDATE_CHARACTER_SKILL_LEVEL = "UPDATE character_skills SET skill_level=? WHERE skill_id=? AND char_obj_id=? AND class_index=?";
  338. private static final String DELETE_SKILL_FROM_CHAR = "DELETE FROM character_skills WHERE skill_id=? AND char_obj_id=? AND class_index=?";
  339. private static final String DELETE_CHAR_SKILLS = "DELETE FROM character_skills WHERE char_obj_id=? AND class_index=?";
  340.  
  341. private static final String ADD_SKILL_SAVE = "INSERT INTO character_skills_save (char_obj_id,skill_id,skill_level,effect_count,effect_cur_time,reuse_delay,systime,restore_type,class_index,buff_index) VALUES (?,?,?,?,?,?,?,?,?,?)";
  342. private static final String RESTORE_SKILL_SAVE = "SELECT skill_id,skill_level,effect_count,effect_cur_time, reuse_delay, systime, restore_type FROM character_skills_save WHERE char_obj_id=? AND class_index=? ORDER BY buff_index ASC";
  343. private static final String DELETE_SKILL_SAVE = "DELETE FROM character_skills_save WHERE char_obj_id=? AND class_index=?";
  344.  
  345. private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  346. private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,donator=?,name_color=?,title_color=? WHERE obj_id=?";
  347. private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,donator,name_color,title_color FROM characters WHERE obj_id=?";
  348.  
  349. private static final String RESTORE_CHAR_SUBCLASSES = "SELECT class_id,exp,sp,level,class_index FROM character_subclasses WHERE char_obj_id=? ORDER BY class_index ASC";
  350. private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
  351. private static final String UPDATE_CHAR_SUBCLASS = "UPDATE character_subclasses SET exp=?,sp=?,level=?,class_id=? WHERE char_obj_id=? AND class_index =?";
  352. private static final String DELETE_CHAR_SUBCLASS = "DELETE FROM character_subclasses WHERE char_obj_id=? AND class_index=?";
  353.  
  354. private static final String RESTORE_CHAR_HENNAS = "SELECT slot,symbol_id FROM character_hennas WHERE char_obj_id=? AND class_index=?";
  355. private static final String ADD_CHAR_HENNA = "INSERT INTO character_hennas (char_obj_id,symbol_id,slot,class_index) VALUES (?,?,?,?)";
  356. private static final String DELETE_CHAR_HENNA = "DELETE FROM character_hennas WHERE char_obj_id=? AND slot=? AND class_index=?";
  357. private static final String DELETE_CHAR_HENNAS = "DELETE FROM character_hennas WHERE char_obj_id=? AND class_index=?";
  358. private static final String DELETE_CHAR_SHORTCUTS = "DELETE FROM character_shortcuts WHERE char_obj_id=? AND class_index=?";
  359.  
  360. private static final String RESTORE_CHAR_RECOMS = "SELECT char_id,target_id FROM character_recommends WHERE char_id=?";
  361. private static final String ADD_CHAR_RECOM = "INSERT INTO character_recommends (char_id,target_id) VALUES (?,?)";
  362. private static final String DELETE_CHAR_RECOMS = "DELETE FROM character_recommends WHERE char_id=?";
  363.  
  364. private static final String UPDATE_NOBLESS = "UPDATE characters SET nobless=? WHERE obj_Id=?";
  365.  
  366. public static final int REQUEST_TIMEOUT = 15;
  367. // RnP (del pvp zonos)
  368. public boolean checkenabled = true;
  369.  
  370.  
  371. private static final int[] EXPERTISE_LEVELS =
  372. {
  373. 0, // NONE
  374. 20, // D
  375. 40, // C
  376. 52, // B
  377. 61, // A
  378. 76, // S
  379. };
  380.  
  381. private static final int[] COMMON_CRAFT_LEVELS =
  382. {
  383. 5,
  384. 20,
  385. 28,
  386. 36,
  387. 43,
  388. 49,
  389. 55,
  390. 62
  391. };
  392. // RnP (Del augument managerio)
  393. private static String _Password;
  394.  
  395. private L2GameClient _client;
  396. private final Map<Integer, String> _chars = new HashMap<>();
  397.  
  398. private String _accountName;
  399. private long _deleteTimer;
  400.  
  401. private boolean _isOnline;
  402. private long _onlineTime;
  403. private long _onlineBeginTime;
  404. private long _lastAccess;
  405. private long _uptime;
  406. // RnP (Cia del multi zonos :)
  407. /** The _is offline. */
  408. private boolean _isOffline = false;
  409.  
  410. protected int _baseClass;
  411. protected int _activeClass;
  412. protected int _classIndex;
  413.  
  414. private final Map<Integer, SubClass> _subClasses = new ConcurrentSkipListMap<>();
  415. private final ReentrantLock _subclassLock = new ReentrantLock();
  416.  
  417. private PcAppearance _appearance;
  418. /** The Day PvP */ // RnP (cia dejau del pvp zonos)
  419. private int multipvp = 0;
  420.  
  421.  
  422. public int _originalNameColorTvT;
  423.  
  424. private long _expBeforeDeath;
  425. private int _karma;
  426. private int _pvpKills;
  427. private int _pkKills;
  428. private byte _pvpFlag;
  429. private byte _siegeState;
  430. private int _curWeightPenalty;
  431.  
  432. private int _lastCompassZone; // the last compass zone update send to the client
  433.  
  434. private boolean _isInWater;
  435. private boolean _isIn7sDungeon;
  436.  
  437. private PunishLevel _punishLevel = PunishLevel.NONE;
  438. private long _punishTimer;
  439. private ScheduledFuture<?> _punishTask;
  440.  
  441. private boolean _isInOlympiadMode;
  442. private boolean _isInOlympiadStart;
  443. private int _olympiadGameId = -1;
  444. private int _olympiadSide = -1;
  445.  
  446. private DuelState _duelState = DuelState.NO_DUEL;
  447. private int _duelId;
  448. private SystemMessageId _noDuelReason = SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL;
  449.  
  450. private L2Vehicle _vehicle;
  451. private SpawnLocation _vehiclePosition = new SpawnLocation(0, 0, 0, 0);
  452.  
  453. private ScheduledFuture<?> _fishingTask;
  454.  
  455. private boolean _canFeed;
  456. protected PetTemplate _petTemplate;
  457. private PetDataEntry _petData;
  458. private int _controlItemId;
  459. private int _curFeed;
  460. protected Future<?> _mountFeedTask;
  461. private ScheduledFuture<?> _dismountTask;
  462.  
  463. private int _mountType;
  464. private int _mountNpcId;
  465. private int _mountLevel;
  466. private int _mountObjectId;
  467.  
  468. protected int _throneId;
  469.  
  470. private int _teleMode;
  471. private boolean _isCrystallizing;
  472. private boolean _isCrafting;
  473.  
  474. private final Map<Integer, RecipeList> _dwarvenRecipeBook = new HashMap<>();
  475. private final Map<Integer, RecipeList> _commonRecipeBook = new HashMap<>();
  476.  
  477. private boolean _isSitting;
  478.  
  479. private final Location _savedLocation = new Location(0, 0, 0);
  480. private boolean _observerMode;
  481.  
  482. private int _recomHave;
  483. private int _recomLeft;
  484. private long _lastRecomUpdate;
  485. private final List<Integer> _recomChars = new ArrayList<>();
  486.  
  487. private final PcInventory _inventory = new PcInventory(this);
  488. private PcWarehouse _warehouse;
  489. private PcFreight _freight;
  490. private final List<PcFreight> _depositedFreight = new ArrayList<>();
  491.  
  492. private StoreType _storeType = StoreType.NONE;
  493.  
  494. private TradeList _activeTradeList;
  495. private ItemContainer _activeWarehouse;
  496. private L2ManufactureList _createList;
  497. private TradeList _sellList;
  498. private TradeList _buyList;
  499.  
  500. private PreparedListContainer _currentMultiSell;
  501.  
  502. private boolean _isNoble;
  503. private boolean _isHero;
  504.  
  505. private L2Npc _currentFolkNpc;
  506.  
  507. private int _questNpcObject;
  508.  
  509. private final List<QuestState> _quests = new ArrayList<>();
  510. private final List<QuestState> _notifyQuestOfDeathList = new ArrayList<>();
  511.  
  512. private final PlayerMemo _vars = new PlayerMemo(getObjectId());
  513.  
  514. private final ShortCuts _shortCuts = new ShortCuts(this);
  515.  
  516. private final MacroList _macroses = new MacroList(this);
  517.  
  518. private ClassId _skillLearningClassId;
  519.  
  520. private final Henna[] _henna = new Henna[3];
  521. private int _hennaSTR;
  522. private int _hennaINT;
  523. private int _hennaDEX;
  524. private int _hennaMEN;
  525. private int _hennaWIT;
  526. private int _hennaCON;
  527.  
  528. private L2Summon _summon;
  529. private L2TamedBeastInstance _tamedBeast;
  530.  
  531. // TODO: This needs to be better integrated and saved/loaded
  532. private L2Radar _radar;
  533.  
  534. private int _partyroom;
  535.  
  536. private int _clanId;
  537. private L2Clan _clan;
  538. private int _apprentice;
  539. private int _sponsor;
  540. private long _clanJoinExpiryTime;
  541. private long _clanCreateExpiryTime;
  542. private int _powerGrade;
  543. private int _clanPrivileges;
  544. private int _pledgeClass;
  545. private int _pledgeType;
  546. private int _lvlJoinedAcademy;
  547.  
  548. private boolean _wantsPeace;
  549.  
  550. // RnP (del pvp tittle?)
  551. /**Quake System*/
  552. private int quakeSystem = 0;
  553.  
  554. private int _deathPenaltyBuffLevel;
  555.  
  556. private final AtomicInteger _charges = new AtomicInteger();
  557. private ScheduledFuture<?> _chargeTask;
  558.  
  559. private Location _currentSkillWorldPosition;
  560.  
  561. private L2AccessLevel _accessLevel;
  562.  
  563. private boolean _messageRefusal; // message refusal mode
  564. private boolean _tradeRefusal; // Trade refusal
  565. private boolean _exchangeRefusal; // Exchange refusal
  566.  
  567. private L2Party _party;
  568.  
  569. private L2PcInstance _activeRequester;
  570. private long _requestExpireTime;
  571. private final L2Request _request = new L2Request(this);
  572.  
  573. private ItemInstance _arrowItem;
  574.  
  575. private ScheduledFuture<?> _protectTask;
  576.  
  577. private long _recentFakeDeathEndTime;
  578. private boolean _isFakeDeath;
  579.  
  580. private Weapon _fistsWeaponItem;
  581.  
  582. private int _expertiseIndex;
  583. private int _expertiseArmorPenalty;
  584. private boolean _expertiseWeaponPenalty;
  585.  
  586. private ItemInstance _activeEnchantItem;
  587.  
  588. protected boolean _inventoryDisable;
  589.  
  590. protected Map<Integer, L2CubicInstance> _cubics = new ConcurrentSkipListMap<>();
  591.  
  592. protected Set<Integer> _activeSoulShots = ConcurrentHashMap.newKeySet(1);
  593.  
  594. private final int _loto[] = new int[5];
  595. private final int _race[] = new int[2];
  596.  
  597. private final BlockList _blockList = new BlockList(this);
  598.  
  599. private int _team;
  600.  
  601. private int _alliedVarkaKetra; // lvl of alliance with ketra orcs or varka silenos, used in quests and aggro checks [-5,-1] varka, 0 neutral, [1,5] ketra
  602.  
  603. private Location _fishingLoc;
  604. private ItemInstance _lure;
  605. private L2Fishing _fishCombat;
  606. private FishData _fish;
  607.  
  608. private final List<String> _validBypass = new ArrayList<>();
  609. private final List<String> _validBypass2 = new ArrayList<>();
  610.  
  611. private Forum _forumMail;
  612. private Forum _forumMemo;
  613.  
  614. private boolean _isInSiege;
  615.  
  616. private final Map<Integer, L2Skill> _skills = new ConcurrentSkipListMap<>();
  617.  
  618. private final SkillUseHolder _currentSkill = new SkillUseHolder();
  619. private final SkillUseHolder _currentPetSkill = new SkillUseHolder();
  620. private final SkillUseHolder _queuedSkill = new SkillUseHolder();
  621.  
  622. private int _cursedWeaponEquippedId;
  623.  
  624. private int _reviveRequested;
  625. private double _revivePower = .0;
  626. private boolean _revivePet;
  627.  
  628. private double _cpUpdateIncCheck = .0;
  629. private double _cpUpdateDecCheck = .0;
  630. private double _cpUpdateInterval = .0;
  631. private double _mpUpdateIncCheck = .0;
  632. private double _mpUpdateDecCheck = .0;
  633. private double _mpUpdateInterval = .0;
  634.  
  635. private int _clientX;
  636. private int _clientY;
  637. private int _clientZ;
  638. private int _clientHeading;
  639.  
  640. private int _mailPosition;
  641.  
  642. private static final int FALLING_VALIDATION_DELAY = 10000;
  643. private volatile long _fallingTimestamp;
  644.  
  645. // RnP (cia dejau del multi zonos)
  646. public String _originalTitle;
  647.  
  648. private ScheduledFuture<?> _shortBuffTask;
  649. private int _shortBuffTaskSkillId;
  650.  
  651. private boolean _isMarried;
  652. private int _coupleId;
  653. private boolean _isUnderMarryRequest;
  654. private int _requesterId;
  655.  
  656. private final List<Integer> _friendList = new ArrayList<>(); // Related to CB.
  657. private final List<Integer> _selectedFriendList = new ArrayList<>(); // Related to CB.
  658. private final List<Integer> _selectedBlocksList = new ArrayList<>(); // Related to CB.
  659.  
  660. private L2PcInstance _summonTargetRequest;
  661. private L2Skill _summonSkillRequest;
  662.  
  663. private L2DoorInstance _requestedGate;
  664.  
  665. /**
  666. * Constructor of L2PcInstance (use L2Character constructor).
  667. * <ul>
  668. * <li>Call the L2Character constructor to create an empty _skills slot and copy basic Calculator set to this L2PcInstance</li>
  669. * <li>Set the name of the L2PcInstance</li>
  670. * </ul>
  671. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method SET the level of the L2PcInstance to 1</B></FONT>
  672. * @param objectId Identifier of the object to initialized
  673. * @param template The L2PcTemplate to apply to the L2PcInstance
  674. * @param accountName The name of the account including this L2PcInstance
  675. * @param app The PcAppearance of the L2PcInstance
  676. */
  677. private L2PcInstance(int objectId, PcTemplate template, String accountName, PcAppearance app)
  678. {
  679. super(objectId, template);
  680.  
  681. initCharStatusUpdateValues();
  682.  
  683. _accountName = accountName;
  684. _appearance = app;
  685.  
  686. // Create an AI
  687. _ai = new L2PlayerAI(this);
  688.  
  689. // Create a L2Radar object
  690. _radar = new L2Radar(this);
  691.  
  692. // Retrieve from the database all items of this L2PcInstance and add them to _inventory
  693. getInventory().restore();
  694. getWarehouse();
  695. getFreight();
  696. }
  697.  
  698. private L2PcInstance(int objectId)
  699. {
  700. super(objectId, null);
  701.  
  702. initCharStatusUpdateValues();
  703. }
  704.  
  705. /**
  706. * Create a new L2PcInstance and add it in the characters table of the database.
  707. * <ul>
  708. * <li>Create a new L2PcInstance with an account name</li>
  709. * <li>Set the name, the Hair Style, the Hair Color and the Face type of the L2PcInstance</li>
  710. * <li>Add the player in the characters table of the database</li>
  711. * </ul>
  712. * @param objectId Identifier of the object to initialized
  713. * @param template The L2PcTemplate to apply to the L2PcInstance
  714. * @param accountName The name of the L2PcInstance
  715. * @param name The name of the L2PcInstance
  716. * @param hairStyle The hair style Identifier of the L2PcInstance
  717. * @param hairColor The hair color Identifier of the L2PcInstance
  718. * @param face The face type Identifier of the L2PcInstance
  719. * @param sex The sex type Identifier of the L2PcInstance
  720. * @return The L2PcInstance added to the database or null
  721. */
  722. public static L2PcInstance create(int objectId, PcTemplate template, String accountName, String name, byte hairStyle, byte hairColor, byte face, Sex sex)
  723. {
  724. // Create a new L2PcInstance with an account name
  725. PcAppearance app = new PcAppearance(face, hairColor, hairStyle, sex);
  726. L2PcInstance player = new L2PcInstance(objectId, template, accountName, app);
  727.  
  728. // Set the name of the L2PcInstance
  729. player.setName(name);
  730. // RnP (Cia max level keisti pakeisti :) )
  731. long pXp = player.getExp();
  732. long tXp = Experience.LEVEL[76];
  733.  
  734. if (pXp > tXp)
  735. player.removeExpAndSp(pXp - tXp, 0);
  736. else if (pXp < tXp)
  737. player.addExpAndSp(tXp - pXp, 0);
  738.  
  739. // Set the base class ID to that of the actual class ID.
  740. player.setBaseClass(player.getClassId());
  741.  
  742. // Add the player in the characters table of the database
  743. boolean ok = player.createDb();
  744.  
  745. if (!ok)
  746. return null;
  747.  
  748. return player;
  749. }
  750.  
  751. @Override
  752. public void addFuncsToNewCharacter()
  753. {
  754. // Add L2Character functionalities.
  755. super.addFuncsToNewCharacter();
  756.  
  757. addStatFunc(FuncMaxCpMul.getInstance());
  758.  
  759. addStatFunc(FuncHennaSTR.getInstance());
  760. addStatFunc(FuncHennaDEX.getInstance());
  761. addStatFunc(FuncHennaINT.getInstance());
  762. addStatFunc(FuncHennaMEN.getInstance());
  763. addStatFunc(FuncHennaCON.getInstance());
  764. addStatFunc(FuncHennaWIT.getInstance());
  765. }
  766.  
  767. @Override
  768. protected void initCharStatusUpdateValues()
  769. {
  770. super.initCharStatusUpdateValues();
  771.  
  772. _cpUpdateInterval = getMaxCp() / 352.0;
  773. _cpUpdateIncCheck = getMaxCp();
  774. _cpUpdateDecCheck = getMaxCp() - _cpUpdateInterval;
  775. _mpUpdateInterval = getMaxMp() / 352.0;
  776. _mpUpdateIncCheck = getMaxMp();
  777. _mpUpdateDecCheck = getMaxMp() - _mpUpdateInterval;
  778. }
  779.  
  780. @Override
  781. public void initKnownList()
  782. {
  783. setKnownList(new PcKnownList(this));
  784. }
  785.  
  786. @Override
  787. public final PcKnownList getKnownList()
  788. {
  789. return (PcKnownList) super.getKnownList();
  790. }
  791.  
  792. @Override
  793. public void initCharStat()
  794. {
  795. setStat(new PcStat(this));
  796. }
  797.  
  798. @Override
  799. public final PcStat getStat()
  800. {
  801. return (PcStat) super.getStat();
  802. }
  803.  
  804. @Override
  805. public void initCharStatus()
  806. {
  807. setStatus(new PcStatus(this));
  808. }
  809.  
  810. @Override
  811. public final PcStatus getStatus()
  812. {
  813. return (PcStatus) super.getStatus();
  814. }
  815.  
  816. public final PcAppearance getAppearance()
  817. {
  818. return _appearance;
  819. }
  820.  
  821. /**
  822. * @return the base L2PcTemplate link to the L2PcInstance.
  823. */
  824. public final PcTemplate getBaseTemplate()
  825. {
  826. return CharTemplateTable.getInstance().getTemplate(_baseClass);
  827. }
  828.  
  829. /** Return the L2PcTemplate link to the L2PcInstance. */
  830. @Override
  831. public final PcTemplate getTemplate()
  832. {
  833. return (PcTemplate) super.getTemplate();
  834. }
  835.  
  836. public void setTemplate(ClassId newclass)
  837. {
  838. super.setTemplate(CharTemplateTable.getInstance().getTemplate(newclass));
  839. }
  840.  
  841. /**
  842. * Return the AI of the L2PcInstance (create it if necessary).
  843. */
  844. @Override
  845. public L2CharacterAI getAI()
  846. {
  847. L2CharacterAI ai = _ai;
  848. if (ai == null)
  849. {
  850. synchronized (this)
  851. {
  852. if (_ai == null)
  853. _ai = new L2PlayerAI(this);
  854.  
  855. return _ai;
  856. }
  857. }
  858. return ai;
  859. }
  860.  
  861. /** Return the Level of the L2PcInstance. */
  862. @Override
  863. public final int getLevel()
  864. {
  865. return getStat().getLevel();
  866. }
  867.  
  868. /**
  869. * A newbie is a player reaching level 6. He isn't considered newbie at lvl 25.<br>
  870. * Since IL newbie isn't anymore the first character of an account reaching that state, but any.
  871. * @return True if newbie.
  872. */
  873. public boolean isNewbie()
  874. {
  875. return getClassId().level() <= 1 && getLevel() >= 6 && getLevel() <= 25;
  876. }
  877.  
  878. public void setBaseClass(int baseClass)
  879. {
  880. _baseClass = baseClass;
  881. }
  882.  
  883. public void setBaseClass(ClassId classId)
  884. {
  885. _baseClass = classId.ordinal();
  886. }
  887.  
  888. public boolean isInStoreMode()
  889. {
  890. return _storeType != StoreType.NONE;
  891. }
  892.  
  893. public boolean isCrafting()
  894. {
  895. return _isCrafting;
  896. }
  897.  
  898. public void setCrafting(boolean state)
  899. {
  900. _isCrafting = state;
  901. }
  902.  
  903. /**
  904. * Manage Logout Task
  905. */
  906. public void logout()
  907. {
  908. logout(true);
  909. }
  910.  
  911. /**
  912. * Manage Logout Task
  913. * @param closeClient
  914. */
  915. public void logout(boolean closeClient)
  916. {
  917. try
  918. {
  919. closeNetConnection(closeClient);
  920. }
  921. catch (Exception e)
  922. {
  923. _log.log(Level.WARNING, "Exception on logout(): " + e.getMessage(), e);
  924. }
  925. }
  926.  
  927. /**
  928. * @return a table containing all Common RecipeList of the L2PcInstance.
  929. */
  930. public Collection<RecipeList> getCommonRecipeBook()
  931. {
  932. return _commonRecipeBook.values();
  933. }
  934.  
  935. /**
  936. * @return a table containing all Dwarf RecipeList of the L2PcInstance.
  937. */
  938. public Collection<RecipeList> getDwarvenRecipeBook()
  939. {
  940. return _dwarvenRecipeBook.values();
  941. }
  942.  
  943. /**
  944. * Add a new L2RecipList to the table _commonrecipebook containing all RecipeList of the L2PcInstance.
  945. * @param recipe The RecipeList to add to the _recipebook
  946. */
  947. public void registerCommonRecipeList(RecipeList recipe)
  948. {
  949. _commonRecipeBook.put(recipe.getId(), recipe);
  950. }
  951.  
  952. /**
  953. * Add a new L2RecipList to the table _recipebook containing all RecipeList of the L2PcInstance.
  954. * @param recipe The RecipeList to add to the _recipebook
  955. */
  956. public void registerDwarvenRecipeList(RecipeList recipe)
  957. {
  958. _dwarvenRecipeBook.put(recipe.getId(), recipe);
  959. }
  960.  
  961. /**
  962. * @param recipeId The Identifier of the RecipeList to check in the player's recipe books
  963. * @return <b>TRUE</b> if player has the recipe on Common or Dwarven Recipe book else returns <b>FALSE</b>
  964. */
  965. public boolean hasRecipeList(int recipeId)
  966. {
  967. return _dwarvenRecipeBook.containsKey(recipeId) || _commonRecipeBook.containsKey(recipeId);
  968. }
  969.  
  970. /**
  971. * Tries to remove a L2RecipList from the table _DwarvenRecipeBook or from table _CommonRecipeBook, those table contain all RecipeList of the L2PcInstance.
  972. * @param recipeId The Identifier of the RecipeList to remove from the _recipebook.
  973. */
  974. public void unregisterRecipeList(int recipeId)
  975. {
  976. if (_dwarvenRecipeBook.containsKey(recipeId))
  977. _dwarvenRecipeBook.remove(recipeId);
  978. else if (_commonRecipeBook.containsKey(recipeId))
  979. _commonRecipeBook.remove(recipeId);
  980. else
  981. _log.warning("Attempted to remove unknown RecipeList: " + recipeId);
  982.  
  983. for (L2ShortCut sc : getAllShortCuts())
  984. {
  985. if (sc != null && sc.getId() == recipeId && sc.getType() == L2ShortCut.TYPE_RECIPE)
  986. deleteShortCut(sc.getSlot(), sc.getPage());
  987. }
  988. }
  989.  
  990. /**
  991. * @return the Id for the last talked quest NPC.
  992. */
  993. public int getLastQuestNpcObject()
  994. {
  995. return _questNpcObject;
  996. }
  997.  
  998. public void setLastQuestNpcObject(int npcId)
  999. {
  1000. _questNpcObject = npcId;
  1001. }
  1002.  
  1003. /**
  1004. * @param name The name of the quest.
  1005. * @return The QuestState object corresponding to the quest name.
  1006. */
  1007. public QuestState getQuestState(String name)
  1008. {
  1009. for (QuestState qs : _quests)
  1010. {
  1011. if (name.equals(qs.getQuest().getName()))
  1012. return qs;
  1013. }
  1014. return null;
  1015. }
  1016.  
  1017. /**
  1018. * Add a QuestState to the table _quest containing all quests began by the L2PcInstance.
  1019. * @param qs The QuestState to add to _quest.
  1020. */
  1021. public void setQuestState(QuestState qs)
  1022. {
  1023. _quests.add(qs);
  1024. }
  1025.  
  1026. /**
  1027. * Remove a QuestState from the table _quest containing all quests began by the L2PcInstance.
  1028. * @param qs : The QuestState to be removed from _quest.
  1029. */
  1030. public void delQuestState(QuestState qs)
  1031. {
  1032. _quests.remove(qs);
  1033. }
  1034.  
  1035. /**
  1036. * @param completed : If true, include completed quests to the list.
  1037. * @return list of started and eventually completed quests of the player.
  1038. */
  1039. public List<Quest> getAllQuests(boolean completed)
  1040. {
  1041. List<Quest> quests = new ArrayList<>();
  1042.  
  1043. for (QuestState qs : _quests)
  1044. {
  1045. if (qs == null || completed && qs.isCreated() || !completed && !qs.isStarted())
  1046. continue;
  1047.  
  1048. Quest quest = qs.getQuest();
  1049. if (quest == null || !quest.isRealQuest())
  1050. continue;
  1051.  
  1052. quests.add(quest);
  1053. }
  1054.  
  1055. return quests;
  1056. }
  1057.  
  1058. public void processQuestEvent(String questName, String event)
  1059. {
  1060. Quest quest = ScriptManager.getInstance().getQuest(questName);
  1061. if (quest == null)
  1062. return;
  1063.  
  1064. QuestState qs = getQuestState(questName);
  1065. if (qs == null)
  1066. return;
  1067.  
  1068. L2Object object = L2World.getInstance().getObject(getLastQuestNpcObject());
  1069. if (!(object instanceof L2Npc) || !isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
  1070. return;
  1071.  
  1072. L2Npc npc = (L2Npc) object;
  1073. List<Quest> quests = npc.getTemplate().getEventQuests(EventType.ON_TALK);
  1074. if (quests != null)
  1075. {
  1076. for (Quest onTalk : quests)
  1077. {
  1078. if (onTalk == null || !onTalk.equals(quest))
  1079. continue;
  1080.  
  1081. quest.notifyEvent(event, npc, this);
  1082. break;
  1083. }
  1084. }
  1085. }
  1086.  
  1087. /**
  1088. * Add QuestState instance that is to be notified of L2PcInstance's death.
  1089. * @param qs The QuestState that subscribe to this event
  1090. */
  1091. public void addNotifyQuestOfDeath(QuestState qs)
  1092. {
  1093. if (qs == null)
  1094. return;
  1095.  
  1096. if (!_notifyQuestOfDeathList.contains(qs))
  1097. _notifyQuestOfDeathList.add(qs);
  1098. }
  1099.  
  1100. /**
  1101. * Remove QuestState instance that is to be notified of L2PcInstance's death.
  1102. * @param qs The QuestState that subscribe to this event
  1103. */
  1104. public void removeNotifyQuestOfDeath(QuestState qs)
  1105. {
  1106. if (qs == null)
  1107. return;
  1108.  
  1109. _notifyQuestOfDeathList.remove(qs);
  1110. }
  1111.  
  1112. /**
  1113. * @return A list of QuestStates which registered for notify of death of this L2PcInstance.
  1114. */
  1115. public final List<QuestState> getNotifyQuestOfDeath()
  1116. {
  1117. return _notifyQuestOfDeathList;
  1118. }
  1119.  
  1120. /**
  1121. * @return player memos.
  1122. */
  1123. public PlayerMemo getMemos()
  1124. {
  1125. return _vars;
  1126. }
  1127.  
  1128. /**
  1129. * @return A table containing all L2ShortCut of the L2PcInstance.
  1130. */
  1131. public L2ShortCut[] getAllShortCuts()
  1132. {
  1133. return _shortCuts.getAllShortCuts();
  1134. }
  1135.  
  1136. /**
  1137. * @param slot The slot in wich the shortCuts is equipped
  1138. * @param page The page of shortCuts containing the slot
  1139. * @return The L2ShortCut of the L2PcInstance corresponding to the position (page-slot).
  1140. */
  1141. public L2ShortCut getShortCut(int slot, int page)
  1142. {
  1143. return _shortCuts.getShortCut(slot, page);
  1144. }
  1145.  
  1146. /**
  1147. * Add a L2shortCut to the L2PcInstance _shortCuts
  1148. * @param shortcut The shortcut to add.
  1149. */
  1150. public void registerShortCut(L2ShortCut shortcut)
  1151. {
  1152. _shortCuts.registerShortCut(shortcut);
  1153. }
  1154.  
  1155. /**
  1156. * Delete the L2ShortCut corresponding to the position (page-slot) from the L2PcInstance _shortCuts.
  1157. * @param slot
  1158. * @param page
  1159. */
  1160. public void deleteShortCut(int slot, int page)
  1161. {
  1162. _shortCuts.deleteShortCut(slot, page);
  1163. }
  1164.  
  1165. /**
  1166. * Add a L2Macro to the L2PcInstance _macroses.
  1167. * @param macro The Macro object to add.
  1168. */
  1169. public void registerMacro(L2Macro macro)
  1170. {
  1171. _macroses.registerMacro(macro);
  1172. }
  1173.  
  1174. /**
  1175. * Delete the L2Macro corresponding to the Identifier from the L2PcInstance _macroses.
  1176. * @param id
  1177. */
  1178. public void deleteMacro(int id)
  1179. {
  1180. _macroses.deleteMacro(id);
  1181. }
  1182.  
  1183. /**
  1184. * @return all L2Macro of the L2PcInstance.
  1185. */
  1186. public MacroList getMacroses()
  1187. {
  1188. return _macroses;
  1189. }
  1190.  
  1191. /**
  1192. * Set the siege state of the L2PcInstance.
  1193. * @param siegeState 1 = attacker, 2 = defender, 0 = not involved
  1194. */
  1195. public void setSiegeState(byte siegeState)
  1196. {
  1197. _siegeState = siegeState;
  1198. }
  1199.  
  1200. /**
  1201. * @return the siege state of the L2PcInstance.
  1202. */
  1203. public byte getSiegeState()
  1204. {
  1205. return _siegeState;
  1206. }
  1207.  
  1208. /**
  1209. * Set the PvP Flag of the L2PcInstance.
  1210. * @param pvpFlag 0 or 1.
  1211. */
  1212. public void setPvpFlag(int pvpFlag)
  1213. {
  1214. _pvpFlag = (byte) pvpFlag;
  1215. }
  1216.  
  1217. @Override
  1218. public byte getPvpFlag()
  1219. {
  1220. return _pvpFlag;
  1221. }
  1222. // RnP (TvT DEL FLAGO 2)
  1223. public void updatePvPFlag(int value)
  1224. {
  1225. if(TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  1226. {
  1227. setPvpFlag(0);
  1228. sendPacket(new UserInfo(this));
  1229. broadcastRelationsChanges();
  1230. return;
  1231. }
  1232. if(isInsideZone(ZoneId.MULTI_FUNCTION))
  1233. value = 1;
  1234.  
  1235. //if (getPvpFlag() == value)
  1236. //return;
  1237.  
  1238. setPvpFlag(value);
  1239. sendPacket(new UserInfo(this));
  1240.  
  1241. if (getPet() != null)
  1242. sendPacket(new RelationChanged(getPet(), getRelation(this), false));
  1243.  
  1244. broadcastRelationsChanges();
  1245.  
  1246. broadcastUserInfo();
  1247.  
  1248. }
  1249.  
  1250. public int getRelation(L2PcInstance target)
  1251. {
  1252. int result = 0;
  1253.  
  1254. // karma and pvp may not be required
  1255. if (getPvpFlag() != 0)
  1256. result |= RelationChanged.RELATION_PVP_FLAG;
  1257. if (getKarma() > 0)
  1258. result |= RelationChanged.RELATION_HAS_KARMA;
  1259.  
  1260. if (isClanLeader())
  1261. result |= RelationChanged.RELATION_LEADER;
  1262.  
  1263. if (getSiegeState() != 0)
  1264. {
  1265. result |= RelationChanged.RELATION_INSIEGE;
  1266. if (getSiegeState() != target.getSiegeState())
  1267. result |= RelationChanged.RELATION_ENEMY;
  1268. else
  1269. result |= RelationChanged.RELATION_ALLY;
  1270. if (getSiegeState() == 1)
  1271. result |= RelationChanged.RELATION_ATTACKER;
  1272. }
  1273.  
  1274. if (getClan() != null && target.getClan() != null)
  1275. {
  1276. if (target.getPledgeType() != L2Clan.SUBUNIT_ACADEMY && getPledgeType() != L2Clan.SUBUNIT_ACADEMY && target.getClan().isAtWarWith(getClan().getClanId()))
  1277. {
  1278. result |= RelationChanged.RELATION_1SIDED_WAR;
  1279. if (getClan().isAtWarWith(target.getClan().getClanId()))
  1280. result |= RelationChanged.RELATION_MUTUAL_WAR;
  1281. }
  1282. }
  1283. return result;
  1284. }
  1285.  
  1286. @Override
  1287. public void revalidateZone(boolean force)
  1288. {
  1289. super.revalidateZone(force);
  1290.  
  1291. if (Config.ALLOW_WATER)
  1292. checkWaterState();
  1293.  
  1294. if (isInsideZone(ZoneId.SIEGE))
  1295. {
  1296. if (_lastCompassZone == ExSetCompassZoneCode.SIEGEWARZONE2)
  1297. return;
  1298.  
  1299. _lastCompassZone = ExSetCompassZoneCode.SIEGEWARZONE2;
  1300. sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.SIEGEWARZONE2));
  1301. }
  1302. else if (isInsideZone(ZoneId.PVP))
  1303. {
  1304. if (_lastCompassZone == ExSetCompassZoneCode.PVPZONE)
  1305. return;
  1306.  
  1307. _lastCompassZone = ExSetCompassZoneCode.PVPZONE;
  1308. sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.PVPZONE));
  1309. }
  1310. else if (isIn7sDungeon())
  1311. {
  1312. if (_lastCompassZone == ExSetCompassZoneCode.SEVENSIGNSZONE)
  1313. return;
  1314.  
  1315. _lastCompassZone = ExSetCompassZoneCode.SEVENSIGNSZONE;
  1316. sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.SEVENSIGNSZONE));
  1317. }
  1318. else if (isInsideZone(ZoneId.PEACE))
  1319. {
  1320. if (_lastCompassZone == ExSetCompassZoneCode.PEACEZONE)
  1321. return;
  1322.  
  1323. _lastCompassZone = ExSetCompassZoneCode.PEACEZONE;
  1324. sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.PEACEZONE));
  1325. }
  1326. else
  1327. {
  1328. if (_lastCompassZone == ExSetCompassZoneCode.GENERALZONE)
  1329. return;
  1330.  
  1331. if (_lastCompassZone == ExSetCompassZoneCode.SIEGEWARZONE2)
  1332. updatePvPStatus();
  1333.  
  1334. _lastCompassZone = ExSetCompassZoneCode.GENERALZONE;
  1335. sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.GENERALZONE));
  1336. }
  1337. }
  1338.  
  1339. /**
  1340. * @return True if the L2PcInstance can Craft Dwarven Recipes.
  1341. */
  1342. public boolean hasDwarvenCraft()
  1343. {
  1344. return getSkillLevel(L2Skill.SKILL_CREATE_DWARVEN) >= 1;
  1345. }
  1346.  
  1347. public int getDwarvenCraft()
  1348. {
  1349. return getSkillLevel(L2Skill.SKILL_CREATE_DWARVEN);
  1350. }
  1351.  
  1352. /**
  1353. * @return True if the L2PcInstance can Craft Dwarven Recipes.
  1354. */
  1355. public boolean hasCommonCraft()
  1356. {
  1357. return getSkillLevel(L2Skill.SKILL_CREATE_COMMON) >= 1;
  1358. }
  1359.  
  1360. public int getCommonCraft()
  1361. {
  1362. return getSkillLevel(L2Skill.SKILL_CREATE_COMMON);
  1363. }
  1364.  
  1365. /**
  1366. * @return the PK counter of the L2PcInstance.
  1367. */
  1368. public int getPkKills()
  1369. {
  1370. return _pkKills;
  1371. }
  1372.  
  1373. /**
  1374. * Set the PK counter of the L2PcInstance.
  1375. * @param pkKills A number.
  1376. */
  1377. public void setPkKills(int pkKills)
  1378. {
  1379. _pkKills = pkKills;
  1380. }
  1381.  
  1382. /**
  1383. * @return The _deleteTimer of the L2PcInstance.
  1384. */
  1385. public long getDeleteTimer()
  1386. {
  1387. return _deleteTimer;
  1388. }
  1389.  
  1390. /**
  1391. * Set the _deleteTimer of the L2PcInstance.
  1392. * @param deleteTimer Time in ms.
  1393. */
  1394. public void setDeleteTimer(long deleteTimer)
  1395. {
  1396. _deleteTimer = deleteTimer;
  1397. }
  1398.  
  1399. /**
  1400. * @return The current weight of the L2PcInstance.
  1401. */
  1402. public int getCurrentLoad()
  1403. {
  1404. return _inventory.getTotalWeight();
  1405. }
  1406.  
  1407. /**
  1408. * @return The date of last update of recomPoints.
  1409. */
  1410. public long getLastRecomUpdate()
  1411. {
  1412. return _lastRecomUpdate;
  1413. }
  1414.  
  1415. public void setLastRecomUpdate(long date)
  1416. {
  1417. _lastRecomUpdate = date;
  1418. }
  1419.  
  1420. /**
  1421. * @return The number of recommandation obtained by the L2PcInstance.
  1422. */
  1423. public int getRecomHave()
  1424. {
  1425. return _recomHave;
  1426. }
  1427.  
  1428. /**
  1429. * Increment the number of recommandation obtained by the L2PcInstance (Max : 255).
  1430. */
  1431. protected void incRecomHave()
  1432. {
  1433. if (_recomHave < 255)
  1434. _recomHave++;
  1435. }
  1436.  
  1437. /**
  1438. * Set the number of recommandations obtained by the L2PcInstance (Max : 255).
  1439. * @param value Number of recommandations obtained.
  1440. */
  1441. public void setRecomHave(int value)
  1442. {
  1443. if (value > 255)
  1444. _recomHave = 255;
  1445. else if (value < 0)
  1446. _recomHave = 0;
  1447. else
  1448. _recomHave = value;
  1449. }
  1450.  
  1451. /**
  1452. * @return The number of recommandation that the L2PcInstance can give.
  1453. */
  1454. public int getRecomLeft()
  1455. {
  1456. return _recomLeft;
  1457. }
  1458.  
  1459. /**
  1460. * Increment the number of recommandation that the L2PcInstance can give.
  1461. */
  1462. protected void decRecomLeft()
  1463. {
  1464. if (_recomLeft > 0)
  1465. _recomLeft--;
  1466. }
  1467.  
  1468. public void giveRecom(L2PcInstance target)
  1469. {
  1470. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1471. {
  1472. PreparedStatement statement = con.prepareStatement(ADD_CHAR_RECOM);
  1473. statement.setInt(1, getObjectId());
  1474. statement.setInt(2, target.getObjectId());
  1475. statement.execute();
  1476. statement.close();
  1477. }
  1478. catch (Exception e)
  1479. {
  1480. _log.warning("Could not update char recommendations: " + e);
  1481. }
  1482.  
  1483. target.incRecomHave();
  1484. decRecomLeft();
  1485. _recomChars.add(target.getObjectId());
  1486. }
  1487.  
  1488. public boolean canRecom(L2PcInstance target)
  1489. {
  1490. return !_recomChars.contains(target.getObjectId());
  1491. }
  1492.  
  1493. /**
  1494. * Set the exp of the L2PcInstance before a death
  1495. * @param exp
  1496. */
  1497. public void setExpBeforeDeath(long exp)
  1498. {
  1499. _expBeforeDeath = exp;
  1500. }
  1501.  
  1502. public long getExpBeforeDeath()
  1503. {
  1504. return _expBeforeDeath;
  1505. }
  1506.  
  1507. /**
  1508. * Return the Karma of the L2PcInstance.
  1509. */
  1510. @Override
  1511. public int getKarma()
  1512. {
  1513. return _karma;
  1514. }
  1515.  
  1516. /**
  1517. * Set the Karma of the L2PcInstance and send StatusUpdate (broadcast).
  1518. * @param karma A value.
  1519. */
  1520. public void setKarma(int karma)
  1521. {
  1522. if (karma < 0)
  1523. karma = 0;
  1524.  
  1525. if (_karma > 0 && karma == 0)
  1526. {
  1527. sendPacket(new UserInfo(this));
  1528. broadcastRelationsChanges();
  1529. }
  1530.  
  1531. // send message with new karma value
  1532. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOUR_KARMA_HAS_BEEN_CHANGED_TO_S1).addNumber(karma));
  1533.  
  1534. _karma = karma;
  1535. broadcastKarma();
  1536. }
  1537.  
  1538.  
  1539. /**
  1540. * Weight Limit = (CON Modifier*69000)*Skills
  1541. * @return The max weight that the L2PcInstance can load.
  1542. */
  1543. public int getMaxLoad()
  1544. {
  1545. int con = getCON();
  1546. if (con < 1)
  1547. return 31000;
  1548.  
  1549. if (con > 59)
  1550. return 176000;
  1551.  
  1552. double baseLoad = Math.pow(1.029993928, con) * 30495.627366;
  1553. return (int) calcStat(Stats.MAX_LOAD, baseLoad * Config.ALT_WEIGHT_LIMIT, this, null);
  1554. }
  1555.  
  1556. public int getExpertiseArmorPenalty()
  1557. {
  1558. return _expertiseArmorPenalty;
  1559. }
  1560.  
  1561. public boolean getExpertiseWeaponPenalty()
  1562. {
  1563. return _expertiseWeaponPenalty;
  1564. }
  1565.  
  1566. public int getWeightPenalty()
  1567. {
  1568. return _curWeightPenalty;
  1569. }
  1570.  
  1571. /**
  1572. * Update the overloaded status of the L2PcInstance.
  1573. */
  1574. public void refreshOverloaded()
  1575. {
  1576. int maxLoad = getMaxLoad();
  1577. if (maxLoad > 0)
  1578. {
  1579. int weightproc = getCurrentLoad() * 1000 / maxLoad;
  1580. int newWeightPenalty;
  1581.  
  1582. if (weightproc < 500)
  1583. newWeightPenalty = 0;
  1584. else if (weightproc < 666)
  1585. newWeightPenalty = 1;
  1586. else if (weightproc < 800)
  1587. newWeightPenalty = 2;
  1588. else if (weightproc < 1000)
  1589. newWeightPenalty = 3;
  1590. else
  1591. newWeightPenalty = 4;
  1592.  
  1593. if (_curWeightPenalty != newWeightPenalty)
  1594. {
  1595. _curWeightPenalty = newWeightPenalty;
  1596.  
  1597. if (newWeightPenalty > 0)
  1598. {
  1599. super.addSkill(SkillTable.getInstance().getInfo(4270, newWeightPenalty));
  1600. setIsOverloaded(getCurrentLoad() > maxLoad);
  1601. }
  1602. else
  1603. {
  1604. super.removeSkill(getSkill(4270));
  1605. setIsOverloaded(false);
  1606. }
  1607.  
  1608. sendPacket(new UserInfo(this));
  1609. sendPacket(new EtcStatusUpdate(this));
  1610. broadcastCharInfo();
  1611. }
  1612. }
  1613. }
  1614.  
  1615. /**
  1616. * Refresh expertise level ; weapon got one rank, when armor got 4 ranks.<br>
  1617. */
  1618. public void refreshExpertisePenalty()
  1619. {
  1620. int armorPenalty = 0;
  1621. boolean weaponPenalty = false;
  1622.  
  1623. for (ItemInstance item : getInventory().getPaperdollItems())
  1624. {
  1625. if (item.getItemType() != EtcItemType.ARROW && item.getItem().getCrystalType().getId() > getExpertiseIndex())
  1626. {
  1627. if (item.isWeapon())
  1628. weaponPenalty = true;
  1629. else
  1630. armorPenalty += (item.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR) ? 2 : 1;
  1631. }
  1632. }
  1633.  
  1634. armorPenalty = Math.min(armorPenalty, 4);
  1635.  
  1636. // Found a different state than previous ; update it.
  1637. if (_expertiseWeaponPenalty != weaponPenalty || _expertiseArmorPenalty != armorPenalty)
  1638. {
  1639. _expertiseWeaponPenalty = weaponPenalty;
  1640. _expertiseArmorPenalty = armorPenalty;
  1641.  
  1642. // Passive skill "Grade Penalty" is either granted or dropped.
  1643. if (_expertiseWeaponPenalty || _expertiseArmorPenalty > 0)
  1644. super.addSkill(SkillTable.getInstance().getInfo(4267, 1));
  1645. else
  1646. super.removeSkill(getSkill(4267));
  1647.  
  1648. sendSkillList();
  1649. sendPacket(new EtcStatusUpdate(this));
  1650.  
  1651. final ItemInstance weapon = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1652. if (weapon != null)
  1653. {
  1654. if (_expertiseWeaponPenalty)
  1655. ItemPassiveSkillsListener.getInstance().onUnequip(0, weapon, this);
  1656. else
  1657. ItemPassiveSkillsListener.getInstance().onEquip(0, weapon, this);
  1658. }
  1659. }
  1660. }
  1661.  
  1662. /**
  1663. * Equip or unequip the item.
  1664. * <UL>
  1665. * <LI>If item is equipped, shots are applied if automation is on.</LI>
  1666. * <LI>If item is unequipped, shots are discharged.</LI>
  1667. * </UL>
  1668. * @param item The item to charge/discharge.
  1669. * @param abortAttack If true, the current attack will be aborted in order to equip the item.
  1670. */
  1671. public void useEquippableItem(ItemInstance item, boolean abortAttack)
  1672. {
  1673. ItemInstance[] items = null;
  1674. final boolean isEquipped = item.isEquipped();
  1675. final int oldInvLimit = getInventoryLimit();
  1676.  
  1677. if (item.getItem() instanceof Weapon)
  1678. item.unChargeAllShots();
  1679.  
  1680. if (isEquipped)
  1681. {
  1682. if (item.getEnchantLevel() > 0)
  1683. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(item.getEnchantLevel()).addItemName(item));
  1684. else
  1685. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(item));
  1686.  
  1687. int slot = getInventory().getSlotFromItem(item);
  1688. items = getInventory().unEquipItemInBodySlotAndRecord(slot);
  1689. }
  1690. else
  1691. {
  1692. items = getInventory().equipItemAndRecord(item);
  1693.  
  1694. if (item.isEquipped())
  1695. {
  1696. if (item.getEnchantLevel() > 0)
  1697. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_S2_EQUIPPED).addNumber(item.getEnchantLevel()).addItemName(item));
  1698. else
  1699. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_EQUIPPED).addItemName(item));
  1700.  
  1701. if ((item.getItem().getBodyPart() & Item.SLOT_ALLWEAPON) != 0)
  1702. rechargeShots(true, true);
  1703. }
  1704. else
  1705. sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
  1706. }
  1707. refreshExpertisePenalty();
  1708. broadcastUserInfo();
  1709.  
  1710. InventoryUpdate iu = new InventoryUpdate();
  1711. iu.addItems(Arrays.asList(items));
  1712. sendPacket(iu);
  1713.  
  1714. if (abortAttack)
  1715. abortAttack();
  1716.  
  1717. if (getInventoryLimit() != oldInvLimit)
  1718. sendPacket(new ExStorageMaxCount(this));
  1719. }
  1720.  
  1721. /**
  1722. * @return PvP Kills of the L2PcInstance (number of player killed during a PvP).
  1723. */
  1724. public int getPvpKills()
  1725. {
  1726. return _pvpKills;
  1727. }
  1728.  
  1729. /**
  1730. * Set PvP Kills of the L2PcInstance (number of player killed during a PvP).
  1731. * @param pvpKills A value.
  1732. */
  1733. public void setPvpKills(int pvpKills)
  1734. {
  1735. _pvpKills = pvpKills;
  1736. updatecolorSystem();
  1737. }
  1738. // RnP (del PVP zonos)
  1739. public int getMultiKills()
  1740. {
  1741. return multipvp;
  1742. }
  1743.  
  1744.  
  1745. public void setMultiKills(int dpvpKills)
  1746. {
  1747. multipvp = dpvpKills;
  1748. }
  1749.  
  1750.  
  1751. /**
  1752. * @return The ClassId object of the L2PcInstance contained in L2PcTemplate.
  1753. */
  1754. public ClassId getClassId()
  1755. {
  1756. return getTemplate().getClassId();
  1757. }
  1758.  
  1759. /**
  1760. * Set the template of the L2PcInstance.
  1761. * @param Id The Identifier of the L2PcTemplate to set to the L2PcInstance
  1762. */
  1763. public void setClassId(int Id)
  1764. {
  1765. if (!_subclassLock.tryLock())
  1766. return;
  1767.  
  1768. try
  1769. {
  1770. if (getLvlJoinedAcademy() != 0 && _clan != null && ClassId.VALUES[Id].level() == 2)
  1771. {
  1772. if (getLvlJoinedAcademy() <= 16)
  1773. _clan.addReputationScore(400);
  1774. else if (getLvlJoinedAcademy() >= 39)
  1775. _clan.addReputationScore(170);
  1776. else
  1777. _clan.addReputationScore((400 - (getLvlJoinedAcademy() - 16) * 10));
  1778.  
  1779. setLvlJoinedAcademy(0);
  1780.  
  1781. // Oust pledge member from the academy, because he has finished his 2nd class transfer.
  1782. _clan.broadcastToOnlineMembers(new PledgeShowMemberListDelete(getName()), SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_S1_EXPELLED).addString(getName()));
  1783. _clan.removeClanMember(getObjectId(), 0);
  1784. sendPacket(SystemMessageId.ACADEMY_MEMBERSHIP_TERMINATED);
  1785.  
  1786. // receive graduation gift : academy circlet
  1787. addItem("Gift", 8181, 1, this, true);
  1788. }
  1789.  
  1790. if (isSubClassActive())
  1791. _subClasses.get(_classIndex).setClassId(Id);
  1792.  
  1793. broadcastPacket(new MagicSkillUse(this, this, 5103, 1, 1000, 0));
  1794. setClassTemplate(Id);
  1795.  
  1796. if (getClassId().level() == 3)
  1797. sendPacket(SystemMessageId.THIRD_CLASS_TRANSFER);
  1798. else
  1799. sendPacket(SystemMessageId.CLASS_TRANSFER);
  1800.  
  1801. // Update class icon in party and clan
  1802. if (isInParty())
  1803. getParty().broadcastToPartyMembers(new PartySmallWindowUpdate(this));
  1804.  
  1805. if (getClan() != null)
  1806. getClan().broadcastToOnlineMembers(new PledgeShowMemberListUpdate(this));
  1807.  
  1808. if (Config.AUTO_LEARN_SKILLS)
  1809. rewardSkills();
  1810. }
  1811. finally
  1812. {
  1813. _subclassLock.unlock();
  1814. }
  1815. }
  1816.  
  1817. /**
  1818. * @return the Experience of the L2PcInstance.
  1819. */
  1820. public long getExp()
  1821. {
  1822. return getStat().getExp();
  1823. }
  1824.  
  1825. public void setActiveEnchantItem(ItemInstance scroll)
  1826. {
  1827. _activeEnchantItem = scroll;
  1828. }
  1829.  
  1830. public ItemInstance getActiveEnchantItem()
  1831. {
  1832. return _activeEnchantItem;
  1833. }
  1834.  
  1835. /**
  1836. * Set the fists weapon of the L2PcInstance (used when no weapon is equipped).
  1837. * @param weaponItem The fists Weapon to set to the L2PcInstance
  1838. */
  1839. public void setFistsWeaponItem(Weapon weaponItem)
  1840. {
  1841. _fistsWeaponItem = weaponItem;
  1842. }
  1843.  
  1844. /**
  1845. * @return The fists weapon of the L2PcInstance (used when no weapon is equipped).
  1846. */
  1847. public Weapon getFistsWeaponItem()
  1848. {
  1849. return _fistsWeaponItem;
  1850. }
  1851.  
  1852. /**
  1853. * @param classId The classId to test.
  1854. * @return The fists weapon of the L2PcInstance Class (used when no weapon is equipped).
  1855. */
  1856. public static Weapon findFistsWeaponItem(int classId)
  1857. {
  1858. Weapon weaponItem = null;
  1859. if ((classId >= 0x00) && (classId <= 0x09))
  1860. {
  1861. // human fighter fists
  1862. Item temp = ItemTable.getInstance().getTemplate(246);
  1863. weaponItem = (Weapon) temp;
  1864. }
  1865. else if ((classId >= 0x0a) && (classId <= 0x11))
  1866. {
  1867. // human mage fists
  1868. Item temp = ItemTable.getInstance().getTemplate(251);
  1869. weaponItem = (Weapon) temp;
  1870. }
  1871. else if ((classId >= 0x12) && (classId <= 0x18))
  1872. {
  1873. // elven fighter fists
  1874. Item temp = ItemTable.getInstance().getTemplate(244);
  1875. weaponItem = (Weapon) temp;
  1876. }
  1877. else if ((classId >= 0x19) && (classId <= 0x1e))
  1878. {
  1879. // elven mage fists
  1880. Item temp = ItemTable.getInstance().getTemplate(249);
  1881. weaponItem = (Weapon) temp;
  1882. }
  1883. else if ((classId >= 0x1f) && (classId <= 0x25))
  1884. {
  1885. // dark elven fighter fists
  1886. Item temp = ItemTable.getInstance().getTemplate(245);
  1887. weaponItem = (Weapon) temp;
  1888. }
  1889. else if ((classId >= 0x26) && (classId <= 0x2b))
  1890. {
  1891. // dark elven mage fists
  1892. Item temp = ItemTable.getInstance().getTemplate(250);
  1893. weaponItem = (Weapon) temp;
  1894. }
  1895. else if ((classId >= 0x2c) && (classId <= 0x30))
  1896. {
  1897. // orc fighter fists
  1898. Item temp = ItemTable.getInstance().getTemplate(248);
  1899. weaponItem = (Weapon) temp;
  1900. }
  1901. else if ((classId >= 0x31) && (classId <= 0x34))
  1902. {
  1903. // orc mage fists
  1904. Item temp = ItemTable.getInstance().getTemplate(252);
  1905. weaponItem = (Weapon) temp;
  1906. }
  1907. else if ((classId >= 0x35) && (classId <= 0x39))
  1908. {
  1909. // dwarven fists
  1910. Item temp = ItemTable.getInstance().getTemplate(247);
  1911. weaponItem = (Weapon) temp;
  1912. }
  1913.  
  1914. return weaponItem;
  1915. }
  1916.  
  1917. /**
  1918. * This method is kinda polymorph :
  1919. * <ul>
  1920. * <li>it gives proper Expertise, Dwarven && Common Craft skill level ;</li>
  1921. * <li>it controls the Lucky skill (remove at lvl 10) ;</li>
  1922. * <li>it finally sends the skill list.</li>
  1923. * </ul>
  1924. */
  1925. public void rewardSkills()
  1926. {
  1927. // Get the Level of the L2PcInstance
  1928. int lvl = getLevel();
  1929.  
  1930. // Remove the Lucky skill once reached lvl 10.
  1931. if (getSkillLevel(L2Skill.SKILL_LUCKY) > 0 && lvl >= 10)
  1932. removeSkill(FrequentSkill.LUCKY.getSkill());
  1933.  
  1934. // Calculate the current higher Expertise of the L2PcInstance
  1935. for (int i = 0; i < EXPERTISE_LEVELS.length; i++)
  1936. {
  1937. if (lvl >= EXPERTISE_LEVELS[i])
  1938. setExpertiseIndex(i);
  1939. }
  1940.  
  1941. // Add the Expertise skill corresponding to its Expertise level
  1942. if (getExpertiseIndex() > 0)
  1943. {
  1944. L2Skill skill = SkillTable.getInstance().getInfo(239, getExpertiseIndex());
  1945. addSkill(skill, true);
  1946. }
  1947.  
  1948. // Active skill dwarven craft
  1949. if (getSkillLevel(1321) < 1 && getClassId().equalsOrChildOf(ClassId.DWARVEN_FIGHTER))
  1950. {
  1951. L2Skill skill = FrequentSkill.DWARVEN_CRAFT.getSkill();
  1952. addSkill(skill, true);
  1953. }
  1954.  
  1955. // Active skill common craft
  1956. if (getSkillLevel(1322) < 1)
  1957. {
  1958. L2Skill skill = FrequentSkill.COMMON_CRAFT.getSkill();
  1959. addSkill(skill, true);
  1960. }
  1961.  
  1962. for (int i = 0; i < COMMON_CRAFT_LEVELS.length; i++)
  1963. {
  1964. if (lvl >= COMMON_CRAFT_LEVELS[i] && getSkillLevel(1320) < (i + 1))
  1965. {
  1966. L2Skill skill = SkillTable.getInstance().getInfo(1320, (i + 1));
  1967. addSkill(skill, true);
  1968. }
  1969. }
  1970.  
  1971. // Auto-Learn skills if activated
  1972. if (Config.AUTO_LEARN_SKILLS)
  1973. giveAvailableSkills();
  1974.  
  1975. sendSkillList();
  1976. }
  1977.  
  1978. /**
  1979. * Regive all skills which aren't saved to database, like Noble, Hero, Clan Skills.<br>
  1980. * <b>Do not call this on enterworld or char load.</b>.
  1981. */
  1982. private void regiveTemporarySkills()
  1983. {
  1984. // Add noble skills if noble.
  1985. if (isNoble())
  1986. setNoble(true, false);
  1987.  
  1988. // Add Hero skills if hero.
  1989. if (isHero())
  1990. setHero(true);
  1991.  
  1992. // Add clan skills.
  1993. if (getClan() != null)
  1994. {
  1995. getClan().addSkillEffects(this);
  1996.  
  1997. if (getClan().getLevel() >= SiegeManager.MINIMUM_CLAN_LEVEL && isClanLeader())
  1998. SiegeManager.addSiegeSkills(this);
  1999. }
  2000.  
  2001. // Reload passive skills from armors / jewels / weapons
  2002. getInventory().reloadEquippedItems();
  2003.  
  2004. // Add Death Penalty Buff Level
  2005. restoreDeathPenaltyBuffLevel();
  2006. }
  2007.  
  2008. /**
  2009. * Give all available skills to the player.
  2010. * @return The number of given skills.
  2011. */
  2012. public int giveAvailableSkills()
  2013. {
  2014. int result = 0;
  2015. for (L2SkillLearn sl : SkillTreeTable.getInstance().getAllAvailableSkills(this, getClassId()))
  2016. {
  2017. addSkill(SkillTable.getInstance().getInfo(sl.getId(), sl.getLevel()), true);
  2018. result++;
  2019. }
  2020. return result;
  2021. }
  2022.  
  2023. /**
  2024. * @return The Race object of the L2PcInstance.
  2025. */
  2026. public ClassRace getRace()
  2027. {
  2028. if (!isSubClassActive())
  2029. return getTemplate().getRace();
  2030.  
  2031. return CharTemplateTable.getInstance().getTemplate(_baseClass).getRace();
  2032. }
  2033.  
  2034. public L2Radar getRadar()
  2035. {
  2036. return _radar;
  2037. }
  2038.  
  2039. /**
  2040. * @return the SP amount of the L2PcInstance.
  2041. */
  2042. public int getSp()
  2043. {
  2044. return getStat().getSp();
  2045. }
  2046.  
  2047. /**
  2048. * @param castleId The castle to check.
  2049. * @return True if this L2PcInstance is a clan leader in ownership of the passed castle.
  2050. */
  2051. public boolean isCastleLord(int castleId)
  2052. {
  2053. L2Clan clan = getClan();
  2054.  
  2055. // player has clan and is the clan leader, check the castle info
  2056. if ((clan != null) && (clan.getLeader().getPlayerInstance() == this))
  2057. {
  2058. // if the clan has a castle and it is actually the queried castle, return true
  2059. Castle castle = CastleManager.getInstance().getCastleByOwner(clan);
  2060. if ((castle != null) && (castle == CastleManager.getInstance().getCastleById(castleId)))
  2061. return true;
  2062. }
  2063.  
  2064. return false;
  2065. }
  2066.  
  2067. /**
  2068. * @return The Clan Identifier of the L2PcInstance.
  2069. */
  2070. public int getClanId()
  2071. {
  2072. return _clanId;
  2073. }
  2074.  
  2075. /**
  2076. * @return The Clan Crest Identifier of the L2PcInstance or 0.
  2077. */
  2078. public int getClanCrestId()
  2079. {
  2080. if (_clan != null)
  2081. return _clan.getCrestId();
  2082.  
  2083. return 0;
  2084. }
  2085.  
  2086. /**
  2087. * @return The Clan CrestLarge Identifier or 0
  2088. */
  2089. public int getClanCrestLargeId()
  2090. {
  2091. if (_clan != null)
  2092. return _clan.getCrestLargeId();
  2093.  
  2094. return 0;
  2095. }
  2096.  
  2097. public long getClanJoinExpiryTime()
  2098. {
  2099. return _clanJoinExpiryTime;
  2100. }
  2101.  
  2102. public void setClanJoinExpiryTime(long time)
  2103. {
  2104. _clanJoinExpiryTime = time;
  2105. }
  2106.  
  2107. public long getClanCreateExpiryTime()
  2108. {
  2109. return _clanCreateExpiryTime;
  2110. }
  2111.  
  2112. public void setClanCreateExpiryTime(long time)
  2113. {
  2114. _clanCreateExpiryTime = time;
  2115. }
  2116.  
  2117. public void setOnlineTime(long time)
  2118. {
  2119. _onlineTime = time;
  2120. _onlineBeginTime = System.currentTimeMillis();
  2121. }
  2122.  
  2123. /**
  2124. * Return the PcInventory Inventory of the L2PcInstance contained in _inventory.
  2125. */
  2126. @Override
  2127. public PcInventory getInventory()
  2128. {
  2129. return _inventory;
  2130. }
  2131.  
  2132. /**
  2133. * Delete a ShortCut of the L2PcInstance _shortCuts.
  2134. * @param objectId The shortcut id.
  2135. */
  2136. public void removeItemFromShortCut(int objectId)
  2137. {
  2138. _shortCuts.deleteShortCutByObjectId(objectId);
  2139. }
  2140.  
  2141. /**
  2142. * @return True if the L2PcInstance is sitting.
  2143. */
  2144. public boolean isSitting()
  2145. {
  2146. return _isSitting;
  2147. }
  2148.  
  2149. /**
  2150. * Set _isSitting to given value.
  2151. * @param state A boolean.
  2152. */
  2153. public void setSitting(boolean state)
  2154. {
  2155. _isSitting = state;
  2156. }
  2157.  
  2158. /**
  2159. * Sit down the L2PcInstance, set the AI Intention to REST and send ChangeWaitType packet (broadcast)
  2160. */
  2161. public void sitDown()
  2162. {
  2163. sitDown(true);
  2164. }
  2165.  
  2166. public void sitDown(boolean checkCast)
  2167. {
  2168. if (checkCast && isCastingNow())
  2169. return;
  2170.  
  2171. if (!_isSitting && !isAttackingDisabled() && !isOutOfControl() && !isImmobilized())
  2172. {
  2173. breakAttack();
  2174. setSitting(true);
  2175. broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_SITTING));
  2176.  
  2177. // Schedule a sit down task to wait for the animation to finish
  2178. getAI().setIntention(CtrlIntention.REST);
  2179.  
  2180. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  2181. {
  2182. @Override
  2183. public void run()
  2184. {
  2185. setIsParalyzed(false);
  2186. }
  2187. }, 2500);
  2188. setIsParalyzed(true);
  2189. }
  2190. }
  2191.  
  2192. /**
  2193. * Stand up the L2PcInstance, set the AI Intention to IDLE and send ChangeWaitType packet (broadcast)
  2194. */
  2195. public void standUp()
  2196. {
  2197. if (_isSitting && !isInStoreMode() && !isAlikeDead() && !isParalyzed())
  2198. {
  2199. if (_effects.isAffected(L2EffectFlag.RELAXING))
  2200. stopEffects(L2EffectType.RELAXING);
  2201.  
  2202. broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_STANDING));
  2203.  
  2204. // Schedule a stand up task to wait for the animation to finish
  2205. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  2206. {
  2207. @Override
  2208. public void run()
  2209. {
  2210. setSitting(false);
  2211. setIsParalyzed(false);
  2212. getAI().setIntention(CtrlIntention.IDLE);
  2213. }
  2214. }, 2500);
  2215. setIsParalyzed(true);
  2216. }
  2217. }
  2218.  
  2219. /**
  2220. * Stands up and close any opened shop window, if any.
  2221. */
  2222. public void forceStandUp()
  2223. {
  2224. // Cancels any shop types.
  2225. if (isInStoreMode())
  2226. {
  2227. setStoreType(StoreType.NONE);
  2228. broadcastUserInfo();
  2229. }
  2230.  
  2231. // Stand up.
  2232. standUp();
  2233. }
  2234.  
  2235. /**
  2236. * Used to sit or stand. If not possible, queue the action.
  2237. * @param target The target, used for thrones types.
  2238. * @param sittingState The sitting state, inheritated from packet or player status.
  2239. */
  2240. public void tryToSitOrStand(final L2Object target, final boolean sittingState)
  2241. {
  2242. if (isFakeDeath())
  2243. {
  2244. stopFakeDeath(true);
  2245. return;
  2246. }
  2247.  
  2248. final boolean isThrone = target instanceof L2StaticObjectInstance && ((L2StaticObjectInstance) target).getType() == 1;
  2249.  
  2250. // Player wants to sit on a throne but is out of radius, move to the throne delaying the sit action.
  2251. if (isThrone && !sittingState && !isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
  2252. {
  2253. getAI().setIntention(CtrlIntention.MOVE_TO, new Location(target.getX(), target.getY(), target.getZ()));
  2254.  
  2255. NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.MOVE_TO, new Runnable()
  2256. {
  2257. @Override
  2258. public void run()
  2259. {
  2260. if (getMountType() != 0)
  2261. return;
  2262.  
  2263. sitDown();
  2264.  
  2265. if (!((L2StaticObjectInstance) target).isBusy())
  2266. {
  2267. _throneId = target.getObjectId();
  2268.  
  2269. ((L2StaticObjectInstance) target).setBusy(true);
  2270. broadcastPacket(new ChairSit(getObjectId(), ((L2StaticObjectInstance) target).getStaticObjectId()));
  2271. }
  2272. }
  2273. });
  2274.  
  2275. // Binding next action to AI.
  2276. getAI().setNextAction(nextAction);
  2277. return;
  2278. }
  2279.  
  2280. // Player isn't moving, sit directly.
  2281. if (!isMoving())
  2282. {
  2283. if (getMountType() != 0)
  2284. return;
  2285.  
  2286. if (sittingState)
  2287. {
  2288. if (_throneId != 0)
  2289. {
  2290. final L2Object object = L2World.getInstance().getObject(_throneId);
  2291. if (object instanceof L2StaticObjectInstance)
  2292. ((L2StaticObjectInstance) object).setBusy(false);
  2293.  
  2294. _throneId = 0;
  2295. }
  2296.  
  2297. standUp();
  2298. }
  2299. else
  2300. {
  2301. sitDown();
  2302.  
  2303. if (isThrone && !((L2StaticObjectInstance) target).isBusy() && isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
  2304. {
  2305. _throneId = target.getObjectId();
  2306.  
  2307. ((L2StaticObjectInstance) target).setBusy(true);
  2308. broadcastPacket(new ChairSit(getObjectId(), ((L2StaticObjectInstance) target).getStaticObjectId()));
  2309. }
  2310. }
  2311. }
  2312. // Player is moving, wait the current action is done, then sit.
  2313. else
  2314. {
  2315. NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.MOVE_TO, new Runnable()
  2316. {
  2317. @Override
  2318. public void run()
  2319. {
  2320. if (getMountType() != 0)
  2321. return;
  2322.  
  2323. if (sittingState)
  2324. {
  2325. if (_throneId != 0)
  2326. {
  2327. final L2Object object = L2World.getInstance().getObject(_throneId);
  2328. if (object instanceof L2StaticObjectInstance)
  2329. ((L2StaticObjectInstance) object).setBusy(false);
  2330.  
  2331. _throneId = 0;
  2332. }
  2333.  
  2334. standUp();
  2335. }
  2336. else
  2337. {
  2338. sitDown();
  2339.  
  2340. if (isThrone && !((L2StaticObjectInstance) target).isBusy() && isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
  2341. {
  2342. _throneId = target.getObjectId();
  2343.  
  2344. ((L2StaticObjectInstance) target).setBusy(true);
  2345. broadcastPacket(new ChairSit(getObjectId(), ((L2StaticObjectInstance) target).getStaticObjectId()));
  2346. }
  2347. }
  2348. }
  2349. });
  2350.  
  2351. // Binding next action to AI.
  2352. getAI().setNextAction(nextAction);
  2353. }
  2354. }
  2355.  
  2356. /**
  2357. * @return The PcWarehouse object of the L2PcInstance.
  2358. */
  2359. public PcWarehouse getWarehouse()
  2360. {
  2361. if (_warehouse == null)
  2362. {
  2363. _warehouse = new PcWarehouse(this);
  2364. _warehouse.restore();
  2365. }
  2366. return _warehouse;
  2367. }
  2368.  
  2369. /**
  2370. * Free memory used by Warehouse
  2371. */
  2372. public void clearWarehouse()
  2373. {
  2374. if (_warehouse != null)
  2375. _warehouse.deleteMe();
  2376.  
  2377. _warehouse = null;
  2378. }
  2379.  
  2380. /**
  2381. * @return The PcFreight object of the L2PcInstance.
  2382. */
  2383. public PcFreight getFreight()
  2384. {
  2385. if (_freight == null)
  2386. {
  2387. _freight = new PcFreight(this);
  2388. _freight.restore();
  2389. }
  2390. return _freight;
  2391. }
  2392.  
  2393. /**
  2394. * Free memory used by Freight
  2395. */
  2396. public void clearFreight()
  2397. {
  2398. if (_freight != null)
  2399. _freight.deleteMe();
  2400.  
  2401. _freight = null;
  2402. }
  2403.  
  2404. /**
  2405. * @param objectId The id of the owner.
  2406. * @return deposited PcFreight object for the objectId or create new if not existing.
  2407. */
  2408. public PcFreight getDepositedFreight(int objectId)
  2409. {
  2410. for (PcFreight freight : _depositedFreight)
  2411. {
  2412. if (freight != null && freight.getOwnerId() == objectId)
  2413. return freight;
  2414. }
  2415.  
  2416. PcFreight freight = new PcFreight(null);
  2417. freight.doQuickRestore(objectId);
  2418. _depositedFreight.add(freight);
  2419. return freight;
  2420. }
  2421.  
  2422. /**
  2423. * Clear memory used by deposited freight
  2424. */
  2425. public void clearDepositedFreight()
  2426. {
  2427. for (PcFreight freight : _depositedFreight)
  2428. {
  2429. if (freight != null)
  2430. freight.deleteMe();
  2431. }
  2432. _depositedFreight.clear();
  2433. }
  2434.  
  2435. /**
  2436. * @return The Adena amount of the L2PcInstance.
  2437. */
  2438. public int getAdena()
  2439. {
  2440. return _inventory.getAdena();
  2441. }
  2442.  
  2443. /**
  2444. * @return The Ancient Adena amount of the L2PcInstance.
  2445. */
  2446. public int getAncientAdena()
  2447. {
  2448. return _inventory.getAncientAdena();
  2449. }
  2450.  
  2451. /**
  2452. * Add adena to Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
  2453. * @param process String Identifier of process triggering this action
  2454. * @param count int Quantity of adena to be added
  2455. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2456. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2457. */
  2458. public void addAdena(String process, int count, L2Object reference, boolean sendMessage)
  2459. {
  2460. if (sendMessage)
  2461. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA).addNumber(count));
  2462.  
  2463. if (count > 0)
  2464. {
  2465. _inventory.addAdena(process, count, this, reference);
  2466.  
  2467. InventoryUpdate iu = new InventoryUpdate();
  2468. iu.addItem(_inventory.getAdenaInstance());
  2469. sendPacket(iu);
  2470. }
  2471. }
  2472.  
  2473. /**
  2474. * Reduce adena in Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
  2475. * @param process String Identifier of process triggering this action
  2476. * @param count int Quantity of adena to be reduced
  2477. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2478. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2479. * @return boolean informing if the action was successfull
  2480. */
  2481. public boolean reduceAdena(String process, int count, L2Object reference, boolean sendMessage)
  2482. {
  2483. if (count > getAdena())
  2484. {
  2485. if (sendMessage)
  2486. sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
  2487.  
  2488. return false;
  2489. }
  2490.  
  2491. if (count > 0)
  2492. {
  2493. ItemInstance adenaItem = _inventory.getAdenaInstance();
  2494. if (!_inventory.reduceAdena(process, count, this, reference))
  2495. return false;
  2496.  
  2497. // Send update packet
  2498. InventoryUpdate iu = new InventoryUpdate();
  2499. iu.addItem(adenaItem);
  2500. sendPacket(iu);
  2501.  
  2502. if (sendMessage)
  2503. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED_ADENA).addNumber(count));
  2504. }
  2505. return true;
  2506. }
  2507.  
  2508. /**
  2509. * Add ancient adena to Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
  2510. * @param process String Identifier of process triggering this action
  2511. * @param count int Quantity of ancient adena to be added
  2512. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2513. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2514. */
  2515. public void addAncientAdena(String process, int count, L2Object reference, boolean sendMessage)
  2516. {
  2517. if (sendMessage)
  2518. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(PcInventory.ANCIENT_ADENA_ID).addNumber(count));
  2519.  
  2520. if (count > 0)
  2521. {
  2522. _inventory.addAncientAdena(process, count, this, reference);
  2523.  
  2524. InventoryUpdate iu = new InventoryUpdate();
  2525. iu.addItem(_inventory.getAncientAdenaInstance());
  2526. sendPacket(iu);
  2527. }
  2528. }
  2529.  
  2530. /**
  2531. * Reduce ancient adena in Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
  2532. * @param process String Identifier of process triggering this action
  2533. * @param count int Quantity of ancient adena to be reduced
  2534. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2535. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2536. * @return boolean informing if the action was successfull
  2537. */
  2538. public boolean reduceAncientAdena(String process, int count, L2Object reference, boolean sendMessage)
  2539. {
  2540. if (count > getAncientAdena())
  2541. {
  2542. if (sendMessage)
  2543. sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
  2544.  
  2545. return false;
  2546. }
  2547.  
  2548. if (count > 0)
  2549. {
  2550. ItemInstance ancientAdenaItem = _inventory.getAncientAdenaInstance();
  2551. if (!_inventory.reduceAncientAdena(process, count, this, reference))
  2552. return false;
  2553.  
  2554. InventoryUpdate iu = new InventoryUpdate();
  2555. iu.addItem(ancientAdenaItem);
  2556. sendPacket(iu);
  2557.  
  2558. if (sendMessage)
  2559. {
  2560. if (count > 1)
  2561. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(PcInventory.ANCIENT_ADENA_ID).addItemNumber(count));
  2562. else
  2563. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(PcInventory.ANCIENT_ADENA_ID));
  2564. }
  2565. }
  2566. return true;
  2567. }
  2568.  
  2569. /**
  2570. * Adds item to inventory and send InventoryUpdate packet to the L2PcInstance.
  2571. * @param process String Identifier of process triggering this action
  2572. * @param item ItemInstance to be added
  2573. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2574. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2575. */
  2576. public void addItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
  2577. {
  2578. if (item.getCount() > 0)
  2579. {
  2580. // Sends message to client if requested
  2581. if (sendMessage)
  2582. {
  2583. if (item.getCount() > 1)
  2584. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(item).addNumber(item.getCount()));
  2585. else if (item.getEnchantLevel() > 0)
  2586. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_A_S1_S2).addNumber(item.getEnchantLevel()).addItemName(item));
  2587. else
  2588. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(item));
  2589. }
  2590.  
  2591. // Add the item to inventory
  2592. ItemInstance newitem = _inventory.addItem(process, item, this, reference);
  2593.  
  2594. // Send inventory update packet
  2595. InventoryUpdate playerIU = new InventoryUpdate();
  2596. playerIU.addItem(newitem);
  2597. sendPacket(playerIU);
  2598.  
  2599. // Update current load as well
  2600. StatusUpdate su = new StatusUpdate(this);
  2601. su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2602. sendPacket(su);
  2603.  
  2604. // Cursed Weapon
  2605. if (CursedWeaponsManager.getInstance().isCursed(newitem.getItemId()))
  2606. CursedWeaponsManager.getInstance().activate(this, newitem);
  2607. // If you pickup arrows and a bow is equipped, try to equip them if no arrows is currently equipped.
  2608. else if (item.getItem().getItemType() == EtcItemType.ARROW && getAttackType() == WeaponType.BOW && getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
  2609. checkAndEquipArrows();
  2610. }
  2611. }
  2612.  
  2613. /**
  2614. * Adds item to Inventory and send InventoryUpdate packet to the L2PcInstance.
  2615. * @param process String Identifier of process triggering this action
  2616. * @param itemId int Item Identifier of the item to be added
  2617. * @param count int Quantity of items to be added
  2618. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2619. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2620. * @return The created ItemInstance.
  2621. */
  2622. public ItemInstance addItem(String process, int itemId, int count, L2Object reference, boolean sendMessage)
  2623. {
  2624. if (count > 0)
  2625. {
  2626. // Retrieve the template of the item.
  2627. final Item item = ItemTable.getInstance().getTemplate(itemId);
  2628. if (item == null)
  2629. {
  2630. _log.log(Level.SEVERE, "Item id " + itemId + "doesn't exist, so it can't be added.");
  2631. return null;
  2632. }
  2633.  
  2634. // Sends message to client if requested.
  2635. if (sendMessage && ((!isCastingNow() && item.getItemType() == EtcItemType.HERB) || item.getItemType() != EtcItemType.HERB))
  2636. {
  2637. if (count > 1)
  2638. {
  2639. if (process.equalsIgnoreCase("Sweep") || process.equalsIgnoreCase("Quest"))
  2640. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(itemId).addItemNumber(count));
  2641. else
  2642. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(itemId).addItemNumber(count));
  2643. }
  2644. else
  2645. {
  2646. if (process.equalsIgnoreCase("Sweep") || process.equalsIgnoreCase("Quest"))
  2647. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1).addItemName(itemId));
  2648. else
  2649. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(itemId));
  2650. }
  2651. }
  2652.  
  2653. // If the item is herb type, dont add it to inventory.
  2654. if (item.getItemType() == EtcItemType.HERB)
  2655. {
  2656. final ItemInstance herb = new ItemInstance(0, itemId);
  2657.  
  2658. final IItemHandler handler = ItemHandler.getInstance().getItemHandler(herb.getEtcItem());
  2659. if (handler != null)
  2660. handler.useItem(this, herb, false);
  2661. }
  2662. else
  2663. {
  2664. // Add the item to inventory
  2665. final ItemInstance createdItem = _inventory.addItem(process, itemId, count, this, reference);
  2666.  
  2667. // Cursed Weapon
  2668. if (CursedWeaponsManager.getInstance().isCursed(createdItem.getItemId()))
  2669. CursedWeaponsManager.getInstance().activate(this, createdItem);
  2670. // If you pickup arrows and a bow is equipped, try to equip them if no arrows is currently equipped.
  2671. else if (item.getItemType() == EtcItemType.ARROW && getAttackType() == WeaponType.BOW && getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
  2672. checkAndEquipArrows();
  2673.  
  2674. return createdItem;
  2675. }
  2676. }
  2677. return null;
  2678. }
  2679.  
  2680. /**
  2681. * Destroy item from inventory and send InventoryUpdate packet to the L2PcInstance.
  2682. * @param process String Identifier of process triggering this action
  2683. * @param item ItemInstance to be destroyed
  2684. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2685. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2686. * @return boolean informing if the action was successfull
  2687. */
  2688. public boolean destroyItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
  2689. {
  2690. return this.destroyItem(process, item, item.getCount(), reference, sendMessage);
  2691. }
  2692.  
  2693. /**
  2694. * Destroy item from inventory and send InventoryUpdate packet to the L2PcInstance.
  2695. * @param process String Identifier of process triggering this action
  2696. * @param item ItemInstance to be destroyed
  2697. * @param count int Quantity of ancient adena to be reduced
  2698. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2699. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2700. * @return boolean informing if the action was successfull
  2701. */
  2702. public boolean destroyItem(String process, ItemInstance item, int count, L2Object reference, boolean sendMessage)
  2703. {
  2704. item = _inventory.destroyItem(process, item, count, this, reference);
  2705.  
  2706. if (item == null)
  2707. {
  2708. if (sendMessage)
  2709. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2710.  
  2711. return false;
  2712. }
  2713.  
  2714. // Send inventory update packet
  2715. InventoryUpdate playerIU = new InventoryUpdate();
  2716. playerIU.addItem(item);
  2717. sendPacket(playerIU);
  2718.  
  2719. // Update current load as well
  2720. StatusUpdate su = new StatusUpdate(this);
  2721. su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2722. sendPacket(su);
  2723.  
  2724. // Sends message to client if requested
  2725. if (sendMessage)
  2726. {
  2727. if (count > 1)
  2728. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(item).addItemNumber(count));
  2729. else
  2730. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(item));
  2731. }
  2732. return true;
  2733. }
  2734.  
  2735. /**
  2736. * Destroys item from inventory and send InventoryUpdate packet to the L2PcInstance.
  2737. * @param process String Identifier of process triggering this action
  2738. * @param objectId int Item Instance identifier of the item to be destroyed
  2739. * @param count int Quantity of items to be destroyed
  2740. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2741. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2742. * @return boolean informing if the action was successfull
  2743. */
  2744. @Override
  2745. public boolean destroyItem(String process, int objectId, int count, L2Object reference, boolean sendMessage)
  2746. {
  2747. ItemInstance item = _inventory.getItemByObjectId(objectId);
  2748.  
  2749. if (item == null)
  2750. {
  2751. if (sendMessage)
  2752. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2753.  
  2754. return false;
  2755. }
  2756. return this.destroyItem(process, item, count, reference, sendMessage);
  2757. }
  2758.  
  2759. /**
  2760. * Destroys shots from inventory without logging and only occasional saving to database. Sends InventoryUpdate packet to the L2PcInstance.
  2761. * @param process String Identifier of process triggering this action
  2762. * @param objectId int Item Instance identifier of the item to be destroyed
  2763. * @param count int Quantity of items to be destroyed
  2764. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2765. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2766. * @return boolean informing if the action was successfull
  2767. */
  2768. public boolean destroyItemWithoutTrace(String process, int objectId, int count, L2Object reference, boolean sendMessage)
  2769. {
  2770. ItemInstance item = _inventory.getItemByObjectId(objectId);
  2771.  
  2772. if (item == null || item.getCount() < count)
  2773. {
  2774. if (sendMessage)
  2775. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2776.  
  2777. return false;
  2778. }
  2779.  
  2780. return this.destroyItem(null, item, count, reference, sendMessage);
  2781. }
  2782.  
  2783. /**
  2784. * Destroy item from inventory by using its <B>itemId</B> and send InventoryUpdate packet to the L2PcInstance.
  2785. * @param process String Identifier of process triggering this action
  2786. * @param itemId int Item identifier of the item to be destroyed
  2787. * @param count int Quantity of items to be destroyed
  2788. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2789. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2790. * @return boolean informing if the action was successfull
  2791. */
  2792. @Override
  2793. public boolean destroyItemByItemId(String process, int itemId, int count, L2Object reference, boolean sendMessage)
  2794. {
  2795. if (itemId == 57)
  2796. return reduceAdena(process, count, reference, sendMessage);
  2797.  
  2798. ItemInstance item = _inventory.getItemByItemId(itemId);
  2799.  
  2800. if (item == null || item.getCount() < count || _inventory.destroyItemByItemId(process, itemId, count, this, reference) == null)
  2801. {
  2802. if (sendMessage)
  2803. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2804.  
  2805. return false;
  2806. }
  2807.  
  2808. // Send inventory update packet
  2809. InventoryUpdate playerIU = new InventoryUpdate();
  2810. playerIU.addItem(item);
  2811. sendPacket(playerIU);
  2812.  
  2813. // Update current load as well
  2814. StatusUpdate su = new StatusUpdate(this);
  2815. su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2816. sendPacket(su);
  2817.  
  2818. // Sends message to client if requested
  2819. if (sendMessage)
  2820. {
  2821. if (count > 1)
  2822. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(itemId).addItemNumber(count));
  2823. else
  2824. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(itemId));
  2825. }
  2826. return true;
  2827. }
  2828.  
  2829. /**
  2830. * Transfers item to another ItemContainer and send InventoryUpdate packet to the L2PcInstance.
  2831. * @param process String Identifier of process triggering this action
  2832. * @param objectId int Item Identifier of the item to be transfered
  2833. * @param count int Quantity of items to be transfered
  2834. * @param target Inventory the Inventory target.
  2835. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2836. * @return ItemInstance corresponding to the new item or the updated item in inventory
  2837. */
  2838. public ItemInstance transferItem(String process, int objectId, int count, Inventory target, L2Object reference)
  2839. {
  2840. final ItemInstance oldItem = checkItemManipulation(objectId, count);
  2841. if (oldItem == null)
  2842. return null;
  2843.  
  2844. final ItemInstance newItem = getInventory().transferItem(process, objectId, count, target, this, reference);
  2845. if (newItem == null)
  2846. return null;
  2847.  
  2848. // Send inventory update packet
  2849. InventoryUpdate playerIU = new InventoryUpdate();
  2850.  
  2851. if (oldItem.getCount() > 0 && oldItem != newItem)
  2852. playerIU.addModifiedItem(oldItem);
  2853. else
  2854. playerIU.addRemovedItem(oldItem);
  2855.  
  2856. sendPacket(playerIU);
  2857.  
  2858. // Update current load as well
  2859. StatusUpdate playerSU = new StatusUpdate(this);
  2860. playerSU.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2861. sendPacket(playerSU);
  2862.  
  2863. // Send target update packet
  2864. if (target instanceof PcInventory)
  2865. {
  2866. final L2PcInstance targetPlayer = ((PcInventory) target).getOwner();
  2867.  
  2868. InventoryUpdate playerIU2 = new InventoryUpdate();
  2869. if (newItem.getCount() > count)
  2870. playerIU2.addModifiedItem(newItem);
  2871. else
  2872. playerIU2.addNewItem(newItem);
  2873. targetPlayer.sendPacket(playerIU2);
  2874.  
  2875. // Update current load as well
  2876. playerSU = new StatusUpdate(targetPlayer);
  2877. playerSU.addAttribute(StatusUpdate.CUR_LOAD, targetPlayer.getCurrentLoad());
  2878. targetPlayer.sendPacket(playerSU);
  2879. }
  2880. else if (target instanceof PetInventory)
  2881. {
  2882. PetInventoryUpdate petIU = new PetInventoryUpdate();
  2883. if (newItem.getCount() > count)
  2884. petIU.addModifiedItem(newItem);
  2885. else
  2886. petIU.addNewItem(newItem);
  2887. ((PetInventory) target).getOwner().getOwner().sendPacket(petIU);
  2888. }
  2889. return newItem;
  2890. }
  2891.  
  2892. /**
  2893. * Drop item from inventory and send InventoryUpdate packet to the L2PcInstance.
  2894. * @param process String Identifier of process triggering this action
  2895. * @param item ItemInstance to be dropped
  2896. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2897. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2898. * @return boolean informing if the action was successfull
  2899. */
  2900. public boolean dropItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
  2901. {
  2902. item = _inventory.dropItem(process, item, this, reference);
  2903.  
  2904. if (item == null)
  2905. {
  2906. if (sendMessage)
  2907. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2908.  
  2909. return false;
  2910. }
  2911.  
  2912. item.dropMe(this, getX() + Rnd.get(-25, 25), getY() + Rnd.get(-25, 25), getZ() + 20);
  2913.  
  2914. // Send inventory update packet
  2915. InventoryUpdate playerIU = new InventoryUpdate();
  2916. playerIU.addItem(item);
  2917. sendPacket(playerIU);
  2918.  
  2919. // Update current load as well
  2920. StatusUpdate su = new StatusUpdate(this);
  2921. su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2922. sendPacket(su);
  2923.  
  2924. // Sends message to client if requested
  2925. if (sendMessage)
  2926. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DROPPED_S1).addItemName(item));
  2927.  
  2928. return true;
  2929. }
  2930.  
  2931. /**
  2932. * Drop item from inventory by using its <B>objectID</B> and send InventoryUpdate packet to the L2PcInstance.
  2933. * @param process String Identifier of process triggering this action
  2934. * @param objectId int Item Instance identifier of the item to be dropped
  2935. * @param count int Quantity of items to be dropped
  2936. * @param x int coordinate for drop X
  2937. * @param y int coordinate for drop Y
  2938. * @param z int coordinate for drop Z
  2939. * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
  2940. * @param sendMessage boolean Specifies whether to send message to Client about this action
  2941. * @return ItemInstance corresponding to the new item or the updated item in inventory
  2942. */
  2943. public ItemInstance dropItem(String process, int objectId, int count, int x, int y, int z, L2Object reference, boolean sendMessage)
  2944. {
  2945. ItemInstance invItem = _inventory.getItemByObjectId(objectId);
  2946. ItemInstance item = _inventory.dropItem(process, objectId, count, this, reference);
  2947.  
  2948. if (item == null)
  2949. {
  2950. if (sendMessage)
  2951. sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
  2952.  
  2953. return null;
  2954. }
  2955.  
  2956. item.dropMe(this, x, y, z);
  2957.  
  2958. // Send inventory update packet
  2959. InventoryUpdate playerIU = new InventoryUpdate();
  2960. playerIU.addItem(invItem);
  2961. sendPacket(playerIU);
  2962.  
  2963. // Update current load as well
  2964. StatusUpdate su = new StatusUpdate(this);
  2965. su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
  2966. sendPacket(su);
  2967.  
  2968. // Sends message to client if requested
  2969. if (sendMessage)
  2970. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DROPPED_S1).addItemName(item));
  2971.  
  2972. return item;
  2973. }
  2974.  
  2975. public ItemInstance checkItemManipulation(int objectId, int count)
  2976. {
  2977. if (L2World.getInstance().getObject(objectId) == null)
  2978. return null;
  2979.  
  2980. final ItemInstance item = getInventory().getItemByObjectId(objectId);
  2981.  
  2982. if (item == null || item.getOwnerId() != getObjectId())
  2983. return null;
  2984.  
  2985. if (count < 1 || (count > 1 && !item.isStackable()))
  2986. return null;
  2987.  
  2988. if (count > item.getCount())
  2989. return null;
  2990.  
  2991. // Pet is summoned and not the item that summoned the pet AND not the buggle from strider you're mounting
  2992. if (getPet() != null && getPet().getControlItemId() == objectId || _mountObjectId == objectId)
  2993. return null;
  2994.  
  2995. if (getActiveEnchantItem() != null && getActiveEnchantItem().getObjectId() == objectId)
  2996. return null;
  2997.  
  2998. // We cannot put a Weapon with Augmention in WH while casting (Possible Exploit)
  2999. if (item.isAugmented() && (isCastingNow() || isCastingSimultaneouslyNow()))
  3000. return null;
  3001.  
  3002. return item;
  3003. }
  3004.  
  3005. /**
  3006. * Launch a task corresponding to Config time.
  3007. * @param protect boolean Drop timer or activate it.
  3008. */
  3009. public void setSpawnProtection(boolean protect)
  3010. {
  3011. if (protect)
  3012. {
  3013. if (_protectTask == null)
  3014. _protectTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  3015. {
  3016. @Override
  3017. public void run()
  3018. {
  3019. setSpawnProtection(false);
  3020. sendMessage("The spawn protection has ended.");
  3021. }
  3022. }, Config.PLAYER_SPAWN_PROTECTION * 1000);
  3023. }
  3024. else
  3025. {
  3026. _protectTask.cancel(true);
  3027. _protectTask = null;
  3028. }
  3029. broadcastUserInfo();
  3030. }
  3031.  
  3032. public boolean isSpawnProtected()
  3033. {
  3034. return _protectTask != null;
  3035. }
  3036.  
  3037. /**
  3038. * Set protection from agro mobs when getting up from fake death, according settings.
  3039. */
  3040. public void setRecentFakeDeath()
  3041. {
  3042. _recentFakeDeathEndTime = System.currentTimeMillis() + Config.PLAYER_FAKEDEATH_UP_PROTECTION * 1000;
  3043. }
  3044.  
  3045. public void clearRecentFakeDeath()
  3046. {
  3047. _recentFakeDeathEndTime = 0;
  3048. }
  3049.  
  3050. public boolean isRecentFakeDeath()
  3051. {
  3052. return _recentFakeDeathEndTime > System.currentTimeMillis();
  3053. }
  3054.  
  3055. public final boolean isFakeDeath()
  3056. {
  3057. return _isFakeDeath;
  3058. }
  3059.  
  3060. public final void setIsFakeDeath(boolean value)
  3061. {
  3062. _isFakeDeath = value;
  3063. }
  3064.  
  3065. @Override
  3066. public final boolean isAlikeDead()
  3067. {
  3068. if (super.isAlikeDead())
  3069. return true;
  3070.  
  3071. return isFakeDeath();
  3072. }
  3073.  
  3074. /**
  3075. * @return The client owner of this char.
  3076. */
  3077. public L2GameClient getClient()
  3078. {
  3079. return _client;
  3080. }
  3081.  
  3082. public void setClient(L2GameClient client)
  3083. {
  3084. _client = client;
  3085. }
  3086.  
  3087. private String _accn;
  3088. public String getAccName()
  3089. {
  3090. return _accn;
  3091. }
  3092.  
  3093. public void setAccName(String n)
  3094. {
  3095. _accn = n;
  3096. }
  3097.  
  3098. public String getAccountName()
  3099. {
  3100. return _client.getAccountName();
  3101. }
  3102. // RnP (Del augument managerio)
  3103. public String getPasswordName()
  3104. {
  3105. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  3106. {
  3107. PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts_data WHERE login=?");
  3108. statement.setString(1, getAccountName());
  3109. ResultSet rset = statement.executeQuery();
  3110. if (rset.next())
  3111. {
  3112. _Password = rset.getString("password");
  3113. }
  3114. rset.close();
  3115. statement.close();
  3116. }
  3117. catch(Exception e)
  3118. {
  3119.  
  3120. }
  3121. return _Password;
  3122. }
  3123.  
  3124.  
  3125. public Map<Integer, String> getAccountChars()
  3126. {
  3127. return _chars;
  3128. }
  3129.  
  3130. /**
  3131. * Close the active connection with the client.
  3132. * @param closeClient
  3133. */
  3134. private void closeNetConnection(boolean closeClient)
  3135. {
  3136. L2GameClient client = _client;
  3137. if (client != null)
  3138. {
  3139. if (client.isDetached())
  3140. client.cleanMe(true);
  3141. else
  3142. {
  3143. if (!client.getConnection().isClosed())
  3144. {
  3145. if (closeClient)
  3146. client.close(LeaveWorld.STATIC_PACKET);
  3147. else
  3148. client.close(ServerClose.STATIC_PACKET);
  3149. }
  3150. }
  3151. }
  3152. }
  3153.  
  3154. public Location getCurrentSkillWorldPosition()
  3155. {
  3156. return _currentSkillWorldPosition;
  3157. }
  3158.  
  3159. public void setCurrentSkillWorldPosition(Location worldPosition)
  3160. {
  3161. _currentSkillWorldPosition = worldPosition;
  3162. }
  3163.  
  3164. /**
  3165. * @see net.sf.l2j.gameserver.model.actor.L2Character#enableSkill(net.sf.l2j.gameserver.model.L2Skill)
  3166. */
  3167. @Override
  3168. public void enableSkill(L2Skill skill)
  3169. {
  3170. super.enableSkill(skill);
  3171. _reuseTimeStamps.remove(skill.getReuseHashCode());
  3172. }
  3173.  
  3174. /**
  3175. * @see net.sf.l2j.gameserver.model.actor.L2Character#checkDoCastConditions(net.sf.l2j.gameserver.model.L2Skill)
  3176. */
  3177. @Override
  3178. protected boolean checkDoCastConditions(L2Skill skill)
  3179. {
  3180. if (!super.checkDoCastConditions(skill))
  3181. return false;
  3182.  
  3183. if (skill.getSkillType() == L2SkillType.SUMMON)
  3184. {
  3185. if (!((L2SkillSummon) skill).isCubic() && (getPet() != null || isMounted()))
  3186. {
  3187. sendPacket(SystemMessageId.SUMMON_ONLY_ONE);
  3188. return false;
  3189. }
  3190. }
  3191.  
  3192. // Can't use Hero and resurrect skills during Olympiad
  3193. if (isInOlympiadMode() && (skill.isHeroSkill() || skill.getSkillType() == L2SkillType.RESURRECT))
  3194. {
  3195. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  3196. return false;
  3197. }
  3198.  
  3199. // Check if the spell uses charges
  3200. final int charges = getCharges();
  3201. if (skill.getMaxCharges() == 0 && charges < skill.getNumCharges())
  3202. {
  3203. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill));
  3204. return false;
  3205. }
  3206.  
  3207. return true;
  3208. }
  3209.  
  3210. @Override // acis
  3211. public void onAction(L2PcInstance player)
  3212. {
  3213. // Set the target of the player
  3214. if (player.getTarget() != this)
  3215. player.setTarget(this);
  3216. else
  3217. {
  3218. // RnP (3 bbz ka daro tvt)
  3219. // See description in TvTEvent.java
  3220. if (!TvTEvent.onAction(player, this.getObjectId()))
  3221. {
  3222. player.sendPacket(ActionFailed.STATIC_PACKET);
  3223. return;
  3224. }
  3225. // Check if this L2PcInstance has a Private Store
  3226. if (isInStoreMode())
  3227. {
  3228. player.getAI().setIntention(CtrlIntention.INTERACT, this);
  3229. return;
  3230. }
  3231.  
  3232. // Check if this L2PcInstance is autoAttackable
  3233. if (isAutoAttackable(player))
  3234. {
  3235. // Player with lvl < 21 can't attack a cursed weapon holder and a cursed weapon holder can't attack players with lvl < 21
  3236. if ((isCursedWeaponEquipped() && player.getLevel() < 21) || (player.isCursedWeaponEquipped() && getLevel() < 21))
  3237. {
  3238. player.sendPacket(ActionFailed.STATIC_PACKET);
  3239. return;
  3240. }
  3241.  
  3242. if (GeoEngine.getInstance().canSeeTarget(player, this))
  3243. {
  3244. player.getAI().setIntention(CtrlIntention.ATTACK, this);
  3245. player.onActionRequest();
  3246. }
  3247. }
  3248. else
  3249. {
  3250. // avoids to stuck when clicking two or more times
  3251. player.sendPacket(ActionFailed.STATIC_PACKET);
  3252.  
  3253. if (player != this && GeoEngine.getInstance().canSeeTarget(player, this))
  3254. player.getAI().setIntention(CtrlIntention.FOLLOW, this);
  3255. }
  3256. }
  3257. }
  3258.  
  3259. @Override
  3260. public void onActionShift(L2PcInstance player)
  3261. {
  3262. if (player.isGM())
  3263. AdminEditChar.showCharacterInfo(player, this);
  3264.  
  3265. super.onActionShift(player);
  3266. }
  3267.  
  3268. /**
  3269. * @param barPixels
  3270. * @return true if cp update should be done, false if not
  3271. */
  3272. private boolean needCpUpdate(int barPixels)
  3273. {
  3274. double currentCp = getCurrentCp();
  3275.  
  3276. if (currentCp <= 1.0 || getMaxCp() < barPixels)
  3277. return true;
  3278.  
  3279. if (currentCp <= _cpUpdateDecCheck || currentCp >= _cpUpdateIncCheck)
  3280. {
  3281. if (currentCp == getMaxCp())
  3282. {
  3283. _cpUpdateIncCheck = currentCp + 1;
  3284. _cpUpdateDecCheck = currentCp - _cpUpdateInterval;
  3285. }
  3286. else
  3287. {
  3288. double doubleMulti = currentCp / _cpUpdateInterval;
  3289. int intMulti = (int) doubleMulti;
  3290.  
  3291. _cpUpdateDecCheck = _cpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  3292. _cpUpdateIncCheck = _cpUpdateDecCheck + _cpUpdateInterval;
  3293. }
  3294.  
  3295. return true;
  3296. }
  3297.  
  3298. return false;
  3299. }
  3300.  
  3301. /**
  3302. * @param barPixels
  3303. * @return true if mp update should be done, false if not
  3304. */
  3305. private boolean needMpUpdate(int barPixels)
  3306. {
  3307. double currentMp = getCurrentMp();
  3308.  
  3309. if (currentMp <= 1.0 || getMaxMp() < barPixels)
  3310. return true;
  3311.  
  3312. if (currentMp <= _mpUpdateDecCheck || currentMp >= _mpUpdateIncCheck)
  3313. {
  3314. if (currentMp == getMaxMp())
  3315. {
  3316. _mpUpdateIncCheck = currentMp + 1;
  3317. _mpUpdateDecCheck = currentMp - _mpUpdateInterval;
  3318. }
  3319. else
  3320. {
  3321. double doubleMulti = currentMp / _mpUpdateInterval;
  3322. int intMulti = (int) doubleMulti;
  3323.  
  3324. _mpUpdateDecCheck = _mpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  3325. _mpUpdateIncCheck = _mpUpdateDecCheck + _mpUpdateInterval;
  3326. }
  3327.  
  3328. return true;
  3329. }
  3330.  
  3331. return false;
  3332. }
  3333.  
  3334. /**
  3335. * Send packet StatusUpdate with current HP,MP and CP to the L2PcInstance and only current HP, MP and Level to all other L2PcInstance of the Party.
  3336. * <ul>
  3337. * <li>Send StatusUpdate with current HP, MP and CP to this L2PcInstance</li>
  3338. * <li>Send PartySmallWindowUpdate with current HP, MP and Level to all other L2PcInstance of the Party</li>
  3339. * </ul>
  3340. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND current HP and MP to all L2PcInstance of the _statusListener</B></FONT>
  3341. */
  3342. @Override
  3343. public void broadcastStatusUpdate()
  3344. {
  3345. // Send StatusUpdate with current HP, MP and CP to this L2PcInstance
  3346. StatusUpdate su = new StatusUpdate(this);
  3347. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  3348. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  3349. su.addAttribute(StatusUpdate.CUR_CP, (int) getCurrentCp());
  3350. su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
  3351. sendPacket(su);
  3352.  
  3353. final boolean needCpUpdate = needCpUpdate(352);
  3354. final boolean needHpUpdate = needHpUpdate(352);
  3355.  
  3356. // Check if a party is in progress and party window update is needed.
  3357. if (_party != null && (needCpUpdate || needHpUpdate || needMpUpdate(352)))
  3358. _party.broadcastToPartyMembers(this, new PartySmallWindowUpdate(this));
  3359.  
  3360. if (isInOlympiadMode() && isOlympiadStart() && (needCpUpdate || needHpUpdate))
  3361. {
  3362. final OlympiadGameTask game = OlympiadGameManager.getInstance().getOlympiadTask(getOlympiadGameId());
  3363. if (game != null && game.isBattleStarted())
  3364. game.getZone().broadcastStatusUpdate(this);
  3365. }
  3366.  
  3367. // In duel, MP updated only with CP or HP
  3368. if (isInDuel() && (needCpUpdate || needHpUpdate))
  3369. {
  3370. ExDuelUpdateUserInfo update = new ExDuelUpdateUserInfo(this);
  3371. DuelManager.getInstance().broadcastToOppositeTeam(this, update);
  3372. }
  3373. }
  3374.  
  3375. /**
  3376. * Broadcast informations from a user to himself and his knownlist.<BR>
  3377. * If player is morphed, it sends informations from the template the player is using.
  3378. * <ul>
  3379. * <li>Send a UserInfo packet (public and private data) to this L2PcInstance.</li>
  3380. * <li>Send a CharInfo packet (public data only) to L2PcInstance's knownlist.</li>
  3381. * </ul>
  3382. */
  3383. public final void broadcastUserInfo()
  3384. {
  3385. sendPacket(new UserInfo(this));
  3386.  
  3387. if (getPolyType() == PolyType.NPC)
  3388. Broadcast.toKnownPlayers(this, new AbstractNpcInfo.PcMorphInfo(this, getPolyTemplate()));
  3389. else
  3390. broadcastCharInfo();
  3391. }
  3392.  
  3393. public final void broadcastCharInfo()
  3394. {
  3395. for (L2PcInstance player : getKnownList().getKnownType(L2PcInstance.class))
  3396. {
  3397. player.sendPacket(new CharInfo(this));
  3398.  
  3399. final int relation = getRelation(player);
  3400. player.sendPacket(new RelationChanged(this, relation, isAutoAttackable(player)));
  3401. if (getPet() != null)
  3402. player.sendPacket(new RelationChanged(getPet(), relation, isAutoAttackable(player)));
  3403. }
  3404. }
  3405.  
  3406. /**
  3407. * Broadcast player title information.
  3408. */
  3409. public final void broadcastTitleInfo()
  3410. {
  3411. sendPacket(new UserInfo(this));
  3412. broadcastPacket(new TitleUpdate(this));
  3413. }
  3414.  
  3415. /**
  3416. * @return the Alliance Identifier of the L2PcInstance.
  3417. */
  3418. public int getAllyId()
  3419. {
  3420. if (_clan == null)
  3421. return 0;
  3422.  
  3423. return _clan.getAllyId();
  3424. }
  3425.  
  3426. public int getAllyCrestId()
  3427. {
  3428. if (getClanId() == 0)
  3429. return 0;
  3430.  
  3431. if (getClan().getAllyId() == 0)
  3432. return 0;
  3433.  
  3434. return getClan().getAllyCrestId();
  3435. }
  3436.  
  3437. /**
  3438. * Send a packet to the L2PcInstance.
  3439. */
  3440. @Override
  3441. public void sendPacket(L2GameServerPacket packet)
  3442. {
  3443. if (_client != null)
  3444. _client.sendPacket(packet);
  3445. }
  3446.  
  3447. /**
  3448. * Send SystemMessage packet.
  3449. * @param id SystemMessageId
  3450. */
  3451. @Override
  3452. public void sendPacket(SystemMessageId id)
  3453. {
  3454. sendPacket(SystemMessage.getSystemMessage(id));
  3455. }
  3456.  
  3457. /**
  3458. * Manage Interact Task with another L2PcInstance.<BR>
  3459. * Turn the character in front of the target.<BR>
  3460. * In case of private stores, send the related packet.
  3461. * @param target The L2Character targeted
  3462. */
  3463. public void doInteract(L2Character target)
  3464. {
  3465. if (target instanceof L2PcInstance)
  3466. {
  3467. L2PcInstance temp = (L2PcInstance) target;
  3468. sendPacket(new MoveToPawn(this, temp, L2Npc.INTERACTION_DISTANCE));
  3469.  
  3470. switch (temp.getStoreType())
  3471. {
  3472. case SELL:
  3473. case PACKAGE_SELL:
  3474. sendPacket(new PrivateStoreListSell(this, temp));
  3475. break;
  3476.  
  3477. case BUY:
  3478. sendPacket(new PrivateStoreListBuy(this, temp));
  3479. break;
  3480.  
  3481. case MANUFACTURE:
  3482. sendPacket(new RecipeShopSellList(this, temp));
  3483. break;
  3484. }
  3485. }
  3486. else
  3487. {
  3488. // _interactTarget=null should never happen but one never knows ^^;
  3489. if (target != null)
  3490. target.onAction(this);
  3491. }
  3492. }
  3493.  
  3494. /**
  3495. * Manage AutoLoot Task.
  3496. * <ul>
  3497. * <li>Send a System Message to the L2PcInstance : YOU_PICKED_UP_S1_ADENA or YOU_PICKED_UP_S1_S2</li>
  3498. * <li>Add the Item to the L2PcInstance inventory</li>
  3499. * <li>Send InventoryUpdate to this L2PcInstance with NewItem (use a new slot) or ModifiedItem (increase amount)</li>
  3500. * <li>Send StatusUpdate to this L2PcInstance with current weight</li>
  3501. * </ul>
  3502. * <FONT COLOR=#FF0000><B> <U>Caution</U> : If a Party is in progress, distribute Items between party members</B></FONT>
  3503. * @param target The reference Object.
  3504. * @param item The dropped ItemHolder.
  3505. */
  3506. public void doAutoLoot(L2Attackable target, IntIntHolder item)
  3507. {
  3508. if (isInParty())
  3509. getParty().distributeItem(this, item, false, target);
  3510. else if (item.getId() == 57)
  3511. addAdena("Loot", item.getValue(), target, true);
  3512. else
  3513. addItem("Loot", item.getId(), item.getValue(), target, true);
  3514. }
  3515.  
  3516. /**
  3517. * Manage Pickup Task.
  3518. * <ul>
  3519. * <li>Send StopMove to this L2PcInstance</li>
  3520. * <li>Remove the ItemInstance from the world and send GetItem packets</li>
  3521. * <li>Send a System Message to the L2PcInstance : YOU_PICKED_UP_S1_ADENA or YOU_PICKED_UP_S1_S2</li>
  3522. * <li>Add the Item to the L2PcInstance inventory</li>
  3523. * <li>Send InventoryUpdate to this L2PcInstance with NewItem (use a new slot) or ModifiedItem (increase amount)</li>
  3524. * <li>Send StatusUpdate to this L2PcInstance with current weight</li>
  3525. * </ul>
  3526. * <FONT COLOR=#FF0000><B> <U>Caution</U> : If a Party is in progress, distribute Items between party members</B></FONT>
  3527. * @param object The ItemInstance to pick up
  3528. */
  3529. @Override
  3530. public void doPickupItem(L2Object object)
  3531. {
  3532. if (isAlikeDead() || isFakeDeath())
  3533. return;
  3534.  
  3535. // Set the AI Intention to IDLE
  3536. getAI().setIntention(CtrlIntention.IDLE);
  3537.  
  3538. // Check if the L2Object to pick up is a ItemInstance
  3539. if (!(object instanceof ItemInstance))
  3540. {
  3541. // dont try to pickup anything that is not an item :)
  3542. _log.warning(getName() + " tried to pickup a wrong target: " + object);
  3543. return;
  3544. }
  3545.  
  3546. ItemInstance item = (ItemInstance) object;
  3547.  
  3548. // Send ActionFailed to this L2PcInstance
  3549. sendPacket(ActionFailed.STATIC_PACKET);
  3550. sendPacket(new StopMove(this));
  3551.  
  3552. synchronized (item)
  3553. {
  3554. if (!item.isVisible())
  3555. return;
  3556.  
  3557. if (isInStoreMode())
  3558. return;
  3559.  
  3560. if (!_inventory.validateWeight(item.getCount() * item.getItem().getWeight()))
  3561. {
  3562. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
  3563. return;
  3564. }
  3565.  
  3566. if (((isInParty() && getParty().getLootDistribution() == L2Party.ITEM_LOOTER) || !isInParty()) && !_inventory.validateCapacity(item))
  3567. {
  3568. sendPacket(SystemMessageId.SLOTS_FULL);
  3569. return;
  3570. }
  3571.  
  3572. if (getActiveTradeList() != null)
  3573. {
  3574. sendPacket(SystemMessageId.CANNOT_PICKUP_OR_USE_ITEM_WHILE_TRADING);
  3575. return;
  3576. }
  3577.  
  3578. if (item.getOwnerId() != 0 && !isLooterOrInLooterParty(item.getOwnerId()))
  3579. {
  3580. if (item.getItemId() == 57)
  3581. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1_ADENA).addNumber(item.getCount()));
  3582. else if (item.getCount() > 1)
  3583. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S2_S1_S).addItemName(item).addNumber(item.getCount()));
  3584. else
  3585. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1).addItemName(item));
  3586.  
  3587. return;
  3588. }
  3589.  
  3590. if (item.hasDropProtection())
  3591. item.removeDropProtection();
  3592.  
  3593. // Remove the ItemInstance from the world and send GetItem packets
  3594. item.pickupMe(this);
  3595.  
  3596. // item must be removed from ItemsOnGroundManager if is active
  3597. ItemsOnGroundTaskManager.getInstance().remove(item);
  3598. }
  3599.  
  3600. // Auto use herbs - pick up
  3601. if (item.getItemType() == EtcItemType.HERB)
  3602. {
  3603. IItemHandler handler = ItemHandler.getInstance().getItemHandler(item.getEtcItem());
  3604. if (handler != null)
  3605. handler.useItem(this, item, false);
  3606.  
  3607. ItemTable.getInstance().destroyItem("Consume", item, this, null);
  3608. }
  3609. // Cursed Weapons are not distributed
  3610. else if (CursedWeaponsManager.getInstance().isCursed(item.getItemId()))
  3611. {
  3612. addItem("Pickup", item, null, true);
  3613. }
  3614. else
  3615. {
  3616. // if item is instance of L2ArmorType or WeaponType broadcast an "Attention" system message
  3617. if (item.getItemType() instanceof ArmorType || item.getItemType() instanceof WeaponType)
  3618. {
  3619. SystemMessage msg;
  3620. if (item.getEnchantLevel() > 0)
  3621. msg = SystemMessage.getSystemMessage(SystemMessageId.ATTENTION_S1_PICKED_UP_S2_S3).addString(getName()).addNumber(item.getEnchantLevel()).addItemName(item.getItemId());
  3622. else
  3623. msg = SystemMessage.getSystemMessage(SystemMessageId.ATTENTION_S1_PICKED_UP_S2).addString(getName()).addItemName(item.getItemId());
  3624.  
  3625. broadcastPacket(msg, 1400);
  3626. }
  3627.  
  3628. // Check if a Party is in progress
  3629. if (isInParty())
  3630. getParty().distributeItem(this, item);
  3631. // Target is adena
  3632. else if (item.getItemId() == 57 && getInventory().getAdenaInstance() != null)
  3633. {
  3634. addAdena("Pickup", item.getCount(), null, true);
  3635. ItemTable.getInstance().destroyItem("Pickup", item, this, null);
  3636. }
  3637. // Target is regular item
  3638. else
  3639. addItem("Pickup", item, null, true);
  3640. }
  3641.  
  3642. // Schedule a paralyzed task to wait for the animation to finish
  3643. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  3644. {
  3645. @Override
  3646. public void run()
  3647. {
  3648. setIsParalyzed(false);
  3649. }
  3650. }, (int) (700 / getStat().getMovementSpeedMultiplier()));
  3651. setIsParalyzed(true);
  3652. }
  3653.  
  3654. @Override
  3655. public void doAttack(L2Character target)
  3656. {
  3657. super.doAttack(target);
  3658. clearRecentFakeDeath();
  3659. }
  3660.  
  3661. @Override
  3662. public void doCast(L2Skill skill)
  3663. {
  3664. super.doCast(skill);
  3665. clearRecentFakeDeath();
  3666. }
  3667.  
  3668. public boolean canOpenPrivateStore()
  3669. {
  3670. if (getActiveTradeList() != null)
  3671. cancelActiveTrade();
  3672.  
  3673. return !isAlikeDead() && !isInOlympiadMode() && !isMounted() && !isInsideZone(ZoneId.NO_STORE) && !isCastingNow();
  3674. }
  3675.  
  3676. public void tryOpenPrivateBuyStore()
  3677. {
  3678. if (canOpenPrivateStore())
  3679. {
  3680. if (getStoreType() == StoreType.BUY || getStoreType() == StoreType.BUY_MANAGE)
  3681. setStoreType(StoreType.NONE);
  3682.  
  3683. if (getStoreType() == StoreType.NONE)
  3684. {
  3685. standUp();
  3686.  
  3687. setStoreType(StoreType.BUY_MANAGE);
  3688. sendPacket(new PrivateStoreManageListBuy(this));
  3689. }
  3690. }
  3691. else
  3692. {
  3693. if (isInsideZone(ZoneId.NO_STORE))
  3694. sendPacket(SystemMessageId.NO_PRIVATE_STORE_HERE);
  3695.  
  3696. sendPacket(ActionFailed.STATIC_PACKET);
  3697. }
  3698. }
  3699.  
  3700. public void tryOpenPrivateSellStore(boolean isPackageSale)
  3701. {
  3702. if (canOpenPrivateStore())
  3703. {
  3704. if (getStoreType() == StoreType.SELL || getStoreType() == StoreType.SELL_MANAGE || getStoreType() == StoreType.PACKAGE_SELL)
  3705. setStoreType(StoreType.NONE);
  3706.  
  3707. if (getStoreType() == StoreType.NONE)
  3708. {
  3709. standUp();
  3710.  
  3711. setStoreType(StoreType.SELL_MANAGE);
  3712. sendPacket(new PrivateStoreManageListSell(this, isPackageSale));
  3713. }
  3714. }
  3715. else
  3716. {
  3717. if (isInsideZone(ZoneId.NO_STORE))
  3718. sendPacket(SystemMessageId.NO_PRIVATE_STORE_HERE);
  3719.  
  3720. sendPacket(ActionFailed.STATIC_PACKET);
  3721. }
  3722. }
  3723.  
  3724. public void tryOpenWorkshop(boolean isDwarven)
  3725. {
  3726. if (canOpenPrivateStore())
  3727. {
  3728. if (isInStoreMode())
  3729. setStoreType(StoreType.NONE);
  3730.  
  3731. if (getStoreType() == StoreType.NONE)
  3732. {
  3733. standUp();
  3734.  
  3735. if (getCreateList() == null)
  3736. setCreateList(new L2ManufactureList());
  3737.  
  3738. sendPacket(new RecipeShopManageList(this, isDwarven));
  3739. }
  3740. }
  3741. else
  3742. {
  3743. if (isInsideZone(ZoneId.NO_STORE))
  3744. sendPacket(SystemMessageId.NO_PRIVATE_WORKSHOP_HERE);
  3745.  
  3746. sendPacket(ActionFailed.STATIC_PACKET);
  3747. }
  3748. }
  3749.  
  3750. public final PreparedListContainer getMultiSell()
  3751. {
  3752. return _currentMultiSell;
  3753. }
  3754.  
  3755. public final void setMultiSell(PreparedListContainer list)
  3756. {
  3757. _currentMultiSell = list;
  3758. }
  3759.  
  3760. @Override
  3761. public void setTarget(L2Object newTarget)
  3762. {
  3763. if (newTarget != null)
  3764. {
  3765. boolean isParty = (((newTarget instanceof L2PcInstance) && isInParty() && getParty().getPartyMembers().contains(newTarget)));
  3766.  
  3767. // Check if the new target is visible
  3768. if (!isParty && (!newTarget.isVisible() || Math.abs(newTarget.getZ() - getZ()) > 1000))
  3769. newTarget = null;
  3770. }
  3771.  
  3772. // Can't target and attack festival monsters if not participant
  3773. if ((newTarget instanceof L2FestivalMonsterInstance) && !isFestivalParticipant())
  3774. newTarget = null;
  3775. // Can't target and attack rift invaders if not in the same room
  3776. else if (isInParty() && getParty().isInDimensionalRift())
  3777. {
  3778. byte riftType = getParty().getDimensionalRift().getType();
  3779. byte riftRoom = getParty().getDimensionalRift().getCurrentRoom();
  3780.  
  3781. if (newTarget != null && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(newTarget.getX(), newTarget.getY(), newTarget.getZ()))
  3782. newTarget = null;
  3783. }
  3784.  
  3785. // Get the current target
  3786. L2Object oldTarget = getTarget();
  3787.  
  3788. if (oldTarget != null)
  3789. {
  3790. if (oldTarget.equals(newTarget))
  3791. return; // no target change
  3792.  
  3793. // Remove the L2PcInstance from the _statusListener of the old target if it was a L2Character
  3794. if (oldTarget instanceof L2Character)
  3795. ((L2Character) oldTarget).removeStatusListener(this);
  3796. }
  3797.  
  3798. // Verify if it's a static object.
  3799. if (newTarget instanceof L2StaticObjectInstance)
  3800. {
  3801. sendPacket(new MyTargetSelected(newTarget.getObjectId(), 0));
  3802. sendPacket(new StaticObject((L2StaticObjectInstance) newTarget));
  3803. }
  3804. // Add the L2PcInstance to the _statusListener of the new target if it's a L2Character
  3805. else if (newTarget instanceof L2Character)
  3806. {
  3807. final L2Character target = (L2Character) newTarget;
  3808.  
  3809. // Validate location of the new target.
  3810. if (newTarget.getObjectId() != getObjectId())
  3811. sendPacket(new ValidateLocation(target));
  3812.  
  3813. // Show the client his new target.
  3814. sendPacket(new MyTargetSelected(target.getObjectId(), (target.isAutoAttackable(this) || target instanceof L2Summon) ? getLevel() - target.getLevel() : 0));
  3815.  
  3816. target.addStatusListener(this);
  3817.  
  3818. // Send max/current hp.
  3819. final StatusUpdate su = new StatusUpdate(target);
  3820. su.addAttribute(StatusUpdate.MAX_HP, target.getMaxHp());
  3821. su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
  3822. sendPacket(su);
  3823.  
  3824. Broadcast.toKnownPlayers(this, new TargetSelected(getObjectId(), newTarget.getObjectId(), getX(), getY(), getZ()));
  3825. }
  3826.  
  3827. if (newTarget == null && getTarget() != null)
  3828. {
  3829. broadcastPacket(new TargetUnselected(this));
  3830. setCurrentFolkNPC(null);
  3831. }
  3832. else
  3833. {
  3834. // Rehabilitates that useful check.
  3835. if (newTarget instanceof L2NpcInstance)
  3836. setCurrentFolkNPC((L2Npc) newTarget);
  3837. }
  3838.  
  3839. // Target the new L2Object (add the target to the L2PcInstance _target, _knownObject and L2PcInstance to _KnownObject of the L2Object)
  3840. super.setTarget(newTarget);
  3841. }
  3842.  
  3843. /**
  3844. * Return the active weapon instance (always equipped in the right hand).
  3845. */
  3846. @Override
  3847. public ItemInstance getActiveWeaponInstance()
  3848. {
  3849. return getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  3850. }
  3851.  
  3852. /**
  3853. * Return the active weapon item (always equipped in the right hand).
  3854. */
  3855. @Override
  3856. public Weapon getActiveWeaponItem()
  3857. {
  3858. final ItemInstance weapon = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  3859. if (weapon == null)
  3860. return getFistsWeaponItem();
  3861.  
  3862. return (Weapon) weapon.getItem();
  3863. }
  3864.  
  3865. /**
  3866. * @param type : The ArmorType to check. It supports NONE, SHIELD, MAGIC, LIGHT and HEAVY.
  3867. * @return true if the given ArmorType is used by the chest of the player, false otherwise.
  3868. */
  3869. public boolean isWearingArmorType(ArmorType type)
  3870. {
  3871. // Retrieve either the shield or the chest, following ArmorType to check.
  3872. final ItemInstance armor = getInventory().getPaperdollItem((type == ArmorType.SHIELD) ? Inventory.PAPERDOLL_LHAND : Inventory.PAPERDOLL_CHEST);
  3873. if (armor == null)
  3874. return type == ArmorType.NONE; // Return true if not equipped and the check was based on NONE ArmorType.
  3875.  
  3876. // Test if the equipped item is an armor, then finally compare both ArmorType.
  3877. return armor.getItemType() instanceof ArmorType && armor.getItemType() == type;
  3878. }
  3879.  
  3880. public boolean isMarried()
  3881. {
  3882. return _isMarried;
  3883. }
  3884.  
  3885. public void setMarried(boolean state)
  3886. {
  3887. _isMarried = state;
  3888. }
  3889.  
  3890. public boolean isUnderMarryRequest()
  3891. {
  3892. return _isUnderMarryRequest;
  3893. }
  3894.  
  3895. public void setUnderMarryRequest(boolean state)
  3896. {
  3897. _isUnderMarryRequest = state;
  3898. }
  3899.  
  3900. public int getCoupleId()
  3901. {
  3902. return _coupleId;
  3903. }
  3904.  
  3905. public void setCoupleId(int coupleId)
  3906. {
  3907. _coupleId = coupleId;
  3908. }
  3909.  
  3910. public void setRequesterId(int requesterId)
  3911. {
  3912. _requesterId = requesterId;
  3913. }
  3914.  
  3915. public void EngageAnswer(int answer)
  3916. {
  3917. if (!_isUnderMarryRequest || _requesterId == 0)
  3918. return;
  3919.  
  3920. L2PcInstance ptarget = L2World.getInstance().getPlayer(_requesterId);
  3921. if (ptarget != null)
  3922. {
  3923. if (answer == 1)
  3924. {
  3925. // Create the couple
  3926. CoupleManager.getInstance().createCouple(ptarget, this);
  3927.  
  3928. // Then "finish the job"
  3929. L2WeddingManagerInstance.justMarried(ptarget, this);
  3930. }
  3931. else
  3932. {
  3933. setUnderMarryRequest(false);
  3934. sendMessage("You declined your partner's marriage request.");
  3935.  
  3936. ptarget.setUnderMarryRequest(false);
  3937. ptarget.sendMessage("Your partner declined your marriage request.");
  3938. }
  3939. }
  3940. }
  3941.  
  3942. /**
  3943. * Return the secondary weapon instance (always equipped in the left hand).
  3944. */
  3945. @Override
  3946. public ItemInstance getSecondaryWeaponInstance()
  3947. {
  3948. return getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  3949. }
  3950.  
  3951. /**
  3952. * Return the secondary L2Item item (always equiped in the left hand).
  3953. */
  3954. @Override
  3955. public Item getSecondaryWeaponItem()
  3956. {
  3957. ItemInstance item = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  3958. if (item != null)
  3959. return item.getItem();
  3960.  
  3961. return null;
  3962. }
  3963.  
  3964. /**
  3965. * Kill the L2Character, Apply Death Penalty, Manage gain/loss Karma and Item Drop.
  3966. * <ul>
  3967. * <li>Reduce the Experience of the L2PcInstance in function of the calculated Death Penalty</li>
  3968. * <li>If necessary, unsummon the Pet of the killed L2PcInstance</li>
  3969. * <li>Manage Karma gain for attacker and Karam loss for the killed L2PcInstance</li>
  3970. * <li>If the killed L2PcInstance has Karma, manage Drop Item</li>
  3971. * <li>Kill the L2PcInstance</li>
  3972. * </ul>
  3973. * @param killer The L2Character who attacks
  3974. */
  3975. @Override
  3976. public boolean doDie(L2Character killer)
  3977. {
  3978. // Kill the L2PcInstance
  3979. if (!super.doDie(killer))
  3980. return false;
  3981.  
  3982. if (isMounted())
  3983. stopFeed();
  3984.  
  3985. synchronized (this)
  3986. {
  3987. if (isFakeDeath())
  3988. stopFakeDeath(true);
  3989. }
  3990.  
  3991. if (killer != null)
  3992. {
  3993. L2PcInstance pk = killer.getActingPlayer();
  3994.  
  3995. // RNP (4 Cia del tvt kill kaskas)
  3996. TvTEvent.onKill(killer, this);
  3997. DMEvent.onKill(killer, this);
  3998. // Clear resurrect xp calculation
  3999. setExpBeforeDeath(0);
  4000.  
  4001. if (isCursedWeaponEquipped())
  4002. CursedWeaponsManager.getInstance().drop(_cursedWeaponEquippedId, killer);
  4003. else
  4004. {
  4005. if (pk == null || !pk.isCursedWeaponEquipped())
  4006. {
  4007. onDieDropItem(killer); // Check if any item should be dropped
  4008.  
  4009. // if the area isn't an arena
  4010. if (!isInArena())
  4011. {
  4012. // if both victim and attacker got clans & aren't academicians
  4013. if (pk != null && pk.getClan() != null && getClan() != null && !isAcademyMember() && !pk.isAcademyMember())
  4014. {
  4015. // if clans got mutual war, then use the reputation calcul
  4016. if (_clan.isAtWarWith(pk.getClanId()) && pk.getClan().isAtWarWith(_clan.getClanId()))
  4017. {
  4018. // when your reputation score is 0 or below, the other clan cannot acquire any reputation points
  4019. if (getClan().getReputationScore() > 0)
  4020. pk.getClan().addReputationScore(1);
  4021. // when the opposing sides reputation score is 0 or below, your clans reputation score doesn't decrease
  4022. if (pk.getClan().getReputationScore() > 0)
  4023. _clan.takeReputationScore(1);
  4024. }
  4025. }
  4026. }
  4027.  
  4028. // Reduce player's xp and karma.
  4029. // RnP (BUVO PAMIRSES POVIS 4 TVT DM)
  4030. if (Config.ALT_GAME_DELEVEL && TvTEvent.isStarted() && !TvTEvent.isPlayerParticipant(getObjectId()) && (getSkillLevel(L2Skill.SKILL_LUCKY) < 0 || getStat().getLevel() > 9))
  4031. deathPenalty(pk != null && getClan() != null && pk.getClan() != null && (getClan().isAtWarWith(pk.getClanId()) || pk.getClan().isAtWarWith(getClanId())), pk != null, killer instanceof L2SiegeGuardInstance);
  4032. }
  4033. }
  4034. }
  4035.  
  4036. // Unsummon Cubics
  4037. if (!_cubics.isEmpty())
  4038. {
  4039. for (L2CubicInstance cubic : _cubics.values())
  4040. {
  4041. cubic.stopAction();
  4042. cubic.cancelDisappear();
  4043. }
  4044.  
  4045. _cubics.clear();
  4046. }
  4047.  
  4048. if (_fusionSkill != null)
  4049. abortCast();
  4050.  
  4051. for (L2Character character : getKnownList().getKnownType(L2Character.class))
  4052. if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  4053. character.abortCast();
  4054.  
  4055. if (isInParty() && getParty().isInDimensionalRift())
  4056. getParty().getDimensionalRift().getDeadMemberList().add(this);
  4057.  
  4058. // calculate death penalty buff
  4059. calculateDeathPenaltyBuffLevel(killer);
  4060.  
  4061. stopWaterTask();
  4062.  
  4063. if (isPhoenixBlessed() || (isAffected(L2EffectFlag.CHARM_OF_COURAGE) && isInSiege()))
  4064. reviveRequest(this, null, false);
  4065.  
  4066. // Icons update in order to get retained buffs list
  4067. updateEffectIcons();
  4068.  
  4069. return true;
  4070. }
  4071.  
  4072. private void onDieDropItem(L2Character killer)
  4073. {
  4074. if (killer == null)
  4075. return;
  4076.  
  4077. L2PcInstance pk = killer.getActingPlayer();
  4078. if (getKarma() <= 0 && pk != null && pk.getClan() != null && getClan() != null && pk.getClan().isAtWarWith(getClanId()))
  4079. return;
  4080.  
  4081. if ((!isInsideZone(ZoneId.PVP) || pk == null) && (!isGM() || Config.KARMA_DROP_GM))
  4082. {
  4083. boolean isKillerNpc = (killer instanceof L2Npc);
  4084. int pkLimit = Config.KARMA_PK_LIMIT;
  4085.  
  4086. int dropEquip = 0;
  4087. int dropEquipWeapon = 0;
  4088. int dropItem = 0;
  4089. int dropLimit = 0;
  4090. int dropPercent = 0;
  4091.  
  4092. if (getKarma() > 0 && getPkKills() >= pkLimit)
  4093. {
  4094. dropPercent = Config.KARMA_RATE_DROP;
  4095. dropEquip = Config.KARMA_RATE_DROP_EQUIP;
  4096. dropEquipWeapon = Config.KARMA_RATE_DROP_EQUIP_WEAPON;
  4097. dropItem = Config.KARMA_RATE_DROP_ITEM;
  4098. dropLimit = Config.KARMA_DROP_LIMIT;
  4099. }
  4100. else if (isKillerNpc && getLevel() > 4 && !isFestivalParticipant())
  4101. {
  4102. dropPercent = Config.PLAYER_RATE_DROP;
  4103. dropEquip = Config.PLAYER_RATE_DROP_EQUIP;
  4104. dropEquipWeapon = Config.PLAYER_RATE_DROP_EQUIP_WEAPON;
  4105. dropItem = Config.PLAYER_RATE_DROP_ITEM;
  4106. dropLimit = Config.PLAYER_DROP_LIMIT;
  4107. }
  4108.  
  4109. if (dropPercent > 0 && Rnd.get(100) < dropPercent)
  4110. {
  4111. int dropCount = 0;
  4112. int itemDropPercent = 0;
  4113.  
  4114. for (ItemInstance itemDrop : getInventory().getItems())
  4115. {
  4116. // Don't drop those following things
  4117. if (!itemDrop.isDropable() || itemDrop.isShadowItem() || itemDrop.getItemId() == 57 || itemDrop.getItem().getType2() == Item.TYPE2_QUEST || getPet() != null && getPet().getControlItemId() == itemDrop.getItemId() || Arrays.binarySearch(Config.KARMA_LIST_NONDROPPABLE_ITEMS, itemDrop.getItemId()) >= 0 || Arrays.binarySearch(Config.KARMA_LIST_NONDROPPABLE_PET_ITEMS, itemDrop.getItemId()) >= 0)
  4118. continue;
  4119.  
  4120. if (itemDrop.isEquipped())
  4121. {
  4122. // Set proper chance according to Item type of equipped Item
  4123. itemDropPercent = itemDrop.getItem().getType2() == Item.TYPE2_WEAPON ? dropEquipWeapon : dropEquip;
  4124. getInventory().unEquipItemInSlot(itemDrop.getLocationSlot());
  4125. }
  4126. else
  4127. itemDropPercent = dropItem; // Item in inventory
  4128.  
  4129. // NOTE: Each time an item is dropped, the chance of another item being dropped gets lesser (dropCount * 2)
  4130. if (Rnd.get(100) < itemDropPercent)
  4131. {
  4132. dropItem("DieDrop", itemDrop, killer, true);
  4133.  
  4134. if (++dropCount >= dropLimit)
  4135. break;
  4136. }
  4137. }
  4138. }
  4139. }
  4140. }
  4141.  
  4142. public void updateKarmaLoss(long exp)
  4143. {
  4144. if (!isCursedWeaponEquipped() && getKarma() > 0)
  4145. {
  4146. int karmaLost = Formulas.calculateKarmaLost(getLevel(), exp);
  4147. if (karmaLost > 0)
  4148. setKarma(getKarma() - karmaLost);
  4149. }
  4150. }
  4151.  
  4152. /**
  4153. * This method is used to update PvP counter, or PK counter / add Karma if necessary.<br>
  4154. * It also updates clan kills/deaths counters on siege.
  4155. * @param target The L2Playable victim.
  4156. */
  4157. public void onKillUpdatePvPKarma(L2Playable target)
  4158. {
  4159. if (target == null)
  4160. return;
  4161.  
  4162. final L2PcInstance targetPlayer = target.getActingPlayer();
  4163. if (targetPlayer == null || targetPlayer == this)
  4164. return;
  4165. // RnP (DEL TVT Event tikrinau viska 5)
  4166. if(DMEvent.isStarted() && DMEvent.isPlayerParticipant(getObjectId()) || TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  4167. return;
  4168.  
  4169. // Don't rank up the CW if it was a summon.
  4170. if (isCursedWeaponEquipped() && target instanceof L2PcInstance)
  4171. {
  4172. CursedWeaponsManager.getInstance().increaseKills(_cursedWeaponEquippedId);
  4173. return;
  4174. }
  4175.  
  4176. // If in duel and you kill (only can kill l2summon), do nothing
  4177. if (isInDuel() && targetPlayer.isInDuel())
  4178. return;
  4179.  
  4180. // If in pvp zone, do nothing.
  4181. if (isInsideZone(ZoneId.PVP) && targetPlayer.isInsideZone(ZoneId.PVP))
  4182. {
  4183. // Until the zone was a siege zone. Check also if victim was a player. Randomers aren't counted.
  4184. if (target instanceof L2PcInstance && getSiegeState() > 0 && targetPlayer.getSiegeState() > 0 && getSiegeState() != targetPlayer.getSiegeState())
  4185. {
  4186. // Now check clan relations.
  4187. final L2Clan killerClan = getClan();
  4188. if (killerClan != null)
  4189. killerClan.setSiegeKills(killerClan.getSiegeKills() + 1);
  4190.  
  4191. final L2Clan targetClan = targetPlayer.getClan();
  4192. if (targetClan != null)
  4193. targetClan.setSiegeDeaths(targetClan.getSiegeDeaths() + 1);
  4194. }
  4195. return;
  4196. }
  4197.  
  4198. // Check if it's pvp (cases : regular, wars, victim is PKer)
  4199. if (checkIfPvP(target) || (targetPlayer.getClan() != null && getClan() != null && getClan().isAtWarWith(targetPlayer.getClanId()) && targetPlayer.getClan().isAtWarWith(getClanId()) && targetPlayer.getPledgeType() != L2Clan.SUBUNIT_ACADEMY && getPledgeType() != L2Clan.SUBUNIT_ACADEMY) || (targetPlayer.getKarma() > 0 && Config.KARMA_AWARD_PK_KILL))
  4200. {
  4201. if (target instanceof L2PcInstance)
  4202. {
  4203. // Add PvP point to attacker.
  4204. setPvpKills(getPvpKills() + 1);
  4205. // RnP (del pvp zonos :)
  4206. if(isInsideZone(ZoneId.MULTI_FUNCTION))
  4207. {
  4208. L2MultiFunctionZone.updatepvps(this);
  4209. addItem("Reward",9903,1,this,true);
  4210. setMultiKills(getMultiKills() + 1);
  4211. setTitle("PvP: "+getMultiKills());
  4212. }
  4213. // RnP (DM event, nors kaska duotu)
  4214. if (DMEvent.isStarted() && DMEvent.isPlayerParticipant(getObjectId()))
  4215. {
  4216. DMEvent.updatepvps(this);
  4217. addItem("Reward",6392,1,this,true);
  4218. setMultiKills(getMultiKills() + 1);
  4219. setTitle("PvP: "+getMultiKills());
  4220. }
  4221. updatePvPColor(getPvpKills());
  4222. broadcastUserInfo();
  4223.  
  4224. quakeSystem++;
  4225. if (Config.QUAKE_SYSTEM)
  4226. {
  4227. String text1 = "Quake System: ";
  4228. if (quakeSystem == (Config.PVP_COUNT1))
  4229. {
  4230. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE1));
  4231. }
  4232. else if (quakeSystem == (Config.PVP_COUNT2))
  4233. {
  4234. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE2));
  4235. }
  4236. else if (quakeSystem == (Config.PVP_COUNT3))
  4237. {
  4238. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE3));
  4239. }
  4240. else if (quakeSystem == (Config.PVP_COUNT4))
  4241. {
  4242. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE4));
  4243. }
  4244. else if (quakeSystem == (Config.PVP_COUNT5))
  4245. {
  4246. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE5));
  4247. }
  4248. else if (quakeSystem == (Config.PVP_COUNT6))
  4249. {
  4250. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE6));
  4251. }
  4252. else if (quakeSystem == (Config.PVP_COUNT7))
  4253. {
  4254. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE7));
  4255. }
  4256. else if (quakeSystem == (Config.PVP_COUNT8))
  4257. {
  4258. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE8));
  4259. }
  4260. else if (quakeSystem == (Config.PVP_COUNT9))
  4261. {
  4262. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE9));
  4263. }
  4264. else if (quakeSystem == (Config.PVP_COUNT10))
  4265. {
  4266. Announcements.customAnnounce(text1,this.getName()+ " " + (Config.PVP_ANNOUNCE10));
  4267. }
  4268. }
  4269.  
  4270. // Send UserInfo packet to attacker with its Karma and PK Counter
  4271. sendPacket(new UserInfo(this));
  4272. }
  4273. }
  4274. // Otherwise, killer is considered as a PKer.
  4275. else if (targetPlayer.getKarma() == 0 && targetPlayer.getPvpFlag() == 0)
  4276. {
  4277. // PK Points are increased only if you kill a player.
  4278. if (target instanceof L2PcInstance)
  4279. setPkKills(getPkKills() + 1);
  4280.  
  4281. // Calculate new karma.
  4282. setKarma(getKarma() + Formulas.calculateKarmaGain(getPkKills(), target instanceof L2Summon));
  4283.  
  4284. // Send UserInfo packet to attacker with its Karma and PK Counter
  4285. sendPacket(new UserInfo(this));
  4286. }
  4287. }
  4288.  
  4289. public void updatePvPStatus()
  4290. {
  4291. if (isInsideZone(ZoneId.PVP))
  4292. return;
  4293.  
  4294. // RnP (kad pvp status updatintu 6)
  4295. if(TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  4296. return;
  4297.  
  4298. PvpFlagTaskManager.getInstance().add(this, Config.PVP_NORMAL_TIME);
  4299.  
  4300. if (getPvpFlag() == 0)
  4301. updatePvPFlag(1);
  4302. }
  4303.  
  4304. public void updatePvPStatus(L2Character target)
  4305. {
  4306. final L2PcInstance player = target.getActingPlayer();
  4307. if (player == null)
  4308. return;
  4309.  
  4310. if (isInDuel() && player.getDuelId() == getDuelId())
  4311. return;
  4312. // RnP (cia kaskas bbz kas )
  4313. if ((!isInsideZone(ZoneId.PVP) || !target.isInsideZone(ZoneId.PVP) || !TvTEvent.isPlayerParticipant(getObjectId()) || !TvTEvent.isPlayerParticipant(target.getObjectId()))
  4314. && player.getKarma() == 0)
  4315. {
  4316. PvpFlagTaskManager.getInstance().add(this, System.currentTimeMillis() + ((checkIfPvP(player)) ? Config.PVP_PVP_TIME : Config.PVP_NORMAL_TIME));
  4317.  
  4318. if (getPvpFlag() == 0)
  4319. updatePvPFlag(1);
  4320. }
  4321. }
  4322.  
  4323. /**
  4324. * Restore the experience this L2PcInstance has lost and sends StatusUpdate packet.
  4325. * @param restorePercent The specified % of restored experience.
  4326. */
  4327. public void restoreExp(double restorePercent)
  4328. {
  4329. if (getExpBeforeDeath() > 0)
  4330. {
  4331. getStat().addExp((int) Math.round((getExpBeforeDeath() - getExp()) * restorePercent / 100));
  4332. setExpBeforeDeath(0);
  4333. }
  4334. }
  4335.  
  4336. /**
  4337. * Reduce the Experience (and level if necessary) of the L2PcInstance in function of the calculated Death Penalty.
  4338. * <ul>
  4339. * <li>Calculate the Experience loss</li>
  4340. * <li>Set the value of _expBeforeDeath</li>
  4341. * <li>Set the new Experience value of the L2PcInstance and Decrease its level if necessary</li>
  4342. * <li>Send StatusUpdate packet with its new Experience</li>
  4343. * </ul>
  4344. * @param atWar If true, use clan war penalty system instead of regular system.
  4345. * @param killedByPlayable Used to see if victim loses XP or not.
  4346. * @param killedBySiegeNpc Used to see if victim loses XP or not.
  4347. */
  4348. public void deathPenalty(boolean atWar, boolean killedByPlayable, boolean killedBySiegeNpc)
  4349. {
  4350. // No xp loss inside pvp zone unless
  4351. // - it's a siege zone and you're NOT participating
  4352. // - you're killed by a non-pc whose not belong to the siege
  4353. if (isInsideZone(ZoneId.PVP))
  4354. {
  4355. // No xp loss for siege participants inside siege zone.
  4356. if (isInsideZone(ZoneId.SIEGE))
  4357. {
  4358. if (isInSiege() && (killedByPlayable || killedBySiegeNpc))
  4359. return;
  4360. }
  4361. // No xp loss for arenas participants killed by playable.
  4362. else if (killedByPlayable)
  4363. return;
  4364. }
  4365.  
  4366. // Get the level of the L2PcInstance
  4367. final int lvl = getLevel();
  4368.  
  4369. // The death steal you some Exp
  4370. double percentLost = 7.0;
  4371. if (getLevel() >= 76)
  4372. percentLost = 2.0;
  4373. else if (getLevel() >= 40)
  4374. percentLost = 4.0;
  4375.  
  4376. if (getKarma() > 0)
  4377. percentLost *= Config.RATE_KARMA_EXP_LOST;
  4378.  
  4379. if (isFestivalParticipant() || atWar || isInsideZone(ZoneId.SIEGE))
  4380. percentLost /= 4.0;
  4381.  
  4382. // Calculate the Experience loss
  4383. long lostExp = 0;
  4384.  
  4385. if (lvl < Experience.MAX_LEVEL)
  4386. lostExp = Math.round((getStat().getExpForLevel(lvl + 1) - getStat().getExpForLevel(lvl)) * percentLost / 100);
  4387. else
  4388. lostExp = Math.round((getStat().getExpForLevel(Experience.MAX_LEVEL) - getStat().getExpForLevel(Experience.MAX_LEVEL - 1)) * percentLost / 100);
  4389.  
  4390. // Get the Experience before applying penalty
  4391. setExpBeforeDeath(getExp());
  4392.  
  4393. // Set new karma
  4394. updateKarmaLoss(lostExp);
  4395.  
  4396. // Set the new Experience value of the L2PcInstance
  4397. getStat().addExp(-lostExp);
  4398. }
  4399.  
  4400. public boolean isPartyWaiting()
  4401. {
  4402. return PartyMatchWaitingList.getInstance().getPlayers().contains(this);
  4403. }
  4404.  
  4405. public void setPartyRoom(int id)
  4406. {
  4407. _partyroom = id;
  4408. }
  4409.  
  4410. public int getPartyRoom()
  4411. {
  4412. return _partyroom;
  4413. }
  4414.  
  4415. public boolean isInPartyMatchRoom()
  4416. {
  4417. return _partyroom > 0;
  4418. }
  4419.  
  4420. /**
  4421. * Stop all timers related to that L2PcInstance.
  4422. */
  4423. public void stopAllTimers()
  4424. {
  4425. stopHpMpRegeneration();
  4426. stopWaterTask();
  4427. stopFeed();
  4428.  
  4429. _petTemplate = null;
  4430. _petData = null;
  4431.  
  4432. storePetFood(_mountNpcId);
  4433. stopPunishTask(true);
  4434. stopChargeTask();
  4435.  
  4436. AttackStanceTaskManager.getInstance().remove(this);
  4437. PvpFlagTaskManager.getInstance().remove(this);
  4438. GameTimeTaskManager.getInstance().remove(this);
  4439. ShadowItemTaskManager.getInstance().remove(this);
  4440. }
  4441.  
  4442. /**
  4443. * Return the L2Summon of the L2PcInstance or null.
  4444. */
  4445. @Override
  4446. public L2Summon getPet()
  4447. {
  4448. return _summon;
  4449. }
  4450.  
  4451. /**
  4452. * @return {@code true} if the player has a pet, {@code false} otherwise
  4453. */
  4454. public boolean hasPet()
  4455. {
  4456. return _summon instanceof L2PetInstance;
  4457. }
  4458.  
  4459. /**
  4460. * @return {@code true} if the player has a summon, {@code false} otherwise
  4461. */
  4462. public boolean hasServitor()
  4463. {
  4464. return _summon instanceof L2SummonInstance;
  4465. }
  4466.  
  4467. /**
  4468. * Set the L2Summon of the L2PcInstance.
  4469. * @param summon The Object.
  4470. */
  4471. public void setPet(L2Summon summon)
  4472. {
  4473. _summon = summon;
  4474. }
  4475.  
  4476. /**
  4477. * @return the L2TamedBeast of the L2PcInstance or null.
  4478. */
  4479. public L2TamedBeastInstance getTrainedBeast()
  4480. {
  4481. return _tamedBeast;
  4482. }
  4483.  
  4484. /**
  4485. * Set the L2TamedBeast of the L2PcInstance.
  4486. * @param tamedBeast The Object.
  4487. */
  4488. public void setTrainedBeast(L2TamedBeastInstance tamedBeast)
  4489. {
  4490. _tamedBeast = tamedBeast;
  4491. }
  4492.  
  4493. /**
  4494. * @return the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
  4495. */
  4496. public L2Request getRequest()
  4497. {
  4498. return _request;
  4499. }
  4500.  
  4501. /**
  4502. * Set the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
  4503. * @param requester
  4504. */
  4505. public void setActiveRequester(L2PcInstance requester)
  4506. {
  4507. _activeRequester = requester;
  4508. }
  4509.  
  4510. /**
  4511. * @return the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
  4512. */
  4513. public L2PcInstance getActiveRequester()
  4514. {
  4515. if (_activeRequester != null && _activeRequester.isRequestExpired() && _activeTradeList == null)
  4516. _activeRequester = null;
  4517.  
  4518. return _activeRequester;
  4519. }
  4520.  
  4521. /**
  4522. * @return True if a request is in progress.
  4523. */
  4524. public boolean isProcessingRequest()
  4525. {
  4526. return getActiveRequester() != null || _requestExpireTime > System.currentTimeMillis();
  4527. }
  4528.  
  4529. /**
  4530. * @return True if a transaction <B>(trade OR request)</B> is in progress.
  4531. */
  4532. public boolean isProcessingTransaction()
  4533. {
  4534. return getActiveRequester() != null || _activeTradeList != null || _requestExpireTime > System.currentTimeMillis();
  4535. }
  4536.  
  4537. /**
  4538. * Set the _requestExpireTime of that L2PcInstance, and set his partner as the active requester.
  4539. * @param partner The partner to make checks on.
  4540. */
  4541. public void onTransactionRequest(L2PcInstance partner)
  4542. {
  4543. _requestExpireTime = System.currentTimeMillis() + REQUEST_TIMEOUT * 1000;
  4544. partner.setActiveRequester(this);
  4545. }
  4546.  
  4547. /**
  4548. * @return true if last request is expired.
  4549. */
  4550. public boolean isRequestExpired()
  4551. {
  4552. return _requestExpireTime <= System.currentTimeMillis();
  4553. }
  4554.  
  4555. /**
  4556. * Select the Warehouse to be used in next activity.
  4557. */
  4558. public void onTransactionResponse()
  4559. {
  4560. _requestExpireTime = 0;
  4561. }
  4562.  
  4563. /**
  4564. * Select the Warehouse to be used in next activity.
  4565. * @param warehouse An active warehouse.
  4566. */
  4567. public void setActiveWarehouse(ItemContainer warehouse)
  4568. {
  4569. _activeWarehouse = warehouse;
  4570. }
  4571.  
  4572. /**
  4573. * @return The active Warehouse.
  4574. */
  4575. public ItemContainer getActiveWarehouse()
  4576. {
  4577. return _activeWarehouse;
  4578. }
  4579.  
  4580. /**
  4581. * Set the TradeList to be used in next activity.
  4582. * @param tradeList The TradeList to be used.
  4583. */
  4584. public void setActiveTradeList(TradeList tradeList)
  4585. {
  4586. _activeTradeList = tradeList;
  4587. }
  4588.  
  4589. /**
  4590. * @return The active TradeList.
  4591. */
  4592. public TradeList getActiveTradeList()
  4593. {
  4594. return _activeTradeList;
  4595. }
  4596.  
  4597. public void onTradeStart(L2PcInstance partner)
  4598. {
  4599. _activeTradeList = new TradeList(this);
  4600. _activeTradeList.setPartner(partner);
  4601.  
  4602. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.BEGIN_TRADE_WITH_S1).addString(partner.getName()));
  4603. sendPacket(new TradeStart(this));
  4604. }
  4605.  
  4606. public void onTradeConfirm(L2PcInstance partner)
  4607. {
  4608. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CONFIRMED_TRADE).addString(partner.getName()));
  4609.  
  4610. partner.sendPacket(TradePressOwnOk.STATIC_PACKET);
  4611. sendPacket(TradePressOtherOk.STATIC_PACKET);
  4612. }
  4613.  
  4614. public void onTradeCancel(L2PcInstance partner)
  4615. {
  4616. if (_activeTradeList == null)
  4617. return;
  4618.  
  4619. _activeTradeList.lock();
  4620. _activeTradeList = null;
  4621.  
  4622. sendPacket(new SendTradeDone(0));
  4623. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANCELED_TRADE).addString(partner.getName()));
  4624. }
  4625.  
  4626. public void onTradeFinish(boolean successfull)
  4627. {
  4628. _activeTradeList = null;
  4629. sendPacket(new SendTradeDone(1));
  4630. if (successfull)
  4631. sendPacket(SystemMessageId.TRADE_SUCCESSFUL);
  4632. }
  4633.  
  4634. public void startTrade(L2PcInstance partner)
  4635. {
  4636. onTradeStart(partner);
  4637. partner.onTradeStart(this);
  4638. }
  4639.  
  4640. public void cancelActiveTrade()
  4641. {
  4642. if (_activeTradeList == null)
  4643. return;
  4644.  
  4645. L2PcInstance partner = _activeTradeList.getPartner();
  4646. if (partner != null)
  4647. partner.onTradeCancel(this);
  4648.  
  4649. onTradeCancel(this);
  4650. }
  4651.  
  4652. /**
  4653. * @return The _createList object of the L2PcInstance.
  4654. */
  4655. public L2ManufactureList getCreateList()
  4656. {
  4657. return _createList;
  4658. }
  4659.  
  4660. /**
  4661. * Set the _createList object of the L2PcInstance.
  4662. * @param list
  4663. */
  4664. public void setCreateList(L2ManufactureList list)
  4665. {
  4666. _createList = list;
  4667. }
  4668.  
  4669. /**
  4670. * @return The _sellList object of the L2PcInstance.
  4671. */
  4672. public TradeList getSellList()
  4673. {
  4674. if (_sellList == null)
  4675. _sellList = new TradeList(this);
  4676.  
  4677. return _sellList;
  4678. }
  4679.  
  4680. /**
  4681. * @return the _buyList object of the L2PcInstance.
  4682. */
  4683. public TradeList getBuyList()
  4684. {
  4685. if (_buyList == null)
  4686. _buyList = new TradeList(this);
  4687.  
  4688. return _buyList;
  4689. }
  4690.  
  4691. /**
  4692. * Set the Store type of the L2PcInstance.
  4693. * @param type : 0 = none, 1 = sell, 2 = sellmanage, 3 = buy, 4 = buymanage, 5 = manufacture.
  4694. */
  4695. public void setStoreType(StoreType type)
  4696. {
  4697. _storeType = type;
  4698. if (Config.OFFLINE_DISCONNECT_FINISHED && (_storeType == StoreType.NONE) && ((getClient() == null) || getClient().isDetached()))
  4699. {
  4700. deleteMe();
  4701. }
  4702. }
  4703.  
  4704. /**
  4705. * @return The Store type of the L2PcInstance.
  4706. */
  4707. public StoreType getStoreType()
  4708. {
  4709. return _storeType;
  4710. }
  4711.  
  4712. /**
  4713. * Set the _skillLearningClassId object of the L2PcInstance.
  4714. * @param classId The parameter.
  4715. */
  4716. public void setSkillLearningClassId(ClassId classId)
  4717. {
  4718. _skillLearningClassId = classId;
  4719. }
  4720.  
  4721. /**
  4722. * @return The _skillLearningClassId object of the L2PcInstance.
  4723. */
  4724. public ClassId getSkillLearningClassId()
  4725. {
  4726. return _skillLearningClassId;
  4727. }
  4728.  
  4729. /**
  4730. * Set the _clan object, _clanId, _clanLeader Flag and title of the L2PcInstance.
  4731. * @param clan The Clan object which is used to feed L2PcInstance values.
  4732. */
  4733. public void setClan(L2Clan clan)
  4734. {
  4735. _clan = clan;
  4736. setTitle("");
  4737.  
  4738. if (clan == null)
  4739. {
  4740. _clanId = 0;
  4741. _clanPrivileges = 0;
  4742. _pledgeType = 0;
  4743. _powerGrade = 0;
  4744. _lvlJoinedAcademy = 0;
  4745. _apprentice = 0;
  4746. _sponsor = 0;
  4747. return;
  4748. }
  4749.  
  4750. if (!clan.isMember(getObjectId()))
  4751. {
  4752. // char has been kicked from clan
  4753. setClan(null);
  4754. return;
  4755. }
  4756.  
  4757. _clanId = clan.getClanId();
  4758. }
  4759.  
  4760. /**
  4761. * @return The _clan object of the L2PcInstance.
  4762. */
  4763. public L2Clan getClan()
  4764. {
  4765. return _clan;
  4766. }
  4767.  
  4768. /**
  4769. * @return True if the L2PcInstance is the leader of its clan.
  4770. */
  4771. public boolean isClanLeader()
  4772. {
  4773. if (getClan() == null)
  4774. return false;
  4775.  
  4776. return getObjectId() == getClan().getLeaderId();
  4777. }
  4778.  
  4779. /**
  4780. * Reduce the number of arrows owned by the L2PcInstance and send InventoryUpdate or ItemList (to unequip if the last arrow was consummed).
  4781. */
  4782. @Override
  4783. protected void reduceArrowCount()
  4784. {
  4785. ItemInstance arrows = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  4786.  
  4787. if (arrows == null)
  4788. {
  4789. getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  4790. _arrowItem = null;
  4791. sendPacket(new ItemList(this, false));
  4792. return;
  4793. }
  4794.  
  4795. // Adjust item quantity
  4796. if (arrows.getCount() > 1)
  4797. {
  4798. synchronized (arrows)
  4799. {
  4800. arrows.changeCountWithoutTrace(-1, this, null);
  4801. arrows.setLastChange(ItemInstance.MODIFIED);
  4802.  
  4803. // could do also without saving, but let's save approx 1 of 10
  4804. if (Rnd.get(10) < 1)
  4805. arrows.updateDatabase();
  4806. _inventory.refreshWeight();
  4807. }
  4808. }
  4809. else
  4810. {
  4811. // Destroy entire item and save to database
  4812. _inventory.destroyItem("Consume", arrows, this, null);
  4813.  
  4814. getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
  4815. _arrowItem = null;
  4816.  
  4817. sendPacket(new ItemList(this, false));
  4818. return;
  4819. }
  4820.  
  4821. InventoryUpdate iu = new InventoryUpdate();
  4822. iu.addModifiedItem(arrows);
  4823. sendPacket(iu);
  4824. }
  4825.  
  4826. /**
  4827. * Equip arrows needed in left hand and send ItemList to the L2PcInstance then return True.
  4828. */
  4829. @Override
  4830. protected boolean checkAndEquipArrows()
  4831. {
  4832. // Check if nothing is equipped in left hand
  4833. if (getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
  4834. {
  4835. // Get the ItemInstance of the arrows needed for this bow
  4836. _arrowItem = getInventory().findArrowForBow(getActiveWeaponItem());
  4837.  
  4838. if (_arrowItem != null)
  4839. {
  4840. // Equip arrows needed in left hand
  4841. getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, _arrowItem);
  4842.  
  4843. // Send ItemList to this L2PcINstance to update left hand equipement
  4844. sendPacket(new ItemList(this, false));
  4845. }
  4846. }
  4847. // Get the ItemInstance of arrows equipped in left hand
  4848. else
  4849. _arrowItem = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  4850.  
  4851. return _arrowItem != null;
  4852. }
  4853.  
  4854. /**
  4855. * Disarm the player's weapon and shield.
  4856. * @return true if successful, false otherwise.
  4857. */
  4858. public boolean disarmWeapons()
  4859. {
  4860. // Don't allow disarming a cursed weapon
  4861. if (isCursedWeaponEquipped())
  4862. return false;
  4863.  
  4864. // Unequip the weapon
  4865. ItemInstance wpn = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  4866. if (wpn != null)
  4867. {
  4868. ItemInstance[] unequipped = getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  4869. InventoryUpdate iu = new InventoryUpdate();
  4870. for (ItemInstance itm : unequipped)
  4871. iu.addModifiedItem(itm);
  4872. sendPacket(iu);
  4873.  
  4874. abortAttack();
  4875. broadcastUserInfo();
  4876.  
  4877. // this can be 0 if the user pressed the right mousebutton twice very fast
  4878. if (unequipped.length > 0)
  4879. {
  4880. SystemMessage sm;
  4881. if (unequipped[0].getEnchantLevel() > 0)
  4882. sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(unequipped[0].getEnchantLevel()).addItemName(unequipped[0]);
  4883. else
  4884. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(unequipped[0]);
  4885.  
  4886. sendPacket(sm);
  4887. }
  4888. }
  4889.  
  4890. // Unequip the shield
  4891. ItemInstance sld = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  4892. if (sld != null)
  4893. {
  4894. ItemInstance[] unequipped = getInventory().unEquipItemInBodySlotAndRecord(sld.getItem().getBodyPart());
  4895. InventoryUpdate iu = new InventoryUpdate();
  4896. for (ItemInstance itm : unequipped)
  4897. iu.addModifiedItem(itm);
  4898. sendPacket(iu);
  4899.  
  4900. abortAttack();
  4901. broadcastUserInfo();
  4902.  
  4903. // this can be 0 if the user pressed the right mousebutton twice very fast
  4904. if (unequipped.length > 0)
  4905. {
  4906. SystemMessage sm;
  4907. if (unequipped[0].getEnchantLevel() > 0)
  4908. sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(unequipped[0].getEnchantLevel()).addItemName(unequipped[0]);
  4909. else
  4910. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(unequipped[0]);
  4911.  
  4912. sendPacket(sm);
  4913. }
  4914. }
  4915. return true;
  4916. }
  4917.  
  4918. public boolean mount(L2Summon pet)
  4919. {
  4920. if (!disarmWeapons())
  4921. return false;
  4922.  
  4923. setRunning();
  4924. stopAllToggles();
  4925.  
  4926. Ride mount = new Ride(getObjectId(), Ride.ACTION_MOUNT, pet.getTemplate().getNpcId());
  4927. setMount(pet.getNpcId(), pet.getLevel(), mount.getMountType());
  4928.  
  4929. _petTemplate = (PetTemplate) pet.getTemplate();
  4930. _petData = _petTemplate.getPetDataEntry(pet.getLevel());
  4931. _mountObjectId = pet.getControlItemId();
  4932.  
  4933. startFeed(pet.getNpcId());
  4934. broadcastPacket(mount);
  4935.  
  4936. // Notify self and others about speed change
  4937. broadcastUserInfo();
  4938.  
  4939. pet.unSummon(this);
  4940. return true;
  4941. }
  4942.  
  4943. public boolean mount(int npcId, int controlItemId, boolean useFood)
  4944. {
  4945. if (!disarmWeapons())
  4946. return false;
  4947.  
  4948. setRunning();
  4949. stopAllToggles();
  4950.  
  4951. Ride mount = new Ride(getObjectId(), Ride.ACTION_MOUNT, npcId);
  4952. if (setMount(npcId, getLevel(), mount.getMountType()))
  4953. {
  4954. _petTemplate = (PetTemplate) NpcTable.getInstance().getTemplate(npcId);
  4955. _petData = _petTemplate.getPetDataEntry(getLevel());
  4956. _mountObjectId = controlItemId;
  4957.  
  4958. broadcastPacket(mount);
  4959.  
  4960. // Notify self and others about speed change
  4961. broadcastUserInfo();
  4962.  
  4963. if (useFood)
  4964. startFeed(npcId);
  4965.  
  4966. return true;
  4967. }
  4968. return false;
  4969. }
  4970.  
  4971. public boolean mountPlayer(L2Summon summon)
  4972. {
  4973. if (summon instanceof L2PetInstance && summon.isMountable() && !isMounted() && !isBetrayed())
  4974. {
  4975. if (isDead()) // A strider cannot be ridden when dead.
  4976. {
  4977. sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_DEAD);
  4978. return false;
  4979. }
  4980.  
  4981. if (summon.isDead()) // A dead strider cannot be ridden.
  4982. {
  4983. sendPacket(SystemMessageId.DEAD_STRIDER_CANT_BE_RIDDEN);
  4984. return false;
  4985. }
  4986.  
  4987. if (summon.isInCombat() || summon.isRooted()) // A strider in battle cannot be ridden.
  4988. {
  4989. sendPacket(SystemMessageId.STRIDER_IN_BATLLE_CANT_BE_RIDDEN);
  4990. return false;
  4991. }
  4992.  
  4993. if (isInCombat()) // A strider cannot be ridden while in battle
  4994. {
  4995. sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
  4996. return false;
  4997. }
  4998.  
  4999. if (isSitting()) // A strider can be ridden only when standing
  5000. {
  5001. sendPacket(SystemMessageId.STRIDER_CAN_BE_RIDDEN_ONLY_WHILE_STANDING);
  5002. return false;
  5003. }
  5004.  
  5005. if (isFishing()) // You can't mount, dismount, break and drop items while fishing
  5006. {
  5007. sendPacket(SystemMessageId.CANNOT_DO_WHILE_FISHING_2);
  5008. return false;
  5009. }
  5010.  
  5011. if (isCursedWeaponEquipped()) // You can't mount, dismount, break and drop items while weilding a cursed weapon
  5012. {
  5013. sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
  5014. return false;
  5015. }
  5016.  
  5017. if (!Util.checkIfInRange(200, this, summon, true))
  5018. {
  5019. sendPacket(SystemMessageId.TOO_FAR_AWAY_FROM_STRIDER_TO_MOUNT);
  5020. return false;
  5021. }
  5022.  
  5023. if (((L2PetInstance) summon).checkHungryState())
  5024. {
  5025. sendPacket(SystemMessageId.HUNGRY_STRIDER_NOT_MOUNT);
  5026. return false;
  5027. }
  5028.  
  5029. if (!summon.isDead() && !isMounted())
  5030. mount(summon);
  5031. }
  5032. else if (isMounted())
  5033. {
  5034. if (getMountType() == 2 && isInsideZone(ZoneId.NO_LANDING))
  5035. {
  5036. sendPacket(SystemMessageId.NO_DISMOUNT_HERE);
  5037. return false;
  5038. }
  5039.  
  5040. if (checkFoodState(_petTemplate.getHungryLimit()))
  5041. {
  5042. sendPacket(SystemMessageId.HUNGRY_STRIDER_NOT_MOUNT);
  5043. return false;
  5044. }
  5045.  
  5046. dismount();
  5047. }
  5048. return true;
  5049. }
  5050.  
  5051. public boolean dismount()
  5052. {
  5053. sendPacket(new SetupGauge(3, 0, 0));
  5054. int petId = _mountNpcId;
  5055. if (setMount(0, 0, 0))
  5056. {
  5057. stopFeed();
  5058.  
  5059. broadcastPacket(new Ride(getObjectId(), Ride.ACTION_DISMOUNT, 0));
  5060.  
  5061. _petTemplate = null;
  5062. _petData = null;
  5063. _mountObjectId = 0;
  5064.  
  5065. storePetFood(petId);
  5066.  
  5067. // Notify self and others about speed change
  5068. broadcastUserInfo();
  5069. return true;
  5070. }
  5071. return false;
  5072. }
  5073.  
  5074. public void storePetFood(int petId)
  5075. {
  5076. if (_controlItemId != 0 && petId != 0)
  5077. {
  5078. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5079. {
  5080. PreparedStatement statement = con.prepareStatement("UPDATE pets SET fed=? WHERE item_obj_id = ?");
  5081. statement.setInt(1, getCurrentFeed());
  5082. statement.setInt(2, _controlItemId);
  5083. statement.executeUpdate();
  5084. statement.close();
  5085. _controlItemId = 0;
  5086. }
  5087. catch (Exception e)
  5088. {
  5089. _log.log(Level.SEVERE, "Failed to store Pet [NpcId: " + petId + "] data", e);
  5090. }
  5091. }
  5092. }
  5093.  
  5094. protected class FeedTask implements Runnable
  5095. {
  5096. @Override
  5097. public void run()
  5098. {
  5099. if (!isMounted())
  5100. {
  5101. stopFeed();
  5102. return;
  5103. }
  5104.  
  5105. // Eat or return to pet control item.
  5106. if (getCurrentFeed() > getFeedConsume())
  5107. setCurrentFeed(getCurrentFeed() - getFeedConsume());
  5108. else
  5109. {
  5110. setCurrentFeed(0);
  5111. stopFeed();
  5112. dismount();
  5113. sendPacket(SystemMessageId.OUT_OF_FEED_MOUNT_CANCELED);
  5114. return;
  5115. }
  5116.  
  5117. ItemInstance food = getInventory().getItemByItemId(_petTemplate.getFood1());
  5118. if (food == null)
  5119. food = getInventory().getItemByItemId(_petTemplate.getFood2());
  5120.  
  5121. if (food != null && checkFoodState(_petTemplate.getAutoFeedLimit()))
  5122. {
  5123. IItemHandler handler = ItemHandler.getInstance().getItemHandler(food.getEtcItem());
  5124. if (handler != null)
  5125. {
  5126. handler.useItem(L2PcInstance.this, food, false);
  5127. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_TOOK_S1_BECAUSE_HE_WAS_HUNGRY).addItemName(food));
  5128. }
  5129. }
  5130. }
  5131. }
  5132.  
  5133. protected synchronized void startFeed(int npcId)
  5134. {
  5135. _canFeed = npcId > 0;
  5136. if (!isMounted())
  5137. return;
  5138.  
  5139. if (getPet() != null)
  5140. {
  5141. setCurrentFeed(((L2PetInstance) getPet()).getCurrentFed());
  5142. _controlItemId = getPet().getControlItemId();
  5143. sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), _petData.getMaxMeal() * 10000 / getFeedConsume()));
  5144. if (!isDead())
  5145. _mountFeedTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FeedTask(), 10000, 10000);
  5146. }
  5147. else if (_canFeed)
  5148. {
  5149. setCurrentFeed(_petData.getMaxMeal());
  5150. sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), _petData.getMaxMeal() * 10000 / getFeedConsume()));
  5151. if (!isDead())
  5152. _mountFeedTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FeedTask(), 10000, 10000);
  5153. }
  5154. }
  5155.  
  5156. protected synchronized void stopFeed()
  5157. {
  5158. if (_mountFeedTask != null)
  5159. {
  5160. _mountFeedTask.cancel(false);
  5161. _mountFeedTask = null;
  5162. }
  5163. }
  5164.  
  5165. public PetTemplate getPetTemplate()
  5166. {
  5167. return _petTemplate;
  5168. }
  5169.  
  5170. public PetDataEntry getPetDataEntry()
  5171. {
  5172. return _petData;
  5173. }
  5174.  
  5175. public int getCurrentFeed()
  5176. {
  5177. return _curFeed;
  5178. }
  5179.  
  5180. protected int getFeedConsume()
  5181. {
  5182. return (isAttackingNow()) ? _petData.getMountMealInBattle() : _petData.getMountMealInNormal();
  5183. }
  5184.  
  5185. public void setCurrentFeed(int num)
  5186. {
  5187. _curFeed = (num > _petData.getMaxMeal()) ? _petData.getMaxMeal() : num;
  5188. sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), _petData.getMaxMeal() * 10000 / getFeedConsume()));
  5189. }
  5190.  
  5191. /**
  5192. * @param state : The state to check (can be autofeed, hungry or unsummon).
  5193. * @return true if the limit is reached, false otherwise or if there is no need to feed.
  5194. */
  5195. public boolean checkFoodState(double state)
  5196. {
  5197. return (_canFeed) ? getCurrentFeed() < (_petData.getMaxMeal() * state) : false;
  5198. }
  5199.  
  5200. /**
  5201. * @return the type of attack, depending of the worn weapon.
  5202. */
  5203. @Override
  5204. public WeaponType getAttackType()
  5205. {
  5206. final Weapon weapon = getActiveWeaponItem();
  5207. if (weapon != null)
  5208. return weapon.getItemType();
  5209.  
  5210. return WeaponType.FIST;
  5211. }
  5212.  
  5213. public void setUptime(long time)
  5214. {
  5215. _uptime = time;
  5216. }
  5217.  
  5218. public long getUptime()
  5219. {
  5220. return System.currentTimeMillis() - _uptime;
  5221. }
  5222.  
  5223. /**
  5224. * Return True if the L2PcInstance is invulnerable.
  5225. */
  5226. @Override
  5227. public boolean isInvul()
  5228. {
  5229. return super.isInvul() || isSpawnProtected();
  5230. }
  5231.  
  5232. /**
  5233. * Return True if the L2PcInstance has a Party in progress.
  5234. */
  5235. @Override
  5236. public boolean isInParty()
  5237. {
  5238. return _party != null;
  5239. }
  5240.  
  5241. /**
  5242. * Set the _party object of the L2PcInstance (without joining it).
  5243. * @param party The object.
  5244. */
  5245. public void setParty(L2Party party)
  5246. {
  5247. _party = party;
  5248. }
  5249.  
  5250. /**
  5251. * Set the _party object of the L2PcInstance AND join it.
  5252. * @param party
  5253. */
  5254. public void joinParty(L2Party party)
  5255. {
  5256. if (party != null)
  5257. {
  5258. _party = party;
  5259. party.addPartyMember(this);
  5260. }
  5261. }
  5262.  
  5263. /**
  5264. * Manage the Leave Party task of the L2PcInstance.
  5265. */
  5266. public void leaveParty()
  5267. {
  5268. if (isInParty())
  5269. {
  5270. _party.removePartyMember(this, MessageType.Disconnected);
  5271. _party = null;
  5272. }
  5273. }
  5274.  
  5275. /**
  5276. * Return the _party object of the L2PcInstance.
  5277. */
  5278. @Override
  5279. public L2Party getParty()
  5280. {
  5281. return _party;
  5282. }
  5283.  
  5284. /**
  5285. * Return True if the L2PcInstance is a GM.
  5286. */
  5287. @Override
  5288. public boolean isGM()
  5289. {
  5290. return getAccessLevel().isGm();
  5291. }
  5292.  
  5293. /**
  5294. * Set the _accessLevel of the L2PcInstance.
  5295. * @param level
  5296. */
  5297. public void setAccessLevel(int level)
  5298. {
  5299. if (level == AccessLevels.MASTER_ACCESS_LEVEL_NUMBER)
  5300. {
  5301. _log.warning(getName() + " has logged in with Master access level.");
  5302. _accessLevel = AccessLevels.MASTER_ACCESS_LEVEL;
  5303. }
  5304. else if (level == AccessLevels.USER_ACCESS_LEVEL_NUMBER)
  5305. _accessLevel = AccessLevels.USER_ACCESS_LEVEL;
  5306. else
  5307. {
  5308. L2AccessLevel accessLevel = AccessLevels.getInstance().getAccessLevel(level);
  5309.  
  5310. if (accessLevel == null)
  5311. {
  5312. if (level < 0)
  5313. {
  5314. AccessLevels.getInstance().addBanAccessLevel(level);
  5315. _accessLevel = AccessLevels.getInstance().getAccessLevel(level);
  5316. }
  5317. else
  5318. {
  5319. _log.warning("Server tried to set unregistered access level " + level + " to " + getName() + ". His access level have been reseted to user level.");
  5320. _accessLevel = AccessLevels.USER_ACCESS_LEVEL;
  5321. }
  5322. }
  5323. else
  5324. {
  5325. _accessLevel = accessLevel;
  5326. setTitle(_accessLevel.getName());
  5327. }
  5328. }
  5329.  
  5330. getAppearance().setNameColor(_accessLevel.getNameColor());
  5331. getAppearance().setTitleColor(_accessLevel.getTitleColor());
  5332. broadcastUserInfo();
  5333.  
  5334. CharNameTable.getInstance().addName(this);
  5335. }
  5336.  
  5337. public void setAccountAccesslevel(int level)
  5338. {
  5339. LoginServerThread.getInstance().sendAccessLevel(getAccountName(), level);
  5340. }
  5341.  
  5342. /**
  5343. * @return the _accessLevel of the L2PcInstance.
  5344. */
  5345. public L2AccessLevel getAccessLevel()
  5346. {
  5347. if (Config.EVERYBODY_HAS_ADMIN_RIGHTS)
  5348. return AccessLevels.MASTER_ACCESS_LEVEL;
  5349.  
  5350. if (_accessLevel == null) /* This is here because inventory etc. is loaded before access level on login, so it is not null */
  5351. setAccessLevel(AccessLevels.USER_ACCESS_LEVEL_NUMBER);
  5352.  
  5353. return _accessLevel;
  5354. }
  5355.  
  5356. /**
  5357. * Update Stats of the L2PcInstance client side by sending UserInfo/StatusUpdate to this L2PcInstance and CharInfo/StatusUpdate to all L2PcInstance in its _KnownPlayers (broadcast).
  5358. * @param broadcastType
  5359. */
  5360. public void updateAndBroadcastStatus(int broadcastType)
  5361. {
  5362. refreshOverloaded();
  5363. refreshExpertisePenalty();
  5364.  
  5365. if (broadcastType == 1)
  5366. sendPacket(new UserInfo(this));
  5367. else if (broadcastType == 2)
  5368. broadcastUserInfo();
  5369. }
  5370.  
  5371. /**
  5372. * Send StatusUpdate packet with Karma to the L2PcInstance and all L2PcInstance to inform (broadcast).
  5373. */
  5374. public void broadcastKarma()
  5375. {
  5376. StatusUpdate su = new StatusUpdate(this);
  5377. su.addAttribute(StatusUpdate.KARMA, getKarma());
  5378. sendPacket(su);
  5379.  
  5380. if (getPet() != null)
  5381. sendPacket(new RelationChanged(getPet(), getRelation(this), false));
  5382.  
  5383. broadcastRelationsChanges();
  5384. }
  5385.  
  5386. /**
  5387. * Set the online Flag to True or False and update the characters table of the database with online status and lastAccess (called when login and logout).
  5388. * @param isOnline
  5389. * @param updateInDb
  5390. */
  5391. public void setOnlineStatus(boolean isOnline, boolean updateInDb)
  5392. {
  5393. if (_isOnline != isOnline)
  5394. _isOnline = isOnline;
  5395.  
  5396. // Update the characters table of the database with online status and lastAccess (called when login and logout)
  5397. if (updateInDb)
  5398. updateOnlineStatus();
  5399. }
  5400.  
  5401. public void setIsIn7sDungeon(boolean isIn7sDungeon)
  5402. {
  5403. _isIn7sDungeon = isIn7sDungeon;
  5404. }
  5405.  
  5406. /**
  5407. * Update the characters table of the database with online status and lastAccess of this L2PcInstance (called when login and logout).
  5408. */
  5409. public void updateOnlineStatus()
  5410. {
  5411. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5412. {
  5413. PreparedStatement statement = con.prepareStatement("UPDATE characters SET online=?, lastAccess=? WHERE obj_id=?");
  5414. statement.setInt(1, isOnlineInt());
  5415. statement.setLong(2, System.currentTimeMillis());
  5416. statement.setInt(3, getObjectId());
  5417. statement.execute();
  5418. statement.close();
  5419. }
  5420. catch (Exception e)
  5421. {
  5422. _log.warning("could not set char online status:" + e);
  5423. }
  5424. }
  5425.  
  5426. /**
  5427. * Create a new player in the characters table of the database.
  5428. * @return true if successful.
  5429. */
  5430. private boolean createDb()
  5431. {
  5432. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5433. {
  5434. PreparedStatement statement = con.prepareStatement(INSERT_CHARACTER);
  5435. statement.setString(1, _accountName);
  5436. statement.setInt(2, getObjectId());
  5437. statement.setString(3, getName());
  5438. statement.setInt(4, getLevel());
  5439. statement.setInt(5, getMaxHp());
  5440. statement.setDouble(6, getCurrentHp());
  5441. statement.setInt(7, getMaxCp());
  5442. statement.setDouble(8, getCurrentCp());
  5443. statement.setInt(9, getMaxMp());
  5444. statement.setDouble(10, getCurrentMp());
  5445. statement.setInt(11, getAppearance().getFace());
  5446. statement.setInt(12, getAppearance().getHairStyle());
  5447. statement.setInt(13, getAppearance().getHairColor());
  5448. statement.setInt(14, getAppearance().getSex().ordinal());
  5449. statement.setLong(15, getExp());
  5450. statement.setInt(16, getSp());
  5451. statement.setInt(17, getKarma());
  5452. statement.setInt(18, getPvpKills());
  5453. statement.setInt(19, getPkKills());
  5454. statement.setInt(20, getClanId());
  5455. statement.setInt(21, getRace().ordinal());
  5456. statement.setInt(22, getClassId().getId());
  5457. statement.setLong(23, getDeleteTimer());
  5458. statement.setInt(24, hasDwarvenCraft() ? 1 : 0);
  5459. statement.setString(25, getTitle());
  5460. statement.setInt(26, getAccessLevel().getLevel());
  5461. statement.setInt(27, isOnlineInt());
  5462. statement.setInt(28, isIn7sDungeon() ? 1 : 0);
  5463. statement.setInt(29, getClanPrivileges());
  5464. statement.setInt(30, wantsPeace() ? 1 : 0);
  5465. statement.setInt(31, getBaseClass());
  5466. statement.setInt(32, isNoble() ? 1 : 0);
  5467. statement.setLong(33, 0);
  5468. statement.setLong(34, System.currentTimeMillis());
  5469. statement.executeUpdate();
  5470. statement.close();
  5471. }
  5472. catch (Exception e)
  5473. {
  5474. _log.severe("Could not insert char data: " + e);
  5475. return false;
  5476. }
  5477. return true;
  5478. }
  5479.  
  5480. /**
  5481. * Retrieve a L2PcInstance from the characters table of the database and add it in _allObjects of the L2world.
  5482. * <ul>
  5483. * <li>Retrieve the L2PcInstance from the characters table of the database</li>
  5484. * <li>Add the L2PcInstance object in _allObjects</li>
  5485. * <li>Set the x,y,z position of the L2PcInstance and make it invisible</li>
  5486. * <li>Update the overloaded status of the L2PcInstance</li>
  5487. * </ul>
  5488. * @param objectId Identifier of the object to initialized
  5489. * @return The L2PcInstance loaded from the database
  5490. */
  5491. public static L2PcInstance restore(int objectId)
  5492. {
  5493. L2PcInstance player = null;
  5494. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5495. {
  5496. PreparedStatement statement = con.prepareStatement(RESTORE_CHARACTER);
  5497. statement.setInt(1, objectId);
  5498. ResultSet rset = statement.executeQuery();
  5499.  
  5500. while (rset.next())
  5501. {
  5502.  
  5503. final int activeClassId = rset.getInt("classid");
  5504. final PcTemplate template = CharTemplateTable.getInstance().getTemplate(activeClassId);
  5505. final PcAppearance app = new PcAppearance(rset.getByte("face"), rset.getByte("hairColor"), rset.getByte("hairStyle"), Sex.values()[rset.getInt("sex")]);
  5506.  
  5507. player = new L2PcInstance(objectId, template, rset.getString("account_name"), app);
  5508. player.setName(rset.getString("char_name"));
  5509. player._lastAccess = rset.getLong("lastAccess");
  5510.  
  5511. try
  5512. {
  5513. player.getAppearance().setNameColor(Integer.decode(new StringBuilder().append("0x").append(rset.getString("name_color")).toString()).intValue());
  5514.  
  5515. }
  5516. catch (final Exception e)
  5517. { //e.printStackTrace();
  5518. }
  5519. try
  5520. {
  5521. player.getAppearance().setTitleColor(Integer.decode(new StringBuilder().append("0x").append(rset.getString("title_color")).toString()).intValue());
  5522. }
  5523. catch (final Exception e)
  5524. { //e.printStackTrace();
  5525. }
  5526. player.setAccName(rset.getString("account_name"));
  5527.  
  5528. player.getStat().setExp(rset.getLong("exp"));
  5529. player.setExpBeforeDeath(rset.getLong("expBeforeDeath"));
  5530. player.getStat().setLevel(rset.getByte("level"));
  5531. player.getStat().setSp(rset.getInt("sp"));
  5532.  
  5533. player.setWantsPeace(rset.getInt("wantspeace") == 1);
  5534.  
  5535. player.setHeading(rset.getInt("heading"));
  5536.  
  5537. player.setKarma(rset.getInt("karma"));
  5538. player.setPvpKills(rset.getInt("pvpkills"));
  5539. player.setPkKills(rset.getInt("pkkills"));
  5540. player.setOnlineTime(rset.getLong("onlinetime"));
  5541. player.setNoble(rset.getInt("nobless") == 1, false);
  5542.  
  5543. player.setClanJoinExpiryTime(rset.getLong("clan_join_expiry_time"));
  5544. if (player.getClanJoinExpiryTime() < System.currentTimeMillis())
  5545. player.setClanJoinExpiryTime(0);
  5546.  
  5547. player.setClanCreateExpiryTime(rset.getLong("clan_create_expiry_time"));
  5548. if (player.getClanCreateExpiryTime() < System.currentTimeMillis())
  5549. player.setClanCreateExpiryTime(0);
  5550.  
  5551. player.setPowerGrade(rset.getInt("power_grade"));
  5552. player.setPledgeType(rset.getInt("subpledge"));
  5553. player.setLastRecomUpdate(rset.getLong("last_recom_date"));
  5554.  
  5555. player.setdonator(rset.getInt("donator")==1);
  5556.  
  5557. int clanId = rset.getInt("clanid");
  5558. if (clanId > 0)
  5559. player.setClan(ClanTable.getInstance().getClan(clanId));
  5560.  
  5561. if (player.getClan() != null)
  5562. {
  5563. if (player.getClan().getLeaderId() != player.getObjectId())
  5564. {
  5565. if (player.getPowerGrade() == 0)
  5566. player.setPowerGrade(5);
  5567.  
  5568. player.setClanPrivileges(player.getClan().getRankPrivs(player.getPowerGrade()));
  5569. }
  5570. else
  5571. {
  5572. player.setClanPrivileges(L2Clan.CP_ALL);
  5573. player.setPowerGrade(1);
  5574. }
  5575. }
  5576. else
  5577. player.setClanPrivileges(L2Clan.CP_NOTHING);
  5578.  
  5579. player.setDeleteTimer(rset.getLong("deletetime"));
  5580.  
  5581. player.setTitle(rset.getString("title"));
  5582. player.setAccessLevel(rset.getInt("accesslevel"));
  5583. player.setFistsWeaponItem(findFistsWeaponItem(activeClassId));
  5584. player.setUptime(System.currentTimeMillis());
  5585.  
  5586. // Check recs
  5587. player.checkRecom(rset.getInt("rec_have"), rset.getInt("rec_left"));
  5588.  
  5589. player._classIndex = 0;
  5590. try
  5591. {
  5592. player.setBaseClass(rset.getInt("base_class"));
  5593. }
  5594. catch (Exception e)
  5595. {
  5596. player.setBaseClass(activeClassId);
  5597. }
  5598.  
  5599. // Restore Subclass Data (cannot be done earlier in function)
  5600. if (restoreSubClassData(player))
  5601. {
  5602. if (activeClassId != player.getBaseClass())
  5603. {
  5604. for (SubClass subClass : player.getSubClasses().values())
  5605. if (subClass.getClassId() == activeClassId)
  5606. player._classIndex = subClass.getClassIndex();
  5607. }
  5608. }
  5609. if (player.getClassIndex() == 0 && activeClassId != player.getBaseClass())
  5610. {
  5611. // Subclass in use but doesn't exist in DB -
  5612. // a possible restart-while-modifysubclass cheat has been attempted.
  5613. // Switching to use base class
  5614. player.setClassId(player.getBaseClass());
  5615. _log.warning("Player " + player.getName() + " reverted to base class. Possibly has tried a relogin exploit while subclassing.");
  5616. }
  5617. else
  5618. player._activeClass = activeClassId;
  5619.  
  5620. player.setApprentice(rset.getInt("apprentice"));
  5621. player.setSponsor(rset.getInt("sponsor"));
  5622. player.setLvlJoinedAcademy(rset.getInt("lvl_joined_academy"));
  5623. player.setIsIn7sDungeon(rset.getInt("isin7sdungeon") == 1);
  5624. player.setPunishLevel(rset.getInt("punish_level"));
  5625. if (player.getPunishLevel() != PunishLevel.NONE)
  5626. player.setPunishTimer(rset.getLong("punish_timer"));
  5627. else
  5628. player.setPunishTimer(0);
  5629.  
  5630. CursedWeaponsManager.getInstance().checkPlayer(player);
  5631.  
  5632. player.setAllianceWithVarkaKetra(rset.getInt("varka_ketra_ally"));
  5633.  
  5634. player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
  5635.  
  5636. // Set the x,y,z position of the L2PcInstance and make it invisible
  5637. player.setXYZInvisible(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
  5638.  
  5639. // Set Hero status if it applies
  5640. if (Hero.getInstance().isActiveHero(objectId))
  5641. player.setHero(true);
  5642.  
  5643. // Set pledge class rank.
  5644. player.setPledgeClass(L2ClanMember.calculatePledgeClass(player));
  5645.  
  5646. // Retrieve from the database all secondary data of this L2PcInstance and reward expertise/lucky skills if necessary.
  5647. // Note that Clan, Noblesse and Hero skills are given separately and not here.
  5648. player.restoreCharData();
  5649. player.rewardSkills();
  5650.  
  5651. // buff and status icons
  5652. if (Config.STORE_SKILL_COOLTIME)
  5653. player.restoreEffects();
  5654.  
  5655. // Restore current CP, HP and MP values
  5656. final double currentHp = rset.getDouble("curHp");
  5657.  
  5658. player.setCurrentCp(rset.getDouble("curCp"));
  5659. player.setCurrentHp(currentHp);
  5660. player.setCurrentMp(rset.getDouble("curMp"));
  5661.  
  5662. if (currentHp < 0.5)
  5663. {
  5664. player.setIsDead(true);
  5665. player.stopHpMpRegeneration();
  5666. }
  5667.  
  5668. // Restore pet if exists in the world
  5669. player.setPet(L2World.getInstance().getPet(player.getObjectId()));
  5670. if (player.getPet() != null)
  5671. player.getPet().setOwner(player);
  5672.  
  5673. player.refreshOverloaded();
  5674. player.refreshExpertisePenalty();
  5675.  
  5676. player.restoreFriendList();
  5677.  
  5678. // Retrieve the name and ID of the other characters assigned to this account.
  5679. PreparedStatement stmt = con.prepareStatement("SELECT obj_Id, char_name FROM characters WHERE account_name=? AND obj_Id<>?");
  5680. stmt.setString(1, player._accountName);
  5681. stmt.setInt(2, objectId);
  5682. ResultSet chars = stmt.executeQuery();
  5683.  
  5684. while (chars.next())
  5685. player.getAccountChars().put(chars.getInt("obj_Id"), chars.getString("char_name"));
  5686.  
  5687. chars.close();
  5688. stmt.close();
  5689. break;
  5690. }
  5691.  
  5692. rset.close();
  5693. statement.close();
  5694. }
  5695. catch (Exception e)
  5696. {
  5697. _log.severe("Could not restore char data: " + e);
  5698. }
  5699.  
  5700. return player;
  5701. }
  5702.  
  5703. public Forum getMail()
  5704. {
  5705. if (_forumMail == null)
  5706. {
  5707. setMail(ForumsBBSManager.getInstance().getForumByName("MailRoot").getChildByName(getName()));
  5708.  
  5709. if (_forumMail == null)
  5710. {
  5711. ForumsBBSManager.getInstance().createNewForum(getName(), ForumsBBSManager.getInstance().getForumByName("MailRoot"), Forum.MAIL, Forum.OWNERONLY, getObjectId());
  5712. setMail(ForumsBBSManager.getInstance().getForumByName("MailRoot").getChildByName(getName()));
  5713. }
  5714. }
  5715.  
  5716. return _forumMail;
  5717. }
  5718.  
  5719. public void setMail(Forum forum)
  5720. {
  5721. _forumMail = forum;
  5722. }
  5723.  
  5724. public Forum getMemo()
  5725. {
  5726. if (_forumMemo == null)
  5727. {
  5728. setMemo(ForumsBBSManager.getInstance().getForumByName("MemoRoot").getChildByName(_accountName));
  5729.  
  5730. if (_forumMemo == null)
  5731. {
  5732. ForumsBBSManager.getInstance().createNewForum(_accountName, ForumsBBSManager.getInstance().getForumByName("MemoRoot"), Forum.MEMO, Forum.OWNERONLY, getObjectId());
  5733. setMemo(ForumsBBSManager.getInstance().getForumByName("MemoRoot").getChildByName(_accountName));
  5734. }
  5735. }
  5736.  
  5737. return _forumMemo;
  5738. }
  5739.  
  5740. public void setMemo(Forum forum)
  5741. {
  5742. _forumMemo = forum;
  5743. }
  5744.  
  5745. /**
  5746. * Restores sub-class data for the L2PcInstance, used to check the current class index for the character.
  5747. * @param player The player to make checks on.
  5748. * @return true if successful.
  5749. */
  5750. private static boolean restoreSubClassData(L2PcInstance player)
  5751. {
  5752. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5753. {
  5754. PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_SUBCLASSES);
  5755. statement.setInt(1, player.getObjectId());
  5756.  
  5757. ResultSet rset = statement.executeQuery();
  5758.  
  5759. while (rset.next())
  5760. {
  5761. SubClass subClass = new SubClass(rset.getInt("class_id"), rset.getInt("class_index"), rset.getLong("exp"), rset.getInt("sp"), rset.getByte("level"));
  5762.  
  5763. // Enforce the correct indexing of _subClasses against their class indexes.
  5764. player.getSubClasses().put(subClass.getClassIndex(), subClass);
  5765. }
  5766. rset.close();
  5767. statement.close();
  5768. }
  5769. catch (Exception e)
  5770. {
  5771. _log.warning("Could not restore classes for " + player.getName() + ": " + e);
  5772. e.printStackTrace();
  5773. }
  5774.  
  5775. return true;
  5776. }
  5777.  
  5778. /**
  5779. * Restores secondary data for the L2PcInstance, based on the current class index.
  5780. */
  5781. private void restoreCharData()
  5782. {
  5783. // Retrieve from the database all skills of this L2PcInstance and add them to _skills.
  5784. restoreSkills();
  5785.  
  5786. // Retrieve from the database all macroses of this L2PcInstance and add them to _macroses.
  5787. _macroses.restore();
  5788.  
  5789. // Retrieve from the database all shortCuts of this L2PcInstance and add them to _shortCuts.
  5790. _shortCuts.restore();
  5791.  
  5792. // Retrieve from the database all henna of this L2PcInstance and add them to _henna.
  5793. restoreHenna();
  5794.  
  5795. // Retrieve from the database all recom data of this L2PcInstance and add to _recomChars.
  5796. restoreRecom();
  5797.  
  5798. // Retrieve from the database the recipe book of this L2PcInstance.
  5799. if (!isSubClassActive())
  5800. restoreRecipeBook();
  5801. }
  5802.  
  5803. /**
  5804. * Store recipe book data for this L2PcInstance, if not on an active sub-class.
  5805. */
  5806. private void storeRecipeBook()
  5807. {
  5808. // If the player is on a sub-class don't even attempt to store a recipe book.
  5809. if (isSubClassActive())
  5810. return;
  5811.  
  5812. if (getCommonRecipeBook().isEmpty() && getDwarvenRecipeBook().isEmpty())
  5813. return;
  5814.  
  5815. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5816. {
  5817. PreparedStatement statement = con.prepareStatement("DELETE FROM character_recipebook WHERE char_id=?");
  5818. statement.setInt(1, getObjectId());
  5819. statement.execute();
  5820. statement.close();
  5821.  
  5822. for (RecipeList recipe : getCommonRecipeBook())
  5823. {
  5824. statement = con.prepareStatement("INSERT INTO character_recipebook (char_id, id, type) values(?,?,0)");
  5825. statement.setInt(1, getObjectId());
  5826. statement.setInt(2, recipe.getId());
  5827. statement.execute();
  5828. statement.close();
  5829. }
  5830.  
  5831. for (RecipeList recipe : getDwarvenRecipeBook())
  5832. {
  5833. statement = con.prepareStatement("INSERT INTO character_recipebook (char_id, id, type) values(?,?,1)");
  5834. statement.setInt(1, getObjectId());
  5835. statement.setInt(2, recipe.getId());
  5836. statement.execute();
  5837. statement.close();
  5838. }
  5839. }
  5840. catch (Exception e)
  5841. {
  5842. _log.warning("Could not store recipe book data: " + e);
  5843. }
  5844. }
  5845.  
  5846. /**
  5847. * Restore recipe book data for this L2PcInstance.
  5848. */
  5849. private void restoreRecipeBook()
  5850. {
  5851. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5852. {
  5853. PreparedStatement statement = con.prepareStatement("SELECT id, type FROM character_recipebook WHERE char_id=?");
  5854. statement.setInt(1, getObjectId());
  5855. ResultSet rset = statement.executeQuery();
  5856.  
  5857. while (rset.next())
  5858. {
  5859. final RecipeList recipe = RecipeTable.getInstance().getRecipeList(rset.getInt("id"));
  5860. if (rset.getInt("type") == 1)
  5861. registerDwarvenRecipeList(recipe);
  5862. else
  5863. registerCommonRecipeList(recipe);
  5864. }
  5865.  
  5866. rset.close();
  5867. statement.close();
  5868. }
  5869. catch (Exception e)
  5870. {
  5871. _log.warning("Could not restore recipe book data:" + e);
  5872. }
  5873. }
  5874.  
  5875. /**
  5876. * Update L2PcInstance stats in the characters table of the database.
  5877. * @param storeActiveEffects
  5878. */
  5879. public synchronized void store(boolean storeActiveEffects)
  5880. {
  5881. // update client coords, if these look like true
  5882. if (isInsideRadius(getClientX(), getClientY(), 1000, true))
  5883. setXYZ(getClientX(), getClientY(), getClientZ());
  5884.  
  5885. storeCharBase();
  5886. storeCharSub();
  5887. storeEffect(storeActiveEffects);
  5888. storeRecipeBook();
  5889.  
  5890. SevenSigns.getInstance().saveSevenSignsData(getObjectId());
  5891.  
  5892. _vars.storeMe();
  5893. }
  5894.  
  5895. public void store()
  5896. {
  5897. store(true);
  5898. }
  5899.  
  5900. private void storeCharBase()
  5901. {
  5902. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  5903. {
  5904. // Get the exp, level, and sp of base class to store in base table
  5905. int currentClassIndex = getClassIndex();
  5906. _classIndex = 0;
  5907. long exp = getStat().getExp();
  5908. int level = getStat().getLevel();
  5909. int sp = getStat().getSp();
  5910. _classIndex = currentClassIndex;
  5911.  
  5912. PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER);
  5913.  
  5914. statement.setInt(1, level);
  5915. statement.setInt(2, getMaxHp());
  5916. statement.setDouble(3, getCurrentHp());
  5917. statement.setInt(4, getMaxCp());
  5918. statement.setDouble(5, getCurrentCp());
  5919. statement.setInt(6, getMaxMp());
  5920. statement.setDouble(7, getCurrentMp());
  5921. statement.setInt(8, getAppearance().getFace());
  5922. statement.setInt(9, getAppearance().getHairStyle());
  5923. statement.setInt(10, getAppearance().getHairColor());
  5924. statement.setInt(11, getAppearance().getSex().ordinal());
  5925. statement.setInt(12, getHeading());
  5926. statement.setInt(13, _observerMode ? _savedLocation.getX() : getX());
  5927. statement.setInt(14, _observerMode ? _savedLocation.getY() : getY());
  5928. statement.setInt(15, _observerMode ? _savedLocation.getZ() : getZ());
  5929. statement.setLong(16, exp);
  5930. statement.setLong(17, getExpBeforeDeath());
  5931. statement.setInt(18, sp);
  5932. statement.setInt(19, getKarma());
  5933. statement.setInt(20, getPvpKills());
  5934. statement.setInt(21, getPkKills());
  5935. statement.setInt(22, getRecomHave());
  5936. statement.setInt(23, getRecomLeft());
  5937. statement.setInt(24, getClanId());
  5938. statement.setInt(25, getRace().ordinal());
  5939. statement.setInt(26, getClassId().getId());
  5940. statement.setLong(27, getDeleteTimer());
  5941. statement.setString(28, getTitle());
  5942. statement.setInt(29, getAccessLevel().getLevel());
  5943. statement.setInt(30, isOnlineInt());
  5944. statement.setInt(31, isIn7sDungeon() ? 1 : 0);
  5945. statement.setInt(32, getClanPrivileges());
  5946. statement.setInt(33, wantsPeace() ? 1 : 0);
  5947. statement.setInt(34, getBaseClass());
  5948.  
  5949. long totalOnlineTime = _onlineTime;
  5950. if (_onlineBeginTime > 0)
  5951. totalOnlineTime += (System.currentTimeMillis() - _onlineBeginTime) / 1000;
  5952.  
  5953. statement.setLong(35, totalOnlineTime);
  5954. statement.setInt(36, getPunishLevel().value());
  5955. statement.setLong(37, getPunishTimer());
  5956. statement.setInt(38, isNoble() ? 1 : 0);
  5957. statement.setLong(39, getPowerGrade());
  5958. statement.setInt(40, getPledgeType());
  5959. statement.setLong(41, getLastRecomUpdate());
  5960. statement.setInt(42, getLvlJoinedAcademy());
  5961. statement.setLong(43, getApprentice());
  5962. statement.setLong(44, getSponsor());
  5963. statement.setInt(45, getAllianceWithVarkaKetra());
  5964. statement.setLong(46, getClanJoinExpiryTime());
  5965. statement.setLong(47, getClanCreateExpiryTime());
  5966. statement.setString(48, getName());
  5967. statement.setLong(49, getDeathPenaltyBuffLevel());
  5968. statement.setLong(50, isdonator() ? 1 : 0);
  5969. statement.setString(51, StringToHex(Integer.toHexString(getAppearance().getNameColor()).toUpperCase()));
  5970. statement.setString(52, StringToHex(Integer.toHexString(getAppearance().getTitleColor()).toUpperCase()));
  5971. statement.setInt(53, getObjectId());
  5972.  
  5973. statement.execute();
  5974. statement.close();
  5975. }
  5976. catch (Exception e)
  5977. {
  5978. _log.warning("Could not store char base data: " + e);
  5979. }
  5980. }
  5981.  
  5982. /**
  5983. * String to hex.
  5984. * @param color the color
  5985. * @return the string
  5986. */
  5987. private String StringToHex(String color)
  5988. {
  5989. switch (color.length())
  5990. {
  5991. case 1:
  5992. color = new StringBuilder().append("00000").append(color).toString();
  5993. break;
  5994.  
  5995. case 2:
  5996. color = new StringBuilder().append("0000").append(color).toString();
  5997. break;
  5998.  
  5999. case 3:
  6000. color = new StringBuilder().append("000").append(color).toString();
  6001. break;
  6002.  
  6003. case 4:
  6004. color = new StringBuilder().append("00").append(color).toString();
  6005. break;
  6006.  
  6007. case 5:
  6008. color = new StringBuilder().append('0').append(color).toString();
  6009. break;
  6010. }
  6011. return color;
  6012. }
  6013.  
  6014. private void storeCharSub()
  6015. {
  6016. if (_subClasses.isEmpty())
  6017. return;
  6018.  
  6019. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6020. {
  6021. PreparedStatement statement = con.prepareStatement(UPDATE_CHAR_SUBCLASS);
  6022. for (SubClass subClass : _subClasses.values())
  6023. {
  6024. statement.setLong(1, subClass.getExp());
  6025. statement.setInt(2, subClass.getSp());
  6026. statement.setInt(3, subClass.getLevel());
  6027. statement.setInt(4, subClass.getClassId());
  6028. statement.setInt(5, getObjectId());
  6029. statement.setInt(6, subClass.getClassIndex());
  6030. statement.execute();
  6031. statement.clearParameters();
  6032. }
  6033. statement.close();
  6034. }
  6035. catch (Exception e)
  6036. {
  6037. _log.warning("Could not store sub class data for " + getName() + ": " + e);
  6038. }
  6039. }
  6040.  
  6041. private void storeEffect(boolean storeEffects)
  6042. {
  6043. if (!Config.STORE_SKILL_COOLTIME)
  6044. return;
  6045.  
  6046. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6047. {
  6048. // Delete all current stored effects for char to avoid dupe
  6049. PreparedStatement statement = con.prepareStatement(DELETE_SKILL_SAVE);
  6050.  
  6051. statement.setInt(1, getObjectId());
  6052. statement.setInt(2, getClassIndex());
  6053. statement.execute();
  6054. statement.close();
  6055.  
  6056. int buff_index = 0;
  6057.  
  6058. final List<Integer> storedSkills = new ArrayList<>();
  6059.  
  6060. // Store all effect data along with calulated remaining reuse delays for matching skills. 'restore_type'= 0.
  6061. statement = con.prepareStatement(ADD_SKILL_SAVE);
  6062.  
  6063. if (storeEffects)
  6064. {
  6065. for (L2Effect effect : getAllEffects())
  6066. {
  6067. if (effect == null)
  6068. continue;
  6069.  
  6070. switch (effect.getEffectType())
  6071. {
  6072. case HEAL_OVER_TIME:
  6073. case COMBAT_POINT_HEAL_OVER_TIME:
  6074. continue;
  6075. }
  6076.  
  6077. L2Skill skill = effect.getSkill();
  6078. if (storedSkills.contains(skill.getReuseHashCode()))
  6079. continue;
  6080.  
  6081. storedSkills.add(skill.getReuseHashCode());
  6082.  
  6083. if (!effect.isHerbEffect() && effect.getInUse() && !skill.isToggle())
  6084. {
  6085. statement.setInt(1, getObjectId());
  6086. statement.setInt(2, skill.getId());
  6087. statement.setInt(3, skill.getLevel());
  6088. statement.setInt(4, effect.getCount());
  6089. statement.setInt(5, effect.getTime());
  6090.  
  6091. if (_reuseTimeStamps.containsKey(skill.getReuseHashCode()))
  6092. {
  6093. TimeStamp t = _reuseTimeStamps.get(skill.getReuseHashCode());
  6094. statement.setLong(6, t.hasNotPassed() ? t.getReuse() : 0);
  6095. statement.setDouble(7, t.hasNotPassed() ? t.getStamp() : 0);
  6096. }
  6097. else
  6098. {
  6099. statement.setLong(6, 0);
  6100. statement.setDouble(7, 0);
  6101. }
  6102.  
  6103. statement.setInt(8, 0);
  6104. statement.setInt(9, getClassIndex());
  6105. statement.setInt(10, ++buff_index);
  6106. statement.execute();
  6107. }
  6108. }
  6109. }
  6110.  
  6111. // Store the reuse delays of remaining skills which lost effect but still under reuse delay. 'restore_type' 1.
  6112. for (Map.Entry<Integer, TimeStamp> timestampEntry : _reuseTimeStamps.entrySet())
  6113. {
  6114. final int hash = timestampEntry.getKey();
  6115. if (storedSkills.contains(hash))
  6116. continue;
  6117.  
  6118. TimeStamp t = timestampEntry.getValue();
  6119. if (t != null && t.hasNotPassed())
  6120. {
  6121. storedSkills.add(hash);
  6122.  
  6123. statement.setInt(1, getObjectId());
  6124. statement.setInt(2, t.getSkillId());
  6125. statement.setInt(3, t.getSkillLvl());
  6126. statement.setInt(4, -1);
  6127. statement.setInt(5, -1);
  6128. statement.setLong(6, t.getReuse());
  6129. statement.setDouble(7, t.getStamp());
  6130. statement.setInt(8, 1);
  6131. statement.setInt(9, getClassIndex());
  6132. statement.setInt(10, ++buff_index);
  6133. statement.execute();
  6134. }
  6135. }
  6136. statement.close();
  6137. }
  6138. catch (Exception e)
  6139. {
  6140. _log.log(Level.WARNING, "Could not store char effect data: ", e);
  6141. }
  6142. }
  6143.  
  6144. /**
  6145. * @return True if the L2PcInstance is online.
  6146. */
  6147. public boolean isOnline()
  6148. {
  6149. return _isOnline;
  6150. }
  6151.  
  6152. /**
  6153. * @return an int interpretation of online status.
  6154. */
  6155. public int isOnlineInt()
  6156. {
  6157. if (_isOnline && getClient() != null)
  6158. return getClient().isDetached() ? 2 : 1;
  6159.  
  6160. return 0;
  6161. }
  6162.  
  6163. public boolean isIn7sDungeon()
  6164. {
  6165. return _isIn7sDungeon;
  6166. }
  6167.  
  6168. /**
  6169. * Add a skill to the L2PcInstance _skills and its Func objects to the calculator set of the L2PcInstance and save update in the character_skills table of the database.
  6170. * <ul>
  6171. * <li>Replace oldSkill by newSkill or Add the newSkill</li>
  6172. * <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li>
  6173. * <li>Add Func objects of newSkill to the calculator set of the L2Character</li>
  6174. * </ul>
  6175. * @param newSkill The L2Skill to add to the L2Character
  6176. * @param store
  6177. * @return The L2Skill replaced or null if just added a new L2Skill
  6178. */
  6179. public L2Skill addSkill(L2Skill newSkill, boolean store)
  6180. {
  6181. // Add a skill to the L2PcInstance _skills and its Func objects to the calculator set of the L2PcInstance
  6182. L2Skill oldSkill = super.addSkill(newSkill);
  6183.  
  6184. // Add or update a L2PcInstance skill in the character_skills table of the database
  6185. if (store)
  6186. storeSkill(newSkill, oldSkill, -1);
  6187.  
  6188. return oldSkill;
  6189. }
  6190.  
  6191. @Override
  6192. public L2Skill removeSkill(L2Skill skill, boolean store)
  6193. {
  6194. if (store)
  6195. return removeSkill(skill);
  6196.  
  6197. return super.removeSkill(skill, true);
  6198. }
  6199.  
  6200. public L2Skill removeSkill(L2Skill skill, boolean store, boolean cancelEffect)
  6201. {
  6202. if (store)
  6203. return removeSkill(skill);
  6204.  
  6205. return super.removeSkill(skill, cancelEffect);
  6206. }
  6207.  
  6208. /**
  6209. * Remove a skill from the L2Character and its Func objects from calculator set of the L2Character and save update in the character_skills table of the database.
  6210. * <ul>
  6211. * <li>Remove the skill from the L2Character _skills</li>
  6212. * <li>Remove all its Func objects from the L2Character calculator set</li>
  6213. * </ul>
  6214. * @param skill The L2Skill to remove from the L2Character
  6215. * @return The L2Skill removed
  6216. */
  6217. @Override
  6218. public L2Skill removeSkill(L2Skill skill)
  6219. {
  6220. // Remove a skill from the L2Character and its Func objects from calculator set of the L2Character
  6221. L2Skill oldSkill = super.removeSkill(skill);
  6222.  
  6223. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6224. {
  6225. PreparedStatement statement = con.prepareStatement(DELETE_SKILL_FROM_CHAR);
  6226.  
  6227. if (oldSkill != null)
  6228. {
  6229. statement.setInt(1, oldSkill.getId());
  6230. statement.setInt(2, getObjectId());
  6231. statement.setInt(3, getClassIndex());
  6232. statement.execute();
  6233. }
  6234. statement.close();
  6235. }
  6236. catch (Exception e)
  6237. {
  6238. _log.warning("Error could not delete skill: " + e);
  6239. }
  6240.  
  6241. // Don't busy with shortcuts if skill was a passive skill.
  6242. if (skill != null && !skill.isPassive())
  6243. {
  6244. for (L2ShortCut sc : getAllShortCuts())
  6245. {
  6246. if (sc != null && sc.getId() == skill.getId() && sc.getType() == L2ShortCut.TYPE_SKILL)
  6247. deleteShortCut(sc.getSlot(), sc.getPage());
  6248. }
  6249. }
  6250.  
  6251. return oldSkill;
  6252. }
  6253.  
  6254. /**
  6255. * Add or update a L2PcInstance skill in the character_skills table of the database. <BR>
  6256. * <BR>
  6257. * If newClassIndex > -1, the skill will be stored with that class index, not the current one.
  6258. * @param newSkill
  6259. * @param oldSkill
  6260. * @param newClassIndex
  6261. */
  6262. private void storeSkill(L2Skill newSkill, L2Skill oldSkill, int newClassIndex)
  6263. {
  6264. int classIndex = _classIndex;
  6265.  
  6266. if (newClassIndex > -1)
  6267. classIndex = newClassIndex;
  6268.  
  6269. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6270. {
  6271. if (oldSkill != null && newSkill != null)
  6272. {
  6273. PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER_SKILL_LEVEL);
  6274. statement.setInt(1, newSkill.getLevel());
  6275. statement.setInt(2, oldSkill.getId());
  6276. statement.setInt(3, getObjectId());
  6277. statement.setInt(4, classIndex);
  6278. statement.execute();
  6279. statement.close();
  6280. }
  6281. else if (newSkill != null)
  6282. {
  6283. PreparedStatement statement = con.prepareStatement(ADD_NEW_SKILL);
  6284. statement.setInt(1, getObjectId());
  6285. statement.setInt(2, newSkill.getId());
  6286. statement.setInt(3, newSkill.getLevel());
  6287. statement.setInt(4, classIndex);
  6288. statement.execute();
  6289. statement.close();
  6290. }
  6291. else
  6292. {
  6293. _log.warning("storeSkill() couldn't store new skill. It's null type.");
  6294. }
  6295. }
  6296. catch (Exception e)
  6297. {
  6298. _log.warning("Error could not store char skills: " + e);
  6299. }
  6300. }
  6301.  
  6302. /**
  6303. * Retrieve from the database all skills of this L2PcInstance and add them to _skills.
  6304. */
  6305. private void restoreSkills()
  6306. {
  6307. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6308. {
  6309. PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR);
  6310. statement.setInt(1, getObjectId());
  6311. statement.setInt(2, getClassIndex());
  6312. ResultSet rset = statement.executeQuery();
  6313.  
  6314. // Go though the recordset of this SQL query
  6315. while (rset.next())
  6316. {
  6317. int id = rset.getInt("skill_id");
  6318. int level = rset.getInt("skill_level");
  6319.  
  6320. if (id > 9000)
  6321. continue; // fake skills for base stats
  6322.  
  6323. // Create a L2Skill object for each record
  6324. L2Skill skill = SkillTable.getInstance().getInfo(id, level);
  6325.  
  6326. // Add the L2Skill object to the L2Character _skills and its Func objects to the calculator set of the L2Character
  6327. super.addSkill(skill);
  6328. }
  6329.  
  6330. rset.close();
  6331. statement.close();
  6332. }
  6333. catch (Exception e)
  6334. {
  6335. _log.warning("Could not restore character skills: " + e);
  6336. }
  6337. }
  6338.  
  6339. /**
  6340. * Retrieve from the database all skill effects of this L2PcInstance and add them to the player.
  6341. */
  6342. public void restoreEffects()
  6343. {
  6344. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6345. {
  6346. PreparedStatement statement = con.prepareStatement(RESTORE_SKILL_SAVE);
  6347. statement.setInt(1, getObjectId());
  6348. statement.setInt(2, getClassIndex());
  6349. ResultSet rset = statement.executeQuery();
  6350.  
  6351. while (rset.next())
  6352. {
  6353. int effectCount = rset.getInt("effect_count");
  6354. int effectCurTime = rset.getInt("effect_cur_time");
  6355. long reuseDelay = rset.getLong("reuse_delay");
  6356. long systime = rset.getLong("systime");
  6357. int restoreType = rset.getInt("restore_type");
  6358.  
  6359. final L2Skill skill = SkillTable.getInstance().getInfo(rset.getInt("skill_id"), rset.getInt("skill_level"));
  6360. if (skill == null)
  6361. continue;
  6362.  
  6363. final long remainingTime = systime - System.currentTimeMillis();
  6364. if (remainingTime > 10)
  6365. {
  6366. disableSkill(skill, remainingTime);
  6367. addTimeStamp(skill, reuseDelay, systime);
  6368. }
  6369.  
  6370. /**
  6371. * Restore Type 1 The remaning skills lost effect upon logout but were still under a high reuse delay.
  6372. */
  6373. if (restoreType > 0)
  6374. continue;
  6375.  
  6376. /**
  6377. * Restore Type 0 These skills were still in effect on the character upon logout. Some of which were self casted and might still have a long reuse delay which also is restored.
  6378. */
  6379. if (skill.hasEffects())
  6380. {
  6381. final Env env = new Env();
  6382. env.setCharacter(this);
  6383. env.setTarget(this);
  6384. env.setSkill(skill);
  6385.  
  6386. for (EffectTemplate et : skill.getEffectTemplates())
  6387. {
  6388. final L2Effect ef = et.getEffect(env);
  6389. if (ef != null)
  6390. {
  6391. ef.setCount(effectCount);
  6392. ef.setFirstTime(effectCurTime);
  6393. ef.scheduleEffect();
  6394. }
  6395. }
  6396. }
  6397. }
  6398.  
  6399. rset.close();
  6400. statement.close();
  6401.  
  6402. statement = con.prepareStatement(DELETE_SKILL_SAVE);
  6403. statement.setInt(1, getObjectId());
  6404. statement.setInt(2, getClassIndex());
  6405. statement.executeUpdate();
  6406. statement.close();
  6407. }
  6408. catch (Exception e)
  6409. {
  6410. _log.log(Level.WARNING, "Could not restore " + this + " active effect data: " + e.getMessage(), e);
  6411. }
  6412. }
  6413.  
  6414. /**
  6415. * Retrieve from the database all Henna of this L2PcInstance, add them to _henna and calculate stats of the L2PcInstance.
  6416. */
  6417. private void restoreHenna()
  6418. {
  6419. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6420. {
  6421. PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_HENNAS);
  6422. statement.setInt(1, getObjectId());
  6423. statement.setInt(2, getClassIndex());
  6424. ResultSet rset = statement.executeQuery();
  6425.  
  6426. for (int i = 0; i < 3; i++)
  6427. _henna[i] = null;
  6428.  
  6429. while (rset.next())
  6430. {
  6431. int slot = rset.getInt("slot");
  6432.  
  6433. if (slot < 1 || slot > 3)
  6434. continue;
  6435.  
  6436. int symbolId = rset.getInt("symbol_id");
  6437. if (symbolId != 0)
  6438. {
  6439. Henna tpl = HennaTable.getInstance().getTemplate(symbolId);
  6440. if (tpl != null)
  6441. _henna[slot - 1] = tpl;
  6442. }
  6443. }
  6444.  
  6445. rset.close();
  6446. statement.close();
  6447. }
  6448. catch (Exception e)
  6449. {
  6450. _log.warning("could not restore henna: " + e);
  6451. }
  6452.  
  6453. // Calculate Henna modifiers of this L2PcInstance
  6454. recalcHennaStats();
  6455. }
  6456.  
  6457. /**
  6458. * Retrieve from the database all Recommendation data of this L2PcInstance, add to _recomChars and calculate stats of the L2PcInstance.
  6459. */
  6460. private void restoreRecom()
  6461. {
  6462. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6463. {
  6464. PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_RECOMS);
  6465. statement.setInt(1, getObjectId());
  6466. ResultSet rset = statement.executeQuery();
  6467. while (rset.next())
  6468. _recomChars.add(rset.getInt("target_id"));
  6469.  
  6470. rset.close();
  6471. statement.close();
  6472. }
  6473. catch (Exception e)
  6474. {
  6475. _log.warning("could not restore recommendations: " + e);
  6476. }
  6477. }
  6478.  
  6479. /**
  6480. * @return the number of Henna empty slot of the L2PcInstance.
  6481. */
  6482. public int getHennaEmptySlots()
  6483. {
  6484. int totalSlots = 0;
  6485. if (getClassId().level() == 1)
  6486. totalSlots = 2;
  6487. else
  6488. totalSlots = 3;
  6489.  
  6490. for (int i = 0; i < 3; i++)
  6491. {
  6492. if (_henna[i] != null)
  6493. totalSlots--;
  6494. }
  6495.  
  6496. if (totalSlots <= 0)
  6497. return 0;
  6498.  
  6499. return totalSlots;
  6500. }
  6501.  
  6502. /**
  6503. * Remove a Henna of the L2PcInstance, save update in the character_hennas table of the database and send HennaInfo/UserInfo packet to this L2PcInstance.
  6504. * @param slot The slot number to make checks on.
  6505. * @return true if successful.
  6506. */
  6507. public boolean removeHenna(int slot)
  6508. {
  6509. if (slot < 1 || slot > 3)
  6510. return false;
  6511.  
  6512. slot--;
  6513.  
  6514. if (_henna[slot] == null)
  6515. return false;
  6516.  
  6517. Henna henna = _henna[slot];
  6518. _henna[slot] = null;
  6519.  
  6520. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6521. {
  6522. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNA);
  6523.  
  6524. statement.setInt(1, getObjectId());
  6525. statement.setInt(2, slot + 1);
  6526. statement.setInt(3, getClassIndex());
  6527.  
  6528. statement.execute();
  6529. statement.close();
  6530. }
  6531. catch (Exception e)
  6532. {
  6533. _log.warning("could not remove char henna: " + e);
  6534. }
  6535.  
  6536. // Calculate Henna modifiers of this L2PcInstance
  6537. recalcHennaStats();
  6538.  
  6539. // Send HennaInfo packet to this L2PcInstance
  6540. sendPacket(new HennaInfo(this));
  6541.  
  6542. // Send UserInfo packet to this L2PcInstance
  6543. sendPacket(new UserInfo(this));
  6544.  
  6545. reduceAdena("Henna", henna.getPrice() / 5, this, false);
  6546.  
  6547. // Add the recovered dyes to the player's inventory and notify them.
  6548. addItem("Henna", henna.getDyeId(), Henna.getAmountDyeRequire() / 2, this, true);
  6549. sendPacket(SystemMessageId.SYMBOL_DELETED);
  6550. return true;
  6551. }
  6552.  
  6553. /**
  6554. * Add a Henna to the L2PcInstance, save update in the character_hennas table of the database and send Server->Client HennaInfo/UserInfo packet to this L2PcInstance.
  6555. * @param henna The Henna template to add.
  6556. */
  6557. public void addHenna(Henna henna)
  6558. {
  6559. for (int i = 0; i < 3; i++)
  6560. {
  6561. if (_henna[i] == null)
  6562. {
  6563. _henna[i] = henna;
  6564.  
  6565. // Calculate Henna modifiers of this L2PcInstance
  6566. recalcHennaStats();
  6567.  
  6568. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  6569. {
  6570. PreparedStatement statement = con.prepareStatement(ADD_CHAR_HENNA);
  6571.  
  6572. statement.setInt(1, getObjectId());
  6573. statement.setInt(2, henna.getSymbolId());
  6574. statement.setInt(3, i + 1);
  6575. statement.setInt(4, getClassIndex());
  6576.  
  6577. statement.execute();
  6578. statement.close();
  6579. }
  6580. catch (Exception e)
  6581. {
  6582. _log.warning("could not save char henna: " + e);
  6583. }
  6584.  
  6585. sendPacket(new HennaInfo(this));
  6586. sendPacket(new UserInfo(this));
  6587. sendPacket(SystemMessageId.SYMBOL_ADDED);
  6588. return;
  6589. }
  6590. }
  6591. }
  6592.  
  6593. /**
  6594. * Calculate Henna modifiers of this L2PcInstance.
  6595. */
  6596. private void recalcHennaStats()
  6597. {
  6598. _hennaINT = 0;
  6599. _hennaSTR = 0;
  6600. _hennaCON = 0;
  6601. _hennaMEN = 0;
  6602. _hennaWIT = 0;
  6603. _hennaDEX = 0;
  6604.  
  6605. for (int i = 0; i < 3; i++)
  6606. {
  6607. if (_henna[i] == null)
  6608. continue;
  6609.  
  6610. _hennaINT += _henna[i].getStatINT();
  6611. _hennaSTR += _henna[i].getStatSTR();
  6612. _hennaMEN += _henna[i].getStatMEN();
  6613. _hennaCON += _henna[i].getStatCON();
  6614. _hennaWIT += _henna[i].getStatWIT();
  6615. _hennaDEX += _henna[i].getStatDEX();
  6616. }
  6617.  
  6618. if (_hennaINT > 5)
  6619. _hennaINT = 5;
  6620.  
  6621. if (_hennaSTR > 5)
  6622. _hennaSTR = 5;
  6623.  
  6624. if (_hennaMEN > 5)
  6625. _hennaMEN = 5;
  6626.  
  6627. if (_hennaCON > 5)
  6628. _hennaCON = 5;
  6629.  
  6630. if (_hennaWIT > 5)
  6631. _hennaWIT = 5;
  6632.  
  6633. if (_hennaDEX > 5)
  6634. _hennaDEX = 5;
  6635. }
  6636.  
  6637. /**
  6638. * @param slot A slot to check.
  6639. * @return the Henna of this L2PcInstance corresponding to the selected slot.
  6640. */
  6641. public Henna getHenna(int slot)
  6642. {
  6643. if (slot < 1 || slot > 3)
  6644. return null;
  6645.  
  6646. return _henna[slot - 1];
  6647. }
  6648.  
  6649. public int getHennaStatINT()
  6650. {
  6651. return _hennaINT;
  6652. }
  6653.  
  6654. public int getHennaStatSTR()
  6655. {
  6656. return _hennaSTR;
  6657. }
  6658.  
  6659. public int getHennaStatCON()
  6660. {
  6661. return _hennaCON;
  6662. }
  6663.  
  6664. public int getHennaStatMEN()
  6665. {
  6666. return _hennaMEN;
  6667. }
  6668.  
  6669. public int getHennaStatWIT()
  6670. {
  6671. return _hennaWIT;
  6672. }
  6673.  
  6674. public int getHennaStatDEX()
  6675. {
  6676. return _hennaDEX;
  6677. }
  6678.  
  6679. /**
  6680. * Return True if the L2PcInstance is autoAttackable.
  6681. * <ul>
  6682. * <li>Check if the attacker isn't the L2PcInstance Pet</li>
  6683. * <li>Check if the attacker is L2MonsterInstance</li>
  6684. * <li>If the attacker is a L2PcInstance, check if it is not in the same party</li>
  6685. * <li>Check if the L2PcInstance has Karma</li>
  6686. * <li>If the attacker is a L2PcInstance, check if it is not in the same siege clan (Attacker, Defender)</li>
  6687. * </ul>
  6688. */
  6689. @Override
  6690. public boolean isAutoAttackable(L2Character attacker)
  6691. {
  6692. // Check if the attacker isn't the L2PcInstance Pet
  6693. if (attacker == this || attacker == getPet())
  6694. return false;
  6695.  
  6696. // Check if the attacker is a L2MonsterInstance
  6697. if (attacker instanceof L2MonsterInstance)
  6698. return true;
  6699.  
  6700. // Check if the attacker is not in the same party
  6701. if (getParty() != null && getParty().getPartyMembers().contains(attacker))
  6702. return false;
  6703.  
  6704. // Check if the attacker is a L2Playable
  6705. if (attacker instanceof L2Playable)
  6706. {
  6707. if (isInsideZone(ZoneId.PEACE))
  6708. return false;
  6709.  
  6710. // Get L2PcInstance
  6711. final L2PcInstance cha = attacker.getActingPlayer();
  6712.  
  6713. // Check if the attacker is in olympiad and olympiad start
  6714. if (attacker instanceof L2PcInstance && cha.isInOlympiadMode())
  6715. {
  6716. if (isInOlympiadMode() && isOlympiadStart() && cha.getOlympiadGameId() == getOlympiadGameId())
  6717. return true;
  6718.  
  6719. return false;
  6720. }
  6721.  
  6722. // is AutoAttackable if both players are in the same duel and the duel is still going on
  6723. if (getDuelState() == DuelState.DUELLING && getDuelId() == cha.getDuelId())
  6724. return true;
  6725.  
  6726. if (getClan() != null)
  6727. {
  6728. final Siege siege = SiegeManager.getSiege(getX(), getY(), getZ());
  6729. if (siege != null)
  6730. {
  6731. // Check if a siege is in progress and if attacker and the L2PcInstance aren't in the Defender clan
  6732. if (siege.checkIsDefender(cha.getClan()) && siege.checkIsDefender(getClan()))
  6733. return false;
  6734.  
  6735. // Check if a siege is in progress and if attacker and the L2PcInstance aren't in the Attacker clan
  6736. if (siege.checkIsAttacker(cha.getClan()) && siege.checkIsAttacker(getClan()))
  6737. return false;
  6738. }
  6739.  
  6740. // Check if clan is at war
  6741. if (getClan().isAtWarWith(cha.getClanId()) && !wantsPeace() && !cha.wantsPeace() && !isAcademyMember())
  6742. return true;
  6743. }
  6744.  
  6745. // Check if the L2PcInstance is in an arena.
  6746. if (isInArena() && attacker.isInArena())
  6747. return true;
  6748.  
  6749. // Check if the attacker is not in the same ally.
  6750. if (getAllyId() != 0 && getAllyId() == cha.getAllyId())
  6751. return false;
  6752.  
  6753. // RnP (cia bbz kam 7 kaskas su attackers)
  6754. // Check if the attacker is in TvT and TvT is started
  6755. if (TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  6756. return true;
  6757.  
  6758. // Check if the attacker is in DM and DM is started
  6759. if (DMEvent.isStarted() && DMEvent.isPlayerParticipant(getObjectId()))
  6760. return true;
  6761.  
  6762. // Check if the attacker is not in the same clan.
  6763. if (getClan() != null && getClan().isMember(cha.getObjectId()))
  6764. return false;
  6765.  
  6766. // Now check again if the L2PcInstance is in pvp zone (as arenas check was made before, it ends with sieges).
  6767. if (isInsideZone(ZoneId.PVP) && attacker.isInsideZone(ZoneId.PVP))
  6768. return true;
  6769. }
  6770. else if (attacker instanceof L2SiegeGuardInstance)
  6771. {
  6772. if (getClan() != null)
  6773. {
  6774. final Siege siege = SiegeManager.getSiege(this);
  6775. return (siege != null && siege.checkIsAttacker(getClan()));
  6776. }
  6777. }
  6778.  
  6779. // Check if the L2PcInstance has Karma
  6780. if (getKarma() > 0 || getPvpFlag() > 0)
  6781. return true;
  6782.  
  6783. return false;
  6784. }
  6785.  
  6786. /**
  6787. * Check if the active L2Skill can be casted.
  6788. * <ul>
  6789. * <li>Check if the skill isn't toggle and is offensive</li>
  6790. * <li>Check if the target is in the skill cast range</li>
  6791. * <li>Check if the skill is Spoil type and if the target isn't already spoiled</li>
  6792. * <li>Check if the caster owns enought consummed Item, enough HP and MP to cast the skill</li>
  6793. * <li>Check if the caster isn't sitting</li>
  6794. * <li>Check if all skills are enabled and this skill is enabled</li>
  6795. * <li>Check if the caster own the weapon needed</li>
  6796. * <li>Check if the skill is active</li>
  6797. * <li>Check if all casting conditions are completed</li>
  6798. * <li>Notify the AI with CAST and target</li>
  6799. * </ul>
  6800. * @param skill The L2Skill to use
  6801. * @param forceUse used to force ATTACK on players
  6802. * @param dontMove used to prevent movement, if not in range
  6803. */
  6804. @Override
  6805. public boolean useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
  6806. {
  6807. // Check if the skill is active
  6808. if (skill.isPassive())
  6809. {
  6810. sendPacket(ActionFailed.STATIC_PACKET);
  6811. return false;
  6812. }
  6813.  
  6814. // Cancels the use of skills when player uses a cursed weapon or is flying.
  6815. if ((isCursedWeaponEquipped() && !skill.isDemonicSkill()) // If CW, allow ONLY demonic skills.
  6816. || (getMountType() == 1 && !skill.isStriderSkill()) // If mounted, allow ONLY Strider skills.
  6817. || (getMountType() == 2 && !skill.isFlyingSkill())) // If flying, allow ONLY Wyvern skills.
  6818. {
  6819. sendPacket(ActionFailed.STATIC_PACKET);
  6820. return false;
  6821. }
  6822.  
  6823. // Players wearing Formal Wear cannot use skills.
  6824. final ItemInstance formal = getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  6825. if (formal != null && formal.getItem().getBodyPart() == Item.SLOT_ALLDRESS)
  6826. {
  6827. sendPacket(SystemMessageId.CANNOT_USE_ITEMS_SKILLS_WITH_FORMALWEAR);
  6828. sendPacket(ActionFailed.STATIC_PACKET);
  6829. return false;
  6830. }
  6831.  
  6832. // ************************************* Check Casting in Progress *******************************************
  6833.  
  6834. // If a skill is currently being used, queue this one if this is not the same
  6835. if (isCastingNow())
  6836. {
  6837. // Check if new skill different from current skill in progress ; queue it in the player _queuedSkill
  6838. if (_currentSkill.getSkill() != null && skill.getId() != _currentSkill.getSkillId())
  6839. setQueuedSkill(skill, forceUse, dontMove);
  6840.  
  6841. sendPacket(ActionFailed.STATIC_PACKET);
  6842. return false;
  6843. }
  6844.  
  6845. setIsCastingNow(true);
  6846.  
  6847. // Set the player _currentSkill.
  6848. setCurrentSkill(skill, forceUse, dontMove);
  6849.  
  6850. // Wipe queued skill.
  6851. if (_queuedSkill.getSkill() != null)
  6852. setQueuedSkill(null, false, false);
  6853.  
  6854. if (!checkUseMagicConditions(skill, forceUse, dontMove))
  6855. {
  6856. setIsCastingNow(false);
  6857. return false;
  6858. }
  6859.  
  6860. // Check if the target is correct and Notify the AI with CAST and target
  6861. L2Object target = null;
  6862.  
  6863. switch (skill.getTargetType())
  6864. {
  6865. case TARGET_AURA:
  6866. case TARGET_FRONT_AURA:
  6867. case TARGET_BEHIND_AURA:
  6868. case TARGET_GROUND:
  6869. case TARGET_SELF:
  6870. case TARGET_CORPSE_ALLY:
  6871. case TARGET_AURA_UNDEAD:
  6872. target = this;
  6873. break;
  6874.  
  6875. default: // Get the first target of the list
  6876. target = skill.getFirstOfTargetList(this);
  6877. break;
  6878. }
  6879.  
  6880. // Notify the AI with CAST and target
  6881. getAI().setIntention(CtrlIntention.CAST, skill, target);
  6882. return true;
  6883. }
  6884.  
  6885. private boolean checkUseMagicConditions(L2Skill skill, boolean forceUse, boolean dontMove)
  6886. {
  6887. // ************************************* Check Player State *******************************************
  6888.  
  6889. // Check if the player is dead or out of control.
  6890. if (isDead() || isOutOfControl())
  6891. {
  6892. sendPacket(ActionFailed.STATIC_PACKET);
  6893. return false;
  6894. }
  6895.  
  6896. L2SkillType sklType = skill.getSkillType();
  6897.  
  6898. if (isFishing() && (sklType != L2SkillType.PUMPING && sklType != L2SkillType.REELING && sklType != L2SkillType.FISHING))
  6899. {
  6900. // Only fishing skills are available
  6901. sendPacket(SystemMessageId.ONLY_FISHING_SKILLS_NOW);
  6902. return false;
  6903. }
  6904.  
  6905. if (inObserverMode())
  6906. {
  6907. sendPacket(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE);
  6908. abortCast();
  6909. sendPacket(ActionFailed.STATIC_PACKET);
  6910. return false;
  6911. }
  6912.  
  6913. // Check if the caster is sitted. Toggle skills can be only removed, not activated.
  6914. if (isSitting())
  6915. {
  6916. if (skill.isToggle())
  6917. {
  6918. // Get effects of the skill
  6919. L2Effect effect = getFirstEffect(skill.getId());
  6920. if (effect != null)
  6921. {
  6922. effect.exit();
  6923.  
  6924. // Send ActionFailed to the L2PcInstance
  6925. sendPacket(ActionFailed.STATIC_PACKET);
  6926. return false;
  6927. }
  6928. }
  6929.  
  6930. // Send a System Message to the caster
  6931. sendPacket(SystemMessageId.CANT_MOVE_SITTING);
  6932.  
  6933. // Send ActionFailed to the L2PcInstance
  6934. sendPacket(ActionFailed.STATIC_PACKET);
  6935. return false;
  6936. }
  6937.  
  6938. // Check if the skill type is TOGGLE
  6939. if (skill.isToggle())
  6940. {
  6941. // Get effects of the skill
  6942. L2Effect effect = getFirstEffect(skill.getId());
  6943.  
  6944. if (effect != null)
  6945. {
  6946. // If the toggle is different of FakeDeath, you can de-activate it clicking on it.
  6947. if (skill.getId() != 60)
  6948. effect.exit();
  6949.  
  6950. // Send ActionFailed to the L2PcInstance
  6951. sendPacket(ActionFailed.STATIC_PACKET);
  6952. return false;
  6953. }
  6954. }
  6955.  
  6956. // Check if the player uses "Fake Death" skill
  6957. if (isFakeDeath())
  6958. {
  6959. // Send ActionFailed to the L2PcInstance
  6960. sendPacket(ActionFailed.STATIC_PACKET);
  6961. return false;
  6962. }
  6963.  
  6964. // ************************************* Check Target *******************************************
  6965. // Create and set a L2Object containing the target of the skill
  6966. L2Object target = null;
  6967. SkillTargetType sklTargetType = skill.getTargetType();
  6968. Location worldPosition = getCurrentSkillWorldPosition();
  6969.  
  6970. if (sklTargetType == SkillTargetType.TARGET_GROUND && worldPosition == null)
  6971. {
  6972. _log.info("WorldPosition is null for skill: " + skill.getName() + ", player: " + getName() + ".");
  6973. sendPacket(ActionFailed.STATIC_PACKET);
  6974. return false;
  6975. }
  6976.  
  6977. switch (sklTargetType)
  6978. {
  6979. // Target the player if skill type is AURA, PARTY, CLAN or SELF
  6980. case TARGET_AURA:
  6981. case TARGET_FRONT_AURA:
  6982. case TARGET_BEHIND_AURA:
  6983. case TARGET_AURA_UNDEAD:
  6984. case TARGET_PARTY:
  6985. case TARGET_ALLY:
  6986. case TARGET_CLAN:
  6987. case TARGET_GROUND:
  6988. case TARGET_SELF:
  6989. case TARGET_CORPSE_ALLY:
  6990. case TARGET_AREA_SUMMON:
  6991. target = this;
  6992. break;
  6993. case TARGET_PET:
  6994. case TARGET_SUMMON:
  6995. target = getPet();
  6996. break;
  6997. default:
  6998. target = getTarget();
  6999. break;
  7000. }
  7001.  
  7002. // Check the validity of the target
  7003. if (target == null)
  7004. {
  7005. sendPacket(ActionFailed.STATIC_PACKET);
  7006. return false;
  7007. }
  7008.  
  7009. if (target instanceof L2DoorInstance)
  7010. {
  7011. if (!((L2DoorInstance) target).isAutoAttackable(this) // Siege doors only hittable during siege
  7012. || (((L2DoorInstance) target).isUnlockable() && skill.getSkillType() != L2SkillType.UNLOCK)) // unlockable doors
  7013. {
  7014. sendPacket(SystemMessageId.INCORRECT_TARGET);
  7015. sendPacket(ActionFailed.STATIC_PACKET);
  7016. return false;
  7017. }
  7018. }
  7019.  
  7020. // Are the target and the player in the same duel?
  7021. if (isInDuel())
  7022. {
  7023. if (target instanceof L2Playable)
  7024. {
  7025. // Get L2PcInstance
  7026. L2PcInstance cha = target.getActingPlayer();
  7027. if (cha.getDuelId() != getDuelId())
  7028. {
  7029. sendPacket(SystemMessageId.INCORRECT_TARGET);
  7030. sendPacket(ActionFailed.STATIC_PACKET);
  7031. return false;
  7032. }
  7033. }
  7034. }
  7035.  
  7036. // ************************************* Check skill availability *******************************************
  7037.  
  7038. // Siege summon checks. Both checks send a message to the player if it return false.
  7039. if (skill.isSiegeSummonSkill() && (!SiegeManager.checkIfOkToSummon(this) || !SevenSigns.getInstance().checkSummonConditions(this)))
  7040. return false;
  7041.  
  7042. // Check if this skill is enabled (ex : reuse time)
  7043. if (isSkillDisabled(skill))
  7044. {
  7045. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE).addSkillName(skill));
  7046. return false;
  7047. }
  7048.  
  7049. // ************************************* Check casting conditions *******************************************
  7050.  
  7051. // Check if all casting conditions are completed
  7052. if (!skill.checkCondition(this, target, false))
  7053. {
  7054. // Send ActionFailed to the L2PcInstance
  7055. sendPacket(ActionFailed.STATIC_PACKET);
  7056. return false;
  7057. }
  7058.  
  7059. // ************************************* Check Skill Type *******************************************
  7060.  
  7061. // Check if this is offensive magic skill
  7062. if (skill.isOffensive())
  7063. {
  7064. if (isInsidePeaceZone(this, target))
  7065. {
  7066. // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE ActionFailed
  7067. sendPacket(SystemMessageId.TARGET_IN_PEACEZONE);
  7068. sendPacket(ActionFailed.STATIC_PACKET);
  7069. return false;
  7070. }
  7071.  
  7072. if (isInOlympiadMode() && !isOlympiadStart())
  7073. {
  7074. // if L2PcInstance is in Olympia and the match isn't already start, send ActionFailed
  7075. sendPacket(ActionFailed.STATIC_PACKET);
  7076. return false;
  7077. }
  7078.  
  7079. // Check if the target is attackable
  7080. if (!target.isAttackable() && !getAccessLevel().allowPeaceAttack())
  7081. {
  7082. // If target is not attackable, send ActionFailed
  7083. sendPacket(ActionFailed.STATIC_PACKET);
  7084. return false;
  7085. }
  7086. // RnP (cia 8 del tvt)
  7087. // Check if a Forced ATTACK is in progress on non-attackable target
  7088. if (!target.isAutoAttackable(this) && !forceUse && !(TvTEvent.isStarted()))
  7089. {
  7090. switch (sklTargetType)
  7091. {
  7092. case TARGET_AURA:
  7093. case TARGET_FRONT_AURA:
  7094. case TARGET_BEHIND_AURA:
  7095. case TARGET_AURA_UNDEAD:
  7096. case TARGET_CLAN:
  7097. case TARGET_ALLY:
  7098. case TARGET_PARTY:
  7099. case TARGET_SELF:
  7100. case TARGET_GROUND:
  7101. case TARGET_CORPSE_ALLY:
  7102. case TARGET_AREA_SUMMON:
  7103. break;
  7104. default: // Send ActionFailed to the L2PcInstance
  7105. sendPacket(ActionFailed.STATIC_PACKET);
  7106. return false;
  7107. }
  7108. }
  7109.  
  7110. // Check if the target is in the skill cast range
  7111. if (dontMove)
  7112. {
  7113. // Calculate the distance between the L2PcInstance and the target
  7114. if (sklTargetType == SkillTargetType.TARGET_GROUND)
  7115. {
  7116. if (!isInsideRadius(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), (int) (skill.getCastRange() + getCollisionRadius()), false, false))
  7117. {
  7118. // Send a System Message to the caster
  7119. sendPacket(SystemMessageId.TARGET_TOO_FAR);
  7120.  
  7121. // Send ActionFailed to the L2PcInstance
  7122. sendPacket(ActionFailed.STATIC_PACKET);
  7123. return false;
  7124. }
  7125. }
  7126. else if (skill.getCastRange() > 0 && !isInsideRadius(target, (int) (skill.getCastRange() + getCollisionRadius()), false, false))
  7127. {
  7128. // Send a System Message to the caster
  7129. sendPacket(SystemMessageId.TARGET_TOO_FAR);
  7130.  
  7131. // Send ActionFailed to the L2PcInstance
  7132. sendPacket(ActionFailed.STATIC_PACKET);
  7133. return false;
  7134. }
  7135. }
  7136. }
  7137.  
  7138. // Check if the skill is defensive
  7139. if (!skill.isOffensive() && target instanceof L2MonsterInstance && !forceUse)
  7140. {
  7141. // check if the target is a monster and if force attack is set.. if not then we don't want to cast.
  7142. switch (sklTargetType)
  7143. {
  7144. case TARGET_PET:
  7145. case TARGET_SUMMON:
  7146. case TARGET_AURA:
  7147. case TARGET_FRONT_AURA:
  7148. case TARGET_BEHIND_AURA:
  7149. case TARGET_AURA_UNDEAD:
  7150. case TARGET_CLAN:
  7151. case TARGET_SELF:
  7152. case TARGET_CORPSE_ALLY:
  7153. case TARGET_PARTY:
  7154. case TARGET_ALLY:
  7155. case TARGET_CORPSE_MOB:
  7156. case TARGET_AREA_CORPSE_MOB:
  7157. case TARGET_GROUND:
  7158. break;
  7159. default:
  7160. {
  7161. switch (sklType)
  7162. {
  7163. case BEAST_FEED:
  7164. case DELUXE_KEY_UNLOCK:
  7165. case UNLOCK:
  7166. break;
  7167. default:
  7168. sendPacket(ActionFailed.STATIC_PACKET);
  7169. return false;
  7170. }
  7171. break;
  7172. }
  7173. }
  7174. }
  7175.  
  7176. // Check if the skill is Spoil type and if the target isn't already spoiled
  7177. if (sklType == L2SkillType.SPOIL)
  7178. {
  7179. if (!(target instanceof L2MonsterInstance))
  7180. {
  7181. // Send a System Message to the L2PcInstance
  7182. sendPacket(SystemMessageId.INCORRECT_TARGET);
  7183.  
  7184. // Send ActionFailed to the L2PcInstance
  7185. sendPacket(ActionFailed.STATIC_PACKET);
  7186. return false;
  7187. }
  7188. }
  7189.  
  7190. // Check if the skill is Sweep type and if conditions not apply
  7191. if (sklType == L2SkillType.SWEEP && target instanceof L2Attackable)
  7192. {
  7193. if (((L2Attackable) target).isDead())
  7194. {
  7195. final int spoilerId = ((L2Attackable) target).getSpoilerId();
  7196. if (spoilerId == 0)
  7197. {
  7198. // Send a System Message to the L2PcInstance
  7199. sendPacket(SystemMessageId.SWEEPER_FAILED_TARGET_NOT_SPOILED);
  7200.  
  7201. // Send ActionFailed to the L2PcInstance
  7202. sendPacket(ActionFailed.STATIC_PACKET);
  7203. return false;
  7204. }
  7205.  
  7206. if (!isLooterOrInLooterParty(spoilerId))
  7207. {
  7208. // Send a System Message to the L2PcInstance
  7209. sendPacket(SystemMessageId.SWEEP_NOT_ALLOWED);
  7210.  
  7211. // Send ActionFailed to the L2PcInstance
  7212. sendPacket(ActionFailed.STATIC_PACKET);
  7213. return false;
  7214. }
  7215. }
  7216. }
  7217.  
  7218. // Check if the skill is Drain Soul (Soul Crystals) and if the target is a MOB
  7219. if (sklType == L2SkillType.DRAIN_SOUL)
  7220. {
  7221. if (!(target instanceof L2MonsterInstance))
  7222. {
  7223. // Send a System Message to the L2PcInstance
  7224. sendPacket(SystemMessageId.INCORRECT_TARGET);
  7225.  
  7226. // Send ActionFailed to the L2PcInstance
  7227. sendPacket(ActionFailed.STATIC_PACKET);
  7228. return false;
  7229. }
  7230. }
  7231.  
  7232. // Check if this is a Pvp skill and target isn't a non-flagged/non-karma player
  7233. switch (sklTargetType)
  7234. {
  7235. case TARGET_PARTY:
  7236. case TARGET_ALLY: // For such skills, checkPvpSkill() is called from L2Skill.getTargetList()
  7237. case TARGET_CLAN: // For such skills, checkPvpSkill() is called from L2Skill.getTargetList()
  7238. case TARGET_AURA:
  7239. case TARGET_FRONT_AURA:
  7240. case TARGET_BEHIND_AURA:
  7241. case TARGET_AURA_UNDEAD:
  7242. case TARGET_GROUND:
  7243. case TARGET_SELF:
  7244. case TARGET_CORPSE_ALLY:
  7245. break;
  7246. default:
  7247. if (!checkPvpSkill(target, skill) && !getAccessLevel().allowPeaceAttack())
  7248. {
  7249. // Send a System Message to the L2PcInstance
  7250. sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  7251.  
  7252. // Send ActionFailed to the L2PcInstance
  7253. sendPacket(ActionFailed.STATIC_PACKET);
  7254. return false;
  7255. }
  7256. }
  7257.  
  7258. if ((sklTargetType == SkillTargetType.TARGET_HOLY && !checkIfOkToCastSealOfRule(CastleManager.getInstance().getCastle(this), false, skill, target)) || (sklType == L2SkillType.SIEGEFLAG && !L2SkillSiegeFlag.checkIfOkToPlaceFlag(this, false)) || (sklType == L2SkillType.STRSIEGEASSAULT && !checkIfOkToUseStriderSiegeAssault(skill)) || (sklType == L2SkillType.SUMMON_FRIEND && !(checkSummonerStatus(this) && checkSummonTargetStatus(target, this))))
  7259. {
  7260. sendPacket(ActionFailed.STATIC_PACKET);
  7261. abortCast();
  7262. return false;
  7263. }
  7264.  
  7265. // GeoData Los Check here
  7266. if (skill.getCastRange() > 0)
  7267. {
  7268. if (sklTargetType == SkillTargetType.TARGET_GROUND)
  7269. {
  7270. if (!GeoEngine.getInstance().canSeeTarget(this, worldPosition))
  7271. {
  7272. sendPacket(SystemMessageId.CANT_SEE_TARGET);
  7273. sendPacket(ActionFailed.STATIC_PACKET);
  7274. return false;
  7275. }
  7276. }
  7277. else if (!GeoEngine.getInstance().canSeeTarget(this, target))
  7278. {
  7279. sendPacket(SystemMessageId.CANT_SEE_TARGET);
  7280. sendPacket(ActionFailed.STATIC_PACKET);
  7281. return false;
  7282. }
  7283. }
  7284. // finally, after passing all conditions
  7285. return true;
  7286. }
  7287.  
  7288. public boolean checkIfOkToUseStriderSiegeAssault(L2Skill skill)
  7289. {
  7290. SystemMessage sm;
  7291. Castle castle = CastleManager.getInstance().getCastle(this);
  7292.  
  7293. if (!isRiding())
  7294. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7295. else if (!(getTarget() instanceof L2DoorInstance))
  7296. sm = SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET);
  7297. else if (castle == null || castle.getCastleId() <= 0)
  7298. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7299. else if (!castle.getSiege().isInProgress() || castle.getSiege().getAttackerClan(getClan()) == null)
  7300. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7301. else
  7302. return true;
  7303.  
  7304. sendPacket(sm);
  7305. return false;
  7306. }
  7307.  
  7308. public boolean checkIfOkToCastSealOfRule(Castle castle, boolean isCheckOnly, L2Skill skill, L2Object target)
  7309. {
  7310. SystemMessage sm;
  7311.  
  7312. if (castle == null || castle.getCastleId() <= 0)
  7313. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7314. else if (!castle.getArtefacts().contains(target))
  7315. sm = SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET);
  7316. else if (!castle.getSiege().isInProgress())
  7317. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7318. else if (!Util.checkIfInRange(200, this, target, true))
  7319. sm = SystemMessage.getSystemMessage(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED);
  7320. else if (!isInsideZone(ZoneId.CAST_ON_ARTIFACT))
  7321. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7322. else if (castle.getSiege().getAttackerClan(getClan()) == null)
  7323. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
  7324. else
  7325. {
  7326. if (!isCheckOnly)
  7327. {
  7328. sm = SystemMessage.getSystemMessage(SystemMessageId.OPPONENT_STARTED_ENGRAVING);
  7329. castle.getSiege().announceToPlayer(sm, false);
  7330. }
  7331. return true;
  7332. }
  7333. sendPacket(sm);
  7334. return false;
  7335. }
  7336.  
  7337. /**
  7338. * @param objectId : The looter object to make checks on.
  7339. * @return true if the active player is the looter or in the same party or command channel than looter objectId.
  7340. */
  7341. public boolean isLooterOrInLooterParty(int objectId)
  7342. {
  7343. if (objectId == getObjectId())
  7344. return true;
  7345.  
  7346. final L2PcInstance looter = L2World.getInstance().getPlayer(objectId);
  7347. if (looter == null)
  7348. return false;
  7349.  
  7350. final L2Party party = getParty();
  7351. if (party == null)
  7352. return false;
  7353.  
  7354. if (party.isInCommandChannel())
  7355. return party.getCommandChannel().getMembers().contains(looter);
  7356.  
  7357. return party.getPartyMembers().contains(looter);
  7358. }
  7359.  
  7360. /**
  7361. * Check if the requested casting is a Pc->Pc skill cast and if it's a valid pvp condition
  7362. * @param target L2Object instance containing the target
  7363. * @param skill L2Skill instance with the skill being casted
  7364. * @return {@code false} if the skill is a pvpSkill and target is not a valid pvp target, {@code true} otherwise.
  7365. */
  7366. public boolean checkPvpSkill(L2Object target, L2Skill skill)
  7367. {
  7368. if (skill == null || target == null)
  7369. return false;
  7370.  
  7371. if (!(target instanceof L2Playable))
  7372. return true;
  7373.  
  7374. if (skill.isDebuff() || skill.isOffensive())
  7375. {
  7376. final L2PcInstance targetPlayer = target.getActingPlayer();
  7377. if (targetPlayer == null || this == target)
  7378. return false;
  7379. // RnP (tvt cia paziuri skilus 9)
  7380. if ((TvTEvent.isStarting() && TvTEvent.isStarted()))
  7381. return true;
  7382.  
  7383. // Peace Zone
  7384. if (target.isInsideZone(ZoneId.PEACE))
  7385. return false;
  7386.  
  7387. // Duel
  7388. if (isInDuel() && targetPlayer.isInDuel() && getDuelId() == targetPlayer.getDuelId())
  7389. return true;
  7390.  
  7391. final boolean isCtrlPressed = getCurrentSkill() != null && getCurrentSkill().isCtrlPressed();
  7392.  
  7393. // Party
  7394. if (isInParty() && targetPlayer.isInParty())
  7395. {
  7396. // Same Party
  7397. if (getParty().getLeader() == targetPlayer.getParty().getLeader())
  7398. {
  7399. if (skill.getEffectRange() > 0 && isCtrlPressed && getTarget() == target && skill.isDamage())
  7400. return true;
  7401.  
  7402. return false;
  7403. }
  7404. else if (getParty().getCommandChannel() != null && getParty().getCommandChannel().containsPlayer(targetPlayer))
  7405. {
  7406. if (skill.getEffectRange() > 0 && isCtrlPressed && getTarget() == target && skill.isDamage())
  7407. return true;
  7408.  
  7409. return false;
  7410. }
  7411. }
  7412.  
  7413. // You can debuff anyone except party members while in an arena...
  7414. if (isInsideZone(ZoneId.PVP) && targetPlayer.isInsideZone(ZoneId.PVP))
  7415. return true;
  7416.  
  7417. // Olympiad
  7418. if (isInOlympiadMode() && targetPlayer.isInOlympiadMode() && getOlympiadGameId() == targetPlayer.getOlympiadGameId())
  7419. return true;
  7420.  
  7421. final L2Clan aClan = getClan();
  7422. final L2Clan tClan = targetPlayer.getClan();
  7423.  
  7424. if (aClan != null && tClan != null)
  7425. {
  7426. if (aClan.isAtWarWith(tClan.getClanId()) && tClan.isAtWarWith(aClan.getClanId()))
  7427. {
  7428. // Check if skill can do dmg
  7429. if (skill.getEffectRange() > 0 && isCtrlPressed && getTarget() == target && skill.isAOE())
  7430. return true;
  7431.  
  7432. return isCtrlPressed;
  7433. }
  7434. else if (getClanId() == targetPlayer.getClanId() || (getAllyId() > 0 && getAllyId() == targetPlayer.getAllyId()))
  7435. {
  7436. // Check if skill can do dmg
  7437. if (skill.getEffectRange() > 0 && isCtrlPressed && getTarget() == target && skill.isDamage())
  7438. return true;
  7439.  
  7440. return false;
  7441. }
  7442. }
  7443.  
  7444. // On retail, it is impossible to debuff a "peaceful" player.
  7445. if (targetPlayer.getPvpFlag() == 0 && targetPlayer.getKarma() == 0)
  7446. {
  7447. // Check if skill can do dmg
  7448. if (skill.getEffectRange() > 0 && isCtrlPressed && getTarget() == target && skill.isDamage())
  7449. return true;
  7450.  
  7451. return false;
  7452. }
  7453.  
  7454. if (targetPlayer.getPvpFlag() > 0 || targetPlayer.getKarma() > 0)
  7455. return true;
  7456.  
  7457. return false;
  7458. }
  7459. return true;
  7460. }
  7461.  
  7462. /**
  7463. * @return True if the L2PcInstance is a Mage (based on class templates).
  7464. */
  7465. public boolean isMageClass()
  7466. {
  7467. return getClassId().getType() != ClassType.FIGHTER;
  7468. }
  7469.  
  7470. public boolean isMounted()
  7471. {
  7472. return _mountType > 0;
  7473. }
  7474.  
  7475. /**
  7476. * This method allows to :
  7477. * <ul>
  7478. * <li>change isRiding/isFlying flags</li>
  7479. * <li>gift player with Wyvern Breath skill if mount is a wyvern</li>
  7480. * <li>send the skillList (faded icons update)</li>
  7481. * </ul>
  7482. * @param npcId the npcId of the mount
  7483. * @param npcLevel The level of the mount
  7484. * @param mountType 0, 1 or 2 (dismount, strider or wyvern).
  7485. * @return always true.
  7486. */
  7487. public boolean setMount(int npcId, int npcLevel, int mountType)
  7488. {
  7489. switch (mountType)
  7490. {
  7491. case 0: // Dismounted
  7492. if (isFlying())
  7493. removeSkill(FrequentSkill.WYVERN_BREATH.getSkill());
  7494. break;
  7495.  
  7496. case 2: // Flying Wyvern
  7497. addSkill(FrequentSkill.WYVERN_BREATH.getSkill(), false); // not saved to DB
  7498. break;
  7499. }
  7500.  
  7501. _mountNpcId = npcId;
  7502. _mountType = mountType;
  7503. _mountLevel = npcLevel;
  7504.  
  7505. sendSkillList(); // Update faded icons && eventual added skills.
  7506. return true;
  7507. }
  7508.  
  7509. @Override
  7510. public boolean isSeated()
  7511. {
  7512. return _throneId > 0;
  7513. }
  7514.  
  7515. @Override
  7516. public boolean isRiding()
  7517. {
  7518. return _mountType == 1;
  7519. }
  7520.  
  7521. @Override
  7522. public boolean isFlying()
  7523. {
  7524. return _mountType == 2;
  7525. }
  7526.  
  7527. /**
  7528. * @return the type of Pet mounted (0 : none, 1 : Strider, 2 : Wyvern).
  7529. */
  7530. public int getMountType()
  7531. {
  7532. return _mountType;
  7533. }
  7534.  
  7535. @Override
  7536. public final void stopAllEffects()
  7537. {
  7538. super.stopAllEffects();
  7539. updateAndBroadcastStatus(2);
  7540. }
  7541.  
  7542. @Override
  7543. public final void stopAllEffectsExceptThoseThatLastThroughDeath()
  7544. {
  7545. super.stopAllEffectsExceptThoseThatLastThroughDeath();
  7546. updateAndBroadcastStatus(2);
  7547. }
  7548.  
  7549. /**
  7550. * Stop all toggle-type effects
  7551. */
  7552. public final void stopAllToggles()
  7553. {
  7554. _effects.stopAllToggles();
  7555. }
  7556.  
  7557. public final void stopCubics()
  7558. {
  7559. if (getCubics() != null)
  7560. {
  7561. boolean removed = false;
  7562. for (L2CubicInstance cubic : getCubics().values())
  7563. {
  7564. cubic.stopAction();
  7565. delCubic(cubic.getId());
  7566. removed = true;
  7567. }
  7568. if (removed)
  7569. broadcastUserInfo();
  7570. }
  7571. }
  7572.  
  7573. public final void stopCubicsByOthers()
  7574. {
  7575. if (getCubics() != null)
  7576. {
  7577. boolean removed = false;
  7578. for (L2CubicInstance cubic : getCubics().values())
  7579. {
  7580. if (cubic.givenByOther())
  7581. {
  7582. cubic.stopAction();
  7583. delCubic(cubic.getId());
  7584. removed = true;
  7585. }
  7586. }
  7587. if (removed)
  7588. broadcastUserInfo();
  7589. }
  7590. }
  7591.  
  7592. /**
  7593. * Send UserInfo to this L2PcInstance and CharInfo to all L2PcInstance in its _KnownPlayers.<BR>
  7594. * <ul>
  7595. * <li>Send UserInfo to this L2PcInstance (Public and Private Data)</li>
  7596. * <li>Send CharInfo to all L2PcInstance in _KnownPlayers of the L2PcInstance (Public data only)</li>
  7597. * </ul>
  7598. * <FONT COLOR=#FF0000><B> <U>Caution</U> : DON'T SEND UserInfo packet to other players instead of CharInfo packet. Indeed, UserInfo packet contains PRIVATE DATA as MaxHP, STR, DEX...</B></FONT><BR>
  7599. * <BR>
  7600. */
  7601. @Override
  7602. public void updateAbnormalEffect()
  7603. {
  7604. broadcastUserInfo();
  7605. }
  7606.  
  7607. /**
  7608. * Disable the Inventory and create a new task to enable it after 1.5s.
  7609. */
  7610. public void tempInventoryDisable()
  7611. {
  7612. _inventoryDisable = true;
  7613.  
  7614. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  7615. {
  7616. @Override
  7617. public void run()
  7618. {
  7619. _inventoryDisable = false;
  7620. }
  7621. }, 1500);
  7622. }
  7623. public void updatePvPColor(int pvpKillAmount)
  7624. {
  7625. // RnP (del PVP)
  7626. if(Config.PVP_COLOR_SYSTEM_ENABLED)
  7627. {
  7628. //Check if the character has GM access and if so, let them be.
  7629. if(isGM())
  7630. return;
  7631.  
  7632. if(pvpKillAmount >= Config.PVP_AMOUNT1 && pvpKillAmount < Config.PVP_AMOUNT2)
  7633. {
  7634. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT1);
  7635. }
  7636. else if(pvpKillAmount >= Config.PVP_AMOUNT2 && pvpKillAmount < Config.PVP_AMOUNT3)
  7637. {
  7638. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT2);
  7639. }
  7640. else if(pvpKillAmount >= Config.PVP_AMOUNT3 && pvpKillAmount < Config.PVP_AMOUNT4)
  7641. {
  7642. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT3);
  7643. }
  7644. else if(pvpKillAmount >= Config.PVP_AMOUNT4 && pvpKillAmount < Config.PVP_AMOUNT5)
  7645. {
  7646. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT4);
  7647. }
  7648. else if(pvpKillAmount >= Config.PVP_AMOUNT5 && pvpKillAmount < Config.PVP_AMOUNT6)
  7649. {
  7650. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT5);
  7651. }
  7652. else if(pvpKillAmount >= Config.PVP_AMOUNT6 && pvpKillAmount < Config.PVP_AMOUNT7)
  7653. {
  7654. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT6);
  7655. }
  7656. else if(pvpKillAmount >= Config.PVP_AMOUNT7)
  7657. {
  7658. getAppearance().setNameColor(Config.NAME_COLOR_FOR_PVP_AMOUNT7);
  7659. }
  7660. }
  7661. }
  7662.  
  7663. /**
  7664. * Update pk color.
  7665. *
  7666. * @param pkKillAmount the pk kill amount
  7667. */
  7668. public void updatePkColor(int pkKillAmount)
  7669. {
  7670. if(Config.PK_COLOR_SYSTEM_ENABLED)
  7671. {
  7672. //Check if the character has GM access and if so, let them be, like above.
  7673. if(isGM())
  7674. return;
  7675.  
  7676. if(pkKillAmount >= Config.PK_AMOUNT1 && pkKillAmount < Config.PK_AMOUNT1)
  7677. {
  7678. getAppearance().setTitleColor(Config.TITLE_COLOR_FOR_PK_AMOUNT1);
  7679. }
  7680. else if(pkKillAmount >= Config.PK_AMOUNT1 && pkKillAmount < Config.PK_AMOUNT2)
  7681. {
  7682. getAppearance().setTitleColor(Config.TITLE_COLOR_FOR_PK_AMOUNT2);
  7683. }
  7684. else if(pkKillAmount >= Config.PK_AMOUNT3 && pkKillAmount < Config.PK_AMOUNT4)
  7685. {
  7686. getAppearance().setTitleColor(Config.TITLE_COLOR_FOR_PK_AMOUNT3);
  7687. }
  7688. else if(pkKillAmount >= Config.PK_AMOUNT4 && pkKillAmount < Config.PK_AMOUNT5)
  7689. {
  7690. getAppearance().setTitleColor(Config.TITLE_COLOR_FOR_PK_AMOUNT4);
  7691. }
  7692. else if(pkKillAmount >= Config.PK_AMOUNT5)
  7693. {
  7694. getAppearance().setTitleColor(Config.TITLE_COLOR_FOR_PK_AMOUNT5);
  7695. }
  7696. }
  7697. }
  7698.  
  7699. /**
  7700. * @return True if the Inventory is disabled.
  7701. */
  7702. public boolean isInventoryDisabled()
  7703. {
  7704. return _inventoryDisable;
  7705. }
  7706.  
  7707. public Map<Integer, L2CubicInstance> getCubics()
  7708. {
  7709. return _cubics;
  7710. }
  7711.  
  7712. /**
  7713. * Add a L2CubicInstance to the L2PcInstance _cubics.
  7714. * @param id
  7715. * @param level
  7716. * @param matk
  7717. * @param activationtime
  7718. * @param activationchance
  7719. * @param totalLifetime
  7720. * @param givenByOther
  7721. */
  7722. public void addCubic(int id, int level, double matk, int activationtime, int activationchance, int totalLifetime, boolean givenByOther)
  7723. {
  7724. _cubics.put(id, new L2CubicInstance(this, id, level, (int) matk, activationtime, activationchance, totalLifetime, givenByOther));
  7725. }
  7726.  
  7727. /**
  7728. * Remove a L2CubicInstance from the L2PcInstance _cubics.
  7729. * @param id
  7730. */
  7731. public void delCubic(int id)
  7732. {
  7733. _cubics.remove(id);
  7734. }
  7735.  
  7736. /**
  7737. * @param id
  7738. * @return the L2CubicInstance corresponding to the Identifier of the L2PcInstance _cubics.
  7739. */
  7740. public L2CubicInstance getCubic(int id)
  7741. {
  7742. return _cubics.get(id);
  7743. }
  7744.  
  7745. @Override
  7746. public String toString()
  7747. {
  7748. return "player " + getName();
  7749. }
  7750.  
  7751. /**
  7752. * @return the modifier corresponding to the Enchant Effect of the Active Weapon (Min : 127).
  7753. */
  7754. public int getEnchantEffect()
  7755. {
  7756. final ItemInstance wpn = getActiveWeaponInstance();
  7757. return (wpn == null) ? 0 : Math.min(127, wpn.getEnchantLevel());
  7758. }
  7759.  
  7760. /**
  7761. * Set the _currentFolkNpc of the player.
  7762. * @param npc
  7763. */
  7764. public void setCurrentFolkNPC(L2Npc npc)
  7765. {
  7766. _currentFolkNpc = npc;
  7767. }
  7768.  
  7769. /**
  7770. * @return the _currentFolkNpc of the player.
  7771. */
  7772. public L2Npc getCurrentFolkNPC()
  7773. {
  7774. return _currentFolkNpc;
  7775. }
  7776.  
  7777. /**
  7778. * @return True if L2PcInstance is a participant in the Festival of Darkness.
  7779. */
  7780. public boolean isFestivalParticipant()
  7781. {
  7782. return SevenSignsFestival.getInstance().isParticipant(this);
  7783. }
  7784.  
  7785. public void addAutoSoulShot(int itemId)
  7786. {
  7787. _activeSoulShots.add(itemId);
  7788. }
  7789.  
  7790. public boolean removeAutoSoulShot(int itemId)
  7791. {
  7792. return _activeSoulShots.remove(itemId);
  7793. }
  7794.  
  7795. public Set<Integer> getAutoSoulShot()
  7796. {
  7797. return _activeSoulShots;
  7798. }
  7799.  
  7800. @Override
  7801. public boolean isChargedShot(ShotType type)
  7802. {
  7803. ItemInstance weapon = getActiveWeaponInstance();
  7804. return weapon != null && weapon.isChargedShot(type);
  7805. }
  7806.  
  7807. @Override
  7808. public void setChargedShot(ShotType type, boolean charged)
  7809. {
  7810. ItemInstance weapon = getActiveWeaponInstance();
  7811. if (weapon != null)
  7812. weapon.setChargedShot(type, charged);
  7813. }
  7814.  
  7815. @Override
  7816. public void rechargeShots(boolean physical, boolean magic)
  7817. {
  7818. if (_activeSoulShots.isEmpty())
  7819. return;
  7820.  
  7821. for (int itemId : _activeSoulShots)
  7822. {
  7823. ItemInstance item = getInventory().getItemByItemId(itemId);
  7824. if (item != null)
  7825. {
  7826. if (magic && item.getItem().getDefaultAction() == ActionType.spiritshot)
  7827. {
  7828. IItemHandler handler = ItemHandler.getInstance().getItemHandler(item.getEtcItem());
  7829. if (handler != null)
  7830. handler.useItem(this, item, false);
  7831. }
  7832.  
  7833. if (physical && item.getItem().getDefaultAction() == ActionType.soulshot)
  7834. {
  7835. IItemHandler handler = ItemHandler.getInstance().getItemHandler(item.getEtcItem());
  7836. if (handler != null)
  7837. handler.useItem(this, item, false);
  7838. }
  7839. }
  7840. else
  7841. removeAutoSoulShot(itemId);
  7842. }
  7843. }
  7844.  
  7845. /**
  7846. * Cancel autoshot use for shot itemId
  7847. * @param itemId int id to disable
  7848. * @return true if canceled.
  7849. */
  7850. public boolean disableAutoShot(int itemId)
  7851. {
  7852. if (_activeSoulShots.contains(itemId))
  7853. {
  7854. removeAutoSoulShot(itemId);
  7855. sendPacket(new ExAutoSoulShot(itemId, 0));
  7856. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED).addItemName(itemId));
  7857. return true;
  7858. }
  7859.  
  7860. return false;
  7861. }
  7862.  
  7863. /**
  7864. * Cancel all autoshots for player
  7865. */
  7866. public void disableAutoShotsAll()
  7867. {
  7868. for (int itemId : _activeSoulShots)
  7869. {
  7870. sendPacket(new ExAutoSoulShot(itemId, 0));
  7871. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED).addItemName(itemId));
  7872. }
  7873. _activeSoulShots.clear();
  7874. }
  7875.  
  7876. class LookingForFishTask implements Runnable
  7877. {
  7878. boolean _isNoob, _isUpperGrade;
  7879. int _fishType, _fishGutsCheck;
  7880. long _endTaskTime;
  7881.  
  7882. protected LookingForFishTask(int fishWaitTime, int fishGutsCheck, int fishType, boolean isNoob, boolean isUpperGrade)
  7883. {
  7884. _fishGutsCheck = fishGutsCheck;
  7885. _endTaskTime = System.currentTimeMillis() + fishWaitTime + 10000;
  7886. _fishType = fishType;
  7887. _isNoob = isNoob;
  7888. _isUpperGrade = isUpperGrade;
  7889. }
  7890.  
  7891. @Override
  7892. public void run()
  7893. {
  7894. if (System.currentTimeMillis() >= _endTaskTime)
  7895. {
  7896. endFishing(false);
  7897. return;
  7898. }
  7899.  
  7900. if (_fishType == -1)
  7901. return;
  7902.  
  7903. int check = Rnd.get(1000);
  7904. if (_fishGutsCheck > check)
  7905. {
  7906. stopLookingForFishTask();
  7907. startFishCombat(_isNoob, _isUpperGrade);
  7908. }
  7909. }
  7910. }
  7911.  
  7912. public int getClanPrivileges()
  7913. {
  7914. return _clanPrivileges;
  7915. }
  7916.  
  7917. public void setClanPrivileges(int n)
  7918. {
  7919. _clanPrivileges = n;
  7920. }
  7921.  
  7922. public int getPledgeClass()
  7923. {
  7924. return _pledgeClass;
  7925. }
  7926.  
  7927. public void setPledgeClass(int classId)
  7928. {
  7929. _pledgeClass = classId;
  7930. }
  7931.  
  7932. public int getPledgeType()
  7933. {
  7934. return _pledgeType;
  7935. }
  7936.  
  7937. public void setPledgeType(int typeId)
  7938. {
  7939. _pledgeType = typeId;
  7940. }
  7941.  
  7942. public int getApprentice()
  7943. {
  7944. return _apprentice;
  7945. }
  7946.  
  7947. public void setApprentice(int id)
  7948. {
  7949. _apprentice = id;
  7950. }
  7951.  
  7952. public int getSponsor()
  7953. {
  7954. return _sponsor;
  7955. }
  7956.  
  7957. public void setSponsor(int id)
  7958. {
  7959. _sponsor = id;
  7960. }
  7961.  
  7962. @Override
  7963. public void sendMessage(String message)
  7964. {
  7965. sendPacket(SystemMessage.sendString(message));
  7966. }
  7967.  
  7968. /**
  7969. * Unsummon all types of summons : pets, cubics, normal summons and trained beasts.
  7970. */
  7971. public void dropAllSummons()
  7972. {
  7973. // Delete summons and pets
  7974. if (getPet() != null)
  7975. getPet().unSummon(this);
  7976.  
  7977. // Delete trained beasts
  7978. if (getTrainedBeast() != null)
  7979. getTrainedBeast().deleteMe();
  7980.  
  7981. // Delete any form of cubics
  7982. stopCubics();
  7983. }
  7984.  
  7985. public void enterObserverMode(int x, int y, int z)
  7986. {
  7987. _savedLocation.set(getX(), getY(), getZ());
  7988. _observerMode = true;
  7989.  
  7990. standUp();
  7991.  
  7992. dropAllSummons();
  7993. setTarget(null);
  7994. setIsParalyzed(true);
  7995. startParalyze();
  7996. setIsInvul(true);
  7997. getAppearance().setInvisible();
  7998.  
  7999. sendPacket(new ObservationMode(x, y, z));
  8000. getKnownList().removeAllKnownObjects(); // reinit knownlist
  8001. setXYZ(x, y, z);
  8002.  
  8003. broadcastUserInfo();
  8004. }
  8005.  
  8006. public void enterOlympiadObserverMode(int id)
  8007. {
  8008. final OlympiadGameTask task = OlympiadGameManager.getInstance().getOlympiadTask(id);
  8009. if (task == null)
  8010. return;
  8011.  
  8012. dropAllSummons();
  8013.  
  8014. if (getParty() != null)
  8015. getParty().removePartyMember(this, MessageType.Expelled);
  8016.  
  8017. _olympiadGameId = id;
  8018.  
  8019. standUp();
  8020.  
  8021. if (!_observerMode)
  8022. _savedLocation.set(getX(), getY(), getZ());
  8023.  
  8024. _observerMode = true;
  8025. setTarget(null);
  8026. setIsInvul(true);
  8027. getAppearance().setInvisible();
  8028. teleToLocation(task.getZone().getSpawns().get(2), 0);
  8029. sendPacket(new ExOlympiadMode(3));
  8030. broadcastUserInfo();
  8031. }
  8032. // RnP (VA POVIS SVARBU DALYKA PAMIRSO 10)
  8033. public void cryptChar()
  8034. {
  8035. if(TvTEvent.getParticipantTeamId(getObjectId()) == 1)
  8036. {
  8037. _originalNameColorTvT = getAppearance().getNameColor();
  8038. getAppearance().setNameColor(0x0000FF);
  8039. }
  8040. else
  8041. {
  8042. _originalNameColorTvT = getAppearance().getNameColor();
  8043. getAppearance().setNameColor(0xFF0000);
  8044. }
  8045. }
  8046.  
  8047. public void decryptChar()
  8048. {
  8049. setTitle(_originalTitle);
  8050. getAppearance().setNameColor(_originalNameColorTvT);
  8051. updatecolorSystem();
  8052. }
  8053.  
  8054. public void leaveObserverMode()
  8055. {
  8056. setTarget(null);
  8057. getKnownList().removeAllKnownObjects(); // reinit knownlist
  8058. setXYZ(_savedLocation.getX(), _savedLocation.getY(), _savedLocation.getZ());
  8059. setIsParalyzed(false);
  8060. stopParalyze(false);
  8061. getAppearance().setVisible();
  8062. setIsInvul(false);
  8063.  
  8064. if (hasAI())
  8065. getAI().setIntention(CtrlIntention.IDLE);
  8066.  
  8067. // prevent receive falling damage
  8068. setFalling();
  8069.  
  8070. _observerMode = false;
  8071. _savedLocation.set(getX(), getY(), getZ());
  8072. sendPacket(new ObservationReturn(_savedLocation));
  8073. broadcastUserInfo();
  8074. }
  8075.  
  8076. public void leaveOlympiadObserverMode()
  8077. {
  8078. if (_olympiadGameId == -1)
  8079. return;
  8080.  
  8081. _olympiadGameId = -1;
  8082. _observerMode = false;
  8083.  
  8084. setTarget(null);
  8085. sendPacket(new ExOlympiadMode(0));
  8086. teleToLocation(_savedLocation, 20);
  8087. getAppearance().setVisible();
  8088. setIsInvul(false);
  8089.  
  8090. if (hasAI())
  8091. getAI().setIntention(CtrlIntention.IDLE);
  8092.  
  8093. _savedLocation.set(getX(), getY(), getZ());
  8094. broadcastUserInfo();
  8095. }
  8096.  
  8097. public int getOlympiadSide()
  8098. {
  8099. return _olympiadSide;
  8100. }
  8101.  
  8102. public void setOlympiadSide(int i)
  8103. {
  8104. _olympiadSide = i;
  8105. }
  8106.  
  8107. public int getOlympiadGameId()
  8108. {
  8109. return _olympiadGameId;
  8110. }
  8111.  
  8112. public void setOlympiadGameId(int id)
  8113. {
  8114. _olympiadGameId = id;
  8115. }
  8116.  
  8117. public Location getSavedLocation()
  8118. {
  8119. return _savedLocation;
  8120. }
  8121.  
  8122. public boolean inObserverMode()
  8123. {
  8124. return _observerMode;
  8125. }
  8126.  
  8127. public int getTeleMode()
  8128. {
  8129. return _teleMode;
  8130. }
  8131.  
  8132. public void setTeleMode(int mode)
  8133. {
  8134. _teleMode = mode;
  8135. }
  8136.  
  8137. public int getLoto(int i)
  8138. {
  8139. return _loto[i];
  8140. }
  8141.  
  8142. public void setLoto(int i, int val)
  8143. {
  8144. _loto[i] = val;
  8145. }
  8146.  
  8147. public int getRace(int i)
  8148. {
  8149. return _race[i];
  8150. }
  8151.  
  8152. public void setRace(int i, int val)
  8153. {
  8154. _race[i] = val;
  8155. }
  8156.  
  8157. public boolean isInRefusalMode()
  8158. {
  8159. return _messageRefusal;
  8160. }
  8161.  
  8162. public void setInRefusalMode(boolean mode)
  8163. {
  8164. _messageRefusal = mode;
  8165. sendPacket(new EtcStatusUpdate(this));
  8166. }
  8167.  
  8168. public void setTradeRefusal(boolean mode)
  8169. {
  8170. _tradeRefusal = mode;
  8171. }
  8172.  
  8173. public boolean getTradeRefusal()
  8174. {
  8175. return _tradeRefusal;
  8176. }
  8177. // RnP (Cia del multi zonos)
  8178. public void setDeathRefusal(boolean mode)
  8179. {
  8180. checkenabled = mode;
  8181. }
  8182. public boolean getDeathRefusal()
  8183. {
  8184. if(DMEvent.isStarted() && DMEvent.isPlayerParticipant(getObjectId()))
  8185. {
  8186. return false;
  8187. }
  8188. return checkenabled;
  8189. }
  8190.  
  8191. public void setExchangeRefusal(boolean mode)
  8192. {
  8193. _exchangeRefusal = mode;
  8194. }
  8195.  
  8196. public boolean getExchangeRefusal()
  8197. {
  8198. return _exchangeRefusal;
  8199. }
  8200.  
  8201. public BlockList getBlockList()
  8202. {
  8203. return _blockList;
  8204. }
  8205.  
  8206. public boolean isHero()
  8207. {
  8208. return _isHero;
  8209. }
  8210.  
  8211. public void setHero(boolean hero)
  8212. {
  8213. if (hero && _baseClass == _activeClass)
  8214. {
  8215. for (L2Skill s : SkillTable.getHeroSkills())
  8216. addSkill(s, false); // Dont save Hero skills to database.
  8217. }
  8218. else
  8219. {
  8220. for (L2Skill s : SkillTable.getHeroSkills())
  8221. super.removeSkill(s); // Remove skills from non Hero characters.
  8222. }
  8223. _isHero = hero;
  8224.  
  8225. sendSkillList();
  8226. }
  8227.  
  8228. public boolean isOlympiadStart()
  8229. {
  8230. return _isInOlympiadStart;
  8231. }
  8232.  
  8233. public void setOlympiadStart(boolean b)
  8234. {
  8235. _isInOlympiadStart = b;
  8236. }
  8237.  
  8238. public boolean isInOlympiadMode()
  8239. {
  8240. return _isInOlympiadMode;
  8241. }
  8242.  
  8243. public void setOlympiadMode(boolean b)
  8244. {
  8245. _isInOlympiadMode = b;
  8246. }
  8247. // RnP (Del multifunction zonos)
  8248. public boolean isOffline()
  8249. {
  8250. return _isOffline;
  8251. }
  8252. public boolean isInDuel()
  8253. {
  8254. return _duelId > 0;
  8255. }
  8256.  
  8257. public int getDuelId()
  8258. {
  8259. return _duelId;
  8260. }
  8261.  
  8262. public void setDuelState(DuelState state)
  8263. {
  8264. _duelState = state;
  8265. }
  8266.  
  8267. public DuelState getDuelState()
  8268. {
  8269. return _duelState;
  8270. }
  8271.  
  8272. /**
  8273. * Sets up the duel state using a non 0 duelId.
  8274. * @param duelId 0=not in a duel
  8275. */
  8276. public void setInDuel(int duelId)
  8277. {
  8278. if (duelId > 0)
  8279. {
  8280. _duelState = DuelState.ON_COUNTDOWN;
  8281. _duelId = duelId;
  8282. }
  8283. else
  8284. {
  8285. if (_duelState == DuelState.DEAD)
  8286. {
  8287. enableAllSkills();
  8288. getStatus().startHpMpRegeneration();
  8289. }
  8290. _duelState = DuelState.NO_DUEL;
  8291. _duelId = 0;
  8292. }
  8293. }
  8294.  
  8295. /**
  8296. * This returns a SystemMessage stating why the player is not available for duelling.
  8297. * @return S1_CANNOT_DUEL... message
  8298. */
  8299. public SystemMessage getNoDuelReason()
  8300. {
  8301. // Prepare the message with the good reason.
  8302. final SystemMessage sm = SystemMessage.getSystemMessage(_noDuelReason).addPcName(this);
  8303.  
  8304. // Reinitialize the reason.
  8305. _noDuelReason = SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL;
  8306.  
  8307. // Send stored reason.
  8308. return sm;
  8309. }
  8310.  
  8311. /**
  8312. * Checks if this player might join / start a duel. To get the reason use getNoDuelReason() after calling this function.
  8313. * @return true if the player might join/start a duel.
  8314. */
  8315. public boolean canDuel()
  8316. {
  8317. if (isInCombat() || getPunishLevel() == PunishLevel.JAIL)
  8318. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_ENGAGED_IN_BATTLE;
  8319. else if (isDead() || isAlikeDead() || (getCurrentHp() < getMaxHp() / 2 || getCurrentMp() < getMaxMp() / 2))
  8320. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_HP_OR_MP_IS_BELOW_50_PERCENT;
  8321. else if (isInDuel())
  8322. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_ALREADY_ENGAGED_IN_A_DUEL;
  8323. else if (isInOlympiadMode())
  8324. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_PARTICIPATING_IN_THE_OLYMPIAD;
  8325. else if (isCursedWeaponEquipped() || getKarma() != 0)
  8326. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_IN_A_CHAOTIC_STATE;
  8327. else if (isInStoreMode())
  8328. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_ENGAGED_IN_A_PRIVATE_STORE_OR_MANUFACTURE;
  8329. else if (isMounted() || isInBoat())
  8330. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_RIDING_A_BOAT_WYVERN_OR_STRIDER;
  8331. else if (isFishing())
  8332. _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_FISHING;
  8333. else if (isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.PEACE) || isInsideZone(ZoneId.SIEGE))
  8334. _noDuelReason = SystemMessageId.S1_CANNOT_MAKE_A_CHALLANGE_TO_A_DUEL_BECAUSE_S1_IS_CURRENTLY_IN_A_DUEL_PROHIBITED_AREA;
  8335. else
  8336. return true;
  8337.  
  8338. return false;
  8339. }
  8340.  
  8341. public boolean isNoble()
  8342. {
  8343. return _isNoble;
  8344. }
  8345.  
  8346. /**
  8347. * Set Noblesse Status, and reward with nobles' skills.
  8348. * @param val Add skills if setted to true, else remove skills.
  8349. * @param store Store the status directly in the db if setted to true.
  8350. */
  8351. public void setNoble(boolean val, boolean store)
  8352. {
  8353. if (val)
  8354. for (L2Skill s : SkillTable.getNobleSkills())
  8355. addSkill(s, false); // Dont Save Noble skills to Sql
  8356. else
  8357. for (L2Skill s : SkillTable.getNobleSkills())
  8358. super.removeSkill(s); // Just Remove skills without deleting from Sql
  8359.  
  8360. _isNoble = val;
  8361.  
  8362. sendSkillList();
  8363.  
  8364. if (store)
  8365. {
  8366. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8367. {
  8368. PreparedStatement statement = con.prepareStatement(UPDATE_NOBLESS);
  8369. statement.setBoolean(1, val);
  8370. statement.setInt(2, getObjectId());
  8371. statement.executeUpdate();
  8372. statement.close();
  8373. }
  8374. catch (Exception e)
  8375. {
  8376. _log.log(Level.WARNING, "Could not update " + getName() + " nobless status: " + e.getMessage(), e);
  8377. }
  8378. }
  8379. }
  8380.  
  8381. public void setLvlJoinedAcademy(int lvl)
  8382. {
  8383. _lvlJoinedAcademy = lvl;
  8384. }
  8385.  
  8386. public int getLvlJoinedAcademy()
  8387. {
  8388. return _lvlJoinedAcademy;
  8389. }
  8390.  
  8391. public boolean isAcademyMember()
  8392. {
  8393. return _lvlJoinedAcademy > 0;
  8394. }
  8395.  
  8396. public void setTeam(int team)
  8397. {
  8398. _team = team;
  8399. }
  8400.  
  8401. public int getTeam()
  8402. {
  8403. return _team;
  8404. }
  8405.  
  8406. public void setWantsPeace(boolean wantsPeace)
  8407. {
  8408. _wantsPeace = wantsPeace;
  8409. }
  8410.  
  8411. public boolean wantsPeace()
  8412. {
  8413. return _wantsPeace;
  8414. }
  8415.  
  8416. public boolean isFishing()
  8417. {
  8418. return _fishingLoc != null;
  8419. }
  8420.  
  8421. public void setAllianceWithVarkaKetra(int sideAndLvlOfAlliance)
  8422. {
  8423. _alliedVarkaKetra = sideAndLvlOfAlliance;
  8424. }
  8425.  
  8426. /**
  8427. * [-5,-1] varka, 0 neutral, [1,5] ketra
  8428. * @return the side faction.
  8429. */
  8430. public int getAllianceWithVarkaKetra()
  8431. {
  8432. return _alliedVarkaKetra;
  8433. }
  8434.  
  8435. public boolean isAlliedWithVarka()
  8436. {
  8437. return _alliedVarkaKetra < 0;
  8438. }
  8439.  
  8440. public boolean isAlliedWithKetra()
  8441. {
  8442. return _alliedVarkaKetra > 0;
  8443. }
  8444.  
  8445. public void sendSkillList()
  8446. {
  8447. final ItemInstance formal = getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  8448. final boolean isWearingFormalWear = formal != null && formal.getItem().getBodyPart() == Item.SLOT_ALLDRESS;
  8449.  
  8450. boolean isDisabled = false;
  8451. SkillList sl = new SkillList();
  8452.  
  8453. for (L2Skill s : getSkills().values())
  8454. {
  8455. if (s.getId() > 9000 && s.getId() < 9007)
  8456. continue; // Fake skills to change base stats
  8457.  
  8458. if (getClan() != null)
  8459. isDisabled = s.isClanSkill() && getClan().getReputationScore() < 0;
  8460.  
  8461. if (isCursedWeaponEquipped()) // Only Demonic skills are available
  8462. isDisabled = !s.isDemonicSkill();
  8463. else if (isMounted()) // else if, because only ONE state is possible
  8464. {
  8465. if (getMountType() == 1) // Only Strider skills are available
  8466. isDisabled = !s.isStriderSkill();
  8467. else if (getMountType() == 2) // Only Wyvern skills are available
  8468. isDisabled = !s.isFlyingSkill();
  8469. }
  8470.  
  8471. if (isWearingFormalWear)
  8472. isDisabled = true;
  8473.  
  8474. sl.addSkill(s.getId(), s.getLevel(), s.isPassive(), isDisabled);
  8475. }
  8476. sendPacket(sl);
  8477. }
  8478.  
  8479. /**
  8480. * 1. Add the specified class ID as a subclass (up to the maximum number of <b>three</b>) for this character.<BR>
  8481. * 2. This method no longer changes the active _classIndex of the player. This is only done by the calling of setActiveClass() method as that should be the only way to do so.
  8482. * @param classId
  8483. * @param classIndex
  8484. * @return boolean subclassAdded
  8485. */
  8486. public boolean addSubClass(int classId, int classIndex)
  8487. {
  8488. if (!_subclassLock.tryLock())
  8489. return false;
  8490.  
  8491. try
  8492. {
  8493. if (_subClasses.size() == 3 || classIndex == 0 || _subClasses.containsKey(classIndex))
  8494. return false;
  8495.  
  8496. SubClass newClass = new SubClass(classId, classIndex);
  8497.  
  8498. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8499. {
  8500. PreparedStatement statement = con.prepareStatement(ADD_CHAR_SUBCLASS);
  8501. statement.setInt(1, getObjectId());
  8502. statement.setInt(2, newClass.getClassId());
  8503. statement.setLong(3, newClass.getExp());
  8504. statement.setInt(4, newClass.getSp());
  8505. statement.setInt(5, newClass.getLevel());
  8506. statement.setInt(6, newClass.getClassIndex());
  8507.  
  8508. statement.execute();
  8509. statement.close();
  8510. }
  8511. catch (Exception e)
  8512. {
  8513. _log.warning("WARNING: Could not add character sub class for " + getName() + ": " + e);
  8514. return false;
  8515. }
  8516.  
  8517. // Commit after database INSERT incase exception is thrown.
  8518. _subClasses.put(newClass.getClassIndex(), newClass);
  8519.  
  8520. ClassId subTemplate = ClassId.VALUES[classId];
  8521. Collection<L2SkillLearn> skillTree = SkillTreeTable.getInstance().getAllowedSkills(subTemplate);
  8522.  
  8523. if (skillTree == null)
  8524. return true;
  8525.  
  8526. final Map<Integer, L2Skill> prevSkillList = new LinkedHashMap<>();
  8527.  
  8528. for (L2SkillLearn skillInfo : skillTree)
  8529. {
  8530. if (skillInfo.getMinLevel() <= 40)
  8531. {
  8532. L2Skill prevSkill = prevSkillList.get(skillInfo.getId());
  8533. L2Skill newSkill = SkillTable.getInstance().getInfo(skillInfo.getId(), skillInfo.getLevel());
  8534.  
  8535. if (prevSkill != null && (prevSkill.getLevel() > newSkill.getLevel()))
  8536. continue;
  8537.  
  8538. prevSkillList.put(newSkill.getId(), newSkill);
  8539. storeSkill(newSkill, prevSkill, classIndex);
  8540. }
  8541. }
  8542.  
  8543. return true;
  8544. }
  8545. finally
  8546. {
  8547. _subclassLock.unlock();
  8548. }
  8549. }
  8550.  
  8551. /**
  8552. * 1. Completely erase all existance of the subClass linked to the classIndex.<BR>
  8553. * 2. Send over the newClassId to addSubClass()to create a new instance on this classIndex.<BR>
  8554. * 3. Upon Exception, revert the player to their BaseClass to avoid further problems.<BR>
  8555. * @param classIndex
  8556. * @param newClassId
  8557. * @return boolean subclassAdded
  8558. */
  8559. public boolean modifySubClass(int classIndex, int newClassId)
  8560. {
  8561. if (!_subclassLock.tryLock())
  8562. return false;
  8563.  
  8564. try
  8565. {
  8566. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8567. {
  8568. // Remove all henna info stored for this sub-class.
  8569. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNAS);
  8570. statement.setInt(1, getObjectId());
  8571. statement.setInt(2, classIndex);
  8572. statement.execute();
  8573. statement.close();
  8574.  
  8575. // Remove all shortcuts info stored for this sub-class.
  8576. statement = con.prepareStatement(DELETE_CHAR_SHORTCUTS);
  8577. statement.setInt(1, getObjectId());
  8578. statement.setInt(2, classIndex);
  8579. statement.execute();
  8580. statement.close();
  8581.  
  8582. // Remove all effects info stored for this sub-class.
  8583. statement = con.prepareStatement(DELETE_SKILL_SAVE);
  8584. statement.setInt(1, getObjectId());
  8585. statement.setInt(2, classIndex);
  8586. statement.execute();
  8587. statement.close();
  8588.  
  8589. // Remove all skill info stored for this sub-class.
  8590. statement = con.prepareStatement(DELETE_CHAR_SKILLS);
  8591. statement.setInt(1, getObjectId());
  8592. statement.setInt(2, classIndex);
  8593. statement.execute();
  8594. statement.close();
  8595.  
  8596. // Remove all basic info stored about this sub-class.
  8597. statement = con.prepareStatement(DELETE_CHAR_SUBCLASS);
  8598. statement.setInt(1, getObjectId());
  8599. statement.setInt(2, classIndex);
  8600. statement.execute();
  8601. statement.close();
  8602. }
  8603. catch (Exception e)
  8604. {
  8605. _log.warning("Could not modify subclass for " + getName() + " to class index " + classIndex + ": " + e);
  8606.  
  8607. // This must be done in order to maintain data consistency.
  8608. _subClasses.remove(classIndex);
  8609. return false;
  8610. }
  8611.  
  8612. _subClasses.remove(classIndex);
  8613. }
  8614. finally
  8615. {
  8616. _subclassLock.unlock();
  8617. }
  8618.  
  8619. return addSubClass(newClassId, classIndex);
  8620. }
  8621.  
  8622. public boolean isSubClassActive()
  8623. {
  8624. return _classIndex > 0;
  8625. }
  8626.  
  8627. public Map<Integer, SubClass> getSubClasses()
  8628. {
  8629. return _subClasses;
  8630. }
  8631. // RNP (CIA DEL NOBLESO ITEM)
  8632. public int getTotalSubClasses()
  8633. {
  8634. return getSubClasses().size();
  8635. }
  8636.  
  8637. public int getBaseClass()
  8638. {
  8639. return _baseClass;
  8640. }
  8641.  
  8642. public int getActiveClass()
  8643. {
  8644. return _activeClass;
  8645. }
  8646.  
  8647. public int getClassIndex()
  8648. {
  8649. return _classIndex;
  8650. }
  8651.  
  8652. private void setClassTemplate(int classId)
  8653. {
  8654. _activeClass = classId;
  8655.  
  8656. PcTemplate t = CharTemplateTable.getInstance().getTemplate(classId);
  8657.  
  8658. if (t == null)
  8659. {
  8660. _log.severe("Missing template for classId: " + classId);
  8661. throw new Error();
  8662. }
  8663.  
  8664. // Set the template of the L2PcInstance
  8665. setTemplate(t);
  8666. }
  8667.  
  8668. /**
  8669. * Changes the character's class based on the given class index. <BR>
  8670. * <BR>
  8671. * An index of zero specifies the character's original (base) class, while indexes 1-3 specifies the character's sub-classes respectively.
  8672. * @param classIndex
  8673. * @return true if successful.
  8674. */
  8675. public boolean setActiveClass(int classIndex)
  8676. {
  8677. if (!_subclassLock.tryLock())
  8678. return false;
  8679.  
  8680. try
  8681. {
  8682. // Remove active item skills before saving char to database because next time when choosing this class, worn items can be different
  8683. for (ItemInstance item : getInventory().getAugmentedItems())
  8684. {
  8685. if (item != null && item.isEquipped())
  8686. item.getAugmentation().removeBonus(this);
  8687. }
  8688.  
  8689. // abort any kind of cast.
  8690. abortCast();
  8691.  
  8692. // Stop casting for any player that may be casting a force buff on this l2pcinstance.
  8693. for (L2Character character : getKnownList().getKnownType(L2Character.class))
  8694. if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  8695. character.abortCast();
  8696.  
  8697. store();
  8698. _reuseTimeStamps.clear();
  8699.  
  8700. // clear charges
  8701. _charges.set(0);
  8702. stopChargeTask();
  8703.  
  8704. if (classIndex == 0)
  8705. setClassTemplate(getBaseClass());
  8706. else
  8707. {
  8708. try
  8709. {
  8710. setClassTemplate(_subClasses.get(classIndex).getClassId());
  8711. }
  8712. catch (Exception e)
  8713. {
  8714. _log.info("Could not switch " + getName() + "'s sub class to class index " + classIndex + ": " + e);
  8715. return false;
  8716. }
  8717. }
  8718. _classIndex = classIndex;
  8719.  
  8720. if (isInParty())
  8721. getParty().recalculatePartyLevel();
  8722.  
  8723. if (getPet() instanceof L2SummonInstance)
  8724. getPet().unSummon(this);
  8725.  
  8726. for (L2Skill oldSkill : getSkills().values())
  8727. super.removeSkill(oldSkill);
  8728.  
  8729. stopAllEffectsExceptThoseThatLastThroughDeath();
  8730. stopCubics();
  8731.  
  8732. if (isSubClassActive())
  8733. {
  8734. _dwarvenRecipeBook.clear();
  8735. _commonRecipeBook.clear();
  8736. }
  8737. else
  8738. restoreRecipeBook();
  8739.  
  8740. restoreSkills();
  8741. rewardSkills();
  8742. regiveTemporarySkills();
  8743.  
  8744. // Prevents some issues when changing between subclases that shares skills
  8745. getDisabledSkills().clear();
  8746.  
  8747. restoreEffects();
  8748. updateEffectIcons();
  8749. sendPacket(new EtcStatusUpdate(this));
  8750.  
  8751. // If player has quest "Repent Your Sins", remove it
  8752. QuestState st = getQuestState("Q422_RepentYourSins");
  8753. if (st != null)
  8754. st.exitQuest(true);
  8755.  
  8756. for (int i = 0; i < 3; i++)
  8757. _henna[i] = null;
  8758.  
  8759. restoreHenna();
  8760. sendPacket(new HennaInfo(this));
  8761.  
  8762. if (getCurrentHp() > getMaxHp())
  8763. setCurrentHp(getMaxHp());
  8764. if (getCurrentMp() > getMaxMp())
  8765. setCurrentMp(getMaxMp());
  8766. if (getCurrentCp() > getMaxCp())
  8767. setCurrentCp(getMaxCp());
  8768.  
  8769. refreshOverloaded();
  8770. refreshExpertisePenalty();
  8771. broadcastUserInfo();
  8772.  
  8773. // Clear resurrect xp calculation
  8774. setExpBeforeDeath(0);
  8775.  
  8776. // Remove shot automation
  8777. disableAutoShotsAll();
  8778.  
  8779. // Discharge any active shots
  8780. ItemInstance item = getActiveWeaponInstance();
  8781. if (item != null)
  8782. item.unChargeAllShots();
  8783.  
  8784. _shortCuts.restore();
  8785. sendPacket(new ShortCutInit(this));
  8786.  
  8787. broadcastPacket(new SocialAction(this, 15));
  8788. sendPacket(new SkillCoolTime(this));
  8789. return true;
  8790. }
  8791. finally
  8792. {
  8793. _subclassLock.unlock();
  8794. }
  8795. }
  8796.  
  8797. public boolean isLocked()
  8798. {
  8799. return _subclassLock.isLocked();
  8800. }
  8801.  
  8802. public void stopWaterTask()
  8803. {
  8804. if (_isInWater)
  8805. {
  8806. _isInWater = false;
  8807. sendPacket(new SetupGauge(2, 0));
  8808. WaterTaskManager.getInstance().remove(this);
  8809. }
  8810. }
  8811.  
  8812. public void startWaterTask()
  8813. {
  8814. if (!isDead() && !_isInWater)
  8815. {
  8816. _isInWater = true;
  8817. final int time = (int) calcStat(Stats.BREATH, 60000 * getRace().getBreathMultiplier(), this, null);
  8818.  
  8819. sendPacket(new SetupGauge(2, time));
  8820. WaterTaskManager.getInstance().add(this, time);
  8821. }
  8822. }
  8823.  
  8824. public void checkWaterState()
  8825. {
  8826. if (isInsideZone(ZoneId.WATER))
  8827. startWaterTask();
  8828. else
  8829. stopWaterTask();
  8830. }
  8831.  
  8832. public void onPlayerEnter()
  8833. {
  8834. if (isCursedWeaponEquipped())
  8835. CursedWeaponsManager.getInstance().getCursedWeapon(getCursedWeaponEquippedId()).cursedOnLogin();
  8836.  
  8837. // Add to the GameTimeTask to keep inform about activity time.
  8838. GameTimeTaskManager.getInstance().add(this);
  8839.  
  8840. // Teleport player if the Seven Signs period isn't the good one, or if the player isn't in a cabal.
  8841. if (isIn7sDungeon() && !isGM())
  8842. {
  8843. if (SevenSigns.getInstance().isSealValidationPeriod() || SevenSigns.getInstance().isCompResultsPeriod())
  8844. {
  8845. if (SevenSigns.getInstance().getPlayerCabal(getObjectId()) != SevenSigns.getInstance().getCabalHighestScore())
  8846. {
  8847. teleToLocation(TeleportWhereType.TOWN);
  8848. setIsIn7sDungeon(false);
  8849. }
  8850. }
  8851. else if (SevenSigns.getInstance().getPlayerCabal(getObjectId()) == SevenSigns.CABAL_NULL)
  8852. {
  8853. teleToLocation(TeleportWhereType.TOWN);
  8854. setIsIn7sDungeon(false);
  8855. }
  8856. }
  8857.  
  8858. // Jail task
  8859. updatePunishState();
  8860.  
  8861. if (isGM())
  8862. {
  8863. if (isInvul())
  8864. sendMessage("Entering world in Invulnerable mode.");
  8865. if (getAppearance().getInvisible())
  8866. sendMessage("Entering world in Invisible mode.");
  8867. if (isInRefusalMode())
  8868. sendMessage("Entering world in Message Refusal mode.");
  8869. }
  8870.  
  8871. revalidateZone(true);
  8872. notifyFriends(true);
  8873. }
  8874.  
  8875. public long getLastAccess()
  8876. {
  8877. return _lastAccess;
  8878. }
  8879.  
  8880. private void checkRecom(int recsHave, int recsLeft)
  8881. {
  8882. Calendar check = Calendar.getInstance();
  8883. check.setTimeInMillis(_lastRecomUpdate);
  8884. check.add(Calendar.DAY_OF_MONTH, 1);
  8885.  
  8886. Calendar min = Calendar.getInstance();
  8887.  
  8888. _recomHave = recsHave;
  8889. _recomLeft = recsLeft;
  8890.  
  8891. if (getStat().getLevel() < 10 || check.after(min))
  8892. return;
  8893.  
  8894. restartRecom();
  8895. }
  8896.  
  8897. public void restartRecom()
  8898. {
  8899. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  8900. {
  8901. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_RECOMS);
  8902. statement.setInt(1, getObjectId());
  8903. statement.execute();
  8904. statement.close();
  8905.  
  8906. _recomChars.clear();
  8907. }
  8908. catch (Exception e)
  8909. {
  8910. _log.warning("could not clear char recommendations: " + e);
  8911. }
  8912.  
  8913. if (getStat().getLevel() < 20)
  8914. {
  8915. _recomLeft = 3;
  8916. _recomHave--;
  8917. }
  8918. else if (getStat().getLevel() < 40)
  8919. {
  8920. _recomLeft = 6;
  8921. _recomHave -= 2;
  8922. }
  8923. else
  8924. {
  8925. _recomLeft = 9;
  8926. _recomHave -= 3;
  8927. }
  8928.  
  8929. if (_recomHave < 0)
  8930. _recomHave = 0;
  8931.  
  8932. // If we have to update last update time, but it's now before 13, we should set it to yesterday
  8933. Calendar update = Calendar.getInstance();
  8934. if (update.get(Calendar.HOUR_OF_DAY) < 13)
  8935. update.add(Calendar.DAY_OF_MONTH, -1);
  8936.  
  8937. update.set(Calendar.HOUR_OF_DAY, 13);
  8938. _lastRecomUpdate = update.getTimeInMillis();
  8939. }
  8940.  
  8941. @Override
  8942. public void doRevive()
  8943. {
  8944. super.doRevive();
  8945.  
  8946. stopEffects(L2EffectType.CHARMOFCOURAGE);
  8947. sendPacket(new EtcStatusUpdate(this));
  8948.  
  8949. _reviveRequested = 0;
  8950. _revivePower = 0;
  8951.  
  8952. if (isMounted())
  8953. startFeed(_mountNpcId);
  8954.  
  8955. if (isInParty() && getParty().isInDimensionalRift())
  8956. {
  8957. if (!DimensionalRiftManager.getInstance().checkIfInPeaceZone(getX(), getY(), getZ()))
  8958. getParty().getDimensionalRift().memberRessurected(this);
  8959. }
  8960.  
  8961. // Schedule a paralyzed task to wait for the animation to finish
  8962. ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  8963. {
  8964. @Override
  8965. public void run()
  8966. {
  8967. setIsParalyzed(false);
  8968. }
  8969. }, (int) (2000 / getStat().getMovementSpeedMultiplier()));
  8970. setIsParalyzed(true);
  8971. }
  8972.  
  8973. @Override
  8974. public void doRevive(double revivePower)
  8975. {
  8976. // Restore the player's lost experience, depending on the % return of the skill used (based on its power).
  8977. restoreExp(revivePower);
  8978. doRevive();
  8979. }
  8980.  
  8981. public void reviveRequest(L2PcInstance Reviver, L2Skill skill, boolean Pet)
  8982. {
  8983. if (_reviveRequested == 1)
  8984. {
  8985. // Resurrection has already been proposed.
  8986. if (_revivePet == Pet)
  8987. Reviver.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED);
  8988. else
  8989. {
  8990. if (Pet)
  8991. // A pet cannot be resurrected while it's owner is in the process of resurrecting.
  8992. Reviver.sendPacket(SystemMessageId.CANNOT_RES_PET2);
  8993. else
  8994. // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
  8995. Reviver.sendPacket(SystemMessageId.MASTER_CANNOT_RES);
  8996. }
  8997. return;
  8998. }
  8999.  
  9000. if ((Pet && getPet() != null && getPet().isDead()) || (!Pet && isDead()))
  9001. {
  9002. _reviveRequested = 1;
  9003.  
  9004. if (isPhoenixBlessed())
  9005. _revivePower = 100;
  9006. else if (isAffected(L2EffectFlag.CHARM_OF_COURAGE))
  9007. _revivePower = 0;
  9008. else
  9009. _revivePower = Formulas.calculateSkillResurrectRestorePercent(skill.getPower(), Reviver);
  9010.  
  9011. _revivePet = Pet;
  9012.  
  9013. if (isAffected(L2EffectFlag.CHARM_OF_COURAGE))
  9014. {
  9015. sendPacket(new ConfirmDlg(SystemMessageId.DO_YOU_WANT_TO_BE_RESTORED).addTime(60000));
  9016. return;
  9017. }
  9018.  
  9019. sendPacket(new ConfirmDlg(SystemMessageId.RESSURECTION_REQUEST_BY_S1).addPcName(Reviver));
  9020. }
  9021. }
  9022.  
  9023. public void reviveAnswer(int answer)
  9024. {
  9025. if (_reviveRequested != 1 || (!isDead() && !_revivePet) || (_revivePet && getPet() != null && !getPet().isDead()))
  9026. return;
  9027.  
  9028. if (answer == 0 && isPhoenixBlessed())
  9029. stopPhoenixBlessing(null);
  9030. else if (answer == 1)
  9031. {
  9032. if (!_revivePet)
  9033. {
  9034. if (_revivePower != 0)
  9035. doRevive(_revivePower);
  9036. else
  9037. doRevive();
  9038. }
  9039. else if (getPet() != null)
  9040. {
  9041. if (_revivePower != 0)
  9042. getPet().doRevive(_revivePower);
  9043. else
  9044. getPet().doRevive();
  9045. }
  9046. }
  9047. _reviveRequested = 0;
  9048. _revivePower = 0;
  9049. }
  9050.  
  9051. public boolean isReviveRequested()
  9052. {
  9053. return (_reviveRequested == 1);
  9054. }
  9055.  
  9056. public boolean isRevivingPet()
  9057. {
  9058. return _revivePet;
  9059. }
  9060.  
  9061. public void removeReviving()
  9062. {
  9063. _reviveRequested = 0;
  9064. _revivePower = 0;
  9065. }
  9066.  
  9067. public void onActionRequest()
  9068. {
  9069. if (isSpawnProtected())
  9070. {
  9071. sendMessage("As you acted, you are no longer under spawn protection.");
  9072. setSpawnProtection(false);
  9073. }
  9074. }
  9075.  
  9076. /**
  9077. * @param expertiseIndex The expertiseIndex to set.
  9078. */
  9079. public void setExpertiseIndex(int expertiseIndex)
  9080. {
  9081. _expertiseIndex = expertiseIndex;
  9082. }
  9083.  
  9084. /**
  9085. * @return Returns the expertiseIndex.
  9086. */
  9087. public int getExpertiseIndex()
  9088. {
  9089. return _expertiseIndex;
  9090. }
  9091.  
  9092. @Override
  9093. public final void onTeleported()
  9094. {
  9095. super.onTeleported();
  9096.  
  9097. // Force a revalidation
  9098. revalidateZone(true);
  9099.  
  9100. if (Config.PLAYER_SPAWN_PROTECTION > 0)
  9101. setSpawnProtection(true);
  9102.  
  9103. // Stop toggles upon teleport.
  9104. if (!isGM())
  9105. stopAllToggles();
  9106.  
  9107. // Modify the position of the tamed beast if necessary
  9108. if (getTrainedBeast() != null)
  9109. {
  9110. getTrainedBeast().getAI().stopFollow();
  9111. getTrainedBeast().teleToLocation(getPosition(), 0);
  9112. getTrainedBeast().getAI().startFollow(this);
  9113. }
  9114.  
  9115. // Modify the position of the pet if necessary
  9116. L2Summon pet = getPet();
  9117. if (pet != null)
  9118. {
  9119. pet.setFollowStatus(false);
  9120. pet.teleToLocation(getPosition(), 0);
  9121. ((L2SummonAI) pet.getAI()).setStartFollowController(true);
  9122. pet.setFollowStatus(true);
  9123. }
  9124. // RnP (11 Cia del petu gal)
  9125. TvTEvent.onTeleported(this);
  9126. DMEvent.onTeleported(this);
  9127. }
  9128.  
  9129. @Override
  9130. public void addExpAndSp(long addToExp, int addToSp)
  9131. {
  9132. getStat().addExpAndSp(addToExp, addToSp);
  9133. }
  9134.  
  9135. public void removeExpAndSp(long removeExp, int removeSp)
  9136. {
  9137. getStat().removeExpAndSp(removeExp, removeSp);
  9138. }
  9139.  
  9140. @Override
  9141. public void reduceCurrentHp(double value, L2Character attacker, boolean awake, boolean isDOT, L2Skill skill)
  9142. {
  9143. if (skill != null)
  9144. getStatus().reduceHp(value, attacker, awake, isDOT, skill.isToggle(), skill.getDmgDirectlyToHP());
  9145. else
  9146. getStatus().reduceHp(value, attacker, awake, isDOT, false, false);
  9147.  
  9148. // notify the tamed beast of attacks
  9149. if (getTrainedBeast() != null)
  9150. getTrainedBeast().onOwnerGotAttacked(attacker);
  9151. }
  9152.  
  9153. public synchronized void addBypass(String bypass)
  9154. {
  9155. if (bypass == null)
  9156. return;
  9157.  
  9158. _validBypass.add(bypass);
  9159. }
  9160.  
  9161. public synchronized void addBypass2(String bypass)
  9162. {
  9163. if (bypass == null)
  9164. return;
  9165.  
  9166. _validBypass2.add(bypass);
  9167. }
  9168.  
  9169. public synchronized boolean validateBypass(String cmd)
  9170. {
  9171. for (String bp : _validBypass)
  9172. {
  9173. if (bp == null)
  9174. continue;
  9175.  
  9176. if (bp.equals(cmd))
  9177. return true;
  9178. }
  9179.  
  9180. for (String bp : _validBypass2)
  9181. {
  9182. if (bp == null)
  9183. continue;
  9184.  
  9185. if (cmd.startsWith(bp))
  9186. return true;
  9187. }
  9188.  
  9189. return false;
  9190. }
  9191.  
  9192. /**
  9193. * Test multiple cases where the item shouldn't be able to manipulate.
  9194. * @param objectId : The item objectId.
  9195. * @return true if it the item can be manipulated, false ovtherwise.
  9196. */
  9197. public boolean validateItemManipulation(int objectId)
  9198. {
  9199. final ItemInstance item = getInventory().getItemByObjectId(objectId);
  9200.  
  9201. // You don't own the item, or item is null.
  9202. if (item == null || item.getOwnerId() != getObjectId())
  9203. return false;
  9204.  
  9205. // Pet whom item you try to manipulate is summoned/mounted.
  9206. if (getPet() != null && getPet().getControlItemId() == objectId || _mountObjectId == objectId)
  9207. return false;
  9208.  
  9209. if (getActiveEnchantItem() != null && getActiveEnchantItem().getObjectId() == objectId)
  9210. return false;
  9211.  
  9212. // Can't trade a cursed weapon.
  9213. if (CursedWeaponsManager.getInstance().isCursed(item.getItemId()))
  9214. return false;
  9215.  
  9216. return true;
  9217. }
  9218.  
  9219. public synchronized void clearBypass()
  9220. {
  9221. _validBypass.clear();
  9222. _validBypass2.clear();
  9223. }
  9224.  
  9225. /**
  9226. * @return Returns the inBoat.
  9227. */
  9228. public boolean isInBoat()
  9229. {
  9230. return _vehicle != null;
  9231. }
  9232.  
  9233. public L2Vehicle getBoat()
  9234. {
  9235. return _vehicle;
  9236. }
  9237.  
  9238. public L2Vehicle getVehicle()
  9239. {
  9240. return _vehicle;
  9241. }
  9242.  
  9243. public void setVehicle(L2Vehicle v)
  9244. {
  9245. if (v == null && _vehicle != null)
  9246. _vehicle.removePassenger(this);
  9247.  
  9248. _vehicle = v;
  9249. }
  9250.  
  9251. public void setCrystallizing(boolean mode)
  9252. {
  9253. _isCrystallizing = mode;
  9254. }
  9255.  
  9256. public boolean isCrystallizing()
  9257. {
  9258. return _isCrystallizing;
  9259. }
  9260.  
  9261. public SpawnLocation getVehiclePosition()
  9262. {
  9263. return _vehiclePosition;
  9264. }
  9265.  
  9266. /**
  9267. * Manage the delete task of a L2PcInstance (Leave Party, Unsummon pet, Save its inventory in the database, Remove it from the world...).
  9268. * <ul>
  9269. * <li>If the L2PcInstance is in observer mode, set its position to its position before entering in observer mode</li>
  9270. * <li>Set the online Flag to True or False and update the characters table of the database with online status and lastAccess</li>
  9271. * <li>Stop the HP/MP/CP Regeneration task</li>
  9272. * <li>Cancel Crafting, Attak or Cast</li>
  9273. * <li>Remove the L2PcInstance from the world</li>
  9274. * <li>Stop Party and Unsummon Pet</li>
  9275. * <li>Update database with items in its inventory and remove them from the world</li>
  9276. * <li>Remove all L2Object from _knownObjects and _knownPlayer of the L2Character then cancel Attak or Cast and notify AI</li>
  9277. * <li>Close the connection with the client</li>
  9278. * </ul>
  9279. */
  9280. @Override
  9281. public void deleteMe()
  9282. {
  9283. cleanup();
  9284. store();
  9285. super.deleteMe();
  9286. }
  9287.  
  9288. private synchronized void cleanup()
  9289. {
  9290. try
  9291. {
  9292. // Put the online status to false
  9293. setOnlineStatus(false, true);
  9294.  
  9295. // abort cast & attack and remove the target. Cancels movement aswell.
  9296. abortAttack();
  9297. abortCast();
  9298. stopMove(null);
  9299. setTarget(null);
  9300.  
  9301. PartyMatchWaitingList.getInstance().removePlayer(this);
  9302. if (_partyroom != 0)
  9303. {
  9304. PartyMatchRoom room = PartyMatchRoomList.getInstance().getRoom(_partyroom);
  9305. if (room != null)
  9306. room.deleteMember(this);
  9307. }
  9308.  
  9309. if (isFlying())
  9310. removeSkill(SkillTable.getInstance().getInfo(4289, 1));
  9311.  
  9312. // Stop all scheduled tasks
  9313. stopAllTimers();
  9314.  
  9315. // Cancel the cast of eventual fusion skill users on this target.
  9316. for (L2Character character : getKnownList().getKnownType(L2Character.class))
  9317. if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  9318. character.abortCast();
  9319.  
  9320. // Stop signets & toggles effects.
  9321. for (L2Effect effect : getAllEffects())
  9322. {
  9323. if (effect.getSkill().isToggle())
  9324. {
  9325. effect.exit();
  9326. continue;
  9327. }
  9328.  
  9329. switch (effect.getEffectType())
  9330. {
  9331. case SIGNET_GROUND:
  9332. case SIGNET_EFFECT:
  9333. effect.exit();
  9334. break;
  9335. }
  9336. }
  9337.  
  9338. // Remove the L2PcInstance from the world
  9339. decayMe();
  9340.  
  9341. // If a party is in progress, leave it
  9342. if (isInParty())
  9343. leaveParty();
  9344.  
  9345. // If the L2PcInstance has Pet, unsummon it
  9346. if (getPet() != null)
  9347. getPet().unSummon(this);
  9348.  
  9349. // Handle removal from olympiad game
  9350. if (OlympiadManager.getInstance().isRegistered(this) || getOlympiadGameId() != -1)
  9351. OlympiadManager.getInstance().removeDisconnectedCompetitor(this);
  9352.  
  9353. // set the status for pledge member list to OFFLINE
  9354. if (getClan() != null)
  9355. {
  9356. L2ClanMember clanMember = getClan().getClanMember(getObjectId());
  9357. if (clanMember != null)
  9358. clanMember.setPlayerInstance(null);
  9359. }
  9360.  
  9361. // deals with sudden exit in the middle of transaction
  9362. if (getActiveRequester() != null)
  9363. {
  9364. setActiveRequester(null);
  9365. cancelActiveTrade();
  9366. }
  9367.  
  9368. // If the L2PcInstance is a GM, remove it from the GM List
  9369. if (isGM())
  9370. GmListTable.getInstance().deleteGm(this);
  9371.  
  9372. // Check if the L2PcInstance is in observer mode to set its position to its position
  9373. // before entering in observer mode
  9374. if (inObserverMode())
  9375. setXYZInvisible(_savedLocation.getX(), _savedLocation.getY(), _savedLocation.getZ());
  9376.  
  9377. // Oust player from boat
  9378. if (getVehicle() != null)
  9379. getVehicle().oustPlayer(this, true, Location.DUMMY_LOC);
  9380.  
  9381. // RnP (cia del tvt 12 Logout)
  9382. TvTEvent.onLogout(this);
  9383. DMEvent.onLogout(this);
  9384.  
  9385. // Update inventory and remove them from the world
  9386. getInventory().deleteMe();
  9387.  
  9388. // Update warehouse and remove them from the world
  9389. clearWarehouse();
  9390.  
  9391. // Update freight and remove them from the world
  9392. clearFreight();
  9393. clearDepositedFreight();
  9394.  
  9395. if (isCursedWeaponEquipped())
  9396. CursedWeaponsManager.getInstance().getCursedWeapon(_cursedWeaponEquippedId).setPlayer(null);
  9397.  
  9398. // Remove all L2Object from _knownObjects and _knownPlayer of the L2Character then cancel Attak or Cast and notify AI
  9399. getKnownList().removeAllKnownObjects();
  9400.  
  9401. if (getClanId() > 0)
  9402. getClan().broadcastToOtherOnlineMembers(new PledgeShowMemberListUpdate(this), this);
  9403.  
  9404. if (isSeated())
  9405. {
  9406. final L2Object object = L2World.getInstance().getObject(_throneId);
  9407. if (object instanceof L2StaticObjectInstance)
  9408. ((L2StaticObjectInstance) object).setBusy(false);
  9409. }
  9410.  
  9411. L2World.getInstance().removePlayer(this); // force remove in case of crash during teleport
  9412.  
  9413. // friends & blocklist update
  9414. notifyFriends(false);
  9415. getBlockList().playerLogout();
  9416. }
  9417. catch (Exception e)
  9418. {
  9419. _log.log(Level.WARNING, "Exception on deleteMe()" + e.getMessage(), e);
  9420. }
  9421. }
  9422.  
  9423. public void startFishing(Location loc)
  9424. {
  9425. stopMove(null);
  9426. setIsImmobilized(true);
  9427.  
  9428. _fishingLoc = loc;
  9429.  
  9430. // Starts fishing
  9431. int group = getRandomGroup();
  9432.  
  9433. _fish = FishTable.getFish(getRandomFishLvl(), getRandomFishType(group), group);
  9434. if (_fish == null)
  9435. {
  9436. endFishing(false);
  9437. return;
  9438. }
  9439.  
  9440. sendPacket(SystemMessageId.CAST_LINE_AND_START_FISHING);
  9441.  
  9442. broadcastPacket(new ExFishingStart(this, _fish.getType(_lure.isNightLure()), loc, _lure.isNightLure()));
  9443. sendPacket(new PlaySound(1, "SF_P_01", 0, 0, 0, 0, 0));
  9444. startLookingForFishTask();
  9445. }
  9446.  
  9447. public void stopLookingForFishTask()
  9448. {
  9449. if (_fishingTask != null)
  9450. {
  9451. _fishingTask.cancel(false);
  9452. _fishingTask = null;
  9453. }
  9454. }
  9455.  
  9456. public void startLookingForFishTask()
  9457. {
  9458. if (!isDead() && _fishingTask == null)
  9459. {
  9460. int checkDelay = 0;
  9461. boolean isNoob = false;
  9462. boolean isUpperGrade = false;
  9463.  
  9464. if (_lure != null)
  9465. {
  9466. int lureid = _lure.getItemId();
  9467. isNoob = _fish.getGroup() == 0;
  9468. isUpperGrade = _fish.getGroup() == 2;
  9469. if (lureid == 6519 || lureid == 6522 || lureid == 6525 || lureid == 8505 || lureid == 8508 || lureid == 8511) // low grade
  9470. checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (1.33)));
  9471. else if (lureid == 6520 || lureid == 6523 || lureid == 6526 || (lureid >= 8505 && lureid <= 8513) || (lureid >= 7610 && lureid <= 7613) || (lureid >= 7807 && lureid <= 7809) || (lureid >= 8484 && lureid <= 8486)) // medium grade, beginner, prize-winning & quest special bait
  9472. checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (1.00)));
  9473. else if (lureid == 6521 || lureid == 6524 || lureid == 6527 || lureid == 8507 || lureid == 8510 || lureid == 8513) // high grade
  9474. checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (0.66)));
  9475. }
  9476. _fishingTask = ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(new LookingForFishTask(_fish.getWaitTime(), _fish.getFishGuts(), _fish.getType(_lure.isNightLure()), isNoob, isUpperGrade), 10000, checkDelay);
  9477. }
  9478. }
  9479.  
  9480. private int getRandomGroup()
  9481. {
  9482. switch (_lure.getItemId())
  9483. {
  9484. case 7807: // green for beginners
  9485. case 7808: // purple for beginners
  9486. case 7809: // yellow for beginners
  9487. case 8486: // prize-winning for beginners
  9488. return 0;
  9489.  
  9490. case 8485: // prize-winning luminous
  9491. case 8506: // green luminous
  9492. case 8509: // purple luminous
  9493. case 8512: // yellow luminous
  9494. return 2;
  9495.  
  9496. default:
  9497. return 1;
  9498. }
  9499. }
  9500.  
  9501. private int getRandomFishType(int group)
  9502. {
  9503. int check = Rnd.get(100);
  9504. int type = 1;
  9505. switch (group)
  9506. {
  9507. case 0: // fish for novices
  9508. switch (_lure.getItemId())
  9509. {
  9510. case 7807: // green lure, preferred by fast-moving (nimble) fish (type 5)
  9511. if (check <= 54)
  9512. type = 5;
  9513. else if (check <= 77)
  9514. type = 4;
  9515. else
  9516. type = 6;
  9517. break;
  9518.  
  9519. case 7808: // purple lure, preferred by fat fish (type 4)
  9520. if (check <= 54)
  9521. type = 4;
  9522. else if (check <= 77)
  9523. type = 6;
  9524. else
  9525. type = 5;
  9526. break;
  9527.  
  9528. case 7809: // yellow lure, preferred by ugly fish (type 6)
  9529. if (check <= 54)
  9530. type = 6;
  9531. else if (check <= 77)
  9532. type = 5;
  9533. else
  9534. type = 4;
  9535. break;
  9536.  
  9537. case 8486: // prize-winning fishing lure for beginners
  9538. if (check <= 33)
  9539. type = 4;
  9540. else if (check <= 66)
  9541. type = 5;
  9542. else
  9543. type = 6;
  9544. break;
  9545. }
  9546. break;
  9547.  
  9548. case 1: // normal fish
  9549. switch (_lure.getItemId())
  9550. {
  9551. case 7610:
  9552. case 7611:
  9553. case 7612:
  9554. case 7613:
  9555. type = 3;
  9556. break;
  9557.  
  9558. case 6519: // all theese lures (green) are prefered by fast-moving (nimble) fish (type 1)
  9559. case 8505:
  9560. case 6520:
  9561. case 6521:
  9562. case 8507:
  9563. if (check <= 54)
  9564. type = 1;
  9565. else if (check <= 74)
  9566. type = 0;
  9567. else if (check <= 94)
  9568. type = 2;
  9569. else
  9570. type = 3;
  9571. break;
  9572.  
  9573. case 6522: // all theese lures (purple) are prefered by fat fish (type 0)
  9574. case 8508:
  9575. case 6523:
  9576. case 6524:
  9577. case 8510:
  9578. if (check <= 54)
  9579. type = 0;
  9580. else if (check <= 74)
  9581. type = 1;
  9582. else if (check <= 94)
  9583. type = 2;
  9584. else
  9585. type = 3;
  9586. break;
  9587.  
  9588. case 6525: // all theese lures (yellow) are prefered by ugly fish (type 2)
  9589. case 8511:
  9590. case 6526:
  9591. case 6527:
  9592. case 8513:
  9593. if (check <= 55)
  9594. type = 2;
  9595. else if (check <= 74)
  9596. type = 1;
  9597. else if (check <= 94)
  9598. type = 0;
  9599. else
  9600. type = 3;
  9601. break;
  9602. case 8484: // prize-winning fishing lure
  9603. if (check <= 33)
  9604. type = 0;
  9605. else if (check <= 66)
  9606. type = 1;
  9607. else
  9608. type = 2;
  9609. break;
  9610. }
  9611. break;
  9612.  
  9613. case 2: // upper grade fish, luminous lure
  9614. switch (_lure.getItemId())
  9615. {
  9616. case 8506: // green lure, preferred by fast-moving (nimble) fish (type 8)
  9617. if (check <= 54)
  9618. type = 8;
  9619. else if (check <= 77)
  9620. type = 7;
  9621. else
  9622. type = 9;
  9623. break;
  9624.  
  9625. case 8509: // purple lure, preferred by fat fish (type 7)
  9626. if (check <= 54)
  9627. type = 7;
  9628. else if (check <= 77)
  9629. type = 9;
  9630. else
  9631. type = 8;
  9632. break;
  9633.  
  9634. case 8512: // yellow lure, preferred by ugly fish (type 9)
  9635. if (check <= 54)
  9636. type = 9;
  9637. else if (check <= 77)
  9638. type = 8;
  9639. else
  9640. type = 7;
  9641. break;
  9642.  
  9643. case 8485: // prize-winning fishing lure
  9644. if (check <= 33)
  9645. type = 7;
  9646. else if (check <= 66)
  9647. type = 8;
  9648. else
  9649. type = 9;
  9650. break;
  9651. }
  9652. }
  9653. return type;
  9654. }
  9655.  
  9656. private int getRandomFishLvl()
  9657. {
  9658. int skilllvl = getSkillLevel(1315);
  9659.  
  9660. final L2Effect e = getFirstEffect(2274);
  9661. if (e != null)
  9662. skilllvl = (int) e.getSkill().getPower();
  9663.  
  9664. if (skilllvl <= 0)
  9665. return 1;
  9666.  
  9667. int randomlvl;
  9668.  
  9669. final int check = Rnd.get(100);
  9670. if (check <= 50)
  9671. randomlvl = skilllvl;
  9672. else if (check <= 85)
  9673. {
  9674. randomlvl = skilllvl - 1;
  9675. if (randomlvl <= 0)
  9676. randomlvl = 1;
  9677. }
  9678. else
  9679. {
  9680. randomlvl = skilllvl + 1;
  9681. if (randomlvl > 27)
  9682. randomlvl = 27;
  9683. }
  9684. return randomlvl;
  9685. }
  9686.  
  9687. public void startFishCombat(boolean isNoob, boolean isUpperGrade)
  9688. {
  9689. _fishCombat = new L2Fishing(this, _fish, isNoob, isUpperGrade, _lure.getItemId());
  9690. }
  9691.  
  9692. public void endFishing(boolean win)
  9693. {
  9694. if (_fishCombat == null)
  9695. sendPacket(SystemMessageId.BAIT_LOST_FISH_GOT_AWAY);
  9696. else
  9697. _fishCombat = null;
  9698.  
  9699. _lure = null;
  9700. _fishingLoc = null;
  9701.  
  9702. // Ends fishing
  9703. broadcastPacket(new ExFishingEnd(win, getObjectId()));
  9704. sendPacket(SystemMessageId.REEL_LINE_AND_STOP_FISHING);
  9705. setIsImmobilized(false);
  9706. stopLookingForFishTask();
  9707. }
  9708.  
  9709. public L2Fishing getFishCombat()
  9710. {
  9711. return _fishCombat;
  9712. }
  9713.  
  9714. public Location getFishingLoc()
  9715. {
  9716. return _fishingLoc;
  9717. }
  9718.  
  9719. public void setLure(ItemInstance lure)
  9720. {
  9721. _lure = lure;
  9722. }
  9723.  
  9724. public ItemInstance getLure()
  9725. {
  9726. return _lure;
  9727. }
  9728.  
  9729. public int getInventoryLimit()
  9730. {
  9731. return ((getRace() == ClassRace.DWARF) ? Config.INVENTORY_MAXIMUM_DWARF : Config.INVENTORY_MAXIMUM_NO_DWARF) + (int) getStat().calcStat(Stats.INV_LIM, 0, null, null);
  9732. }
  9733.  
  9734. public static int getQuestInventoryLimit()
  9735. {
  9736. return Config.INVENTORY_MAXIMUM_QUEST_ITEMS;
  9737. }
  9738.  
  9739. public int getWareHouseLimit()
  9740. {
  9741. return ((getRace() == ClassRace.DWARF) ? Config.WAREHOUSE_SLOTS_DWARF : Config.WAREHOUSE_SLOTS_NO_DWARF) + (int) getStat().calcStat(Stats.WH_LIM, 0, null, null);
  9742. }
  9743.  
  9744. public int getPrivateSellStoreLimit()
  9745. {
  9746. return ((getRace() == ClassRace.DWARF) ? Config.MAX_PVTSTORE_SLOTS_DWARF : Config.MAX_PVTSTORE_SLOTS_OTHER) + (int) getStat().calcStat(Stats.P_SELL_LIM, 0, null, null);
  9747. }
  9748.  
  9749. public int getPrivateBuyStoreLimit()
  9750. {
  9751. return ((getRace() == ClassRace.DWARF) ? Config.MAX_PVTSTORE_SLOTS_DWARF : Config.MAX_PVTSTORE_SLOTS_OTHER) + (int) getStat().calcStat(Stats.P_BUY_LIM, 0, null, null);
  9752. }
  9753.  
  9754. public int getFreightLimit()
  9755. {
  9756. return Config.FREIGHT_SLOTS + (int) getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null);
  9757. }
  9758.  
  9759. public int getDwarfRecipeLimit()
  9760. {
  9761. return Config.DWARF_RECIPE_LIMIT + (int) getStat().calcStat(Stats.REC_D_LIM, 0, null, null);
  9762. }
  9763.  
  9764. public int getCommonRecipeLimit()
  9765. {
  9766. return Config.COMMON_RECIPE_LIMIT + (int) getStat().calcStat(Stats.REC_C_LIM, 0, null, null);
  9767. }
  9768.  
  9769. public int getMountNpcId()
  9770. {
  9771. return _mountNpcId;
  9772. }
  9773.  
  9774. public int getMountLevel()
  9775. {
  9776. return _mountLevel;
  9777. }
  9778.  
  9779. public void setMountObjectId(int id)
  9780. {
  9781. _mountObjectId = id;
  9782. }
  9783.  
  9784. public int getMountObjectId()
  9785. {
  9786. return _mountObjectId;
  9787. }
  9788.  
  9789. /**
  9790. * This method is overidden on L2PcInstance, L2Summon and L2Npc.
  9791. * @return the skills list of this L2Character.
  9792. */
  9793. @Override
  9794. public Map<Integer, L2Skill> getSkills()
  9795. {
  9796. return _skills;
  9797. }
  9798.  
  9799. /**
  9800. * @return the current player skill in use.
  9801. */
  9802. public SkillUseHolder getCurrentSkill()
  9803. {
  9804. return _currentSkill;
  9805. }
  9806.  
  9807. /**
  9808. * Update the _currentSkill holder.
  9809. * @param skill : The skill to update for (or null)
  9810. * @param ctrlPressed : The boolean information regarding ctrl key.
  9811. * @param shiftPressed : The boolean information regarding shift key.
  9812. */
  9813. public void setCurrentSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
  9814. {
  9815. _currentSkill.setSkill(skill);
  9816. _currentSkill.setCtrlPressed(ctrlPressed);
  9817. _currentSkill.setShiftPressed(shiftPressed);
  9818. }
  9819.  
  9820. /**
  9821. * @return the current pet skill in use.
  9822. */
  9823. public SkillUseHolder getCurrentPetSkill()
  9824. {
  9825. return _currentPetSkill;
  9826. }
  9827.  
  9828. /**
  9829. * Update the _currentPetSkill holder.
  9830. * @param skill : The skill to update for (or null)
  9831. * @param ctrlPressed : The boolean information regarding ctrl key.
  9832. * @param shiftPressed : The boolean information regarding shift key.
  9833. */
  9834. public void setCurrentPetSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
  9835. {
  9836. _currentPetSkill.setSkill(skill);
  9837. _currentPetSkill.setCtrlPressed(ctrlPressed);
  9838. _currentPetSkill.setShiftPressed(shiftPressed);
  9839. }
  9840.  
  9841. /**
  9842. * @return the current queued skill in use.
  9843. */
  9844. public SkillUseHolder getQueuedSkill()
  9845. {
  9846. return _queuedSkill;
  9847. }
  9848.  
  9849. /**
  9850. * Update the _queuedSkill holder.
  9851. * @param skill : The skill to update for (or null)
  9852. * @param ctrlPressed : The boolean information regarding ctrl key.
  9853. * @param shiftPressed : The boolean information regarding shift key.
  9854. */
  9855. public void setQueuedSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
  9856. {
  9857. _queuedSkill.setSkill(skill);
  9858. _queuedSkill.setCtrlPressed(ctrlPressed);
  9859. _queuedSkill.setShiftPressed(shiftPressed);
  9860. }
  9861.  
  9862. /**
  9863. * @return punishment level of player
  9864. */
  9865. public PunishLevel getPunishLevel()
  9866. {
  9867. return _punishLevel;
  9868. }
  9869.  
  9870. /**
  9871. * @return True if player is jailed
  9872. */
  9873. public boolean isInJail()
  9874. {
  9875. return _punishLevel == PunishLevel.JAIL;
  9876. }
  9877.  
  9878. /**
  9879. * @return True if player is chat banned
  9880. */
  9881. public boolean isChatBanned()
  9882. {
  9883. return _punishLevel == PunishLevel.CHAT;
  9884. }
  9885.  
  9886. public void setPunishLevel(int state)
  9887. {
  9888. switch (state)
  9889. {
  9890. case 0:
  9891. _punishLevel = PunishLevel.NONE;
  9892. break;
  9893. case 1:
  9894. _punishLevel = PunishLevel.CHAT;
  9895. break;
  9896. case 2:
  9897. _punishLevel = PunishLevel.JAIL;
  9898. break;
  9899. case 3:
  9900. _punishLevel = PunishLevel.CHAR;
  9901. break;
  9902. case 4:
  9903. _punishLevel = PunishLevel.ACC;
  9904. break;
  9905. }
  9906. }
  9907.  
  9908. /**
  9909. * Sets punish level for player based on delay
  9910. * @param state
  9911. * @param delayInMinutes -- 0 for infinite
  9912. */
  9913. public void setPunishLevel(PunishLevel state, int delayInMinutes)
  9914. {
  9915. long delayInMilliseconds = delayInMinutes * 60000L;
  9916. switch (state)
  9917. {
  9918. case NONE: // Remove Punishments
  9919. {
  9920. switch (_punishLevel)
  9921. {
  9922. case CHAT:
  9923. {
  9924. _punishLevel = state;
  9925. stopPunishTask(true);
  9926. sendPacket(new EtcStatusUpdate(this));
  9927. sendMessage("Chatting is now available.");
  9928. sendPacket(new PlaySound("systemmsg_e.345"));
  9929. break;
  9930. }
  9931. case JAIL:
  9932. {
  9933. _punishLevel = state;
  9934.  
  9935. // Open a Html message to inform the player
  9936. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  9937. html.setFile("data/html/jail_out.htm");
  9938. sendPacket(html);
  9939. // RnP (del jailo 13 tvt)
  9940. if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(getObjectId()))
  9941. {
  9942. TvTEvent.removeParticipant(getObjectId());
  9943. }
  9944.  
  9945. if (!DMEvent.isInactive() && DMEvent.isPlayerParticipant(getObjectId()))
  9946. {
  9947. DMEvent.removeParticipant(this);
  9948. }
  9949.  
  9950. stopPunishTask(true);
  9951. teleToLocation(17836, 170178, -3507, 20); // Floran village
  9952. break;
  9953. }
  9954. }
  9955. break;
  9956. }
  9957. case CHAT: // Chat ban
  9958. {
  9959. // not allow player to escape jail using chat ban
  9960. if (_punishLevel == PunishLevel.JAIL)
  9961. break;
  9962.  
  9963. _punishLevel = state;
  9964. _punishTimer = 0;
  9965. sendPacket(new EtcStatusUpdate(this));
  9966.  
  9967. // Remove the task if any
  9968. stopPunishTask(false);
  9969.  
  9970. if (delayInMinutes > 0)
  9971. {
  9972. _punishTimer = delayInMilliseconds;
  9973.  
  9974. // start the countdown
  9975. _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  9976. {
  9977. @Override
  9978. public void run()
  9979. {
  9980. setPunishLevel(PunishLevel.NONE, 0);
  9981. }
  9982. }, _punishTimer);
  9983. sendMessage("Chatting has been suspended for " + delayInMinutes + " minute(s).");
  9984. }
  9985. else
  9986. sendMessage("Chatting has been suspended.");
  9987.  
  9988. // Send same sound packet in both "delay" cases.
  9989. sendPacket(new PlaySound("systemmsg_e.346"));
  9990. break;
  9991.  
  9992. }
  9993. case JAIL: // Jail Player
  9994. {
  9995. _punishLevel = state;
  9996. _punishTimer = 0;
  9997.  
  9998. // Remove the task if any
  9999. stopPunishTask(false);
  10000.  
  10001. if (delayInMinutes > 0)
  10002. {
  10003. _punishTimer = delayInMilliseconds;
  10004.  
  10005. // start the countdown
  10006. _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  10007. {
  10008. @Override
  10009. public void run()
  10010. {
  10011. setPunishLevel(PunishLevel.NONE, 0);
  10012. }
  10013. }, _punishTimer);
  10014. sendMessage("You are jailed for " + delayInMinutes + " minutes.");
  10015. }
  10016.  
  10017. if (OlympiadManager.getInstance().isRegisteredInComp(this))
  10018. OlympiadManager.getInstance().removeDisconnectedCompetitor(this);
  10019.  
  10020. // Open a Html message to inform the player
  10021. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  10022. html.setFile("data/html/jail_in.htm");
  10023. sendPacket(html);
  10024.  
  10025. setIsIn7sDungeon(false);
  10026. teleToLocation(-114356, -249645, -2984, 0); // Jail
  10027. break;
  10028. }
  10029. case CHAR: // Ban Character
  10030. {
  10031. setAccessLevel(-100);
  10032. logout();
  10033. break;
  10034. }
  10035. case ACC: // Ban Account
  10036. {
  10037. setAccountAccesslevel(-100);
  10038. logout();
  10039. break;
  10040. }
  10041. default:
  10042. {
  10043. _punishLevel = state;
  10044. break;
  10045. }
  10046. }
  10047.  
  10048. // store in database
  10049. storeCharBase();
  10050. }
  10051.  
  10052. public long getPunishTimer()
  10053. {
  10054. return _punishTimer;
  10055. }
  10056.  
  10057. public void setPunishTimer(long time)
  10058. {
  10059. _punishTimer = time;
  10060. }
  10061.  
  10062. private void updatePunishState()
  10063. {
  10064. if (getPunishLevel() != PunishLevel.NONE)
  10065. {
  10066. // If punish timer exists, restart punishtask.
  10067. if (_punishTimer > 0)
  10068. {
  10069. _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  10070. {
  10071. @Override
  10072. public void run()
  10073. {
  10074. setPunishLevel(PunishLevel.NONE, 0);
  10075. }
  10076. }, _punishTimer);
  10077. sendMessage("You are still " + getPunishLevel().string() + " for " + Math.round(_punishTimer / 60000f) + " minutes.");
  10078. }
  10079. if (getPunishLevel() == PunishLevel.JAIL)
  10080. {
  10081. // If player escaped, put him back in jail
  10082. if (!isInsideZone(ZoneId.JAIL))
  10083. teleToLocation(-114356, -249645, -2984, 20);
  10084. }
  10085. }
  10086. }
  10087.  
  10088. public void stopPunishTask(boolean save)
  10089. {
  10090. if (_punishTask != null)
  10091. {
  10092. if (save)
  10093. {
  10094. long delay = _punishTask.getDelay(TimeUnit.MILLISECONDS);
  10095. if (delay < 0)
  10096. delay = 0;
  10097. setPunishTimer(delay);
  10098. }
  10099. _punishTask.cancel(false);
  10100. _punishTask = null;
  10101. }
  10102. }
  10103.  
  10104. public int getPowerGrade()
  10105. {
  10106. return _powerGrade;
  10107. }
  10108.  
  10109. public void setPowerGrade(int power)
  10110. {
  10111. _powerGrade = power;
  10112. }
  10113.  
  10114. public void updatecolorSystem()
  10115. {
  10116. if(isdonator())
  10117. return;
  10118. // Color System checks - Start
  10119. // Check if the custom PvP and PK color systems are enabled and if so check the character's counters
  10120. // and apply any color changes that must be done. Thankz Kidzor
  10121. /** KidZor: Ammount 1 **/
  10122. if (getPvpKills() >= Config.PVP_AMOUNT1 && Config.PVP_COLOR_SYSTEM_ENABLED)
  10123. updatePvPColor(getPvpKills());
  10124. if (getPkKills() >= Config.PK_AMOUNT1 && Config.PK_COLOR_SYSTEM_ENABLED)
  10125. updatePkColor(getPkKills());
  10126.  
  10127. /** KidZor: Ammount 2 **/
  10128. if (getPvpKills() >= Config.PVP_AMOUNT2 && Config.PVP_COLOR_SYSTEM_ENABLED)
  10129. updatePvPColor(getPvpKills());
  10130. if (getPkKills() >= Config.PK_AMOUNT2 && Config.PK_COLOR_SYSTEM_ENABLED)
  10131. updatePkColor(getPkKills());
  10132.  
  10133. /** KidZor: Ammount 3 **/
  10134. if (getPvpKills() >= Config.PVP_AMOUNT3 && Config.PVP_COLOR_SYSTEM_ENABLED)
  10135. updatePvPColor(getPvpKills());
  10136. if (getPkKills() >= Config.PK_AMOUNT3 && Config.PK_COLOR_SYSTEM_ENABLED)
  10137. updatePkColor(getPkKills());
  10138.  
  10139. /** KidZor: Ammount 4 **/
  10140. if (getPvpKills() >= Config.PVP_AMOUNT4 && Config.PVP_COLOR_SYSTEM_ENABLED)
  10141. updatePvPColor(getPvpKills());
  10142. if (getPkKills() >= Config.PK_AMOUNT4 && Config.PK_COLOR_SYSTEM_ENABLED)
  10143. updatePkColor(getPkKills());
  10144.  
  10145. /** KidZor: Ammount 5 **/
  10146. if (getPvpKills() >= Config.PVP_AMOUNT5 && Config.PVP_COLOR_SYSTEM_ENABLED)
  10147. updatePvPColor(getPvpKills());
  10148. if (getPkKills() >= Config.PK_AMOUNT5 && Config.PK_COLOR_SYSTEM_ENABLED)
  10149. updatePkColor(getPkKills());
  10150. // Color System checks - End
  10151. broadcastUserInfo();
  10152. }
  10153. public boolean isCursedWeaponEquipped()
  10154. {
  10155. return _cursedWeaponEquippedId != 0;
  10156. }
  10157.  
  10158. public void setCursedWeaponEquippedId(int value)
  10159. {
  10160. _cursedWeaponEquippedId = value;
  10161. }
  10162.  
  10163. public int getCursedWeaponEquippedId()
  10164. {
  10165. return _cursedWeaponEquippedId;
  10166. }
  10167.  
  10168. public void shortBuffStatusUpdate(int magicId, int level, int time)
  10169. {
  10170. if (_shortBuffTask != null)
  10171. {
  10172. _shortBuffTask.cancel(false);
  10173. _shortBuffTask = null;
  10174. }
  10175.  
  10176. _shortBuffTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  10177. {
  10178. @Override
  10179. public void run()
  10180. {
  10181. sendPacket(new ShortBuffStatusUpdate(0, 0, 0));
  10182. setShortBuffTaskSkillId(0);
  10183. }
  10184. }, time * 1000);
  10185. setShortBuffTaskSkillId(magicId);
  10186.  
  10187. sendPacket(new ShortBuffStatusUpdate(magicId, level, time));
  10188. }
  10189.  
  10190. public int getShortBuffTaskSkillId()
  10191. {
  10192. return _shortBuffTaskSkillId;
  10193. }
  10194.  
  10195. public int getOriginalNameColorTvT()
  10196. {
  10197. return _originalNameColorTvT;
  10198. }
  10199.  
  10200. public void setShortBuffTaskSkillId(int id)
  10201. {
  10202. _shortBuffTaskSkillId = id;
  10203. }
  10204.  
  10205. public int getDeathPenaltyBuffLevel()
  10206. {
  10207. return _deathPenaltyBuffLevel;
  10208. }
  10209.  
  10210. public void setDeathPenaltyBuffLevel(int level)
  10211. {
  10212. _deathPenaltyBuffLevel = level;
  10213. }
  10214.  
  10215. public void calculateDeathPenaltyBuffLevel(L2Character killer)
  10216. {
  10217. if (_deathPenaltyBuffLevel >= 15) // maximum level reached
  10218. return;
  10219. // RnP (POVIS PAMIRSO 14 DEL KARMOS GAVIMO AR KASKAS)
  10220. if ((getKarma() > 0 || Rnd.get(1, 100) <= Config.DEATH_PENALTY_CHANCE) && !(killer instanceof L2PcInstance) && !isGM() && !(getCharmOfLuck() && (killer == null || killer.isRaid())) && !isPhoenixBlessed() && !(TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId())) && !(DMEvent.isStarted() && DMEvent.isPlayerParticipant(getObjectId())) && !(isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.SIEGE)))
  10221. {
  10222. if (_deathPenaltyBuffLevel != 0)
  10223. {
  10224. final L2Skill skill = SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel);
  10225. if (skill != null)
  10226. removeSkill(skill, true);
  10227. }
  10228.  
  10229. _deathPenaltyBuffLevel++;
  10230.  
  10231. addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
  10232. sendPacket(new EtcStatusUpdate(this));
  10233. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DEATH_PENALTY_LEVEL_S1_ADDED).addNumber(_deathPenaltyBuffLevel));
  10234. }
  10235. }
  10236.  
  10237. public void reduceDeathPenaltyBuffLevel()
  10238. {
  10239. if (_deathPenaltyBuffLevel <= 0)
  10240. return;
  10241.  
  10242. final L2Skill skill = SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel);
  10243. if (skill != null)
  10244. removeSkill(skill, true);
  10245.  
  10246. _deathPenaltyBuffLevel--;
  10247.  
  10248. if (_deathPenaltyBuffLevel > 0)
  10249. {
  10250. addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
  10251. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DEATH_PENALTY_LEVEL_S1_ADDED).addNumber(_deathPenaltyBuffLevel));
  10252. }
  10253. else
  10254. sendPacket(SystemMessageId.DEATH_PENALTY_LIFTED);
  10255.  
  10256. sendPacket(new EtcStatusUpdate(this));
  10257. }
  10258.  
  10259. public void restoreDeathPenaltyBuffLevel()
  10260. {
  10261. if (_deathPenaltyBuffLevel > 0)
  10262. addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
  10263. }
  10264.  
  10265. private final Map<Integer, TimeStamp> _reuseTimeStamps = new ConcurrentHashMap<>();
  10266.  
  10267. public Collection<TimeStamp> getReuseTimeStamps()
  10268. {
  10269. return _reuseTimeStamps.values();
  10270. }
  10271.  
  10272. public Map<Integer, TimeStamp> getReuseTimeStamp()
  10273. {
  10274. return _reuseTimeStamps;
  10275. }
  10276.  
  10277. /**
  10278. * Simple class containing all neccessary information to maintain valid timestamps and reuse for skills upon relog. Filter this carefully as it becomes redundant to store reuse for small delays.
  10279. * @author Yesod
  10280. */
  10281. public static class TimeStamp
  10282. {
  10283. private final int _skillId;
  10284. private final int _skillLvl;
  10285. private final long _reuse;
  10286. private final long _stamp;
  10287.  
  10288. public TimeStamp(L2Skill skill, long reuse)
  10289. {
  10290. _skillId = skill.getId();
  10291. _skillLvl = skill.getLevel();
  10292. _reuse = reuse;
  10293. _stamp = System.currentTimeMillis() + reuse;
  10294. }
  10295.  
  10296. public TimeStamp(L2Skill skill, long reuse, long systime)
  10297. {
  10298. _skillId = skill.getId();
  10299. _skillLvl = skill.getLevel();
  10300. _reuse = reuse;
  10301. _stamp = systime;
  10302. }
  10303.  
  10304. public long getStamp()
  10305. {
  10306. return _stamp;
  10307. }
  10308.  
  10309. public int getSkillId()
  10310. {
  10311. return _skillId;
  10312. }
  10313.  
  10314. public int getSkillLvl()
  10315. {
  10316. return _skillLvl;
  10317. }
  10318.  
  10319. public long getReuse()
  10320. {
  10321. return _reuse;
  10322. }
  10323.  
  10324. public long getRemaining()
  10325. {
  10326. return Math.max(_stamp - System.currentTimeMillis(), 0);
  10327. }
  10328.  
  10329. public boolean hasNotPassed()
  10330. {
  10331. return System.currentTimeMillis() < _stamp;
  10332. }
  10333. }
  10334.  
  10335. /**
  10336. * Index according to skill id the current timestamp of use.
  10337. * @param skill
  10338. * @param reuse delay
  10339. */
  10340. @Override
  10341. public void addTimeStamp(L2Skill skill, long reuse)
  10342. {
  10343. _reuseTimeStamps.put(skill.getReuseHashCode(), new TimeStamp(skill, reuse));
  10344. }
  10345.  
  10346. /**
  10347. * Index according to skill this TimeStamp instance for restoration purposes only.
  10348. * @param skill
  10349. * @param reuse
  10350. * @param systime
  10351. */
  10352. public void addTimeStamp(L2Skill skill, long reuse, long systime)
  10353. {
  10354. _reuseTimeStamps.put(skill.getReuseHashCode(), new TimeStamp(skill, reuse, systime));
  10355. }
  10356.  
  10357. @Override
  10358. public L2PcInstance getActingPlayer()
  10359. {
  10360. return this;
  10361. }
  10362.  
  10363. @Override
  10364. public final void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  10365. {
  10366. // Check if hit is missed
  10367. if (miss)
  10368. {
  10369. sendPacket(SystemMessageId.MISSED_TARGET);
  10370. return;
  10371. }
  10372.  
  10373. // Check if hit is critical
  10374. if (pcrit)
  10375. sendPacket(SystemMessageId.CRITICAL_HIT);
  10376. if (mcrit)
  10377. sendPacket(SystemMessageId.CRITICAL_HIT_MAGIC);
  10378.  
  10379. if (target.isInvul())
  10380. {
  10381. if (target.isParalyzed())
  10382. sendPacket(SystemMessageId.OPPONENT_PETRIFIED);
  10383. else
  10384. sendPacket(SystemMessageId.ATTACK_WAS_BLOCKED);
  10385. }
  10386. else
  10387. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DID_S1_DMG).addNumber(damage));
  10388.  
  10389. if (isInOlympiadMode() && target instanceof L2PcInstance && ((L2PcInstance) target).isInOlympiadMode() && ((L2PcInstance) target).getOlympiadGameId() == getOlympiadGameId())
  10390. OlympiadGameManager.getInstance().notifyCompetitorDamage(this, damage);
  10391. }
  10392.  
  10393. public void checkItemRestriction()
  10394. {
  10395. for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
  10396. {
  10397. ItemInstance equippedItem = getInventory().getPaperdollItem(i);
  10398. if (equippedItem != null && !equippedItem.getItem().checkCondition(this, this, false))
  10399. {
  10400. getInventory().unEquipItemInSlot(i);
  10401.  
  10402. InventoryUpdate iu = new InventoryUpdate();
  10403. iu.addModifiedItem(equippedItem);
  10404. sendPacket(iu);
  10405.  
  10406. SystemMessage sm = null;
  10407. if (equippedItem.getEnchantLevel() > 0)
  10408. {
  10409. sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  10410. sm.addNumber(equippedItem.getEnchantLevel());
  10411. sm.addItemName(equippedItem);
  10412. }
  10413. else
  10414. {
  10415. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED);
  10416. sm.addItemName(equippedItem);
  10417. }
  10418. sendPacket(sm);
  10419. }
  10420. }
  10421. }
  10422.  
  10423. public void enteredNoLanding(int delay)
  10424. {
  10425. _dismountTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  10426. {
  10427. @Override
  10428. public void run()
  10429. {
  10430. dismount();
  10431. }
  10432. }, delay * 1000);
  10433. }
  10434.  
  10435. public void exitedNoLanding()
  10436. {
  10437. if (_dismountTask != null)
  10438. {
  10439. _dismountTask.cancel(true);
  10440. _dismountTask = null;
  10441. }
  10442. }
  10443.  
  10444. public void setIsInSiege(boolean b)
  10445. {
  10446. _isInSiege = b;
  10447. }
  10448.  
  10449. public boolean isInSiege()
  10450. {
  10451. return _isInSiege;
  10452. }
  10453.  
  10454. /**
  10455. * Remove player from BossZones (used on char logout/exit)
  10456. */
  10457. public void removeFromBossZone()
  10458. {
  10459. for (L2BossZone _zone : ZoneManager.getInstance().getAllZones(L2BossZone.class))
  10460. _zone.removePlayer(this);
  10461. }
  10462.  
  10463. /**
  10464. * @return the number of charges this L2PcInstance got.
  10465. */
  10466. public int getCharges()
  10467. {
  10468. return _charges.get();
  10469. }
  10470.  
  10471. public void increaseCharges(int count, int max)
  10472. {
  10473. if (_charges.get() >= max)
  10474. {
  10475. sendPacket(SystemMessageId.FORCE_MAXLEVEL_REACHED);
  10476. return;
  10477. }
  10478.  
  10479. restartChargeTask();
  10480.  
  10481. if (_charges.addAndGet(count) >= max)
  10482. {
  10483. _charges.set(max);
  10484. sendPacket(SystemMessageId.FORCE_MAXLEVEL_REACHED);
  10485. }
  10486. else
  10487. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FORCE_INCREASED_TO_S1).addNumber(_charges.get()));
  10488.  
  10489. sendPacket(new EtcStatusUpdate(this));
  10490. }
  10491.  
  10492. public boolean decreaseCharges(int count)
  10493. {
  10494. if (_charges.get() < count)
  10495. return false;
  10496.  
  10497. if (_charges.addAndGet(-count) == 0)
  10498. stopChargeTask();
  10499. else
  10500. restartChargeTask();
  10501.  
  10502. sendPacket(new EtcStatusUpdate(this));
  10503. return true;
  10504. }
  10505.  
  10506. public void clearCharges()
  10507. {
  10508. _charges.set(0);
  10509. sendPacket(new EtcStatusUpdate(this));
  10510. }
  10511.  
  10512. /**
  10513. * Starts/Restarts the ChargeTask to Clear Charges after 10 Mins.
  10514. */
  10515. private void restartChargeTask()
  10516. {
  10517. if (_chargeTask != null)
  10518. {
  10519. _chargeTask.cancel(false);
  10520. _chargeTask = null;
  10521. }
  10522.  
  10523. _chargeTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  10524. {
  10525. @Override
  10526. public void run()
  10527. {
  10528. clearCharges();
  10529. }
  10530. }, 600000);
  10531. }
  10532.  
  10533. /**
  10534. * Stops the Charges Clearing Task.
  10535. */
  10536. public void stopChargeTask()
  10537. {
  10538. if (_chargeTask != null)
  10539. {
  10540. _chargeTask.cancel(false);
  10541. _chargeTask = null;
  10542. }
  10543. }
  10544.  
  10545. /**
  10546. * Signets check used to valid who is affected when he entered in the aoe effect.
  10547. * @param cha The target to make checks on.
  10548. * @return true if player can attack the target.
  10549. */
  10550. public boolean canAttackCharacter(L2Character cha)
  10551. {
  10552. if (cha instanceof L2Attackable)
  10553. return true;
  10554.  
  10555. if (cha instanceof L2Playable)
  10556. {
  10557. if (cha.isInArena())
  10558. return true;
  10559.  
  10560. final L2PcInstance target = cha.getActingPlayer();
  10561.  
  10562. if (isInDuel() && target.isInDuel() && target.getDuelId() == getDuelId())
  10563. return true;
  10564.  
  10565. if (isInParty() && target.isInParty())
  10566. {
  10567. if (getParty() == target.getParty())
  10568. return false;
  10569.  
  10570. if ((getParty().getCommandChannel() != null || target.getParty().getCommandChannel() != null) && (getParty().getCommandChannel() == target.getParty().getCommandChannel()))
  10571. return false;
  10572. }
  10573.  
  10574. if (getClan() != null && target.getClan() != null)
  10575. {
  10576. if (getClanId() == target.getClanId())
  10577. return false;
  10578.  
  10579. if ((getAllyId() > 0 || target.getAllyId() > 0) && getAllyId() == target.getAllyId())
  10580. return false;
  10581.  
  10582. if (getClan().isAtWarWith(target.getClanId()))
  10583. return true;
  10584. }
  10585. else
  10586. {
  10587. if (target.getPvpFlag() == 0 && target.getKarma() == 0)
  10588. return false;
  10589. }
  10590. }
  10591. return true;
  10592. }
  10593.  
  10594. public static void teleToTarget(L2PcInstance targetChar, L2PcInstance summonerChar, L2Skill summonSkill)
  10595. {
  10596. if (targetChar == null || summonerChar == null || summonSkill == null)
  10597. return;
  10598.  
  10599. if (!checkSummonerStatus(summonerChar))
  10600. return;
  10601.  
  10602. if (!checkSummonTargetStatus(targetChar, summonerChar))
  10603. return;
  10604.  
  10605. final int itemConsumeId = summonSkill.getTargetConsumeId();
  10606. final int itemConsumeCount = summonSkill.getTargetConsume();
  10607.  
  10608. if (itemConsumeId != 0 && itemConsumeCount != 0)
  10609. {
  10610. if (targetChar.getInventory().getInventoryItemCount(itemConsumeId, -1) < itemConsumeCount)
  10611. {
  10612. targetChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_REQUIRED_FOR_SUMMONING).addItemName(summonSkill.getTargetConsumeId()));
  10613. return;
  10614. }
  10615.  
  10616. targetChar.destroyItemByItemId("Consume", itemConsumeId, itemConsumeCount, targetChar, true);
  10617. }
  10618. targetChar.teleToLocation(summonerChar.getX(), summonerChar.getY(), summonerChar.getZ(), 20);
  10619. }
  10620.  
  10621. public static boolean checkSummonerStatus(L2PcInstance summonerChar)
  10622. {
  10623. if (summonerChar == null)
  10624. return false;
  10625. // RnP (CIA DEL SUMMONU VEL RnP 15)
  10626. if (!TvTEvent.onEscapeUse(summonerChar.getObjectId()) || !DMEvent.onEscapeUse(summonerChar.getObjectId()))
  10627. return false;
  10628.  
  10629. if (summonerChar.isInOlympiadMode() || summonerChar.inObserverMode() || summonerChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND) || summonerChar.isMounted())
  10630. {
  10631. summonerChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  10632. return false;
  10633. }
  10634.  
  10635. return true;
  10636. }
  10637.  
  10638. public static boolean checkSummonTargetStatus(L2Object target, L2PcInstance summonerChar)
  10639. {
  10640. if (target == null || !(target instanceof L2PcInstance))
  10641. return false;
  10642.  
  10643. L2PcInstance targetChar = (L2PcInstance) target;
  10644.  
  10645. // RnP (CIA DEL SUMMONU tvt 16)
  10646. if (!TvTEvent.onEscapeUse(targetChar.getObjectId()) || !DMEvent.onEscapeUse(targetChar.getObjectId()))
  10647. {
  10648. summonerChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  10649. return false;
  10650. }
  10651. // Rnp (Cia DEL SUMMONU TVT 17 Povis pamirses buvo)
  10652. if (!TvTEvent.onEscapeUse(summonerChar.getObjectId()))
  10653. {
  10654. summonerChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  10655. return false;
  10656. }
  10657.  
  10658. if (targetChar.isAlikeDead())
  10659. {
  10660. summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
  10661. return false;
  10662. }
  10663.  
  10664. if (targetChar.isInStoreMode())
  10665. {
  10666. summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
  10667. return false;
  10668. }
  10669.  
  10670. if (targetChar.isRooted() || targetChar.isInCombat())
  10671. {
  10672. summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
  10673. return false;
  10674. }
  10675.  
  10676. if (targetChar.isInOlympiadMode())
  10677. {
  10678. summonerChar.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD);
  10679. return false;
  10680. }
  10681.  
  10682. if (targetChar.isFestivalParticipant() || targetChar.isMounted())
  10683. {
  10684. summonerChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
  10685. return false;
  10686. }
  10687.  
  10688. if (targetChar.inObserverMode() || targetChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
  10689. {
  10690. summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IN_SUMMON_BLOCKING_AREA).addCharName(targetChar));
  10691. return false;
  10692. }
  10693.  
  10694. return true;
  10695. }
  10696.  
  10697. public final int getClientX()
  10698. {
  10699. return _clientX;
  10700. }
  10701.  
  10702. public final int getClientY()
  10703. {
  10704. return _clientY;
  10705. }
  10706.  
  10707. public final int getClientZ()
  10708. {
  10709. return _clientZ;
  10710. }
  10711.  
  10712. public final int getClientHeading()
  10713. {
  10714. return _clientHeading;
  10715. }
  10716.  
  10717. public final void setClientX(int val)
  10718. {
  10719. _clientX = val;
  10720. }
  10721.  
  10722. public final void setClientY(int val)
  10723. {
  10724. _clientY = val;
  10725. }
  10726.  
  10727. public final void setClientZ(int val)
  10728. {
  10729. _clientZ = val;
  10730. }
  10731.  
  10732. public final void setClientHeading(int val)
  10733. {
  10734. _clientHeading = val;
  10735. }
  10736.  
  10737. /**
  10738. * @return the mailPosition.
  10739. */
  10740. public int getMailPosition()
  10741. {
  10742. return _mailPosition;
  10743. }
  10744.  
  10745. /**
  10746. * @param mailPosition The mailPosition to set.
  10747. */
  10748. public void setMailPosition(int mailPosition)
  10749. {
  10750. _mailPosition = mailPosition;
  10751. }
  10752.  
  10753. /**
  10754. * @param z
  10755. * @return true if character falling now On the start of fall return false for correct coord sync !
  10756. */
  10757. public final boolean isFalling(int z)
  10758. {
  10759. if (isDead() || isFlying() || isInsideZone(ZoneId.WATER))
  10760. return false;
  10761.  
  10762. if (System.currentTimeMillis() < _fallingTimestamp)
  10763. return true;
  10764.  
  10765. final int deltaZ = getZ() - z;
  10766. if (deltaZ <= getBaseTemplate().getFallHeight())
  10767. return false;
  10768.  
  10769. final int damage = (int) Formulas.calcFallDam(this, deltaZ);
  10770. if (damage > 0)
  10771. {
  10772. reduceCurrentHp(Math.min(damage, getCurrentHp() - 1), null, false, true, null);
  10773. sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FALL_DAMAGE_S1).addNumber(damage));
  10774. }
  10775.  
  10776. setFalling();
  10777.  
  10778. return false;
  10779. }
  10780.  
  10781. /**
  10782. * Set falling timestamp
  10783. */
  10784. public final void setFalling()
  10785. {
  10786. _fallingTimestamp = System.currentTimeMillis() + FALLING_VALIDATION_DELAY;
  10787. }
  10788.  
  10789. public boolean isAllowedToEnchantSkills()
  10790. {
  10791. if (isLocked())
  10792. return false;
  10793.  
  10794. if (AttackStanceTaskManager.getInstance().isInAttackStance(this))
  10795. return false;
  10796.  
  10797. if (isCastingNow() || isCastingSimultaneouslyNow())
  10798. return false;
  10799.  
  10800. if (isInBoat())
  10801. return false;
  10802.  
  10803. return true;
  10804. }
  10805.  
  10806. public List<Integer> getFriendList()
  10807. {
  10808. return _friendList;
  10809. }
  10810.  
  10811. public void selectFriend(Integer friendId)
  10812. {
  10813. if (!_selectedFriendList.contains(friendId))
  10814. _selectedFriendList.add(friendId);
  10815. }
  10816.  
  10817. public void deselectFriend(Integer friendId)
  10818. {
  10819. if (_selectedFriendList.contains(friendId))
  10820. _selectedFriendList.remove(friendId);
  10821. }
  10822.  
  10823. public List<Integer> getSelectedFriendList()
  10824. {
  10825. return _selectedFriendList;
  10826. }
  10827.  
  10828. private void restoreFriendList()
  10829. {
  10830. _friendList.clear();
  10831.  
  10832. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  10833. {
  10834. PreparedStatement statement = con.prepareStatement("SELECT friend_id FROM character_friends WHERE char_id = ? AND relation = 0");
  10835. statement.setInt(1, getObjectId());
  10836. ResultSet rset = statement.executeQuery();
  10837.  
  10838. int friendId;
  10839. while (rset.next())
  10840. {
  10841. friendId = rset.getInt("friend_id");
  10842. if (friendId == getObjectId())
  10843. continue;
  10844.  
  10845. _friendList.add(friendId);
  10846. }
  10847.  
  10848. rset.close();
  10849. statement.close();
  10850. }
  10851. catch (Exception e)
  10852. {
  10853. _log.log(Level.WARNING, "Error found in " + getName() + "'s friendlist: " + e.getMessage(), e);
  10854. }
  10855. }
  10856.  
  10857. private void notifyFriends(boolean login)
  10858. {
  10859. for (int id : _friendList)
  10860. {
  10861. L2PcInstance friend = L2World.getInstance().getPlayer(id);
  10862. if (friend != null)
  10863. {
  10864. friend.sendPacket(new FriendList(friend));
  10865.  
  10866. if (login)
  10867. friend.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FRIEND_S1_HAS_LOGGED_IN).addPcName(this));
  10868. }
  10869. }
  10870. }
  10871.  
  10872. public void selectBlock(Integer friendId)
  10873. {
  10874. if (!_selectedBlocksList.contains(friendId))
  10875. _selectedBlocksList.add(friendId);
  10876. }
  10877.  
  10878. public void deselectBlock(Integer friendId)
  10879. {
  10880. if (_selectedBlocksList.contains(friendId))
  10881. _selectedBlocksList.remove(friendId);
  10882. }
  10883.  
  10884. public List<Integer> getSelectedBlocksList()
  10885. {
  10886. return _selectedBlocksList;
  10887. }
  10888.  
  10889. @Override
  10890. public void broadcastRelationsChanges()
  10891. {
  10892. for (L2PcInstance player : getKnownList().getKnownType(L2PcInstance.class))
  10893. {
  10894. player.sendPacket(new RelationChanged(this, getRelation(player), isAutoAttackable(player)));
  10895. if (getPet() != null)
  10896. player.sendPacket(new RelationChanged(getPet(), getRelation(player), isAutoAttackable(player)));
  10897. }
  10898. }
  10899.  
  10900. @Override
  10901. public void sendInfo(L2PcInstance activeChar)
  10902. {
  10903. if (isInBoat())
  10904. getPosition().set(getBoat().getPosition());
  10905.  
  10906. if (getPolyType() == PolyType.NPC)
  10907. activeChar.sendPacket(new AbstractNpcInfo.PcMorphInfo(this, getPolyTemplate()));
  10908. else
  10909. {
  10910. activeChar.sendPacket(new CharInfo(this));
  10911.  
  10912. if (isSeated())
  10913. {
  10914. final L2Object object = L2World.getInstance().getObject(_throneId);
  10915. if (object instanceof L2StaticObjectInstance)
  10916. activeChar.sendPacket(new ChairSit(getObjectId(), ((L2StaticObjectInstance) object).getStaticObjectId()));
  10917. }
  10918. }
  10919.  
  10920. final int relation1 = getRelation(activeChar);
  10921. activeChar.sendPacket(new RelationChanged(this, relation1, isAutoAttackable(activeChar)));
  10922. if (getPet() != null)
  10923. activeChar.sendPacket(new RelationChanged(getPet(), relation1, isAutoAttackable(activeChar)));
  10924.  
  10925. final int relation2 = activeChar.getRelation(this);
  10926. sendPacket(new RelationChanged(activeChar, relation2, activeChar.isAutoAttackable(this)));
  10927. if (activeChar.getPet() != null)
  10928. sendPacket(new RelationChanged(activeChar.getPet(), relation2, activeChar.isAutoAttackable(this)));
  10929.  
  10930. if (isInBoat())
  10931. activeChar.sendPacket(new GetOnVehicle(getObjectId(), getBoat().getObjectId(), getVehiclePosition()));
  10932.  
  10933. switch (getStoreType())
  10934. {
  10935. case SELL:
  10936. case PACKAGE_SELL:
  10937. activeChar.sendPacket(new PrivateStoreMsgSell(this));
  10938. break;
  10939.  
  10940. case BUY:
  10941. activeChar.sendPacket(new PrivateStoreMsgBuy(this));
  10942. break;
  10943.  
  10944. case MANUFACTURE:
  10945. activeChar.sendPacket(new RecipeShopMsg(this));
  10946. break;
  10947. }
  10948. }
  10949.  
  10950. @Override
  10951. public double getCollisionRadius()
  10952. {
  10953. return getBaseTemplate().getCollisionRadiusBySex(getAppearance().getSex());
  10954. }
  10955.  
  10956. @Override
  10957. public double getCollisionHeight()
  10958. {
  10959. return getBaseTemplate().getCollisionHeightBySex(getAppearance().getSex());
  10960. }
  10961.  
  10962. public boolean teleportRequest(L2PcInstance requester, L2Skill skill)
  10963. {
  10964. if (_summonTargetRequest != null && requester != null)
  10965. return false;
  10966.  
  10967. _summonTargetRequest = requester;
  10968. _summonSkillRequest = skill;
  10969. return true;
  10970. }
  10971.  
  10972. public void teleportAnswer(int answer, int requesterId)
  10973. {
  10974. if (_summonTargetRequest == null)
  10975. return;
  10976.  
  10977. if (answer == 1 && _summonTargetRequest.getObjectId() == requesterId)
  10978. teleToTarget(this, _summonTargetRequest, _summonSkillRequest);
  10979.  
  10980. _summonTargetRequest = null;
  10981. _summonSkillRequest = null;
  10982. }
  10983.  
  10984. public void activateGate(int answer, int type)
  10985. {
  10986. if (_requestedGate == null)
  10987. return;
  10988.  
  10989. if (answer == 1 && getTarget() == _requestedGate)
  10990. {
  10991. if (type == 1)
  10992. _requestedGate.openMe();
  10993. else if (type == 0)
  10994. _requestedGate.closeMe();
  10995. }
  10996.  
  10997. _requestedGate = null;
  10998. }
  10999.  
  11000. public void setRequestedGate(L2DoorInstance door)
  11001. {
  11002. _requestedGate = door;
  11003. }
  11004.  
  11005. @Override
  11006. public boolean polymorph(PolyType type, int npcId)
  11007. {
  11008. if (super.polymorph(type, npcId))
  11009. {
  11010. sendPacket(new UserInfo(this));
  11011. return true;
  11012. }
  11013. return false;
  11014. }
  11015.  
  11016. @Override
  11017. public void unpolymorph()
  11018. {
  11019. super.unpolymorph();
  11020. sendPacket(new UserInfo(this));
  11021. }
  11022.  
  11023. @Override
  11024. protected void badCoords()
  11025. {
  11026. teleToLocation(0, 0, 0, 0);
  11027. sendMessage("Error with your coords, Please ask a GM for help!");
  11028. }
  11029.  
  11030. private boolean _isVoting = false;
  11031.  
  11032. public final boolean isVoting()
  11033. {
  11034. return _isVoting;
  11035. }
  11036.  
  11037. public final void setIsVoting(boolean value)
  11038. {
  11039. _isVoting = value;
  11040. }
  11041.  
  11042. /** The _vote timestamp. */
  11043. private long _voteTimestamp = 0;
  11044.  
  11045. /**
  11046. * Gets the vote timestamp.
  11047. * @return the _voteTimestamp
  11048. */
  11049. public long getVoteTimestamp()
  11050. {
  11051. return _voteTimestamp;
  11052. }
  11053.  
  11054. /**
  11055. * Sets the vote timestamp.
  11056. * @param timestamp the _voteTimestamp to set
  11057. */
  11058. public void setVoteTimestamp(final long timestamp)
  11059. {
  11060. _voteTimestamp = timestamp;
  11061. }
  11062.  
  11063. /**
  11064. * Gets the vote points.
  11065. * @return the vote points
  11066. */
  11067. public int getVotePoints()
  11068. {
  11069. Connection conn = null;
  11070. int votePoints = 0;
  11071. try
  11072. {
  11073. conn = L2DatabaseFactory.getInstance().getConnection();
  11074. PreparedStatement statement;
  11075. statement = conn.prepareStatement("select votePoints from accounts where login=?");
  11076. statement.setString(1, _accountName);
  11077.  
  11078. ResultSet rset = statement.executeQuery();
  11079. while (rset.next())
  11080. {
  11081. votePoints = rset.getInt("votePoints");
  11082. }
  11083. rset.close();
  11084. rset = null;
  11085. statement.close();
  11086. statement = null;
  11087. }
  11088. catch (final Exception e)
  11089. {
  11090. e.printStackTrace();
  11091. }
  11092. finally
  11093. {
  11094. try{
  11095. conn.close();
  11096. conn = null;}catch(Exception a){}
  11097. }
  11098. return votePoints;
  11099. }
  11100.  
  11101.  
  11102. /**
  11103. * Sets the vote points.
  11104. * @param points the new vote points
  11105. */
  11106. public void setVotePoints(final int points)
  11107. {
  11108. Connection conn = null;
  11109. try
  11110. {
  11111. conn = L2DatabaseFactory.getInstance().getConnection();
  11112. PreparedStatement statement;
  11113. statement = conn.prepareStatement("update accounts set votePoints=" + points + " where login='" + _accountName + "'");
  11114. statement.execute();
  11115. statement.close();
  11116. statement = null;
  11117. }
  11118. catch (final Exception e)
  11119. {
  11120. e.printStackTrace();
  11121. }
  11122. finally
  11123. {
  11124. try{
  11125. conn.close();
  11126. conn = null;}catch(Exception a){}
  11127. }
  11128. }
  11129.  
  11130. /**
  11131. * Gets the vote time.
  11132. * @return the vote time
  11133. */
  11134. public int getVoteTime()
  11135. {
  11136. Connection conn = null;
  11137. int lastVote = 0;
  11138. try
  11139. {
  11140. conn = L2DatabaseFactory.getInstance().getConnection();
  11141. PreparedStatement statement;
  11142. statement = conn.prepareStatement("select lastVote from accounts where login=?");
  11143. statement.setString(1, _accountName);
  11144.  
  11145. ResultSet rset = statement.executeQuery();
  11146. while (rset.next())
  11147. {
  11148. lastVote = rset.getInt("lastVote");
  11149. }
  11150. rset.close();
  11151. rset = null;
  11152. statement.close();
  11153. statement = null;
  11154. }
  11155. catch (final Exception e)
  11156. {
  11157. e.printStackTrace();
  11158. }
  11159. finally
  11160. {
  11161. try{
  11162. conn.close();
  11163. conn = null;}catch(Exception a){}
  11164. }
  11165. return lastVote;
  11166. }
  11167.  
  11168. public void decryptDmChar()
  11169. {
  11170. setTitle(_originalTitle);
  11171. getAppearance().getNameColor();
  11172. }
  11173. /** CTF Engine parameters */
  11174. public int _originalNameColorDM,_originalTitleColorDM,_originalKarmaTvT,_originalKarmaDM;
  11175.  
  11176. public long getOfflineStartTime()
  11177. {
  11178. return _offlineShopStart;
  11179. }
  11180.  
  11181. public void setOfflineStartTime(long time)
  11182. {
  11183. _offlineShopStart = time;
  11184. }
  11185. /**Offline Shop*/
  11186. private long _offlineShopStart = 0;
  11187. private boolean _timeRefusal = false;
  11188.  
  11189. public boolean getTimeRefusal()
  11190. {
  11191. return _timeRefusal;
  11192. }
  11193.  
  11194. public void setTimeRefusal(boolean mode)
  11195. {
  11196. _timeRefusal = mode;
  11197. }
  11198.  
  11199. private boolean _DonateRefusal = false;
  11200.  
  11201. public void setDonateRefusal(boolean mode)
  11202. {
  11203. _DonateRefusal = mode;
  11204. }
  11205.  
  11206.  
  11207. public boolean getDonateRefusal()
  11208. {
  11209. return _DonateRefusal;
  11210. }
  11211.  
  11212. private boolean _DonateColor = false;
  11213.  
  11214. public void setdonatecolor (boolean donator)
  11215. {
  11216. _DonateColor = donator;
  11217. }
  11218.  
  11219. public boolean getDonateColor()
  11220. {
  11221. return _DonateColor;
  11222. }
  11223.  
  11224. public boolean isdonator()
  11225. {
  11226. return _donator;
  11227. }
  11228.  
  11229. public void setdonator(boolean donator)
  11230. {
  11231. _donator = donator;
  11232. }
  11233.  
  11234. private boolean _donator = false;
  11235.  
  11236. /**
  11237. * Update name title color.
  11238. */
  11239. public void updateNameTitleColor()
  11240. {
  11241. /** Updates title and name color of a donator **/
  11242. if(Config.DONATOR_NAME_COLOR_ENABLED && isdonator())
  11243. {
  11244. if(getDonateColor())
  11245. {
  11246. getAppearance().setNameColor(Config.DONATOR_NAME_COLOR);
  11247. getAppearance().setTitleColor(Config.DONATOR_TITLE_COLOR);
  11248. broadcastUserInfo();
  11249. }
  11250. else
  11251. {
  11252. updatecolorSystem();
  11253. broadcastUserInfo();
  11254. }
  11255. }
  11256. }
  11257.  
  11258. public String getIP()
  11259. {
  11260. return getClient().getConnection().getInetAddress().getHostAddress();
  11261. }
  11262. }
Advertisement
Add Comment
Please, Sign In to add comment