public void mainHandler(){ /*Basic Info*/ //make kuni list string seiryoku = PlayerPrefs.GetString ("seiryoku"); List<string> seiryokuList = new List<string> (); char[] delimiterChars = {','}; seiryokuList = new List<string> (seiryoku.Split (delimiterChars)); int myDaimyo = PlayerPrefs.GetInt ("myDaimyo"); /*Kassen*/ //1. Randome choice Kassen Qty between 0,1,2,3 //2. Ratio 50% check //3. Random choice Kassen Souce Kuni 1-65 //4. Destination Check by Mapping // if Same Daimyo between Kassen Souce & Destination Kuni => Skip // else => Make guntai Instance // 4-1. Destination == myDaimyo // 4-2. Destination == has own relation or master relation // //Message List<string> messageList = new List<string> (); //Count Kassen Qty int kassenQty = CountEnemyAction (); for (int i=1; i<kassenQty+1; i++) { //Check Kassen or Not bool kassenFlg = CheckByProbability (kassenRatio); if (kassenFlg == true) { //target kuni extraction while (true) { int randomKuni = UnityEngine.Random.Range (1, 65); string eDaimyo = seiryokuList [randomKuni - 1]; string tDaimyo = ""; bool doumeiFlg = false; if (eDaimyo != myDaimyo.ToString ()) { //Check Kuni Mapping List<int> targetKuniList = new List<int> (); KuniInfo kuni = new KuniInfo (); targetKuniList = kuni.getMappingKuni (randomKuni); //Yukoudo Check int worstGaikouDaimyo = 0; int worstGaikouValue = 100; int worstGaikouKuni = 0; for (int k=0; k<targetKuniList.Count; k++) { tDaimyo = seiryokuList [targetKuniList [k] - 1]; int gaikouValue = 0; if (eDaimyo != tDaimyo) { if (tDaimyo == myDaimyo.ToString ()) { //Get Gaikou Value string eGaikouM = "gaikou" + eDaimyo; gaikouValue = PlayerPrefs.GetInt (eGaikouM); } else { //Gaikou Data Check string gaikouTemp = ""; if (int.Parse (eDaimyo) < int.Parse (tDaimyo)) { gaikouTemp = eDaimyo + "gaikou" + tDaimyo; } else { gaikouTemp = tDaimyo + "gaikou" + eDaimyo; } if (PlayerPrefs.HasKey (gaikouTemp)) { //exsit gaikouValue = PlayerPrefs.GetInt (gaikouTemp); } else { //non exist //gaikou check gaikouValue = gaikou.getGaikouValue (int.Parse (eDaimyo), int.Parse (tDaimyo)); } } //Compare with Previous one if (worstGaikouValue > gaikouValue) { worstGaikouValue = gaikouValue; worstGaikouDaimyo = int.Parse (tDaimyo); worstGaikouKuni = targetKuniList [k]; } } }//Loop End //Create Guntai Instance if (worstGaikouValue != 100) { int kassenRatio2 = 100 - worstGaikouValue; //doumei check string doumeiCheck = "doumei" + eDaimyo; 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 -> Half Ratio if(cDoumeiList.Contains(worstGaikouDaimyo.ToString())){ doumeiFlg = true; kassenRatio2 = kassenRatio2/2; }else{ doumeiFlg = false; } } Debug.Log ("doumeiFlg:"+doumeiFlg +",src:"+eDaimyo +",dst:"+worstGaikouDaimyo + ",kassen Ratio:" + kassenRatio2); bool GaikouValueFlg = CheckByProbability (kassenRatio2); if (GaikouValueFlg) { //Make Guntai Instance string key = randomKuni.ToString () + "-" + worstGaikouKuni.ToString (); bool ExistFlg = false; //Exist Check Same Daimyo foreach (GameObject obs in GameObject.FindGameObjectsWithTag("Gunzei")){ int gunzeiSrcDaimyoId = obs.GetComponent<Gunzei>().srcDaimyoId; if(int.Parse(eDaimyo) == gunzeiSrcDaimyoId){ ExistFlg = true; } } if(!ExistFlg){ string path = "Prefabs/Map/Gunzei"; GameObject Gunzei = Instantiate (Resources.Load (path)) as GameObject; Gunzei.transform.SetParent (GameObject.Find ("Panel").transform); Gunzei.transform.localScale = new Vector2 (1, 1); //Location int srcX = kuni.getKuniLocationX(randomKuni); int srcY = kuni.getKuniLocationY(randomKuni); int dstX = kuni.getKuniLocationX(worstGaikouKuni); int dstY = kuni.getKuniLocationY(worstGaikouKuni); string direction = ""; Gunzei gunzei = new Gunzei (); if(srcX < dstX){ Gunzei.transform.localScale = new Vector2 (1, 1); direction = "right"; }else{ Gunzei.transform.localScale = new Vector2 (-1, 1); 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); Gunzei.GetComponent<Gunzei> ().key = key; Gunzei.GetComponent<Gunzei> ().srcKuni = randomKuni; Gunzei.GetComponent<Gunzei> ().srcDaimyoId = int.Parse (eDaimyo); string srcDaimyoName = daimyo.getName (int.Parse (eDaimyo)); Gunzei.GetComponent<Gunzei> ().srcDaimyoName = srcDaimyoName; Gunzei.GetComponent<Gunzei> ().dstKuni = worstGaikouKuni; Gunzei.GetComponent<Gunzei> ().dstDaimyoId = worstGaikouDaimyo; string dstDaimyoName = daimyo.getName (worstGaikouDaimyo); Gunzei.GetComponent<Gunzei> ().dstDaimyoName = dstDaimyoName; int myHei = gunzei.heiryokuCalc (randomKuni); Gunzei.GetComponent<Gunzei> ().myHei = myHei; Gunzei.name = key; //Engun from Doumei Doumei doumei = new 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; doumeiDaimyoList = doumei.doumeiExistCheck(worstGaikouDaimyo,eDaimyo); if(doumeiDaimyoList.Count != 0){ //Doumei Exist //Trace Check List<string> okDaimyoList = new List<string> (); List<string> checkList = new List<string> (); okDaimyoList = doumei.traceNeighborDaimyo(worstGaikouKuni, worstGaikouDaimyo, doumeiDaimyoList, seiryokuList, checkList,okDaimyoList); if(okDaimyoList.Count !=0){ //Doumei & Neghbor Daimyo Exist for(int k=0; k<okDaimyoList.Count; k++){ string engunDaimyo = okDaimyoList[k]; int yukoudo = gaikou.getExistGaikouValue(int.Parse(engunDaimyo), worstGaikouDaimyo); //engun check dstEngunFlg = CheckByProbability (yukoudo); if(dstEngunFlg){ //Engun OK dstEngunFlg = true; if(dstEngunDaimyoId !=null && dstEngunDaimyoId !=""){ dstEngunDaimyoId = dstEngunDaimyoId + ":" + engunDaimyo; string tempEngunSts = getEngunSts(engunDaimyo); int tempEngunHei = getEngunHei(tempEngunSts); dstEngunHei = dstEngunHei + ":" + tempEngunHei.ToString(); totalEngunHei = totalEngunHei + tempEngunHei; dstEngunSts = dstEngunSts + ":" + tempEngunSts; }else{ dstEngunDaimyoId = engunDaimyo; string tempEngunSts = getEngunSts(engunDaimyo); int tempEngunHei = 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 + "," + eDaimyo + "," + worstGaikouDaimyo + "," + 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); flush (); string kassenText = ""; if(!dstEngunFlg){ kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしましたぞ。"; }else{ kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしましたぞ。\t同盟国が援軍" + totalEngunHei + "人を派兵しました。"; } messageList.Add (kassenText); if(doumeiFlg){ //Delete doumei Debug.Log (eDaimyo +":"+ worstGaikouDaimyo); doumei.deleteDoumei(eDaimyo, worstGaikouDaimyo.ToString()); //Zero Gaikou string tempYukou = ""; if(tDaimyo == myDaimyo.ToString()){ tempYukou = "gaikou" + eDaimyo; }else{ if(worstGaikouDaimyo < int.Parse(eDaimyo)){ tempYukou = worstGaikouDaimyo.ToString() + "gaikou" + eDaimyo; }else{ tempYukou = eDaimyo + "gaikou" + worstGaikouDaimyo.ToString(); } } PlayerPrefs.SetInt(tempYukou,0); PlayerPrefs.Flush (); } } } } break; } } } } /*Gaikou*/ int gaikouQty = CountEnemyAction (); for (int i=1; i<gaikouQty+1; i++) { bool gaikouFlg = CheckByProbability (gaikouRatio); if (gaikouFlg == true) { //Do gaikou int randomKuni = UnityEngine.Random.Range (1, 66); int srcDaimyoId = int.Parse (seiryokuList [randomKuni - 1]); string srcDaimyoName = daimyo.getName (srcDaimyoId); if (srcDaimyoId != myDaimyo) { int gaikouAction = UnityEngine.Random.Range (1, 3); if (gaikouAction == 1) { //1. yukoudo up(Mitsugimono) bool yukoudoUpFlg = CheckByProbability (yukoudoUpMissRatio); if (yukoudoUpFlg == true) { //Choose Target Daimyo int randomDstKuni = UnityEngine.Random.Range (1, 66); int dstDaimyoId = int.Parse (seiryokuList [randomDstKuni - 1]); string dstDaimyoName = daimyo.getName (dstDaimyoId); if (srcDaimyoId != dstDaimyoId) { if (dstDaimyoId == myDaimyo) { //In the case that MyDaimyo receive Mitsugimono int addYukoudo = UpYukouValueWithMyDaimyo (myDaimyo, dstDaimyoId); int addMoney = addYukoudo * 1000; string yukouUpText = srcDaimyoName + "殿が御屋形様に、金" + addMoney.ToString() + "の貢物を送って参りました。\t友好度が" + addYukoudo + "上がります。"; int myMoney = PlayerPrefs.GetInt("money"); myMoney = myMoney + addMoney; PlayerPrefs.SetInt("money",myMoney); flush (); GameObject.Find ("MoneyValue").GetComponent<Text>().text = myMoney.ToString(); messageList.Add (yukouUpText); } else { //In the case between other daimyos int addYukoudo = UpYukouValueWithMyDaimyo (myDaimyo, dstDaimyoId); string yukouUpText = srcDaimyoName + "が" + dstDaimyoName + "に貢物をしました。友好度が" + addYukoudo + "上がります。"; messageList.Add (yukouUpText); } } } } else if (gaikouAction == 2) { //2. yukoudo down(Ryugen) bool yukoudoDownFlg = CheckByProbability (yukoudoDownMissRatio); if (yukoudoDownFlg == true) { //Choose Target Daimyo int randomDst1stKuni = UnityEngine.Random.Range (1, 66); int dst1stDaimyoId = int.Parse (seiryokuList [randomDst1stKuni - 1]); int randomDst2ndKuni = UnityEngine.Random.Range (1, 66); int dst2ndDaimyoId = int.Parse (seiryokuList [randomDst2ndKuni - 1]); if (dst1stDaimyoId != dst2ndDaimyoId) { int reduceYukoudo = 0; //My Daimyo if (dst1stDaimyoId == myDaimyo || dst2ndDaimyoId == myDaimyo) { string dstDaimyoName = ""; if (dst1stDaimyoId == myDaimyo) { reduceYukoudo = DownYukouValueWithMyDaimyo (myDaimyo, dst2ndDaimyoId); dstDaimyoName = daimyo.getName (dst1stDaimyoId); } if (dst2ndDaimyoId == myDaimyo) { reduceYukoudo = DownYukouValueWithMyDaimyo (myDaimyo, dst1stDaimyoId); dstDaimyoName = daimyo.getName (dst2ndDaimyoId); } //string yukouDownText = srcDaimyoName + "が当家と" + dstDaimyoName + "に流言を流し、友好度が" + dstDaimyoName + "下がりました。"; string yukouDownText = "何者かが当家と" + dstDaimyoName + "間に流言を流し、友好度が" + reduceYukoudo + "下がりました。"; messageList.Add (yukouDownText); } else { reduceYukoudo = DownYukouValueWithOther (dst1stDaimyoId, dst2ndDaimyoId); string dst1stDaimyoName = daimyo.getName (dst1stDaimyoId); string dst2ndDaimyoName = daimyo.getName (dst2ndDaimyoId); string yukouDownText = "何者かが" + dst1stDaimyoName + "と" + dst2ndDaimyoName + "間に流言を流し、友好度が" + reduceYukoudo + "下がりました。"; messageList.Add (yukouDownText); } } } } else if (gaikouAction == 3) { //doumei bool doumeiFlg = CheckByProbability (doumeiRatio); if (doumeiFlg == true) { } } else if (gaikouAction == 4) { } } } } /*Nanbanjin*/ /**/ /*Decrease Yukou with Doumei koku*/ string myDoumei = PlayerPrefs.GetString ("doumei"); List<string> myDoumeiList = new List<string> (); if (myDoumei != null && myDoumei != "") { if(myDoumei.Contains(",")){ myDoumeiList = new List<string> (myDoumei.Split (delimiterChars)); }else{ myDoumeiList.Add(myDoumei); } } for (int j=0; j<myDoumeiList.Count; j++) { string doumeiDaimyo = myDoumeiList[j]; string yukouTemp = "gaikou" + doumeiDaimyo; int yukouWithDoumei = PlayerPrefs.GetInt (yukouTemp); int reduceYukou = UnityEngine.Random.Range(0,3); yukouWithDoumei = yukouWithDoumei - reduceYukou; PlayerPrefs.SetInt (yukouTemp,yukouWithDoumei); /*Doumei Clear Check*/ if(yukouWithDoumei<30){ //My Doumei Clear myDoumeiList.Remove(doumeiDaimyo); string newMyDoumei = ""; for(int i=0; i<myDoumeiList.Count; i++){ if(i==0){ newMyDoumei = myDoumeiList[i]; }else{ newMyDoumei = newMyDoumei + "," + myDoumeiList[i]; } } PlayerPrefs.SetString ("doumei",newMyDoumei); //Opposite Doumei Clear string otherTemp = "doumei" + doumeiDaimyo; string otherDoumei = PlayerPrefs.GetString (otherTemp); List<string> otherDoumeiList = new List<string> (); if (otherDoumei != null && otherDoumei != "") { if(otherDoumei.Contains(",")){ otherDoumeiList = new List<string> (otherDoumei.Split (delimiterChars)); }else{ otherDoumeiList.Add(otherDoumei); } } otherDoumeiList.Remove(myDaimyo.ToString()); string newOtherDoumei = ""; for(int i=0; i<otherDoumeiList.Count; i++){ if(i==0){ newOtherDoumei = otherDoumeiList[i]; }else{ newOtherDoumei = newOtherDoumei + "," + otherDoumeiList[i]; } } PlayerPrefs.SetString (otherTemp,newOtherDoumei); //Icon & Flg Change KuniInfo kuni = new KuniInfo(); kuni.deleteDoumeiKuniIcon(int.Parse(doumeiDaimyo)); //Message string dstDaimyoName = daimyo.getName (int.Parse(doumeiDaimyo)); string doumeiClearText = "友好度悪化により、当家と" + dstDaimyoName + "間の同盟が解消しました。"; messageList.Add (doumeiClearText); } PlayerPrefs.Flush(); } /*Message*/ if (messageList.Count != 0) { /*Common Process*/ //make back string pathOfBack = "Prefabs/Common/TouchBack"; GameObject back = Instantiate(Resources.Load (pathOfBack)) as GameObject; back.transform.SetParent(GameObject.Find ("Panel").transform); back.transform.localScale = new Vector2 (1,1); back.transform.localPosition = new Vector2 (0,0); //make board string pathOfBoard = "Prefabs/Event/EventBoard"; GameObject board = Instantiate(Resources.Load (pathOfBoard)) as GameObject; board.transform.SetParent(GameObject.Find ("Panel").transform); board.transform.localScale = new Vector2 (1,1); string pathOfScroll = "Prefabs/Event/EventScrollView"; GameObject scroll = Instantiate(Resources.Load (pathOfScroll)) as GameObject; scroll.transform.SetParent(board.transform); scroll.transform.localScale = new Vector2 (1,1); RectTransform scrollTransform = scroll.GetComponent<RectTransform> (); scrollTransform.anchoredPosition = new Vector3 (0, -40, 0); string pathOfSlot = "Prefabs/Event/EventSlot"; foreach (string text in messageList) { GameObject slot = Instantiate(Resources.Load (pathOfSlot)) as GameObject; slot.transform.SetParent(scroll.transform.FindChild("Content").transform); slot.transform.FindChild("EventText").GetComponent<Text>().text = text; slot.transform.localScale = new Vector2 (1,1); } } }
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); }
public void mainHandler(){ /*Basic Info*/ //make kuni list string seiryoku = PlayerPrefs.GetString ("seiryoku"); List<string> seiryokuList = new List<string> (); char[] delimiterChars = {','}; seiryokuList = new List<string> (seiryoku.Split (delimiterChars)); int myDaimyo = PlayerPrefs.GetInt ("myDaimyo"); GameObject targetKuni = GameObject.Find ("KuniIconView"); /*Kassen*/ //1. Randome choice Kassen Qty between 0,1,2,3 //2. Ratio 50% check //3. Random choice Kassen Souce Kuni 1-65 //4. Destination Check by Mapping // if Same Daimyo between Kassen Souce & Destination Kuni => Skip // else => Make guntai Instance // 4-1. Destination == myDaimyo // 4-2. Destination == has own relation or master relation // //Message List<string> messageList = new List<string> (); //Count Kassen Qty int kassenQty = CountEnemyKassenAction (); for (int i=1; i<kassenQty+1; i++) { //Check Kassen or Not bool kassenFlg = CheckByProbability (kassenRatio); if (kassenFlg == true) { //target kuni extraction while (true) { int randomKuni = UnityEngine.Random.Range (1, 65); string eDaimyo = seiryokuList [randomKuni - 1]; string tDaimyo = ""; bool doumeiFlg = false; if (eDaimyo != myDaimyo.ToString ()) { //Check Kuni Mapping List<int> targetKuniList = new List<int> (); KuniInfo kuni = new KuniInfo (); targetKuniList = kuni.getMappingKuni (randomKuni); //Yukoudo Check int worstGaikouDaimyo = 0; int worstGaikouValue = 100; int worstGaikouKuni = 0; int worstHeiryokuValue = 100000000; SendParam srcSendParam = targetKuni.transform.FindChild (randomKuni.ToString ()).GetComponent<SendParam> (); bool aggressiveFlg = srcSendParam.aggressiveFlg; for (int k=0; k<targetKuniList.Count; k++) { SendParam sendParam = targetKuni.transform.FindChild (targetKuniList [k].ToString ()).GetComponent<SendParam> (); if (aggressiveFlg) { //Find worst gaikou daimyo tDaimyo = seiryokuList [targetKuniList [k] - 1]; int gaikouValue = 0; if (eDaimyo != tDaimyo) { if (tDaimyo == myDaimyo.ToString ()) { //Get Gaikou Value string eGaikouM = "gaikou" + eDaimyo; gaikouValue = PlayerPrefs.GetInt (eGaikouM); } else { //Gaikou Data Check string gaikouTemp = ""; if (int.Parse (eDaimyo) < int.Parse (tDaimyo)) { gaikouTemp = eDaimyo + "gaikou" + tDaimyo; } else { gaikouTemp = tDaimyo + "gaikou" + eDaimyo; } if (PlayerPrefs.HasKey (gaikouTemp)) { //exsit gaikouValue = PlayerPrefs.GetInt (gaikouTemp); } else { //non exist //gaikou check gaikouValue = gaikou.getGaikouValue (int.Parse (eDaimyo), int.Parse (tDaimyo)); } } //Compare with Previous one if (worstGaikouValue > gaikouValue) { worstGaikouValue = gaikouValue; worstGaikouDaimyo = int.Parse (tDaimyo); worstGaikouKuni = targetKuniList [k]; } } } else { //Find worst heiryoku daimyo tDaimyo = seiryokuList [targetKuniList [k] - 1]; if (eDaimyo != tDaimyo) { //Heiryoku Check int heiryoku = sendParam.heiryoku; //Compare with Previous one if (worstHeiryokuValue > heiryoku) { worstHeiryokuValue = heiryoku; int gaikouValue = 0; if (tDaimyo == myDaimyo.ToString ()) { //Get Gaikou Value string eGaikouM = "gaikou" + eDaimyo; gaikouValue = PlayerPrefs.GetInt (eGaikouM); } else { //Gaikou Data Check string gaikouTemp = ""; if (int.Parse (eDaimyo) < int.Parse (tDaimyo)) { gaikouTemp = eDaimyo + "gaikou" + tDaimyo; } else { gaikouTemp = tDaimyo + "gaikou" + eDaimyo; } if (PlayerPrefs.HasKey (gaikouTemp)) { //exsit gaikouValue = PlayerPrefs.GetInt (gaikouTemp); } else { //non exist gaikouValue = gaikou.getGaikouValue (int.Parse (eDaimyo), int.Parse (tDaimyo)); } } worstGaikouValue = gaikouValue; worstGaikouDaimyo = int.Parse (tDaimyo); worstGaikouKuni = targetKuniList [k]; } } } }//Loop End //Create Guntai Instance if (worstGaikouValue != 100) { int kassenRatio2 = 100 - worstGaikouValue; //doumei check string doumeiCheck = "doumei" + eDaimyo; 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 -> Half Ratio if(cDoumeiList.Contains(worstGaikouDaimyo.ToString())){ doumeiFlg = true; kassenRatio2 = kassenRatio2/2; }else{ doumeiFlg = false; } } bool GaikouValueFlg = CheckByProbability (kassenRatio2); if (GaikouValueFlg) { //Make Guntai Instance string key = randomKuni.ToString () + "-" + worstGaikouKuni.ToString (); bool ExistFlg = false; //Exist Check Same Daimyo foreach (GameObject obs in GameObject.FindGameObjectsWithTag("Gunzei")){ int gunzeiSrcDaimyoId = obs.GetComponent<Gunzei>().srcDaimyoId; if(int.Parse(eDaimyo) == gunzeiSrcDaimyoId){ ExistFlg = true; } } if(!ExistFlg){ string path = "Prefabs/Map/Gunzei"; GameObject Gunzei = Instantiate (Resources.Load (path)) as GameObject; Gunzei.transform.SetParent (GameObject.Find ("Panel").transform); Gunzei.transform.localScale = new Vector2 (1, 1); //Location int srcX = kuni.getKuniLocationX(randomKuni); int srcY = kuni.getKuniLocationY(randomKuni); int dstX = kuni.getKuniLocationX(worstGaikouKuni); int dstY = kuni.getKuniLocationY(worstGaikouKuni); string direction = ""; Gunzei gunzei = new Gunzei (); if(srcX < dstX){ Gunzei.transform.localScale = new Vector2 (1, 1); direction = "right"; }else{ Gunzei.transform.localScale = new Vector2 (-1, 1); 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); Gunzei.GetComponent<Gunzei> ().key = key; Gunzei.GetComponent<Gunzei> ().srcKuni = randomKuni; Gunzei.GetComponent<Gunzei> ().srcDaimyoId = int.Parse (eDaimyo); string srcDaimyoName = daimyo.getName (int.Parse (eDaimyo)); Gunzei.GetComponent<Gunzei> ().srcDaimyoName = srcDaimyoName; Gunzei.GetComponent<Gunzei> ().dstKuni = worstGaikouKuni; Gunzei.GetComponent<Gunzei> ().dstDaimyoId = worstGaikouDaimyo; string dstDaimyoName = daimyo.getName (worstGaikouDaimyo); Gunzei.GetComponent<Gunzei> ().dstDaimyoName = dstDaimyoName; int myHei = gunzei.heiryokuCalc (randomKuni); Gunzei.GetComponent<Gunzei> ().myHei = myHei; Gunzei.name = key; //Engun from Doumei Doumei doumei = new 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; doumeiDaimyoList = doumei.doumeiExistCheck(worstGaikouDaimyo,eDaimyo); if(doumeiDaimyoList.Count != 0){ //Doumei Exist //Trace Check List<string> okDaimyoList = new List<string> (); List<string> checkList = new List<string> (); okDaimyoList = doumei.traceNeighborDaimyo(worstGaikouKuni, worstGaikouDaimyo, doumeiDaimyoList, seiryokuList, checkList,okDaimyoList); if(okDaimyoList.Count !=0){ //Doumei & Neghbor Daimyo Exist for(int k=0; k<okDaimyoList.Count; k++){ string engunDaimyo = okDaimyoList[k]; int yukoudo = gaikou.getExistGaikouValue(int.Parse(engunDaimyo), worstGaikouDaimyo); //engun check dstEngunFlg = CheckByProbability (yukoudo); if(dstEngunFlg){ //Engun OK dstEngunFlg = true; if(dstEngunDaimyoId !=null && dstEngunDaimyoId !=""){ dstEngunDaimyoId = dstEngunDaimyoId + ":" + engunDaimyo; string tempEngunSts = getEngunSts(engunDaimyo); int tempEngunHei = getEngunHei(tempEngunSts); dstEngunHei = dstEngunHei + ":" + tempEngunHei.ToString(); totalEngunHei = totalEngunHei + tempEngunHei; dstEngunSts = dstEngunSts + ":" + tempEngunSts; }else{ dstEngunDaimyoId = engunDaimyo; string tempEngunSts = getEngunSts(engunDaimyo); int tempEngunHei = 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 + "," + eDaimyo + "," + worstGaikouDaimyo + "," + 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); flush (); string kassenText = ""; if(!dstEngunFlg){ kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしました。"; }else{ kassenText = srcDaimyoName + "が" + dstDaimyoName + "討伐の兵" + myHei + "人を起こしました。\n防衛側の同盟国が援軍" + totalEngunHei + "人を派兵しました。"; } messageList.Add (kassenText); if(doumeiFlg){ //Delete doumei doumei.deleteDoumei(eDaimyo, worstGaikouDaimyo.ToString()); //Zero Gaikou string tempYukou = ""; if(tDaimyo == myDaimyo.ToString()){ tempYukou = "gaikou" + eDaimyo; }else{ if(worstGaikouDaimyo < int.Parse(eDaimyo)){ tempYukou = worstGaikouDaimyo.ToString() + "gaikou" + eDaimyo; }else{ tempYukou = eDaimyo + "gaikou" + worstGaikouDaimyo.ToString(); } } PlayerPrefs.SetInt(tempYukou,0); PlayerPrefs.Flush (); } } } } break; } } } } /************/ /***Gaikou***/ /************/ int gaikouQty = CountEnemyGaikouAction (); for (int i=1; i<gaikouQty+1; i++) { bool gaikouFlg = CheckByProbability (gaikouRatio); if (gaikouFlg == true) { //Do gaikou int randomKuni = UnityEngine.Random.Range (1, 66); int srcDaimyoId = int.Parse (seiryokuList [randomKuni - 1]); string srcDaimyoName = daimyo.getName (srcDaimyoId); if (srcDaimyoId != myDaimyo) { List<int> targetKuniList = new List<int> (); KuniInfo kuni = new KuniInfo (); targetKuniList = kuni.getMappingKuni (randomKuni); //Yukoudo Check int bestGaikouDaimyo = 0; int bestGaikouValue = 0; int bestGaikouKuni = 0; int bestHeiryokuValue = 0; SendParam sendParamSrc = targetKuni.transform.FindChild (randomKuni.ToString ()).GetComponent<SendParam> (); bool aggressiveFlg = sendParamSrc.aggressiveFlg; for (int k=0; k<targetKuniList.Count; k++) { SendParam sendParam = targetKuni.transform.FindChild (targetKuniList [k].ToString ()).GetComponent<SendParam> (); if (aggressiveFlg) { //Find best gaikou daimyo int dstDaimyoId = int.Parse (seiryokuList [targetKuniList [k] - 1]); int gaikouValue = 0; if (srcDaimyoId != dstDaimyoId) { if (dstDaimyoId == myDaimyo) { //Get Gaikou Value string eGaikouM = "gaikou" + srcDaimyoId; gaikouValue = PlayerPrefs.GetInt (eGaikouM); } else { //Gaikou Data Check string gaikouTemp = ""; if (srcDaimyoId < dstDaimyoId) { gaikouTemp = srcDaimyoId + "gaikou" + dstDaimyoId; } else { gaikouTemp = dstDaimyoId + "gaikou" + srcDaimyoId; } if (PlayerPrefs.HasKey (gaikouTemp)) { //exsit gaikouValue = PlayerPrefs.GetInt (gaikouTemp); } else { //non exist //gaikou check gaikouValue = gaikou.getGaikouValue (srcDaimyoId, dstDaimyoId); } } //Compare with Previous one //Best one if (gaikouValue >= bestGaikouValue) { bestGaikouValue = gaikouValue; bestGaikouDaimyo = dstDaimyoId; bestGaikouKuni = targetKuniList [k]; } } } else { //Find best heiryoku daimyo int dstDaimyoId = int.Parse (seiryokuList [targetKuniList [k] - 1]); if (srcDaimyoId != dstDaimyoId) { //Heiryoku Check int heiryoku = sendParam.heiryoku; //Compare with Previous one if (heiryoku >= bestHeiryokuValue) { bestHeiryokuValue = heiryoku; int gaikouValue = 0; if (dstDaimyoId == myDaimyo) { //Get Gaikou Value string eGaikouM = "gaikou" + srcDaimyoId; gaikouValue = PlayerPrefs.GetInt (eGaikouM); } else { //Gaikou Data Check string gaikouTemp = ""; if (srcDaimyoId < dstDaimyoId) { gaikouTemp = srcDaimyoId + "gaikou" + dstDaimyoId; } else { gaikouTemp = dstDaimyoId + "gaikou" + srcDaimyoId; } if (PlayerPrefs.HasKey (gaikouTemp)) { //exsit gaikouValue = PlayerPrefs.GetInt (gaikouTemp); } else { //non exist gaikouValue = gaikou.getGaikouValue (srcDaimyoId, dstDaimyoId); } } bestGaikouValue = gaikouValue; bestGaikouDaimyo = dstDaimyoId; bestGaikouKuni = targetKuniList [k]; } } } }//Loop End //Gaikou Action float percent = UnityEngine.Random.value; percent = percent * 100; int gaikouAction = 0; if (percent <= 60) { gaikouAction = 1; //Mitsugi } else if (60 < percent && percent <= 97) { gaikouAction = 2; //Ryugen } else if (97 < percent && percent <= 100) { gaikouAction = 3; //Doumei } if (gaikouAction == 1) { //1. yukoudo up(Mitsugimono) bool yukoudoUpFlg = CheckByProbability (yukoudoUpMissRatio); if (yukoudoUpFlg == true) { //Choose Target Daimyo string dstDaimyoName = daimyo.getName (bestGaikouDaimyo); if (bestGaikouDaimyo == myDaimyo) { //In the case that MyDaimyo receive Mitsugimono int addYukoudo = UpYukouValueWithMyDaimyo (myDaimyo, bestGaikouDaimyo); int addMoney = addYukoudo * 1000; string yukouUpText = srcDaimyoName + "殿が御屋形様に、金" + addMoney.ToString() + "の貢物を送って参りました。\t友好度が" + addYukoudo + "上がります。"; int myMoney = PlayerPrefs.GetInt("money"); myMoney = myMoney + addMoney; PlayerPrefs.SetInt("money",myMoney); flush (); GameObject.Find ("MoneyValue").GetComponent<Text>().text = myMoney.ToString(); messageList.Add (yukouUpText); } else { //In the case between other daimyos int addYukoudo = UpYukouValueWithOther (srcDaimyoId, bestGaikouDaimyo); string yukouUpText = srcDaimyoName + "が" + dstDaimyoName + "に貢物をしました。友好度が" + addYukoudo + "上がります。"; messageList.Add (yukouUpText); } } } else if (gaikouAction == 2) { //2. yukoudo down(Ryugen) bool yukoudoDownFlg = CheckByProbability (yukoudoDownMissRatio); if (yukoudoDownFlg == true) { //Choose Target Daimyo int reduceYukoudo = 0; if (bestGaikouDaimyo != 0) { if (bestGaikouDaimyo == myDaimyo) { //My Daimyo string dstDaimyoName = ""; reduceYukoudo = DownYukouValueWithMyDaimyo (myDaimyo, srcDaimyoId); dstDaimyoName = daimyo.getName (srcDaimyoId); string yukouDownText = "何者かが当家と" + dstDaimyoName + "間に流言を流し、友好度が" + reduceYukoudo + "下がりました。"; messageList.Add (yukouDownText); } else { reduceYukoudo = DownYukouValueWithOther (srcDaimyoId, bestGaikouDaimyo); string dst1stDaimyoName = daimyo.getName (srcDaimyoId); string dst2ndDaimyoName = daimyo.getName (bestGaikouDaimyo); string yukouDownText = "何者かが" + dst1stDaimyoName + "と" + dst2ndDaimyoName + "間に流言を流し、友好度が" + reduceYukoudo + "下がりました。"; messageList.Add (yukouDownText); } } } } else if (gaikouAction == 3) { //3. doumei Gaikou gaiko = new Gaikou(); int yukoudo = gaikou.getExistGaikouValue(srcDaimyoId, bestGaikouDaimyo); bool doumeiFlg = CheckByProbability (yukoudo); if (doumeiFlg == true) { if (bestGaikouDaimyo == myDaimyo) { // // // // // // // // } else { //Exist Check string doumeiTmp = "doumei" + srcDaimyoId; string doumeiString = PlayerPrefs.GetString (doumeiTmp); List<string> doumeiList = new List<string> (); if (doumeiString != null && doumeiString != "") { if (doumeiString.Contains (",")) { doumeiList = new List<string> (doumeiString.Split (delimiterChars)); } else { doumeiList.Add (doumeiString); } } if (!doumeiList.Contains (bestGaikouDaimyo.ToString())) { //Not Exist Case //Doumei Data Register string newDoumei1 = ""; if (doumeiString != null && doumeiString != "") { newDoumei1 = doumeiString + "," + bestGaikouDaimyo; } else { newDoumei1 = bestGaikouDaimyo.ToString(); } PlayerPrefs.SetString (doumeiTmp, newDoumei1); string doumeiTmp2 = "doumei" + bestGaikouDaimyo; string doumeiString2 = PlayerPrefs.GetString (doumeiTmp2); string newDoumei2 = ""; if (doumeiString2 != null && doumeiString2 != "") { newDoumei2 = doumeiString2 + "," + srcDaimyoId; } else { newDoumei2 = srcDaimyoId.ToString(); } PlayerPrefs.SetString (doumeiTmp2, newDoumei2); flush (); string dst1stDaimyoName = daimyo.getName (srcDaimyoId); string dst2ndDaimyoName = daimyo.getName (bestGaikouDaimyo); string doumeiText = dst1stDaimyoName + "と" + dst2ndDaimyoName + "間に同盟が成立しました。"; messageList.Add (doumeiText); } } } } //else if (gaikouAction == 4) { //add here //} } } } //Check Shinobi Cyouhou 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); } } for(int i=0; i<cyouhouList.Count; i++){ int kuniId = int.Parse(cyouhouList [i]); string snbTmp = "cyouhou" + kuniId.ToString (); int rank = PlayerPrefs.GetInt(snbTmp); float missPercent = 0; if(rank == 1){ missPercent = 30; }else if(rank == 2){ missPercent = 15; }else if(rank == 3){ missPercent = 5; } float percent = Random.value; percent = percent * 100; if (percent < missPercent) { //Miss PlayerPrefs.DeleteKey(snbTmp); cyouhouList.Remove (kuniId.ToString()); string newCyouhou = ""; for(int j=0;j<cyouhouList.Count;j++){ if (j == 0) { newCyouhou = cyouhouList[j]; } else { newCyouhou = newCyouhou + "," + cyouhouList[j]; } } PlayerPrefs.SetString ("cyouhou",newCyouhou); //Reset Chouhou Id targetKuni.transform.FindChild(kuniId.ToString()).GetComponent<SendParam>().cyouhouSnbRankId = 0; //Message KuniInfo kuni = new KuniInfo(); string kuniName = kuni.getKuniName(kuniId); int daimyoId = int.Parse(seiryokuList [kuniId - 1]); Daimyo daimyo = new Daimyo (); string daimyoName = daimyo.getName (daimyoId); int reduceYukoudo = DownYukouValueWithMyDaimyo (myDaimyo, daimyoId); string cyouhouMissText = kuniName + "に潜伏中の忍が見つかりました。\n" + daimyoName + "との友好度が"+reduceYukoudo+"下がりました。"; messageList.Add (cyouhouMissText); } } PlayerPrefs.Flush(); /*Decrease Yukou with Doumei koku*/ string myDoumei = PlayerPrefs.GetString ("doumei"); List<string> myDoumeiList = new List<string> (); if (myDoumei != null && myDoumei != "") { if(myDoumei.Contains(",")){ myDoumeiList = new List<string> (myDoumei.Split (delimiterChars)); }else{ myDoumeiList.Add(myDoumei); } } for (int j=0; j<myDoumeiList.Count; j++) { string doumeiDaimyo = myDoumeiList[j]; string yukouTemp = "gaikou" + doumeiDaimyo; int yukouWithDoumei = PlayerPrefs.GetInt (yukouTemp); int reduceYukou = UnityEngine.Random.Range(0,3); yukouWithDoumei = yukouWithDoumei - reduceYukou; PlayerPrefs.SetInt (yukouTemp,yukouWithDoumei); /*Doumei Clear Check*/ if(yukouWithDoumei<30){ //My Doumei Clear myDoumeiList.Remove(doumeiDaimyo); string newMyDoumei = ""; for(int i=0; i<myDoumeiList.Count; i++){ if(i==0){ newMyDoumei = myDoumeiList[i]; }else{ newMyDoumei = newMyDoumei + "," + myDoumeiList[i]; } } PlayerPrefs.SetString ("doumei",newMyDoumei); //Opposite Doumei Clear string otherTemp = "doumei" + doumeiDaimyo; string otherDoumei = PlayerPrefs.GetString (otherTemp); List<string> otherDoumeiList = new List<string> (); if (otherDoumei != null && otherDoumei != "") { if(otherDoumei.Contains(",")){ otherDoumeiList = new List<string> (otherDoumei.Split (delimiterChars)); }else{ otherDoumeiList.Add(otherDoumei); } } otherDoumeiList.Remove(myDaimyo.ToString()); string newOtherDoumei = ""; for(int i=0; i<otherDoumeiList.Count; i++){ if(i==0){ newOtherDoumei = otherDoumeiList[i]; }else{ newOtherDoumei = newOtherDoumei + "," + otherDoumeiList[i]; } } PlayerPrefs.SetString (otherTemp,newOtherDoumei); //Icon & Flg Change KuniInfo kuni = new KuniInfo(); kuni.deleteDoumeiKuniIcon(int.Parse(doumeiDaimyo)); //Message string dstDaimyoName = daimyo.getName (int.Parse(doumeiDaimyo)); string doumeiClearText = "友好度悪化により、当家と" + dstDaimyoName + "間の同盟が解消しました。"; messageList.Add (doumeiClearText); } PlayerPrefs.Flush(); } /*Decrease Yukou with Doumei koku in other county*/ List<string> activeDaimyoList = new List<string> (); for (int k=0; k<seiryokuList.Count; k++) { string daimyoId = seiryokuList[k]; if(int.Parse(daimyoId) != myDaimyo && !activeDaimyoList.Contains(daimyoId)){ activeDaimyoList.Add(daimyoId); } } for(int l=0; l<activeDaimyoList.Count; l++){ string activeDaimyoId = activeDaimyoList[l]; string temp = "doumei" + activeDaimyoId; if(PlayerPrefs.HasKey(temp)){ string doumeiString = PlayerPrefs.GetString(temp); if(doumeiString != null && doumeiString != ""){ List<string> doumeiTargetList = new List<string> (); if(doumeiString.Contains(",")){ doumeiTargetList = new List<string> (doumeiString.Split (delimiterChars)); }else{ doumeiTargetList.Add(doumeiString); } for(int m=0; m<doumeiTargetList.Count; m++){ string targetDaimyoId = doumeiTargetList[m]; string gaikoTemp = ""; if(int.Parse(activeDaimyoId)<int.Parse(targetDaimyoId)){ gaikoTemp = activeDaimyoId + "gaikou" + targetDaimyoId; }else{ gaikoTemp = targetDaimyoId + "gaikou" + activeDaimyoId; } if(PlayerPrefs.HasKey(gaikoTemp)){ int gaikouValue = PlayerPrefs.GetInt(gaikoTemp); if(gaikouValue <30){ //Doumei Clear //src to dst doumeiTargetList.Remove(targetDaimyoId); string newDoumei1 = ""; for(int n=0; n<doumeiTargetList.Count; n++){ if(n==0){ newDoumei1 = doumeiTargetList[n]; }else{ newDoumei1 = newDoumei1 +"," + doumeiTargetList[n]; } } PlayerPrefs.SetString(temp,newDoumei1); //dst to src string tgtTemp = "doumei" + targetDaimyoId; string tgtDoumeiString = PlayerPrefs.GetString(tgtTemp); List<string> tgtDoumeiList = new List<string> (); if(tgtDoumeiString!=null && tgtDoumeiString != ""){ if(tgtDoumeiString.Contains(",")){ tgtDoumeiList = new List<string> (tgtDoumeiString.Split (delimiterChars)); }else{ tgtDoumeiList.Add(tgtDoumeiString); } tgtDoumeiList.Remove(activeDaimyoId); string newDoumei2 = ""; for(int n=0; n<tgtDoumeiList.Count; n++){ if(n==0){ newDoumei2 = tgtDoumeiList[n]; }else{ newDoumei2 = newDoumei2 +"," + tgtDoumeiList[n]; } } PlayerPrefs.SetString(tgtTemp,newDoumei2); } string srcDaimyoName = daimyo.getName(int.Parse(activeDaimyoId)); string dstDaimyoName = daimyo.getName(int.Parse(targetDaimyoId)); string doumeiClearText = "友好度悪化により、"+ srcDaimyoName+"と" + dstDaimyoName + "間の同盟が解消しました。"; messageList.Add (doumeiClearText); PlayerPrefs.Flush(); } } } } } } //Delete Cyouryaku Data string cyoryakuHst = PlayerPrefs.GetString("cyouryaku"); List<string> cyoryakuHstList = new List<string> (); if(cyoryakuHst != null && cyoryakuHst != ""){ if (cyoryakuHst.Contains (",")) { cyoryakuHstList = new List<string> (cyoryakuHst.Split (delimiterChars)); } else { cyoryakuHstList.Add (cyoryakuHst); } for (int i=0; i<cyoryakuHstList.Count; i++) { string tmp = cyoryakuHstList [i]; PlayerPrefs.DeleteKey (tmp); } PlayerPrefs.DeleteKey ("cyouryaku"); PlayerPrefs.Flush (); } /*Message*/ if (messageList.Count != 0) { /*Common Process*/ //make back string pathOfBack = "Prefabs/Common/TouchBack"; GameObject back = Instantiate(Resources.Load (pathOfBack)) as GameObject; back.transform.SetParent(GameObject.Find ("Panel").transform); back.transform.localScale = new Vector2 (1,1); back.transform.localPosition = new Vector2 (0,0); //make board string pathOfBoard = "Prefabs/Event/EventBoard"; GameObject board = Instantiate(Resources.Load (pathOfBoard)) as GameObject; board.transform.SetParent(GameObject.Find ("Panel").transform); board.transform.localScale = new Vector2 (1,1); string pathOfScroll = "Prefabs/Event/EventScrollView"; GameObject scroll = Instantiate(Resources.Load (pathOfScroll)) as GameObject; scroll.transform.SetParent(board.transform); scroll.transform.localScale = new Vector2 (1,1); RectTransform scrollTransform = scroll.GetComponent<RectTransform> (); scrollTransform.anchoredPosition = new Vector3 (0, -40, 0); string pathOfSlot = "Prefabs/Event/EventSlot"; foreach (string text in messageList) { GameObject slot = Instantiate(Resources.Load (pathOfSlot)) as GameObject; slot.transform.SetParent(scroll.transform.FindChild("Content").transform); slot.transform.FindChild("EventText").GetComponent<Text>().text = text; slot.transform.localScale = new Vector2 (1,1); } } }
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); }