Example #1
0
	public void Start () {

		//Get Temp Kuni Id & Stage Id
		activeKuniId = PlayerPrefs.GetInt ("activeKuniId");
		string temp = "naisei" + activeKuniId.ToString ();

		/*Initial Setting*/
		//Kuni Name & jyosyu
		string title = "";
		string kuniName = PlayerPrefs.GetString ("activeKuniName");

		string jyosyuTemp = "jyosyu" + activeKuniId;

		//Clear Image
		foreach ( Transform n in GameObject.Find ("JyosyuImage").transform){
			GameObject.Destroy(n.gameObject);
		}

		if (PlayerPrefs.HasKey (jyosyuTemp)) {
			//Jyosyu Exist
			jyosyuId = PlayerPrefs.GetInt (jyosyuTemp);
			string busyoPath = "Prefabs/Player/Unit/" + jyosyuId;
			GameObject busyo = Instantiate (Resources.Load (busyoPath)) as GameObject;
			busyo.transform.SetParent (GameObject.Find ("JyosyuImage").transform);
			busyo.transform.localScale = new Vector2 (4, 4);
			busyo.GetComponent<DragHandler>().enabled = false;
			RectTransform busyo_transform = busyo.GetComponent<RectTransform>();
			busyo_transform.anchoredPosition3D = new Vector3(40,40,0);
			busyo_transform.sizeDelta = new Vector2( 23, 23);

			foreach(Transform n in busyo.transform){
				GameObject.Destroy(n.gameObject);
			}

			StatusGet sts = new StatusGet();
			string jyosyuName = sts.getBusyoName(jyosyuId);
			title = kuniName + "・" + jyosyuName;

			//Ninmei Button
			GameObject btn = GameObject.Find ("Ninmei").gameObject;
			btn.GetComponent<Ninmei>().kaininFlg = true;
			btn.transform.FindChild("NinmeiText").GetComponent<Text>().text = "城主解任";
			btn.GetComponent<Ninmei>().jyosyuId = jyosyuId;
			btn.GetComponent<Ninmei>().jyosyuName = jyosyuName;

		} else {
			//Jyosyu Not Exist
			title = kuniName + "・蔵入地"; 

			//Ninmei Button
			GameObject btn = GameObject.Find ("Ninmei").gameObject;
			btn.GetComponent<Ninmei>().kaininFlg = false;
			btn.transform.FindChild("NinmeiText").GetComponent<Text>().text = "城主任命";
		}

		GameObject.Find ("StageNameValue").GetComponent<Text> ().text = title;


		//Money
		int money = PlayerPrefs.GetInt("money");
		GameObject.Find ("MoneyValue").GetComponent<Text> ().text = money.ToString();

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

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

		//Naisei Icon List
		KuniInfo kuni = new KuniInfo ();
		shigen = kuni.getKuniNaisei (activeKuniId);



		//Sea or Tree
		isSeaFlg = kuni.getKuniIsSeaFlg (activeKuniId);
		GameObject otherObj = GameObject.Find ("Other").gameObject;
		if (isSeaFlg) {
			if(otherObj.transform.FindChild("treeUpper") != null){
				otherObj.transform.FindChild("treeUpper").gameObject.SetActive(false);
			}
		} else {
			if(otherObj.transform.FindChild("sea") != null){
				otherObj.transform.FindChild("sea").gameObject.SetActive(false);
			}
		}



		/*Open Panel*/
		//Clear Previous Panel
		foreach ( Transform n in GameObject.Find ("NaiseiView").transform){
			GameObject.Destroy(n.gameObject);
		}
		//Clear Previous Mask Panel
		foreach ( Transform n in GameObject.Find ("MaskView").transform){
			GameObject.Destroy(n.gameObject);
		}

		//Open Panel & MaskPanel
 		panelByShiro(activeKuniId);
		panelByKuniLv();

		if (PlayerPrefs.HasKey (temp)) {
			/*initial setting*/
			string naiseiString = PlayerPrefs.GetString (temp);
			List<string> naiseiList = new List<string>();
			char[] delimiterChars = {','};
			naiseiList = new List<string>(naiseiString.Split (delimiterChars));

			/*Naisei Bldg Handling*/
			char[] delimiterChars2 = {':'};
			List<string> deletePanelList = new List<string>();
			Entity_naisei_mst naiseiMst = Resources.Load ("Data/naisei_mst") as Entity_naisei_mst;

			for(int i=1; i<naiseiList.Count;i++){

				List<string> naiseiContentList = new List<string>();
				naiseiContentList = new List<string>(naiseiList[i].Split (delimiterChars2));


				if(naiseiContentList[0] != "0"){
					//Exist
					string bldgRank = "";
					if(int.Parse(naiseiContentList[1])<8){
						bldgRank = "s";
					}else if(int.Parse(naiseiContentList[1]) < 15){
						bldgRank = "m";
					}else if(15 <= int.Parse(naiseiContentList[1])){
						bldgRank = "l";
					}

					//Add Delete Target
					deletePanelList.Add(i.ToString());

					//Make New Panel
					string type = naiseiMst.param [int.Parse(naiseiContentList[0])].code;
					string bldg = type + "_" + bldgRank;
					string bldgPath = "Prefabs/Naisei/Bldg/" + bldg;
					GameObject bldgObj = Instantiate (Resources.Load (bldgPath)) as GameObject;
					bldgObj.transform.parent = GameObject.Find ("NaiseiView").transform;
					bldgObj.transform.localScale = new Vector3 (1, 1, 1);
					setBldg(bldgObj, i);
					bldgObj.name = i.ToString();
					bldgObj.GetComponent<AreaButton>().blank = false;
					bldgObj.GetComponent<AreaButton>().type = type;
					bldgObj.GetComponent<AreaButton>().lv = naiseiContentList[1];
					bldgObj.GetComponent<AreaButton>().naiseiId = int.Parse(naiseiContentList[0]);

					//Effect by Level
					List<int> naiseiEffectList = new List<int>();
					naiseiEffectList = getNaiseiList(type, int.Parse(naiseiContentList[1]));
					if(type != "kzn"){
						if(type != "yr" &&type != "kb"&&type != "tp" &&type != "ym" &&type !="snb"){
							bldgObj.GetComponent<AreaButton>().effect = naiseiEffectList[0];
							bldgObj.GetComponent<AreaButton>().effectNextLv = naiseiEffectList[1];
						}else{
							bldgObj.GetComponent<AreaButton>().effect = naiseiEffectList[0] * 2;
							bldgObj.GetComponent<AreaButton>().effectNextLv = naiseiEffectList[1] * 2;
						}
					}else{
						bldgObj.GetComponent<AreaButton>().effect = naiseiEffectList[0] * 4;
						bldgObj.GetComponent<AreaButton>().effectNextLv = naiseiEffectList[1] * 4;
					}

					bldgObj.GetComponent<AreaButton>().moneyNextLv = naiseiEffectList[2];
					bldgObj.GetComponent<AreaButton>().requiredHyourou =naiseiMst.param [int.Parse(naiseiContentList[0])].hyourou;
					bldgObj.GetComponent<AreaButton>().naiseiName =naiseiMst.param [int.Parse(naiseiContentList[0])].name;

					//Status
					if(type == "shop"){
						syogyo = syogyo + naiseiEffectList[0];
					}else if(type == "ta"){
						nogyo = nogyo + naiseiEffectList[0];
					}else if(type == "yr" ||type == "kb"||type == "tp" ||type == "ym"||type == "snb"){
						int tempCalc = naiseiEffectList[0] * 2;
						gunjyu = gunjyu + tempCalc;
					}else if(type == "ashigaru"){
						ashigaru = ashigaru + naiseiEffectList[0];
					}else if(type == "trd"){
						boubi = boubi + naiseiEffectList[0];
					}else if(type == "kzn"){
						int tempCalc = naiseiEffectList[0] * 4;
						syogyo = syogyo + tempCalc;
					}else if(type == "nbn"){
						int tempCalc = naiseiEffectList[0];
						kirisuto = kirisuto + tempCalc;
					}else if(type == "kgy"){
						int tempCalc = naiseiEffectList[0];
						bunka = bunka + tempCalc;					
					}else if(type == "bky"){
						int tempCalc = naiseiEffectList[0];
						bukkyo = bukkyo + tempCalc;					
					}else if(type == "hsy"){
						int tempCalc = naiseiEffectList[0];
						ashigaru = ashigaru + tempCalc;					
					}else{
						Debug.Log ("Not Yet");

					}
				}
			}

			//Clear Duplicated Panel
			foreach ( Transform n in GameObject.Find ("NaiseiView").transform){
				if(deletePanelList.Contains(n.name)){
					if(n.tag == "Area"){
						GameObject.Destroy(n.gameObject);
					}
				}
			}

			/*shiro setting*/
			string rank = "";
			if(int.Parse(naiseiList[0])<8){
				rank = "s";
				setShiro(rank, naiseiList[0]);
			}else if(int.Parse(naiseiList[0]) < 15){
				rank = "m";
				setShiro(rank, naiseiList[0]);
			}else if(15 <= int.Parse(naiseiList[0])){
				rank = "l";
				setShiro(rank, naiseiList[0]);
			}
			
			string maskPath = "Prefabs/Naisei/MaskPanel";
			GameObject maskPanel = Instantiate (Resources.Load (maskPath)) as GameObject;
			maskPanel.transform.parent = GameObject.Find ("MaskView").transform;
			maskPanel.transform.localScale = new Vector3 (1, 1, 1);
			RectTransform maskPanel_transform = maskPanel.GetComponent<RectTransform>();
			maskPanel_transform.anchoredPosition3D = new Vector3(0,-20,0);
			maskPanel.name = "shiro_" + rank;


			//Status Handling

			//Status Jyosyu Modification
			if (PlayerPrefs.HasKey (jyosyuTemp)) {
				StatusGet sts = new StatusGet();
				int lv = PlayerPrefs.GetInt (jyosyuId.ToString());
				float naiseiSts = (float)sts.getDfc(jyosyuId,lv);

				float hpSts = (float)sts.getHp(jyosyuId,lv);
				float atkSts = (float)sts.getAtk(jyosyuId,lv);
				float boubiSts = (hpSts + atkSts)/2;

				float tempSyogyo = (float)syogyo;
				tempSyogyo = tempSyogyo + (tempSyogyo * naiseiSts/200);
				float tempNogyo = (float)nogyo;
				tempNogyo = tempNogyo + (tempNogyo * naiseiSts/200);
				float tempBoubi = (float)boubi;
				tempBoubi = tempBoubi + (tempBoubi * naiseiSts/200);

				syogyo = (int)tempSyogyo;
				nogyo = (int)tempNogyo;
				boubi = (int)tempBoubi;

			}

			GameObject.Find("SyogyoValue").GetComponent<Text>().text = syogyo.ToString();
			GameObject.Find("NougyoValue").GetComponent<Text>().text = nogyo.ToString();
			GameObject.Find("GunjyuValue").GetComponent<Text>().text = gunjyu.ToString();
			GameObject.Find("AshigaruValue").GetComponent<Text>().text = ashigaru.ToString();
			GameObject.Find("BoubiValue").GetComponent<Text>().text = boubi.ToString();
			GameObject.Find("BukkyoValue").GetComponent<Text>().text = bukkyo.ToString();
			GameObject.Find("KirisutoValue").GetComponent<Text>().text = kirisuto.ToString();
			GameObject.Find("BunkaValue").GetComponent<Text>().text = bunka.ToString();
			GameObject.Find("BukkyoValue").GetComponent<Text>().text = bukkyo.ToString();


			//jyosyu status update
			if (PlayerPrefs.HasKey (jyosyuTemp)) {
				int jyosyuId = PlayerPrefs.GetInt (jyosyuTemp);
				string heiTmp = "jyosyuHei" + jyosyuId;

				PlayerPrefs.SetInt (heiTmp,ashigaru);
			}
			string boubiTmp = "boubi" + activeKuniId;
			PlayerPrefs.SetInt (boubiTmp,boubi);




		} else {
			//Error
			Debug.Log ("ERROR");
		}

		/***************************/
		/*Tabibito Controller Start*/
		/***************************/

		tabibitoObj = GameObject.Find ("Tabibito").gameObject;
		
		loginTemp = "naiseiLoginDate" + activeKuniId.ToString ();
		string loginTimeString = PlayerPrefs.GetString (loginTemp);
		if (loginTimeString == null || loginTimeString == "") {
			loginTimeString = System.DateTime.Today.ToString ();
			PlayerPrefs.SetString (loginTemp,loginTimeString);
			PlayerPrefs.Flush();
		}
		
		System.DateTime loginTime = System.DateTime.Parse (loginTimeString);
		System.TimeSpan span = System.DateTime.Today - loginTime;
		double spanDay = span.TotalDays;
		
		string counterTemp = "naiseiTabibitoCounter" + activeKuniId.ToString ();
		if (spanDay >= 1) {
			//Reset
			PlayerPrefs.SetInt (counterTemp,0);
			PlayerPrefs.Flush();
			counter = 0;
			
		}else{
			//Get Counted No
			counter = PlayerPrefs.GetInt (counterTemp,0);
		}
		
		//Set Tabibito Max
		total = (boubi + bukkyo + kirisuto + bunka)/10;
		remain = total - counter;
		tabibitoObj.transform.FindChild ("TabibitoMaxValue").GetComponent<Text> ().text = total.ToString ();
		tabibitoObj.transform.FindChild ("TabibitoCountDownValue").GetComponent<Text> ().text = remain.ToString ();



		/***************************/
		/*Tabibito Controller End  */
		/***************************/



	}