Exemple #1
0
    public IEnumerator IELoadLocationJson(SimpleJSON_DatDz.JSONArray lsData)
    {
        long   totalTime            = 0;
        double dollarRecive         = 0;
        double maxOutputMadeRevenue = 0;

        for (int i = 0; i < lsData.Count; i++)
        {
            int        indexTypeWork = lsData[i]["indexTypeWork"].AsInt;
            GameObject obj           = Instantiate(GameManager.Instance.lsItemLocation[indexTypeWork], GameManager.Instance.locationManager);
            obj.transform.SetAsFirstSibling();
            obj.name = lsData[i]["nameLocation"];
            Location location = obj.GetComponent <Location>();

            var lsOther = lsData[i]["lsOther"].AsArray;
            location.lsOther = new List <int>();
            for (int iOther = 0; iOther < lsOther.Count; iOther++)
            {
                location.lsOther.Add(lsOther[iOther].AsInt);
            }

            var lsRiverRight = lsData[i]["lsRiverRight"].AsArray;
            location.lsRiverRight = new List <int>();
            for (int iRiverRight = 0; iRiverRight < lsRiverRight.Count; iRiverRight++)
            {
                location.lsRiverRight.Add(lsRiverRight[iRiverRight].AsInt);
            }

            var lsRiverLeft = lsData[i]["lsRiverLeft"].AsArray;
            location.lsRiverLeft = new List <int>();
            for (int iRiverLeft = 0; iRiverLeft < lsRiverLeft.Count; iRiverLeft++)
            {
                location.lsRiverLeft.Add(lsRiverLeft[iRiverLeft].AsInt);
            }

            var lsStreet = lsData[i]["lsStreet"].AsArray;
            location.lsStreet = new List <int>();
            for (int iStreet = 0; iStreet < lsStreet.Count; iStreet++)
            {
                location.lsStreet.Add(lsStreet[iStreet].AsInt);
            }

            yield return(new WaitUntil(() =>
                                       location.lsStreet.Count == lsStreet.Count &&
                                       location.lsRiverLeft.Count == lsRiverLeft.Count &&
                                       location.lsRiverRight.Count == lsRiverRight.Count &&
                                       location.lsOther.Count == lsOther.Count));

            location.LoadLocationJson();

            yield return(new WaitUntil(() => location.isLoadFull));

            location.id            = lsData[i]["id"].AsInt;
            location.nameLocation  = lsData[i]["nameLocation"];
            location.indexTypeWork = lsData[i]["indexTypeWork"].AsInt;
            location.countType     = lsData[i]["countType"].AsInt;
            location.makerType     = lsData[i]["makerType"].AsInt;
            location.risk          = lsData[i]["risk"].AsInt;
            location.indexTypeRisk = lsData[i]["indexTypeRisk"].AsInt;
            location.timeCheckRisk = lsData[i]["timeCheckRisk"].AsFloat;
            location.timeCheckFire = lsData[i]["timeCheckFire"].AsFloat;

            location.forest.tree             = lsData[i]["forest"]["tree"].AsInt;
            location.forest.isOnBtnAutoPlant = lsData[i]["forest"]["isOnBtnAutoPlant"].AsBool;
            location.forest.isAutoPlant      = lsData[i]["forest"]["isAutoPlant"].AsBool;
            location.forest.typeTree         = lsData[i]["forest"]["typeTree"].AsInt;

            location.forest.forestClass.LoadTree();

            var lsWorking = lsData[i]["lsWorking"].AsArray;
            for (int j = 0; j < lsWorking.Count; j++)
            {
                if (location.countType >= j)
                {
                    location.lsWorking[j].icon.color = Color.white;
                }

                location.lsWorking[j].name        = lsWorking[j]["name"];
                location.lsWorking[j].id          = lsWorking[j]["id"].AsInt;
                location.lsWorking[j].level       = lsWorking[j]["level"].AsInt;
                location.lsWorking[j].countPlayer = lsWorking[j]["countPlayer"].AsInt;
                location.lsWorking[j].isClaim     = lsWorking[j]["isClaim"].AsBool;

                location.lsWorking[j].input                 = lsWorking[j]["input"].AsDouble;
                location.lsWorking[j].output                = lsWorking[j]["output"].AsDouble;
                location.lsWorking[j].priceOutput           = lsWorking[j]["priceOutput"].AsDouble;
                location.lsWorking[j].isISO                 = lsWorking[j]["isISO"].AsBool;
                location.lsWorking[j].isUpgradeMachineJob   = lsWorking[j]["isUpgradeMachineJob"].AsBool;
                location.lsWorking[j].isUpgradeMachineTrunk = lsWorking[j]["isUpgradeMachineTrunk"].AsBool;

                location.lsWorking[j].maxOutputMade      = lsWorking[j]["maxOutputMade"].AsDouble;
                location.lsWorking[j].maxOutputMadeStart = lsWorking[j]["maxOutputMadeStart"].AsDouble;

                location.lsWorking[j].levelTruck             = lsWorking[j]["levelTruck"].AsInt;
                location.lsWorking[j].priceUpgradeTruck      = lsWorking[j]["priceUpgradeTruck"].AsDouble;
                location.lsWorking[j].priceUpgradeTruckStart = lsWorking[j]["priceUpgradeTruckStart"].AsDouble;
                location.lsWorking[j].priceTruckSent         = lsWorking[j]["priceTruckSent"].AsDouble;
                location.lsWorking[j].priceTruckSentStart    = lsWorking[j]["priceTruckSentStart"].AsDouble;
                location.lsWorking[j].currentSent            = lsWorking[j]["currentSent"].AsDouble;
                location.lsWorking[j].maxSent      = lsWorking[j]["maxSent"].AsDouble;
                location.lsWorking[j].maxSentStart = lsWorking[j]["maxSentStart"].AsDouble;

                location.lsWorking[j].priceUpgrade      = lsWorking[j]["priceUpgrade"].AsDouble;
                location.lsWorking[j].priceUpgradeStart = lsWorking[j]["priceUpgradeStart"].AsDouble;
                location.lsWorking[j].price             = lsWorking[j]["price"].AsDouble;
                location.lsWorking[j].UN2 = lsWorking[j]["UN2"].AsFloat;

                if (location.lsWorking[j].isISO)
                {
                    location.lsWorking[j].iso.SetActive(true);
                }

                if (location.lsWorking[j].id <= location.countType)
                {
                    location.lsWorking[j].info.SetActive(true);
                    if (location.lsWorking[j].textInput != null)
                    {
                        location.lsWorking[j].textInput.text = UIManager.Instance.ConvertNumber(location.lsWorking[j].input);
                    }
                    location.lsWorking[j].textOutput.text = UIManager.Instance.ConvertNumber(location.lsWorking[j].output);
                    if (location.lsWorking[j].output > 0)
                    {
                        location.lsWorking[j].truckManager.LoadTruck();
                    }
                    location.lsWorking[j].textLevel.text             = UIManager.Instance.ConvertNumber(location.lsWorking[j].level);
                    location.lsWorking[j].truckManager.txtLevel.text = UIManager.Instance.ConvertNumber(location.lsWorking[j].levelTruck);
                }
                if (i != lsData.Count - 1)
                {
                    location.lsWorking[j].animLock.gameObject.SetActive(false);
                }
                else
                {
                    if (location.lsWorking[j].id <= location.countType)
                    {
                        location.lsWorking[j].animLock.gameObject.SetActive(false);
                    }
                    else if (location.lsWorking[j].id == location.countType + 1)
                    {
                        location.lsWorking[j].animLock.enabled = true;
                    }
                }
            }

            yield return(new WaitUntil(() => location.lsWorking[0].price != 0));

            if (!location.forest.isAutoPlant)
            {
                if (location.forest.isOnBtnAutoPlant)
                {
                    location.forest.btnAutoPlant.gameObject.SetActive(true);
                    if (GameManager.Instance.dollar >= (double)(location.lsWorking[0].price * GameConfig.Instance.AutoPlant))
                    {
                        location.forest.btnAutoPlant.interactable = true;
                    }
                    else
                    {
                        location.forest.btnAutoPlant.interactable = false;
                    }
                }
            }
            GameManager.Instance.lsLocation.Add(location);
            UIManager.Instance.lsBtnLocationUI[i].interactable = true;

            if (location.countType == -1)
            {
                maxOutputMadeRevenue += 0;
            }
            else
            {
                maxOutputMadeRevenue += location
                                        .lsWorking[location.countType].maxOutputMade
                                        * GameConfig.Instance.r
                                        * GameConfig.Instance.productCost;
            }
        }
        yield return(new WaitUntil(() => UIManager.Instance.lsBtnLocationUI[lsData.Count - 1].interactable));

        UIManager.Instance.handWorld.position = UIManager.Instance.lsBtnLocationUI[lsData.Count - 1].transform.GetChild(0).position - new Vector3(0f, 0.25f, 0f);;

        int locationEnd = GameManager.Instance.lsLocation.Count - 1;
        int jobEnd      = GameManager.Instance.lsLocation[locationEnd].countType;

        if (jobEnd == -1 && GameManager.Instance.lsLocation.Count > 1)
        {
            locationEnd--;
            jobEnd = GameManager.Instance.lsLocation[locationEnd].countType;
        }

        if (GameManager.Instance.lsLocation.Count > 1)
        {
            dollarRecive = GameManager.Instance.lsLocation[locationEnd].lsWorking[jobEnd].price;
        }
        else
        {
            if (jobEnd == -1)
            {
                dollarRecive = GameManager.Instance.lsLocation[0].lsWorking[0].price;
            }
            else
            {
                dollarRecive = GameManager.Instance.lsLocation[locationEnd].lsWorking[jobEnd].price;
            }
        }
        UIManager.Instance.txtRevenue.text
            = "Revenue : " + UIManager.Instance.ConvertNumber(maxOutputMadeRevenue) + "$/day";
        ScenesManager.Instance.isNextScene = true;
        double adddollar = 0;

        if (!isFirst)
        {
            if (UIManager.Instance.isContinue)
            {
                totalTime = (long)((TimeSpan)(dateNowPlayer - DateTime.Parse(PlayerPrefs.GetString("DateTimeOutGame")))).TotalMinutes;
                if (totalTime >= 5 && dollarRecive > 0)
                {
                    if (totalTime <= 60)
                    {
                        adddollar = (double)(0.1f * dollarRecive);
                    }
                    else if (totalTime <= 600)
                    {
                        totalTime = totalTime / 60;
                        adddollar = (double)((double)totalTime * 0.5f * dollarRecive);
                    }
                    else
                    {
                        totalTime = 10;
                        adddollar = (double)((double)totalTime * 0.5f * dollarRecive);
                    }
                    GameManager.Instance.AddDollar(+adddollar);
                    string strGive = "Offline Reward\n"
                                     + UIManager.Instance.ConvertNumber(adddollar)
                                     + "$";
                    UIManager.Instance.PushGiveGold(strGive);
                    PlayerPrefs.SetString("DateTimeOutGame", DateTime.Now.ToString());
                }
            }
            isFirst = true;
        }
    }
        public static JSONNode Deserialize(System.IO.BinaryReader aReader)
        {
            JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();

            switch (type)
            {
            case JSONBinaryTag.Array:
            {
                int       count = aReader.ReadInt32();
                JSONArray tmp   = new JSONArray();
                for (int i = 0; i < count; i++)
                {
                    tmp.Add(Deserialize(aReader));
                }
                return(tmp);
            }

            case JSONBinaryTag.Class:
            {
                int       count = aReader.ReadInt32();
                JSONClass tmp   = new JSONClass();
                for (int i = 0; i < count; i++)
                {
                    string key = aReader.ReadString();
                    var    val = Deserialize(aReader);
                    tmp.Add(key, val);
                }
                return(tmp);
            }

            case JSONBinaryTag.Value:
            {
                return(new JSONData(aReader.ReadString()));
            }

            case JSONBinaryTag.IntValue:
            {
                return(new JSONData(aReader.ReadInt32()));
            }

            case JSONBinaryTag.DoubleValue:
            {
                return(new JSONData(aReader.ReadDouble()));
            }

            case JSONBinaryTag.BoolValue:
            {
                return(new JSONData(aReader.ReadBoolean()));
            }

            case JSONBinaryTag.FloatValue:
            {
                return(new JSONData(aReader.ReadSingle()));
            }

            default:
            {
                throw new Exception("Error deserializing JSON. Unknown tag: " + type);
            }
            }
        }