/** * Collect the required modules from all elements that are written to the script, sort those * modules and write them after into the needed form for the LUA script. * * @param source the parsed NPC that supplies the data * @param target the target writer that receives the written text * @throws java.io.IOException thrown in case the writing operations fail */ private void writeModules(final ParsedNpc source, final Writer target) throws IOException { final List<String> modules = new ArrayList<String>(); LuaWritable writeable = null; String[] partModules; final int count = source.getDataCount(); for (int i = 0; i < count; ++i) { writeable = source.getLuaData(i); partModules = writeable.getRequiredModules(); if (partModules != null) { for (final String module : partModules) { checkModuleAndAdd(modules, module); } } } checkModuleAndAdd(modules, "npc.base.basic"); // $NON-NLS-1$ Collections.sort(modules); for (final String module : modules) { target.write(String.format(requireCode, module)); target.write(NL); } }
/** * Fill the SQL query builder will all required data. * * @param source the NPC that is the data source to build the query * @return the prepared SQL query */ private String buildSQL(final ParsedNpc source) { final int count = source.getDataCount(); final SQLBuilder builder = new SQLBuilder(); LuaWritable writeable = null; for (int i = 0; i < count; ++i) { writeable = source.getLuaData(i); writeable.buildSQL(builder); } builder.setNpcName(source.getNpcName()); final String scriptName = source.getNpcName().toLowerCase().replace(' ', '_'); builder.setNpcScript("npc." + scriptName); // $NON-NLS-1$ builder.setNpcFaceTo(source.getNpcDir().getId()); builder.setNpcPosX(source.getNpcPos().getScX()); builder.setNpcPosY(source.getNpcPos().getScY()); builder.setNpcPosZ(source.getNpcPos().getScZ()); builder.setNpcType(source.getNpcRace().getId()); builder.setNpcSex(source.getNpcSex().getId()); return builder.getSQL(); }
/** * Write a given stage of the full NPC data. * * @param source the parsed NPC that is the data source * @param target the writer that is the target * @param stage the current stage that is supposed to be processed * @throws java.io.IOException thrown in case the writing operations fail */ private void writeStage(final ParsedNpc source, final Writer target, final WritingStage stage) throws IOException { final int count = source.getDataCount(); LuaWritable writeable = null; for (int i = 0; i < count; ++i) { writeable = source.getLuaData(i); writeable.writeLua(target, stage); } }
/** * Check if there are any entries in this stage. * * @param source the NPC that is the data source * @param stage the stage to check * @return <code>true</code> in case the NPC contains entries in this stage. */ private boolean checkStageExists(final ParsedNpc source, final WritingStage stage) { final int count = source.getDataCount(); LuaWritable writeable = null; for (int i = 0; i < count; ++i) { writeable = source.getLuaData(i); if (writeable.effectsLuaWritingStage(stage)) { return true; } } return false; }