Ejemplo n.º 1
0
    public void CloneItem(GameObject obj)
    {
        FurnitureData f = obj.GetComponent <FurnitureData>();

        Player        p     = SaveSystem.A_LoadSaveGame();
        GameObject    clone = Instantiate(furniturePrefab, roomParent);
        FurnitureData c     = clone.AddComponent <FurnitureData>();

        foreach (Furniture fur in p.inventory.furniture)
        {
            if (fur.id == f.id && fur.type == f.type && fur.furnitureIsUsing == false && !idFurInstall.Contains(fur.realId))
            {
                c.realId             = fur.realId;
                fur.furnitureIsUsing = true;
                idFurInstall.Add(fur.realId);
                break;
            }
        }
        SaveSystem.A_SaveGame(p);
        c.id               = f.id;
        c.type             = f.type;
        c.furnitureIsUsing = true;
        clone.SetActive(false);
        clone.GetComponent <SpriteRenderer>().sprite = GetFurnitureSprites(f);
        clone.name = ((FurnitureType)f.type).ToString();

        PolygonCollider2D polygonCollider2D = clone.AddComponent <PolygonCollider2D>();

        polygonCollider2D.isTrigger = true;

        clone.transform.position = new Vector3(clone.transform.position.x, clone.transform.position.y, 0);
        clone.GetComponent <Rigidbody2D>().gravityScale = 0;

        Text t = obj.GetComponentInChildren <Text>();

        t.text = (int.Parse(t.text) - 1).ToString();

        target = clone;
    }
Ejemplo n.º 2
0
    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());
        }
    }