Пример #1
0
        public Person(string fName, string lName, bool male, bool isHacker = false, string handle = null)
        {
            this.firstName = fName;
            this.lastName  = lName;
            this.isMale    = male;
            if (handle == null)
            {
                handle = UsernameGenerator.getName();
            }
            if (handle == null)
            {
                throw new InvalidOperationException();
            }
            this.handle     = handle;
            this.isHacker   = isHacker;
            this.birthplace = WorldLocationLoader.getRandomLocation();
            this.vehicles   = new List <VehicleRegistration>();
            this.degrees    = new List <Degree>();
            this.addRandomDegrees();
            this.addRandomVehicles();
            int num1 = 18;
            int num2 = 72;

            if (isHacker)
            {
                num2 = 45;
            }
            this.DateOfBirth   = DateTime.Now - TimeSpan.FromDays((double)(num1 * 365 + (int)(Utils.random.NextDouble() * (double)(num2 - num1) * 365.0)));
            this.medicalRecord = new MedicalRecord(this.birthplace, this.DateOfBirth);
            if (!Settings.EnableDLC || !DLC1SessionUpgrader.HasDLC1Installed || !isHacker && (double)Utils.randm(1f) >= 0.800000011920929)
            {
                return;
            }
            this.NeopalsAccount = NeopalsAccount.GenerateAccount(handle, Utils.flipCoin() && Utils.flipCoin() && isHacker && handle.ToLower() != "bit");
        }
Пример #2
0
        public static NeopalsAccount GenerateAccount(string handle, bool isActiveUser = false)
        {
            NeopalsAccount neopalsAccount = new NeopalsAccount()
            {
                AccountName = handle, NeoPoints = isActiveUser ? (long)Utils.random.Next(50000) : (long)Utils.random.Next(5000), BankedPoints = isActiveUser ? (long)Utils.random.Next(10000) : (long)Utils.random.Next(2000), InventoryID = Guid.NewGuid().ToString(), Pets = new List <Neopal>()
            };
            int num = 1 + Utils.random.Next(2);

            if (num == 2 && Utils.flipCoin() && Utils.flipCoin())
            {
                ++num;
            }
            for (int index = 0; index < num; ++index)
            {
                neopalsAccount.Pets.Add(Neopal.GeneratePet(isActiveUser));
            }
            return(neopalsAccount);
        }
Пример #3
0
 private void InitDataset()
 {
     if (this.Dataset != null)
     {
         this.FilenameIsPersonName = this.DataType == typeof(Person);
         for (int index = 0; index < this.Dataset.Count; ++index)
         {
             string dataEntry         = this.CleanXMLForFile(ObjectSerializer.SerializeObject(this.Dataset[index]));
             string filenameForObject = this.GetFilenameForObject(this.Dataset[index]);
             try
             {
             }
             catch (Exception ex)
             {
                 Console.WriteLine("Deserialization error for Generic Object: " + (object)ex);
             }
             this.DatasetFolder.files.Add(new FileEntry(dataEntry, filenameForObject));
         }
     }
     else if (this.DataTypeIdentifier.EndsWith("VehicleInfo"))
     {
         this.FilenameIsPersonName = true;
         this.DataType             = People.all[0].vehicles.GetType();
         for (int index = 0; index < People.all.Count; ++index)
         {
             if (People.all[index].vehicles.Count != 0)
             {
                 string dataEntry = this.CleanXMLForFile(ObjectSerializer.SerializeObject((object)People.all[index].vehicles));
                 List <VehicleRegistration> vehicles = People.all[index].vehicles;
                 try
                 {
                     string filenameForPersonName = this.GetFilenameForPersonName(People.all[index].firstName, People.all[index].lastName);
                     this.DatasetFolder.files.Add(new FileEntry(dataEntry, filenameForPersonName));
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine("Deserialization error for Vehicle: " + (object)ex);
                 }
             }
         }
     }
     else if (this.DataTypeIdentifier.EndsWith("NeopalsAccount"))
     {
         this.FilenameIsPersonName = false;
         this.HasSpecialCaseDraw   = true;
         this.DataType             = typeof(NeopalsAccount);
         if (People.all.Count == 0)
         {
             return;
         }
         for (int index = 0; index < People.all.Count; ++index)
         {
             if (People.all[index].NeopalsAccount != null)
             {
                 string         dataEntry      = this.CleanXMLForFile(ObjectSerializer.SerializeObject((object)People.all[index].NeopalsAccount));
                 NeopalsAccount neopalsAccount = People.all[index].NeopalsAccount;
                 try
                 {
                     string filenameForObject = this.GetFilenameForObject((object)neopalsAccount);
                     this.DatasetFolder.files.Add(new FileEntry(dataEntry, filenameForObject));
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine("Deserialization error for NeopalsAccount: " + (object)ex);
                 }
             }
         }
     }
     else
     {
         if (!this.DataTypeIdentifier.EndsWith("Person"))
         {
             return;
         }
         this.FilenameIsPersonName = true;
         this.DataType             = People.all[0].GetType();
         for (int index = 0; index < People.all.Count; ++index)
         {
             if (People.all[index].vehicles.Count != 0)
             {
                 string dataEntry = this.CleanXMLForFile(ObjectSerializer.SerializeObject((object)People.all[index]));
                 Person person    = People.all[index];
                 try
                 {
                     string filenameForPersonName = this.GetFilenameForPersonName(People.all[index].firstName, People.all[index].lastName);
                     this.DatasetFolder.files.Add(new FileEntry(dataEntry, filenameForPersonName));
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine("Deserialization error for People: " + (object)ex);
                 }
             }
         }
     }
 }
