Merge pull request #302 from madsboddum/12

Conversations are now linked to spawners via conversation_id instead of spawn_id #12
This commit is contained in:
Josh Larson
2021-01-06 21:01:01 -06:00
committed by GitHub
9 changed files with 42 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
spawn_id conversation_id
conversation_id conversation_file
TEXT TEXT
imperial_recruiter imperial_recruiter/rebel_root
imperial_recruiter imperial_recruiter/neutral_root

View File

@@ -1,4 +1,4 @@
spawn_id conversation_id
conversation_id conversation_file
TEXT TEXT
rebel_recruiter rebel_recruiter/imperial_root
rebel_recruiter rebel_recruiter/neutral_root

View File

@@ -1,4 +1,4 @@
file enabled
TEXT BOOLEAN
rebel_recruiter.sdb TRUE
imperial_recruiter.sdb TRUE
imperial_recruiter.sdb TRUE

View File

@@ -62,28 +62,28 @@ public class ConversationLoader extends DataLoader {
}
@Nullable
public Conversation getConversation(String conversationId) {
public Conversation getConversation(String conversationFile) {
try {
InputStream inputStream = new FileInputStream("serverdata/nge/conversation/" + conversationId + ".json");
InputStream inputStream = new FileInputStream("serverdata/nge/conversation/" + conversationFile + ".json");
JSONObject jsonObject = JSON.readObject(inputStream);
return readConversation(conversationId, jsonObject);
return readConversation(conversationFile, jsonObject);
} catch (Throwable t) {
Log.e("Unable to load conversation by ID %s", conversationId);
Log.e("Unable to load conversation from file %s", conversationFile);
Log.e(t);
return null;
}
}
@NotNull
public List<Conversation> getInitialConversations(String spawnId) {
if (!spawnConversationsMap.containsKey(spawnId)) {
public List<Conversation> getInitialConversations(String conversationId) {
if (!spawnConversationsMap.containsKey(conversationId)) {
return Collections.emptyList();
}
Collection<String> conversationIds = spawnConversationsMap.get(spawnId);
Collection<String> conversationFiles = spawnConversationsMap.get(conversationId);
return conversationIds.stream()
return conversationFiles.stream()
.map(this::getConversation)
.filter(Objects::nonNull)
.collect(Collectors.toList());
@@ -94,8 +94,8 @@ public class ConversationLoader extends DataLoader {
return spawnConversationsMap.getOrDefault(spawnId, Collections.emptyList());
}
private Conversation readConversation(String conversationId, JSONObject jsonObject) {
Conversation conversation = new Conversation(conversationId);
private Conversation readConversation(String conversationFile, JSONObject jsonObject) {
Conversation conversation = new Conversation(conversationFile);
Map<String, Object> npcMessageObj = (Map<String, Object>) jsonObject.get("npcMessage");
@@ -199,10 +199,10 @@ public class ConversationLoader extends DataLoader {
private void loadSpawnToConversations() throws IOException {
try (SdbLoader.SdbResultSet set = SdbLoader.load(new File("serverdata/nge/conversation/spawn_conversation_map.msdb"))) {
while (set.next()) {
String spawnId = set.getText("spawn_id");
String conversationId = set.getText("conversation_id");
String conversationFile = set.getText("conversation_file");
spawnConversationsMap.computeIfAbsent(spawnId, a -> new ArrayList<>()).add(conversationId);
spawnConversationsMap.computeIfAbsent(conversationId, a -> new ArrayList<>()).add(conversationFile);
}
}
}

View File

@@ -96,6 +96,7 @@ public final class NpcStaticSpawnLoader extends DataLoader {
private final int minSpawnTime;
private final int maxSpawnTime;
private final int amount;
private final String conversationId;
private StaticSpawnInfo(SdbResultSet set) {
this.id = set.getText("spawn_id");
@@ -145,6 +146,8 @@ public final class NpcStaticSpawnLoader extends DataLoader {
this.difficulty = CreatureDifficulty.BOSS;
break;
}
this.conversationId = set.getText("conversation_id");
}
@Override
@@ -257,6 +260,11 @@ public final class NpcStaticSpawnLoader extends DataLoader {
return amount;
}
@Override
public String getConversationId() {
return conversationId;
}
private static PatrolFormation parsePatrolFormation(String str) {
switch (str.toUpperCase(Locale.US)) {
case "COLUMN":

View File

@@ -175,8 +175,13 @@ public class SimpleSpawnInfo implements SpawnInfo {
public int getAmount() {
return amount;
}
public static class Builder {
@Override
public String getConversationId() {
return null;
}
public static class Builder {
private final SimpleSpawnInfo info;

View File

@@ -75,5 +75,7 @@ public interface SpawnInfo {
int getMaxSpawnTime();
int getAmount();
String getConversationId();
}

View File

@@ -126,7 +126,10 @@ class Spawner(spawn: SpawnInfo, egg: SWGObject) {
val maxLevel: Int
get() = spawn.maxLevel
val conversationId: String
get() = spawn.conversationId
val name: String
get() = npc.name
@@ -198,7 +201,7 @@ class Spawner(spawn: SpawnInfo, egg: SWGObject) {
val creatureInfo: CreatureNpcInfo
get() = npc.creatureInfo
init {
if (spawn.patrolId.isEmpty() || spawn.patrolId == "0") { // TODO: Replace the latter with empty string
this.patrolRoute = null

View File

@@ -138,14 +138,14 @@ public class ConversationService extends Service {
CreatureObject starter = intent.getStarter();
Spawner spawner = npc.getSpawner();
String spawnId = spawner.getId();
String conversationId = spawner.getConversationId();
List<Conversation> conversations = conversationLoader.getInitialConversations(spawnId);
List<Conversation> conversations = conversationLoader.getInitialConversations(conversationId);
Conversation conversation = reduce(conversations, starter.getOwner());
if (conversation == null) {
StandardLog.onPlayerEvent(this, starter, "No eligible conversations for spawnId %s", spawnId);
StandardLog.onPlayerEvent(this, starter, "No eligible conversations for spawner with ID %s", spawner.getId());
return;
}
@@ -194,9 +194,9 @@ public class ConversationService extends Service {
private boolean isConversableNpc(AIObject npc) {
ConversationLoader conversationLoader = ServerData.INSTANCE.getConversationLoader();
Spawner spawner = npc.getSpawner();
String spawnId = spawner.getId();
String conversationId = spawner.getConversationId();
Collection<String> spawnConversationIds = conversationLoader.getConversationIds(spawnId);
Collection<String> spawnConversationIds = conversationLoader.getConversationIds(conversationId);
return !spawnConversationIds.isEmpty();
}