Example #1
0
    public void OnClick()
    {
        AudioSource[] audioSources = GameObject.Find("SEController").GetComponents <AudioSource> ();
        audioSources [1].Play();

        if (shisyaSceneFlg)
        {
            Application.LoadLevel("shisya");
        }
        else
        {
            Destroy(deleteObj);
            Destroy(deleteObj2);

            if (activityUpdateFlg)
            {
                MapPointer pointerScript = new MapPointer();
                if (kassenDaimyoList.Count != 0)
                {
                    foreach (int daimyoId in kassenDaimyoList)
                    {
                        pointerScript.createKassenPointer(daimyoId);
                    }
                }
                if (upDaimyo1List.Count != 0)
                {
                    for (int i = 0; i < upDaimyo1List.Count; i++)
                    {
                        int downDaimyo1 = upDaimyo1List[i];
                        int downDaimyo2 = upDaimyo2List[i];

                        pointerScript.createUpPointer(downDaimyo1, downDaimyo2);
                    }
                }
                if (downDaimyo1List.Count != 0)
                {
                    for (int i = 0; i < downDaimyo1List.Count; i++)
                    {
                        int downDaimyo1 = downDaimyo1List[i];
                        int downDaimyo2 = downDaimyo2List[i];

                        pointerScript.createDownPointer(downDaimyo1, downDaimyo2);
                    }
                }
                if (metsubouKuniList.Count != 0)
                {
                    Gunzei gunzeiScript = new Gunzei();
                    for (int i = 0; i < metsubouKuniList.Count; i++)
                    {
                        int kuniId = metsubouKuniList[i];
                        gunzeiScript.fire(kuniId);
                    }
                }
            }
        }
    }
Example #2
0
	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);
			}
		}


	}
Example #3
0
	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);
			}
		}


	}
