private object Invalidize(string fieldName, object value, Type type)
 {
     if (fieldName.Equals("path", StringComparison.InvariantCultureIgnoreCase))
     {
         return("45/shapes");
     }
     if (type == typeof(string))
     {
         return((string)value + "invalidValue");
     }
     if (type == typeof(int))
     {
         return(593);
     }
     if (type == typeof(List <int>))
     {
         return(new List <int> {
             593
         });
     }
     if (type.IsEnum)
     {
         Array values = Enum.GetValues(type);
         return(values.GetValue(RandomInstance.Next(values.Length)));
     }
     return(null);
 }
예제 #2
0
        private async void ListenerEventWorker()
        {
            var EventID = RandomInstance.Next();

            ListenerEventID = EventID;

            await Task.Delay(500);

            if (EventID != ListenerEventID)
            {
                return;                                         // Another event called
            }
            var res = new ResourceModel
            {
                Date = DateTime.Now,

                Fuel    = CurrentFuel,
                Ammo    = CurrentAmmo,
                Steel   = CurrentSteel,
                Bauxite = CurrentBauxite,

                RepairBucket        = CurrentRepairBucket,
                DevelopmentMaterial = CurrentDevelopmentMaterial,
                InstantConstruction = CurrentInstantConstruction,
                ImprovementMaterial = CurrentImprovementMaterial
            };

            var x = ResourceList.ToList();

            x.Add(res);
            ResourceList = x.ToArray();

            ResetChart(GetDaysFromPeriod());
        }
예제 #3
0
        private async void ListenerEventWorker()
        {
            var EventID = RandomInstance.Next();

            ListenerEventID = EventID;

            await Task.Delay(500);

            if (EventID != ListenerEventID)
            {
                return;                                         // Another event called
            }
            string zItemsPath = ResourceCachePath;

            var res = new ResourceModel
            {
                Date = DateTime.Now,

                Fuel    = CurrentFuel,
                Ammo    = CurrentAmmo,
                Steel   = CurrentSteel,
                Bauxite = CurrentBauxite,

                RepairBucket        = CurrentRepairBucket,
                DevelopmentMaterial = CurrentDevelopmentMaterial,
                InstantConstruction = CurrentInstantConstruction,
                ImprovementMaterial = CurrentImprovementMaterial
            };

            CriticalSection("ResourceChartWrite", () =>
            {
                int tries = 5;
                if ((DateTime.Now - LatestWritten).TotalSeconds < 60.0)
                {
                    return;
                }

                while (tries > 0)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(zItemsPath, FileMode.Append))
                        {
                            CSV.Write(fs,
                                      res.Date.ToString("yyyy-MM-dd HH:mm:ss"),
                                      res.Fuel, res.Ammo, res.Steel, res.Bauxite,
                                      res.RepairBucket, res.DevelopmentMaterial,
                                      res.InstantConstruction, res.ImprovementMaterial
                                      );
                        }
                        break;
                    }
                    catch (IOException) { tries--; }
                    catch (Exception) { break; }
                }
            });
        }
예제 #4
0
        private int GetNextNumber(int totalDice)
        {
            int totalValue = 0;

            for (int i = 0; i < totalDice; i++)
            {
                totalValue += RandomInstance.Next(1, NUM_SIDES + 1);
            }

            return(totalValue);
        }
예제 #5
0
        /// <summary>
        /// 创建游戏
        /// </summary>
        /// <param name="name"></param>
        /// <param name="username"></param>
        /// <param name="result"></param>
        /// <param name="MapSelection"></param>
        /// <param name="seed"></param>
        /// <param name="isTestGame"></param>
        /// <param name="isSocket"></param>
        /// <param name="IsRotatoMap"></param>
        /// <param name="version"></param>
        /// <returns></returns>

        private static bool CreateNewGame(string name, string[] username, out GaiaGame result, string MapSelection, int seed = 0, bool isTestGame = false, bool isSocket = false, bool IsRotatoMap = false, int version = 3)
        {
            if (m_dic.ContainsKey(name))
            {
                result = null;
                return(false);
            }
            else
            {
                seed               = seed == 0 ? RandomInstance.Next(int.MaxValue) : seed;
                result             = new GaiaGame(username, name);
                result.IsTestGame  = isTestGame;
                result.GameName    = name;        //游戏名称
                result.IsSocket    = isSocket;    //即时制
                result.IsRotatoMap = IsRotatoMap; //旋转地图
                result.version     = version;

                //开局的两条命令
                result.Syntax(GameSyntax.setupmap + " " + MapSelection, out string log);
                result.Syntax(GameSyntax.setupGame + seed, out log);
                m_dic.Add(name, result);
                return(true);
            }
        }
예제 #6
0
 /// <summary>
 /// Returns whether or not the datareader should be closed
 /// </summary>
 protected virtual bool ShouldCloseDataReader()
 {
     // Ignore commandCancelled, instead randomly close it 9/10 of the time
     return(RandomInstance.Next(10) != 0);
 }
예제 #7
0
        /// <summary>
        /// Retrieves a random element from <paramref name="list"/>.
        /// </summary>
        /// <typeparam name="T"><see cref="List{T}"/> type</typeparam>
        /// <param name="list"><see cref="List{T}"/> from which to retrieve a random element</param>
        /// <returns>A random element</returns>
        public static T GetRandomElement <T>(this IList <T> list)
        {
            var i = RandomInstance.Next(list.Count);

            return(list[i]);
        }