void SetPetCellState(GameObject o, Pet p) { Text[] t = o.GetComponentsInChildren <Text> (); Monster m = LoadTxt.GetMonster(p.monsterId); t [0].text = m.name; switch (p.state) { case 0: t [1].text = "Free Range"; break; case 1: t [1].text = "Riding"; break; case 2: t [1].text = "Patrolling"; break; default: t [1].text = "Free Range"; break; } t[2].text = m.canCapture.ToString(); }
public void Kill() { if (_localPet.state == 1) { RemoveMount(); } string s = "You slaughtered " + _localPet.name + "."; Monster m = LoadTxt.GetMonster(_localPet.monsterId); Dictionary <int, int> r = Algorithms.GetReward(m.drop); if (r.Count > 0) { foreach (int key in r.Keys) { _gameData.AddItem(key * 10000, r [key]); s += LoadTxt.MatDic [key].name + " ×" + r [key] + ","; } s = s.Substring(0, s.Length - 1) + "."; } _logManager.AddLog(s); GameData._playerData.Pets.Remove(_localIndex); StorePetState(); CallOutDetail(); SetPetCells(); }
void UpdateDetail() { Text[] t = Detail.gameObject.GetComponentsInChildren <Text> (); Monster m = LoadTxt.GetMonster(_localPet.monsterId); t [0].text = _localPet.name; t [1].text = "Desc."; switch (_localPet.state) { case 0: t [2].text = "Free Range"; break; case 1: t [2].text = "Ride"; break; case 2: t [2].text = "Patrolling"; break; default: break; } t [2].color = Color.green; t [3].text = m.canCapture.ToString(); t [4].text = m.name; t [5].text = _localPet.speed.ToString(); t [6].text = _localPet.alertness.ToString(); }
void SetPetCells() { OnLeave(); petCell = Instantiate(Resources.Load("petCell")) as GameObject; petCell.SetActive(false); petSpace = GameData._playerData.PetsOpen * 10; openPetCell = 0; usedSpace = 0; for (int i = 0; i < petCells.Count; i++) { GameObject o = petCells [i] as GameObject; ClearContents(o); } foreach (int key in GameData._playerData.Pets.Keys) { openPetCell++; Monster m = LoadTxt.GetMonster(GameData._playerData.Pets [key].monsterId); usedSpace += m.canCapture; } spaceText.text = "Space(" + usedSpace + "/" + petSpace + ")"; if (openPetCell > petCells.Count) { for (int i = petCells.Count; i < openPetCell; i++) { GameObject o = Instantiate(petCell) as GameObject; o.transform.SetParent(contentP.transform); o.transform.localPosition = Vector3.zero; o.transform.localScale = Vector3.one; petCells.Add(o); } } if (openPetCell < petCells.Count) { for (int i = openPetCell; i < petCells.Count; i++) { GameObject o = petCells [i] as GameObject; petCells.RemoveAt(i); GameObject.Destroy(o); } } int j = 0; foreach (int key in GameData._playerData.Pets.Keys) { GameObject o = petCells [j] as GameObject; o.SetActive(true); o.gameObject.name = key.ToString(); SetPetCellState(o, GameData._playerData.Pets [key]); j++; } contentP.gameObject.GetComponent <RectTransform> ().sizeDelta = new Vector2(800, 100 * openPetCell); }
void CatchThief(Thief t) { string s = "You get "; Dictionary <int, int> drop = Algorithms.GetReward(LoadTxt.GetMonster(t.monsterId).drop); foreach (int key in drop.Keys) { _gameData.AddItem(key * 10000, drop [key]); s += LoadTxt.MatDic [key].name + " ×" + drop [key]; break; } if (drop.Count <= 0) { s = ""; } _logManager.AddLog(t.name + " tried to steal, but was caught by your guard." + s); //Achievement this.gameObject.GetComponentInParent <AchieveActions>().CatchThief(t.id); }
void CheckThiefActivities() { //开始日期 if (GameData._playerData.dayNow <= GameConfigs.StartThiefEvent) { return; } //上次盗贼光顾时间 if (GameData._playerData.lastThiefTime >= GameData._playerData.dayNow - 2) { return; } //触发盗贼概率 int r = Algorithms.GetIndexByRange(0, 100); // Debug.Log(r); if (r >= (int)(GameData._playerData.ThiefDefence * 100f)) { return; } GameData._playerData.lastThiefTime = GameData._playerData.dayNow; _gameData.StoreData("LastThiefTime", GameData._playerData.lastThiefTime); Thief[] tList = LoadTxt.GetThiefList(); int[] weight = new int[tList.Length]; int[] ids = new int[weight.Length]; int i = 0; for (int key = 0; key < tList.Length; key++) { weight [i] = tList[key].weight; ids [i] = key; i++; } i = Algorithms.GetResultByWeight(weight); Thief _thisThief = tList[ids [i]]; int antiAlert = LoadTxt.GetMonster(_thisThief.monsterId).level; int alert = GetGuardAlert(); //发现概率 int p = 0; if (alert > 2 * antiAlert) { p = 10000; } else if (antiAlert > alert * 5) { p = 0; } else { p = alert * 10000 / (alert + antiAlert); } r = Random.Range(0, 10000); if (r <= p) { CatchThief(_thisThief); } else { BeStolen(_thisThief); } }