/// <summary>
        /// This function will receive a Universe and a StarDefaultSettings object and create Stars from the data
        /// provided
        /// </summary>
        /// <param name="universe"></param>
        /// <param name="starDefaultSettings"></param>
        /// <param name="starData"></param>
        /// <param name="nameGeneration"></param>
        /// <returns>
        /// A newly modified Universe
        /// </returns>
        public Universe AddStars(Universe universe, StarDefaultSettings starDefaultSettings, StarData starData,
                                 NameGeneration nameGeneration)
        {
            // Check if the Stars have been initialized prior
            universe.Stars ??= new List <Star>();

            // Set the number of stars to create. The default is 1d10+20
            var starLen   = starData.Stars.Count;
            var starCount = starDefaultSettings.StarCount < 0
                ? Rand.Next(0, 10) + 20
                : starDefaultSettings.StarCount;

            var sCount = 0;

            while (sCount < starCount)
            {
                var star = new Star();

                // Generate the unique ID for the Star
                IdGen.GenerateId(star);

                // Set Grid Location of the Star
                var zone = universe.Zones[Rand.Next(0, universe.Zones.Count)];
                if (zone.StarId == null)
                {
                    zone.StarId = star.Id;
                }
                else
                {
                    continue;
                }

                // If that ID exists roll a new one
                if (universe.Stars.Exists(a => a.Id == star.Id))
                {
                    continue;
                }

                // Pick a random Name for the Star
                star.Name = Rand.Next(0, 4) == 2
                    ? nameGeneration.GenerateName()
                    : starData.Stars[Rand.Next(0, starLen - 1)];

                // If that Name exists roll a new one
                if (universe.Stars.Exists(a => a.Name == star.Name))
                {
                    continue;
                }

                // Set the type of Star
                star.StarType = starData.StarTypes[Rand.Next(0, 8) + Rand.Next(0, 8) + Rand.Next(0, 8)];

                // Add the Star to the Universe
                universe.Stars.Add(star);

                sCount++;
            }

            return(universe);
        }
Esempio n. 2
0
        public void LoadProgram(string FileName, Stream DataStream)
        {
            int ProcessId = IdGen.GenerateId();

            Process MainProcess = new Process(Ns, Allocator, ProcessId);

            using (MemoryStream Input = new MemoryStream())
            {
                DataStream.CopyTo(Input);

                if (Path.GetExtension(FileName).ToLower() == ".nro")
                {
                    MainProcess.LoadProgram(new Nro(Input));
                }
                else
                {
                    MainProcess.LoadProgram(new Nso(Input));
                }

                DataStream.Dispose();
            }

            MainProcess.SetEmptyArgs();
            MainProcess.InitializeHeap();
            MainProcess.Run();

            Processes.TryAdd(ProcessId, MainProcess);
        }
Esempio n. 3
0
        // Creates a new order with the first artpiece's price updated
        public static Order CreateNewOrder(Artpiece artpiece)
        {
            // Obtain customer from session
            Customer customer = (Customer)Net.GetSession("customer");

            Order order = new Order();

            //OrderID Generator
            IdGen IdGen = new IdGen();

            order.OrderId = IdGen.GenerateId("Order");

            order.CustomerId = customer.Id;             // Get customer ID
            order.TotalPrice = artpiece.Price;          // Set total price;

            return(order);
        }
Esempio n. 4
0
        public void LoadCart(string ExeFsDir, string RomFsFile = null)
        {
            if (RomFsFile != null)
            {
                Ns.VFs.LoadRomFs(RomFsFile);
            }

            int ProcessId = IdGen.GenerateId();

            Process MainProcess = new Process(Ns, Allocator, ProcessId);

            void LoadNso(string FileName)
            {
                foreach (string File in Directory.GetFiles(ExeFsDir, FileName))
                {
                    if (Path.GetExtension(File) != string.Empty)
                    {
                        continue;
                    }

                    Logging.Info($"Loading {Path.GetFileNameWithoutExtension(File)}...");

                    using (FileStream Input = new FileStream(File, FileMode.Open))
                    {
                        Nso Program = new Nso(Input);

                        MainProcess.LoadProgram(Program);
                    }
                }
            }

            LoadNso("rtld");

            MainProcess.SetEmptyArgs();

            LoadNso("main");
            LoadNso("subsdk*");
            LoadNso("sdk");

            MainProcess.InitializeHeap();
            MainProcess.Run();

            Processes.TryAdd(ProcessId, MainProcess);
        }
