Example #1
0
    public void StarBelong(uint _playerId, int _starId)
    {
        UnitStar _star = GetUnitStarById(_starId);

        _star.BelongTo = MogoWorld.GetEntityById(_playerId);
        _star.SetGroup(GetGroupByPalyerId(_playerId));//设置阵营信息
    }
Example #2
0
    /// <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();
        }
    }