Exemplo n.º 1
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message == "/当前联赛")
     {
         ICocCoreClans war      = BaseData.Instance.container.Resolve <ICocCoreClans>();
         var           keypairs = BaseData.valuePairs(configType.部落冲突);
         if (keypairs.ContainsKey(chat.FromGroup.ToString()))
         {
             LeagueWar league = war.GetCurrentWarLeague(keypairs[chat.FromGroup.ToString()]);
             if (league != null && string.IsNullOrEmpty(league.Reason))
             {
                 StringBuilder sb = new StringBuilder();
                 Array.Reverse(league.Rounds);
                 IMessageBase[] result = null;
                 Parallel.ForEach(league.Rounds, (rounds) =>
                 {
                     foreach (var warTag in rounds.warTags)
                     {
                         if (warTag != "#0")
                         {
                             if (result != null)
                             {
                                 return;
                             }
                             var roundData = war.GetCurrentWarLeagueRound(warTag);
                             if (result != null)
                             {
                                 return;
                             }
                             Logger.Instance.AddLog(LogType.Debug, "联赛部落" + roundData.clan.Name + " vs " + roundData.opponent.Name);
                             if (roundData.clan.Tag == keypairs[chat.FromGroup.ToString()].ToUpper())
                             {
                                 if (roundData.state == "inWar")
                                 {
                                     sb.AppendLine("当前联赛结束时间为: " + roundData.EndTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.opponent.Name);
                                     sb.AppendLine("当前我方战星: " + roundData.clan.Stars + ", 敌方战星: " + roundData.opponent.Stars);
                                     sb.AppendLine("========================");
                                     foreach (var Member in roundData.clan.Members.OrderBy(x => x.MapPosition))
                                     {
                                         if (Member.Attacks == null || Member.Attacks.Length < 1)
                                         {
                                             sb.AppendLine(Member.Name + " : 还未进攻");
                                         }
                                         else
                                         {
                                             sb.AppendLine(Member.Name + " : " + Member.Attacks[0].Stars + "星(摧毁: " + Member.Attacks[0].DestructionPercentage + "%)");
                                         }
                                     }
                                     result = new IMessageBase[] { BaseData.TextToImg(sb.ToString(), chat.Session) };
                                 }
                             }
                             else if (roundData.opponent.Tag == keypairs[chat.FromGroup.ToString()].ToUpper())
                             {
                                 if (roundData.state == "inWar")
                                 {
                                     sb.AppendLine("当前联赛结束时间为: " + roundData.EndTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.clan.Name);
                                     sb.AppendLine("当前我方战星: " + roundData.opponent.Stars + ", 敌方战星: " + roundData.clan.Stars);
                                     foreach (var Member in roundData.opponent.Members.OrderBy(x => x.MapPosition))
                                     {
                                         if (Member.Attacks == null || Member.Attacks.Length < 1)
                                         {
                                             sb.AppendLine(Member.Name + " : 还未进攻");
                                         }
                                         else
                                         {
                                             sb.AppendLine(Member.Name + " : " + Member.Attacks[0].Stars + "星(摧毁: " + Member.Attacks[0].DestructionPercentage + "%)");
                                         }
                                     }
                                     result = new IMessageBase[] { BaseData.TextToImg(sb.ToString(), chat.Session) };
                                 }
                             }
                         }
                     }
                 });
                 if (result == null)
                 {
                     result = new IMessageBase[] { new PlainMessage("联赛资料获取失败!也许现在不是联赛时间?") };
                 }
                 return(result);
             }
             else
             {
                 if (league != null)
                 {
                     return(new IMessageBase[] { new PlainMessage("无法获取任何联赛资料,错误详情: " + league.Reason + "!") });
                 }
                 else
                 {
                     return(new IMessageBase[] { new PlainMessage("无法获取任何联赛资料!") });
                 }
             }
         }
         else
         {
             return(new IMessageBase[] { new PlainMessage("请设置好config.ini后才使用此功能,或者使用</绑定群 #部落标签>后才使用!") });
         }
     }
     return(await base.GetReply(chat));
 }