Esempio n. 5
0
        public void LoadProgram(string FileName)
        {
            bool IsNro = Path.GetExtension(FileName).ToLower() == ".nro";

            int ProcessId = IdGen.GenerateId();

            Process MainProcess = new Process(Ns, Allocator, ProcessId);

            using (FileStream Input = new FileStream(FileName, FileMode.Open))
            {
                MainProcess.LoadProgram(IsNro
                    ? (IExecutable) new Nro(Input)
                    : (IExecutable) new Nso(Input));
            }

            MainProcess.SetEmptyArgs();
            MainProcess.InitializeHeap();
            MainProcess.Run(IsNro);

            Processes.TryAdd(ProcessId, MainProcess);
        }
Esempio n. 6
0
        private void pay()
        {
            // Get customer details
            Customer customer = (Customer)Net.GetSession("customer");

            // Get count
            List <Order_Artwork> oaList = (List <Order_Artwork>)Net.GetSession("oaList");
            int    itemCount            = oaList.Count;
            double total = 0;

            // Create order
            Order order = (Order)Net.GetSession("order");
            IdGen IdGen = new IdGen();

            order.OrderId         = IdGen.GenerateId("custorder");
            order.OrderDate       = DateTime.Now;
            order.IsCanceled      = false;
            order.CustomerId      = customer.Id;
            order.DeliveryAddress = txtAddress.Text;


            foreach (Order_Artwork oa in oaList)
            {
                // Cumulate price
                ArtpieceDao      dao      = new ArtpieceDao();
                Classes.Artpiece artpiece = dao.Get("ARTPIECEID", oa.ArtpieceId);

                total += oa.Quantity * artpiece.Price;


                // Set Foreign Keys
                oa.ArtpieceId = artpiece.ArtpieceId;
                oa.OrderId    = order.OrderId;

                // Update stocks
                artpiece.Stocks = artpiece.Stocks - oa.Quantity;

                // Update artpiece
                ArtpieceDao artpieceDao = new ArtpieceDao();
                artpieceDao.Update(artpiece);
            }

            // Set cumulated price as total price
            order.TotalPrice = total;

            // Insert order
            CustorderDao custorderDao = new CustorderDao();

            custorderDao.Add(order);

            // Insert OrderArtwork
            foreach (Order_Artwork oa in oaList)
            {
                OrderArtworkDao orderArtworkDao = new OrderArtworkDao();
                orderArtworkDao.Add(oa);
            }

            // Send receipt
            sendReceipt(order, oaList, customer.Email);

            // Clear cart
            Net.SetSession("order", new Order());
            Net.SetSession("oaList", new List <Order_Artwork>());
            Net.SetSession("cartSaved", false);
        }
        /// <summary>
        /// This function handles all Character creation. Should receive a Universe to edit and a set of
        /// CharacterDefaultSettings that will be used to set defaults.
        /// </summary>
        /// <param name="universe"></param>
        /// <param name="characterDefaultSettings"></param>
        /// <param name="charData"></param>
        /// <param name="nameGenerations"></param>
        /// <returns>The newly modified universe</returns>
        public Universe AddCharacters(Universe universe, CharacterDefaultSettings characterDefaultSettings,
                                      CharData charData, List <NameGeneration> nameGenerations)
        {
            // If no Characters have been created on the Universe then give it an empty list of them.
            universe.Characters ??= new List <Character>();

            // Set the number of characters you want to create. Default is 1.
            var count = characterDefaultSettings.Count < 0
                ? 1
                : characterDefaultSettings.Count;

            var cCount = 0;

            while (cCount < count)
            {
                // Create the character with the specified first and last name
                var character = new Character();

                // Generate a randomized ID for the new Character
                IdGen.GenerateId(character);

                // If the created ID happens to exist (unlikely) then just continue and create a new one
                if (universe.Characters.Exists(a => a.Id == character.Id))
                {
                    continue;
                }

                // Set sheet bounds including sheet# and row count.
                // Must be done here to randomly select the sheet
                var gender = characterDefaultSettings.Gender != Character.GenderEnum.Undefined
                    ? characterDefaultSettings.Gender == Character.GenderEnum.Male ? 0 : 1
                    : Rand.Next(0, 2);

                // Get the list of names for the specified gender
                var firstNameList  = gender == 0 ? charData.MaleName : charData.FemaleName;
                var nameGeneration = gender == 0 ? nameGenerations[0] : nameGenerations[1];

                // Set the number of items in each list to be used for the max value in rand.Next()
                var firstCount     = firstNameList.Count;
                var lastCount      = charData.LastName.Count;
                var hairColorCount = charData.HairColor.Count;
                var hairStyleCount = charData.HairStyle.Count;
                var eyeColorCount  = charData.EyeColor.Count;

                // Grab random values from their respective lists or use provided values
                character.First = string.IsNullOrEmpty(characterDefaultSettings.First)
                    ? Rand.Next(0, 4) == 1
                        ? nameGeneration.GenerateName()
                        : firstNameList[Rand.Next(0, firstCount - 1)]
                    : characterDefaultSettings.First;
                character.Last = string.IsNullOrEmpty(characterDefaultSettings.Last)
                    ? charData.LastName[Rand.Next(0, lastCount - 1)]
                    : characterDefaultSettings.Last;
                character.Age = characterDefaultSettings.Age == null || characterDefaultSettings.Age.Length == 0 ||
                                characterDefaultSettings.Age[0] == -1 || characterDefaultSettings.Age[1] == -1
                                // This creates Ages on a bell-curve where it's more likely to land somewhere around 30-45
                                // with a minimum of 15
                    ? Rand.Next(5, 22) + Rand.Next(5, 23) + Rand.Next(5, 23)
                    : Rand.Next(characterDefaultSettings.Age[0], characterDefaultSettings.Age[1]);
                character.Gender  = (Character.GenderEnum)gender;
                character.HairCol = string.IsNullOrEmpty(characterDefaultSettings.HairCol)
                    ? charData.HairColor[Rand.Next(0, hairColorCount)]
                    : characterDefaultSettings.HairCol;
                character.HairStyle = string.IsNullOrEmpty(characterDefaultSettings.HairStyle)
                    ? charData.HairStyle[Rand.Next(0, hairStyleCount)]
                    : characterDefaultSettings.HairStyle;
                character.EyeCol = string.IsNullOrEmpty(characterDefaultSettings.EyeCol)
                    ? charData.EyeColor[Rand.Next(0, eyeColorCount)]
                    : characterDefaultSettings.EyeCol;
                character.Title = string.IsNullOrEmpty(characterDefaultSettings.Title)
                    ? null
                    : characterDefaultSettings.Title;
                character.BirthPlanet     = universe.Planets?[Rand.Next(0, universe.Planets.Count)].Id;
                character.CurrentLocation = Rand.Next(0, 100) < 5
                    ? universe.Planets?[Rand.Next(0, universe.Planets.Count)].Id
                    : character.BirthPlanet;
                character.CrimeChance = characterDefaultSettings.CrimeChance == null ||
                                        characterDefaultSettings.CrimeChance.Length == 0 ||
                                        characterDefaultSettings.CrimeChance[0] == -1 ||
                                        characterDefaultSettings.CrimeChance[1] == -1
                    ? Rand.Next(1, 26) + Rand.Next(0, 25) + // Default chance up to 50%
                                        (Rand.Next(0, 4) != 1
                          ? 0
                          : Rand.Next(1, 26) + Rand.Next(0, 25)) // 25% Additional crime roll chance
                    : Rand.Next(characterDefaultSettings.CrimeChance[0], characterDefaultSettings.CrimeChance[1] + 1);
                character.ShipId = string.IsNullOrEmpty(characterDefaultSettings.ShipId)
                    ? null
                    : characterDefaultSettings.ShipId;

                character.InitialReaction = (Rand.Next(0, 6) + Rand.Next(0, 6)) switch
                {
                    0 => charData.InitialReactions[0],
                    {} n when(n >= 1 && n <= 3) => charData.InitialReactions[1],
                    {
                    }

                    n when(n >= 4 && n <= 6) => charData.InitialReactions[2],
                    {
                    }

                    n when(n >= 7 && n <= 9) => charData.InitialReactions[3],
                    10 => charData.InitialReactions[4],
                    _ => charData.InitialReactions[2]
                };

                // Add the Character to the list of Characters in the universe
                universe.Characters.Add(character);

                cCount++;
            }

            // Re-order the list of Characters by their first name.
            universe.Characters = universe.Characters.OrderBy(c => c.First).ToList();

            return(universe);
        }
    }
        public Universe AddProblems(Universe universe, ProblemDefaultSettings problemDefaultSettings, ProblemData problemData)
        {
            if (universe.Problems == null)
            {
                universe.Problems = new List <Problem>();
            }

            var count = problemDefaultSettings.Count < 0
                ? 5
                : problemDefaultSettings.Count;

            var add = problemDefaultSettings.Additive;

            var id = string.IsNullOrEmpty(problemDefaultSettings.Id)
                ? null
                : problemDefaultSettings.Id;

            if (id != null)
            {
                var locId = (from planets in universe.Planets select new { ID = planets.Id })
                            .Union(from stars in universe.Stars select new { ID = stars.Id })
                            .Single(a => a.ID == id).ID;

                if (string.IsNullOrEmpty(locId))
                {
                    throw new FileNotFoundException("No locations with ID " + id + " found");
                }

                var probCount = 0;
                while (probCount < count)
                {
                    if (count <= universe.Problems.Count(a => a.LocationId == locId) &&
                        !add)
                    {
                        break;
                    }

                    var problem = new Problem();

                    IdGen.GenerateId(problem);
                    problem.LocationId = locId;
                    var conflict = problemData.Conflicts[Rand.Next(0, problemData.Conflicts.Count)];
                    problem.ConflictType = conflict.Type;
                    problem.Situation    = conflict.Situations[Rand.Next(0, 5)];
                    problem.Focus        = conflict.Focuses[Rand.Next(0, 5)];
                    problem.Restraint    = problemData.Restraints[Rand.Next(0, 20)];
                    problem.Twist        = problemData.Twists[Rand.Next(0, 20)];

                    universe.Problems.Add(problem);

                    probCount++;
                }
            }
            else
            {
                foreach (Planet planet in universe.Planets)
                {
                    var probCount = 0;
                    while (probCount < count)
                    {
                        if (probCount + count <= universe.Problems.Count(a => a.LocationId == planet.Id) &&
                            !add)
                        {
                            break;
                        }

                        var problem = new Problem();

                        IdGen.GenerateId(problem);
                        problem.LocationId = planet.Id;
                        var conflict = problemData.Conflicts[Rand.Next(0, problemData.Conflicts.Count)];
                        problem.ConflictType = conflict.Type;
                        problem.Situation    = conflict.Situations[Rand.Next(0, 5)];
                        problem.Focus        = conflict.Focuses[Rand.Next(0, 5)];
                        problem.Restraint    = problemData.Restraints[Rand.Next(0, 20)];
                        problem.Twist        = problemData.Twists[Rand.Next(0, 20)];

                        universe.Problems.Add(problem);

                        probCount++;
                    }
                }

                //TODO: Add more locations for problems
            }

            return(universe);
        }