Пример #4
0
        public static Person loadPersonFromFile(string path)
        {
            try
            {
                using (FileStream fileStream = new FileStream(path, FileMode.Open))
                {
                    XmlReader rdr = XmlReader.Create((Stream)fileStream, new XmlReaderSettings());
                    while (rdr.Name != "Person")
                    {
                        rdr.Read();
                    }
                    string str1;
                    string lName    = str1 = "unknown";
                    string fName    = str1;
                    string handle   = str1;
                    string str2     = str1;
                    bool   male     = true;
                    bool   isHacker = false;
                    bool   flag     = false;
                    if (rdr.MoveToAttribute("id"))
                    {
                        str2 = rdr.ReadContentAsString();
                    }
                    if (rdr.MoveToAttribute("handle"))
                    {
                        handle = rdr.ReadContentAsString();
                    }
                    if (rdr.MoveToAttribute("firstName"))
                    {
                        fName = rdr.ReadContentAsString();
                    }
                    if (rdr.MoveToAttribute("lastName"))
                    {
                        lName = rdr.ReadContentAsString();
                    }
                    if (rdr.MoveToAttribute("isMale"))
                    {
                        male = rdr.ReadContentAsBoolean();
                    }
                    if (rdr.MoveToAttribute("isHacker"))
                    {
                        isHacker = rdr.ReadContentAsBoolean();
                    }
                    if (rdr.MoveToAttribute("forceHasNeopals"))
                    {
                        flag = rdr.ReadContentAsBoolean();
                    }
                    Person person = new Person(fName, lName, male, isHacker, handle);
                    if (person.NeopalsAccount == null && flag && DLC1SessionUpgrader.HasDLC1Installed)
                    {
                        person.NeopalsAccount = NeopalsAccount.GenerateAccount(person.handle, Utils.flipCoin());
                    }
                    rdr.Read();
                    while (!(rdr.Name == "Person") || rdr.IsStartElement())
                    {
                        switch (rdr.Name)
                        {
                        case "Degrees":
                            List <Degree> degreeList = new List <Degree>();
                            rdr.Read();
                            while (!(rdr.Name == "Degrees") || rdr.IsStartElement())
                            {
                                if (rdr.Name == "Degree")
                                {
                                    string str3;
                                    string uniName = str3 = "UNKNOWN";
                                    double num     = 3.0;
                                    if (rdr.MoveToAttribute("uni"))
                                    {
                                        uniName = rdr.ReadContentAsString();
                                    }
                                    if (rdr.MoveToAttribute("gpa"))
                                    {
                                        num = rdr.ReadContentAsDouble();
                                    }
                                    int    content = (int)rdr.MoveToContent();
                                    Degree degree  = new Degree(rdr.ReadElementContentAsString(), uniName, (float)num);
                                    degreeList.Add(degree);
                                }
                                rdr.Read();
                            }
                            if (degreeList.Count > 0)
                            {
                                person.degrees = degreeList;
                                break;
                            }
                            break;

                        case "Birthplace":
                            string name = (string)null;
                            if (rdr.MoveToAttribute("name"))
                            {
                                name = rdr.ReadContentAsString();
                            }
                            if (name == null)
                            {
                                name = WorldLocationLoader.getRandomLocation().name;
                            }
                            person.birthplace = WorldLocationLoader.getClosestOrCreate(name);
                            break;

                        case "DOB":
                            CultureInfo cultureInfo = new CultureInfo("en-au");
                            int         content1    = (int)rdr.MoveToContent();
                            DateTime    dateTime    = Utils.SafeParseDateTime(rdr.ReadElementContentAsString());
                            if (dateTime.Hour == 0 && dateTime.Second == 0)
                            {
                                TimeSpan timeSpan = TimeSpan.FromHours(Utils.random.NextDouble() * 23.99);
                                dateTime += timeSpan;
                            }
                            person.DateOfBirth = dateTime;
                            break;

                        case "Medical":
                            person.medicalRecord = MedicalRecord.Load(rdr, person.birthplace, person.DateOfBirth);
                            break;
                        }
                        rdr.Read();
                    }
                    if (DLC1SessionUpgrader.HasDLC1Installed)
                    {
                        if (person.handle == "Minx" && person.NeopalsAccount == null)
                        {
                            person.NeopalsAccount = NeopalsAccount.GenerateAccount("Minx", false);
                        }
                        if (person.handle == "Orann" && person.NeopalsAccount == null && DLC1SessionUpgrader.HasDLC1Installed && People.PeopleWereGeneratedWithDLCAdditions)
                        {
                            person.NeopalsAccount = NeopalsAccount.GenerateAccount("Orann", false);
                        }
                    }
                    return(person);
                }
            }
            catch (FileNotFoundException ex)
            {
                return((Person)null);
            }
        }