예제 #1
0
파일: SkillUnit.cs 프로젝트: soulhez/Lemon
 /// <summary>
 /// 激活行为树
 /// </summary>
 protected override void MonoStart()
 {
     SetPosition(ORIGIN_POSIITON);
     SkillSystemManager.Instance.RegisterSkillUnit(ID, this);
     Result = BT_Result.NONE;
     bRun   = false;
 }
예제 #2
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        if (am.IsRunning(ID) == false)
        {
            am.SetInt(ID, "lastRunningNode", 0);
            am.StartRunning(ID);
        }

        for (int node = am.GetInt(ID, "lastRunningNode", 0); node < Children.Count; node++)
        {
            BT_Result result = TickChild(Children[node], am);

            if (result == BT_Result.SUCCESS)
            {
                // Sprawdzamy następny
                continue;
            }
            else if (result == BT_Result.RUNNING)
            {
                am.SetInt(ID, "lastRunningNode", node);
                return(result);
            }
            else
            {
                // Porażka lub błąd - zaczynamy od nowa
                am.StopRunning(ID);
                return(result);
            }
        }

        am.StopRunning(ID);
        return(BT_Result.SUCCESS);
    }
예제 #3
0
        public override BT_Result doAction()
        {
            if (this.children == null || this.children.Count == 0)
            {
                return(BT_Result.SUCCESSFUL);
            }

            if (this.index >= this.children.Count)
            {
                reset();
            }

            BT_Result _result = BT_Result.NONE;

            for (int length = this.children.Count; index < length; ++index)
            {
                _result = this.children[index].doAction();
                if (_result == BT_Result.FAIL)
                {
                    reset();
                    return(_result);
                }
                else if (_result == BT_Result.RUNING)
                {
                    return(_result);
                }
                else
                {
                    continue;
                }
            }

            reset();
            return(BT_Result.SUCCESSFUL);
        }
예제 #4
0
    public static BT_Result TickChild(BT_Node child, BT_AgentMemory am)
    {
        if (child.CheckPrecondition(am) == false)
        {
            return(BT_Result.FAILURE);
        }

        am.FinalNodeLastCall = child.ID;

        if (child.Activates == false)
        {
            // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - decider tick");
            BT_Result result = child.Tick(am);
            return(result);
        }
        else
        {
            am.ActivateNode(child.ID);
            // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - action tick");
            BT_Result result = child.Tick(am);
            if (result != BT_Result.RUNNING)
            {
                am.DeactivateNode(child.ID);
            }
            return(result);
        }
    }
예제 #5
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        if (am.IsRunning(ID) == false)
        {
            am.SetInt(ID, "lastRunningNode", 0);
            am.StartRunning(ID);
        }

        for (int node = am.GetInt(ID, "lastRunningNode", 0); node < Children.Count; node++)
        {
            BT_Result result = TickChild(Children[node], am);

            if (result == BT_Result.FAILURE)
            {
                continue;
            }
            else if (result == BT_Result.RUNNING)
            {
                am.SetInt(ID, "lastRunningNode", node);
                return(result);
            }
            else
            {
                am.StopRunning(ID);
                return(result);
            }
        }

        am.StopRunning(ID);
        return(BT_Result.FAILURE);
    }
예제 #6
0
    public BT_Result Tick(BT_AgentMemory am)
    {
        am.ResetActiveNodesList();
        am.ProcessTimers(am.DeltaTime);
        am.CurrentTree = this;

        BT_Result result = BT_Node.TickChild(Root, am);

        // Debug.Log(am.Character.Name + " - " + am.FinalNodeLastCall + " - " + GetNodeByID(am.FinalNodeLastCall).GetType());
        return(result);
    }
예제 #7
0
파일: SkillUnit.cs 프로젝트: soulhez/Lemon
 public void Running()
 {
     if (!bRun)
     {
         return;
     }
     Result = SequenceNode.doAction();
     //执行结束
     if (Result == BT_Result.FAIL || Result == BT_Result.SUCCESSFUL)
     {
         bRun = false;
     }
 }
예제 #8
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        for (int i = 0; i < Children.Count; i++)
        {
            BT_Result result = TickChild(Children[i], am);

            if (result != BT_Result.SUCCESS)
            {
                return(result);
            }
        }

        return(BT_Result.SUCCESS);
    }
예제 #9
0
        public override BT_Result doAction()
        {
            if (this.children == null || this.children.Count == 0)
            {
                return(BT_Result.SUCCESSFUL);
            }

            BT_Result      _result    = BT_Result.NONE;
            List <BT_Node> _waitNodes = ListPool <BT_Node> .Get();

            List <BT_Node> _mainNodes = ListPool <BT_Node> .Get();

            _mainNodes = this.m_pWaitNodes.Count > 0 ? this.m_pWaitNodes : this.children;
            for (int i = 0, length = _mainNodes.Count; i < length; ++i)
            {
                _result = _mainNodes[i].doAction();
                switch (_result)
                {
                case BT_Result.SUCCESSFUL:
                    break;

                case BT_Result.RUNING:
                    _waitNodes.Add(_mainNodes[i]);
                    break;

                default:
                    m_pIsFail = true;
                    break;
                }
            }
            ListPool <BT_Node> .Release(_mainNodes);


            // 存在等待节点就返回等待;
            if (_waitNodes.Count > 0)
            {
                this.m_pWaitNodes.Clear();
                this.m_pWaitNodes.AddRange(_waitNodes);
                ListPool <BT_Node> .Release(_waitNodes);

                return(BT_Result.RUNING);
            }

            // 检查返回结果;
            _result = checkResult();
            reset();
            return(_result);
        }