Esempio n. 9
0
        public Universe AddAliens(Universe universe, AlienDefaultSettings alienDefaultSettings, AlienData alienData)
        {
            // If no Characters have been created on the Universe then give it an empty list of them.
            universe.Aliens ??= new List <Alien>();

            var count = alienDefaultSettings.Count < 0
                ? Rand.Next(0, universe.Planets.Count)
                : alienDefaultSettings.Count;

            var bCount = alienDefaultSettings.BodyTraitCount < 0
                ? -1
                : alienDefaultSettings.BodyTraitCount;

            //Generate an Alien
            var aCount = 0;

            while (aCount < count)
            {
                var alien = new Alien();

                IdGen.GenerateId(alien);

                if (universe.Aliens.Exists(a => a.Id == alien.Id))
                {
                    continue;
                }

                alien.BodyTraits = new List <string>();

                // Alien Body Traits
                if (bCount > 0)
                {
                    var bCounter = 0;

                    while (bCounter < bCount)
                    {
                        var trait = alienData.BodyTraits[Rand.Next(0, alienData.BodyTraits.Count)];
                        if (!alien.BodyTraits.Contains(trait))
                        {
                            alien.BodyTraits.Add(trait);
                        }
                        else
                        {
                            continue;
                        }

                        bCounter++;
                    }
                }
                else // If there were no traits passed in, pick random
                {
                    while (true)
                    {
                        var trait = alienData.BodyTraits[Rand.Next(0, alienData.BodyTraits.Count)];
                        if (!alien.BodyTraits.Contains(trait))
                        {
                            alien.BodyTraits.Add(trait);
                        }
                        else
                        {
                            continue;
                        }

                        if (Rand.Next(0, 6) == 0)
                        {
                            continue;
                        }
                        break;
                    }
                }

                alien.Lenses = new List <string>();
                // Alien Lenses
                if (alienDefaultSettings.Lenses == null || alienDefaultSettings.Lenses.Count == 0)
                {
                    var lCount   = Rand.Next(0, 2) + 1;
                    var lCounter = 0;

                    while (lCounter < lCount)
                    {
                        var lens = alienData.Lenses[Rand.Next(0, alienData.Lenses.Count)].Type;
                        if (!alien.Lenses.Contains(lens))
                        {
                            alien.Lenses.Add(lens);
                        }
                        else
                        {
                            continue;
                        }

                        lCounter++;
                    }
                }
                else
                {
                    alien.Lenses = alienDefaultSettings.Lenses;
                }

                alien.SocialStructures = new List <string>();
                // Alien Social Structure
                if (Rand.Next(0, 2) == 0)
                {
                    alien.SocialStructures.Add(alienData
                                               .SocialStructures[Rand.Next(0, alienData.SocialStructures.Count)].Type);
                }
                else
                {
                    var sCounter = 0;
                    var sCount   = Rand.Next(0, 3) + 1;
                    alien.MultiPolarType = Rand.Next(0, 2) == 0 ? "Cooperative" : "Competitive";
                    while (sCounter < sCount)
                    {
                        var type = alienData.SocialStructures[Rand.Next(0, alienData.SocialStructures.Count)].Type;
                        if (!alien.SocialStructures.Contains(type))
                        {
                            alien.SocialStructures.Add(type);
                        }
                        else
                        {
                            continue;
                        }

                        sCounter++;
                    }
                }

                universe.Aliens.Add(alien);

                aCount++;
            }

            universe.Aliens = universe.Aliens.OrderBy(a => a.Id).ToList();

            return(universe);
        }
