Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="gaiaGame"></param>
        /// <param name="faction"></param>
        /// <param name="isAdd">追加</param>
        public static void Score(Type type, GaiaGame gaiaGame, Faction faction, bool isAdd = true)
        {
            if (type.Name.Contains("ATT") && gaiaGame.dbContext != null && gaiaGame.IsSaveToDb)
            {
                if (type.Name == "ATT11")
                {
                    int a = 1;
                }

                GameFactionExtendModel gameFactionExtendModel = gaiaGame.dbContext.GameFactionExtendModel.SingleOrDefault(
                    item => item.gameinfo_name == gaiaGame.GameName &&
                    item.FactionName == faction.FactionName.ToString());
                if (gameFactionExtendModel != null)
                {
                    //取值
                    string strClass  = "GaiaCore.Gaia.Tiles." + type.Name; //命名空间+类名
                    string strMethod = "GetResources";                     //方法名

                    Type   classtype;
                    object obj;

                    classtype = Type.GetType(strClass);                     //通过string类型的strClass获得同名类“type”
                    obj       = System.Activator.CreateInstance(classtype); //创建type类的实例 "obj"


                    MethodInfo method = type.GetMethod(strMethod, new Type[] { typeof(Faction) }); //取的方法描述//2
                    short      result = (short)method.Invoke(obj, new object[] { faction, });      //3

                    //赋值
                    Type modeltype = gameFactionExtendModel.GetType();
                    //var ps = type.GetProperties();

                    var ps = modeltype.GetProperties().ToList().Find(item => item.Name == type.Name + "Score");
                    if (ps != null)
                    {
                        if (isAdd)
                        {
                            short value = (short)ps.GetValue(gameFactionExtendModel);
                            ps.SetValue(gameFactionExtendModel, (Int16)(result + value), null);
                        }
                        else
                        {
                            ps.SetValue(gameFactionExtendModel, (Int16)(result), null);
                        }
                    }
                    //保存
                    gaiaGame.dbContext.GameFactionExtendModel.Update(gameFactionExtendModel);
                    gaiaGame.dbContext.SaveChanges();

                    //var ti = type.GetTypeInfo();
                    //MethodInfo mtd = ti.GetMethod("GetResources");
                    //var genMethod = mtd.MakeGenericMethod(typeof(int));

                    //var obj = genMethod.Invoke(type, new object[] { });

                    //                        switch (type.ToString())
                    //                        {
                    //                            case "ATT4":
                    //                                gameFactionExtendModel.ATT4Score += (short)new ATT4().GetTriggerScore;
                    //                                break;
                    //
                    //                        }
                    //
                }
            }
        }
