Пример #1
0
    public void OnClick()
    {
        audioSources = GameObject.Find("SEController").GetComponents <AudioSource> ();
        audioSources [5].Play();

        //Hyourou
        int hyourou    = PlayerPrefs.GetInt("hyourou");
        int newHyourou = hyourou - 10;

        PlayerPrefs.SetInt("hyourou", newHyourou);
        GameObject.Find("HyourouCurrentValue").GetComponent <Text> ().text = newHyourou.ToString();

        //Track
        int TrackToubatsuNo = PlayerPrefs.GetInt("TrackToubatsuNo", 0);

        TrackToubatsuNo = TrackToubatsuNo + 1;
        PlayerPrefs.SetInt("TrackToubatsuNo", TrackToubatsuNo);

        MainStageController script = GameObject.Find("GameController").GetComponent <MainStageController> ();

        myKuniQty             = script.myKuniQty;
        myDaimyo              = script.myDaimyo;
        myKuniQtyIsBiggestFlg = GameObject.Find("bakuhuReturn").GetComponent <BakuhuMenuReturn> ().myKuniQtyIsBiggestFlg;
        List <string> messageList = new List <string> ();

        //reduce yukoudo
        Gaikou   gaikou   = new Gaikou();
        DoGaikou doGaikou = new DoGaikou();
        int      myGaikouValueWithTarget = gaikou.getMyGaikou(targetDaimyoId);
        int      newYukoudoWithTarget    = gaikou.downMyGaikou(targetDaimyoId, myGaikouValueWithTarget, 50);
        int      reducedValueWithTarget  = myGaikouValueWithTarget - newYukoudoWithTarget;
        string   firstKassenText         = "";

        if (Application.systemLanguage != SystemLanguage.Japanese)
        {
            firstKassenText = "Declared " + targetDaimyoName + " attack order. \n Friendship reduced " + reducedValueWithTarget + " point.";
        }
        else
        {
            firstKassenText = targetDaimyoName + "討伐を宣言しました。\n当家との友好度が" + reducedValueWithTarget + "下がります。";
        }
        doGaikou.downYukouOnIcon(targetDaimyoId, newYukoudoWithTarget);
        messageList.Add(firstKassenText);

        //doumei check
        Doumei   doumei         = new Doumei();
        KuniInfo kuni           = new KuniInfo();
        bool     doumeiExistFlg = doumei.myDoumeiExistCheck(targetDaimyoId);

        if (doumeiExistFlg)
        {
            doumei.deleteDoumei(myDaimyo.ToString(), targetDaimyoId.ToString());

            //Change Map & Yukoudo
            kuni.deleteDoumeiKuniIcon(targetDaimyoId);
        }
        PlayerPrefs.Flush();


        //Listup Target kuni Id
        string        seiryoku     = PlayerPrefs.GetString("seiryoku");
        List <string> seiryokuList = new List <string> ();

        char[] delimiterChars = { ',' };
        seiryokuList = new List <string> (seiryoku.Split(delimiterChars));
        List <int> targetKuniList = new List <int> ();

        for (int i = 0; i < seiryokuList.Count; i++)
        {
            if (int.Parse(seiryokuList [i]) == targetDaimyoId)
            {
                int kuniId = i + 1;
                targetKuniList.Add(kuniId);
            }
        }

        //Listup Available Open kuni
        List <string>           srcDstKuniList = new List <string> ();
        Entity_kuni_mapping_mst kuniMapMst     = Resources.Load("Data/kuni_mapping_mst") as Entity_kuni_mapping_mst;

        for (int j = 0; j < targetKuniList.Count; j++)
        {
            int tmpTargetKuniId = targetKuniList [j];

            for (int i = 0; i < kuniMapMst.param.Count; i++)
            {
                int temClearedKuniId = kuniMapMst.param[i].Souce;
                if (temClearedKuniId == tmpTargetKuniId)
                {
                    int openKuniId = kuniMapMst.param [i].Open;

                    if (int.Parse(seiryokuList [openKuniId - 1]) != targetDaimyoId &&
                        int.Parse(seiryokuList [openKuniId - 1]) != myDaimyo)
                    {
                        srcDstKuniList.Add(openKuniId.ToString() + "-" + tmpTargetKuniId.ToString());
                    }
                }
            }
        }

        //Shuffule
        for (int i = 0; i < srcDstKuniList.Count; i++)
        {
            string temp        = srcDstKuniList[i];
            int    randomIndex = Random.Range(i, srcDstKuniList.Count);
            srcDstKuniList[i]           = srcDstKuniList[randomIndex];
            srcDstKuniList[randomIndex] = temp;
        }

        /*Condition of succesful*/
        //1. number of own kuni is more thab twice as number as target ... 20%
        //2. number of own kuni is the largest ... 30%
        //3. relathionship btwn my party and src kuni is 100% ... 20%
        //4. relathionship btwn the other countiries each other is 0% ... 20%
        //5. attacker keep kuni number more than country receiving attack ... 10%

        //1.
        if (myKuniQty > 2 * kuniQty)
        {
            baseRatio = 20;
        }

        //2.
        if (myKuniQtyIsBiggestFlg)
        {
            baseRatio = baseRatio + 30;
        }

        //Make Gunzei
        char[]           delimiterChars2    = { '-' };
        GameObject       BakuhuKuniIconView = GameObject.Find("BakuhuKuniIconView").gameObject;
        string           path              = "Prefabs/Map/Gunzei";
        string           visualizePath     = "Prefabs/Bakuhu/ToubatsuSrcBusyo";
        GameObject       panel             = GameObject.Find("Panel").gameObject;
        Gunzei           gunzei            = new Gunzei();
        Daimyo           daimyo            = new Daimyo();
        MainEventHandler mEvent            = new MainEventHandler();
        List <int>       doneSrcDaimyoList = new List <int> ();

        for (int k = 0; k < srcDstKuniList.Count; k++)
        {
            float indvRatio = 0;

            string        key        = srcDstKuniList[k];
            List <string> srcDstList = new List <string> ();
            srcDstList = new List <string> (key.Split(delimiterChars2));

            //3
            int srcKuniId = int.Parse(srcDstList[0]);
            int srcDaimyo = int.Parse(seiryokuList[srcKuniId - 1]);

            if (!doneSrcDaimyoList.Contains(srcDaimyo))
            {
                doneSrcDaimyoList.Add(srcDaimyo);
                bool ExistFlg = false;
                foreach (GameObject obs in  GameObject.FindGameObjectsWithTag("Gunzei"))
                {
                    int gunzeiSrcDaimyoId = obs.GetComponent <Gunzei>().srcDaimyoId;

                    if (srcDaimyo == gunzeiSrcDaimyoId)
                    {
                        ExistFlg = true;
                    }
                }

                if (!ExistFlg)
                {
                    int myGaikouValue = gaikou.getMyGaikou(srcDaimyo);
                    indvRatio = baseRatio + (float)myGaikouValue / 5;

                    //4.
                    int dstKuniId        = int.Parse(srcDstList [1]);
                    int dstDaimyo        = int.Parse(seiryokuList [dstKuniId - 1]);
                    int otherGaikouValue = gaikou.getOtherGaikouValue(srcDaimyo, dstDaimyo);
                    indvRatio = indvRatio + (float)((100 - otherGaikouValue) / 5);

                    //5.
                    int   srcKuniQty = BakuhuKuniIconView.transform.FindChild(srcDstList [0]).GetComponent <SendParam> ().kuniQty;
                    float addRatio   = 0;
                    if (srcKuniQty >= kuniQty)
                    {
                        addRatio  = 10;
                        indvRatio = indvRatio + addRatio;
                    }

                    //Success Check
                    float percent = UnityEngine.Random.value;
                    percent = percent * 100;
                    if (percent <= indvRatio)
                    {
                        //OK
                        toubatsuFlg = true;
                        GameObject Gunzei = Instantiate(Resources.Load(path)) as GameObject;
                        Gunzei.transform.SetParent(panel.transform);
                        Gunzei.transform.localScale = new Vector2(1, 1);

                        GameObject minGunzei = Instantiate(Resources.Load(visualizePath)) as GameObject;
                        minGunzei.transform.SetParent(BakuhuKuniIconView.transform);
                        int    daimyoBusyoId = daimyo.getDaimyoBusyoId(srcDaimyo);
                        string daimyoPath    = "Prefabs/Player/Sprite/unit" + daimyoBusyoId.ToString();
                        minGunzei.GetComponent <SpriteRenderer> ().sprite =
                            Resources.Load(daimyoPath, typeof(Sprite)) as Sprite;

                        //Location
                        int    srcX      = kuni.getKuniLocationX(srcKuniId);
                        int    srcY      = kuni.getKuniLocationY(srcKuniId);
                        int    dstX      = kuni.getKuniLocationX(dstKuniId);
                        int    dstY      = kuni.getKuniLocationY(dstKuniId);
                        string direction = "";

                        if (srcX < dstX)
                        {
                            Gunzei.transform.localScale    = new Vector2(1, 1);
                            minGunzei.transform.localScale = new Vector2(60, 72);
                            direction = "right";
                        }
                        else
                        {
                            Gunzei.transform.localScale    = new Vector2(-1, 1);
                            minGunzei.transform.localScale = new Vector2(-60, 72);
                            direction = "left";
                            Gunzei.GetComponent <Gunzei> ().leftFlg = true;
                        }

                        int           aveX            = (srcX + dstX) / 2;
                        int           aveY            = (srcY + dstY) / 2;
                        RectTransform GunzeiTransform = Gunzei.GetComponent <RectTransform> ();
                        GunzeiTransform.anchoredPosition = new Vector3(aveX, aveY, 0);

                        RectTransform minGunzeiTransform = minGunzei.GetComponent <RectTransform> ();
                        float         minAveX            = (float)aveX * 0.8f;
                        float         minAveY            = (float)aveY * 0.65f;
                        minGunzeiTransform.anchoredPosition = new Vector3((int)minAveX, (int)minAveY, 0);


                        Gunzei.GetComponent <Gunzei> ().key         = key;
                        Gunzei.GetComponent <Gunzei> ().srcKuni     = srcKuniId;
                        Gunzei.GetComponent <Gunzei> ().srcDaimyoId = srcDaimyo;
                        string srcDaimyoName = daimyo.getName(srcDaimyo);
                        Gunzei.GetComponent <Gunzei> ().srcDaimyoName = srcDaimyoName;
                        Gunzei.GetComponent <Gunzei> ().dstKuni       = dstKuniId;
                        Gunzei.GetComponent <Gunzei> ().dstDaimyoId   = dstDaimyo;
                        string dstDaimyoName = daimyo.getName(dstDaimyo);
                        Gunzei.GetComponent <Gunzei> ().dstDaimyoName = dstDaimyoName;
                        int myHei = gunzei.heiryokuCalc(srcKuniId);

                        //random myHei from -50%-myHei
                        List <float> randomPercent = new List <float> {
                            0.8f, 0.9f, 1.0f
                        };
                        int   rmd = UnityEngine.Random.Range(0, randomPercent.Count);
                        float per = randomPercent [rmd];
                        myHei = Mathf.CeilToInt(myHei * per);

                        Gunzei.GetComponent <Gunzei> ().myHei = myHei;
                        Gunzei.name = key;

                        //Engun from Doumei
                        List <string> doumeiDaimyoList = new List <string> ();
                        bool          dstEngunFlg      = false;
                        string        dstEngunDaimyoId = "";             //2:3:5
                        string        dstEngunHei      = "";
                        string        dstEngunSts      = "";             //BusyoId-BusyoLv-ButaiQty-ButaiLv:
                        int           totalEngunHei    = 0;

                        //Doumei Check
                        doumeiDaimyoList = doumei.doumeiExistCheck(dstDaimyo, srcDaimyo.ToString());
                        string doumeiCheck = "doumei" + srcDaimyo;
                        if (PlayerPrefs.HasKey(doumeiCheck))
                        {
                            string        cDoumei     = PlayerPrefs.GetString(doumeiCheck);
                            List <string> cDoumeiList = new List <string>();
                            if (cDoumei.Contains(","))
                            {
                                cDoumeiList = new List <string> (cDoumei.Split(delimiterChars));
                            }
                            else
                            {
                                cDoumeiList.Add(cDoumei);
                            }

                            //If Doumei Daimyo -> Delete
                            if (cDoumeiList.Contains(dstDaimyo.ToString()))
                            {
                                doumei.deleteDoumei(srcDaimyo.ToString(), dstDaimyo.ToString());
                            }
                        }

                        if (doumeiDaimyoList.Count != 0)
                        {
                            //Doumei Exist

                            //Trace Check
                            List <string> okDaimyoList = new List <string> ();
                            List <string> checkList    = new List <string> ();
                            okDaimyoList = doumei.traceNeighborDaimyo(dstKuniId, dstDaimyo, doumeiDaimyoList, seiryokuList, checkList, okDaimyoList);

                            if (okDaimyoList.Count != 0)
                            {
                                //Doumei & Neghbor Daimyo Exist

                                for (int h = 0; h < okDaimyoList.Count; h++)
                                {
                                    string engunDaimyo = okDaimyoList[h];
                                    int    yukoudo     = gaikou.getExistGaikouValue(int.Parse(engunDaimyo), dstDaimyo);

                                    //engun check

                                    dstEngunFlg = mEvent.CheckByProbability(yukoudo);
                                    if (dstEngunFlg)
                                    {
                                        //Engun OK
                                        dstEngunFlg = true;
                                        if (dstEngunDaimyoId != null && dstEngunDaimyoId != "")
                                        {
                                            dstEngunDaimyoId = dstEngunDaimyoId + ":" + engunDaimyo;
                                            string tempEngunSts = engunDaimyo + "-" + mEvent.getEngunSts(engunDaimyo);
                                            int    tempEngunHei = mEvent.getEngunHei(tempEngunSts);
                                            dstEngunHei   = dstEngunHei + ":" + tempEngunHei.ToString();
                                            totalEngunHei = totalEngunHei + tempEngunHei;
                                            dstEngunSts   = dstEngunSts + ":" + tempEngunSts;
                                        }
                                        else
                                        {
                                            dstEngunDaimyoId = engunDaimyo;
                                            string tempEngunSts = engunDaimyo + "-" + mEvent.getEngunSts(engunDaimyo);
                                            int    tempEngunHei = mEvent.getEngunHei(tempEngunSts);
                                            dstEngunHei   = tempEngunHei.ToString();
                                            totalEngunHei = tempEngunHei;
                                            dstEngunSts   = tempEngunSts;
                                        }
                                    }
                                }
                                Gunzei.GetComponent <Gunzei> ().dstEngunFlg      = dstEngunFlg;
                                Gunzei.GetComponent <Gunzei> ().dstEngunDaimyoId = dstEngunDaimyoId;
                                Gunzei.GetComponent <Gunzei> ().dstEngunHei      = dstEngunHei;
                                Gunzei.GetComponent <Gunzei> ().dstEngunSts      = dstEngunSts;
                            }
                        }

                        //Set Value
                        //CreateTime,srcDaimyoId,dstDaimyoId,srcDaimyoName,dstDaimyoName, srcHei,locationX,locationY,left or right, engunFlg, engunDaimyoId(A:B:C), dstEngunHei(1000:2000:3000), dstEngunSts
                        string keyValue   = "";
                        string createTime = System.DateTime.Now.ToString();
                        keyValue = createTime + "," + srcDaimyo + "," + dstDaimyo + "," + srcDaimyoName + "," + dstDaimyoName + "," + myHei + "," + aveX + "," + aveY + "," + direction + "," + dstEngunFlg + "," + dstEngunDaimyoId + "," + dstEngunHei + "," + dstEngunSts;
                        PlayerPrefs.SetString(key, keyValue);
                        string keyHistory = PlayerPrefs.GetString("keyHistory");
                        if (keyHistory == null || keyHistory == "")
                        {
                            keyHistory = key;
                        }
                        else
                        {
                            keyHistory = keyHistory + "," + key;
                        }
                        PlayerPrefs.SetString("keyHistory", keyHistory);
                        PlayerPrefs.SetInt("bakuhuTobatsuDaimyoId", dstDaimyo);
                        PlayerPrefs.Flush();

                        string kassenText = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            if (!dstEngunFlg)
                            {
                                kassenText = srcDaimyoName + " is attacking " + dstDaimyoName + " with " + myHei + " soldiers.";
                            }
                            else
                            {
                                kassenText = srcDaimyoName + " is attacking " + dstDaimyoName + " with " + myHei + " soldiers.\n Defender's allianced country sent " + totalEngunHei + " soldiers.";
                            }
                        }
                        else
                        {
                            if (!dstEngunFlg)
                            {
                                kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしました。";
                            }
                            else
                            {
                                kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしました。\n防衛側の同盟国が援軍" + totalEngunHei + "人を派兵しました。";
                            }
                        }
                        messageList.Add(kassenText);
                    }
                    else
                    {
                        //NG
                        string kassenText    = "";
                        string srcDaimyoName = daimyo.getName(srcDaimyo);
                        int    newYukoudo    = gaikou.downMyGaikou(srcDaimyo, myGaikouValue, 15);
                        int    reducedValue  = myGaikouValue - newYukoudo;
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            kassenText = srcDaimyoName + " rejected our attack order. Friendship reduced " + reducedValue + " point.";
                        }
                        else
                        {
                            kassenText = srcDaimyoName + "が討伐令を黙殺しました。当家との友好度が" + reducedValue + "下がります。";
                        }
                        doGaikou.downYukouOnIcon(srcDaimyo, newYukoudo);
                        messageList.Add(kassenText);
                    }
                }
            }
        }


        //Disabled
        foreach (Transform obj in BakuhuKuniIconView.transform)
        {
            if (obj.GetComponent <Button> ())
            {
                obj.GetComponent <Button> ().enabled = false;
            }
        }

        GameObject toubatsuSelect = GameObject.Find("ToubatsuSelect").gameObject;

        toubatsuSelect.transform.FindChild("ToubatsuBtn").gameObject.SetActive(false);
        if (toubatsuFlg)
        {
            audioSources [3].Play();
            if (Application.systemLanguage != SystemLanguage.Japanese)
            {
                toubatsuSelect.transform.FindChild("Exp").GetComponent <Text> ().text = "Declared " + targetDaimyoName + " attack order. Other family responded to it.";
            }
            else
            {
                toubatsuSelect.transform.FindChild("Exp").GetComponent <Text>().text = targetDaimyoName + "の討伐令を出しました。諸大名が呼応したようです。";
            }
        }
        else
        {
            audioSources [4].Play();
            if (srcDstKuniList.Count == 0)
            {
                if (Application.systemLanguage != SystemLanguage.Japanese)
                {
                    toubatsuSelect.transform.FindChild("Exp").GetComponent <Text> ().text = "There is no family who can respond to " + targetDaimyoName + " attack order.";
                }
                else
                {
                    toubatsuSelect.transform.FindChild("Exp").GetComponent <Text>().text = "現在" + targetDaimyoName + "の討伐に呼応可能な大名はおりません。";
                }
            }
            else
            {
                if (Application.systemLanguage != SystemLanguage.Japanese)
                {
                    toubatsuSelect.transform.FindChild("Exp").GetComponent <Text> ().text = "No family responded to our attack order because of fear for " + targetDaimyoName + ".";
                }
                else
                {
                    toubatsuSelect.transform.FindChild("Exp").GetComponent <Text>().text = targetDaimyoName + "を恐れてか、討伐令にどの大名も呼応しませんでした。";
                }
            }
        }

        Message msg = new Message();

        msg.makeSlotMessage(messageList);
    }
