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 java.util.stream.Collectors;
16 import jp.osdn.jindolf.parser.content.DecodedContent;
17 import jp.sourceforge.jindolf.corelib.EventFamily;
18 import jp.sourceforge.jindolf.corelib.GameRole;
19 import jp.sourceforge.jindolf.corelib.SysEventType;
22 * 人狼BBSシステムが生成する各種メッセージ。
25 public class SysEvent implements Topic{
26 // TODO 狼の襲撃先表示は Talk か SysEvent どちらにしよう...
28 private EventFamily eventFamily;
29 private SysEventType sysEventType;
30 private DecodedContent content;
32 private final List<Avatar> avatarList = new LinkedList<>();
33 private final List<GameRole> roleList = new LinkedList<>();
34 private final List<Integer> integerList = new LinkedList<>();
35 private final List<CharSequence> charseqList =
37 /** for playerList and onStage. */
38 private final List<Player> playerList = new LinkedList<>();
40 private final List<Nominated> nominatedList = new LinkedList<>();
41 /** for vote, judge, counting, etc. */
42 private final List<InterPlay> interPlayList = new LinkedList<>();
57 public EventFamily getEventFamily(){
58 return this.eventFamily;
63 * @param eventFamily イベントファミリ
64 * @throws NullPointerException 引数がnull
66 public void setEventFamily(EventFamily eventFamily)
67 throws NullPointerException{
68 this.eventFamily = eventFamily;
76 public SysEventType getSysEventType(){
77 return this.sysEventType;
83 * @throws NullPointerException 引数がnull
85 public void setSysEventType(SysEventType type)
86 throws NullPointerException{
87 if(type == null) throw new NullPointerException();
88 this.sysEventType = type;
96 public DecodedContent getContent(){
102 * @param content イベントメッセージ
103 * @throws NullPointerException 引数がnull
105 public void setContent(DecodedContent content)
106 throws NullPointerException{
107 if(content == null) throw new NullPointerException();
108 this.content = content;
116 public List<Avatar> getAvatarList(){
117 List<Avatar> result = Collections.unmodifiableList(this.avatarList);
125 public List<GameRole> getRoleList(){
126 List<GameRole> result = Collections.unmodifiableList(this.roleList);
134 public List<Integer> getIntegerList(){
135 List<Integer> result = Collections.unmodifiableList(this.integerList);
140 * CharSequenceリストを取得する。
141 * @return CharSequenceリスト
143 public List<CharSequence> getCharSequenceList(){
144 List<CharSequence> result =
145 Collections.unmodifiableList(this.charseqList);
154 public List<Player> getPlayerList(){
155 List<Player> result =
156 Collections.unmodifiableList(this.playerList);
163 * @return Nominatedリスト
165 public List<Nominated> getNominatedList(){
166 List<Nominated> result =
167 Collections.unmodifiableList(this.nominatedList);
174 * @return InterPlayリスト
176 public List<InterPlay> getInterPlayList(){
177 List<InterPlay> result =
178 Collections.unmodifiableList(this.interPlayList);
184 * @param list Avatar一覧
186 public void addAvatarList(List<Avatar> list){
187 this.avatarList.addAll(list);
195 public void addRoleList(List<GameRole> list){
196 this.roleList.addAll(list);
204 public void addIntegerList(List<Integer> list){
205 this.integerList.addAll(list);
213 public void addCharSequenceList(List<CharSequence> list){
214 this.charseqList.addAll(list);
221 * @param list Player一覧
223 public void addPlayerList(List<Player> list){
224 this.playerList.addAll(list);
231 * @param list Nominated一覧
233 public void addNominatedList(List<Nominated> list){
234 this.nominatedList.addAll(list);
240 * @param list InterPlay一覧
242 public void addInterPlayList(List<InterPlay> list){
243 this.interPlayList.addAll(list);
248 * システムイベントを解析し、処刑されたAvatarを返す。
249 * G国運用中の時点で、処刑者が出るのはCOUNTINGとEXECUTIONのみ。
250 * @return 処刑されたAvatar。いなければnull
252 public Avatar getExecutedAvatar(){
253 Avatar result = null;
255 switch(this.sysEventType){
258 if( ! this.avatarList.isEmpty()){
259 result = this.avatarList.get(0);
273 * 投票に参加したAvatarの集合を返す。
274 * G国運用中の時点で、投票者が出るのはCOUNTINGとCOUNTING2のみ。
275 * @param set 結果格納先。nullなら自動的に確保される。
276 * @return 投票に参加したAvatarのSet
278 public Set<Avatar> getVoterSet(Set<Avatar> set){
280 if(set == null) result = new HashSet<>();
283 if( this.sysEventType != SysEventType.COUNTING
284 && this.sysEventType != SysEventType.COUNTING2 ){
288 Set<Avatar> voterSet = this.interPlayList.stream()
289 .map(interPlay -> interPlay.getByWhom())
290 .collect(Collectors.toSet());
292 result.addAll(voterSet);