4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sourceforge.jindolf.archiver;
10 import java.io.IOException;
11 import java.util.LinkedList;
12 import java.util.List;
13 import jp.osdn.jindolf.parser.content.DecodedContent;
14 import jp.sourceforge.jindolf.corelib.GameRole;
15 import jp.sourceforge.jindolf.corelib.SysEventType;
20 public class EventData extends TopicData{
22 private SysEventType eventType = null;
24 private final List<AvatarData> avatarList = new LinkedList<>();
25 private final List<Integer> intList = new LinkedList<>();
26 private final List<GameRole> roleList = new LinkedList<>();
27 private final List<DecodedContent> strList =
41 * イベント種別からXML要素名を取得する。
45 public static String getTagName(SysEventType type){
49 case STARTENTRY: tagName = "startEntry"; break;
50 case ONSTAGE: tagName = "onStage"; break;
51 case STARTMIRROR: tagName = "startMirror"; break;
52 case OPENROLE: tagName = "openRole"; break;
53 case MURDERED: tagName = "murdered"; break;
54 case STARTASSAULT: tagName = "startAssault"; break;
55 case SURVIVOR: tagName = "survivor"; break;
56 case COUNTING: tagName = "counting"; break;
57 case NOMURDER: tagName = "noMurder"; break;
58 case SUDDENDEATH: tagName = "suddenDeath"; break;
59 case WINVILLAGE: tagName = "winVillage"; break;
60 case WINWOLF: tagName = "winWolf"; break;
61 case WINHAMSTER: tagName = "winHamster"; break;
62 case PLAYERLIST: tagName = "playerList"; break;
63 case PANIC: tagName = "panic"; break;
64 case EXECUTION: tagName = "execution"; break;
65 case VANISH: tagName = "vanish"; break;
66 case CHECKOUT: tagName = "checkout"; break;
67 case SHORTMEMBER: tagName = "shortMember"; break;
68 case ASKENTRY: tagName = "askEntry"; break;
69 case ASKCOMMIT: tagName = "askCommit"; break;
70 case NOCOMMENT: tagName = "noComment"; break;
71 case STAYEPILOGUE: tagName = "stayEpilogue"; break;
72 case GAMEOVER: tagName = "gameOver"; break;
73 case GUARD: tagName = "guard"; break;
74 case JUDGE: tagName = "judge"; break;
75 case COUNTING2: tagName = "counting2"; break;
76 case ASSAULT: tagName = "assault"; break;
77 default: throw new IllegalArgumentException();
88 public static String getRoleAttrValue(GameRole role){
92 case INNOCENT: roleName = "innocent"; break;
93 case WOLF: roleName = "wolf"; break;
94 case SEER: roleName = "seer"; break;
95 case SHAMAN: roleName = "shaman"; break;
96 case MADMAN: roleName = "madman"; break;
97 case HUNTER: roleName = "hunter"; break;
98 case FRATER: roleName = "frater"; break;
99 case HAMSTER: roleName = "hamster"; break;
100 default: throw new IllegalArgumentException();
107 * avatarRef要素をXML出力する。
109 * @param avatar Avatar
110 * @throws IOException 出力エラー
112 public static void dumpAvatarRef(XmlOut writer, AvatarData avatar)
114 writer.append("<avatarRef");
116 writer.attrOut("avatarId", avatar.getAvatarId());
117 writer.append(" />");
126 public SysEventType getEventType(){
127 return this.eventType;
132 * @param eventType システムイベント種別
134 public void setEventType(SysEventType eventType){
135 this.eventType = eventType;
141 * @param avatarData Avatar情報
143 public void addAvatarData(AvatarData avatarData){
144 this.avatarList.add(avatarData);
152 public void addInteger(int intVal){
153 this.intList.add(intVal);
161 public void addGameRole(GameRole role){
162 this.roleList.add(role);
170 public void addDecodedContent(DecodedContent seq){
171 this.strList.add(seq);
176 * ONSTAGE属性値をXML出力する。
178 * @throws IOException 出力エラー
180 public void dumpOnstageAttr(XmlOut writer) throws IOException{
181 int entryNo = this.intList.get(0);
182 AvatarData avatarData = this.avatarList.get(0);
185 writer.attrOut("entryNo", Integer.toString(entryNo));
187 writer.attrOut("avatarId", avatarData.getAvatarId());
193 * avatarId属性値をXML出力する。
195 * @throws IOException 出力エラー
197 public void dumpSingleAvatarAttr(XmlOut writer) throws IOException{
198 AvatarData avatarData = this.avatarList.get(0);
201 writer.attrOut("avatarId", avatarData.getAvatarId());
207 * COUNTINGのvictim属性値をXML出力する。
209 * @throws IOException 出力エラー
211 public void dumpCountingAttr(XmlOut writer) throws IOException{
212 int total = this.avatarList.size();
214 AvatarData victim = this.avatarList.get(total - 1);
216 writer.attrOut("victim", victim.getAvatarId());
222 * EXECUTIONのvictim属性値をXML出力する。
224 * @throws IOException 出力エラー
226 public void dumpExecutionAttr(XmlOut writer) throws IOException{
227 int totalAvatar = this.avatarList.size();
228 int totalVotes = this.intList.size();
229 if(totalAvatar != totalVotes){
230 AvatarData victim = this.avatarList.get(totalAvatar - 1);
232 writer.attrOut("victim", victim.getAvatarId());
238 * ASKENTRY属性値をXML出力する。
240 * @throws IOException 出力エラー
242 public void dumpAskEntryAttr(XmlOut writer) throws IOException{
243 int hour = this.intList.get(0);
244 int minute = this.intList.get(1);
245 int minLimit = this.intList.get(2);
246 int maxLimit = this.intList.get(3);
249 writer.timeAttrOut("commitTime", hour, minute);
252 writer.attrOut("minMembers", Integer.toString(minLimit));
255 writer.attrOut("maxMembers", Integer.toString(maxLimit));
261 * ASKCOMMIT属性値をXML出力する。
263 * @throws IOException 出力エラー
265 public void dumpAskCommitAttr(XmlOut writer) throws IOException{
266 int hour = this.intList.get(0);
267 int minute = this.intList.get(1);
270 writer.timeAttrOut("limitVote", hour, minute);
273 writer.timeAttrOut("limitSpecial", hour, minute);
279 * STAYEPILOGUE属性値をXML出力する。
281 * @throws IOException 出力エラー
283 public void dumpStayEpilogueAttr(XmlOut writer) throws IOException{
284 GameRole role = this.roleList.get(0);
285 int hour = this.intList.get(0);
286 int minute = this.intList.get(1);
290 case INNOCENT: winner = "village"; break;
291 case WOLF: winner = "wolf"; break;
292 case HAMSTER: winner = "hamster"; break;
293 default: throw new IllegalArgumentException();
296 writer.attrOut("maxMembers", winner);
299 writer.timeAttrOut("limitTime", hour, minute);
305 * openRole子要素をXML出力する。
307 * @throws IOException 出力エラー
309 public void dumpOpenroleElem(XmlOut writer) throws IOException{
310 int num = this.roleList.size();
311 for(int index = 0; index < num; index++){
312 int heads = this.intList.get(index);
313 GameRole role = this.roleList.get(index);
314 String roleName = getRoleAttrValue(role);
316 writer.append("<roleHeads");
318 writer.attrOut("role", roleName);
320 writer.attrOut("heads", Integer.toString(heads));
321 writer.append(" />");
328 * murdered子要素をXML出力する。
330 * @throws IOException 出力エラー
332 public void dumpMurderedElem(XmlOut writer) throws IOException{
333 for(AvatarData avatar : this.avatarList){
334 dumpAvatarRef(writer, avatar);
340 * survivor子要素をXML出力する。
342 * @throws IOException 出力エラー
344 public void dumpSurvivorElem(XmlOut writer) throws IOException{
345 for(AvatarData avatar : this.avatarList){
346 dumpAvatarRef(writer, avatar);
352 * nocomment子要素をXML出力する。
354 * @throws IOException 出力エラー
356 public void dumpNoCommentElem(XmlOut writer) throws IOException{
357 for(AvatarData avatar : this.avatarList){
358 dumpAvatarRef(writer, avatar);
364 * counting子要素をXML出力する。
366 * @throws IOException 出力エラー
368 public void dumpCountingElem(XmlOut 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 writer.attrOut("byWhom", voteBy.getAvatarId());
378 writer.attrOut("target", voteTo.getAvatarId());
379 writer.append(" />");
386 * execution子要素をXML出力する。
388 * @throws IOException 出力エラー
390 public void dumpExecutionElem(XmlOut writer) throws IOException{
391 int total = this.intList.size();
392 for(int index = 0; index < total; index++){
393 AvatarData voteTo = this.avatarList.get(index);
394 int count = this.intList.get(index);
395 writer.append("<nominated");
397 writer.attrOut("avatarId", voteTo.getAvatarId());
399 writer.attrOut("count", "" + count);
400 writer.append(" />");
407 * playerlist子要素をXML出力する。
409 * @throws IOException 出力エラー
411 public void dumpPlayerlistElem(XmlOut writer) throws IOException{
412 int num = this.avatarList.size();
414 for(int index = 0; index < num; index++){
415 AvatarData avatar = this.avatarList.get(index);
416 DecodedContent uri = this.strList.get(index * 2);
417 DecodedContent account = this.strList.get(index * 2 + 1);
418 int isLiving = this.intList.get(index);
420 if(isLiving == 0) survive = "false";
421 else survive = "true";
422 GameRole role = this.roleList.get(index);
423 String roleName = getRoleAttrValue(role);
425 writer.append("<playerInfo");
427 writer.attrOut("playerId", account.toString());
429 writer.attrOut("avatarId", avatar.getAvatarId());
431 writer.attrOut("survive", survive);
433 writer.attrOut("role", roleName);
435 String uriStr = uri.toString();
436 uriStr = uriStr.replaceAll("^[\\s\\p{Cntrl}]+", "");
437 uriStr = uriStr.replaceAll("[\\s\\p{Cntrl}]+$", "");
438 uriStr = uriStr.replaceAll("[\\s]+", "\u0020");
439 if(uriStr.length() > 0){
441 writer.attrOut("uri", uriStr);
444 writer.append(" />");
452 * Avatar間関係の属性値をXML出力する。
454 * @throws IOException 出力エラー
456 public void dumpByWhomAttr(XmlOut writer) throws IOException{
457 AvatarData by = this.avatarList.get(0);
458 AvatarData to = this.avatarList.get(1);
461 writer.attrOut("byWhom", by.getAvatarId());
463 writer.attrOut("target", to.getAvatarId());
469 * ASSAULT属性値をXML出力する。
471 * @throws IOException 出力エラー
473 public void dumpAssaultAttr(XmlOut writer) throws IOException{
474 AvatarData by = this.avatarList.get(0);
475 AvatarData to = this.avatarList.get(1);
480 writer.attrOut("byWhom", by.getAvatarId());
482 writer.attrOut("target", to.getAvatarId());
485 DecodedContent xname = this.strList.get(0);
487 writer.attrOut("xname", xname);
489 int hour = this.intList.get(0);
490 int minute = this.intList.get(1);
492 writer.timeAttrOut("time", hour, minute);
495 String icon = this.strList.get(1).toString();
496 if( ! icon.equals(by.getFaceIconUri()) ){
498 writer.attrOut("faceIconURI", icon);
506 * システムイベント各種要素のXML出力を行う。
508 * @throws IOException 出力エラー
511 public void dumpXml(XmlOut writer) throws IOException{
512 String tagName = getTagName(this.eventType);
515 writer.append(tagName);
517 boolean hasAttr = true;
518 switch(this.eventType){
520 dumpOnstageAttr(writer);
523 dumpCountingAttr(writer);
526 dumpExecutionAttr(writer);
531 dumpSingleAvatarAttr(writer);
534 dumpAskEntryAttr(writer);
537 dumpAskCommitAttr(writer);
540 dumpStayEpilogueAttr(writer);
544 dumpByWhomAttr(writer);
547 dumpAssaultAttr(writer);
554 if(hasAttr) writer.sp();
560 switch(this.eventType){
562 dumpOpenroleElem(writer);
565 dumpMurderedElem(writer);
568 dumpSurvivorElem(writer);
572 dumpCountingElem(writer);
575 dumpExecutionElem(writer);
578 dumpPlayerlistElem(writer);
581 dumpNoCommentElem(writer);
588 writer.append(tagName);