Example #4
0
	// Update is called once per frame
	void Update () {
		life = getTotalHp (targetTag);

		//Show Heiryoku
		if (life >= 0) {
			gameObject.transform.FindChild("HpText").GetComponent<Text>().text = life.ToString();
		}

		if (!flag) {
			if (life == 0) {
				flag = true;

				GameObject.Find ("ScrollView").SetActive (false);
				GameObject canvas = GameObject.Find ("Canvas").gameObject;

				if (targetTag == "Player") {
					//Game Over
					string backPath = "Prefabs/PostKassen/back";
					GameObject backObj = Instantiate(Resources.Load (backPath)) as GameObject;
					backObj.transform.SetParent (canvas.transform);
					backObj.transform.localScale = new Vector2(70,63);
					backObj.transform.localPosition = new Vector2 (0,0);

					//Chane word
					Color color = Color.blue;
					GameObject.Find ("winlose").GetComponent<TextMesh>().text = "敗北";
					GameObject.Find ("winlose").GetComponent<TextMesh>().color = color;
					
					string blackPath = "Prefabs/PostKassen/black";
					GameObject blackObj = Instantiate(Resources.Load (blackPath)) as GameObject;
					blackObj.transform.SetParent (canvas.transform);
					blackObj.transform.localScale = new Vector2(330,300);
					blackObj.transform.localPosition = new Vector2 (0,0);

					string makimonoPath = "Prefabs/PostKassen/makimono";
					GameObject makimonoObj = Instantiate(Resources.Load (makimonoPath)) as GameObject;
					makimonoObj.transform.SetParent (canvas.transform);
					makimonoObj.transform.localScale = new Vector2(1,1);
					makimonoObj.transform.localPosition = new Vector2(0,-135);

					//Button List
					string nextbtnPath = "Prefabs/PostKassen/bttnList";
					GameObject bttnListObj = Instantiate(Resources.Load (nextbtnPath)) as GameObject;
					bttnListObj.transform.SetParent (canvas.transform);
					bttnListObj.transform.localScale = new Vector2(1,1);		
					bttnListObj.transform.localPosition = new Vector2 (0,0);

					//Time Stop
					GameObject.Find ("timer").GetComponent<Timer>().enabled = false;


					//lose Stage Name
					string stageNamePath = "Prefabs/PostKassen/loseStageName";
					GameObject stageNameObj = Instantiate(Resources.Load (stageNamePath)) as GameObject;
					stageNameObj.transform.SetParent (canvas.transform);
					stageNameObj.transform.localScale = new Vector2(1,1);
					stageNameObj.transform.localPosition = new Vector2 (0,-102);
					string stageName = PlayerPrefs.GetString("activeStageName");

					//Check is attacked flag
					if (isAttackedFlg == true) {

						stageNameObj.transform.FindChild ("stageNameValue").GetComponent<Text> ().text = stageName + "失敗";

						//My Daimyo Lose 
						Gunzei lose = new Gunzei ();
						string tKey = PlayerPrefs.GetString ("activeKey");
						int tSrcDaimyoId = PlayerPrefs.GetInt ("activeSrcDaimyoId");
						int tDstDaimyoId = PlayerPrefs.GetInt ("activeDstDaimyoId");
						bool noGunzeiFlg = true;
						PlayerPrefs.DeleteKey ("isAttacked");
						lose.win (tKey, tSrcDaimyoId, tDstDaimyoId, noGunzeiFlg);


						//Delete Cleared Kuni
						int activeKuniId = PlayerPrefs.GetInt ("activeKuniId");
						string clearedKuni = PlayerPrefs.GetString ("clearedKuni");

						char[] delimiterChars = { ',' };
						List<string> clearedKuniList = new List<string> ();
						
						if (clearedKuni != null && clearedKuni != "") {
							if (clearedKuni.Contains (",")) {
								clearedKuniList = new List<string> (clearedKuni.Split (delimiterChars));
							} else {
								clearedKuniList.Add (clearedKuni);
							}
						}

						string tempActiveKuni = activeKuniId.ToString ();
						clearedKuniList.Remove (tempActiveKuni);
						string newClearedKuni = "";
						for (int i = 0; i < clearedKuniList.Count; i++) {
							if (i == 0) {
								newClearedKuni = clearedKuniList [i];
							} else {
								newClearedKuni = newClearedKuni + "," + clearedKuniList [i];
							}
						}
						PlayerPrefs.SetString ("clearedKuni", newClearedKuni);

						if (newClearedKuni == null || newClearedKuni == "") {
							PlayerPrefs.SetBool ("gameOverFlg", true);

						}

						//Delete Naisei
						//string tempNaisei = "naisei" + activeKuniId.ToString();
						//PlayerPrefs.DeleteKey(tempNaisei);

						//Delete Jyosyu
						string tempJyosyu = "jyosyu" + activeKuniId.ToString ();
						PlayerPrefs.DeleteKey (tempJyosyu);

						//Delete Stage Clear
						string tempKuni = "kuni" + activeKuniId.ToString ();
						PlayerPrefs.DeleteKey (tempKuni);

						//Delete open
						KuniInfo kuni = new KuniInfo ();
						kuni.updateOpenKuni ();
						PlayerPrefs.Flush ();
					
					} else {
						stageNameObj.transform.FindChild("stageNameValue").GetComponent<Text> ().text = stageName + "攻略失敗";
					}

				} else if (targetTag == "Enemy") {
					//Win
					if(isAttackedFlg == true){
						//history
						string tKey = PlayerPrefs.GetString("activeKey");
						MainStageController main = new MainStageController();
						main.deleteKeyHistory(tKey);
						PlayerPrefs.DeleteKey("isAttacked");
						PlayerPrefs.Flush();
					}

					string backPath = "Prefabs/PostKassen/back";
					GameObject backObj = Instantiate(Resources.Load (backPath)) as GameObject;
					backObj.transform.SetParent (canvas.transform);
					backObj.transform.localScale = new Vector2(70,63);
					backObj.transform.localPosition = new Vector2 (0,0);

					string particlePath = "Prefabs/PostKassen/particle";
					GameObject particleObj = Instantiate(Resources.Load (particlePath)) as GameObject;
					particleObj.transform.SetParent (canvas.transform);
					particleObj.transform.localPosition = new Vector2(0,60);

					string blackPath = "Prefabs/PostKassen/black";
					GameObject blackObj = Instantiate(Resources.Load (blackPath)) as GameObject;
					blackObj.transform.SetParent (canvas.transform);
					blackObj.transform.localScale = new Vector2(330,300);
					blackObj.transform.localPosition = new Vector2 (0,0);

					string makimonoPath = "Prefabs/PostKassen/makimono";
					GameObject makimonoObj = Instantiate(Resources.Load (makimonoPath)) as GameObject;
					makimonoObj.transform.SetParent (canvas.transform);
					makimonoObj.transform.localScale = new Vector2(1,1);
					makimonoObj.transform.localPosition = new Vector2(0,-135);

					string stageName = PlayerPrefs.GetString("activeStageName");


					//Item List
					string itemListPath = "Prefabs/PostKassen/itemList";
					GameObject itemListObj = Instantiate(Resources.Load (itemListPath)) as GameObject;
					itemListObj.transform.SetParent (canvas.transform);
					itemListObj.transform.localScale = new Vector2(1,1);
					itemListObj.transform.localPosition = new Vector2 (0,-136);

					if (!isAttackedFlg) {

						itemListObj.transform.FindChild ("stageName").transform.FindChild("stageNameValue").GetComponent<Text> ().text = stageName + "攻略";

						/*Item or Kahou*/
						string activeItemGrp = PlayerPrefs.GetString ("activeItemGrp");

						if (activeItemGrp != "no") {
								
							string activeItemType = PlayerPrefs.GetString ("activeItemType");
							Debug.Log (activeItemType);
							int activeItemId = PlayerPrefs.GetInt ("activeItemId");
							Debug.Log (activeItemId);
							int activeItemQty = PlayerPrefs.GetInt ("activeItemQty");
							Debug.Log (activeItemQty);

							//Get Item
							string cyouheiPath = "Prefabs/Item/Cyouhei/" + activeItemType;
							string kanjyoPath = "Prefabs/Item/Kanjyo/Kanjyo";
							string hidensyoPath = "Prefabs/Item/Hidensyo/Hidensyo";
							string shinobiPath = "Prefabs/Item/Shinobi/Shinobi";
							char[] delimiterChars = { ',' };

							if (activeItemGrp == "item") {

								//Cyouhei
								if (activeItemType.Contains ("Cyouhei") == true) {
									string newCyouheiString = "";

									makeItemIcon (cyouheiPath, activeItemId.ToString (), itemListObj);
									if (activeItemType.Contains ("YR") == true) {
										string cyouheiString = PlayerPrefs.GetString ("cyouheiYR");
										string[] cyouheiList = cyouheiString.Split (delimiterChars);
										if (activeItemId == 1) {
											int tempQty = int.Parse (cyouheiList [0]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = tempQty.ToString () + "," + cyouheiList [1] + "," + cyouheiList [2];

										} else if (activeItemId == 2) {
											int tempQty = int.Parse (cyouheiList [1]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + tempQty.ToString () + "," + cyouheiList [2];

										} else if (activeItemId == 3) {
											int tempQty = int.Parse (cyouheiList [2]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + cyouheiList [1] + "," + tempQty.ToString ();
										}

										PlayerPrefs.SetString ("cyouheiYR", newCyouheiString);

									} else if (activeItemType.Contains ("KB") == true) {
										string cyouheiString = PlayerPrefs.GetString ("cyouheiKB");
										string[] cyouheiList = cyouheiString.Split (delimiterChars);
										if (activeItemId == 1) {
											int tempQty = int.Parse (cyouheiList [0]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = tempQty.ToString () + "," + cyouheiList [1] + "," + cyouheiList [2];
											
										} else if (activeItemId == 2) {
											int tempQty = int.Parse (cyouheiList [1]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + tempQty.ToString () + "," + cyouheiList [2];
											
										} else if (activeItemId == 3) {
											int tempQty = int.Parse (cyouheiList [2]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + cyouheiList [1] + "," + tempQty.ToString ();
										}
										
										PlayerPrefs.SetString ("cyouheiKB", newCyouheiString);

									} else if (activeItemType.Contains ("TP") == true) {
										string cyouheiString = PlayerPrefs.GetString ("cyouheiTP");
										string[] cyouheiList = cyouheiString.Split (delimiterChars);
										if (activeItemId == 1) {
											int tempQty = int.Parse (cyouheiList [0]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = tempQty.ToString () + "," + cyouheiList [1] + "," + cyouheiList [2];
											
										} else if (activeItemId == 2) {
											int tempQty = int.Parse (cyouheiList [1]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + tempQty.ToString () + "," + cyouheiList [2];
											
										} else if (activeItemId == 3) {
											int tempQty = int.Parse (cyouheiList [2]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + cyouheiList [1] + "," + tempQty.ToString ();
										}
										
										PlayerPrefs.SetString ("cyouheiTP", newCyouheiString);

									} else if (activeItemType.Contains ("YM") == true) {
										string cyouheiString = PlayerPrefs.GetString ("cyouheiYM");
										string[] cyouheiList = cyouheiString.Split (delimiterChars);
										if (activeItemId == 1) {
											int tempQty = int.Parse (cyouheiList [0]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = tempQty.ToString () + "," + cyouheiList [1] + "," + cyouheiList [2];
											
										} else if (activeItemId == 2) {
											int tempQty = int.Parse (cyouheiList [1]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + tempQty.ToString () + "," + cyouheiList [2];
											
										} else if (activeItemId == 3) {
											int tempQty = int.Parse (cyouheiList [2]);
											tempQty = tempQty + activeItemQty;
											newCyouheiString = cyouheiList [0] + "," + cyouheiList [1] + "," + tempQty.ToString ();
										}
										
										PlayerPrefs.SetString ("cyouheiYM", newCyouheiString);
									}


									//Kanjyo
								} else if (activeItemType == "Kanjyo") {
									makeItemIcon (kanjyoPath, activeItemId.ToString (), itemListObj);

									string newKanjyoString = "";
									string kanjyoString = PlayerPrefs.GetString ("kanjyo");
									string[] kanjyoList = kanjyoString.Split (delimiterChars);

									if (activeItemId == 1) {
										int tempQty = int.Parse (kanjyoList [0]);
										tempQty = tempQty + activeItemQty;
										newKanjyoString = tempQty.ToString () + "," + kanjyoList [1] + "," + kanjyoList [2];
										
									} else if (activeItemId == 2) {
										int tempQty = int.Parse (kanjyoList [1]);
										tempQty = tempQty + activeItemQty;
										newKanjyoString = kanjyoList [0] + "," + tempQty.ToString () + "," + kanjyoList [2];
										
									} else if (activeItemId == 3) {
										int tempQty = int.Parse (kanjyoList [2]);
										tempQty = tempQty + activeItemQty;
										newKanjyoString = kanjyoList [0] + "," + kanjyoList [1] + "," + tempQty.ToString ();
									}
									PlayerPrefs.SetString ("kanjyo", newKanjyoString);
								
									//Hidensyo
								} else if (activeItemType == "Hidensyo") {
									makeItemIcon (hidensyoPath, activeItemId.ToString (), itemListObj);

									if (activeItemId == 1) {
										int hidensyoQty = PlayerPrefs.GetInt ("hidensyoGe");
										hidensyoQty = hidensyoQty + activeItemQty;
										PlayerPrefs.SetInt ("hidensyoGe", hidensyoQty);

									} else if (activeItemId == 2) {
										int hidensyoQty = PlayerPrefs.GetInt ("hidensyoCyu");
										hidensyoQty = hidensyoQty + activeItemQty;
										PlayerPrefs.SetInt ("hidensyoCyu", hidensyoQty);

									} else if (activeItemId == 3) {
										int hidensyoQty = PlayerPrefs.GetInt ("hidensyoJyo");
										hidensyoQty = hidensyoQty + activeItemQty;
										PlayerPrefs.SetInt ("hidensyoJyo", hidensyoQty);
									}

									//Shinobi
								} else if (activeItemType == "Shinobi") {
									makeItemIcon (shinobiPath, activeItemId.ToString (), itemListObj);
									RectTransform rect = itemListObj.transform.FindChild ("itemIcon").transform.FindChild ("Shinobi").GetComponent<RectTransform> ();
									rect.sizeDelta = new Vector2 (100, 100);


									if (activeItemId == 1) {
										int newQty = 0;
										int shinobiQty = PlayerPrefs.GetInt ("shinobiGe");
										newQty = shinobiQty + activeItemQty;
										PlayerPrefs.SetInt ("shinobiGe", newQty);

									} else if (activeItemId == 2) {
										int newQty = 0;
										int shinobiQty = PlayerPrefs.GetInt ("shinobiCyu");
										newQty = shinobiQty + activeItemQty;
										PlayerPrefs.SetInt ("shinobiCyu", newQty);

									} else if (activeItemId == 3) {
										int newQty = 0;
										int shinobiQty = PlayerPrefs.GetInt ("shinobiJyo");
										newQty = shinobiQty + activeItemQty;
										PlayerPrefs.SetInt ("shinobiJyo", newQty);

									}								
								
									//tech
								} else if (activeItemType == "tech") {
									string path = "Prefabs/Item/Tech/Tech";
									GameObject tech = Instantiate (Resources.Load (path)) as GameObject;
									tech.transform.SetParent (itemListObj.transform);
									tech.transform.localScale = new Vector2 (0.4f, 0.4f);
									RectTransform techTransform = tech.GetComponent<RectTransform> ();
									techTransform.sizeDelta = new Vector2 (100, 100);
									techTransform.anchoredPosition3D = new Vector3 (650, 110, 0);
									tech.GetComponent<Button> ().enabled = false;

									string spritePath = "";
									if (activeItemId == 1) {
										//TP
										int qty = PlayerPrefs.GetInt ("transferTP", 0);
										int newQty = qty + activeItemQty;
										PlayerPrefs.SetInt ("transferTP", newQty);
										spritePath = "Prefabs/Item/Tech/Sprite/tp";

									} else if (activeItemId == 2) {
										int qty = PlayerPrefs.GetInt ("transferKB", 0);
										int newQty = qty + activeItemQty;
										PlayerPrefs.SetInt ("transferKB", newQty);
										spritePath = "Prefabs/Item/Tech/Sprite/kb";

									} else if (activeItemId == 3) {
										int qty = PlayerPrefs.GetInt ("transferSNB", 0);
										int newQty = qty + activeItemQty;
										PlayerPrefs.SetInt ("transferSNB", newQty);
										spritePath = "Prefabs/Item/Tech/Sprite/snb";
									}
										
									tech.GetComponent<Image> ().sprite = 
										Resources.Load (spritePath, typeof(Sprite)) as Sprite;
									
								
									//cyoutei or koueki
								} else if (activeItemType == "cyoutei" || activeItemType == "koueki") {

									if (activeItemType == "cyoutei") {
										string syoukaijyoPath = "Prefabs/Item/cyoutei";
										GameObject icon = Instantiate (Resources.Load (syoukaijyoPath)) as GameObject;
										icon.transform.SetParent (itemListObj.transform);
										icon.transform.localPosition = new Vector3 (250, 35, 0);
										icon.transform.localScale = new Vector2 (0.4f, 0.4f);
										icon.GetComponent<Button> ().enabled = false;

										if (activeItemId == 1) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "山科言継";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "下";
										} else if (activeItemId == 2) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "三条西実枝";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "中";
										} else if (activeItemId == 3) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "近衛前久";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "上";
										}

									} else if (activeItemType == "koueki") {
										string syoukaijyoPath = "Prefabs/Item/koueki";
										GameObject icon = Instantiate (Resources.Load (syoukaijyoPath)) as GameObject;
										icon.transform.SetParent (itemListObj.transform);
										icon.transform.localPosition = new Vector3 (250, 35, 0);
										icon.transform.localScale = new Vector2 (0.4f, 0.4f);
										icon.GetComponent<Button> ().enabled = false;

										if (activeItemId == 1) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "加藤浄与";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "下";
										} else if (activeItemId == 2) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "島井宗室";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "中";
										} else if (activeItemId == 3) {
											GameObject nameObj = icon.transform.FindChild ("Name").gameObject;
											nameObj.GetComponent<Text> ().text = "茶屋四郎次郎";
											nameObj.transform.localScale = new Vector2 (0.08f, 0.1f);
											icon.transform.FindChild ("Rank").GetComponent<Text> ().text = "上";
										}
									}

									TabibitoItemGetter syoukaijyo = new TabibitoItemGetter ();
									syoukaijyo.registerKouekiOrCyoutei (activeItemType, activeItemId);
								
								} else if (activeItemType == "Tama") {

									string path = "Prefabs/Item/Tama";
									GameObject icon = Instantiate (Resources.Load (path)) as GameObject;
									icon.transform.SetParent (itemListObj.transform);
									icon.transform.localPosition = new Vector3 (250, 35, 0);
									icon.transform.localScale = new Vector2 (0.4f, 0.4f);
									icon.GetComponent<Button> ().enabled = false;
								
									int nowQty = PlayerPrefs.GetInt ("busyoDama");
									int newQty = nowQty + activeItemQty;
									PlayerPrefs.SetInt ("busyoDama", newQty);

								}


							} else if (activeItemGrp == "kahou") {
								//Kahou
								string kahouIconPath = "Prefabs/Item/Kahou/" + activeItemType + activeItemId;
								GameObject kahouIcon = Instantiate (Resources.Load (kahouIconPath)) as GameObject;
								kahouIcon.transform.SetParent (itemListObj.transform);
								kahouIcon.name = "itemIcon";
								kahouIcon.transform.localPosition = new Vector3 (250, 35, 0);
								kahouIcon.transform.localScale = new Vector2 (0.4f, 0.4f);
								RectTransform kahouTransform = kahouIcon.GetComponent<RectTransform> ();
								kahouTransform.sizeDelta = new Vector2 (100, 100);

								GameObject rank = kahouIcon.transform.FindChild ("Rank").gameObject;
								rank.transform.localScale = new Vector2 (0.3f, 0.3f);
								rank.transform.localPosition = new Vector2 (20, -20);

								//Register
								addKahou (activeItemType, activeItemId);
							}

							//Qty
							string itemQtyPath = "Prefabs/PostKassen/itemQty";
							GameObject itemQtyObj = Instantiate (Resources.Load (itemQtyPath)) as GameObject;
							itemQtyObj.transform.SetParent (itemListObj.transform);
							itemQtyObj.transform.localScale = new Vector2 (0.09f, 0.09f);
							itemQtyObj.transform.localPosition = new Vector2 (290, 35);
							itemQtyObj.GetComponent<Text> ().text = "x " + activeItemQty.ToString ();

							
							PlayerPrefs.Flush ();
						}

					} else {
						itemListObj.transform.FindChild ("stageName").transform.FindChild("stageNameValue").GetComponent<Text> ().text = stageName + "成功";
					}
					
					//Money
					int activeStageMoney = PlayerPrefs.GetInt("activeStageMoney",0);
					GameObject.Find ("moneyAmt").GetComponent<Text>().text = activeStageMoney.ToString();
					int currentMoney = PlayerPrefs.GetInt("money");
					currentMoney = currentMoney + activeStageMoney;
					PlayerPrefs.SetInt("money",currentMoney);

					//kuniExp
					int activeStageExp = PlayerPrefs.GetInt("activeStageExp",0);
					GameObject.Find ("expAmt").GetComponent<Text>().text = activeStageExp.ToString();
					int currentKuniExp = PlayerPrefs.GetInt ("kuniExp");
					currentKuniExp = currentKuniExp + activeStageExp;
					int kuniLv = PlayerPrefs.GetInt ("kuniLv");
					Exp kuniExp = new Exp();
					int newKuniLv = kuniExp.getKuniLv(kuniLv,currentKuniExp);

					if(newKuniLv>kuniLv){
						//lv up
						int jinkeiLimit = kuniExp.getJinkeiLimit(newKuniLv);
						int stockLimit = kuniExp.getStockLimit(newKuniLv);
						PlayerPrefs.SetInt("jinkeiLimit",jinkeiLimit);
						PlayerPrefs.SetInt("stockLimit",stockLimit);


					}else{
						Debug.Log ("No level up");
					}

					/*Cleared Flag*/
					if(!isAttackedFlg){
						int activeKuniId  = PlayerPrefs.GetInt("activeKuniId");
						int activeStageId = PlayerPrefs.GetInt("activeStageId");
						string temp = "kuni" + activeKuniId.ToString();

						List<string> clearedStageList = new List<string>();
						string clearedStageString  = PlayerPrefs.GetString(temp);

						if(clearedStageString !=null && clearedStageString !=""){
							//after 1st time
							char[] delimiterChars = {','};
							clearedStageList = new List<string>(clearedStageString.Split (delimiterChars));
							if(clearedStageList.Contains(activeStageId.ToString()) == false){
								clearedStageString = clearedStageString + "," + activeStageId.ToString();

								//1st Kuni Clear Check
								string[] commaCounter = clearedStageString.Split(delimiterChars);
								int counter = commaCounter.Length;

								if(counter == 10){
									//1st time
									string clearedKuni = PlayerPrefs.GetString("clearedKuni");
									if(clearedKuni !=null && clearedKuni !=""){
										clearedKuni = clearedKuni + "," + activeKuniId.ToString();
									}else{
										clearedKuni = activeKuniId.ToString();
									}
									PlayerPrefs.SetString("clearedKuni",clearedKuni);
									//Give 1st cleared revenue 
									PlayerPrefs.SetBool("kuniClearedFlg",true);

									//Open Kuni
									KuniInfo kuni = new KuniInfo();
									kuni.registerOpenKuni(activeKuniId);

									//Seiryoku Change
									string seiryoku = PlayerPrefs.GetString ("seiryoku");
									List<string> seiryokuList = new List<string>();
									seiryokuList = new List<string> (seiryoku.Split (delimiterChars));

									int myDaimyo = PlayerPrefs.GetInt ("myDaimyo");
									seiryokuList[activeKuniId-1] = myDaimyo.ToString();
									string newSeiryoku = "";
									bool gameClearFlg = true;
									for(int i=0; i<seiryokuList.Count; i++){
										if(i==0){
											newSeiryoku = seiryokuList[i];
										}else{
											newSeiryoku = newSeiryoku + "," + seiryokuList[i];
										}

										//game clear check
										if(gameClearFlg){
											if(seiryokuList[i] != myDaimyo.ToString()){
												gameClearFlg = false;
											}
										}
									}
									PlayerPrefs.SetBool("gameClearFlg",gameClearFlg);
									PlayerPrefs.SetString("seiryoku",newSeiryoku);


									//Cyouhou Delete
									string cyouhouTmp = "cyouhou" + activeKuniId;
									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 (activeKuniId.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);

									}
								}
							}
						}else{
							//1st time
							clearedStageString = activeStageId.ToString();
						}
						PlayerPrefs.SetString(temp,clearedStageString);

						PlayerPrefs.SetInt("kuniLv",newKuniLv);
						PlayerPrefs.SetInt("kuniExp",currentKuniExp);
						PlayerPrefs.Flush();
					}

					//Button List
					string nextbtnPath = "Prefabs/PostKassen/bttnList";
					GameObject bttnListObj = Instantiate(Resources.Load (nextbtnPath)) as GameObject;
					bttnListObj.transform.SetParent (canvas.transform);
					bttnListObj.transform.localScale = new Vector2(1,1);
					bttnListObj.transform.localPosition = new Vector2 (0,0);

					//Time Stop
					GameObject.Find ("timer").GetComponent<Timer>().enabled = false;


					//Get Exp
					SenkouButton senkou = new SenkouButton();
					List<BusyoSenkou> senkouList = new List<BusyoSenkou>();
					senkouList=senkou.getSenkou ();
					for(int i=0;i<senkouList.Count;i++){

						int busyoId = senkouList[i].id;
						int senkouAmt = senkouList[i].senkou;
						Exp exp = new Exp();

						//Modify by Cyadougu Kahou
						senkouAmt = exp.getExpbyCyadougu(busyoId,senkouAmt);

						//Busyo Exp
						string tempExp = "exp" + busyoId;
						int nowExp = PlayerPrefs.GetInt(tempExp);
						int newExp = nowExp + senkouAmt;
						PlayerPrefs.SetInt(tempExp, newExp);

						//Busyo Lv
						int nowLv = PlayerPrefs.GetInt(busyoId.ToString());
						int newLv = exp.getLvbyTotalExp(nowLv,newExp);
						PlayerPrefs.SetInt(busyoId.ToString(), newLv);

						PlayerPrefs.Flush();
					}
				}
			}
		}
	}
	// Use this for initialization
	public void Start () {


		Resources.UnloadUnusedAssets ();

		//Data Initialization
		//DataMaker data = new DataMaker ();
		//data.Start ();

		/*Initial Data*/
		bool initDataFlg = PlayerPrefs.GetBool ("initDataFlg");
		if (initDataFlg == false) {
			//my daimyo
			InitDataMaker initData = new InitDataMaker ();
			initData.makeInitData ();
		}

		Entity_kuni_mst kuniMst = Resources.Load ("Data/kuni_mst") as Entity_kuni_mst;
		Entity_kuni_mapping_mst kuniMappingMst = Resources.Load ("Data/kuni_mapping_mst") as Entity_kuni_mapping_mst;
		Entity_daimyo_mst daimyoMst = Resources.Load ("Data/daimyo_mst") as Entity_daimyo_mst;

		//Base Info.
		int kuniLv = PlayerPrefs.GetInt ("kuniLv");
		int money = PlayerPrefs.GetInt ("money");
		int busyoDama = PlayerPrefs.GetInt ("busyoDama");
		GameObject.Find ("KuniLvValue").GetComponent<Text> ().text = kuniLv.ToString ();
		GameObject.Find ("MoneyValue").GetComponent<Text> ().text = money.ToString ();
		GameObject.Find ("BusyoDamaValue").GetComponent<Text> ().text = busyoDama.ToString ();

		myDaimyo = PlayerPrefs.GetInt ("myDaimyo");
		string myDaimyoName = daimyoMst.param [myDaimyo - 1].daimyoName;

		GameObject.Find ("DaimyoValue").GetComponent<Text> ().text = myDaimyoName;


		//Kuni List
		string openKuni = PlayerPrefs.GetString ("openKuni");
		List<string> openKuniList = new List<string> ();
		char[] delimiterChars = {','};
		if (openKuni != null && openKuni != "") {
			if (openKuni.Contains (",")) {
				openKuniList = new List<string> (openKuni.Split (delimiterChars));
			} else {
				openKuniList.Add (openKuni);
			}
		}

		GameObject kuniIconView = GameObject.Find ("KuniIconView");

		string clearedKuni = PlayerPrefs.GetString ("clearedKuni");
		List<string> clearedKuniList = new List<string> ();
		if (clearedKuni != null && clearedKuni != "") {
			if (clearedKuni.Contains (",")) {
				clearedKuniList = new List<string> (clearedKuni.Split (delimiterChars));
			} else {
				clearedKuniList.Add (clearedKuni);
			}
		}

		/*View Every Kuni by Master*/
		GameObject KuniMap = GameObject.Find ("KuniMap");

		//Seiryoku Default Setting
		string seiryoku = PlayerPrefs.GetString ("seiryoku");
		List<string> seiryokuList = new List<string> ();
		seiryokuList = new List<string> (seiryoku.Split (delimiterChars));

		//Count my Kuni QTY
		for (int m=0; m<seiryokuList.Count; m++) {
			int seiryokuId = int.Parse (seiryokuList [m]);
			if (seiryokuId == myDaimyo) {
				myKuniQty = myKuniQty + 1;
			}
		}

		//My Doumei
		Color doumeiColor = new Color (100f / 255f, 130f / 255f, 255f / 255f, 255f / 255f); //Blue
		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);
			}
		}

		string kuniPath = "Prefabs/Map/Kuni/";
		for (int i=0; i<kuniMst.param.Count; i++) {
			int kuniId = kuniMst.param [i].kunId;

			string newKuniPath = kuniPath + kuniId.ToString ();
			int locationX = kuniMst.param [i].locationX;
			int locationY = kuniMst.param [i].locationY;

			GameObject kuni = Instantiate (Resources.Load (newKuniPath)) as GameObject;

			kuni.transform.SetParent (kuniIconView.transform);
			kuni.name = kuniId.ToString ();
			kuni.GetComponent<SendParam> ().kuniId = kuniId;
			kuni.GetComponent<SendParam> ().kuniName = kuniMst.param [i].kuniName;
			kuni.transform.localScale = new Vector2 (1, 1);

			//Seiryoku Handling
			int daimyoId = int.Parse (seiryokuList [kuniId - 1]);

			string daimyoName = daimyoMst.param [daimyoId - 1].daimyoName;

			kuni.GetComponent<SendParam> ().daimyoId = daimyoId;
			kuni.GetComponent<SendParam> ().daimyoName = daimyoName;
			int daimyoBusyoIdTemp = daimyoMst.param [daimyoId - 1].busyoId;

			kuni.GetComponent<SendParam> ().daimyoBusyoId = daimyoBusyoIdTemp;

			//Senryoku
			//Count QTY of Enemy Kuni
			int enemyKuniQty = 0;
			for (int l=0; l<seiryokuList.Count; l++) {
				int seiryokuId = int.Parse (seiryokuList [l]);

				if (seiryokuId == daimyoId) {
					enemyKuniQty = enemyKuniQty + 1;
				}
			}

			EnemySenryokuCalc calc = new EnemySenryokuCalc ();
			int busyoQty = 0;
			int busyoLv = 0;
			int butaiQty = 0;
			int butaiLv = 0;

			busyoQty = calc.EnemyBusyoQtyCalc (myKuniQty, enemyKuniQty);
			int senryokuRatio = daimyoMst.param [daimyoId - 1].senryoku;
			busyoLv = calc.EnemyBusyoLvCalc (senryokuRatio);
			butaiQty = calc.EnemyButaiQtyCalc (enemyKuniQty);
			butaiLv = calc.EnemyButaiLvCalc (senryokuRatio);
			
			kuni.GetComponent<SendParam> ().busyoQty = busyoQty;
			kuni.GetComponent<SendParam> ().busyoLv = busyoLv;
			kuni.GetComponent<SendParam> ().butaiQty = butaiQty;
			kuni.GetComponent<SendParam> ().butaiLv = butaiLv;
			kuni.GetComponent<SendParam>().kuniQty = enemyKuniQty;

			//Color Handling
			float colorR = (float)daimyoMst.param [daimyoId - 1].colorR;
			float colorG = (float)daimyoMst.param [daimyoId - 1].colorG;
			float colorB = (float)daimyoMst.param [daimyoId - 1].colorB;
			Color kuniColor = new Color (colorR / 255f, colorG / 255f, colorB / 255f, 255f / 255f);
		
			KuniMap.transform.FindChild (kuni.name).GetComponent<Image> ().color = kuniColor;

			//Daimyo Kamon Image
			string imagePath = "Prefabs/Kamon/" + daimyoId.ToString ();
			kuni.GetComponent<Image> ().sprite = 
				Resources.Load (imagePath, typeof(Sprite)) as Sprite;



			RectTransform kuniTransform = kuni.GetComponent<RectTransform> ();
			kuniTransform.anchoredPosition = new Vector3 (locationX, locationY, 0);

			//My Doumei Check
			if (myDoumei != null && myDoumei != "") {
				if(myDoumeiList.Contains(daimyoId.ToString())){
					kuni.GetComponent<SendParam> ().doumeiFlg = true;
					kuni.GetComponent<Image>().color = doumeiColor;
				}
			}

			//My daimyo Check
			if(daimyoId==myDaimyo){
				string myDaimyoPath = "Prefabs/Kamon/MyDaimyoKamon/" + myDaimyo.ToString ();
				kuni.GetComponent<Image> ().sprite = 
				Resources.Load (myDaimyoPath, typeof(Sprite)) as Sprite;
				kuni.GetComponent<SendParam> ().clearFlg = true;
			}
		}

		//Color Change for kuni icon "Open but never cleared"
		Color openKuniColor = new Color (255f / 255f, 255f / 255f, 0f / 255f, 255f / 255f); //Yellow

		for (int i=0; i<openKuniList.Count; i++) {
			string openKuniId = openKuniList [i];

			//Flg Change
			GameObject targetOpenKuni = GameObject.Find ("KuniIconView").transform.FindChild (openKuniId).gameObject;
			targetOpenKuni.GetComponent<SendParam> ().openFlg = true;
			bool doumeiFlg = targetOpenKuni.GetComponent<SendParam>().doumeiFlg;

			//Color Change
			if (!clearedKuniList.Contains (openKuniId)) {
				if(!doumeiFlg){
					targetOpenKuni.GetComponent<Image> ().color = openKuniColor;
				}
			}
		}



		//Clear Kuni Check
		bool kuniClearedFlg = PlayerPrefs.GetBool ("kuniClearedFlg");
		if (kuniClearedFlg == true) {
			Message msg = new Message (); 
			string Text = "国盗り、祝着至極に御座りますな。\n民から武将珠100個届いておりますぞ。";
			msg.makeMessage (Text);

			//Add Busyo Dama
			busyoDama = busyoDama + 100;
			GameObject.Find ("BusyoDamaValue").GetComponent<Text> ().text = busyoDama.ToString ();

			PlayerPrefs.SetInt ("busyoDama", busyoDama);
			PlayerPrefs.SetBool ("kuniClearedFlg", false);
			PlayerPrefs.Flush ();
		}

		//From Naisei Check
		bool fromNaiseiFlg = PlayerPrefs.GetBool ("fromNaiseiFlg");
		if (fromNaiseiFlg == true) {
			int activeKuniId = PlayerPrefs.GetInt ("activeKuniId");
			GameObject.Find ("KuniIconView").transform.FindChild (activeKuniId.ToString ()).GetComponent<SendParam> ().OnClick ();			
			PlayerPrefs.SetBool ("fromNaiseiFlg", false);
			PlayerPrefs.Flush ();
		}

		/*Timer Handling*/
		//Last Log-In Time
		string timestring = PlayerPrefs.GetString ("lasttime");
		if (timestring == null || timestring == "")
			timestring = System.DateTime.Now.ToString ();
		System.DateTime datetime = System.DateTime.Parse (timestring);
		System.TimeSpan span = System.DateTime.Now - datetime;
		//Last Get Time
		string lastGetTime = PlayerPrefs.GetString ("lastGetTime");
		if (lastGetTime == null || lastGetTime == "") {
			lastGetTime = System.DateTime.Now.ToString ();
			PlayerPrefs.SetString ("lastGetTime", lastGetTime);
			PlayerPrefs.Flush ();
		}
		System.DateTime getdatetime = System.DateTime.Parse (lastGetTime);
		System.TimeSpan getspan = System.DateTime.Now - getdatetime;

		//経過時間を秒,時間で取得
		double spantime = span.TotalSeconds;
		double spanhour = getspan.TotalHours;



		//spantimeでスタミナの回復分を求める
		double staminaDouble = spantime / 300;
		int addHyourou = (int)staminaDouble;
		int amariSec = (int)spantime - (addHyourou * 300);
		amariSec = 300 - amariSec;

		//HyourouMax
		hyourouMax = PlayerPrefs.GetInt ("hyourouMax");
		GameObject.Find ("HyourouMaxValue").GetComponent<Text> ().text = hyourouMax.ToString ();

		//Now Hyourou
		int nowHyourou = PlayerPrefs.GetInt ("hyourou");
		currentHyourou = GameObject.Find ("HyourouCurrentValue").gameObject;
		currentHyourou.GetComponent<Text> ().text = nowHyourou.ToString ();


		//Hyourou Full Check
		if (hyourouMax <= nowHyourou) {
			hyourouFull = true;
			GameObject.Find ("HyourouCurrentValue").GetComponent<Text> ().text = hyourouMax.ToString ();
			PlayerPrefs.SetInt ("hyourou", hyourouMax);
			PlayerPrefs.Flush ();

		} else {

			if (addHyourou > 0) {
				int newHyourou = nowHyourou + addHyourou;

				if (hyourouMax <= newHyourou) {
					hyourouFull = true;
					PlayerPrefs.SetInt ("hyourou", hyourouMax);
					PlayerPrefs.Flush ();
					GameObject.Find ("HyourouCurrentValue").GetComponent<Text> ().text = hyourouMax.ToString ();

				} else {
					hyourouFull = false;
					PlayerPrefs.SetInt ("hyourou", newHyourou);
					PlayerPrefs.Flush ();
					GameObject.Find ("HyourouCurrentValue").GetComponent<Text> ().text = newHyourou.ToString ();

					//Timer
					GameObject.Find ("TimerValue").GetComponent<Text> ().text = amariSec.ToString ();
					timer = (float)amariSec;
				}

				//終了時の処理
				// 現在の時刻を取得
				System.DateTime now = System.DateTime.Now;
				// 文字列に変換して保存
				PlayerPrefs.SetString ("lasttime", now.ToString ());
				PlayerPrefs.Flush ();

			} else {
				hyourouFull = false;
				PlayerPrefs.SetInt ("hyourou", nowHyourou);
				PlayerPrefs.Flush ();
				GameObject.Find ("HyourouCurrentValue").GetComponent<Text> ().text = nowHyourou.ToString ();

				//Timer
				GameObject.Find ("TimerValue").GetComponent<Text> ().text = amariSec.ToString ();
				timer = (float)amariSec;
			}
		}

		//Year Handling
		string yearSeason = PlayerPrefs.GetString ("yearSeason");

		string[] yearSeasonList = yearSeason.Split (delimiterChars);

		GameObject.Find ("YearValue").GetComponent<Text> ().text = yearSeasonList [0];

		int seasonId = int.Parse (yearSeasonList [1]);
		if (seasonId == 1) {
			GameObject.Find ("SeasonValue").GetComponent<Text> ().text = "春";
		} else if (seasonId == 2) {
			GameObject.Find ("SeasonValue").GetComponent<Text> ().text = "夏";
		} else if (seasonId == 3) {
			GameObject.Find ("SeasonValue").GetComponent<Text> ().text = "秋";
		} else if (seasonId == 4) {
			GameObject.Find ("SeasonValue").GetComponent<Text> ().text = "冬";
		}

		//Cyosyu Flg
		cyosyuFlg = PlayerPrefs.GetBool ("cyosyuFlg");

		double spansec = getspan.TotalSeconds;
		cyosyuTimer = cyosyuMstTime - spansec;

		if (cyosyuTimer <= 0.0f) {
			cyosyuFlg = true;
		} else {
			cyosyuFlg = false;
		}

		if (cyosyuFlg == true) {
			GameObject.Find ("SeiryokuInfo").transform.FindChild ("Ex").GetComponent<Image> ().enabled = true;
		} else {
			GameObject.Find ("SeiryokuInfo").transform.FindChild ("Ex").GetComponent<Image> ().enabled = false;
		}


		/*--------------------*/
		/*Gunzei*/
		/*--------------------*/
		string keyHistory = PlayerPrefs.GetString ("keyHistory");
		List<string> keyHistoryList = new List<string> ();
		if (keyHistory != null && keyHistory != "") {
			if(keyHistory.Contains(",")){
				keyHistoryList = new List<string> (keyHistory.Split (delimiterChars));
			}else{
				keyHistoryList.Add(keyHistory);
			}
		}

		for(int n=0; n<keyHistoryList.Count; n++){
			string keyTemp = keyHistoryList[n];
			string keyValue = PlayerPrefs.GetString (keyTemp);

			if(keyValue != null){
				List<string> keyValueList = new List<string> ();
				keyValueList = new List<string> (keyValue.Split (delimiterChars));

				string gunzeiTime = keyValueList[0];
				System.DateTime gunzeiDatetime = System.DateTime.Parse (gunzeiTime);
				System.TimeSpan gunzeiSpan = System.DateTime.Now - gunzeiDatetime;
				double gunzeiSpantime = gunzeiSpan.TotalSeconds;

				double remainTime = 0;
				List<string> srcDstKuniList = new List<string> ();
				char[] keyDelimiterChars = {'-'};
				srcDstKuniList = new List<string> (keyTemp.Split (keyDelimiterChars));
				int srcDaimyoId = int.Parse(keyValueList[1]);
				int dstDaimyoId = int.Parse(keyValueList[2]);
				int srcKuni = int.Parse(srcDstKuniList[0]);
				int dstKuni = int.Parse(srcDstKuniList[1]);
				bool dstEngunFlg = bool.Parse(keyValueList[9]);
				string dstEngunDaimyoId = keyValueList[10];
				string dstEngunHei = keyValueList[11];
				string dstEngunSts = keyValueList[12];

				if(gunzeiSpantime >= 300){
					//Has past
					//Simulation
					Gunzei gunzei = new Gunzei();

					if (dstDaimyoId != myDaimyo) {
						int enemyHei = gunzei.heiryokuCalc (int.Parse(srcDstKuniList[1]));

						int engunTotalHei = 0;
						if(dstEngunFlg){
							char[] delimiterChars2 = {':'};
							List<string> engunHeiList = new List<string>();
							engunHeiList = new List<string> (dstEngunHei.Split (delimiterChars2));
							
							for(int k=0; k<engunHeiList.Count; k++){
								engunTotalHei = engunTotalHei + int.Parse(engunHeiList[k]);
							}
						}
						
						enemyHei = enemyHei + engunTotalHei;

						int ratio = 0;
						int myHei = int.Parse(keyValueList[5]);
						if((myHei + enemyHei)>0){
							ratio = 100 * myHei / (myHei + enemyHei);
							if (ratio < 1) {
								ratio = 1;
							}
						}

						MainEventHandler kassenEvent = new MainEventHandler ();
						bool winFlg = kassenEvent.CheckByProbability (ratio);

						if (winFlg) {
							bool noGunzeiFlg = true;
							gunzei.win (keyTemp, int.Parse(keyValueList[1]), int.Parse(keyValueList[2]),noGunzeiFlg);
							
						} else {
							deleteKeyHistory(keyTemp);
						}
					}else{
						MyDaimyoWasAttacked atked = new MyDaimyoWasAttacked();
						atked.wasAttacked(keyTemp, srcKuni, dstKuni, srcDaimyoId, dstDaimyoId, dstEngunFlg, dstEngunDaimyoId,dstEngunSts);

					}

				}else{

					//View Previous
					string path = "Prefabs/Map/Gunzei";
					GameObject Gunzei = Instantiate (Resources.Load (path)) as GameObject;			
					Gunzei.transform.SetParent (GameObject.Find ("Panel").transform);

					Gunzei.GetComponent<Gunzei>().key = keyTemp;

					Gunzei.GetComponent<Gunzei>().srcKuni = int.Parse(srcDstKuniList[0]);
					Gunzei.GetComponent<Gunzei>().dstKuni = int.Parse(srcDstKuniList[1]);
					Gunzei.GetComponent<Gunzei>().spantime = gunzeiSpantime;
					Gunzei.GetComponent<Gunzei>().srcDaimyoId = srcDaimyoId;
					Gunzei.GetComponent<Gunzei>().dstDaimyoId = dstDaimyoId;
					Gunzei.GetComponent<Gunzei>().srcDaimyoName = keyValueList[3];
					Gunzei.GetComponent<Gunzei>().dstDaimyoName = keyValueList[4];
					Gunzei.GetComponent<Gunzei>().myHei = int.Parse(keyValueList[5]);
					Gunzei.GetComponent<Gunzei>().dstEngunFlg = bool.Parse(keyValueList[9]);
					Gunzei.GetComponent<Gunzei>().dstEngunDaimyoId = keyValueList[10];
					Gunzei.GetComponent<Gunzei>().dstEngunHei = keyValueList[11];
					Gunzei.GetComponent<Gunzei>().dstEngunSts = keyValueList[12];
					Gunzei.name = keyTemp;

					RectTransform GunzeiTransform = Gunzei.GetComponent<RectTransform> ();
					GunzeiTransform.anchoredPosition = new Vector3 (int.Parse(keyValueList[6]), int.Parse(keyValueList[7]), 0);

					if(keyValueList[8] == "right"){
						Gunzei.transform.localScale = new Vector2 (1, 1);
					}else{
						Gunzei.transform.localScale = new Vector2 (-1, 1);
						Gunzei.GetComponent<Gunzei>().leftFlg = true;
					}
				}
			}else{
				PlayerPrefs.DeleteKey(keyTemp);
				PlayerPrefs.Flush();
			
			}
		}

		//Metsubou Flg Check
		if (PlayerPrefs.HasKey ("metsubou")) {
			string metsubou = PlayerPrefs.GetString ("metsubou");
			List<string> metsubouList = new List<string> ();
			if (metsubou.Contains (",")) {
				metsubouList = new List<string> (metsubou.Split (delimiterChars));
			} else {
				metsubouList.Add (metsubou);
			}
			
			//Metsubou Message
			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/Metsubou";
			GameObject scroll = Instantiate (Resources.Load (pathOfScroll)) as GameObject;
			scroll.transform.SetParent (board.transform);
			scroll.transform.localScale = new Vector2 (1, 1);

			string pathOfSlot = "Prefabs/Event/MetsubouSlot";
			GameObject contents = scroll.transform.FindChild ("MetsubouScrollView/MetsubouContent").gameObject;
			char[] delimiterChars2 = {':'};
			foreach (string text in metsubouList) {
				GameObject slot = Instantiate (Resources.Load (pathOfSlot)) as GameObject;
				slot.transform.SetParent (contents.transform);
				List<string> metsubouTextList = new List<string> ();
				metsubouTextList = new List<string> (text.Split (delimiterChars2));
				string srcDaimyoName = daimyoMst.param [int.Parse (metsubouTextList [0]) - 1].daimyoName;
				string dstDaimyoName = daimyoMst.param [int.Parse (metsubouTextList [1]) - 1].daimyoName;
				string metsubouText = dstDaimyoName + "は" + srcDaimyoName + "に滅ぼされました";
				slot.transform.FindChild ("MetsubouText").GetComponent<Text> ().text = metsubouText;
				slot.transform.localScale = new Vector2 (1, 1);
			}
			
			PlayerPrefs.DeleteKey ("metsubou");
			PlayerPrefs.Flush ();
		}





		/*--------------------*/
		/*Enemy Action*/
		/*--------------------*/
		MainEventHandler gameEvent = new MainEventHandler ();
		gameEvent.mainHandler ();


		/*--------------------*/
		/*Game Over*/
		/*--------------------*/
		bool gameOverFlg = PlayerPrefs.GetBool("gameOverFlg");
		if (gameOverFlg) {
			Debug.Log ("gameOver");



		}
	
	}	
Example #6
0
    // Use this for initialization
    public void OnClick()
    {
        Message    msg         = new Message();
        Gaikou     gaikou      = new Gaikou();
        CloseBoard closeScript = GameObject.Find("close").GetComponent <CloseBoard> ();

        daimyoId = closeScript.daimyoId;

        if (hyourouOKflg)
        {
            if (moneyOKflg)
            {
                //Track
                int TrackGaikouNo = PlayerPrefs.GetInt("TrackGaikouNo", 0);
                TrackGaikouNo = TrackGaikouNo + 1;
                PlayerPrefs.SetInt("TrackGaikouNo", TrackGaikouNo);


                if (name == "DoMitsugiBtn")
                {
                    string tempGaikou = "gaikou" + daimyoId;
                    int    nowYukoudo = 0;
                    if (PlayerPrefs.HasKey(tempGaikou))
                    {
                        nowYukoudo = PlayerPrefs.GetInt(tempGaikou);
                    }
                    else
                    {
                        nowYukoudo = 50;
                    }

                    float percent = UnityEngine.Random.value;
                    percent = percent * 100;
                    float tmpYukoudo = (float)nowYukoudo;
                    if (tmpYukoudo < 5)
                    {
                        tmpYukoudo = 5;
                    }

                    if (percent <= tmpYukoudo * 2)
                    {
                        //Success
                        audioSources[3].Play();
                        reduceMoneyHyourou();
                        addUsedBusyo(busyoId);

                        //Doumei
                        bool doumeiFlg = closeScript.doumeiFlg;

                        //Add Yukoudo
                        // AddYukoudo = (Money/200)*chiryaku/500
                        int addYukoudo = (paiedMoney / 200) + (busyoChiryaku / 100);
                        if (addYukoudo <= 0)
                        {
                            addYukoudo = 1;
                        }


                        if (doumeiFlg)
                        {
                            addYukoudo = addYukoudo * 2;
                        }


                        int newYukoudo = nowYukoudo + addYukoudo;
                        if (newYukoudo > 100)
                        {
                            newYukoudo = 100;
                        }
                        PlayerPrefs.SetInt(tempGaikou, newYukoudo);
                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();

                        //Change new yukoudo
                        closeScript.yukoudo = newYukoudo;

                        //Message
                        string OKtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            OKtext = "Gave money " + paiedMoney + " to " + daimyoName + ".\n Friendship increased " + addYukoudo + " point";
                        }
                        else
                        {
                            OKtext = daimyoName + "に金" + paiedMoney + "の貢物をしました。\n友好度が" + addYukoudo + "上がりますぞ。";
                        }
                        msg.makeMessage(OKtext);
                        PlayerPrefs.SetBool("questDailyFlg28", true);

                        PlayerPrefs.Flush();

                        //Extension Mark Handling
                        MainStageController main = new MainStageController();
                        main.questExtension();

                        upYukouOnIcon(daimyoId, newYukoudo);
                    }
                    else
                    {
                        //Fail
                        audioSources[4].Play();
                        paiedMoney = 0;
                        reduceMoneyHyourou();

                        //Message
                        string NGtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            NGtext = daimyoName + " declined our money.\n He doesn't want to build a good relationship with us";
                        }
                        else
                        {
                            NGtext = daimyoName + "に貢物を体よく断られ申した。\n当家と関係を修復する気はないようですな。";
                        }
                        msg.makeMessage(NGtext);
                    }
                    //Back
                    GameObject.Find("return").GetComponent <MenuReturn> ().OnClick();
                }
                else if (name == "DoDoumeiBtn")
                {
                    reduceMoneyHyourou();

                    //Doumei
                    float percent = Random.value;
                    percent = percent * 100;

                    if (percent <= doumeiRatio)
                    {
                        //Doumei Success
                        audioSources [3].Play();

                        //Track
                        int TrackDoumeiNo = PlayerPrefs.GetInt("TrackDoumeiNo", 0);
                        TrackDoumeiNo = TrackDoumeiNo + 1;
                        PlayerPrefs.SetInt("TrackDoumeiNo", TrackDoumeiNo);


                        addUsedBusyo(busyoId);

                        string doumei = PlayerPrefs.GetString("doumei");
                        if (doumei == null || doumei == "")
                        {
                            doumei = daimyoId.ToString();
                        }
                        else
                        {
                            doumei = doumei + "," + daimyoId.ToString();
                        }

                        //Data
                        int    myDaimyo      = PlayerPrefs.GetInt("myDaimyo");
                        string cpuDoumeiTemp = "doumei" + daimyoId.ToString();
                        string cpuDoumei     = PlayerPrefs.GetString(cpuDoumeiTemp);
                        if (cpuDoumei != null & cpuDoumei != "")
                        {
                            cpuDoumei = cpuDoumei + "," + myDaimyo.ToString();
                        }
                        else
                        {
                            cpuDoumei = myDaimyo.ToString();
                        }
                        PlayerPrefs.SetString(cpuDoumeiTemp, cpuDoumei);
                        PlayerPrefs.SetString("doumei", doumei);

                        //Change Target Flg & Kuni Icon Color
                        string        seiryoku       = PlayerPrefs.GetString("seiryoku");
                        char[]        delimiterChars = { ',' };
                        List <string> seiryokuList   = new List <string> ();
                        seiryokuList = new List <string> (seiryoku.Split(delimiterChars));
                        GameObject KuniIconView = GameObject.Find("KuniIconView").gameObject;

                        Color doumeiColor = new Color(100f / 255f, 130f / 255f, 255f / 255f, 255f / 255f);                          //Blue
                        for (int i = 0; i < seiryokuList.Count; i++)
                        {
                            int tempDaimyoId = int.Parse(seiryokuList [i]);

                            if (tempDaimyoId == daimyoId)
                            {
                                int        kuniId   = i + 1;
                                GameObject kuniIcon = KuniIconView.transform.FindChild(kuniId.ToString()).gameObject;
                                kuniIcon.GetComponent <Image> ().color         = doumeiColor;
                                kuniIcon.GetComponent <SendParam> ().doumeiFlg = true;
                            }
                        }

                        PlayerPrefs.SetBool("questSpecialFlg2", true);
                        //Extension Mark Handling
                        MainStageController main = new MainStageController();
                        main.questExtension();

                        //Msg
                        string OKtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            OKtext = "Congratulations.\n" + "We concluded an alliance with" + daimyoName + ".\n" + "we got some of strategic options.";
                        }
                        else
                        {
                            OKtext = "教悦至極にございます。" + daimyoName + "と同盟を結びましたぞ。\n" + "戦略の幅が広がりますな。";
                        }
                        msg.makeMessage(OKtext);

                        //If Gunzei Exist
                        foreach (GameObject obs in  GameObject.FindGameObjectsWithTag("Gunzei"))
                        {
                            int srcDaimyoId = obs.GetComponent <Gunzei>().srcDaimyoId;
                            int dstDaimyoId = obs.GetComponent <Gunzei>().dstDaimyoId;
                            if (srcDaimyoId == daimyoId && dstDaimyoId == myDaimyo)
                            {
                                Gunzei gunzeiScript = new Gunzei();
                                gunzeiScript.deleteGunzei(obs);
                            }
                        }


                        Destroy(GameObject.Find("smallBoard(Clone)"));
                        Destroy(GameObject.Find("TouchBack(Clone)"));
                    }
                    else
                    {
                        //Doumie Failed
                        audioSources [4].Play();

                        int maxReduceValue = 3;
                        int nowYukoudo     = gaikou.getMyGaikou(daimyoId);
                        int newYukoudo     = gaikou.downMyGaikou(daimyoId, nowYukoudo, maxReduceValue);
                        int reduceYukoudo  = nowYukoudo - newYukoudo;
                        closeScript.yukoudo = newYukoudo;

                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();
                        string NGtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            NGtext = daimyoName + " declined our proposal. \n" + "Friendship decreased " + reduceYukoudo + " point";
                        }
                        else
                        {
                            NGtext = daimyoName + "に体よく断られ申した。\n友好度が" + reduceYukoudo + "下がりますぞ。";
                        }
                        msg.makeMessage(NGtext);

                        downYukouOnIcon(daimyoId, newYukoudo);

                        //Back
                        GameObject.Find("return").GetComponent <MenuReturn> ().OnClick();
                    }

                    PlayerPrefs.Flush();
                }
                else if (name == "DoKyoutouBtn")
                {
                    reduceMoneyHyourou();

                    //Kyoutou Check
                    float percent = Random.value;
                    percent = percent * 100;
                    if (percent <= kyoutouRatio)
                    {
                        audioSources [3].Play();

                        //Success
                        addUsedBusyo(busyoId);

                        string           playerKyoutouList = PlayerPrefs.GetString("playerKyoutouList", "");
                        MainEventHandler kyoutou           = new MainEventHandler();
                        if (playerKyoutouList == null || playerKyoutouList == "")
                        {
                            playerKyoutouList = targetKuniId + "-" + kyoutou.getEngunSts(daimyoId.ToString());
                        }
                        else
                        {
                            playerKyoutouList = playerKyoutouList + ":" + +targetKuniId + "-" + kyoutou.getEngunSts(daimyoId.ToString());
                        }
                        PlayerPrefs.SetString("playerKyoutouList", playerKyoutouList);

                        //Msg
                        string OKtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            OKtext = "Good. " + daimyoName + "will support our party in " + kuniName + " attack";
                        }
                        else
                        {
                            OKtext = daimyoName + "殿が" + kuniName + "攻めに\n加勢してくれますぞ。百人力ですな。";
                        }
                        msg.makeMessage(OKtext);
                    }
                    else
                    {
                        //Fail
                        audioSources [4].Play();

                        //Doumie Failed
                        int maxReduceValue = 3;
                        int nowYukoudo     = gaikou.getMyGaikou(daimyoId);
                        int newYukoudo     = gaikou.downMyGaikou(daimyoId, nowYukoudo, maxReduceValue);
                        int reduceYukoudo  = nowYukoudo - newYukoudo;
                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();
                        closeScript.yukoudo = newYukoudo;

                        string NGtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            NGtext = daimyoName + " declined our proposal. \n" + "Friendship decreased " + reduceYukoudo + " point";
                        }
                        else
                        {
                            NGtext = daimyoName + "に体よく断られ申した。\n友好度が" + reduceYukoudo + "下がりますぞ。";
                        }
                        msg.makeMessage(NGtext);

                        downYukouOnIcon(daimyoId, newYukoudo);
                    }

                    PlayerPrefs.Flush();

                    //Back
                    GameObject.Find("return").GetComponent <MenuReturn> ().OnClick();
                }
                else if (name == "DoDoukatsuBtn")
                {
                    reduceMoneyHyourou();

                    float percent = Random.value;
                    percent = percent * 100;

                    if (percent <= doukatsuRatio)
                    {
                        //Success
                        audioSources [3].Play();
                        addUsedBusyo(busyoId);

                        int kuniQty  = closeScript.kuniQty;
                        int getMoney = 0;
                        //Money or Item 0:money, 1:item
                        int moneyOrItem = UnityEngine.Random.Range(0, 2);
                        //Kahou or Shizai 0:kahou, 1:shizai
                        int    kahouOrShizai = UnityEngine.Random.Range(0, 2);
                        string kahouName     = "";
                        string shigenName    = "";
                        int    addQty        = 0;
                        int    kahouRank     = 0;                  //kahouRank S,A,B,C=1,2,3,4
                        //shigen Type
                        int shigenType = 0;                        //KB,YR,TP,YM=1,2,3,4

                        if (moneyOrItem == 0)
                        {
                            //money
                            int temGetMoney = UnityEngine.Random.Range(1000, 1501);
                            getMoney = temGetMoney * kuniQty;
                            int nowMoney = PlayerPrefs.GetInt("money");
                            nowMoney = nowMoney + getMoney;
                            if (nowMoney < 0)
                            {
                                nowMoney = int.MaxValue;
                            }
                            PlayerPrefs.SetInt("money", nowMoney);
                            PlayerPrefs.Flush();
                        }
                        else
                        {
                            //item
                            //Kahou or Shizai 0:kahou, 1:shizai
                            kahouOrShizai = UnityEngine.Random.Range(0, 2);
                            if (kahouOrShizai == 0)
                            {
                                //kahou
                                Kahou kahou = new Kahou();
                                ////Bugu, Gusoku, Kabuto, Meiba, Heihousyo, Cyadougu, Chishikisyo(1,2,3,4,5,6)
                                int kahouType = UnityEngine.Random.Range(1, 7);

                                float khPercent = Random.value;
                                khPercent = khPercent * 100;
                                if (5 <= kuniQty)
                                {
                                    if (khPercent <= 1)
                                    {
                                        //S
                                        kahouRank = 1;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (1 < khPercent && khPercent <= 30)
                                    {
                                        //A
                                        kahouRank = 2;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (30 < khPercent)
                                    {
                                        //B
                                        kahouRank = 3;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                }
                                else if (3 <= kuniQty && kuniQty < 5)
                                {
                                    if (khPercent <= 0.5f)
                                    {
                                        //S
                                        kahouRank = 1;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (0.5f < khPercent && khPercent <= 10)
                                    {
                                        //A
                                        kahouRank = 2;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (10 < khPercent && khPercent <= 40)
                                    {
                                        //B
                                        kahouRank = 3;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (40 < khPercent)
                                    {
                                        //C
                                        kahouRank = 4;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                }
                                else if (kuniQty < 3)
                                {
                                    //(A,B,C : 5, 35, 60%)
                                    if (khPercent <= 3)
                                    {
                                        //A
                                        kahouRank = 2;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (3 < khPercent && khPercent <= 31)
                                    {
                                        //B
                                        kahouRank = 3;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                    else if (31 < khPercent)
                                    {
                                        //C
                                        kahouRank = 3;
                                        kahouName = kahou.getRamdomKahou(kahouType, kahouRank);
                                    }
                                }
                            }
                            else
                            {
                                //shizai
                                shigenType = UnityEngine.Random.Range(1, 5);
                                float sgPercent = Random.value;
                                sgPercent = sgPercent * 100;
                                addQty    = UnityEngine.Random.Range(1, 6);
                                Item item       = new Item();
                                int  shigenRank = 0;                               //下、中、上=1,2,3

                                if (5 <= kuniQty)
                                {
                                    //(上,中,下  40,40, 20%)
                                    if (sgPercent <= 40)
                                    {
                                        shigenRank = 3;
                                    }
                                    else if (40 < sgPercent && sgPercent <= 81)
                                    {
                                        shigenRank = 2;
                                    }
                                    else if (81 < sgPercent)
                                    {
                                        shigenRank = 1;
                                    }
                                    shigenName = item.getRandomShigen(shigenType, shigenRank, addQty);
                                }
                                else if (3 <= kuniQty && kuniQty < 5)
                                {
                                    //(上,中,下  20,50,30%)
                                    if (sgPercent <= 20)
                                    {
                                        shigenRank = 3;
                                    }
                                    else if (20 < sgPercent && sgPercent <= 51)
                                    {
                                        shigenRank = 2;
                                    }
                                    else if (51 < sgPercent)
                                    {
                                        shigenRank = 1;
                                    }
                                    shigenName = item.getRandomShigen(shigenType, shigenRank, addQty);
                                }
                                else if (kuniQty < 3)
                                {
                                    //(上,中,下  5,25,70%)
                                    if (sgPercent <= 5)
                                    {
                                        shigenRank = 3;
                                    }
                                    else if (5 < sgPercent && sgPercent <= 26)
                                    {
                                        shigenRank = 2;
                                    }
                                    else if (26 < sgPercent)
                                    {
                                        shigenRank = 1;
                                    }
                                    shigenName = item.getRandomShigen(shigenType, shigenRank, addQty);
                                }
                            }
                        }


                        //Message
                        PlayerPrefs.SetBool("questDailyFlg29", true);
                        //Extension Mark Handling
                        MainStageController main = new MainStageController();
                        main.questExtension();
                        string OKtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            OKtext = "My lord, successed to threat " + daimyoName;
                        }
                        else
                        {
                            OKtext = "御屋形様、恫喝に成功しましたぞ。\n" + daimyoName + "が";
                        }
                        string addText = "";
                        if (moneyOrItem == 0)
                        {
                            if (Application.systemLanguage != SystemLanguage.Japanese)
                            {
                                addText = " gave money " + getMoney + "to us.\n";
                            }
                            else
                            {
                                addText = "金" + getMoney + "を送って参りました。\n";
                            }
                        }
                        else
                        {
                            if (kahouOrShizai == 0)
                            {
                                //kahou
                                if (Application.systemLanguage != SystemLanguage.Japanese)
                                {
                                    addText = " gave treasure " + kahouName + "to us.\n";
                                }
                                else
                                {
                                    addText = "家宝、" + kahouName + "を送って参りました。\n";
                                }
                            }
                            else
                            {
                                //shizai+
                                if (Application.systemLanguage != SystemLanguage.Japanese)
                                {
                                    addText = " gave " + addQty + " " + shigenName + " to us.\n";
                                }
                                else
                                {
                                    addText = shigenName + "を" + addQty + "個送って参りました。\n";
                                }
                            }
                        }

                        int maxReduceValue = 5;
                        int nowYukoudo     = gaikou.getMyGaikou(daimyoId);
                        int newYukoudo     = gaikou.downMyGaikou(daimyoId, nowYukoudo, maxReduceValue);
                        int reduceYukoudo  = nowYukoudo - newYukoudo;
                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();
                        closeScript.yukoudo = newYukoudo;
                        string reducceText = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            reducceText = "Friendship decreased " + reduceYukoudo + " point";
                        }
                        else
                        {
                            reducceText = "友好度が" + reduceYukoudo + "下がりますぞ。";
                        }


                        OKtext = OKtext + addText + reducceText;
                        msg.makeMessage(OKtext);

                        downYukouOnIcon(daimyoId, newYukoudo);
                    }
                    else
                    {
                        //Failed
                        audioSources [4].Play();

                        int maxReduceValue = 10;
                        int nowYukoudo     = gaikou.getMyGaikou(daimyoId);
                        int newYukoudo     = gaikou.downMyGaikou(daimyoId, nowYukoudo, maxReduceValue);
                        int reduceYukoudo  = nowYukoudo - newYukoudo;
                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();
                        closeScript.yukoudo = newYukoudo;

                        //Message
                        string NGtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            NGtext = daimyoName + " declined our proposal. \n" + "Friendship decreased " + reduceYukoudo + " point";
                        }
                        else
                        {
                            NGtext = daimyoName + "に体よく断られ申した。\n友好度が" + reduceYukoudo + "下がりますぞ。";
                        }
                        msg.makeMessage(NGtext);

                        downYukouOnIcon(daimyoId, newYukoudo);
                    }

                    PlayerPrefs.Flush();

                    //Back
                    GameObject.Find("return").GetComponent <MenuReturn> ().OnClick();
                }
                else if (name == "DoSyuppeiBtn")
                {
                    reduceMoneyHyourou();

                    //Syuppei Check
                    float percent = Random.value;
                    percent = percent * 100;
                    if (percent <= kyoutouRatio)
                    {
                        audioSources [3].Play();

                        //Success
                        //Track
                        int TrackSyuppeiNo = PlayerPrefs.GetInt("TrackSyuppeiNo", 0);
                        TrackSyuppeiNo = TrackSyuppeiNo + 1;
                        PlayerPrefs.SetInt("TrackSyuppeiNo", TrackSyuppeiNo);


                        //Success
                        addUsedBusyo(busyoId);

                        //Process
                        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
                        KuniInfo kuni      = new KuniInfo();
                        int      srcX      = kuni.getKuniLocationX(srcKuniId);
                        int      srcY      = kuni.getKuniLocationY(srcKuniId);
                        int      dstX      = kuni.getKuniLocationX(targetKuniId);
                        int      dstY      = kuni.getKuniLocationY(targetKuniId);
                        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);

                        string key = srcKuniId.ToString() + "-" + targetKuniId.ToString();
                        Gunzei.GetComponent <Gunzei> ().key           = key;
                        Gunzei.GetComponent <Gunzei> ().srcKuni       = srcKuniId;
                        Gunzei.GetComponent <Gunzei> ().srcDaimyoId   = srcDaimyoId;
                        Gunzei.GetComponent <Gunzei> ().srcDaimyoName = srcDaimyoName;
                        Gunzei.GetComponent <Gunzei> ().dstKuni       = targetKuniId;
                        Gunzei.GetComponent <Gunzei> ().dstDaimyoId   = targetDaimyoId;
                        Gunzei.GetComponent <Gunzei> ().dstDaimyoName = targetDaimyoName;
                        int myHei = gunzei.heiryokuCalc(srcKuniId);

                        //random myHei from -50%-myHeis
                        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
                        Doumei        doumei           = new Doumei();
                        List <string> doumeiDaimyoList = doumei.doumeiExistCheck(targetDaimyoId, srcDaimyoId.ToString());
                        bool          dstEngunFlg      = false;
                        string        dstEngunDaimyoId = "";             //2:3:5
                        string        dstEngunHei      = "";
                        string        dstEngunSts      = "";             //BusyoId-BusyoLv-ButaiQty-ButaiLv:
                        int           totalEngunHei    = 0;

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


                        //Trace Check
                        List <string> okDaimyoList = new List <string> ();
                        List <string> checkList    = new List <string> ();
                        okDaimyoList = doumei.traceNeighborDaimyo(targetKuniId, targetDaimyoId, 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), targetDaimyoId);

                                //engun check
                                MainEventHandler mainEvent = new MainEventHandler();
                                dstEngunFlg = mainEvent.CheckByProbability(yukoudo);

                                if (dstEngunFlg)
                                {
                                    //Engun OK
                                    dstEngunFlg = true;
                                    if (dstEngunDaimyoId != null && dstEngunDaimyoId != "")
                                    {
                                        dstEngunDaimyoId = dstEngunDaimyoId + ":" + engunDaimyo;
                                        string tempEngunSts = engunDaimyo + "-" + mainEvent.getEngunSts(engunDaimyo);
                                        int    tempEngunHei = mainEvent.getEngunHei(tempEngunSts);
                                        dstEngunHei   = dstEngunHei + ":" + tempEngunHei.ToString();
                                        totalEngunHei = totalEngunHei + tempEngunHei;
                                        dstEngunSts   = dstEngunSts + ":" + tempEngunSts;
                                    }
                                    else
                                    {
                                        dstEngunDaimyoId = engunDaimyo;
                                        string tempEngunSts = engunDaimyo + "-" + mainEvent.getEngunSts(engunDaimyo);
                                        int    tempEngunHei = mainEvent.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 + "," + srcDaimyoId + "," + targetDaimyoId + "," + srcDaimyoName + "," + targetDaimyoName + "," + 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);


                        //Msg
                        string OKtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            OKtext = "Lord " + daimyoName + " is sending " + myHei + " soldiers to " + kuniName;
                        }
                        else
                        {
                            OKtext = daimyoName + "殿が" + kuniName + "攻めのため、\n" + myHei + "人の兵を起こしましたぞ。";
                        }

                        string AddText = "";
                        if (totalEngunHei != 0)
                        {
                            if (Application.systemLanguage != SystemLanguage.Japanese)
                            {
                                AddText = targetDaimyoName + " has a support army " + totalEngunHei + " soldiers";
                            }
                            else
                            {
                                AddText = targetDaimyoName + "に" + totalEngunHei + "の援軍がいるようです。";
                            }

                            OKtext = OKtext + "\n" + AddText;
                        }
                        msg.makeMessage(OKtext);
                    }
                    else
                    {
                        //Fail
                        audioSources [4].Play();

                        int maxReduceValue = 3;
                        int nowYukoudo     = gaikou.getMyGaikou(daimyoId);
                        int newYukoudo     = gaikou.downMyGaikou(daimyoId, nowYukoudo, maxReduceValue);
                        int reduceYukoudo  = nowYukoudo - newYukoudo;
                        GameObject.Find("YukouValue").GetComponent <Text> ().text = newYukoudo.ToString();
                        closeScript.yukoudo = newYukoudo;

                        string NGtext = "";
                        if (Application.systemLanguage != SystemLanguage.Japanese)
                        {
                            NGtext = daimyoName + " declined our proposal. \n" + "Friendship decreased " + reduceYukoudo + " point";
                        }
                        else
                        {
                            NGtext = daimyoName + "に体よく断られ申した。\n友好度が" + reduceYukoudo + "下がりますぞ。";
                        }
                        msg.makeMessage(NGtext);

                        downYukouOnIcon(daimyoId, newYukoudo);
                    }

                    PlayerPrefs.Flush();

                    //Back
                    GameObject.Find("return").GetComponent <MenuReturn> ().OnClick();
                }
            }
            else
            {
                //Message
                audioSources [4].Play();

                string NGtext = msg.getMessage(6);
                msg.makeMessage(NGtext);
            }
        }
        else
        {
            //Message
            audioSources [4].Play();

            //string NGtext = msg.getMessage(7);
            //msg.makeMessage (NGtext);
            msg.hyourouMovieMessage();
        }
    }
Example #7
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);
    }