Пример #2
0
    public void OnClick()
    {
        AudioSource[] audioSources = GameObject.Find("SEController").GetComponents <AudioSource> ();
        Message       msg          = new Message();

        if (!checkJinkeiAvailable())
        {
            audioSources[4].Play();
            msg.makeUpperMessageOnBoard(msg.getMessage(133));
        }
        else
        {
            //Hyourou Check
            int nowHyourou = PlayerPrefs.GetInt("hyourou");

            if (nowHyourou >= 5)
            {
                audioSources [5].Play();

                //Now on Kuni & Stage
                PlayerPrefs.SetInt("activeKuniId", activeKuniId);
                PlayerPrefs.SetInt("activeStageId", activeStageId);
                PlayerPrefs.SetString("activeStageName", activeStageName);

                //What we can get
                PlayerPrefs.SetInt("activeStageMoney", activeStageMoney);
                PlayerPrefs.SetInt("activeStageExp", activeStageExp);
                PlayerPrefs.SetString("activeItemGrp", activeItemGrp);
                PlayerPrefs.SetString("activeItemType", activeItemType);
                PlayerPrefs.SetInt("activeItemId", activeItemId);
                PlayerPrefs.SetInt("activeItemQty", activeItemQty);

                //For Dramatic Enemy Creation
                PlayerPrefs.SetInt("activeDaimyoId", activeDaimyoId);
                PlayerPrefs.SetInt("activeBusyoQty", activeBusyoQty);
                PlayerPrefs.SetInt("activeBusyoLv", activeBusyoLv);
                PlayerPrefs.SetInt("activeButaiQty", activeButaiQty);
                PlayerPrefs.SetInt("activeButaiLv", activeButaiLv);

                //Gaikou
                int    myDaimyo = PlayerPrefs.GetInt("myDaimyo");
                Gaikou gaikou   = new Gaikou();
                gaikou.downGaikouByAttack(myDaimyo, activeDaimyoId);

                //Reverse Flag
                PlayerPrefs.DeleteKey("isAttackedFlg");
                PlayerPrefs.DeleteKey("isKessenFlg");

                //Player Doumei Flg
                PlayerPrefs.DeleteKey("playerEngunList");

                //Enemy Doumei Handling
                PlayerPrefs.DeleteKey("enemyEngunList");
                string        doumeiTemp        = "doumei" + activeDaimyoId;
                string        enemyDoumeiString = PlayerPrefs.GetString(doumeiTemp);
                char[]        delimiterChars    = { ',' };
                List <string> doumeiList        = new List <string>();
                if (enemyDoumeiString != null && enemyDoumeiString != "")
                {
                    if (enemyDoumeiString.Contains(","))
                    {
                        doumeiList = new List <string> (enemyDoumeiString.Split(delimiterChars));
                    }
                    else
                    {
                        doumeiList.Add(enemyDoumeiString);
                    }
                }
                string        seiryoku     = PlayerPrefs.GetString("seiryoku");
                List <string> seiryokuList = new List <string> ();
                seiryokuList = new List <string> (seiryoku.Split(delimiterChars));

                Doumei        doumei           = new Doumei();
                List <string> okDaimyoList     = new List <string> ();
                List <string> checkedList      = new List <string> ();
                string        dstEngunDaimyoId = "";
                string        dstEngunSts      = ""; //BusyoId-BusyoLv-ButaiQty-ButaiLv:

                okDaimyoList = doumei.traceNeighborDaimyo(activeKuniId, activeDaimyoId, doumeiList, seiryokuList, checkedList, okDaimyoList);

                if (okDaimyoList.Count != 0)
                {
                    for (int k = 0; k < okDaimyoList.Count; k++)
                    {
                        string engunDaimyo = okDaimyoList[k];
                        int    yukoudo     = gaikou.getExistGaikouValue(int.Parse(engunDaimyo), activeDaimyoId);

                        //mydaimyo doumei check
                        bool myDoumeiFlg = false;
                        myDoumeiFlg = doumei.myDoumeiExistCheck(int.Parse(engunDaimyo));
                        if (myDoumeiFlg)
                        {
                            yukoudo = yukoudo / 2;
                        }

                        //engun check
                        MainEventHandler main        = new MainEventHandler();
                        bool             dstEngunFlg = main.CheckByProbability(yukoudo);
                        if (dstEngunFlg)
                        {
                            //Engun OK
                            dstEngunFlg = true;
                            if (dstEngunDaimyoId != null && dstEngunDaimyoId != "")
                            {
                                dstEngunDaimyoId = dstEngunDaimyoId + ":" + engunDaimyo;
                                string tempEngunSts = main.getEngunSts(engunDaimyo);
                                dstEngunSts = dstEngunSts + ":" + engunDaimyo + "-" + tempEngunSts;
                            }
                            else
                            {
                                dstEngunDaimyoId = engunDaimyo;
                                string tempEngunSts = main.getEngunSts(engunDaimyo);
                                dstEngunSts = engunDaimyo + "-" + tempEngunSts;
                            }
                        }
                    }
                    PlayerPrefs.SetString("enemyEngunList", dstEngunSts);
                }


                //Kyoutou Handling

                PlayerPrefs.DeleteKey("tempKyoutouList");
                string tempKyoutouList = "";

                char[]        delimiterChars2   = { ':' };
                char[]        delimiterChars3   = { '-' };
                List <string> unitList          = new List <string> ();
                string        nextKyoutouList   = "";
                string        playerKyoutouList = PlayerPrefs.GetString("playerKyoutouList", "");
                if (playerKyoutouList != null && playerKyoutouList != "")
                {
                    if (playerKyoutouList.Contains(":"))
                    {
                        unitList = new List <string> (playerKyoutouList.Split(delimiterChars2));
                    }
                    else
                    {
                        unitList.Add(playerKyoutouList);
                    }
                    List <string> unit2List = new List <string> ();
                    for (int i = 0; i < unitList.Count; i++)
                    {
                        string playerKyoutouList2 = unitList[i];
                        unit2List = new List <string> (playerKyoutouList2.Split(delimiterChars3));

                        string tempString = unit2List[0] + "-" + unit2List[1] + "-" + unit2List[2] + "-" + unit2List[3] + "-" + unit2List[4];
                        if (unit2List[0] == activeKuniId.ToString())
                        {
                            if (tempKyoutouList != null && tempKyoutouList != "")
                            {
                                tempKyoutouList = tempKyoutouList + ":" + tempString;
                            }
                            else
                            {
                                tempKyoutouList = tempString;
                            }
                        }
                        else
                        {
                            if (nextKyoutouList != "" && nextKyoutouList != null)
                            {
                                nextKyoutouList = nextKyoutouList + ":" + tempString;
                            }
                            else
                            {
                                nextKyoutouList = tempString;
                            }
                        }
                    }
                }

                PlayerPrefs.SetString("tempKyoutouList", tempKyoutouList);
                PlayerPrefs.SetString("playerKyoutouList", nextKyoutouList);


                //Power Keisu
                PlayerPrefs.DeleteKey("activeLink");
                PlayerPrefs.DeleteKey("activePowerType");
                PlayerPrefs.SetInt("activeLink", linkNo);

                //Power Type Config
                if (powerType == 1)
                {
                    int rdm = UnityEngine.Random.Range(0, 3); //1:happen, 0,2:not happen
                    if (rdm == 1)
                    {
                        powerType = 2;
                    }
                }
                else if (powerType == 2)
                {
                    int rdm = UnityEngine.Random.Range(0, 3); //1:happen, 0,2:not happen
                    if (rdm == 1)
                    {
                        powerType = 3;
                    }
                }



                PlayerPrefs.SetInt("activePowerType", powerType);

                PlayerPrefs.Flush();
                //Stop BGM
                GameObject.Find("BGMController").GetComponent <DontDestroySoundOnLoad> ().DestoryFlg = true;

                Stage stage      = new Stage();
                int   stageMapId = stage.getStageMap(activeKuniId, activeStageId);

                if (stageMapId != 4)
                {
                    Application.LoadLevel("preKassen");
                }
                else
                {
                    Application.LoadLevel("preKaisen");
                }
            }
            else
            {
                //Error Message
                audioSources [4].Play();

                msg.hyourouMovieMessage();
            }
        }
    }
