package client;
import client.anticheat.CheatTracker;
import client.anticheat.ReportType;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.ItemFlag;
import client.inventory.ItemLoader;
import client.inventory.MapleAndroid;
import client.inventory.MapleImp;
import client.inventory.MapleImp.ImpFlag;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryIdentifier;
import client.inventory.MapleInventoryType;
import client.inventory.MapleMount;
import client.inventory.MaplePet;
import client.inventory.MapleRing;
import client.inventory.MapleRing.RingComparator;
import client.status.MonsterStatus;
import client.status.MonsterStatusEffect;
import constants.BattleConstants;
import constants.BattleConstants.HoldItem;
import constants.BattleConstants.PokemonNature;
import constants.BattleConstants.PokemonStat;
import constants.GameConstants;
import constants.MapConstants;
import constants.OccupationConstants;
import constants.ServerConstants;
import database.DatabaseConnection;
import database.DatabaseException;
import handling.channel.ChannelServer;
import handling.channel.PlayerStorage;
import handling.login.LoginInformationProvider.JobType;
import handling.login.LoginServer;
import handling.world.CharacterTransfer;
import handling.world.MapleCharacterLook;
import handling.world.MapleMessenger;
import handling.world.MapleMessengerCharacter;
import handling.world.MapleParty;
import handling.world.MaplePartyCharacter;
import handling.world.PartyOperation;
import handling.world.PlayerBuffStorage;
import handling.world.PlayerBuffValueHolder;
import handling.world.World;
import handling.world.World.Broadcast;
import handling.world.World.Family;
import handling.world.World.Guild;
import handling.world.World.Messenger;
import handling.world.World.Party;
import handling.world.family.MapleFamily;
import handling.world.family.MapleFamilyBuff;
import handling.world.family.MapleFamilyCharacter;
import handling.world.guild.MapleGuild;
import handling.world.guild.MapleGuildCharacter;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.PrintStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.apache.mina.common.IoSession;
import scripting.EventInstanceManager;
import scripting.NPCScriptManager;
import server.CashShop;
import server.MapleAchievement;
import server.MapleAchievements;
import server.MapleCarnivalChallenge;
import server.MapleCarnivalParty;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MaplePortal;
import server.MapleShop;
import server.MapleStatEffect;
import server.MapleStatEffect.CancelEffectAction;
import server.MapleStorage;
import server.MapleTrade;
import server.PokemonBattle;
import server.RandomRewards;
import server.Randomizer;
import server.StructFamiliar;
import server.Timer.BuffTimer;
import server.Timer.MapTimer;
import server.life.MapleLifeFactory;
import server.life.MapleMonster;
import server.life.MapleMonsterStats;
import server.life.MobSkill;
import server.life.MobSkillFactory;
import server.life.PlayerNPC;
import server.maps.AnimatedMapleMapObject;
import server.maps.Event_PyramidSubway;
import server.maps.FieldLimitType;
import server.maps.MapleDoor;
import server.maps.MapleDragon;
import server.maps.MapleExtractor;
import server.maps.MapleFoothold;
import server.maps.MapleFootholdTree;
import server.maps.MapleMap;
import server.maps.MapleMapFactory;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.maps.MapleSummon;
import server.maps.MechDoor;
import server.maps.SavedLocationType;
import server.movement.LifeMovementFragment;
import server.quest.MapleQuest;
import server.quest.custom.CustomQuest;
import server.quest.custom.CustomQuestProvider;
import server.shops.HiredMerchant;
import server.shops.IMaplePlayerShop;
import tools.ConcurrentEnumMap;
import tools.FileoutputUtil;
import tools.MockIOSession;
import tools.Pair;
import tools.StringUtil;
import tools.Triple;
import tools.data.MaplePacketLittleEndianWriter;
import tools.packet.CField;
import tools.packet.CField.EffectPacket;
import tools.packet.CField.NPCPacket;
import tools.packet.CField.SummonPacket;
import tools.packet.CWvsContext;
import tools.packet.CWvsContext.BuddylistPacket;
import tools.packet.CWvsContext.BuffPacket;
import tools.packet.CWvsContext.InfoPacket;
import tools.packet.CWvsContext.InventoryPacket;
import tools.packet.MTSCSPacket;
import tools.packet.MobPacket;
import tools.packet.MonsterCarnivalPacket;
import tools.packet.PetPacket;
import tools.packet.PlayerShopPacket;
public class MapleCharacter extends AnimatedMapleMapObject
implements Serializable, MapleCharacterLook
{
private static final long serialVersionUID = 845748950829L;
private String name;
private String chalktext;
private String BlessOfFairy_Origin;
private String BlessOfEmpress_Origin;
private String teleportname;
private long lastCombo;
private long lastfametime;
private long keydown_skill;
private long nextConsume;
private long pqStartTime;
private long lastDragonBloodTime;
private long lastBerserkTime;
private long lastRecoveryTime;
private long lastSummonTime;
private long mapChangeTime;
private long lastFishingTime;
private long lastFairyTime;
private long lastHPTime;
private long lastMPTime;
private long lastFamiliarEffectTime;
private long lastDOTTime;
private byte gmLevel;
private byte gender;
private byte initialSpawnPoint;
private byte skinColor;
private byte guildrank = 5; private byte allianceRank = 5;
private byte world;
private byte fairyExp;
private byte numClones;
private byte subcategory;
private byte cardStack;
private short level;
private short mulung_energy;
private short combo;
private short force;
private short availableCP;
private short fatigue;
private short totalCP;
private short hpApUsed;
private short job;
private short remainingAp;
private short scrolledPosition;
private int accountid;
private int id;
private int meso;
private int exp;
private int hair;
private int face;
private int demonMarking;
private int mapid;
private int fame;
private int pvpExp;
private int pvpPoints;
private int totalWins;
private int totalLosses;
private int guildid = 0;
private int fallcounter;
private int maplepoints;
private int acash;
private int chair;
private int itemEffect;
private int points;
private int vpoints;
private int rank = 1; private int rankMove = 0; private int jobRank = 1; private int jobRankMove = 0;
private int marriageId;
private int marriageItemId;
private int dotHP;
private int runningStack;
private int currentrep;
private int totalrep;
private int coconutteam;
private int followid;
private int battleshipHP;
private int gachexp;
private int challenge;
private int guildContribution = 0;
private int toSteal;
private Point old;
private MonsterFamiliar summonedFamiliar;
private int[] wishlist;
private int[] rocks;
private int[] savedLocations;
private int[] regrocks;
private int[] hyperrocks;
private int[] remainingSp = new int[10];
private transient AtomicInteger inst;
private transient AtomicInteger insd;
private transient List<LifeMovementFragment> lastres;
private List<Integer> lastmonthfameids;
private List<Integer> lastmonthbattleids;
private List<Integer> extendedSlots;
private List<MapleDoor> doors;
private List<MechDoor> mechDoors;
private List<MaplePet> pets;
private List<Item> rebuy;
private MapleImp[] imps;
private transient WeakReference<MapleCharacter>[] clones;
private transient Set<MapleMonster> controlled;
private transient Set<MapleMapObject> visibleMapObjects;
private transient ReentrantReadWriteLock visibleMapObjectsLock;
private transient ReentrantReadWriteLock summonsLock;
private transient ReentrantReadWriteLock controlledLock;
private transient MapleAndroid android;
private Map<CustomQuest, MapleCustomQuestStatus> customQuests;
private Map<MapleQuest, MapleQuestStatus> quests;
private Map<Integer, String> questinfo;
private Map<Skill, SkillEntry> skills;
private transient Map<MapleBuffStat, MapleBuffStatValueHolder> effects;
private transient List<MapleSummon> summons;
private transient Map<Integer, MapleCoolDownValueHolder> coolDowns;
private transient Map<MapleDisease, MapleDiseaseValueHolder> diseases;
private Map<ReportType, Integer> reports;
private CashShop cs;
private transient Deque<MapleCarnivalChallenge> pendingCarnivalRequests;
private transient MapleCarnivalParty carnivalParty;
private BuddyList buddylist;
private MonsterBook monsterbook;
private transient CheatTracker anticheat;
private MapleClient client;
private transient MapleParty party;
private PlayerStats stats;
private MapleCharacterCards characterCard;
private transient MapleMap map;
private transient MapleShop shop;
private transient MapleDragon dragon;
private transient MapleExtractor extractor;
private transient RockPaperScissors rps;
private Map<Integer, MonsterFamiliar> familiars;
private MapleStorage storage;
private transient MapleTrade trade;
private MapleMount mount;
private List<Integer> finishedAchievements;
private MapleMessenger messenger;
private byte[] petStore;
private transient IMaplePlayerShop playerShop;
private boolean invincible;
private boolean canTalk;
private boolean clone;
private boolean followinitiator;
private boolean followon;
private boolean smega;
private boolean hasSummon;
private MapleGuildCharacter mgc;
private MapleFamilyCharacter mfc;
private transient EventInstanceManager eventInstance;
private MapleInventory[] inventory;
private SkillMacro[] skillMacros = new SkillMacro[5];
private EnumMap<MapleTrait.MapleTraitType, MapleTrait> traits;
private Battler[] battlers = new Battler[6];
private List<Battler> boxed;
private MapleKeyLayout keylayout;
private transient ScheduledFuture<?> mapTimeLimitTask;
private transient Event_PyramidSubway pyramidSubway = null;
private transient List<Integer> pendingExpiration = null;
private transient Map<Skill, SkillEntry> pendingSkills = null;
private transient Map<Integer, Integer> linkMobs;
private transient PokemonBattle battle;
protected MapleClient c;
private HiredMerchant hiredMerchant = null;
private boolean changed_wishlist;
private boolean changed_trocklocations;
private boolean changed_regrocklocations;
private boolean changed_hyperrocklocations;
private boolean changed_skillmacros;
private boolean changed_achievements;
private boolean changed_savedlocations;
private boolean changed_pokemon;
private boolean changed_questinfo;
private boolean changed_skills;
private boolean changed_reports;
private boolean changed_extendedSlots;
private int reborns;
private int apstorage;
private short occupationId;
private short occupationEXP;
private short mobKilledNo;
private long loginTime;
private transient PlayerRandomStream CRand;
private MapleCharacter(boolean ChannelServer)
{
setStance(0);
setPosition(new Point(0, 0));
this.inventory = new MapleInventory[MapleInventoryType.values().length];
for (MapleInventoryType type : MapleInventoryType.values()) {
this.inventory[type.ordinal()] = new MapleInventory(type);
}
this.quests = new LinkedHashMap();
this.skills = new LinkedHashMap();
this.stats = new PlayerStats();
this.characterCard = new MapleCharacterCards();
for (int i = 0; i < this.remainingSp.length; ++i) {
this.remainingSp[i] = 0;
}
this.traits = new EnumMap(MapleTrait.MapleTraitType.class);
for (MapleTrait.MapleTraitType t : MapleTrait.MapleTraitType.values()) {
this.traits.put(t, new MapleTrait(t));
}
if (ChannelServer) {
this.changed_reports = false;
this.changed_skills = false;
this.changed_achievements = false;
this.changed_wishlist = false;
this.changed_trocklocations = false;
this.changed_regrocklocations = false;
this.changed_hyperrocklocations = false;
this.changed_skillmacros = false;
this.changed_savedlocations = false;
this.changed_pokemon = false;
this.changed_extendedSlots = false;
this.changed_questinfo = false;
this.scrolledPosition = 0;
this.lastCombo = 0L;
this.mulung_energy = 0;
this.loginTime = 0L;
this.combo = 0;
this.force = 0;
this.keydown_skill = 0L;
this.nextConsume = 0L;
this.pqStartTime = 0L;
this.fairyExp = 0;
this.cardStack = 0;
this.runningStack = 1;
this.mapChangeTime = 0L;
this.lastRecoveryTime = 0L;
this.lastDragonBloodTime = 0L;
this.lastBerserkTime = 0L;
this.lastFishingTime = 0L;
this.lastFairyTime = 0L;
this.lastHPTime = 0L;
this.lastMPTime = 0L;
this.lastFamiliarEffectTime = 0L;
this.old = new Point(0, 0);
this.coconutteam = 0;
this.followid = 0;
this.toSteal = 0;
this.battleshipHP = 0;
this.marriageItemId = 0;
this.fallcounter = 0;
this.challenge = 0;
this.dotHP = 0;
this.lastSummonTime = 0L;
this.hasSummon = false;
this.invincible = false;
this.canTalk = true;
this.clone = false;
this.followinitiator = false;
this.followon = false;
this.rebuy = new ArrayList();
this.linkMobs = new HashMap();
this.finishedAchievements = new ArrayList();
this.reports = new EnumMap(ReportType.class);
this.teleportname = "";
this.smega = true;
this.petStore = new byte[3];
for (int i = 0; i < this.petStore.length; ++i) {
this.petStore[i] = -1;
}
this.wishlist = new int[10];
this.rocks = new int[10];
this.regrocks = new int[5];
this.hyperrocks = new int[13];
this.imps = new MapleImp[3];
this.clones = new WeakReference[5];
for (int i = 0; i < this.clones.length; ++i) {
this.clones[i] = new WeakReference(null);
}
this.boxed = new ArrayList();
this.familiars = new LinkedHashMap();
this.extendedSlots = new ArrayList();
this.effects = new ConcurrentEnumMap(MapleBuffStat.class);
this.coolDowns = new LinkedHashMap();
this.diseases = new ConcurrentEnumMap(MapleDisease.class);
this.inst = new AtomicInteger(0);
this.insd = new AtomicInteger(-1);
this.keylayout = new MapleKeyLayout();
this.doors = new ArrayList();
this.mechDoors = new ArrayList();
this.controlled = new LinkedHashSet();
this.controlledLock = new ReentrantReadWriteLock();
this.summons = new LinkedList();
this.summonsLock = new ReentrantReadWriteLock();
this.visibleMapObjects = new LinkedHashSet();
this.visibleMapObjectsLock = new ReentrantReadWriteLock();
this.pendingCarnivalRequests = new LinkedList();
this.savedLocations = new int[SavedLocationType.values().length];
for (int i = 0; i < SavedLocationType.values().length; ++i) {
this.savedLocations[i] = -1;
}
this.questinfo = new LinkedHashMap();
this.pets = new ArrayList();
}
}
public static MapleCharacter getDefault(MapleClient client, JobType type) {
MapleCharacter ret = new MapleCharacter(false);
ret.client = client;
ret.map = null;
ret.exp = 0;
ret.gmLevel = 0;
ret.job = (short)type.id;
ret.meso = 0;
ret.level = (short)((type.id == 2400) ? 10 : (type.id == 508) ? 10 : 1);
ret.remainingAp = 0;
ret.fame = 0;
ret.accountid = client.getAccID();
ret.buddylist = new BuddyList((byte) 20);
ret.stats.str = 12;
ret.stats.dex = 5;
ret.stats.int_ = 4;
ret.stats.luk = 4;
ret.stats.maxhp = 50;
ret.stats.hp = 50;
ret.stats.maxmp = 50;
ret.stats.mp = 50;
ret.gachexp = 0;
try
{
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
ps.setInt(1, ret.accountid);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ret.client.setAccountName(rs.getString("name"));
ret.acash = rs.getInt("ACash");
ret.maplepoints = rs.getInt("mPoints");
ret.points = rs.getInt("points");
ret.vpoints = rs.getInt("vpoints");
}
rs.close();
ps.close();
} catch (SQLException e) {
System.err.println(new StringBuilder().append("Error getting character default").append(e).toString());
}
return ret;
}
public static final MapleCharacter ReconstructChr(CharacterTransfer ct, MapleClient client, boolean isChannel) {
MapleCharacter ret = new MapleCharacter(true);
ret.client = client;
if (!(isChannel)) {
ret.client.setChannel(ct.channel);
}
ret.id = ct.characterid;
ret.name = ct.name;
ret.level = ct.level;
ret.fame = ct.fame;
ret.CRand = new PlayerRandomStream();
ret.stats.str = ct.str;
ret.stats.dex = ct.dex;
ret.stats.int_ = ct.int_;
ret.stats.luk = ct.luk;
ret.stats.maxhp = ct.maxhp;
ret.stats.maxmp = ct.maxmp;
ret.stats.hp = ct.hp;
ret.stats.mp = ct.mp;
ret.characterCard.setCards(ct.cardsInfo);
ret.chalktext = ct.chalkboard;
ret.gmLevel = ct.gmLevel;
ret.exp = (((((ret.level >= 200) || ((GameConstants.isKOC(ret.job)) && (ret.level >= 120)))) && (!(ret.isIntern()))) ? 0 : ct.exp);
ret.hpApUsed = ct.hpApUsed;
ret.remainingSp = ct.remainingSp;
ret.remainingAp = ct.remainingAp;
ret.meso = ct.meso;
ret.skinColor = ct.skinColor;
ret.gender = ct.gender;
ret.job = ct.job;
ret.hair = ct.hair;
ret.face = ct.face;
ret.demonMarking = ct.demonMarking;
ret.accountid = ct.accountid;
ret.totalWins = ct.totalWins;
ret.totalLosses = ct.totalLosses;
client.setAccID(ct.accountid);
ret.mapid = ct.mapid;
ret.initialSpawnPoint = ct.initialSpawnPoint;
ret.world = ct.world;
ret.guildid = ct.guildid;
ret.guildrank = ct.guildrank;
ret.guildContribution = ct.guildContribution;
ret.allianceRank = ct.alliancerank;
ret.points = ct.points;
ret.vpoints = ct.vpoints;
ret.fairyExp = ct.fairyExp;
ret.cardStack = ct.cardStack;
ret.marriageId = ct.marriageId;
ret.currentrep = ct.currentrep;
ret.totalrep = ct.totalrep;
ret.gachexp = ct.gachexp;
ret.pvpExp = ct.pvpExp;
ret.pvpPoints = ct.pvpPoints;
ret.reborns = ct.reborns;
ret.apstorage = ct.apstorage;
ret.occupationId = ct.occupationId;
ret.occupationEXP = ct.occupationEXP;
ret.makeMFC(ct.familyid, ct.seniorid, ct.junior1, ct.junior2);
if (ret.guildid > 0) {
ret.mgc = new MapleGuildCharacter(ret);
}
ret.fatigue = ct.fatigue;
ret.buddylist = new BuddyList(ct.buddysize);
ret.subcategory = ct.subcategory;
if (isChannel) {
MapleMapFactory mapFactory = ChannelServer.getInstance(client.getChannel()).getMapFactory();
ret.map = mapFactory.getMap(ret.mapid);
if (ret.map == null) {
ret.map = mapFactory.getMap(100000000);
}
else if ((ret.map.getForcedReturnId() != 999999999) && (ret.map.getForcedReturnMap() != null)) {
ret.map = ret.map.getForcedReturnMap();
}
MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
if (portal == null) {
portal = ret.map.getPortal(0);
ret.initialSpawnPoint = 0;
}
ret.setPosition(portal.getPosition());
int messengerid = ct.messengerid;
if (messengerid > 0)
ret.messenger = World.Messenger.getMessenger(messengerid);
}
else
{
ret.messenger = null;
}
int partyid = ct.partyid;
if (partyid >= 0) {
MapleParty party = World.Party.getParty(partyid);
if ((party != null) && (party.getMemberById(ret.id) != null)) {
ret.party = party;
}
}
for (Iterator i$ = ct.Quest.entrySet().iterator(); i$.hasNext(); ) { Map.Entry<Integer, Object> qs = (Map.Entry)i$.next();
MapleQuestStatus queststatus_from = (MapleQuestStatus)qs.getValue();
queststatus_from.setQuest(((Integer)qs.getKey()).intValue());
ret.quests.put(queststatus_from.getQuest(), queststatus_from);
}
for (Iterator i$ = ct.Skills.entrySet().iterator(); i$.hasNext(); ) { Map.Entry<Integer, SkillEntry> qs = (Map.Entry)i$.next();
ret.skills.put(SkillFactory.getSkill(((Integer)qs.getKey()).intValue()), qs.getValue());
}
for (Integer zz : ct.finishedAchievements) {
ret.finishedAchievements.add(zz);
}
for (Iterator i$ = ct.boxed.iterator(); i$.hasNext(); ) { Object zz = i$.next();
Battler zzz = (Battler)zz;
zzz.setStats();
ret.boxed.add(zzz);
}
for (Map.Entry t : ct.traits.entrySet()) {
((MapleTrait)ret.traits.get(t.getKey())).setExp(((Integer)t.getValue()).intValue());
}
for (Iterator i$ = ct.reports.entrySet().iterator(); i$.hasNext(); ) { Map.Entry<Byte, Integer> qs = (Map.Entry)i$.next();
ret.reports.put(ReportType.getById(((Byte)qs.getKey()).byteValue()), qs.getValue());
}
ret.monsterbook = new MonsterBook(ct.mbook, ret);
ret.inventory = ((MapleInventory[])(MapleInventory[])ct.inventorys);
ret.BlessOfFairy_Origin = ct.BlessOfFairy;
ret.BlessOfEmpress_Origin = ct.BlessOfEmpress;
ret.skillMacros = ((SkillMacro[])(SkillMacro[])ct.skillmacro);
ret.battlers = ((Battler[])(Battler[])ct.battlers);
for (Battler b : ret.battlers) {
if (b != null) {
b.setStats();
}
}
ret.petStore = ct.petStore;
ret.keylayout = new MapleKeyLayout(ct.keymap);
ret.questinfo = ct.InfoQuest;
ret.familiars = ct.familiars;
ret.savedLocations = ct.savedlocation;
ret.wishlist = ct.wishlist;
ret.rocks = ct.rocks;
ret.regrocks = ct.regrocks;
ret.hyperrocks = ct.hyperrocks;
ret.buddylist.loadFromTransfer(ct.buddies);
ret.keydown_skill = 0L;
ret.lastfametime = ct.lastfametime;
ret.lastmonthfameids = ct.famedcharacters;
ret.lastmonthbattleids = ct.battledaccs;
ret.extendedSlots = ct.extendedSlots;
ret.storage = ((MapleStorage)ct.storage);
ret.cs = ((CashShop)ct.cs);
client.setAccountName(ct.accountname);
ret.acash = ct.ACash;
ret.maplepoints = ct.MaplePoints;
ret.numClones = ct.clonez;
ret.imps = ct.imps;
ret.anticheat = ((CheatTracker)ct.anticheat);
ret.anticheat.start(ret);
ret.rebuy = ct.rebuy;
ret.mount = new MapleMount(ret, ct.mount_itemid, PlayerStats.getSkillByJob(1004, ret.job), ct.mount_Fatigue, ct.mount_level, ct.mount_exp);
ret.expirationTask(false, false);
ret.stats.recalcLocalStats(true, ret);
client.setTempIP(ct.tempIP);
return ret;
}
public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver) {
return loadCharFromDB(charid, client, channelserver, null);
}
public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver, Map<Integer, CardData> cads) {
MapleCharacter ret = new MapleCharacter(channelserver);
ret.client = client;
ret.id = charid;
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
PreparedStatement pse = null;
ResultSet rs = null;
try
{
ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
if (!(rs.next())) {
rs.close();
ps.close();
throw new RuntimeException("Loading the Char Failed (char not found)");
}
ret.name = rs.getString("name");
ret.level = rs.getShort("level");
ret.fame = rs.getInt("fame");
ret.stats.str = rs.getShort("str");
ret.stats.dex = rs.getShort("dex");
ret.stats.int_ = rs.getShort("int");
ret.stats.luk = rs.getShort("luk");
ret.stats.maxhp = rs.getInt("maxhp");
ret.stats.maxmp = rs.getInt("maxmp");
ret.stats.hp = rs.getInt("hp");
ret.stats.mp = rs.getInt("mp");
ret.job = rs.getShort("job");
ret.gmLevel = rs.getByte("gm");
ret.exp = (((((ret.level >= 200) || ((GameConstants.isKOC(ret.job)) && (ret.level >= 120)))) && (!(ret.isIntern()))) ? 0 : rs.getInt("exp"));
ret.hpApUsed = rs.getShort("hpApUsed");
String[] sp = rs.getString("sp").split(",");
for (int i = 0; i < ret.remainingSp.length; ++i) {
ret.remainingSp[i] = Integer.parseInt(sp[i]);
}
ret.remainingAp = rs.getShort("ap");
ret.meso = rs.getInt("meso");
ret.skinColor = rs.getByte("skincolor");
ret.gender = rs.getByte("gender");
ret.hair = rs.getInt("hair");
ret.face = rs.getInt("face");
ret.demonMarking = rs.getInt("demonMarking");
ret.accountid = rs.getInt("accountid");
client.setAccID(ret.accountid);
ret.mapid = rs.getInt("map");
ret.initialSpawnPoint = rs.getByte("spawnpoint");
ret.world = rs.getByte("world");
ret.guildid = rs.getInt("guildid");
ret.guildrank = rs.getByte("guildrank");
ret.allianceRank = rs.getByte("allianceRank");
ret.guildContribution = rs.getInt("guildContribution");
ret.totalWins = rs.getInt("totalWins");
ret.totalLosses = rs.getInt("totalLosses");
ret.currentrep = rs.getInt("currentrep");
ret.totalrep = rs.getInt("totalrep");
ret.makeMFC(rs.getInt("familyid"), rs.getInt("seniorid"), rs.getInt("junior1"), rs.getInt("junior2"));
if (ret.guildid > 0) {
ret.mgc = new MapleGuildCharacter(ret);
}
ret.gachexp = rs.getInt("gachexp");
ret.buddylist = new BuddyList(rs.getByte("buddyCapacity"));
ret.subcategory = rs.getByte("subcategory");
ret.mount = new MapleMount(ret, 0, PlayerStats.getSkillByJob(1004, ret.job), (byte) 0, (byte) 1, 0);
ret.rank = rs.getInt("rank");
ret.rankMove = rs.getInt("rankMove");
ret.jobRank = rs.getInt("jobRank");
ret.jobRankMove = rs.getInt("jobRankMove");
ret.marriageId = rs.getInt("marriageId");
ret.fatigue = rs.getShort("fatigue");
ret.pvpExp = rs.getInt("pvpExp");
ret.pvpPoints = rs.getInt("pvpPoints");
ret.reborns = rs.getInt("reborns");
ret.apstorage = rs.getInt("apstorage");
ret.occupationId = rs.getShort("occupationId");
ret.occupationEXP = rs.getShort("occupationEXP");
for (MapleTrait t : ret.traits.values()) {
t.setExp(rs.getInt(t.getType().name()));
}
if (channelserver) {
ret.CRand = new PlayerRandomStream();
ret.anticheat = new CheatTracker(ret);
MapleMapFactory mapFactory = ChannelServer.getInstance(client.getChannel()).getMapFactory();
ret.map = mapFactory.getMap(ret.mapid);
if (ret.map == null) {
ret.map = mapFactory.getMap(100000000);
}
MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
if (portal == null) {
portal = ret.map.getPortal(0);
ret.initialSpawnPoint = 0;
}
ret.setPosition(portal.getPosition());
int partyid = rs.getInt("party");
if (partyid >= 0) {
MapleParty party = World.Party.getParty(partyid);
if ((party != null) && (party.getMemberById(ret.id) != null)) {
ret.party = party;
}
}
String[] pets = rs.getString("pets").split(",");
for (int i = 0; i < ret.petStore.length; ++i) {
ret.petStore[i] = Byte.parseByte(pets[i]);
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM achievements WHERE accountid = ?");
ps.setInt(1, ret.accountid);
rs = ps.executeQuery();
while (rs.next()) {
ret.finishedAchievements.add(Integer.valueOf(rs.getInt("achievementid")));
}
ps.close();
rs.close();
ps = con.prepareStatement("SELECT * FROM reports WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
if (ReportType.getById(rs.getByte("type")) != null);
ret.reports.put(ReportType.getById(rs.getByte("type")), Integer.valueOf(rs.getInt("count")));
}
}
rs.close();
ps.close();
if (cads != null)
ret.characterCard.setCards(cads);
else {
ret.characterCard.loadCards(client, channelserver);
}
ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
pse = con.prepareStatement("SELECT * FROM queststatusmobs WHERE queststatusid = ?");
while (rs.next()) {
int id = rs.getInt("quest");
MapleQuest q = MapleQuest.getInstance(id);
byte stat = rs.getByte("status");
if ((((stat == 1) || (stat == 2))) && (channelserver)) { if (q == null) continue; if (q.isBlocked())
continue;
}
if ((stat == 1) && (channelserver) && (!(q.canStart(ret, null)))) {
continue;
}
MapleQuestStatus status = new MapleQuestStatus(q, stat);
long cTime = rs.getLong("time");
if (cTime > -1L) {
status.setCompletionTime(cTime * 1000L);
}
status.setForfeited(rs.getInt("forfeited"));
status.setCustomData(rs.getString("customData"));
ret.quests.put(q, status);
pse.setInt(1, rs.getInt("queststatusid"));
ResultSet rsMobs = pse.executeQuery();
while (rsMobs.next()) {
status.setMobKills(rsMobs.getInt("mob"), rsMobs.getInt("count"));
}
rsMobs.close();
}
rs.close();
ps.close();
pse.close();
Pair mit;
if (channelserver) {
ret.monsterbook = MonsterBook.loadCards(ret.accountid, ret);
ps = con.prepareStatement("SELECT * FROM inventoryslot where characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
if (!(rs.next())) {
rs.close();
ps.close();
throw new RuntimeException("No Inventory slot column found in SQL. [inventoryslot]");
}
ret.getInventory(MapleInventoryType.EQUIP).setSlotLimit(rs.getByte("equip"));
ret.getInventory(MapleInventoryType.USE).setSlotLimit(rs.getByte("use"));
ret.getInventory(MapleInventoryType.SETUP).setSlotLimit(rs.getByte("setup"));
ret.getInventory(MapleInventoryType.ETC).setSlotLimit(rs.getByte("etc"));
ret.getInventory(MapleInventoryType.CASH).setSlotLimit(rs.getByte("cash"));
ps.close();
rs.close();
for (Iterator i$ = ItemLoader.INVENTORY.loadItems(false, charid).values().iterator(); i$.hasNext(); ) { mit = (Pair)i$.next();
ret.getInventory((MapleInventoryType)mit.getRight()).addFromDB((Item)mit.getLeft());
if (((Item)mit.getLeft()).getPet() != null) {
ret.pets.add(((Item)mit.getLeft()).getPet());
}
}
ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
ps.setInt(1, ret.accountid);
rs = ps.executeQuery();
if (rs.next()) {
ret.getClient().setAccountName(rs.getString("name"));
ret.acash = rs.getInt("ACash");
ret.maplepoints = rs.getInt("mPoints");
ret.points = rs.getInt("points");
ret.vpoints = rs.getInt("vpoints");
if (rs.getTimestamp("lastlogon") != null) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(rs.getTimestamp("lastlogon").getTime());
if (cal.get(7) + 1 == Calendar.getInstance().get(7)) {
ret.acash += 500;
}
}
if (rs.getInt("banned") > 0) {
rs.close();
ps.close();
ret.getClient().getSession().close();
throw new RuntimeException("Loading a banned character");
}
rs.close();
ps.close();
ps = con.prepareStatement("UPDATE accounts SET lastlogon = CURRENT_TIMESTAMP() WHERE id = ?");
ps.setInt(1, ret.accountid);
ps.executeUpdate();
} else {
rs.close();
}
ps.close();
ps = con.prepareStatement("SELECT * FROM questinfo WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
ret.questinfo.put(Integer.valueOf(rs.getInt("quest")), rs.getString("customData"));
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT skillid, skilllevel, masterlevel, expiration, slot, equipped FROM skills WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
int skid = rs.getInt("skillid");
Skill skil = SkillFactory.getSkill(skid);
int skl = rs.getInt("skilllevel");
byte msl = rs.getByte("masterlevel");
if ((skil != null) && (GameConstants.isApplicableSkill(skid))) {
if ((skl > skil.getMaxLevel()) && (skid < 92000000)) {
if ((!(skil.isBeginnerSkill())) && (skil.canBeLearnedBy(ret.job)) && (!(skil.isSpecialSkill()))) {
ret.remainingSp[GameConstants.getSkillBookForSkill(skid)] += skl - skil.getMaxLevel();
}
skl = (byte)skil.getMaxLevel();
}
if (msl > skil.getMaxLevel()) {
msl = (byte)skil.getMaxLevel();
}
ret.skills.put(skil, new SkillEntry(skl, msl, rs.getLong("expiration"), rs.getByte("slot"), rs.getByte("equipped")));
} else if ((skil == null) &&
(!(GameConstants.isBeginnerJob(skid / 10000))) && (skid / 10000 != 900) && (skid / 10000 != 800) && (skid / 10000 != 9000)) {
ret.remainingSp[GameConstants.getSkillBookForSkill(skid)] += skl;
}
}
rs.close();
ps.close();
ret.expirationTask(false, true);
ps = con.prepareStatement("SELECT * FROM characters WHERE accountid = ? ORDER BY level DESC");
ps.setInt(1, ret.accountid);
rs = ps.executeQuery();
int maxlevel_ = 0; int maxlevel_2 = 0;
while (rs.next()) {
if (rs.getInt("id") != charid);
if (GameConstants.isKOC(rs.getShort("job"))) {
int maxlevel = rs.getShort("level") / 5;
if (maxlevel > 24) {
maxlevel = 24;
}
if ((maxlevel > maxlevel_2) || (maxlevel_2 == 0)) {
maxlevel_2 = maxlevel;
ret.BlessOfEmpress_Origin = rs.getString("name");
}
}
int maxlevel = rs.getShort("level") / 10;
if (maxlevel > 20) {
maxlevel = 20;
}
if ((maxlevel > maxlevel_) || (maxlevel_ == 0)) {
maxlevel_ = maxlevel;
ret.BlessOfFairy_Origin = rs.getString("name");
}
}
if (ret.BlessOfFairy_Origin == null) {
ret.BlessOfFairy_Origin = ret.name;
}
ret.skills.put(SkillFactory.getSkill(GameConstants.getBOF_ForJob(ret.job)), new SkillEntry(maxlevel_, (byte) 0, -1L));
if (SkillFactory.getSkill(GameConstants.getEmpress_ForJob(ret.job)) != null) {
if (ret.BlessOfEmpress_Origin == null) {
ret.BlessOfEmpress_Origin = ret.BlessOfFairy_Origin;
}
ret.skills.put(SkillFactory.getSkill(GameConstants.getEmpress_ForJob(ret.job)), new SkillEntry(maxlevel_2, (byte) 0, -1L));
}
ps.close();
rs.close();
ps = con.prepareStatement("SELECT * FROM skillmacros WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
int position;
while (rs.next()) {
position = rs.getInt("position");
SkillMacro macro = new SkillMacro(rs.getInt("skill1"), rs.getInt("skill2"), rs.getInt("skill3"), rs.getString("name"), rs.getInt("shout"), position);
ret.skillMacros[position] = macro;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM familiars WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getLong("expiry") <= System.currentTimeMillis()) {
continue;
}
ret.familiars.put(Integer.valueOf(rs.getInt("familiar")), new MonsterFamiliar(charid, rs.getInt("id"), rs.getInt("familiar"), rs.getLong("expiry"), rs.getString("name"), rs.getInt("fatigue"), rs.getByte("vitality")));
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM pokemon WHERE characterid = ? OR (accountid = ? AND active = 0)");
ps.setInt(1, charid);
ps.setInt(2, ret.accountid);
rs = ps.executeQuery();
position = 0;
while (rs.next()) {
Battler b = new Battler(rs.getInt("level"), rs.getInt("exp"), charid, rs.getInt("monsterid"), rs.getString("name"), BattleConstants.PokemonNature.values()[rs.getInt("nature")], rs.getInt("itemid"), rs.getByte("gender"), rs.getByte("hpiv"), rs.getByte("atkiv"), rs.getByte("defiv"), rs.getByte("spatkiv"), rs.getByte("spdefiv"), rs.getByte("speediv"), rs.getByte("evaiv"), rs.getByte("acciv"), rs.getByte("ability"));
if (b.getFamily() == null) {
continue;
}
if ((rs.getInt("active") > 0) && (position < 6) && (rs.getInt("characterid") == charid)) {
ret.battlers[position] = b;
++position;
} else {
ret.boxed.add(b);
}
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
Map keyb = ret.keylayout.Layout();
while (rs.next()) {
keyb.put(Integer.valueOf(rs.getInt("key")), new Pair(Byte.valueOf(rs.getByte("type")), Integer.valueOf(rs.getInt("action"))));
}
rs.close();
ps.close();
ret.keylayout.unchanged();
ps = con.prepareStatement("SELECT `locationtype`,`map` FROM savedlocations WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
ret.savedLocations[rs.getInt("locationtype")] = rs.getInt("map");
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT `characterid_to`,`when` FROM famelog WHERE characterid = ? AND DATEDIFF(NOW(),`when`) < 30");
ps.setInt(1, charid);
rs = ps.executeQuery();
ret.lastfametime = 0L;
ret.lastmonthfameids = new ArrayList(31);
while (rs.next()) {
ret.lastfametime = Math.max(ret.lastfametime, rs.getTimestamp("when").getTime());
ret.lastmonthfameids.add(Integer.valueOf(rs.getInt("characterid_to")));
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT `accid_to`,`when` FROM battlelog WHERE accid = ? AND DATEDIFF(NOW(),`when`) < 30");
ps.setInt(1, ret.accountid);
rs = ps.executeQuery();
ret.lastmonthbattleids = new ArrayList();
while (rs.next()) {
ret.lastmonthbattleids.add(Integer.valueOf(rs.getInt("accid_to")));
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT `itemId` FROM extendedSlots WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
while (rs.next()) {
ret.extendedSlots.add(Integer.valueOf(rs.getInt("itemId")));
}
rs.close();
ps.close();
ret.buddylist.loadFromDb(charid);
ret.storage = MapleStorage.loadStorage(ret.accountid);
ret.cs = new CashShop(ret.accountid, charid, ret.getJob());
ps = con.prepareStatement("SELECT sn FROM wishlist WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
int i = 0;
while (rs.next()) {
ret.wishlist[i] = rs.getInt("sn");
++i;
}
while (i < 10) {
ret.wishlist[i] = 0;
++i;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT mapid FROM trocklocations WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
int r = 0;
while (rs.next()) {
ret.rocks[r] = rs.getInt("mapid");
++r;
}
while (r < 10) {
ret.rocks[r] = 999999999;
++r;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT mapid FROM regrocklocations WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
r = 0;
while (rs.next()) {
ret.regrocks[r] = rs.getInt("mapid");
++r;
}
while (r < 5) {
ret.regrocks[r] = 999999999;
++r;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT mapid FROM hyperrocklocations WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
r = 0;
while (rs.next()) {
ret.hyperrocks[r] = rs.getInt("mapid");
++r;
}
while (r < 13) {
ret.hyperrocks[r] = 999999999;
++r;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM imps WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
r = 0;
while (rs.next()) {
ret.imps[r] = new MapleImp(rs.getInt("itemid"));
ret.imps[r].setLevel(rs.getByte("level"));
ret.imps[r].setState(rs.getByte("state"));
ret.imps[r].setCloseness(rs.getShort("closeness"));
ret.imps[r].setFullness(rs.getShort("fullness"));
++r;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT * FROM mountdata WHERE characterid = ?");
ps.setInt(1, charid);
rs = ps.executeQuery();
if (!(rs.next())) {
throw new RuntimeException("No mount data found on SQL column");
}
Item mount = ret.getInventory(MapleInventoryType.EQUIPPED).getItem((short)(byte)((GameConstants.GMS) ? -18 : -23));
ret.mount = new MapleMount(ret, (mount != null) ? mount.getItemId() : 0, (GameConstants.GMS) ? 80001000 : PlayerStats.getSkillByJob(1004, ret.job), rs.getByte("Fatigue"), rs.getByte("Level"), rs.getInt("Exp"));
ps.close();
rs.close();
ret.stats.recalcLocalStats(true, ret);
} else {
for (Iterator i$ = ItemLoader.INVENTORY.loadItems(true, charid).values().iterator(); i$.hasNext(); ) { mit = (Pair)i$.next();
ret.getInventory((MapleInventoryType)mit.getRight()).addFromDB((Item)mit.getLeft());
}
ret.stats.recalcPVPRank(ret);
}
} catch (SQLException ess) {
ess.printStackTrace();
System.out.println("Failed to load character..");
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", ess);
} finally {
try {
if (ps != null) {
ps.close();
}
if (rs != null)
rs.close();
}
catch (SQLException ignore) {
}
}
return ret;
}
public static void saveNewCharToDB(MapleCharacter chr, JobType type, short db) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
PreparedStatement pse = null;
ResultSet rs = null;
try {
con.setTransactionIsolation(1);
con.setAutoCommit(false);
ps = con.prepareStatement("INSERT INTO characters (level, str, dex, luk, `int`, hp, mp, maxhp, maxmp, sp, ap, skincolor, gender, job, hair, face, demonMarking, map, meso, party, buddyCapacity, pets, subcategory, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 1);
ps.setInt(1, chr.level);
PlayerStats stat = chr.stats;
ps.setShort(2, stat.getStr());
ps.setShort(3, stat.getDex());
ps.setShort(4, stat.getInt());
ps.setShort(5, stat.getLuk());
ps.setInt(6, stat.getHp());
ps.setInt(7, stat.getMp());
ps.setInt(8, stat.getMaxHp());
ps.setInt(9, stat.getMaxMp());
StringBuilder sps = new StringBuilder();
for (int i = 0; i < chr.remainingSp.length; ++i) {
sps.append(chr.remainingSp[i]);
sps.append(",");
}
String sp = sps.toString();
ps.setString(10, sp.substring(0, sp.length() - 1));
ps.setShort(11, chr.remainingAp);
ps.setByte(12, chr.skinColor);
ps.setByte(13, chr.gender);
ps.setShort(14, chr.job);
ps.setInt(15, chr.hair);
ps.setInt(16, chr.face);
ps.setInt(17, chr.demonMarking);
if (db < 0 || db > (GameConstants.GMS ? 2 : 1)) {
db = 0;
}
label356: ps.setInt(18, (db == 2) ? 3000600 : type.map);
ps.setInt(19, chr.meso);
ps.setInt(20, -1);
ps.setByte(21, chr.buddylist.getCapacity());
ps.setString(22, "-1,-1,-1");
ps.setInt(23, db);
ps.setInt(24, chr.getAccountID());
ps.setString(25, chr.name);
ps.setByte(26, chr.world);
ps.executeUpdate();
rs = ps.getGeneratedKeys();
if (rs.next()) {
chr.id = rs.getInt(1);
} else {
ps.close();
rs.close();
throw new DatabaseException("Inserting char failed.");
}
ps.close();
rs.close();
ps = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `forfeited`, `customData`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?)", 1);
pse = con.prepareStatement("INSERT INTO queststatusmobs VALUES (DEFAULT, ?, ?, ?)");
ps.setInt(1, chr.id);
for (MapleQuestStatus q : chr.quests.values()) {
ps.setInt(2, q.getQuest().getId());
ps.setInt(3, q.getStatus());
ps.setInt(4, (int)(q.getCompletionTime() / 1000L));
ps.setInt(5, q.getForfeited());
ps.setString(6, q.getCustomData());
ps.execute();
rs = ps.getGeneratedKeys();
Iterator i$;
if (q.hasMobKills()) {
rs.next();
for (i$ = q.getMobKills().keySet().iterator(); i$.hasNext(); ) { int mob = ((Integer)i$.next()).intValue();
pse.setInt(1, rs.getInt(1));
pse.setInt(2, mob);
pse.setInt(3, q.getMobKills(mob));
pse.execute();
}
}
rs.close();
}
ps.close();
pse.close();
ps = con.prepareStatement("INSERT INTO skills (characterid, skillid, skilllevel, masterlevel, expiration, slot, equipped) VALUES (?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, chr.id);
for (Map.Entry skill : chr.skills.entrySet()) {
if (GameConstants.isApplicableSkill(((Skill)skill.getKey()).getId())) {
ps.setInt(2, ((Skill)skill.getKey()).getId());
ps.setInt(3, ((SkillEntry)skill.getValue()).skillevel);
ps.setByte(4, ((SkillEntry)skill.getValue()).masterlevel);
ps.setLong(5, ((SkillEntry)skill.getValue()).expiration);
ps.setByte(6, ((SkillEntry)skill.getValue()).slot);
ps.setByte(7, ((SkillEntry)skill.getValue()).equipped);
ps.execute();
}
}
ps.close();
ps = con.prepareStatement("INSERT INTO inventoryslot (characterid, `equip`, `use`, `setup`, `etc`, `cash`) VALUES (?, ?, ?, ?, ?, ?)");
ps.setInt(1, chr.id);
ps.setByte(2, (byte) 96);
ps.setByte(3, (byte) 96);
ps.setByte(4, (byte) 96);
ps.setByte(5, (byte) 96);
ps.setByte(6, (byte) 60);
ps.execute();
ps.close();
ps = con.prepareStatement("INSERT INTO mountdata (characterid, `Level`, `Exp`, `Fatigue`) VALUES (?, ?, ?, ?)");
ps.setInt(1, chr.id);
ps.setByte(2, (byte) 1);
ps.setInt(3, 0);
ps.setByte(4, (byte) 0);
ps.execute();
ps.close();
int[] array1 = { 18, 65, 2, 23, 3, 4, 5, 6, 16, 17, 19, 25, 26, 27, 31, 34, 35, 37, 38, 40, 43, 44, 45, 46, 50, 56, 59, 60, 61, 62, 63, 64, 57, 48, 29, 7, 24, 33, 41 };
int[] array2 = { 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 5, 6, 6, 6, 6, 6, 6, 5, 4, 5, 4, 4, 4, 4 };
int[] array3 = { 0, 106, 10, 1, 12, 13, 18, 24, 8, 5, 4, 19, 14, 15, 2, 17, 11, 3, 20, 16, 9, 50, 51, 6, 7, 53, 100, 101, 102, 103, 104, 105, 54, 22, 52, 21, 25, 26, 23 };
ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
ps.setInt(1, chr.id);
for (int i = 0; i < array1.length; ++i) {
ps.setInt(2, array1[i]);
ps.setInt(3, array2[i]);
ps.setInt(4, array3[i]);
ps.execute();
}
ps.close();
List listing = new ArrayList();
for (MapleInventory iv : chr.inventory) {
for (Item item : iv.list()) {
listing.add(new Pair(item, iv.getType()));
}
}
ItemLoader.INVENTORY.saveItems(listing, con, chr.id);
con.commit();
} catch (Exception e) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", e);
e.printStackTrace();
System.err.println("[charsave] Error saving character data");
try {
con.rollback();
} catch (SQLException ex) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", ex);
ex.printStackTrace();
System.err.println("[charsave] Error Rolling Back");
}
} finally {
try {
if (pse != null) {
pse.close();
}
if (ps != null) {
ps.close();
}
if (rs != null) {
rs.close();
}
con.setAutoCommit(true);
con.setTransactionIsolation(4);
} catch (SQLException e) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", e);
e.printStackTrace();
System.err.println("[charsave] Error going back to autocommit mode");
}
}
}
public void saveToDB(boolean dc, boolean fromcs) {
if (isClone()) {
return;
}
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
PreparedStatement pse = null;
ResultSet rs = null;
try
{
con.setTransactionIsolation(1);
con.setAutoCommit(false);
ps = con.prepareStatement("UPDATE characters SET level = ?, fame = ?, str = ?, dex = ?, luk = ?, `int` = ?, exp = ?, hp = ?, mp = ?, maxhp = ?, maxmp = ?, sp = ?, ap = ?, gm = ?, skincolor = ?, gender = ?, job = ?, hair = ?, face = ?, demonMarking = ?, map = ?, meso = ?, hpApUsed = ?, spawnpoint = ?, party = ?, buddyCapacity = ?, pets = ?, subcategory = ?, marriageId = ?, currentrep = ?, totalrep = ?, gachexp = ?, fatigue = ?, charm = ?, charisma = ?, craft = ?, insight = ?, sense = ?, will = ?, totalwins = ?, totallosses = ?, pvpExp = ?, pvpPoints = ?, reborns = ?, apstorage = ?, occupationId = ?, occupationEXP = ?, name = ? WHERE id = ?", 1);
ps.setInt(1, this.level);
ps.setInt(2, this.fame);
ps.setShort(3, this.stats.getStr());
ps.setShort(4, this.stats.getDex());
ps.setShort(5, this.stats.getLuk());
ps.setShort(6, this.stats.getInt());
ps.setInt(7, ((((this.level >= 200) || ((GameConstants.isKOC(this.job)) && (this.level >= 120)))) && (!(isIntern()))) ? 0 : this.exp);
ps.setInt(8, (this.stats.getHp() < 1) ? 50 : this.stats.getHp());
ps.setInt(9, this.stats.getMp());
ps.setInt(10, this.stats.getMaxHp());
ps.setInt(11, this.stats.getMaxMp());
StringBuilder sps = new StringBuilder();
for (int i = 0; i < this.remainingSp.length; ++i) {
sps.append(this.remainingSp[i]);
sps.append(",");
}
String sp = sps.toString();
ps.setString(12, sp.substring(0, sp.length() - 1));
ps.setShort(13, this.remainingAp);
ps.setByte(14, this.gmLevel);
ps.setByte(15, this.skinColor);
ps.setByte(16, this.gender);
ps.setShort(17, this.job);
ps.setInt(18, this.hair);
ps.setInt(19, this.face);
ps.setInt(20, this.demonMarking);
if ((!(fromcs)) && (this.map != null)) {
if ((this.map.getForcedReturnId() != 999999999) && (this.map.getForcedReturnMap() != null))
ps.setInt(21, this.map.getForcedReturnId());
else
ps.setInt(21, (this.stats.getHp() < 1) ? this.map.getReturnMapId() : this.map.getId());
}
else {
ps.setInt(21, this.mapid);
}
ps.setInt(22, this.meso);
ps.setShort(23, this.hpApUsed);
if (this.map == null) {
ps.setByte(24, (byte) 0);
} else {
MaplePortal closest = this.map.findClosestSpawnpoint(getTruePosition());
ps.setByte(24, (byte)((closest != null) ? closest.getId() : 0));
}
ps.setInt(25, (this.party == null) ? -1 : this.party.getId());
ps.setShort(26, (short)this.buddylist.getCapacity());
StringBuilder petz = new StringBuilder();
int petLength = 0;
for (MaplePet pet : this.pets) {
if (pet.getSummoned()) {
pet.saveToDb();
petz.append(pet.getInventoryPosition());
petz.append(",");
++petLength;
}
}
while (petLength < 3) {
petz.append("-1,");
++petLength;
}
String petstring = petz.toString();
ps.setString(27, petstring.substring(0, petstring.length() - 1));
ps.setByte(28, this.subcategory);
ps.setInt(29, this.marriageId);
ps.setInt(30, this.currentrep);
ps.setInt(31, this.totalrep);
ps.setInt(32, this.gachexp);
ps.setShort(33, this.fatigue);
ps.setInt(34, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.charm)).getTotalExp());
ps.setInt(35, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.charisma)).getTotalExp());
ps.setInt(36, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.craft)).getTotalExp());
ps.setInt(37, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.insight)).getTotalExp());
ps.setInt(38, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.sense)).getTotalExp());
ps.setInt(39, ((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.will)).getTotalExp());
ps.setInt(40, this.totalWins);
ps.setInt(41, this.totalLosses);
ps.setInt(42, this.pvpExp);
ps.setInt(43, this.pvpPoints);
ps.setInt(44, this.reborns);
ps.setInt(45, this.apstorage);
ps.setShort(46, this.occupationId);
ps.setShort(47, this.occupationEXP);
ps.setString(48, this.name);
ps.setInt(49, this.id);
if (ps.executeUpdate() < 1) {
ps.close();
throw new DatabaseException(new StringBuilder().append("Character not in database (").append(this.id).append(")").toString());
}
ps.close();
int i;
if (this.changed_skillmacros) {
deleteWhereCharacterId(con, "DELETE FROM skillmacros WHERE characterid = ?");
for (i = 0; i < 5; ++i) {
SkillMacro macro = this.skillMacros[i];
if (macro != null) {
ps = con.prepareStatement("INSERT INTO skillmacros (characterid, skill1, skill2, skill3, name, shout, position) VALUES (?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, this.id);
ps.setInt(2, macro.getSkill1());
ps.setInt(3, macro.getSkill2());
ps.setInt(4, macro.getSkill3());
ps.setString(5, macro.getName());
ps.setInt(6, macro.getShout());
ps.setInt(7, i);
ps.execute();
ps.close();
}
}
}
Iterator i$;
if (this.changed_pokemon) {
ps = con.prepareStatement("DELETE FROM pokemon WHERE characterid = ? OR (accountid = ? AND active = 0)");
ps.setInt(1, this.id);
ps.setInt(2, this.accountid);
ps.execute();
ps.close();
ps = con.prepareStatement("INSERT INTO pokemon (characterid, level, exp, monsterid, name, nature, active, accountid, itemid, gender, hpiv, atkiv, defiv, spatkiv, spdefiv, speediv, evaiv, acciv, ability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
Battler macro;
for (i = 0; i < this.battlers.length; ++i) {
macro = this.battlers[i];
if (macro != null) {
ps.setInt(1, this.id);
ps.setInt(2, macro.getLevel());
ps.setInt(3, macro.getExp());
ps.setInt(4, macro.getMonsterId());
ps.setString(5, macro.getName());
ps.setInt(6, macro.getNature().ordinal());
ps.setInt(7, 1);
ps.setInt(8, this.accountid);
ps.setInt(9, (macro.getItem() == null) ? 0 : macro.getItem().id);
ps.setByte(10, macro.getGender());
ps.setByte(11, macro.getIV(BattleConstants.PokemonStat.HP));
ps.setByte(12, macro.getIV(BattleConstants.PokemonStat.ATK));
ps.setByte(13, macro.getIV(BattleConstants.PokemonStat.DEF));
ps.setByte(14, macro.getIV(BattleConstants.PokemonStat.SPATK));
ps.setByte(15, macro.getIV(BattleConstants.PokemonStat.SPDEF));
ps.setByte(16, macro.getIV(BattleConstants.PokemonStat.SPEED));
ps.setByte(17, macro.getIV(BattleConstants.PokemonStat.EVA));
ps.setByte(18, macro.getIV(BattleConstants.PokemonStat.ACC));
ps.setByte(19, macro.getAbilityIndex());
ps.execute();
}
}
for (i$ = this.boxed.iterator(); i$.hasNext(); ) { macro = (Battler)i$.next();
ps.setInt(1, this.id);
ps.setInt(2, macro.getLevel());
ps.setInt(3, macro.getExp());
ps.setInt(4, macro.getMonsterId());
ps.setString(5, macro.getName());
ps.setInt(6, macro.getNature().ordinal());
ps.setInt(7, 0);
ps.setInt(8, this.accountid);
ps.setInt(9, (macro.getItem() == null) ? 0 : macro.getItem().id);
ps.setByte(10, macro.getGender());
ps.setByte(11, macro.getIV(BattleConstants.PokemonStat.HP));
ps.setByte(12, macro.getIV(BattleConstants.PokemonStat.ATK));
ps.setByte(13, macro.getIV(BattleConstants.PokemonStat.DEF));
ps.setByte(14, macro.getIV(BattleConstants.PokemonStat.SPATK));
ps.setByte(15, macro.getIV(BattleConstants.PokemonStat.SPDEF));
ps.setByte(16, macro.getIV(BattleConstants.PokemonStat.SPEED));
ps.setByte(17, macro.getIV(BattleConstants.PokemonStat.EVA));
ps.setByte(18, macro.getIV(BattleConstants.PokemonStat.ACC));
ps.setByte(19, macro.getAbilityIndex());
ps.execute();
}
ps.close();
}
deleteWhereCharacterId(con, "DELETE FROM inventoryslot WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO inventoryslot (characterid, `equip`, `use`, `setup`, `etc`, `cash`) VALUES (?, ?, ?, ?, ?, ?)");
ps.setInt(1, this.id);
ps.setByte(2, getInventory(MapleInventoryType.EQUIP).getSlotLimit());
ps.setByte(3, getInventory(MapleInventoryType.USE).getSlotLimit());
ps.setByte(4, getInventory(MapleInventoryType.SETUP).getSlotLimit());
ps.setByte(5, getInventory(MapleInventoryType.ETC).getSlotLimit());
ps.setByte(6, getInventory(MapleInventoryType.CASH).getSlotLimit());
ps.execute();
ps.close();
saveInventory(con);
if (this.changed_questinfo) {
deleteWhereCharacterId(con, "DELETE FROM questinfo WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO questinfo (`characterid`, `quest`, `customData`) VALUES (?, ?, ?)");
ps.setInt(1, this.id);
for (Map.Entry q : this.questinfo.entrySet()) {
ps.setInt(2, ((Integer)q.getKey()).intValue());
ps.setString(3, (String)q.getValue());
ps.execute();
}
ps.close();
}
deleteWhereCharacterId(con, "DELETE FROM queststatus WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `forfeited`, `customData`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?)", 1);
pse = con.prepareStatement("INSERT INTO queststatusmobs VALUES (DEFAULT, ?, ?, ?)");
ps.setInt(1, this.id);
for (MapleQuestStatus q : this.quests.values()) {
ps.setInt(2, q.getQuest().getId());
ps.setInt(3, q.getStatus());
ps.setInt(4, (int)(q.getCompletionTime() / 1000L));
ps.setInt(5, q.getForfeited());
ps.setString(6, q.getCustomData());
ps.execute();
rs = ps.getGeneratedKeys();
if (q.hasMobKills()) {
rs.next();
for (i$ = q.getMobKills().keySet().iterator(); i$.hasNext(); ) { int mob = ((Integer)i$.next()).intValue();
pse.setInt(1, rs.getInt(1));
pse.setInt(2, mob);
pse.setInt(3, q.getMobKills(mob));
pse.execute();
}
}
rs.close();
}
ps.close();
pse.close();
if (this.changed_skills) {
deleteWhereCharacterId(con, "DELETE FROM skills WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO skills (characterid, skillid, skilllevel, masterlevel, expiration, slot, equipped) VALUES (?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, this.id);
for (Map.Entry skill : this.skills.entrySet()) {
if (GameConstants.isApplicableSkill(((Skill)skill.getKey()).getId())) {
ps.setInt(2, ((Skill)skill.getKey()).getId());
ps.setInt(3, ((SkillEntry)skill.getValue()).skillevel);
ps.setByte(4, ((SkillEntry)skill.getValue()).masterlevel);
ps.setLong(5, ((SkillEntry)skill.getValue()).expiration);
ps.setByte(6, ((SkillEntry)skill.getValue()).slot);
ps.setByte(7, ((SkillEntry)skill.getValue()).equipped);
ps.execute();
}
}
ps.close();
}
List<MapleCoolDownValueHolder> cd = getCooldowns();
if ((dc) && (cd.size() > 0)) {
ps = con.prepareStatement("INSERT INTO skills_cooldowns (charid, SkillID, StartTime, length) VALUES (?, ?, ?, ?)");
ps.setInt(1, getId());
for (MapleCoolDownValueHolder cooling : cd) {
ps.setInt(2, cooling.skillId);
ps.setLong(3, cooling.startTime);
ps.setLong(4, cooling.length);
ps.execute();
}
ps.close();
}
if (this.changed_savedlocations) {
deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO savedlocations (characterid, `locationtype`, `map`) VALUES (?, ?, ?)");
ps.setInt(1, this.id);
for (SavedLocationType savedLocationType : SavedLocationType.values()) {
if (this.savedLocations[savedLocationType.getValue()] != -1) {
ps.setInt(2, savedLocationType.getValue());
ps.setInt(3, this.savedLocations[savedLocationType.getValue()]);
ps.execute();
}
}
ps.close();
}
if (this.changed_achievements) {
ps = con.prepareStatement("DELETE FROM achievements WHERE accountid = ?");
ps.setInt(1, this.accountid);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("INSERT INTO achievements(charid, achievementid, accountid) VALUES(?, ?, ?)");
for (Integer achid : this.finishedAchievements) {
ps.setInt(1, this.id);
ps.setInt(2, achid.intValue());
ps.setInt(3, this.accountid);
ps.execute();
}
ps.close();
}
if (this.changed_reports) {
deleteWhereCharacterId(con, "DELETE FROM reports WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO reports VALUES(DEFAULT, ?, ?, ?)");
for (Map.Entry achid : this.reports.entrySet()) {
ps.setInt(1, this.id);
ps.setByte(2, ((ReportType)achid.getKey()).i);
ps.setInt(3, ((Integer)achid.getValue()).intValue());
ps.execute();
}
ps.close();
}
if (this.buddylist.changed()) {
deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`) VALUES (?, ?, ?)");
ps.setInt(1, this.id);
for (BuddylistEntry entry : this.buddylist.getBuddies()) {
ps.setInt(2, entry.getCharacterId());
ps.setInt(3, (entry.isVisible()) ? 0 : 1);
ps.execute();
}
ps.close();
this.buddylist.setChanged(false);
}
ps = con.prepareStatement("UPDATE accounts SET `ACash` = ?, `mPoints` = ?, `points` = ?, `vpoints` = ? WHERE id = ?");
ps.setInt(1, this.acash);
ps.setInt(2, this.maplepoints);
ps.setInt(3, this.points);
ps.setInt(4, this.vpoints);
ps.setInt(5, this.client.getAccID());
ps.executeUpdate();
ps.close();
if (this.storage != null) {
this.storage.saveToDB();
}
if (this.cs != null) {
this.cs.save();
}
PlayerNPC.updateByCharId(this);
this.keylayout.saveKeys(this.id);
this.mount.saveMount(this.id);
this.monsterbook.saveCards(this.accountid);
deleteWhereCharacterId(con, "DELETE FROM familiars WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO familiars (characterid, expiry, name, fatigue, vitality, familiar) VALUES (?, ?, ?, ?, ?, ?)");
ps.setInt(1, this.id);
for (MonsterFamiliar f : this.familiars.values()) {
ps.setLong(2, f.getExpiry());
ps.setString(3, f.getName());
ps.setInt(4, f.getFatigue());
ps.setByte(5, f.getVitality());
ps.setInt(6, f.getFamiliar());
ps.executeUpdate();
}
ps.close();
deleteWhereCharacterId(con, "DELETE FROM imps WHERE characterid = ?");
ps = con.prepareStatement("INSERT INTO imps (characterid, itemid, closeness, fullness, state, level) VALUES (?, ?, ?, ?, ?, ?)");
ps.setInt(1, this.id);
for (i = 0; i < this.imps.length; ++i) {
if (this.imps[i] != null) {
ps.setInt(2, this.imps[i].getItemId());
ps.setShort(3, this.imps[i].getCloseness());
ps.setShort(4, this.imps[i].getFullness());
ps.setByte(5, this.imps[i].getState());
ps.setByte(6, this.imps[i].getLevel());
ps.executeUpdate();
}
}
ps.close();
if (this.changed_wishlist) {
deleteWhereCharacterId(con, "DELETE FROM wishlist WHERE characterid = ?");
for (i = 0; i < getWishlistSize(); ++i) {
ps = con.prepareStatement("INSERT INTO wishlist(characterid, sn) VALUES(?, ?) ");
ps.setInt(1, getId());
ps.setInt(2, this.wishlist[i]);
ps.execute();
ps.close();
}
}
if (this.changed_trocklocations) {
deleteWhereCharacterId(con, "DELETE FROM trocklocations WHERE characterid = ?");
for (i = 0; i < this.rocks.length; ++i) {
if (this.rocks[i] != 999999999) {
ps = con.prepareStatement("INSERT INTO trocklocations(characterid, mapid) VALUES(?, ?) ");
ps.setInt(1, getId());
ps.setInt(2, this.rocks[i]);
ps.execute();
ps.close();
}
}
}
if (this.changed_regrocklocations) {
deleteWhereCharacterId(con, "DELETE FROM regrocklocations WHERE characterid = ?");
for (i = 0; i < this.regrocks.length; ++i) {
if (this.regrocks[i] != 999999999) {
ps = con.prepareStatement("INSERT INTO regrocklocations(characterid, mapid) VALUES(?, ?) ");
ps.setInt(1, getId());
ps.setInt(2, this.regrocks[i]);
ps.execute();
ps.close();
}
}
}
if (this.changed_hyperrocklocations) {
deleteWhereCharacterId(con, "DELETE FROM hyperrocklocations WHERE characterid = ?");
for (i = 0; i < this.hyperrocks.length; ++i) {
if (this.hyperrocks[i] != 999999999) {
ps = con.prepareStatement("INSERT INTO hyperrocklocations(characterid, mapid) VALUES(?, ?) ");
ps.setInt(1, getId());
ps.setInt(2, this.hyperrocks[i]);
ps.execute();
ps.close();
}
}
}
if (this.changed_extendedSlots) {
deleteWhereCharacterId(con, "DELETE FROM extendedSlots WHERE characterid = ?");
for (i$ = this.extendedSlots.iterator(); i$.hasNext(); ) { i = ((Integer)i$.next()).intValue();
if (getInventory(MapleInventoryType.ETC).findById(i) != null) {
ps = con.prepareStatement("INSERT INTO extendedSlots(characterid, itemId) VALUES(?, ?) ");
ps.setInt(1, getId());
ps.setInt(2, i);
ps.execute();
ps.close();
}
}
}
this.changed_wishlist = false;
this.changed_trocklocations = false;
this.changed_regrocklocations = false;
this.changed_hyperrocklocations = false;
this.changed_skillmacros = false;
this.changed_savedlocations = false;
this.changed_pokemon = false;
this.changed_questinfo = false;
this.changed_achievements = false;
this.changed_extendedSlots = false;
this.changed_skills = false;
this.changed_reports = false;
con.commit();
} catch (Exception e) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", e);
e.printStackTrace();
System.err.println(new StringBuilder().append(MapleClient.getLogMessage(this, "[charsave] Error saving character data")).append(e).toString());
try {
con.rollback();
} catch (SQLException ex) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", ex);
System.err.println(new StringBuilder().append(MapleClient.getLogMessage(this, "[charsave] Error Rolling Back")).append(e).toString());
}
} finally {
try {
if (ps != null) {
ps.close();
}
if (pse != null) {
pse.close();
}
if (rs != null) {
rs.close();
}
con.setAutoCommit(true);
con.setTransactionIsolation(4);
} catch (SQLException e) {
FileoutputUtil.outputFileError("Log_Packet_Except.rtf", e);
System.err.println(new StringBuilder().append(MapleClient.getLogMessage(this, "[charsave] Error going back to autocommit mode")).append(e).toString());
}
}
}
private void deleteWhereCharacterId(Connection con, String sql) throws SQLException {
deleteWhereCharacterId(con, sql, this.id);
}
public static void deleteWhereCharacterId(Connection con, String sql, int id) throws SQLException {
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
ps.close();
}
public static void deleteWhereCharacterId_NoLock(Connection con, String sql, int id) throws SQLException {
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, id);
ps.execute();
ps.close();
}
public void saveInventory(Connection con) throws SQLException {
List listing = new ArrayList();
for (MapleInventory iv : this.inventory) {
for (Item item : iv.list()) {
listing.add(new Pair(item, iv.getType()));
}
}
if (con != null)
ItemLoader.INVENTORY.saveItems(listing, con, this.id);
else
ItemLoader.INVENTORY.saveItems(listing, this.id);
}
public final PlayerStats getStat()
{
return this.stats;
}
public final void QuestInfoPacket(MaplePacketLittleEndianWriter mplew) {
mplew.writeShort(this.questinfo.size());
for (Map.Entry q : this.questinfo.entrySet()) {
mplew.writeShort(((Integer)q.getKey()).intValue());
mplew.writeMapleAsciiString((q.getValue() == null) ? "" : (String)q.getValue());
}
}
public final void updateInfoQuest(int questid, String data) {
this.questinfo.put(Integer.valueOf(questid), data);
this.changed_questinfo = true;
this.client.getSession().write(CWvsContext.InfoPacket.updateInfoQuest(questid, data));
}
public final String getInfoQuest(int questid) {
if (this.questinfo.containsKey(Integer.valueOf(questid))) {
return ((String)this.questinfo.get(Integer.valueOf(questid)));
}
return "";
}
public final int getNumQuest() {
int i = 0;
for (MapleQuestStatus q : this.quests.values()) {
if ((q.getStatus() == 2) && (!(q.isCustom()))) {
++i;
}
}
return i;
}
public final byte getQuestStatus(int quest) {
MapleQuest qq = MapleQuest.getInstance(quest);
if (getQuestNoAdd(qq) == null) {
return 0;
}
return getQuestNoAdd(qq).getStatus();
}
public final MapleQuestStatus getQuest(MapleQuest quest) {
if (!(this.quests.containsKey(quest))) {
return new MapleQuestStatus(quest, 0);
}
return ((MapleQuestStatus)this.quests.get(quest));
}
public final void setQuestAdd(MapleQuest quest, byte status, String customData) {
if (!(this.quests.containsKey(quest))) {
MapleQuestStatus stat = new MapleQuestStatus(quest, status);
stat.setCustomData(customData);
this.quests.put(quest, stat);
}
}
public final MapleQuestStatus getQuestNAdd(MapleQuest quest) {
if (!(this.quests.containsKey(quest))) {
MapleQuestStatus status = new MapleQuestStatus(quest, 0);
this.quests.put(quest, status);
return status;
}
return ((MapleQuestStatus)this.quests.get(quest));
}
public final MapleQuestStatus getQuestNoAdd(MapleQuest quest) {
return ((MapleQuestStatus)this.quests.get(quest));
}
public final MapleQuestStatus getQuestRemove(MapleQuest quest) {
return ((MapleQuestStatus)this.quests.remove(quest));
}
public final void updateQuest(MapleQuestStatus quest) {
updateQuest(quest, false);
}
public final void updateQuest(MapleQuestStatus quest, boolean update) {
this.quests.put(quest.getQuest(), quest);
if (!(quest.isCustom())) {
this.client.getSession().write(CWvsContext.InfoPacket.updateQuest(quest));
if ((quest.getStatus() == 1) && (!(update)))
this.client.getSession().write(CField.updateQuestInfo(this, quest.getQuest().getId(), quest.getNpc(), (byte) 10));
}
}
public final Map<Integer, String> getInfoQuest_Map()
{
return this.questinfo;
}
public final Map<MapleQuest, MapleQuestStatus> getQuest_Map() {
return this.quests;
}
public Integer getBuffedValue(MapleBuffStat effect) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
return ((mbsvh == null) ? null : Integer.valueOf(mbsvh.value));
}
public final Integer getBuffedSkill_X(MapleBuffStat effect) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
if (mbsvh == null) {
return null;
}
return Integer.valueOf(mbsvh.effect.getX());
}
public final Integer getBuffedSkill_Y(MapleBuffStat effect) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
if (mbsvh == null) {
return null;
}
return Integer.valueOf(mbsvh.effect.getY());
}
public boolean isBuffFrom(MapleBuffStat stat, Skill skill) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(stat);
if ((mbsvh == null) || (mbsvh.effect == null)) {
return false;
}
return ((mbsvh.effect.isSkill()) && (mbsvh.effect.getSourceId() == skill.getId()));
}
public int getBuffSource(MapleBuffStat stat) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(stat);
return ((mbsvh == null) ? -1 : mbsvh.effect.getSourceId());
}
public int getTrueBuffSource(MapleBuffStat stat) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(stat);
return ((mbsvh.effect.isSkill()) ? mbsvh.effect.getSourceId() : (mbsvh == null) ? -1 : -mbsvh.effect.getSourceId());
}
public int getItemQuantity(int itemid, boolean checkEquipped) {
int possesed = this.inventory[GameConstants.getInventoryType(itemid).ordinal()].countById(itemid);
if (checkEquipped) {
possesed += this.inventory[MapleInventoryType.EQUIPPED.ordinal()].countById(itemid);
}
return possesed;
}
public void setBuffedValue(MapleBuffStat effect, int value) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
if (mbsvh == null) {
return;
}
mbsvh.value = value;
}
public void setSchedule(MapleBuffStat effect, ScheduledFuture<?> sched) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
if (mbsvh == null) {
return;
}
mbsvh.schedule.cancel(false);
mbsvh.schedule = sched;
}
public Long getBuffedStarttime(MapleBuffStat effect) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
return ((mbsvh == null) ? null : Long.valueOf(mbsvh.startTime));
}
public MapleStatEffect getStatForBuff(MapleBuffStat effect) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.get(effect);
return ((mbsvh == null) ? null : mbsvh.effect);
}
public void doDragonBlood() {
MapleStatEffect bloodEffect = getStatForBuff(MapleBuffStat.DRAGONBLOOD);
if (bloodEffect == null) {
this.lastDragonBloodTime = 0L;
return;
}
prepareDragonBlood();
if (this.stats.getHp() - bloodEffect.getX() <= 1) {
cancelBuffStats(new MapleBuffStat[] { MapleBuffStat.DRAGONBLOOD });
} else {
addHP(-bloodEffect.getX());
this.client.getSession().write(CField.EffectPacket.showOwnBuffEffect(bloodEffect.getSourceId(), 7, getLevel(), bloodEffect.getLevel()));
this.map.broadcastMessage(this, CField.EffectPacket.showBuffeffect(getId(), bloodEffect.getSourceId(), 7, getLevel(), bloodEffect.getLevel()), false);
}
}
public final boolean canBlood(long now) {
return ((this.lastDragonBloodTime > 0L) && (this.lastDragonBloodTime + 4000L < now));
}
private void prepareDragonBlood() {
this.lastDragonBloodTime = System.currentTimeMillis();
}
public void doRecovery() {
MapleStatEffect bloodEffect = getStatForBuff(MapleBuffStat.RECOVERY);
if (bloodEffect == null) {
bloodEffect = getStatForBuff(MapleBuffStat.MECH_CHANGE);
if (bloodEffect == null) {
this.lastRecoveryTime = 0L;
return; }
if (bloodEffect.getSourceId() == 35121005) {
prepareRecovery();
if (this.stats.getMp() < bloodEffect.getU()) {
cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
cancelEffectFromBuffStat(MapleBuffStat.MECH_CHANGE);
} else {
addMP(-bloodEffect.getU());
}
}
} else {
prepareRecovery();
if (this.stats.getHp() >= this.stats.getCurrentMaxHp())
cancelEffectFromBuffStat(MapleBuffStat.RECOVERY);
else
healHP(bloodEffect.getX());
}
}
public final boolean canRecover(long now)
{
return ((this.lastRecoveryTime > 0L) && (this.lastRecoveryTime + 5000L < now));
}
private void prepareRecovery() {
this.lastRecoveryTime = System.currentTimeMillis();
}
public void startMapTimeLimitTask(int time, final MapleMap to) {
if (time <= 0) {
time = 1;
}
this.client.getSession().write(CField.getClock(time));
final MapleMap ourMap = getMap();
time *= 1000;
this.mapTimeLimitTask = MapTimer.getInstance().register(new Runnable()
{
public void run()
{
if (ourMap.getId() == 180000002) {
MapleCharacter.this.getQuestNAdd(MapleQuest.getInstance(123455)).setCustomData(String.valueOf(System.currentTimeMillis()));
MapleCharacter.this.getQuestNAdd(MapleQuest.getInstance(123456)).setCustomData("0");
}
MapleCharacter.this.changeMap(to, to.getPortal(0));
}
}
, time, time);
}
public boolean canDOT(long now)
{
return ((this.lastDOTTime > 0L) && (this.lastDOTTime + 8000L < now));
}
public boolean hasDOT() {
return (this.dotHP > 0);
}
public void doDOT() {
addHP(-(this.dotHP * 4));
this.dotHP = 0;
this.lastDOTTime = 0L;
}
public void setDOT(int d, int source, int sourceLevel) {
this.dotHP = d;
addHP(-(this.dotHP * 4));
this.map.broadcastMessage(CField.getPVPMist(this.id, source, sourceLevel, d));
this.lastDOTTime = System.currentTimeMillis();
}
public void startFishingTask() {
cancelFishingTask();
this.lastFishingTime = System.currentTimeMillis();
}
public boolean canFish(long now) {
return ((this.lastFishingTime > 0L) && (this.lastFishingTime + GameConstants.getFishingTime(false, isGM()) < now));
}
public void doFish(long now) {
this.lastFishingTime = now;
if ((this.client == null) || (this.client.getPlayer() == null) || (!(this.client.isReceiving())) || (!(haveItem(2270008, 1, false, true))) || (!(GameConstants.isFishingMap(getMapId()))) || (this.chair <= 0)) {
cancelFishingTask();
return;
}
MapleInventoryManipulator.removeById(this.client, MapleInventoryType.USE, 2270008, 1, false, false);
boolean passed = false;
while (!(passed)) {
int randval = RandomRewards.getFishingReward();
switch (randval)
{
case 0:
int money = Randomizer.rand(10, 50000);
gainMeso(money, true);
passed = true;
break;
case 1:
int experi = Math.min(Randomizer.nextInt(Math.abs(getNeededExp() / 200) + 1), 500000);
gainExp(experi, true, false, true);
passed = true;
break;
default:
if (MapleItemInformationProvider.getInstance().itemExists(randval)) {
MapleInventoryManipulator.addById(this.client, randval, (short) 1, new StringBuilder().append("Fishing on ").append(FileoutputUtil.CurrentReadable_Date()).toString());
passed = true;
}
}
}
}
public void cancelMapTimeLimitTask()
{
if (this.mapTimeLimitTask != null) {
this.mapTimeLimitTask.cancel(false);
this.mapTimeLimitTask = null;
}
}
public int getNeededExp() {
return GameConstants.getExpNeededForLevel(this.level);
}
public void cancelFishingTask() {
this.lastFishingTime = 0L;
}
public void registerEffect(MapleStatEffect effect, long starttime, ScheduledFuture<?> schedule, int from) {
registerEffect(effect, starttime, schedule, effect.getStatups(), false, effect.getDuration(), from);
}
public void registerEffect(MapleStatEffect effect, long starttime, ScheduledFuture<?> schedule, Map<MapleBuffStat, Integer> statups, boolean silent, int localDuration, int cid) {
if (effect.isHide())
this.map.broadcastMessage(this, CField.removePlayerFromMap(getId()), false);
else if (effect.isDragonBlood())
prepareDragonBlood();
else if (effect.isRecovery())
prepareRecovery();
else if (effect.isBerserk())
checkBerserk();
else if (effect.isMonsterRiding_()) {
getMount().startSchedule();
}
int clonez = 0;
for (Entry<MapleBuffStat, Integer> statup : statups.entrySet()) {
if (statup.getKey() == MapleBuffStat.ILLUSION) {
clonez = ((Integer)statup.getValue()).intValue();
}
int value = ((Integer)statup.getValue()).intValue();
if (statup.getKey() == MapleBuffStat.MONSTER_RIDING) {
if ((effect.getSourceId() == 5221006) && (this.battleshipHP <= 0)) {
this.battleshipHP = maxBattleshipHP(effect.getSourceId());
}
removeFamiliar();
}
this.effects.put(statup.getKey(), new MapleBuffStatValueHolder(effect, starttime, schedule, value, localDuration, cid));
}
if (clonez > 0) {
int cloneSize = Math.max(getNumClones(), getCloneSize());
if (clonez > cloneSize) {
for (int i = 0; i < clonez - cloneSize; ++i) {
cloneLook();
}
}
}
if (!(silent))
this.stats.recalcLocalStats(this);
}
public List<MapleBuffStat> getBuffStats(MapleStatEffect effect, long startTime)
{
List bstats = new ArrayList();
Map<MapleBuffStat, MapleBuffStatValueHolder> allBuffs = new EnumMap<MapleBuffStat, MapleBuffStatValueHolder>(effects);
for (Map.Entry stateffect : allBuffs.entrySet()) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)stateffect.getValue();
if ((mbsvh.effect.sameSource(effect)) && (((startTime == -1L) || (startTime == mbsvh.startTime) || (((MapleBuffStat)stateffect.getKey()).canStack())))) {
bstats.add(stateffect.getKey());
}
}
return bstats;
}
private boolean deregisterBuffStats(List<MapleBuffStat> stats) {
boolean clonez = false;
List<MapleBuffStatValueHolder> effectsToCancel = new ArrayList(stats.size());
for (MapleBuffStat stat : stats) {
MapleBuffStatValueHolder mbsvh = (MapleBuffStatValueHolder)this.effects.remove(stat);
if (mbsvh != null) {
boolean addMbsvh = true;
for (MapleBuffStatValueHolder contained : effectsToCancel) {
if ((mbsvh.startTime == contained.startTime) && (contained.effect == mbsvh.effect)) {
addMbsvh = false;
}
}
if (addMbsvh) {
effectsToCancel.add(mbsvh);
}
if ((stat == MapleBuffStat.SUMMON) || (stat == MapleBuffStat.PUPPET) || (stat == MapleBuffStat.REAPER) || (stat == MapleBuffStat.BEHOLDER) || (stat == MapleBuffStat.DAMAGE_BUFF) || (stat == MapleBuffStat.RAINING_MINES) || (stat == MapleBuffStat.ANGEL_ATK)) {
int summonId = mbsvh.effect.getSourceId();
List<MapleSummon> toRemove = new ArrayList();
this.visibleMapObjectsLock.writeLock().lock();
this.summonsLock.writeLock().lock();
try {
for (MapleSummon summon : this.summons) {
if ((summon.getSkill() == summonId) || ((stat == MapleBuffStat.RAINING_MINES) && (summonId == 33101008)) || ((summonId == 35121009) && (summon.getSkill() == 35121011)) || ((((summonId == 86) || (summonId == 88) || (summonId == 91))) && (((summon.getSkill() == summonId + 999) || ((((summonId == 1085) || (summonId == 1087) || (summonId == 1090) || (summonId == 1179))) && (summon.getSkill() == summonId - 999)))))) {
this.map.broadcastMessage(CField.SummonPacket.removeSummon(summon, true));
this.map.removeMapObject(summon);
this.visibleMapObjects.remove(summon);
toRemove.add(summon);
}
}
for (MapleSummon s : toRemove)
this.summons.remove(s);
}
finally {
this.summonsLock.writeLock().unlock();
this.visibleMapObjectsLock.writeLock().unlock();
}
if ((summonId == 3111005) || (summonId == 3211005))
cancelEffectFromBuffStat(MapleBuffStat.SPIRIT_LINK);
}
else if (stat == MapleBuffStat.DRAGONBLOOD) {
this.lastDragonBloodTime = 0L;
} else if ((stat == MapleBuffStat.RECOVERY) || (mbsvh.effect.getSourceId() == 35121005)) {
this.lastRecoveryTime = 0L;
} else if ((stat == MapleBuffStat.HOMING_BEACON) || (stat == MapleBuffStat.ARCANE_AIM)) {
this.linkMobs.clear();
} else if (stat == MapleBuffStat.ILLUSION) {
disposeClones();
clonez = true;
}
}
}
for (MapleBuffStatValueHolder cancelEffectCancelTasks : effectsToCancel) {
if ((getBuffStats(cancelEffectCancelTasks.effect, cancelEffectCancelTasks.startTime).size() == 0) &&
(cancelEffectCancelTasks.schedule != null)) {
cancelEffectCancelTasks.schedule.cancel(false);
}
}
return clonez;
}
public void cancelEffect(MapleStatEffect effect, boolean overwrite, long startTime)
{
if (effect == null) {
return;
}
cancelEffect(effect, overwrite, startTime, effect.getStatups());
}
public void cancelEffect(MapleStatEffect effect, boolean overwrite, long startTime, Map<MapleBuffStat, Integer> statups) {
if (effect == null)
return;
List buffstats;
if (!(overwrite))
buffstats = getBuffStats(effect, startTime);
else {
buffstats = new ArrayList(statups.keySet());
}
if (buffstats.size() <= 0) {
return;
}
if ((effect.isInfinity()) && (getBuffedValue(MapleBuffStat.INFINITY) != null)) {
int duration = Math.max(effect.getDuration(), effect.alchemistModifyVal(this, effect.getDuration(), false));
long start = getBuffedStarttime(MapleBuffStat.INFINITY).longValue();
duration += (int)(start - System.currentTimeMillis());
if (duration > 0) {
int neworbcount = getBuffedValue(MapleBuffStat.INFINITY).intValue() + effect.getDamage();
Map stat = new EnumMap(MapleBuffStat.class);
stat.put(MapleBuffStat.INFINITY, Integer.valueOf(neworbcount));
setBuffedValue(MapleBuffStat.INFINITY, neworbcount);
this.client.getSession().write(CWvsContext.BuffPacket.giveBuff(effect.getSourceId(), duration, stat, effect));
addHP((int)(effect.getHpR() * this.stats.getCurrentMaxHp()));
addMP((int)(effect.getMpR() * this.stats.getCurrentMaxMp(getJob())));
setSchedule(MapleBuffStat.INFINITY, BuffTimer.getInstance().schedule(new MapleStatEffect.CancelEffectAction(this, effect, start, stat), effect.alchemistModifyVal(this, 4000, false)));
return;
}
}
boolean clonez = deregisterBuffStats(buffstats);
if (effect.isMagicDoor())
{
if (!(getDoors().isEmpty())) {
removeDoor();
silentPartyUpdate(); }
}
else if (effect.isMechDoor()) {
if (!(getMechDoors().isEmpty()))
removeMechDoor();
}
else if (effect.isMonsterRiding_())
getMount().cancelSchedule();
else if (effect.isMonsterRiding())
cancelEffectFromBuffStat(MapleBuffStat.MECH_CHANGE);
else if (effect.isAranCombo()) {
this.combo = 0;
}
cancelPlayerBuffs(buffstats, overwrite);
if ((!(overwrite)) &&
(effect.isHide()) && (this.client.getChannelServer().getPlayerStorage().getCharacterById(getId()) != null)) {
this.map.broadcastMessage(this, CField.spawnPlayerMapobject(this), false);
for (MaplePet pet : this.pets) {
if (pet.getSummoned()) {
this.map.broadcastMessage(this, PetPacket.showPet(this, pet, false, false), false);
}
}
for (WeakReference<MapleCharacter> chr : this.clones) {
if (chr.get() != null) {
this.map.broadcastMessage((MapleCharacter)chr.get(), CField.spawnPlayerMapobject((MapleCharacter)chr.get()), false);
}
}
}
if ((effect.getSourceId() == 35121013) && (!(overwrite))) {
SkillFactory.getSkill(35121005).getEffect(getTotalSkillLevel(35121005)).applyTo(this);
}
if (!(clonez))
for (WeakReference<MapleCharacter> chr : this.clones)
if (chr.get() != null)
((MapleCharacter)chr.get()).cancelEffect(effect, overwrite, startTime);
}
public void cancelBuffStats(MapleBuffStat[] stat)
{
List buffStatList = Arrays.asList(stat);
deregisterBuffStats(buffStatList);
cancelPlayerBuffs(buffStatList, false);
}
public void cancelEffectFromBuffStat(MapleBuffStat stat) {
if (this.effects.get(stat) != null)
cancelEffect(((MapleBuffStatValueHolder)this.effects.get(stat)).effect, false, -1L);
}
public void cancelEffectFromBuffStat(MapleBuffStat stat, int from)
{
if ((this.effects.get(stat) != null) && (((MapleBuffStatValueHolder)this.effects.get(stat)).cid == from))
cancelEffect(((MapleBuffStatValueHolder)this.effects.get(stat)).effect, false, -1L);
}
private void cancelPlayerBuffs(List<MapleBuffStat> buffstats, boolean overwrite)
{
boolean write = (this.client != null) && (this.client.getChannelServer() != null) && (this.client.getChannelServer().getPlayerStorage().getCharacterById(getId()) != null);
if (buffstats.contains(MapleBuffStat.HOMING_BEACON)) {
this.client.getSession().write(CWvsContext.BuffPacket.cancelHoming());
} else {
if (overwrite) {
List z = new ArrayList();
for (MapleBuffStat s : buffstats) {
if (s.canStack()) {
z.add(s);
}
}
if (z.size() > 0)
buffstats = z;
else
return;
}
else if (write) {
this.stats.recalcLocalStats(this);
}
this.client.getSession().write(CWvsContext.BuffPacket.cancelBuff(buffstats));
this.map.broadcastMessage(this, CWvsContext.BuffPacket.cancelForeignBuff(getId(), buffstats), false);
}
}
public void dispel() {
if (!(isHidden())) {
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
if ((mbsvh.effect.isSkill()) && (mbsvh.schedule != null) && (!(mbsvh.effect.isMorph())) && (!(mbsvh.effect.isGmBuff())) && (!(mbsvh.effect.isMonsterRiding())) && (!(mbsvh.effect.isMechChange())) && (!(mbsvh.effect.isEnergyCharge())) && (!(mbsvh.effect.isAranCombo())))
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
}
public void dispelSkill(int skillid)
{
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
if ((mbsvh.effect.isSkill()) && (mbsvh.effect.getSourceId() == skillid)) {
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
return;
}
}
public void dispelSummons()
{
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
if (mbsvh.effect.getSummonMovementType() != null)
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
public void dispelBuff(int skillid)
{
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
if (mbsvh.effect.getSourceId() == skillid) {
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
return;
}
}
public void cancelAllBuffs_()
{
this.effects.clear();
}
public void cancelAllBuffs() {
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
public void cancelMorphs()
{
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs) {
switch (mbsvh.effect.getSourceId())
{
case 5111005:
case 5121003:
case 13111005:
case 15111002:
return;
}
if (mbsvh.effect.isMorph()) {
if (MapConstants.isStorylineMap(getMapId())) {
return;
}
if (mbsvh.effect.isMorph()) {
disposeClones();
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
}
}
}
public int getMorphState()
{
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs) {
if (mbsvh.effect.isMorph()) {
return mbsvh.effect.getSourceId();
}
}
return -1;
}
public void silentGiveBuffs(List<PlayerBuffValueHolder> buffs) {
if (buffs == null) {
return;
}
for (PlayerBuffValueHolder mbsvh : buffs)
mbsvh.effect.silentApplyBuff(this, mbsvh.startTime, mbsvh.localDuration, mbsvh.statup, mbsvh.cid);
}
public List<PlayerBuffValueHolder> getAllBuffs()
{
List ret = new ArrayList();
Map alreadyDone = new HashMap();
LinkedList<Entry<MapleBuffStat, MapleBuffStatValueHolder>> allBuffs = new LinkedList(this.effects.entrySet());
for (Entry<MapleBuffStat, MapleBuffStatValueHolder> mbsvh : allBuffs) {
Pair<Integer, Byte> key = new Pair(Integer.valueOf(((MapleBuffStatValueHolder)mbsvh.getValue()).effect.getSourceId()), Byte.valueOf(((MapleBuffStatValueHolder)mbsvh.getValue()).effect.getLevel()));
if (alreadyDone.containsKey(key)) {
((PlayerBuffValueHolder)ret.get(((Integer)alreadyDone.get(key)).intValue())).statup.put(mbsvh.getKey(), Integer.valueOf(((MapleBuffStatValueHolder)mbsvh.getValue()).value));
} else {
alreadyDone.put(key, Integer.valueOf(ret.size()));
EnumMap list = new EnumMap(MapleBuffStat.class);
list.put((Enum)mbsvh.getKey(), Integer.valueOf(((MapleBuffStatValueHolder)mbsvh.getValue()).value));
ret.add(new PlayerBuffValueHolder(((MapleBuffStatValueHolder)mbsvh.getValue()).startTime, ((MapleBuffStatValueHolder)mbsvh.getValue()).effect, list, ((MapleBuffStatValueHolder)mbsvh.getValue()).localDuration, ((MapleBuffStatValueHolder)mbsvh.getValue()).cid));
}
}
return ret;
}
public void cancelMagicDoor() {
LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList(this.effects.values());
for (MapleBuffStatValueHolder mbsvh : allBuffs)
if (mbsvh.effect.isMagicDoor()) {
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
return;
}
}
public int getSkillLevel(int skillid)
{
return getSkillLevel(SkillFactory.getSkill(skillid));
}
public int getTotalSkillLevel(int skillid) {
return getTotalSkillLevel(SkillFactory.getSkill(skillid));
}
public final void handleEnergyCharge(int skillid, int targets) {
Skill echskill = SkillFactory.getSkill(skillid);
int skilllevel = getTotalSkillLevel(echskill);
if (skilllevel > 0) {
MapleStatEffect echeff = echskill.getEffect(skilllevel);
if (targets > 0)
if (getBuffedValue(MapleBuffStat.ENERGY_CHARGE) == null) {
echeff.applyEnergyBuff(this, true);
} else {
Integer energyLevel = getBuffedValue(MapleBuffStat.ENERGY_CHARGE);
if (energyLevel.intValue() < 10000) {
energyLevel = Integer.valueOf(energyLevel.intValue() + echeff.getX() * targets);
this.client.getSession().write(CField.EffectPacket.showOwnBuffEffect(skillid, 2, getLevel(), skilllevel));
this.map.broadcastMessage(this, CField.EffectPacket.showBuffeffect(this.id, skillid, 2, getLevel(), skilllevel), false);
if (energyLevel.intValue() >= 10000) {
energyLevel = Integer.valueOf(10000);
}
this.client.getSession().write(CWvsContext.BuffPacket.giveEnergyChargeTest(energyLevel.intValue(), echeff.getDuration() / 1000));
setBuffedValue(MapleBuffStat.ENERGY_CHARGE, Integer.valueOf(energyLevel.intValue()).intValue());
} else if (energyLevel.intValue() == 10000) {
echeff.applyEnergyBuff(this, false);
setBuffedValue(MapleBuffStat.ENERGY_CHARGE, Integer.valueOf(10001).intValue());
}
}
}
}
public final void handleBattleshipHP(int damage)
{
if (damage < 0) {
MapleStatEffect effect = getStatForBuff(MapleBuffStat.MONSTER_RIDING);
if ((effect != null) && (effect.getSourceId() == 5221006)) {
this.battleshipHP += damage;
this.client.getSession().write(CField.skillCooldown(5221999, this.battleshipHP / 10));
if (this.battleshipHP <= 0) {
this.battleshipHP = 0;
this.client.getSession().write(CField.skillCooldown(5221006, effect.getCooldown(this)));
addCooldown(5221006, System.currentTimeMillis(), effect.getCooldown(this) * 1000);
cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
}
}
}
}
public final void handleOrbgain() {
int orbcount = getBuffedValue(MapleBuffStat.COMBO).intValue();
Skill combo;
Skill advcombo;
switch (getJob())
{
case 1110:
case 1111:
case 1112:
combo = SkillFactory.getSkill(11111001);
advcombo = SkillFactory.getSkill(11110005);
break;
default:
combo = SkillFactory.getSkill(1111002);
advcombo = SkillFactory.getSkill(1120003);
}
MapleStatEffect ceffect = null;
int advComboSkillLevel = getTotalSkillLevel(advcombo);
if (advComboSkillLevel > 0)
ceffect = advcombo.getEffect(advComboSkillLevel);
else if (getSkillLevel(combo) > 0)
ceffect = combo.getEffect(getTotalSkillLevel(combo));
else {
return;
}
if (orbcount < ceffect.getX() + 1) {
int neworbcount = orbcount + 1;
if ((advComboSkillLevel > 0) && (ceffect.makeChanceResult()) &&
(neworbcount < ceffect.getX() + 1)) {
++neworbcount;
}
EnumMap stat = new EnumMap(MapleBuffStat.class);
stat.put(MapleBuffStat.COMBO, Integer.valueOf(neworbcount));
setBuffedValue(MapleBuffStat.COMBO, neworbcount);
int duration = ceffect.getDuration();
duration += (int)(getBuffedStarttime(MapleBuffStat.COMBO).longValue() - System.currentTimeMillis());
this.client.getSession().write(CWvsContext.BuffPacket.giveBuff(combo.getId(), duration, stat, ceffect));
this.map.broadcastMessage(this, CWvsContext.BuffPacket.giveForeignBuff(getId(), stat, ceffect), false);
}
}
public void handleOrbconsume(int howmany)
{
Skill combo;
switch (getJob())
{
case 1110:
case 1111:
case 1112:
combo = SkillFactory.getSkill(11111001);
break;
default:
combo = SkillFactory.getSkill(1111002);
}
if (getSkillLevel(combo) <= 0) {
return;
}
MapleStatEffect ceffect = getStatForBuff(MapleBuffStat.COMBO);
if (ceffect == null) {
return;
}
EnumMap stat = new EnumMap(MapleBuffStat.class);
stat.put(MapleBuffStat.COMBO, Integer.valueOf(Math.max(1, getBuffedValue(MapleBuffStat.COMBO).intValue() - howmany)));
setBuffedValue(MapleBuffStat.COMBO, Math.max(1, getBuffedValue(MapleBuffStat.COMBO).intValue() - howmany));
int duration = ceffect.getDuration();
duration += (int)(getBuffedStarttime(MapleBuffStat.COMBO).longValue() - System.currentTimeMillis());
this.client.getSession().write(CWvsContext.BuffPacket.giveBuff(combo.getId(), duration, stat, ceffect));
this.map.broadcastMessage(this, CWvsContext.BuffPacket.giveForeignBuff(getId(), stat, ceffect), false);
}
public void silentEnforceMaxHpMp() {
this.stats.setMp(this.stats.getMp(), this);
this.stats.setHp(this.stats.getHp(), true, this);
}
public void enforceMaxHpMp() {
Map statups = new EnumMap(MapleStat.class);
if (this.stats.getMp() > this.stats.getCurrentMaxMp(getJob())) {
this.stats.setMp(this.stats.getMp(), this);
statups.put(MapleStat.MP, Integer.valueOf(this.stats.getMp()));
}
if (this.stats.getHp() > this.stats.getCurrentMaxHp()) {
this.stats.setHp(this.stats.getHp(), this);
statups.put(MapleStat.HP, Integer.valueOf(this.stats.getHp()));
}
if (statups.size() > 0)
this.client.getSession().write(CWvsContext.updatePlayerStats(statups, this));
}
public MapleMap getMap()
{
return this.map;
}
public MonsterBook getMonsterBook() {
return this.monsterbook;
}
public void setMap(MapleMap newmap) {
this.map = newmap;
}
public void setMap(int PmapId) {
this.mapid = PmapId;
}
public int getMapId() {
if (this.map != null) {
return this.map.getId();
}
return this.mapid;
}
public byte getInitialSpawnpoint() {
return this.initialSpawnPoint;
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
public final String getBlessOfFairyOrigin() {
return this.BlessOfFairy_Origin;
}
public final String getBlessOfEmpressOrigin() {
return this.BlessOfEmpress_Origin;
}
public final short getLevel() {
return this.level;
}
public final int getFame() {
return this.fame;
}
public final int getFallCounter() {
return this.fallcounter;
}
public final MapleClient getClient() {
return this.client;
}
public final void setClient(MapleClient client) {
this.client = client;
}
public int getExp() {
return this.exp;
}
public short getRemainingAp() {
return this.remainingAp;
}
public int getRemainingSp() {
return this.remainingSp[GameConstants.getSkillBook(this.job)];
}
public int getRemainingSp(int skillbook) {
return this.remainingSp[skillbook];
}
public int[] getRemainingSps() {
return this.remainingSp;
}
public int getRemainingSpSize() {
int ret = 0;
for (int i = 0; i < this.remainingSp.length; ++i) {
if (this.remainingSp[i] > 0) {
++ret;
}
}
return ret;
}
public short getHpApUsed() {
return this.hpApUsed;
}
public boolean isHidden() {
return (getBuffSource(MapleBuffStat.DARKSIGHT) / 1000000 == 9);
}
public void setHpApUsed(short hpApUsed) {
this.hpApUsed = hpApUsed;
}
public byte getSkinColor() {
return this.skinColor;
}
public void setSkinColor(byte skinColor) {
this.skinColor = skinColor;
}
public short getJob() {
return this.job;
}
public byte getGender() {
return this.gender;
}
public int getHair() {
return this.hair;
}
public int getFace() {
return this.face;
}
public int getDemonMarking() {
return this.demonMarking;
}
public void setDemonMarking(int mark) {
this.demonMarking = mark;
}
public void setName(String name) {
this.name = name;
}
public void setExp(int exp) {
this.exp = exp;
}
public void setHair(int hair) {
this.hair = hair;
}
public void setFace(int face) {
this.face = face;
}
public void setFame(int fame) {
this.fame = fame;
}
public void setFallCounter(int fallcounter) {
this.fallcounter = fallcounter;
}
public Point getOldPosition() {
return this.old;
}
public void setOldPosition(Point x) {
this.old = x;
}
public void setRemainingAp(short remainingAp) {
this.remainingAp = remainingAp;
}
public void setRemainingSp(int remainingSp) {
this.remainingSp[GameConstants.getSkillBook(this.job)] = remainingSp;
}
public void setRemainingSp(int remainingSp, int skillbook) {
this.remainingSp[skillbook] = remainingSp;
}
public void setGender(byte gender) {
this.gender = gender;
}
public void setInvincible(boolean invinc) {
this.invincible = invinc;
}
public boolean isInvincible() {
return this.invincible;
}
public CheatTracker getCheatTracker() {
return this.anticheat;
}
public BuddyList getBuddylist() {
return this.buddylist;
}
public void addFame(int famechange) {
this.fame += famechange;
getTrait(MapleTrait.MapleTraitType.charm).addLocalExp(famechange);
if (this.fame >= 50)
finishAchievement(7);
}
public void updateFame()
{
updateSingleStat(MapleStat.FAME, this.fame);
}
public void changeMapBanish(int mapid, String portal, String msg) {
dropMessage(5, msg);
MapleMap map = this.client.getChannelServer().getMapFactory().getMap(mapid);
changeMap(map, map.getPortal(portal));
}
public void changeMap(MapleMap to, Point pos) {
changeMapInternal(to, pos, CField.getWarpToMap(to, 128, this), null);
}
public void changeMap(int map, int portal) {
MapleMap warpMap = this.client.getChannelServer().getMapFactory().getMap(map);
changeMap(warpMap, warpMap.getPortal(portal));
}
public void changeMap(int map) {
changeMap(map, 0);
}
public void changeMap(MapleMap to) {
changeMapInternal(to, to.getPortal(0).getPosition(), CField.getWarpToMap(to, 0, this), to.getPortal(0));
}
public void changeMap(MapleMap to, MaplePortal pto) {
changeMapInternal(to, pto.getPosition(), CField.getWarpToMap(to, pto.getId(), this), null);
}
public void changeMapPortal(MapleMap to, MaplePortal pto) {
changeMapInternal(to, pto.getPosition(), CField.getWarpToMap(to, pto.getId(), this), pto);
}
private void changeMapInternal(MapleMap to, Point pos, byte[] warpPacket, MaplePortal pto) {
if (to == null) {
return;
}
int nowmapid = this.map.getId();
if (this.eventInstance != null) {
this.eventInstance.changedMap(this, to.getId());
}
boolean pyramid = this.pyramidSubway != null;
if (this.map.getId() == nowmapid) {
this.client.getSession().write(warpPacket);
boolean shouldChange = (!(isClone())) && (this.client.getChannelServer().getPlayerStorage().getCharacterById(getId()) != null);
boolean shouldState = this.map.getId() == to.getId();
if ((shouldChange) && (shouldState)) {
to.setCheckStates(false);
}
this.map.removePlayer(this);
if (shouldChange) {
this.map = to;
setPosition(pos);
to.addPlayer(this);
this.stats.relocHeal(this);
if (shouldState) {
to.setCheckStates(true);
}
}
}
if ((pyramid) && (this.pyramidSubway != null))
this.pyramidSubway.onChangeMap(this, to.getId());
}
public void cancelChallenge()
{
if ((this.challenge != 0) && (this.client.getChannelServer() != null)) {
MapleCharacter chr = this.client.getChannelServer().getPlayerStorage().getCharacterById(this.challenge);
if (chr != null) {
chr.dropMessage(6, new StringBuilder().append(getName()).append(" has denied your request.").toString());
chr.setChallenge(0);
}
dropMessage(6, "Denied the challenge.");
this.challenge = 0;
}
}
public void leaveMap(MapleMap map) {
this.controlledLock.writeLock().lock();
this.visibleMapObjectsLock.writeLock().lock();
try {
for (MapleMonster mons : this.controlled) {
if (mons != null) {
mons.setController(null);
mons.setControllerHasAggro(false);
map.updateMonsterController(mons);
}
}
this.controlled.clear();
this.visibleMapObjects.clear();
} finally {
this.controlledLock.writeLock().unlock();
this.visibleMapObjectsLock.writeLock().unlock();
}
if (this.chair != 0) {
this.chair = 0;
}
clearLinkMid();
cancelFishingTask();
cancelChallenge();
if (getBattle() != null) {
getBattle().forfeit(this, true);
}
if (!(getMechDoors().isEmpty())) {
removeMechDoor();
}
cancelMapTimeLimitTask();
if (getTrade() != null)
MapleTrade.cancelTrade(getTrade(), this.client, this);
}
public void changeJob(int newJob)
{
try {
cancelEffectFromBuffStat(MapleBuffStat.SHADOWPARTNER);
this.job = (short)newJob;
updateSingleStat(MapleStat.JOB, newJob);
if (!(GameConstants.isBeginnerJob(newJob))) {
if ((GameConstants.isEvan(newJob)) || (GameConstants.isResist(newJob)) || (GameConstants.isMercedes(newJob)) || (GameConstants.isJett(newJob)) || (GameConstants.isPhantom(newJob))) {
if (GameConstants.isPhantom(this.job)) {
this.client.getSession().write(CField.updateCardStack(0));
}
int changeSp = ((newJob == 2200) || (newJob == 2210) || (newJob == 2211) || (newJob == 2213)) ? 3 : 5;
if ((GameConstants.isResist(this.job)) && (newJob != 3100) && (newJob != 3200) && (newJob != 3300) && (newJob != 3500)) {
changeSp = 3;
}
this.remainingSp[GameConstants.getSkillBook(newJob)] += changeSp;
this.client.getSession().write(CWvsContext.InfoPacket.getSPMsg((byte)changeSp, (short)newJob));
} else {
this.remainingSp[GameConstants.getSkillBook(newJob)] += 1;
if (newJob % 10 >= 2) {
this.remainingSp[GameConstants.getSkillBook(newJob)] += 2;
}
}
if ((newJob % 10 >= 1) && (this.level >= 70))
{
MapleCharacter tmp252_251 = this; tmp252_251.remainingAp = (short)(tmp252_251.remainingAp + 5);
updateSingleStat(MapleStat.AVAILABLEAP, this.remainingAp);
}
if (!(isGM())) {
resetStatsByJob(true);
if (!(GameConstants.isEvan(newJob))) {
if ((getLevel() > ((newJob == 200) ? 8 : 10)) && (newJob % 100 == 0) && (newJob % 1000 / 100 > 0))
this.remainingSp[GameConstants.getSkillBook(newJob)] += 3 * (getLevel() - ((newJob == 200) ? 8 : 10));
}
else if (newJob == 2200) {
MapleQuest.getInstance(22100).forceStart(this, 0, null);
MapleQuest.getInstance(22100).forceComplete(this, 0);
expandInventory((byte) 1, 4);
expandInventory((byte) 2, 4);
expandInventory((byte) 3, 4);
expandInventory((byte) 4, 4);
this.client.getSession().write(CField.NPCPacket.getEvanTutorial("UI/tutorial/evan/14/0"));
dropMessage(5, "The baby Dragon hatched and appears to have something to tell you. Click the baby Dragon to start a conversation.");
}
}
updateSingleStat(MapleStat.AVAILABLESP, 0);
}
int maxhp = this.stats.getMaxHp(); int maxmp = this.stats.getMaxMp();
switch (this.job)
{
case 100:
case 1100:
case 2100:
case 3200:
maxhp += Randomizer.rand(200, 250);
break;
case 3100:
maxhp += Randomizer.rand(200, 250);
break;
case 3110:
maxhp += Randomizer.rand(300, 350);
break;
case 200:
case 2200:
case 2210:
maxmp += Randomizer.rand(100, 150);
break;
case 300:
case 400:
case 500:
case 2300:
case 3300:
case 3500:
maxhp += Randomizer.rand(100, 150);
maxmp += Randomizer.rand(25, 50);
break;
case 110:
case 120:
case 130:
case 1110:
case 2110:
case 3210:
maxhp += Randomizer.rand(300, 350);
break;
case 210:
case 220:
case 230:
maxmp += Randomizer.rand(400, 450);
break;
case 310:
case 320:
case 410:
case 420:
case 430:
case 510:
case 520:
case 530:
case 1310:
case 1410:
case 2310:
case 3310:
case 3510:
maxhp += Randomizer.rand(200, 250);
maxhp += Randomizer.rand(150, 200);
break;
case 800:
case 900:
maxhp += 99999;
maxmp += 99999;
}
if (maxhp >= 99999) {
maxhp = 99999;
}
if (maxmp >= 99999) {
maxmp = 99999;
}
if (GameConstants.isDemon(this.job)) {
maxmp = GameConstants.getMPByJob(this.job);
}
this.stats.setInfo(maxhp, maxmp, maxhp, maxmp);
Map statup = new EnumMap(MapleStat.class);
statup.put(MapleStat.MAXHP, Integer.valueOf(maxhp));
statup.put(MapleStat.MAXMP, Integer.valueOf(maxmp));
statup.put(MapleStat.HP, Integer.valueOf(maxhp));
statup.put(MapleStat.MP, Integer.valueOf(maxmp));
this.characterCard.recalcLocalStats(this);
this.stats.recalcLocalStats(this);
this.client.getSession().write(CWvsContext.updatePlayerStats(statup, this));
this.map.broadcastMessage(this, CField.EffectPacket.showForeignEffect(getId(), 11), false);
silentPartyUpdate();
guildUpdate();
familyUpdate();
if (this.dragon != null) {
this.map.broadcastMessage(CField.removeDragon(this.id));
this.dragon = null;
}
baseSkills();
if ((newJob >= 2200) && (newJob <= 2218)) {
if (getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
cancelBuffStats(new MapleBuffStat[] { MapleBuffStat.MONSTER_RIDING });
}
makeDragon();
}
} catch (Exception e) {
FileoutputUtil.outputFileError("Log_Script_Except.rtf", e);
}
}
public void baseSkills() {
if ((getJob() == 2400) && (getLevel() == 10)) {
gainSP(5);
levelUp();
}
if ((getJob() == 508) && (getLevel() == 10)) {
gainSP(1);
levelUp();
}
Map list = new HashMap();
Iterator i$;
if (GameConstants.getJobNumber(this.job) >= 3) {
List skills = SkillFactory.getSkillsByJob(this.job);
if (skills != null)
for (i$ = skills.iterator(); i$.hasNext(); ) { int i = ((Integer)i$.next()).intValue();
Skill skil = SkillFactory.getSkill(i);
if ((skil != null) && (!(skil.isInvisible())) && (skil.isFourthJob()) && (getSkillLevel(skil) <= 0) && (getMasterLevel(skil) <= 0) && (skil.getMasterLevel() > 0))
list.put(skil, new SkillEntry(0, (byte)skil.getMasterLevel(), SkillFactory.getDefaultSExpiry(skil)));
else if ((skil != null) && (skil.getName() != null) && (skil.getName().contains("Maple Warrior")) && (getSkillLevel(skil) <= 0) && (getMasterLevel(skil) <= 0))
list.put(skil, new SkillEntry(0, (byte) 10, SkillFactory.getDefaultSExpiry(skil)));
}
}
int[] ss50;
Skill skil;
if ((this.job >= 2100) && (this.job <= 2112)) {
ss50 = new int[] { 21120002, 21120001, 21120005, 21120003, 21121000, 211210012, 211210004, 211210006, 211210007 };
for (int i : ss50) {
skil = SkillFactory.getSkill(i);
if ((skil == null) ||
(getSkillLevel(skil) > 0)) continue;
list.put(skil, new SkillEntry(0, (byte) 10, -1L));
}
}
if ((this.job >= 2211) && (this.job <= 2218)) {
skil = SkillFactory.getSkill(22111001);
if ((skil != null) &&
(getSkillLevel(skil) <= 0)) {
list.put(skil, new SkillEntry(0, (byte) 20, -1L));
}
}
if ((this.job >= 430) && (this.job <= 434)) {
ss50 = new int[] { 4341000, 4341002, 4341003, 4341004, 4341007, 4341009, 4341011 };
for (int i : ss50) {
skil = SkillFactory.getSkill(i);
if ((skil == null) ||
(getSkillLevel(skil) > 0)) continue;
list.put(skil, new SkillEntry(0, (byte) 10, -1L));
}
}
if (GameConstants.isMercedes(this.job)) {
int[] ss = { 20021000, 20021001, 20020002, 20020022, 20020109, 20021110, 20020111, 20020112 };
for (int i : ss) {
skil = SkillFactory.getSkill(i);
if ((skil == null) ||
(getSkillLevel(skil) > 0)) continue;
list.put(skil, new SkillEntry(1, (byte) 1, -1L));
}
skil = SkillFactory.getSkill(20021181);
if ((skil != null) &&
(getSkillLevel(skil) <= 0)) {
list.put(skil, new SkillEntry(-1, (byte) 0, -1L));
}
skil = SkillFactory.getSkill(20021166);
if ((skil != null) &&
(getSkillLevel(skil) <= 0)) {
list.put(skil, new SkillEntry(-1, (byte) 0, -1L));
}
}
if (GameConstants.isDemon(this.job)) {
int[] ss1 = { 30011000, 30011001, 30010002, 30010185, 30010112, 30010111, 30010110, 30010022, 30011109 };
for (int i : ss1) {
skil = SkillFactory.getSkill(i);
if ((skil == null) ||
(getSkillLevel(skil) > 0)) continue;
list.put(skil, new SkillEntry(1, (byte) 1, -1L));
}
int[] ss2 = { 30011170, 30011169, 30011168, 30011167, 30010166, 30010184, 30010183, 30010186 };
for (int i : ss2) {
skil = SkillFactory.getSkill(i);
if ((skil == null) ||
(getSkillLevel(skil) > 0)) continue;
list.put(skil, new SkillEntry(-1, (byte) -1, -1L));
}
}
if (!(list.isEmpty()))
changeSkillsLevel(list);
}
public void makeDragon()
{
this.dragon = new MapleDragon(this);
this.map.broadcastMessage(CField.spawnDragon(this.dragon));
}
public MapleDragon getDragon() {
return this.dragon;
}
public void gainAp(short ap)
{
MapleCharacter tmp1_0 = this; tmp1_0.remainingAp = (short)(tmp1_0.remainingAp + ap);
updateSingleStat(MapleStat.AVAILABLEAP, this.remainingAp);
}
public void gainSP(int sp) {
this.remainingSp[GameConstants.getSkillBook(this.job)] += sp;
updateSingleStat(MapleStat.AVAILABLESP, 0);
this.client.getSession().write(CWvsContext.InfoPacket.getSPMsg((byte)sp, this.job));
}
public void gainSP(int sp, int skillbook) {
this.remainingSp[skillbook] += sp;
updateSingleStat(MapleStat.AVAILABLESP, 0);
this.client.getSession().write(CWvsContext.InfoPacket.getSPMsg((byte)sp, (short) 0));
}
public void resetSP(int sp) {
for (int i = 0; i < this.remainingSp.length; ++i) {
this.remainingSp[i] = sp;
}
updateSingleStat(MapleStat.AVAILABLESP, 0);
}
public void resetAPSP() {
resetSP(0);
gainAp((short)(-this.remainingAp));
}
public List<Integer> getProfessions() {
List prof = new ArrayList();
for (int i = 9200; i <= 9204; ++i) {
if (getProfessionLevel(this.id * 10000) > 0) {
prof.add(Integer.valueOf(i));
}
}
return prof;
}
public byte getProfessionLevel(int id) {
int ret = getSkillLevel(id);
if (ret <= 0) {
return 0;
}
return (byte)(ret >>> 24 & 0xFF);
}
public short getProfessionExp(int id) {
int ret = getSkillLevel(id);
if (ret <= 0) {
return 0;
}
return (short)(ret & 0xFFFF);
}
public boolean addProfessionExp(int id, int expGain) {
int ret = getProfessionLevel(id);
if ((ret <= 0) || (ret >= 10)) {
return false;
}
int newExp = getProfessionExp(id) + expGain;
if (newExp >= GameConstants.getProfessionEXP(ret))
{
changeProfessionLevelExp(id, ret + 1, newExp - GameConstants.getProfessionEXP(ret));
int traitGain = (int)Math.pow(2.0D, ret + 1);
switch (id)
{
case 92000000:
((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.sense)).addExp(traitGain, this);
break;
case 92010000:
((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.will)).addExp(traitGain, this);
break;
case 92020000:
case 92030000:
case 92040000:
((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.craft)).addExp(traitGain, this);
}
return true;
}
changeProfessionLevelExp(id, ret, newExp);
return false;
}
public void changeProfessionLevelExp(int id, int level, int exp)
{
changeSingleSkillLevel(SkillFactory.getSkill(id), ((level & 0xFF) << 24) + (exp & 0xFFFF), (byte) 10);
}
public void changeSingleSkillLevel(Skill skill, int newLevel, byte newMasterlevel) {
if (skill == null) {
return;
}
changeSingleSkillLevel(skill, newLevel, newMasterlevel, SkillFactory.getDefaultSExpiry(skill));
}
public void changeSingleSkillLevel(Skill skill, int newLevel, byte newMasterlevel, long expiration) {
changeSingleSkillLevel(skill, newLevel, newMasterlevel, expiration, (byte) -1, (byte) -1);
}
public void changeSingleSkillLevel(Skill skill, int newLevel, byte newMasterlevel, long expiration, byte slot, byte equipped) {
Map list = new HashMap();
boolean hasRecovery = false; boolean recalculate = false;
if (changeSkillData(skill, newLevel, newMasterlevel, expiration, slot, equipped)) {
list.put(skill, new SkillEntry(newLevel, newMasterlevel, expiration, slot, equipped));
if (GameConstants.isRecoveryIncSkill(skill.getId())) {
hasRecovery = true;
}
if (skill.getId() < 80000000) {
recalculate = true;
}
}
if (list.isEmpty()) {
return;
}
this.client.getSession().write(CWvsContext.updateSkills(list));
reUpdateStat(hasRecovery, recalculate);
}
public void changeSkillsLevel(Map<Skill, SkillEntry> ss) {
if (ss.isEmpty()) {
return;
}
Map list = new HashMap();
boolean hasRecovery = false; boolean recalculate = false;
for (Map.Entry data : ss.entrySet()) {
if (changeSkillData((Skill)data.getKey(), ((SkillEntry)data.getValue()).skillevel, ((SkillEntry)data.getValue()).masterlevel, ((SkillEntry)data.getValue()).expiration, ((SkillEntry)data.getValue()).slot, ((SkillEntry)data.getValue()).equipped)) {
list.put(data.getKey(), data.getValue());
if (GameConstants.isRecoveryIncSkill(((Skill)data.getKey()).getId())) {
hasRecovery = true;
}
if (((Skill)data.getKey()).getId() < 80000000) {
recalculate = true;
}
}
}
if (list.isEmpty()) {
return;
}
this.client.getSession().write(CWvsContext.updateSkills(list));
reUpdateStat(hasRecovery, recalculate);
}
private void reUpdateStat(boolean hasRecovery, boolean recalculate) {
this.changed_skills = true;
if (hasRecovery) {
this.stats.relocHeal(this);
}
if (recalculate)
this.stats.recalcLocalStats(this);
}
public boolean changeSkillData(Skill skill, int newLevel, byte newMasterlevel, long expiration, byte slot, byte equipped)
{
if ((skill == null) || ((!(GameConstants.isApplicableSkill(skill.getId()))) && (!(GameConstants.isApplicableSkill_(skill.getId()))))) {
return false;
}
if ((newLevel == 0) && (newMasterlevel == 0)) {
if (this.skills.containsKey(skill)) {
this.skills.remove(skill);
}
return false;
}
this.skills.put(skill, new SkillEntry(newLevel, newMasterlevel, expiration, slot, equipped));
label89: return true;
}
public void changeSkillLevel_Skip(Map<Skill, SkillEntry> skill, boolean write) {
if (skill.isEmpty()) {
return;
}
Map newL = new HashMap();
for (Entry<Skill, SkillEntry> z : skill.entrySet()) {
if (z.getKey() == null) {
continue;
}
newL.put(z.getKey(), z.getValue());
if ((((SkillEntry)z.getValue()).skillevel == 0) && (((SkillEntry)z.getValue()).masterlevel == 0)) {
if (this.skills.containsKey(z.getKey()));
this.skills.remove(z.getKey());
}
else
{
this.skills.put(z.getKey(), z.getValue());
}
}
if ((write) && (!(newL.isEmpty())))
this.client.getSession().write(CWvsContext.updateSkills(newL));
}
public void playerDead()
{
MapleStatEffect statss = getStatForBuff(MapleBuffStat.SOUL_STONE);
if (statss != null) {
dropMessage(5, "You have been revived by Soul Stone.");
getStat().setHp(getStat().getMaxHp() / 100 * statss.getX(), this);
setStance(0);
changeMap(getMap(), getMap().getPortal(0));
return;
}
if (getEventInstance() != null) {
getEventInstance().playerKilled(this);
}
cancelEffectFromBuffStat(MapleBuffStat.SHADOWPARTNER);
cancelEffectFromBuffStat(MapleBuffStat.MORPH);
cancelEffectFromBuffStat(MapleBuffStat.SOARING);
cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
cancelEffectFromBuffStat(MapleBuffStat.MECH_CHANGE);
cancelEffectFromBuffStat(MapleBuffStat.RECOVERY);
cancelEffectFromBuffStat(MapleBuffStat.HP_BOOST_PERCENT);
cancelEffectFromBuffStat(MapleBuffStat.MP_BOOST_PERCENT);
cancelEffectFromBuffStat(MapleBuffStat.HP_BOOST);
cancelEffectFromBuffStat(MapleBuffStat.MP_BOOST);
cancelEffectFromBuffStat(MapleBuffStat.ENHANCED_MAXHP);
cancelEffectFromBuffStat(MapleBuffStat.ENHANCED_MAXMP);
cancelEffectFromBuffStat(MapleBuffStat.MAXHP);
cancelEffectFromBuffStat(MapleBuffStat.MAXMP);
dispelSummons();
checkFollow();
setStealTarget(0);
this.dotHP = 0;
this.lastDOTTime = 0L;
if ((!(GameConstants.isBeginnerJob(this.job))) && (!(inPVP()))) {
int charms = getItemQuantity(5130000, false);
if (charms > 0) {
MapleInventoryManipulator.removeById(this.client, MapleInventoryType.CASH, 5130000, 1, true, false);
--charms;
if (charms > 255) {
charms = 255;
}
this.client.getSession().write(CField.EffectPacket.useCharm((byte)charms, (byte) 0, true));
} else {
float diepercentage = 0.0F;
int expforlevel = getNeededExp();
if ((this.map.isTown()) || (FieldLimitType.RegularExpLoss.check(this.map.getFieldLimit())))
diepercentage = 0.01F;
else {
diepercentage = 0.1F - (((MapleTrait)this.traits.get(MapleTrait.MapleTraitType.charisma)).getLevel() / 20 / 100.0F) - (this.stats.expLossReduceR / 100.0F);
}
int v10 = (int) (exp - (long) ((double) expforlevel * diepercentage));
if (v10 < 0) {
v10 = 0;
}
this.exp = v10;
}
updateSingleStat(MapleStat.EXP, this.exp);
}
if (!(this.stats.checkEquipDurabilitys(this, -100))) {
dropMessage(5, "An item has run out of durability but has no inventory room to go to.");
}
if (this.pyramidSubway != null) {
this.stats.setHp(50, this);
this.pyramidSubway.fail(this);
}
}
public void updatePartyMemberHP()
{
int channel;
if ((this.party != null) && (this.client.getChannelServer() != null)) {
channel = this.client.getChannel();
for (MaplePartyCharacter partychar : this.party.getMembers())
if ((partychar != null) && (partychar.getMapid() == getMapId()) && (partychar.getChannel() == channel)) {
MapleCharacter other = this.client.getChannelServer().getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null)
other.getClient().getSession().write(CField.updatePartyMemberHP(getId(), this.stats.getHp(), this.stats.getCurrentMaxHp()));
}
}
}
public void receivePartyMemberHP()
{
if (this.party == null) {
return;
}
int channel = this.client.getChannel();
for (MaplePartyCharacter partychar : this.party.getMembers())
if ((partychar != null) && (partychar.getMapid() == getMapId()) && (partychar.getChannel() == channel)) {
MapleCharacter other = this.client.getChannelServer().getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null)
this.client.getSession().write(CField.updatePartyMemberHP(other.getId(), other.getStat().getHp(), other.getStat().getCurrentMaxHp()));
}
}
public void healHP(int delta)
{
addHP(delta);
this.client.getSession().write(CField.EffectPacket.showOwnHpHealed(delta));
getMap().broadcastMessage(this, CField.EffectPacket.showHpHealed(getId(), delta), false);
}
public void healMP(int delta) {
addMP(delta);
this.client.getSession().write(CField.EffectPacket.showOwnHpHealed(delta));
getMap().broadcastMessage(this, CField.EffectPacket.showHpHealed(getId(), delta), false);
}
public void addHP(int delta)
{
if (this.stats.setHp(this.stats.getHp() + delta, this))
updateSingleStat(MapleStat.HP, this.stats.getHp());
}
public void addMP(int delta)
{
addMP(delta, false);
}
public void addMP(int delta, boolean ignore) {
if ((((delta >= 0) || (!(GameConstants.isDemon(getJob()))))) && ((((GameConstants.isDemon(getJob())) && (!(ignore))) ||
(!(this.stats.setMp(this.stats.getMp() + delta, this)))))) return;
updateSingleStat(MapleStat.MP, this.stats.getMp());
}
public void addMPHP(int hpDiff, int mpDiff)
{
Map statups = new EnumMap(MapleStat.class);
if (this.stats.setHp(this.stats.getHp() + hpDiff, this)) {
statups.put(MapleStat.HP, Integer.valueOf(this.stats.getHp()));
}
if (((mpDiff < 0) && (GameConstants.isDemon(getJob()))) || ((!(GameConstants.isDemon(getJob()))) &&
(this.stats.setMp(this.stats.getMp() + mpDiff, this)))) {
statups.put(MapleStat.MP, Integer.valueOf(this.stats.getMp()));
}
if (statups.size() > 0)
this.client.getSession().write(CWvsContext.updatePlayerStats(statups, this));
}
public void updateSingleStat(MapleStat stat, int newval)
{
updateSingleStat(stat, newval, false);
}
public void updateSingleStat(MapleStat stat, int newval, boolean itemReaction)
{
Map statup = new EnumMap(MapleStat.class);
statup.put(stat, Integer.valueOf(newval));
this.client.getSession().write(CWvsContext.updatePlayerStats(statup, itemReaction, this));
}
public void gainExp(int total, boolean show, boolean inChat, boolean white) {
try {
int prevexp = getExp();
int needed = getNeededExp();
if (total > 0) {
this.stats.checkEquipLevels(this, total);
}
if ((((this.level >= 200) || ((GameConstants.isKOC(this.job)) && (this.level >= 120)))) && (!(isIntern()))) {
setExp(0);
}
else
{
boolean leveled = false;
long tot = this.exp + total;
if (tot >= needed) {
this.exp += total;
levelUp();
leveled = true;
if ((((this.level >= 200) || ((GameConstants.isKOC(this.job)) && (this.level >= 120)))) && (!(isIntern()))) {
setExp(0);
} else {
needed = getNeededExp();
if (this.exp >= needed)
setExp(needed - 1);
}
}
else {
this.exp += total;
}
if (total > 0) {
familyRep(prevexp, needed, leveled);
}
}
if (total != 0) {
if (this.exp < 0) {
if (total > 0)
setExp(needed);
else if (total < 0) {
setExp(0);
}
}
updateSingleStat(MapleStat.EXP, getExp());
if (show)
this.client.getSession().write(CWvsContext.InfoPacket.GainEXP_Others(total, inChat, white));
}
}
catch (Exception e) {
FileoutputUtil.outputFileError("Log_Script_Except.rtf", e);
}
}
public void familyRep(int prevexp, int needed, boolean leveled) {
if (this.mfc != null) {
int onepercent = needed / 100;
if (onepercent <= 0) {
return;
}
int percentrep = getExp() / onepercent - (prevexp / onepercent);
if (leveled) {
percentrep = 100 - percentrep + this.level / 2;
}
if (percentrep > 0) {
int sensen = World.Family.setRep(this.mfc.getFamilyId(), this.mfc.getSeniorId(), percentrep * 10, this.level, this.name);
if (sensen > 0)
World.Family.setRep(this.mfc.getFamilyId(), sensen, percentrep * 5, this.level, this.name);
}
}
}
public void gainExpMonster(int gain, boolean show, boolean white, byte pty, int Class_Bonus_EXP, int Equipment_Bonus_EXP, int Premium_Bonus_EXP, boolean partyBonusMob, int partyBonusRate)
{
if (!(isAlive()))
return;
MapleCharacter tmp9_8 = this; tmp9_8.mobKilledNo = (short)(tmp9_8.mobKilledNo + 1);
int total = gain + Class_Bonus_EXP + Equipment_Bonus_EXP + Premium_Bonus_EXP;
long Trio_Bonus_EXP = 0L;
short percentage = 0;
double hoursFromLogin = 0.0D;
if (this.mobKilledNo == 3)
{
hoursFromLogin = (System.currentTimeMillis() - this.loginTime) / 3600000L;
if ((hoursFromLogin >= 1.0D) && (hoursFromLogin < 2.0D))
percentage = 30;
else if ((hoursFromLogin >= 2.0D) && (hoursFromLogin < 3.0D))
percentage = 100;
else if ((hoursFromLogin >= 3.0D) && (hoursFromLogin < 4.0D))
percentage = 150;
else if ((hoursFromLogin >= 4.0D) && (hoursFromLogin < 5.0D))
percentage = 180;
else if (hoursFromLogin >= 5.0D) {
percentage = 200;
}
Trio_Bonus_EXP = (long)(gain / 100 * percentage);
total = (int)(total + Trio_Bonus_EXP);
this.mobKilledNo = 0;
}
int partyinc = 0;
int prevexp = getExp();
if (pty > 1) {
double rate = ((this.map == null) || (!(partyBonusMob)) || (this.map.getPartyBonusRate() <= 0)) ? 0.05D : (partyBonusRate > 0) ? partyBonusRate / 100.0D : this.map.getPartyBonusRate() / 100.0D;
partyinc = (int)((float)(gain * rate) * (pty + ((rate > 0.05D) ? -1 : 1)));
total += partyinc;
}
if ((gain > 0) && (total < gain)) {
total = 2147483647;
}
if (total > 0) {
this.stats.checkEquipLevels(this, total);
}
int needed = getNeededExp();
if ((((this.level >= 200) || ((GameConstants.isKOC(this.job)) && (this.level >= 120)))) && (!(isIntern()))) {
setExp(0);
}
else
{
boolean leveled = false;
if ((this.exp + total >= needed) || (this.exp >= needed)) {
this.exp += total;
levelUp();
leveled = true;
if ((((this.level >= 200) || ((GameConstants.isKOC(this.job)) && (this.level >= 120)))) && (!(isIntern()))) {
setExp(0);
} else {
needed = getNeededExp();
if (this.exp >= needed)
setExp(needed);
}
}
else {
this.exp += total;
}
if (total > 0) {
familyRep(prevexp, needed, leveled);
if ((getOccupation() / 100 == 1) && (Randomizer.nextInt(100) < 40))
gainOccupationEXP(1);
else if ((getOccupation() / 100 == 5) &&
(pty > 0) && (Randomizer.nextInt(100) < getOccupation() % 10 * 2 * pty))
gainOccupationEXP(1);
}
else
{
return;
}
}
if (gain != 0) {
if (this.exp < 0) {
if (gain > 0)
setExp(getNeededExp());
else if (gain < 0) {
setExp(0);
}
}
updateSingleStat(MapleStat.EXP, getExp());
if (show)
this.client.getSession().write(CWvsContext.InfoPacket.GainEXP_Monster(gain, white, partyinc, Class_Bonus_EXP, Equipment_Bonus_EXP, Premium_Bonus_EXP));
}
}
public void forceReAddItem_NoUpdate(Item item, MapleInventoryType type)
{
getInventory(type).removeSlot(item.getPosition());
getInventory(type).addFromDB(item);
}
public void forceReAddItem(Item item, MapleInventoryType type) {
forceReAddItem_NoUpdate(item, type);
if (type != MapleInventoryType.UNDEFINED)
this.client.getSession().write(CWvsContext.InventoryPacket.updateSpecialItemUse(item, (type == MapleInventoryType.EQUIPPED) ? 1 : type.getType(), this));
}
public void forceReAddItem_Flag(Item item, MapleInventoryType type)
{
forceReAddItem_NoUpdate(item, type);
if (type != MapleInventoryType.UNDEFINED)
this.client.getSession().write(CWvsContext.InventoryPacket.updateSpecialItemUse_(item, (type == MapleInventoryType.EQUIPPED) ? 1 : type.getType(), this));
}
public void forceReAddItem_Book(Item item, MapleInventoryType type)
{
forceReAddItem_NoUpdate(item, type);
if (type != MapleInventoryType.UNDEFINED)
this.client.getSession().write(CWvsContext.upgradeBook(item, this));
}
public void silentPartyUpdate()
{
if (this.party != null)
World.Party.updateParty(this.party.getId(), PartyOperation.SILENT_UPDATE, new MaplePartyCharacter(this));
}
public boolean isSuperGM()
{
return (this.gmLevel >= ServerConstants.PlayerGMRank.SUPERGM.getLevel());
}
public boolean isIntern() {
return (this.gmLevel >= ServerConstants.PlayerGMRank.INTERN.getLevel());
}
public boolean isGM() {
return (this.gmLevel >= ServerConstants.PlayerGMRank.GM.getLevel());
}
public boolean isAdmin() {
return (this.gmLevel >= ServerConstants.PlayerGMRank.ADMIN.getLevel());
}
public int getGMLevel() {
return this.gmLevel;
}
public boolean hasGmLevel(int level) {
return (this.gmLevel >= level);
}
public byte gmLevel() {
return this.gmLevel;
}
public final MapleInventory getInventory(MapleInventoryType type) {
return this.inventory[type.ordinal()];
}
public final MapleInventory[] getInventorys() {
return this.inventory;
}
public final void expirationTask(boolean pending, boolean firstLoad) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (pending) {
if (this.pendingExpiration != null) {
for (Integer z : this.pendingExpiration) {
this.client.getSession().write(CWvsContext.InfoPacket.itemExpired(z.intValue()));
if (!(firstLoad)) {
Pair replace = ii.replaceItemInfo(z.intValue());
if ((replace != null) && (((Integer)replace.left).intValue() > 0) && (((String)replace.right).length() > 0)) {
dropMessage(5, (String)replace.right);
}
}
}
}
this.pendingExpiration = null;
if (this.pendingSkills != null) {
this.client.getSession().write(CWvsContext.updateSkills(this.pendingSkills));
for (Skill z : this.pendingSkills.keySet()) {
this.client.getSession().write(CWvsContext.serverNotice(5, new StringBuilder().append("[").append(SkillFactory.getSkillName(z.getId())).append("] skill has expired and will not be available for use.").toString()));
}
}
this.pendingSkills = null;
return;
}
MapleQuestStatus stat = getQuestNoAdd(MapleQuest.getInstance(122700));
List ret = new ArrayList();
long currenttime = System.currentTimeMillis();
List<Triple<MapleInventoryType, Item, Boolean>> toberemove = new ArrayList();
List<Item> tobeunlock = new ArrayList();
for (MapleInventoryType inv : MapleInventoryType.values()) {
for (Item item : getInventory(inv)) {
long expiration = item.getExpiration();
if (((expiration != -1L) && (!(GameConstants.isPet(item.getItemId()))) && (currenttime > expiration)) || ((firstLoad) && (ii.isLogoutExpire(item.getItemId())))) {
if (ItemFlag.LOCK.check(item.getFlag()))
tobeunlock.add(item);
else if (currenttime > expiration)
toberemove.add(new Triple(inv, item, Boolean.valueOf(false)));
}
else if ((item.getItemId() == 5000054) && (item.getPet() != null) && (item.getPet().getSecondsLeft() <= 0))
toberemove.add(new Triple(inv, item, Boolean.valueOf(false)));
else if ((item.getPosition() == -59) && ((
(stat == null) || (stat.getCustomData() == null) || (Long.parseLong(stat.getCustomData()) < currenttime)))) {
toberemove.add(new Triple(inv, item, Boolean.valueOf(true)));
}
}
}
for (Triple<MapleInventoryType, Item, Boolean> itemz : toberemove) {
Item item = (Item)itemz.getMid();
getInventory((MapleInventoryType)itemz.getLeft()).removeItem(item.getPosition(), item.getQuantity(), false);
if ((((Boolean)itemz.getRight()).booleanValue()) && (getInventory(GameConstants.getInventoryType(item.getItemId())).getNextFreeSlot() > -1)) {
item.setPosition(getInventory(GameConstants.getInventoryType(item.getItemId())).getNextFreeSlot());
getInventory(GameConstants.getInventoryType(item.getItemId())).addFromDB(item);
} else {
ret.add(Integer.valueOf(item.getItemId()));
}
if (!(firstLoad)) {
Pair replace = ii.replaceItemInfo(item.getItemId());
if ((replace != null) && (((Integer)replace.left).intValue() > 0)) {
Item theNewItem = null;
if (GameConstants.getInventoryType(((Integer)replace.left).intValue()) == MapleInventoryType.EQUIP) {
theNewItem = ii.getEquipById(((Integer)replace.left).intValue());
theNewItem.setPosition(item.getPosition());
} else {
theNewItem = new Item(((Integer)replace.left).intValue(), item.getPosition(), (short) 1, (short) 0);
}
getInventory((MapleInventoryType)itemz.getLeft()).addFromDB(theNewItem);
}
}
}
for (Item itemz : tobeunlock) {
itemz.setExpiration(-1L);
itemz.setFlag((short)(byte)(itemz.getFlag() - ItemFlag.LOCK.getValue()));
}
this.pendingExpiration = ret;
Map<Skill, SkillEntry> skilz = new HashMap();
List<Skill> toberem = new ArrayList();
for (Entry<Skill, SkillEntry> skil : this.skills.entrySet()) {
if ((((SkillEntry)skil.getValue()).expiration != -1L) && (currenttime > ((SkillEntry)skil.getValue()).expiration)) {
toberem.add(skil.getKey());
}
}
for (Skill skil : toberem) {
skilz.put(skil, new SkillEntry(0, (byte) 0, -1L));
this.skills.remove(skil);
this.changed_skills = true;
}
this.pendingSkills = skilz;
if ((stat != null) && (stat.getCustomData() != null) && (Long.parseLong(stat.getCustomData()) < currenttime)) {
this.quests.remove(MapleQuest.getInstance(7830));
this.quests.remove(MapleQuest.getInstance(122700));
}
}
public MapleShop getShop() {
return this.shop;
}
public void setShop(MapleShop shop) {
this.shop = shop;
}
public int getMeso() {
return this.meso;
}
public final int[] getSavedLocations() {
return this.savedLocations;
}
public int getSavedLocation(SavedLocationType type) {
return this.savedLocations[type.getValue()];
}
public void saveLocation(SavedLocationType type) {
this.savedLocations[type.getValue()] = getMapId();
this.changed_savedlocations = true;
}
public void saveLocation(SavedLocationType type, int mapz) {
this.savedLocations[type.getValue()] = mapz;
this.changed_savedlocations = true;
}
public void clearSavedLocation(SavedLocationType type) {
this.savedLocations[type.getValue()] = -1;
this.changed_savedlocations = true;
}
public void gainMeso(int gain, boolean show) {
gainMeso(gain, show, false);
}
public void gainMeso(int gain, boolean show, boolean inChat) {
if (this.meso + gain < 0) {
this.client.getSession().write(CWvsContext.enableActions());
return;
}
this.meso += gain;
if (this.meso >= 1000000) {
finishAchievement(31);
}
if (this.meso >= 10000000) {
finishAchievement(32);
}
if (this.meso >= 100000000) {
finishAchievement(33);
}
if (this.meso >= 1000000000) {
finishAchievement(34);
}
updateSingleStat(MapleStat.MESO, this.meso, false);
this.client.getSession().write(CWvsContext.enableActions());
if (show)
this.client.getSession().write(CWvsContext.InfoPacket.showMesoGain(gain, inChat));
}
public void controlMonster(MapleMonster monster, boolean aggro)
{
if ((this.clone) || (monster == null)) {
return;
}
monster.setController(this);
this.controlledLock.writeLock().lock();
try {
this.controlled.add(monster);
} finally {
this.controlledLock.writeLock().unlock();
}
this.client.getSession().write(MobPacket.controlMonster(monster, false, aggro));
monster.sendStatus(this.client);
}
public void stopControllingMonster(MapleMonster monster) {
if ((this.clone) || (monster == null)) {
return;
}
this.controlledLock.writeLock().lock();
try {
if (this.controlled.contains(monster))
this.controlled.remove(monster);
}
finally {
this.controlledLock.writeLock().unlock();
}
}
public void checkMonsterAggro(MapleMonster monster) {
if ((this.clone) || (monster == null)) {
return;
}
if (monster.getController() == this)
monster.setControllerHasAggro(true);
else
monster.switchController(this, true);
}
public int getControlledSize()
{
return this.controlled.size();
}
public int getAccountID() {
return this.accountid;
}
public void mobKilled(int id, int skillID) {
for (MapleQuestStatus q : this.quests.values()) {
if (q.getStatus() != 1) continue; if (!(q.hasMobKills())) {
continue;
}
if (q.mobKilled(id, skillID)) {
this.client.getSession().write(CWvsContext.InfoPacket.updateQuestMobKills(q));
if (q.getQuest().canComplete(this, null))
this.client.getSession().write(CWvsContext.getShowQuestCompletion(q.getQuest().getId()));
}
}
}
public final List<MapleQuestStatus> getStartedQuests()
{
List ret = new LinkedList();
for (MapleQuestStatus q : this.quests.values()) {
if ((q.getStatus() == 1) && (!(q.isCustom())) && (!(q.getQuest().isBlocked()))) {
ret.add(q);
}
}
return ret;
}
public final List<MapleQuestStatus> getCompletedQuests() {
List ret = new LinkedList();
for (MapleQuestStatus q : this.quests.values()) {
if ((q.getStatus() == 2) && (!(q.isCustom())) && (!(q.getQuest().isBlocked()))) {
ret.add(q);
}
}
return ret;
}
public final List<Pair<Integer, Long>> getCompletedMedals() {
List ret = new ArrayList();
for (MapleQuestStatus q : this.quests.values()) {
if ((q.getStatus() == 2) && (!(q.isCustom())) && (!(q.getQuest().isBlocked())) && (q.getQuest().getMedalItem() > 0) && (GameConstants.getInventoryType(q.getQuest().getMedalItem()) == MapleInventoryType.EQUIP)) {
ret.add(new Pair(Integer.valueOf(q.getQuest().getId()), Long.valueOf(q.getCompletionTime())));
}
}
return ret;
}
public Map<Skill, SkillEntry> getSkills() {
return Collections.unmodifiableMap(this.skills);
}
public Map<Skill, SkillEntry> getAllPhantomSkills() {
Map rettt = new LinkedHashMap();
for (Map.Entry ret : this.skills.entrySet()) {
if ((((SkillEntry)ret.getValue()).slot > -1) && (GameConstants.canBeStolen(((Skill)ret.getKey()).getId())) && (((SkillEntry)ret.getValue()).equipped > -1)) {
rettt.put(ret.getKey(), ret.getValue());
}
}
return rettt;
}
public byte getNextStolenSlot(int skillid) {
int book = GameConstants.getPhantomBook(skillid);
Map rettt = new LinkedHashMap();
for (Map.Entry ret : this.skills.entrySet()) {
if ((skillid == ((Skill)ret.getKey()).getId()) && (((SkillEntry)ret.getValue()).slot > -1)) {
return ((SkillEntry)ret.getValue()).slot;
}
if ((((SkillEntry)ret.getValue()).slot > -1) && (GameConstants.getPhantomBook(((Skill)ret.getKey()).getId()) == book)) {
rettt.put(Integer.valueOf(((SkillEntry)ret.getValue()).slot), Integer.valueOf(((Skill)ret.getKey()).getId()));
}
}
for (int i = 0; i < GameConstants.getPhantomBookSlot(book); ++i) {
if (rettt.get(Integer.valueOf(i)) == null) {
return (byte)i;
}
}
return -1;
}
public Map<Integer, Integer> getEquippedSkills() {
Map rettt = new LinkedHashMap();
for (Map.Entry ret : this.skills.entrySet()) {
if ((((SkillEntry)ret.getValue()).slot > -1) && (GameConstants.canBeStolen(((Skill)ret.getKey()).getId())) && (((SkillEntry)ret.getValue()).equipped > 0)) {
rettt.put(Integer.valueOf(((SkillEntry)ret.getValue()).equipped), Integer.valueOf(((Skill)ret.getKey()).getId()));
}
}
return rettt;
}
public Map<Integer, List<Integer>> sortPhantomSkills() {
Map<Object, Object> rettt = new LinkedHashMap();
for (Map.Entry ret : this.skills.entrySet()) {
if ((((SkillEntry)ret.getValue()).slot > -1) && (((SkillEntry)ret.getValue()).equipped > -1) && (GameConstants.canBeStolen(((Skill)ret.getKey()).getId()))) {
rettt.put(ret.getKey(), ret.getValue());
}
}
Map newMap = new LinkedHashMap();
for (int i = 1; i <= 4; ++i) {
newMap.put(Integer.valueOf(i), new LinkedList());
}
int book1 = -1; int book2 = -1; int book3 = -1; int book4 = -1;
for (Map.Entry ret : rettt.entrySet()) {
this.skills.remove(ret.getKey());
int book = GameConstants.getPhantomBook(((Skill)ret.getKey()).getId());
int max = GameConstants.getPhantomBookSlot(book);
if (book == 0) continue; if (max == 0) {
continue;
}
if (book == 1) {
++book1;
if (book1 < max)
break;
}
if (book == 2) {
++book2;
if (book2 < max)
break;
}
if (book == 3) {
++book3;
if (book3 < max)
break;
}
if (book == 4) {
++book4;
if (book4 >= max) {
continue;
}
}
this.skills.put((Skill) ret.getKey(), new SkillEntry(((SkillEntry)ret.getValue()).skillevel, ((SkillEntry)ret.getValue()).masterlevel, -1L, (byte)((book == 3) ? book3 : (book == 2) ? book2 : (book == 1) ? book1 : book4), ((SkillEntry)ret.getValue()).equipped));
((List)newMap.get(Integer.valueOf(book))).add(Integer.valueOf(((Skill)ret.getKey()).getId()));
&n