Beispiel #1
0
    void OnMODButtonClick(object data)
    {
        int index = (int)data;

        SetSelectKing();

        Informations.Reset();
        MODLoadController.Instance.LoadMOD(index);
    }
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < kingName.Length; i++)
        {
            if (kingName[i].GetButtonState() == PushedButton.ButtonState.Down)
            {
                SelectKing(i);

                if (!isConfirmBoxShow)
                {
                    confirmBox.SetActive(true);
                    isConfirmBoxShow = true;
                }
                break;
            }
        }

        if (isConfirmBoxShow)
        {
            if (btnOK.GetButtonState() == Button.ButtonState.Clicked)
            {
                Controller.kingIndex = kingIndex;

                Informations.Reset();
                StrategyController.isFirstEnter = true;
                Misc.LoadLevel("InternalAffairs");
            }
            else if (btnCancel.GetButtonState() == Button.ButtonState.Clicked || Misc.GetBack())
            {
                isConfirmBoxShow = false;
                confirmBox.SetActive(false);

                btnCancel.SetButtonState(Button.ButtonState.Normal);
            }
        }
        else
        {
            if (Misc.GetBack())
            {
                if (PlayerPrefs.HasKey("GamePass"))
                {
                    ssCtrl.SetSelectMOD();
                }
                else
                {
                    Misc.LoadLevel("StartScene");
                    GameObject.Destroy(GameObject.Find("MouseTrack"));
                }
            }
        }
    }
    public void LoadRecord(int index, RecordCallback recordCallback)
    {
        string path = "";

        if (Application.isEditor)
        {
            path = Application.dataPath + "/../SAVES/";
        }
        else
        {
            path = Application.persistentDataPath + "/SAVES/";
        }
        DirectoryInfo dir = new DirectoryInfo(path);

        if (!dir.Exists)
        {
            return;
        }

        int    idx      = index;
        string filePath = path + "SANGO0" + (idx + 1) + ".SAV.xml";

        if (!File.Exists(filePath))
        {
            return;
        }

        Informations.Reset();

        XmlDocument  xmlDoc = new XmlDocument();
        StreamReader sr     = File.OpenText(filePath);

        xmlDoc.LoadXml(sr.ReadToEnd().Trim());
        XmlElement root = xmlDoc.DocumentElement;
        XmlElement node;

        node = (XmlElement)root.SelectSingleNode("Mod");
        if (node != null)
        {
            Controller.MODSelect = int.Parse(node.GetAttribute("Index"));
        }
        else
        {
            Controller.MODSelect = 1;
        }
        Informations.Instance.kingNum = Informations.Instance.modKingNum[Controller.MODSelect];

        node = (XmlElement)root.SelectSingleNode("HeadInfo");
        Controller.kingIndex   = int.Parse(node.GetAttribute("SelectKing"));
        Controller.historyTime = int.Parse(node.GetAttribute("HistoryTime"));

        node = (XmlElement)root.SelectSingleNode("Misc");
        StrategyController.isFirstEnter   = bool.Parse(node.GetAttribute("IsFirstEnter"));
        StrategyController.strategyCamPos = StringToVector3(node.GetAttribute("StrategyCamPos"));

        XmlNodeList nodeList = root.SelectNodes("KingsInfo");
        int         i        = 0;

        foreach (XmlElement kingNode in nodeList)
        {
            KingInfo kInfo = new KingInfo();
            kInfo.active     = int.Parse(kingNode.GetAttribute("active"));
            kInfo.generalIdx = int.Parse(kingNode.GetAttribute("generalIdx"));
            Informations.Instance.SetKingInfo(i++, kInfo);
        }
        KingInfo k = new KingInfo();

        k.generalIdx = 0;
        Informations.Instance.SetKingInfo(Informations.Instance.kingNum, k);

        i        = 0;
        nodeList = root.SelectNodes("CitiesInfo");
        foreach (XmlElement cityNode in nodeList)
        {
            CityInfo cInfo = new CityInfo();
            cInfo.king         = int.Parse(cityNode.GetAttribute("king"));
            cInfo.prefect      = int.Parse(cityNode.GetAttribute("prefect"));
            cInfo.population   = int.Parse(cityNode.GetAttribute("population"));
            cInfo.money        = int.Parse(cityNode.GetAttribute("money"));
            cInfo.reservist    = int.Parse(cityNode.GetAttribute("reservist"));
            cInfo.reservistMax = int.Parse(cityNode.GetAttribute("reservistMax"));
            cInfo.defense      = int.Parse(cityNode.GetAttribute("defense"));

            if (cityNode.HasAttribute("objects"))
            {
                string   str        = cityNode.GetAttribute("objects");
                string[] objectsStr = str.Split(',');
                cInfo.objects = new List <int>();
                for (int j = 0; j < objectsStr.Length; j++)
                {
                    cInfo.objects.Add(int.Parse(objectsStr[j]));
                }
            }

            Informations.Instance.SetCityInfo(i++, cInfo);
        }

        i        = 0;
        nodeList = root.SelectNodes("GeneralsInfo");
        foreach (XmlElement generalNode in nodeList)
        {
            GeneralInfo gInfo = new GeneralInfo();
            gInfo.active       = int.Parse(generalNode.GetAttribute("active"));
            gInfo.king         = int.Parse(generalNode.GetAttribute("king"));
            gInfo.city         = int.Parse(generalNode.GetAttribute("city"));
            gInfo.prisonerIdx  = int.Parse(generalNode.GetAttribute("prisonerIdx"));
            gInfo.loyalty      = int.Parse(generalNode.GetAttribute("loyalty"));
            gInfo.job          = int.Parse(generalNode.GetAttribute("job"));
            gInfo.equipment    = int.Parse(generalNode.GetAttribute("equipment"));
            gInfo.strength     = int.Parse(generalNode.GetAttribute("strength"));
            gInfo.intellect    = int.Parse(generalNode.GetAttribute("intellect"));
            gInfo.experience   = int.Parse(generalNode.GetAttribute("experience"));
            gInfo.level        = int.Parse(generalNode.GetAttribute("level"));
            gInfo.healthMax    = int.Parse(generalNode.GetAttribute("healthMax"));
            gInfo.healthCur    = int.Parse(generalNode.GetAttribute("healthCur"));
            gInfo.manaMax      = int.Parse(generalNode.GetAttribute("manaMax"));
            gInfo.manaCur      = int.Parse(generalNode.GetAttribute("manaCur"));
            gInfo.soldierMax   = int.Parse(generalNode.GetAttribute("soldierMax"));
            gInfo.soldierCur   = int.Parse(generalNode.GetAttribute("soldierCur"));
            gInfo.knightMax    = int.Parse(generalNode.GetAttribute("knightMax"));
            gInfo.knightCur    = int.Parse(generalNode.GetAttribute("knightCur"));
            gInfo.arms         = int.Parse(generalNode.GetAttribute("arms"));
            gInfo.armsCur      = int.Parse(generalNode.GetAttribute("armsCur"));
            gInfo.formation    = int.Parse(generalNode.GetAttribute("formation"));
            gInfo.formationCur = int.Parse(generalNode.GetAttribute("formationCur"));
            gInfo.escape       = int.Parse(generalNode.GetAttribute("escape"));

            string[] magics = generalNode.GetAttribute("magic").Split(',');

            for (int m = 0; m < 4; m++)
            {
                gInfo.magic[m] = int.Parse(magics[m]);
            }

            Informations.Instance.SetGeneralInfo(i++, gInfo);

            //check
            gInfo.soldierCur = Mathf.Clamp(gInfo.soldierCur, 0, gInfo.soldierMax);
            gInfo.knightCur  = Mathf.Clamp(gInfo.knightCur, 0, gInfo.knightMax);
        }

        nodeList = root.SelectNodes("ArmiesInfo");
        if (nodeList != null && nodeList.Count > 0)
        {
            i = 0;
            foreach (XmlElement armyNode in nodeList)
            {
                ArmyInfo armyInfo = new ArmyInfo();
                armyInfo.king      = int.Parse(armyNode.GetAttribute("king"));
                armyInfo.cityFrom  = int.Parse(armyNode.GetAttribute("cityFrom"));
                armyInfo.cityTo    = int.Parse(armyNode.GetAttribute("cityTo"));
                armyInfo.commander = int.Parse(armyNode.GetAttribute("commander"));
                armyInfo.money     = int.Parse(armyNode.GetAttribute("money"));
                armyInfo.state     = int.Parse(armyNode.GetAttribute("state"));
                armyInfo.direction = int.Parse(armyNode.GetAttribute("direction"));
                armyInfo.isFlipped = bool.Parse(armyNode.GetAttribute("isFlipped"));
                armyInfo.pos       = StringToVector3(armyNode.GetAttribute("pos"));
                armyInfo.timeTick  = float.Parse(armyNode.GetAttribute("timeTick"));

                if (armyNode.HasAttribute("generals"))
                {
                    string[] generals = armyNode.GetAttribute("generals").Split(',');
                    for (int j = 0; j < generals.Length; j++)
                    {
                        int temp = int.Parse(generals[j]);
                        armyInfo.generals.Add(temp);
                        //check
                        GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(temp);
                        gInfo.city        = -1;
                        gInfo.king        = armyInfo.king;
                        gInfo.prisonerIdx = -1;
                    }
                }

                if (armyInfo.generals.Count == 0)
                {
                    continue;
                }

                if (armyNode.HasAttribute("prisons"))
                {
                    string[] prisons = armyNode.GetAttribute("prisons").Split(',');
                    for (int j = 0; j < prisons.Length; j++)
                    {
                        int temp = int.Parse(prisons[j]);
                        armyInfo.prisons.Add(temp);
                        //check
                        GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(temp);
                        gInfo.city        = -1;
                        gInfo.prisonerIdx = armyInfo.king;
                    }
                }

                Informations.Instance.armys.Add(armyInfo);
            }
        }

        Informations.Instance.InitKingInfo();
        Informations.Instance.InitCityInfo();

        if (recordCallback != null)
        {
            recordCallback();
        }
    }