Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.l2j.gameserver.model.actor.instance;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.CopyOnWriteArraySet;
- import java.util.concurrent.Future;
- import java.util.concurrent.ScheduledFuture;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.util.concurrent.locks.ReentrantLock;
- import net.sf.l2j.commons.config.Config;
- import net.sf.l2j.commons.db.DatabaseFactory;
- import net.sf.l2j.commons.util.Point3D;
- import net.sf.l2j.commons.util.Rnd;
- import net.sf.l2j.gameserver.GameTimeController;
- import net.sf.l2j.gameserver.GeoData;
- import net.sf.l2j.gameserver.LoginServerThread;
- import net.sf.l2j.gameserver.ThreadPoolManager;
- import net.sf.l2j.gameserver.ai.CtrlEvent;
- import net.sf.l2j.gameserver.ai.CtrlIntention;
- import net.sf.l2j.gameserver.ai.L2CharacterAI;
- import net.sf.l2j.gameserver.ai.L2PlayerAI;
- import net.sf.l2j.gameserver.ai.L2SummonAI;
- import net.sf.l2j.gameserver.ai.NextAction;
- import net.sf.l2j.gameserver.ai.NextAction.NextActionCallback;
- import net.sf.l2j.gameserver.communitybbs.BB.Forum;
- import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
- import net.sf.l2j.gameserver.datatables.AccessLevels;
- import net.sf.l2j.gameserver.datatables.CharNameTable;
- import net.sf.l2j.gameserver.datatables.CharTemplateTable;
- import net.sf.l2j.gameserver.datatables.ClanTable;
- import net.sf.l2j.gameserver.datatables.FishTable;
- import net.sf.l2j.gameserver.datatables.GmListTable;
- import net.sf.l2j.gameserver.datatables.HennaTable;
- import net.sf.l2j.gameserver.datatables.ItemTable;
- import net.sf.l2j.gameserver.datatables.MapRegionTable;
- import net.sf.l2j.gameserver.datatables.PetDataTable;
- import net.sf.l2j.gameserver.datatables.RecipeTable;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.datatables.SkillTable.FrequentSkill;
- import net.sf.l2j.gameserver.datatables.SkillTreeTable;
- import net.sf.l2j.gameserver.handler.admin.AdminCommandHandler;
- import net.sf.l2j.gameserver.handler.admin.IAdminCommandHandler;
- import net.sf.l2j.gameserver.handler.item.IItemHandler;
- import net.sf.l2j.gameserver.handler.item.ItemHandler;
- import net.sf.l2j.gameserver.instancemanager.BypassManager;
- import net.sf.l2j.gameserver.instancemanager.CastleManager;
- import net.sf.l2j.gameserver.instancemanager.CoupleManager;
- import net.sf.l2j.gameserver.instancemanager.CursedWeaponsManager;
- import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
- import net.sf.l2j.gameserver.instancemanager.DuelManager;
- import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
- import net.sf.l2j.gameserver.instancemanager.ItemsOnGroundManager;
- import net.sf.l2j.gameserver.instancemanager.PremiumManager;
- import net.sf.l2j.gameserver.instancemanager.QuestManager;
- import net.sf.l2j.gameserver.instancemanager.SevenSigns;
- import net.sf.l2j.gameserver.instancemanager.SevenSignsFestival;
- import net.sf.l2j.gameserver.instancemanager.SiegeManager;
- import net.sf.l2j.gameserver.model.BlockList;
- import net.sf.l2j.gameserver.model.FishData;
- import net.sf.l2j.gameserver.model.L2AccessLevel;
- import net.sf.l2j.gameserver.model.L2CharPosition;
- import net.sf.l2j.gameserver.model.L2Clan;
- import net.sf.l2j.gameserver.model.L2ClanMember;
- import net.sf.l2j.gameserver.model.L2Effect;
- import net.sf.l2j.gameserver.model.L2Fishing;
- import net.sf.l2j.gameserver.model.L2Macro;
- import net.sf.l2j.gameserver.model.L2ManufactureList;
- import net.sf.l2j.gameserver.model.L2Object;
- import net.sf.l2j.gameserver.model.L2Party;
- import net.sf.l2j.gameserver.model.L2Party.MessageType;
- import net.sf.l2j.gameserver.model.L2PetData;
- import net.sf.l2j.gameserver.model.L2PetData.L2PetLevelData;
- import net.sf.l2j.gameserver.model.L2Radar;
- import net.sf.l2j.gameserver.model.L2Request;
- import net.sf.l2j.gameserver.model.L2ShortCut;
- import net.sf.l2j.gameserver.model.L2Skill;
- import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
- import net.sf.l2j.gameserver.model.L2SkillLearn;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.L2WorldRegion;
- import net.sf.l2j.gameserver.model.Location;
- import net.sf.l2j.gameserver.model.MacroList;
- import net.sf.l2j.gameserver.model.ShortCuts;
- import net.sf.l2j.gameserver.model.ShotType;
- import net.sf.l2j.gameserver.model.TradeList;
- import net.sf.l2j.gameserver.model.actor.L2Attackable;
- import net.sf.l2j.gameserver.model.actor.L2Character;
- import net.sf.l2j.gameserver.model.actor.L2Npc;
- import net.sf.l2j.gameserver.model.actor.L2Playable;
- import net.sf.l2j.gameserver.model.actor.L2Summon;
- import net.sf.l2j.gameserver.model.actor.L2Vehicle;
- import net.sf.l2j.gameserver.model.actor.appearance.PcAppearance;
- import net.sf.l2j.gameserver.model.actor.knownlist.PcKnownList;
- import net.sf.l2j.gameserver.model.actor.position.PcPosition;
- import net.sf.l2j.gameserver.model.actor.stat.PcStat;
- import net.sf.l2j.gameserver.model.actor.status.PcStatus;
- import net.sf.l2j.gameserver.model.actor.template.PcTemplate;
- import net.sf.l2j.gameserver.model.base.ClassId;
- import net.sf.l2j.gameserver.model.base.ClassLevel;
- import net.sf.l2j.gameserver.model.base.Experience;
- import net.sf.l2j.gameserver.model.base.PlayerClass;
- import net.sf.l2j.gameserver.model.base.Race;
- import net.sf.l2j.gameserver.model.base.SubClass;
- import net.sf.l2j.gameserver.model.entity.Castle;
- import net.sf.l2j.gameserver.model.entity.Duel;
- import net.sf.l2j.gameserver.model.entity.Hero;
- import net.sf.l2j.gameserver.model.entity.Siege;
- import net.sf.l2j.gameserver.model.holder.ItemHolder;
- import net.sf.l2j.gameserver.model.holder.SkillUseHolder;
- import net.sf.l2j.gameserver.model.item.Henna;
- import net.sf.l2j.gameserver.model.item.RecipeList;
- import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
- import net.sf.l2j.gameserver.model.item.kind.Armor;
- import net.sf.l2j.gameserver.model.item.kind.Item;
- import net.sf.l2j.gameserver.model.item.kind.Premium;
- import net.sf.l2j.gameserver.model.item.kind.Weapon;
- import net.sf.l2j.gameserver.model.item.type.ActionType;
- import net.sf.l2j.gameserver.model.item.type.ArmorType;
- import net.sf.l2j.gameserver.model.item.type.EtcItemType;
- import net.sf.l2j.gameserver.model.item.type.WeaponType;
- import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
- import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
- import net.sf.l2j.gameserver.model.itemcontainer.PcFreight;
- import net.sf.l2j.gameserver.model.itemcontainer.PcInventory;
- import net.sf.l2j.gameserver.model.itemcontainer.PcWarehouse;
- import net.sf.l2j.gameserver.model.itemcontainer.PetInventory;
- import net.sf.l2j.gameserver.model.itemcontainer.listeners.ItemPassiveSkillsListener;
- import net.sf.l2j.gameserver.model.olympiad.OlympiadGameManager;
- import net.sf.l2j.gameserver.model.olympiad.OlympiadGameTask;
- import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
- import net.sf.l2j.gameserver.model.partymatching.PartyMatchRoom;
- import net.sf.l2j.gameserver.model.partymatching.PartyMatchRoomList;
- import net.sf.l2j.gameserver.model.partymatching.PartyMatchWaitingList;
- import net.sf.l2j.gameserver.model.quest.Quest;
- import net.sf.l2j.gameserver.model.quest.QuestEventType;
- import net.sf.l2j.gameserver.model.quest.QuestState;
- import net.sf.l2j.gameserver.model.zone.ZoneId;
- import net.sf.l2j.gameserver.model.zone.type.L2BossZone;
- import net.sf.l2j.gameserver.network.L2GameClient;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.network.clientpackets.Say2;
- import net.sf.l2j.gameserver.network.components.CustomMessage;
- import net.sf.l2j.gameserver.network.serverpackets.AbstractNpcInfo;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.ChairSit;
- import net.sf.l2j.gameserver.network.serverpackets.ChangeWaitType;
- import net.sf.l2j.gameserver.network.serverpackets.CharInfo;
- import net.sf.l2j.gameserver.network.serverpackets.ConfirmDlg;
- import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- import net.sf.l2j.gameserver.network.serverpackets.EtcStatusUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.ExAutoSoulShot;
- import net.sf.l2j.gameserver.network.serverpackets.ExDuelUpdateUserInfo;
- import net.sf.l2j.gameserver.network.serverpackets.ExFishingEnd;
- import net.sf.l2j.gameserver.network.serverpackets.ExFishingStart;
- import net.sf.l2j.gameserver.network.serverpackets.ExOlympiadMode;
- import net.sf.l2j.gameserver.network.serverpackets.ExPCCafePointInfo;
- import net.sf.l2j.gameserver.network.serverpackets.ExSetCompassZoneCode;
- import net.sf.l2j.gameserver.network.serverpackets.ExStorageMaxCount;
- import net.sf.l2j.gameserver.network.serverpackets.FriendList;
- import net.sf.l2j.gameserver.network.serverpackets.GetOnVehicle;
- import net.sf.l2j.gameserver.network.serverpackets.HennaInfo;
- import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.ItemList;
- import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
- import net.sf.l2j.gameserver.network.serverpackets.LeaveWorld;
- import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
- import net.sf.l2j.gameserver.network.serverpackets.MoveToPawn;
- import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
- import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.network.serverpackets.ObservationMode;
- import net.sf.l2j.gameserver.network.serverpackets.ObservationReturn;
- import net.sf.l2j.gameserver.network.serverpackets.PartySmallWindowUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.PetInventoryUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
- import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListDelete;
- import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreListBuy;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreListSell;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreManageListBuy;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreManageListSell;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreMsgBuy;
- import net.sf.l2j.gameserver.network.serverpackets.PrivateStoreMsgSell;
- import net.sf.l2j.gameserver.network.serverpackets.RecipeShopManageList;
- import net.sf.l2j.gameserver.network.serverpackets.RecipeShopMsg;
- import net.sf.l2j.gameserver.network.serverpackets.RecipeShopSellList;
- import net.sf.l2j.gameserver.network.serverpackets.RelationChanged;
- import net.sf.l2j.gameserver.network.serverpackets.Ride;
- import net.sf.l2j.gameserver.network.serverpackets.SendTradeDone;
- import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
- import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
- import net.sf.l2j.gameserver.network.serverpackets.ShortBuffStatusUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.ShortCutInit;
- import net.sf.l2j.gameserver.network.serverpackets.SkillCoolTime;
- import net.sf.l2j.gameserver.network.serverpackets.SkillList;
- import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
- import net.sf.l2j.gameserver.network.serverpackets.StaticObject;
- import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.StopMove;
- import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.network.serverpackets.TargetSelected;
- import net.sf.l2j.gameserver.network.serverpackets.TargetUnselected;
- import net.sf.l2j.gameserver.network.serverpackets.TitleUpdate;
- import net.sf.l2j.gameserver.network.serverpackets.TradePressOtherOk;
- import net.sf.l2j.gameserver.network.serverpackets.TradePressOwnOk;
- import net.sf.l2j.gameserver.network.serverpackets.TradeStart;
- import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
- import net.sf.l2j.gameserver.skills.Env;
- import net.sf.l2j.gameserver.skills.Formulas;
- import net.sf.l2j.gameserver.skills.Stats;
- import net.sf.l2j.gameserver.skills.effects.EffectTemplate;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaCON;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaDEX;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaINT;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaMEN;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaSTR;
- import net.sf.l2j.gameserver.skills.funcs.FuncHennaWIT;
- import net.sf.l2j.gameserver.skills.funcs.FuncMaxCpMul;
- import net.sf.l2j.gameserver.skills.l2skills.L2SkillSiegeFlag;
- import net.sf.l2j.gameserver.skills.l2skills.L2SkillSummon;
- import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
- import net.sf.l2j.gameserver.taskmanager.ItemsAutoDestroyTaskManager;
- import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
- import net.sf.l2j.gameserver.taskmanager.TakeBreakTaskManager;
- import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
- import net.sf.l2j.gameserver.templates.StatsSet;
- import net.sf.l2j.gameserver.templates.skills.L2EffectFlag;
- import net.sf.l2j.gameserver.templates.skills.L2EffectType;
- import net.sf.l2j.gameserver.templates.skills.L2SkillType;
- import net.sf.l2j.gameserver.util.Broadcast;
- import net.sf.l2j.gameserver.util.FloodProtectors;
- import net.sf.l2j.gameserver.util.Util;
- /**
- * This class represents all player characters in the world. There is always a client-thread connected to this (except if a player-store is activated upon logout).
- */
- public final class L2PcInstance extends L2Playable
- {
- private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE char_obj_id=? AND class_index=?";
- private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (char_obj_id,skill_id,skill_level,class_index) VALUES (?,?,?,?)";
- private static final String UPDATE_CHARACTER_SKILL_LEVEL = "UPDATE character_skills SET skill_level=? WHERE skill_id=? AND char_obj_id=? AND class_index=?";
- private static final String DELETE_SKILL_FROM_CHAR = "DELETE FROM character_skills WHERE skill_id=? AND char_obj_id=? AND class_index=?";
- private static final String DELETE_CHAR_SKILLS = "DELETE FROM character_skills WHERE char_obj_id=? AND class_index=?";
- 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 (?,?,?,?,?,?,?,?,?,?)";
- 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";
- private static final String DELETE_SKILL_SAVE = "DELETE FROM character_skills_save WHERE char_obj_id=? AND class_index=?";
- 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,title_color,name_color) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- 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=?,pc_point=?,title_color=?,name_color=? WHERE obj_id=?";
- 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,pc_point,title_color,name_color FROM characters WHERE obj_id=?";
- 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";
- private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
- private static final String UPDATE_CHAR_SUBCLASS = "UPDATE character_subclasses SET exp=?,sp=?,level=?,class_id=? WHERE char_obj_id=? AND class_index =?";
- private static final String DELETE_CHAR_SUBCLASS = "DELETE FROM character_subclasses WHERE char_obj_id=? AND class_index=?";
- private static final String RESTORE_CHAR_HENNAS = "SELECT slot,symbol_id FROM character_hennas WHERE char_obj_id=? AND class_index=?";
- private static final String ADD_CHAR_HENNA = "INSERT INTO character_hennas (char_obj_id,symbol_id,slot,class_index) VALUES (?,?,?,?)";
- private static final String DELETE_CHAR_HENNA = "DELETE FROM character_hennas WHERE char_obj_id=? AND slot=? AND class_index=?";
- private static final String DELETE_CHAR_HENNAS = "DELETE FROM character_hennas WHERE char_obj_id=? AND class_index=?";
- private static final String DELETE_CHAR_SHORTCUTS = "DELETE FROM character_shortcuts WHERE char_obj_id=? AND class_index=?";
- private static final String RESTORE_CHAR_RECOMS = "SELECT char_id,target_id FROM character_recommends WHERE char_id=?";
- private static final String ADD_CHAR_RECOM = "INSERT INTO character_recommends (char_id,target_id) VALUES (?,?)";
- private static final String DELETE_CHAR_RECOMS = "DELETE FROM character_recommends WHERE char_id=?";
- private static final String UPDATE_NOBLESS = "UPDATE characters SET nobless=? WHERE obj_Id=?";
- private static final String CREATE_CHAR_DATA = "INSERT INTO character_data values (?,?,?)";
- private static final String STORE_CHAR_DATA = "UPDATE character_data set valueData=? where charId=? and valueName=?";
- private static final String LOAD_CHAR_DATA = "SELECT valueName,valueData from character_data where charId=?";
- private static final String CHAR_SETTINGS = "SELECT hero, hero_end_date FROM char_settings WHERE obj_Id = ?";
- private static final String DELETE_OFFLINE_NAME_COLOR = "DELETE FROM character_offline_name_color WHERE charId=?";
- private static final String INSERT_OFFLINE_NAME_COLOR = "INSERT INTO character_offline_name_color (charId, name_color) VALUES (?,?)";
- private static final String SELECT_OFFLINE_NAME_COLOR = "SELECT name_color FROM character_offline_name_color WHERE charId=?";
- public static final int REQUEST_TIMEOUT = 15;
- public static final int STORE_PRIVATE_NONE = 0;
- public static final int STORE_PRIVATE_SELL = 1;
- public static final int STORE_PRIVATE_SELL_MANAGE = 2;
- public static final int STORE_PRIVATE_BUY = 3;
- public static final int STORE_PRIVATE_BUY_MANAGE = 4;
- public static final int STORE_PRIVATE_MANUFACTURE = 5;
- public static final int STORE_PRIVATE_MANUFACTURE_MANAGE = 6;
- public static final int STORE_PRIVATE_PACKAGE_SELL = 8;
- public final Map<Integer, Long> _pvpKilledList = new ConcurrentHashMap<>();
- public final Map<Integer, Long> _pkKilledList = new ConcurrentHashMap<>();
- private final StatsSet _characterData = new StatsSet();
- private static final int[] EXPERTISE_LEVELS =
- {
- 0, // NONE
- 20, // D
- 40, // C
- 52, // B
- 61, // A
- 76, // S
- };
- private static final int[] COMMON_CRAFT_LEVELS =
- {
- 5,
- 20,
- 28,
- 36,
- 43,
- 49,
- 55,
- 62
- };
- public boolean canRegisterToEvents()
- {
- return _event == null && getKarma() == 0 && !(isInJail() || isInsideZone(ZoneId.JAIL)) && !(isInOlympiadMode() || OlympiadManager.getInstance().isRegistered(this));
- }
- public class AIAccessor extends L2Character.AIAccessor
- {
- protected AIAccessor()
- {
- }
- public L2PcInstance getPlayer()
- {
- return L2PcInstance.this;
- }
- public void doPickupItem(L2Object object)
- {
- L2PcInstance.this.doPickupItem(object);
- // Schedule a paralyzed task to wait for the animation to finish
- ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
- {
- @Override
- public void run()
- {
- setIsParalyzed(false);
- }
- }, 500);
- setIsParalyzed(true);
- }
- public void doInteract(L2Character target)
- {
- L2PcInstance.this.doInteract(target);
- }
- @Override
- public void doAttack(L2Character target)
- {
- super.doAttack(target);
- getPlayer().setRecentFakeDeath(false);
- }
- @Override
- public void doCast(L2Skill skill)
- {
- super.doCast(skill);
- getPlayer().setRecentFakeDeath(false);
- }
- }
- private L2GameClient _client;
- private String _hwid;
- private String _accountName;
- private long _deleteTimer;
- private boolean _isOnline = false;
- private long _onlineTime;
- private long _onlineBeginTime;
- private long _lastAccess;
- private long _uptime;
- private final ReentrantLock _subclassLock = new ReentrantLock();
- protected int _baseClass;
- protected int _activeClass;
- protected int _classIndex = 0;
- private final Map<Integer, SubClass> _subClasses = new LinkedHashMap<>();
- private int pcBangPoint = 0;
- private PcAppearance _appearance;
- private long _expBeforeDeath;
- private int _karma;
- private int _pvpKills;
- private int _pkKills;
- private byte _pvpFlag;
- private byte _siegeState = 0;
- private int _curWeightPenalty = 0;
- private int _lastCompassZone; // the last compass zone update send to the client
- private boolean _isInWater;
- private boolean _isIn7sDungeon = false;
- private PunishLevel _punishLevel = PunishLevel.NONE;
- private long _punishTimer = 0;
- private ScheduledFuture<?> _punishTask;
- private long _offlineShopStart = 0;
- public enum PunishLevel
- {
- NONE(0, ""),
- CHAT(1, "chat banned"),
- JAIL(2, "jailed"),
- CHAR(3, "banned"),
- ACC(4, "banned");
- private final int punValue;
- private final String punString;
- PunishLevel(int value, String string)
- {
- punValue = value;
- punString = string;
- }
- public int value()
- {
- return punValue;
- }
- public String string()
- {
- return punString;
- }
- }
- private boolean _inOlympiadMode = false;
- private boolean _OlympiadStart = false;
- private int _olympiadGameId = -1;
- private int _olympiadSide = -1;
- private boolean _isInDuel = false;
- private int _duelState = Duel.DUELSTATE_NODUEL;
- private int _duelId = 0;
- private SystemMessageId _noDuelReason = SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL;
- private L2Vehicle _vehicle = null;
- private Point3D _inVehiclePosition;
- public ScheduledFuture<?> _taskforfish;
- private int _mountType;
- private int _mountNpcId;
- private int _mountLevel;
- private int _mountObjectID = 0;
- public int _telemode = 0;
- private boolean _inCrystallize;
- private boolean _inCraftMode;
- private final Map<Integer, RecipeList> _dwarvenRecipeBook = new HashMap<>();
- private final Map<Integer, RecipeList> _commonRecipeBook = new HashMap<>();
- private boolean _waitTypeSitting;
- private int _lastX;
- private int _lastY;
- private int _lastZ;
- private boolean _observerMode = false;
- private final Point3D _lastServerPosition = new Point3D(0, 0, 0);
- private int _recomHave;
- private int _recomLeft;
- private long _lastRecomUpdate;
- private final List<Integer> _recomChars = new ArrayList<>();
- private final PcInventory _inventory = new PcInventory(this);
- private PcWarehouse _warehouse;
- private PcFreight _freight;
- private final List<PcFreight> _depositedFreight = new ArrayList<>();
- private int _privateStore;
- private TradeList _activeTradeList;
- private ItemContainer _activeWarehouse;
- private L2ManufactureList _createList;
- private TradeList _sellList;
- private TradeList _buyList;
- private boolean _noble = false;
- private boolean _hero = false;
- private L2Npc _currentFolkNpc = null;
- private int _questNpcObject = 0;
- private final List<QuestState> _quests = new ArrayList<>();
- private final List<QuestState> _notifyQuestOfDeathList = new ArrayList<>();
- private final ShortCuts _shortCuts = new ShortCuts(this);
- private final MacroList _macroses = new MacroList(this);
- private ClassId _skillLearningClassId;
- private final Henna[] _henna = new Henna[3];
- private int _hennaSTR;
- private int _hennaINT;
- private int _hennaDEX;
- private int _hennaMEN;
- private int _hennaWIT;
- private int _hennaCON;
- private L2Summon _summon = null;
- private L2TamedBeastInstance _tamedBeast = null;
- // TODO: This needs to be better integrated and saved/loaded
- private L2Radar _radar;
- private int _partyroom = 0;
- private int _clanId;
- private L2Clan _clan;
- private int _apprentice = 0;
- private int _sponsor = 0;
- private long _clanJoinExpiryTime;
- private long _clanCreateExpiryTime;
- private int _powerGrade = 0;
- private int _clanPrivileges = 0;
- private int _pledgeClass = 0;
- private int _pledgeType = 0;
- private int _lvlJoinedAcademy = 0;
- private boolean _wantsPeace;
- private int _deathPenaltyBuffLevel = 0;
- private final AtomicInteger _charges = new AtomicInteger();
- private ScheduledFuture<?> _chargeTask = null;
- private Point3D _currentSkillWorldPosition;
- private L2AccessLevel _accessLevel;
- private boolean _messageRefusal = false; // message refusal mode
- private boolean _exchangeRefusal = false; // Exchange refusal
- private L2Party _party;
- private L2PcInstance _activeRequester;
- private long _requestExpireTime = 0;
- private final L2Request _request = new L2Request(this);
- private ItemInstance _arrowItem;
- private ScheduledFuture<?> _protectTask = null;
- private long _recentFakeDeathEndTime = 0;
- private boolean _isFakeDeath;
- private Weapon _fistsWeaponItem;
- private final Map<Integer, String> _chars = new HashMap<>();
- private int _expertiseIndex;
- private int _expertiseArmorPenalty = 0;
- private boolean _expertiseWeaponPenalty = false;
- private ItemInstance _activeEnchantItem = null;
- protected boolean _inventoryDisable = false;
- protected Map<Integer, L2CubicInstance> _cubics = new ConcurrentHashMap<>();
- protected Set<Integer> _activeSoulShots = new CopyOnWriteArraySet<>();
- private final int _loto[] = new int[5];
- private final int _race[] = new int[2];
- private final BlockList _blockList = new BlockList(this);
- private int _team = 0;
- private int _alliedVarkaKetra = 0; // lvl of alliance with ketra orcs or varka silenos, used in quests and aggro checks [-5,-1] varka, 0 neutral, [1,5] ketra
- private Location _fishingLoc;
- private ItemInstance _lure = null;
- private L2Fishing _fishCombat;
- private FishData _fish;
- private Forum _forumMail;
- private Forum _forumMemo;
- private boolean _canFeed;
- private L2PetData _data;
- private L2PetLevelData _leveldata;
- private int _controlItemId;
- private int _curFeed;
- protected Future<?> _mountFeedTask;
- private ScheduledFuture<?> _dismountTask;
- private boolean _isInSiege;
- private final SkillUseHolder _currentSkill = new SkillUseHolder();
- private final SkillUseHolder _currentPetSkill = new SkillUseHolder();
- private final SkillUseHolder _queuedSkill = new SkillUseHolder();
- private int _cursedWeaponEquippedId = 0;
- private int _reviveRequested = 0;
- private double _revivePower = 0;
- private boolean _revivePet = false;
- private double _cpUpdateIncCheck = .0;
- private double _cpUpdateDecCheck = .0;
- private double _cpUpdateInterval = .0;
- private double _mpUpdateIncCheck = .0;
- private double _mpUpdateDecCheck = .0;
- private double _mpUpdateInterval = .0;
- private volatile int _clientX;
- private volatile int _clientY;
- private volatile int _clientZ;
- private volatile int _clientHeading;
- private int _mailPosition;
- private static final int FALLING_VALIDATION_DELAY = 10000;
- private volatile long _fallingTimestamp = 0;
- ScheduledFuture<?> _shortBuffTask = null;
- private int _shortBuffTaskSkillId = 0;
- private boolean _married = false;
- private int _coupleId = 0;
- private boolean _marryrequest = false;
- private int _requesterId = 0;
- public boolean PassedProt;
- public int botx, boty, botz;
- private final SummonRequest _summonRequest = new SummonRequest();
- private final GatesRequest _gatesRequest = new GatesRequest();
- protected class ShortBuffTask implements Runnable
- {
- @Override
- public void run()
- {
- sendPacket(new ShortBuffStatusUpdate(0, 0, 0));
- setShortBuffTaskSkillId(0);
- }
- }
- protected static class SummonRequest
- {
- private L2PcInstance _target = null;
- private L2Skill _skill = null;
- public void setTarget(L2PcInstance destination, L2Skill skill)
- {
- _target = destination;
- _skill = skill;
- }
- public L2PcInstance getTarget()
- {
- return _target;
- }
- public L2Skill getSkill()
- {
- return _skill;
- }
- }
- protected static class GatesRequest
- {
- private L2DoorInstance _target = null;
- public void setTarget(L2DoorInstance door)
- {
- _target = door;
- }
- public L2DoorInstance getDoor()
- {
- return _target;
- }
- }
- public void gatesRequest(L2DoorInstance door)
- {
- _gatesRequest.setTarget(door);
- }
- public void gatesAnswer(int answer, int type)
- {
- if (_gatesRequest.getDoor() == null)
- {
- return;
- }
- if (answer == 1 && getTarget() == _gatesRequest.getDoor() && type == 1)
- {
- _gatesRequest.getDoor().openMe();
- }
- else if (answer == 1 && getTarget() == _gatesRequest.getDoor() && type == 0)
- {
- _gatesRequest.getDoor().closeMe();
- }
- _gatesRequest.setTarget(null);
- }
- /**
- * Create a new L2PcInstance and add it in the characters table of the database.
- * <ul>
- * <li>Create a new L2PcInstance with an account name</li>
- * <li>Set the name, the Hair Style, the Hair Color and the Face type of the L2PcInstance</li>
- * <li>Add the player in the characters table of the database</li>
- * </ul>
- * @param objectId Identifier of the object to initialized
- * @param template The L2PcTemplate to apply to the L2PcInstance
- * @param accountName The name of the L2PcInstance
- * @param name The name of the L2PcInstance
- * @param hairStyle The hair style Identifier of the L2PcInstance
- * @param hairColor The hair color Identifier of the L2PcInstance
- * @param face The face type Identifier of the L2PcInstance
- * @param sex The sex type Identifier of the L2PcInstance
- * @return The L2PcInstance added to the database or null
- */
- public static L2PcInstance create(int objectId, PcTemplate template, String accountName, String name, byte hairStyle, byte hairColor, byte face, boolean sex)
- {
- // Create a new L2PcInstance with an account name
- PcAppearance app = new PcAppearance(face, hairColor, hairStyle, sex);
- L2PcInstance player = new L2PcInstance(objectId, template, accountName, app);
- // Set the name of the L2PcInstance
- player.setName(name);
- // Set the base class ID to that of the actual class ID.
- player.setBaseClass(player.getClassId());
- // Add the player in the characters table of the database
- boolean ok = player.createDb();
- if (!ok)
- {
- return null;
- }
- return player;
- }
- public static L2PcInstance createDummyPlayer(int objectId, String name)
- {
- // Create a new L2PcInstance with an account name
- L2PcInstance player = new L2PcInstance(objectId);
- player.setName(name);
- return player;
- }
- public String getAccountName()
- {
- return getClient().getAccountName();
- }
- public String getAccountNamePlayer()
- {
- return _accountName;
- }
- public Map<Integer, String> getAccountChars()
- {
- return _chars;
- }
- public int getRelation(L2PcInstance target)
- {
- int result = 0;
- // karma and pvp may not be required
- if (getPvpFlag() != 0)
- {
- result |= RelationChanged.RELATION_PVP_FLAG;
- }
- if (getKarma() > 0)
- {
- result |= RelationChanged.RELATION_HAS_KARMA;
- }
- if (isClanLeader())
- {
- result |= RelationChanged.RELATION_LEADER;
- }
- if (getSiegeState() != 0)
- {
- result |= RelationChanged.RELATION_INSIEGE;
- if (getSiegeState() != target.getSiegeState())
- {
- result |= RelationChanged.RELATION_ENEMY;
- }
- else
- {
- result |= RelationChanged.RELATION_ALLY;
- }
- if (getSiegeState() == 1)
- {
- result |= RelationChanged.RELATION_ATTACKER;
- }
- }
- if (getClan() != null && target.getClan() != null)
- {
- if (target.getPledgeType() != L2Clan.SUBUNIT_ACADEMY && getPledgeType() != L2Clan.SUBUNIT_ACADEMY && target.getClan().isAtWarWith(getClan().getClanId()))
- {
- result |= RelationChanged.RELATION_1SIDED_WAR;
- if (getClan().isAtWarWith(target.getClan().getClanId()))
- {
- result |= RelationChanged.RELATION_MUTUAL_WAR;
- }
- }
- }
- return result;
- }
- private void initPcStatusUpdateValues()
- {
- _cpUpdateInterval = getMaxCp() / 352.0;
- _cpUpdateIncCheck = getMaxCp();
- _cpUpdateDecCheck = getMaxCp() - _cpUpdateInterval;
- _mpUpdateInterval = getMaxMp() / 352.0;
- _mpUpdateIncCheck = getMaxMp();
- _mpUpdateDecCheck = getMaxMp() - _mpUpdateInterval;
- }
- /**
- * Constructor of L2PcInstance (use L2Character constructor).
- * <ul>
- * <li>Call the L2Character constructor to create an empty _skills slot and copy basic Calculator set to this L2PcInstance</li>
- * <li>Set the name of the L2PcInstance</li>
- * </ul>
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method SET the level of the L2PcInstance to 1</B></FONT>
- * @param objectId Identifier of the object to initialized
- * @param template The L2PcTemplate to apply to the L2PcInstance
- * @param accountName The name of the account including this L2PcInstance
- * @param app The PcAppearance of the L2PcInstance
- */
- private L2PcInstance(int objectId, PcTemplate template, String accountName, PcAppearance app)
- {
- super(objectId, template);
- super.initCharStatusUpdateValues();
- initPcStatusUpdateValues();
- _accountName = accountName;
- _appearance = app;
- _appearance.setOwner(this);
- // Create an AI
- _ai = new L2PlayerAI(new AIAccessor());
- // Create a L2Radar object
- _radar = new L2Radar(this);
- // Retrieve from the database all items of this L2PcInstance and add them to _inventory
- getInventory().restore();
- getWarehouse();
- getFreight();
- }
- private L2PcInstance(int objectId)
- {
- super(objectId, null);
- super.initCharStatusUpdateValues();
- initPcStatusUpdateValues();
- }
- @Override
- public void addFuncsToNewCharacter()
- {
- // Add L2Character functionalities.
- super.addFuncsToNewCharacter();
- addStatFunc(FuncMaxCpMul.getInstance());
- addStatFunc(FuncHennaSTR.getInstance());
- addStatFunc(FuncHennaDEX.getInstance());
- addStatFunc(FuncHennaINT.getInstance());
- addStatFunc(FuncHennaMEN.getInstance());
- addStatFunc(FuncHennaCON.getInstance());
- addStatFunc(FuncHennaWIT.getInstance());
- }
- @Override
- public void initKnownList()
- {
- setKnownList(new PcKnownList(this));
- }
- @Override
- public final PcKnownList getKnownList()
- {
- return (PcKnownList) super.getKnownList();
- }
- @Override
- public void initCharStat()
- {
- setStat(new PcStat(this));
- }
- @Override
- public final PcStat getStat()
- {
- return (PcStat) super.getStat();
- }
- @Override
- public void initCharStatus()
- {
- setStatus(new PcStatus(this));
- }
- @Override
- public final PcStatus getStatus()
- {
- return (PcStatus) super.getStatus();
- }
- @Override
- public void initPosition()
- {
- setObjectPosition(new PcPosition(this));
- }
- @Override
- public PcPosition getPosition()
- {
- return (PcPosition) super.getPosition();
- }
- public final PcAppearance getAppearance()
- {
- return _appearance;
- }
- /**
- * @return the base L2PcTemplate link to the L2PcInstance.
- */
- public final PcTemplate getBaseTemplate()
- {
- return CharTemplateTable.getInstance().getTemplate(_baseClass);
- }
- /** Return the L2PcTemplate link to the L2PcInstance. */
- @Override
- public final PcTemplate getTemplate()
- {
- return (PcTemplate) super.getTemplate();
- }
- public void setTemplate(ClassId newclass)
- {
- super.setTemplate(CharTemplateTable.getInstance().getTemplate(newclass));
- }
- /**
- * Return the AI of the L2PcInstance (create it if necessary).
- */
- @Override
- public L2CharacterAI getAI()
- {
- if (_ai == null)
- {
- synchronized (this)
- {
- if (_ai == null)
- {
- _ai = new L2PlayerAI(new AIAccessor());
- }
- }
- }
- return _ai;
- }
- /** Return the Level of the L2PcInstance. */
- @Override
- public final int getLevel()
- {
- return getStat().getLevel();
- }
- /**
- * A newbie is a player reaching level 6. He isn't considered newbie at lvl 25.<br>
- * Since IL newbie isn't anymore the first character of an account reaching that state, but any.
- * @return True if newbie.
- */
- public boolean isNewbie()
- {
- return getClassId().level() <= 1 && getLevel() >= 6 && getLevel() <= 25;
- }
- public void setBaseClass(int baseClass)
- {
- _baseClass = baseClass;
- }
- public void setBaseClass(ClassId classId)
- {
- _baseClass = classId.ordinal();
- }
- public boolean isInStoreMode()
- {
- return _privateStore > STORE_PRIVATE_NONE;
- }
- public boolean isInCraftMode()
- {
- return _inCraftMode;
- }
- public void isInCraftMode(boolean b)
- {
- _inCraftMode = b;
- }
- /**
- * Manage Logout Task
- */
- public void logout()
- {
- logout(true);
- }
- /**
- * Manage Logout Task
- * @param closeClient
- */
- public void logout(boolean closeClient)
- {
- try
- {
- closeNetConnection(closeClient);
- }
- catch (Exception e)
- {
- _log.warn("Exception on logout(): " + e.getMessage(), e);
- }
- }
- /**
- * @return a table containing all Common RecipeList of the L2PcInstance.
- */
- public Collection<RecipeList> getCommonRecipeBook()
- {
- return _commonRecipeBook.values();
- }
- /**
- * @return a table containing all Dwarf RecipeList of the L2PcInstance.
- */
- public Collection<RecipeList> getDwarvenRecipeBook()
- {
- return _dwarvenRecipeBook.values();
- }
- /**
- * Add a new L2RecipList to the table _commonrecipebook containing all RecipeList of the L2PcInstance.
- * @param recipe The RecipeList to add to the _recipebook
- */
- public void registerCommonRecipeList(RecipeList recipe)
- {
- _commonRecipeBook.put(recipe.getId(), recipe);
- }
- /**
- * Add a new L2RecipList to the table _recipebook containing all RecipeList of the L2PcInstance.
- * @param recipe The RecipeList to add to the _recipebook
- */
- public void registerDwarvenRecipeList(RecipeList recipe)
- {
- _dwarvenRecipeBook.put(recipe.getId(), recipe);
- }
- /**
- * @param recipeId The Identifier of the RecipeList to check in the player's recipe books
- * @return <b>TRUE</b> if player has the recipe on Common or Dwarven Recipe book else returns <b>FALSE</b>
- */
- public boolean hasRecipeList(int recipeId)
- {
- if (_dwarvenRecipeBook.containsKey(recipeId))
- {
- return true;
- }
- if (_commonRecipeBook.containsKey(recipeId))
- {
- return true;
- }
- return false;
- }
- /**
- * Tries to remove a L2RecipList from the table _DwarvenRecipeBook or from table _CommonRecipeBook, those table contain all RecipeList of the L2PcInstance.
- * @param recipeId The Identifier of the RecipeList to remove from the _recipebook.
- */
- public void unregisterRecipeList(int recipeId)
- {
- if (_dwarvenRecipeBook.containsKey(recipeId))
- {
- _dwarvenRecipeBook.remove(recipeId);
- }
- else if (_commonRecipeBook.containsKey(recipeId))
- {
- _commonRecipeBook.remove(recipeId);
- }
- else
- {
- _log.warn("Attempted to remove unknown RecipeList: " + recipeId);
- }
- for (L2ShortCut sc : getAllShortCuts())
- {
- if (sc != null && sc.getId() == recipeId && sc.getType() == L2ShortCut.TYPE_RECIPE)
- {
- deleteShortCut(sc.getSlot(), sc.getPage());
- }
- }
- }
- /**
- * @return the Id for the last talked quest NPC.
- */
- public int getLastQuestNpcObject()
- {
- return _questNpcObject;
- }
- public void setLastQuestNpcObject(int npcId)
- {
- _questNpcObject = npcId;
- }
- /**
- * @param name The name of the quest.
- * @return The QuestState object corresponding to the quest name.
- */
- public QuestState getQuestState(String name)
- {
- for (QuestState qs : _quests)
- {
- if (name.equals(qs.getQuest().getName()))
- {
- return qs;
- }
- }
- return null;
- }
- /**
- * Add a QuestState to the table _quest containing all quests began by the L2PcInstance.
- * @param qs The QuestState to add to _quest.
- */
- public void setQuestState(QuestState qs)
- {
- _quests.add(qs);
- }
- /**
- * Remove a QuestState from the table _quest containing all quests began by the L2PcInstance.
- * @param qs : The QuestState to be removed from _quest.
- */
- public void delQuestState(QuestState qs)
- {
- _quests.remove(qs);
- }
- /**
- * @param completed : If true, include completed quests to the list.
- * @return list of started and eventually completed quests of the player.
- */
- public List<Quest> getAllQuests(boolean completed)
- {
- List<Quest> quests = new ArrayList<>();
- for (QuestState qs : _quests)
- {
- if (qs == null || completed && qs.isCreated() || !completed && !qs.isStarted())
- {
- continue;
- }
- Quest quest = qs.getQuest();
- if (quest == null || !quest.isRealQuest())
- {
- continue;
- }
- quests.add(quest);
- }
- return quests;
- }
- public void processQuestEvent(String questName, String event)
- {
- Quest quest = QuestManager.getInstance().getQuest(questName);
- if (quest == null)
- {
- return;
- }
- QuestState qs = getQuestState(questName);
- if (qs == null)
- {
- return;
- }
- L2Object object = L2World.getInstance().findObject(getLastQuestNpcObject());
- if (!(object instanceof L2Npc) || !isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
- {
- return;
- }
- L2Npc npc = (L2Npc) object;
- List<Quest> quests = npc.getTemplate().getEventQuests(QuestEventType.ON_TALK);
- if (quests != null)
- {
- for (Quest onTalk : quests)
- {
- if (onTalk == null || !onTalk.equals(quest))
- {
- continue;
- }
- quest.notifyEvent(event, npc, this);
- break;
- }
- }
- }
- /**
- * Add QuestState instance that is to be notified of L2PcInstance's death.
- * @param qs The QuestState that subscribe to this event
- */
- public void addNotifyQuestOfDeath(QuestState qs)
- {
- if (qs == null)
- {
- return;
- }
- if (!_notifyQuestOfDeathList.contains(qs))
- {
- _notifyQuestOfDeathList.add(qs);
- }
- }
- /**
- * Remove QuestState instance that is to be notified of L2PcInstance's death.
- * @param qs The QuestState that subscribe to this event
- */
- public void removeNotifyQuestOfDeath(QuestState qs)
- {
- if (qs == null)
- {
- return;
- }
- _notifyQuestOfDeathList.remove(qs);
- }
- /**
- * @return A list of QuestStates which registered for notify of death of this L2PcInstance.
- */
- public final List<QuestState> getNotifyQuestOfDeath()
- {
- return _notifyQuestOfDeathList;
- }
- /**
- * @return A table containing all L2ShortCut of the L2PcInstance.
- */
- public L2ShortCut[] getAllShortCuts()
- {
- return _shortCuts.getAllShortCuts();
- }
- /**
- * @param slot The slot in wich the shortCuts is equipped
- * @param page The page of shortCuts containing the slot
- * @return The L2ShortCut of the L2PcInstance corresponding to the position (page-slot).
- */
- public L2ShortCut getShortCut(int slot, int page)
- {
- return _shortCuts.getShortCut(slot, page);
- }
- /**
- * Add a L2shortCut to the L2PcInstance _shortCuts
- * @param shortcut The shortcut to add.
- */
- public void registerShortCut(L2ShortCut shortcut)
- {
- _shortCuts.registerShortCut(shortcut);
- }
- /**
- * Delete the L2ShortCut corresponding to the position (page-slot) from the L2PcInstance _shortCuts.
- * @param slot
- * @param page
- */
- public void deleteShortCut(int slot, int page)
- {
- _shortCuts.deleteShortCut(slot, page);
- }
- /**
- * Add a L2Macro to the L2PcInstance _macroses.
- * @param macro The Macro object to add.
- */
- public void registerMacro(L2Macro macro)
- {
- _macroses.registerMacro(macro);
- }
- /**
- * Delete the L2Macro corresponding to the Identifier from the L2PcInstance _macroses.
- * @param id
- */
- public void deleteMacro(int id)
- {
- _macroses.deleteMacro(id);
- }
- /**
- * @return all L2Macro of the L2PcInstance.
- */
- public MacroList getMacroses()
- {
- return _macroses;
- }
- /**
- * Set the siege state of the L2PcInstance.
- * @param siegeState 1 = attacker, 2 = defender, 0 = not involved
- */
- public void setSiegeState(byte siegeState)
- {
- _siegeState = siegeState;
- }
- /**
- * @return the siege state of the L2PcInstance.
- */
- public byte getSiegeState()
- {
- return _siegeState;
- }
- /**
- * Определяем состояние игрока как участника осады
- *
- * @return < 1 = Значит атакующий. > < 2 = Значит защитник. >
- *
- * Данный механизм, еще легче делает вызов проверки состояния игрока на
- * осаде, что бы 100 раз не вызывать дебилизм, упрощаем себе задачу через
- * булевое.
- *
- * P.s: даже для кастумных затей очень полезный механизм, как для эвентов
- * так и для прочего, если вы участвуете в осаде.
- */
- public boolean isSiegeChar()
- {
- return getSiegeState() == 1 || getSiegeState() == 2;
- }
- /**
- * Set the PvP Flag of the L2PcInstance.
- * @param pvpFlag 0 or 1.
- */
- public void setPvpFlag(int pvpFlag)
- {
- _pvpFlag = (byte) pvpFlag;
- }
- @Override
- public byte getPvpFlag()
- {
- return _pvpFlag;
- }
- public void updatePvPFlag(int value)
- {
- if (getPvpFlag() == value)
- {
- return;
- }
- setPvpFlag(value);
- sendPacket(new UserInfo(this));
- if (getPet() != null)
- {
- sendPacket(new RelationChanged(getPet(), getRelation(this), false));
- }
- broadcastRelationsChanges();
- }
- @Override
- public void revalidateZone(boolean force)
- {
- // Cannot validate if not in a world region (happens during teleport)
- if (getWorldRegion() == null)
- {
- return;
- }
- // This function is called very often from movement code
- if (force)
- {
- _zoneValidateCounter = 4;
- }
- else
- {
- _zoneValidateCounter--;
- if (_zoneValidateCounter >= 0)
- {
- return;
- }
- _zoneValidateCounter = 4;
- }
- getWorldRegion().revalidateZones(this);
- if (Config.ALLOW_WATER)
- {
- checkWaterState();
- }
- if (isInsideZone(ZoneId.SIEGE))
- {
- if (_lastCompassZone == ExSetCompassZoneCode.SIEGEWARZONE2)
- {
- return;
- }
- _lastCompassZone = ExSetCompassZoneCode.SIEGEWARZONE2;
- sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.SIEGEWARZONE2));
- }
- else if (isInsideZone(ZoneId.PVP))
- {
- if (_lastCompassZone == ExSetCompassZoneCode.PVPZONE)
- {
- return;
- }
- _lastCompassZone = ExSetCompassZoneCode.PVPZONE;
- sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.PVPZONE));
- }
- else if (isIn7sDungeon())
- {
- if (_lastCompassZone == ExSetCompassZoneCode.SEVENSIGNSZONE)
- {
- return;
- }
- _lastCompassZone = ExSetCompassZoneCode.SEVENSIGNSZONE;
- sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.SEVENSIGNSZONE));
- }
- else if (isInsideZone(ZoneId.PEACE))
- {
- if (_lastCompassZone == ExSetCompassZoneCode.PEACEZONE)
- {
- return;
- }
- _lastCompassZone = ExSetCompassZoneCode.PEACEZONE;
- sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.PEACEZONE));
- }
- else
- {
- if (_lastCompassZone == ExSetCompassZoneCode.GENERALZONE)
- {
- return;
- }
- if (_lastCompassZone == ExSetCompassZoneCode.SIEGEWARZONE2)
- {
- updatePvPStatus();
- }
- _lastCompassZone = ExSetCompassZoneCode.GENERALZONE;
- sendPacket(new ExSetCompassZoneCode(ExSetCompassZoneCode.GENERALZONE));
- }
- }
- /**
- * @return True if the L2PcInstance can Craft Dwarven Recipes.
- */
- public boolean hasDwarvenCraft()
- {
- return getSkillLevel(L2Skill.SKILL_CREATE_DWARVEN) >= 1;
- }
- public int getDwarvenCraft()
- {
- return getSkillLevel(L2Skill.SKILL_CREATE_DWARVEN);
- }
- /**
- * @return True if the L2PcInstance can Craft Dwarven Recipes.
- */
- public boolean hasCommonCraft()
- {
- return getSkillLevel(L2Skill.SKILL_CREATE_COMMON) >= 1;
- }
- public int getCommonCraft()
- {
- return getSkillLevel(L2Skill.SKILL_CREATE_COMMON);
- }
- /**
- * @return the PK counter of the L2PcInstance.
- */
- public int getPkKills()
- {
- return _pkKills;
- }
- /**
- * Set the PK counter of the L2PcInstance.
- * @param pkKills A number.
- */
- public void setPkKills(int pkKills)
- {
- _pkKills = pkKills;
- }
- /**
- * @return The _deleteTimer of the L2PcInstance.
- */
- public long getDeleteTimer()
- {
- return _deleteTimer;
- }
- /**
- * Set the _deleteTimer of the L2PcInstance.
- * @param deleteTimer Time in ms.
- */
- public void setDeleteTimer(long deleteTimer)
- {
- _deleteTimer = deleteTimer;
- }
- /**
- * @return The current weight of the L2PcInstance.
- */
- public int getCurrentLoad()
- {
- return _inventory.getTotalWeight();
- }
- /**
- * @return The date of last update of recomPoints.
- */
- public long getLastRecomUpdate()
- {
- return _lastRecomUpdate;
- }
- public void setLastRecomUpdate(long date)
- {
- _lastRecomUpdate = date;
- }
- /**
- * @return The number of recommandation obtained by the L2PcInstance.
- */
- public int getRecomHave()
- {
- return _recomHave;
- }
- /**
- * Increment the number of recommandation obtained by the L2PcInstance (Max : 255).
- */
- protected void incRecomHave()
- {
- if (_recomHave < 255)
- {
- _recomHave++;
- }
- }
- /**
- * Set the number of recommandations obtained by the L2PcInstance (Max : 255).
- * @param value Number of recommandations obtained.
- */
- public void setRecomHave(int value)
- {
- if (value > 255)
- {
- _recomHave = 255;
- }
- else if (value < 0)
- {
- _recomHave = 0;
- }
- else
- {
- _recomHave = value;
- }
- }
- /**
- * @return The number of recommandation that the L2PcInstance can give.
- */
- public int getRecomLeft()
- {
- return _recomLeft;
- }
- /**
- * Increment the number of recommandation that the L2PcInstance can give.
- */
- protected void decRecomLeft()
- {
- if (_recomLeft > 0)
- {
- _recomLeft--;
- }
- }
- public void giveRecom(L2PcInstance target)
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(ADD_CHAR_RECOM);
- statement.setInt(1, getObjectId());
- statement.setInt(2, target.getObjectId());
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not update char recommendations: " + e);
- }
- target.incRecomHave();
- decRecomLeft();
- _recomChars.add(target.getObjectId());
- }
- public boolean canRecom(L2PcInstance target)
- {
- return !_recomChars.contains(target.getObjectId());
- }
- /**
- * Set the exp of the L2PcInstance before a death
- * @param exp
- */
- public void setExpBeforeDeath(long exp)
- {
- _expBeforeDeath = exp;
- }
- public long getExpBeforeDeath()
- {
- return _expBeforeDeath;
- }
- /**
- * Return the Karma of the L2PcInstance.
- */
- @Override
- public int getKarma()
- {
- return _karma;
- }
- /**
- * Set the Karma of the L2PcInstance and send StatusUpdate (broadcast).
- * @param karma A value.
- */
- public void setKarma(int karma)
- {
- if (karma < 0)
- {
- karma = 0;
- }
- if (_karma > 0 && karma == 0)
- {
- sendPacket(new UserInfo(this));
- broadcastRelationsChanges();
- }
- // send message with new karma value
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOUR_KARMA_HAS_BEEN_CHANGED_TO_S1).addNumber(karma));
- _karma = karma;
- broadcastKarma();
- }
- /**
- * Weight Limit = (CON Modifier*69000)*Skills
- * @return The max weight that the L2PcInstance can load.
- */
- public int getMaxLoad()
- {
- int con = getCON();
- if (con < 1)
- {
- return 31000;
- }
- if (con > 59)
- {
- return 176000;
- }
- double baseLoad = Math.pow(1.029993928, con) * 30495.627366;
- return (int) calcStat(Stats.MAX_LOAD, baseLoad * Config.ALT_WEIGHT_LIMIT, this, null);
- }
- public int getExpertiseArmorPenalty()
- {
- return _expertiseArmorPenalty;
- }
- public boolean getExpertiseWeaponPenalty()
- {
- return _expertiseWeaponPenalty;
- }
- public int getWeightPenalty()
- {
- return _curWeightPenalty;
- }
- /**
- * Update the overloaded status of the L2PcInstance.
- */
- public void refreshOverloaded()
- {
- int maxLoad = getMaxLoad();
- if (maxLoad > 0)
- {
- int weightproc = getCurrentLoad() * 1000 / maxLoad;
- int newWeightPenalty;
- if (weightproc < 500)
- {
- newWeightPenalty = 0;
- }
- else if (weightproc < 666)
- {
- newWeightPenalty = 1;
- }
- else if (weightproc < 800)
- {
- newWeightPenalty = 2;
- }
- else if (weightproc < 1000)
- {
- newWeightPenalty = 3;
- }
- else
- {
- newWeightPenalty = 4;
- }
- if (_curWeightPenalty != newWeightPenalty)
- {
- _curWeightPenalty = newWeightPenalty;
- if (newWeightPenalty > 0)
- {
- super.addSkill(SkillTable.getInstance().getInfo(4270, newWeightPenalty));
- setIsOverloaded(getCurrentLoad() > maxLoad);
- }
- else
- {
- super.removeSkill(getKnownSkill(4270));
- setIsOverloaded(false);
- }
- sendPacket(new UserInfo(this));
- sendPacket(new EtcStatusUpdate(this));
- broadcastCharInfo();
- }
- }
- }
- /**
- * Refresh expertise level ; weapon got one rank, when armor got 4 ranks.<br>
- */
- public void refreshExpertisePenalty()
- {
- int armorPenalty = 0;
- boolean weaponPenalty = false;
- for (ItemInstance item : getInventory().getItems())
- {
- if (item != null && item.isEquipped() && item.getItemType() != EtcItemType.ARROW && item.getItem().getCrystalType().getId() > getExpertiseIndex())
- {
- if (item.isWeapon())
- {
- weaponPenalty = true;
- }
- else
- {
- armorPenalty += (item.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR) ? 2 : 1;
- }
- }
- }
- armorPenalty = Math.min(armorPenalty, 4);
- // Found a different state than previous ; update it.
- if (_expertiseWeaponPenalty != weaponPenalty || _expertiseArmorPenalty != armorPenalty)
- {
- _expertiseWeaponPenalty = weaponPenalty;
- _expertiseArmorPenalty = armorPenalty;
- // Passive skill "Grade Penalty" is either granted or dropped.
- if (_expertiseWeaponPenalty || _expertiseArmorPenalty > 0)
- {
- super.addSkill(SkillTable.getInstance().getInfo(4267, 1));
- }
- else
- {
- super.removeSkill(getKnownSkill(4267));
- }
- sendSkillList();
- sendPacket(new EtcStatusUpdate(this));
- final ItemInstance weapon = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
- if (weapon != null)
- {
- if (_expertiseWeaponPenalty)
- {
- ItemPassiveSkillsListener.getInstance().onUnequip(0, weapon, this);
- }
- else
- {
- ItemPassiveSkillsListener.getInstance().onEquip(0, weapon, this);
- }
- }
- }
- }
- private void removeFistFuryEffect(ItemInstance item)
- {
- if (item.isEquipped())
- {
- _effects.stopSkillEffects(222);
- }
- else
- {
- if (item.getWeaponItem().getItemType() != WeaponType.DUALFIST)
- {
- _effects.stopSkillEffects(222);
- }
- }
- }
- private void removeAugmentationEffect(ItemInstance item)
- {
- if (Config.REMOVE_AUGMENTATION_EFFECT && item.isEquipped() && item.isAugmented())
- {
- final L2Skill skill = item.getAugmentation().getSkill();
- if (skill != null)
- {
- _effects.stopSkillEffects(skill.getId());
- }
- }
- }
- /**
- * Equip or unequip the item.
- * <UL>
- * <LI>If item is equipped, shots are applied if automation is on.</LI>
- * <LI>If item is unequipped, shots are discharged.</LI>
- * </UL>
- * @param item The item to charge/discharge.
- * @param abortAttack If true, the current attack will be aborted in order to equip the item.
- */
- public void useEquippableItem(ItemInstance item, boolean abortAttack)
- {
- ItemInstance[] items;
- final boolean isEquipped = item.isEquipped();
- final int oldInvLimit = getInventoryLimit();
- SystemMessage sm;
- //if (item.getItem() instanceof Weapon)
- if (item.getItem().getType2() == Item.TYPE2_WEAPON)
- {
- item.unChargeAllShots();
- removeFistFuryEffect(item);
- removeAugmentationEffect(item);
- }
- if (isEquipped)
- {
- if (item.getEnchantLevel() > 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(item.getEnchantLevel()).addItemName(item);
- }
- else
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(item);
- }
- sendPacket(sm);
- int slot = getInventory().getSlotFromItem(item);
- items = getInventory().unEquipItemInBodySlotAndRecord(slot);
- }
- else
- {
- items = getInventory().equipItemAndRecord(item);
- if (item.isEquipped())
- {
- if (item.getEnchantLevel() > 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2_EQUIPPED).addNumber(item.getEnchantLevel()).addItemName(item);
- }
- else
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_EQUIPPED).addItemName(item);
- }
- sendPacket(sm);
- if ((item.getItem().getBodyPart() & Item.SLOT_ALLWEAPON) != 0)
- {
- rechargeShots(true, true);
- }
- }
- else
- {
- sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
- }
- }
- refreshExpertisePenalty();
- broadcastUserInfo();
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItems(Arrays.asList(items));
- sendPacket(iu);
- if (abortAttack)
- {
- abortAttack();
- }
- if (getInventoryLimit() != oldInvLimit)
- {
- sendPacket(new ExStorageMaxCount(this));
- }
- }
- /**
- * @return PvP Kills of the L2PcInstance (number of player killed during a PvP).
- */
- public int getPvpKills()
- {
- return _pvpKills;
- }
- /**
- * Set PvP Kills of the L2PcInstance (number of player killed during a PvP).
- * @param pvpKills A value.
- */
- public void setPvpKills(int pvpKills)
- {
- _pvpKills = pvpKills;
- }
- /**
- * @return The ClassId object of the L2PcInstance contained in L2PcTemplate.
- */
- public ClassId getClassId()
- {
- return getTemplate().getClassId();
- }
- /**
- * Set the template of the L2PcInstance.
- * @param Id The Identifier of the L2PcTemplate to set to the L2PcInstance
- */
- public void setClassId(int Id)
- {
- if (!_subclassLock.tryLock())
- {
- return;
- }
- try
- {
- if (getLvlJoinedAcademy() != 0 && _clan != null && PlayerClass.values()[Id].getLevel() == ClassLevel.Third)
- {
- if (getLvlJoinedAcademy() <= 16)
- {
- _clan.addReputationScore(400);
- }
- else if (getLvlJoinedAcademy() >= 39)
- {
- _clan.addReputationScore(170);
- }
- else
- {
- _clan.addReputationScore((400 - (getLvlJoinedAcademy() - 16) * 10));
- }
- setLvlJoinedAcademy(0);
- // Oust pledge member from the academy, because he has finished his 2nd class transfer.
- _clan.broadcastToOnlineMembers(new PledgeShowMemberListDelete(getName()), SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_S1_EXPELLED).addString(getName()));
- _clan.removeClanMember(getObjectId(), 0);
- sendPacket(SystemMessageId.ACADEMY_MEMBERSHIP_TERMINATED);
- // receive graduation gift : academy circlet
- addItem("Gift", 8181, 1, this, true);
- }
- if (isSubClassActive())
- {
- getSubClasses().get(_classIndex).setClassId(Id);
- }
- broadcastPacket(new MagicSkillUse(this, this, 5103, 1, 1000, 0));
- setClassTemplate(Id);
- if (getClassId().level() == 3)
- {
- sendPacket(SystemMessageId.THIRD_CLASS_TRANSFER);
- }
- else
- {
- sendPacket(SystemMessageId.CLASS_TRANSFER);
- }
- // Update class icon in party and clan
- if (isInParty())
- {
- getParty().broadcastToPartyMembers(new PartySmallWindowUpdate(this));
- }
- if (getClan() != null)
- {
- getClan().broadcastToOnlineMembers(new PledgeShowMemberListUpdate(this));
- }
- if (Config.AUTO_LEARN_SKILLS)
- {
- rewardSkills();
- }
- }
- finally
- {
- _subclassLock.unlock();
- }
- }
- /**
- * @return the Experience of the L2PcInstance.
- */
- public long getExp()
- {
- return getStat().getExp();
- }
- public void setActiveEnchantItem(ItemInstance scroll)
- {
- _activeEnchantItem = scroll;
- }
- public ItemInstance getActiveEnchantItem()
- {
- return _activeEnchantItem;
- }
- /**
- * Set the fists weapon of the L2PcInstance (used when no weapon is equipped).
- * @param weaponItem The fists Weapon to set to the L2PcInstance
- */
- public void setFistsWeaponItem(Weapon weaponItem)
- {
- _fistsWeaponItem = weaponItem;
- }
- /**
- * @return The fists weapon of the L2PcInstance (used when no weapon is equipped).
- */
- public Weapon getFistsWeaponItem()
- {
- return _fistsWeaponItem;
- }
- /**
- * @param classId The classId to test.
- * @return The fists weapon of the L2PcInstance Class (used when no weapon is equipped).
- */
- public static Weapon findFistsWeaponItem(int classId)
- {
- Weapon weaponItem = null;
- if ((classId >= 0x00) && (classId <= 0x09))
- {
- // human fighter fists
- Item temp = ItemTable.getInstance().getTemplate(246);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x0a) && (classId <= 0x11))
- {
- // human mage fists
- Item temp = ItemTable.getInstance().getTemplate(251);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x12) && (classId <= 0x18))
- {
- // elven fighter fists
- Item temp = ItemTable.getInstance().getTemplate(244);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x19) && (classId <= 0x1e))
- {
- // elven mage fists
- Item temp = ItemTable.getInstance().getTemplate(249);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x1f) && (classId <= 0x25))
- {
- // dark elven fighter fists
- Item temp = ItemTable.getInstance().getTemplate(245);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x26) && (classId <= 0x2b))
- {
- // dark elven mage fists
- Item temp = ItemTable.getInstance().getTemplate(250);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x2c) && (classId <= 0x30))
- {
- // orc fighter fists
- Item temp = ItemTable.getInstance().getTemplate(248);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x31) && (classId <= 0x34))
- {
- // orc mage fists
- Item temp = ItemTable.getInstance().getTemplate(252);
- weaponItem = (Weapon) temp;
- }
- else if ((classId >= 0x35) && (classId <= 0x39))
- {
- // dwarven fists
- Item temp = ItemTable.getInstance().getTemplate(247);
- weaponItem = (Weapon) temp;
- }
- return weaponItem;
- }
- /**
- * This method is kinda polymorph :
- * <ul>
- * <li>it gives proper Expertise, Dwarven && Common Craft skill level ;</li>
- * <li>it controls the Lucky skill (remove at lvl 10) ;</li>
- * <li>it finally sends the skill list.</li>
- * </ul>
- */
- public void rewardSkills()
- {
- // Get the Level of the L2PcInstance
- int lvl = getLevel();
- // Remove the Lucky skill once reached lvl 10.
- if (getSkillLevel(L2Skill.SKILL_LUCKY) > 0 && lvl >= 10)
- {
- removeSkill(FrequentSkill.LUCKY.getSkill());
- }
- // Calculate the current higher Expertise of the L2PcInstance
- for (int i = 0; i < EXPERTISE_LEVELS.length; i++)
- {
- if (lvl >= EXPERTISE_LEVELS[i])
- {
- setExpertiseIndex(i);
- }
- }
- // Add the Expertise skill corresponding to its Expertise level
- if (getExpertiseIndex() > 0)
- {
- L2Skill skill = SkillTable.getInstance().getInfo(239, getExpertiseIndex());
- addSkill(skill, true);
- }
- // Active skill dwarven craft
- if (getSkillLevel(1321) < 1 && getClassId().equalsOrChildOf(ClassId.dwarvenFighter))
- {
- L2Skill skill = FrequentSkill.DWARVEN_CRAFT.getSkill();
- addSkill(skill, true);
- }
- // Active skill common craft
- if (getSkillLevel(1322) < 1)
- {
- L2Skill skill = FrequentSkill.COMMON_CRAFT.getSkill();
- addSkill(skill, true);
- }
- for (int i = 0; i < COMMON_CRAFT_LEVELS.length; i++)
- {
- if (lvl >= COMMON_CRAFT_LEVELS[i] && getSkillLevel(1320) < (i + 1))
- {
- L2Skill skill = SkillTable.getInstance().getInfo(1320, (i + 1));
- addSkill(skill, true);
- }
- }
- // Auto-Learn skills if activated
- if (Config.AUTO_LEARN_SKILLS)
- {
- giveAvailableSkills();
- }
- sendSkillList();
- }
- /**
- * Regive all skills which aren't saved to database, like Noble, Hero, Clan Skills.<br>
- * <b>Do not call this on enterworld or char load.</b>.
- */
- private void regiveTemporarySkills()
- {
- // Add noble skills if noble.
- if (isNoble())
- {
- setNoble(true, false);
- }
- // Add Hero skills if hero.
- if (isHero())
- {
- setHero(true);
- }
- // Add clan skills.
- if (getClan() != null)
- {
- getClan().addSkillEffects(this);
- if (getClan().getLevel() >= SiegeManager.MINIMUM_CLAN_LEVEL && isClanLeader())
- {
- SiegeManager.addSiegeSkills(this);
- }
- }
- // Reload passive skills from armors / jewels / weapons
- getInventory().reloadEquippedItems();
- // Add Death Penalty Buff Level
- restoreDeathPenaltyBuffLevel();
- }
- /**
- * Give all available skills to the player.
- * @return The number of given skills.
- */
- public int giveAvailableSkills()
- {
- int result = 0;
- for (L2SkillLearn sl : SkillTreeTable.getInstance().getAllAvailableSkills(this, getClassId()))
- {
- addSkill(SkillTable.getInstance().getInfo(sl.getId(), sl.getLevel()), true);
- result++;
- }
- return result;
- }
- /**
- * @return The Race object of the L2PcInstance.
- */
- public Race getRace()
- {
- if (!isSubClassActive())
- {
- return getTemplate().getRace();
- }
- return CharTemplateTable.getInstance().getTemplate(_baseClass).getRace();
- }
- public L2Radar getRadar()
- {
- return _radar;
- }
- /**
- * @return the SP amount of the L2PcInstance.
- */
- public int getSp()
- {
- return getStat().getSp();
- }
- /**
- * @param castleId The castle to check.
- * @return True if this L2PcInstance is a clan leader in ownership of the passed castle.
- */
- public boolean isCastleLord(int castleId)
- {
- L2Clan clan = getClan();
- // player has clan and is the clan leader, check the castle info
- if ((clan != null) && (clan.getLeader().getPlayerInstance() == this))
- {
- // if the clan has a castle and it is actually the queried castle, return true
- Castle castle = CastleManager.getInstance().getCastleByOwner(clan);
- if ((castle != null) && (castle == CastleManager.getInstance().getCastleById(castleId)))
- {
- return true;
- }
- }
- return false;
- }
- /**
- * @return The Clan Identifier of the L2PcInstance.
- */
- public int getClanId()
- {
- return _clanId;
- }
- /**
- * @return The Clan Crest Identifier of the L2PcInstance or 0.
- */
- public int getClanCrestId()
- {
- if (_clan != null)
- {
- return _clan.getCrestId();
- }
- return 0;
- }
- /**
- * @return The Clan CrestLarge Identifier or 0
- */
- public int getClanCrestLargeId()
- {
- if (_clan != null)
- {
- return _clan.getCrestLargeId();
- }
- return 0;
- }
- public long getClanJoinExpiryTime()
- {
- return _clanJoinExpiryTime;
- }
- public void setClanJoinExpiryTime(long time)
- {
- _clanJoinExpiryTime = time;
- }
- public long getClanCreateExpiryTime()
- {
- return _clanCreateExpiryTime;
- }
- public void setClanCreateExpiryTime(long time)
- {
- _clanCreateExpiryTime = time;
- }
- public void setOnlineTime(long time)
- {
- _onlineTime = time;
- _onlineBeginTime = System.currentTimeMillis();
- }
- /**
- * Return the PcInventory Inventory of the L2PcInstance contained in _inventory.
- */
- @Override
- public PcInventory getInventory()
- {
- return _inventory;
- }
- /**
- * Delete a ShortCut of the L2PcInstance _shortCuts.
- * @param objectId The shortcut id.
- */
- public void removeItemFromShortCut(int objectId)
- {
- _shortCuts.deleteShortCutByObjectId(objectId);
- }
- /**
- * @return True if the L2PcInstance is sitting.
- */
- public boolean isSitting()
- {
- return _waitTypeSitting;
- }
- /**
- * Set _waitTypeSitting to given value.
- * @param state A boolean.
- */
- public void setIsSitting(boolean state)
- {
- _waitTypeSitting = state;
- }
- /**
- * Sit down the L2PcInstance, set the AI Intention to REST and send ChangeWaitType packet (broadcast)
- */
- public void sitDown()
- {
- sitDown(true);
- }
- public void sitDown(boolean checkCast)
- {
- if (checkCast && isCastingNow())
- {
- return;
- }
- if (!_waitTypeSitting && !isAttackingDisabled() && !isOutOfControl() && !isImmobilized())
- {
- breakAttack();
- setIsSitting(true);
- broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_SITTING));
- // Schedule a sit down task to wait for the animation to finish
- getAI().setIntention(CtrlIntention.REST);
- ThreadPoolManager.getInstance().scheduleGeneral(new SitDownTask(), 2500);
- setIsParalyzed(true);
- }
- }
- protected class SitDownTask implements Runnable
- {
- @Override
- public void run()
- {
- setIsParalyzed(false);
- }
- }
- protected class StandUpTask implements Runnable
- {
- @Override
- public void run()
- {
- setIsSitting(false);
- setIsParalyzed(false);
- getAI().setIntention(CtrlIntention.IDLE);
- }
- }
- /**
- * Stand up the L2PcInstance, set the AI Intention to IDLE and send ChangeWaitType packet (broadcast)
- */
- public void standUp()
- {
- if (_event != null && !_event.canDoAction(this, 0))
- {
- return;
- }
- if (_waitTypeSitting && !isInStoreMode() && !isAlikeDead() && !isParalyzed())
- {
- if (_effects.isAffected(L2EffectFlag.RELAXING))
- {
- stopEffects(L2EffectType.RELAXING);
- }
- broadcastPacket(new ChangeWaitType(this, ChangeWaitType.WT_STANDING));
- // Schedule a stand up task to wait for the animation to finish
- ThreadPoolManager.getInstance().scheduleGeneral(new StandUpTask(), 2500);
- setIsParalyzed(true);
- }
- }
- /**
- * Stands up and close any opened shop window, if any.
- */
- public void forceStandUp()
- {
- // Cancels any shop types.
- if (isInStoreMode())
- {
- setPrivateStoreType(STORE_PRIVATE_NONE);
- broadcastUserInfo();
- }
- // Stand up.
- standUp();
- }
- /**
- * Used to sit or stand. If not possible, queue the action.
- * @param target The target, used for thrones types.
- * @param sittingState The sitting state, inheritated from packet or player status.
- */
- public void tryToSitOrStand(final L2Object target, final boolean sittingState)
- {
- if (isFakeDeath())
- {
- stopFakeDeath(true);
- return;
- }
- else if (isInStoreMode())
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- final boolean isThrone = target instanceof L2StaticObjectInstance && ((L2StaticObjectInstance) target).getType() == 1;
- // Player wants to sit on a throne but is out of radius, move to the throne delaying the sit action.
- if (isThrone && !sittingState && !isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
- {
- getAI().setIntention(CtrlIntention.MOVE_TO, new L2CharPosition(target.getX(), target.getY(), target.getZ(), 0));
- NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.MOVE_TO, new NextActionCallback()
- {
- @Override
- public void doWork()
- {
- if (getMountType() != 0)
- {
- return;
- }
- sitDown();
- broadcastPacket(new ChairSit(L2PcInstance.this, ((L2StaticObjectInstance) target).getStaticObjectId()));
- }
- });
- // Binding next action to AI.
- getAI().setNextAction(nextAction);
- return;
- }
- // Player isn't moving, sit directly.
- if (!isMoving())
- {
- if (getMountType() != 0)
- {
- return;
- }
- if (sittingState)
- {
- standUp();
- }
- else
- {
- sitDown();
- if (isThrone && isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
- {
- broadcastPacket(new ChairSit(this, ((L2StaticObjectInstance) target).getStaticObjectId()));
- }
- }
- }
- // Player is moving, wait the current action is done, then sit.
- else
- {
- NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.MOVE_TO, new NextActionCallback()
- {
- @Override
- public void doWork()
- {
- if (getMountType() != 0)
- {
- return;
- }
- if (sittingState)
- {
- standUp();
- }
- else
- {
- sitDown();
- if (isThrone && isInsideRadius(target, L2Npc.INTERACTION_DISTANCE, false, false))
- {
- broadcastPacket(new ChairSit(L2PcInstance.this, ((L2StaticObjectInstance) target).getStaticObjectId()));
- }
- }
- }
- });
- // Binding next action to AI.
- getAI().setNextAction(nextAction);
- }
- }
- /**
- * @return The PcWarehouse object of the L2PcInstance.
- */
- public PcWarehouse getWarehouse()
- {
- if (_warehouse == null)
- {
- _warehouse = new PcWarehouse(this);
- _warehouse.restore();
- }
- return _warehouse;
- }
- /**
- * Free memory used by Warehouse
- */
- public void clearWarehouse()
- {
- if (_warehouse != null)
- {
- _warehouse.deleteMe();
- }
- _warehouse = null;
- }
- /**
- * @return The PcFreight object of the L2PcInstance.
- */
- public PcFreight getFreight()
- {
- if (_freight == null)
- {
- _freight = new PcFreight(this);
- _freight.restore();
- }
- return _freight;
- }
- /**
- * Free memory used by Freight
- */
- public void clearFreight()
- {
- if (_freight != null)
- {
- _freight.deleteMe();
- }
- _freight = null;
- }
- /**
- * @param objectId The id of the owner.
- * @return deposited PcFreight object for the objectId or create new if not existing.
- */
- public PcFreight getDepositedFreight(int objectId)
- {
- for (PcFreight freight : _depositedFreight)
- {
- if (freight != null && freight.getOwnerId() == objectId)
- {
- return freight;
- }
- }
- PcFreight freight = new PcFreight(null);
- freight.doQuickRestore(objectId);
- _depositedFreight.add(freight);
- return freight;
- }
- /**
- * Clear memory used by deposited freight
- */
- public void clearDepositedFreight()
- {
- for (PcFreight freight : _depositedFreight)
- {
- if (freight != null)
- {
- freight.deleteMe();
- }
- }
- _depositedFreight.clear();
- }
- /**
- * @return The Adena amount of the L2PcInstance.
- */
- public int getAdena()
- {
- return _inventory.getAdena();
- }
- /**
- * @return The Ancient Adena amount of the L2PcInstance.
- */
- public int getAncientAdena()
- {
- return _inventory.getAncientAdena();
- }
- /**
- * Add adena to Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param count int Quantity of adena to be added
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- */
- public void addAdena(String process, int count, L2Object reference, boolean sendMessage)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA).addNumber(count));
- }
- if (count > 0)
- {
- _inventory.addAdena(process, count, this, reference);
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(_inventory.getAdenaInstance());
- sendPacket(iu);
- }
- }
- /**
- * Reduce adena in Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param count int Quantity of adena to be reduced
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- public boolean reduceAdena(String process, int count, L2Object reference, boolean sendMessage)
- {
- if (count > getAdena())
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
- }
- return false;
- }
- if (count > 0)
- {
- ItemInstance adenaItem = _inventory.getAdenaInstance();
- if (!_inventory.reduceAdena(process, count, this, reference))
- {
- return false;
- }
- // Send update packet
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(adenaItem);
- sendPacket(iu);
- if (sendMessage)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED_ADENA).addNumber(count));
- }
- }
- return true;
- }
- /**
- * Add ancient adena to Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param count int Quantity of ancient adena to be added
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- */
- public void addAncientAdena(String process, int count, L2Object reference, boolean sendMessage)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(PcInventory.ANCIENT_ADENA_ID).addNumber(count));
- }
- if (count > 0)
- {
- _inventory.addAncientAdena(process, count, this, reference);
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(_inventory.getAncientAdenaInstance());
- sendPacket(iu);
- }
- }
- /**
- * Reduce ancient adena in Inventory of the L2PcInstance and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param count int Quantity of ancient adena to be reduced
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- public boolean reduceAncientAdena(String process, int count, L2Object reference, boolean sendMessage)
- {
- if (count > getAncientAdena())
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
- }
- return false;
- }
- if (count > 0)
- {
- ItemInstance ancientAdenaItem = _inventory.getAncientAdenaInstance();
- if (!_inventory.reduceAncientAdena(process, count, this, reference))
- {
- return false;
- }
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(ancientAdenaItem);
- sendPacket(iu);
- if (sendMessage)
- {
- if (count > 1)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(PcInventory.ANCIENT_ADENA_ID).addItemNumber(count));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(PcInventory.ANCIENT_ADENA_ID));
- }
- }
- }
- return true;
- }
- /**
- * Adds item to inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param item ItemInstance to be added
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- */
- public void addItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
- {
- if (item.getCount() > 0)
- {
- // Sends message to client if requested
- if (sendMessage)
- {
- if (item.getCount() > 1)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(item).addNumber(item.getCount()));
- }
- else if (item.getEnchantLevel() > 0)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_A_S1_S2).addNumber(item.getEnchantLevel()).addItemName(item));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(item));
- }
- }
- // Add the item to inventory
- ItemInstance newitem = _inventory.addItem(process, item, this, reference);
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(newitem);
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
- // If over capacity, drop the item
- if (!_inventory.validateCapacity(0, item.isQuestItem()) && newitem.isDropable() && (!newitem.isStackable() || newitem.getLastChange() != ItemInstance.MODIFIED))
- {
- dropItem("InvDrop", newitem, null, true, true);
- }
- else if (CursedWeaponsManager.getInstance().isCursed(newitem.getItemId()))
- {
- CursedWeaponsManager.getInstance().activate(this, newitem);
- }
- else if (item.getItem().getItemType() == EtcItemType.ARROW && getAttackType() == WeaponType.BOW && getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
- {
- checkAndEquipArrows();
- }
- }
- }
- /**
- * Adds item to Inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param itemId int Item Identifier of the item to be added
- * @param count int Quantity of items to be added
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return The created ItemInstance.
- */
- public ItemInstance addItem(String process, int itemId, int count, L2Object reference, boolean sendMessage)
- {
- if (count > 0)
- {
- // Retrieve the template of the item.
- final Item item = ItemTable.getInstance().getTemplate(itemId);
- if (item == null)
- {
- _log.warn("Item id " + itemId + "doesn't exist, so it can't be added.");
- return null;
- }
- // Sends message to client if requested.
- if (sendMessage && ((!isCastingNow() && item.getItemType() == EtcItemType.HERB) || item.getItemType() != EtcItemType.HERB))
- {
- if (count > 1)
- {
- if (process.equalsIgnoreCase("Sweep") || process.equalsIgnoreCase("Quest"))
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(itemId).addItemNumber(count));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(itemId).addItemNumber(count));
- }
- }
- else
- {
- if (process.equalsIgnoreCase("Sweep") || process.equalsIgnoreCase("Quest"))
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1).addItemName(itemId));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(itemId));
- }
- }
- }
- // If the item is herb type, dont add it to inventory.
- if (item.getItemType() == EtcItemType.HERB)
- {
- final ItemInstance herb = new ItemInstance(0, itemId);
- final IItemHandler handler = ItemHandler.getInstance().getHandler(herb.getEtcItem());
- if (handler != null)
- {
- handler.useItem(this, herb, false);
- }
- }
- else
- {
- // Add the item to inventory
- final ItemInstance createdItem = _inventory.addItem(process, itemId, count, this, reference);
- // If over capacity, drop the item
- if (!_inventory.validateCapacity(0, item.isQuestItem()) && createdItem.isDropable() && (!createdItem.isStackable() || createdItem.getLastChange() != ItemInstance.MODIFIED))
- {
- dropItem("InvDrop", createdItem, null, true);
- }
- else if (CursedWeaponsManager.getInstance().isCursed(createdItem.getItemId()))
- {
- CursedWeaponsManager.getInstance().activate(this, createdItem);
- }
- else if (item.getItemType() == EtcItemType.ARROW && getAttackType() == WeaponType.BOW && getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
- {
- checkAndEquipArrows();
- }
- return createdItem;
- }
- }
- return null;
- }
- public boolean addItem(String process, int[] itemsId, int[] counts, L2Object reference, boolean sendMessage)
- {
- if (itemsId.length == 0 || itemsId.length != counts.length)
- {
- return false;
- }
- for (int i = 0; i < itemsId.length; i++)
- {
- if (addItem(process, itemsId[i], counts[i], reference, sendMessage) == null)
- {
- return false;
- }
- }
- return true;
- }
- /**
- * Destroy item from inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param item ItemInstance to be destroyed
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- public boolean destroyItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
- {
- return this.destroyItem(process, item, item.getCount(), reference, sendMessage);
- }
- /**
- * Destroy item from inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param item ItemInstance to be destroyed
- * @param count int Quantity of ancient adena to be reduced
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- public boolean destroyItem(String process, ItemInstance item, int count, L2Object reference, boolean sendMessage)
- {
- item = _inventory.destroyItem(process, item, count, this, reference);
- if (item == null)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return false;
- }
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(item);
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
- // Sends message to client if requested
- if (sendMessage)
- {
- if (count > 1)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(item).addItemNumber(count));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(item));
- }
- }
- return true;
- }
- /**
- * Destroys item from inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param objectId int Item Instance identifier of the item to be destroyed
- * @param count int Quantity of items to be destroyed
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- @Override
- public boolean destroyItem(String process, int objectId, int count, L2Object reference, boolean sendMessage)
- {
- ItemInstance item = _inventory.getItemByObjectId(objectId);
- if (item == null)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return false;
- }
- return this.destroyItem(process, item, count, reference, sendMessage);
- }
- /**
- * Destroys shots from inventory without logging and only occasional saving to database. Sends InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param objectId int Item Instance identifier of the item to be destroyed
- * @param count int Quantity of items to be destroyed
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- public boolean destroyItemWithoutTrace(String process, int objectId, int count, L2Object reference, boolean sendMessage)
- {
- ItemInstance item = _inventory.getItemByObjectId(objectId);
- if (item == null || item.getCount() < count)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return false;
- }
- return this.destroyItem(null, item, count, reference, sendMessage);
- }
- /**
- * Destroy item from inventory by using its <B>itemId</B> and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param itemId int Item identifier of the item to be destroyed
- * @param count int Quantity of items to be destroyed
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @return boolean informing if the action was successfull
- */
- @Override
- public boolean destroyItemByItemId(String process, int itemId, int count, L2Object reference, boolean sendMessage)
- {
- if (itemId == 57)
- {
- return reduceAdena(process, count, reference, sendMessage);
- }
- ItemInstance item = _inventory.getItemByItemId(itemId);
- if (item == null || item.getCount() < count || _inventory.destroyItemByItemId(process, itemId, count, this, reference) == null)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return false;
- }
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(item);
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
- // Sends message to client if requested
- if (sendMessage)
- {
- if (count > 1)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED).addItemName(itemId).addItemNumber(count));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(itemId));
- }
- }
- return true;
- }
- /**
- * Transfers item to another ItemContainer and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param objectId int Item Identifier of the item to be transfered
- * @param count int Quantity of items to be transfered
- * @param target Inventory the Inventory target.
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @return ItemInstance corresponding to the new item or the updated item in inventory
- */
- public ItemInstance transferItem(String process, int objectId, int count, Inventory target, L2Object reference)
- {
- final ItemInstance oldItem = checkItemManipulation(objectId, count);
- if (oldItem == null)
- {
- return null;
- }
- final ItemInstance newItem = getInventory().transferItem(process, objectId, count, target, this, reference);
- if (newItem == null)
- {
- return null;
- }
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- if (oldItem.getCount() > 0 && oldItem != newItem)
- {
- playerIU.addModifiedItem(oldItem);
- }
- else
- {
- playerIU.addRemovedItem(oldItem);
- }
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate playerSU = new StatusUpdate(this);
- playerSU.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(playerSU);
- // Send target update packet
- if (target instanceof PcInventory)
- {
- final L2PcInstance targetPlayer = ((PcInventory) target).getOwner();
- InventoryUpdate playerIU2 = new InventoryUpdate();
- if (newItem.getCount() > count)
- {
- playerIU2.addModifiedItem(newItem);
- }
- else
- {
- playerIU2.addNewItem(newItem);
- }
- targetPlayer.sendPacket(playerIU2);
- // Update current load as well
- playerSU = new StatusUpdate(targetPlayer);
- playerSU.addAttribute(StatusUpdate.CUR_LOAD, targetPlayer.getCurrentLoad());
- targetPlayer.sendPacket(playerSU);
- }
- else if (target instanceof PetInventory)
- {
- PetInventoryUpdate petIU = new PetInventoryUpdate();
- if (newItem.getCount() > count)
- {
- petIU.addModifiedItem(newItem);
- }
- else
- {
- petIU.addNewItem(newItem);
- }
- ((PetInventory) target).getOwner().getOwner().sendPacket(petIU);
- }
- return newItem;
- }
- /**
- * Drop item from inventory and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param item ItemInstance to be dropped
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @param protectItem whether or not dropped item must be protected temporary against other players
- * @return boolean informing if the action was successfull
- */
- public boolean dropItem(String process, ItemInstance item, L2Object reference, boolean sendMessage, boolean protectItem)
- {
- item = _inventory.dropItem(process, item, this, reference);
- if (item == null)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return false;
- }
- item.dropMe(this, getX() + Rnd.get(50) - 25, getY() + Rnd.get(50) - 25, getZ() + 20);
- if (Config.ITEM_AUTO_DESTROY_TIME > 0 && Config.DESTROY_DROPPED_PLAYER_ITEM && !Config.LIST_PROTECTED_ITEMS.contains(item.getItemId()))
- {
- if ((item.isEquipable() && Config.DESTROY_EQUIPABLE_PLAYER_ITEM) || !item.isEquipable())
- {
- ItemsAutoDestroyTaskManager.getInstance().addItem(item);
- }
- }
- if (Config.DESTROY_DROPPED_PLAYER_ITEM)
- {
- if (!item.isEquipable() || (item.isEquipable() && Config.DESTROY_EQUIPABLE_PLAYER_ITEM))
- {
- item.setProtected(false);
- }
- else
- {
- item.setProtected(true);
- }
- }
- else
- {
- item.setProtected(true);
- }
- // retail drop protection
- if (protectItem)
- {
- item.getDropProtection().protect(this);
- }
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(item);
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
- // Sends message to client if requested
- if (sendMessage)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DROPPED_S1).addItemName(item));
- }
- return true;
- }
- public boolean dropItem(String process, ItemInstance item, L2Object reference, boolean sendMessage)
- {
- return dropItem(process, item, reference, sendMessage, false);
- }
- /**
- * Drop item from inventory by using its <B>objectID</B> and send InventoryUpdate packet to the L2PcInstance.
- * @param process String Identifier of process triggering this action
- * @param objectId int Item Instance identifier of the item to be dropped
- * @param count int Quantity of items to be dropped
- * @param x int coordinate for drop X
- * @param y int coordinate for drop Y
- * @param z int coordinate for drop Z
- * @param reference L2Object Object referencing current action like NPC selling item or previous item in transformation
- * @param sendMessage boolean Specifies whether to send message to Client about this action
- * @param protectItem boolean Activates drop protection on that item if true
- * @return ItemInstance corresponding to the new item or the updated item in inventory
- */
- public ItemInstance dropItem(String process, int objectId, int count, int x, int y, int z, L2Object reference, boolean sendMessage, boolean protectItem)
- {
- ItemInstance invitem = _inventory.getItemByObjectId(objectId);
- ItemInstance item = _inventory.dropItem(process, objectId, count, this, reference);
- if (item == null)
- {
- if (sendMessage)
- {
- sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
- }
- return null;
- }
- item.dropMe(this, x, y, z);
- if (Config.ITEM_AUTO_DESTROY_TIME > 0 && Config.DESTROY_DROPPED_PLAYER_ITEM && !Config.LIST_PROTECTED_ITEMS.contains(item.getItemId()))
- {
- if ((item.isEquipable() && Config.DESTROY_EQUIPABLE_PLAYER_ITEM) || !item.isEquipable())
- {
- ItemsAutoDestroyTaskManager.getInstance().addItem(item);
- }
- }
- if (Config.DESTROY_DROPPED_PLAYER_ITEM)
- {
- if (!item.isEquipable() || (item.isEquipable() && Config.DESTROY_EQUIPABLE_PLAYER_ITEM))
- {
- item.setProtected(false);
- }
- else
- {
- item.setProtected(true);
- }
- }
- else
- {
- item.setProtected(true);
- }
- // retail drop protection
- if (protectItem)
- {
- item.getDropProtection().protect(this);
- }
- // Send inventory update packet
- InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(invitem);
- sendPacket(playerIU);
- // Update current load as well
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
- // Sends message to client if requested
- if (sendMessage)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DROPPED_S1).addItemName(item));
- }
- return item;
- }
- public ItemInstance checkItemManipulation(int objectId, int count)
- {
- if (L2World.getInstance().findObject(objectId) == null)
- {
- return null;
- }
- final ItemInstance item = getInventory().getItemByObjectId(objectId);
- if (item == null || item.getOwnerId() != getObjectId())
- {
- return null;
- }
- if (count < 1 || (count > 1 && !item.isStackable()))
- {
- return null;
- }
- if (count > item.getCount())
- {
- return null;
- }
- // Pet is summoned and not the item that summoned the pet AND not the buggle from strider you're mounting
- if (getPet() != null && getPet().getControlItemId() == objectId || getMountObjectID() == objectId)
- {
- return null;
- }
- if (getActiveEnchantItem() != null && getActiveEnchantItem().getObjectId() == objectId)
- {
- return null;
- }
- // We cannot put a Weapon with Augmention in WH while casting (Possible Exploit)
- if (item.isAugmented() && (isCastingNow() || isCastingSimultaneouslyNow()))
- {
- return null;
- }
- return item;
- }
- /**
- * Launch a task corresponding to Config time.
- * @param protect boolean Drop timer or activate it.
- */
- public void setProtection(boolean protect)
- {
- if (protect)
- {
- if (_protectTask == null)
- {
- _protectTask = ThreadPoolManager.getInstance().scheduleGeneral(new ProtectTask(), Config.PLAYER_SPAWN_PROTECTION * 1000);
- }
- }
- else
- {
- _protectTask.cancel(true);
- _protectTask = null;
- }
- broadcastUserInfo();
- }
- public boolean isSpawnProtected()
- {
- return _protectTask != null;
- }
- protected class ProtectTask implements Runnable
- {
- @Override
- public void run()
- {
- setProtection(false);
- sendMessage("The spawn protection has ended.");
- }
- }
- /**
- * Set protection from agro mobs when getting up from fake death, according settings.
- * @param protect boolean Drop timer or activate it.
- */
- public void setRecentFakeDeath(boolean protect)
- {
- _recentFakeDeathEndTime = protect ? GameTimeController.getGameTicks() + Config.PLAYER_FAKEDEATH_UP_PROTECTION * GameTimeController.TICKS_PER_SECOND : 0;
- }
- public boolean isRecentFakeDeath()
- {
- return _recentFakeDeathEndTime > GameTimeController.getGameTicks();
- }
- public final boolean isFakeDeath()
- {
- return _isFakeDeath;
- }
- public final void setIsFakeDeath(boolean value)
- {
- _isFakeDeath = value;
- }
- @Override
- public final boolean isAlikeDead()
- {
- if (super.isAlikeDead())
- {
- return true;
- }
- return isFakeDeath();
- }
- /**
- * @return The client owner of this char.
- */
- public L2GameClient getClient()
- {
- return _client;
- }
- public void setClient(L2GameClient client)
- {
- _client = client;
- }
- /**
- * Close the active connection with the client.
- * @param closeClient
- */
- public void closeNetConnection(boolean closeClient)
- {
- L2GameClient client = _client;
- if (client != null)
- {
- if (client.isDetached())
- {
- client.cleanMe(true);
- }
- else
- {
- if (!client.getConnection().isClosed())
- {
- if (closeClient)
- {
- client.close(LeaveWorld.STATIC_PACKET);
- }
- else
- {
- client.close(ServerClose.STATIC_PACKET);
- }
- }
- }
- }
- }
- public Point3D getCurrentSkillWorldPosition()
- {
- return _currentSkillWorldPosition;
- }
- public void setCurrentSkillWorldPosition(Point3D worldPosition)
- {
- _currentSkillWorldPosition = worldPosition;
- }
- /**
- * @see net.sf.l2j.gameserver.model.actor.L2Character#enableSkill(net.sf.l2j.gameserver.model.L2Skill)
- */
- @Override
- public void enableSkill(L2Skill skill)
- {
- super.enableSkill(skill);
- _reuseTimeStamps.remove(skill.getReuseHashCode());
- }
- /**
- * @see net.sf.l2j.gameserver.model.actor.L2Character#checkDoCastConditions(net.sf.l2j.gameserver.model.L2Skill)
- */
- @Override
- protected boolean checkDoCastConditions(L2Skill skill)
- {
- if (!super.checkDoCastConditions(skill))
- {
- return false;
- }
- if (skill.getSkillType() == L2SkillType.SUMMON)
- {
- if (!((L2SkillSummon) skill).isCubic() && (getPet() != null || isMounted()))
- {
- sendPacket(SystemMessageId.SUMMON_ONLY_ONE);
- return false;
- }
- }
- // Can't use Hero and resurrect skills during Olympiad
- if (isInOlympiadMode() && (skill.isHeroSkill() || skill.getSkillType() == L2SkillType.RESURRECT))
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
- return false;
- }
- // Check if the spell uses charges
- final int charges = getCharges();
- if (skill.getMaxCharges() == 0 && charges < skill.getNumCharges())
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill));
- return false;
- }
- return true;
- }
- /**
- * Manage actions when a player click on this L2PcInstance.<BR>
- * <BR>
- * <B><U> Actions on first click on the L2PcInstance (Select it)</U> :</B>
- * <ul>
- * <li>Set the target of the player</li>
- * <li>Send MyTargetSelected to the player (display the select window)</li>
- * </ul>
- * <B><U> Actions on second click on the L2PcInstance (Follow it/Attack it/Intercat with it)</U> :</B>
- * <ul>
- * <li>Send MyTargetSelected to the player (display the select window)</li>
- * <li>If this L2PcInstance has a Private Store, notify the player AI with INTERACT</li>
- * <li>If this L2PcInstance is autoAttackable, notify the player AI with ATTACK</li>
- * <li>If this L2PcInstance is NOT autoAttackable, notify the player AI with FOLLOW</li>
- * </ul>
- * @param player The player that start an action on this L2PcInstance
- */
- @Override
- public void onAction(L2PcInstance player)
- {
- if (player._event != _event)
- {
- if ((player._event != null && !player._event.canInteract(player, this)) || (_event != null && !_event.canInteract(player, this)) && !player.isGM())
- {
- player.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- if (player.getTarget() != this)
- {
- player.setTarget(this);
- }
- else
- {
- // Check if this L2PcInstance has a Private Store
- if (isInStoreMode())
- {
- player.getAI().setIntention(CtrlIntention.INTERACT, this);
- return;
- }
- // Check if this L2PcInstance is autoAttackable
- if (isAutoAttackable(player))
- {
- // Player with lvl < 21 can't attack a cursed weapon holder and a cursed weapon holder can't attack players with lvl < 21
- if ((isCursedWeaponEquipped() && player.getLevel() < 21) || (player.isCursedWeaponEquipped() && getLevel() < 21))
- {
- player.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (Config.GEODATA == 0 || GeoData.getInstance().canSeeTarget(player, this))
- {
- player.getAI().setIntention(CtrlIntention.ATTACK, this);
- player.onActionRequest();
- }
- }
- else
- {
- // avoids to stuck when clicking two or more times
- player.sendPacket(ActionFailed.STATIC_PACKET);
- if (player != this && (Config.GEODATA == 0 || GeoData.getInstance().canSeeTarget(player, this)))
- {
- player.getAI().setIntention(CtrlIntention.FOLLOW, this);
- }
- }
- }
- }
- /**
- * @param barPixels
- * @return true if cp update should be done, false if not
- */
- private boolean needCpUpdate(int barPixels)
- {
- double currentCp = getCurrentCp();
- if (currentCp <= 1.0 || getMaxCp() < barPixels)
- {
- return true;
- }
- if (currentCp <= _cpUpdateDecCheck || currentCp >= _cpUpdateIncCheck)
- {
- if (currentCp == getMaxCp())
- {
- _cpUpdateIncCheck = currentCp + 1;
- _cpUpdateDecCheck = currentCp - _cpUpdateInterval;
- }
- else
- {
- double doubleMulti = currentCp / _cpUpdateInterval;
- int intMulti = (int) doubleMulti;
- _cpUpdateDecCheck = _cpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
- _cpUpdateIncCheck = _cpUpdateDecCheck + _cpUpdateInterval;
- }
- return true;
- }
- return false;
- }
- /**
- * @param barPixels
- * @return true if mp update should be done, false if not
- */
- private boolean needMpUpdate(int barPixels)
- {
- double currentMp = getCurrentMp();
- if (currentMp <= 1.0 || getMaxMp() < barPixels)
- {
- return true;
- }
- if (currentMp <= _mpUpdateDecCheck || currentMp >= _mpUpdateIncCheck)
- {
- if (currentMp == getMaxMp())
- {
- _mpUpdateIncCheck = currentMp + 1;
- _mpUpdateDecCheck = currentMp - _mpUpdateInterval;
- }
- else
- {
- double doubleMulti = currentMp / _mpUpdateInterval;
- int intMulti = (int) doubleMulti;
- _mpUpdateDecCheck = _mpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
- _mpUpdateIncCheck = _mpUpdateDecCheck + _mpUpdateInterval;
- }
- return true;
- }
- return false;
- }
- /**
- * 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.
- * <ul>
- * <li>Send StatusUpdate with current HP, MP and CP to this L2PcInstance</li>
- * <li>Send PartySmallWindowUpdate with current HP, MP and Level to all other L2PcInstance of the Party</li>
- * </ul>
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND current HP and MP to all L2PcInstance of the _statusListener</B></FONT>
- */
- @Override
- public void broadcastStatusUpdate()
- {
- // Send StatusUpdate with current HP, MP and CP to this L2PcInstance
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
- su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
- su.addAttribute(StatusUpdate.CUR_CP, (int) getCurrentCp());
- su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
- sendPacket(su);
- final boolean needCpUpdate = needCpUpdate(352);
- final boolean needHpUpdate = needHpUpdate(352);
- // Check if a party is in progress and party window update is needed.
- if (_party != null && (needCpUpdate || needHpUpdate || needMpUpdate(352)))
- {
- _party.broadcastToPartyMembers(this, new PartySmallWindowUpdate(this));
- }
- if (isInOlympiadMode() && isOlympiadStart() && (needCpUpdate || needHpUpdate))
- {
- final OlympiadGameTask game = OlympiadGameManager.getInstance().getOlympiadTask(getOlympiadGameId());
- if (game != null && game.isBattleStarted())
- {
- game.getZone().broadcastStatusUpdate(this);
- }
- }
- // In duel, MP updated only with CP or HP
- if (isInDuel() && (needCpUpdate || needHpUpdate))
- {
- ExDuelUpdateUserInfo update = new ExDuelUpdateUserInfo(this);
- DuelManager.getInstance().broadcastToOppositeTeam(this, update);
- }
- }
- /**
- * Broadcast informations from a user to himself and his knownlist.<BR>
- * If player is morphed, it sends informations from the template the player is using.
- * <ul>
- * <li>Send a UserInfo packet (public and private data) to this L2PcInstance.</li>
- * <li>Send a CharInfo packet (public data only) to L2PcInstance's knownlist.</li>
- * </ul>
- */
- public final void broadcastUserInfo()
- {
- sendPacket(new UserInfo(this));
- if (getPoly().isMorphed())
- {
- Broadcast.toKnownPlayers(this, new AbstractNpcInfo.PcMorphInfo(this, getPoly().getNpcTemplate()));
- }
- else
- {
- broadcastCharInfo();
- }
- }
- public final void broadcastCharInfo()
- {
- for (L2PcInstance player : getKnownList().getKnownType(L2PcInstance.class))
- {
- player.sendPacket(new CharInfo(this));
- final int relation = getRelation(player);
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable(player)));
- if (getPet() != null)
- {
- player.sendPacket(new RelationChanged(getPet(), relation, isAutoAttackable(player)));
- }
- }
- }
- /**
- * Broadcast player title information.
- */
- public final void broadcastTitleInfo()
- {
- sendPacket(new UserInfo(this));
- broadcastPacket(new TitleUpdate(this));
- }
- /**
- * @return the Alliance Identifier of the L2PcInstance.
- */
- public int getAllyId()
- {
- if (_clan == null)
- {
- return 0;
- }
- return _clan.getAllyId();
- }
- public int getAllyCrestId()
- {
- if (getClanId() == 0)
- {
- return 0;
- }
- if (getClan().getAllyId() == 0)
- {
- return 0;
- }
- return getClan().getAllyCrestId();
- }
- /**
- * Send a packet to the L2PcInstance.
- */
- @Override
- public void sendPacket(L2GameServerPacket packet)
- {
- if (_client != null)
- {
- _client.sendPacket(packet);
- }
- }
- /**
- * Send SystemMessage packet.
- * @param id SystemMessageId
- */
- @Override
- public void sendPacket(SystemMessageId id)
- {
- sendPacket(SystemMessage.getSystemMessage(id));
- }
- /**
- * Manage Interact Task with another L2PcInstance.<BR>
- * Turn the character in front of the target.<BR>
- * In case of private stores, send the related packet.
- * @param target The L2Character targeted
- */
- public void doInteract(L2Character target)
- {
- if (target instanceof L2PcInstance)
- {
- L2PcInstance temp = (L2PcInstance) target;
- sendPacket(new MoveToPawn(this, temp, L2Npc.INTERACTION_DISTANCE));
- switch (temp.getPrivateStoreType())
- {
- case STORE_PRIVATE_SELL:
- case STORE_PRIVATE_PACKAGE_SELL:
- sendPacket(new PrivateStoreListSell(this, temp));
- break;
- case STORE_PRIVATE_BUY:
- sendPacket(new PrivateStoreListBuy(this, temp));
- break;
- case STORE_PRIVATE_MANUFACTURE:
- sendPacket(new RecipeShopSellList(this, temp));
- break;
- }
- }
- else
- {
- // _interactTarget=null should never happen but one never knows ^^;
- if (target != null)
- {
- target.onAction(this);
- }
- }
- }
- /**
- * Manage AutoLoot Task.
- * <ul>
- * <li>Send a System Message to the L2PcInstance : YOU_PICKED_UP_S1_ADENA or YOU_PICKED_UP_S1_S2</li>
- * <li>Add the Item to the L2PcInstance inventory</li>
- * <li>Send InventoryUpdate to this L2PcInstance with NewItem (use a new slot) or ModifiedItem (increase amount)</li>
- * <li>Send StatusUpdate to this L2PcInstance with current weight</li>
- * </ul>
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : If a Party is in progress, distribute Items between party members</B></FONT>
- * @param target The reference Object.
- * @param item The dropped ItemHolder.
- */
- public void doAutoLoot(L2Attackable target, ItemHolder item)
- {
- if (isInParty())
- {
- getParty().distributeItem(this, item, false, target);
- }
- else if (item.getId() == 57)
- {
- addAdena("Loot", item.getCount(), target, true);
- }
- else
- {
- addItem("Loot", item.getId(), item.getCount(), target, true);
- }
- }
- /**
- * Manage Pickup Task.
- * <ul>
- * <li>Send StopMove to this L2PcInstance</li>
- * <li>Remove the ItemInstance from the world and send GetItem packets</li>
- * <li>Send a System Message to the L2PcInstance : YOU_PICKED_UP_S1_ADENA or YOU_PICKED_UP_S1_S2</li>
- * <li>Add the Item to the L2PcInstance inventory</li>
- * <li>Send InventoryUpdate to this L2PcInstance with NewItem (use a new slot) or ModifiedItem (increase amount)</li>
- * <li>Send StatusUpdate to this L2PcInstance with current weight</li>
- * </ul>
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : If a Party is in progress, distribute Items between party members</B></FONT>
- * @param object The ItemInstance to pick up
- */
- protected void doPickupItem(L2Object object)
- {
- if (isAlikeDead() || isFakeDeath())
- {
- return;
- }
- // Set the AI Intention to IDLE
- getAI().setIntention(CtrlIntention.IDLE);
- // Check if the L2Object to pick up is a ItemInstance
- if (!(object instanceof ItemInstance))
- {
- // dont try to pickup anything that is not an item :)
- _log.warn(getName() + " tried to pickup a wrong target: " + object);
- return;
- }
- ItemInstance target = (ItemInstance) object;
- // Send ActionFailed to this L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- sendPacket(new StopMove(this));
- synchronized (target)
- {
- // Check if the target to pick up is visible
- if (!target.isVisible())
- {
- return;
- }
- if (!target.getDropProtection().tryPickUp(this))
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1).addItemName(target.getItemId()));
- return;
- }
- if (((isInParty() && getParty().getLootDistribution() == L2Party.ITEM_LOOTER) || !isInParty()) && !_inventory.validateCapacity(target))
- {
- sendPacket(SystemMessageId.SLOTS_FULL);
- return;
- }
- if (getActiveTradeList() != null)
- {
- sendPacket(SystemMessageId.CANNOT_PICKUP_OR_USE_ITEM_WHILE_TRADING);
- return;
- }
- if (target.getOwnerId() != 0 && target.getOwnerId() != getObjectId() && !isInLooterParty(target.getOwnerId()))
- {
- if (target.getItemId() == 57)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1_ADENA).addNumber(target.getCount()));
- }
- else if (target.getCount() > 1)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S2_S1_S).addItemName(target).addNumber(target.getCount()));
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_TO_PICKUP_S1).addItemName(target));
- }
- return;
- }
- if (target.getItemLootShedule() != null && (target.getOwnerId() == getObjectId() || isInLooterParty(target.getOwnerId())))
- {
- target.resetOwnerTimer();
- }
- if (target.getItemId() == 57 && getInventory().getAdenaInstance() != null)
- {
- if (getInventory().getAdena() == Integer.MAX_VALUE)
- {
- return;
- }
- }
- // Remove the ItemInstance from the world and send GetItem packets
- target.pickupMe(this);
- if (Config.SAVE_DROPPED_ITEM)
- {
- ItemsOnGroundManager.getInstance().removeObject(target);
- }
- }
- // Auto use herbs - pick up
- if (target.getItemType() == EtcItemType.HERB)
- {
- IItemHandler handler = ItemHandler.getInstance().getHandler(target.getEtcItem());
- if (handler != null)
- {
- handler.useItem(this, target, false);
- }
- ItemTable.getInstance().destroyItem("Consume", target, this, null);
- }
- // Cursed Weapons are not distributed
- else if (CursedWeaponsManager.getInstance().isCursed(target.getItemId()))
- {
- addItem("Pickup", target, null, true);
- }
- else
- {
- // if item is instance of L2ArmorType or WeaponType broadcast an "Attention" system message
- if (target.getItemType() instanceof ArmorType || target.getItemType() instanceof WeaponType)
- {
- if (target.getEnchantLevel() > 0)
- {
- SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.ATTENTION_S1_PICKED_UP_S2_S3);
- msg.addString(getName());
- msg.addNumber(target.getEnchantLevel());
- msg.addItemName(target.getItemId());
- broadcastPacket(msg, 1400);
- }
- else
- {
- SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.ATTENTION_S1_PICKED_UP_S2);
- msg.addString(getName());
- msg.addItemName(target.getItemId());
- broadcastPacket(msg, 1400);
- }
- }
- // Check if a Party is in progress
- if (isInParty())
- {
- getParty().distributeItem(this, target);
- }
- else if (target.getItemId() == 57 && getInventory().getAdenaInstance() != null)
- {
- addAdena("Pickup", target.getCount(), null, true);
- ItemTable.getInstance().destroyItem("Pickup", target, this, null);
- }
- // Target is regular item
- else
- {
- addItem("Pickup", target, null, true);
- }
- }
- }
- public boolean canOpenPrivateStore()
- {
- if (getActiveTradeList() != null)
- {
- cancelActiveTrade();
- }
- return !isAlikeDead() && !isInOlympiadMode() && !isMounted() && !isInsideZone(ZoneId.NO_STORE) && !isCastingNow() && !isInsideZone(ZoneId.WATER);
- }
- public void tryOpenPrivateBuyStore()
- {
- if (canOpenPrivateStore())
- {
- if (getPrivateStoreType() == STORE_PRIVATE_BUY || getPrivateStoreType() == STORE_PRIVATE_BUY_MANAGE)
- {
- setPrivateStoreType(STORE_PRIVATE_NONE);
- }
- if (getPrivateStoreType() == STORE_PRIVATE_NONE)
- {
- standUp();
- setPrivateStoreType(STORE_PRIVATE_BUY_MANAGE);
- sendPacket(new PrivateStoreManageListBuy(this));
- }
- }
- else
- {
- if (isInsideZone(ZoneId.NO_STORE))
- {
- sendPacket(SystemMessageId.NO_PRIVATE_STORE_HERE);
- }
- sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- public void tryOpenPrivateSellStore(boolean isPackageSale)
- {
- if (canOpenPrivateStore())
- {
- if (getPrivateStoreType() == STORE_PRIVATE_SELL || getPrivateStoreType() == STORE_PRIVATE_SELL_MANAGE || getPrivateStoreType() == STORE_PRIVATE_PACKAGE_SELL)
- {
- setPrivateStoreType(STORE_PRIVATE_NONE);
- }
- if (getPrivateStoreType() == STORE_PRIVATE_NONE)
- {
- standUp();
- setPrivateStoreType(STORE_PRIVATE_SELL_MANAGE);
- sendPacket(new PrivateStoreManageListSell(this, isPackageSale));
- }
- }
- else
- {
- if (isInsideZone(ZoneId.NO_STORE))
- {
- sendPacket(SystemMessageId.NO_PRIVATE_STORE_HERE);
- }
- sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- public void tryOpenWorkshop(boolean isDwarven)
- {
- if (canOpenPrivateStore())
- {
- if (isInStoreMode())
- {
- setPrivateStoreType(STORE_PRIVATE_NONE);
- }
- if (getPrivateStoreType() == STORE_PRIVATE_NONE)
- {
- standUp();
- if (getCreateList() == null)
- {
- setCreateList(new L2ManufactureList());
- }
- setPrivateStoreType(STORE_PRIVATE_MANUFACTURE_MANAGE);
- sendPacket(new RecipeShopManageList(this, isDwarven));
- }
- }
- else
- {
- if (isInsideZone(ZoneId.NO_STORE))
- {
- sendPacket(SystemMessageId.NO_PRIVATE_WORKSHOP_HERE);
- }
- sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- /**
- * Set a target.
- * <ul>
- * <li>Remove the L2PcInstance from the _statusListener of the old target if it was a L2Character</li>
- * <li>Add the L2PcInstance to the _statusListener of the new target if it's a L2Character</li>
- * <li>Target the new L2Object (add the target to the L2PcInstance _target, _knownObject and L2PcInstance to _KnownObject of the L2Object)</li>
- * </ul>
- * @param newTarget The L2Object to target
- */
- @Override
- public void setTarget(L2Object newTarget)
- {
- if (newTarget != null)
- {
- boolean isParty = (((newTarget instanceof L2PcInstance) && isInParty() && getParty().getPartyMembers().contains(newTarget)));
- // Check if the new target is visible
- if (!isParty && (!newTarget.isVisible() || Math.abs(newTarget.getZ() - getZ()) > 1000))
- {
- newTarget = null;
- }
- }
- // Can't target and attack festival monsters if not participant
- if ((newTarget instanceof L2FestivalMonsterInstance) && !isFestivalParticipant())
- {
- newTarget = null;
- }
- else if (isInParty() && getParty().isInDimensionalRift())
- {
- byte riftType = getParty().getDimensionalRift().getType();
- byte riftRoom = getParty().getDimensionalRift().getCurrentRoom();
- if (newTarget != null && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(newTarget.getX(), newTarget.getY(), newTarget.getZ()))
- {
- newTarget = null;
- }
- }
- if (newTarget instanceof L2PcInstance)
- {
- sendPacket(new MyTargetSelected(getObjectId(), 0));
- }
- // Get the current target
- L2Object oldTarget = getTarget();
- if (oldTarget != null)
- {
- if (oldTarget.equals(newTarget))
- {
- return; // no target change
- }
- // Remove the L2PcInstance from the _statusListener of the old target if it was a L2Character
- if (oldTarget instanceof L2Character)
- {
- ((L2Character) oldTarget).removeStatusListener(this);
- }
- }
- // Verify if it's a static object.
- if (newTarget instanceof L2StaticObjectInstance)
- {
- sendPacket(new MyTargetSelected(newTarget.getObjectId(), getLevel()));
- sendPacket(new StaticObject((L2StaticObjectInstance) newTarget));
- }
- // Add the L2PcInstance to the _statusListener of the new target if it's a L2Character
- else if (newTarget instanceof L2Character)
- {
- final L2Character target = (L2Character) newTarget;
- target.addStatusListener(this);
- // Show the client his new target.
- if (target.isAutoAttackable(this))
- {
- // Show the client his new target.
- sendPacket(new MyTargetSelected(target.getObjectId(), getLevel() - target.getLevel()));
- // Send max/current hp.
- final StatusUpdate su = new StatusUpdate(target);
- su.addAttribute(StatusUpdate.MAX_HP, target.getMaxHp());
- su.addAttribute(StatusUpdate.CUR_HP, (int) target.getCurrentHp());
- sendPacket(su);
- }
- else
- {
- sendPacket(new MyTargetSelected(target.getObjectId(), 0));
- }
- Broadcast.toKnownPlayers(this, new TargetSelected(getObjectId(), newTarget.getObjectId(), getX(), getY(), getZ()));
- }
- if (newTarget == null && getTarget() != null)
- {
- broadcastPacket(new TargetUnselected(this));
- setCurrentFolkNPC(null);
- }
- else
- {
- // Rehabilitates that useful check.
- if (newTarget instanceof L2NpcInstance)
- {
- setCurrentFolkNPC((L2Npc) newTarget);
- }
- }
- // Target the new L2Object (add the target to the L2PcInstance _target, _knownObject and L2PcInstance to _KnownObject of the L2Object)
- super.setTarget(newTarget);
- }
- /**
- * Return the active weapon instance (always equipped in the right hand).
- */
- @Override
- public ItemInstance getActiveWeaponInstance()
- {
- return getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
- }
- /**
- * Return the active weapon item (always equipped in the right hand).
- */
- @Override
- public Weapon getActiveWeaponItem()
- {
- ItemInstance weapon = getActiveWeaponInstance();
- if (weapon == null)
- {
- return getFistsWeaponItem();
- }
- return (Weapon) weapon.getItem();
- }
- public ItemInstance getChestArmorInstance()
- {
- return getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
- }
- public Armor getActiveChestArmorItem()
- {
- ItemInstance armor = getChestArmorInstance();
- if (armor == null)
- {
- return null;
- }
- return (Armor) armor.getItem();
- }
- public boolean isWearingHeavyArmor()
- {
- ItemInstance armor = getChestArmorInstance();
- if ((ArmorType) armor.getItemType() == ArmorType.HEAVY)
- {
- return true;
- }
- return false;
- }
- public boolean isWearingLightArmor()
- {
- ItemInstance armor = getChestArmorInstance();
- if ((ArmorType) armor.getItemType() == ArmorType.LIGHT)
- {
- return true;
- }
- return false;
- }
- public boolean isWearingMagicArmor()
- {
- ItemInstance armor = getChestArmorInstance();
- if ((ArmorType) armor.getItemType() == ArmorType.MAGIC)
- {
- return true;
- }
- return false;
- }
- public boolean isMarried()
- {
- return _married;
- }
- public void setMarried(boolean state)
- {
- _married = state;
- }
- public void setUnderMarryRequest(boolean state)
- {
- _marryrequest = state;
- }
- public boolean isUnderMarryRequest()
- {
- return _marryrequest;
- }
- public int getCoupleId()
- {
- return _coupleId;
- }
- public void setCoupleId(int coupleId)
- {
- _coupleId = coupleId;
- }
- public void setRequesterId(int requesterId)
- {
- _requesterId = requesterId;
- }
- public void EngageAnswer(int answer)
- {
- if (!_marryrequest || _requesterId == 0)
- {
- return;
- }
- L2PcInstance ptarget = L2World.getInstance().getPlayer(_requesterId);
- if (ptarget != null)
- {
- if (answer == 1)
- {
- // Create the couple
- CoupleManager.getInstance().createCouple(ptarget, this);
- // Then "finish the job"
- L2WeddingManagerInstance.justMarried(ptarget, this);
- }
- else
- {
- setUnderMarryRequest(false);
- sendMessage("You declined your partner's marriage request.");
- ptarget.setUnderMarryRequest(false);
- ptarget.sendMessage("Your partner declined your marriage request.");
- }
- }
- }
- /**
- * Return the secondary weapon instance (always equipped in the left hand).
- */
- @Override
- public ItemInstance getSecondaryWeaponInstance()
- {
- return getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
- }
- /**
- * Return the secondary L2Item item (always equiped in the left hand).
- */
- @Override
- public Item getSecondaryWeaponItem()
- {
- ItemInstance item = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
- if (item != null)
- {
- return item.getItem();
- }
- return null;
- }
- /**
- * Kill the L2Character, Apply Death Penalty, Manage gain/loss Karma and Item Drop.
- * <ul>
- * <li>Reduce the Experience of the L2PcInstance in function of the calculated Death Penalty</li>
- * <li>If necessary, unsummon the Pet of the killed L2PcInstance</li>
- * <li>Manage Karma gain for attacker and Karam loss for the killed L2PcInstance</li>
- * <li>If the killed L2PcInstance has Karma, manage Drop Item</li>
- * <li>Kill the L2PcInstance</li>
- * </ul>
- * @param killer The L2Character who attacks
- */
- @Override
- public boolean doDie(L2Character killer)
- {
- // Kill the L2PcInstance
- if (!super.doDie(killer))
- {
- return false;
- }
- if (_event != null)
- {
- _event.onKill(killer, this);
- }
- if (isMounted())
- {
- stopFeed();
- }
- synchronized (this)
- {
- if (isFakeDeath())
- {
- stopFakeDeath(true);
- }
- }
- if (killer != null)
- {
- L2PcInstance pk = killer.getActingPlayer();
- // Clear resurrect xp calculation
- setExpBeforeDeath(0);
- if (isCursedWeaponEquipped())
- {
- CursedWeaponsManager.getInstance().drop(_cursedWeaponEquippedId, killer);
- }
- else
- {
- if (pk == null || !pk.isCursedWeaponEquipped())
- {
- onDieDropItem(killer); // Check if any item should be dropped
- // if the area isn't an arena
- if (!isInArena())
- {
- // if both victim and attacker got clans & aren't academicians
- if (pk != null && pk.getClan() != null && getClan() != null && !isAcademyMember() && !pk.isAcademyMember())
- {
- // if clans got mutual war, then use the reputation calcul
- if (_clan.isAtWarWith(pk.getClanId()) && pk.getClan().isAtWarWith(_clan.getClanId()))
- {
- // when your reputation score is 0 or below, the other clan cannot acquire any reputation points
- if (getClan().getReputationScore() > 0)
- {
- pk.getClan().addReputationScore(1);
- }
- // when the opposing sides reputation score is 0 or below, your clans reputation score doesn't decrease
- if (pk.getClan().getReputationScore() > 0)
- {
- _clan.takeReputationScore(1);
- }
- }
- }
- }
- // Reduce player's xp and karma.
- if (Config.ALT_GAME_DELEVEL && (getSkillLevel(L2Skill.SKILL_LUCKY) < 0 || getStat().getLevel() > 9))
- {
- deathPenalty(pk != null && getClan() != null && pk.getClan() != null && (getClan().isAtWarWith(pk.getClanId()) || pk.getClan().isAtWarWith(getClanId())), pk != null, killer instanceof L2SiegeGuardInstance);
- }
- }
- }
- }
- // Unsummon Cubics
- if (!_cubics.isEmpty())
- {
- for (L2CubicInstance cubic : _cubics.values())
- {
- cubic.stopAction();
- cubic.cancelDisappear();
- }
- _cubics.clear();
- }
- if (_fusionSkill != null)
- {
- abortCast();
- }
- for (L2Character character : getKnownList().getKnownType(L2Character.class))
- {
- if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
- {
- character.abortCast();
- }
- }
- if (isInParty() && getParty().isInDimensionalRift())
- {
- getParty().getDimensionalRift().getDeadMemberList().add(this);
- }
- // calculate death penalty buff
- calculateDeathPenaltyBuffLevel(killer);
- stopWaterTask();
- if (isPhoenixBlessed() || (isAffected(L2EffectFlag.CHARM_OF_COURAGE) && isInSiege()))
- {
- reviveRequest(this, null, false);
- }
- // Icons update in order to get retained buffs list
- updateEffectIcons();
- if (Config.PVP_REWARD_ENABLED)
- {
- updateKillRewardInfo(killer, this);
- }
- return true;
- }
- private void onDieDropItem(L2Character killer)
- {
- if (killer == null)
- {
- return;
- }
- if (_event != null && _event.isRunning())
- {
- return;
- }
- L2PcInstance pk = killer.getActingPlayer();
- if (getKarma() <= 0 && pk != null && pk.getClan() != null && getClan() != null && pk.getClan().isAtWarWith(getClanId()))
- {
- return;
- }
- if ((!isInsideZone(ZoneId.PVP) || pk == null) && (!isGM() || Config.KARMA_DROP_GM))
- {
- boolean isKillerNpc = (killer instanceof L2Npc);
- int pkLimit = Config.KARMA_PK_LIMIT;
- int dropEquip = 0;
- int dropEquipWeapon = 0;
- int dropItem = 0;
- int dropLimit = 0;
- int dropPercent = 0;
- if (getKarma() > 0 && getPkKills() >= pkLimit)
- {
- dropPercent = Config.KARMA_RATE_DROP;
- dropEquip = Config.KARMA_RATE_DROP_EQUIP;
- dropEquipWeapon = Config.KARMA_RATE_DROP_EQUIP_WEAPON;
- dropItem = Config.KARMA_RATE_DROP_ITEM;
- dropLimit = Config.KARMA_DROP_LIMIT;
- }
- else if (isKillerNpc && getLevel() > 4 && !isFestivalParticipant())
- {
- dropPercent = Config.PLAYER_RATE_DROP;
- dropEquip = Config.PLAYER_RATE_DROP_EQUIP;
- dropEquipWeapon = Config.PLAYER_RATE_DROP_EQUIP_WEAPON;
- dropItem = Config.PLAYER_RATE_DROP_ITEM;
- dropLimit = Config.PLAYER_DROP_LIMIT;
- }
- if (dropPercent > 0 && Rnd.get(100) < dropPercent)
- {
- int dropCount = 0;
- int itemDropPercent = 0;
- for (ItemInstance itemDrop : getInventory().getItems())
- {
- // Don't drop those following things
- 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)
- {
- continue;
- }
- if (itemDrop.isEquipped())
- {
- // Set proper chance according to Item type of equipped Item
- itemDropPercent = itemDrop.getItem().getType2() == Item.TYPE2_WEAPON ? dropEquipWeapon : dropEquip;
- getInventory().unEquipItemInSlot(itemDrop.getLocationSlot());
- }
- else
- {
- itemDropPercent = dropItem; // Item in inventory
- }
- // NOTE: Each time an item is dropped, the chance of another item being dropped gets lesser (dropCount * 2)
- if (Rnd.get(100) < itemDropPercent)
- {
- dropItem("DieDrop", itemDrop, killer, true);
- if (++dropCount >= dropLimit)
- {
- break;
- }
- }
- }
- }
- }
- }
- public void updateKarmaLoss(long exp)
- {
- if (!isCursedWeaponEquipped() && getKarma() > 0)
- {
- int karmaLost = Formulas.calculateKarmaLost(getLevel(), Math.round(exp));
- if (karmaLost > 0)
- {
- setKarma(getKarma() - karmaLost);
- }
- }
- }
- /**
- * This method is used to update PvP counter, or PK counter / add Karma if necessary.<br>
- * It also updates clan kills/deaths counters on siege.
- * @param target The L2Playable victim.
- */
- public void onKillUpdatePvPKarma(L2Playable target)
- {
- if (target == null)
- {
- return;
- }
- final L2PcInstance targetPlayer = target.getActingPlayer();
- if (targetPlayer == null || targetPlayer == this)
- {
- return;
- }
- // Don't rank up the CW if it was a summon.
- if (isCursedWeaponEquipped() && target instanceof L2PcInstance)
- {
- CursedWeaponsManager.getInstance().increaseKills(_cursedWeaponEquippedId);
- return;
- }
- // If in duel and you kill (only can kill l2summon), do nothing
- if (isInDuel() && targetPlayer.isInDuel())
- {
- return;
- }
- // If in pvp zone, do nothing.
- if (isInsideZone(ZoneId.PVP) && targetPlayer.isInsideZone(ZoneId.PVP))
- {
- // Until the zone was a siege zone. Check also if victim was a player. Randomers aren't counted.
- if (target instanceof L2PcInstance && getSiegeState() > 0 && targetPlayer.getSiegeState() > 0 && getSiegeState() != targetPlayer.getSiegeState())
- {
- // Now check clan relations.
- final L2Clan killerClan = getClan();
- if (killerClan != null)
- {
- killerClan.setSiegeKills(killerClan.getSiegeKills() + 1);
- }
- final L2Clan targetClan = targetPlayer.getClan();
- if (targetClan != null)
- {
- targetClan.setSiegeDeaths(targetClan.getSiegeDeaths() + 1);
- }
- }
- return;
- }
- if (_event != null && _event.isRunning() && targetPlayer.getEvent() != null && targetPlayer.getEvent().isRunning())
- {
- _event.onKill(this, targetPlayer);
- }
- // Check if it's pvp (cases : regular, wars, victim is PKer)
- else 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))
- {
- if (target instanceof L2PcInstance)
- {
- // Add PvP point to attacker.
- setPvpKills(getPvpKills() + 1);
- // Send UserInfo packet to attacker with its Karma and PK Counter
- sendPacket(new UserInfo(this));
- }
- }
- // Otherwise, killer is considered as a PKer.
- else if (targetPlayer.getKarma() == 0 && targetPlayer.getPvpFlag() == 0)
- {
- // PK Points are increased only if you kill a player.
- if (target instanceof L2PcInstance)
- {
- setPkKills(getPkKills() + 1);
- }
- // Calculate new karma.
- setKarma(getKarma() + Formulas.calculateKarmaGain(getPkKills(), target instanceof L2Summon));
- // Send UserInfo packet to attacker with its Karma and PK Counter
- sendPacket(new UserInfo(this));
- }
- }
- public void updatePvPStatus()
- {
- if (_event != null && _event.isRunning())
- {
- return;
- }
- if (isInsideZone(ZoneId.PVP))
- {
- return;
- }
- PvpFlagTaskManager.getInstance().add(this, System.currentTimeMillis() + Config.PVP_NORMAL_TIME);
- if (getPvpFlag() == 0)
- {
- updatePvPFlag(1);
- }
- }
- public void updatePvPStatus(L2Character target)
- {
- final L2PcInstance player = target.getActingPlayer();
- if (player == null)
- {
- return;
- }
- if (_event != null && _event.isRunning())
- {
- return;
- }
- if (isInDuel() && player.getDuelId() == getDuelId())
- {
- return;
- }
- if ((!isInsideZone(ZoneId.PVP) || !target.isInsideZone(ZoneId.PVP)) && player.getKarma() == 0)
- {
- PvpFlagTaskManager.getInstance().add(this, System.currentTimeMillis() + ((checkIfPvP(player)) ? Config.PVP_PVP_TIME : Config.PVP_NORMAL_TIME));
- if (getPvpFlag() == 0)
- {
- updatePvPFlag(1);
- }
- }
- }
- /**
- * Restore the experience this L2PcInstance has lost and sends StatusUpdate packet.
- * @param restorePercent The specified % of restored experience.
- */
- public void restoreExp(double restorePercent)
- {
- if (getExpBeforeDeath() > 0)
- {
- getStat().addExp((int) Math.round((getExpBeforeDeath() - getExp()) * restorePercent / 100));
- setExpBeforeDeath(0);
- }
- }
- /**
- * Reduce the Experience (and level if necessary) of the L2PcInstance in function of the calculated Death Penalty.
- * <ul>
- * <li>Calculate the Experience loss</li>
- * <li>Set the value of _expBeforeDeath</li>
- * <li>Set the new Experience value of the L2PcInstance and Decrease its level if necessary</li>
- * <li>Send StatusUpdate packet with its new Experience</li>
- * </ul>
- * @param atWar If true, use clan war penalty system instead of regular system.
- * @param killedByPlayable Used to see if victim loses XP or not.
- * @param killedBySiegeNpc Used to see if victim loses XP or not.
- */
- public void deathPenalty(boolean atWar, boolean killedByPlayable, boolean killedBySiegeNpc)
- {
- // No xp loss inside pvp zone unless
- // - it's a siege zone and you're NOT participating
- // - you're killed by a non-pc whose not belong to the siege
- if (isInsideZone(ZoneId.PVP))
- {
- // No xp loss for siege participants inside siege zone.
- if (isInsideZone(ZoneId.SIEGE))
- {
- if (isInSiege() && (killedByPlayable || killedBySiegeNpc))
- {
- return;
- }
- }
- // No xp loss for arenas participants killed by playable.
- else if (killedByPlayable)
- {
- return;
- }
- }
- // Get the level of the L2PcInstance
- final int lvl = getLevel();
- // The death steal you some Exp
- double percentLost = 7.0;
- if (getLevel() >= 76)
- {
- percentLost = 2.0;
- }
- else if (getLevel() >= 40)
- {
- percentLost = 4.0;
- }
- if (getKarma() > 0)
- {
- percentLost *= Config.RATE_KARMA_EXP_LOST;
- }
- if (isFestivalParticipant() || atWar || isInsideZone(ZoneId.SIEGE))
- {
- percentLost /= 4.0;
- }
- // Calculate the Experience loss
- long lostExp = 0;
- if (_event == null || _event.canLostExpOnDie())
- {
- if (lvl < Experience.MAX_LEVEL)
- {
- lostExp = Math.round((getStat().getExpForLevel(lvl + 1) - getStat().getExpForLevel(lvl)) * percentLost / 100);
- }
- else
- {
- lostExp = Math.round((getStat().getExpForLevel(Experience.MAX_LEVEL) - getStat().getExpForLevel(Experience.MAX_LEVEL - 1)) * percentLost / 100);
- }
- }
- // Get the Experience before applying penalty
- setExpBeforeDeath(getExp());
- // Set new karma
- updateKarmaLoss(lostExp);
- // Set the new Experience value of the L2PcInstance
- getStat().addExp(-lostExp);
- }
- public boolean isPartyWaiting()
- {
- return PartyMatchWaitingList.getInstance().getPlayers().contains(this);
- }
- public void setPartyRoom(int id)
- {
- _partyroom = id;
- }
- public int getPartyRoom()
- {
- return _partyroom;
- }
- public boolean isInPartyMatchRoom()
- {
- return _partyroom > 0;
- }
- /**
- * Manage the increase level task of a L2PcInstance (Max MP, Max MP, Recommandation, Expertise and beginner skills...).
- * <ul>
- * <li>Send System Message to the L2PcInstance : YOU_INCREASED_YOUR_LEVEL</li>
- * <li>Send StatusUpdate to the L2PcInstance with new LEVEL, MAX_HP and MAX_MP</li>
- * <li>Set the current HP and MP of the L2PcInstance, Launch/Stop a HP/MP/CP Regeneration Task and send StatusUpdate packet to all other L2PcInstance to inform (exclusive broadcast)</li>
- * <li>Recalculate the party level</li>
- * <li>Recalculate the number of Recommandation that the L2PcInstance can give</li>
- * <li>Give Expertise skill of this level and remove beginner Lucky skill</li>
- * </ul>
- */
- public void increaseLevel()
- {
- // Set the current HP and MP of the L2Character, Launch/Stop a HP/MP/CP Regeneration Task and send StatusUpdate packet to all other L2PcInstance to inform (exclusive broadcast)
- setCurrentHpMp(getMaxHp(), getMaxMp());
- setCurrentCp(getMaxCp());
- }
- /**
- * Stop all timers related to that L2PcInstance.
- */
- public void stopAllTimers()
- {
- stopHpMpRegeneration();
- stopWaterTask();
- stopFeed();
- clearPetData();
- storePetFood(_mountNpcId);
- stopPunishTask(true);
- stopChargeTask();
- getInventory().stopShadowTimers();
- AttackStanceTaskManager.getInstance().remove(this);
- PvpFlagTaskManager.getInstance().remove(this);
- TakeBreakTaskManager.getInstance().remove(this);
- }
- /**
- * Return the L2Summon of the L2PcInstance or null.
- */
- @Override
- public L2Summon getPet()
- {
- return _summon;
- }
- /**
- * @return {@code true} if the player has a pet, {@code false} otherwise
- */
- public boolean hasPet()
- {
- return _summon instanceof L2PetInstance;
- }
- /**
- * @return {@code true} if the player has a summon, {@code false} otherwise
- */
- public boolean hasServitor()
- {
- return _summon instanceof L2SummonInstance;
- }
- /**
- * Set the L2Summon of the L2PcInstance.
- * @param summon The Object.
- */
- public void setPet(L2Summon summon)
- {
- _summon = summon;
- }
- /**
- * @return the L2TamedBeast of the L2PcInstance or null.
- */
- public L2TamedBeastInstance getTrainedBeast()
- {
- return _tamedBeast;
- }
- /**
- * Set the L2TamedBeast of the L2PcInstance.
- * @param tamedBeast The Object.
- */
- public void setTrainedBeast(L2TamedBeastInstance tamedBeast)
- {
- _tamedBeast = tamedBeast;
- }
- /**
- * @return the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
- */
- public L2Request getRequest()
- {
- return _request;
- }
- /**
- * Set the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
- * @param requester
- */
- public void setActiveRequester(L2PcInstance requester)
- {
- _activeRequester = requester;
- }
- /**
- * @return the L2PcInstance requester of a transaction (ex : FriendInvite, JoinAlly, JoinParty...).
- */
- public L2PcInstance getActiveRequester()
- {
- if (_activeRequester != null && _activeRequester.isRequestExpired() && _activeTradeList == null)
- {
- _activeRequester = null;
- }
- return _activeRequester;
- }
- /**
- * @return True if a request is in progress.
- */
- public boolean isProcessingRequest()
- {
- return getActiveRequester() != null || _requestExpireTime > GameTimeController.getGameTicks();
- }
- /**
- * @return True if a transaction <B>(trade OR request)</B> is in progress.
- */
- public boolean isProcessingTransaction()
- {
- return getActiveRequester() != null || _activeTradeList != null || _requestExpireTime > GameTimeController.getGameTicks();
- }
- /**
- * Set the _requestExpireTime of that L2PcInstance, and set his partner as the active requester.
- * @param partner The partner to make checks on.
- */
- public void onTransactionRequest(L2PcInstance partner)
- {
- _requestExpireTime = GameTimeController.getGameTicks() + REQUEST_TIMEOUT * GameTimeController.TICKS_PER_SECOND;
- partner.setActiveRequester(this);
- }
- /**
- * @return true if last request is expired.
- */
- public boolean isRequestExpired()
- {
- return !(_requestExpireTime > GameTimeController.getGameTicks());
- }
- /**
- * Select the Warehouse to be used in next activity.
- */
- public void onTransactionResponse()
- {
- _requestExpireTime = 0;
- }
- /**
- * Select the Warehouse to be used in next activity.
- * @param warehouse An active warehouse.
- */
- public void setActiveWarehouse(ItemContainer warehouse)
- {
- _activeWarehouse = warehouse;
- }
- /**
- * @return The active Warehouse.
- */
- public ItemContainer getActiveWarehouse()
- {
- return _activeWarehouse;
- }
- /**
- * Set the TradeList to be used in next activity.
- * @param tradeList The TradeList to be used.
- */
- public void setActiveTradeList(TradeList tradeList)
- {
- _activeTradeList = tradeList;
- }
- /**
- * @return The active TradeList.
- */
- public TradeList getActiveTradeList()
- {
- return _activeTradeList;
- }
- public void onTradeStart(L2PcInstance partner)
- {
- _activeTradeList = new TradeList(this);
- _activeTradeList.setPartner(partner);
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.BEGIN_TRADE_WITH_S1).addString(partner.getName()));
- sendPacket(new TradeStart(this));
- }
- public void onTradeConfirm(L2PcInstance partner)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CONFIRMED_TRADE).addString(partner.getName()));
- partner.sendPacket(TradePressOwnOk.STATIC_PACKET);
- sendPacket(TradePressOtherOk.STATIC_PACKET);
- }
- public void onTradeCancel(L2PcInstance partner)
- {
- if (_activeTradeList == null)
- {
- return;
- }
- _activeTradeList.lock();
- _activeTradeList = null;
- sendPacket(new SendTradeDone(0));
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANCELED_TRADE).addString(partner.getName()));
- }
- public void onTradeFinish(boolean successfull)
- {
- _activeTradeList = null;
- sendPacket(new SendTradeDone(1));
- if (successfull)
- {
- sendPacket(SystemMessageId.TRADE_SUCCESSFUL);
- }
- }
- public void startTrade(L2PcInstance partner)
- {
- onTradeStart(partner);
- partner.onTradeStart(this);
- }
- public void cancelActiveTrade()
- {
- if (_activeTradeList == null)
- {
- return;
- }
- L2PcInstance partner = _activeTradeList.getPartner();
- if (partner != null)
- {
- partner.onTradeCancel(this);
- }
- onTradeCancel(this);
- }
- /**
- * @return The _createList object of the L2PcInstance.
- */
- public L2ManufactureList getCreateList()
- {
- return _createList;
- }
- /**
- * Set the _createList object of the L2PcInstance.
- * @param list
- */
- public void setCreateList(L2ManufactureList list)
- {
- _createList = list;
- }
- /**
- * @return The _sellList object of the L2PcInstance.
- */
- public TradeList getSellList()
- {
- if (_sellList == null)
- {
- _sellList = new TradeList(this);
- }
- return _sellList;
- }
- /**
- * @return the _buyList object of the L2PcInstance.
- */
- public TradeList getBuyList()
- {
- if (_buyList == null)
- {
- _buyList = new TradeList(this);
- }
- return _buyList;
- }
- /**
- * Set the Private Store type of the L2PcInstance.
- * @param type The value : 0 = none, 1 = sell, 2 = sellmanage, 3 = buy, 4 = buymanage, 5 = manufacture.
- */
- public void setPrivateStoreType(int type)
- {
- _privateStore = type;
- if (Config.OFFLINE_DISCONNECT_FINISHED && (_privateStore == STORE_PRIVATE_NONE) && ((getClient() == null) || getClient().isDetached()))
- {
- deleteMe();
- }
- }
- /**
- * @return The Private Store type of the L2PcInstance.
- */
- public int getPrivateStoreType()
- {
- return _privateStore;
- }
- /**
- * Set the _skillLearningClassId object of the L2PcInstance.
- * @param classId The parameter.
- */
- public void setSkillLearningClassId(ClassId classId)
- {
- _skillLearningClassId = classId;
- }
- /**
- * @return The _skillLearningClassId object of the L2PcInstance.
- */
- public ClassId getSkillLearningClassId()
- {
- return _skillLearningClassId;
- }
- /**
- * Set the _clan object, _clanId, _clanLeader Flag and title of the L2PcInstance.
- * @param clan The Clan object which is used to feed L2PcInstance values.
- */
- public void setClan(L2Clan clan)
- {
- _clan = clan;
- setTitle("");
- if (clan == null)
- {
- _clanId = 0;
- _clanPrivileges = 0;
- _pledgeType = 0;
- _powerGrade = 0;
- _lvlJoinedAcademy = 0;
- _apprentice = 0;
- _sponsor = 0;
- return;
- }
- if (!clan.isMember(getObjectId()))
- {
- // char has been kicked from clan
- setClan(null);
- return;
- }
- _clanId = clan.getClanId();
- }
- /**
- * @return The _clan object of the L2PcInstance.
- */
- public L2Clan getClan()
- {
- return _clan;
- }
- /**
- * @return True if the L2PcInstance is the leader of its clan.
- */
- public boolean isClanLeader()
- {
- if (getClan() == null)
- {
- return false;
- }
- return getObjectId() == getClan().getLeaderId();
- }
- /**
- * Reduce the number of arrows owned by the L2PcInstance and send InventoryUpdate or ItemList (to unequip if the last arrow was consummed).
- */
- @Override
- protected void reduceArrowCount(boolean arrow)
- {
- ItemInstance arrows = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
- if (arrows == null)
- {
- getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
- _arrowItem = null;
- sendPacket(new ItemList(this, false));
- return;
- }
- // Adjust item quantity
- if (arrows.getCount() > 1)
- {
- synchronized (arrows)
- {
- arrows.changeCountWithoutTrace(-1, this, null);
- arrows.setLastChange(ItemInstance.MODIFIED);
- // could do also without saving, but let's save approx 1 of 10
- if (GameTimeController.getGameTicks() % 10 == 0)
- {
- arrows.updateDatabase();
- }
- _inventory.refreshWeight();
- }
- }
- else
- {
- // Destroy entire item and save to database
- _inventory.destroyItem("Consume", arrows, this, null);
- getInventory().unEquipItemInSlot(Inventory.PAPERDOLL_LHAND);
- _arrowItem = null;
- sendPacket(new ItemList(this, false));
- return;
- }
- InventoryUpdate iu = new InventoryUpdate();
- iu.addModifiedItem(arrows);
- sendPacket(iu);
- }
- /**
- * Equip arrows needed in left hand and send ItemList to the L2PcInstance then return True.
- */
- @Override
- protected boolean checkAndEquipArrows()
- {
- // Check if nothing is equipped in left hand
- if (getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND) == null)
- {
- // Get the ItemInstance of the arrows needed for this bow
- _arrowItem = getInventory().findArrowForBow(getActiveWeaponItem());
- if (_arrowItem != null)
- {
- // Equip arrows needed in left hand
- getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, _arrowItem);
- // Send ItemList to this L2PcINstance to update left hand equipement
- sendPacket(new ItemList(this, false));
- }
- }
- // Get the ItemInstance of arrows equipped in left hand
- else
- {
- _arrowItem = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
- }
- return _arrowItem != null;
- }
- /**
- * Disarm the player's weapon and shield.
- * @return true if successful, false otherwise.
- */
- public boolean disarmWeapons()
- {
- // Don't allow disarming a cursed weapon
- if (isCursedWeaponEquipped())
- {
- return false;
- }
- // Unequip the weapon
- ItemInstance wpn = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
- if (wpn != null)
- {
- ItemInstance[] unequipped = getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
- InventoryUpdate iu = new InventoryUpdate();
- for (ItemInstance itm : unequipped)
- {
- iu.addModifiedItem(itm);
- }
- sendPacket(iu);
- abortAttack();
- broadcastUserInfo();
- // this can be 0 if the user pressed the right mousebutton twice very fast
- if (unequipped.length > 0)
- {
- SystemMessage sm;
- if (unequipped[0].getEnchantLevel() > 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(unequipped[0].getEnchantLevel()).addItemName(unequipped[0]);
- }
- else
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(unequipped[0]);
- }
- sendPacket(sm);
- }
- }
- // Unequip the shield
- ItemInstance sld = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
- if (sld != null)
- {
- ItemInstance[] unequipped = getInventory().unEquipItemInBodySlotAndRecord(sld.getItem().getBodyPart());
- InventoryUpdate iu = new InventoryUpdate();
- for (ItemInstance itm : unequipped)
- {
- iu.addModifiedItem(itm);
- }
- sendPacket(iu);
- abortAttack();
- broadcastUserInfo();
- // this can be 0 if the user pressed the right mousebutton twice very fast
- if (unequipped.length > 0)
- {
- SystemMessage sm;
- if (unequipped[0].getEnchantLevel() > 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED).addNumber(unequipped[0].getEnchantLevel()).addItemName(unequipped[0]);
- }
- else
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED).addItemName(unequipped[0]);
- }
- sendPacket(sm);
- }
- }
- return true;
- }
- public boolean mount(L2Summon pet)
- {
- if (!disarmWeapons())
- {
- return false;
- }
- stopAllToggles();
- Ride mount = new Ride(getObjectId(), Ride.ACTION_MOUNT, pet.getTemplate().getNpcId());
- setMount(pet.getNpcId(), pet.getLevel(), mount.getMountType());
- setMountObjectID(pet.getControlItemId());
- clearPetData();
- startFeed(pet.getNpcId());
- broadcastPacket(mount);
- // Notify self and others about speed change
- broadcastUserInfo();
- pet.unSummon(this);
- return true;
- }
- public boolean mount(int npcId, int controlItemId, boolean useFood)
- {
- if (!disarmWeapons())
- {
- return false;
- }
- stopAllToggles();
- Ride mount = new Ride(getObjectId(), Ride.ACTION_MOUNT, npcId);
- if (setMount(npcId, getLevel(), mount.getMountType()))
- {
- clearPetData();
- setMountObjectID(controlItemId);
- broadcastPacket(mount);
- // Notify self and others about speed change
- broadcastUserInfo();
- if (useFood)
- {
- startFeed(npcId);
- }
- return true;
- }
- return false;
- }
- public boolean mountPlayer(L2Summon summon)
- {
- if (summon != null && summon.isMountable() && !isMounted() && !isBetrayed())
- {
- if (isDead()) // A strider cannot be ridden when dead.
- {
- sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_DEAD);
- return false;
- }
- if (summon.isDead()) // A dead strider cannot be ridden.
- {
- sendPacket(SystemMessageId.DEAD_STRIDER_CANT_BE_RIDDEN);
- return false;
- }
- if (summon.isInCombat() || summon.isRooted()) // A strider in battle cannot be ridden.
- {
- sendPacket(SystemMessageId.STRIDER_IN_BATLLE_CANT_BE_RIDDEN);
- return false;
- }
- if (isInCombat()) // A strider cannot be ridden while in battle
- {
- sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
- return false;
- }
- if (isSitting()) // A strider can be ridden only when standing
- {
- sendPacket(SystemMessageId.STRIDER_CAN_BE_RIDDEN_ONLY_WHILE_STANDING);
- return false;
- }
- if (isFishing()) // You can't mount, dismount, break and drop items while fishing
- {
- sendPacket(SystemMessageId.CANNOT_DO_WHILE_FISHING_2);
- return false;
- }
- if (isCursedWeaponEquipped()) // You can't mount, dismount, break and drop items while weilding a cursed weapon
- {
- sendPacket(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
- return false;
- }
- if (!Util.checkIfInRange(200, this, summon, true))
- {
- sendPacket(SystemMessageId.TOO_FAR_AWAY_FROM_STRIDER_TO_MOUNT);
- return false;
- }
- if (summon.isHungry())
- {
- sendPacket(SystemMessageId.HUNGRY_STRIDER_NOT_MOUNT);
- return false;
- }
- if (_event != null && !_event.canDoAction(this, 38))
- {
- return false;
- }
- if (!summon.isDead() && !isMounted())
- {
- mount(summon);
- }
- }
- else if (isMounted())
- {
- if (getMountType() == 2 && isInsideZone(ZoneId.NO_LANDING))
- {
- sendPacket(SystemMessageId.NO_DISMOUNT_HERE);
- return false;
- }
- if (isHungry())
- {
- sendPacket(SystemMessageId.HUNGRY_STRIDER_NOT_MOUNT);
- return false;
- }
- dismount();
- }
- return true;
- }
- public boolean dismount()
- {
- sendPacket(new SetupGauge(3, 0, 0));
- int petId = _mountNpcId;
- if (setMount(0, 0, 0))
- {
- stopFeed();
- clearPetData();
- broadcastPacket(new Ride(getObjectId(), Ride.ACTION_DISMOUNT, 0));
- setMountObjectID(0);
- storePetFood(petId);
- // Notify self and others about speed change
- broadcastUserInfo();
- return true;
- }
- return false;
- }
- public void storePetFood(int petId)
- {
- if (_controlItemId != 0 && petId != 0)
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("UPDATE pets SET fed=? WHERE item_obj_id = ?");
- statement.setInt(1, getCurrentFeed());
- statement.setInt(2, _controlItemId);
- statement.executeUpdate();
- statement.close();
- _controlItemId = 0;
- }
- catch (Exception e)
- {
- _log.warn("Failed to store Pet [NpcId: " + petId + "] data", e);
- }
- }
- }
- protected class FeedTask implements Runnable
- {
- @Override
- public void run()
- {
- try
- {
- if (!isMounted())
- {
- stopFeed();
- return;
- }
- if (getCurrentFeed() > getFeedConsume())
- {
- // eat
- setCurrentFeed(getCurrentFeed() - getFeedConsume());
- }
- else
- {
- // go back to pet control item, or simply said, unsummon it
- setCurrentFeed(0);
- stopFeed();
- dismount();
- sendPacket(SystemMessageId.OUT_OF_FEED_MOUNT_CANCELED);
- }
- int[] foodIds = getPetData(getMountNpcId()).getFood();
- if (foodIds.length == 0)
- {
- return;
- }
- ItemInstance food = null;
- for (int id : foodIds)
- {
- food = getInventory().getItemByItemId(id);
- if (food != null)
- {
- break;
- }
- }
- if (food != null && isHungry())
- {
- IItemHandler handler = ItemHandler.getInstance().getHandler(food.getEtcItem());
- if (handler != null)
- {
- handler.useItem(L2PcInstance.this, food, false);
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_TOOK_S1_BECAUSE_HE_WAS_HUNGRY).addItemName(food));
- }
- }
- }
- catch (Exception e)
- {
- _log.warn("Mounted Pet [NpcId: " + getMountNpcId() + "] a feed task error has occurred", e);
- }
- }
- }
- protected synchronized void startFeed(int npcId)
- {
- _canFeed = npcId > 0;
- if (!isMounted())
- {
- return;
- }
- if (getPet() != null)
- {
- setCurrentFeed(((L2PetInstance) getPet()).getCurrentFed());
- _controlItemId = getPet().getControlItemId();
- sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), getMaxFeed() * 10000 / getFeedConsume()));
- if (!isDead())
- {
- _mountFeedTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FeedTask(), 10000, 10000);
- }
- }
- else if (_canFeed)
- {
- setCurrentFeed(getMaxFeed());
- sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), getMaxFeed() * 10000 / getFeedConsume()));
- if (!isDead())
- {
- _mountFeedTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FeedTask(), 10000, 10000);
- }
- }
- }
- protected synchronized void stopFeed()
- {
- if (_mountFeedTask != null)
- {
- _mountFeedTask.cancel(false);
- _mountFeedTask = null;
- }
- }
- private final void clearPetData()
- {
- _data = null;
- }
- protected final L2PetData getPetData(int npcId)
- {
- if (_data == null)
- {
- _data = PetDataTable.getInstance().getPetData(npcId);
- }
- return _data;
- }
- private final L2PetLevelData getPetLevelData(int npcId)
- {
- if (_leveldata == null)
- {
- _leveldata = PetDataTable.getInstance().getPetData(npcId).getPetLevelData(getMountLevel());
- }
- return _leveldata;
- }
- public int getCurrentFeed()
- {
- return _curFeed;
- }
- protected int getFeedConsume()
- {
- return (isAttackingNow()) ? getPetLevelData(_mountNpcId).getPetFeedBattle() : getPetLevelData(_mountNpcId).getPetFeedNormal();
- }
- public void setCurrentFeed(int num)
- {
- _curFeed = (num > getMaxFeed()) ? getMaxFeed() : num;
- sendPacket(new SetupGauge(3, getCurrentFeed() * 10000 / getFeedConsume(), getMaxFeed() * 10000 / getFeedConsume()));
- }
- private int getMaxFeed()
- {
- return getPetLevelData(_mountNpcId).getPetMaxFeed();
- }
- protected boolean isHungry()
- {
- return _canFeed ? (getCurrentFeed() < (getPetLevelData(getMountNpcId()).getPetMaxFeed() * 0.55)) : false;
- }
- /**
- * @return the type of attack, depending of the worn weapon.
- */
- @Override
- public WeaponType getAttackType()
- {
- final Weapon weapon = getActiveWeaponItem();
- if (weapon != null)
- {
- return weapon.getItemType();
- }
- return WeaponType.FIST;
- }
- public void setUptime(long time)
- {
- _uptime = time;
- }
- public long getUptime()
- {
- return System.currentTimeMillis() - _uptime;
- }
- /**
- * Return True if the L2PcInstance is invulnerable.
- */
- @Override
- public boolean isInvul()
- {
- return super.isInvul() || isSpawnProtected();
- }
- /**
- * Return True if the L2PcInstance has a Party in progress.
- */
- @Override
- public boolean isInParty()
- {
- return _party != null;
- }
- /**
- * Set the _party object of the L2PcInstance (without joining it).
- * @param party The object.
- */
- public void setParty(L2Party party)
- {
- _party = party;
- }
- /**
- * Set the _party object of the L2PcInstance AND join it.
- * @param party
- */
- public void joinParty(L2Party party)
- {
- if (party != null)
- {
- _party = party;
- party.addPartyMember(this);
- }
- }
- /**
- * Manage the Leave Party task of the L2PcInstance.
- */
- public void leaveParty()
- {
- if (isInParty())
- {
- _party.removePartyMember(this, MessageType.Disconnected);
- _party = null;
- }
- }
- /**
- * Return the _party object of the L2PcInstance.
- */
- @Override
- public L2Party getParty()
- {
- return _party;
- }
- /**
- * Return True if the L2PcInstance is a GM.
- */
- @Override
- public boolean isGM()
- {
- return getAccessLevel().isGm();
- }
- /**
- * Set the _accessLevel of the L2PcInstance.
- * @param level
- */
- public void setAccessLevel(int level)
- {
- if (level == AccessLevels.MASTER_ACCESS_LEVEL_NUMBER)
- {
- _log.warn(getName() + " has logged in with Master access level.");
- _accessLevel = AccessLevels.MASTER_ACCESS_LEVEL;
- }
- else if (level == AccessLevels.USER_ACCESS_LEVEL_NUMBER)
- {
- _accessLevel = AccessLevels.USER_ACCESS_LEVEL;
- }
- else
- {
- L2AccessLevel accessLevel = AccessLevels.getInstance().getAccessLevel(level);
- if (accessLevel == null)
- {
- if (level < 0)
- {
- AccessLevels.getInstance().addBanAccessLevel(level);
- _accessLevel = AccessLevels.getInstance().getAccessLevel(level);
- }
- else
- {
- _log.warn("Server tried to set unregistered access level " + level + " to " + getName() + ". His access level have been reseted to user level.");
- _accessLevel = AccessLevels.USER_ACCESS_LEVEL;
- }
- }
- else
- {
- _accessLevel = accessLevel;
- setTitle(_accessLevel.getName());
- }
- }
- broadcastUserInfo();
- CharNameTable.getInstance().addName(this);
- }
- public void setAccountAccesslevel(int level)
- {
- LoginServerThread.getInstance().sendAccessLevel(getAccountName(), level);
- }
- /**
- * @return the _accessLevel of the L2PcInstance.
- */
- public L2AccessLevel getAccessLevel()
- {
- if (Config.EVERYBODY_HAS_ADMIN_RIGHTS)
- {
- return AccessLevels.MASTER_ACCESS_LEVEL;
- }
- if (_accessLevel == null)
- {
- setAccessLevel(AccessLevels.USER_ACCESS_LEVEL_NUMBER);
- }
- return _accessLevel;
- }
- /**
- * Update Stats of the L2PcInstance client side by sending UserInfo/StatusUpdate to this L2PcInstance and CharInfo/StatusUpdate to all L2PcInstance in its _KnownPlayers (broadcast).
- * @param broadcastType
- */
- public void updateAndBroadcastStatus(int broadcastType)
- {
- refreshOverloaded();
- refreshExpertisePenalty();
- if (broadcastType == 1)
- {
- sendPacket(new UserInfo(this));
- }
- else if (broadcastType == 2)
- {
- broadcastUserInfo();
- }
- }
- /**
- * Send StatusUpdate packet with Karma to the L2PcInstance and all L2PcInstance to inform (broadcast).
- */
- public void broadcastKarma()
- {
- StatusUpdate su = new StatusUpdate(this);
- su.addAttribute(StatusUpdate.KARMA, getKarma());
- sendPacket(su);
- if (getPet() != null)
- {
- sendPacket(new RelationChanged(getPet(), getRelation(this), false));
- }
- broadcastRelationsChanges();
- }
- private final double[] _premium = new double[12];
- public double getPremiumAttribute(int modifier)
- {
- return _premium[modifier] != 0 ? _premium[modifier] : 1;
- }
- public void calculatePremiumAttributes()
- {
- if (!Config.PREMIUM_ITEM_ENABLED)
- {
- return;
- }
- for (int i = 0; i < _premium.length; i++)
- {
- _premium[i] = 1.0;
- }
- int bonusIndex = -1;
- if (Config.PREMIUM_FIRST_ITEM_BONUS)
- {
- Premium firstItem = PremiumManager.getInstance().getFirstPremiumItem(getActingPlayer());
- if (firstItem != null)
- {
- ItemInstance item = this.getInventory().getItemByObjectId(firstItem.getItemId());
- if (item != null)
- {
- bonusIndex = PremiumManager.getInstance().getItemIndex(item.getItemId());
- }
- }
- }
- final int[] array = Config.PREMIUM_ITEM_IDS;
- for (int i = 0; i < array.length; i++)
- {
- if ((Config.PREMIUM_FIRST_ITEM_BONUS && i == bonusIndex) || (!Config.PREMIUM_FIRST_ITEM_BONUS))
- {
- if (this.getInventory().getItemByItemId(array[i]) != null)
- {
- // MODIFIER_XP
- if (Config.PREMIUM_ITEM_XP_MULTIPLIERS[i] > _premium[Premium.MODIFIER_XP])
- {
- _premium[Premium.MODIFIER_XP] = Config.PREMIUM_ITEM_XP_MULTIPLIERS[i];
- }
- // MODIFIER_SP
- if (Config.PREMIUM_ITEM_SP_MULTIPLIERS[i] > _premium[Premium.MODIFIER_SP])
- {
- _premium[Premium.MODIFIER_SP] = Config.PREMIUM_ITEM_SP_MULTIPLIERS[i];
- }
- // MODIFIER_PARTY_XP
- if (Config.PREMIUM_ITEM_PARTY_XP_MULTIPLIERS[i] > _premium[Premium.MODIFIER_PARTY_XP])
- {
- _premium[Premium.MODIFIER_PARTY_XP] = Config.PREMIUM_ITEM_PARTY_XP_MULTIPLIERS[i];
- }
- // MODIFIER_PARTY_SP
- if (Config.PREMIUM_ITEM_PARTY_SP_MULTIPLIERS[i] > _premium[Premium.MODIFIER_PARTY_SP])
- {
- _premium[Premium.MODIFIER_PARTY_SP] = Config.PREMIUM_ITEM_PARTY_SP_MULTIPLIERS[i];
- }
- // MODIFIER_DROP_ADENA
- if (Config.PREMIUM_ITEM_DROP_ADENA_MULTIPLIERS[i] > _premium[Premium.MODIFIER_DROP_ADENA])
- {
- _premium[Premium.MODIFIER_DROP_ADENA] = Config.PREMIUM_ITEM_DROP_ADENA_MULTIPLIERS[i];
- }
- // MODIFIER_DROP_ITEMS
- if (Config.PREMIUM_ITEM_DROP_ITEMS_MULTIPLIERS[i] > _premium[Premium.MODIFIER_DROP_ITEMS])
- {
- _premium[Premium.MODIFIER_DROP_ITEMS] = Config.PREMIUM_ITEM_DROP_ITEMS_MULTIPLIERS[i];
- }
- // MODIFIER_SPOIL
- if (Config.PREMIUM_ITEM_SPOIL_MULTIPLIERS[i] > _premium[Premium.MODIFIER_SPOIL])
- {
- _premium[Premium.MODIFIER_SPOIL] = Config.PREMIUM_ITEM_SPOIL_MULTIPLIERS[i];
- }
- // MODIFIER_QUEST
- if (Config.PREMIUM_ITEM_QUEST_ITEMS_MULTIPLIERS[i] > _premium[Premium.MODIFIER_QUEST])
- {
- _premium[Premium.MODIFIER_QUEST] = Config.PREMIUM_ITEM_QUEST_ITEMS_MULTIPLIERS[i];
- }
- // MODIFIER_BUFFS_TIME
- if (Config.PREMIUM_ITEM_BUFFS_TIME_MULTIPLIERS[i] > _premium[Premium.MODIFIER_BUFFS_TIME])
- {
- _premium[Premium.MODIFIER_BUFFS_TIME] = Config.PREMIUM_ITEM_BUFFS_TIME_MULTIPLIERS[i];
- }
- // MODIFIER_ENCHANT_CHANCE
- if (Config.PREMIUM_ITEM_ENCHANT_CHANCE_MULTIPLIERS[i] > _premium[Premium.MODIFIER_ENCHANT_CHANCE])
- {
- _premium[Premium.MODIFIER_ENCHANT_CHANCE] = Config.PREMIUM_ITEM_ENCHANT_CHANCE_MULTIPLIERS[i];
- }
- // MODIFIER_AUGMENT_CHANCE
- if (Config.PREMIUM_ITEM_AUGMENT_CHANCE_MULTIPLIERS[i] > _premium[Premium.MODIFIER_AUGMENT_CHANCE])
- {
- _premium[Premium.MODIFIER_AUGMENT_CHANCE] = Config.PREMIUM_ITEM_AUGMENT_CHANCE_MULTIPLIERS[i];
- }
- // MODIFIER_DROP_SEAL_STONES
- if (Config.PREMIUM_ITEM_DROP_SEAL_STONES_MULTIPLIERS[i] > _premium[Premium.MODIFIER_DROP_SEAL_STONES])
- {
- _premium[Premium.MODIFIER_DROP_SEAL_STONES] = Config.PREMIUM_ITEM_DROP_SEAL_STONES_MULTIPLIERS[i];
- }
- }
- }
- }
- }
- public void showPremiumInfo()
- {
- final NpcHtmlMessage html = new NpcHtmlMessage(0);
- html.setFile("data/html/premium.htm");
- final StringBuilder sb = new StringBuilder();
- for (int id : Config.PREMIUM_ITEM_IDS)
- {
- final List<ItemInstance> list = this.getInventory().getItemsByItemId(id);
- if (!list.isEmpty())
- {
- for (ItemInstance item : list)
- {
- sb.append("<tr>");
- sb.append("<td width=21></td>");
- sb.append("<td width=100>").append(item.getName()).append("</td>");
- long timeLeft = PremiumManager.getInstance().getPremiumItem(item.getObjectId()).getActivationTime() - (System.currentTimeMillis() / 1000); //in secconds
- int mins = (int) timeLeft / 60;
- int hours = mins / 60;
- sb.append("<td width=57>").append(hours % 24).append(" days; ").append(hours).append(" hours; ").append(mins % 60).append(" minutes; </td>");
- sb.append("</tr>");
- }
- }
- }
- calculatePremiumAttributes();
- html.replace("%entries%", sb.toString());
- html.replace("%xp%", _premium[Premium.MODIFIER_XP]);
- html.replace("%sp%", _premium[Premium.MODIFIER_SP]);
- html.replace("%pxp%", _premium[Premium.MODIFIER_PARTY_XP]);
- html.replace("%psp%", _premium[Premium.MODIFIER_PARTY_SP]);
- html.replace("%adena%", _premium[Premium.MODIFIER_DROP_ADENA]);
- html.replace("%drop%", _premium[Premium.MODIFIER_DROP_ITEMS]);
- html.replace("%spoil%", _premium[Premium.MODIFIER_SPOIL]);
- html.replace("%quest%", _premium[Premium.MODIFIER_QUEST]);
- html.replace("%seal%", _premium[Premium.MODIFIER_DROP_SEAL_STONES]);
- html.replace("%buff%", _premium[Premium.MODIFIER_BUFFS_TIME]);
- html.replace("%ench%", _premium[Premium.MODIFIER_ENCHANT_CHANCE]);
- html.replace("%augm%", _premium[Premium.MODIFIER_AUGMENT_CHANCE]);
- sendPacket(html);
- sendPacket(ActionFailed.STATIC_PACKET);
- }
- /*public int getPremiumItem()
- {
- if (!Config.PREMIUM_ITEM_ENABLED)
- return -1;
- final int[] array = Config.PREMIUM_ITEM_IDS;
- for (int i = 0; i < array.length; i++)
- {
- if (this.getInventory().getItemByItemId(array[i]) != null)
- {
- return i;
- }
- }
- return -1;
- }*/
- /**
- * 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).
- * @param isOnline
- * @param updateInDb
- */
- public void setOnlineStatus(boolean isOnline, boolean updateInDb)
- {
- if (_isOnline != isOnline)
- {
- _isOnline = isOnline;
- }
- // Update the characters table of the database with online status and lastAccess (called when login and logout)
- if (updateInDb)
- {
- updateOnlineStatus();
- }
- }
- public void setIsIn7sDungeon(boolean isIn7sDungeon)
- {
- _isIn7sDungeon = isIn7sDungeon;
- }
- /**
- * Update the characters table of the database with online status and lastAccess of this L2PcInstance (called when login and logout).
- */
- public void updateOnlineStatus()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET online=?, lastAccess=? WHERE obj_id=?");
- statement.setInt(1, isOnlineInt());
- statement.setLong(2, System.currentTimeMillis());
- statement.setInt(3, getObjectId());
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("could not set char online status:" + e);
- }
- }
- /**
- * Create a new player in the characters table of the database.
- * @return true if successful.
- */
- private boolean createDb()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(INSERT_CHARACTER);
- statement.setString(1, _accountName);
- statement.setInt(2, getObjectId());
- statement.setString(3, getName());
- statement.setInt(4, getLevel());
- statement.setInt(5, getMaxHp());
- statement.setDouble(6, getCurrentHp());
- statement.setInt(7, getMaxCp());
- statement.setDouble(8, getCurrentCp());
- statement.setInt(9, getMaxMp());
- statement.setDouble(10, getCurrentMp());
- statement.setInt(11, getAppearance().getFace());
- statement.setInt(12, getAppearance().getHairStyle());
- statement.setInt(13, getAppearance().getHairColor());
- statement.setInt(14, getAppearance().getSex() ? 1 : 0);
- statement.setLong(15, getExp());
- statement.setInt(16, getSp());
- statement.setInt(17, getKarma());
- statement.setInt(18, getPvpKills());
- statement.setInt(19, getPkKills());
- statement.setInt(20, getClanId());
- statement.setInt(21, getRace().ordinal());
- statement.setInt(22, getClassId().getId());
- statement.setLong(23, getDeleteTimer());
- statement.setInt(24, hasDwarvenCraft() ? 1 : 0);
- statement.setString(25, getTitle());
- statement.setInt(26, getAccessLevel().getLevel());
- statement.setInt(27, isOnlineInt());
- statement.setInt(28, isIn7sDungeon() ? 1 : 0);
- statement.setInt(29, getClanPrivileges());
- statement.setInt(30, wantsPeace() ? 1 : 0);
- statement.setInt(31, getBaseClass());
- statement.setInt(32, isNoble() ? 1 : 0);
- statement.setLong(33, 0);
- statement.setLong(34, System.currentTimeMillis());
- statement.setInt(35, getAppearance().getTitleColor());
- statement.setInt(36, getAppearance().getNameColor());
- statement.executeUpdate();
- statement.close();
- }
- catch (Exception e)
- {
- _log.error("Could not insert char data: " + e);
- return false;
- }
- return true;
- }
- /**
- * Retrieve a L2PcInstance from the characters table of the database and add it in _allObjects of the L2world.
- * <ul>
- * <li>Retrieve the L2PcInstance from the characters table of the database</li>
- * <li>Add the L2PcInstance object in _allObjects</li>
- * <li>Set the x,y,z position of the L2PcInstance and make it invisible</li>
- * <li>Update the overloaded status of the L2PcInstance</li>
- * </ul>
- * @param objectId Identifier of the object to initialized
- * @return The L2PcInstance loaded from the database
- */
- public static L2PcInstance restore(int objectId)
- {
- L2PcInstance player = null;
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_CHARACTER);
- statement.setInt(1, objectId);
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- final int activeClassId = rset.getInt("classid");
- final PcTemplate template = CharTemplateTable.getInstance().getTemplate(activeClassId);
- final PcAppearance app = new PcAppearance(rset.getByte("face"), rset.getByte("hairColor"), rset.getByte("hairStyle"), rset.getInt("sex") != 0);
- player = new L2PcInstance(objectId, template, rset.getString("account_name"), app);
- player.setName(rset.getString("char_name"));
- player._lastAccess = rset.getLong("lastAccess");
- player.getStat().setExp(rset.getLong("exp"));
- player.setExpBeforeDeath(rset.getLong("expBeforeDeath"));
- player.getStat().setLevel(rset.getByte("level"));
- player.getStat().setSp(rset.getInt("sp"));
- player.setWantsPeace(rset.getInt("wantspeace") == 1);
- player.setHeading(rset.getInt("heading"));
- player.setKarma(rset.getInt("karma"));
- player.setPvpKills(rset.getInt("pvpkills"));
- player.setPkKills(rset.getInt("pkkills"));
- player.setOnlineTime(rset.getLong("onlinetime"));
- player.setNoble(rset.getInt("nobless") == 1, false);
- player.setClanJoinExpiryTime(rset.getLong("clan_join_expiry_time"));
- if (player.getClanJoinExpiryTime() < System.currentTimeMillis())
- {
- player.setClanJoinExpiryTime(0);
- }
- player.setClanCreateExpiryTime(rset.getLong("clan_create_expiry_time"));
- if (player.getClanCreateExpiryTime() < System.currentTimeMillis())
- {
- player.setClanCreateExpiryTime(0);
- }
- player.setPowerGrade(rset.getInt("power_grade"));
- player.setPledgeType(rset.getInt("subpledge"));
- player.setLastRecomUpdate(rset.getLong("last_recom_date"));
- int clanId = rset.getInt("clanid");
- if (clanId > 0)
- {
- player.setClan(ClanTable.getInstance().getClan(clanId));
- }
- if (player.getClan() != null)
- {
- if (player.getClan().getLeaderId() != player.getObjectId())
- {
- if (player.getPowerGrade() == 0)
- {
- player.setPowerGrade(5);
- }
- player.setClanPrivileges(player.getClan().getRankPrivs(player.getPowerGrade()));
- }
- else
- {
- player.setClanPrivileges(L2Clan.CP_ALL);
- player.setPowerGrade(1);
- }
- }
- else
- {
- player.setClanPrivileges(L2Clan.CP_NOTHING);
- }
- player.setDeleteTimer(rset.getLong("deletetime"));
- player.setTitle(rset.getString("title"));
- player.setAccessLevel(rset.getInt("accesslevel"));
- player.setFistsWeaponItem(findFistsWeaponItem(activeClassId));
- player.setUptime(System.currentTimeMillis());
- // Color system
- player.getAppearance().setTitleColor(rset.getInt("title_color"));
- player.getAppearance().setNameColor(rset.getInt("name_color"));
- // Check recs
- player.checkRecom(rset.getInt("rec_have"), rset.getInt("rec_left"));
- player._classIndex = 0;
- try
- {
- player.setBaseClass(rset.getInt("base_class"));
- }
- catch (Exception e)
- {
- player.setBaseClass(activeClassId);
- }
- // Restore Subclass Data (cannot be done earlier in function)
- if (restoreSubClassData(player))
- {
- if (activeClassId != player.getBaseClass())
- {
- for (SubClass subClass : player.getSubClasses().values())
- {
- if (subClass.getClassId() == activeClassId)
- {
- player._classIndex = subClass.getClassIndex();
- }
- }
- }
- }
- if (player.getClassIndex() == 0 && activeClassId != player.getBaseClass())
- {
- // Subclass in use but doesn't exist in DB -
- // a possible restart-while-modifysubclass cheat has been attempted.
- // Switching to use base class
- player.setClassId(player.getBaseClass());
- _log.warn("Player " + player.getName() + " reverted to base class. Possibly has tried a relogin exploit while subclassing.");
- }
- else
- {
- player._activeClass = activeClassId;
- }
- player.setApprentice(rset.getInt("apprentice"));
- player.setSponsor(rset.getInt("sponsor"));
- player.setLvlJoinedAcademy(rset.getInt("lvl_joined_academy"));
- player.setIsIn7sDungeon(rset.getInt("isin7sdungeon") == 1);
- player.setPunishLevel(rset.getInt("punish_level"));
- if (player.getPunishLevel() != PunishLevel.NONE)
- {
- player.setPunishTimer(rset.getLong("punish_timer"));
- }
- else
- {
- player.setPunishTimer(0);
- }
- CursedWeaponsManager.getInstance().checkPlayer(player);
- player.setAllianceWithVarkaKetra(rset.getInt("varka_ketra_ally"));
- player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
- player.pcBangPoint = rset.getInt("pc_point");
- // Set the x,y,z position of the L2PcInstance and make it invisible
- player.setXYZInvisible(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
- // Set Hero status if it applies
- if (Hero.getInstance().isActiveHero(objectId))
- {
- player.setHero(true);
- }
- // Set pledge class rank.
- player.setPledgeClass(L2ClanMember.calculatePledgeClass(player));
- // Retrieve from the database all secondary data of this L2PcInstance and reward expertise/lucky skills if necessary.
- // Note that Clan, Noblesse and Hero skills are given separately and not here.
- player.restoreCharData();
- player.rewardSkills();
- player.loadSetting(con);
- // buff and status icons
- if (Config.STORE_SKILL_COOLTIME)
- {
- player.restoreEffects();
- }
- // Restore current CP, HP and MP values
- final double currentHp = rset.getDouble("curHp");
- player.setCurrentCp(rset.getDouble("curCp"));
- player.setCurrentHp(currentHp);
- player.setCurrentMp(rset.getDouble("curMp"));
- if (currentHp < 0.5)
- {
- player.setIsDead(true);
- player.stopHpMpRegeneration();
- }
- // Restore pet if exists in the world
- player.setPet(L2World.getInstance().getPet(player.getObjectId()));
- if (player.getPet() != null)
- {
- player.getPet().setOwner(player);
- }
- player.refreshOverloaded();
- player.refreshExpertisePenalty();
- player.restoreFriendList();
- // Retrieve the name and ID of the other characters assigned to this account.
- PreparedStatement stmt = con.prepareStatement("SELECT obj_Id, char_name FROM characters WHERE account_name=? AND obj_Id<>?");
- stmt.setString(1, player._accountName);
- stmt.setInt(2, objectId);
- ResultSet chars = stmt.executeQuery();
- while (chars.next())
- {
- player._chars.put(chars.getInt("obj_Id"), chars.getString("char_name"));
- }
- chars.close();
- stmt.close();
- break;
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.error("Could not restore char data: " + e);
- }
- return player;
- }
- public Forum getMail()
- {
- if (_forumMail == null)
- {
- setMail(ForumsBBSManager.getInstance().getForumByName("MailRoot").getChildByName(getName()));
- if (_forumMail == null)
- {
- ForumsBBSManager.getInstance().createNewForum(getName(), ForumsBBSManager.getInstance().getForumByName("MailRoot"), Forum.MAIL, Forum.OWNERONLY, getObjectId());
- setMail(ForumsBBSManager.getInstance().getForumByName("MailRoot").getChildByName(getName()));
- }
- }
- return _forumMail;
- }
- public void setMail(Forum forum)
- {
- _forumMail = forum;
- }
- public Forum getMemo()
- {
- if (_forumMemo == null)
- {
- setMemo(ForumsBBSManager.getInstance().getForumByName("MemoRoot").getChildByName(_accountName));
- if (_forumMemo == null)
- {
- ForumsBBSManager.getInstance().createNewForum(_accountName, ForumsBBSManager.getInstance().getForumByName("MemoRoot"), Forum.MEMO, Forum.OWNERONLY, getObjectId());
- setMemo(ForumsBBSManager.getInstance().getForumByName("MemoRoot").getChildByName(_accountName));
- }
- }
- return _forumMemo;
- }
- public void setMemo(Forum forum)
- {
- _forumMemo = forum;
- }
- /**
- * Restores sub-class data for the L2PcInstance, used to check the current class index for the character.
- * @param player The player to make checks on.
- * @return true if successful.
- */
- private static boolean restoreSubClassData(L2PcInstance player)
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_SUBCLASSES);
- statement.setInt(1, player.getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- SubClass subClass = new SubClass();
- subClass.setClassId(rset.getInt("class_id"));
- subClass.setLevel(rset.getByte("level"));
- subClass.setExp(rset.getLong("exp"));
- subClass.setSp(rset.getInt("sp"));
- subClass.setClassIndex(rset.getInt("class_index"));
- // Enforce the correct indexing of _subClasses against their class indexes.
- player.getSubClasses().put(subClass.getClassIndex(), subClass);
- }
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not restore classes for " + player.getName() + ": " + e);
- e.printStackTrace();
- }
- return true;
- }
- /**
- * Restores secondary data for the L2PcInstance, based on the current class index.
- */
- private void restoreCharData()
- {
- // Retrieve from the database all skills of this L2PcInstance and add them to _skills.
- restoreSkills();
- // Retrieve from the database all macroses of this L2PcInstance and add them to _macroses.
- _macroses.restore();
- // Retrieve from the database all shortCuts of this L2PcInstance and add them to _shortCuts.
- _shortCuts.restore();
- // Retrieve from the database all henna of this L2PcInstance and add them to _henna.
- restoreHenna();
- // Retrieve from the database all recom data of this L2PcInstance and add to _recomChars.
- restoreRecom();
- // Retrieve from the database the recipe book of this L2PcInstance.
- if (!isSubClassActive())
- {
- restoreRecipeBook();
- }
- }
- /**
- * Store recipe book data for this L2PcInstance, if not on an active sub-class.
- */
- private void storeRecipeBook()
- {
- // If the player is on a sub-class don't even attempt to store a recipe book.
- if (isSubClassActive())
- {
- return;
- }
- if (getCommonRecipeBook().isEmpty() && getDwarvenRecipeBook().isEmpty())
- {
- return;
- }
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("DELETE FROM character_recipebook WHERE char_id=?");
- statement.setInt(1, getObjectId());
- statement.execute();
- statement.close();
- for (RecipeList recipe : getCommonRecipeBook())
- {
- statement = con.prepareStatement("INSERT INTO character_recipebook (char_id, id, type) values(?,?,0)");
- statement.setInt(1, getObjectId());
- statement.setInt(2, recipe.getId());
- statement.execute();
- statement.close();
- }
- for (RecipeList recipe : getDwarvenRecipeBook())
- {
- statement = con.prepareStatement("INSERT INTO character_recipebook (char_id, id, type) values(?,?,1)");
- statement.setInt(1, getObjectId());
- statement.setInt(2, recipe.getId());
- statement.execute();
- statement.close();
- }
- }
- catch (Exception e)
- {
- _log.warn("Could not store recipe book data: " + e);
- }
- }
- /**
- * Restore recipe book data for this L2PcInstance.
- */
- private void restoreRecipeBook()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT id, type FROM character_recipebook WHERE char_id=?");
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- final RecipeList recipe = RecipeTable.getInstance().getRecipeList(rset.getInt("id"));
- if (rset.getInt("type") == 1)
- {
- registerDwarvenRecipeList(recipe);
- }
- else
- {
- registerCommonRecipeList(recipe);
- }
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not restore recipe book data:" + e);
- }
- }
- /**
- * Update L2PcInstance stats in the characters table of the database.
- * @param storeActiveEffects
- */
- public synchronized void store(boolean storeActiveEffects)
- {
- // update client coords, if these look like true
- if (isInsideRadius(getClientX(), getClientY(), 1000, true))
- {
- setXYZ(getClientX(), getClientY(), getClientZ());
- }
- storeCharBase();
- storeCharSub();
- storeEffect(storeActiveEffects);
- storeRecipeBook();
- SevenSigns.getInstance().saveSevenSignsData(getObjectId());
- try
- {
- saveSettingInDb();
- }
- catch (Exception e)
- {
- _log.info("L2PcInstance: Error saving character " + getName() + " settings, not fatal" + e);
- }
- }
- public void store()
- {
- store(true);
- }
- private void storeCharBase()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- // Get the exp, level, and sp of base class to store in base table
- int currentClassIndex = getClassIndex();
- _classIndex = 0;
- long exp = getStat().getExp();
- int level = getStat().getLevel();
- int sp = getStat().getSp();
- _classIndex = currentClassIndex;
- PreparedStatement statement = con.prepareStatement(UPDATE_CHARACTER);
- statement.setInt(1, level);
- statement.setInt(2, getMaxHp());
- statement.setDouble(3, getCurrentHp());
- statement.setInt(4, getMaxCp());
- statement.setDouble(5, getCurrentCp());
- statement.setInt(6, getMaxMp());
- statement.setDouble(7, getCurrentMp());
- statement.setInt(8, getAppearance().getFace());
- statement.setInt(9, getAppearance().getHairStyle());
- statement.setInt(10, getAppearance().getHairColor());
- statement.setInt(11, getAppearance().getSex() ? 1 : 0);
- statement.setInt(12, getHeading());
- statement.setInt(13, _observerMode ? _lastX : getX());
- statement.setInt(14, _observerMode ? _lastY : getY());
- statement.setInt(15, _observerMode ? _lastZ : getZ());
- statement.setLong(16, exp);
- statement.setLong(17, getExpBeforeDeath());
- statement.setInt(18, sp);
- statement.setInt(19, getKarma());
- statement.setInt(20, getPvpKills());
- statement.setInt(21, getPkKills());
- statement.setInt(22, getRecomHave());
- statement.setInt(23, getRecomLeft());
- statement.setInt(24, getClanId());
- statement.setInt(25, getRace().ordinal());
- statement.setInt(26, getClassId().getId());
- statement.setLong(27, getDeleteTimer());
- statement.setString(28, getTitle());
- statement.setInt(29, getAccessLevel().getLevel());
- statement.setInt(30, isOnlineInt());
- statement.setInt(31, isIn7sDungeon() ? 1 : 0);
- statement.setInt(32, getClanPrivileges());
- statement.setInt(33, wantsPeace() ? 1 : 0);
- statement.setInt(34, getBaseClass());
- long totalOnlineTime = _onlineTime;
- if (_onlineBeginTime > 0)
- {
- totalOnlineTime += (System.currentTimeMillis() - _onlineBeginTime) / 1000;
- }
- statement.setLong(35, totalOnlineTime);
- statement.setInt(36, getPunishLevel().value());
- statement.setLong(37, getPunishTimer());
- statement.setInt(38, isNoble() ? 1 : 0);
- statement.setLong(39, getPowerGrade());
- statement.setInt(40, getPledgeType());
- statement.setLong(41, getLastRecomUpdate());
- statement.setInt(42, getLvlJoinedAcademy());
- statement.setLong(43, getApprentice());
- statement.setLong(44, getSponsor());
- statement.setInt(45, getAllianceWithVarkaKetra());
- statement.setLong(46, getClanJoinExpiryTime());
- statement.setLong(47, getClanCreateExpiryTime());
- statement.setString(48, getName());
- statement.setLong(49, getDeathPenaltyBuffLevel());
- statement.setInt(50, getPcBangScore());
- statement.setInt(51, getAppearance().getTitleColor());
- statement.setInt(52, getAppearance().getNameColor());
- statement.setInt(53, getObjectId());
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not store char base data: " + e);
- }
- }
- private void storeCharSub()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(UPDATE_CHAR_SUBCLASS);
- if (getTotalSubClasses() > 0)
- {
- for (SubClass subClass : getSubClasses().values())
- {
- statement.setLong(1, subClass.getExp());
- statement.setInt(2, subClass.getSp());
- statement.setInt(3, subClass.getLevel());
- statement.setInt(4, subClass.getClassId());
- statement.setInt(5, getObjectId());
- statement.setInt(6, subClass.getClassIndex());
- statement.execute();
- }
- }
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not store sub class data for " + getName() + ": " + e);
- }
- }
- private void storeEffect(boolean storeEffects)
- {
- if (!Config.STORE_SKILL_COOLTIME)
- {
- return;
- }
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- // Delete all current stored effects for char to avoid dupe
- PreparedStatement statement = con.prepareStatement(DELETE_SKILL_SAVE);
- statement.setInt(1, getObjectId());
- statement.setInt(2, getClassIndex());
- statement.execute();
- statement.close();
- int buff_index = 0;
- final List<Integer> storedSkills = new ArrayList<>();
- // Store all effect data along with calulated remaining reuse delays for matching skills. 'restore_type'= 0.
- statement = con.prepareStatement(ADD_SKILL_SAVE);
- if (storeEffects)
- {
- for (L2Effect effect : getAllEffects())
- {
- if (effect == null)
- {
- continue;
- }
- switch (effect.getEffectType())
- {
- case HEAL_OVER_TIME:
- case COMBAT_POINT_HEAL_OVER_TIME:
- continue;
- }
- L2Skill skill = effect.getSkill();
- if (storedSkills.contains(skill.getReuseHashCode()))
- {
- continue;
- }
- storedSkills.add(skill.getReuseHashCode());
- if (!effect.isHerbEffect() && effect.getInUse() && !skill.isToggle())
- {
- statement.setInt(1, getObjectId());
- statement.setInt(2, skill.getId());
- statement.setInt(3, skill.getLevel());
- statement.setInt(4, effect.getCount());
- statement.setInt(5, effect.getTime());
- if (_reuseTimeStamps.containsKey(skill.getReuseHashCode()))
- {
- TimeStamp t = _reuseTimeStamps.get(skill.getReuseHashCode());
- statement.setLong(6, t.hasNotPassed() ? t.getReuse() : 0);
- statement.setDouble(7, t.hasNotPassed() ? t.getStamp() : 0);
- }
- else
- {
- statement.setLong(6, 0);
- statement.setDouble(7, 0);
- }
- statement.setInt(8, 0);
- statement.setInt(9, getClassIndex());
- statement.setInt(10, ++buff_index);
- statement.execute();
- }
- }
- }
- // Store the reuse delays of remaining skills which lost effect but still under reuse delay. 'restore_type' 1.
- for (int hash : _reuseTimeStamps.keySet())
- {
- if (storedSkills.contains(hash))
- {
- continue;
- }
- TimeStamp t = _reuseTimeStamps.get(hash);
- if (t != null && t.hasNotPassed())
- {
- storedSkills.add(hash);
- statement.setInt(1, getObjectId());
- statement.setInt(2, t.getSkillId());
- statement.setInt(3, t.getSkillLvl());
- statement.setInt(4, -1);
- statement.setInt(5, -1);
- statement.setLong(6, t.getReuse());
- statement.setDouble(7, t.getStamp());
- statement.setInt(8, 1);
- statement.setInt(9, getClassIndex());
- statement.setInt(10, ++buff_index);
- statement.execute();
- }
- }
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not store char effect data: ", e);
- }
- }
- /**
- * @return True if the L2PcInstance is online.
- */
- public boolean isOnline()
- {
- return _isOnline;
- }
- /**
- * @return an int interpretation of online status.
- */
- public int isOnlineInt()
- {
- if (_isOnline && getClient() != null)
- {
- return getClient().isDetached() ? 2 : 1;
- }
- return 0;
- }
- public boolean isIn7sDungeon()
- {
- return _isIn7sDungeon;
- }
- /**
- * 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.
- * <ul>
- * <li>Replace oldSkill by newSkill or Add the newSkill</li>
- * <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li>
- * <li>Add Func objects of newSkill to the calculator set of the L2Character</li>
- * </ul>
- * @param newSkill The L2Skill to add to the L2Character
- * @param store
- * @return The L2Skill replaced or null if just added a new L2Skill
- */
- public L2Skill addSkill(L2Skill newSkill, boolean store)
- {
- // Add a skill to the L2PcInstance _skills and its Func objects to the calculator set of the L2PcInstance
- L2Skill oldSkill = super.addSkill(newSkill);
- // Add or update a L2PcInstance skill in the character_skills table of the database
- if (store)
- {
- storeSkill(newSkill, oldSkill, -1);
- }
- return oldSkill;
- }
- @Override
- public L2Skill removeSkill(L2Skill skill, boolean store)
- {
- if (store)
- {
- return removeSkill(skill);
- }
- return super.removeSkill(skill, true);
- }
- public L2Skill removeSkill(L2Skill skill, boolean store, boolean cancelEffect)
- {
- if (store)
- {
- return removeSkill(skill);
- }
- return super.removeSkill(skill, cancelEffect);
- }
- /**
- * 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.
- * <ul>
- * <li>Remove the skill from the L2Character _skills</li>
- * <li>Remove all its Func objects from the L2Character calculator set</li>
- * </ul>
- * @param skill The L2Skill to remove from the L2Character
- * @return The L2Skill removed
- */
- @Override
- public L2Skill removeSkill(L2Skill skill)
- {
- // Remove a skill from the L2Character and its Func objects from calculator set of the L2Character
- L2Skill oldSkill = super.removeSkill(skill);
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(DELETE_SKILL_FROM_CHAR);
- if (oldSkill != null)
- {
- statement.setInt(1, oldSkill.getId());
- statement.setInt(2, getObjectId());
- statement.setInt(3, getClassIndex());
- statement.execute();
- }
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Error could not delete skill: " + e);
- }
- // Don't busy with shortcuts if skill was a passive skill.
- if (skill != null && !skill.isPassive())
- {
- for (L2ShortCut sc : getAllShortCuts())
- {
- if (sc != null && sc.getId() == skill.getId() && sc.getType() == L2ShortCut.TYPE_SKILL)
- {
- deleteShortCut(sc.getSlot(), sc.getPage());
- }
- }
- }
- return oldSkill;
- }
- /**
- * Add or update a L2PcInstance skill in the character_skills table of the database. <BR>
- * <BR>
- * If newClassIndex > -1, the skill will be stored with that class index, not the current one.
- * @param newSkill
- * @param oldSkill
- * @param newClassIndex
- */
- private void storeSkill(L2Skill newSkill, L2Skill oldSkill, int newClassIndex)
- {
- int classIndex = _classIndex;
- if (newClassIndex > -1)
- {
- classIndex = newClassIndex;
- }
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement;
- if (oldSkill != null && newSkill != null)
- {
- statement = con.prepareStatement(UPDATE_CHARACTER_SKILL_LEVEL);
- statement.setInt(1, newSkill.getLevel());
- statement.setInt(2, oldSkill.getId());
- statement.setInt(3, getObjectId());
- statement.setInt(4, classIndex);
- statement.execute();
- statement.close();
- }
- else if (newSkill != null)
- {
- statement = con.prepareStatement(ADD_NEW_SKILL);
- statement.setInt(1, getObjectId());
- statement.setInt(2, newSkill.getId());
- statement.setInt(3, newSkill.getLevel());
- statement.setInt(4, classIndex);
- statement.execute();
- statement.close();
- }
- else
- {
- _log.warn("storeSkill() couldn't store new skill. It's null type.");
- }
- }
- catch (Exception e)
- {
- _log.warn("Error could not store char skills: " + e);
- }
- }
- /**
- * Retrieve from the database all skills of this L2PcInstance and add them to _skills.
- */
- private void restoreSkills()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR);
- statement.setInt(1, getObjectId());
- statement.setInt(2, getClassIndex());
- ResultSet rset = statement.executeQuery();
- // Go though the recordset of this SQL query
- while (rset.next())
- {
- int id = rset.getInt("skill_id");
- int level = rset.getInt("skill_level");
- if (id > 9000)
- {
- continue; // fake skills for base stats
- }
- // Create a L2Skill object for each record
- L2Skill skill = SkillTable.getInstance().getInfo(id, level);
- // Add the L2Skill object to the L2Character _skills and its Func objects to the calculator set of the L2Character
- super.addSkill(skill);
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not restore character skills: " + e);
- }
- }
- /**
- * Retrieve from the database all skill effects of this L2PcInstance and add them to the player.
- */
- public void restoreEffects()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_SKILL_SAVE);
- statement.setInt(1, getObjectId());
- statement.setInt(2, getClassIndex());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- int effectCount = rset.getInt("effect_count");
- int effectCurTime = rset.getInt("effect_cur_time");
- long reuseDelay = rset.getLong("reuse_delay");
- long systime = rset.getLong("systime");
- int restoreType = rset.getInt("restore_type");
- final L2Skill skill = SkillTable.getInstance().getInfo(rset.getInt("skill_id"), rset.getInt("skill_level"));
- if (skill == null)
- {
- continue;
- }
- final long remainingTime = systime - System.currentTimeMillis();
- if (remainingTime > 10)
- {
- disableSkill(skill, remainingTime);
- addTimeStamp(skill, reuseDelay, systime);
- }
- /**
- * Restore Type 1 The remaning skills lost effect upon logout but were still under a high reuse delay.
- */
- if (restoreType > 0)
- {
- continue;
- }
- /**
- * 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.
- */
- if (skill.hasEffects())
- {
- final Env env = new Env();
- env.setCharacter(this);
- env.setTarget(this);
- env.setSkill(skill);
- for (EffectTemplate et : skill.getEffectTemplates())
- {
- final L2Effect ef = et.getEffect(env);
- if (ef != null)
- {
- ef.setCount(effectCount);
- ef.setFirstTime(effectCurTime);
- ef.scheduleEffect();
- }
- }
- }
- }
- rset.close();
- statement.close();
- statement = con.prepareStatement(DELETE_SKILL_SAVE);
- statement.setInt(1, getObjectId());
- statement.setInt(2, getClassIndex());
- statement.executeUpdate();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not restore " + this + " active effect data: " + e.getMessage(), e);
- }
- }
- /**
- * Retrieve from the database all Henna of this L2PcInstance, add them to _henna and calculate stats of the L2PcInstance.
- */
- private void restoreHenna()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_HENNAS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, getClassIndex());
- ResultSet rset = statement.executeQuery();
- for (int i = 0; i < 3; i++)
- {
- _henna[i] = null;
- }
- while (rset.next())
- {
- int slot = rset.getInt("slot");
- if (slot < 1 || slot > 3)
- {
- continue;
- }
- int symbolId = rset.getInt("symbol_id");
- if (symbolId != 0)
- {
- Henna tpl = HennaTable.getInstance().getTemplate(symbolId);
- if (tpl != null)
- {
- _henna[slot - 1] = tpl;
- }
- }
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("could not restore henna: " + e);
- }
- // Calculate Henna modifiers of this L2PcInstance
- recalcHennaStats();
- }
- /**
- * Retrieve from the database all Recommendation data of this L2PcInstance, add to _recomChars and calculate stats of the L2PcInstance.
- */
- private void restoreRecom()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_CHAR_RECOMS);
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- _recomChars.add(rset.getInt("target_id"));
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("could not restore recommendations: " + e);
- }
- }
- /**
- * @return the number of Henna empty slot of the L2PcInstance.
- */
- public int getHennaEmptySlots()
- {
- int totalSlots = 0;
- if (getClassId().level() == 1)
- {
- totalSlots = 2;
- }
- else
- {
- totalSlots = 3;
- }
- for (int i = 0; i < 3; i++)
- {
- if (_henna[i] != null)
- {
- totalSlots--;
- }
- }
- if (totalSlots <= 0)
- {
- return 0;
- }
- return totalSlots;
- }
- /**
- * Remove a Henna of the L2PcInstance, save update in the character_hennas table of the database and send HennaInfo/UserInfo packet to this L2PcInstance.
- * @param slot The slot number to make checks on.
- * @return true if successful.
- */
- public boolean removeHenna(int slot)
- {
- if (slot < 1 || slot > 3)
- {
- return false;
- }
- slot--;
- if (_henna[slot] == null)
- {
- return false;
- }
- Henna henna = _henna[slot];
- _henna[slot] = null;
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNA);
- statement.setInt(1, getObjectId());
- statement.setInt(2, slot + 1);
- statement.setInt(3, getClassIndex());
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("could not remove char henna: " + e);
- }
- // Calculate Henna modifiers of this L2PcInstance
- recalcHennaStats();
- // Send HennaInfo packet to this L2PcInstance
- sendPacket(new HennaInfo(this));
- // Send UserInfo packet to this L2PcInstance
- sendPacket(new UserInfo(this));
- reduceAdena("Henna", henna.getPrice() / 5, this, false);
- // Add the recovered dyes to the player's inventory and notify them.
- addItem("Henna", henna.getDyeId(), Henna.getAmountDyeRequire() / 2, this, true);
- sendPacket(SystemMessageId.SYMBOL_DELETED);
- return true;
- }
- /**
- * 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.
- * @param henna The Henna template to add.
- */
- public void addHenna(Henna henna)
- {
- for (int i = 0; i < 3; i++)
- {
- if (_henna[i] == null)
- {
- _henna[i] = henna;
- // Calculate Henna modifiers of this L2PcInstance
- recalcHennaStats();
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(ADD_CHAR_HENNA);
- statement.setInt(1, getObjectId());
- statement.setInt(2, henna.getSymbolId());
- statement.setInt(3, i + 1);
- statement.setInt(4, getClassIndex());
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("could not save char henna: " + e);
- }
- sendPacket(new HennaInfo(this));
- sendPacket(new UserInfo(this));
- sendPacket(SystemMessageId.SYMBOL_ADDED);
- return;
- }
- }
- }
- /**
- * Calculate Henna modifiers of this L2PcInstance.
- */
- private void recalcHennaStats()
- {
- _hennaINT = 0;
- _hennaSTR = 0;
- _hennaCON = 0;
- _hennaMEN = 0;
- _hennaWIT = 0;
- _hennaDEX = 0;
- for (int i = 0; i < 3; i++)
- {
- if (_henna[i] == null)
- {
- continue;
- }
- _hennaINT += _henna[i].getStatINT();
- _hennaSTR += _henna[i].getStatSTR();
- _hennaMEN += _henna[i].getStatMEN();
- _hennaCON += _henna[i].getStatCON();
- _hennaWIT += _henna[i].getStatWIT();
- _hennaDEX += _henna[i].getStatDEX();
- }
- if (_hennaINT > 5)
- {
- _hennaINT = 5;
- }
- if (_hennaSTR > 5)
- {
- _hennaSTR = 5;
- }
- if (_hennaMEN > 5)
- {
- _hennaMEN = 5;
- }
- if (_hennaCON > 5)
- {
- _hennaCON = 5;
- }
- if (_hennaWIT > 5)
- {
- _hennaWIT = 5;
- }
- if (_hennaDEX > 5)
- {
- _hennaDEX = 5;
- }
- }
- /**
- * @param slot A slot to check.
- * @return the Henna of this L2PcInstance corresponding to the selected slot.
- */
- public Henna getHenna(int slot)
- {
- if (slot < 1 || slot > 3)
- {
- return null;
- }
- return _henna[slot - 1];
- }
- public int getHennaStatINT()
- {
- return _hennaINT;
- }
- public int getHennaStatSTR()
- {
- return _hennaSTR;
- }
- public int getHennaStatCON()
- {
- return _hennaCON;
- }
- public int getHennaStatMEN()
- {
- return _hennaMEN;
- }
- public int getHennaStatWIT()
- {
- return _hennaWIT;
- }
- public int getHennaStatDEX()
- {
- return _hennaDEX;
- }
- /**
- * Return True if the L2PcInstance is autoAttackable.
- * <ul>
- * <li>Check if the attacker isn't the L2PcInstance Pet</li>
- * <li>Check if the attacker is L2MonsterInstance</li>
- * <li>If the attacker is a L2PcInstance, check if it is not in the same party</li>
- * <li>Check if the L2PcInstance has Karma</li>
- * <li>If the attacker is a L2PcInstance, check if it is not in the same siege clan (Attacker, Defender)</li>
- * </ul>
- */
- @Override
- public boolean isAutoAttackable(L2Character attacker)
- {
- // Check if the attacker isn't the L2PcInstance Pet
- if (attacker == this || attacker == getPet())
- {
- return false;
- }
- // Check if the attacker is a L2MonsterInstance
- if (attacker instanceof L2MonsterInstance)
- {
- return true;
- }
- // Check if the attacker is not in the same party
- if (getParty() != null && getParty().getPartyMembers().contains(attacker))
- {
- return false;
- }
- if (attacker.getEvent() != null && attacker.getEvent().canAttack(attacker, this))
- {
- return true;
- }
- // Check if the attacker is a L2Playable
- if (attacker instanceof L2Playable)
- {
- if (isInsideZone(ZoneId.PEACE))
- {
- return false;
- }
- // Get L2PcInstance
- final L2PcInstance cha = attacker.getActingPlayer();
- if (cha != null && cha.isCursedWeaponEquipped())
- {
- return true;
- }
- // Check if the attacker is in olympiad and olympiad start
- if (attacker instanceof L2PcInstance && cha.isInOlympiadMode())
- {
- if (isInOlympiadMode() && isOlympiadStart() && cha.getOlympiadGameId() == getOlympiadGameId())
- {
- return true;
- }
- return false;
- }
- // is AutoAttackable if both players are in the same duel and the duel is still going on
- if (getDuelState() == Duel.DUELSTATE_DUELLING && getDuelId() == cha.getDuelId())
- {
- return true;
- }
- if (getClan() != null)
- {
- final Siege siege = SiegeManager.getSiege(getX(), getY(), getZ());
- if (siege != null)
- {
- // Check if a siege is in progress and if attacker and the L2PcInstance aren't in the Defender clan
- if (siege.checkIsDefender(cha.getClan()) && siege.checkIsDefender(getClan()))
- {
- return false;
- }
- // Check if a siege is in progress and if attacker and the L2PcInstance aren't in the Attacker clan
- if (siege.checkIsAttacker(cha.getClan()) && siege.checkIsAttacker(getClan()))
- {
- return false;
- }
- }
- // Check if clan is at war
- if (getClan().isAtWarWith(cha.getClanId()) && !wantsPeace() && !cha.wantsPeace() && !isAcademyMember())
- {
- return true;
- }
- }
- // Check if the L2PcInstance is in an arena.
- if (isInArena() && attacker.isInArena())
- {
- return true;
- }
- // Check if the attacker is not in the same ally.
- if (getAllyId() != 0 && getAllyId() == cha.getAllyId())
- {
- return false;
- }
- // Check if the attacker is not in the same clan.
- if (getClan() != null && getClan().isMember(cha.getObjectId()))
- {
- return false;
- }
- // Now check again if the L2PcInstance is in pvp zone (as arenas check was made before, it ends with sieges).
- if (isInsideZone(ZoneId.PVP) && attacker.isInsideZone(ZoneId.PVP))
- {
- return true;
- }
- }
- else if (attacker instanceof L2SiegeGuardInstance)
- {
- if (getClan() != null)
- {
- final Siege siege = SiegeManager.getSiege(this);
- return (siege != null && siege.checkIsAttacker(getClan()));
- }
- }
- // Check if the L2PcInstance has Karma
- if (getKarma() > 0 || getPvpFlag() > 0)
- {
- return true;
- }
- return false;
- }
- /**
- * Check if the active L2Skill can be casted.
- * <ul>
- * <li>Check if the skill isn't toggle and is offensive</li>
- * <li>Check if the target is in the skill cast range</li>
- * <li>Check if the skill is Spoil type and if the target isn't already spoiled</li>
- * <li>Check if the caster owns enought consummed Item, enough HP and MP to cast the skill</li>
- * <li>Check if the caster isn't sitting</li>
- * <li>Check if all skills are enabled and this skill is enabled</li>
- * <li>Check if the caster own the weapon needed</li>
- * <li>Check if the skill is active</li>
- * <li>Check if all casting conditions are completed</li>
- * <li>Notify the AI with CAST and target</li>
- * </ul>
- * @param skill The L2Skill to use
- * @param forceUse used to force ATTACK on players
- * @param dontMove used to prevent movement, if not in range
- */
- @Override
- public boolean useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
- {
- // Check if the skill is active
- if (skill.isPassive())
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // Cancels the use of skills when player uses a cursed weapon or is flying.
- if ((isCursedWeaponEquipped() && (!skill.isDemonicSkill()
- && !(skill.isMagic() && Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("mage"))
- && !(!skill.isMagic() && Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("fighter"))
- && !Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("all")
- && !Arrays.asList(Config.DEMONIC_SWORD_CAST_SKILL_LIST).contains(skill.getDisplayId()))) // If CW, allow ONLY demonic skills.
- || (getMountType() == 1 && !skill.isStriderSkill()
- && !(skill.isMagic() && Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("mage"))
- && !(!skill.isMagic() && Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("fighter"))
- && !Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("all")
- && !Arrays.asList(Config.STRIDER_CAST_SKILL_LIST).contains(skill.getDisplayId())) // If mounted, allow ONLY Strider skills.
- || (getMountType() == 2 && !skill.isFlyingSkill())) // If flying, allow ONLY Wyvern skills.
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // Players wearing Formal Wear cannot use skills.
- final ItemInstance formal = getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
- if (formal != null && formal.getItem().getBodyPart() == Item.SLOT_ALLDRESS)
- {
- sendPacket(SystemMessageId.CANNOT_USE_ITEMS_SKILLS_WITH_FORMALWEAR);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // ************************************* Check Casting in Progress *******************************************
- // If a skill is currently being used, queue this one if this is not the same
- if (isCastingNow())
- {
- // Check if new skill different from current skill in progress ; queue it in the player _queuedSkill
- if (_currentSkill.getSkill() != null && skill.getId() != _currentSkill.getSkillId())
- {
- setQueuedSkill(skill, forceUse, dontMove);
- }
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- setIsCastingNow(true);
- // Set the player _currentSkill.
- setCurrentSkill(skill, forceUse, dontMove);
- // Wipe queued skill.
- if (_queuedSkill.getSkill() != null)
- {
- setQueuedSkill(null, false, false);
- }
- if (!checkUseMagicConditions(skill, forceUse, dontMove))
- {
- setIsCastingNow(false);
- return false;
- }
- // Check if the target is correct and Notify the AI with CAST and target
- L2Object target = null;
- switch (skill.getTargetType())
- {
- case TARGET_AURA:
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_GROUND:
- case TARGET_SELF:
- case TARGET_CORPSE_ALLY:
- case TARGET_AURA_UNDEAD:
- target = this;
- break;
- default: // Get the first target of the list
- target = skill.getFirstOfTargetList(this);
- break;
- }
- // Notify the AI with CAST and target
- getAI().setIntention(CtrlIntention.CAST, skill, target);
- return true;
- }
- private boolean checkUseMagicConditions(L2Skill skill, boolean forceUse, boolean dontMove)
- {
- // ************************************* Check Player State *******************************************
- if (isDead() || isOutOfControl())
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- L2SkillType sklType = skill.getSkillType();
- if (isFishing() && (sklType != L2SkillType.PUMPING && sklType != L2SkillType.REELING && sklType != L2SkillType.FISHING))
- {
- // Only fishing skills are available
- sendPacket(SystemMessageId.ONLY_FISHING_SKILLS_NOW);
- return false;
- }
- if (inObserverMode())
- {
- sendPacket(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE);
- abortCast();
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // Check if the caster is sitted. Toggle skills can be only removed, not activated.
- if (isSitting())
- {
- if (skill.isToggle())
- {
- // Get effects of the skill
- L2Effect effect = getFirstEffect(skill.getId());
- if (effect != null)
- {
- effect.exit();
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Send a System Message to the caster
- sendPacket(SystemMessageId.CANT_MOVE_SITTING);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // Check if the skill type is TOGGLE
- if (skill.isToggle())
- {
- // Get effects of the skill
- L2Effect effect = getFirstEffect(skill.getId());
- if (effect != null)
- {
- // If the toggle is different of FakeDeath, you can de-activate it clicking on it.
- if (skill.getId() != 60)
- {
- effect.exit();
- }
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Check if the player uses "Fake Death" skill
- if (isFakeDeath())
- {
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // ************************************* Check Target *******************************************
- // Create and set a L2Object containing the target of the skill
- L2Object target = null;
- SkillTargetType sklTargetType = skill.getTargetType();
- Point3D worldPosition = getCurrentSkillWorldPosition();
- if (sklTargetType == SkillTargetType.TARGET_GROUND && worldPosition == null)
- {
- _log.info("WorldPosition is null for skill: " + skill.getName() + ", player: " + getName() + ".");
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- switch (sklTargetType)
- {
- // Target the player if skill type is AURA, PARTY, CLAN or SELF
- case TARGET_AURA:
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_AURA_UNDEAD:
- case TARGET_PARTY:
- case TARGET_ALLY:
- case TARGET_CLAN:
- case TARGET_GROUND:
- case TARGET_SELF:
- case TARGET_CORPSE_ALLY:
- case TARGET_AREA_SUMMON:
- target = this;
- break;
- case TARGET_PET:
- case TARGET_SUMMON:
- target = getPet();
- break;
- default:
- target = getTarget();
- break;
- }
- // Check the validity of the target
- if (target == null)
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- if (target instanceof L2DoorInstance)
- {
- if (!((L2DoorInstance) target).isAttackable(this) // Siege doors only hittable during siege
- || (((L2DoorInstance) target).isUnlockable() && skill.getSkillType() != L2SkillType.UNLOCK)) // unlockable doors
- {
- sendPacket(SystemMessageId.INCORRECT_TARGET);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Are the target and the player in the same duel?
- if (isInDuel())
- {
- if (target instanceof L2Playable)
- {
- // Get L2PcInstance
- L2PcInstance cha = target.getActingPlayer();
- if (cha.getDuelId() != getDuelId())
- {
- sendPacket(SystemMessageId.INCORRECT_TARGET);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- }
- // ************************************* Check skill availability *******************************************
- // Siege summon checks. Both checks send a message to the player if it return false.
- if (skill.isSiegeSummonSkill() && (!SiegeManager.checkIfOkToSummon(this) || !SevenSigns.getInstance().checkSummonConditions(this)))
- {
- return false;
- }
- // Check if this skill is enabled (ex : reuse time)
- if (isSkillDisabled(skill))
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE).addSkillName(skill));
- return false;
- }
- // ************************************* Check casting conditions *******************************************
- // Check if all casting conditions are completed
- if (!skill.checkCondition(this, target, false))
- {
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // ************************************* Check Skill Type *******************************************
- // Check if this is offensive magic skill
- if (skill.isOffensive())
- {
- if (isInsidePeaceZone(this, target))
- {
- final L2PcInstance player = target.getActingPlayer();
- if (player != null)
- {
- if (!(_event != null && _event.isRunning()) || !(player.getEvent() != null && player.getEvent().isRunning()))
- {
- sendPacket(SystemMessageId.TARGET_IN_PEACEZONE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- else
- {
- sendPacket(SystemMessageId.TARGET_IN_PEACEZONE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- if (isInOlympiadMode() && !isOlympiadStart())
- {
- // if L2PcInstance is in Olympia and the match isn't already start, send ActionFailed
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- // Check if the target is attackable
- if (!target.isAttackable() && !getAccessLevel().allowPeaceAttack())
- {
- final L2PcInstance player = target.getActingPlayer();
- if (player != null)
- {
- if (!(_event != null && _event.isRunning()) || !(player.getEvent() != null && player.getEvent().isRunning()) && target != this)
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- else
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Check if a Forced ATTACK is in progress on non-attackable target
- if (!target.isAutoAttackable(this) && !forceUse && !(_event != null && _event.isRunning()))
- {
- switch (sklTargetType)
- {
- case TARGET_AURA:
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_AURA_UNDEAD:
- case TARGET_CLAN:
- case TARGET_ALLY:
- case TARGET_PARTY:
- case TARGET_SELF:
- case TARGET_GROUND:
- case TARGET_CORPSE_ALLY:
- case TARGET_AREA_SUMMON:
- break;
- default: // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Check if the target is in the skill cast range
- if (dontMove)
- {
- // Calculate the distance between the L2PcInstance and the target
- if (sklTargetType == SkillTargetType.TARGET_GROUND)
- {
- if (!isInsideRadius(worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), skill.getCastRange() + getTemplate().getCollisionRadius(), false, false))
- {
- // Send a System Message to the caster
- sendPacket(SystemMessageId.TARGET_TOO_FAR);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- else if (skill.getCastRange() > 0 && !isInsideRadius(target, skill.getCastRange() + getTemplate().getCollisionRadius(), false, false))
- {
- // Send a System Message to the caster
- sendPacket(SystemMessageId.TARGET_TOO_FAR);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- }
- // Check if the skill is defensive
- if (!skill.isOffensive() && target instanceof L2MonsterInstance && !forceUse)
- {
- // check if the target is a monster and if force attack is set.. if not then we don't want to cast.
- switch (sklTargetType)
- {
- case TARGET_PET:
- case TARGET_SUMMON:
- case TARGET_AURA:
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_AURA_UNDEAD:
- case TARGET_CLAN:
- case TARGET_SELF:
- case TARGET_CORPSE_ALLY:
- case TARGET_PARTY:
- case TARGET_ALLY:
- case TARGET_CORPSE_MOB:
- case TARGET_AREA_CORPSE_MOB:
- case TARGET_GROUND:
- break;
- default:
- {
- switch (sklType)
- {
- case BEAST_FEED:
- case DELUXE_KEY_UNLOCK:
- case UNLOCK:
- break;
- default:
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- break;
- }
- }
- }
- // Check if the skill is Spoil type and if the target isn't already spoiled
- if (sklType == L2SkillType.SPOIL)
- {
- if (!(target instanceof L2MonsterInstance))
- {
- // Send a System Message to the L2PcInstance
- sendPacket(SystemMessageId.INCORRECT_TARGET);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Check if the skill is Sweep type and if conditions not apply
- if (sklType == L2SkillType.SWEEP && target instanceof L2Attackable)
- {
- if (((L2Attackable) target).isDead())
- {
- final int spoilerId = ((L2Attackable) target).getSpoilerId();
- if (spoilerId == 0)
- {
- // Send a System Message to the L2PcInstance
- sendPacket(SystemMessageId.SWEEPER_FAILED_TARGET_NOT_SPOILED);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- if (getObjectId() != spoilerId && !isInLooterParty(spoilerId))
- {
- // Send a System Message to the L2PcInstance
- sendPacket(SystemMessageId.SWEEP_NOT_ALLOWED);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- }
- // Check if the skill is Drain Soul (Soul Crystals) and if the target is a MOB
- if (sklType == L2SkillType.DRAIN_SOUL)
- {
- if (!(target instanceof L2MonsterInstance))
- {
- // Send a System Message to the L2PcInstance
- sendPacket(SystemMessageId.INCORRECT_TARGET);
- // Send ActionFailed to the L2PcInstance
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // Check if this is a Pvp skill and target isn't a non-flagged/non-karma player
- switch (sklTargetType)
- {
- case TARGET_PARTY:
- case TARGET_ALLY: // For such skills, checkPvpSkill() is called from L2Skill.getTargetList()
- case TARGET_CLAN: // For such skills, checkPvpSkill() is called from L2Skill.getTargetList()
- case TARGET_AURA:
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_AURA_UNDEAD:
- case TARGET_GROUND:
- case TARGET_SELF:
- case TARGET_CORPSE_ALLY:
- break;
- default:
- if (!checkPvpSkill(target, skill) && !getAccessLevel().allowPeaceAttack())
- {
- final L2PcInstance player = target.getActingPlayer();
- if (player != null)
- {
- if (!(_event != null && _event.isRunning()) || !(player.getEvent() != null && player.getEvent().isRunning()))
- {
- sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- else
- {
- sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- }
- 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))))
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- abortCast();
- return false;
- }
- // GeoData Los Check here
- if (skill.getCastRange() > 0)
- {
- if (sklTargetType == SkillTargetType.TARGET_GROUND)
- {
- if (!GeoData.getInstance().canSeeTarget(this, worldPosition))
- {
- sendPacket(SystemMessageId.CANT_SEE_TARGET);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- else if (!GeoData.getInstance().canSeeTarget(this, target))
- {
- sendPacket(SystemMessageId.CANT_SEE_TARGET);
- sendPacket(ActionFailed.STATIC_PACKET);
- return false;
- }
- }
- // finally, after passing all conditions
- return true;
- }
- public boolean checkIfOkToUseStriderSiegeAssault(L2Skill skill)
- {
- SystemMessage sm;
- Castle castle = CastleManager.getInstance().getCastle(this);
- if (!isRiding())
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else if (!(getTarget() instanceof L2DoorInstance))
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET);
- }
- else if (castle == null || castle.getCastleId() <= 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else if (!castle.getSiege().isInProgress() || castle.getSiege().getAttackerClan(getClan()) == null)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else
- {
- return true;
- }
- sendPacket(sm);
- return false;
- }
- public boolean checkIfOkToCastSealOfRule(Castle castle, boolean isCheckOnly, L2Skill skill, L2Object target)
- {
- SystemMessage sm;
- if (castle == null || castle.getCastleId() <= 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else if (!castle.getArtefacts().contains(target))
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET);
- }
- else if (!castle.getSiege().isInProgress())
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else if (!Util.checkIfInRange(200, this, target, true))
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED);
- }
- else if (!isInsideZone(ZoneId.CAST_ON_ARTIFACT))
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else if (castle.getSiege().getAttackerClan(getClan()) == null)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill);
- }
- else
- {
- if (!isCheckOnly)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.OPPONENT_STARTED_ENGRAVING);
- castle.getSiege().announceToPlayer(sm, false);
- }
- return true;
- }
- sendPacket(sm);
- return false;
- }
- public boolean isInLooterParty(int LooterId)
- {
- L2PcInstance looter = L2World.getInstance().getPlayer(LooterId);
- // if L2PcInstance is in a CommandChannel
- if (isInParty() && getParty().isInCommandChannel() && looter != null)
- {
- return getParty().getCommandChannel().getMembers().contains(looter);
- }
- if (isInParty() && looter != null)
- {
- return getParty().getPartyMembers().contains(looter);
- }
- return false;
- }
- /**
- * Check if the requested casting is a Pc->Pc skill cast and if it's a valid pvp condition
- * @param target L2Object instance containing the target
- * @param skill L2Skill instance with the skill being casted
- * @return False if the skill is a pvpSkill and target is not a valid pvp target
- */
- public boolean checkPvpSkill(L2Object target, L2Skill skill)
- {
- return checkPvpSkill(target, skill, false);
- }
- /**
- * Check if the requested casting is a Pc->Pc skill cast and if it's a valid pvp condition
- * @param target L2Object instance containing the target
- * @param skill L2Skill instance with the skill being casted
- * @param srcIsSummon is L2Summon - caster?
- * @return False if the skill is a pvpSkill and target is not a valid pvp target
- */
- public boolean checkPvpSkill(L2Object target, L2Skill skill, boolean srcIsSummon)
- {
- // Retrieve pet owner.
- if (target instanceof L2Summon)
- {
- target = target.getActingPlayer();
- }
- if (target != null && target != this && target instanceof L2PcInstance && !(isInDuel() && ((L2PcInstance) target).getDuelId() == getDuelId()) && !isInsideZone(ZoneId.PVP) && !target.isInsideZone(ZoneId.PVP))
- {
- final L2PcInstance targetPlayer = ((L2PcInstance) target);
- if (skill.isPvpSkill())
- {
- // in clan war player can attack whites even with sleep etc.
- if (getClan() != null && targetPlayer.getClan() != null)
- {
- if (getClan().isAtWarWith(targetPlayer.getClan().getClanId()))
- {
- return true;
- }
- }
- // target's pvp flag is not set and target has no karma
- if (targetPlayer.getPvpFlag() == 0 && targetPlayer.getKarma() == 0)
- {
- return false;
- }
- }
- else
- {
- final boolean isForcedPlayerOrPetSkill = ((_currentSkill.getSkill() != null && !_currentSkill.isCtrlPressed() && !srcIsSummon) || (_currentPetSkill.getSkill() != null && !_currentPetSkill.isCtrlPressed() && srcIsSummon));
- if (skill.isOffensive())
- {
- if (isForcedPlayerOrPetSkill)
- {
- // in clan war player can attack whites even with sleep etc.
- if (getClan() != null && targetPlayer.getClan() != null)
- {
- if (getClan().isAtWarWith(targetPlayer.getClan().getClanId()))
- {
- return true;
- }
- }
- // target's pvp flag is not set and target has no karma
- if (targetPlayer.getPvpFlag() == 0 && targetPlayer.getKarma() == 0)
- {
- return false;
- }
- }
- }
- else if (isForcedPlayerOrPetSkill && (targetPlayer.getPvpFlag() != 0 || targetPlayer.getKarma() != 0))
- {
- final L2Party targetParty = targetPlayer.getParty();
- if (targetParty != null && getParty() == targetParty)
- {
- return true;
- }
- final L2Clan targetClan = targetPlayer.getClan();
- if (targetClan != null && getClan() != null)
- {
- if (getClan() == targetClan || (targetClan.getAllyId() != 0 && targetClan.getAllyId() == getClan().getAllyId()))
- {
- return true;
- }
- }
- return false;
- }
- }
- }
- return true;
- }
- /**
- * @return True if the L2PcInstance is a Mage (based on class templates).
- */
- public boolean isMageClass()
- {
- return getClassId().isMage();
- }
- public boolean isMounted()
- {
- return _mountType > 0;
- }
- /**
- * This method allows to :
- * <ul>
- * <li>change isRiding/isFlying flags</li>
- * <li>gift player with Wyvern Breath skill if mount is a wyvern</li>
- * <li>send the skillList (faded icons update)</li>
- * </ul>
- * @param npcId the npcId of the mount
- * @param npcLevel The level of the mount
- * @param mountType 0, 1 or 2 (dismount, strider or wyvern).
- * @return always true.
- */
- public boolean setMount(int npcId, int npcLevel, int mountType)
- {
- switch (mountType)
- {
- case 0: // Dismounted
- if (isFlying())
- {
- removeSkill(FrequentSkill.WYVERN_BREATH.getSkill());
- }
- break;
- case 2: // Flying Wyvern
- addSkill(FrequentSkill.WYVERN_BREATH.getSkill(), false); // not saved to DB
- break;
- }
- _mountNpcId = npcId;
- _mountType = mountType;
- _mountLevel = npcLevel;
- sendSkillList(); // Update faded icons && eventual added skills.
- return true;
- }
- @Override
- public boolean isRiding()
- {
- return _mountType == 1;
- }
- @Override
- public boolean isFlying()
- {
- return _mountType == 2;
- }
- /**
- * @return the type of Pet mounted (0 : none, 1 : Strider, 2 : Wyvern).
- */
- public int getMountType()
- {
- return _mountType;
- }
- @Override
- public final void stopAllEffects()
- {
- super.stopAllEffects();
- updateAndBroadcastStatus(2);
- }
- @Override
- public final void stopAllEffectsExceptThoseThatLastThroughDeath()
- {
- super.stopAllEffectsExceptThoseThatLastThroughDeath();
- updateAndBroadcastStatus(2);
- }
- /**
- * Stop all toggle-type effects
- */
- public final void stopAllToggles()
- {
- _effects.stopAllToggles();
- }
- public final void stopCubics()
- {
- if (getCubics() != null)
- {
- boolean removed = false;
- for (L2CubicInstance cubic : getCubics().values())
- {
- cubic.stopAction();
- delCubic(cubic.getId());
- removed = true;
- }
- if (removed)
- {
- broadcastUserInfo();
- }
- }
- }
- public final void stopCubicsByOthers()
- {
- if (getCubics() != null)
- {
- boolean removed = false;
- for (L2CubicInstance cubic : getCubics().values())
- {
- if (cubic.givenByOther())
- {
- cubic.stopAction();
- delCubic(cubic.getId());
- removed = true;
- }
- }
- if (removed)
- {
- broadcastUserInfo();
- }
- }
- }
- /**
- * Send UserInfo to this L2PcInstance and CharInfo to all L2PcInstance in its _KnownPlayers.<BR>
- * <ul>
- * <li>Send UserInfo to this L2PcInstance (Public and Private Data)</li>
- * <li>Send CharInfo to all L2PcInstance in _KnownPlayers of the L2PcInstance (Public data only)</li>
- * </ul>
- * <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>
- * <BR>
- */
- @Override
- public void updateAbnormalEffect()
- {
- broadcastUserInfo();
- }
- /**
- * Disable the Inventory and create a new task to enable it after 1.5s.
- */
- public void tempInventoryDisable()
- {
- _inventoryDisable = true;
- ThreadPoolManager.getInstance().scheduleGeneral(new InventoryEnable(), 1500);
- }
- /**
- * @return True if the Inventory is disabled.
- */
- public boolean isInventoryDisabled()
- {
- return _inventoryDisable;
- }
- protected class InventoryEnable implements Runnable
- {
- @Override
- public void run()
- {
- _inventoryDisable = false;
- }
- }
- public Map<Integer, L2CubicInstance> getCubics()
- {
- return _cubics;
- }
- /**
- * Add a L2CubicInstance to the L2PcInstance _cubics.
- * @param id
- * @param level
- * @param matk
- * @param activationtime
- * @param activationchance
- * @param totalLifetime
- * @param givenByOther
- */
- public void addCubic(int id, int level, double matk, int activationtime, int activationchance, int totalLifetime, boolean givenByOther)
- {
- _cubics.put(id, new L2CubicInstance(this, id, level, (int) matk, activationtime, activationchance, totalLifetime, givenByOther));
- }
- /**
- * Remove a L2CubicInstance from the L2PcInstance _cubics.
- * @param id
- */
- public void delCubic(int id)
- {
- _cubics.remove(id);
- }
- /**
- * @param id
- * @return the L2CubicInstance corresponding to the Identifier of the L2PcInstance _cubics.
- */
- public L2CubicInstance getCubic(int id)
- {
- return _cubics.get(id);
- }
- @Override
- public String toString()
- {
- return "player " + getName();
- }
- /**
- * @return the modifier corresponding to the Enchant Effect of the Active Weapon (Min : 127).
- */
- public int getEnchantEffect()
- {
- ItemInstance wpn = getActiveWeaponInstance();
- if (wpn == null)
- {
- return 0;
- }
- return Math.min(127, wpn.getEnchantLevel());
- }
- /**
- * Set the _currentFolkNpc of the player.
- * @param npc
- */
- public void setCurrentFolkNPC(L2Npc npc)
- {
- _currentFolkNpc = npc;
- }
- /**
- * @return the _currentFolkNpc of the player.
- */
- public L2Npc getCurrentFolkNPC()
- {
- return _currentFolkNpc;
- }
- /**
- * @return True if L2PcInstance is a participant in the Festival of Darkness.
- */
- public boolean isFestivalParticipant()
- {
- return SevenSignsFestival.getInstance().isParticipant(this);
- }
- public void addAutoSoulShot(int itemId)
- {
- _activeSoulShots.add(itemId);
- }
- public boolean removeAutoSoulShot(int itemId)
- {
- return _activeSoulShots.remove(itemId);
- }
- public Set<Integer> getAutoSoulShot()
- {
- return _activeSoulShots;
- }
- @Override
- public boolean isChargedShot(ShotType type)
- {
- ItemInstance weapon = getActiveWeaponInstance();
- return weapon != null && weapon.isChargedShot(type);
- }
- @Override
- public void setChargedShot(ShotType type, boolean charged)
- {
- ItemInstance weapon = getActiveWeaponInstance();
- if (weapon != null)
- {
- weapon.setChargedShot(type, charged);
- }
- }
- @Override
- public void rechargeShots(boolean physical, boolean magic)
- {
- if (_activeSoulShots == null || _activeSoulShots.isEmpty())
- {
- return;
- }
- for (int itemId : _activeSoulShots)
- {
- ItemInstance item = getInventory().getItemByItemId(itemId);
- if (item != null)
- {
- if (magic && item.getItem().getDefaultAction() == ActionType.spiritshot)
- {
- IItemHandler handler = ItemHandler.getInstance().getHandler(item.getEtcItem());
- if (handler != null)
- {
- handler.useItem(this, item, false);
- }
- }
- if (physical && item.getItem().getDefaultAction() == ActionType.soulshot)
- {
- IItemHandler handler = ItemHandler.getInstance().getHandler(item.getEtcItem());
- if (handler != null)
- {
- handler.useItem(this, item, false);
- }
- }
- }
- else
- {
- removeAutoSoulShot(itemId);
- }
- }
- }
- /**
- * Cancel autoshot use for shot itemId
- * @param itemId int id to disable
- * @return true if canceled.
- */
- public boolean disableAutoShot(int itemId)
- {
- if (_activeSoulShots.contains(itemId))
- {
- removeAutoSoulShot(itemId);
- sendPacket(new ExAutoSoulShot(itemId, 0));
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED).addItemName(itemId));
- return true;
- }
- return false;
- }
- /**
- * Cancel all autoshots for player
- */
- public void disableAutoShotsAll()
- {
- for (int itemId : _activeSoulShots)
- {
- sendPacket(new ExAutoSoulShot(itemId, 0));
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.AUTO_USE_OF_S1_CANCELLED).addItemName(itemId));
- }
- _activeSoulShots.clear();
- }
- class LookingForFishTask implements Runnable
- {
- boolean _isNoob, _isUpperGrade;
- int _fishType, _fishGutsCheck;
- long _endTaskTime;
- protected LookingForFishTask(int fishWaitTime, int fishGutsCheck, int fishType, boolean isNoob, boolean isUpperGrade)
- {
- _fishGutsCheck = fishGutsCheck;
- _endTaskTime = System.currentTimeMillis() + fishWaitTime + 10000;
- _fishType = fishType;
- _isNoob = isNoob;
- _isUpperGrade = isUpperGrade;
- }
- @Override
- public void run()
- {
- if (System.currentTimeMillis() >= _endTaskTime)
- {
- endFishing(false);
- return;
- }
- if (_fishType == -1)
- {
- return;
- }
- int check = Rnd.get(1000);
- if (_fishGutsCheck > check)
- {
- stopLookingForFishTask();
- startFishCombat(_isNoob, _isUpperGrade);
- }
- }
- }
- public int getClanPrivileges()
- {
- return _clanPrivileges;
- }
- public void setClanPrivileges(int n)
- {
- _clanPrivileges = n;
- }
- // baron etc
- public void setPledgeClass(int classId)
- {
- _pledgeClass = classId;
- }
- public int getPledgeClass()
- {
- return _pledgeClass;
- }
- public void setPledgeType(int typeId)
- {
- _pledgeType = typeId;
- }
- public int getPledgeType()
- {
- return _pledgeType;
- }
- public int getApprentice()
- {
- return _apprentice;
- }
- public void setApprentice(int apprentice_id)
- {
- _apprentice = apprentice_id;
- }
- public int getSponsor()
- {
- return _sponsor;
- }
- public void setSponsor(int sponsor_id)
- {
- _sponsor = sponsor_id;
- }
- @Override
- public void sendMessage(String message)
- {
- if (isGM())
- {
- sendChatMessage(message); // SYS: message
- }
- else
- {
- sendPacket(SystemMessage.sendString(message)); // System message
- }
- }
- public void sendChatMessage(String message)
- {
- sendPacket(new CreatureSay(0, Say2.ALL, "SYS", message));
- }
- public void sendCustomMessage(String address)
- {
- sendMessage(new CustomMessage(address, this).toString());
- }
- public void sendCustomMessage(String address, String[] replacements)
- {
- CustomMessage cm = new CustomMessage(address, this);
- if (replacements != null)
- {
- for (String s : replacements)
- {
- cm.addString(s);
- }
- }
- sendMessage(cm.toString());
- }
- /**
- * Unsummon all types of summons : pets, cubics, normal summons and trained beasts.
- */
- public void dropAllSummons()
- {
- // Delete summons and pets
- if (getPet() != null)
- {
- getPet().unSummon(this);
- }
- // Delete trained beasts
- if (getTrainedBeast() != null)
- {
- getTrainedBeast().deleteMe();
- }
- // Delete any form of cubics
- stopCubics();
- }
- public void enterObserverMode(int x, int y, int z)
- {
- _lastX = getX();
- _lastY = getY();
- _lastZ = getZ();
- _observerMode = true;
- standUp();
- dropAllSummons();
- setTarget(null);
- setIsParalyzed(true);
- startParalyze();
- setIsInvul(true);
- getAppearance().setInvisible();
- sendPacket(new ObservationMode(x, y, z));
- getKnownList().removeAllKnownObjects(); // reinit knownlist
- setXYZ(x, y, z);
- broadcastUserInfo();
- }
- public void setLastCords(int x, int y, int z)
- {
- _lastX = getX();
- _lastY = getY();
- _lastZ = getZ();
- }
- public void enterOlympiadObserverMode(int id)
- {
- final OlympiadGameTask task = OlympiadGameManager.getInstance().getOlympiadTask(id);
- if (task == null)
- {
- return;
- }
- dropAllSummons();
- if (getParty() != null)
- {
- getParty().removePartyMember(this, MessageType.Expelled);
- }
- _olympiadGameId = id;
- standUp();
- if (!_observerMode)
- {
- _lastX = getX();
- _lastY = getY();
- _lastZ = getZ();
- }
- _observerMode = true;
- setTarget(null);
- setIsInvul(true);
- getAppearance().setInvisible();
- teleToLocation(task.getZone().getSpawns().get(2), 0);
- sendPacket(new ExOlympiadMode(3));
- broadcastUserInfo();
- }
- public void leaveObserverMode()
- {
- setTarget(null);
- getKnownList().removeAllKnownObjects(); // reinit knownlist
- setXYZ(_lastX, _lastY, _lastZ);
- setIsParalyzed(false);
- stopParalyze(false);
- getAppearance().setVisible();
- setIsInvul(false);
- if (hasAI())
- {
- getAI().setIntention(CtrlIntention.IDLE);
- }
- // prevent receive falling damage
- setFalling();
- _observerMode = false;
- setLastCords(0, 0, 0);
- sendPacket(new ObservationReturn(this));
- broadcastUserInfo();
- }
- public void leaveOlympiadObserverMode()
- {
- if (_olympiadGameId == -1)
- {
- return;
- }
- _olympiadGameId = -1;
- _observerMode = false;
- setTarget(null);
- sendPacket(new ExOlympiadMode(0));
- teleToLocation(_lastX, _lastY, _lastZ, 20);
- getAppearance().setVisible();
- setIsInvul(false);
- if (hasAI())
- {
- getAI().setIntention(CtrlIntention.IDLE);
- }
- setLastCords(0, 0, 0);
- broadcastUserInfo();
- }
- public void setOlympiadSide(int i)
- {
- _olympiadSide = i;
- }
- public int getOlympiadSide()
- {
- return _olympiadSide;
- }
- public void setOlympiadGameId(int id)
- {
- _olympiadGameId = id;
- }
- public int getOlympiadGameId()
- {
- return _olympiadGameId;
- }
- public int getLastX()
- {
- return _lastX;
- }
- public int getLastY()
- {
- return _lastY;
- }
- public int getLastZ()
- {
- return _lastZ;
- }
- public boolean inObserverMode()
- {
- return _observerMode;
- }
- public int getTeleMode()
- {
- return _telemode;
- }
- public void setTeleMode(int mode)
- {
- _telemode = mode;
- }
- public void setLoto(int i, int val)
- {
- _loto[i] = val;
- }
- public int getLoto(int i)
- {
- return _loto[i];
- }
- public void setRace(int i, int val)
- {
- _race[i] = val;
- }
- public int getRace(int i)
- {
- return _race[i];
- }
- public boolean getRefusalMode()
- {
- try
- {
- return _characterData.getBool("messagerefusal");
- }
- catch (IllegalArgumentException e)
- {
- _characterData.set("messagerefusal", false);
- return false;
- }
- }
- public boolean isInRefusalMode()
- {
- return _messageRefusal;
- }
- public void setInRefusalMode(boolean mode)
- {
- _messageRefusal = mode;
- _characterData.set("messagerefusal", mode);
- sendPacket(new EtcStatusUpdate(this));
- }
- public void setTradeRefusal(boolean mode)
- {
- _characterData.set("traderefusal", mode);
- }
- public boolean getTradeRefusal()
- {
- try
- {
- return _characterData.getBool("traderefusal");
- }
- catch (IllegalArgumentException e)
- {
- _characterData.set("traderefusal", false);
- return false;
- }
- }
- public void setExchangeRefusal(boolean mode)
- {
- _exchangeRefusal = mode;
- }
- public boolean getExchangeRefusal()
- {
- return _exchangeRefusal;
- }
- public BlockList getBlockList()
- {
- return _blockList;
- }
- public void setHero(boolean hero)
- {
- if (hero && _baseClass == _activeClass)
- {
- for (L2Skill s : SkillTable.getHeroSkills())
- {
- addSkill(s, false); // Dont Save Hero skills to database
- }
- }
- else
- {
- for (L2Skill s : SkillTable.getHeroSkills())
- {
- super.removeSkill(s); // Just Remove skills from nonHero characters
- }
- }
- _hero = hero;
- sendSkillList();
- }
- public static void addHeroStatus(L2PcInstance player, int days)
- {
- if (player == null)
- {
- return;
- }
- Connection con = null;
- try
- {
- Calendar finishtime = Calendar.getInstance();
- finishtime.setTimeInMillis(System.currentTimeMillis());
- finishtime.set(Calendar.SECOND, 0);
- finishtime.add(Calendar.DAY_OF_MONTH, days);
- con = DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement = con.prepareStatement("UPDATE character_herolist SET enddate=? WHERE charId=?");
- statement.setLong(1, finishtime.getTimeInMillis());
- statement.setInt(2, player.getObjectId());
- statement.execute();
- statement.close();
- player.setHero(true);
- player.broadcastUserInfo();
- player.sendMessage("Вы получили статус героя");
- }
- catch (SQLException e)
- {
- _log.info("Set hero: Could not update data");
- }
- finally
- {
- try
- {
- if (con != null)
- {
- con.close();
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public void setIsInOlympiadMode(boolean b)
- {
- _inOlympiadMode = b;
- }
- public void setIsOlympiadStart(boolean b)
- {
- _OlympiadStart = b;
- }
- public boolean isOlympiadStart()
- {
- return _OlympiadStart;
- }
- public boolean isHero()
- {
- return _hero;
- }
- public boolean isInOlympiadMode()
- {
- return _inOlympiadMode;
- }
- public boolean isInDuel()
- {
- return _isInDuel;
- }
- public int getDuelId()
- {
- return _duelId;
- }
- public void setDuelState(int mode)
- {
- _duelState = mode;
- }
- public int getDuelState()
- {
- return _duelState;
- }
- /**
- * Sets up the duel state using a non 0 duelId.
- * @param duelId 0=not in a duel
- */
- public void setIsInDuel(int duelId)
- {
- if (duelId > 0)
- {
- _isInDuel = true;
- _duelState = Duel.DUELSTATE_DUELLING;
- _duelId = duelId;
- }
- else
- {
- if (_duelState == Duel.DUELSTATE_DEAD)
- {
- enableAllSkills();
- getStatus().startHpMpRegeneration();
- }
- _isInDuel = false;
- _duelState = Duel.DUELSTATE_NODUEL;
- _duelId = 0;
- }
- }
- /**
- * This returns a SystemMessage stating why the player is not available for duelling.
- * @return S1_CANNOT_DUEL... message
- */
- public SystemMessage getNoDuelReason()
- {
- SystemMessage sm = SystemMessage.getSystemMessage(_noDuelReason);
- sm.addPcName(this);
- _noDuelReason = SystemMessageId.THERE_IS_NO_OPPONENT_TO_RECEIVE_YOUR_CHALLENGE_FOR_A_DUEL;
- return sm;
- }
- /**
- * Checks if this player might join / start a duel. To get the reason use getNoDuelReason() after calling this function.
- * @return true if the player might join/start a duel.
- */
- public boolean canDuel()
- {
- if (isInCombat() || getPunishLevel() == PunishLevel.JAIL)
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_ENGAGED_IN_BATTLE;
- }
- else if (isDead() || isAlikeDead() || (getCurrentHp() < getMaxHp() / 2 || getCurrentMp() < getMaxMp() / 2))
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_HP_OR_MP_IS_BELOW_50_PERCENT;
- }
- else if (isInDuel())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_ALREADY_ENGAGED_IN_A_DUEL;
- }
- else if (isInOlympiadMode())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_PARTICIPATING_IN_THE_OLYMPIAD;
- }
- else if (isCursedWeaponEquipped())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_IN_A_CHAOTIC_STATE;
- }
- else if (isInStoreMode())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_ENGAGED_IN_A_PRIVATE_STORE_OR_MANUFACTURE;
- }
- else if (isMounted() || isInBoat())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_RIDING_A_BOAT_WYVERN_OR_STRIDER;
- }
- else if (isFishing())
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_DUEL_BECAUSE_S1_IS_CURRENTLY_FISHING;
- }
- else if (isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.PEACE) || isInsideZone(ZoneId.SIEGE))
- {
- _noDuelReason = SystemMessageId.S1_CANNOT_MAKE_A_CHALLANGE_TO_A_DUEL_BECAUSE_S1_IS_CURRENTLY_IN_A_DUEL_PROHIBITED_AREA;
- }
- else
- {
- return true;
- }
- return false;
- }
- public boolean isNoble()
- {
- return _noble;
- }
- /**
- * Set Noblesse Status, and reward with nobles' skills.
- * @param val Add skills if setted to true, else remove skills.
- * @param store Store the status directly in the db if setted to true.
- */
- public void setNoble(boolean val, boolean store)
- {
- if (val)
- {
- for (L2Skill s : SkillTable.getNobleSkills())
- {
- addSkill(s, false); // Dont Save Noble skills to Sql
- }
- }
- else
- {
- for (L2Skill s : SkillTable.getNobleSkills())
- {
- super.removeSkill(s); // Just Remove skills without deleting from Sql
- }
- }
- _noble = val;
- sendSkillList();
- if (store)
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(UPDATE_NOBLESS);
- statement.setBoolean(1, val);
- statement.setInt(2, getObjectId());
- statement.executeUpdate();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not update " + getName() + " nobless status: " + e.getMessage(), e);
- }
- }
- }
- public void setLvlJoinedAcademy(int lvl)
- {
- _lvlJoinedAcademy = lvl;
- }
- public int getLvlJoinedAcademy()
- {
- return _lvlJoinedAcademy;
- }
- public boolean isAcademyMember()
- {
- return _lvlJoinedAcademy > 0;
- }
- public void setTeam(int team)
- {
- _team = team;
- }
- public int getTeam()
- {
- return _team;
- }
- public void setWantsPeace(boolean wantsPeace)
- {
- _wantsPeace = wantsPeace;
- }
- public boolean wantsPeace()
- {
- return _wantsPeace;
- }
- public boolean isFishing()
- {
- return _fishingLoc != null;
- }
- public void setAllianceWithVarkaKetra(int sideAndLvlOfAlliance)
- {
- _alliedVarkaKetra = sideAndLvlOfAlliance;
- }
- /**
- * [-5,-1] varka, 0 neutral, [1,5] ketra
- * @return the side faction.
- */
- public int getAllianceWithVarkaKetra()
- {
- return _alliedVarkaKetra;
- }
- public boolean isAlliedWithVarka()
- {
- return (_alliedVarkaKetra < 0);
- }
- public boolean isAlliedWithKetra()
- {
- return (_alliedVarkaKetra > 0);
- }
- public void sendSkillList()
- {
- final ItemInstance formal = getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
- final boolean isWearingFormalWear = formal != null && formal.getItem().getBodyPart() == Item.SLOT_ALLDRESS;
- boolean isDisabled = false;
- SkillList sl = new SkillList();
- for (L2Skill s : getAllSkills())
- {
- if (s == null)
- {
- continue;
- }
- if (s.getId() > 9000 && s.getId() < 9007)
- {
- continue; // Fake skills to change base stats
- }
- if (getClan() != null)
- {
- isDisabled = s.isClanSkill() && getClan().getReputationScore() < 0;
- }
- if (isCursedWeaponEquipped())
- {
- isDisabled = !s.isDemonicSkill()
- && !(s.isMagic() && Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("mage"))
- && !(!s.isMagic() && Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("fighter"))
- && !Config.DEMONIC_SWORD_LEFT_SKILLS.equalsIgnoreCase("all")
- && !Arrays.asList(Config.DEMONIC_SWORD_CAST_SKILL_LIST).contains(s.getDisplayId());
- }
- else if (isMounted()) // else if, because only ONE state is possible
- {
- if (getMountType() == 1)
- {
- isDisabled = !s.isStriderSkill()
- && !(s.isMagic() && Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("mage"))
- && !(!s.isMagic() && Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("fighter"))
- && !Config.STRIDER_CAST_ALLOW.equalsIgnoreCase("all")
- && !Arrays.asList(Config.STRIDER_CAST_SKILL_LIST).contains(s.getDisplayId());
- }
- else if (getMountType() == 2)
- {
- isDisabled = !s.isFlyingSkill();
- }
- }
- if (isWearingFormalWear)
- {
- isDisabled = true;
- }
- sl.addSkill(s.getId(), s.getLevel(), s.isPassive(), isDisabled);
- }
- sendPacket(sl);
- }
- /**
- * 1. Add the specified class ID as a subclass (up to the maximum number of <b>three</b>) for this character.<BR>
- * 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.
- * @param classId
- * @param classIndex
- * @return boolean subclassAdded
- */
- public boolean addSubClass(int classId, int classIndex)
- {
- if (!_subclassLock.tryLock())
- {
- return false;
- }
- try
- {
- if (getTotalSubClasses() == Config.ALT_SUBCLASS_MAX_SUB_COUNT || classIndex == 0)
- {
- return false;
- }
- if (getSubClasses().containsKey(classIndex))
- {
- return false;
- }
- // Note: Never change _classIndex in any method other than setActiveClass().
- SubClass newClass = new SubClass();
- newClass.setClassId(classId);
- newClass.setClassIndex(classIndex);
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(ADD_CHAR_SUBCLASS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, newClass.getClassId());
- statement.setLong(3, newClass.getExp());
- statement.setInt(4, newClass.getSp());
- statement.setInt(5, newClass.getLevel());
- statement.setInt(6, newClass.getClassIndex()); // <-- Added
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("WARNING: Could not add character sub class for " + getName() + ": " + e);
- return false;
- }
- // Commit after database INSERT incase exception is thrown.
- getSubClasses().put(newClass.getClassIndex(), newClass);
- ClassId subTemplate = ClassId.values()[classId];
- Collection<L2SkillLearn> skillTree = SkillTreeTable.getInstance().getAllowedSkills(subTemplate);
- if (skillTree == null)
- {
- return true;
- }
- final Map<Integer, L2Skill> prevSkillList = new LinkedHashMap<>();
- for (L2SkillLearn skillInfo : skillTree)
- {
- if (skillInfo.getMinLevel() <= 40)
- {
- L2Skill prevSkill = prevSkillList.get(skillInfo.getId());
- L2Skill newSkill = SkillTable.getInstance().getInfo(skillInfo.getId(), skillInfo.getLevel());
- if (prevSkill != null && (prevSkill.getLevel() > newSkill.getLevel()))
- {
- continue;
- }
- prevSkillList.put(newSkill.getId(), newSkill);
- storeSkill(newSkill, prevSkill, classIndex);
- }
- }
- return true;
- }
- finally
- {
- _subclassLock.unlock();
- }
- }
- /**
- * 1. Completely erase all existance of the subClass linked to the classIndex.<BR>
- * 2. Send over the newClassId to addSubClass()to create a new instance on this classIndex.<BR>
- * 3. Upon Exception, revert the player to their BaseClass to avoid further problems.<BR>
- * @param classIndex
- * @param newClassId
- * @return boolean subclassAdded
- */
- public boolean modifySubClass(int classIndex, int newClassId)
- {
- if (!_subclassLock.tryLock())
- {
- return false;
- }
- try
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- // Remove all henna info stored for this sub-class.
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNAS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- // Remove all shortcuts info stored for this sub-class.
- statement = con.prepareStatement(DELETE_CHAR_SHORTCUTS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- // Remove all effects info stored for this sub-class.
- statement = con.prepareStatement(DELETE_SKILL_SAVE);
- statement.setInt(1, getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- // Remove all skill info stored for this sub-class.
- statement = con.prepareStatement(DELETE_CHAR_SKILLS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- // Remove all basic info stored about this sub-class.
- statement = con.prepareStatement(DELETE_CHAR_SUBCLASS);
- statement.setInt(1, getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Could not modify subclass for " + getName() + " to class index " + classIndex + ": " + e);
- // This must be done in order to maintain data consistency.
- getSubClasses().remove(classIndex);
- return false;
- }
- getSubClasses().remove(classIndex);
- }
- finally
- {
- _subclassLock.unlock();
- }
- return addSubClass(newClassId, classIndex);
- }
- public boolean isSubClassActive()
- {
- return _classIndex > 0;
- }
- public Map<Integer, SubClass> getSubClasses()
- {
- return _subClasses;
- }
- public int getTotalSubClasses()
- {
- return getSubClasses().size();
- }
- public int getBaseClass()
- {
- return _baseClass;
- }
- public int getActiveClass()
- {
- return _activeClass;
- }
- public int getClassIndex()
- {
- return _classIndex;
- }
- private void setClassTemplate(int classId)
- {
- _activeClass = classId;
- PcTemplate t = CharTemplateTable.getInstance().getTemplate(classId);
- if (t == null)
- {
- _log.error("Missing template for classId: " + classId);
- throw new Error();
- }
- // Set the template of the L2PcInstance
- setTemplate(t);
- }
- /**
- * Changes the character's class based on the given class index. <BR>
- * <BR>
- * An index of zero specifies the character's original (base) class, while indexes 1-3 specifies the character's sub-classes respectively.
- * @param classIndex
- * @return true if successful.
- */
- public boolean setActiveClass(int classIndex)
- {
- if (!_subclassLock.tryLock())
- {
- return false;
- }
- try
- {
- // Remove active item skills before saving char to database because next time when choosing this class, worn items can be different
- for (ItemInstance item : getInventory().getAugmentedItems())
- {
- if (item != null && item.isEquipped())
- {
- item.getAugmentation().removeBonus(this);
- }
- }
- // abort any kind of cast.
- abortCast();
- // Stop casting for any player that may be casting a force buff on this l2pcinstance.
- for (L2Character character : getKnownList().getKnownType(L2Character.class))
- {
- if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
- {
- character.abortCast();
- }
- }
- store();
- _reuseTimeStamps.clear();
- // clear charges
- _charges.set(0);
- stopChargeTask();
- if (classIndex == 0)
- {
- setClassTemplate(getBaseClass());
- }
- else
- {
- try
- {
- setClassTemplate(getSubClasses().get(classIndex).getClassId());
- }
- catch (Exception e)
- {
- _log.info("Could not switch " + getName() + "'s sub class to class index " + classIndex + ": " + e);
- return false;
- }
- }
- _classIndex = classIndex;
- if (isInParty())
- {
- getParty().recalculatePartyLevel();
- }
- if (getPet() instanceof L2SummonInstance)
- {
- getPet().unSummon(this);
- }
- for (L2Skill oldSkill : getAllSkills())
- {
- super.removeSkill(oldSkill);
- }
- stopAllEffectsExceptThoseThatLastThroughDeath();
- stopCubics();
- if (isSubClassActive())
- {
- _dwarvenRecipeBook.clear();
- _commonRecipeBook.clear();
- }
- else
- {
- restoreRecipeBook();
- }
- restoreSkills();
- rewardSkills();
- regiveTemporarySkills();
- // Prevents some issues when changing between subclases that shares skills
- if (_disabledSkills != null && !_disabledSkills.isEmpty())
- {
- _disabledSkills.clear();
- }
- restoreEffects();
- updateEffectIcons();
- sendPacket(new EtcStatusUpdate(this));
- // If player has quest "Repent Your Sins", remove it
- QuestState st = getQuestState("Q422_RepentYourSins");
- if (st != null)
- {
- st.exitQuest(true);
- }
- for (int i = 0; i < 3; i++)
- {
- _henna[i] = null;
- }
- restoreHenna();
- sendPacket(new HennaInfo(this));
- if (getCurrentHp() > getMaxHp())
- {
- setCurrentHp(getMaxHp());
- }
- if (getCurrentMp() > getMaxMp())
- {
- setCurrentMp(getMaxMp());
- }
- if (getCurrentCp() > getMaxCp())
- {
- setCurrentCp(getMaxCp());
- }
- refreshOverloaded();
- refreshExpertisePenalty();
- broadcastUserInfo();
- // Clear resurrect xp calculation
- setExpBeforeDeath(0);
- _shortCuts.restore();
- sendPacket(new ShortCutInit(this));
- broadcastPacket(new SocialAction(this, 15));
- sendPacket(new SkillCoolTime(this));
- return true;
- }
- finally
- {
- _subclassLock.unlock();
- }
- }
- public boolean isLocked()
- {
- return _subclassLock.isLocked();
- }
- public void stopWaterTask()
- {
- if (_isInWater)
- {
- _isInWater = false;
- sendPacket(new SetupGauge(2, 0));
- WaterTaskManager.getInstance().remove(this);
- }
- }
- public void startWaterTask()
- {
- if (!isDead() && !_isInWater)
- {
- _isInWater = true;
- final int time = (int) calcStat(Stats.BREATH, 60000 * getRace().getBreathMultiplier(), this, null);
- sendPacket(new SetupGauge(2, time));
- WaterTaskManager.getInstance().add(this, System.currentTimeMillis() + time);
- }
- }
- public void checkWaterState()
- {
- if (isInsideZone(ZoneId.WATER))
- {
- startWaterTask();
- }
- else
- {
- stopWaterTask();
- }
- }
- public void onPlayerEnter()
- {
- if (isCursedWeaponEquipped())
- {
- CursedWeaponsManager.getInstance().getCursedWeapon(getCursedWeaponEquippedId()).cursedOnLogin();
- }
- // Add a task for the "Take Break" message.
- TakeBreakTaskManager.getInstance().add(this);
- // Teleport player if the Seven Signs period isn't the good one, or if the player isn't in a cabal.
- if (isIn7sDungeon() && !isGM())
- {
- if (SevenSigns.getInstance().isSealValidationPeriod() || SevenSigns.getInstance().isCompResultsPeriod())
- {
- if (SevenSigns.getInstance().getPlayerCabal(getObjectId()) != SevenSigns.getInstance().getCabalHighestScore())
- {
- teleToLocation(MapRegionTable.TeleportWhereType.Town);
- setIsIn7sDungeon(false);
- }
- }
- else if (SevenSigns.getInstance().getPlayerCabal(getObjectId()) == SevenSigns.CABAL_NULL)
- {
- teleToLocation(MapRegionTable.TeleportWhereType.Town);
- setIsIn7sDungeon(false);
- }
- }
- // Jail task
- updatePunishState();
- if (isGM())
- {
- if (isInvul())
- {
- sendMessage("Entering world in Invulnerable mode.");
- }
- if (getAppearance().getInvisible())
- {
- sendMessage("Entering world in Invisible mode.");
- }
- if (isInRefusalMode())
- {
- sendMessage("Entering world in Message Refusal mode.");
- }
- }
- List<Premium> premiumItems = PremiumManager.getInstance().getPremiumItemsByOwner(getObjectId());
- if (!premiumItems.isEmpty())
- {
- for (Premium item : premiumItems)
- {
- ItemInstance itemInstance = getInventory().getItemByObjectId(item.getItemId());
- long timeLeft = item.getActivationTime() - (System.currentTimeMillis() / 1000); //in seconds
- int mins = (int) timeLeft / 60;
- int hours = mins / 60;
- if (itemInstance != null)
- {
- sendMessage(itemInstance.getItemName() + " time left: " + hours + " hours " + (mins % 60) + " minutes");
- }
- }
- }
- revalidateZone(true);
- notifyFriends(true);
- }
- public long getLastAccess()
- {
- return _lastAccess;
- }
- private void checkRecom(int recsHave, int recsLeft)
- {
- Calendar check = Calendar.getInstance();
- check.setTimeInMillis(_lastRecomUpdate);
- check.add(Calendar.DAY_OF_MONTH, 1);
- Calendar min = Calendar.getInstance();
- _recomHave = recsHave;
- _recomLeft = recsLeft;
- if (getStat().getLevel() < 10 || check.after(min))
- {
- return;
- }
- restartRecom();
- }
- public void restartRecom()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_RECOMS);
- statement.setInt(1, getObjectId());
- statement.execute();
- statement.close();
- _recomChars.clear();
- }
- catch (Exception e)
- {
- _log.warn("could not clear char recommendations: " + e);
- }
- if (getStat().getLevel() < 20)
- {
- _recomLeft = 3;
- _recomHave--;
- }
- else if (getStat().getLevel() < 40)
- {
- _recomLeft = 6;
- _recomHave -= 2;
- }
- else
- {
- _recomLeft = 9;
- _recomHave -= 3;
- }
- if (_recomHave < 0)
- {
- _recomHave = 0;
- }
- // If we have to update last update time, but it's now before 13, we should set it to yesterday
- Calendar update = Calendar.getInstance();
- if (update.get(Calendar.HOUR_OF_DAY) < 13)
- {
- update.add(Calendar.DAY_OF_MONTH, -1);
- }
- update.set(Calendar.HOUR_OF_DAY, 13);
- _lastRecomUpdate = update.getTimeInMillis();
- }
- @Override
- public void doRevive()
- {
- super.doRevive();
- stopEffects(L2EffectType.CHARMOFCOURAGE);
- sendPacket(new EtcStatusUpdate(this));
- _reviveRequested = 0;
- _revivePower = 0;
- if (isMounted())
- {
- startFeed(_mountNpcId);
- }
- if (isInParty() && getParty().isInDimensionalRift())
- {
- if (!DimensionalRiftManager.getInstance().checkIfInPeaceZone(getX(), getY(), getZ()))
- {
- getParty().getDimensionalRift().memberRessurected(this);
- }
- }
- if (isPassKey())
- {
- setIsPassKey(true);
- setIsImmobilized(true);
- }
- if (_event != null && _event.isRunning())
- {
- _event.onRevive(this);
- }
- }
- @Override
- public void doRevive(double revivePower)
- {
- // Restore the player's lost experience, depending on the % return of the skill used (based on its power).
- restoreExp(revivePower);
- doRevive();
- }
- public void reviveRequest(L2PcInstance Reviver, L2Skill skill, boolean Pet)
- {
- if (_reviveRequested == 1)
- {
- // Resurrection has already been proposed.
- if (_revivePet == Pet)
- {
- Reviver.sendPacket(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED);
- }
- else
- {
- if (Pet)
- {
- // A pet cannot be resurrected while it's owner is in the process of resurrecting.
- Reviver.sendPacket(SystemMessageId.CANNOT_RES_PET2);
- }
- else
- {
- // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
- Reviver.sendPacket(SystemMessageId.MASTER_CANNOT_RES);
- }
- }
- return;
- }
- if ((Pet && getPet() != null && getPet().isDead()) || (!Pet && isDead()))
- {
- _reviveRequested = 1;
- if (isPhoenixBlessed())
- {
- _revivePower = 100;
- }
- else if (isAffected(L2EffectFlag.CHARM_OF_COURAGE))
- {
- _revivePower = 0;
- }
- else
- {
- _revivePower = Formulas.calculateSkillResurrectRestorePercent(skill.getPower(), Reviver);
- }
- _revivePet = Pet;
- if (isAffected(L2EffectFlag.CHARM_OF_COURAGE))
- {
- sendPacket(new ConfirmDlg(SystemMessageId.DO_YOU_WANT_TO_BE_RESTORED).addTime(60000));
- return;
- }
- sendPacket(new ConfirmDlg(SystemMessageId.RESSURECTION_REQUEST_BY_S1).addPcName(Reviver));
- }
- }
- public void reviveAnswer(int answer)
- {
- if (_reviveRequested != 1 || (!isDead() && !_revivePet) || (_revivePet && getPet() != null && !getPet().isDead()))
- {
- return;
- }
- if (answer == 0 && isPhoenixBlessed())
- {
- stopPhoenixBlessing(null);
- }
- else if (answer == 1)
- {
- if (!_revivePet)
- {
- if (_revivePower != 0)
- {
- doRevive(_revivePower);
- }
- else
- {
- doRevive();
- }
- }
- else if (getPet() != null)
- {
- if (_revivePower != 0)
- {
- getPet().doRevive(_revivePower);
- }
- else
- {
- getPet().doRevive();
- }
- }
- }
- _reviveRequested = 0;
- _revivePower = 0;
- }
- public boolean isReviveRequested()
- {
- return (_reviveRequested == 1);
- }
- public boolean isRevivingPet()
- {
- return _revivePet;
- }
- public void removeReviving()
- {
- _reviveRequested = 0;
- _revivePower = 0;
- }
- public void onActionRequest()
- {
- if (isSpawnProtected())
- {
- sendMessage("As you acted, you are no longer under spawn protection.");
- setProtection(false);
- }
- }
- /**
- * @param expertiseIndex The expertiseIndex to set.
- */
- public void setExpertiseIndex(int expertiseIndex)
- {
- _expertiseIndex = expertiseIndex;
- }
- /**
- * @return Returns the expertiseIndex.
- */
- public int getExpertiseIndex()
- {
- return _expertiseIndex;
- }
- @Override
- public final void onTeleported()
- {
- super.onTeleported();
- // Force a revalidation
- revalidateZone(true);
- if (Config.PLAYER_SPAWN_PROTECTION > 0)
- {
- setProtection(true);
- }
- // Stop toggles upon teleport.
- if (!isGM())
- {
- stopAllToggles();
- }
- // Modify the position of the tamed beast if necessary
- if (getTrainedBeast() != null)
- {
- getTrainedBeast().getAI().stopFollow();
- getTrainedBeast().teleToLocation(getPosition().getX(), getPosition().getY(), getPosition().getZ(), 0);
- getTrainedBeast().getAI().startFollow(this);
- }
- // Modify the position of the pet if necessary
- L2Summon pet = getPet();
- if (pet != null)
- {
- pet.setFollowStatus(false);
- pet.teleToLocation(getPosition().getX(), getPosition().getY(), getPosition().getZ(), 0);
- ((L2SummonAI) pet.getAI()).setStartFollowController(true);
- pet.setFollowStatus(true);
- }
- }
- public void setLastServerPosition(int x, int y, int z)
- {
- _lastServerPosition.setXYZ(x, y, z);
- }
- public boolean checkLastServerPosition(int x, int y, int z)
- {
- return _lastServerPosition.equals(x, y, z);
- }
- public int getLastServerDistance(int x, int y, int z)
- {
- double dx = (x - _lastServerPosition.getX());
- double dy = (y - _lastServerPosition.getY());
- double dz = (z - _lastServerPosition.getZ());
- return (int) Math.sqrt(dx * dx + dy * dy + dz * dz);
- }
- @Override
- public void addExpAndSp(long addToExp, int addToSp)
- {
- getStat().addExpAndSp(addToExp, addToSp);
- }
- public void removeExpAndSp(long removeExp, int removeSp)
- {
- getStat().removeExpAndSp(removeExp, removeSp);
- }
- @Override
- public void reduceCurrentHp(double value, L2Character attacker, boolean awake, boolean isDOT, L2Skill skill)
- {
- if (skill != null)
- {
- getStatus().reduceHp(value, attacker, awake, isDOT, skill.isToggle(), skill.getDmgDirectlyToHP());
- }
- else
- {
- getStatus().reduceHp(value, attacker, awake, isDOT, false, false);
- }
- // notify the tamed beast of attacks
- if (getTrainedBeast() != null)
- {
- getTrainedBeast().onOwnerGotAttacked(attacker);
- }
- }
- /**
- * Test multiple cases where the item shouldn't be able to manipulate.
- * @param objectId : The item objectId.
- * @return true if it the item can be manipulated, false ovtherwise.
- */
- public boolean validateItemManipulation(int objectId)
- {
- final ItemInstance item = getInventory().getItemByObjectId(objectId);
- // You don't own the item, or item is null.
- if (item == null || item.getOwnerId() != getObjectId())
- {
- return false;
- }
- // Pet whom item you try to manipulate is summoned/mounted.
- if (getPet() != null && getPet().getControlItemId() == objectId || getMountObjectID() == objectId)
- {
- return false;
- }
- if (getActiveEnchantItem() != null && getActiveEnchantItem().getObjectId() == objectId)
- {
- return false;
- }
- // Can't trade a cursed weapon.
- if (CursedWeaponsManager.getInstance().isCursed(item.getItemId()))
- {
- return false;
- }
- return true;
- }
- /**
- * @return Returns the inBoat.
- */
- public boolean isInBoat()
- {
- return _vehicle != null && _vehicle.isBoat();
- }
- public L2BoatInstance getBoat()
- {
- return (L2BoatInstance) _vehicle;
- }
- public L2Vehicle getVehicle()
- {
- return _vehicle;
- }
- public void setVehicle(L2Vehicle v)
- {
- if (v == null && _vehicle != null)
- {
- _vehicle.removePassenger(this);
- }
- _vehicle = v;
- }
- public void setInCrystallize(boolean inCrystallize)
- {
- _inCrystallize = inCrystallize;
- }
- public boolean isInCrystallize()
- {
- return _inCrystallize;
- }
- public Point3D getInVehiclePosition()
- {
- return _inVehiclePosition;
- }
- public void setInVehiclePosition(Point3D pt)
- {
- _inVehiclePosition = pt;
- }
- /**
- * Manage the delete task of a L2PcInstance (Leave Party, Unsummon pet, Save its inventory in the database, Remove it from the world...).
- * <ul>
- * <li>If the L2PcInstance is in observer mode, set its position to its position before entering in observer mode</li>
- * <li>Set the online Flag to True or False and update the characters table of the database with online status and lastAccess</li>
- * <li>Stop the HP/MP/CP Regeneration task</li>
- * <li>Cancel Crafting, Attak or Cast</li>
- * <li>Remove the L2PcInstance from the world</li>
- * <li>Stop Party and Unsummon Pet</li>
- * <li>Update database with items in its inventory and remove them from the world</li>
- * <li>Remove all L2Object from _knownObjects and _knownPlayer of the L2Character then cancel Attak or Cast and notify AI</li>
- * <li>Close the connection with the client</li>
- * </ul>
- */
- @Override
- public void deleteMe()
- {
- cleanup();
- store();
- super.deleteMe();
- }
- private synchronized void cleanup()
- {
- try
- {
- // Put the online status to false
- setOnlineStatus(false, true);
- // abort cast & attack and remove the target. Cancels movement aswell.
- abortAttack();
- abortCast();
- stopMove(null);
- setTarget(null);
- PartyMatchWaitingList.getInstance().removePlayer(this);
- if (_partyroom != 0)
- {
- PartyMatchRoom room = PartyMatchRoomList.getInstance().getRoom(_partyroom);
- if (room != null)
- {
- room.deleteMember(this);
- }
- }
- if (isFlying())
- {
- removeSkill(SkillTable.getInstance().getInfo(4289, 1));
- }
- // Stop all scheduled tasks
- stopAllTimers();
- // Cancel the cast of eventual fusion skill users on this target.
- for (L2Character character : getKnownList().getKnownType(L2Character.class))
- {
- if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
- {
- character.abortCast();
- }
- }
- // Stop signets & toggles effects.
- for (L2Effect effect : getAllEffects())
- {
- if (effect.getSkill().isToggle())
- {
- effect.exit();
- continue;
- }
- switch (effect.getEffectType())
- {
- case SIGNET_GROUND:
- case SIGNET_EFFECT:
- effect.exit();
- break;
- }
- }
- // Remove the L2PcInstance from the world
- decayMe();
- // Remove from world regions zones
- L2WorldRegion oldRegion = getWorldRegion();
- if (oldRegion != null)
- {
- oldRegion.removeFromZones(this);
- }
- // If a party is in progress, leave it
- if (isInParty())
- {
- leaveParty();
- }
- // If the L2PcInstance has Pet, unsummon it
- if (getPet() != null)
- {
- getPet().unSummon(this);
- }
- // Handle removal from olympiad game
- if (OlympiadManager.getInstance().isRegistered(this) || getOlympiadGameId() != -1)
- {
- OlympiadManager.getInstance().removeDisconnectedCompetitor(this);
- }
- // set the status for pledge member list to OFFLINE
- if (getClan() != null)
- {
- L2ClanMember clanMember = getClan().getClanMember(getObjectId());
- if (clanMember != null)
- {
- clanMember.setPlayerInstance(null);
- }
- }
- // deals with sudden exit in the middle of transaction
- if (getActiveRequester() != null)
- {
- setActiveRequester(null);
- cancelActiveTrade();
- }
- // If the L2PcInstance is a GM, remove it from the GM List
- if (isGM())
- {
- GmListTable.getInstance().deleteGm(this);
- }
- // Check if the L2PcInstance is in observer mode to set its position to its position
- // before entering in observer mode
- if (inObserverMode())
- {
- setXYZInvisible(_lastX, _lastY, _lastZ);
- }
- // Oust player from boat
- if (getVehicle() != null)
- {
- getVehicle().oustPlayer(this);
- }
- // Update inventory and remove them from the world
- getInventory().deleteMe();
- // Update warehouse and remove them from the world
- clearWarehouse();
- // Update freight and remove them from the world
- clearFreight();
- clearDepositedFreight();
- if (isCursedWeaponEquipped())
- {
- CursedWeaponsManager.getInstance().getCursedWeapon(_cursedWeaponEquippedId).setPlayer(null);
- }
- // Remove all L2Object from _knownObjects and _knownPlayer of the L2Character then cancel Attak or Cast and notify AI
- getKnownList().removeAllKnownObjects();
- if (getClanId() > 0)
- {
- getClan().broadcastToOtherOnlineMembers(new PledgeShowMemberListUpdate(this), this);
- }
- // Remove L2Object object from _allObjects of L2World
- L2World.getInstance().removeObject(this);
- L2World.getInstance().removeFromAllPlayers(this); // force remove in case of crash during teleport
- // friends & blocklist update
- notifyFriends(false);
- getBlockList().playerLogout();
- }
- catch (Exception e)
- {
- _log.warn("Exception on deleteMe()" + e.getMessage(), e);
- }
- }
- public void startFishing(Location loc)
- {
- stopMove(null);
- setIsImmobilized(true);
- _fishingLoc = loc;
- // Starts fishing
- int group = getRandomGroup();
- _fish = FishTable.getFish(getRandomFishLvl(), getRandomFishType(group), group);
- if (_fish == null)
- {
- endFishing(false);
- return;
- }
- sendPacket(SystemMessageId.CAST_LINE_AND_START_FISHING);
- broadcastPacket(new ExFishingStart(this, _fish.getType(_lure.isNightLure()), loc, _lure.isNightLure()));
- sendPacket(new PlaySound(1, "SF_P_01", 0, 0, 0, 0, 0));
- startLookingForFishTask();
- }
- public void stopLookingForFishTask()
- {
- if (_taskforfish != null)
- {
- _taskforfish.cancel(false);
- _taskforfish = null;
- }
- }
- public void startLookingForFishTask()
- {
- if (!isDead() && _taskforfish == null)
- {
- int checkDelay = 0;
- boolean isNoob = false;
- boolean isUpperGrade = false;
- if (_lure != null)
- {
- int lureid = _lure.getItemId();
- isNoob = _fish.getGroup() == 0;
- isUpperGrade = _fish.getGroup() == 2;
- if (lureid == 6519 || lureid == 6522 || lureid == 6525 || lureid == 8505 || lureid == 8508 || lureid == 8511)
- {
- checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (1.33)));
- }
- else if (lureid == 6520 || lureid == 6523 || lureid == 6526 || (lureid >= 8505 && lureid <= 8513) || (lureid >= 7610 && lureid <= 7613) || (lureid >= 7807 && lureid <= 7809) || (lureid >= 8484 && lureid <= 8486))
- {
- checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (1.00)));
- }
- else if (lureid == 6521 || lureid == 6524 || lureid == 6527 || lureid == 8507 || lureid == 8510 || lureid == 8513)
- {
- checkDelay = Math.round((float) (_fish.getGutsCheckTime() * (0.66)));
- }
- }
- _taskforfish = ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(new LookingForFishTask(_fish.getWaitTime(), _fish.getFishGuts(), _fish.getType(_lure.isNightLure()), isNoob, isUpperGrade), 10000, checkDelay);
- }
- }
- private int getRandomGroup()
- {
- switch (_lure.getItemId())
- {
- case 7807: // green for beginners
- case 7808: // purple for beginners
- case 7809: // yellow for beginners
- case 8486: // prize-winning for beginners
- return 0;
- case 8485: // prize-winning luminous
- case 8506: // green luminous
- case 8509: // purple luminous
- case 8512: // yellow luminous
- return 2;
- default:
- return 1;
- }
- }
- private int getRandomFishType(int group)
- {
- int check = Rnd.get(100);
- int type = 1;
- switch (group)
- {
- case 0: // fish for novices
- switch (_lure.getItemId())
- {
- case 7807: // green lure, preferred by fast-moving (nimble) fish (type 5)
- if (check <= 54)
- {
- type = 5;
- }
- else if (check <= 77)
- {
- type = 4;
- }
- else
- {
- type = 6;
- }
- break;
- case 7808: // purple lure, preferred by fat fish (type 4)
- if (check <= 54)
- {
- type = 4;
- }
- else if (check <= 77)
- {
- type = 6;
- }
- else
- {
- type = 5;
- }
- break;
- case 7809: // yellow lure, preferred by ugly fish (type 6)
- if (check <= 54)
- {
- type = 6;
- }
- else if (check <= 77)
- {
- type = 5;
- }
- else
- {
- type = 4;
- }
- break;
- case 8486: // prize-winning fishing lure for beginners
- if (check <= 33)
- {
- type = 4;
- }
- else if (check <= 66)
- {
- type = 5;
- }
- else
- {
- type = 6;
- }
- break;
- }
- break;
- case 1: // normal fish
- switch (_lure.getItemId())
- {
- case 7610:
- case 7611:
- case 7612:
- case 7613:
- type = 3;
- break;
- case 6519: // all theese lures (green) are prefered by fast-moving (nimble) fish (type 1)
- case 8505:
- case 6520:
- case 6521:
- case 8507:
- if (check <= 54)
- {
- type = 1;
- }
- else if (check <= 74)
- {
- type = 0;
- }
- else if (check <= 94)
- {
- type = 2;
- }
- else
- {
- type = 3;
- }
- break;
- case 6522: // all theese lures (purple) are prefered by fat fish (type 0)
- case 8508:
- case 6523:
- case 6524:
- case 8510:
- if (check <= 54)
- {
- type = 0;
- }
- else if (check <= 74)
- {
- type = 1;
- }
- else if (check <= 94)
- {
- type = 2;
- }
- else
- {
- type = 3;
- }
- break;
- case 6525: // all theese lures (yellow) are prefered by ugly fish (type 2)
- case 8511:
- case 6526:
- case 6527:
- case 8513:
- if (check <= 55)
- {
- type = 2;
- }
- else if (check <= 74)
- {
- type = 1;
- }
- else if (check <= 94)
- {
- type = 0;
- }
- else
- {
- type = 3;
- }
- break;
- case 8484: // prize-winning fishing lure
- if (check <= 33)
- {
- type = 0;
- }
- else if (check <= 66)
- {
- type = 1;
- }
- else
- {
- type = 2;
- }
- break;
- }
- break;
- case 2: // upper grade fish, luminous lure
- switch (_lure.getItemId())
- {
- case 8506: // green lure, preferred by fast-moving (nimble) fish (type 8)
- if (check <= 54)
- {
- type = 8;
- }
- else if (check <= 77)
- {
- type = 7;
- }
- else
- {
- type = 9;
- }
- break;
- case 8509: // purple lure, preferred by fat fish (type 7)
- if (check <= 54)
- {
- type = 7;
- }
- else if (check <= 77)
- {
- type = 9;
- }
- else
- {
- type = 8;
- }
- break;
- case 8512: // yellow lure, preferred by ugly fish (type 9)
- if (check <= 54)
- {
- type = 9;
- }
- else if (check <= 77)
- {
- type = 8;
- }
- else
- {
- type = 7;
- }
- break;
- case 8485: // prize-winning fishing lure
- if (check <= 33)
- {
- type = 7;
- }
- else if (check <= 66)
- {
- type = 8;
- }
- else
- {
- type = 9;
- }
- break;
- }
- }
- return type;
- }
- private int getRandomFishLvl()
- {
- int skilllvl = getSkillLevel(1315);
- final L2Effect e = getFirstEffect(2274);
- if (e != null)
- {
- skilllvl = (int) e.getSkill().getPower();
- }
- if (skilllvl <= 0)
- {
- return 1;
- }
- int randomlvl;
- final int check = Rnd.get(100);
- if (check <= 50)
- {
- randomlvl = skilllvl;
- }
- else if (check <= 85)
- {
- randomlvl = skilllvl - 1;
- if (randomlvl <= 0)
- {
- randomlvl = 1;
- }
- }
- else
- {
- randomlvl = skilllvl + 1;
- if (randomlvl > 27)
- {
- randomlvl = 27;
- }
- }
- return randomlvl;
- }
- public void startFishCombat(boolean isNoob, boolean isUpperGrade)
- {
- _fishCombat = new L2Fishing(this, _fish, isNoob, isUpperGrade, _lure.getItemId());
- }
- public void endFishing(boolean win)
- {
- if (_fishCombat == null)
- {
- sendPacket(SystemMessageId.BAIT_LOST_FISH_GOT_AWAY);
- }
- else
- {
- _fishCombat = null;
- }
- _lure = null;
- _fishingLoc = null;
- // Ends fishing
- broadcastPacket(new ExFishingEnd(win, this));
- sendPacket(SystemMessageId.REEL_LINE_AND_STOP_FISHING);
- setIsImmobilized(false);
- stopLookingForFishTask();
- }
- public L2Fishing getFishCombat()
- {
- return _fishCombat;
- }
- public Location getFishingLoc()
- {
- return _fishingLoc;
- }
- public void setLure(ItemInstance lure)
- {
- _lure = lure;
- }
- public ItemInstance getLure()
- {
- return _lure;
- }
- public int getInventoryLimit()
- {
- return ((getRace() == Race.Dwarf) ? Config.INVENTORY_MAXIMUM_DWARF : Config.INVENTORY_MAXIMUM_NO_DWARF) + (int) getStat().calcStat(Stats.INV_LIM, 0, null, null);
- }
- public static int getQuestInventoryLimit()
- {
- return Config.INVENTORY_MAXIMUM_QUEST_ITEMS;
- }
- public int getWareHouseLimit()
- {
- return ((getRace() == Race.Dwarf) ? Config.WAREHOUSE_SLOTS_DWARF : Config.WAREHOUSE_SLOTS_NO_DWARF) + (int) getStat().calcStat(Stats.WH_LIM, 0, null, null);
- }
- public int getPrivateSellStoreLimit()
- {
- return ((getRace() == Race.Dwarf) ? Config.MAX_PVTSTORE_SLOTS_DWARF : Config.MAX_PVTSTORE_SLOTS_OTHER) + (int) getStat().calcStat(Stats.P_SELL_LIM, 0, null, null);
- }
- public int getPrivateBuyStoreLimit()
- {
- return ((getRace() == Race.Dwarf) ? Config.MAX_PVTSTORE_SLOTS_DWARF : Config.MAX_PVTSTORE_SLOTS_OTHER) + (int) getStat().calcStat(Stats.P_BUY_LIM, 0, null, null);
- }
- public int getFreightLimit()
- {
- return Config.FREIGHT_SLOTS + (int) getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null);
- }
- public int getDwarfRecipeLimit()
- {
- return Config.DWARF_RECIPE_LIMIT + (int) getStat().calcStat(Stats.REC_D_LIM, 0, null, null);
- }
- public int getCommonRecipeLimit()
- {
- return Config.COMMON_RECIPE_LIMIT + (int) getStat().calcStat(Stats.REC_C_LIM, 0, null, null);
- }
- public int getMountNpcId()
- {
- return _mountNpcId;
- }
- public int getMountLevel()
- {
- return _mountLevel;
- }
- public void setMountObjectID(int newID)
- {
- _mountObjectID = newID;
- }
- public int getMountObjectID()
- {
- return _mountObjectID;
- }
- /**
- * @return the current player skill in use.
- */
- public SkillUseHolder getCurrentSkill()
- {
- return _currentSkill;
- }
- /**
- * Update the _currentSkill holder.
- * @param skill : The skill to update for (or null)
- * @param ctrlPressed : The boolean information regarding ctrl key.
- * @param shiftPressed : The boolean information regarding shift key.
- */
- public void setCurrentSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
- {
- _currentSkill.setSkill(skill);
- _currentSkill.setCtrlPressed(ctrlPressed);
- _currentSkill.setShiftPressed(shiftPressed);
- }
- /**
- * @return the current pet skill in use.
- */
- public SkillUseHolder getCurrentPetSkill()
- {
- return _currentPetSkill;
- }
- /**
- * Update the _currentPetSkill holder.
- * @param skill : The skill to update for (or null)
- * @param ctrlPressed : The boolean information regarding ctrl key.
- * @param shiftPressed : The boolean information regarding shift key.
- */
- public void setCurrentPetSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
- {
- _currentPetSkill.setSkill(skill);
- _currentPetSkill.setCtrlPressed(ctrlPressed);
- _currentPetSkill.setShiftPressed(shiftPressed);
- }
- /**
- * @return the current queued skill in use.
- */
- public SkillUseHolder getQueuedSkill()
- {
- return _queuedSkill;
- }
- /**
- * Update the _queuedSkill holder.
- * @param skill : The skill to update for (or null)
- * @param ctrlPressed : The boolean information regarding ctrl key.
- * @param shiftPressed : The boolean information regarding shift key.
- */
- public void setQueuedSkill(L2Skill skill, boolean ctrlPressed, boolean shiftPressed)
- {
- _queuedSkill.setSkill(skill);
- _queuedSkill.setCtrlPressed(ctrlPressed);
- _queuedSkill.setShiftPressed(shiftPressed);
- }
- /**
- * @return the timer to delay animation tasks, based on run speed.
- */
- public int getAnimationTimer()
- {
- return Math.max(1000, 5000 - getRunSpeed() * 20);
- }
- /**
- * @return punishment level of player
- */
- public PunishLevel getPunishLevel()
- {
- return _punishLevel;
- }
- /**
- * @return True if player is jailed
- */
- public boolean isInJail()
- {
- return _punishLevel == PunishLevel.JAIL;
- }
- /**
- * @return True if player is chat banned
- */
- public boolean isChatBanned()
- {
- return _punishLevel == PunishLevel.CHAT;
- }
- public void setPunishLevel(int state)
- {
- switch (state)
- {
- case 0:
- _punishLevel = PunishLevel.NONE;
- break;
- case 1:
- _punishLevel = PunishLevel.CHAT;
- break;
- case 2:
- _punishLevel = PunishLevel.JAIL;
- break;
- case 3:
- _punishLevel = PunishLevel.CHAR;
- break;
- case 4:
- _punishLevel = PunishLevel.ACC;
- break;
- }
- }
- /**
- * Sets punish level for player based on delay
- * @param state
- * @param delayInMinutes -- 0 for infinite
- */
- public void setPunishLevel(PunishLevel state, int delayInMinutes)
- {
- long delayInMilliseconds = delayInMinutes * 60000L;
- switch (state)
- {
- case NONE: // Remove Punishments
- {
- switch (_punishLevel)
- {
- case CHAT:
- {
- _punishLevel = state;
- stopPunishTask(true);
- sendPacket(new EtcStatusUpdate(this));
- sendMessage("Chatting is now available.");
- sendPacket(new PlaySound("systemmsg_e.345"));
- break;
- }
- case JAIL:
- {
- _punishLevel = state;
- // Open a Html message to inform the player
- NpcHtmlMessage htmlMsg = new NpcHtmlMessage(0);
- htmlMsg.setFile("data/html/jail_out.htm");
- sendPacket(htmlMsg);
- stopPunishTask(true);
- teleToLocation(17836, 170178, -3507, 20); // Floran village
- break;
- }
- }
- break;
- }
- case CHAT: // Chat ban
- {
- // not allow player to escape jail using chat ban
- if (_punishLevel == PunishLevel.JAIL)
- {
- break;
- }
- _punishLevel = state;
- _punishTimer = 0;
- sendPacket(new EtcStatusUpdate(this));
- // Remove the task if any
- stopPunishTask(false);
- if (delayInMinutes > 0)
- {
- _punishTimer = delayInMilliseconds;
- // start the countdown
- _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(), _punishTimer);
- sendMessage("Chatting has been suspended for " + delayInMinutes + " minute(s).");
- }
- else
- {
- sendMessage("Chatting has been suspended.");
- }
- // Send same sound packet in both "delay" cases.
- sendPacket(new PlaySound("systemmsg_e.346"));
- break;
- }
- case JAIL: // Jail Player
- {
- if (_event != null)
- {
- _event.remove(this);
- }
- _punishLevel = state;
- _punishTimer = 0;
- // Remove the task if any
- stopPunishTask(false);
- if (delayInMinutes > 0)
- {
- _punishTimer = delayInMilliseconds;
- // start the countdown
- _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(), _punishTimer);
- sendMessage("You are jailed for " + delayInMinutes + " minutes.");
- }
- if (OlympiadManager.getInstance().isRegisteredInComp(this))
- {
- OlympiadManager.getInstance().removeDisconnectedCompetitor(this);
- }
- // Open a Html message to inform the player
- NpcHtmlMessage htmlMsg = new NpcHtmlMessage(0);
- htmlMsg.setFile("data/html/jail_in.htm");
- sendPacket(htmlMsg);
- setIsIn7sDungeon(false);
- teleToLocation(-114356, -249645, -2984, 0); // Jail
- break;
- }
- case CHAR: // Ban Character
- {
- setAccessLevel(-100);
- logout(false);
- break;
- }
- case ACC: // Ban Account
- {
- setAccountAccesslevel(-100);
- logout(false);
- break;
- }
- default:
- {
- _punishLevel = state;
- break;
- }
- }
- // store in database
- storeCharBase();
- }
- public long getPunishTimer()
- {
- return _punishTimer;
- }
- public void setPunishTimer(long time)
- {
- _punishTimer = time;
- }
- private void updatePunishState()
- {
- if (getPunishLevel() != PunishLevel.NONE)
- {
- // If punish timer exists, restart punishtask.
- if (_punishTimer > 0)
- {
- _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(), _punishTimer);
- sendMessage("You are still " + getPunishLevel().string() + " for " + Math.round(_punishTimer / 60000f) + " minutes.");
- }
- if (getPunishLevel() == PunishLevel.JAIL)
- {
- // If player escaped, put him back in jail
- if (!isInsideZone(ZoneId.JAIL))
- {
- teleToLocation(-114356, -249645, -2984, 20);
- }
- }
- }
- }
- public void stopPunishTask(boolean save)
- {
- if (_punishTask != null)
- {
- if (save)
- {
- long delay = _punishTask.getDelay(TimeUnit.MILLISECONDS);
- if (delay < 0)
- {
- delay = 0;
- }
- setPunishTimer(delay);
- }
- _punishTask.cancel(false);
- _punishTask = null;
- }
- }
- protected class PunishTask implements Runnable
- {
- @Override
- public void run()
- {
- setPunishLevel(PunishLevel.NONE, 0);
- }
- }
- public int getPowerGrade()
- {
- return _powerGrade;
- }
- public void setPowerGrade(int power)
- {
- _powerGrade = power;
- }
- public boolean isCursedWeaponEquipped()
- {
- return _cursedWeaponEquippedId != 0;
- }
- public void setCursedWeaponEquippedId(int value)
- {
- _cursedWeaponEquippedId = value;
- }
- public int getCursedWeaponEquippedId()
- {
- return _cursedWeaponEquippedId;
- }
- public void shortBuffStatusUpdate(int magicId, int level, int time)
- {
- if (_shortBuffTask != null)
- {
- _shortBuffTask.cancel(false);
- _shortBuffTask = null;
- }
- _shortBuffTask = ThreadPoolManager.getInstance().scheduleGeneral(new ShortBuffTask(), time * 1000);
- setShortBuffTaskSkillId(magicId);
- sendPacket(new ShortBuffStatusUpdate(magicId, level, time));
- }
- public int getShortBuffTaskSkillId()
- {
- return _shortBuffTaskSkillId;
- }
- public void setShortBuffTaskSkillId(int id)
- {
- _shortBuffTaskSkillId = id;
- }
- public int getDeathPenaltyBuffLevel()
- {
- return _deathPenaltyBuffLevel;
- }
- public void setDeathPenaltyBuffLevel(int level)
- {
- _deathPenaltyBuffLevel = level;
- }
- public void calculateDeathPenaltyBuffLevel(L2Character killer)
- {
- if (_deathPenaltyBuffLevel >= 15)
- {
- return;
- }
- if ((getKarma() > 0 || Rnd.get(1, 100) <= Config.DEATH_PENALTY_CHANCE) && !(killer instanceof L2PcInstance) && !isGM() && !(getCharmOfLuck() && (killer == null || killer.isRaid())) && !isPhoenixBlessed() && !(isInsideZone(ZoneId.PVP) || isInsideZone(ZoneId.SIEGE)) && !(_event != null && _event.isRunning()))
- {
- increaseDeathPenaltyBuffLevel(1);
- }
- }
- public void increaseDeathPenaltyBuffLevel(int count)
- {
- if (_deathPenaltyBuffLevel != 0)
- {
- final L2Skill skill = SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel);
- if (skill != null)
- {
- removeSkill(skill, true);
- }
- }
- _deathPenaltyBuffLevel += count;
- addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
- sendPacket(new EtcStatusUpdate(this));
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DEATH_PENALTY_LEVEL_S1_ADDED).addNumber(_deathPenaltyBuffLevel));
- }
- public void reduceDeathPenaltyBuffLevel()
- {
- if (_deathPenaltyBuffLevel <= 0)
- {
- return;
- }
- final L2Skill skill = SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel);
- if (skill != null)
- {
- removeSkill(skill, true);
- }
- _deathPenaltyBuffLevel--;
- if (_deathPenaltyBuffLevel > 0)
- {
- addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DEATH_PENALTY_LEVEL_S1_ADDED).addNumber(_deathPenaltyBuffLevel));
- }
- else
- {
- sendPacket(SystemMessageId.DEATH_PENALTY_LIFTED);
- }
- sendPacket(new EtcStatusUpdate(this));
- }
- public void restoreDeathPenaltyBuffLevel()
- {
- if (_deathPenaltyBuffLevel > 0)
- {
- addSkill(SkillTable.getInstance().getInfo(5076, _deathPenaltyBuffLevel), false);
- }
- }
- private final Map<Integer, TimeStamp> _reuseTimeStamps = new ConcurrentHashMap<>();
- public Map<Integer, TimeStamp> getReuseTimeStamp()
- {
- return _reuseTimeStamps;
- }
- /**
- * 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.
- * @author Yesod
- */
- public static class TimeStamp
- {
- private final int _skillId;
- private final int _skillLvl;
- private final long _reuse;
- private final long _stamp;
- public TimeStamp(L2Skill skill, long reuse)
- {
- _skillId = skill.getId();
- _skillLvl = skill.getLevel();
- _reuse = reuse;
- _stamp = System.currentTimeMillis() + reuse;
- }
- public TimeStamp(L2Skill skill, long reuse, long systime)
- {
- _skillId = skill.getId();
- _skillLvl = skill.getLevel();
- _reuse = reuse;
- _stamp = systime;
- }
- public long getStamp()
- {
- return _stamp;
- }
- public int getSkillId()
- {
- return _skillId;
- }
- public int getSkillLvl()
- {
- return _skillLvl;
- }
- public long getReuse()
- {
- return _reuse;
- }
- public long getRemaining()
- {
- return Math.max(_stamp - System.currentTimeMillis(), 0);
- }
- public boolean hasNotPassed()
- {
- return System.currentTimeMillis() < _stamp;
- }
- }
- /**
- * Index according to skill id the current timestamp of use.
- * @param skill
- * @param reuse delay
- */
- @Override
- public void addTimeStamp(L2Skill skill, long reuse)
- {
- _reuseTimeStamps.put(skill.getReuseHashCode(), new TimeStamp(skill, reuse));
- }
- /**
- * Index according to skill this TimeStamp instance for restoration purposes only.
- * @param skill
- * @param reuse
- * @param systime
- */
- public void addTimeStamp(L2Skill skill, long reuse, long systime)
- {
- _reuseTimeStamps.put(skill.getReuseHashCode(), new TimeStamp(skill, reuse, systime));
- }
- @Override
- public L2PcInstance getActingPlayer()
- {
- return this;
- }
- @Override
- public final void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
- {
- // Check if hit is missed
- if (miss)
- {
- sendPacket(SystemMessageId.MISSED_TARGET);
- return;
- }
- // Check if hit is critical
- if (pcrit)
- {
- sendPacket(SystemMessageId.CRITICAL_HIT);
- }
- if (mcrit)
- {
- sendPacket(SystemMessageId.CRITICAL_HIT_MAGIC);
- }
- if (target.isInvul())
- {
- if (target.isParalyzed())
- {
- sendPacket(SystemMessageId.OPPONENT_PETRIFIED);
- }
- else
- {
- sendPacket(SystemMessageId.ATTACK_WAS_BLOCKED);
- }
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DID_S1_DMG).addNumber(damage));
- }
- if (isInOlympiadMode() && target instanceof L2PcInstance && ((L2PcInstance) target).isInOlympiadMode() && ((L2PcInstance) target).getOlympiadGameId() == getOlympiadGameId())
- {
- OlympiadGameManager.getInstance().notifyCompetitorDamage(this, damage);
- }
- }
- public void checkItemRestriction()
- {
- for (int i = 0; i < Inventory.PAPERDOLL_TOTALSLOTS; i++)
- {
- ItemInstance equippedItem = getInventory().getPaperdollItem(i);
- if (equippedItem != null && !equippedItem.getItem().checkCondition(this, this, false))
- {
- getInventory().unEquipItemInSlot(i);
- InventoryUpdate iu = new InventoryUpdate();
- iu.addModifiedItem(equippedItem);
- sendPacket(iu);
- SystemMessage sm = null;
- if (equippedItem.getEnchantLevel() > 0)
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
- sm.addNumber(equippedItem.getEnchantLevel());
- sm.addItemName(equippedItem);
- }
- else
- {
- sm = SystemMessage.getSystemMessage(SystemMessageId.S1_DISARMED);
- sm.addItemName(equippedItem);
- }
- sendPacket(sm);
- }
- }
- }
- protected class Dismount implements Runnable
- {
- @Override
- public void run()
- {
- try
- {
- dismount();
- }
- catch (Exception e)
- {
- _log.warn("Exception on dismount(): " + e.getMessage(), e);
- }
- }
- }
- public void enteredNoLanding(int delay)
- {
- _dismountTask = ThreadPoolManager.getInstance().scheduleGeneral(new Dismount(), delay * 1000);
- }
- public void exitedNoLanding()
- {
- if (_dismountTask != null)
- {
- _dismountTask.cancel(true);
- _dismountTask = null;
- }
- }
- public void setIsInSiege(boolean b)
- {
- _isInSiege = b;
- }
- public boolean isInSiege()
- {
- return _isInSiege;
- }
- public FloodProtectors getFloodProtectors()
- {
- return getClient().getFloodProtectors();
- }
- /**
- * Remove player from BossZones (used on char logout/exit)
- */
- public void removeFromBossZone()
- {
- try
- {
- for (L2BossZone _zone : GrandBossManager.getInstance().getZones())
- {
- _zone.removePlayer(this);
- }
- }
- catch (Exception e)
- {
- _log.warn("Exception on removeFromBossZone(): " + e.getMessage(), e);
- }
- }
- /**
- * @return the number of charges this L2PcInstance got.
- */
- public int getCharges()
- {
- return _charges.get();
- }
- public void increaseCharges(int count, int max)
- {
- if (_charges.get() >= max)
- {
- sendPacket(SystemMessageId.FORCE_MAXLEVEL_REACHED);
- return;
- }
- restartChargeTask();
- if (_charges.addAndGet(count) >= max)
- {
- _charges.set(max);
- sendPacket(SystemMessageId.FORCE_MAXLEVEL_REACHED);
- }
- else
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FORCE_INCREASED_TO_S1).addNumber(_charges.get()));
- }
- sendPacket(new EtcStatusUpdate(this));
- }
- public boolean decreaseCharges(int count)
- {
- if (_charges.get() < count)
- {
- return false;
- }
- if (_charges.addAndGet(-count) == 0)
- {
- stopChargeTask();
- }
- else
- {
- restartChargeTask();
- }
- sendPacket(new EtcStatusUpdate(this));
- return true;
- }
- public void clearCharges()
- {
- _charges.set(0);
- sendPacket(new EtcStatusUpdate(this));
- }
- /**
- * Starts/Restarts the ChargeTask to Clear Charges after 10 Mins.
- */
- private void restartChargeTask()
- {
- if (_chargeTask != null)
- {
- _chargeTask.cancel(false);
- _chargeTask = null;
- }
- _chargeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChargeTask(), 600000);
- }
- /**
- * Stops the Charges Clearing Task.
- */
- public void stopChargeTask()
- {
- if (_chargeTask != null)
- {
- _chargeTask.cancel(false);
- _chargeTask = null;
- }
- }
- protected class ChargeTask implements Runnable
- {
- @Override
- public void run()
- {
- clearCharges();
- }
- }
- /**
- * Signets check used to valid who is affected when he entered in the aoe effect.
- * @param cha The target to make checks on.
- * @return true if player can attack the target.
- */
- public boolean canAttackCharacter(L2Character cha)
- {
- if (cha instanceof L2Attackable)
- {
- return true;
- }
- if (cha instanceof L2Playable)
- {
- if (cha.isInArena())
- {
- return true;
- }
- final L2PcInstance target = cha.getActingPlayer();
- if (isInDuel() && target.isInDuel() && target.getDuelId() == getDuelId())
- {
- return true;
- }
- if (isInParty() && target.isInParty())
- {
- if (getParty() == target.getParty())
- {
- return false;
- }
- if ((getParty().getCommandChannel() != null || target.getParty().getCommandChannel() != null) && (getParty().getCommandChannel() == target.getParty().getCommandChannel()))
- {
- return false;
- }
- }
- if (getClan() != null && target.getClan() != null)
- {
- if (getClanId() == target.getClanId())
- {
- return false;
- }
- if ((getAllyId() > 0 || target.getAllyId() > 0) && getAllyId() == target.getAllyId())
- {
- return false;
- }
- if (getClan().isAtWarWith(target.getClanId()))
- {
- return true;
- }
- }
- else
- {
- if (target.getPvpFlag() == 0 && target.getKarma() == 0)
- {
- return false;
- }
- }
- }
- return true;
- }
- /**
- * Request Teleport
- * @param requester The player who requested the teleport.
- * @param skill The used skill.
- * @return true if successful.
- **/
- public boolean teleportRequest(L2PcInstance requester, L2Skill skill)
- {
- if (_summonRequest.getTarget() != null && requester != null)
- {
- return false;
- }
- _summonRequest.setTarget(requester, skill);
- return true;
- }
- /**
- * Action teleport
- * @param answer
- * @param requesterId
- **/
- public void teleportAnswer(int answer, int requesterId)
- {
- if (_summonRequest.getTarget() == null)
- {
- return;
- }
- if (answer == 1 && _summonRequest.getTarget().getObjectId() == requesterId)
- {
- teleToTarget(this, _summonRequest.getTarget(), _summonRequest.getSkill());
- }
- _summonRequest.setTarget(null, null);
- }
- public static void teleToTarget(L2PcInstance targetChar, L2PcInstance summonerChar, L2Skill summonSkill)
- {
- if (targetChar == null || summonerChar == null || summonSkill == null)
- {
- return;
- }
- if (!checkSummonerStatus(summonerChar))
- {
- return;
- }
- if (!checkSummonTargetStatus(targetChar, summonerChar))
- {
- return;
- }
- int itemConsumeId = summonSkill.getTargetConsumeId();
- int itemConsumeCount = summonSkill.getTargetConsume();
- if (itemConsumeId != 0 && itemConsumeCount != 0)
- {
- // Delete by rocknow
- if (targetChar.getInventory().getInventoryItemCount(itemConsumeId, 0) < itemConsumeCount)
- {
- targetChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_REQUIRED_FOR_SUMMONING).addItemName(summonSkill.getTargetConsumeId()));
- return;
- }
- targetChar.getInventory().destroyItemByItemId("Consume", itemConsumeId, itemConsumeCount, summonerChar, targetChar);
- targetChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_DISAPPEARED).addItemName(summonSkill.getTargetConsumeId()));
- }
- targetChar.teleToLocation(summonerChar.getX(), summonerChar.getY(), summonerChar.getZ(), 20);
- }
- public static boolean checkSummonerStatus(L2PcInstance summonerChar)
- {
- if (summonerChar == null)
- {
- return false;
- }
- if (summonerChar.isInOlympiadMode() || summonerChar.inObserverMode() || summonerChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND) || summonerChar.isMounted())
- {
- return false;
- }
- return true;
- }
- public static boolean checkSummonTargetStatus(L2Object target, L2PcInstance summonerChar)
- {
- if (target == null || !(target instanceof L2PcInstance))
- {
- return false;
- }
- L2PcInstance targetChar = (L2PcInstance) target;
- if (targetChar.isAlikeDead())
- {
- summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_DEAD_AT_THE_MOMENT_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
- return false;
- }
- if (targetChar.isInStoreMode())
- {
- summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CURRENTLY_TRADING_OR_OPERATING_PRIVATE_STORE_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
- return false;
- }
- if (targetChar.isRooted() || targetChar.isInCombat() || targetChar.isInDuel())
- {
- summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IS_ENGAGED_IN_COMBAT_AND_CANNOT_BE_SUMMONED).addPcName(targetChar));
- return false;
- }
- if (targetChar.isInOlympiadMode())
- {
- summonerChar.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_PLAYERS_WHO_ARE_IN_OLYMPIAD);
- return false;
- }
- if (targetChar.getEvent() != null && targetChar.getEvent().isRunning() && !targetChar.getEvent().canLogout(targetChar))
- {
- return false;
- }
- if (targetChar.isFestivalParticipant() || targetChar.isMounted())
- {
- summonerChar.sendPacket(SystemMessageId.YOUR_TARGET_IS_IN_AN_AREA_WHICH_BLOCKS_SUMMONING);
- return false;
- }
- if (targetChar.inObserverMode() || targetChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
- {
- summonerChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_IN_SUMMON_BLOCKING_AREA).addCharName(targetChar));
- return false;
- }
- return true;
- }
- public final int getClientX()
- {
- return _clientX;
- }
- public final int getClientY()
- {
- return _clientY;
- }
- public final int getClientZ()
- {
- return _clientZ;
- }
- public final int getClientHeading()
- {
- return _clientHeading;
- }
- public final void setClientX(int val)
- {
- _clientX = val;
- }
- public final void setClientY(int val)
- {
- _clientY = val;
- }
- public final void setClientZ(int val)
- {
- _clientZ = val;
- }
- public final void setClientHeading(int val)
- {
- _clientHeading = val;
- }
- /**
- * @return the mailPosition.
- */
- public int getMailPosition()
- {
- return _mailPosition;
- }
- /**
- * @param mailPosition The mailPosition to set.
- */
- public void setMailPosition(int mailPosition)
- {
- _mailPosition = mailPosition;
- }
- /**
- * @param z
- * @return true if character falling now On the start of fall return false for correct coord sync !
- */
- public final boolean isFalling(int z)
- {
- if (isDead() || isFlying() || isInsideZone(ZoneId.WATER))
- {
- return false;
- }
- if (System.currentTimeMillis() < _fallingTimestamp)
- {
- return true;
- }
- final int deltaZ = getZ() - z;
- if (deltaZ <= getBaseTemplate().getFallHeight())
- {
- return false;
- }
- final int damage = (int) Formulas.calcFallDam(this, deltaZ);
- if (damage > 0 && !(_event != null && _event.isRunning()))
- {
- reduceCurrentHp(Math.min(damage, getCurrentHp() - 1), null, false, true, null);
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FALL_DAMAGE_S1).addNumber(damage));
- }
- setFalling();
- return false;
- }
- /**
- * Set falling timestamp
- */
- public final void setFalling()
- {
- _fallingTimestamp = System.currentTimeMillis() + FALLING_VALIDATION_DELAY;
- }
- public boolean isAllowedToEnchantSkills()
- {
- if (isLocked())
- {
- return false;
- }
- if (AttackStanceTaskManager.getInstance().get(this))
- {
- return false;
- }
- if (isCastingNow() || isCastingSimultaneouslyNow())
- {
- return false;
- }
- if (isInBoat())
- {
- return false;
- }
- return true;
- }
- /**
- * Friendlist / selected Friendlist (for community board)
- */
- private final List<Integer> _friendList = new ArrayList<>();
- private final List<Integer> _selectedFriendList = new ArrayList<>();
- public List<Integer> getFriendList()
- {
- return _friendList;
- }
- public void selectFriend(Integer friendId)
- {
- if (!_selectedFriendList.contains(friendId))
- {
- _selectedFriendList.add(friendId);
- }
- }
- public void deselectFriend(Integer friendId)
- {
- if (_selectedFriendList.contains(friendId))
- {
- _selectedFriendList.remove(friendId);
- }
- }
- public List<Integer> getSelectedFriendList()
- {
- return _selectedFriendList;
- }
- private void restoreFriendList()
- {
- _friendList.clear();
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement statement = con.prepareStatement("SELECT friend_id FROM character_friends WHERE char_id = ? AND relation = 0");
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- int friendId;
- while (rset.next())
- {
- friendId = rset.getInt("friend_id");
- if (friendId == getObjectId())
- {
- continue;
- }
- _friendList.add(friendId);
- }
- rset.close();
- statement.close();
- }
- catch (Exception e)
- {
- _log.warn("Error found in " + getName() + "'s friendlist: " + e.getMessage(), e);
- }
- }
- private void notifyFriends(boolean login)
- {
- for (int id : _friendList)
- {
- L2PcInstance friend = L2World.getInstance().getPlayer(id);
- if (friend != null)
- {
- friend.sendPacket(new FriendList(friend));
- if (login)
- {
- friend.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FRIEND_S1_HAS_LOGGED_IN).addPcName(this));
- }
- }
- }
- }
- private final List<Integer> _selectedBlocksList = new ArrayList<>();
- public void selectBlock(Integer friendId)
- {
- if (!_selectedBlocksList.contains(friendId))
- {
- _selectedBlocksList.add(friendId);
- }
- }
- public void deselectBlock(Integer friendId)
- {
- if (_selectedBlocksList.contains(friendId))
- {
- _selectedBlocksList.remove(friendId);
- }
- }
- public List<Integer> getSelectedBlocksList()
- {
- return _selectedBlocksList;
- }
- /**
- * Test if player inventory is under 80% capaity
- * @param includeQuestInv check also quest inventory
- * @return
- */
- public boolean isInventoryUnder80(boolean includeQuestInv)
- {
- if (getInventory().getSize(false) <= (getInventoryLimit() * 0.8))
- {
- if (includeQuestInv)
- {
- if (getInventory().getSize(true) <= (getQuestInventoryLimit() * 0.8))
- {
- return true;
- }
- }
- else
- {
- return true;
- }
- }
- return false;
- }
- @Override
- public void broadcastRelationsChanges()
- {
- for (L2PcInstance player : getKnownList().getKnownType(L2PcInstance.class))
- {
- player.sendPacket(new RelationChanged(this, getRelation(player), isAutoAttackable(player)));
- if (getPet() != null)
- {
- player.sendPacket(new RelationChanged(getPet(), getRelation(player), isAutoAttackable(player)));
- }
- }
- }
- @Override
- public void sendInfo(L2PcInstance activeChar)
- {
- if (isInBoat())
- {
- getPosition().setWorldPosition(getBoat().getPosition().getWorldPosition());
- }
- if (getPoly().isMorphed())
- {
- activeChar.sendPacket(new AbstractNpcInfo.PcMorphInfo(this, getPoly().getNpcTemplate()));
- }
- else
- {
- activeChar.sendPacket(new CharInfo(this));
- }
- final int relation1 = getRelation(activeChar);
- activeChar.sendPacket(new RelationChanged(this, relation1, isAutoAttackable(activeChar)));
- if (getPet() != null)
- {
- activeChar.sendPacket(new RelationChanged(getPet(), relation1, isAutoAttackable(activeChar)));
- }
- final int relation2 = activeChar.getRelation(this);
- sendPacket(new RelationChanged(activeChar, relation2, activeChar.isAutoAttackable(this)));
- if (activeChar.getPet() != null)
- {
- sendPacket(new RelationChanged(activeChar.getPet(), relation2, activeChar.isAutoAttackable(this)));
- }
- if (isInBoat())
- {
- activeChar.sendPacket(new GetOnVehicle(getObjectId(), getBoat().getObjectId(), getInVehiclePosition()));
- }
- // No reason to try to broadcast shop message if player isn't in store mode
- if (isInStoreMode())
- {
- switch (getPrivateStoreType())
- {
- case STORE_PRIVATE_SELL:
- case STORE_PRIVATE_PACKAGE_SELL:
- activeChar.sendPacket(new PrivateStoreMsgSell(this));
- break;
- case STORE_PRIVATE_BUY:
- activeChar.sendPacket(new PrivateStoreMsgBuy(this));
- break;
- case STORE_PRIVATE_MANUFACTURE:
- activeChar.sendPacket(new RecipeShopMsg(this));
- break;
- }
- }
- }
- public long getOfflineStartTime()
- {
- return _offlineShopStart;
- }
- public void setOfflineStartTime(long time)
- {
- _offlineShopStart = time;
- }
- public void setStopExp(boolean mode)
- {
- _characterData.set("stopexp", mode);
- }
- public boolean getStopExp()
- {
- try
- {
- return _characterData.getBool("stopexp");
- }
- catch (IllegalArgumentException e)
- {
- _characterData.set("stopexp", false);
- return false;
- }
- }
- public void setAutoLoot(boolean var)
- {
- _characterData.set("autoloot", var);
- }
- public boolean isAutoLoot()
- {
- try
- {
- return _characterData.getBool("autoloot");
- }
- catch (IllegalArgumentException e)
- {
- _characterData.set("autoloot", Config.AUTO_LOOT);
- return Config.AUTO_LOOT;
- }
- }
- public int getPcBangScore()
- {
- return pcBangPoint;
- }
- public void reducePcBangScore(int to)
- {
- pcBangPoint -= to;
- updatePcBangWnd(to, false, false);
- }
- public void addPcBangScore(int to)
- {
- pcBangPoint += to;
- }
- public void updatePcBangWnd(int score, boolean add, boolean duble)
- {
- ExPCCafePointInfo wnd = new ExPCCafePointInfo(getPcBangScore(), score, add, 24, duble);
- sendPacket(wnd);
- }
- public void showPcBangWindow()
- {
- ExPCCafePointInfo wnd = new ExPCCafePointInfo(getPcBangScore(), 0, false, 24, false);
- sendPacket(wnd);
- }
- public void loadSetting(Connection con)
- {
- try
- {
- PreparedStatement stm = con.prepareStatement(LOAD_CHAR_DATA);
- stm.setInt(1, getObjectId());
- ResultSet rs = stm.executeQuery();
- while (rs.next())
- {
- _characterData.set(rs.getString(1), rs.getString(2));
- }
- rs.close();
- stm.close();
- }
- catch (Exception e)
- {
- _log.info("Error on loading character data " + e);
- }
- }
- public void saveSettingInDb()
- {
- Connection con = null;
- try
- {
- con = DatabaseFactory.getInstance().getConnection();
- PreparedStatement statement = con.prepareStatement(STORE_CHAR_DATA);
- statement.setInt(2, getObjectId());
- PreparedStatement insert = con.prepareStatement(CREATE_CHAR_DATA);
- insert.setInt(1, getObjectId());
- for (String s : _characterData.getSet().keySet())
- {
- try
- {
- statement.setString(1, _characterData.getString(s));
- }
- catch (IllegalArgumentException e)
- {
- statement.setString(1, "");
- }
- statement.setString(3, s);
- if (statement.executeUpdate() == 0)
- {
- insert.setString(2, s);
- try
- {
- insert.setString(3, _characterData.getString(s));
- }
- catch (IllegalArgumentException e)
- {
- insert.setString(3, "");
- }
- insert.execute();
- }
- }
- insert.close();
- statement.close();
- con.close();
- }
- catch (Exception ex)
- {
- _log.info("Error on character data saving to DB " + ex);
- }
- }
- public StatsSet getCharacterData()
- {
- return _characterData;
- }
- /**
- * restore for CharSettings parametrs
- */
- public void restoreCharSettings()
- {
- _log.debug("restoring character status from database...");
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- int hero = 0;
- long hero_end = 0;
- PreparedStatement statement = con.prepareStatement(CHAR_SETTINGS);
- statement.setInt(1, getObjectId());
- ResultSet rset = statement.executeQuery();
- while (rset.next())
- {
- hero = rset.getInt("hero");
- hero_end = rset.getLong("hero_end_date");
- }
- rset.close();
- statement.close();
- statement = null;
- rset = null;
- if (hero > 0 && (hero_end == 0 || hero_end > System.currentTimeMillis()))
- {
- setHero(true);
- }
- }
- catch (Exception e)
- {
- _log.warn("Error: could not restore char_mods data info: " + e);
- }
- }
- public String getHWid()
- {
- if (getClient() == null)
- {
- return _hwid;
- }
- _hwid = getClient().getHWid();
- return _hwid;
- }
- public String getLastHwId()
- {
- return _hwid;
- }
- @Override
- public void onActionShift(L2PcInstance player)
- {
- if (player.isGM())
- {
- IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler("admin_character_info");
- ach.useAdminCommand("admin_character_info " + getName(), player);
- }
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- public synchronized void addToPvpKilledList(int objId, long time)
- {
- _pvpKilledList.put(objId, time);
- }
- public synchronized boolean containsInPvpKilledList(int objId)
- {
- return _pvpKilledList.containsKey(objId);
- }
- public synchronized long getPvpKilledListValue(int objId)
- {
- if (_pvpKilledList.containsKey(objId))
- {
- return _pvpKilledList.get(objId);
- }
- return 0;
- }
- public synchronized void addToPkKilledList(int objId, long time)
- {
- _pkKilledList.put(objId, time);
- }
- public synchronized boolean containsInPkKilledList(int objId)
- {
- return _pkKilledList.containsKey(objId);
- }
- public synchronized long getPkKilledListValue(int objId)
- {
- if (_pkKilledList.containsKey(objId))
- {
- return _pkKilledList.get(objId);
- }
- return 0;
- }
- private void updateKillRewardInfo(L2Character attacker, L2PcInstance victim)
- {
- L2PcInstance killer = attacker.getActingPlayer();
- if (killer.getActingPlayer() == null || this.getActingPlayer() == null)
- {
- return;
- }
- if (victim.getPvpFlag() == 1 || victim.getPvpFlag() == 2)
- {
- if (!killer.containsInPvpKilledList(victim.getObjectId()))
- {
- killer.addToPvpKilledList(victim.getObjectId(), System.currentTimeMillis());
- }
- if ((Config.PVP_REWARD_PVP_LEVEL_DIF > 0) && (Math.abs(killer.getLevel() - victim.getLevel()) > Config.PVP_REWARD_PVP_LEVEL_DIF))
- {
- return;
- }
- if (Config.PVP_REWARD_BLOCK_SAME_IP && killer.getHWid().equals(victim.getHWid()))
- {
- return;
- }
- if (Config.PVP_REWARD_BLOCK_SAME_IP && killer.getClient().getConnection().getInetAddress().getHostAddress().equals(victim.getClient().getConnection().getInetAddress().getHostAddress()))
- {
- return;
- }
- if (killer.getPvpKilledListValue(victim.getObjectId()) > System.currentTimeMillis())
- {
- return;
- }
- doPvPReward(killer, true);
- killer.addToPvpKilledList(victim.getObjectId(), System.currentTimeMillis() + Config.PVP_REWARD_PVP_UPDATE_TIME * 1000);
- }
- else
- {
- if (!killer.containsInPkKilledList(victim.getObjectId()))
- {
- killer.addToPkKilledList(victim.getObjectId(), System.currentTimeMillis());
- }
- if ((Config.PVP_REWARD_PK_LEVEL_DIF > 0) && (Math.abs(killer.getLevel() - victim.getLevel()) > Config.PVP_REWARD_PK_LEVEL_DIF))
- {
- return;
- }
- if (Config.PVP_REWARD_PK_BLOCK_SAME_IP && killer.getHWid().equals(victim.getHWid()))
- {
- return;
- }
- if (Config.PVP_REWARD_PK_BLOCK_SAME_IP && killer.getClient().getConnection().getInetAddress().equals(victim.getClient().getConnection().getInetAddress()))
- {
- return;
- }
- if (killer.getPkKilledListValue(victim.getObjectId()) > System.currentTimeMillis())
- {
- return;
- }
- doPvPReward(killer, false);
- killer.addToPkKilledList(victim.getObjectId(), System.currentTimeMillis() + Config.PVP_REWARD_PK_UPDATE_TIME * 1000);
- }
- }
- private void doPvPReward(L2PcInstance player, boolean isPvP)
- {
- if (isPvP)
- {
- if (Config.PVP_REWARD_EXP_AMOUNT > 0)
- {
- player.addExpAndSp(Config.PVP_REWARD_EXP_AMOUNT, 0);
- }
- if (Config.PVP_REWARD_SP_AMOUNT > 0)
- {
- player.addExpAndSp(0, Config.PVP_REWARD_SP_AMOUNT);
- }
- if ((Config.PVP_REWARD_ITEMS.length == 1) && (Config.PVP_REWARD_ITEMS[0] == 0))
- {
- return;
- }
- for (int i = 0; i < Config.PVP_REWARD_ITEMS.length; i++)
- {
- if (Rnd.chance(Config.PVP_REWARD_ITEMS_CHANCE[i]))
- {
- player.addItem("PvPReward", Config.PVP_REWARD_ITEMS[i], Config.PVP_REWARD_ITEMS_COUNT[i], null, true);
- }
- }
- }
- else
- {
- if (Config.PVP_REWARD_PK_EXP_AMOUNT > 0)
- {
- player.addExpAndSp(Config.PVP_REWARD_PK_EXP_AMOUNT, 0);
- }
- if (Config.PVP_REWARD_PK_SP_AMOUNT > 0)
- {
- player.addExpAndSp(0, Config.PVP_REWARD_PK_SP_AMOUNT);
- }
- if ((Config.PVP_REWARD_PK_ITEMS.length == 1) && (Config.PVP_REWARD_PK_ITEMS[0] == 0))
- {
- return;
- }
- for (int i = 0; i < Config.PVP_REWARD_PK_ITEMS.length; i++)
- {
- if (Rnd.chance(Config.PVP_REWARD_PK_ITEMS_CHANCE[i]))
- {
- player.addItem("PkReward", Config.PVP_REWARD_PK_ITEMS[i], Config.PVP_REWARD_PK_ITEMS_COUNT[i], null, true);
- }
- }
- }
- }
- private List<String> bypasses = null, bypasses_bbs = null;
- private List<String> getStoredBypasses(boolean bbs)
- {
- if (bbs)
- {
- if (bypasses_bbs == null)
- {
- bypasses_bbs = new ArrayList<>();
- }
- return bypasses_bbs;
- }
- if (bypasses == null)
- {
- bypasses = new ArrayList<>();
- }
- return bypasses;
- }
- public void cleanBypasses(boolean bbs)
- {
- List<String> bypassStorage = getStoredBypasses(bbs);
- synchronized (bypassStorage)
- {
- bypassStorage.clear();
- }
- }
- public String encodeBypasses(String htmlCode, boolean bbs)
- {
- List<String> bypassStorage = getStoredBypasses(bbs);
- synchronized (bypassStorage)
- {
- return BypassManager.encode(htmlCode, bypassStorage, bbs);
- }
- }
- public BypassManager.DecodedBypass decodeBypass(String bypass)
- {
- BypassManager.BypassType bpType = BypassManager.getBypassType(bypass);
- boolean bbs = false;
- if (bpType == BypassManager.BypassType.ENCODED_BBS || bpType == BypassManager.BypassType.SIMPLE_BBS)
- {
- bbs = true;
- }
- List<String> bypassStorage = getStoredBypasses(bbs);
- if (bpType == BypassManager.BypassType.ENCODED || bpType == BypassManager.BypassType.ENCODED_BBS)
- {
- return BypassManager.decode(bypass, bypassStorage, bbs, this);
- }
- if (bpType == BypassManager.BypassType.SIMPLE || bpType == BypassManager.BypassType.SIMPLE_BBS)
- {
- return new BypassManager.DecodedBypass(bypass, bbs).trim();
- }
- _log.warn("Direct access to bypass: " + bypass + " / Player: " + getName());
- return null;
- }
- public void setOfflineNameColor(int nameColor)
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement stmt_ins = con.prepareStatement(INSERT_OFFLINE_NAME_COLOR);
- stmt_ins.setInt(1, getObjectId());
- stmt_ins.setInt(2, getAppearance().getNameColor());
- stmt_ins.execute();
- stmt_ins.close();
- }
- catch (SQLException e)
- {
- _log.warn("Error while saving offline name color: " + e);
- }
- getAppearance().setNameColor(nameColor);
- }
- public void getOfflineNameColor()
- {
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement stmt_read = con.prepareStatement(SELECT_OFFLINE_NAME_COLOR);
- stmt_read.setInt(1, getObjectId());
- ResultSet rset = stmt_read.executeQuery();
- while (rset.next())
- {
- int nameColor = rset.getInt("name_color");
- getAppearance().setNameColor(nameColor);
- }
- rset.close();
- stmt_read.close();
- }
- catch (SQLException e)
- {
- _log.warn("Error while reading offline name color: " + e);
- }
- try (Connection con = DatabaseFactory.getInstance().getConnection())
- {
- PreparedStatement stmt_del = con.prepareStatement(DELETE_OFFLINE_NAME_COLOR);
- stmt_del.setInt(1, getObjectId());
- stmt_del.execute();
- stmt_del.close();
- }
- catch (SQLException e)
- {
- _log.warn("Error while cleaning offline name color: " + e);
- }
- }
- public void showDialog(String msg)
- {
- NpcHtmlMessage html = new NpcHtmlMessage(5);
- html.setHtml(msg);
- sendPacket(html);
- }
- private int _dmKills = 0;
- public int getDmKills()
- {
- return _dmKills;
- }
- public void setDmKills(int x)
- {
- _dmKills = x;
- }
- public void resetSkillTime(boolean ssl)
- {
- for (L2Skill skill : getAllSkills())
- {
- if (skill != null)
- {
- if (skill.isActive())
- {
- enableSkill(skill);
- }
- }
- }
- if (ssl)
- {
- sendSkillList();
- }
- sendPacket(new SkillCoolTime(this));
- }
- @Override
- public void checkCondition(final double curHp, final double newHp)
- {
- final int[] hp =
- {
- 30,
- 30,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60
- };
- final int[] skills =
- {
- 290,
- 291,
- 3027,
- 3028,
- 3029,
- 3030,
- 3031,
- 3032,
- 3033,
- 3034,
- 3056,
- 3069,
- 3071
- };
- final double percent = getMaxHp() / 100.0d;
- final double curHpPercent = curHp / percent;
- final double newHpPercent = newHp / percent;
- boolean needsUpdate = false;
- int hpcalc;
- for (int i = 0; i < skills.length; i++)
- {
- final int level = getSkillLevel(skills[i]);
- if (level > 0)
- {
- hpcalc = hp[i];
- if (curHpPercent > hpcalc)
- {
- if (newHpPercent <= hpcalc)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.HP_DECREASED_EFFECT_APPLIES).addSkillName(skills[i]));
- needsUpdate = true;
- }
- }
- else if (newHpPercent > hpcalc)
- {
- sendPacket(SystemMessage.getSystemMessage(SystemMessageId.HP_INCREASED_EFFECT_DISAPPEARS).addSkillName(skills[i]));
- needsUpdate = true;
- }
- }
- }
- if (needsUpdate)
- {
- broadcastUserInfo();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement