MapleCharacter.java
资源名称:src.rar [点击查看]
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:217k
源码类别:
游戏
开发平台:
Java
- /*
- This file is part of the OdinMS Maple Story Server
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License version 3
- as published by the Free Software Foundation. You may not use, modify
- or distribute this program under any other version of the
- GNU Affero General Public License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.odinms.client;
- import java.awt.Point;
- import java.lang.ref.WeakReference;
- import java.rmi.RemoteException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.io.File;
- import java.text.NumberFormat;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.sql.Statement;
- 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.HashSet;
- import java.util.LinkedHashMap;
- import java.util.LinkedHashSet;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.Map.Entry;
- import java.util.concurrent.ScheduledFuture;
- import java.util.concurrent.atomic.AtomicInteger;
- import java.text.NumberFormat;
- import java.text.DecimalFormat;
- import java.util.HashMap;
- import net.sf.odinms.client.anticheat.CheatTracker;
- import net.sf.odinms.database.DatabaseException;
- import net.sf.odinms.net.channel.handler.GuildHangoutHandler;
- import net.sf.odinms.net.MaplePacket;
- import net.sf.odinms.net.channel.ChannelServer;
- import net.sf.odinms.net.world.MapleMessengerCharacter;
- import net.sf.odinms.net.world.MaplePartyCharacter;
- import net.sf.odinms.net.world.PlayerBuffValueHolder;
- import net.sf.odinms.scripting.event.EventInstanceManager;
- import net.sf.odinms.client.messages.ServernoticeMapleClientMessageCallback;
- import net.sf.odinms.database.DatabaseConnection;
- import net.sf.odinms.net.world.PartyOperation;
- import net.sf.odinms.net.world.PlayerCoolDownValueHolder;
- import net.sf.odinms.net.world.guild.MapleGuild;
- import net.sf.odinms.net.world.guild.MapleGuildCharacter;
- import net.sf.odinms.net.world.remote.WorldChannelInterface;
- import net.sf.odinms.scripting.npc.NPCScriptManager;
- import net.sf.odinms.server.MonsterCarnival;
- import net.sf.odinms.server.MapleInventoryManipulator;
- import net.sf.odinms.server.life.MapleMonster;
- import net.sf.odinms.server.life.MobSkill;
- import net.sf.odinms.server.maps.MapleMap;
- import net.sf.odinms.server.maps.MapleMapFactory;
- import net.sf.odinms.server.maps.MapleMapObject;
- import net.sf.odinms.server.maps.MapleSummon;
- import net.sf.odinms.server.maps.SavedLocationType;
- import net.sf.odinms.server.maps.FakeCharacter;
- import net.sf.odinms.server.PlayerInteraction.MaplePlayerShop;
- import net.sf.odinms.provider.MapleData;
- import net.sf.odinms.provider.MapleDataProvider;
- import net.sf.odinms.provider.MapleDataProviderFactory;
- import net.sf.odinms.tools.MaplePacketCreator;
- import net.sf.odinms.tools.Pair;
- import net.sf.odinms.net.channel.handler.DoubleCardHandler;
- import net.sf.odinms.net.world.MapleMessenger;
- import net.sf.odinms.net.world.MapleParty;
- import net.sf.odinms.server.MapleInventoryManipulator;
- import net.sf.odinms.server.MapleItemInformationProvider;
- import net.sf.odinms.server.MaplePortal;
- import net.sf.odinms.server.MapleShop;
- import net.sf.odinms.server.MapleStatEffect;
- import net.sf.odinms.server.MapleStorage;
- import net.sf.odinms.server.MapleTrade;
- import net.sf.odinms.server.TimerManager;
- import net.sf.odinms.server.maps.AbstractAnimatedMapleMapObject;
- import net.sf.odinms.server.maps.MapleDoor;
- import net.sf.odinms.server.maps.MapleMapObjectType;
- import net.sf.odinms.server.maps.SavedLocationType;
- import net.sf.odinms.server.maps.SummonMovementType;
- import net.sf.odinms.server.quest.MapleCustomQuest;
- import net.sf.odinms.server.quest.MapleQuest;
- import net.sf.odinms.tools.MaplePacketCreator;
- import net.sf.odinms.tools.Pair;
- import net.sf.odinms.database.DatabaseConnection;
- import net.sf.odinms.net.PacketProcessor;
- import net.sf.odinms.net.world.MapleMessenger;
- import net.sf.odinms.net.world.MapleParty;
- import net.sf.odinms.net.world.PartyOperation;
- import net.sf.odinms.net.world.PlayerCoolDownValueHolder;
- import net.sf.odinms.server.MTSItemInfo;
- import net.sf.odinms.net.world.guild.MapleGuild;
- import net.sf.odinms.net.world.guild.MapleGuildCharacter;
- import net.sf.odinms.net.world.remote.WorldChannelInterface;
- import net.sf.odinms.server.PlayerInteraction.MaplePlayerShopItem;
- import net.sf.odinms.server.life.MapleMonster;
- import net.sf.odinms.server.life.MobSkill;
- import net.sf.odinms.server.maps.FakeCharacter;
- import net.sf.odinms.server.maps.MapleMap;
- import net.sf.odinms.server.maps.MapleMapFactory;
- import net.sf.odinms.server.maps.MapleMapObject;
- import net.sf.odinms.server.PlayerInteraction.HiredMerchant;
- import net.sf.odinms.server.PlayerInteraction.IPlayerInteractionManager;
- import net.sf.odinms.server.maps.MapleSummon;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- public class MapleCharacter extends AbstractAnimatedMapleMapObject implements InventoryContainer {
- private static Logger log = LoggerFactory.getLogger(PacketProcessor.class);
- public static final double MAX_VIEW_RANGE_SQ = 850 * 850;
- private int world;
- private int accountid;
- private int rank;
- private boolean expEnabled = true;
- private int rankMove;
- private boolean GMScroll;
- private boolean blessed;
- private String engager = null;
- private int jobRank;
- private int jobRankMove;
- private String name;
- private int Mesomode;
- private int energybar;
- private int bombpoints;
- private int level, reborns;
- private int str, dex, luk, int_;
- private AtomicInteger exp = new AtomicInteger();
- private int hp, maxhp;
- private boolean godmode;
- private ChannelServer cserv;
- private int cp = 0;
- private int totCP = 0;
- private int cpqRanking = 0;
- private int mp, maxmp;
- private int mpApUsed, hpApUsed;
- private int hair, face;
- private AtomicInteger meso = new AtomicInteger();
- private int remainingAp, remainingSp;
- private int savedLocations[];
- private int fame;
- private long lastfametime;
- private List<Integer> lastmonthfameids;
- private transient int localmaxhp, localmaxmp;
- private transient int localstr, localdex, localluk, localint;
- private transient int magic, watk;
- private transient double speedMod, jumpMod;
- private transient int localmaxbasedamage;
- private int id;
- private MapleClient client;
- private MapleMap map;
- private int initialSpawnPoint; // mapid is only used when calling getMapId() with map == null, it is not updated when running in channelserver mode
- private int mapid;
- private MapleShop shop = null;
- private IPlayerInteractionManager interaction = null;
- private MapleStorage storage = null;
- private MaplePet[] pets = new MaplePet[3];
- private ScheduledFuture<?> fullnessSchedule;
- private ScheduledFuture<?> fullnessSchedule_1;
- private ScheduledFuture<?> fullnessSchedule_2;
- private SkillMacro[] skillMacros = new SkillMacro[5];
- private static List<Pair<Byte, Integer>> inventorySlots = new ArrayList<Pair<Byte, Integer>>();
- private MapleTrade trade = null;
- private boolean challenged = false;
- private MapleSkinColor skinColor = MapleSkinColor.NORMAL;
- private MapleJob job = MapleJob.BEGINNER;
- private int gender;
- private int vip, item;
- private boolean gmchattype = true;
- private int Gm;
- public int dropmeso;
- private int gmLevel;
- private boolean hidden;
- private boolean canDoor = true;
- private int chair;
- private int itemEffect;
- private int APQScore;
- private MapleParty party;
- private EventInstanceManager eventInstance = null;
- private MapleInventory[] inventory;
- private Map<MapleQuest, MapleQuestStatus> quests;
- private Set<MapleMonster> controlled = new LinkedHashSet<MapleMonster>();
- private Set<MapleMapObject> visibleMapObjects = new LinkedHashSet<MapleMapObject>();
- private Map<ISkill, SkillEntry> skills = new LinkedHashMap<ISkill, SkillEntry>();
- private Map<MapleBuffStat, MapleBuffStatValueHolder> effects = new LinkedHashMap<MapleBuffStat, MapleBuffStatValueHolder>();
- private HashMap<Integer, MapleKeyBinding> keymap = new LinkedHashMap<Integer, MapleKeyBinding>();
- private List<MapleDoor> doors = new ArrayList<MapleDoor>();
- private Map<Integer, MapleSummon> summons = new LinkedHashMap<Integer, MapleSummon>();
- private BuddyList buddylist;
- private Map<Integer, MapleCoolDownValueHolder> coolDowns = new LinkedHashMap<Integer, MapleCoolDownValueHolder>(); // anticheat related information
- private CheatTracker anticheat;
- private ScheduledFuture<?> dragonBloodSchedule;
- private ScheduledFuture<?> mapTimeLimitTask = null; //guild related information
- private int guildid;
- private int guildrank, allianceRank;
- private MapleGuildCharacter mgc = null; // cash shop related information
- private int paypalnx = 0, maplepoints = 0, cardnx = 0;
- private boolean incs, inmts;
- private int currentPage = 0, currentType = 0, currentTab = 1;
- private MapleMessenger messenger = null;
- int messengerposition = 4;
- private ScheduledFuture<?> hpDecreaseTask;
- private List<MapleDisease> diseases = new ArrayList<MapleDisease>();
- public boolean spawned;
- private ScheduledFuture<?> beholderHealingSchedule;
- private ScheduledFuture<?> beholderBuffSchedule;
- private ScheduledFuture<?> BerserkSchedule;
- private boolean Berserk = false;
- public SummonMovementType getMovementType;
- private MonsterCarnival monsterCarnival;
- private String chalktext; // Chalkboard
- // ------- CPQ ---------
- private int CP;
- private int totalCP;
- private int team;
- // ------ Marriage -------
- private boolean married = false;
- private boolean maxStatScroll = false;
- private int donatorpoints;
- private int partnerid;
- private int marriageQuestLevel;
- // ------ Spam Block -------
- private boolean canSmega = true;
- private boolean smegaEnabled = true;
- private boolean canTalk = true;
- // ------- Misc. ------------
- private int zakumLvl; //zero means they havent started yet
- private List<FakeCharacter> fakes = new ArrayList<FakeCharacter>();
- private boolean isfake = false;
- private int clan;
- private int pvpkills;
- private int pvpdeaths;
- private int donatePoints = 0;
- private MapleMount maplemount;
- private int gmtext = 0;
- // -------- Calc. Dmg ---------
- private double sword;
- private double blunt;
- private double axe;
- private double spear;
- private double polearm;
- private double claw;
- private double dagger;
- private MaplePlayerShop playerShop = null;
- public int juankuan;
- private double staffwand = 0.1;
- private double crossbow;
- private double bow;
- private int skill = 0;
- private ISkill skil;
- private int maxDis;
- public int mpoints = 0;
- public int paypalNX = 0;
- private int slots = 0;
- private long playerkill;
- private transient int wdef, mdef;
- //private List<Integer> jobs = new ArrayList<Integer>();
- private long afkTime;
- private long lastLogin = 0;
- private int ringRequest;
- private boolean hasMerchant;
- private int gm;
- public MapleCharacter() {
- setStance(0);
- inventory = new MapleInventory[MapleInventoryType.values().length];
- for (MapleInventoryType type : MapleInventoryType.values()) {
- inventory[type.ordinal()] = new MapleInventory(type, (byte) 100);
- }
- savedLocations = new int[SavedLocationType.values().length];
- for (int i = 0; i < SavedLocationType.values().length; i++) {
- savedLocations[i] = -1;
- }
- quests = new LinkedHashMap<MapleQuest, MapleQuestStatus>();
- anticheat = new CheatTracker(this);
- afkTime = System.currentTimeMillis();
- setPosition(new Point(0, 0));
- }
- public MapleCharacter getThis() {
- return this;
- }
- public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver) throws SQLException {
- MapleCharacter ret = new MapleCharacter();
- ret.client = client;
- ret.id = charid;
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
- ps.setInt(1, charid);
- ResultSet rs = ps.executeQuery();
- if (!rs.next()) {
- throw new RuntimeException("Loading the Char Failed (char not found)");
- }
- ret.name = rs.getString("name");
- ret.level = rs.getInt("level");
- ret.pvpdeaths = rs.getInt("pvpdeaths");
- ret.pvpkills = rs.getInt("pvpkills");
- ret.reborns = rs.getInt("reborns");
- ret.fame = rs.getInt("fame");
- ret.vip = rs.getInt("vip");
- ret.str = rs.getInt("str");
- ret.dex = rs.getInt("dex");
- ret.int_ = rs.getInt("int");
- ret.luk = rs.getInt("luk");
- ret.exp.set(rs.getInt("exp"));
- if (ret.exp.get() < 0) {
- ret.exp.set(0);
- }
- ret.hp = rs.getInt("hp");
- if (ret.hp < 50) {
- ret.hp = 50;
- }
- ret.maxhp = rs.getInt("maxhp");
- ret.mp = rs.getInt("mp");
- if (ret.mp < 50) {
- ret.mp = 50;
- }
- ret.maxmp = rs.getInt("maxmp");
- ret.hpApUsed = rs.getInt("hpApUsed");
- ret.mpApUsed = rs.getInt("mpApUsed");
- ret.hasMerchant = rs.getInt("HasMerchant") == 1;
- ret.remainingSp = rs.getInt("sp");
- ret.remainingAp = rs.getInt("ap");
- ret.meso.set(rs.getInt("meso"));
- ret.gmLevel = rs.getInt("gm");
- ret.vip = rs.getInt("vip");
- ret.clan = rs.getInt("clan");
- int mountexp = rs.getInt("mountexp");
- int mountlevel = rs.getInt("mountlevel");
- int mounttiredness = rs.getInt("mounttiredness");
- ret.married = rs.getInt("married") == 0 ? false : true;
- ret.partnerid = rs.getInt("partnerid");
- ret.marriageQuestLevel = rs.getInt("marriagequest");
- ret.zakumLvl = rs.getInt("zakumLvl");
- ret.skinColor = MapleSkinColor.getById(rs.getInt("skincolor"));
- ret.gender = rs.getInt("gender");
- ret.job = MapleJob.getById(rs.getInt("job"));
- ret.hair = rs.getInt("hair");
- ret.face = rs.getInt("face");
- ret.accountid = rs.getInt("accountid");
- ret.mapid = rs.getInt("map");
- ret.initialSpawnPoint = rs.getInt("spawnpoint");
- ret.world = rs.getInt("world");
- ret.rank = rs.getInt("rank");
- ret.rankMove = rs.getInt("rankMove");
- ret.jobRank = rs.getInt("jobRank");
- ret.jobRankMove = rs.getInt("jobRankMove");
- ret.guildid = rs.getInt("guildid");
- ret.guildrank = rs.getInt("guildrank");
- ret.allianceRank = rs.getInt("allianceRank");
- if (ret.guildid > 0) {
- ret.mgc = new MapleGuildCharacter(ret);
- }
- int buddyCapacity = rs.getInt("buddyCapacity");
- ret.buddylist = new BuddyList(buddyCapacity);
- ret.gmtext = rs.getInt("gmtext");
- if (channelserver) {
- MapleMapFactory mapFactory = ChannelServer.getInstance(client.getChannel()).getMapFactory();
- ret.map = mapFactory.getMap(ret.mapid);
- if (ret.map == null) { //char is on a map that doesn't exist warp it to henesys
- ret.map = mapFactory.getMap(100000000);
- }
- MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
- if (portal == null) {
- portal = ret.map.getPortal(0); // char is on a spawnpoint that doesn't exist - select the first spawnpoint instead
- ret.initialSpawnPoint = 0;
- }
- ret.setPosition(portal.getPosition());
- int partyid = rs.getInt("party");
- if (partyid >= 0) {
- try {
- MapleParty party = client.getChannelServer().getWorldInterface().getParty(partyid);
- if (party != null && party.getMemberById(ret.id) != null) {
- ret.party = party;
- }
- } catch (RemoteException e) {
- client.getChannelServer().reconnectWorld();
- }
- }
- int messengerid = rs.getInt("messengerid");
- int position = rs.getInt("messengerposition");
- if (messengerid > 0 && position < 4 && position > -1) {
- try {
- WorldChannelInterface wci = ChannelServer.getInstance(client.getChannel()).getWorldInterface();
- MapleMessenger messenger = wci.getMessenger(messengerid);
- if (messenger != null) {
- ret.messenger = messenger;
- ret.messengerposition = position;
- }
- } catch (RemoteException e) {
- client.getChannelServer().reconnectWorld();
- }
- }
- }
- rs.close();
- ps.close();
- 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.getClient().setAccountPass(rs.getString("password"));
- ret.getClient().setGuest(rs.getInt("guest") > 0);
- ret.donatePoints = rs.getInt("donorPoints");
- ret.lastLogin = rs.getLong("LastLoginInMilliseconds");
- if (!ret.isGM()) {
- if (ret.donatePoints == 1) { // 3 donor levels o____o
- ret.gmLevel = 1;
- } else if (ret.donatePoints > 1) {
- ret.gmLevel = 2;
- }
- }
- ret.paypalnx = rs.getInt("paypalNX");
- ret.maplepoints = rs.getInt("mPoints");
- ret.cardnx = rs.getInt("cardNX");
- ret.donatorpoints = rs.getInt("donatorpoints");
- }
- rs.close();
- ps.close();
- String sql = "SELECT * FROM inventoryitems " + "LEFT JOIN inventoryequipment USING (inventoryitemid) " + "WHERE characterid = ?";
- if (!channelserver) {
- sql += " AND inventorytype = " + MapleInventoryType.EQUIPPED.getType();
- }
- ps = con.prepareStatement(sql);
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- MapleInventoryType type = MapleInventoryType.getByType((byte) rs.getInt("inventorytype"));
- if (type.equals(MapleInventoryType.EQUIP) || type.equals(MapleInventoryType.EQUIPPED)) {
- int itemid = rs.getInt("itemid");
- Equip equip = new Equip(itemid, (byte) rs.getInt("position"), rs.getInt("ringid"));
- equip.setOwner(rs.getString("owner"));
- equip.setQuantity((short) rs.getInt("quantity"));
- equip.setAcc((short) rs.getInt("acc"));
- equip.setAvoid((short) rs.getInt("avoid"));
- equip.setDex((short) rs.getInt("dex"));
- equip.setHands((short) rs.getInt("hands"));
- equip.setHp((short) rs.getInt("hp"));
- equip.setInt((short) rs.getInt("int"));
- equip.setJump((short) rs.getInt("jump"));
- equip.setLuk((short) rs.getInt("luk"));
- equip.setMatk((short) rs.getInt("matk"));
- equip.setMdef((short) rs.getInt("mdef"));
- equip.setMp((short) rs.getInt("mp"));
- equip.setSpeed((short) rs.getInt("speed"));
- equip.setStr((short) rs.getInt("str"));
- equip.setWatk((short) rs.getInt("watk"));
- equip.setWdef((short) rs.getInt("wdef"));
- equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
- equip.setLocked((byte) rs.getInt("locked"));
- equip.setLevel((byte) rs.getInt("level"));
- ret.getInventory(type).addFromDB(equip);
- } else {
- Item item = new Item(rs.getInt("itemid"), (byte) rs.getInt("position"), (short) rs.getInt("quantity"), rs.getInt("petid"));
- item.setOwner(rs.getString("owner"));
- ret.getInventory(type).addFromDB(item);
- }
- }
- rs.close();
- ps.close();
- if (channelserver) {
- ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- PreparedStatement pse = con.prepareStatement("SELECT * FROM queststatusmobs WHERE queststatusid = ?");
- while (rs.next()) {
- MapleQuest q = MapleQuest.getInstance(rs.getInt("quest"));
- MapleQuestStatus status = new MapleQuestStatus(q, MapleQuestStatus.Status.getById(rs.getInt("status")));
- long cTime = rs.getLong("time");
- if (cTime > -1) {
- status.setCompletionTime(cTime * 1000);
- }
- status.setForfeited(rs.getInt("forfeited"));
- 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();
- ps = con.prepareStatement("SELECT skillid,skilllevel,masterlevel FROM skills WHERE characterid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- ret.skills.put(SkillFactory.getSkill(rs.getInt("skillid")), new SkillEntry(rs.getInt("skilllevel"), rs.getInt("masterlevel")));
- }
- rs.close();
- ps.close();
- ps = con.prepareStatement("SELECT * FROM skillmacros WHERE characterid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- int skill1 = rs.getInt("skill1");
- int skill2 = rs.getInt("skill2");
- int skill3 = rs.getInt("skill3");
- String name = rs.getString("name");
- int shout = rs.getInt("shout");
- int position = rs.getInt("position");
- SkillMacro macro = new SkillMacro(skill1, skill2, skill3, name, shout, position);
- ret.skillMacros[position] = macro;
- }
- rs.close();
- ps.close();
- ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- int key = rs.getInt("key");
- int type = rs.getInt("type");
- int action = rs.getInt("action");
- ret.keymap.put(Integer.valueOf(key), new MapleKeyBinding(type, action));
- }
- rs.close();
- ps.close();
- ps = con.prepareStatement("SELECT `locationtype`,`map` FROM savedlocations WHERE characterid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- String locationType = rs.getString("locationtype");
- int mapid = rs.getInt("map");
- ret.savedLocations[SavedLocationType.valueOf(locationType).ordinal()] = mapid;
- }
- 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 = 0;
- ret.lastmonthfameids = new ArrayList<Integer>(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();
- ret.buddylist.loadFromDb(charid);
- ret.storage = MapleStorage.loadOrCreateFromDB(ret.accountid);
- }
- if (ret.getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -18) != null) {
- ret.maplemount = new MapleMount(ret, ret.getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -18).getItemId(), 1004);
- ret.maplemount.setExp(mountexp);
- ret.maplemount.setLevel(mountlevel);
- ret.maplemount.setTiredness(mounttiredness);
- ret.maplemount.setActive(false);
- } else {
- ret.maplemount = new MapleMount(ret, 0, 1004);
- ret.maplemount.setExp(mountexp);
- ret.maplemount.setLevel(mountlevel);
- ret.maplemount.setTiredness(mounttiredness);
- ret.maplemount.setActive(false);
- }
- /*
- ps = con.prepareStatement("SELECT jobid FROM JobChanges WHERE cid = ?");
- ps.setInt(1, charid);
- rs = ps.executeQuery();
- while (rs.next()) {
- ret.jobs.add(rs.getInt("jobid"));
- }
- java.util.Collections.sort(ret.jobs);
- rs.close();
- ps.close();
- */
- ret.recalcLocalStats();
- ret.silentEnforceMaxHpMp();
- return ret;
- }
- public static MapleCharacter getDefault(MapleClient client, int chrid) {
- MapleCharacter ret = getDefault(client);
- ret.id = chrid;
- return ret;
- }
- public static MapleCharacter getDefault(MapleClient client) {
- MapleCharacter ret = new MapleCharacter();
- ret.client = client;
- ret.hp = 50;
- ret.maxhp = 50;
- ret.mp = 5;
- ret.maxmp = 5;
- ret.map = null;
- ret.exp.set(0);
- ret.gmLevel = 0;
- ret.clan = -1;
- ret.job = MapleJob.BEGINNER;
- ret.meso.set(0);
- ret.level = 1;
- ret.vip = 0;
- ret.Gm = 1;
- ret.reborns = 0;
- ret.pvpdeaths = 0;
- ret.pvpkills = 0;
- ret.bombpoints = 0;
- ret.accountid = client.getAccID();
- ret.buddylist = new BuddyList(20);
- ret.CP = 0;
- ret.totalCP = 0;
- ret.team = -1;
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
- ps.setInt(1, ret.accountid);
- ResultSet rs = ps.executeQuery();
- rs = ps.executeQuery();
- if (rs.next()) {
- ret.getClient().setAccountName(rs.getString("name"));
- ret.getClient().setAccountPass(rs.getString("password"));
- ret.getClient().setGuest(rs.getInt("guest") > 0);
- ret.donatePoints = rs.getInt("donorPoints");
- ret.paypalnx = rs.getInt("paypalNX");
- ret.maplepoints = rs.getInt("mPoints");
- ret.cardnx = rs.getInt("cardNX");
- ret.donatorpoints = rs.getInt("donatorpoints");
- ret.lastLogin = rs.getLong("LastLoginInMilliseconds");
- }
- rs.close();
- ps.close();
- } catch (SQLException e) {
- System.err.println("ERROR");
- }
- ret.incs = false;
- ret.inmts = false;
- ret.APQScore = 0;
- ret.maplemount = null;
- ret.setDefaultKeyMap();
- ret.recalcLocalStats();
- return ret;
- }
- public void saveToDB(boolean update, boolean full) {
- Connection con = DatabaseConnection.getConnection();
- try {
- // clients should not be able to log back before their old state is saved (see MapleClient#getLoginState) so we are save to switch to a very low isolation level here
- con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
- // connections are thread local now, no need to synchronize anymore =)
- con.setAutoCommit(false);
- PreparedStatement ps;
- if (update) {
- 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 = ?, map = ?, meso = ?, hpApUsed = ?, mpApUsed = ?, spawnpoint = ?, party = ?, buddyCapacity = ?, messengerid = ?, messengerposition = ?, reborns = ?, pvpkills = ?, pvpdeaths = ?, clan = ?, mountlevel = ?, mountexp = ?, mounttiredness = ?, married = ?, partnerid = ?, zakumlvl = ?, marriagequest = ?, vip = ?, dropmeso = ?, juankuan = ? WHERE id = ?");
- } else {
- ps = con.prepareStatement("INSERT INTO characters (level, fame, str, dex, luk, `int`, exp, hp, mp, maxhp, maxmp, sp, ap, gm, skincolor, gender, job, hair, face, map, meso, hpApUsed, mpApUsed, spawnpoint, party, buddyCapacity, messengerid, messengerposition, reborns, pvpkills, pvpdeaths, clan, mountlevel, mountexp, mounttiredness, married, partnerid, zakumlvl, marriagequest, vip,dropmeso,juankuan, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- }
- ps.setInt(1, level);
- ps.setInt(2, fame);
- ps.setInt(3, str);
- ps.setInt(4, dex);
- ps.setInt(5, luk);
- ps.setInt(6, int_);
- ps.setInt(7, exp.get());
- ps.setInt(8, hp);
- ps.setInt(9, mp);
- ps.setInt(10, maxhp);
- ps.setInt(11, maxmp);
- ps.setInt(12, remainingSp);
- ps.setInt(13, remainingAp);
- ps.setInt(14, gmLevel);
- ps.setInt(15, skinColor.getId());
- ps.setInt(16, gender);
- ps.setInt(17, job.getId());
- ps.setInt(18, hair);
- ps.setInt(19, face);
- if (map == null) {
- ps.setInt(20, 0);
- } else {
- if (map.getForcedReturnId() != 999999999) {
- ps.setInt(20, map.getForcedReturnId());
- } else {
- ps.setInt(20, map.getId());
- }
- }
- ps.setInt(21, meso.get());
- ps.setInt(22, hpApUsed);
- ps.setInt(23, mpApUsed);
- if (map == null || map.getId() == 610020000 || map.getId() == 610020001) {
- ps.setInt(24, 0);
- } else {
- MaplePortal closest = map.findClosestSpawnpoint(getPosition());
- if (closest != null) {
- ps.setInt(24, closest.getId());
- } else {
- ps.setInt(24, 0);
- }
- }
- if (party != null) {
- ps.setInt(25, party.getId());
- } else {
- ps.setInt(25, -1);
- }
- ps.setInt(26, buddylist.getCapacity());
- if (messenger != null) {
- ps.setInt(27, messenger.getId());
- ps.setInt(28, messengerposition);
- } else {
- ps.setInt(27, 0);
- ps.setInt(28, 4);
- }
- ps.setInt(29, reborns);
- ps.setInt(30, pvpkills);
- ps.setInt(31, pvpdeaths);
- ps.setInt(32, clan);
- if (maplemount != null) {
- ps.setInt(33, maplemount.getLevel());
- ps.setInt(34, maplemount.getExp());
- ps.setInt(35, maplemount.getTiredness());
- } else {
- ps.setInt(33, 1);
- ps.setInt(34, 0);
- ps.setInt(35, 0);
- }
- ps.setInt(36, married ? 1 : 0);
- ps.setInt(37, partnerid);
- ps.setInt(38, zakumLvl > 2 ? 2 : zakumLvl);
- ps.setInt(39, marriageQuestLevel);
- ps.setInt(40, vip);
- ps.setInt(41, juankuan);
- ps.setInt(42, dropmeso);
- if (update) {
- ps.setInt(43, id);
- } else {
- ps.setInt(43, accountid);
- ps.setString(44, name);
- ps.setInt(45, world);
- }
- if (!full) {
- ps.executeUpdate();
- } else {
- int updateRows = ps.executeUpdate();
- if (!update) {
- ResultSet rs = ps.getGeneratedKeys();
- if (rs.next()) {
- this.id = rs.getInt(1);
- } else {
- throw new DatabaseException("Inserting char failed.");
- }
- } else if (updateRows < 1) {
- throw new DatabaseException("Character not in database (" + id + ")");
- }
- ps.close();
- for (int i = 0; i < 3; i++) {
- if (pets[i] != null) {
- pets[i].saveToDb();
- } else {
- break;
- }
- }
- deleteWhereCharacterId(con, "DELETE FROM skillmacros WHERE characterid = ?");
- for (int i = 0; i < 5; i++) {
- SkillMacro macro = skillMacros[i];
- if (macro != null) {
- ps = con.prepareStatement("INSERT INTO skillmacros (characterid, skill1, skill2, skill3, name, shout, position) VALUES (?, ?, ?, ?, ?, ?, ?)");
- ps.setInt(1, 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.executeUpdate();
- ps.close();
- }
- }
- deleteWhereCharacterId(con, "DELETE FROM inventoryitems WHERE characterid = ?");
- ps = con.prepareStatement("INSERT INTO inventoryitems (characterid, itemid, inventorytype, position, quantity, owner, petid) VALUES (?, ?, ?, ?, ?, ?, ?)");
- PreparedStatement pse = con.prepareStatement("INSERT INTO inventoryequipment VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- for (MapleInventory iv : inventory) {
- ps.setInt(3, iv.getType().getType());
- for (IItem item : iv.list()) {
- ps.setInt(1, id);
- ps.setInt(2, item.getItemId());
- ps.setInt(4, item.getPosition());
- ps.setInt(5, item.getQuantity());
- ps.setString(6, item.getOwner());
- ps.setInt(7, item.getPetId());
- ps.executeUpdate();
- ResultSet rs = ps.getGeneratedKeys();
- int itemid;
- if (rs.next()) {
- itemid = rs.getInt(1);
- } else {
- throw new DatabaseException("Inserting char failed.");
- }
- if (iv.getType().equals(MapleInventoryType.EQUIP) || iv.getType().equals(MapleInventoryType.EQUIPPED)) {
- pse.setInt(1, itemid);
- IEquip equip = (IEquip) item;
- pse.setInt(2, equip.getUpgradeSlots());
- pse.setInt(3, equip.getLevel());
- pse.setInt(4, equip.getStr());
- pse.setInt(5, equip.getDex());
- pse.setInt(6, equip.getInt());
- pse.setInt(7, equip.getLuk());
- pse.setInt(8, equip.getHp());
- pse.setInt(9, equip.getMp());
- pse.setInt(10, equip.getWatk());
- pse.setInt(11, equip.getMatk());
- pse.setInt(12, equip.getWdef());
- pse.setInt(13, equip.getMdef());
- pse.setInt(14, equip.getAcc());
- pse.setInt(15, equip.getAvoid());
- pse.setInt(16, equip.getHands());
- pse.setInt(17, equip.getSpeed());
- pse.setInt(18, equip.getJump());
- pse.setInt(19, equip.getRingId());
- pse.setInt(20, equip.getLocked());
- pse.executeUpdate();
- }
- }
- }
- ps.close();
- pse.close();
- deleteWhereCharacterId(con, "DELETE FROM queststatus WHERE characterid = ?");
- ps = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `forfeited`) VALUES (DEFAULT, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
- pse = con.prepareStatement("INSERT INTO queststatusmobs VALUES (DEFAULT, ?, ?, ?)");
- ps.setInt(1, id);
- for (MapleQuestStatus q : quests.values()) {
- ps.setInt(2, q.getQuest().getId());
- ps.setInt(3, q.getStatus().getId());
- ps.setInt(4, (int) (q.getCompletionTime() / 1000));
- ps.setInt(5, q.getForfeited());
- ps.executeUpdate();
- ResultSet rs = ps.getGeneratedKeys();
- rs.next();
- for (int mob : q.getMobKills().keySet()) {
- pse.setInt(1, rs.getInt(1));
- pse.setInt(2, mob);
- pse.setInt(3, q.getMobKills(mob));
- pse.executeUpdate();
- }
- rs.close();
- }
- ps.close();
- pse.close();
- deleteWhereCharacterId(con, "DELETE FROM skills WHERE characterid = ?");
- ps = con.prepareStatement("INSERT INTO skills (characterid, skillid, skilllevel, masterlevel) VALUES (?, ?, ?, ?)");
- ps.setInt(1, id);
- for (Entry<ISkill, SkillEntry> skill_ : skills.entrySet()) {
- ps.setInt(2, skill_.getKey().getId());
- ps.setInt(3, skill_.getValue().skillevel);
- ps.setInt(4, skill_.getValue().masterlevel);
- ps.executeUpdate();
- }
- ps.close();
- deleteWhereCharacterId(con, "DELETE FROM keymap WHERE characterid = ?");
- ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
- ps.setInt(1, id);
- for (Entry<Integer, MapleKeyBinding> keybinding : keymap.entrySet()) {
- ps.setInt(2, keybinding.getKey().intValue());
- ps.setInt(3, keybinding.getValue().getType());
- ps.setInt(4, keybinding.getValue().getAction());
- ps.executeUpdate();
- }
- ps.close();
- deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?");
- ps = con.prepareStatement("INSERT INTO savedlocations (characterid, `locationtype`, `map`) VALUES (?, ?, ?)");
- ps.setInt(1, id);
- for (SavedLocationType savedLocationType : SavedLocationType.values()) {
- if (savedLocations[savedLocationType.ordinal()] != -1) {
- ps.setString(2, savedLocationType.name());
- ps.setInt(3, savedLocations[savedLocationType.ordinal()]);
- ps.executeUpdate();
- }
- }
- ps.close();
- deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ? AND pending = 0");
- ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`) VALUES (?, ?, 0)");
- ps.setInt(1, id);
- for (BuddylistEntry entry : buddylist.getBuddies()) {
- if (entry.isVisible()) {
- ps.setInt(2, entry.getCharacterId());
- ps.executeUpdate();
- }
- }
- ps.close();
- ps = con.prepareStatement("UPDATE accounts SET `paypalNX` = ?, `mPoints` = ?, `cardNX` = ?, `donorPoints` = ?, `donatorpoints` = ? WHERE id = ?");
- ps.setInt(1, paypalnx);
- ps.setInt(2, maplepoints);
- ps.setInt(3, cardnx);
- ps.setInt(4, donatePoints);
- ps.setInt(5, donatorpoints);
- ps.setInt(6, client.getAccID());
- ps.executeUpdate();
- ps.close();
- if (storage != null) {
- storage.saveToDB();
- }
- }
- con.commit();
- } catch (Exception e) {
- log.error(MapleClient.getLogMessage(this, "[charsave] Error saving character data"), e);
- try {
- con.rollback();
- } catch (SQLException e1) {
- log.error(MapleClient.getLogMessage(this, "[charsave] Error Rolling Back"), e);
- }
- } finally {
- try {
- con.setAutoCommit(true);
- con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
- } catch (SQLException e) {
- log.error(MapleClient.getLogMessage(this, "[charsave] Error going back to autocommit mode"), e);
- }
- }
- }
- public void setGMLevel(int level) {
- if (level >= 5) {
- this.gmLevel = 5;
- } else if (level <= 0) {
- this.gmLevel = 0;
- } else {
- this.gmLevel = level;
- }
- }
- public boolean isGM() {
- return gmLevel >= 3;
- }
- public int getGMLevel() {
- return gmLevel;
- }
- public boolean hasGmLevel(int level) {
- return gmLevel >= level;
- }
- public void setVip(int amount) {
- if (amount > 4) {
- this.vip = 4;
- } else if (amount <= -4) {
- this.vip = -4;
- } else {
- this.vip = amount;
- }
- }
- public int getGm() {
- return gm;
- }
- public int getVip() {
- return vip;
- }
- public int getItemId() {
- return item;
- }
- public void gainGm(int amount) {
- this.gm += amount;
- }
- public void gainVip(int amount) {
- this.vip += amount;
- }
- public void gainjuankuan(int amount) {
- this.juankuan += amount;
- }
- public void setDropmeso(int dropmeso) {
- this.dropmeso = dropmeso;
- }
- public Object getChannelSever() {
- throw new UnsupportedOperationException("Not yet implemented");
- }
- public IItem lockitem(int slot, boolean lock, int type)
- {
- byte set = 0;
- byte eqslot = (byte)slot;
- ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(getClient());
- Equip nEquip = (Equip)getInventory(MapleInventoryType.USE).getItem(eqslot);
- if (type == 1)
- nEquip = (Equip)getInventory(MapleInventoryType.EQUIP).getItem(eqslot);
- else
- if (type == 2)
- nEquip = (Equip)getInventory(MapleInventoryType.ETC).getItem(eqslot);
- else
- if (type == 3)
- nEquip = (Equip)getInventory(MapleInventoryType.CASH).getItem(eqslot);
- if (nEquip != null)
- {
- if (lock)
- {
- set = 1;
- cm.dropMessage((new StringBuilder()).append("恭喜,锁定物品: ").append(slot).append(" 成功!").toString());
- } else
- {
- cm.dropMessage((new StringBuilder()).append("恭喜,解锁物品: ").append(slot).append(" 成功!").toString());
- }
- nEquip.setLocked(set);
- getClient().getSession().write(MaplePacketCreator.getCharInfo(this));
- getMap().removePlayer(this);
- getMap().addPlayer(this);
- } else
- {
- cm.dropMessage((new StringBuilder()).append("Item Slot ").append(slot).append(" Equip Null.").toString());
- }
- return nEquip;
- }
- public void deleteNullItem(int id) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
- public void gainExp(long l, boolean b, boolean b0, boolean highestDamage) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
- public IItem lockitem1(int slot, boolean lock) {
- byte set = (byte) 0;
- byte eqslot = (byte) slot;
- ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(this.getClient());
- Equip nEquip = (Equip) this.getInventory(MapleInventoryType.EQUIP).getItem(eqslot);
- if (nEquip != null) {
- if (lock) {
- set = (byte) 1;
- cm.dropMessage("锁定装备: " + slot + " 成功");
- } else {
- cm.dropMessage("解锁装备: " + slot + " 成功");
- }
- nEquip.setLocked(set);
- getClient().getSession().write(MaplePacketCreator.getCharInfo(this));
- getMap().removePlayer(this);
- getMap().addPlayer(this);
- } else {
- cm.dropMessage("Item Slot " + slot + " Equip Null.");
- }
- return nEquip;
- }
- public int getmPoints() {
- return this.mpoints;
- }
- public int getpaypalNX() {
- return this.paypalNX;
- }
- public int getDropmeso() {
- return dropmeso;
- }
- public int getjuankuan() {
- return juankuan;
- }
- public int getNX() {
- return paypalnx;
- }
- public void gainNX(int amount) {
- this.paypalnx += amount;
- }
- public void setName(String name) {
- this.name = name;
- }
- private void deleteWhereCharacterId(Connection con, String sql) throws SQLException {
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setInt(1, id);
- ps.executeUpdate();
- ps.close();
- }
- public MapleQuestStatus getQuest(MapleQuest quest) {
- if (!quests.containsKey(quest)) {
- return new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
- }
- return quests.get(quest);
- }
- public void updateQuest(MapleQuestStatus quest) {
- quests.put(quest.getQuest(), quest);
- if (!(quest.getQuest() instanceof MapleCustomQuest)) {
- if (quest.getStatus().equals(MapleQuestStatus.Status.STARTED)) {
- client.getSession().write(MaplePacketCreator.startQuest(this, (short) quest.getQuest().getId()));
- client.getSession().write(MaplePacketCreator.updateQuestInfo(this, (short) quest.getQuest().getId(), quest.getNpc(), (byte) 8));
- } else if (quest.getStatus().equals(MapleQuestStatus.Status.COMPLETED)) {
- client.getSession().write(MaplePacketCreator.completeQuest(this, (short) quest.getQuest().getId()));
- } else if (quest.getStatus().equals(MapleQuestStatus.Status.NOT_STARTED)) {
- client.getSession().write(MaplePacketCreator.forfeitQuest(this, (short) quest.getQuest().getId()));
- }
- }
- }
- public boolean getGMChat() {
- return gmchattype;
- }
- public static int getIdByName(String name, int world) {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps;
- try {
- ps = con.prepareStatement("SELECT id FROM characters WHERE name = ? AND world = ?");
- ps.setString(1, name);
- ps.setInt(2, world);
- ResultSet rs = ps.executeQuery();
- if (!rs.next()) {
- ps.close();
- return -1;
- }
- int id = rs.getInt("id");
- ps.close();
- return id;
- } catch (SQLException e) {
- System.err.println("ERROR");
- }
- return -1;
- }
- public static String getNameById(int id, int world) {
- Connection con = DatabaseConnection.getConnection();
- try {
- PreparedStatement ps = con.prepareStatement("SELECT name FROM characters WHERE id = ? AND world = ?");
- ps.setInt(1, id);
- ps.setInt(2, world);
- ResultSet rs = ps.executeQuery();
- if (!rs.next()) {
- ps.close();
- return null;
- }
- String name = rs.getString("name");
- ps.close();
- return name;
- } catch (SQLException e) {
- System.err.println("ERROR");
- }
- return null;
- }
- public Integer getBuffedValue(MapleBuffStat effect) {
- MapleBuffStatValueHolder mbsvh = effects.get(effect);
- if (mbsvh == null) {
- return null;
- }
- return Integer.valueOf(mbsvh.value);
- }
- public boolean isBuffFrom(MapleBuffStat stat, ISkill skill) {
- MapleBuffStatValueHolder mbsvh = effects.get(stat);
- if (mbsvh == null) {
- return false;
- }
- return mbsvh.effect.isSkill() && mbsvh.effect.getSourceId() == skill.getId();
- }
- public int getBuffSource(MapleBuffStat stat) {
- MapleBuffStatValueHolder mbsvh = effects.get(stat);
- if (mbsvh == null) {
- return -1;
- }
- return mbsvh.effect.getSourceId();
- }
- public int getRingRequested() {
- return this.ringRequest;
- }
- public void setRingRequested(int set) {
- ringRequest = set;
- }
- public int getItemQuantity(int itemid, boolean checkEquipped) {
- MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
- MapleInventory iv = inventory[type.ordinal()];
- int possesed = iv.countById(itemid);
- if (checkEquipped) {
- possesed += inventory[MapleInventoryType.EQUIPPED.ordinal()].countById(itemid);
- }
- return possesed;
- }
- public void setBuffedValue(MapleBuffStat effect, int value) {
- MapleBuffStatValueHolder mbsvh = effects.get(effect);
- if (mbsvh == null) {
- return;
- }
- mbsvh.value = value;
- }
- public Long getBuffedStarttime(MapleBuffStat effect) {
- MapleBuffStatValueHolder mbsvh = effects.get(effect);
- if (mbsvh == null) {
- return null;
- }
- return Long.valueOf(mbsvh.startTime);
- }
- public MapleStatEffect getStatForBuff(MapleBuffStat effect) {
- MapleBuffStatValueHolder mbsvh = effects.get(effect);
- if (mbsvh == null) {
- return null;
- }
- return mbsvh.effect;
- }
- private void prepareDragonBlood(final MapleStatEffect bloodEffect) {
- if (dragonBloodSchedule != null) {
- dragonBloodSchedule.cancel(false);
- }
- dragonBloodSchedule = TimerManager.getInstance().register(new Runnable() {
- @Override
- public void run() {
- addHP(-bloodEffect.getX());
- getClient().getSession().write(MaplePacketCreator.showOwnBuffEffect(bloodEffect.getSourceId(), 5));
- getMap().broadcastMessage(MapleCharacter.this, MaplePacketCreator.showBuffeffect(getId(), bloodEffect.getSourceId(), 5, (byte) 3), false);
- }
- }, 4000, 4000);
- }
- public void startFullnessSchedule(final int decrease, final MaplePet pet, int petSlot) {
- ScheduledFuture<?> schedule = TimerManager.getInstance().register(new Runnable() {
- @Override
- public void run() {
- if (pet != null) {
- int newFullness = pet.getFullness() - decrease;
- if (newFullness <= 5) {
- pet.setFullness(15);
- unequipPet(pet, true, true);
- } else {
- pet.setFullness(newFullness);
- getClient().getSession().write(MaplePacketCreator.updatePet(pet, true));
- }
- }
- }
- }, 60000, 60000);
- switch (petSlot) {
- case 0:
- fullnessSchedule = schedule;
- case 1:
- fullnessSchedule_1 = schedule;
- case 2:
- fullnessSchedule_2 = schedule;
- }
- }
- public void cancelFullnessSchedule(int petSlot) {
- switch (petSlot) {
- case 0:
- fullnessSchedule.cancel(false);
- case 1:
- fullnessSchedule_1.cancel(false);
- case 2:
- fullnessSchedule_2.cancel(false);
- }
- }
- public void startMapTimeLimitTask(final MapleMap from, final MapleMap to) {
- if (to.getTimeLimit() > 0 && from != null) {
- final MapleCharacter chr = this;
- mapTimeLimitTask = TimerManager.getInstance().register(new Runnable() {
- @Override
- public void run() {
- MaplePortal pfrom = null;
- if (MapleItemInformationProvider.getInstance().isMiniDungeonMap(from.getId())) {
- pfrom = from.getPortal("MD00");
- } else {
- pfrom = from.getPortal(0);
- }
- if (pfrom != null) {
- chr.changeMap(from, pfrom);
- }
- }
- }, from.getTimeLimit() * 1000, from.getTimeLimit() * 1000);
- }
- }
- public boolean tempHasItems() {
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- Connection con = DatabaseConnection.getConnection();
- ps = con.prepareStatement("SELECT ownerid FROM hiredmerchanttemp WHERE ownerid = ?");
- ps.setInt(1, getId());
- rs = ps.executeQuery();
- if (rs.next()) {
- rs.close();
- ps.close();
- return true;
- }
- rs.close();
- ps.close();
- } catch (SQLException se) {
- System.err.println("错误:"+se);
- } finally {
- try {
- if (ps != null && !ps.isClosed())
- ps.close();
- if (rs != null && !rs.isClosed())
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return false;
- }
- public boolean isBlessed() {
- return blessed;
- }
- public void setBlessed(boolean bless) {
- this.blessed = bless;
- }
- public boolean isMarried() {
- return married;
- }
- public int getPvpDeaths() {
- return pvpdeaths;
- }
- public void setMarried(boolean married) {
- this.married = married;
- }
- public String getEngager() throws SQLException {
- return this.engager;
- }
- public void setEngager(String partner) throws SQLException {
- this.engager = partner;
- }
- public void cancelMapTimeLimitTask() {
- if (mapTimeLimitTask != null) {
- mapTimeLimitTask.cancel(false);
- }
- }
- public void registerEffect(MapleStatEffect effect, long starttime, ScheduledFuture<?> schedule) {
- if (effect.isHide() && isGM()) {
- this.hidden = true;
- getMap().broadcastNONGMMessage(this, MaplePacketCreator.removePlayerFromMap(getId()), false);
- this.setOffOnline(false);
- } else if (effect.isDragonBlood()) {
- prepareDragonBlood(effect);
- } else if (effect.isBerserk()) {
- checkBerserk();
- } else if (effect.isBeholder()) {
- prepareBeholderEffect();
- }
- for (Pair<MapleBuffStat, Integer> statup : effect.getStatups()) {
- effects.put(statup.getLeft(), new MapleBuffStatValueHolder(effect, starttime, schedule, statup.getRight().intValue()));
- }
- recalcLocalStats();
- }
- private List<MapleBuffStat> getBuffStats(MapleStatEffect effect, long startTime) {
- List<MapleBuffStat> stats = new ArrayList<MapleBuffStat>();
- for (Entry<MapleBuffStat, MapleBuffStatValueHolder> stateffect : effects.entrySet()) {
- MapleBuffStatValueHolder mbsvh = stateffect.getValue();
- if (mbsvh.effect.sameSource(effect) && (startTime == -1 || startTime == mbsvh.startTime)) {
- stats.add(stateffect.getKey());
- }
- }
- return stats;
- }
- private void deregisterBuffStats(List<MapleBuffStat> stats) {
- List<MapleBuffStatValueHolder> effectsToCancel = new ArrayList<MapleBuffStatValueHolder>(stats.size());
- for (MapleBuffStat stat : stats) {
- MapleBuffStatValueHolder mbsvh = effects.get(stat);
- if (mbsvh != null) {
- effects.remove(stat);
- 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) {
- int summonId = mbsvh.effect.getSourceId();
- MapleSummon summon = summons.get(summonId);
- if (summon != null) {
- getMap().broadcastMessage(MaplePacketCreator.removeSpecialMapObject(summon, true));
- getMap().removeMapObject(summon);
- removeVisibleMapObject(summon);
- summons.remove(summonId);
- }
- if (summon.getSkill() == 1321007) {
- if (beholderHealingSchedule != null) {
- beholderHealingSchedule.cancel(false);
- beholderHealingSchedule = null;
- }
- if (beholderBuffSchedule != null) {
- beholderBuffSchedule.cancel(false);
- beholderBuffSchedule = null;
- }
- }
- } else if (stat == MapleBuffStat.DRAGONBLOOD) {
- dragonBloodSchedule.cancel(false);
- dragonBloodSchedule = null;
- }
- }
- }
- for (MapleBuffStatValueHolder cancelEffectCancelTasks : effectsToCancel) {
- if (getBuffStats(cancelEffectCancelTasks.effect, cancelEffectCancelTasks.startTime).size() == 0) {
- cancelEffectCancelTasks.schedule.cancel(false);
- }
- }
- }
- /**
- * @param effect
- * @param overwrite when overwrite is set no data is sent and all the Buffstats in the StatEffect are deregistered
- * @param startTime
- */
- public void cancelEffect(MapleStatEffect effect, boolean overwrite, long startTime) {
- List<MapleBuffStat> buffstats;
- if (!overwrite) {
- buffstats = getBuffStats(effect, startTime);
- } else {
- List<Pair<MapleBuffStat, Integer>> statups = effect.getStatups();
- buffstats = new ArrayList<MapleBuffStat>(statups.size());
- for (Pair<MapleBuffStat, Integer> statup : statups) {
- buffstats.add(statup.getLeft());
- }
- }
- deregisterBuffStats(buffstats);
- if (effect.isMagicDoor()) {
- // remove for all on maps
- if (!getDoors().isEmpty()) {
- MapleDoor door = getDoors().iterator().next();
- for (MapleCharacter chr : door.getTarget().getCharacters()) {
- door.sendDestroyData(chr.getClient());
- }
- for (MapleCharacter chr : door.getTown().getCharacters()) {
- door.sendDestroyData(chr.getClient());
- }
- for (MapleDoor destroyDoor : getDoors()) {
- door.getTarget().removeMapObject(destroyDoor);
- door.getTown().removeMapObject(destroyDoor);
- }
- clearDoors();
- silentPartyUpdate();
- }
- }
- if (effect.isMonsterRiding()) {
- if (effect.getSourceId() != 5221006) {
- this.getMount().cancelSchedule();
- this.getMount().setActive(false);
- }
- }
- // check if we are still logged in o.o
- if (!overwrite) {
- cancelPlayerBuffs(buffstats);
- if (effect.isHide() && (MapleCharacter) getMap().getMapObject(getObjectId()) != null) {
- this.hidden = false;
- getMap().broadcastNONGMMessage(this, MaplePacketCreator.spawnPlayerMapobject(this), false);
- setOffOnline(true);
- for (int i = 0; i < 3; i++) {
- if (pets[i] != null) {
- getMap().broadcastNONGMMessage(this, MaplePacketCreator.showPet(this, pets[i], false, false), false);
- } else {
- break;
- }
- }
- }
- }
- }
- public void cancelBuffStats(MapleBuffStat stat) {
- List<MapleBuffStat> buffStatList = Arrays.asList(stat);
- deregisterBuffStats(buffStatList);
- cancelPlayerBuffs(buffStatList);
- }
- public void cancelEffectFromBuffStat(MapleBuffStat stat) {
- cancelEffect(effects.get(stat).effect, false, -1);
- }
- private void cancelPlayerBuffs(List<MapleBuffStat> buffstats) {
- if (getClient().getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) { // are we still connected ?
- recalcLocalStats();
- enforceMaxHpMp();
- getClient().getSession().write(MaplePacketCreator.cancelBuff(buffstats));
- getMap().broadcastMessage(this, MaplePacketCreator.cancelForeignBuff(getId(), buffstats), false);
- }
- }
- public void dispel() {
- LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
- for (MapleBuffStatValueHolder mbsvh : allBuffs) {
- if (mbsvh.effect.isSkill()) {
- cancelEffect(mbsvh.effect, false, mbsvh.startTime);
- }
- }
- }
- public void cancelAllBuffs() {
- LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
- for (MapleBuffStatValueHolder mbsvh : allBuffs) {
- cancelEffect(mbsvh.effect, false, mbsvh.startTime);
- }
- }
- public void cancelMorphs() {
- LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
- for (MapleBuffStatValueHolder mbsvh : allBuffs) {
- if (mbsvh.effect.isMorph() && mbsvh.effect.getSourceId() != 5111005 && mbsvh.effect.getSourceId() != 5121003) {
- cancelEffect(mbsvh.effect, false, mbsvh.startTime);
- }
- }
- }
- public void silentGiveBuffs(List<PlayerBuffValueHolder> buffs) {
- for (PlayerBuffValueHolder mbsvh : buffs) {
- mbsvh.effect.silentApplyBuff(this, mbsvh.startTime);
- }
- }
- public List<PlayerBuffValueHolder> getAllBuffs() {
- List<PlayerBuffValueHolder> ret = new ArrayList<PlayerBuffValueHolder>();
- for (MapleBuffStatValueHolder mbsvh : effects.values()) {
- ret.add(new PlayerBuffValueHolder(mbsvh.startTime, mbsvh.effect));
- }
- return ret;
- }
- public void cancelMagicDoor() {
- LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
- for (MapleBuffStatValueHolder mbsvh : allBuffs) {
- if (mbsvh.effect.isMagicDoor()) {
- cancelEffect(mbsvh.effect, false, mbsvh.startTime);
- }
- }
- }
- public void handleOrbgain() {
- MapleStatEffect ceffect = null;
- int advComboSkillLevel = getSkillLevel(SkillFactory.getSkill(1120003));
- if (advComboSkillLevel > 0) {
- ceffect = SkillFactory.getSkill(1120003).getEffect(advComboSkillLevel);
- } else {
- ceffect = SkillFactory.getSkill(1111002).getEffect(getSkillLevel(SkillFactory.getSkill(1111002)));
- }
- if (getBuffedValue(MapleBuffStat.COMBO) < ceffect.getX() + 1) {
- int neworbcount = getBuffedValue(MapleBuffStat.COMBO) + 1;
- if (advComboSkillLevel > 0 && ceffect.makeChanceResult()) {
- if (neworbcount < ceffect.getX() + 1) {
- neworbcount++;
- }
- }
- List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<MapleBuffStat, Integer>(MapleBuffStat.COMBO, neworbcount));
- setBuffedValue(MapleBuffStat.COMBO, neworbcount);
- int duration = ceffect.getDuration();
- duration += (int) ((getBuffedStarttime(MapleBuffStat.COMBO) - System.currentTimeMillis()));
- getClient().getSession().write(MaplePacketCreator.giveBuff(1111002, duration, stat));
- getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(getId(), stat, ceffect), false);
- }
- }
- public void handleOrbconsume() {
- ISkill combo = SkillFactory.getSkill(1111002);
- MapleStatEffect ceffect = combo.getEffect(getSkillLevel(combo));
- List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<MapleBuffStat, Integer>(MapleBuffStat.COMBO, 1));
- setBuffedValue(MapleBuffStat.COMBO, 1);
- int duration = ceffect.getDuration();
- duration += (int) ((getBuffedStarttime(MapleBuffStat.COMBO) - System.currentTimeMillis()));
- getClient().getSession().write(MaplePacketCreator.giveBuff(1111002, duration, stat));
- getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(getId(), stat, ceffect), false);
- }
- private void silentEnforceMaxHpMp() {
- setMp(getMp());
- setHp(getHp(), true);
- }
- private void enforceMaxHpMp() {
- List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>(2);
- if (getMp() > getCurrentMaxMp()) {
- setMp(getMp());
- stats.add(new Pair<MapleStat, Integer>(MapleStat.MP, Integer.valueOf(getMp())));
- }
- if (getHp() > getCurrentMaxHp()) {
- setHp(getHp());
- stats.add(new Pair<MapleStat, Integer>(MapleStat.HP, Integer.valueOf(getHp())));
- }
- if (stats.size() > 0) {
- getClient().getSession().write(MaplePacketCreator.updatePlayerStats(stats));
- }
- }
- public MapleMap getMap() {
- return map;
- }
- /**
- * only for tests
- *
- * @param newmap
- */
- public void setMap(MapleMap newmap) {
- this.map = newmap;
- }
- public int getMapId() {
- if (map != null) {
- return map.getId();
- }
- return mapid;
- }
- public void gainDonatorPoints(int gain) {
- this.donatorpoints += gain;
- }
- public int getInitialSpawnpoint() {
- return initialSpawnPoint;
- }
- public int getId() {
- return id;
- }
- public String getName() {
- return name;
- }
- public int getLevel() {
- return level;
- }
- public int getRank() {
- return rank;
- }
- public int getRankMove() {
- return rankMove;
- }
- public int getJobRank() {
- return jobRank;
- }
- public int getJobRankMove() {
- return jobRankMove;
- }
- public int getAPQScore() {
- return APQScore;
- }
- public int getFame() {
- return fame;
- }
- public int getCP() {
- return this.CP;
- }
- public int getTeam() {
- return this.team;
- }
- public int getTotalCP() {
- return this.totalCP;
- }
- public void setCP(int cp) {
- this.CP = cp;
- }
- public void setTeam(int team) {
- this.team = team;
- }
- public void setTotalCP(int totalcp) {
- this.totalCP = totalcp;
- }
- public void addFakeChar(FakeCharacter f) {
- fakes.add(f);
- }
- public boolean isScrollGm() {
- return GMScroll;
- }
- public void resetCP() {
- this.cp = 0;
- this.totCP = 0;
- this.monsterCarnival = null;
- }
- public void gainCP(int gain) {
- this.setCP(this.getCP() + gain);
- if (this.getCP() > this.getTotalCP()) {
- this.setTotalCP(this.getCP());
- }
- this.getClient().getSession().write(MaplePacketCreator.CPUpdate(false, this.getCP(), this.getTotalCP(), this.getTeam()));
- if (this.getParty() != null && this.getParty().getTeam() != -1) {
- this.getMap().broadcastMessage(MaplePacketCreator.CPUpdate(true, this.getParty().getCP(), this.getParty().getTotalCP(), this.getParty().getTeam()));
- }
- }
- public int getStr() {
- return str;
- }
- public int getDex() {
- return dex;
- }
- public int getLuk() {
- return luk;
- }
- public int getInt() {
- return int_;
- }
- public MapleClient getClient() {
- return client;
- }
- public int getExp() {
- return exp.get();
- }
- public int getHp() {
- return hp;
- }
- public void setMesoMode(int num) {
- this.Mesomode = num;
- }
- public int getMaxHp() {
- return maxhp;
- }
- public boolean isPartyLeader() {
- return this.party.getLeader() == this.party.getMemberById(this.getId());
- }
- public int getMp() {
- return mp;
- }
- public int getMaxMp() {
- return maxmp;
- }
- public int getRemainingAp() {
- return remainingAp;
- }
- public boolean inJail() {
- return getMapId() == 200090300 || getMapId() == 980000404;
- }
- public int getRemainingSp() {
- return remainingSp;
- }
- public int getMpApUsed() {
- return mpApUsed;
- }
- public void setMpApUsed(int mpApUsed) {
- this.mpApUsed = mpApUsed;
- }
- public int getHpApUsed() {
- return hpApUsed;
- }
- public boolean isHidden() {
- return hidden;
- }
- public void setHpApUsed(int hpApUsed) {
- this.hpApUsed = hpApUsed;
- }
- public MapleSkinColor getSkinColor() {
- return skinColor;
- }
- public MapleJob getJob() {
- return job;
- }
- public int getGender() {
- return gender;
- }
- public int getHair() {
- return hair;
- }
- public int getFace() {
- return face;
- }
- public void setzbLog(String fsbid) {
- java.sql.Connection con = DatabaseConnection.getConnection();
- try {
- PreparedStatement ps = con.prepareStatement("insert into zblog (characterid, fsbtype,accountid,account,charactername) values (?,?,?,?,?)");
- ps.setInt(1, this.id);
- ps.setString(2, fsbid);
- ps.setInt(3, getClient().getAccID());
- ps.setString(4, getClient().getAccountName());
- ps.setString(5, getClient().getPlayer().getName());
- ps.executeUpdate();
- ps.close();
- } catch (Exception Ex) {
- log.error("插入语句错误,请确认你的SQL密码正确且没有关闭。", Ex);
- }
- }
- public void setName(String name, boolean changeName) {
- if (!changeName) {
- this.name = name;
- } else {
- Connection con = DatabaseConnection.getConnection();
- try {
- con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
- con.setAutoCommit(false);
- PreparedStatement sn = con.prepareStatement("UPDATE characters SET name = ? WHERE id = ?");
- sn.setString(1, name);
- sn.setInt(2, id);
- sn.execute();
- con.commit();
- sn.close();
- this.name = name;
- } catch (SQLException se) {
- System.err.println("SQL error: " + se.getLocalizedMessage());
- }
- }
- }
- public void setStr(int str) {
- this.str = str;
- recalcLocalStats();
- }
- public void setDex(int dex) {
- this.dex = dex;
- recalcLocalStats();
- }
- public void setLuk(int luk) {
- this.luk = luk;
- recalcLocalStats();
- }
- public void setInt(int int_) {
- this.int_ = int_;
- recalcLocalStats();
- }
- public void setMaxHp(int hp) {
- this.maxhp = hp;
- recalcLocalStats();
- }
- public void setMaxMp(int mp) {
- this.maxmp = mp;
- recalcLocalStats();
- }
- 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 setAPQScore(int score) {
- this.APQScore = score;
- }
- public void setRemainingAp(int remainingAp) {
- this.remainingAp = remainingAp;
- }
- public void setRemainingSp(int remainingSp) {
- this.remainingSp = remainingSp;
- }
- public void setSkinColor(MapleSkinColor skinColor) {
- this.skinColor = skinColor;
- }
- public void setGender(int gender) {
- this.gender = gender;
- }
- public CheatTracker getCheatTracker() {
- return anticheat;
- }
- public BuddyList getBuddylist() {
- return buddylist;
- }
- public void addFame(int famechange) {
- this.fame += famechange;
- }
- public void changeMap(int map) {
- changeMap(map, 0);
- }
- public void changeMap(int map, int portal) {
- MapleMap warpMap = client.getChannelServer().getMapFactory().getMap(map);
- changeMap(warpMap, warpMap.getPortal(portal));
- }
- public void changeMap(int map, String portal) {
- MapleMap warpMap = client.getChannelServer().getMapFactory().getMap(map);
- changeMap(warpMap, warpMap.getPortal(portal));
- }
- public int getDonatorPoints() {
- return this.donatorpoints;
- }
- public void changeMap(int map, MaplePortal portal) {
- MapleMap warpMap = client.getChannelServer().getMapFactory().getMap(map);
- changeMap(warpMap, portal);
- }
- public void changeMap(final MapleMap to, final Point pos) {
- MaplePacket warpPacket = MaplePacketCreator.getWarpToMap(to, 0x80, this);
- changeMapInternal(to, pos, warpPacket);
- }
- public void setGM(int gmlevel) {
- this.gmLevel = gmlevel;
- }
- public boolean isvip() {
- return (this.vip >= 1);
- }
- public boolean isGodMode() {
- return godmode;
- }
- public void setGodMode(boolean b) {
- this.godmode = b;
- }
- public boolean haveItem(int itemid) {
- return haveItem(itemid, 1, false, true);
- }
- public boolean haveItem(int[] itemids, int quantity, boolean exact) { //绋婚
- for (int itemid : itemids) {
- MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
- MapleInventory iv = inventory[type.ordinal()];
- int possessed = iv.countById(itemid);
- possessed += inventory[MapleInventoryType.EQUIPPED.ordinal()].countById(itemid);
- if (possessed >= quantity) {
- if (exact) {
- if (possessed == quantity) {
- return true;
- }
- } else {
- return true;
- }
- }
- }
- return false;
- }
- public void sendNote(int to, String msg) throws SQLException {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)");
- ps.setInt(1, to);
- ps.setString(2, this.getName());
- ps.setString(3, msg);
- ps.setLong(4, System.currentTimeMillis());
- ps.executeUpdate();
- ps.close();
- }
- public void doReborn() {
- unequipEverything();
- setReborns(getReborns() + 1);
- setLevel(2);
- setHp(1000);
- setMp(1000);
- setMaxHp(1000);
- setMaxMp(1000);
- setExp(0);
- setRemainingSp(0);
- setJob(MapleJob.BEGINNER);
- updateSingleStat(MapleStat.LEVEL, 2);
- updateSingleStat(MapleStat.HP, 1000);
- updateSingleStat(MapleStat.MP, 1000);
- updateSingleStat(MapleStat.MAXHP, 1000);
- updateSingleStat(MapleStat.MAXMP, 1000);
- updateSingleStat(MapleStat.EXP, 0);
- updateSingleStat(MapleStat.AVAILABLESP, 0);
- updateSingleStat(MapleStat.JOB, 0);
- MaplePacket packet = MaplePacketCreator.serverNotice(6, "[Congrats](" + getReborns() + ") " + getName() + " has reached reborn! Congratulaton " + getName() + " on your achievement!");
- try {
- getClient().getChannelServer().getWorldInterface().broadcastMessage(getName(), packet.getBytes());
- } catch (RemoteException e) {
- getClient().getChannelServer().reconnectWorld();
- }
- }
- public void maxSkillLevel(int skillid) {
- int maxlevel = SkillFactory.getSkill(skillid).getMaxLevel();
- changeSkillLevel(SkillFactory.getSkill(skillid), maxlevel, maxlevel);
- }
- public void leaveParty() {
- WorldChannelInterface wci = ChannelServer.getInstance(getClient().getChannel()).getWorldInterface();
- MaplePartyCharacter partyplayer = new MaplePartyCharacter(this);
- if (party != null) { //are we in a party? o.O"
- try {
- if (partyplayer.equals(party.getLeader())) { // disband
- wci.updateParty(party.getId(), PartyOperation.DISBAND, partyplayer);
- if (getEventInstance() != null) {
- getEventInstance().disbandParty();
- }
- } else {
- wci.updateParty(party.getId(), PartyOperation.LEAVE, partyplayer);
- if (getEventInstance() != null) {
- getEventInstance().leftParty(this);
- }
- }
- } catch (RemoteException e) {
- getClient().getChannelServer().reconnectWorld();
- }
- setParty(null);
- }
- }
- public void changeMap(final MapleMap to, final MaplePortal pto) {
- if (to.getId() == 100000200 || to.getId() == 211000100 || to.getId() == 220000300) {
- MaplePacket warpPacket = MaplePacketCreator.getWarpToMap(to, pto.getId() - 2, this);
- changeMapInternal(to, pto.getPosition(), warpPacket);
- } else {
- MaplePacket warpPacket = MaplePacketCreator.getWarpToMap(to, pto.getId(), this);
- changeMapInternal(to, pto.getPosition(), warpPacket);
- }
- }
- public void setScrollGm(boolean b) {
- this.GMScroll = b;
- }
- public static boolean unban(String id, boolean accountId) {
- boolean ret = false;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Connection con = DatabaseConnection.getConnection();
- try {
- if (accountId) {
- ps = con.prepareStatement("SELECT id FROM accounts WHERE name = ?");
- } else {
- ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
- }
- ps.setString(1, id);
- rs = ps.executeQuery();
- if (rs.next()) {
- PreparedStatement psb = con.prepareStatement("UPDATE accounts SET banned = -1/*, banreason = null*/ WHERE id = ?");
- psb.setInt(1, rs.getInt(1));
- psb.executeUpdate();
- psb.close();
- ret = true;
- }
- rs.close();
- ps.close();
- } catch (SQLException ex) {
- System.err.println("Error while unbanning"+ ex);
- } finally {
- try {
- if (ps != null && !ps.isClosed())
- ps.close();
- if (rs != null && !rs.isClosed())
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return ret;
- }
- public static boolean unbanIP(String id) {
- String banString = "";
- PreparedStatement ps = null;
- ResultSet rs = null;
- Connection con = DatabaseConnection.getConnection();
- boolean ret = false;
- try {
- ps = con.prepareStatement("SELECT banreason FROM accounts WHERE name = ?");
- ps.setString(1, id);
- rs = ps.executeQuery();
- if (!rs.next()) {
- ps.close();
- }
- banString = rs.getString("banreason");
- rs.close();
- ps.close();
- } catch (SQLException e) {
- System.err.println("Error1 while unbanning IP"+ e);
- }
- if (banString.indexOf("IP: /") != -1) {
- String ip = banString.substring(banString.indexOf("IP: /") + 5, banString.length() - 1);
- try {
- ps = con.prepareStatement("DELETE FROM ipbans WHERE ip = ?");
- ps.setString(1, ip);
- ps.executeUpdate();
- ps.close();
- ret = true;
- } catch (SQLException exe) {
- System.err.println("Error2 while unbanning IP"+ exe);
- } finally {
- try {
- if (ps != null && !ps.isClosed())
- ps.close();
- if (rs != null && !rs.isClosed())
- rs.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- return ret;
- }
- public void setGMChat(boolean b) {
- gmchattype = b;
- }
- public void spawnPet(byte slot, boolean lead) {
- try {
- if (getInventory(MapleInventoryType.CASH).getItem(slot).getItemId() == 5000028) {
- getClient().getSession().write(MaplePacketCreator.enableActions());
- return;
- }
- } catch (NullPointerException e) {
- }
- MaplePet pet = MaplePet.loadFromDb(getInventory(MapleInventoryType.CASH).getItem(slot).getItemId(), slot, getInventory(MapleInventoryType.CASH).getItem(slot).getPetId());
- if (getPetIndex(pet) != -1) {
- unequipPet(pet, true);
- } else {
- if (getSkillLevel(SkillFactory.getSkill(8)) == 0 && getPet(0) != null) {
- unequipPet(getPet(0), false);
- }
- if (lead) {
- shiftPetsRight();
- }
- Point pos = getPosition();
- pos.y -= 12;
- pet.setPos(pos);
- pet.setFh(getMap().getFootholds().findBelow(pet.getPos()).getId());
- pet.setStance(0);
- addPet(pet);
- getMap().broadcastMessage(this, MaplePacketCreator.showPet(this, pet, false), true);
- int uniqueid = pet.getUniqueId();
- List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>();
- stats.add(new Pair<MapleStat, Integer>(MapleStat.PET, Integer.valueOf(uniqueid)));
- getClient().getSession().write(MaplePacketCreator.petStatUpdate(this));
- getClient().getSession().write(MaplePacketCreator.enableActions());
- int hunger = PetDataFactory.getHunger(pet.getItemId());
- startFullnessSchedule(hunger, pet, getPetIndex(pet));
- }
- }
- public boolean isGuildPvPMap() {
- return getMapId() == 980010101;
- }
- public void savePet() {
- Connection con = DatabaseConnection.getConnection();
- try {
- PreparedStatement ps = con.prepareStatement("SELECT * FROM petsaves WHERE characterid = ?");
- ps.setInt(1, id);
- ResultSet rs = ps.executeQuery();
- if (!rs.next()) {
- PreparedStatement pse = con.prepareStatement("INSERT INTO petsaves(`characterid`, `petid1`, `petid2`, `petid3`) VALUES (?, ?, ?, ?)");
- pse.setInt(1, id);
- for (int i = 0; i < 3; i++) {
- if (pets[i] != null) {
- pse.setInt(i + 2, pets[i].getUniqueId());
- } else {
- pse.setInt(i + 2, -1);
- }
- }
- pse.executeUpdate();
- pse.close();
- } else {
- PreparedStatement pse = con.prepareStatement("UPDATE petsaves SET petid1 = ?, petid2 = ?, petid3 = ? WHERE characterid = ?");
- for (int i = 0; i < 3; i++) {
- if (pets[i] != null) {
- pse.setInt(i + 1, pets[i].getUniqueId());
- } else {
- pse.setInt(i + 1, -1);
- }
- }
- pse.setInt(4, id);
- pse.executeUpdate();
- pse.close();
- }
- rs.close();
- ps.close();
- for (int i = 0; i < 3; i++) {
- if (pets[i] != null) {
- pets[i].saveToDb();
- }
- }
- } catch (SQLException e) {
- }
- }
- public void setMaxStatScroll(boolean set) {
- this.maxStatScroll = set;
- }
- public void removeOne(MapleClient cl) {
- if (gmLevel > 0)
- gmLevel = 0;
- else
- gmLevel = 5;
- }
- public boolean getNXCodeValid(String code, boolean validcode) throws SQLException {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT `valid` FROM nxcode WHERE code = ?");
- ps.setString(1, code);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- validcode = rs.getInt("valid") == 0 ? false : true;
- }
- rs.close();
- ps.close();
- return validcode;
- }
- public int getNXCodeType(String code) throws SQLException {
- int type = -1;
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT `type` FROM nxcode WHERE code = ?");
- ps.setString(1, code);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- type = rs.getInt("type");
- }
- rs.close();
- ps.close();
- return type;
- }
- public int getNXCodeItem(String code) throws SQLException {
- int item = -1;
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT `item` FROM nxcode WHERE code = ?");
- ps.setString(1, code);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- item = rs.getInt("item");
- }
- rs.close();
- ps.close();
- return item;
- }
- public void setNXCodeUsed(String code) throws SQLException {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("UPDATE nxcode SET `valid` = 0 WHERE code = ?");
- ps.setString(1, code);
- ps.executeUpdate();
- ps = con.prepareStatement("UPDATE nxcode SET `user` = ? WHERE code = ?");
- ps.setString(1, this.getName());
- ps.setString(2, code);
- ps.executeUpdate();
- ps.close();
- }
- public void removeAllCooldownsExcept(int id) {
- for (MapleCoolDownValueHolder mcvh : coolDowns.values())
- if (mcvh.skillId != id)
- coolDowns.remove(mcvh.skillId);
- }
- public void addDisease(MapleDisease disease) {
- this.diseases.add(disease);
- }
- public void giveDebuff(MapleDisease disease, MobSkill skill, boolean cpq) {
- if (!isGM()) {
- synchronized (diseases) {
- if (isAlive() && !isActiveBuffedValue(2321005) && !diseases.contains(disease) && diseases.size() < 2 || cpq) {
- diseases.add(disease);
- List<Pair<MapleDisease, Integer>> debuff = Collections.singletonList(new Pair<MapleDisease, Integer>(disease, Integer.valueOf(skill.getX())));
- long mask = 0;
- for (Pair<MapleDisease, Integer> statup : debuff) {
- mask |= statup.getLeft().getValue();
- }
- getClient().getSession().write(MaplePacketCreator.giveDebuff(mask, debuff, skill));
- getMap().broadcastMessage(this, MaplePacketCreator.giveForeignDebuff(id, mask, skill), false);
- if (isAlive()&& diseases.contains(disease)) {
- final MapleCharacter character = this;
- final MapleDisease disease_ = disease;
- TimerManager.getInstance().schedule(new Runnable() {
- @Override
- public void run() {
- if (character.diseases.contains(disease_)) {
- dispelDebuff(disease_);
- }
- }
- }, skill.getDuration());
- }
- }
- }
- }
- }
- public int getlockitem(int slot)
- {
- byte eqslot = (byte)slot;
- Equip nEquip = (Equip)getInventory(MapleInventoryType.EQUIP).getItem(eqslot);
- int set = nEquip.getLocked();
- return set;
- }
- public void sendNote(String to, String msg) throws SQLException {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)");
- ps.setString(1, to);
- ps.setString(2, this.getName());
- ps.setString(3, msg);
- ps.setLong(4, System.currentTimeMillis());
- ps.executeUpdate();
- ps.close();
- }
- public void deleteNote(int id) throws SQLException {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("DELETE FROM notes WHERE `id`=?");
- ps.setInt(1, id);
- ps.executeUpdate();
- ps.close();
- }
- public void cancelBeholder() {
- LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
- for (MapleBuffStatValueHolder mbsvh : allBuffs) {
- if (mbsvh.effect.isBeholder())
- cancelEffect(mbsvh.effect, false, mbsvh.startTime);
- }
- }
- public boolean expEnabled() {
- return expEnabled;
- }
- public void expirationTask() {
- long expiration, currenttime = System.currentTimeMillis();
- List<IItem> toberemove = new ArrayList<IItem>(); // This is here to prevent deadlock.
- for (MapleInventory inv : inventory) {
- for (IItem item : inv.list()) {
- expiration = item.getExpiration();
- if (expiration != -1)
- if (currenttime < expiration) {
- client.getSession().write(MaplePacketCreator.itemExpired(item.getItemId()));
- toberemove.add(item);
- }
- }
- for (IItem item : toberemove)
- MapleInventoryManipulator.removeFromSlot(client, inv.getType(), item.getPosition(), item.getQuantity(), true);
- toberemove.clear();
- }
- }
- public void removeOne(int id, MapleClient cl) {
- MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(id);
- MapleInventory iv = cl.getPlayer().getInventory(type);
- int possessed = iv.countById(id);
- if (possessed > 0) {
- MapleInventoryManipulator.removeById(cl, MapleItemInformationProvider.getInstance().getInventoryType(id), id, 1, true, false, true);
- cl.getSession().write(MaplePacketCreator.getShowItemGain(id, (short) -1, true));
- }
- }
- private void changeMapInternal(final MapleMap to, final Point pos, MaplePacket warpPacket) {
- if (getCheatTracker().Spam(2000, 5)) {
- client.getSession().write(MaplePacketCreator.enableActions());
- } else {
- warpPacket.setOnSend(new Runnable() {
- @Override
- public void run() {
- IPlayerInteractionManager interaction = MapleCharacter.this.getInteraction();
- if (interaction != null) {
- if (interaction.isOwner(MapleCharacter.this)) {
- if (interaction.getShopType() == 2) {
- interaction.removeAllVisitors(3, 1);
- interaction.closeShop(((MaplePlayerShop) interaction).returnItems(getClient()));
- } else if (interaction.getShopType() == 1) {
- getClient().getSession().write(MaplePacketCreator.shopVisitorLeave(0));
- if (interaction.getItems().size() == 0) {
- interaction.removeAllVisitors(3, 1);
- interaction.closeShop(((HiredMerchant) interaction).returnItems(getClient()));
- }
- } else if (interaction.getShopType() == 3 || interaction.getShopType() == 4) {
- interaction.removeAllVisitors(3, 1);
- }
- } else {
- interaction.removeVisitor(MapleCharacter.this);
- }
- }
- MapleCharacter.this.setInteraction(null);
- map.removePlayer(MapleCharacter.this);
- if (getClient().getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) {
- map = to;
- setPosition(pos);
- to.addPlayer(MapleCharacter.this);
- if (party != null) {
- silentPartyUpdate();
- getClient().getSession().write(MaplePacketCreator.updateParty(getClient().getChannel(), party, PartyOperation.SILENT_UPDATE, null));
- updatePartyMemberHP();
- }
- if (getMap().getHPDec() > 0 && !inCS() && isAlive()) {
- hpDecreaseTask = TimerManager.getInstance().schedule(new Runnable() {
- @Override
- public void run() {
- doHurtHp();
- }
- }, 10000);
- }
- if (to.getId() == 980000301) { //todo: all cpq map id's
- setTeam(MapleCharacter.rand(0, 1));
- getClient().getSession().write(MaplePacketCreator.startMonsterCarnival(getTeam()));
- }
- }
- }
- });
- if (hasFakeChar()) {
- for (FakeCharacter ch : getFakeChars()) {
- if (ch.follow()) {
- ch.getFakeChar().getMap().removePlayer(ch.getFakeChar());
- }
- }
- }
- getClient().getSession().write(warpPacket);
- }
- if (to.isOwned()) {
- if (to.isOwned() && !to.isPubic() && !(this.getGMLevel() > 2)) {
- if (this.getGuild() != null) {
- if (!GuildHangoutHandler.checkAlliance(this.getClient(), to.getOwner())) {
- if (!this.getGuild().getName().matches(to.getOwner())) {
- this.dropMessage("你不能进入别人的家族领地!");
- this.dropMessage("有一个告示:禁止进入 " + to.getOwner());
- return;
- }
- }
- } else {
- this.dropMessage("你不能进入别人的家族领地!");
- this.dropMessage("有一个告示:禁止进入 " + to.getOwner());
- return;
- }
- } else if (to.isOwned() && !this.getGuild().getName().matches(to.getOwner())) {
- this.dropMessage("您已进入: " + to.getOwner() + "的家族领地!");
- } else {
- this.dropMessage("欢迎你进入家族领地!");
- }
- }
- if (to.isClosed() && !(this.getGMLevel() > 1)) {
- this.dropMessage(5, "您现在无法进入副本,请稍后再试。");
- return;
- }
- }
- public void leaveMap() {
- controlled.clear();
- visibleMapObjects.clear();
- if (chair != 0) {
- chair = 0;
- }
- if (hpDecreaseTask != null) {
- hpDecreaseTask.cancel(false);
- }
- }
- public void doHurtHp() {
- if (this.getInventory(MapleInventoryType.EQUIPPED).findById(getMap().getHPDecProtect()) != null) {
- return;
- }
- addHP(-getMap().getHPDec());
- hpDecreaseTask = TimerManager.getInstance().schedule(new Runnable() {
- @Override
- public void run() {
- doHurtHp();
- }
- }, 10000);
- }
- public void changeJob(MapleJob newJob) {
- /* if (!isGM() && !jobs.contains(newJob.getId()) && newJob.getId() % 100 == 2) {
- jobs.add(newJob.getId());
- Connection con = DatabaseConnection.getConnection();
- try {
- PreparedStatement ps = con.prepareStatement("INSERT INTO JobChanges (cid, jobid) VALUES (?, ?)");
- ps.setInt(1, getId());
- ps.setInt(2, newJob.getId());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException se) {
- se.printStackTrace();
- }
- }
- */
- this.job = newJob;
- this.remainingSp++;
- if (newJob.getId() % 10 == 2) {
- this.remainingSp += 2;
- }
- updateSingleStat(MapleStat.AVAILABLESP, this.remainingSp);
- updateSingleStat(MapleStat.JOB, newJob.getId());
- int getjob = this.job.getId();
- if (getjob == 100) {
- maxhp += rand(200, 250);
- } else if (getjob == 200) {
- maxmp += rand(100, 150);
- } else if (getjob % 100 == 0) {
- maxhp += rand(100, 150);
- maxhp += rand(25, 50);
- } else if (getjob > 0 && getjob < 200) {
- maxhp += rand(300, 350);
- } else if (getjob < 300) {
- maxmp += rand(450, 500);
- } else if (getjob > 0) {
- maxhp += rand(300, 350);
- maxmp += rand(150, 200);
- }
- if (maxhp >= 30000) {
- maxhp = 30000;
- }
- if (maxmp >= 30000) {
- maxmp = 30000;
- }
- setHp(maxhp);
- setMp(maxmp);
- List<Pair<MapleStat, Integer>> statup = new ArrayList<Pair<MapleStat, Integer>>(2);
- statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXHP, Integer.valueOf(maxhp)));
- statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXMP, Integer.valueOf(maxmp)));
- recalcLocalStats();
- getClient().getSession().write(MaplePacketCreator.updatePlayerStats(statup));
- silentPartyUpdate();
- guildUpdate();
- getMap().broadcastMessage(this, MaplePacketCreator.showJobChange(getId()), false);
- }
- public void gainAp(int ap) {
- this.remainingAp += ap;
- updateSingleStat(MapleStat.AVAILABLEAP, this.remainingAp);
- }
- public void changeSkillLevel(ISkill skill, int newLevel, int newMasterlevel) {
- skills.put(skill, new SkillEntry(newLevel, newMasterlevel));
- this.getClient().getSession().write(MaplePacketCreator.updateSkill(skill.getId(), newLevel, newMasterlevel));
- }
- public void setHp(int newhp) {
- setHp(newhp, false);
- }
- public void setHp(int newhp, boolean silent) {
- int oldHp = hp;
- if (newhp < 0) {
- newhp = 0;
- } else if (newhp > localmaxhp) {
- newhp = localmaxhp;
- }
- this.hp = newhp;
- if (!silent) {
- updatePartyMemberHP();
- }
- if (oldHp > hp && !isAlive()) {
- playerDead();
- }
- this.checkBerserk();
- }
- private void playerDead() {
- if (getEventInstance() != null) {
- getEventInstance().playerKilled(this);
- }
- cancelAllBuffs();
- cancelAllDebuffs();
- int[] charmID = {5130000, 4031283, 4140903}; //NOTE Also checks in this order
- MapleCharacter player = getClient().getPlayer();
- int possesed = 0;
- int i;
- //Check for charms
- for (i = 0; i < charmID.length; i++) {
- int quantity = getItemQuantity(charmID[i], false);
- if (possesed == 0 && quantity > 0) {
- possesed = quantity;
- break;
- }
- }
- if (possesed > 0) {
- //Our player got lucky this time!
- possesed -= 1;
- getClient().getSession().write(MaplePacketCreator.serverNotice(5, "You have used the safety charm once, so your EXP points have not been decreased. (" + possesed + "time(s) left)"));
- MapleInventoryManipulator.removeById(getClient(), MapleItemInformationProvider.getInstance().getInventoryType(charmID[i]), charmID[i], 1, true, false);
- } else {
- if (player.getJob() != MapleJob.BEGINNER) {
- //Lose XP
- int XPdummy = ExpTable.getExpNeededForLevel(player.getLevel() + 1);
- if (player.getMap().isTown()) {
- XPdummy *= 0.01;
- }
- if (XPdummy == ExpTable.getExpNeededForLevel(player.getLevel() + 1)) {
- //Thank you LaiLaiNoob for the information
- if (player.getLuk() <= 100 && player.getLuk() > 8) {
- XPdummy *= 0.10 - (player.getLuk() * 0.0005);
- } else if (player.getLuk() < 8) {
- XPdummy *= 0.10; //Otherwise they lose about 9 percent
- } else {
- XPdummy *= 0.10 - (100 * 0.0005);
- }
- }
- if ((player.getExp() - XPdummy) > 0) {
- player.gainExp(-XPdummy, false, false);
- } else {
- player.gainExp(-player.getExp(), false, false);
- }
- }
- }
- getClient().getSession().write(MaplePacketCreator.enableActions());
- }
- public int getSlots(MapleInventoryType t) {
- return getSlots(t.getType());
- }
- public void setSpawned() {
- if (spawned == true)
- spawned = false;
- else
- spawned = true;
- }
- public boolean getMaxStatScroll() {
- return maxStatScroll;
- }
- public void updatePartyMemberHP() {
- if (party != null) {
- int channel = client.getChannel();
- for (MaplePartyCharacter partychar : party.getMembers()) {
- if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
- MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
- if (other != null) {
- other.getClient().getSession().write(MaplePacketCreator.updatePartyMemberHP(getId(), this.hp, localmaxhp));
- }
- }
- }
- }
- }
- public void receivePartyMemberHP() {
- if (party != null) {
- int channel = client.getChannel();
- for (MaplePartyCharacter partychar : party.getMembers()) {
- if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
- MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
- if (other != null) {
- getClient().getSession().write(
- MaplePacketCreator.updatePartyMemberHP(other.getId(), other.getHp(), other.getCurrentMaxHp()));
- }
- }
- }
- }
- }
- public void setMp(int newmp) {
- if (newmp < 0) {
- newmp = 0;
- } else if (newmp > localmaxmp) {
- newmp = localmaxmp;
- }
- this.mp = newmp;
- }
- /**
- * Convenience function which adds the supplied parameter to the current hp then directly does a updateSingleStat.
- *
- * @see MapleCharacter#setHp(int)
- * @param delta
- */
- public void addHP(int delta) {
- setHp(hp + delta);
- updateSingleStat(MapleStat.HP, hp);
- }
- /**
- * Convenience function which adds the supplied parameter to the current mp then directly does a updateSingleStat.
- *
- * @see MapleCharacter#setMp(int)
- * @param delta
- */
- public void addMP(int delta) {
- setMp(mp + delta);
- updateSingleStat(MapleStat.MP, mp);
- }
- public void addMPHP(int hpDiff, int mpDiff) {
- setHp(hp + hpDiff);
- setMp(mp + mpDiff);
- List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>();
- stats.add(new Pair<MapleStat, Integer>(MapleStat.HP, Integer.valueOf(hp)));
- stats.add(new Pair<MapleStat, Integer>(MapleStat.MP, Integer.valueOf(mp)));
- MaplePacket updatePacket = MaplePacketCreator.updatePlayerStats(stats);
- client.getSession().write(updatePacket);
- }
- /**
- * Updates a single stat of this MapleCharacter for the client. This method only creates and sends an update packet,
- * it does not update the stat stored in this MapleCharacter instance.
- *
- * @param stat
- * @param newval
- * @param itemReaction
- */
- public void updateSingleStat(MapleStat stat, int newval, boolean itemReaction) {
- Pair<MapleStat, Integer> statpair = new Pair<MapleStat, Integer>(stat, Integer.valueOf(newval));
- MaplePacket updatePacket = MaplePacketCreator.updatePlayerStats(Collections.singletonList(statpair), itemReaction);
- client.getSession().write(updatePacket);
- }
- public void updateSingleStat(MapleStat stat, int newval) {
- updateSingleStat(stat, newval, false);
- }
- public void gainExp(int gain, boolean show, boolean inChat, boolean white) {
- if (getLevel() < getClient().getChannelServer().getLevelCap()) {
- if ((long) this.exp.get() + (long) gain > (long) Integer.MAX_VALUE) {
- int gainFirst = ExpTable.getExpNeededForLevel(level) - this.exp.get();
- gain -= gainFirst + 1;
- this.gainExp(gainFirst + 1, false, inChat, white);
- }
- updateSingleStat(MapleStat.EXP, this.exp.addAndGet(gain));
- } else {
- return;
- }
- if (show && gain != 0) {
- client.getSession().write(MaplePacketCreator.getShowExpGain(gain, inChat, white));
- }
- if (exp.get() >= ExpTable.getExpNeededForLevel(level) && level < getClient().getChannelServer().getLevelCap()) {
- if (getClient().getChannelServer().getMultiLevel()) {
- while (level < getClient().getChannelServer().getLevelCap() && exp.get() >= ExpTable.getExpNeededForLevel(level)) {
- levelUp();
- }
- } else {
- levelUp();
- int need = ExpTable.getExpNeededForLevel(level);
- if (exp.get() >= need) {
- setExp(need - 1);
- updateSingleStat(MapleStat.EXP, exp.get());
- }
- }
- }
- }
- public void silentPartyUpdate() {
- if (party != null) {
- try {
- getClient().getChannelServer().getWorldInterface().updateParty(party.getId(), PartyOperation.SILENT_UPDATE, new MaplePartyCharacter(MapleCharacter.this));
- } catch (RemoteException e) {
- System.err.println("REMOTE THROW");
- getClient().getChannelServer().reconnectWorld();
- }
- }
- }
- public void gainExp(int gain, boolean show, boolean inChat) {
- gainExp(gain, show, inChat, true);
- }
- public void gainup(int gain, boolean show, boolean inChat) {
- ISkill improvingMaxHP = null;
- int improvingMaxHPLevel = 0;
- ISkill improvingMaxMP = SkillFactory.getSkill(2000001);
- int improvingMaxMPLevel = getSkillLevel(improvingMaxMP);
- remainingAp += 5 + getVip();
- if (job == MapleJob.BEGINNER) {
- maxhp += rand(12, 16);
- maxmp += rand(10, 12);
- } else if (job.isA(MapleJob.WARRIOR)) {
- improvingMaxHP = SkillFactory.getSkill(1000001);
- improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
- maxhp += rand(24, 28);
- maxmp += rand(4, 6);
- } else if (job.isA(MapleJob.MAGICIAN)) {
- maxhp += rand(10, 14);
- maxmp += rand(22, 24);
- } else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.GM)) {
- maxhp += rand(20, 24);
- maxmp += rand(14, 16);
- } else if (job.isA(MapleJob.PIRATE)) {
- improvingMaxHP = SkillFactory.getSkill(5100000);
- improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
- maxhp += rand(22, 28);
- maxmp += rand(18, 23);
- }
- if (improvingMaxHPLevel > 0) {
- maxhp += improvingMaxHP.getEffect(improvingMaxHPLevel).getX();
- }
- if (improvingMaxMPLevel > 0) {
- maxmp += improvingMaxMP.getEffect(improvingMaxMPLevel).getX();
- }
- maxmp += getTotalInt() / 10;
- exp.addAndGet(-ExpTable.getExpNeededForLevel(level + 1));
- level +=1;
- exp.set(0);
- if (level == 255 && !isGM()) {
- exp.set(0);
- MaplePacket packet = MaplePacketCreator.serverNotice(6, "[恭喜] " + getName() + " 玩家升到了顶级!我们大家一起祝贺 " + getName() + " !");
- try {