예제 #10
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        for (int i = 0; i < Children.Count; i++)
        {
            BT_Result result = TickChild(Children[i], am);

            if (result == BT_Result.FAILURE)
            {
                continue;
            }
            else
            {
                return(result);
            }
        }
        return(BT_Result.FAILURE);
    }
예제 #11
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        BT_Result result = TickChild(Child, am);

        if (result == BT_Result.FAILURE)
        {
            return(BT_Result.SUCCESS);
        }
        else if (result == BT_Result.SUCCESS)
        {
            return(BT_Result.FAILURE);
        }
        else
        {
            return(result);
        }
    }
예제 #12
0
파일: BT_Debug.cs 프로젝트: soulhez/Lemon
    public static void Log(BT_Result _result, string msg)
    {
        switch (_result)
        {
        case BT_Result.FAIL:
            QLog.LogError("Bt_Result: " + _result);
            break;

        case BT_Result.RUNING:
            QLog.LogWarning("Bt_Result: " + _result);
            break;

        case BT_Result.SUCCESSFUL:
            QLog.Log("Bt_Result: " + _result);
            break;

        default:
            QLog.Log("Bt_Result: " + _result);
            break;
        }
    }
    public override BT_Result Tick(BT_AgentMemory am)
    {
        BT_FindStorageForResourceData data = am.GetObject(ID) as BT_FindStorageForResourceData;

        if (data == null)
        {
            return(BT_Result.FAILURE);
        }

        data.PotentialReservation = GameManager.Instance.World.GetReservationToStoreCurrentResource(am.Character);

        if (data.PotentialReservation == null)
        {
            am.SetTimer(ID, timeoutAfterNullResults);
            return(BT_Result.FAILURE);
        }

        BT_Result result = TickChild(subnode, am);

        if (result == BT_Result.SUCCESS)
        {
            if (data.PotentialReservation.TargetStorage.ReserveFreeSpace(am.Character.Resource, am.Character))
            {
                am.Character.SetNewReservation(data.PotentialReservation);
                data.PotentialReservation = null;
                return(BT_Result.SUCCESS);
            }
            else
            {
                return(BT_Result.FAILURE);
            }
        }
        else
        {
            return(result);
        }
    }
예제 #14
0
 public ResultContainer(BT_Result _r)
 {
     nextStartNodesQueue = new Queue <BT_Node>();
     result = _r;
 }
예제 #15
0
    public override BT_Result Tick(BT_AgentMemory am)
    {
        BT_FindTransportJobNodeData data = am.GetObject(ID) as BT_FindTransportJobNodeData;

        if (data == null)
        {
            return(BT_Result.FAILURE);
        }

        World world = GameManager.Instance.World;

        if (data.PotentialReservation == null)
        {
            ResourceReservation newReservation = null;

            newReservation = world.GetReservationForFillingInput(am.Character);

            if (newReservation == null)
            {
                newReservation = world.GetReservationForEmptying(am.Character);
            }

            if (newReservation != null)
            {
                data.PotentialReservation = newReservation;
                data.TargetStorageChecked = false;
                data.SourceStorageChecked = false;
            }
            else
            {
                am.SetTimer(ID, timeoutAfterFailure);
                return(BT_Result.FAILURE);
            }

            return(BT_Result.RUNNING);
        }

        if (data.TargetStorageChecked == false)
        {
            BT_Result result = TickChild(findTargetStorageNode, am);

            if (result == BT_Result.SUCCESS)
            {
                data.TargetStorageChecked = true;
                return(BT_Result.RUNNING);
            }
            else if (result == BT_Result.RUNNING)
            {
                return(BT_Result.RUNNING);
            }
            else
            {
                am.SetTimer(ID, timeoutAfterFailure);
                return(BT_Result.FAILURE);
            }
        }
        else
        {
            BT_Result result = TickChild(findSourceStorageNode, am);

            if (result == BT_Result.SUCCESS)
            {
                data.SourceStorageChecked = true;

                if (am.Character.SetNewReservation(data.PotentialReservation))
                {
                    am.SetObject(ID, null);
                    return(BT_Result.SUCCESS);
                }
                else
                {
                    data.PotentialReservation.SourceStorage.RemoveResourceReservation(am.Character);
                    data.PotentialReservation.TargetStorage.RemoveFreeSpaceReservation(am.Character);

                    am.SetTimer(ID, timeoutAfterFailure);
                    return(BT_Result.FAILURE);
                }
            }
            else if (result == BT_Result.RUNNING)
            {
                return(BT_Result.RUNNING);
            }
            else
            {
                am.SetTimer(ID, timeoutAfterFailure);
                return(BT_Result.FAILURE);
            }
        }
    }