Exemple #1
0
        public static void LoadData(string filename)
        {
            XmlDocument doc = LoadXmlDocument(filename);

            NameGenerator.Init((XmlElement)doc.SelectSingleNode("data/names"));

            // Terrain
            foreach (XmlElement el in doc.SelectNodes("/data/terrain/entry"))
            {
                new Terrain(el.GetAttribute("name"));
            }

            // Weather
            foreach (XmlElement el in doc.SelectNodes("/data/weather/entry"))
            {
                new Weather(el.GetAttribute("name"));
            }

            // Item
            foreach (XmlElement el in doc.SelectNodes("/data/item/entry"))
            {
                new ItemType(el.GetAttribute("name"));
            }

            // Skill
            foreach (XmlElement el in doc.SelectNodes("/data/skill/entry"))
            {
                new SkillType(el.GetAttribute("name"));
            }

            // Months
            foreach (XmlElement el in doc.SelectNodes("/data/month/entry"))
            {
                Month m = new Month();
                m.NameEn      = el.GetAttribute("name-en");
                m.NameRu      = el.GetAttribute("name-ru");
                m.Weather     = Weather.Get(el.GetAttribute("weather"));
                m.Temperature = Convert.ToInt32(el.GetAttribute("temperature"));
            }

            // Building
            foreach (XmlElement el in doc.SelectNodes("/data/building/entry"))
            {
                BuildingType t = new BuildingType(el.GetAttribute("name"));
                t.FullNameEn   = el.GetAttribute("name-en");
                t.FullNameRu   = el.GetAttribute("name-ru");
                t.Speed        = LoadInteger(el, "speed");
                t.DriveTerrain = Terrain.Get(el.GetAttribute("drive-terrain"));
                t.Capacity     = LoadInteger(el, "capacity");
                t.Defence      = LoadInteger(el, "defence");
                t.HP           = LoadInteger(el, "hp");
                t.Radiation    = LoadInteger(el, "radiation");
                t.Temperature  = LoadInteger(el, "temperature");
                t.NoBuild      = (el.GetAttribute("nobuild") == "True");

                t.MaintainSkill = LoadSkill(el, "maintain-skill");
                t.DriveSkill    = LoadSkill(el, "drive-skill");
                foreach (XmlElement elItem in el.SelectNodes("material"))
                {
                    t.Materials.Add(LoadItem(elItem));
                }
                foreach (XmlElement elItem in el.SelectNodes("optional"))
                {
                    t.OptionalMaterials.Add(LoadItem(elItem));
                }
                t.Fuel     = ItemType.Get(el.GetAttribute("fuel"));
                t.Resource = LoadItem(el, "resource");
            }

            // Terrain - full
            foreach (XmlElement el in doc.SelectNodes("/data/terrain/entry"))
            {
                Terrain t = Terrain.Get(el.GetAttribute("name"));
                t.FullNameEn = el.GetAttribute("name-en");
                t.FullNameRu = el.GetAttribute("name-ru");
                t.MP         = LoadInteger(el, "mp");
                if (el.GetAttribute("walking") != "")
                {
                    t.Walking = Convert.ToBoolean(el.GetAttribute("walking"));
                }
                if (el.GetAttribute("vehicles") != "")
                {
                    t.Vehicles = Convert.ToBoolean(el.GetAttribute("vehicles"));
                }
                if (el.GetAttribute("ships") != "")
                {
                    t.Ships = Convert.ToBoolean(el.GetAttribute("ships"));
                }
                foreach (XmlElement elMonster in el.SelectNodes("monster"))
                {
                    t.Monsters.Add(ItemType.Get(elMonster.GetAttribute("type")),
                                   Convert.ToInt32(elMonster.GetAttribute("chance")));
                }
            }

            // Weather - full
            foreach (XmlElement el in doc.SelectNodes("/data/weather/entry"))
            {
                Weather t = Weather.Get(el.GetAttribute("name"));
                t.FullNameEn = el.GetAttribute("name-en");
                t.FullNameRu = el.GetAttribute("name-ru");
                LoadInteger(ref t.Radiation, el.GetAttribute("radiation"));
            }

            // Skills - full
            foreach (XmlElement el in doc.SelectNodes("/data/skill/entry"))
            {
                SkillType t = SkillType.Get(el.GetAttribute("name"));
                t.FullNameEn    = el.GetAttribute("name-en");
                t.FullNameRu    = el.GetAttribute("name-ru");
                t.DescriptionEn = el.GetAttribute("description-en");
                t.DescriptionRu = el.GetAttribute("description-ru");
                t.BasedOn       = SkillType.Get(el.GetAttribute("based-on"));
                LoadInteger(ref t.DefaultLevel, el.GetAttribute("default-level"));
            }

            // Items - fill
            foreach (XmlElement el in doc.SelectNodes("/data/item/entry"))
            {
                ItemType t = ItemType.Get(el.GetAttribute("name"));
                t.FullNameEn1 = el.GetAttribute("name-en1");
                t.FullNameEn2 = el.GetAttribute("name-en2");
                t.FullNameRu0 = el.GetAttribute("name-ru0");
                t.FullNameRu1 = el.GetAttribute("name-ru1");
                t.FullNameRu2 = el.GetAttribute("name-ru2");

                t.IsMan     = (el.GetAttribute("is-man") == "True");
                t.IsWeapon  = (el.GetAttribute("is-weapon") == "True");
                t.IsArmor   = (el.GetAttribute("is-armor") == "True");
                t.IsMonster = (el.GetAttribute("is-monster") == "True");

                if (el.GetAttribute("nogive") != "")
                {
                    t.NoGive = Convert.ToBoolean(el.GetAttribute("nogive"));
                }
                LoadInteger(ref t.Weight, el.GetAttribute("weight"));
                t.Capacity[(int)Movement.Walk] = LoadInteger(el, "capacity-walk");
                t.Capacity[(int)Movement.Ride] = LoadInteger(el, "capacity-ride");
                t.InstallSkill     = LoadSkill(el, "install-skill");
                t.Rations          = LoadInteger(el, "rations");
                t.Dead             = ItemType.Get(el.GetAttribute("dead"));
                t.DecomposeChance  = LoadInteger(el, "decompose-chance");
                t.OwnerRadiation   = LoadInteger(el, "owner-radiation");
                t.RegionRadiation  = LoadInteger(el, "region-radiation");
                t.OwnerTemperature = LoadInteger(el, "owner-temperature");
                LoadInteger(ref t.TemperatureFrom, el.GetAttribute("temperature-from"));
                LoadInteger(ref t.TemperatureEffect, el.GetAttribute("temperature-effect"));
                t.Burn = (el.GetAttribute("burn") == "True");
                LoadItems(t.Drops, el.SelectNodes("drop"));

                // Production
                t.ProduceSkill    = LoadSkill(el, "produce-skill");
                t.ProduceBuilding = BuildingType.Get(el.GetAttribute("produce-inside"));
                if (el.GetAttribute("production-rate") != "")
                {
                    t.ProductionRate = LoadInteger(el, "production-rate");
                }
                t.ProduceFrom1 = LoadItem(el, "produce-from1");
                t.ProduceFrom2 = LoadItem(el, "produce-from2");
                t.ProduceAs    = ItemType.Get(el.GetAttribute("produce-as"));

                // Mutation
                if (el.GetAttribute("radiation-effect") != "")
                {
                    t.RadiationEffect = LoadInteger(el, "radiation-effect");
                }
                if (el.GetAttribute("radiation-from") != "")
                {
                    t.RadiationFrom = LoadInteger(el, "radiation-from");
                }
                if (el.GetAttribute("radiation-to") != "")
                {
                    t.RadiationTo = LoadInteger(el, "radiation-to");
                }
                t.MutatePercent = LoadInteger(el, "mutate-percent");
                t.MutateTo      = ItemType.Get(el.GetAttribute("mutate-to"));

                // Man
                foreach (XmlElement elFood in el.SelectNodes("food"))
                {
                    ItemType it = ItemType.Get(elFood.GetAttribute("name"));
                    t.Food.Add(it);
                }
                t.Medicine      = ItemType.Get(el.GetAttribute("medicine"));
                t.Baby          = ItemType.Get(el.GetAttribute("baby"));
                t.BabyFrom      = ItemType.Get(el.GetAttribute("baby-from"));
                t.BabyTimer     = LoadInteger(el, "baby-timer");
                t.MaxHireAmount = LoadInteger(el, "max-hire-amount");
                t.NoLearn       = (el.GetAttribute("nolearn") == "True");

                // Monster
                LoadSkills(t.Skills, el.SelectNodes("skill"));
                LoadInteger(ref t.Aggression, el.GetAttribute("aggression"));
                LoadInteger(ref t.PackSize, el.GetAttribute("pack-size"));

                // Baby
                foreach (XmlElement elGrowTo in el.SelectNodes("grow-to"))
                {
                    t.GrowTo.Add(ItemType.Get(elGrowTo.GetAttribute("name")));
                }

                // Weapon
                t.WeaponSkill = SkillType.Get(el.GetAttribute("weapon-skill"));
                if (el.GetAttribute("ranged") != "")
                {
                    t.Ranged = Convert.ToBoolean(el.GetAttribute("ranged"));
                }
                if (el.GetAttribute("heavy") != "")
                {
                    t.Heavy = Convert.ToBoolean(el.GetAttribute("ranged"));
                }
                if (el.GetAttribute("anti-tank") != "")
                {
                    t.AntiTank = Convert.ToBoolean(el.GetAttribute("anti-tank"));
                }
                if (el.GetAttribute("explosive") != "")
                {
                    t.Explosive = Convert.ToBoolean(el.GetAttribute("explosive"));
                }
                if (el.GetAttribute("ammo") != "")
                {
                    t.Ammo = ItemType.Get(el.GetAttribute("ammo"));
                }
                if (el.GetAttribute("case") != "")
                {
                    t.Case = ItemType.Get(el.GetAttribute("case"));
                }
                LoadInteger(ref t.ToWound, el.GetAttribute("wound-chance"));
                LoadInteger(ref t.HitModifier, el.GetAttribute("hit-modifier"));
                LoadInteger(ref t.ArmorModifier, el.GetAttribute("armor-modifier"));
                LoadInteger(ref t.Attacks, el.GetAttribute("attacks"));
                LoadInteger(ref t.Targets, el.GetAttribute("targets"));
                LoadInteger(ref t.Lethality, el.GetAttribute("lethality"));
                LoadInteger(ref t.HP, el.GetAttribute("hp"));

                // Armor
                t.ArmorSave = LoadInteger(el, "armor-save");
            }

            // Chosen
            LoadSkills(ChosenSkills, doc.SelectNodes("data/chosen/skill"));
            LoadItems(ChosenItems, doc.SelectNodes("data/chosen/item"));
        }