Esempio n. 10
0
        public Universe AddPoi(Universe universe, PoiDefaultSettings poiDefaultSettings, PoiData poiData)
        {
            universe.PointsOfInterest ??= new List <PointOfInterest>();

            var starId = string.IsNullOrEmpty(poiDefaultSettings.StarId)
                ? null
                : poiDefaultSettings.StarId;

            if (starId == null)
            {
                foreach (var star in universe.Stars)
                {
                    var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 ||
                              poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1
                        ? Rand.Next(2, 5)
                        : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1);

                    var poiCount = 0;

                    while (poiCount < max)
                    {
                        var poi = new PointOfInterest();

                        // Generate a POI ID
                        IdGen.GenerateId(poi);

                        if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id))
                        {
                            continue;
                        }

                        // Set the POI information with randomized data
                        poi.StarId = star.Id;
                        universe.Zones.Single(a => a.StarId == star.Id).PointsOfInterest.Add(poi.Id);
                        poi.Name = star.Name + " " + ToRoman(poiCount + 1);
                        var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)];
                        poi.Type       = type.Type;
                        poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)];
                        poi.Situation  = type.Situation[Rand.Next(0, type.Situation.Count)];

                        universe.PointsOfInterest.Add(poi);

                        poiCount++;
                    }
                }
            }
            else
            {
                var locId = (from stars in universe.Stars select new { ID = stars.Id })
                            .Single(a => a.ID == starId).ID;

                if (string.IsNullOrEmpty(locId))
                {
                    throw new FileNotFoundException("No locations with ID " + starId + " found");
                }

                var max = poiDefaultSettings.PoiRange == null || poiDefaultSettings.PoiRange.Length == 0 ||
                          poiDefaultSettings.PoiRange[0] == -1 || poiDefaultSettings.PoiRange[1] == -1
                    ? Rand.Next(1, 5)
                    : Rand.Next(poiDefaultSettings.PoiRange[0], poiDefaultSettings.PoiRange[1] + 1);

                var poiCount = 0;

                while (poiCount < max)
                {
                    var poi = new PointOfInterest();

                    // Generate a POI ID
                    IdGen.GenerateId(poi);

                    if (universe.PointsOfInterest.Exists(a => a.Id == poi.Id))
                    {
                        continue;
                    }

                    // Set the POI information with randomized data
                    poi.StarId = starId;
                    universe.Zones.Single(a => a.StarId == starId).PointsOfInterest.Add(poi.Id);
                    poi.Name = universe.Stars.Single(a => a.Id == starId).Name + " " + ToRoman(poiCount + 1);
                    var type = poiData.PointsOfInterest[Rand.Next(0, poiData.PointsOfInterest.Count)];
                    poi.Type       = type.Type;
                    poi.OccupiedBy = type.OccupiedBy[Rand.Next(0, type.OccupiedBy.Count)];
                    poi.Situation  = type.Situation[Rand.Next(0, type.Situation.Count)];

                    universe.PointsOfInterest.Add(poi);

                    poiCount++;
                }
            }

            return(universe);
        }
