Beispiel #1
0
        protected ConcurrentArrayList <Entities.GameClient> GetPossibleTargets()
        {
            ConcurrentArrayList <Entities.GameClient> Targets = new ConcurrentArrayList <GameClient>();

            if (Screen.MapObjects.Count == 0)
            {
                return(Targets);
            }

            foreach (Maps.IMapObject MapObject in Screen.MapObjects.Values)
            {
                if (ProtectedPlayers.Contains((MapObject as Entities.GameClient)))
                {
                    continue;
                }
                if (MapObject is Entities.GameClient)
                {
                    if ((MapObject as Entities.GameClient).Alive)
                    {
                        Targets.Add(MapObject as Entities.GameClient);
                    }
                }
            }
            return(Targets);
        }
Beispiel #2
0
        public void GetOrSet()
        {
            var list = new ConcurrentArrayList <TestValue>(1, true);

            list[5] = new TestValue(5);
            XAssert.IsNotNull(list[5]);
            XAssert.AreEqual(5, list[5].Value);

            bool      callBackCalled = false;
            TestValue val            = list.GetOrSet(
                5,
                () =>
            {
                callBackCalled = true;
                return(new TestValue(10));
            });

            XAssert.IsNotNull(val);
            XAssert.AreEqual(5, val.Value);

            // also test index
            XAssert.IsNotNull(list[5]);
            XAssert.AreEqual(5, list[5].Value);

            XAssert.IsFalse(callBackCalled);
        }
Beispiel #3
0
        public void HandleSkills()
        {
            if (!IsSpawned)
            {
                return;
            }

            if (BossSkills.Count > 0 && Creatures.Count == 0)
            {
                ConcurrentArrayList <Entities.GameClient> PossibleTargets = GetPossibleTargets();
                if (PossibleTargets.Count > 0)
                {
                    if (DateTime.Now >= BossSkillTime)
                    {
                        BossSkillTime = DateTime.Now.AddMilliseconds(ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(BossSkillSpeed * 2));

                        ushort[] rSkills = BossSkills.Keys.ToArray();
                        if (rSkills.Length > 0)
                        {
                            ushort[] Skills = new ushort[rSkills.Length * 4];                             // fixing random index issue with .NET's random ...
                            Array.Copy(rSkills, 0, Skills, 0, rSkills.Length);
                            Array.Copy(rSkills, 0, Skills, rSkills.Length, rSkills.Length);
                            ushort Skill = Skills[ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(Skills.Length - 1)];

                            BossSkills[Skill].Use(this, PossibleTargets.ToDictionary().Values.ToArray());
                        }

                        foreach (Data.AdvancedSkill skill in BossAlwaysSkills.Values)
                        {
                            skill.Use(this, PossibleTargets.ToDictionary().Values.ToArray());
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void Create()
        {
            var list = new ConcurrentArrayList <TestValue>(1, false);

            list[0] = new TestValue(1);
            XAssert.IsNotNull(list[0]);
            XAssert.AreEqual(1, list[0].Value);
        }
Beispiel #5
0
 public ArenaMatch(Entities.GameClient Player1, Entities.GameClient Player2)
 {
     Started            = false;
     AcceptedFight1     = false;
     AcceptedFight2     = false;
     Player1.ArenaMatch = this;
     this.Player1       = Player1;
     this.Player2       = Player2;
     Watchers           = new ConcurrentArrayList <ProjectX_V3_Game.Entities.GameClient>();
 }
Beispiel #6
0
 public ArenaMatch(Entities.GameClient Player1, Entities.GameClient Player2)
 {
     Started = false;
     AcceptedFight1 = false;
     AcceptedFight2 = false;
     Player1.ArenaMatch = this;
     this.Player1 = Player1;
     this.Player2 = Player2;
     Watchers = new ConcurrentArrayList<ProjectX_V3_Game.Entities.GameClient>();
 }
        static NameGenerator()
        {
            Names     = new ConcurrentDictionary <int, string>();
            UsedNames = new ConcurrentArrayList <string>();

            string[] nNames = NameList.Replace("\n", "THISISANEWLINE").MakeReadable(true, false, true, false, false)
                              .Replace("THISISANEWLINE", "\n").Split('\n');
            foreach (string name in nNames)
            {
                Names.TryAdd(Names.Count, name);
            }
        }
Beispiel #8
0
        public void ReadAndIterate()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

                foreach (var item in student)
                {
                    var harmless = student[0];
                }
            }
        }
Beispiel #9
0
        public BossMonster()
            : base()
        {
            BossSkills       = new ConcurrentDictionary <ushort, Data.AdvancedSkill>();
            BossAlwaysSkills = new ConcurrentDictionary <ushort, ProjectX_V3_Game.Data.AdvancedSkill>();

            Creatures        = new ConcurrentDictionary <uint, BossCreature>();
            ProtectedPlayers = new ConcurrentArrayList <GameClient>();

            CanRevive = false;
            IsSpawned = false;
        }
Beispiel #10
0
        public void AllowResize()
        {
            var list = new ConcurrentArrayList <TestValue>(1, true);

            list[0] = new TestValue(0);
            XAssert.IsNotNull(list[0]);
            XAssert.AreEqual(0, list[0].Value);

            list[1] = new TestValue(1);
            XAssert.IsNotNull(list[1]);
            XAssert.AreEqual(1, list[1].Value);
        }
Beispiel #11
0
        public void UpdateAndIterate()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

                Assert.ThrowsAny <Exception>(() =>
                {
                    foreach (var item in student)
                    {
                        student[0] = item;
                    }
                });
            }
        }
Beispiel #12
0
        public void Scramble()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

                Parallel.For(0, 20, (i) =>
                {
                    var r = new Random(i);
                    for (var j = 0; j < 100; j++)
                    {
                        student[r.Next(0, 10)] = student[r.Next(0, 10)];
                    }
                });
            }
        }