Exemple #2
0
        public static void Load(string folder)
        {
            if (folder == "")
            {
                folder = Directory.GetCurrentDirectory();
            }
            DirectoryInfo di = new DirectoryInfo(folder);

            foreach (FileInfo fi in di.GetFiles("request.*"))
            {
                TextReader tr = new StreamReader(fi.FullName, Encoding.GetEncoding(1251));

                string email        = "";
                string faction_name = "Faction";
                string gender       = "MAN";
                string chosen_name  = NameGenerator.Name(gender);
                Lang   lng          = Lang.En;
                bool   body         = false;

                while (true)
                {
                    string s = tr.ReadLine();
                    if (s == null)
                    {
                        break;
                    }
                    if (s.Trim() == "")
                    {
                        body = true;
                    }

                    if (s.IndexOf(":") == -1)
                    {
                        continue;
                    }
                    string name = s.Substring(0, s.IndexOf(":")).ToLower();
                    string val  = s.Substring(s.IndexOf(":") + 2);

                    if (name == "from")
                    {
                        email = val;
                    }

                    if (!body)
                    {
                        continue;
                    }

                    if (name == "faction")
                    {
                        faction_name = val;
                    }
                    if (name == "chosen" && val.ToLower() == "woman")
                    {
                        gender = "WOMA";
                    }
                    if (name == "name")
                    {
                        chosen_name = val;
                    }
                    if (name == "language" && val.ToLower() == "ru")
                    {
                        lng = Lang.Ru;
                    }
                }
                tr.Close();

                if (email != "")
                {
                    // Create new faction
                    Faction f = new Faction();
                    f.Email        = email;
                    f.Name         = faction_name;
                    f.Options.Lang = lng;
                    for (int i = 0; i < 6; i++)
                    {
                        f.Password += (Char)('a' + Constants.Random('z' - 'a'));
                    }

                    // Select region with less faction players and monsters and more wanderers
                    Region r               = Map.Regions[Constants.Random(Map.Regions.Count)];
                    int    with_faction    = 0;
                    int    without_faction = 0;
                    foreach (Person p in r.Persons)
                    {
                        if (!p.Faction.IsNPC || p.Man.IsMonster)
                        {
                            with_faction++;
                        }
                        else
                        {
                            without_faction++;
                        }
                    }

                    int j     = Map.Regions.IndexOf(r);
                    int start = j;
                    while (true)
                    {
                        j++;
                        if (j >= Map.Regions.Count)
                        {
                            j = 0;
                        }
                        if (j == start)
                        {
                            break;
                        }
                        Region r2 = Map.Regions[j];
                        if (r2._radiation >= 90 || r2.Radiation >= 90 || !r2.Terrain.Walking)
                        {
                            continue;
                        }
                        int with_faction2    = 0;
                        int without_faction2 = 0;
                        foreach (Person p in r2.Persons)
                        {
                            if (!p.Faction.IsNPC || p.Man.IsMonster)
                            {
                                with_faction2++;
                            }
                            else
                            {
                                without_faction2++;
                            }
                        }

                        if (with_faction2 < with_faction ||
                            (with_faction2 == with_faction && without_faction2 > without_faction))
                        {
                            r               = r2;
                            with_faction    = with_faction2;
                            without_faction = without_faction2;
                        }
                    }

                    if (r._radiation >= 90 || !r.Terrain.Walking)
                    {
                        throw new Exception("What region you picked you?");
                    }

                    // Create Chosen One
                    Person chosen = new Person(f, r);
                    chosen.Chosen   = true;
                    chosen.Name     = chosen_name;
                    chosen.Avoiding = true;

                    chosen.AddItems(ItemType.Get(gender), 1);
                    foreach (Item itm in DataFile.ChosenItems)
                    {
                        chosen.AddItems(itm.Type, itm.Amount);
                    }
                    foreach (Skill sk in DataFile.ChosenSkills)
                    {
                        chosen.AddSkill(sk.Type).Level = sk.Level;
                    }

                    // Show all buildable objects
                    foreach (Skill sk in chosen.Skills)
                    {
                        foreach (BuildingType bt in BuildingType.List)
                        {
                            if (!bt.NoBuild && bt.Materials.Count > 0 &&
                                bt.Materials[0].Type.InstallSkill.Type == sk.Type)
                            {
                                f.ShowBuilding(bt);
                            }
                        }
                    }

                    Console.WriteLine("..Faction created for " + email);
                }
            }
        }