Exemplo n.º 1
0
        public void TestSpawnedTypeFirst()
        {
            FixedSpawn     fixedSpawn = new FixedSpawn();
            GameObjectStub gameObject = new GameObjectStub();

            fixedSpawn.Spawn(gameObject);
            Assert.AreEqual(0, fixedSpawn.getCurrentType());
        }
Exemplo n.º 2
0
        public void TestRandomnessOfPowerUp()
        {
            FixedSpawn     fixedSpawn = new FixedSpawn();
            GameObjectStub gameObject = new GameObjectStub();
            int            timesOfPermamentPowerup = 0;

            for (int i = 0; i < 1000; i++)
            {
                var powerUp = fixedSpawn.Spawn(gameObject);
                if (powerUp.GetType() == typeof(PermanentAttack) || powerUp.GetType() == typeof(PermanentDefense) || powerUp.GetType() == typeof(PermanentHealth) || powerUp.GetType() == typeof(PermanentSpeed))
                {
                    timesOfPermamentPowerup++;
                }
            }
            Assert.IsTrue(timesOfPermamentPowerup >= 450 && timesOfPermamentPowerup <= 550);
        }
Exemplo n.º 3
0
        private void LoadMapFromFile(int mapNumber, string hybrasylMapFilename)
        {
            saveYamlButton.Enabled = false;

            int height = 100,
                width  = 100;
            string            mapName     = null;
            List <FixedSpawn> fixedSpawns = new List <FixedSpawn>();
            List <ZoneSpawn>  zoneSpawns  = new List <ZoneSpawn>();

            // load Hybrasyl map file
            var hybrasylMap = LoadHybrasylMapYamlFile(hybrasylMapFilename);

            if (hybrasylMap != null)
            {
                saveYamlButton.Enabled = true;

                var mapDimensions = hybrasylMap["size"].ToString().Split('x');

                width   = Convert.ToInt32(mapDimensions[0]);
                height  = Convert.ToInt32(mapDimensions[1]);
                mapName = hybrasylMapFilename;

                Dictionary <object, object> spawns = null;
                if (hybrasylMap.ContainsKey("spawns"))
                {
                    spawns = hybrasylMap["spawns"] as Dictionary <object, object>;
                }

                if (spawns != null)
                {
                    var fixedd = (spawns.ContainsKey("fixed")) ? spawns["fixed"] as List <object> : null;
                    var zone   = (spawns.ContainsKey("zone")) ? spawns["zone"] as List <object> : null;

                    if (fixedd != null)
                    {
                        foreach (var f in fixedd)
                        {
                            var item = f as Dictionary <object, object>;

                            // required fields
                            var s = new FixedSpawn {
                                name      = item["name"].ToString(),
                                checkrate = Convert.ToInt32(item["checkrate"])
                            };

                            // optional fields
                            if (item.ContainsKey("every"))
                            {
                                s.every = Convert.ToInt32(item["every"]);
                            }
                            if (item.ContainsKey("min"))
                            {
                                s.min = Convert.ToInt32(item["min"]);
                            }
                            if (item.ContainsKey("max"))
                            {
                                s.max = Convert.ToInt32(item["max"]);
                            }
                            if (item.ContainsKey("percentage"))
                            {
                                s.percentage = Convert.ToSingle(item["percentage"]);
                            }

                            if (item.ContainsKey("speed"))
                            {
                                s.speed = Convert.ToInt32(item["speed"]);
                            }
                            if (item.ContainsKey("hostile"))
                            {
                                s.hostile = Convert.ToBoolean(item["hostile"]);
                            }
                            if (item.ContainsKey("strategy"))
                            {
                                s.strategy = item["strategy"].ToString();
                            }

                            fixedSpawns.Add(s);
                        }
                    }

                    if (zone != null)
                    {
                        foreach (var z in zone)
                        {
                            var item = z as Dictionary <object, object>;

                            // required fields
                            var s = new ZoneSpawn
                            {
                                name      = item["name"].ToString(),
                                checkrate = Convert.ToInt32(item["checkrate"]),
                            };

                            var start = item["start_point"].ToString().Split(',');
                            var end   = item["end_point"].ToString().Split(',');

                            s.start_point = new System.Drawing.Point(Convert.ToInt32(start[0]), Convert.ToInt32(start[1]));
                            s.end_point   = new System.Drawing.Point(Convert.ToInt32(end[0]), Convert.ToInt32(end[1]));

                            // optional fields
                            if (item.ContainsKey("every"))
                            {
                                s.every = Convert.ToInt32(item["every"]);
                            }
                            if (item.ContainsKey("min"))
                            {
                                s.min = Convert.ToInt32(item["min"]);
                            }
                            if (item.ContainsKey("max"))
                            {
                                s.max = Convert.ToInt32(item["max"]);
                            }
                            if (item.ContainsKey("percentage"))
                            {
                                s.percentage = Convert.ToSingle(item["percentage"]);
                            }

                            zoneSpawns.Add(s);
                        }
                    }
                }
            }

            // load DA map file
            string mapPath;

            if (!string.IsNullOrEmpty(Configuration.Current.DarkagesInstallDirectory))
            {
                mapPath = Path.Combine(Configuration.Current.DarkagesInstallDirectory, "maps", "lod" + mapNumber.ToString() + ".map");
            }
            else
            {
                // original code defaulted to VirtualStore. do we want this..?
                string localStorage = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                mapPath = localStorage + @"\VirtualStore\Program Files (x86)\KRU\Dark Ages\maps\lod" + mapNumber.ToString() + ".map";
            }

            this.map = new Map(fixedSpawns, zoneSpawns)
            {
                Width  = width,
                Height = height,
                Name   = mapName ?? ("lod" + mapNumber + ".map"),
            };
            this.map.SetData(File.ReadAllBytes(mapPath));

            this.propertyGrid1.SelectedObject = map;
            this.mapPanel.Map = map;
            this.Text         = "Edit Map - " + map.Name;
        }