public PlanCourse(List <UnitStar> nodeList, int originID) { this.htPassedPath = new Hashtable(); UnitStar originNode = null; foreach (UnitStar node in nodeList) { if (node.UnitId == originID) { originNode = node; } else { PassedPath pPath = new PassedPath(node.UnitId); this.htPassedPath.Add(node.UnitId, pPath);//保存源节点跟其他节点的路径 } } if (originNode == null) { throw new Exception("The origin node is not exist !"); } this.InitializeWeight(originNode); }
/// <summary> /// 集合继承 /// </summary> private int TogetherExtends(UnitStar firstStar) { List <int> _listStarId = new List <int>(); int nowStarId = firstStar.UnitId; _listStarId.Add(firstStar.UnitId); while (true) { UnitStar _nowStar = GetUnitStarById(nowStarId); if (_nowStar.TogetherId < 0) {//没下个集合点 return(_nowStar.UnitId); } UnitStar _nextStar = GetUnitStarById(_nowStar.TogetherId); if (_nextStar.BelongTo != null && _nextStar.BelongTo.ID != _nowStar.BelongTo.ID) {//下个集合点不属于玩家 return(_nowStar.UnitId); } if (_listStarId.Contains(_nowStar.TogetherId)) {//下个集合点 有 环 return(_nowStar.UnitId); } _listStarId.Add(_nowStar.TogetherId); nowStarId = _nowStar.TogetherId; } }
public void PlayerAttackStar(uint attackPlayerId, uint starBelongPlayerId, int StarId, int energy) { UnitStar _star = GetUnitStarById(StarId); if (_star == null) { return; } //LoggerHelper.Error("attackPlayerId:" + attackPlayerId + "_star.BelongTo.ID:" + _star.BelongTo.ID); //自己攻击自己星球 if ((_star.BelongTo != null) && (attackPlayerId == _star.BelongTo.ID)) { return; } //LoggerHelper.Error("_star.CurEnergy:" + _star.CurEnergy + " energy:" + energy); _star.CurEnergy -= energy; if (_star.CurEnergy <= 0) { MogoWorld.thePlayer.RpcCall("UpdateStarBelongTo", attackPlayerId, StarId); } ShowFloatText(string.Concat(-energy), _star.PositionX, _star.PositionY, 1); if (CurStarID == StarId)//是当前星球,显示能量减少的过程 { UIManager.I.GetUILogic <StarInfoUIMgr>().SetStarEnergy(_star.CurEnergy); if (_star.CurEnergy <= 0) { UIManager.I.GetUILogic <StarInfoUIMgr>().SetStarEnergy(_star.BaseData.energy); } } }
public void SetStatus() { UnitStar star = MogoWorld.m_dataMapManager.GetUnitStarById(MogoWorld.m_dataMapManager.CurStarID); UnitSoldier soldier; UILabel numTxt; MogoUIBtn soldierBtn; foreach (SoldierData data in SoldierData.dataMap.Values) { soldier = star.GetSoldierById(MogoWorld.thePlayer.ID, data.id); soldierBtn = GetSoldierBtn(data.id); numTxt = soldierBtn.transform.FindChild("NumText").gameObject.GetComponent <UILabel>(); if (soldier != null)//当前有这种士兵 { soldierBtn.IsEnabled = true; SetSelectSign(soldierBtn, true); StarInfoController.getInstance().FightSoldierIdList.Add(data.id); numTxt.text = ((int)(soldier.GetSoldierNum() * (1 - StarInfoController.getInstance().soldierNumPercent))).ToString(); } else { soldierBtn.IsEnabled = false; SetSelectSign(soldierBtn, false); numTxt.text = ""; } } }
private void SetOtherAndNonStar() { if (AttackStatus == AttackStatusType.DisPatch || AttackStatus == AttackStatusType.Gather) //准备攻击,点了下一个星球 { if (curStar.CheckStarReachByRangle(clickStar) == false && IsOpenRangleCheck) //暂时去掉,给战斗测试 { ShowAttackOkBtn(false); ShowReconSoldierBtn(false); } else { ShowAttackOkBtn(true); ShowReconSoldierBtn(true); } SetAttackAndgatherStatus(); } else//展示未开发星球信息 { curStar = clickStar; MogoWorld.m_dataMapManager.CurStarID = clickStar.UnitId; StarNameTxt.gameObject.SetActive(true); StarNameTxt.text = LanguageData.GetContent(168); HideAllInfo(); curSoldierEnergy = curStar.GetSoldierEnergy(); if (curSoldierEnergy > 0) { ShowBuildings(true); } } }
public void QuicklyAttackTargetStar(UnitStar _beginStar, UnitStar _endStar) { beginStar = _beginStar; endStar = _endStar; List <UnitStar> starList = MogoWorld.m_dataMapManager.GetStarList(); foreach (UnitStar star in starList) { star.MovingRange.SetActive(false); star.SelectSign.SetActive(false); } if (m_starInfoUIMgr.bShow) { m_starInfoUIMgr.Close(); } m_starInfoUIMgr.curStar = beginStar; m_starInfoUIMgr.targetStar = endStar; m_starInfoUIMgr.AttackStatus = AttackStatusType.DisPatch;//准备攻击状态 beginStar.m_currentTargetStar = null; MogoWorld.m_dataMapManager.CurStarID = beginStar.UnitId; UIManager.I.ShowUI <ComfirmUIMgr>(ShowComfirmUI); UIManager.I.ShowUI <SoldierFightUIMgr>(); }
/// <summary> /// 星球是否开始战争 /// </summary> /// <param name="_star"></param> public void StarOrEndStartFighting(UnitStar _star) { if (WarOfStarDic.ContainsKey(_star.UnitId)) { //结束战斗 if (!_star.HasOtherSoldier()) { WarOfStarDic.Remove(_star.UnitId); WarOfStarList.Remove(_star); MogoWorld.thePlayer.RpcCall("ArrayedSoldier", _star.UnitId, 2); } } else { //LoggerHelper.Debug("主角的星球上:" + _star.UnitId); //在主角的星球上存在多个阵营的士兵 if (_star.HasOtherSoldier()) { WarOfStarDic.Add(_star.UnitId, _star); WarOfStarList.Add(_star); //LoggerHelper.Debug("WarOfStarDic:" + WarOfStarDic.Count + "WarOfStarList:" + WarOfStarList.Count); MogoWorld.thePlayer.RpcCall("ArrayedSoldier", _star.UnitId, 1); } } }
public void StarBelong(uint _playerId, int _starId) { UnitStar _star = GetUnitStarById(_starId); _star.BelongTo = MogoWorld.GetEntityById(_playerId); _star.SetGroup(GetGroupByPalyerId(_playerId));//设置阵营信息 }
private void OnAddSoldier() { if (bShow == false) { return; } UnitStar curStar = MogoWorld.m_dataMapManager.GetUnitStarById(MogoWorld.m_dataMapManager.CurStarID); UnitSoldier soldier; MogoUIBtn btn; UILabel numTxt; foreach (SoldierData data in SoldierData.dataMap.Values) { soldier = curStar.GetSoldierById(MogoWorld.thePlayer.ID, data.id); if (soldier != null) { int num = soldier.GetSoldierNum(); if (num > 0) { btn = GetSoldierBtn(data.id); numTxt = btn.transform.FindChild("NumText").gameObject.GetComponent <UILabel>(); numTxt.text = ((int)(num * (1 - StarInfoController.getInstance().soldierNumPercent))).ToString(); } } } }
//从PlanCourse取出一个当前累积权值最小,并且没有被处理过的节点 private UnitStar GetMinWeightRudeNode(PlanCourse planCourse, List <UnitStar> nodeList, int originID) { double weight = double.MaxValue; UnitStar destNode = null; foreach (UnitStar node in nodeList) { if (node.UnitId == originID) { continue; } PassedPath pPath = planCourse[node.UnitId]; if (pPath.BeProcessed) { continue; } if (pPath.Weight < weight) { weight = pPath.Weight; destNode = node; } } return(destNode); }
public void MoveToNextStar() { if ((m_iCurMoveStep + 1) < m_listMovePath.PassedStars.Count) { UnitStar _startStar = m_listMovePath.PassedStars[m_iCurMoveStep]; UnitStar _endStar = m_listMovePath.PassedStars[m_iCurMoveStep + 1]; float distace = Vector2.Distance(new Vector2(_startStar.PositionX, _startStar.PositionY), new Vector2(_endStar.PositionX, _endStar.PositionY)); m_fMoveTime = distace / BaseSoldierData.move; Move(_endStar.PositionX, _endStar.PositionY, m_fMoveTime - 0.01f); if (BelongTo.ID != MogoWorld.thePlayer.ID) { ShowUnit(_endStar.IsExplore); } } else { if (BelongTo.ID == MogoWorld.thePlayer.ID) { MogoWorld.thePlayer.RpcCall("AddSoldier", BelongTo.ID, m_listMovePath.PassedStars[m_iCurMoveStep].UnitId, BaseSoldierData.id, CurEnergy, 0); } m_fMoveTime = 1000; m_listMovePath = null; ClearUnit(); MogoWorld.m_dataMapManager.RemoveArrivedSoldier(this); } }
public double GetTargetStarDistance(UnitStar targetStar) { if (!starDistance.ContainsKey(targetStar.UnitId)) { starDistance[targetStar.UnitId] = Mathf.Sqrt(Mathf.Pow(PositionX - targetStar.PositionX, 2) + Mathf.Pow(PositionY - targetStar.PositionY, 2)); } return(starDistance[targetStar.UnitId]); }
private void UpdateArrow(GameObject go, Vector3 delta, Vector3 currentPos) { if (!m_isExploxe) { return; //还未探索,不做操作 } m_totalDelta += delta; var pos = go.transform.position; var targetPos = pos + m_totalDelta; if (m_movingDrawArrow) { m_movingDrawArrow.SetSourcePos(pos); if (m_currentTargetStar != null)//如果缓存的目标星球不为空,则每帧检测有没有拖出范围,保证效果 { var starPos = m_currentTargetStar.UnitGO.transform.position; if (Vector3.Distance(targetPos, starPos) < m_currentTargetStar.BaseData.radius * 1.5) { return; } } if (Time.time - m_totleDeltaTime > 0.2f)//隔固定时间检测有没有箭头顶点有没有在可达星球范围内 { m_totleDeltaTime = Time.time; for (int i = 0; i < MogoWorld.m_dataMapManager.ReachStarList.Count; i++) { var star = MogoWorld.m_dataMapManager.ReachStarList[i]; if (star == this) { continue; } var starPos = star.UnitGO.transform.position; //Debug.Log(Vector3.Distance(targetPos, starPos)); if (Vector3.Distance(targetPos, starPos) < star.BaseData.radius * 1.5) { m_currentPath = MapUtil.Plan(this, star).PassedStars; m_currentTargetStar = star; DrawAllPathLine(); return; } } } //都没有就跟着移动坐标画 m_movingDrawArrow.DrawArrowToTargetPoint(targetPos); m_currentTargetStar = null; HideOtherLines(); //var cam = UIManager.I.GetUILogic<MapUIMgr>().MyCameraController; ////cam.transform.localPosition -= delta; //TweenPosition.Begin(cam.gameObject, 0.2f, new Vector3(-targetPos.x, -targetPos.y, 0)); m_starInfoUIMgr.ShowOwnerRangle(true, true); } }
/// <summary> /// 通过多个星球移动范围检查节点是否能到达目标节点(是否可连通) /// </summary> /// <param name="targetNode"></param> /// <returns></returns> public bool CheckStarReachByRangle(UnitStar targetStar) { if (MogoWorld.m_dataMapManager.ReachStarList.IndexOf(targetStar) != -1) { return(true); } return(false); }
public void DrawLineToStar(UnitStar target) { if (m_movingDrawArrow) { MovingArrow.SetActive(true); m_movingDrawArrow.SetSourcePos(UnitGO.transform.position); m_movingDrawArrow.DrawLineToTargetPoint(target.UnitGO.transform.position); } }
/// <summary> /// 更新星球归属 /// </summary> /// <param name="playerId"></param> /// <param name="starId"></param> public void UpdateStarBelongTo(uint playerId, int starId) { //Debug.Log("playerId:" + playerId + " starId:" + starId); UnitStar updateStar = GetUnitStarById(starId); bool _isOccupy = false; if (updateStar.BelongTo != null && updateStar.BelongTo.ID != playerId && playerId == MogoWorld.thePlayer.ID) { //LoggerHelper.Error("ddd"); _isOccupy = true; } GroupData data = GetGroupByPalyerId(playerId);//先设置阵营信息 updateStar.SetGroup(data); if (MogoWorld.thePlayer.ID == playerId) { SoundManager.PlaySound("tree grow 1.ogg"); updateStar.BelongTo = MogoWorld.thePlayer; if (CurStarID == starId) { EventDispatcher.TriggerEvent(Events.StarUIEvent.AddBuildingEvent); //发送我方当前星球添加建筑的消息 } foreach (UnitStar star in m_starDataManager.StarList) //添加我方星球移动范围 { if (updateStar.CheckStarReachByDistance(star) == true && ReachStarList.IndexOf(star) == -1) { ReachStarList.Add(star); } } } else { if (updateStar.BelongTo != null && updateStar.BelongTo.ID == MogoWorld.thePlayer.ID)//之前是我方星球,被攻占了 { RemoveStarRangle(updateStar); } updateStar.BelongTo = MogoWorld.Entities.Get(playerId); } //攻占成功 if (AttackStar.Contains(updateStar)) { if (!updateStar.IsInAttackStar()) { AttackStar.Remove(updateStar); } } if (_isOccupy)//占领成功 自动送一个建筑 { //updateStar.CurEnergy = updateStar.BaseData.energy / 2; //LoggerHelper.Error("占领成功 自动送一个建筑"); //MogoWorld.thePlayer.RpcCall("AddBuilding", playerId, starId, 1, 100);//key为建筑类型 updateStar.RecoveryBuilding(); } }
public void DrawArrowToStar(UnitStar target) { if (m_movingDrawArrow) { MovingArrow.SetActive(true); m_movingDrawArrow.SetSourcePos(UnitGO.transform.position); m_movingDrawArrow.DrawArrowToTargetCircle(target.BaseData.radius, target.UnitGO.transform.position); } }
/// <summary> /// 对星球增加建筑 /// </summary> /// <param name="_starID"></param> /// <param name="_buildingTime"></param> public void addBuildingToStar(uint dbid, int _starID, int _buildingType, int finishPercentage) { //LoggerHelper.Error("dbid:" + dbid); UnitStar _star = GetUnitStarById(_starID); if (_star.BelongTo != null && _star.BelongTo.ID != dbid) { LoggerHelper.Error("星球和建筑主人不对"); return; } //是否是升级建筑 int _index = _star.IsLevelUpBuilding(_buildingType); if (_index >= 0) { _star.RemoveBuilding(_index, _star.GetBuildingByIndex(_index)); } else {//新建建筑 _index = _star.GetAddBuildingIndex(); if (_index >= 0) { _star.AddBuildingLog(_buildingType); } } if (_index < 0) { return; } UnitBuilding _building = GetUnitBuildingFromPool(); Vector2 _pos = _star.GetAddBuildingPos(_index); if (_index >= 0) { _building.UnitId = _star.UnitId * 100 + _index; _building.BaseBuildingData = BuildingData.dataMap.Get(_buildingType); _building.PositionX = _pos.x; _building.PositionY = _pos.y; _building.UnitParent = BuildLayer; _building.InitPercentage = finishPercentage; _building.BelongToStar = _star; _building.AttackPlayerId = dbid; _building.InitUnit(); _building.SetGroup(GetGroupByPalyerId(dbid));//设置阵营信息 _star.AddBuilding(_index, _building); if (_starID == CurStarID)//根据当前准备建设的建筑来刷新战斗UI { UIManager.I.GetUILogic <StarInfoUIMgr>().ShowBuildings(true); } } m_starDataManager.StarOrEndStartFighting(_star); }
/// <summary> /// 移动镜头到自己星球总部 /// </summary> private void MoveCamera() { UnitStar headStar = MogoWorld.m_dataMapManager.GetUnitStarById(MogoWorld.thePlayer.HeadQuarterId); m_BattleUIPanel.localPosition = new Vector3(-headStar.PositionX, -headStar.PositionY, 0); //GameObject camera = m_myGameObject.transform.parent.parent.FindChild("Camera").gameObject; //Vector3 pos = new Vector3(headStar.PositionX, headStar.PositionY, 0); //camera.transform.localPosition = pos; //m_myGameObject.transform.FindChild("Bg").localPosition = pos; }
private void SetAttackAndgatherStatus() { clickStar.MovingRange.SetActive(false); ShowOwnerRangle(true); targetStar = clickStar; curStar.HideAllLine();//先全部隐藏 curStar.SetCurrentPath(MapUtil.Plan(curStar, targetStar).PassedStars); curStar.DrawAllPathLine(); UIManager.I.GetUILogic <MapUIMgr>().MyCameraController.MoveTo(new Vector3(-targetStar.PositionX, -targetStar.PositionY, 0)); //TweenPosition.Begin(cam.gameObject, 0.2f, new Vector3(-targetStar.PositionX, -targetStar.PositionY, 0)); }
/// <summary> /// 检查节点是否能到达目标节点(是否可连通) /// </summary> /// <param name="targetNode"></param> /// <returns></returns> public bool CheckStarReachByDistance(UnitStar targetStar) { bool canReach = false; double dis = GetTargetStarDistance(targetStar); if (dis <= BaseData.radius + BaseData.range + targetStar.BaseData.radius) { canReach = true; } return(canReach); }
public void HideUI() { Close(); ShowOwnerRangle(false); if (curStar != null) { curStar.MovingRange.SetActive(false); curStar.SelectSign.SetActive(false); curStar.HideAllLine(); curStar = null; } }
/// <summary> /// 攻击 建筑 /// </summary> /// <param name="_starID"></param> /// <param name="_buildingTime"></param> public void AttackBuilding(uint _attackplayerId, int _starID, int buildingPosition, int _Energy) { UnitStar _star = GetUnitStarById(_starID); UnitBuilding _building = _star.GetBuildingByIndex(buildingPosition); //LoggerHelper.Error("_building.BelongToStar.BelongTo.ID:" + _building.BelongToStar.BelongTo.ID + "_Energy:" + _Energy); if (_building != null) { //被攻击建筑所属 if ((_building.BelongToStar != null) && (_building.BelongToStar.BelongTo != null) && (_building.BelongToStar.BelongTo.ID == _attackplayerId)) { return; } _building.ReduceBuildingEnergy(_Energy); ShowFloatText(string.Concat(-_Energy), _building.PositionX, _building.PositionY, _building.BaseBuildingData.float_color); if (_building.CurEnergy <= 0) { _building.OnDead(); } else { _building.OnHit(); } } else { //LoggerHelper.Debug("没有该类建筑"); return; } //LoggerHelper.Error("_attackplayerId:" + _attackplayerId + "_building.CurEnergy:" + _building.CurEnergy); if (_building.CurEnergy <= 0) { //LoggerHelper.Error("_building.CurEnergy:" + _building.CurEnergy); _star.RemoveBuilding(buildingPosition, _building); //拆一个建筑后就可以占领星球 /*if (!AttackStar.Contains(_star)) * { * if (_star.IsInAttackStar()) * { * AttackStar.Add(_star); * } * }*/ IsAttackStar(_star); } _star.showAttackBuildingEffect(_building.UnitGO.transform.localPosition); }
/// <summary> /// 创建星球(此方法还没初始化星球数据和它跟其他星球的有向边) /// </summary> /// <returns></returns> public UnitStar CreateStar() { foreach (UnitStar _star in m_StarList) { if (_star.UnitId == -1) { return(_star); } } UnitStar _newStar = new UnitStar(); m_StarList.Add(_newStar); return(_newStar); }
/// <summary> /// 对星球增加士兵 /// </summary> /// <param name="_starID"></param> /// <param name="_buildingTime"></param> public void addSoldierToStar(uint _playerId, int _starID, int _soldierType, int _Energy, int _isSelfProduce, bool _isMoveAnimation = true) { UnitStar _star = GetUnitStarById(_starID); UnitSoldier _Soldier = _star.GetSoldierById(_playerId, _soldierType); if (_star.BelongTo != null && _star.BelongTo.ID == MogoWorld.thePlayer.ID && _starID == CurStarID) { EventDispatcher.TriggerEvent(Events.StarUIEvent.AddSoldierEvent);//发送我方当前星球添加兵力的消息 } if (_Soldier != null) { _Soldier.AddSoldier(_Energy, _isSelfProduce); _star.CulAllSoldierAttack(); if (_isMoveAnimation && (_Soldier.GetGatherSoldierNum() > 0)) { m_starDataManager.StarTogether(_star); } m_starDataManager.StarOrEndStartFighting(_star); return; } _Soldier = GetUnitSoldierFromPool(); SoldierIndex++; _Soldier.UnitId = SoldierIndex; _Soldier.BelongTo = MogoWorld.GetEntityById(_playerId); _Soldier.BaseSoldierData = SoldierData.dataMap.Get(_soldierType); Vector2 _pos = _star.GetSoliderPositionById(_soldierType); //LoggerHelper.Error("_pos.x:" + _pos.x + "_pos.y:" + _pos.y); _Soldier.PositionX = _pos.x; _Soldier.PositionY = _pos.y; _Soldier.UnitParent = SoldierLyaer; _Soldier.AddSoldier(_Energy, _isSelfProduce); _Soldier.BelongToStar = _star; _Soldier.IsMoveAnimation = _isMoveAnimation; _Soldier.InitUnit(); _Soldier.SetGroup(GetGroupByPalyerId(_playerId));//设置阵营信息 _star.AddSoldier(_playerId, _soldierType, _Soldier); _star.CulAllSoldierAttack(); m_starDataManager.StarOrEndStartFighting(_star); if (_isMoveAnimation && (_Soldier.GetGatherSoldierNum() > 0)) { m_starDataManager.StarTogether(_star); //_Soldier.CallBack = SoldierCallback; } IsAttackStar(_star); }
public void StarTogether(UnitStar _star) { //检查是否要集合 if ((_star.TogetherId != -1) && (_star.BelongTo.ID == MogoWorld.thePlayer.ID)) { List <int> fightSoliderIdList = StarInfoController.getInstance().GetStarFightSoliderIdList(_star); int _nextTogetherId = TogetherExtends(_star); LuaTable lt = StarInfoController.getInstance().MoveSoldierToLuaTable(MogoWorld.thePlayer.ID, _star.UnitId, _nextTogetherId, 1, 0, fightSoliderIdList); MogoWorld.thePlayer.RpcCall("MoveSoldier", lt); } }
/// <summary> /// 获取星球可出战士兵id /// </summary> /// <param name="star"></param> /// <returns></returns> public List <int> GetStarFightSoliderIdList(UnitStar star) { List <int> fightSoldierIdList = new List <int>(); UnitSoldier soldier; foreach (SoldierData data in SoldierData.dataMap.Values) { soldier = star.GetSoldierById(MogoWorld.thePlayer.ID, data.id); if (soldier != null)//当前有这种士兵 { fightSoldierIdList.Add(data.id); } } return(fightSoldierIdList); }
public void SetAggregateSoldier() { UnitStar star = MogoWorld.m_dataMapManager.GetUnitStarById(MogoWorld.m_dataMapManager.CurStarID); UnitSoldier soldier; StarInfoController.getInstance().FightSoldierIdList.Clear(); foreach (SoldierData data in SoldierData.dataMap.Values) { soldier = star.GetSoldierById(MogoWorld.thePlayer.ID, data.id); if (soldier != null)//当前有这种士兵 { StarInfoController.getInstance().FightSoldierIdList.Add(data.id); } } }
/// <summary> /// 1 开始战斗 2结束战斗 /// </summary> /// <param name="starid"></param> /// <param name="type"></param> public void ArrayedSoldier(int starid, int type) { UnitStar _star = GetUnitStarById(starid); switch (type) { case 1: _star.ArrayedSoldier(); break; case 2: _star.HomePosition(); break; } }
public void InitStarData(int _index, int _starId, float _PosX, float _PosY, Transform _parent, Action _callBack) { if (_index >= m_StarList.Count) { m_StarList.Add(new UnitStar()); } UnitStar _unitStar = m_StarList[_index]; _unitStar.UnitId = _index; _unitStar.BaseData = StarData.dataMap.Get(_starId); _unitStar.PositionX = _PosX; _unitStar.PositionY = _PosY; _unitStar.UnitParent = _parent; _unitStar.CallBack = _callBack; _unitStar.InitUnit(); }