/// <summary> /// 选择规则:以积分低的士兵优先,若积分相等的再以建筑消耗优先级高的优先 /// </summary> /// <param name="_listSoldierIds"></param> /// <returns></returns> private List <int> SortReconSoldier(List <int> _listSoldierIds) { UnitSoldier _ReconSoldier = null; UnitSoldier _TempSoldier = null; for (int i = 0; i < _listSoldierIds.Count; i++) { if (_ReconSoldier == null) { _ReconSoldier = m_starInfoUIMgr.curStar.GetSoldierById(MogoWorld.thePlayer.ID, _listSoldierIds[i]); } else { _TempSoldier = m_starInfoUIMgr.curStar.GetSoldierById(MogoWorld.thePlayer.ID, _listSoldierIds[i]); if (_TempSoldier.BaseSoldierData.score < _ReconSoldier.BaseSoldierData.score)//优先传送分数低的士兵 { _ReconSoldier = _TempSoldier; } else if (_TempSoldier.BaseSoldierData.score == _ReconSoldier.BaseSoldierData.score)//若积分相等的再以建筑消耗优先级高的优先 { if (_TempSoldier.BaseSoldierData.building_priority > _ReconSoldier.BaseSoldierData.building_priority) { _ReconSoldier = _TempSoldier; } } } } //LoggerHelper.Error("_ReconSoldier.BaseSoldierData.id:" + _ReconSoldier.BaseSoldierData.id); var _list = new List <int>(); _list.Add(_ReconSoldier.BaseSoldierData.id); return(_list); }
public void RemoveArrivedSoldier(UnitSoldier _soldier) { if (MoveSoldierList.Contains(_soldier)) { MoveSoldierList.Remove(_soldier); _soldier.ClearUnit(); } }
public void RemoveToCurrentSoldier(UnitSoldier soldier) { if (currentSoldiers.Contains(soldier)) { currentSoldiers.Remove(soldier); } UpdateresourcesGame(); }
public void AddToCurrentSoldier(UnitSoldier soldier) { if (!currentSoldiers.Contains(soldier)) { currentSoldiers.Add(soldier); } UpdateresourcesGame(); }
public void AddSoldier(uint _playerId, int _soldierType, UnitSoldier _soldier) { //第一个到达 if ((m_iFirstArried <= 0) && (SoldierDic.Count <= 0)) { m_iFirstArried = _playerId; } if (!SoldierDic.ContainsKey(_playerId)) { SoldierDic[_playerId] = new Dictionary <int, UnitSoldier>(); } //LoggerHelper.Error("m_isExploxe:" + m_isExploxe); _soldier.ShowUnit(m_isExploxe); SoldierDic[_playerId][_soldierType] = _soldier; /*foreach (var _item in SoldierDic) * { * AttackPriority[_item.Key] = new List<KeyValuePair<int, UnitSoldier>>(_item.Value); * AttackPriority[_item.Key].Sort(delegate(KeyValuePair<int, UnitSoldier> s1, KeyValuePair<int, UnitSoldier> s2) * { return s2.Value.BaseSoldierData.attack_priority.CompareTo(s1.Value.BaseSoldierData.attack_priority); }); * }*/ if (!AttackPriority.ContainsKey(_playerId)) { AttackPriority[_playerId] = new SortedList <int, UnitSoldier>(new DuplicateKeyDescendingComparer <int>()); } if (!AttackPriority[_playerId].ContainsValue(_soldier)) { AttackPriority[_playerId].Add(_soldier.BaseSoldierData.attack_priority, _soldier); } if (!BuildingPriorityList.ContainsKey(_playerId)) { BuildingPriorityList[_playerId] = new SortedList <int, UnitSoldier>(new DuplicateKeyDescendingComparer <int>()); } if (!BuildingPriorityList[_playerId].ContainsValue(_soldier)) { BuildingPriorityList[_playerId].Add(_soldier.BaseSoldierData.building_priority, _soldier); } //LoggerHelper.Debug("UnitId:" + UnitId + "_playerId:" + _playerId + "MogoWorld.thePlayer.ID:" + MogoWorld.thePlayer.ID); //这个星球探索过了 //LoggerHelper.Error("IsExplore:" + IsExplore + " _playerid:" + _playerId + " MogoWorld.thePlayer.ID:" + MogoWorld.thePlayer.ID); if (!IsExplore && (_playerId == MogoWorld.thePlayer.ID)) { IsExplore = true; } //foreach (var _item in BuildingPriorityList[_playerId]) //{ // LoggerHelper.Debug("_key:" + _item.Key); //} }
/// <summary> /// 从对象池取 士兵 /// </summary> /// <returns></returns> private UnitSoldier GetUnitSoldierFromPool() { foreach (UnitSoldier _soldier in m_SoldierList) { if (_soldier.UnitId == -1) { return(_soldier); } } UnitSoldier _newSoldier = new UnitSoldier(); m_SoldierList.Add(_newSoldier); return(_newSoldier); }
/// <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); }
/// <summary> /// 士兵攻击星球 /// </summary> /// <param name="_starID"></param> /// <param name="_buildingTime"></param> public void ShowSoldierIntrusionStar(uint _playerId, int _starID, int _soldierType, int _Energy, float _PositionX, float _PositionY) { UnitStar _star = GetUnitStarById(_starID); UnitSoldier _Soldier = GetUnitSoldierFromPool(); SoldierIndex++; _Soldier.UnitId = SoldierIndex; _Soldier.BelongTo = MogoWorld.GetEntityById(_playerId); _Soldier.BaseSoldierData = SoldierData.dataMap.Get(_soldierType); _Soldier.PositionX = _PositionX; _Soldier.PositionY = _PositionY; _Soldier.UnitParent = SoldierLyaer; _Soldier.AddSoldier(_Energy, 1); _Soldier.BelongToStar = _star; _Soldier.IsMoveAnimation = false; _Soldier.IsShowSoldierIntrusionStar = true; _Soldier.InitUnit(); _Soldier.SetGroup(GetGroupByPalyerId(_playerId));//设置阵营信息 }
/// <summary> /// 发送一个侦察兵 /// </summary> public void SendReconSoldier() { //检查是否选择了出战兵 if (FightSoldierIdList.Count <= 0) { BillboardManager.I.FloatText(LanguageData.GetContent(181), new Vector3(m_starInfoUIMgr.curStar.PositionX, m_starInfoUIMgr.curStar.PositionY, -3), 1.5f); return; } foreach (SoldierData data in SoldierData.dataMap.Values) { UnitSoldier soldier = m_starInfoUIMgr.curStar.GetSoldierById(MogoWorld.thePlayer.ID, data.id); if (soldier != null) { soldierNumPercent = 1 - (float)data.energy / (float)soldier.CurEnergy; break; } soldierNumPercent = 1; } LuaTable lt = MoveSoldierToLuaTable(MogoWorld.thePlayer.ID, m_starInfoUIMgr.curStar.UnitId, m_starInfoUIMgr.targetStar.UnitId, 0, soldierNumPercent, SortReconSoldier(FightSoldierIdList)); MogoWorld.thePlayer.RpcCall("MoveSoldier", lt); }
public UnitSoldier RemoveSoldier(uint _playerId, int _soldierID) { UnitSoldier _soldier = null; if (SoldierDic.ContainsKey(_playerId)) { if (SoldierDic[_playerId].ContainsKey(_soldierID)) { _soldier = SoldierDic[_playerId][_soldierID]; SoldierDic[_playerId].Remove(_soldierID); if (SoldierDic[_playerId].Count <= 0) { SoldierDic.Remove(_playerId); } } } if (AttackPriority.ContainsKey(_playerId)) { int _index = AttackPriority[_playerId].IndexOfValue(_soldier); //LoggerHelper.Error("_playerId:"+_playerId + "_index:" + _index); if (_index >= 0) { AttackPriority[_playerId].RemoveAt(_index); } } if (BuildingPriorityList.ContainsKey(_playerId)) { int _index = BuildingPriorityList[_playerId].IndexOfValue(_soldier); if (_index >= 0) { BuildingPriorityList[_playerId].RemoveAt(_index); } } return(_soldier); }
void Create() { if (controller.CityHallConstruct.createPeasant.t <= 0) { controller.CityHallConstruct.createPeasant.StartCreate(); if (sTarget == "Farm") { if (controller.farmConstructs.Count <= 0) { return; } GameObject g = GameObject.Instantiate(Resources.Load("Soldier/Peasant") as GameObject, controller.CityHallConstruct.posToCreateSoldier.position, Quaternion.identity); soldier = g.GetComponent <UnitSoldier>(); soldier._property.colorTeam = controller.team; soldier.SetColorTeam(); soldier.ActTo(soldier.GetNearestFarmWithVector3(vTarget)); } else if (sTarget == "Tree") { GameObject g = GameObject.Instantiate(Resources.Load("Soldier/Peasant") as GameObject, controller.CityHallConstruct.posToCreateSoldier.position, Quaternion.identity); soldier = g.GetComponent <UnitSoldier>(); soldier._property.colorTeam = controller.team; soldier.SetColorTeam(); soldier.ActTo(soldier.GetNearestTreeWithVector3(vTarget)); } } }
/// <summary> /// 攻击士兵 /// </summary> /// <param name="_starID"></param> /// <param name="_buildingTime"></param> public void AttackSoldier(uint _playerId, int _starID, int _soldierType, int _Energy, int _type) { /*LoggerHelper.Error("_playerId:" + _playerId + "_starID:" + _starID + * "_soldierType:" + _soldierType + "_Energy:" + _Energy );*/ if (_Energy < 0) { _Energy = 0; } UnitStar _star = GetUnitStarById(_starID); UnitSoldier _Soldier = _star.GetSoldierById(_playerId, _soldierType); if (_Soldier != null) { _Soldier.RemoveSoldier(_Energy); //LoggerHelper.Error(_Soldier.BaseSoldierData.energy + " CurEnergy:" + _Soldier.CurEnergy); if (_star.IsExplore && (_Energy >= _Soldier.BaseSoldierData.energy)) { ShowFloatText(string.Concat(-(_Energy / _Soldier.BaseSoldierData.energy)), _Soldier.PositionX, _Soldier.PositionY, _Soldier.BaseSoldierData.float_color); } //LoggerHelper.Error("_playerId:" + _playerId + " _Energy" + (_Energy / _Soldier.BaseSoldierData.energy)); } else { //LoggerHelper.Debug("没有该类士兵"); return; } switch (_type) { //0建筑 1hit 2侵入 case 0: _Soldier.OnIntrusion(_Energy); break; case 1: if (_Soldier.CurEnergy <= 0) { _Soldier.OnDead(); _star.showAttackSoldierEffect(_playerId, _Soldier.UnitGO.transform.localPosition); } else { _Soldier.OnHit(); _star.showAttackSoldierEffect(_playerId, _Soldier.UnitGO.transform.localPosition); } break; case 2: _Soldier.OnIntrusion(_Energy); break; } //type 类型士兵全军覆没 if (_Soldier.CurEnergy <= 0) { _star.RemoveSoldier(_playerId, _soldierType); _Soldier.ClearUnit(); IsAttackStar(_star); } _star.CulAllSoldierAttack(); m_starDataManager.StarOrEndStartFighting(_star); }
private uint CulSoldierAttack(UnitSoldier _soldier) { return((uint)(_soldier.BaseSoldierData.attack * _soldier.GetSoldierNum())); }