Beispiel #13
0
        public void SimpleAddStuff()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>();


                var r = new Random();
                for (var j = 0; j < 100; j++)
                {
                    student.EnqueAdd(r.Next(0, 100));
                }

                Assert.Equal(100, student.Count);
            }
        }
Beispiel #14
0
        public void DoubleIterate()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
                var count   = 0;

                foreach (var x in student)
                {
                    foreach (var y in student)
                    {
                        count++;
                    }
                }
                Assert.Equal(100, count);
            }
        }
Beispiel #15
0
        public void IndexStress()
        {
            var list     = new ConcurrentArrayList <TestValue>(1, true);
            var rnd      = new Random();
            int maxIndex = 100000;
            IOrderedEnumerable <int> indices = Enumerable.Range(0, maxIndex).ToArray().OrderBy(x => rnd.Next(maxIndex));

            Parallel.ForEach(
                indices,
                index => list[index] = new TestValue(index));

            Parallel.ForEach(
                indices,
                index =>
            {
                TestValue value = list[index];
                XAssert.IsNotNull(value);
                XAssert.AreEqual(index, value.Value);
            });
        }
Beispiel #16
0
        public void PreventResize()
        {
            var list = new ConcurrentArrayList <TestValue>(1, false);

            list[0] = new TestValue(0);
            XAssert.IsNotNull(list[0]);
            XAssert.AreEqual(0, list[0].Value);

            Exception expectedException = null;

            try
            {
                list[1] = new TestValue(1);
            }
            catch (Exception e)
            {
                expectedException = e;
            }

            XAssert.IsNotNull(expectedException as ArgumentException);
            XAssert.AreEqual("index", ((ArgumentException)expectedException).ParamName);
        }
Beispiel #17
0
        public async Task AddStuff()
        {
            for (int k = 0; k < 1000; k++)
            {
                var student = new ConcurrentArrayList <int>();

                var tasks = new List <Task>();
                for (var i = 0; i < 20; i++)
                {
                    tasks.Add(Task.Run(() =>
                    {
                        var r = new Random(i);
                        for (var j = 0; j < 100; j++)
                        {
                            student.EnqueAdd(r.Next(0, 100));
                        }
                    }));
                }

                await Task.WhenAll(tasks.ToArray());

                Assert.Equal(2000, student.Count);
            }
        }
 static ArenaQualifier()
 {
     ArenaStats  = new ConcurrentDictionary <int, ArenaInfo>();
     PlayerQueue = new ConcurrentArrayList <ProjectX_V3_Game.Entities.GameClient>();
     MatchQueue  = new ConcurrentArrayList <Data.ArenaMatch>();
 }
 public TournamentTeam()
 {
     TeamMembers = new ConcurrentArrayList<ProjectX_V3_Game.Entities.GameClient>();
 }
 static ArenaQualifier()
 {
     ArenaStats = new ConcurrentDictionary<int, ArenaInfo>();
     PlayerQueue = new ConcurrentArrayList<ProjectX_V3_Game.Entities.GameClient>();
     MatchQueue = new ConcurrentArrayList<Data.ArenaMatch>();
 }
Beispiel #21
0
        public void GetOrSetStress()
        {
            // Generate a bunch of operations that work on a set of fields that trigger resizes, updates and reads.
            var list                = new ConcurrentArrayList <TestValue>(1, true);
            var rnd                 = new Random();
            int maxIndex            = 2000;
            int maxOperationsFactor = 1000;

            int val0 = 0xfff0000;
            int val1 = 0x000ff000;
            int val2 = 0x00000fff;

            var operations = Enumerable
                             .Range(0, maxIndex * maxOperationsFactor)
                             .Select(
                index =>
            {
                int value;
                int valueToSet = rnd.Next(3);
                switch (valueToSet)
                {
                case 0:
                    value = val0;
                    break;

                case 1:
                    value = val1;
                    break;

                case 2:
                    value = val2;
                    break;

                default:
                    value = 0;
                    XAssert.Fail("sdfsd");
                    break;
                }

                return(new
                {
                    Index = index / maxOperationsFactor,
                    Value = value
                });
            })
                             .ToArray()
                             .OrderBy(x => rnd.Next(maxIndex));

            Parallel.ForEach(
                operations,
                operation =>
            {
                // Make sure it is one of the legal value.
                TestValue res = list.GetOrSet(operation.Index, () => new TestValue(operation.Value));
                XAssert.IsTrue(res.Value == val0 || res.Value == val1 || res.Value == val2);

                // Also inspect random location. Make sure it is a legal value (or null when it is not set yet)
                TestValue other = list[rnd.Next(maxIndex)];
                XAssert.IsTrue(other == null || other.Value == val0 || other.Value == val1 || other.Value == val2);
            });
        }
        static NameGenerator()
        {
            Names = new ConcurrentDictionary<int, string>();
            UsedNames = new ConcurrentArrayList<string>();

            string[] nNames = NameList.Replace("\n", "THISISANEWLINE").MakeReadable(true, false, true, false, false)
                .Replace("THISISANEWLINE", "\n").Split('\n');
            foreach (string name in nNames)
                Names.TryAdd(Names.Count, name);
        }
Beispiel #23
0
 public TournamentTeam()
 {
     TeamMembers = new ConcurrentArrayList <ProjectX_V3_Game.Entities.GameClient>();
 }