use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleCharacter method insertNewChar.
public final boolean insertNewChar() {
Connection con = null;
PreparedStatement ps = null;
try {
con = DatabaseConnection.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, 12);
ps.setInt(2, 5);
ps.setInt(3, 4);
ps.setInt(4, 4);
ps.setInt(5, gmLevel);
ps.setInt(6, skinColor.getId());
ps.setInt(7, gender);
ps.setInt(8, getJob().getId());
ps.setInt(9, hair);
ps.setInt(10, face);
ps.setInt(11, mapid);
ps.setInt(12, Math.abs(meso.get()));
ps.setInt(13, 0);
ps.setInt(14, accountid);
ps.setString(15, name);
ps.setInt(16, world);
int updateRows = ps.executeUpdate();
if (updateRows < 1) {
ps.close();
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to insert " + name);
return false;
}
ResultSet rs = ps.getGeneratedKeys();
if (rs.next()) {
this.id = rs.getInt(1);
rs.close();
ps.close();
} else {
rs.close();
ps.close();
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Inserting char failed " + name);
return false;
}
// Select a keybinding method
int[] selectedKey;
int[] selectedType;
int[] selectedAction;
if (ServerConstants.USE_CUSTOM_KEYSET) {
selectedKey = GameConstants.getCustomKey(true);
selectedType = GameConstants.getCustomType(true);
selectedAction = GameConstants.getCustomAction(true);
} else {
selectedKey = GameConstants.getCustomKey(false);
selectedType = GameConstants.getCustomType(false);
selectedAction = GameConstants.getCustomAction(false);
}
ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
ps.setInt(1, id);
for (int i = 0; i < selectedKey.length; i++) {
ps.setInt(2, selectedKey[i]);
ps.setInt(3, selectedType[i]);
ps.setInt(4, selectedAction[i]);
ps.execute();
}
ps.close();
final List<Pair<Item, MapleInventoryType>> itemsWithType = new ArrayList<>();
for (MapleInventory iv : inventory) {
for (Item item : iv.list()) {
itemsWithType.add(new Pair<>(item, iv.getType()));
}
}
ItemFactory.INVENTORY.saveItems(itemsWithType, id, con);
con.commit();
return true;
} catch (Throwable t) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, t, "Error creating " + name + " Level: " + level + " Job: " + job.getId());
try {
con.rollback();
} catch (SQLException se) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, se, "Error trying to rollback " + name);
}
return false;
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
con.setAutoCommit(true);
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleCharacter method changeMapBanish.
public void changeMapBanish(int mapid, String portal, String msg) {
if (ServerConstants.USE_SPIKES_AVOID_BANISH) {
for (Item it : this.getInventory(MapleInventoryType.EQUIPPED).list()) {
if ((it.getFlag() & ItemConstants.SPIKES) == ItemConstants.SPIKES)
return;
}
}
int banMap = this.getMapId();
int banSp = this.getMap().findClosestPlayerSpawnpoint(this.getPosition()).getId();
long banTime = System.currentTimeMillis();
dropMessage(5, msg);
MapleMap map_ = getWarpMap(mapid);
changeMap(map_, map_.getPortal(portal));
setBanishPlayerData(banMap, banSp, banTime);
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleCharacter method buffMapProtection.
private boolean buffMapProtection() {
effLock.lock();
chrLock.lock();
int thisMapid = mapid;
int returnMapid = client.getChannelServer().getMapFactory().getMap(thisMapid).getReturnMapId();
try {
for (Entry<MapleBuffStat, MapleBuffStatValueHolder> mbs : effects.entrySet()) {
if (mbs.getKey() == MapleBuffStat.MAP_PROTECTION) {
byte value = (byte) mbs.getValue().value;
if (value == 1 && ((returnMapid == 211000000 && thisMapid != 200082300) || returnMapid == 193000000)) {
// protection from cold
return true;
} else if (value == 2 && (returnMapid == 230000000 || thisMapid == 200082300)) {
// breathing underwater
return true;
} else {
return false;
}
}
}
} finally {
chrLock.unlock();
effLock.unlock();
}
for (Item it : this.getInventory(MapleInventoryType.EQUIPPED).list()) {
if ((it.getFlag() & ItemConstants.COLD) == ItemConstants.COLD && ((returnMapid == 211000000 && thisMapid != 200082300) || returnMapid == 193000000)) {
// protection from cold
return true;
}
}
return false;
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleCharacter method expirationTask.
public void expirationTask() {
if (itemExpireTask == null) {
itemExpireTask = TimerManager.getInstance().register(new Runnable() {
@Override
public void run() {
boolean deletedCoupon = false;
long expiration, currenttime = System.currentTimeMillis();
Set<Skill> keys = getSkills().keySet();
for (Iterator<Skill> i = keys.iterator(); i.hasNext(); ) {
Skill key = i.next();
SkillEntry skill = getSkills().get(key);
if (skill.expiration != -1 && skill.expiration < currenttime) {
changeSkillLevel(key, (byte) -1, 0, -1);
}
}
List<Item> toberemove = new ArrayList<>();
for (MapleInventory inv : inventory) {
for (Item item : inv.list()) {
expiration = item.getExpiration();
if (expiration != -1 && (expiration < currenttime) && ((item.getFlag() & ItemConstants.LOCK) == ItemConstants.LOCK)) {
byte aids = item.getFlag();
aids &= ~(ItemConstants.LOCK);
// Probably need a check, else people can make expiring items into permanent items...
item.setFlag(aids);
item.setExpiration(-1);
// TEST :3
forceUpdateItem(item);
} else if (expiration != -1 && expiration < currenttime) {
if (!ItemConstants.isPet(item.getItemId())) {
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
toberemove.add(item);
if (ItemConstants.isRateCoupon(item.getItemId())) {
deletedCoupon = true;
}
} else {
if (item.getPetId() > -1) {
int petIdx = getPetIndex(item.getPetId());
if (petIdx > -1)
unequipPet(getPet(petIdx), true);
}
if (ItemConstants.isExpirablePet(item.getItemId())) {
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
toberemove.add(item);
} else {
item.setExpiration(-1);
forceUpdateItem(item);
}
}
}
}
for (Item item : toberemove) {
MapleInventoryManipulator.removeFromSlot(client, inv.getType(), item.getPosition(), item.getQuantity(), true);
}
toberemove.clear();
if (deletedCoupon) {
updateCouponRates();
}
}
}
}, 60000);
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleCharacter method playerNPC.
public void playerNPC(MapleCharacter v, int scriptId) {
int npcId;
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT id FROM playernpcs WHERE ScriptId = ?");
ps.setInt(1, scriptId);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
rs.close();
ps = con.prepareStatement("INSERT INTO playernpcs (name, hair, face, skin, x, cy, map, ScriptId, Foothold, rx0, rx1) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, v.getName());
ps.setInt(2, v.getHair());
ps.setInt(3, v.getFace());
ps.setInt(4, v.getSkinColor().getId());
ps.setInt(5, getPosition().x);
ps.setInt(6, getPosition().y);
ps.setInt(7, getMapId());
ps.setInt(8, scriptId);
ps.setInt(9, getMap().getFootholds().findBelow(getPosition()).getId());
ps.setInt(10, getPosition().x + 50);
ps.setInt(11, getPosition().x - 50);
ps.executeUpdate();
rs = ps.getGeneratedKeys();
rs.next();
npcId = rs.getInt(1);
ps.close();
ps = con.prepareStatement("INSERT INTO playernpcs_equip (NpcId, equipid, equippos) VALUES (?, ?, ?)");
ps.setInt(1, npcId);
for (Item equip : getInventory(MapleInventoryType.EQUIPPED)) {
int position = Math.abs(equip.getPosition());
if ((position < 12 && position > 0) || (position > 100 && position < 112)) {
ps.setInt(2, equip.getItemId());
ps.setInt(3, equip.getPosition());
ps.addBatch();
}
}
ps.executeBatch();
ps.close();
rs.close();
ps = con.prepareStatement("SELECT * FROM playernpcs WHERE ScriptId = ?");
ps.setInt(1, scriptId);
rs = ps.executeQuery();
rs.next();
PlayerNPCs pn = new PlayerNPCs(rs);
for (Channel channel : Server.getInstance().getChannelsFromWorld(world)) {
MapleMap m = channel.getMapFactory().getMap(getMapId());
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
m.addMapObject(pn);
}
}
ps.close();
rs.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
Aggregations