Esempio n. 11
0
        /// <summary>
        /// This function receives a Universe and a PlanetDefaultSettings to create planets based on
        /// specified information
        /// </summary>
        /// <param name="universe"></param>
        /// <param name="planetDefaultSettings"></param>
        /// <param name="worldInfo"></param>
        /// <param name="starData"></param>
        /// <param name="societyData"></param>
        /// <param name="nameGeneration"></param>
        /// <returns>
        /// The newly updated Universe
        /// </returns>
        public Universe AddPlanets(Universe universe, PlanetDefaultSettings planetDefaultSettings, WorldInfo worldInfo,
                                   StarData starData, SocietyData societyData, NameGeneration nameGeneration)
        {
            // Get the number of Planet Names from starData
            var planLen = starData.Planets.Count;

            // Iterate through each star and
            foreach (Star star in universe.Stars)
            {
                // Set the random number of Planets that will be created for a given Star
                var pMax = planetDefaultSettings.PlanetRange == null || planetDefaultSettings.PlanetRange.Length == 0 ||
                           planetDefaultSettings.PlanetRange[0] == 0 ||
                           planetDefaultSettings.PlanetRange[1] == 0
                    ? Rand.Next(1, 3) // Default Planet count is up-to 3
                    : Rand.Next(planetDefaultSettings.PlanetRange[0],
                                planetDefaultSettings.PlanetRange[1] + 1);

                var pCount = 0;

                while (pCount < pMax)
                {
                    var planet = new Planet
                    {
                        Society = new Society(), Ruler = new Ruler(), Ruled = new Ruled(), Flavor = new Flavor()
                    };

                    // Generate the ID for the Planet
                    IdGen.GenerateId(planet);

                    // If that ID exists somewhere then re-roll it
                    if (universe.Planets.Exists(a => a.Id == planet.Id))
                    {
                        continue;
                    }

                    // Pick a random name out of the list of Planets
                    planet.Name = Rand.Next(0, 4) == 2
                        ? nameGeneration.GenerateName()
                        : starData.Planets[Rand.Next(0, planLen)];

                    // No planets can share a name
                    if (universe.Planets.Exists(a => a.Name == planet.Name))
                    {
                        continue;
                    }

                    // Set the Planet information from either a randomized value or specified information
                    planet.StarId = star.Id;
                    universe.Zones.Single(a => a.StarId == star.Id).Planets.Add(planet.Id);
                    planet.FirstWorldTag  = worldInfo.WorldTags[Rand.Next(0, 100)].Type;
                    planet.SecondWorldTag = worldInfo.WorldTags[Rand.Next(0, 100)].Type;
                    planet.Atmosphere     = worldInfo.Atmospheres[Rand.Next(0, 6) + Rand.Next(0, 6)].Type;
                    planet.Temperature    = worldInfo.Temperatures[Rand.Next(0, 6) + Rand.Next(0, 6)].Type;
                    planet.Biosphere      = worldInfo.Biospheres[Rand.Next(0, 6) + Rand.Next(0, 6)].Type;
                    planet.Population     = worldInfo.Populations[Rand.Next(0, 6) + Rand.Next(0, 6)].Type;
                    planet.TechLevel      = worldInfo.TechLevels[Rand.Next(0, 6) + Rand.Next(0, 6)].Type;

                    if (societyData != null)
                    {
                        // Set the Planet's society information
                        planet.Society.PriorCulture      = societyData.Societies.PriorCultures[Rand.Next(0, 6)];
                        planet.Society.OtherSociety      = societyData.Societies.OtherSocieties[Rand.Next(0, 8)];
                        planet.Society.MainRemnant       = societyData.Societies.MainRemnants[Rand.Next(0, 10)];
                        planet.Society.SocietyAge        = societyData.Societies.SocietyAges[Rand.Next(0, 4)];
                        planet.Society.ImportantResource = societyData.Societies.ImportantResources[Rand.Next(0, 12)];
                        planet.Society.FoundingReason    = societyData.Societies.FoundingReasons[Rand.Next(0, 20)];

                        // Set the Planet's Ruler
                        planet.Ruler.GeneralSecurity   = societyData.Rulers.GeneralSecurities[Rand.Next(0, 6)];
                        planet.Ruler.LegitimacySource  = societyData.Rulers.LegitimacySources[Rand.Next(0, 8)];
                        planet.Ruler.MainRulerConflict = societyData.Rulers.MainRulerConflicts[Rand.Next(0, 10)];
                        planet.Ruler.RuleCompletion    = societyData.Rulers.RuleCompletions[Rand.Next(0, 4)];
                        planet.Ruler.RuleForm          = societyData.Rulers.RuleForms[Rand.Next(0, 12)];
                        planet.Ruler.MainPopConflict   = societyData.Rulers.MainPopConflicts[Rand.Next(0, 20)];

                        // Set the Planet's Ruled
                        planet.Ruled.Contentment     = societyData.Ruled.Contentments[Rand.Next(0, 6)];
                        planet.Ruled.LastMajorThreat = societyData.Ruled.LastMajorThreats[Rand.Next(0, 8)];
                        planet.Ruled.Power           = societyData.Ruled.Powers[Rand.Next(0, 10)];
                        planet.Ruled.Uniformity      = societyData.Ruled.Uniformities[Rand.Next(0, 4)];
                        planet.Ruled.MainConflict    = societyData.Ruled.MainConflicts[Rand.Next(0, 12)];
                        planet.Ruled.Trends          = societyData.Ruled.Trends[Rand.Next(0, 20)];

                        // Set the Planet's Flavor
                        planet.Flavor.BasicFlavor       = societyData.Flavors.BasicFlavors[Rand.Next(0, 12)];
                        planet.Flavor.OutsiderTreatment = societyData.Flavors.OutsiderTreatments[Rand.Next(0, 6)];
                        planet.Flavor.PrimaryVirtue     = societyData.Flavors.PrimaryVirtues[Rand.Next(0, 8)];
                        planet.Flavor.PrimaryVice       = societyData.Flavors.PrimaryVices[Rand.Next(0, 10)];
                        planet.Flavor.XenophiliaDegree  = societyData.Flavors.XenophiliaDegrees[Rand.Next(0, 4)];
                        planet.Flavor.PossiblePatron    = societyData.Flavors.PossiblePatrons[Rand.Next(0, 12)];
                        planet.Flavor.Customs           = societyData.Flavors.Customs[Rand.Next(0, 20)];
                    }

                    // Set primary world
                    if (pCount == 0)
                    {
                        planet.IsPrimary = true;
                    }
                    else
                    {
                        // Non-primary world information
                        planet.Origin       = worldInfo.OwOrigins[Rand.Next(0, 8)];
                        planet.Relationship = worldInfo.OwRelationships[Rand.Next(0, 8)];
                        planet.Contact      = worldInfo.OwContacts[Rand.Next(0, 8)];
                        planet.IsPrimary    = false;
                    }

                    // Add the Planet to the current Universe
                    universe.Planets.Add(planet);
                    pCount++;
                }
            }

            return(universe);
        }
