public void LoadGame() { List <CageSaveData> cages = JsonConvert.DeserializeObject <List <CageSaveData> >(PlayerPrefs.GetString("save")); DataManager.Money = (PlayerPrefs.GetInt("money", 0)); for (int i = 0; i < cages.Count; i++) { Cage tmp = CageFactory.GetNewCage(cages[i].biome, i, true); tmp.Name = cages[i].Name; tmp.stage = cages[i].stage; GameManager.Ins.cages.Add(tmp); GameManager.Ins.ToCage(i); foreach (var item in cages[i].items) { if (item.type == NeedType.Food) { Feeder f = Instantiate(feeders[(int)item.food], tmp.transform).GetComponent <Feeder>(); f.transform.localPosition = item.localPos; f.capacity = item.capacity; f.Place(); } else { SpecialItem s = Instantiate(specials[(int)item.special], tmp.transform).GetComponent <SpecialItem>(); s.transform.localPosition = item.localPos; s.Place(); } } foreach (var animal in cages[i].animals) { Animal a = AnimalFactory.NewAnimalOfKind(animal.kind, tmp.transform, true); a.data.name = animal.data.name; a.data.adult = animal.data.adult; a.data.age = animal.data.age; a.data.male = animal.data.male; a.data.pregnant = animal.data.pregnant; a.data.pregnancy = animal.data.pregnancy; a.data.sexualActivity = animal.data.sexualActivity; a.data.happiness = animal.data.happiness; a.data.foods = animal.data.foods; a.data.specials = animal.data.specials; a.transform.position = tmp.GetFreeTileInGrid(); a.status.RecalculateHappiness(); } if (tmp.animals.Count > 0) { GameManager.Ins.cageIcons.GetChild(i).GetComponent <Image>().sprite = Resources.Load <Sprite>($"Animals/{tmp.animals[0].stats.kind}/CageIcon"); } } Technet99m.Clock.deltaActualized += SaveGame; GameManager.Ins.ToCage(0); StartCoroutine(CalculateTimeChanges()); }
private List <Cage> GetCageList(SQLQueryResult sQLQueryResult) { List <Cage> cages = new List <Cage>(); for (int i = 0; i < sQLQueryResult.dataTable.Rows.Count; i++) { int cageID = (int)sQLQueryResult.dataTable.Rows[i]["CageID"]; int speciesID = (int)sQLQueryResult.dataTable.Rows[i]["SpeciesID"]; string speciesName = (string)sQLQueryResult.dataTable.Rows[i]["SpeciesName"]; Species species = SpeciesFactory.Instance().CreateSpecies(speciesID, speciesName); cages.Add(CageFactory.Instance().CreateCage(cageID, species)); } return(cages); }
private List <Treatment> GetTreatmentList(SQLQueryResult sQLQueryResult) { List <Treatment> treatments = new List <Treatment>(); for (int i = 0; i < sQLQueryResult.dataTable.Rows.Count; i++) { int treatmentID; TreatmentType treatmentType; Employee employee; Employee animalEmployee = null; OperationRoom operationRoom; Cage cage; Item item; int animalID; Title title; if (sQLQueryResult.dataTable.Rows[i].IsNull("TreatmentID")) { treatmentID = -1; } else { treatmentID = (int)sQLQueryResult.dataTable.Rows[i]["TreatmentID"]; } if (sQLQueryResult.dataTable.Rows[i].IsNull("TreatmentTypeID")) { treatmentType = null; } else { int treatmentTypeID = (int)sQLQueryResult.dataTable.Rows[i]["TreatmentTypeID"]; string treatmentTypeName = (string)sQLQueryResult.dataTable.Rows[i]["Name"]; TreatmentType newTreatmentType = TreatmentTypeFactory.Instance().CreateTreatmentType(treatmentTypeID, treatmentTypeName); treatmentType = newTreatmentType; } if (sQLQueryResult.dataTable.Rows[i].IsNull("OperationRoomID")) { operationRoom = null; } else { int operationRoomID = (int)sQLQueryResult.dataTable.Rows[i]["OperationRoomID"]; operationRoom = OperationRoomFactory.Instance().CreateOperationRoom(operationRoomID); } if (sQLQueryResult.dataTable.Rows[i].IsNull("CageID")) { cage = null; } else { int cageID = (int)sQLQueryResult.dataTable.Rows[i]["CageID"]; int speciesID = (int)sQLQueryResult.dataTable.Rows[i]["SpeciesID"]; string speciesName = (string)sQLQueryResult.dataTable.Rows[i]["SpeciesName"]; Species species = SpeciesFactory.Instance().CreateSpecies(speciesID, speciesName); cage = CageFactory.Instance().CreateCage(cageID, species); } if (sQLQueryResult.dataTable.Rows[i].IsNull("ItemID")) { item = null; } else { int itemID = (int)sQLQueryResult.dataTable.Rows[i]["ItemID"]; string name = (string)sQLQueryResult.dataTable.Rows[i]["ItemName"]; decimal price = (decimal)sQLQueryResult.dataTable.Rows[i]["Price"]; decimal costPrice = (decimal)sQLQueryResult.dataTable.Rows[i]["CostPrice"]; int amount = (int)sQLQueryResult.dataTable.Rows[i]["Amount"]; bool prescription = (bool)sQLQueryResult.dataTable.Rows[i]["Prescription"]; bool treatment = (bool)sQLQueryResult.dataTable.Rows[i]["ItemTreatment"]; bool itemActive = (bool)sQLQueryResult.dataTable.Rows[i]["ItemActive"]; item = ItemFactory.Instance().CreateItem(itemID, name, amount, price, costPrice, prescription, treatment, itemActive); } if (sQLQueryResult.dataTable.Rows[i].IsNull("EmployeeID")) { employee = null; } else { int employeeID = (int)sQLQueryResult.dataTable.Rows[i]["EmployeeID"]; string name = (string)sQLQueryResult.dataTable.Rows[i]["Employeename"]; int titleID = (int)sQLQueryResult.dataTable.Rows[i]["TitleID"]; string titleName = (string)sQLQueryResult.dataTable.Rows[i]["TitleName"]; title = TitleFactory.Instance().CreateTitle(titleName, titleID); employee = EmployeeFactory.Instance().CreateEmployee(employeeID, name, true, title); } animalID = (int)sQLQueryResult.dataTable.Rows[i]["AnimalID"]; if (!sQLQueryResult.dataTable.Rows[i].IsNull("AnimalEmployeeID")) { int animalTitleID = (int)sQLQueryResult.dataTable.Rows[i]["AnimalEmployeeTitleID"]; string animalTitleName = (string)sQLQueryResult.dataTable.Rows[i]["AnimalEmployeeTitle"]; Title animalEmployeeTitle = TitleFactory.Instance().CreateTitle(animalTitleName, animalTitleID); int animalEmployeeID = (int)sQLQueryResult.dataTable.Rows[i]["AnimalEmployeeID"]; string animalEmployeeName = (string)sQLQueryResult.dataTable.Rows[i]["AnimalEmployeeName"]; bool animalEmployeeActive = (bool)sQLQueryResult.dataTable.Rows[i]["AnimalEmployeeActive"]; animalEmployee = EmployeeFactory.Instance().CreateEmployee(animalEmployeeID, animalEmployeeName, animalEmployeeActive, animalEmployeeTitle); } int animalSpeciesID = (int)sQLQueryResult.dataTable.Rows[i]["AnimalSpeciesID"]; string animalSpeciesName = (string)sQLQueryResult.dataTable.Rows[i]["AnimalSpeciesName"]; Species animalSpecies = SpeciesFactory.Instance().CreateSpecies(animalSpeciesID, animalSpeciesName); int customerID = (int)sQLQueryResult.dataTable.Rows[i]["CustomerID"]; string customerName = (string)sQLQueryResult.dataTable.Rows[i]["CustomerName"]; string customerAddress = (string)sQLQueryResult.dataTable.Rows[i]["Adress"]; string customerPhone = (string)sQLQueryResult.dataTable.Rows[i]["Phone"]; string customerEmail = (string)sQLQueryResult.dataTable.Rows[i]["Email"]; bool customerActive = (bool)sQLQueryResult.dataTable.Rows[i]["CustomerActive"]; Customer customer = CustomerFactory.Instance().CreateCustomer(customerID, customerName, customerAddress, customerPhone, customerEmail, customerActive, 0); string animalName = (string)sQLQueryResult.dataTable.Rows[i]["AnimalName"]; DateTime animalBirthday = (DateTime)sQLQueryResult.dataTable.Rows[i]["BirthYear"]; bool animalGender = (bool)sQLQueryResult.dataTable.Rows[i]["Gender"]; double animalWeight = Convert.ToDouble((decimal)sQLQueryResult.dataTable.Rows[i]["Weight"]); bool animalActive = (bool)sQLQueryResult.dataTable.Rows[i]["AnimalActive"]; Animal animal = AnimalFactory.Instance().CreateAnimal(customer, animalID, animalName, animalBirthday, animalSpecies, animalWeight, animalGender, animalEmployee, animalActive); if (sQLQueryResult.dataTable.Rows[i].IsNull("AnimalID")) { animalID = -1; } else { animalID = (int)sQLQueryResult.dataTable.Rows[i]["AnimalID"]; } DateTime startTime = (DateTime)sQLQueryResult.dataTable.Rows[i]["StartTime"]; DateTime endTime = (DateTime)sQLQueryResult.dataTable.Rows[i]["EndTime"]; bool payed = (bool)sQLQueryResult.dataTable.Rows[i]["Payed"]; string headline = (string)sQLQueryResult.dataTable.Rows[i]["Headline"]; bool active = (bool)sQLQueryResult.dataTable.Rows[i]["Active"]; int status = (int)sQLQueryResult.dataTable.Rows[i]["Status"]; treatments.Add(TreatmentFactory.Instance().CreateTreatment(treatmentID, treatmentType, operationRoom, cage, item, startTime, endTime, payed, headline, active, animal, employee, status)); } return(treatments); }