void Start() { WorldUI = GameObject.Find("PlayerCamera").transform.Find("WorldUI(Clone)").transform; teamPanel = WorldUI.Find("TeamPanel"); //确定所在国籍 selfCountry = WorldObj.SelfCountry(); cityController = selfCountry.GetComponent <CityController>(); teamController = selfCountry.GetComponent <TeamController>(); uiController = selfCountry.GetComponent <UIController>(); }
/// <summary> /// 同步更新战争状态 /// </summary> /// <param name="_newDefence">新战争状态</param> public void UpdateFighting(bool _fighting) { CountryObj selfCountry = WorldObj.MatchCountry(nationality); if (selfCountry) { uiController = selfCountry.GetComponent <UIController>(); uiController.ScoutInfoShow(nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.CityBeAttacked, this.gameObject); } photonView.RPC("UpdateFightingRPC", PhotonTargets.All, _fighting); }
/// <summary> /// 英雄技能冷却 /// </summary> void HeroSkillCoolDown() { heroSkillButton.enabled = false; float cooltime = 0; switch (WorldObj.MatchHero(teamObj.hero).heroskill) { case WorldObj.HeroSkill.none: cooltime = 0; break; case WorldObj.HeroSkill.IncreaseOwnSpeed: cooltime = WorldObj.IncreaseOwnSpeedCoolDown; break; case WorldObj.HeroSkill.ReduceEnemySpeed: cooltime = WorldObj.ReduceEnemySpeedCoolDown; break; case WorldObj.HeroSkill.Disorient: cooltime = WorldObj.DisorientCoolDown; break; case WorldObj.HeroSkill.Encourage: cooltime = WorldObj.EncourageCoolDown; break; case WorldObj.HeroSkill.Silence: cooltime = WorldObj.SilenceCoolDown; break; case WorldObj.HeroSkill.Disease: cooltime = WorldObj.DiseaseCoolDown; break; default: break; } StartCoroutine(HeroSkillCoolDownReady(cooltime)); }
/// <summary> /// 每个城市人口增长 /// 改变城市对象人口属性- population /// </summary> void PopulationIncrease() { //foreach (var item in FindObjectsOfType<CityObj>()) foreach (var item in WorldObj.allCities) { //仅对本国城市人口计算更新 if (item.nationality == nationality) { int cityHighestPolitics = 0; //城市最高的英雄政治 for (int i = 0; i < item.heros.Count; i++) { int heroPolitics = WorldObj.MatchHero(item.heros[i]).politics; if (heroPolitics > cityHighestPolitics) { cityHighestPolitics = heroPolitics; } } item.UpdatePopulation(WorldObj.calculatePopulationIncrease(item.population, cityHighestPolitics, taxrate)); } } }
/// <summary> /// 加载队伍数据到队伍面板 /// </summary> void LoadTeamDataToTeamPanel() { teamInfoText.color = Color.yellow; teamInfoText.text = "英雄:" + teamObj.hero + " 兵种:" + WorldObj.SoldierTypeDictionary[teamObj.soldiertype] + "\r\n" + "士兵数量:" + teamObj.soldiernumber + " 军心:" + teamObj.teammorale; //WordObj teamHeroWord = WorldObj.MatchWord(teamObj.hero); //heroInfoButton.image.sprite = teamHeroWord.sprite; HeroObj teamHero = WorldObj.MatchHero(teamObj.hero); Text skillButtonText = heroSkillButton.transform.Find("Text").GetComponent <Text>(); switch (teamObj.soldiertype) { case WorldObj.SoldierType.none: case WorldObj.SoldierType.SwordMan: case WorldObj.SoldierType.Archer: case WorldObj.SoldierType.Cavalry: skillButtonText.text = WorldObj.HeroSkillDictionary[teamHero.heroskill]; break; case WorldObj.SoldierType.Tank: skillButtonText.text = "停用"; break; case WorldObj.SoldierType.Worker: skillButtonText.text = "建造"; break; case WorldObj.SoldierType.Griffin: break; default: break; } heroSkillButton.transform.Find("Text").GetComponent <Text>().color = Color.red; }
void Start() { //确定所在国籍 selfCountry = WorldObj.SelfCountry(); }
void Update() { if (!photonView.isMine) { return; } //测试用代码 if (Input.GetMouseButtonDown(1)) { } //鼠标或触摸屏的输入操作 if (Input.GetMouseButtonDown(0) || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { Vector3 pos; if (Input.GetMouseButtonDown(0)) { pos = Input.mousePosition; } else { pos = Input.GetTouch(0).deltaPosition; } //从摄像头发送射线指定屏幕位置到场景位置 RaycastHit hit = Funcs.RayScreenPoint(playercamera, pos); if (!hit.collider) { Debug.Log("未点击到任何物体!"); return; } Transform obj = hit.collider.transform; //如果UI没有在运行 if (!WorldObj.UIRun) { //摄像头移动的操作 if (!teamSelected && obj.parent && !obj.parent.GetComponent <TeamObj>() && (pos.x < Screen.width / 4 || pos.x > Screen.width * 3 / 4)) // || pos.y < Screen.height / 3 || pos.y > Screen.height * 2 / 3)) { float newx = (pos.x - Screen.width / 2) / 100f; //float newy = (pos.y - Screen.height / 2) / 100f; if (obj) { newx = hit.point.x; } //如果没到左右边界,或者到了左右边界但点击的位置不会让摄像头移出边界,则赋值新目标位置cameraNewPosition if (Mathf.Abs(playercamera.position.x) >= (Ground.localScale.x * 10 / 2 - Screen.width / 2 / screenSizeCoefficient)) { if (Mathf.Abs(newx) < Mathf.Abs(playercamera.position.x)) { cameraNewPosition = new Vector3(newx, playercamera.position.y, playercamera.position.z); //newy); } } else { cameraNewPosition = new Vector3(newx, playercamera.position.y, playercamera.position.z); //newy); } } else { cameraNewPosition = playercamera.position; } //如果点到城市并且没有事先选择队伍 if (!teamSelected && obj.parent && obj.parent.GetComponent <CityObj>()) { CityObj aCity = obj.parent.GetComponent <CityObj>(); if (aCity.nationality == nationality && !aCity.fighting) { //teamController.CityGetSpotlight(aCity); //城市获得聚光灯 cityController.cityObj = aCity; cityController.CityMenu(); } } //如果点到队伍并且没有事先选择队伍 else if (!teamSelected && obj.parent && obj.parent.GetComponent <TeamObj>()) { selectedTeam = obj.parent.GetComponent <TeamObj>(); //如果是敌对队伍或带队英雄被沉默,则队伍不可操作 HeroObj teamHero = WorldObj.MatchHero(selectedTeam.hero); if (selectedTeam.nationality != nationality || (!teamHero || teamHero.heroskill == WorldObj.HeroSkill.none) || selectedTeam.hero == "") { return; } teamController.teamObj = selectedTeam; //打开信息提示,使已选择标志为真 teamController.TeamHint(); teamSelected = true; } //如果点到城市并且事先选择了队伍 else if (teamSelected && obj.parent && obj.parent.GetComponent <CityObj>()) { if (teamController.clickSkill) { return; } if (selectedTeam) { selectedTeam.targetCity = obj.parent.GetComponent <CityObj>(); selectedTeam.targetTeam = null; } teamController.TeamToCity(obj.parent.GetComponent <CityObj>()); //关闭信息提示,使已选择标志为假 teamSelected = false; teamController.TeamHintClose(); } //如果点到队伍并且事先选择了队伍 else if (teamSelected && obj.parent && obj.parent.GetComponent <TeamObj>()) { if (selectedTeam && obj.parent.GetComponent <TeamObj>() != selectedTeam) { selectedTeam.targetTeam = obj.parent.GetComponent <TeamObj>(); selectedTeam.targetCity = null; } //teamController.GoToPosition(hit.point); /* * switch (selectedTeam.soldiertype) * { * case WorldObj.SoldierType.SwordMan: * case WorldObj.SoldierType.Archer: * case WorldObj.SoldierType.Cavalry: * case WorldObj.SoldierType.Tank: * teamController.GoToPosition(hit.point); * * break; * //是工程兵则走到指定位置开始建造 * case WorldObj.SoldierType.Worker: * teamController.GoAndBuild(hit.point); * break; * case WorldObj.SoldierType.Griffin: * break; * default: * break; * } */ switch (selectedTeam.soldiertype) { case WorldObj.SoldierType.SwordMan: case WorldObj.SoldierType.Archer: case WorldObj.SoldierType.Cavalry: case WorldObj.SoldierType.Tank: case WorldObj.SoldierType.Worker: if (!teamController.clickSkill) { teamController.TeamToTeam(obj.parent.GetComponent <TeamObj>()); } break; case WorldObj.SoldierType.Griffin: break; default: break; } teamSelected = false; //使用英雄技能 TeamObj objTeam = obj.parent.GetComponent <TeamObj>(); teamController.HeroUseSkill(objTeam); teamController.TeamHintClose(); } //如果点到地上并且事先选择了队伍 else if (teamSelected && obj && obj == Ground) { if (selectedTeam) { selectedTeam.targetTeam = null; selectedTeam.targetCity = null; } switch (selectedTeam.soldiertype) { case WorldObj.SoldierType.SwordMan: case WorldObj.SoldierType.Archer: case WorldObj.SoldierType.Cavalry: case WorldObj.SoldierType.Tank: teamController.GoToPosition(hit.point); break; //是工程兵则走到指定位置开始建造 case WorldObj.SoldierType.Worker: teamController.GoAndBuild(hit.point); break; case WorldObj.SoldierType.Griffin: break; default: break; } teamSelected = false; teamController.TeamHintClose(); //如果工兵队发现位置不可建造,则重新选择建造地点 if (reGoBuild) { teamSelected = true; teamController.clickSkill = true; reGoBuild = false; } } //如果点到侦查模型上 else if (obj && obj == teamScout) { teamSelected = false; teamController.TeamHintClose(); //如果有信息来源,则聚光信息来源,摄像头移动到其位置 if (WorldObj.scoutInfoSourceObj) { TeamObj teamInfoSource = WorldObj.scoutInfoSourceObj.GetComponent <TeamObj>(); CityObj cityInfoSource = WorldObj.scoutInfoSourceObj.GetComponent <CityObj>(); if (teamInfoSource) //如果是队伍信息来源 { //teamController.TeamGetSpotlight(teamInfoSource); cameraNewPosition.x = teamInfoSource.transform.position.x; } else if (cityInfoSource) //如果是城市信息来源 { //teamController.CityGetSpotlight(cityInfoSource); cameraNewPosition.x = cityInfoSource.transform.position.x; } } } } } }
/// <summary> /// 英雄使用英雄技 /// </summary> /// <param name="_objTeam">目标队伍</param> public void HeroUseSkill(TeamObj _objTeam) { if (!clickSkill) { return; } clickSkill = false; //如果本队伍是工兵,则不适用英雄技 if (teamObj.soldiertype == WorldObj.SoldierType.Worker || teamObj.soldiertype == WorldObj.SoldierType.Tank) { return; } //判断目标队伍距离 if (Vector3.Distance(_objTeam.transform.position, teamObj.transform.position) > WorldObj.SkillDistance) { return; } switch (WorldObj.MatchHero(teamObj.hero).heroskill) { case WorldObj.HeroSkill.none: break; case WorldObj.HeroSkill.IncreaseOwnSpeed: if (_objTeam.nationality == countryObj.nationality) { //急行军倒计时,计时完毕恢复初始速度 _objTeam.UpdateTeamNAVSpeed(WorldObj.IncreaseOwnSpeedCoefficient * _objTeam.GetComponent <NavMeshAgent>().speed); StartCoroutine(TeamSpeedCountDownRestore(WorldObj.IncreaseOwnSpeedTime, _objTeam)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; case WorldObj.HeroSkill.ReduceEnemySpeed: if (_objTeam.nationality != countryObj.nationality) { //缓慢倒计时,计时完毕恢复初始速度 _objTeam.UpdateTeamNAVSpeed(WorldObj.ReduceEnemySpeedCoefficient * _objTeam.GetComponent <NavMeshAgent>().speed); StartCoroutine(TeamSpeedCountDownRestore(WorldObj.ReduceEnemySpeedTime, _objTeam)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; case WorldObj.HeroSkill.Disorient: if (_objTeam.nationality != countryObj.nationality) { //迷惑减低军心 _objTeam.UpdateTeamMorale(Mathf.RoundToInt(WorldObj.DisorientCoefficient * _objTeam.GetComponent <TeamObj>().teammorale)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; case WorldObj.HeroSkill.Encourage: if (_objTeam.nationality == countryObj.nationality) { //鼓舞提升军心 _objTeam.UpdateTeamMorale(Mathf.RoundToInt(WorldObj.EncourageCoefficient * _objTeam.GetComponent <TeamObj>().teammorale)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; case WorldObj.HeroSkill.Silence: if (_objTeam.nationality != countryObj.nationality) { //保存原技能 HeroObj objHero = WorldObj.MatchHero(_objTeam.hero); WorldObj.HeroSkill originalSkill = objHero.heroskill; //沉默对手 objHero.GiveHeroSkill(WorldObj.HeroSkill.none); //计时结束后恢复对手 StartCoroutine(HeroSkillSilenceCountDownRestore(WorldObj.SilenceTime, objHero, originalSkill)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; case WorldObj.HeroSkill.Disease: if (_objTeam.nationality != countryObj.nationality) { //瘟疫降低敌方队伍人数 _objTeam.UpdateSoldierNumber(Mathf.RoundToInt(WorldObj.DiseaseCoefficient * _objTeam.GetComponent <TeamObj>().soldiernumber)); // 英雄技能进入冷却 HeroSkillCoolDown(); } break; default: break; } }