コード例 #1
0
    private void OnMoveCompleteEvent(ActorMoveComponent moveComp)
    {
        moveComp.OnMoveCompleteEvent -= OnMoveCompleteEvent;

        //  移动完毕后重新锁定目标
        TryAction();
    }
コード例 #2
0
    /// <summary>
    /// 开始去建造
    /// </summary>
    /// <param name="targeter"></param>
    public void BuildStart(TileEntity targeter)
    {
        Assert.Should(_state == WorkerState.Free || _state == WorkerState.FinishWork);
        Assert.Should(targeter != null);

        this.enabled = true;

        _buildTargeter       = targeter;
        _buildindLastTilePos = new TilePoint(9999, 9999);
        if (_buildArea == null)
        {
            _buildArea = new List <TilePoint>();
        }

        //  当前休息中则从工人小屋出来 回家中则停止移动
        if (_state == WorkerState.Free)
        {
            Entity.tileOffset = new Vector2(0.0f, 0.0f);
            Entity.SetTilePosition(GetDoorOfTheWorkerHouse());
            Entity.ShowEntity();
        }
        else
        {
            ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();
            Assert.Should(move != null);
            move.OnMoveCompleteEvent -= OnMoveCompleteEvent;
            move.CancelMove();
        }
        //  设置上班状态 && 开始移动(3倍速移动)
        RefreshBuildGridArea();
        _state = WorkerState.Working;
        DoActionMove(RandomMoveGrid(IsInBuildArea()), 3.0f);
    }
コード例 #3
0
 private void OnMoveCompleteEvent(ActorMoveComponent moveComp)
 {
     moveComp.OnMoveCompleteEvent -= OnMoveCompleteEvent;
     if (_state == WorkerState.Working)
     {
         //  移动结束如果在建造区域内则开始建造(否则说明建筑移动过了?则继续移动)
         if (IsInBuildArea())
         {
             DoActionBuild();
         }
         else
         {
             DoActionMove(RandomMoveGrid(false));
         }
     }
     else if (_state == WorkerState.FinishWork)
     {
         TilePoint doorPos = GetDoorOfTheWorkerHouse();
         if (Entity.GetTilePos() != doorPos)
         {
             //  回家时(小屋搬家了(233
             DoActionMove(doorPos);
         }
         else
         {
             //  回到家(
             Entity.HideEntity();
             _state       = WorkerState.Free;
             this.enabled = false;
         }
     }
 }
コード例 #4
0
    /// <summary>
    /// 停止移动重新行动
    /// </summary>
    protected virtual void StopMoveAndTryAction()
    {
        ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();

        Assert.Should(move != null);
        move.OnMoveCompleteEvent -= OnMoveCompleteEvent;
        move.CancelMove();

        TryAction();
    }
コード例 #5
0
ファイル: ArmyComponent.cs プロジェクト: boyjimeking/yuanli
    private bool DoActionMove(TilePoint targetPos)
    {
        ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();

        if (move != null)
        {
            if (move.StartMove(targetPos))
            {
                move.OnMoveCompleteEvent += OnMoveCompleteEvent;
                return(true);
            }
        }
        return(false);
    }
コード例 #6
0
    protected virtual bool TryMove(LinkedList <IMoveGrid> moveRoute)
    {
        ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();

        if (move != null)
        {
            if (move.StartMove(moveRoute))
            {
                move.OnMoveCompleteEvent += OnMoveCompleteEvent;
                return(true);
            }
        }
        return(false);
    }
コード例 #7
0
    protected virtual bool TryMove(TilePoint targetPos)
    {
        ActorMoveComponent move = Entity.GetComponent <ActorMoveComponent>();

        if (move != null)
        {
            if (move.StartMove(targetPos, m_tempTargeters))
            {
                move.OnMoveCompleteEvent += OnMoveCompleteEvent;
                return(true);
            }
        }
        return(false);
    }
コード例 #8
0
ファイル: ArmyComponent.cs プロジェクト: boyjimeking/yuanli
    private void OnMoveCompleteEvent(ActorMoveComponent moveComp)
    {
        moveComp.OnMoveCompleteEvent -= OnMoveCompleteEvent;

        if (IsInCamp())
        {
            //  移动结束后在军营内(则待机一会)
            //DoActionIdle(1.0f, 5.0f);
            DoActionIdle(3.0f, 15.0f);  //  TODO:调整为根据总士兵数相关更好,总兵数越多每个的等待时间就可以越长。
        }
        else
        {
            //  移动结束后仍然不在军营内(移动过程中军营搬家了o(╯□╰)o)则继续移动
            TryMove();
        }
    }