4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sourceforge.jindolf.archiver;
10 import java.io.IOException;
11 import java.io.Writer;
12 import java.util.LinkedList;
13 import java.util.List;
14 import jp.sourceforge.jindolf.corelib.GameRole;
15 import jp.sourceforge.jindolf.corelib.SysEventType;
16 import jp.sourceforge.jindolf.parser.DecodedContent;
21 public class EventData extends TopicData{
23 private SysEventType eventType = null;
25 private final List<AvatarData> avatarList = new LinkedList<AvatarData>();
26 private final List<Integer> intList = new LinkedList<Integer>();
27 private final List<GameRole> roleList = new LinkedList<GameRole>();
28 private final List<DecodedContent> strList =
29 new LinkedList<DecodedContent>();
34 * @param periodData 所属元Period
36 public EventData(PeriodData periodData){
43 * イベント種別からXML要素名を取得する。
47 public static String getTagName(SysEventType type){
51 case STARTENTRY: tagName = "startEntry"; break;
52 case ONSTAGE: tagName = "onStage"; break;
53 case STARTMIRROR: tagName = "startMirror"; break;
54 case OPENROLE: tagName = "openRole"; break;
55 case MURDERED: tagName = "murdered"; break;
56 case STARTASSAULT: tagName = "startAssault"; break;
57 case SURVIVOR: tagName = "survivor"; break;
58 case COUNTING: tagName = "counting"; break;
59 case NOMURDER: tagName = "noMurder"; break;
60 case SUDDENDEATH: tagName = "suddenDeath"; break;
61 case WINVILLAGE: tagName = "winVillage"; break;
62 case WINWOLF: tagName = "winWolf"; break;
63 case WINHAMSTER: tagName = "winHamster"; break;
64 case PLAYERLIST: tagName = "playerList"; break;
65 case PANIC: tagName = "panic"; break;
66 case EXECUTION: tagName = "execution"; break;
67 case VANISH: tagName = "vanish"; break;
68 case CHECKOUT: tagName = "checkout"; break;
69 case SHORTMEMBER: tagName = "shortMember"; break;
70 case ASKENTRY: tagName = "askEntry"; break;
71 case ASKCOMMIT: tagName = "askCommit"; break;
72 case NOCOMMENT: tagName = "noComment"; break;
73 case STAYEPILOGUE: tagName = "stayEpilogue"; break;
74 case GAMEOVER: tagName = "gameOver"; break;
75 case GUARD: tagName = "guard"; break;
76 case JUDGE: tagName = "judge"; break;
77 case COUNTING2: tagName = "counting2"; break;
78 case ASSAULT: tagName = "assault"; break;
79 default: throw new IllegalArgumentException();
90 public static String getRoleAttrValue(GameRole role){
94 case INNOCENT: roleName = "innocent"; break;
95 case WOLF: roleName = "wolf"; break;
96 case SEER: roleName = "seer"; break;
97 case SHAMAN: roleName = "shaman"; break;
98 case MADMAN: roleName = "madman"; break;
99 case HUNTER: roleName = "hunter"; break;
100 case FRATER: roleName = "frater"; break;
101 case HAMSTER: roleName = "hamster"; break;
102 default: throw new IllegalArgumentException();
109 * avatarRef要素をXML出力する。
111 * @param avatar Avatar
112 * @throws IOException 出力エラー
114 public static void dumpAvatarRef(Writer writer, AvatarData avatar)
116 writer.append("<avatarRef");
118 XmlUtils.attrOut(writer, "avatarId", avatar.getAvatarId());
119 writer.append(" />\n");
127 public SysEventType getEventType(){
128 return this.eventType;
133 * @param eventType システムイベント種別
135 public void setEventType(SysEventType eventType){
136 this.eventType = eventType;
142 * @param avatarData Avatar情報
144 public void addAvatarData(AvatarData avatarData){
145 this.avatarList.add(avatarData);
153 public void addInteger(int intVal){
154 this.intList.add(intVal);
162 public void addGameRole(GameRole role){
163 this.roleList.add(role);
171 public void addDecodedContent(DecodedContent seq){
172 this.strList.add(seq);
177 * ONSTAGE属性値をXML出力する。
179 * @throws IOException 出力エラー
181 public void dumpOnstageAttr(Writer writer) throws IOException{
182 int entryNo = this.intList.get(0);
183 AvatarData avatarData = this.avatarList.get(0);
186 XmlUtils.attrOut(writer, "entryNo", Integer.toString(entryNo));
188 XmlUtils.attrOut(writer, "avatarId", avatarData.getAvatarId());
194 * avatarId属性値をXML出力する。
196 * @throws IOException 出力エラー
198 public void dumpSingleAvatarAttr(Writer writer) throws IOException{
199 AvatarData avatarData = this.avatarList.get(0);
202 XmlUtils.attrOut(writer, "avatarId", avatarData.getAvatarId());
208 * COUNTINGのvictim属性値をXML出力する。
210 * @throws IOException 出力エラー
212 public void dumpCountingAttr(Writer writer) throws IOException{
213 int total = this.avatarList.size();
215 AvatarData victim = this.avatarList.get(total - 1);
217 XmlUtils.attrOut(writer, "victim", victim.getAvatarId());
223 * EXECUTIONのvictim属性値をXML出力する。
225 * @throws IOException 出力エラー
227 public void dumpExecutionAttr(Writer writer) throws IOException{
228 int totalAvatar = this.avatarList.size();
229 int totalVotes = this.intList.size();
230 if(totalAvatar != totalVotes){
231 AvatarData victim = this.avatarList.get(totalAvatar - 1);
233 XmlUtils.attrOut(writer, "victim", victim.getAvatarId());
239 * ASKENTRY属性値をXML出力する。
241 * @throws IOException 出力エラー
243 public void dumpAskEntryAttr(Writer writer) throws IOException{
244 int hour = this.intList.get(0);
245 int minute = this.intList.get(1);
246 int minLimit = this.intList.get(2);
247 int maxLimit = this.intList.get(3);
250 XmlUtils.timeAttrOut(writer, "commitTime", hour, minute);
253 XmlUtils.attrOut(writer, "minMembers", Integer.toString(minLimit));
256 XmlUtils.attrOut(writer, "maxMembers", Integer.toString(maxLimit));
262 * ASKCOMMIT属性値をXML出力する。
264 * @throws IOException 出力エラー
266 public void dumpAskCommitAttr(Writer writer) throws IOException{
267 int hour = this.intList.get(0);
268 int minute = this.intList.get(1);
271 XmlUtils.timeAttrOut(writer, "limitVote", hour, minute);
274 XmlUtils.timeAttrOut(writer, "limitSpecial", hour, minute);
280 * STAYEPILOGUE属性値をXML出力する。
282 * @throws IOException 出力エラー
284 public void dumpStayEpilogueAttr(Writer writer) throws IOException{
285 GameRole role = this.roleList.get(0);
286 int hour = this.intList.get(0);
287 int minute = this.intList.get(1);
291 case INNOCENT: winner = "village"; break;
292 case WOLF: winner = "wolf"; break;
293 case HAMSTER: winner = "hamster"; break;
294 default: throw new IllegalArgumentException();
297 XmlUtils.attrOut(writer, "maxMembers", winner);
300 XmlUtils.timeAttrOut(writer, "limitTime", hour, minute);
306 * openRole子要素をXML出力する。
308 * @throws IOException 出力エラー
310 public void dumpOpenroleElem(Writer writer) throws IOException{
311 int num = this.roleList.size();
312 for(int index = 0; index < num; index++){
313 int heads = this.intList.get(index);
314 GameRole role = this.roleList.get(index);
315 String roleName = getRoleAttrValue(role);
317 writer.append("<roleHeads");
319 XmlUtils.attrOut(writer, "role", roleName);
321 XmlUtils.attrOut(writer, "heads", Integer.toString(heads));
322 writer.append(" />\n");
328 * murdered子要素をXML出力する。
330 * @throws IOException 出力エラー
332 public void dumpMurderedElem(Writer writer) throws IOException{
333 for(AvatarData avatar : this.avatarList){
334 dumpAvatarRef(writer, avatar);
340 * survivor子要素をXML出力する。
342 * @throws IOException 出力エラー
344 public void dumpSurvivorElem(Writer writer) throws IOException{
345 for(AvatarData avatar : this.avatarList){
346 dumpAvatarRef(writer, avatar);
352 * nocomment子要素をXML出力する。
354 * @throws IOException 出力エラー
356 public void dumpNoCommentElem(Writer writer) throws IOException{
357 for(AvatarData avatar : this.avatarList){
358 dumpAvatarRef(writer, avatar);
364 * counting子要素をXML出力する。
366 * @throws IOException 出力エラー
368 public void dumpCountingElem(Writer writer) throws IOException{
369 int total = this.avatarList.size();
370 total = total / 2 * 2;
371 for(int index = 0; index < total; index += 2){
372 AvatarData voteBy = this.avatarList.get(index);
373 AvatarData voteTo = this.avatarList.get(index + 1);
374 writer.append("<vote");
376 XmlUtils.attrOut(writer, "byWhom", voteBy.getAvatarId());
378 XmlUtils.attrOut(writer, "target", voteTo.getAvatarId());
379 writer.append(" />\n");
385 * execution子要素をXML出力する。
387 * @throws IOException 出力エラー
389 public void dumpExecutionElem(Writer writer) throws IOException{
390 int total = this.intList.size();
391 for(int index = 0; index < total; index++){
392 AvatarData voteTo = this.avatarList.get(index);
393 int count = this.intList.get(index);
394 writer.append("<nominated");
396 XmlUtils.attrOut(writer, "avatarId", voteTo.getAvatarId());
398 XmlUtils.attrOut(writer, "count", "" + count);
399 writer.append(" />\n");
405 * playerlist子要素をXML出力する。
407 * @throws IOException 出力エラー
409 public void dumpPlayerlistElem(Writer writer) throws IOException{
410 int num = this.avatarList.size();
412 for(int index = 0; index < num; index++){
413 AvatarData avatar = this.avatarList.get(index);
414 DecodedContent uri = this.strList.get(index * 2);
415 DecodedContent account = this.strList.get(index * 2 + 1);
416 int isLiving = this.intList.get(index);
418 if(isLiving == 0) survive = "false";
419 else survive = "true";
420 GameRole role = this.roleList.get(index);
421 String roleName = getRoleAttrValue(role);
423 writer.append("<playerInfo");
425 XmlUtils.attrOut(writer, "playerId", account.toString());
427 XmlUtils.attrOut(writer, "avatarId", avatar.getAvatarId());
429 XmlUtils.attrOut(writer, "survive", survive);
431 XmlUtils.attrOut(writer, "role", roleName);
433 String uriStr = uri.toString();
434 uriStr = uriStr.replaceAll("^[\\s]+", "");
435 uriStr = uriStr.replaceAll("[\\s]+$", "");
436 uriStr = uriStr.replaceAll("[\\s]+", "\u0020");
437 if(uriStr.length() > 0){
439 XmlUtils.attrOut(writer, "uri", uriStr);
442 writer.append(" />\n");
449 * Avatar間関係の属性値をXML出力する。
451 * @throws IOException 出力エラー
453 public void dumpByWhomAttr(Writer writer) throws IOException{
454 AvatarData by = this.avatarList.get(0);
455 AvatarData to = this.avatarList.get(1);
458 XmlUtils.attrOut(writer, "byWhom", by.getAvatarId());
460 XmlUtils.attrOut(writer, "target", to.getAvatarId());
466 * ASSAULT属性値をXML出力する。
468 * @throws IOException 出力エラー
470 public void dumpAssaultAttr(Writer writer) throws IOException{
471 AvatarData by = this.avatarList.get(0);
472 AvatarData to = this.avatarList.get(1);
476 XmlUtils.indent(writer, 1);
477 XmlUtils.attrOut(writer, "byWhom", by.getAvatarId());
479 XmlUtils.attrOut(writer, "target", to.getAvatarId());
482 DecodedContent xname = this.strList.get(0);
483 XmlUtils.indent(writer, 1);
484 XmlUtils.attrOut(writer, "xname", xname);
486 int hour = this.intList.get(0);
487 int minute = this.intList.get(1);
489 XmlUtils.timeAttrOut(writer, "time", hour, minute);
492 String icon = this.strList.get(1).toString();
493 if( ! icon.equals(by.getFaceIconUri()) ){
494 XmlUtils.indent(writer, 1);
495 XmlUtils.attrOut(writer, "faceIconURI", icon);
503 * システムイベント各種要素のXML出力を行う。
505 * @throws IOException 出力エラー
507 public void dumpXml(Writer writer) throws IOException{
508 String tagName = getTagName(this.eventType);
511 writer.append(tagName);
513 boolean hasAttr = true;
514 switch(this.eventType){
516 dumpOnstageAttr(writer);
519 dumpCountingAttr(writer);
522 dumpExecutionAttr(writer);
527 dumpSingleAvatarAttr(writer);
530 dumpAskEntryAttr(writer);
533 dumpAskCommitAttr(writer);
536 dumpStayEpilogueAttr(writer);
540 dumpByWhomAttr(writer);
543 dumpAssaultAttr(writer);
550 if(hasAttr) writer.append(' ');
551 writer.append(">\n");
555 switch(this.eventType){
557 dumpOpenroleElem(writer);
560 dumpMurderedElem(writer);
563 dumpSurvivorElem(writer);
567 dumpCountingElem(writer);
570 dumpExecutionElem(writer);
573 dumpPlayerlistElem(writer);
576 dumpNoCommentElem(writer);
583 writer.append(tagName);
584 writer.append(">\n");