Skip to content

Commit

Permalink
[EasyNPC] Adapted changes applied to the easyNPC core
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaring committed Sep 23, 2014
1 parent 98e48c4 commit 081b1cf
Show file tree
Hide file tree
Showing 38 changed files with 69 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ConditionAdmin implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.admin())" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s())" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ConditionAttrib implements TalkCondition {
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE =
"talkEntry:addCondition(%1$s.attribute(\"%2$s\", \"%3$s\", %4$s))" + LuaWriter.NL;
"talkEntry:addCondition(%1$s(\"%2$s\", \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ConditionChance implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.chance(%2$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(%2$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class ConditionItem implements TalkCondition {
* can use.
*/
private static final String LUA_CODE =
"talkEntry:addCondition(%1$s.item(%2$s, \"%3$s\", \"%4$s\", %5$s, %6$s))" + LuaWriter.NL;
"talkEntry:addCondition(%1$s(%2$s, \"%3$s\", \"%4$s\", %5$s, %6$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionLanguage implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.language(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionMagicType implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.magictype(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConditionMoney implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.money(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionNumber implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.number(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConditionQueststatus implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.quest(%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionRace implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.race(%2$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(%2$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConditionRank implements TalkCondition {
/**
* The LUA code needed for this condition to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.rank(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionSex implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.sex(%2$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(%2$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ConditionSkill implements TalkCondition {
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE =
"talkEntry:addCondition(%1$s.skill(Character.%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;
"talkEntry:addCondition(%1$s(Character.%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConditionState implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.state(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionTalkMode implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.talkmode(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionTalkstate implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.basestate(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConditionTown implements TalkCondition {
/**
* The LUA code needed for this consequence to work.
*/
private static final String LUA_CODE = "talkEntry:addCondition(%1$s.town(%2$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addCondition(%1$s(%2$s))" + LuaWriter.NL;

/**
* The LUA module required for this condition to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String getLuaModule() {
@Override
public void writeLua(@Nonnull Writer target, @Nonnull LuaRequireTable requires) throws IOException {
target.write("talkEntry:addConsequence(");
target.write(requires.getStorage(getLuaModule()) + ".arena(\"");
target.write(requires.getStorage(getLuaModule()) + "(\"");
switch (task) {
case RequestMonster:
target.write("request");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ConsequenceAttribute implements TalkConsequence {
* The LUA code needed to be included for a attribute consequence.
*/
private static final String LUA_CODE =
"talkEntry:addConsequence(%1$s.attribute(\"%2$s\", \"%3$s\", %4$s))" + LuaWriter.NL;
"talkEntry:addConsequence(%1$s(\"%2$s\", \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The module used to access this attribute consequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class ConsequenceDeleteItem implements TalkConsequence {
* value set.
*/
private static final String LUA_CODE_DATA =
"talkEntry:addConsequence(%1$s.deleteitem(%2$s, %3$s, %4$s))" + LuaWriter.NL;
"talkEntry:addConsequence(%1$s(%2$s, %3$s, %4$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceGemcraft implements TalkConsequence {
/**
* The LUA code needed to be included for a gemcraft consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.gemcraft(craftNPC))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(craftNPC))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ConsequenceInform implements TalkConsequence {
/**
* The LUA code needed to be included for a inform consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.inform(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module that is required for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceIntroduce implements TalkConsequence {
/**
* The LUA code needed to be included for a introduce consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.introduce())" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s())" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ConsequenceItem implements TalkConsequence {
* The LUA code needed to be included for a create item consequence.
*/
private static final String LUA_CODE =
"talkEntry:addConsequence(%1$s.item(%2$s, %3$s, %4$s, %5$s))" + LuaWriter.NL;
"talkEntry:addConsequence(%1$s(%2$s, %3$s, %4$s, %5$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConsequenceMoney implements TalkConsequence {
/**
* The LUA code needed to be included for a money consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.money(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module that is needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConsequenceQueststatus implements TalkConsequence {
/**
* The LUA code needed to be included for a quest status consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.quest(%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConsequenceRankpoints implements TalkConsequence {
/**
* The LUA code needed to be included for a quest status consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.rankpoints(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String getLuaModule() {

@Override
public void writeLua(@Nonnull Writer target, @Nonnull LuaRequireTable requires) throws IOException {
target.write("talkEntry:addConsequence(" + requires.getStorage(getLuaModule()) + ".repair())");
target.write("talkEntry:addConsequence(" + requires.getStorage(getLuaModule()) + "())");
target.write(LuaWriter.NL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceRune implements TalkConsequence {
/**
* The LUA code needed to be included for a rune consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.rune(%2$s, %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(%2$s, %3$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ConsequenceSkill implements TalkConsequence {
* The LUA code needed to be included for a skill consequence.
*/
private static final String LUA_CODE =
"talkEntry:addConsequence(%1$s.skill(Character.%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;
"talkEntry:addConsequence(%1$s(Character.%2$s, \"%3$s\", %4$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConsequenceState implements TalkConsequence {
/**
* The LUA code needed to be included for a state consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.state(\"%2$s\", %3$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"%2$s\", %3$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceTalkstate implements TalkConsequence {
/**
* The LUA code needed to be included for a talk state consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.talkstate(\"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceTown implements TalkConsequence {
/**
* The LUA code needed to be included for a quest status consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.town(\"=\", \"%2$s\"))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(\"=\", \"%2$s\"))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ConsequenceTrade implements TalkConsequence {
/**
* The LUA code needed to be included for a introduce consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.trade(tradingNPC))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(tradingNPC))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class ConsequenceTreasure implements TalkConsequence {
/**
* The LUA code needed to be included for a rune consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.treasure(%2$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(%2$s))" + LuaWriter.NL;

/**
* The LUA module needed for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ConsequenceWarp implements TalkConsequence {
/**
* The LUA code needed to be included for a warp consequence.
*/
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s.warp(%2$s, %3$s, %4$s))" + LuaWriter.NL;
private static final String LUA_CODE = "talkEntry:addConsequence(%1$s(%2$s, %3$s, %4$s))" + LuaWriter.NL;

