OSDN Git Service

start 4.101.7-SNAPSHOT
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / data / SysEvent.java
1 /*
2  * system event in game
3  *
4  * License : The MIT License
5  * Copyright(c) 2008 olyutorskii
6  */
7
8 package jp.sfjp.jindolf.data;
9
10 import java.util.Collections;
11 import java.util.HashSet;
12 import java.util.LinkedList;
13 import java.util.List;
14 import java.util.Set;
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;
20
21 /**
22  * 人狼BBSシステムが生成する各種メッセージ。
23  * Topicの具体化。
24  */
25 public class SysEvent implements Topic{
26     // TODO 狼の襲撃先表示は Talk か SysEvent どちらにしよう...
27
28     private EventFamily eventFamily;
29     private SysEventType sysEventType;
30     private DecodedContent content;
31
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 =
36             new LinkedList<>();
37     /** for playerList and onStage. */
38     private final List<Player> playerList = new LinkedList<>();
39     /** for execution. */
40     private final List<Nominated> nominatedList = new LinkedList<>();
41     /** for vote, judge, counting, etc. */
42     private final List<InterPlay> interPlayList = new LinkedList<>();
43
44
45     /**
46      * コンストラクタ。
47      */
48     public SysEvent(){
49         super();
50         return;
51     }
52
53     /**
54      * イベントファミリを取得する。
55      * @return イベントファミリ
56      */
57     public EventFamily getEventFamily(){
58         return this.eventFamily;
59     }
60
61     /**
62      * イベントファミリを設定する。
63      * @param eventFamily イベントファミリ
64      * @throws NullPointerException 引数がnull
65      */
66     public void setEventFamily(EventFamily eventFamily)
67             throws NullPointerException{
68         this.eventFamily = eventFamily;
69         return;
70     }
71
72     /**
73      * イベント種別を取得する。
74      * @return イベント種別
75      */
76     public SysEventType getSysEventType(){
77         return this.sysEventType;
78     }
79
80     /**
81      * イベント種別を設定する。
82      * @param type イベント種別
83      * @throws NullPointerException 引数がnull
84      */
85     public void setSysEventType(SysEventType type)
86             throws NullPointerException{
87         if(type == null) throw new NullPointerException();
88         this.sysEventType = type;
89         return;
90     }
91
92     /**
93      * イベントメッセージを取得する。
94      * @return イベントメッセージ
95      */
96     public DecodedContent getContent(){
97         return this.content;
98     }
99
100     /**
101      * イベントメッセージを設定する。
102      * @param content イベントメッセージ
103      * @throws NullPointerException 引数がnull
104      */
105     public void setContent(DecodedContent content)
106             throws NullPointerException{
107         if(content == null) throw new NullPointerException();
108         this.content = content;
109         return;
110     }
111
112     /**
113      * Avatarリストを取得する。
114      * @return Avatarリスト
115      */
116     public List<Avatar> getAvatarList(){
117         List<Avatar> result = Collections.unmodifiableList(this.avatarList);
118         return result;
119     }
120
121     /**
122      * Roleリストを取得する。
123      * @return Roleリスト
124      */
125     public List<GameRole> getRoleList(){
126         List<GameRole> result = Collections.unmodifiableList(this.roleList);
127         return result;
128     }
129
130     /**
131      * Integerリストを取得する。
132      * @return Integerリスト
133      */
134     public List<Integer> getIntegerList(){
135         List<Integer> result = Collections.unmodifiableList(this.integerList);
136         return result;
137     }
138
139     /**
140      * CharSequenceリストを取得する。
141      * @return CharSequenceリスト
142      */
143     public List<CharSequence> getCharSequenceList(){
144         List<CharSequence> result =
145                 Collections.unmodifiableList(this.charseqList);
146         return result;
147     }
148
149     /**
150      * Playerリストを返す。
151      *
152      * @return Playerリスト
153      */
154     public List<Player> getPlayerList(){
155         List<Player> result =
156                 Collections.unmodifiableList(this.playerList);
157         return result;
158     }
159
160     /**
161      * Nominatedリストを返す。
162      *
163      * @return Nominatedリスト
164      */
165     public List<Nominated> getNominatedList(){
166         List<Nominated> result =
167                 Collections.unmodifiableList(this.nominatedList);
168         return result;
169     }
170
171     /**
172      * InterPlayリストを返す。
173      *
174      * @return InterPlayリスト
175      */
176     public List<InterPlay> getInterPlayList(){
177         List<InterPlay> result =
178                 Collections.unmodifiableList(this.interPlayList);
179         return result;
180     }
181
182     /**
183      * Avatar一覧を追加する。
184      * @param list Avatar一覧
185      */
186     public void addAvatarList(List<Avatar> list){
187         this.avatarList.addAll(list);
188         return;
189     }
190
191     /**
192      * 役職一覧を追加する。
193      * @param list 役職一覧
194      */
195     public void addRoleList(List<GameRole> list){
196         this.roleList.addAll(list);
197         return;
198     }
199
200     /**
201      * 数値一覧を追加する。
202      * @param list 数値一覧
203      */
204     public void addIntegerList(List<Integer> list){
205         this.integerList.addAll(list);
206         return;
207     }
208
209     /**
210      * 文字列一覧を追加する。
211      * @param list 文字列一覧
212      */
213     public void addCharSequenceList(List<CharSequence> list){
214         this.charseqList.addAll(list);
215         return;
216     }
217
218     /**
219      * Player一覧を追加する。
220      *
221      * @param list Player一覧
222      */
223     public void addPlayerList(List<Player> list){
224         this.playerList.addAll(list);
225         return;
226     }
227
228     /**
229      * Nominated一覧を追加する。
230      *
231      * @param list Nominated一覧
232      */
233     public void addNominatedList(List<Nominated> list){
234         this.nominatedList.addAll(list);
235         return;
236     }
237
238     /**
239      * InterPlay一覧を追加する。
240      * @param list InterPlay一覧
241      */
242     public void addInterPlayList(List<InterPlay> list){
243         this.interPlayList.addAll(list);
244         return;
245     }
246
247     /**
248      * システムイベントを解析し、処刑されたAvatarを返す。
249      * G国運用中の時点で、処刑者が出るのはCOUNTINGとEXECUTIONのみ。
250      * @return 処刑されたAvatar。いなければnull
251      */
252     public Avatar getExecutedAvatar(){
253         Avatar result = null;
254
255         switch(this.sysEventType){
256         case COUNTING:
257         case EXECUTION:
258             if( ! this.avatarList.isEmpty()){
259                 result = this.avatarList.get(0);
260             }
261             break;
262         case COUNTING2:
263             // NOTHING
264             break;
265         default:
266             break;
267         }
268
269         return result;
270     }
271
272     /**
273      * 投票に参加したAvatarの集合を返す。
274      * G国運用中の時点で、投票者が出るのはCOUNTINGとCOUNTING2のみ。
275      * @param set 結果格納先。nullなら自動的に確保される。
276      * @return 投票に参加したAvatarのSet
277      */
278     public Set<Avatar> getVoterSet(Set<Avatar> set){
279         Set<Avatar> result;
280         if(set == null) result = new HashSet<>();
281         else            result = set;
282
283         if(    this.sysEventType != SysEventType.COUNTING
284             && this.sysEventType != SysEventType.COUNTING2 ){
285             return result;
286         }
287
288         Set<Avatar> voterSet = this.interPlayList.stream()
289                 .map(interPlay -> interPlay.getByWhom())
290                 .collect(Collectors.toSet());
291
292         result.addAll(voterSet);
293
294         return result;
295     }
296
297 }