import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import jp.osdn.jindolf.parser.content.DecodedContent;
import jp.sfjp.jindolf.data.Avatar;
import jp.sfjp.jindolf.data.Talk;
import jp.sfjp.jindolf.data.Topic;
import jp.sfjp.jindolf.data.Village;
+import jp.sourceforge.jindolf.corelib.Destiny;
import jp.sourceforge.jindolf.corelib.EventFamily;
+import jp.sourceforge.jindolf.corelib.GameRole;
import jp.sourceforge.jindolf.corelib.PeriodType;
import jp.sourceforge.jindolf.corelib.SysEventType;
import jp.sourceforge.jindolf.corelib.TalkType;
private final StringBuilder content = new StringBuilder(250);
private final Map<String, Avatar> idAvatarMap = new HashMap<>();
+ private final List<Player> playerList = new LinkedList<>();
+
private Map<String, ElemTag> qNameMap = ElemTag.getQNameMap("");
}
/**
+ * roleをデコードする。
+ *
+ * @param role role属性値
+ * @return GameRole種別
+ * @throws SAXException 不正な値
+ */
+ private static GameRole decodeRole(String role) throws SAXException{
+ GameRole result;
+
+ switch(role){
+ case "innocent":
+ result = GameRole.INNOCENT;
+ break;
+ case "wolf":
+ result = GameRole.WOLF;
+ break;
+ case "seer":
+ result = GameRole.SEER;
+ break;
+ case "shaman":
+ result = GameRole.SHAMAN;
+ break;
+ case "madman":
+ result = GameRole.MADMAN;
+ break;
+ case "hunter":
+ result = GameRole.HUNTER;
+ break;
+ case "frater":
+ result = GameRole.FRATER;
+ break;
+ case "hamster":
+ result = GameRole.HAMSTER;
+ break;
+ default:
+ assert false;
+ throw new SAXException("invalid role: " + role);
+ }
+
+ return result;
+ }
+
+ /**
* decode ElemTag.
*
* @param uri URI of namespace
private void resetBefore(){
this.idAvatarMap.clear();
this.content.setLength(0);
+ this.playerList.clear();
this.inLine = false;
return;
}
private void resetAfter(){
this.idAvatarMap.clear();
this.content.setLength(0);
+ this.playerList.clear();
this.nsPfx = null;
this.land = null;
this.period = null;
}
/**
+ * period要素終了の受信。
+ */
+ private void endPeriod(){
+ this.period.setFullOpen(true);
+ return;
+ }
+
+ /**
* talk要素開始の受信。
*
* @param atts 属性
}
/**
+ * playerList要素開始を受信する。
+ *
+ * @param atts 属性
+ */
+ private void startPlayerList(Attributes atts){
+ this.playerList.clear();
+ return;
+ }
+
+ /**
+ * playerList要素終了を受信する。
+ */
+ private void endPlayerList(){
+ this.sysEvent.addPlayerList(this.playerList);
+ this.playerList.clear();
+ return;
+ }
+
+ /**
* SysEvent 開始の受信。
*
* @param type SysEvent種別
case ONSTAGE:
startOnStage(atts);
break;
+ case PLAYERLIST:
+ startPlayerList(atts);
+ break;
default:
break;
}
*/
private void endSysEvent(){
Topic topic;
- if(this.sysEvent.getSysEventType() == SysEventType.ASSAULT){
+ SysEventType eventType = this.sysEvent.getSysEventType();
+ if(eventType == SysEventType.ASSAULT){
endAssault();
topic = this.talk;
}else{
+ switch(eventType){
+ case PLAYERLIST:
+ endPlayerList();
+ break;
+ default:
+ break;
+ }
+
DecodedContent decoded = new DecodedContent(this.content);
this.sysEvent.setContent(decoded);
+
topic = this.sysEvent;
}
this.period.addTopic(topic);
this.content.setLength(0);
+ this.sysEvent = null;
return;
}
}
/**
+ * playerInfo要素開始を受信する。
+ *
+ * @param atts 属性
+ */
+ private void startPlayerInfo(Attributes atts) throws SAXException{
+ String playerId = attrValue(atts, "playerId");
+ String avatarId = attrValue(atts, "avatarId");
+ String survive = attrValue(atts, "survive");
+ String role = attrValue(atts, "role");
+ String uri = attrValue(atts, "uri");
+
+ Avatar avatar = this.idAvatarMap.get(avatarId);
+ GameRole gameRole = decodeRole(role);
+ if(uri == null) uri = "";
+
+ Player player = new Player();
+
+ player.setAvatar(avatar);
+ player.setRole(gameRole);
+ player.setIdName(playerId);
+ player.setUrlText(uri);
+ if("true".equals(survive) || "1".equals(survive)){
+ player.setObitDay(-1);
+ player.setDestiny(Destiny.ALIVE);
+ }
+
+ this.playerList.add(player);
+
+ return;
+ }
+
+ /**
* {@inheritDoc}
*
* @param locator {@inheritDoc}
case LI:
startLi(atts);
break;
+ case PLAYERINFO:
+ startPlayerInfo(atts);
+ break;
default:
break;
}
}
switch(tag){
+ case PERIOD:
+ endPeriod();
+ break;
case TALK:
endTalk();
break;