Exemplo n.º 1
0
    public bool m_isSwitchForDead = false;//死亡后切换
    //private int m_switchBuffID = 0;
    //切换主控角色
    public bool SwitchMainActor(bool isSwitchForDead, bool isAttacking = false)
    {
        if (m_switchCDTotal > 0 && !MainActor.IsDead)
        {//cd中,并且当前角色未死
            //msg("XXX尚未休整完毕,请稍后再试!");
            return(false);
        }
        if (Deputy == null)
        {//没有可切换的角色
            return(false);
        }
        int curID, lastID;

        if (MainActor == Chief)
        {
            curID  = Deputy.ID;
            lastID = Chief.ID;
        }
        else
        {
            curID  = Chief.ID;
            lastID = Deputy.ID;
        }
        MainPlayer curActor = Lookup(curID) as MainPlayer;

        if (curActor.IsDead)
        {//要切换的角色已经死亡
            return(false);
        }
        MainPlayer lastActor = Lookup(lastID) as MainPlayer;

        // 小地图的点管理 把原来的角色移除
        Map.Singleton.RomvePoint(lastActor);


        //退场角色的信息 begin
        Vector3 lastPos     = lastActor.MainPos;
        Vector3 lastForward = lastActor.MainObj.transform.forward;
        Vector3 targetPos   = Vector3.zero;

        if (!isAttacking)
        {
            if (lastActor.ActionControl.IsActionRunning(ActorAction.ENType.enMoveAction))
            {//move action
                MoveAction action = lastActor.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction;
                if (action.mRealSpeed / action.m_currentSpeed <= 0.1f)
                {
                }
                else
                {
                    targetPos = action.m_realTargetPos;
                }
            }
        }
        int targetID = 0;

        if (lastActor.TargetManager.CurrentTarget != null)
        {
            targetID = lastActor.TargetManager.CurrentTarget.ID;
        }
        //退场角色的信息 end
        ActorExitAction exitAction = lastActor.ActionControl.AddAction(ActorAction.ENType.enActorExitAction) as ActorExitAction;

        if (exitAction == null)
        {//退场失败,不能切换
            return(false);
        }
        lastActor.ActorExit();

        //开始CD
        m_switchCDTimer   = Time.time;
        m_switchCDTotal   = (curActor.CurrentTableInfo.SwitchCD + lastActor.CurrentTableInfo.SwitchCD) / 2;
        m_isSwitchForDead = isSwitchForDead;

        //当前角色上场
        if (lastActor.IsDead)
        {
            float percent = (float)m_switchCDTotal / ((curActor.CurrentTableInfo.SwitchCD + lastActor.CurrentTableInfo.SwitchCD) / 2);
            float hp      = (float)curActor.HP;
            if (percent != 0)
            {
                hp *= percent;
                curActor.SetCurHP((int)hp);
            }
        }
        curActor.ActorEnter(lastPos, lastForward, targetID, targetPos, isAttacking);

        // 小地图新进入的角色 加入
        Map.Singleton.AddPoint(curActor);
        return(true);
    }