Example #2
0
        /// <summary>
        /// 保存哪区科技版
        /// </summary>
        /// <param name="gaiaGame"></param>
        /// <param name="faction"></param>
        /// <param name="techTileStr"></param>
        public static void SaveTTData(GaiaGame gaiaGame, Faction faction, string techTileStr)
        {
            //开始保存数据
            if (!gaiaGame.IsSaveToDb)
            {
                return;
            }
            //            //如果游戏没有结束不保存数据
            //            if (gaiaGame.GameStatus.status != Status.ENDED)
            //            {
            //                return;
            //            }
            if (gaiaGame.dbContext == null)
            {
                return;
            }
            try
            {
                GameFactionExtendModel extendModel = gaiaGame.dbContext.GameFactionExtendModel.SingleOrDefault(extend => extend.gameinfo_name == gaiaGame.GameName && extend.FactionName == faction.FactionName.ToString());

                Action <GameFactionExtendModel> fz = (gameFactionExtendModel) =>
                {
                    Int16 round = (Int16)gaiaGame.GameStatus.RoundCount;
                    //回合
                    switch (techTileStr)
                    {
                    case "stt1":
                        gameFactionExtendModel.STT1 = round;
                        break;

                    case "stt2":
                        gameFactionExtendModel.STT2 = round;
                        break;

                    case "stt3":
                        gameFactionExtendModel.STT3 = round;
                        break;

                    case "stt4":
                        gameFactionExtendModel.STT4 = round;
                        break;

                    case "stt5":
                        gameFactionExtendModel.STT5 = round;
                        break;

                    case "stt6":
                        gameFactionExtendModel.STT6 = round;
                        break;

                    case "stt7":
                        gameFactionExtendModel.STT7 = round;
                        break;

                    case "stt8":
                        gameFactionExtendModel.STT8 = round;
                        break;

                    case "stt9":
                        gameFactionExtendModel.STT9 = round;
                        break;

                    //高级
                    case "att1":
                        gameFactionExtendModel.ATT1 = round;
                        break;

                    case "att2":
                        gameFactionExtendModel.ATT2 = round;
                        break;

                    case "att3":
                        gameFactionExtendModel.ATT3 = round;
                        break;

                    case "att4":
                        gameFactionExtendModel.ATT4 = round;
                        break;

                    case "att5":
                        gameFactionExtendModel.ATT5 = round;
                        break;

                    case "att6":
                        gameFactionExtendModel.ATT6 = round;
                        break;

                    case "att7":
                        gameFactionExtendModel.ATT7 = round;
                        break;

                    case "att8":
                        gameFactionExtendModel.ATT8 = round;
                        break;

                    case "att9":
                        gameFactionExtendModel.ATT9 = round;
                        break;

                    case "att10":
                        gameFactionExtendModel.ATT10 = round;
                        break;

                    case "att11":
                        gameFactionExtendModel.ATT11 = round;
                        break;

                    case "att12":
                        gameFactionExtendModel.ATT12 = round;
                        break;

                    case "att13":
                        gameFactionExtendModel.ATT13 = round;
                        break;

                    case "att14":
                        gameFactionExtendModel.ATT14 = round;
                        break;

                    case "att15":
                        gameFactionExtendModel.ATT15 = round;
                        break;
                    }
                };
                //如果没有记录
                if (extendModel == null)
                {
                    //获取排名
                    int rank = gaiaGame.dbContext.GameFactionModel
                               .SingleOrDefault(item => item.gameinfo_name == gaiaGame.GameName &&
                                                item.username == faction.UserName)?.rank ?? 0;

                    extendModel = new GameFactionExtendModel()
                    {
                        gameinfo_name = gaiaGame.GameName,              //名称
                        FactionName   = faction.FactionName.ToString(), //种族
                        username      = faction.UserName,
                        //rank = faction.,
                        rank = rank,
                    };
                    fz(extendModel);
                    gaiaGame.dbContext.GameFactionExtendModel.Add(extendModel);
                }
                else
                {
                    fz(extendModel);
                    gaiaGame.dbContext.GameFactionExtendModel.Update(extendModel);
                }
                gaiaGame.dbContext.SaveChanges();

                //int? id = this.dbContext.GameFactionModel.SingleOrDefault(fac => fac.gameinfo_name == this.GameName&&fac.FactionName==faction.FactionName.ToString())?.Id;
                //int? id1 = id;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //var server = gaiaGame.dbContext.Database.GetService<this>();
        }
Example #3
0
//        public class TTModel
//        {
//            public string name { get; set; }
//            public int count { get; set; }
//
//
//        }

        public IActionResult TTStatistics()
        {
            //列表统计
            List <GameFactionExtendModel> list = new List <GameFactionExtendModel>();
            //储存
            GameFactionExtendModel gameFactionExtendModel = new GameFactionExtendModel();



            //gameFactionExtendModel.ATT1 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT1 > 0 && item.rank == 1);

            //高级科技
            gameFactionExtendModel.ATT1  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT1 > 0);
            gameFactionExtendModel.ATT2  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT2 > 0);
            gameFactionExtendModel.ATT3  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT3 > 0);
            gameFactionExtendModel.ATT4  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT4 > 0);
            gameFactionExtendModel.ATT5  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT5 > 0);
            gameFactionExtendModel.ATT6  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT6 > 0);
            gameFactionExtendModel.ATT7  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT7 > 0);
            gameFactionExtendModel.ATT8  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT8 > 0);
            gameFactionExtendModel.ATT9  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT9 > 0);
            gameFactionExtendModel.ATT10 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT10 > 0);
            gameFactionExtendModel.ATT11 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT11 > 0);
            gameFactionExtendModel.ATT12 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT12 > 0);
            gameFactionExtendModel.ATT13 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT13 > 0);
            gameFactionExtendModel.ATT14 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT14 > 0);
            gameFactionExtendModel.ATT15 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT15 > 0);
            //低级科技
            gameFactionExtendModel.STT1 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT1 > 0);
            gameFactionExtendModel.STT2 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT2 > 0);
            gameFactionExtendModel.STT3 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT3 > 0);
            gameFactionExtendModel.STT4 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT4 > 0);
            gameFactionExtendModel.STT5 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT5 > 0);
            gameFactionExtendModel.STT6 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT6 > 0);
            gameFactionExtendModel.STT7 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT7 > 0);
            gameFactionExtendModel.STT8 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT8 > 0);
            gameFactionExtendModel.STT9 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.STT9 > 0);

            //平局得分
            try
            {
                gameFactionExtendModel.ATT4Score  = gameFactionExtendModel.ATT4 > 0?(short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT4 > 0).Sum(item => item.ATT4Score) / gameFactionExtendModel.ATT4):(short)0;
                gameFactionExtendModel.ATT5Score  = gameFactionExtendModel.ATT5 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT5 > 0).Sum(item => item.ATT5Score) / gameFactionExtendModel.ATT5):(short)0;
                gameFactionExtendModel.ATT6Score  = gameFactionExtendModel.ATT6 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT6 > 0).Sum(item => item.ATT6Score) / gameFactionExtendModel.ATT6):(short)0;
                gameFactionExtendModel.ATT7Score  = gameFactionExtendModel.ATT7 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT7 > 0).Sum(item => item.ATT7Score) / gameFactionExtendModel.ATT7):(short)0;
                gameFactionExtendModel.ATT8Score  = gameFactionExtendModel.ATT8 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT8 > 0).Sum(item => item.ATT8Score) / gameFactionExtendModel.ATT8):(short)0;
                gameFactionExtendModel.ATT9Score  = gameFactionExtendModel.ATT9 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT9 > 0).Sum(item => item.ATT9Score) / gameFactionExtendModel.ATT9):(short)0;
                gameFactionExtendModel.ATT10Score = gameFactionExtendModel.ATT10 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT10 > 0).Sum(item => item.ATT10Score) / gameFactionExtendModel.ATT10):(short)0;
                gameFactionExtendModel.ATT11Score = gameFactionExtendModel.ATT11 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT11 > 0).Sum(item => item.ATT11Score) / gameFactionExtendModel.ATT11):(short)0;
                gameFactionExtendModel.ATT12Score = gameFactionExtendModel.ATT12 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT12 > 0).Sum(item => item.ATT12Score) / gameFactionExtendModel.ATT12):(short)0;
                gameFactionExtendModel.ATT13Score = gameFactionExtendModel.ATT13 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT13 > 0).Sum(item => item.ATT13Score) / gameFactionExtendModel.ATT13):(short)0;
                gameFactionExtendModel.ATT14Score = gameFactionExtendModel.ATT14 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT14 > 0).Sum(item => item.ATT14Score) / gameFactionExtendModel.ATT14):(short)0;
                gameFactionExtendModel.ATT15Score = gameFactionExtendModel.ATT15 > 0 ? (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT15 > 0).Sum(item => item.ATT15Score) / gameFactionExtendModel.ATT15):(short)0;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            list.Add(gameFactionExtendModel);

            //添加排名统计
            Action <int> addGfe = (index) => {
                //平局得分
                GameFactionExtendModel model = new GameFactionExtendModel();
                model.ATT1  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT1 > 0 && item.rank == index);
                model.ATT2  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT2 > 0 && item.rank == index);
                model.ATT3  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT3 > 0 && item.rank == index);
                model.ATT4  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT4 > 0 && item.rank == index);
                model.ATT5  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT5 > 0 && item.rank == index);
                model.ATT6  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT6 > 0 && item.rank == index);
                model.ATT7  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT7 > 0 && item.rank == index);
                model.ATT8  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT8 > 0 && item.rank == index);
                model.ATT9  = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT9 > 0 && item.rank == index);
                model.ATT10 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT10 > 0 && item.rank == index);
                model.ATT11 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT11 > 0 && item.rank == index);
                model.ATT12 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT12 > 0 && item.rank == index);
                model.ATT13 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT13 > 0 && item.rank == index);
                model.ATT14 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT14 > 0 && item.rank == index);
                model.ATT15 = (short)this.dbContext.GameFactionExtendModel.Count(item => item.ATT15 > 0 && item.rank == index);

                //平局得分
                try
                {
                    model.ATT4Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT4 > 0 && item.rank == index).Sum(item => item.ATT4Score) / model.ATT4);
                    model.ATT5Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT5 > 0 && item.rank == index).Sum(item => item.ATT5Score) / model.ATT5);
                    model.ATT6Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT6 > 0 && item.rank == index).Sum(item => item.ATT6Score) / model.ATT6);
                    model.ATT7Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT7 > 0 && item.rank == index).Sum(item => item.ATT7Score) / model.ATT7);
                    model.ATT8Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT8 > 0 && item.rank == index).Sum(item => item.ATT8Score) / model.ATT8);
                    model.ATT9Score  = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT9 > 0 && item.rank == index).Sum(item => item.ATT9Score) / model.ATT9);
                    model.ATT10Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT10 > 0 && item.rank == index).Sum(item => item.ATT10Score) / model.ATT10);
                    model.ATT11Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT11 > 0 && item.rank == index).Sum(item => item.ATT11Score) / model.ATT11);
                    model.ATT12Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT12 > 0 && item.rank == index).Sum(item => item.ATT12Score) / model.ATT12);
                    model.ATT13Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT13 > 0 && item.rank == index).Sum(item => item.ATT13Score) / model.ATT13);
                    model.ATT14Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT14 > 0 && item.rank == index).Sum(item => item.ATT14Score) / model.ATT14);
                    model.ATT15Score = (short)(this.dbContext.GameFactionExtendModel.Where(item => item.ATT15 > 0 && item.rank == index).Sum(item => item.ATT15Score) / model.ATT15);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                list.Add(model);
            };

            //1-4
            addGfe(1);
            addGfe(2);
            addGfe(3);
            addGfe(4);


            //IQueryable<TTModel> ttModels = this.dbContext.GameFactionExtendModel.Where(item => item.ATT1 > 0).Select(item=>item);
            //                (g => new TTModel
            //            {
            //                count = g.Sum(i => i.ATT1),
            //                name = "ATT1"
            //            });
            return(View(list));
        }