Пример #3
0
    public void OnClick()
    {
        Daimyo daimyo = new Daimyo();

        audioSources = GameObject.Find("SEController").GetComponents <AudioSource> ();

        if (name == "YesButton")
        {
            //Hyourou
            int hyourou    = PlayerPrefs.GetInt("hyourou");
            int newHyourou = hyourou - 30;
            PlayerPrefs.SetInt("hyourou", newHyourou);
            GameObject.Find("HyourouCurrentValue").GetComponent <Text> ().text = newHyourou.ToString();

            //Soubuji Flg
            PlayerPrefs.SetBool("soubujireiFlg", true);

            //Listup
            string        seiryoku       = PlayerPrefs.GetString("seiryoku");
            List <string> seiryokuList   = new List <string> ();
            char[]        delimiterChars = { ',' };
            seiryokuList = new List <string> (seiryoku.Split(delimiterChars));

            MainStageController script = GameObject.Find("GameController").GetComponent <MainStageController> ();
            int myKuniQty = script.myKuniQty;
            int myDaimyo  = script.myDaimyo;

            List <int> daimyoIdList      = new List <int> ();
            List <int> mainKuniIdList    = new List <int> ();
            List <int> kuniQtyByDaimyoId = new List <int> ()
            {
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            };
            for (int i = 0; i < seiryokuList.Count; i++)
            {
                int daimyoId = int.Parse(seiryokuList [i]);
                if (daimyoId != myDaimyo)
                {
                    int kuniId = i + 1;

                    if (!daimyoIdList.Contains(daimyoId))
                    {
                        daimyoIdList.Add(daimyoId);
                        mainKuniIdList.Add(kuniId);
                    }
                    kuniQtyByDaimyoId [daimyoId - 1] = kuniQtyByDaimyoId [daimyoId - 1] + 1;
                }
            }


            //Do Soubujirei
            List <string> newSeiryokuList = new List <string> (seiryokuList);
            string        clearedKuni     = PlayerPrefs.GetString("clearedKuni");
            KuniInfo      kuni            = new KuniInfo();
            GameObject    kuniIconView    = GameObject.Find("KuniIconView").gameObject;
            GameObject    panel           = GameObject.Find("Panel").gameObject;
            GameObject    kuniMap         = GameObject.Find("KuniMap").gameObject;
            Doumei        doumei          = new Doumei();
            bool          allClearedFlg   = true;

            for (int k = 0; k < daimyoIdList.Count; k++)
            {
                int    daimyoId   = daimyoIdList [k];
                string daimyoName = daimyo.getName(daimyoId);
                int    kuniQty    = 0;
                kuniQty = kuniQtyByDaimyoId [daimyoId - 1];

                float ratio = 0;
                ratio = (100 - ((float)kuniQty / (float)myKuniQty * 500));

                if (ratio < 0)
                {
                    ratio = 0;
                }
                if (testMode)
                {
                    ratio = 100;
                }


                //Debug.Log (daimyoName+":"+kuniQty +"/"+myKuniQty+"="+ratio);
                float percent = UnityEngine.Random.value;
                percent = percent * 100;
                if (percent <= ratio)
                {
                    //OK
                    for (int j = 0; j < seiryokuList.Count; j++)
                    {
                        if (seiryokuList [j] == daimyoId.ToString())
                        {
                            int kuniId = j + 1;

                            //1.update seiryoku
                            newSeiryokuList [kuniId - 1] = myDaimyo.ToString();

                            //2.update cleaered kuni & kuni1,2,3
                            clearedKuni = clearedKuni + "," + kuniId.ToString();
                            string tmp = "kuni" + kuniId.ToString();
                            PlayerPrefs.SetString(tmp, "1,2,3,4,5,6,7,8,9,10");

                            //3.update openkuni
                            kuni.registerOpenKuni(kuniId);

                            //4.cyouhou delete
                            //Cyouhou Delete
                            string cyouhouTmp = "cyouhou" + kuniId;
                            if (PlayerPrefs.HasKey(cyouhouTmp))
                            {
                                PlayerPrefs.DeleteKey(cyouhouTmp);
                                string        cyouhou     = PlayerPrefs.GetString("cyouhou");
                                List <string> cyouhouList = new List <string> ();
                                if (cyouhou != null && cyouhou != "")
                                {
                                    if (cyouhou.Contains(","))
                                    {
                                        cyouhouList = new List <string> (cyouhou.Split(delimiterChars));
                                    }
                                    else
                                    {
                                        cyouhouList.Add(cyouhou);
                                    }
                                }
                                cyouhouList.Remove(kuniId.ToString());
                                string newCyouhou = "";
                                for (int a = 0; a < cyouhouList.Count; a++)
                                {
                                    if (a == 0)
                                    {
                                        newCyouhou = cyouhouList [a];
                                    }
                                    else
                                    {
                                        newCyouhou = newCyouhou + "," + cyouhouList [a];
                                    }
                                }
                                PlayerPrefs.SetString("cyouhou", newCyouhou);
                            }

                            //5. naisei
                            string naiseiTmp = "naisei" + kuniId;
                            if (!PlayerPrefs.HasKey(naiseiTmp))
                            {
                                PlayerPrefs.SetString(naiseiTmp, "1,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0,0:0");
                            }

                            //Icon Change
                            IconMapValueUpdate(kuniId, myDaimyo, kuniIconView, kuniMap, myKuniQty);
                        }
                    }
                    //Gunzei Check
                    foreach (GameObject GunzeiObj in  GameObject.FindGameObjectsWithTag("Gunzei"))
                    {
                        int gunzeiSrcDaimyoId = GunzeiObj.GetComponent <Gunzei> ().srcDaimyoId;
                        if (daimyoId == gunzeiSrcDaimyoId)
                        {
                            deleteGunzei(GunzeiObj);
                        }
                    }

                    //Message
                    int msgKuniId = mainKuniIdList [k];
                    okNgMessage(true, msgKuniId, kuniIconView, panel, daimyoName);
                }
                else
                {
                    //NG

                    allClearedFlg = false;

                    //Yukoudo 0
                    string tempGaikou = "gaikou" + daimyoId;
                    PlayerPrefs.SetInt(tempGaikou, 0);

                    //doumei clear
                    bool doumeiFlg = doumei.myDoumeiExistCheck(daimyoId);
                    if (doumeiFlg)
                    {
                        doumei.deleteDoumeiMyDaimyo(myDaimyo.ToString(), daimyoId.ToString());
                    }

                    //Icon color & value
                    kuni.deleteDoumeiKuniIcon(daimyoId);

                    //Message
                    int msgKuniId = mainKuniIdList [k];
                    okNgMessage(false, msgKuniId, kuniIconView, panel, daimyoName);
                }
            }

            string newSeiryoku = "";
            for (int l = 0; l < newSeiryokuList.Count; l++)
            {
                if (l == 0)
                {
                    newSeiryoku = newSeiryokuList [l];
                }
                else
                {
                    newSeiryoku = newSeiryoku + "," + newSeiryokuList [l];
                }
            }
            PlayerPrefs.SetString("seiryoku", newSeiryoku);
            PlayerPrefs.SetString("clearedKuni", clearedKuni);
            PlayerPrefs.Flush();


            //Update OpenKuniIcon
            kuni.updateOpenKuni(myDaimyo, newSeiryoku);

            //Close
            board.transform.FindChild("close").GetComponent <CloseBoard> ().onClick();
            soubujiFlgOn(kuniIconView);

            if (allClearedFlg)
            {
                GameObject.Find("GameController").GetComponent <MainStageController> ().gameClearFlg = true;
                PlayerPrefs.SetBool("gameClearFlg", true);
                PlayerPrefs.Flush();
            }
        }
        else
        {
            audioSources [1].Play();
        }

        Destroy(back.gameObject);
        Destroy(confirm.gameObject);
    }