public void Create( ) { //if (namePet.text.Length <= 0) //{ // Popup.Ins.PopupOne("Please name the pet.", "OK", null); // return; //} //if ((!btnMale.interactable && !btnFemale.interactable) || (btnMale.interactable && btnFemale.interactable)) //{ // Popup.Ins.PopupOne("Please select gender","OK",null); // return; //} Popup.Ins.PopupWaiting(true); PetData pet = SaveSystem.A_LoadPet(PlayerPrefs.GetInt("idPet")); Debug.LogError(PlayerPrefs.GetInt("idPet")); pet.color = numColor; pet.head = numHead; pet.ear = numEar; pet.pattern = numPattern; pet.eye = numEye; pet.eyebrow = numEyebrow; pet.nose = numNose; pet.mouth = numMouth; //SaveSystem.A_EditPet(pet); API_Game.Ins.PutPetRequest(pet, FinishCrreate); Debug.Log("Create Saved"); //PlayerPrefs.SetString("LoadScene", "Edit"); }
public void EditPetWebRequest(string idPet, UnityAction callback) { Popup.Ins.PopupWaiting(true); HttpClient client = new HttpClient(); client.Headers.Add("Authorization", "Token " + PlayerPrefs.GetString("token")); Dictionary <string, string> keyValuePairs = new Dictionary <string, string>(); keyValuePairs.Add("name", namePetEdit); keyValuePairs.Add("pettype", typeEdit); keyValuePairs.Add("breed", breedEdit); keyValuePairs.Add("gendaer", genderEdit); keyValuePairs.Add("birthdate", birthdayEdit); keyValuePairs.Add("weight", weightEdit); keyValuePairs.Add("furcolor", colorEdit); IHttpContent content = new FormUrlEncodedContent(keyValuePairs); client.Patch(new Uri("https://www.pacheti.com/api/pets/" + idPet + "/edit/"), content, HttpCompletionOption.AllResponseContent, r => { Popup.Ins.PopupWaiting(false); if (!r.IsSuccessStatusCode) { Debug.Log(r.ReadAsString()); } else { Debug.Log(r.ReadAsString()); PetData petData = SaveSystem.A_LoadPet(int.Parse(idPet)); petData.namePet = namePetEdit; API_Game.Ins.PutPetRequest(petData, callback); // callback(); } }); }
public IEnumerator StatusAndRewardCalculator() { DateTime oldTime; int totalMin = 0; if (p.lastTimeInGame != null && p.lastTimeInGame.Length > 0) { oldTime = DateTime.Parse(p.lastTimeInGame); totalMin = (int)DateTime.Now.Subtract(oldTime).TotalMinutes; string datett = DateTime.Now.Year + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00"); string formm = "yyyyMMddHHmm"; } p.lastTimeInGame = DateTime.Now.ToString(); SaveSystem.A_SaveGame(p); for (int i = 0; i < petList.Count; i++) { m_Data = SaveSystem.A_LoadPet(petList[i].id); // Debug.LogError(m_Data.UUID.Length + "**" + m_Data.UUID); if (m_Data.UUID.Length != 10) { m_Data.UUID = "2019010112"; } string formm = "yyyyMMddHH"; DateTime oldDate = DateTime.ParseExact(m_Data.UUID, formm, null); oldTime = oldDate; totalMin = (int)DateTime.Now.Subtract(oldTime).TotalMinutes; string newTime = DateTime.Now.Year + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + DateTime.Now.Hour.ToString("00") /*+ DateTime.Now.Minute.ToString("00")*/; // Debug.LogError(newTime); m_Data.UUID = newTime; if (!m_Data.selected) { continue; } float happy = petList[i].Happiness; float hungy = petList[i].Hunger; float unitPerMin = 0.000115740741f; // float unitPerMin = 5f; if (Mathf.Abs(((unitPerMin * totalMin) - hungy)) < 40) { if (hungy > 40f) { float earlierMin = (hungy - 40) / unitPerMin; float afterMin = totalMin - earlierMin; petList[i].Hunger -= unitPerMin * totalMin; petList[i].Happiness -= (unitPerMin / 2) * earlierMin; petList[i].Happiness -= ((unitPerMin / 2) * afterMin) * 2; } else { petList[i].Hunger -= unitPerMin * totalMin; petList[i].Happiness -= unitPerMin * totalMin; } } else { petList[i].Hunger -= unitPerMin * totalMin; petList[i].Happiness -= (unitPerMin / 2) * totalMin; } m_Data.happiness = (int)petList[i].Happiness; m_Data.hunger = (int)petList[i].Hunger; //Reward getReward = false; if (m_Data.lastTimeReward.Length > 0 && petList[i].Happiness >= 50) { DateTime petDate = DateTime.Parse(m_Data.lastTimeReward); if (petDate.Day != DateTime.Now.Day) { m_Data.lastTimeReward = DateTime.Now.ToString("yyyy-MM-dd"); RandomReward(); yield return(null); SoundManager.Ins.PlaySound(SoundManager.Ins._Reward); Popup.Ins.PopupReward(m_Data.namePet + " has a gift for you.", Atlas.Ins.GetSprites(Atlas.Ins.reward.reward)[indexReward], CallbackReward); yield return(new WaitUntil(() => getReward == true)); } } if (m_Data.lastTimeReward.Length <= 0) { Debug.LogError("zxc"); m_Data.lastTimeReward = DateTime.Now.ToString("yyyy-MM-dd"); RandomReward(); yield return(null); SoundManager.Ins.PlaySound(SoundManager.Ins._Reward); Popup.Ins.PopupReward(m_Data.namePet + " has a gift for you.", Atlas.Ins.GetSprites(Atlas.Ins.reward.reward)[indexReward], CallbackReward); yield return(new WaitUntil(() => getReward == true)); } getReward = false; SaveSystem.A_EditPet(m_Data, true); yield return(null); } //Daily Reward if (PlayerPrefs.HasKey("DailyReward")) { DateTime dailyTime = DateTime.Parse(PlayerPrefs.GetString("DailyReward")); if (dailyTime.Day != DateTime.Now.Day) { SaveSystem.A_AddCoin(500); Popup.Ins.PopupReward("", lottery.point500, null); PlayerPrefs.SetString("DailyReward", DateTime.Now.ToString()); } } else { SaveSystem.A_AddCoin(500); Popup.Ins.PopupReward("", lottery.point500, null); PlayerPrefs.SetString("DailyReward", DateTime.Now.ToString()); } }
private void Normal() { if (gameMode != GameMode.Normal) { return; } if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (target != null) { timeer += Time.deltaTime; } switch (touch.phase) { case TouchPhase.Began: if (Popup.Ins.working || lottery.working || setting.working) { return; } hit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(touch.position), Vector2.zero); if (hit2D.collider != null && hit2D.collider.tag == "Pet") { target = hit2D.collider.gameObject; petAI = target.GetComponent <PetAI>(); } break; case TouchPhase.Moved: if (target != null && petAI != null) { petAI.PetAct = PetActivity.Carry; petAI.aleart = false; ray = Camera.main.ScreenPointToRay(touch.position); target.transform.position = new Vector2(ray.origin.x, ray.origin.y); } break; case TouchPhase.Stationary: if (timeer > 0.2f && target != null && petAI != null) { petAI.PetAct = PetActivity.Carry; petAI.aleart = false; ray = Camera.main.ScreenPointToRay(touch.position); target.transform.position = new Vector2(ray.origin.x, ray.origin.y); } break; case TouchPhase.Ended: if (timeer < 0.2f && petAI != null) { petAI.rigidbody.constraints = RigidbodyConstraints2D.FreezeAll; petAI.aleart = false; target.transform.localScale = new Vector3(0.55f, 0.55f, 1); target.transform.position = new Vector3(0, -1.3f, -5); target.transform.rotation = new Quaternion(0, 0, 0, 0); happiness.value = petAI.Happiness / 100; hunger.value = petAI.Hunger / 100; Transform[] roots = target.GetComponentsInChildren <Transform>(); foreach (Transform g in roots) { g.gameObject.layer = 21; } interactCam.gameObject.SetActive(true); target.layer = 21; interactUI.SetActive(true); interactUIBG.SetActive(true); foodCanvasList.SetActive(true); dressUpBtn.onClick.Invoke(); petAI.emoHappy.SetActive(false); petAI.emooHungry.SetActive(false); petAI.emoHappy.layer = 10; petAI.emooHungry.layer = 10; gameMode = GameMode.Interact; petAI.PetAct = PetActivity.Stand; tutor3.SetActive(true); petData = SaveSystem.A_LoadPet(petAI.id); foodDic.Clear(); } else if (target != null && petAI != null) { timeer = 0; petAI.aleart = true; petAI.PetAct = PetActivity.Stand; target.transform.rotation = new Quaternion(0, 0, 0, 0); target = null; petAI = null; } break; case TouchPhase.Canceled: break; } } }