Example #8
0
	// Update is called once per frame
	void Update () {
		life = getTotalHp (targetTag);
		gameObject.transform.FindChild("HpText").GetComponent<Text>().text = life.ToString();

		if (!flag) {
			if (life == 0) {
				flag = true;

				if (targetTag == "Player") {
					//Game Over
					string backPath = "Prefabs/PostKassen/back";
					GameObject backObj = Instantiate(Resources.Load (backPath)) as GameObject;
					backObj.transform.parent = GameObject.Find ("Canvas").transform;
					backObj.transform.localScale = new Vector2(70,63);

					//Chane word
					Color color = Color.blue;
					GameObject.Find ("winlose").GetComponent<TextMesh>().text = "敗北";
					GameObject.Find ("winlose").GetComponent<TextMesh>().color = color;
					
					string blackPath = "Prefabs/PostKassen/black";
					GameObject blackObj = Instantiate(Resources.Load (blackPath)) as GameObject;
					blackObj.transform.parent = GameObject.Find ("Canvas").transform;
					blackObj.transform.localScale = new Vector2(330,300);

					string makimonoPath = "Prefabs/PostKassen/makimono";
					GameObject makimonoObj = Instantiate(Resources.Load (makimonoPath)) as GameObject;
					makimonoObj.transform.parent = GameObject.Find ("Canvas").transform;
					makimonoObj.transform.localScale = new Vector2(60,80);
					makimonoObj.transform.localPosition = new Vector2(0,-130);

					//Button List
					string nextbtnPath = "Prefabs/PostKassen/bttnList";
					GameObject bttnListObj = Instantiate(Resources.Load (nextbtnPath)) as GameObject;
					bttnListObj.transform.parent = GameObject.Find ("Canvas").transform;
					bttnListObj.transform.localScale = new Vector2(1,1);		
					
					//Time Stop
					GameObject.Find ("timer").GetComponent<Timer>().enabled = false;

					Debug.Log (isAttackedFlg);
					//Check is attacked flag
					if(isAttackedFlg == true){
						//My Daimyo Lose 

						Gunzei lose = new Gunzei();
						string tKey = PlayerPrefs.GetString("activeKey");
						int tSrcDaimyoId = PlayerPrefs.GetInt("activeSrcDaimyoId");
						int tDstDaimyoId = PlayerPrefs.GetInt("activeDstDaimyoId");
						bool noGunzeiFlg = true;
						PlayerPrefs.DeleteKey("isAttacked");
						lose.win(tKey, tSrcDaimyoId, tDstDaimyoId,noGunzeiFlg);


						//Delete Cleared Kuni
						int activeKuniId  = PlayerPrefs.GetInt("activeKuniId");
						string clearedKuni = PlayerPrefs.GetString("clearedKuni");

						char[] delimiterChars = {','};
						List<string> clearedKuniList = new List<string>();
						
						if (clearedKuni != null && clearedKuni != "") {
							if(clearedKuni.Contains(",")){
								clearedKuniList = new List<string> (clearedKuni.Split (delimiterChars));
							}else{
								clearedKuniList.Add(clearedKuni);
							}
						}
						Debug.Log ("before:"+clearedKuniList.Count);
						string tempActiveKuni = activeKuniId.ToString();
						clearedKuniList.Remove(tempActiveKuni);
						Debug.Log ("after:"+clearedKuniList.Count);
						string newClearedKuni = "";
						for(int i=0; i<clearedKuniList.Count; i++){
							if(i==0){
								newClearedKuni = clearedKuniList[i];
							}else{
								newClearedKuni = newClearedKuni + "," + clearedKuniList[i];
							}
						}
						PlayerPrefs.SetString("clearedKuni",newClearedKuni);
						Debug.Log ("NewClearedKuni:"+newClearedKuni);

						if(newClearedKuni==null || newClearedKuni == ""){
							PlayerPrefs.SetBool("gameOverFlg",true);
							Debug.Log ("gameOverFlg");

						}

						//Delete Naisei
						string tempNaisei = "naisei" + activeKuniId.ToString();
						PlayerPrefs.DeleteKey(tempNaisei);

						//Delete Jyosyu
						string tempJyosyu = "jyosyu" + activeKuniId.ToString();
						PlayerPrefs.DeleteKey(tempJyosyu);

						//Delete Stage Clear
						string tempKuni = "kuni" + activeKuniId.ToString();
						PlayerPrefs.DeleteKey(tempKuni);

						//Delete open
						KuniInfo kuni = new KuniInfo();
						kuni.updateOpenKuni();
						PlayerPrefs.Flush();
					}

				} else if (targetTag == "Enemy") {
					//Win
					if(isAttackedFlg == true){
						//history
						string tKey = PlayerPrefs.GetString("activeKey");
						MainStageController main = new MainStageController();
						main.deleteKeyHistory(tKey);
						PlayerPrefs.DeleteKey("isAttacked");
						PlayerPrefs.Flush();
					}

					string backPath = "Prefabs/PostKassen/back";
					GameObject backObj = Instantiate(Resources.Load (backPath)) as GameObject;
					backObj.transform.parent = GameObject.Find ("Canvas").transform;
					backObj.transform.localScale = new Vector2(70,63);

					string particlePath = "Prefabs/PostKassen/particle";
					GameObject particleObj = Instantiate(Resources.Load (particlePath)) as GameObject;
					particleObj.transform.parent = GameObject.Find ("Canvas").transform;
					particleObj.transform.localPosition = new Vector2(0,60);

					string blackPath = "Prefabs/PostKassen/black";
					GameObject blackObj = Instantiate(Resources.Load (blackPath)) as GameObject;
					blackObj.transform.parent = GameObject.Find ("Canvas").transform;
					blackObj.transform.localScale = new Vector2(330,300);

					string makimonoPath = "Prefabs/PostKassen/makimono";
					GameObject makimonoObj = Instantiate(Resources.Load (makimonoPath)) as GameObject;
					makimonoObj.transform.parent = GameObject.Find ("Canvas").transform;
					makimonoObj.transform.localScale = new Vector2(60,80);
					makimonoObj.transform.localPosition = new Vector2(0,-130);

					//Item List
					string itemListPath = "Prefabs/PostKassen/itemList";
					GameObject itemListObj = Instantiate(Resources.Load (itemListPath)) as GameObject;
					itemListObj.transform.parent = GameObject.Find ("Canvas").transform;
					itemListObj.transform.localScale = new Vector2(1,1);

					if(!isAttackedFlg){

						/*Item or Kahou*/
						string activeItemType = PlayerPrefs.GetString("activeItemType");
						int activeItemId = PlayerPrefs.GetInt("activeItemId");
						float activeItemRatio = PlayerPrefs.GetFloat("activeItemRatio");
						int activeItemQty = PlayerPrefs.GetInt("activeItemQty");

						float percent = Random.value;
						percent = percent * 100;

						if(percent <= activeItemRatio){
							//if(0 <= activeItemRatio){ //Test
							//Get Item

							string cyouheiPath = "Prefabs/Item/Cyouhei/" + activeItemType;
							string kanjyoPath = "Prefabs/Item/Kanjyo/Kanjyo";
							string hidensyoPath = "Prefabs/Item/Hidensyo/Hidensyo";
							char[] delimiterChars = {','};

							ShowStageDtl itemIcon = new ShowStageDtl();
							if(activeItemType.Contains("Cyouhei")==true){
								string newCyouheiString = "";

								itemIcon.makeItemIcon(cyouheiPath, activeItemId.ToString(), itemListObj);
								if(activeItemType.Contains("YR")==true){
									string cyouheiString = PlayerPrefs.GetString("cyouheiYR");
									string[] cyouheiList = cyouheiString.Split (delimiterChars);
									if(activeItemId == 1){
										int tempQty = int.Parse(cyouheiList[0]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = tempQty.ToString() + "," + cyouheiList[1] +","+ cyouheiList[2];

									}else if(activeItemId == 2){
										int tempQty = int.Parse(cyouheiList[1]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] + "," + tempQty.ToString() +","+ cyouheiList[2];

									}else if(activeItemId == 3){
										int tempQty = int.Parse(cyouheiList[2]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] +","+ cyouheiList[1] + "," + tempQty.ToString();
									}

									PlayerPrefs.SetString("cyouheiYR", newCyouheiString);

								}else if(activeItemType.Contains("KB")==true){
									string cyouheiString = PlayerPrefs.GetString("cyouheiKB");
									string[] cyouheiList = cyouheiString.Split (delimiterChars);
									if(activeItemId == 1){
										int tempQty = int.Parse(cyouheiList[0]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = tempQty.ToString() + "," + cyouheiList[1] +","+ cyouheiList[2];
										
									}else if(activeItemId == 2){
										int tempQty = int.Parse(cyouheiList[1]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] + "," + tempQty.ToString() +","+ cyouheiList[2];
										
									}else if(activeItemId == 3){
										int tempQty = int.Parse(cyouheiList[2]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] +","+ cyouheiList[1] + "," + tempQty.ToString();
									}
									
									PlayerPrefs.SetString("cyouheiKB", newCyouheiString);

								}else if(activeItemType.Contains("TP")==true){
									string cyouheiString = PlayerPrefs.GetString("cyouheiTP");
									string[] cyouheiList = cyouheiString.Split (delimiterChars);
									if(activeItemId == 1){
										int tempQty = int.Parse(cyouheiList[0]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = tempQty.ToString() + "," + cyouheiList[1] +","+ cyouheiList[2];
										
									}else if(activeItemId == 2){
										int tempQty = int.Parse(cyouheiList[1]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] + "," + tempQty.ToString() +","+ cyouheiList[2];
										
									}else if(activeItemId == 3){
										int tempQty = int.Parse(cyouheiList[2]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] +","+ cyouheiList[1] + "," + tempQty.ToString();
									}
									
									PlayerPrefs.SetString("cyouheiTP", newCyouheiString);

								}else if(activeItemType.Contains("YM")==true){
									string cyouheiString = PlayerPrefs.GetString("cyouheiYM");
									string[] cyouheiList = cyouheiString.Split (delimiterChars);
									if(activeItemId == 1){
										int tempQty = int.Parse(cyouheiList[0]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = tempQty.ToString() + "," + cyouheiList[1] +","+ cyouheiList[2];
										
									}else if(activeItemId == 2){
										int tempQty = int.Parse(cyouheiList[1]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] + "," + tempQty.ToString() +","+ cyouheiList[2];
										
									}else if(activeItemId == 3){
										int tempQty = int.Parse(cyouheiList[2]);
										tempQty = tempQty + activeItemQty;
										newCyouheiString = cyouheiList[0] +","+ cyouheiList[1] + "," + tempQty.ToString();
									}
									
									PlayerPrefs.SetString("cyouheiYM", newCyouheiString);
								}



							}else if(activeItemType == "Kanjyo"){
								itemIcon.makeItemIcon(kanjyoPath, activeItemId.ToString(), itemListObj);

								string newKanjyoString = "";
								string kanjyoString = PlayerPrefs.GetString("kanjyo");
								string[] kanjyoList = kanjyoString.Split (delimiterChars);

								if(activeItemId == 1){
									int tempQty = int.Parse(kanjyoList[0]);
									tempQty = tempQty + activeItemQty;
									newKanjyoString = tempQty.ToString() + "," + kanjyoList[1] +","+ kanjyoList[2];
									
								}else if(activeItemId == 2){
									int tempQty = int.Parse(kanjyoList[1]);
									tempQty = tempQty + activeItemQty;
									newKanjyoString = kanjyoList[0] + "," + tempQty.ToString() +","+ kanjyoList[2];
									
								}else if(activeItemId == 3){
									int tempQty = int.Parse(kanjyoList[2]);
									tempQty = tempQty + activeItemQty;
									newKanjyoString = kanjyoList[0] +","+ kanjyoList[1] + "," + tempQty.ToString();
								}
								PlayerPrefs.SetString("kanjyo", newKanjyoString);

							}else if(activeItemType == "Hidensyo"){
								itemIcon.makeItemIcon(hidensyoPath, activeItemId.ToString(), itemListObj);

								if(activeItemId == 1){
									int hidensyoQty = PlayerPrefs.GetInt("hidensyoGe");
									hidensyoQty = hidensyoQty + activeItemQty;
									PlayerPrefs.SetInt("hidensyoGe", hidensyoQty);

								}else if(activeItemId == 2){
									int hidensyoQty = PlayerPrefs.GetInt("hidensyoCyu");
									hidensyoQty = hidensyoQty + activeItemQty;
									PlayerPrefs.SetInt("hidensyoCyu", hidensyoQty);

								}else if(activeItemId == 3){
									int hidensyoQty = PlayerPrefs.GetInt("hidensyoJyo");
									hidensyoQty = hidensyoQty + activeItemQty;
									PlayerPrefs.SetInt("hidensyoJyo", hidensyoQty);
								}

							}else{
								//Kahou
								string kahouIconPath = "Prefabs/Item/Kahou/" + activeItemType + activeItemId;
								GameObject kahouIcon = Instantiate (Resources.Load (kahouIconPath)) as GameObject;
								kahouIcon.transform.SetParent(itemListObj.transform);
								kahouIcon.name = "itemIcon";
								RectTransform kahouTransform = kahouIcon.GetComponent<RectTransform> ();
								kahouTransform.sizeDelta = new Vector2 (100, 100);
								GameObject rank = kahouIcon.transform.FindChild("Rank").gameObject;
								rank.transform.localScale = new Vector2(0.3f,0.3f);
								rank.transform.localPosition = new Vector2(20,-20);

								//Register
								addKahou(activeItemType, activeItemId);
							}



							//Modfication Size & Location
							GameObject item = GameObject.Find ("itemIcon");
							item.transform.localScale = new Vector2 (0.4f, 0.42f);
							item.transform.localPosition = new Vector2(80,-105);
							item.GetComponent<Button>().enabled = false;

							//Qty
							string itemQtyPath = "Prefabs/PostKassen/itemQty";
							GameObject itemQtyObj = Instantiate(Resources.Load (itemQtyPath)) as GameObject;
							itemQtyObj.transform.SetParent(itemListObj.transform);
							itemQtyObj.transform.localScale = new Vector2(0.09f,0.09f);
							itemQtyObj.transform.localPosition = new Vector2(130,-105);
							itemQtyObj.GetComponent<Text>().text = "x " + activeItemQty.ToString();

							//
							PlayerPrefs.Flush();
						}
					}

					//Money
					int activeStageMoney = PlayerPrefs.GetInt("activeStageMoney",0);
					GameObject.Find ("moneyAmt").GetComponent<TextMesh>().text = activeStageMoney.ToString();
					int currentMoney = PlayerPrefs.GetInt("money");
					currentMoney = currentMoney + activeStageMoney;
					PlayerPrefs.SetInt("money",currentMoney);

					//kuniExp
					int activeStageExp = PlayerPrefs.GetInt("activeStageExp",0);
					GameObject.Find ("expAmt").GetComponent<TextMesh>().text = activeStageExp.ToString();
					int currentKuniExp = PlayerPrefs.GetInt ("kuniExp");
					currentKuniExp = currentKuniExp + activeStageExp;
					int kuniLv = PlayerPrefs.GetInt ("kuniLv");
					Exp kuniExp = new Exp();
					int newKuniLv = kuniExp.getKuniLv(kuniLv,currentKuniExp);

					if(newKuniLv>kuniLv){
						//lv up
						int jinkeiLimit = kuniExp.getJinkeiLimit(newKuniLv);
						int stockLimit = kuniExp.getStockLimit(newKuniLv);
						PlayerPrefs.SetInt("jinkeiLimit",jinkeiLimit);
						PlayerPrefs.SetInt("stockLimit",stockLimit);


					}else{
						Debug.Log ("No level up");
					}

					/*Cleared Flag*/
					if(!isAttackedFlg){
						int activeKuniId  = PlayerPrefs.GetInt("activeKuniId");
						int activeStageId = PlayerPrefs.GetInt("activeStageId");
						string temp = "kuni" + activeKuniId.ToString();

						List<string> clearedStageList = new List<string>();
						string clearedStageString  = PlayerPrefs.GetString(temp);

						if(clearedStageString !=null && clearedStageString !=""){
							//after 1st time
							char[] delimiterChars = {','};
							clearedStageList = new List<string>(clearedStageString.Split (delimiterChars));
							if(clearedStageList.Contains(activeStageId.ToString()) == false){
								clearedStageString = clearedStageString + "," + activeStageId.ToString();

								//1st Kuni Clear Check
								string[] commaCounter = clearedStageString.Split(delimiterChars);
								int counter = commaCounter.Length;

								if(counter == 10){
									//1st time
									string clearedKuni = PlayerPrefs.GetString("clearedKuni");
									if(clearedKuni !=null && clearedKuni !=""){
										clearedKuni = clearedKuni + "," + activeKuniId.ToString();
									}else{
										clearedKuni = activeKuniId.ToString();
									}
									PlayerPrefs.SetString("clearedKuni",clearedKuni);
									//Give 1st cleared revenue 
									PlayerPrefs.SetBool("kuniClearedFlg",true);

									//Open Kuni
									KuniInfo kuni = new KuniInfo();
									kuni.registerOpenKuni(activeKuniId);

									//Seiryoku Change
									string seiryoku = PlayerPrefs.GetString ("seiryoku");
									List<string> seiryokuList = new List<string>();
									seiryokuList = new List<string> (seiryoku.Split (delimiterChars));

									int myDaimyo = PlayerPrefs.GetInt ("myDaimyo");
									seiryokuList[activeKuniId-1] = myDaimyo.ToString();
									string newSeiryoku = "";
									for(int i=0; i<seiryokuList.Count; i++){
										if(i==0){
											newSeiryoku = seiryokuList[i];
										}else{
											newSeiryoku = newSeiryoku + "," + seiryokuList[i];
										}
									}
									PlayerPrefs.SetString("seiryoku",newSeiryoku);

								}
							}
						}else{
							//1st time
							clearedStageString = activeStageId.ToString();
							Debug.Log (clearedStageString);
						}
						PlayerPrefs.SetString(temp,clearedStageString);

						PlayerPrefs.SetInt("kuniLv",newKuniLv);
						PlayerPrefs.SetInt("kuniExp",currentKuniExp);
						PlayerPrefs.Flush();
					}

					//Button List
					string nextbtnPath = "Prefabs/PostKassen/bttnList";
					GameObject bttnListObj = Instantiate(Resources.Load (nextbtnPath)) as GameObject;
					bttnListObj.transform.parent = GameObject.Find ("Canvas").transform;
					bttnListObj.transform.localScale = new Vector2(1,1);


					//Time Stop
					GameObject.Find ("timer").GetComponent<Timer>().enabled = false;


					//Get Exp
					SenkouButton senkou = new SenkouButton();
					List<BusyoSenkou> senkouList = new List<BusyoSenkou>();
					senkouList=senkou.getSenkou ();
					for(int i=0;i<senkouList.Count;i++){

						int busyoId = senkouList[i].id;
						int senkouAmt = senkouList[i].senkou;
						Exp exp = new Exp();

						//Modify by Cyadougu Kahou
						senkouAmt = exp.getExpbyCyadougu(busyoId,senkouAmt);

						//Busyo Exp
						string tempExp = "exp" + busyoId;
						int nowExp = PlayerPrefs.GetInt(tempExp);
						int newExp = nowExp + senkouAmt;
						PlayerPrefs.SetInt(tempExp, newExp);

						//Busyo Lv
						int nowLv = PlayerPrefs.GetInt(busyoId.ToString());
						int newLv = exp.getLvbyTotalExp(nowLv,newExp);
						PlayerPrefs.SetInt(busyoId.ToString(), newLv);

						PlayerPrefs.Flush();
					}
				}
			}
		}
	}