Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of event messages #102

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -276,10 +276,16 @@ private void parseTicks(LittleEndianDataInputStream dataStream) throws IOExcepti
String functionName = readString(dataStream);
Object lua = parseLua(dataStream);

// (ab)used by chat messages
if (Objects.equals("GiveResourcesToPlayer", functionName)) {
parseGiveResourcesToPlayer((Map<String, Object>) lua);
}

// used by specific events, such as pausing
if (Objects.equals("EventMessage", functionName)) {
parseEventMessage((Map<String, Object>) lua);
}

// No idea what this skips
if (lua != null) {
dataStream.skipBytes(4 * dataStream.readInt());
Expand Down Expand Up @@ -375,6 +381,16 @@ private void parseGiveResourcesToPlayer(Map<String, Object> lua) {
}
}

private void parseEventMessage(Map<String, Object> lua) {
if (lua.containsKey("fromFocusArmy") && lua.containsKey("event")) {
String sender = (String) lua.get("fromFocusArmy");
String event = (String) lua.get("event");

// this is a bit of a hack as it is not a chat message that players see ingame
chatMessages.add(new ChatMessage(tickToTime(ticks), sender, "", event));
}
}

private Duration tickToTime(int tick) {
return Duration.ofSeconds(tick / 10);
}
Expand Down