use of server.maps.PlayerNPCs 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();
}
}
use of server.maps.PlayerNPCs in project HeavenMS by ronancpl.
the class NPCTalkHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (System.currentTimeMillis() - c.getPlayer().getNpcCooldown() < ServerConstants.BLOCK_NPC_RACE_CONDT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int oid = slea.readInt();
MapleMapObject obj = c.getPlayer().getMap().getMapObject(oid);
if (obj instanceof MapleNPC) {
MapleNPC npc = (MapleNPC) obj;
if (ServerConstants.USE_DEBUG == true)
c.getPlayer().dropMessage(5, "Talking to NPC " + npc.getId());
if (npc.getId() == 9010009) {
// is duey
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
c.announce(MaplePacketCreator.sendDuey((byte) 8, DueyHandler.loadItems(c.getPlayer())));
} else {
if (c.getCM() != null || c.getQM() != null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (npc.getId() >= 9100100 && npc.getId() <= 9100200) {
// Custom handling for gachapon scripts to reduce the amount of scripts needed.
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon", null);
} else {
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
if (!hasNpcScript) {
if (!npc.hasShop()) {
FilePrinter.printError(FilePrinter.NPC_UNCODED, "NPC " + npc.getName() + "(" + npc.getId() + ") is not coded.\r\n");
return;
} else if (c.getPlayer().getShop() != null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
npc.sendShop(c);
}
}
}
} else if (obj instanceof PlayerNPCs) {
NPCScriptManager.getInstance().start(c, ((PlayerNPCs) obj).getId(), null);
}
}
Aggregations