private static void storeItem(PcInstance pc, ItemInstance item) { LsimulatorInventory inventory; if (pc.getInventory().checkAddItem(item, item.getCount()) == LsimulatorInventory.OK) { inventory = pc.getInventory(); } else { // 持てない場合は地面に落とす 処理のキャンセルはしない(不正防止) inventory = LsimulatorWorld.getInstance().getInventory(pc.getLocation()); } inventory.storeItem(item); pc.sendPackets(new S_ServerMessage(403, item.getLogName())); // %0を手に入れました。 }
private void checkNpcChatTime() { for (LsimulatorNpcChat npcChat : NpcChatTable.getInstance().getAllGameTime()) { if (isChatTime(npcChat.getGameTime())) { int npcId = npcChat.getNpcId(); for (LsimulatorObject obj : LsimulatorWorld.getInstance().getObject()) { if (!(obj instanceof NpcInstance)) { continue; } NpcInstance npc = (NpcInstance) obj; if (npc.getNpcTemplate().get_npcId() == npcId) { npc.startChat(NpcInstance.CHAT_TIMING_GAME_TIME); } } } } }
public static void spawn(PcInstance pc, int npcId, int randomRange, int timeMillisToDelete) { try { NpcInstance npc = NpcTable.getInstance().newNpcInstance(npcId); npc.setId(IdFactory.getInstance().nextId()); npc.setMap(pc.getMapId()); if (randomRange == 0) { npc.getLocation().set(pc.getLocation()); npc.getLocation().forward(pc.getHeading()); } else { int tryCount = 0; do { tryCount++; npc.setX(pc.getX() + Random.nextInt(randomRange) - Random.nextInt(randomRange)); npc.setY(pc.getY() + Random.nextInt(randomRange) - Random.nextInt(randomRange)); if (npc.getMap().isInMap(npc.getLocation()) && npc.getMap().isPassable(npc.getLocation())) { break; } Thread.sleep(1); } while (tryCount < 50); if (tryCount >= 50) { npc.getLocation().set(pc.getLocation()); npc.getLocation().forward(pc.getHeading()); } } npc.setHomeX(npc.getX()); npc.setHomeY(npc.getY()); npc.setHeading(pc.getHeading()); // 紀錄龍之門扉編號 if (npc.getNpcId() == 81273) { for (int i = 0; i < 6; i++) { if (!LsimulatorDragonSlayer.getInstance().getPortalNumber()[i]) { LsimulatorDragonSlayer.getInstance().setPortalNumber(i, true); // 重置副本 LsimulatorDragonSlayer.getInstance().resetDragonSlayer(i); npc.setPortalNumber(i); LsimulatorDragonSlayer.getInstance().portalPack()[i] = npc; break; } } } else if (npc.getNpcId() == 81274) { for (int i = 6; i < 12; i++) { if (!LsimulatorDragonSlayer.getInstance().getPortalNumber()[i]) { LsimulatorDragonSlayer.getInstance().setPortalNumber(i, true); // 重置副本 LsimulatorDragonSlayer.getInstance().resetDragonSlayer(i); npc.setPortalNumber(i); LsimulatorDragonSlayer.getInstance().portalPack()[i] = npc; break; } } } LsimulatorWorld.getInstance().storeObject(npc); LsimulatorWorld.getInstance().addVisibleObject(npc); if (npc.getTempCharGfx() == 7548 || npc.getTempCharGfx() == 7550 || npc.getTempCharGfx() == 7552 || npc.getTempCharGfx() == 7554 || npc.getTempCharGfx() == 7585 || npc.getTempCharGfx() == 7591) { npc.broadcastPacket(new S_NPCPack(npc)); npc.broadcastPacket(new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_AxeWalk)); } else if (npc.getTempCharGfx() == 7539 || npc.getTempCharGfx() == 7557 || npc.getTempCharGfx() == 7558 || npc.getTempCharGfx() == 7864 || npc.getTempCharGfx() == 7869 || npc.getTempCharGfx() == 7870) { for (PcInstance _pc : LsimulatorWorld.getInstance().getVisiblePlayer(npc, 50)) { if (npc.getTempCharGfx() == 7539) { _pc.sendPackets(new S_ServerMessage(1570)); } else if (npc.getTempCharGfx() == 7864) { _pc.sendPackets(new S_ServerMessage(1657)); } npc.onPerceive(_pc); S_DoActionGFX gfx = new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_AxeWalk); _pc.sendPackets(gfx); } npc.npcSleepTime(ActionCodes.ACTION_AxeWalk, NpcInstance.ATTACK_SPEED); } else if (npc.getTempCharGfx() == 145) { // 史巴托 npc.setStatus(11); npc.broadcastPacket(new S_NPCPack(npc)); npc.broadcastPacket(new S_DoActionGFX(npc.getId(), ActionCodes.ACTION_Appear)); npc.setStatus(0); npc.broadcastPacket(new S_CharVisualUpdate(npc, npc.getStatus())); } npc.turnOnOffLight(); npc.startChat(NpcInstance.CHAT_TIMING_APPEARANCE); // チャット開始 if (0 < timeMillisToDelete) { LsimulatorNpcDeleteTimer timer = new LsimulatorNpcDeleteTimer(npc, timeMillisToDelete); timer.begin(); } } catch (Exception e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } }