using AX.NetworkSystem;
using LinqInternal.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ReportDataMgr
{
    // 车辆信息
    private static List<GameObject> allTrucks = new List<GameObject>();
    // 轻伤员
    private static List<GameObject> allTrappedPerson = new List<GameObject>();
    // 重伤员
    private static List<GameObject> allWoundedPerson = new List<GameObject>();
    // 发送指令
    private static List<ChatTaskMessage> allSendCommand = new List<ChatTaskMessage>();
    // 接收指令
    private static List<ChatTaskMessage> allReceiverCommand = new List<ChatTaskMessage>();
    // 下级ID
    public static List<long> allSubId = new List<long>();
    // 所有车辆总数
    static float totalTruckCount = 0.0f;
    static float waterTankerCount = 0.0f;
    static float foamTruckCount = 0.0f;
    static float aerialTowerTruckCount = 0.0f;
    static float highSprayingTruckCount = 0.0f;
    static float ladderTruckCount = 0.0f;
    static float smokeExhaustTruckCount = 0.0f;
    static float rescueVehicleCount = 0.0f;
    static float apparatusCount = 0.0f;
    static float lightingApplianceCount = 0.0f;
    static float repairCarCount = 0.0f;
    static float forcibleEntryTruckCount = 0.0f;
    // 车上一共多少人
    static int totalFireman = 0;
    // 总共消耗水量
    static float totalUseWater = 0.0f;
    // 营救轻伤员数量
    static float totalSaveTrappedCount = 0.0f;
    // 营救重伤员数量
    static float totalSaveWoundedCount = 0;
    // 发送命令
    static float totalSendCommand = 0;
    // 接收命令
    static int totalReceiverCommand = 0;
    // 是否胜利
    public static bool IsVictory { get; internal set; }
    // 需要问卷数量
    public static int QuestionnaireNumber;
    // 提交问卷数量
    public static int SubmitQuestionnaireNumber;
    // 所有客户端问卷
    public static List<List<Question>> AllQuestionnaire = new List<List<Question>>();
    // 控火得分
    public static Dictionary<string, float> FireScore = new Dictionary<string, float>();
    // 救人得分
    public static Dictionary<string, float> SaveScore = new Dictionary<string, float>();
    // 侦察得分
    public static Dictionary<string, float> LookAtScore = new Dictionary<string, float>();
    // 冷却得分
    public static Dictionary<string, float> CoolScore = new Dictionary<string, float>();
    // 供水得分
    public static Dictionary<string, float> WaterScore = new Dictionary<string, float>();
    // 参演人员得分
    public static Dictionary<string, float> ActInScore = new Dictionary<string, float>();
    // 演练最好的中队投票
    public static Dictionary<string, float> ZhongDuiScore = new Dictionary<string, float>();
    // 演练最好的指挥
    public static Dictionary<string, float> ZhiHuiScore = new Dictionary<string, float>();
    // 优势投票数据
    public static Dictionary<string, float> StrengthScore = new Dictionary<string, float>();
    // 优势投票数据
    public static Dictionary<string, float> WeaknessesScore = new Dictionary<string, float>();
    // 需要车辆投票
    public static Dictionary<string, float> NeedCarScore = new Dictionary<string, float>();
    // 需要灭火装备投票
    public static Dictionary<string, float> NeedFireEquipScore = new Dictionary<string, float>();
    // 需要救人装备投票
    public static Dictionary<string, float> NeedSaveEquipScore = new Dictionary<string, float>();
    // 胜利投票
    public static Dictionary<string, float> VictoryScore = new Dictionary<string, float>();
    // 失败投票
    public static Dictionary<string, float> DefeatScore = new Dictionary<string, float>();
    // 提升投票
    public static Dictionary<string, float> LevelUpScore = new Dictionary<string, float>();
    public static List<ChatTaskMessage> AllChatMessage = new List<ChatTaskMessage>();
    public static void ResertReportDataMgr()
    {
        allTrucks.Clear();
        allTrappedPerson.Clear();
        allWoundedPerson.Clear();
        allSendCommand.Clear();
        allReceiverCommand.Clear();
        allSubId.Clear();
        totalTruckCount = 0.0f;
        waterTankerCount = 0.0f;
        foamTruckCount = 0.0f;
        aerialTowerTruckCount = 0.0f;
        highSprayingTruckCount = 0.0f;
        ladderTruckCount = 0.0f;
        smokeExhaustTruckCount = 0.0f;
        rescueVehicleCount = 0.0f;
        apparatusCount = 0.0f;
        lightingApplianceCount = 0.0f;
        repairCarCount = 0.0f;
        forcibleEntryTruckCount = 0.0f;

        totalFireman = 0;

        totalUseWater = 0.0f;

        totalSaveTrappedCount = 0.0f;

        totalSaveWoundedCount = 0;

        totalSendCommand = 0;

        totalReceiverCommand = 0;
        IsVictory = false;
        QuestionnaireNumber = 0;
        SubmitQuestionnaireNumber = 0;
        AllQuestionnaire.Clear();
        FireScore = new Dictionary<string, float>();

        SaveScore = new Dictionary<string, float>();

        LookAtScore = new Dictionary<string, float>();

        CoolScore = new Dictionary<string, float>();

        WaterScore = new Dictionary<string, float>();

        ActInScore = new Dictionary<string, float>();

        ZhongDuiScore = new Dictionary<string, float>();

        ZhiHuiScore = new Dictionary<string, float>();

        StrengthScore = new Dictionary<string, float>();

        WeaknessesScore = new Dictionary<string, float>();

        NeedCarScore = new Dictionary<string, float>();

        NeedFireEquipScore = new Dictionary<string, float>();

        NeedSaveEquipScore = new Dictionary<string, float>();

        VictoryScore = new Dictionary<string, float>();

        DefeatScore = new Dictionary<string, float>();

        LevelUpScore = new Dictionary<string, float>();

        AllChatMessage = new List<ChatTaskMessage>();
    }
    public static void SetSendCommand(ChatTaskMessage chatTaskMessage)
    {
        //SEND_COMMAND_SYNC
        NetworkManager.Default.SendAsync("SEND_COMMAND_SYNC", chatTaskMessage);
        //totalSendCommand += 1;//TODO 好像是要与车一样,分上下级的
    }
    public static void SetReceiverCommand(ChatTaskMessage chatTaskMessage)
    {
        //RECEIVER_COMMAND_SYNC
        NetworkManager.Default.SendAsync("RECEIVER_COMMAND_SYNC", chatTaskMessage);
        //totalReceiverCommand += 1;
    }
    // 添加发送命令
    public static void AddSendCommand(ChatTaskMessage chatTaskMessage)
    {
        List<long> chatidlist = new List<long>();
        for (int i = 0; i < allSendCommand.Count; i++)
        {
            chatidlist.Add(allSendCommand[i].ID);
        }
        if (!chatidlist.Contains(chatTaskMessage.ID))
        {
            allSendCommand.Add(chatTaskMessage);
        }
    }
    // 添加接收命令
    public static void AddReceiverCommand(ChatTaskMessage chatTaskMessage)
    {
        List<long> chatidlist = new List<long>();
        for (int i = 0; i < allReceiverCommand.Count; i++)
        {
            chatidlist.Add(allReceiverCommand[i].ID);
        }
        if (!chatidlist.Contains(chatTaskMessage.ID))
        {
            allReceiverCommand.Add(chatTaskMessage);
        }
    }
    // 添加车辆信息
    public static void AddTruckObj(GameObject gameObject)
    {
        allTrucks.Add(gameObject);
    }
    // 添加被困人员
    public static void AddTrappedPerson(GameObject gameObject)
    {
        allTrappedPerson.Add(gameObject);
    }
    // 添加重伤员
    public static void AddWoundedPerson(GameObject gameObject)
    {
        allWoundedPerson.Add(gameObject);
    }
    public static void GetDataSource()
    {
        GetAllTruckCount();
        GetAllSaveCount();
        GetAllCommandCount();
        GetActInPersonCount();
    }
    public static void GetAllCommand()
    {
        totalSendCommand = 0;
        totalReceiverCommand = 0;
        GetAllCommandCount();
    }
    // 获取答题人数
    public static void GetActInPersonCount()
    {
        // 获取参演人数
        QuestionnaireNumber = CurrentUserInfo.room.UserList.Count;
        foreach (var item in CurrentUserInfo.room.UserList)
        {
            if (item.Role == Role.总队指挥中心)
            {
                QuestionnaireNumber -= 1;
            }
            if (item.Role == Role.支队指挥中心)
            {
                QuestionnaireNumber -= 1;
            }
        }
    }
    // 获取出车数据字符串
    public static string GetAllTruckCountString()
    {
        string allTruckString = string.Format("共{0}辆。", totalTruckCount);
        //waterTankerCount
        if (waterTankerCount > 0)
        {
            allTruckString += string.Format("水罐消防车{0}辆;", waterTankerCount);
        }
        //foamTruckCount
        if (foamTruckCount > 0)
        {
            allTruckString += string.Format("泡沫消防车{0}辆;", foamTruckCount);
        }
        //aerialTowerTruckCount
        if (aerialTowerTruckCount > 0)
        {
            allTruckString += string.Format("登高平台车{0}辆;", aerialTowerTruckCount);
        }
        //highSprayingTruckCount
        if (highSprayingTruckCount > 0)
        {
            allTruckString += string.Format("高喷消防车{0}辆;", highSprayingTruckCount);
        }
        //ladderTruckCount
        if (ladderTruckCount > 0)
        {
            allTruckString += string.Format("云梯消防车{0}辆;", ladderTruckCount);
        }
        //smokeExhaustTruckCount
        if (smokeExhaustTruckCount > 0)
        {
            allTruckString += string.Format("排烟消防车{0}辆;", smokeExhaustTruckCount);
        }
        //rescueVehicleCount
        if (rescueVehicleCount > 0)
        {
            allTruckString += string.Format("抢险救援车{0}辆;", rescueVehicleCount);
        }
        //apparatusCount
        if (apparatusCount > 0)
        {
            allTruckString += string.Format("器材消防车{0}辆;", apparatusCount);
        }
        //lightingApplianceCount
        if (lightingApplianceCount > 0)
        {
            allTruckString += string.Format("照明消防车{0}辆;", lightingApplianceCount);
        }
        //repairCarCount
        if (repairCarCount > 0)
        {
            allTruckString += string.Format("抢修车{0}辆;", repairCarCount);
        }
        //forcibleEntryTruckCount
        if (forcibleEntryTruckCount > 0)
        {
            allTruckString += string.Format("破拆消防车{0}辆;", forcibleEntryTruckCount);
        }

        return allTruckString;
    }
    // 获取出动人数字符串
    public static string GetAllFiremanCountString()
    {
        return string.Format("{0}人", totalFireman);
    }
    // 获取救助被困人员字符串
    public static string GetAllSaveCountString()
    {
        return string.Format("轻伤员{0}人,重伤员{1}人", totalSaveTrappedCount, totalSaveWoundedCount);
    }
    // 获取用液量字符串
    public static string GetAllUserWaterString()
    {
        return string.Format("灭火用水{0:F}吨。", totalUseWater * 0.001);
    }
    // 获取发送命令字符串
    public static string GetAllSendCommandString()
    {
        return string.Format("{0}条", totalSendCommand);
    }
    // 获取接收命令字符串
    public static string GetAllReceiverCommandString()
    {
        return string.Format("{0}条", totalReceiverCommand);
    }
    // 获取所有命令数量
    private static void GetAllCommandCount()
    {

        // 如果时导调组观察团
        if (CurrentUserInfo.role == Role.导调组 || CurrentUserInfo.role == Role.观察团)
        {
            // 发送命令
            totalSendCommand = allSendCommand.Count;
            // 接收命令
            totalReceiverCommand = allReceiverCommand.Count;
        }
        else
        {
            allSubId = ChatManager.Instance.FindAllSubUserId();
            // 发送命令
            foreach (var item in allSendCommand)
            {
                // 自己发送的命令
                if (item.SenderId == CurrentUserInfo.mySelf.Id)
                {
                    totalSendCommand += 1;
                }
                // 下级发送的命令
                foreach (var id in allSubId)
                {
                    if (item.SenderId == id)
                    {
                        totalSendCommand += 1;
                        break;
                    }
                }
            }
            // 接收命令
            foreach (var item in allReceiverCommand)
            {
                item.ReceiverId = item.Channel.ID - item.SenderId;
                // 自己接收的命令
                if (item.ReceiverId == CurrentUserInfo.mySelf.Id)
                {
                    totalReceiverCommand += 1;
                }
                // 下级接收的命令
                foreach (var id in allSubId)
                {
                    if (item.ReceiverId == id)
                    {
                        totalReceiverCommand += 1;
                        break;
                    }
                }
            }
        }
    }
    // 获取所有车辆数量
    private static void GetAllTruckCount()
    {
        // 如果时导调组观察团
        if (CurrentUserInfo.role == Role.导调组 || CurrentUserInfo.role == Role.观察团)
        {
            //foreach (var item in allTrucks)
            //{
            //    TruckMessage cloneGameObjInfo = item.GetComponent<TruckMessage>();
            //    // 检测是什么车
            //    CheckedTruckData(cloneGameObjInfo);
            //}
            //List<FireCarEngine> allivecar = new List<FireCarEngine>();
            //foreach (var item in ArrivedPowerTotal.arrivedCars.Values)
            //{
            //    foreach (var item1 in item)
            //    {
            //        int num = item1.Value;
            //        for (int i = 0; i < num; i++)
            //        {
            //            allivecar.Add(item1.Key);
            //        }
            //    }
            //}

            Transform allparent = GameObject.Find("P_AllParent").transform.Find("P_Cars");
            TruckMessage[] allcar = allparent.GetComponentsInChildren<TruckMessage>();
            foreach (var item in allcar)
            {
                //TruckMessage cloneGameObjInfo = item.GetComponent<TruckMessage>();
                // 检测是什么车
                CheckedTruckData(item);
            }
        }
        else
        {
            allSubId = ChatManager.Instance.FindAllSubUserId();
            // 查找属于自己的车辆
            foreach (var item in allTrucks)
            {
                TruckMessage cloneGameObjInfo = item.GetComponent<TruckMessage>();
                if (cloneGameObjInfo.UserID == CurrentUserInfo.mySelf.Id)
                {
                    // 检测是什么车
                    CheckedTruckData(cloneGameObjInfo);
                }
                // 查找自己下级的车辆
                foreach (var id in allSubId)
                {
                    // 是下级车辆+1
                    if (cloneGameObjInfo.UserID == id)
                    {
                        CheckedTruckData(cloneGameObjInfo);
                        break;
                    }
                }
            }
        }
    }
    // 获取营救人员数量
    private static void GetAllSaveCount()
    {
        // 如果时导调组观察团
        if (CurrentUserInfo.role == Role.导调组 || CurrentUserInfo.role == Role.观察团)
        {
            // 轻伤员
            //foreach (var item in allTrappedPerson)
            //{
            //    TrappedMoveFree cloneGameObjInfo = item.GetComponent<TrappedMoveFree>();
            //    if (cloneGameObjInfo.SaveFrirmanUserId != 0)
            //    {
            //        totalSaveTrappedCount += 1;
            //    }
            //}
            //// 重伤员
            //foreach (var item in allWoundedPerson)
            //{
            //    WoundedSave cloneGameObjInfo = item.GetComponent<WoundedSave>();
            //    if (cloneGameObjInfo.SaveFrirmanUserId != 0)
            //    {
            //        totalSaveWoundedCount += 1;
            //    }
            //}
            totalSaveTrappedCount = 0;
            totalSaveWoundedCount = 0;
            Transform p_trapped = GameObject.Find("P_AllParent").transform.Find("P_Disasters/P_TrappedPerson");
            Transform p_wound = GameObject.Find("P_AllParent").transform.Find("P_Disasters/P_Wounded");
            for (int i = 0; i < p_trapped.childCount; i++)
            {
                if (p_trapped.GetChild(i).GetComponent<TrappedMoveFree>().OverMoveOrGuidance)
                {
                    totalSaveTrappedCount++;
                }
            }
            for (int i = 0; i < p_wound.childCount; i++)
            {
                if (p_wound.GetChild(i).GetComponent<WoundedSave>().OverMoveOrGuidance)
                {
                    totalSaveWoundedCount++;
                }
            }

        }
        else
        {
            allSubId = ChatManager.Instance.FindAllSubUserId();
            // 自己救的轻伤员
            foreach (var item in allTrappedPerson)
            {
                if (item && item.GetComponent<TrappedMoveFree>()) 
                {
                    TrappedMoveFree cloneGameObjInfo = item.GetComponent<TrappedMoveFree>();
                    if (cloneGameObjInfo.SaveFrirmanUserId == CurrentUserInfo.mySelf.Id&&cloneGameObjInfo.OverMoveOrGuidance)
                    {
                        totalSaveTrappedCount += 1;
                    }
                    // 下级救的人
                    foreach (var id in allSubId)
                    {
                        if (cloneGameObjInfo.SaveFrirmanUserId == id && cloneGameObjInfo.OverMoveOrGuidance)
                        {
                            totalSaveTrappedCount += 1;
                            break;
                        }
                    }
                }
                
            }
            // 自己救的重伤员
            foreach (var item in allWoundedPerson)
            {
                if (item&&item.GetComponent<WoundedSave>()) 
                {
                    WoundedSave cloneGameObjInfo = item.GetComponent<WoundedSave>();
                    if (cloneGameObjInfo.SaveFrirmanUserId == CurrentUserInfo.mySelf.Id&& cloneGameObjInfo.OverMoveOrGuidance)
                    {
                        totalSaveWoundedCount += 1;
                    }
                    // 下级救的人
                    foreach (var id in allSubId)
                    {
                        if (cloneGameObjInfo.SaveFrirmanUserId == id && cloneGameObjInfo.OverMoveOrGuidance)
                        {
                            totalSaveWoundedCount += 1;
                            break;
                        }
                    }
                }
               
            }
        }
    }
    // 检测是什么车
    private static void CheckedTruckData(TruckMessage truckMessage)
    {
        // 总共多少人
        totalFireman += (int)truckMessage.MyCarMessage.PassengerCapacity;
        totalTruckCount += 1;
        switch (truckMessage.gameObjType)
        {
            case CloneObjType.WaterTanker:
                waterTankerCount += 1;
                // 用水量
                totalUseWater += truckMessage.GetComponent<WaterSource>().AllUserWater;
                break;
            case CloneObjType.FoamTruck:
                foamTruckCount += 1;
                // 用水量
                totalUseWater += truckMessage.GetComponent<WaterSource>().AllUserWater;
                break;
            case CloneObjType.AerialTowerTruck:
                aerialTowerTruckCount += 1;
                break;
            case CloneObjType.HighSprayingTruck:
                highSprayingTruckCount += 1;
                break;
            case CloneObjType.LadderTruck:
                ladderTruckCount += 1;
                break;
            case CloneObjType.SmokeExhaustTruck:
                smokeExhaustTruckCount += 1;
                break;
            case CloneObjType.RescueVehicle:
                rescueVehicleCount += 1;
                break;
            case CloneObjType.Apparatus:
                apparatusCount += 1;
                break;
            case CloneObjType.LightingAppliance:
                lightingApplianceCount += 1;
                break;
            case CloneObjType.RepairCar:
                repairCarCount += 1;
                break;
            case CloneObjType.ForcibleEntryTruck:
                forcibleEntryTruckCount += 1;
                break;
        }
    }
    // 清空数据
    public static void Clear()
    {
        allTrucks.Clear();
        allTrappedPerson.Clear();
        allSubId.Clear();
        totalTruckCount = 0;
        waterTankerCount = 0;
        foamTruckCount = 0;
        aerialTowerTruckCount = 0;
        highSprayingTruckCount = 0;
        ladderTruckCount = 0;
        smokeExhaustTruckCount = 0;
        rescueVehicleCount = 0;
        apparatusCount = 0;
        lightingApplianceCount = 0;
        repairCarCount = 0;
        forcibleEntryTruckCount = 0;
        totalFireman = 0;
        totalUseWater = 0;
        totalSaveTrappedCount = 0;
        totalSaveWoundedCount = 0;
        totalSendCommand = 0;
        totalReceiverCommand = 0;
    }
    // 获取所有得分
    public static void GetAllScoure()
    {
        foreach (var item in AllQuestionnaire)
        {
            // 中队分数初始化
            ZhongDuiScoreInit(item[0]);
            // 指挥分数初始化
            ZhiHuiScoreInit(item[1]);
            // 参演人员分数初始化
            ActInScoreInit(item[2]);
            // 劣势数据初始化
            WeaknessesScoreInit(item[3]);
            // 优势数据初始化
            StrengthScoreInit(item[4]);
            if (IsVictory)
            {
                // 胜利
                VictoryScoreInit(item[5]);
            }
            else
            {
                // 失败
                DefeatScoreInit(item[5]);
            }
            // 需要车辆
            NeedCarScoreInit(item[6]);
            // 需要装备
            NeedFireEquipScoreInit(item[7]);
            // 需要装备
            NeedSaveEquipScoreInit(item[8]);
            // 控火得分初始化
            FireScoreInit(item[9]);
            // 救人得分初始化
            SaveScoreInit(item[10]);
            // 救人得分初始化
            LookAtScoreInit(item[11]);
            // 救人得分初始化
            CoolScoreInit(item[12]);
            // 救人得分初始化
            WaterScoreInit(item[13]);
            // 提升分数提升
            LevelUpScoreInit(item[14]);
        }
    }
    // 提升统计初始化
    private static void LevelUpScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!LevelUpScore.ContainsKey(item.Key))
            {
                LevelUpScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                LevelUpScore[item.Key] += 1;
            }
        }
    }
    // 失败统计初始化
    private static void DefeatScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!DefeatScore.ContainsKey(item.Key))
            {
                DefeatScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                DefeatScore[item.Key] += 1;
            }
        }
    }
    // 胜利统计初始化
    private static void VictoryScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!VictoryScore.ContainsKey(item.Key))
            {
                VictoryScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                VictoryScore[item.Key] += 1;
            }
        }
    }
    // 需要救援装备统计
    private static void NeedSaveEquipScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!NeedSaveEquipScore.ContainsKey(item.Key))
            {
                NeedSaveEquipScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                NeedSaveEquipScore[item.Key] += 1;
            }
        }
    }
    // 需要灭火装备统计
    private static void NeedFireEquipScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!NeedFireEquipScore.ContainsKey(item.Key))
            {
                NeedFireEquipScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                NeedFireEquipScore[item.Key] += 1;
            }
        }
    }
    // 需要车辆统计
    private static void NeedCarScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!NeedCarScore.ContainsKey(item.Key))
            {
                NeedCarScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                NeedCarScore[item.Key] += 1;
            }
        }
    }
    // 短板统计
    private static void WeaknessesScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!WeaknessesScore.ContainsKey(item.Key))
            {
                WeaknessesScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                WeaknessesScore[item.Key] += 1;
            }
        }
    }
    // 优势统计
    private static void StrengthScoreInit(Question question)
    {
        foreach (var item in question.SelectionResult)
        {
            if (!StrengthScore.ContainsKey(item.Key))
            {
                StrengthScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                StrengthScore[item.Key] += 1;
            }
        }
    }

    // 初始化供水得分
    private static void WaterScoreInit(Question question)
    {
        foreach (var score in question.ScoreResult)
        {
            if (!WaterScore.ContainsKey(score.Key))
            {
                WaterScore.Add(score.Key, 0);
            }
            WaterScore[score.Key] += score.Value;
        }
    }
    // 初始化冷却得分
    private static void CoolScoreInit(Question question)
    {
        foreach (var score in question.ScoreResult)
        {
            if (!CoolScore.ContainsKey(score.Key))
            {
                CoolScore.Add(score.Key, 0);
            }
            CoolScore[score.Key] += score.Value;
        }
    }
    // 初始化侦察得分
    private static void LookAtScoreInit(Question question)
    {
        foreach (var score in question.ScoreResult)
        {
            if (!LookAtScore.ContainsKey(score.Key))
            {
                LookAtScore.Add(score.Key, 0);
            }
            LookAtScore[score.Key] += score.Value;
        }
    }
    // 初始化救人得分
    private static void SaveScoreInit(Question question)
    {
        foreach (var score in question.ScoreResult)
        {
            if (!SaveScore.ContainsKey(score.Key))
            {
                SaveScore.Add(score.Key, 0);
            }
            SaveScore[score.Key] += score.Value;
        }
    }
    // 初始化控火得分
    private static void FireScoreInit(Question question)
    {
        foreach (var score in question.ScoreResult)
        {
            if (!FireScore.ContainsKey(score.Key))
            {
                FireScore.Add(score.Key, 0);
            }
            FireScore[score.Key] += score.Value;
        }
    }

    // 参演人员得分初始化
    private static void ActInScoreInit(Question question)
    {
        for (int i = 0; i < question.Content.Count; i++)
        {
            string itemName = question.Content[i];
            int itemScore = question.ScoreResult[itemName];
            if (!ActInScore.ContainsKey(itemName))
            {
                ActInScore.Add(itemName, 0);
            }
            ActInScore[itemName] += itemScore;
        }
    }
    // 初始化中队分数
    private static void ZhongDuiScoreInit(Question question)
    {
        // 计算投票数
        foreach (var item in question.SelectionResult)
        {
            if (!ZhongDuiScore.ContainsKey(item.Key))
            {
                ZhongDuiScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                ZhongDuiScore[item.Key] += 1;
            }
        }
    }

    // 初始化中队分数
    private static void ZhiHuiScoreInit(Question question)
    {
        // 计算投票数
        foreach (var item in question.SelectionResult)
        {
            if (!ZhiHuiScore.ContainsKey(item.Key))
            {
                ZhiHuiScore.Add(item.Key, 0);
            }
            if (item.Value)
            {
                ZhiHuiScore[item.Key] += 1;
            }
        }
    }
    // 获取表现最好的指挥
    public static string GetZhiHuiBest()
    {
        ReportDataMgr.GetActInPersonCount();
        // 计算最高票数
        float max = ZhiHuiScore.Max(i => i.Value);
        string name = ZhiHuiScore.Find(i => i.Value == max).Key;
        float score = (ActInScore.Find(i => i.Key == name).Value) / QuestionnaireNumber;
        return string.Format("<color=#ff0000>{0}</color>被大家评选为本场最佳指挥员,他得到了<color=#ff0000>{1:0.0}</color>分的高分。", name, score);
    }
    // 获取表现最好的中队
    public static string GetZhongDuiBest()
    {
        // 计算最高票数
        float max = ZhongDuiScore.Max(i => i.Value);
        string name = ZhongDuiScore.Find(i => i.Value == max).Key;
        return string.Format("本次演练表现最好的中队是<color=#ff0000>{0}</color>。", name);
    }
    // 获取总分平均分TODO  还需要除以中队个数
    public static float GetTotalScore()
    {
        float fireScore = GetFireScore();
        float saveScore = GetSaveScore();
        float lookAtScore = GetLookAtScore();
        float coolScore = GetCoolScore();
        float waterScore = GetWaterScore();
        return (fireScore + saveScore + lookAtScore + coolScore + waterScore) / 5;
    }
    // 获取灭火平均分
    public static float GetFireScore()
    {
        ReportDataMgr.GetActInPersonCount();
        float score = 0;
        foreach (var item in FireScore)
        {
            score += item.Value;
        }
        return score / QuestionnaireNumber / ZhongDuiScore.Count;
    }
    // 获取救人平均分
    public static float GetSaveScore()
    {
        ReportDataMgr.GetActInPersonCount();
        float score = 0;
        foreach (var item in SaveScore)
        {
            score += item.Value;
        }
        return score / QuestionnaireNumber / ZhongDuiScore.Count;
    }
    // 获取侦察平均分
    public static float GetLookAtScore()
    {
        ReportDataMgr.GetActInPersonCount();
        float score = 0;
        foreach (var item in LookAtScore)
        {
            score += item.Value;
        }
        return score / QuestionnaireNumber / ZhongDuiScore.Count;
    }
    // 获取冷却平均分
    public static float GetCoolScore()
    {
        ReportDataMgr.GetActInPersonCount();
        float score = 0;
        foreach (var item in CoolScore)
        {
            score += item.Value;
        }
        return score / QuestionnaireNumber / ZhongDuiScore.Count;
    }
    // 获取供水平均分
    public static float GetWaterScore()
    {
        ReportDataMgr.GetActInPersonCount();
        float score = 0;
        foreach (var item in WaterScore)
        {
            score += item.Value;
        }
        return score / QuestionnaireNumber / ZhongDuiScore.Count;
    }
    // 获取表现最好的环节
    public static string GetHuanJieBest()
    {
        float fireScore = GetFireScore();
        float saveScore = GetSaveScore();
        float lookAtScore = GetLookAtScore();
        float coolScore = GetCoolScore();
        float waterScore = GetWaterScore();
        float[] temp = new float[] { fireScore, saveScore, lookAtScore, coolScore, waterScore };
        var max = temp.Max();
        string name = "";
        if (max == fireScore)
        {
            name = "控火";
        }
        else if (max == saveScore)
        {
            name = "救人";
        }
        else if (max == lookAtScore)
        {
            name = "侦察";
        }
        else if (max == coolScore)
        {
            name = "冷却";
        }
        else
        {
            name = "供水";
        }
        return string.Format("本次演练表现最出色的是<color=#ff0000>{0}</color>环节,获得了<color=#ff0000>{1:0.0}</color>分。", name, max);
    }
    // 获取表现最差的环节
    public static string GetHuanJieBad()
    {
        float fireScore = GetFireScore();
        float saveScore = GetSaveScore();
        float lookAtScore = GetLookAtScore();
        float coolScore = GetCoolScore();
        float waterScore = GetWaterScore();
        float[] temp = new float[] { fireScore, saveScore, lookAtScore, coolScore, waterScore };
        var min = temp.Min();
        string name = "";
        if (min == fireScore)
        {
            name = "控火";
        }
        else if (min == saveScore)
        {
            name = "救人";
        }
        else if (min == lookAtScore)
        {
            name = "侦察";
        }
        else if (min == coolScore)
        {
            name = "冷却";
        }
        else
        {
            name = "供水";
        }
        return string.Format("本次演练表现最差的是<color=#ff0000>{0}</color>环节,获得了<color=#ff0000>{1:0.0}</color>分。", name, min);
    }
    // 控火环节表现最好的中队
    public static string GetFireScoreBest()
    {
        var max = FireScore.Max(i => i.Value);
        var item = FireScore.Find(i => i.Value == max);
        return string.Format("<color=#ff0000>{0}</color>在<color=#ff0000>控火</color>环节表现最为出色;", item.Key);
    }
    // 救人环节表现最好的中队
    public static string GetSaveScoreBest()
    {
        var max = SaveScore.Max(i => i.Value);
        var item = SaveScore.Find(i => i.Value == max);
        return string.Format("<color=#ff0000>{0}</color>在<color=#ff0000>救人</color>环节表现最为出色;", item.Key);
    }
    // 侦察环节表现最好的中队
    public static string GetLookAtScoreBest()
    {
        var max = LookAtScore.Max(i => i.Value);
        var item = LookAtScore.Find(i => i.Value == max);
        return string.Format("<color=#ff0000>{0}</color>在<color=#ff0000>侦察</color>环节表现最为出色;", item.Key);
    }
    // 冷却环节表现最好的中队
    public static string GetCoolScoreBest()
    {
        var max = CoolScore.Max(i => i.Value);
        var item = CoolScore.Find(i => i.Value == max);
        return string.Format("<color=#ff0000>{0}</color>在<color=#ff0000>冷却</color>环节表现最为出色;", item.Key);
    }
    // 供水环节表现最好的中队
    public static string GetWaterScoreBest()
    {
        var max = WaterScore.Max(i => i.Value);
        var item = WaterScore.Find(i => i.Value == max);
        return string.Format("<color=#ff0000>{0}</color>在<color=#ff0000>供水</color>环节表现最为出色;", item.Key);
    }
    // 优势
    public static string GetStrengthScore()
    {
        var max = StrengthScore.Max(i => i.Value);
        var item = StrengthScore.Find(i => i.Value == max);
        return string.Format("通过本次演练,队伍最大的优势是<color=#ff0000>{0}</color>。", item.Key);
    }
    // 劣势
    public static string GetWeaknessesScore()
    {
        var max = WeaknessesScore.Max(i => i.Value);
        var item = WeaknessesScore.Find(i => i.Value == max);
        return string.Format("通过本次演练,队伍最大的短板是<color=#ff0000>{0}</color>。", item.Key);
    }
    // 急需装备
    public static string GetNeedScore()
    {
        // 急需车辆
        var max1 = NeedCarScore.Max(i => i.Value);
        var item1 = NeedCarScore.Find(i => i.Value == max1);
        // 急需灭火装备
        var max2 = NeedFireEquipScore.Max(i => i.Value);
        var item2 = NeedFireEquipScore.Find(i => i.Value == max2);
        // 急需救援装备
        var max3 = NeedSaveEquipScore.Max(i => i.Value);
        var item3 = NeedSaveEquipScore.Find(i => i.Value == max3);
        return string.Format("通过本次演练,急需的车辆/装备是<color=#ff0000>{0}</color>、<color=#ff0000>{1}</color>、<color=#ff0000>{2}</color>。", item1.Key, item2.Key, item3.Key);
    }
    // 胜利失败
    public static string GetWinOrLostScore()
    {
        if (IsVictory)
        {
            var max = VictoryScore.Max(i => i.Value);
            var item = VictoryScore.Find(i => i.Value == max);
            return string.Format("本次演练胜利的最大原因是<color=#ff0000>{0}</color>。", item.Key);
        }
        else
        {
            var max = DefeatScore.Max(i => i.Value);
            var item = DefeatScore.Find(i => i.Value == max);
            return string.Format("本次演练失败的最大原因是<color=#ff0000>{0}</color>。", item.Key);
        }
    }
    // 改进建议
    public static string GetLevelUpScore()
    {
        var max1 = LevelUpScore.Max(i => i.Value);
        var item1 = LevelUpScore.Find(i => i.Value == max1);
        LevelUpScore.Remove(item1.Key);
        var max2 = LevelUpScore.Max(i => i.Value);
        var item2 = LevelUpScore.Find(i => i.Value == max2);
        LevelUpScore.Remove(item2.Key);
        var max3 = LevelUpScore.Max(i => i.Value);
        var item3 = LevelUpScore.Find(i => i.Value == max3);
        if (max2 == 0)
        {
            return string.Format("参演人员认为,应当通过以下途径提升队伍战力:①{0}(<color=#ff0000>{1}</color>)。", item1.Key, item1.Value);
        }
        else if (max3 == 0)
        {
            return string.Format("参演人员认为,应当通过以下途径提升队伍战力:①{0}(<color=#ff0000>{1}</color>)②{2}(<color=#ff0000>{3}</color>)。", item1.Key, item1.Value, item2.Key, item2.Value);
        }
        else
        {
            return string.Format("参演人员认为,应当通过以下途径提升队伍战力:①{0}(<color=#ff0000>{1}</color>)②{2}(<color=#ff0000>{3}</color>)③{4}(<color=#ff0000>{5}</color>)。", item1.Key, item1.Value, item2.Key, item2.Value, item3.Key, item3.Value);
        }
    }
    /// <summary>
    /// 本客户端发送命令数量统计
    /// </summary>
    /// <returns></returns>
    private static List<ChatMessage> GetSendMsg()
    {
        List<ChatMessage> sendchatlist = new List<ChatMessage>();
        for (int i = 0; i < ReportDataMgr.AllChatMessage.Count; i++)
        {
            if (ReportDataMgr.AllChatMessage[i].SenderId == CurrentUserInfo.mySelf.Id)
            {//当前客户端发送的
             // if (ChatManager.Instance.FindDirectionSubUserDataID().Contains(ReportDataMgr.AllChatMessage[i].ReceiverId)) 
                {//直接下级为接收方
                    sendchatlist.Add(ReportDataMgr.AllChatMessage[i]);
                }
            }
        }
        return sendchatlist;
    }
    /// <summary>
    /// 本客户端接受命令统计
    /// </summary>
    /// <returns></returns>
    private static List<ChatMessage> GetReceiveMsg()
    {
        List<ChatMessage> receivechatlist = new List<ChatMessage>();
        for (int i = 0; i < ReportDataMgr.AllChatMessage.Count; i++)
        {
            if (!(CurrentUserInfo.role == Role.导调组 || CurrentUserInfo.role == Role.观察团))
            {
                if (ReportDataMgr.AllChatMessage[i].ReceiverId == CurrentUserInfo.mySelf.Id)
                {
                    receivechatlist.Add(ReportDataMgr.AllChatMessage[i]);
                }
            }
            else
            {
                receivechatlist.Add(ReportDataMgr.AllChatMessage[i]);
            }

        }
        return receivechatlist;
    }
    public static string GetReceiveMsgCount()
    {
        return string.Format("{0}条", GetReceiveMsg().Count);
    }
    public static string GetSendMsgCount()
    {
        return string.Format("{0}条", GetSendMsg().Count);
    }
}