Esempio n. 12
0
        protected void uploadBt_Click(object sender, EventArgs e)
        {
            // Validate form first

            string errorMsg = ValidateForm();

            if (errorMsg != null)             // If there is an error
            {
                // Set the error msg
                lblUploadError = FormatLbl.Error(errorMsg);
            }
            else             // If there is no error
            {
                // Obtain artist info
                Artist artist = (Artist)Session["artist"];

                // Generate Artpiece Id
                IdGen  IdGen      = new IdGen();
                String ArtpieceId = IdGen.GenerateId("Artpiece");

                // Obtain the values from the form
                Classes.Artpiece artpiece = new Classes.Artpiece();
                artpiece.ArtpieceId = ArtpieceId;
                artpiece.ArtistId   = artist.Id;
                artpiece.Tags       = txtTags.Text;
                artpiece.About      = txtDescription.Text;
                artpiece.Title      = txtTitle.Text;
                artpiece.Price      = Convert.ToDouble(txtPrice.Text);

                artpiece.Stocks = Convert.ToInt32(txtStocks.Text);                  // Need to validate

                // NOTE! NEED TO CHANGE TO DROPDOWNLIST
                if (rblForSale.SelectedValue == "yes")                 // If the artpiece is for sale
                {
                    artpiece.IsForSale = true;
                }
                else
                {
                    artpiece.IsForSale = false;
                }

                // NOTE! NEED TO CHANGE TO DROPDOWNLIST
                if (rblIsPublic.SelectedValue == "yes")                 // If the artpiece is public
                {
                    artpiece.IsPublic = true;
                }
                else
                {
                    artpiece.IsPublic = false;
                }

                //debug
                Quick.Print("selected forsale is " + rblIsPublic.SelectedValue);

                FileUtil file = new FileUtil(fileBt, "~/Pics/");

                // Set image link
                artpiece.ImageLink = file.GetAddress();

                // VERIFY THAT IMAGE LINK DOES NOT HAVE DUPLICATE NAME
                ArtpieceDao      linkCheckDao  = new ArtpieceDao();
                Classes.Artpiece checkArtpiece = linkCheckDao.Get("IMAGELINK", file.GetAddress());

                if (checkArtpiece != null)                 // If there is a duplicate file name
                {
                    // Set the error msg
                    lblUploadError = FormatLbl.Error("An image with that name already exists. Please rename.");
                }
                else                 // If there is no duplicate
                {
                    Quick.Print(file.GetFileName().Substring(file.GetFileName().Length - 4));
                    // Check file type
                    if (file.GetFileName().Substring(file.GetFileName().Length - 4) != ".jpg" && file.GetFileName().Substring(file.GetFileName().Length - 4) != ".png" && file.GetFileName().Substring(file.GetFileName().Length - 5) != ".jpeg")
                    {
                        // Show error
                        lblUploadError = FormatLbl.Error("File must be a picture file that ends in jpg, png, or jpeg");
                    }
                    else
                    {
                        // Perform file upload
                        file.PerformUpload();

                        // Perform database insert
                        ArtpieceDao dao = new ArtpieceDao();
                        dao.Add(artpiece);

                        //To redirect user to the new artpiece
                        Response.Redirect("~/Pages/artpiece.aspx?Id=" + artpiece.ArtpieceId);
                    }
                }
            }
        }