/**
* The LUA module that is required for this consequence to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,34 @@
*/
public class LuaRequireTable {
@Nonnull
private final Map<String, String> requireStoragae;
private final Map<String, String> requireStorage;

public LuaRequireTable() {
requireStoragae = new HashMap<>();
requireStorage = new HashMap<>();
}

public void registerDependency(@Nonnull String dependency) {
if (!requireStoragae.containsKey(dependency)) {
String storage = "dep" + requireStoragae.size();
requireStoragae.put(dependency, storage);
if (!requireStorage.containsKey(dependency)) {
String storage;
if (dependency.startsWith("npc.base.")) {
storage = dependency.substring("npc.base.".length()).replace('.', '_');
} else {
storage = dependency.replace('.', '_');
}
String usedStorage = storage;
int cnt = 0;
while (requireStorage.containsValue(usedStorage)) {
usedStorage = storage + Integer.toString(cnt++);
}
requireStorage.put(dependency, usedStorage);
}
}

public void writeDependencies(@Nonnull Writer writer) throws IOException {
for (Map.Entry<String, String> entry : requireStoragae.entrySet()){
for (Map.Entry<String, String> entry : requireStorage.entrySet()){
writer.write("local ");
writer.write(entry.getValue());
writer.write("=require(\"");
writer.write(" = require(\"");
writer.write(entry.getKey());
writer.write("\")");
writer.write(LuaWriter.NL);
Expand All @@ -54,8 +64,8 @@ public void writeDependencies(@Nonnull Writer writer) throws IOException {

@Nonnull
public String getStorage(@Nonnull String dependency) {
if (requireStoragae.containsKey(dependency)) {
return requireStoragae.get(dependency);
if (requireStorage.containsKey(dependency)) {
return requireStorage.get(dependency);
}
throw new IllegalArgumentException("Dependency \"" + dependency + "\" was never registered.");
}
Expand Down

0 comments on commit 081b1cf

Please sign in to comment.