4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.data;
10 import java.util.Collections;
11 import java.util.HashSet;
12 import java.util.LinkedList;
13 import java.util.List;
15 import jp.sourceforge.jindolf.corelib.EventFamily;
16 import jp.sourceforge.jindolf.corelib.GameRole;
17 import jp.sourceforge.jindolf.corelib.SysEventType;
18 import jp.sourceforge.jindolf.parser.DecodedContent;
21 * 人狼BBSシステムが生成する各種メッセージ。
24 public class SysEvent implements Topic{
25 // TODO 狼の襲撃先表示は Talk か SysEvent どちらにしよう...
27 private EventFamily eventFamily;
28 private SysEventType sysEventType;
29 private DecodedContent content;
31 private final List<Avatar> avatarList = new LinkedList<>();
32 private final List<GameRole> roleList = new LinkedList<>();
33 private final List<Integer> integerList = new LinkedList<>();
34 private final List<CharSequence> charseqList =
49 public EventFamily getEventFamily(){
50 return this.eventFamily;
55 * @param eventFamily イベントファミリ
56 * @throws NullPointerException 引数がnull
58 public void setEventFamily(EventFamily eventFamily)
59 throws NullPointerException{
60 this.eventFamily = eventFamily;
68 public SysEventType getSysEventType(){
69 return this.sysEventType;
75 * @throws NullPointerException 引数がnull
77 public void setSysEventType(SysEventType type)
78 throws NullPointerException{
79 if(type == null) throw new NullPointerException();
80 this.sysEventType = type;
88 public DecodedContent getContent(){
94 * @param content イベントメッセージ
95 * @throws NullPointerException 引数がnull
97 public void setContent(DecodedContent content)
98 throws NullPointerException{
99 if(content == null) throw new NullPointerException();
100 this.content = content;
108 public List<Avatar> getAvatarList(){
109 List<Avatar> result = Collections.unmodifiableList(this.avatarList);
117 public List<GameRole> getRoleList(){
118 List<GameRole> result = Collections.unmodifiableList(this.roleList);
126 public List<Integer> getIntegerList(){
127 List<Integer> result = Collections.unmodifiableList(this.integerList);
132 * CharSequenceリストを取得する。
133 * @return CharSequenceリスト
135 public List<CharSequence> getCharSequenceList(){
136 List<CharSequence> result =
137 Collections.unmodifiableList(this.charseqList);
143 * @param list Avatar一覧
145 public void addAvatarList(List<Avatar> list){
146 this.avatarList.addAll(list);
154 public void addRoleList(List<GameRole> list){
155 this.roleList.addAll(list);
163 public void addIntegerList(List<Integer> list){
164 this.integerList.addAll(list);
172 public void addCharSequenceList(List<CharSequence> list){
173 this.charseqList.addAll(list);
178 * システムイベントを解析し、処刑されたAvatarを返す。
179 * G国運用中の時点で、処刑者が出るのはCOUNTINGとEXECUTIONのみ。
180 * @return 処刑されたAvatar。いなければnull
182 public Avatar getExecutedAvatar(){
183 Avatar result = null;
188 switch(this.sysEventType){
190 if(this.avatarList.isEmpty()) return null;
191 avatarNum = this.avatarList.size();
192 if(avatarNum % 2 != 0){
193 lastAvatar = this.avatarList.get(avatarNum - 1);
198 if(this.avatarList.isEmpty()) return null;
199 avatarNum = this.avatarList.size();
200 List<Integer> intList = getIntegerList();
201 int intNum = intList.size();
203 if(avatarNum != intNum || intList.get(intNum - 1) <= 0){
204 lastAvatar = this.avatarList.get(avatarNum - 1);
219 * 投票に参加したAvatarの集合を返す。
220 * G国運用中の時点で、投票者が出るのはCOUNTINGとCOUNTING2のみ。
221 * @param set 結果格納先。nullなら自動的に確保される。
222 * @return 投票に参加したAvatarのSet
224 public Set<Avatar> getVoterSet(Set<Avatar> set){
226 if(set == null) result = new HashSet<>();
229 if( this.sysEventType != SysEventType.COUNTING
230 && this.sysEventType != SysEventType.COUNTING2 ){
234 int size = this.avatarList.size();
236 int limit = size - 1;
237 if(size % 2 != 0) limit--;
239 for(int idx = 0; idx <= limit; idx += 2){
240 Avatar avatar = this.avatarList.get(idx);