예제 #1
0
 /// <summary>
 /// 进入下一个boss
 /// </summary>
 /// <param name="guildInfo">公会信息</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool GotoNextBoss(GuildInfo guildInfo)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //获取下一个boss的信息
         GuildBattleBoss nextBossData = dbClient.Queryable <GuildBattleBoss>()
                                        .Where(i => i.ServerId == guildInfo.ServerId &&
                                               i.Phase == guildInfo.BossPhase &&
                                               i.Order == guildInfo.Order + 1)
                                        .First();
         GuildInfo updateBossData =
             new GuildInfo()
         {
             Order   = guildInfo.Order + 1,
             HP      = nextBossData.HP,
             TotalHP = nextBossData.HP
         };
         return(dbClient.Updateable(updateBossData)
                .UpdateColumns(i => new { i.Order, i.HP, i.TotalHP })
                .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                .ExecuteCommandHasChange());
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(false);
     }
 }
        /// <summary>
        /// 进入下一个周目
        /// </summary>
        /// <param name="guildInfo">公会信息</param>
        /// <returns>
        /// <para><see langword="true"/> 写入成功</para>
        /// <para><see langword="false"/> 数据库错误</para>
        /// </returns>
        public bool GotoNextRound(GuildInfo guildInfo)
        {
            try
            {
                using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

                int nextPhase = GetRoundPhase(guildInfo.ServerId, guildInfo.Round + 1);
                //获取下一个周目boss的信息
                GuildBattleBoss nextBossData = dbClient.Queryable <GuildBattleBoss>()
                                               .Where(i => i.ServerId == guildInfo.ServerId &&
                                                      i.Phase == nextPhase &&
                                                      i.Order == 1)
                                               .First();
                return(dbClient.Updateable <GuildInfo>()
                       .SetColumns(i => new GuildInfo()
                {
                    BossPhase = nextBossData.Phase,
                    Order = 1,
                    Round = guildInfo.Round + 1,
                    HP = nextBossData.HP,
                    TotalHP = nextBossData.HP
                })
                       .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                       .ExecuteCommandHasChange());
            }
            catch (Exception e)
            {
                Log.Error("Database error", Log.ErrorLogBuilder(e));
                return(false);
            }
        }
예제 #3
0
 /// <summary>
 /// 开始会战
 /// </summary>
 /// <returns>
 /// <para><see langword="1"/> 成功开始统计</para>
 /// <para><see langword="0"/> 未结束会战</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int StartBattle(GuildInfo guildInfo)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (SugarUtils.TableExists <GuildBattle>(dbClient, BattleTableName))
         {
             ConsoleLog.Error("会战管理数据库", "会战表已经存在,请检查是否未结束上次会战统计");
             return(0);
         }
         else
         {
             SugarUtils.CreateTable <GuildBattle>(dbClient, BattleTableName);
             ConsoleLog.Info("会战管理数据库", "开始新的一期会战统计");
             dbClient.Updateable(new GuildInfo {
                 InBattle = true
             })
             .Where(guild => guild.Gid == GuildEventArgs.SourceGroup.Id)
             .UpdateColumns(i => new { i.InBattle })
             .ExecuteCommandHasChange();
             //获取初始周目boss的信息
             GuildBattleBoss initBossData = dbClient.Queryable <GuildBattleBoss>()
                                            .Where(i => i.ServerId == guildInfo.ServerId &&
                                                   i.Phase == 1 &&
                                                   i.Order == 1)
                                            .First();
             GuildInfo updateBossData =
                 new GuildInfo()
             {
                 BossPhase = initBossData.Phase,
                 Order     = 1,
                 Round     = 1,
                 HP        = initBossData.HP,
                 TotalHP   = initBossData.HP
             };
             return(dbClient.Updateable(updateBossData)
                    .UpdateColumns(i => new { i.Order, i.HP, i.BossPhase, i.Round, i.TotalHP })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                    .ExecuteCommandHasChange()
                 ? 1
                 : -1);
         }
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(-1);
     }
 }