Exemplo n.º 2
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message == "/联赛")
     {
         ICocCoreClans war      = BaseData.Instance.container.Resolve <ICocCoreClans>();
         var           keypairs = BaseData.valuePairs(configType.部落冲突);
         if (keypairs.ContainsKey(chat.FromGroup.ToString()))
         {
             List <IMessageBase> result = new List <IMessageBase>();
             LeagueWar           league = war.GetCurrentWarLeague(keypairs[chat.FromGroup.ToString()]);
             if (league != null && string.IsNullOrEmpty(league.Reason))
             {
                 StringBuilder sb = new StringBuilder();
                 sb.AppendLine("============");
                 foreach (var clan in league.Clans)
                 {
                     sb.AppendLine("部落名: " + clan.Name);
                     sb.AppendLine("参赛成员:" + clan.Members.Length);
                     sb.AppendLine("-----------");
                     for (int x = 4; x <= 13; x++)
                     {
                         int count = clan.Members.Count(m => m.TownhallLevel == x);
                         if (count > 0)
                         {
                             sb.AppendLine("拥有" + BaseData.Instance.THLevels[x] + "本 x" + count);
                         }
                     }
                     sb.AppendLine("============");
                 }
                 result.Add(BaseData.TextToImg(sb.ToString(), chat.Session));
                 sb.Clear();
                 Array.Reverse(league.Rounds);
                 Parallel.ForEach(league.Rounds, (rounds) =>
                 {
                     Parallel.ForEach(rounds.warTags, (warTag) =>
                     {
                         if (warTag != "#0")
                         {
                             var roundData = war.GetCurrentWarLeagueRound(warTag);
                             Logger.Instance.AddLog(LogType.Debug, "联赛部落" + roundData.clan.Name + " vs " + roundData.opponent.Name);
                             if (roundData.clan.Tag == keypairs[chat.FromGroup.ToString()].ToUpper())
                             {
                                 if (roundData.state == "preparation")
                                 {
                                     sb.AppendLine("下场联赛开战时间为: " + roundData.StartTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.opponent.Name);
                                     result.Add(BaseData.TextToImg(sb.ToString(), chat.Session));
                                     sb.Clear();
                                 }
                                 else if (roundData.state == "inWar")
                                 {
                                     sb.AppendLine("当前联赛结束时间为: " + roundData.EndTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.opponent.Name);
                                     sb.AppendLine("当前我方战星: " + roundData.clan.Stars + ", 敌方战星: " + roundData.opponent.Stars);
                                     result.Add(BaseData.TextToImg(sb.ToString(), chat.Session));
                                 }
                             }
                             else if (roundData.opponent.Tag == keypairs[chat.FromGroup.ToString()].ToUpper())
                             {
                                 if (roundData.state == "preparation")
                                 {
                                     sb.AppendLine("下场联赛开战时间为: " + roundData.StartTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.clan.Name);
                                     result.Add(BaseData.TextToImg(sb.ToString(), chat.Session));
                                     sb.Clear();
                                 }
                                 else if (roundData.state == "inWar")
                                 {
                                     sb.AppendLine("当前联赛结束时间为: " + roundData.EndTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss tt"));
                                     sb.AppendLine("对手为" + roundData.clan.Name);
                                     sb.AppendLine("当前我方战星: " + roundData.opponent.Stars + ", 敌方战星: " + roundData.clan.Stars);
                                     result.Add(BaseData.TextToImg(sb.ToString(), chat.Session));
                                 }
                             }
                         }
                     });
                 });
                 return(result);
             }
             else if (!string.IsNullOrEmpty(league.Reason))
             {
                 if (league.Reason == "inMaintenance")
                 {
                     return(new IMessageBase[] { new PlainMessage(" 当前服务器在维护!") });
                 }
             }
             else
             {
                 return(new IMessageBase[] { new PlainMessage("请在config.ini设置好Clan_ID后再继续使用此功能或者当前不在联赛时间") });
             }
         }
         else
         {
             return(new IMessageBase[] { new PlainMessage("请在config.ini设置好Clan_ID后再继续使用此功能") });
         }
     }
     return(await base.GetReply(chat));
 }