OSDN Git Service

Merge branch 'release/v4.101.2'
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / data / SysEvent.java
index 4450c95..bae4620 100644 (file)
@@ -12,10 +12,11 @@ import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
+import jp.osdn.jindolf.parser.content.DecodedContent;
 import jp.sourceforge.jindolf.corelib.EventFamily;
 import jp.sourceforge.jindolf.corelib.GameRole;
 import jp.sourceforge.jindolf.corelib.SysEventType;
-import jp.sourceforge.jindolf.parser.DecodedContent;
 
 /**
  * 人狼BBSシステムが生成する各種メッセージ。
@@ -28,11 +29,18 @@ public class SysEvent implements Topic{
     private SysEventType sysEventType;
     private DecodedContent content;
 
-    private final List<Avatar>   avatarList  = new LinkedList<Avatar>();
-    private final List<GameRole> roleList    = new LinkedList<GameRole>();
-    private final List<Integer>  integerList = new LinkedList<Integer>();
+    private final List<Avatar>   avatarList  = new LinkedList<>();
+    private final List<GameRole> roleList    = new LinkedList<>();
+    private final List<Integer>  integerList = new LinkedList<>();
     private final List<CharSequence>  charseqList =
-            new LinkedList<CharSequence>();
+            new LinkedList<>();
+    /** for playerList and onStage. */
+    private final List<Player> playerList = new LinkedList<>();
+    /** for execution. */
+    private final List<Nominated> nominatedList = new LinkedList<>();
+    /** for vote, judge, counting, etc. */
+    private final List<InterPlay> interPlayList = new LinkedList<>();
+
 
     /**
      * コンストラクタ。
@@ -139,6 +147,39 @@ public class SysEvent implements Topic{
     }
 
     /**
+     * Playerリストを返す。
+     *
+     * @return Playerリスト
+     */
+    public List<Player> getPlayerList(){
+        List<Player> result =
+                Collections.unmodifiableList(this.playerList);
+        return result;
+    }
+
+    /**
+     * Nominatedリストを返す。
+     *
+     * @return Nominatedリスト
+     */
+    public List<Nominated> getNominatedList(){
+        List<Nominated> result =
+                Collections.unmodifiableList(this.nominatedList);
+        return result;
+    }
+
+    /**
+     * InterPlayリストを返す。
+     *
+     * @return InterPlayリスト
+     */
+    public List<InterPlay> getInterPlayList(){
+        List<InterPlay> result =
+                Collections.unmodifiableList(this.interPlayList);
+        return result;
+    }
+
+    /**
      * Avatar一覧を追加する。
      * @param list Avatar一覧
      */
@@ -175,6 +216,35 @@ public class SysEvent implements Topic{
     }
 
     /**
+     * Player一覧を追加する。
+     *
+     * @param list Player一覧
+     */
+    public void addPlayerList(List<Player> list){
+        this.playerList.addAll(list);
+        return;
+    }
+
+    /**
+     * Nominated一覧を追加する。
+     *
+     * @param list Nominated一覧
+     */
+    public void addNominatedList(List<Nominated> list){
+        this.nominatedList.addAll(list);
+        return;
+    }
+
+    /**
+     * InterPlay一覧を追加する。
+     * @param list InterPlay一覧
+     */
+    public void addInterPlayList(List<InterPlay> list){
+        this.interPlayList.addAll(list);
+        return;
+    }
+
+    /**
      * システムイベントを解析し、処刑されたAvatarを返す。
      * G国運用中の時点で、処刑者が出るのはCOUNTINGとEXECUTIONのみ。
      * @return 処刑されたAvatar。いなければnull
@@ -182,27 +252,11 @@ public class SysEvent implements Topic{
     public Avatar getExecutedAvatar(){
         Avatar result = null;
 
-        int avatarNum;
-        Avatar lastAvatar;
-
         switch(this.sysEventType){
         case COUNTING:
-            if(this.avatarList.isEmpty()) return null;
-            avatarNum = this.avatarList.size();
-            if(avatarNum % 2 != 0){
-                lastAvatar = this.avatarList.get(avatarNum - 1);
-                result = lastAvatar;
-            }
-            break;
         case EXECUTION:
-            if(this.avatarList.isEmpty()) return null;
-            avatarNum = this.avatarList.size();
-            List<Integer> intList = getIntegerList();
-            int intNum = intList.size();
-            assert intNum > 0;
-            if(avatarNum != intNum || intList.get(intNum - 1) <= 0){
-                lastAvatar = this.avatarList.get(avatarNum - 1);
-                result = lastAvatar;
+            if( ! this.avatarList.isEmpty()){
+                result = this.avatarList.get(0);
             }
             break;
         case COUNTING2:
@@ -223,23 +277,19 @@ public class SysEvent implements Topic{
      */
     public Set<Avatar> getVoterSet(Set<Avatar> set){
         Set<Avatar> result;
-        if(set == null) result = new HashSet<Avatar>();
+        if(set == null) result = new HashSet<>();
         else            result = set;
 
-        if(   this.sysEventType != SysEventType.COUNTING
-           && this.sysEventType != SysEventType.COUNTING2 ){
+        if(    this.sysEventType != SysEventType.COUNTING
+            && this.sysEventType != SysEventType.COUNTING2 ){
             return result;
         }
 
-        int size = this.avatarList.size();
-        assert size >= 2;
-        int limit = size - 1;
-        if(size % 2 != 0) limit--;
+        Set<Avatar> voterSet = this.interPlayList.stream()
+                .map(interPlay -> interPlay.getByWhom())
+                .collect(Collectors.toSet());
 
-        for(int idx = 0; idx <= limit; idx += 2){
-            Avatar avatar = this.avatarList.get(idx);
-            result.add(avatar);
-        }
+        result.addAll(voterSet);
 
         return result;
     }