public IEntity Generate(int breedId = -1)
        {
            var  rand          = new Random();
            var  breed         = breedId == -1 ? Breeds.ElementAt(rand.Next(0, Breeds.Count)) : Breeds.FirstOrDefault(x => x.Id == breedId);
            byte gender        = (byte)(rand.Next(100) >= 50 ? 1 : 0);
            var  possibleHeads = Heads.Where(x => x.Breed == breed.Id && x.Gender == gender);
            var  head          = possibleHeads.ElementAt(rand.Next(0, possibleHeads.Count()));

            var look = EntityLookParser.Parse(gender == 0 ? breed.MaleLook : breed.FemaleLook);

            var entity          = EntityFactory.Instance.CreateCharacter();
            var entityLook      = entity.Look();
            var entityCharacter = entity.Character();
            var entityStats     = entity.Stats();

            entityLook.Name    = "ByPass" + Guid.NewGuid().ToString().Substring(0, 4);
            entityLook.BonesId = look.BonesId;
            entityLook.AddSkin(short.Parse(head.Skin));
            entityLook.IndexedColors.AddRange(gender == 0 ? breed.MaleColors : breed.FemaleColors);
            entityLook.Scales.AddRange(look.Scales);
            entityCharacter.BreedId = breed.Id;
            entityCharacter.Gender  = gender == 1;
            entityStats.Stats       = new StatCollection();

            return(entity);
        }
Beispiel #2
0
        public NABSA(string path)
        {
            Source = XElement.Load(path);

            Name = Path.GetFileNameWithoutExtension(path);

            // General Data
            SingleParams = Source.Element("SingleParams");

            // Land Data
            LandSpecs = Source.Element("LandSpecs");

            // Labour Data
            Priority = FindByNameTag(Source, "Labour Number and Priority");
            Supply   = FindByNameTag(Source, "Labour Supply");

            // Ruminant Data
            SuppAllocs = FindFirst(Source, "SuppAllocs");
            SuppSpecs  = FindFirst(Source, "SuppSpecs");
            RumSpecs   = FindFirst(Source, "RumSpecs");
            Numbers    = FindByNameTag(Source, "Startup ruminant numbers");
            Ages       = FindByNameTag(Source, "Startup ruminant ages");
            Weights    = FindByNameTag(Source, "Startup ruminant weights");
            Prices     = FindByNameTag(Source, "Ruminant prices");

            Fodder      = FindFirst(Source, "Fodder");
            FodderSpecs = FindFirst(Source, "FodderSpecs");

            // List of all possible breeds
            Breeds = SuppAllocs.Element("ColumnNames").Elements().Select(e => e.Value).ToList();

            // Index of each breed
            var indices = from breed in Breeds
                          select Breeds.IndexOf(breed);

            // Breeds that have a presence in the simulation
            PresentBreeds = from index in indices
                            where (
                // The total number of each breed
                from cohort in Numbers.Elements().Skip(1)
                select Convert.ToInt32(cohort.Elements().ToList()[index].Value)
                ).Sum() > 0
                            // Breeds with a non-zero number of ruminants present
                            select Breeds.ElementAt(index);
        }