Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a new BehaviorObject capable of participating in events
 /// </summary>
 /// <param name="root">The root node of the tree</param>
 /// <param name="statusChanged">An OnStatusChanged delegate for receiving
 /// status change events</param>
 public BehaviorObject()
 {
     this.CurrentEvent = null;
     this.PendingEvent = null;
     this.Status       = BehaviorStatus.Idle;
     this.Register();
 }
Ejemplo n.º 2
0
        private void FireTransitionEvent <T>(BehaviorEvent <T> args, TransitionEventDelegate <T> transitionEventDelegate, string viewName)  where T : IViewModel, new()
        {
            var transitionEvent = new TransitionEvent <T>(args)
            {
                ViewModel             = args.ViewModel,
                ViewReference         = viewName,
                PreviousViewReference = this.CurrentViewReference
            };

            transitionEventDelegate(transitionEvent);

            if (viewName != null)
            {
                this.CurrentViewReference = viewName;
            }


            this.ScriptManager = ScriptManager.GetCurrent(this.Page);
            if (this.ScriptManager != null &&
                this.ScriptManager.IsInAsyncPostBack &&
                this.ScriptManager.EnableHistory &&
                string.IsNullOrEmpty(viewName) == false)
            {
                this.ScriptManager.AddHistoryPoint(new NameValueCollection
                {
                    { "pv", transitionEvent.PreviousViewReference }
                }, transitionEvent.PreviousViewReference);
            }
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Returns true if and only if the candidate event is higher
    /// priority than both the running and next pending event, if any
    /// </summary>
    internal RunStatus IsElegible(BehaviorEvent candidate)
    {
        //  Debug.Log("start");



        if (this.CurrentEvent != null && pendingEvent != candidate &&
            BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0)
        {
            //    Debug.Log("fail 1");
            //  Debug.Log("candidate " + candidate.Priority + " " + this.CurrentEvent.Priority);

            return(RunStatus.Failure);
        }

        if (this.pendingEvent != null && pendingEvent != candidate &&
            BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0)
        {
            //Debug.Log("fail 2 " + candidate.Priority + " " + this.pendingEvent.Priority + " ");

            return(RunStatus.Failure);
        }

        //  Debug.Log("success");

        return(RunStatus.Success);
    }
 void Update()
 {
     if (Input.GetButtonDown("Fire2"))
     {
         Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
         BehaviorEvent.Run(new Sequence(Node_GoTo(position)), this);
     }
 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.R) == true)
     {
         BehaviorEvent.Run(
             this.ConversationTree(), Wanderer, Friend);
     }
 }
Ejemplo n.º 6
0
 protected bool FireBehaviorEvent <T>(BehaviorEventHandler <T> handler, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
     if (behaviorEvent == null)
     {
         return(false);
     }
     return(handler != null && handler(this as IBehaviorEventSender <T>, behaviorEvent));
 }
Ejemplo n.º 7
0
 protected void InvokeEvent(BehaviorEvent evt)
 {
     BehaviorComponent[] agents = evt.Agents;
     for (int i = 0; i < agents.Count(); i++)
     {
         agents[i].Suspended = true;
         this.idleAgents.Remove(agents[i]);
     }
     this.activeEvents.Add(evt);
     evt.Start();
 }
Ejemplo n.º 8
0
 private void EventStatusChanged(
     BehaviorEvent sender, 
     EventStatus newStatus)
 {
     if (newStatus == EventStatus.Finished)
     {
         this.SendFreeObjects(sender.Token.Get<uint[]>());
         this.SendRecommendationRequest();
         this.paused = true;
     }
 }
Ejemplo n.º 9
0
 protected void InvokeEvent(BehaviorEvent evt)
 {
     BehaviorComponent[] agents = evt.Agents;
     for (int i = 0; i < agents.Count(); i++)
     {
         agents[i].Suspended = true;
         this.idleAgents.Remove(agents[i]);
     }
     this.activeEvents.Add(evt);
     evt.Start();
 }
Ejemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        participants = findBAgent();
        Behavior     = new BehaviorEvent((Token toke) => this.BuildTreeRoot(), this.participants);

        //participants = findBAcrowd();
        //Crowd = new CrowdBehaviorEvent<AdamBehaviorTree>((AdamBehaviorTree tree, object token)=>this.BuildTreeRoot(),this.participants);


        currentStoryID = StoryID.mainstoryarc;
        adam1Freed     = false;
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs a new BehaviorAgent responsible for taking care of a tree
 /// </summary>
 /// <param name="root">The root node of the tree</param>
 /// <param name="statusChanged">An OnStatusChanged delegate for receiving
 /// status change events</param>
 public BehaviorAgent(Node root, OnStatusChanged statusChanged)
 {
     this.treeRoot      = root;
     this.pendingEvent  = null;
     this.statusChanged = statusChanged;
     this.AgentStatus   = Status.Idle;
     if (BehaviorManager.Instance == null)
     {
         Debug.LogError(this + ": No BehaviorManager!");
     }
     else
     {
         BehaviorManager.RegisterReceiver(this);
     }
 }
Ejemplo n.º 12
0
    /// <summary>
    /// Returns true if and only if the candidate event is higher
    /// priority than both the running and next pending event, if any
    /// </summary>
    internal RunStatus IsElegible(BehaviorEvent candidate)
    {
        if (this.CurrentEvent != null && pendingEvent != candidate &&
            BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0)
        {
            return(RunStatus.Failure);
        }

        if (this.pendingEvent != null && pendingEvent != candidate &&
            BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0)
        {
            return(RunStatus.Failure);
        }

        return(RunStatus.Success);
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Returns true if and only if the candidate event is higher
    /// priority than both the running and next pending event, if any
    /// </summary>
    public bool EventElegible(BehaviorEvent candidate)
    {
        if (this.CurrentEvent != null &&
            BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0)
        {
            return(false);
        }

        if (this.pendingEvent != null &&
            BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0)
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 14
0
 public void StartEvent(Node behavior, bool interruptible = false, IHasBehaviorObject[] agents = null)
 {
     if (Enabled)
     {
         if (interruptible)
         {
             float priority = 1f;
             if (InEvent)
             {
                 priority = g_BehaviorObject.CurrentEvent.Priority + 0.1f;
             }
         }
         agents = agents == null ? new IHasBehaviorObject[] { this } : agents;
         BehaviorEvent ev = new BehaviorEvent(doEvent => behavior, agents);
         ev.StartEvent(InEvent ? g_BehaviorObject.CurrentPriority + 1f : 1f);
     }
 }
Ejemplo n.º 15
0
    /// <summary>
    /// Notification that our pending event has become our current event
    /// </summary>
    public void EventStarted()
    {
        if (this.CurrentEvent != null)
        {
            throw new ApplicationException(
                      this + ".EventStarted(): Clearing active event");
        }
        else if (this.AgentStatus != Status.Idle)
        {
            throw new ApplicationException(
                      this + ".EventStarted(): Starting evt on busy agent");
        }

        this.CurrentEvent = this.pendingEvent;
        this.pendingEvent = null;
        this.AgentStatus  = Status.InEvent;
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Notification that our pending event has become our current event
    /// </summary>
    internal void LaunchEvent()
    {
        if (this.CurrentEvent != null)
        {
            throw new ApplicationException(
                      this + ".EventStarted(): Clearing active event");
        }
        else if (this.Status != BehaviorStatus.Idle)
        {
            throw new ApplicationException(
                      this + ".EventStarted(): Starting evt on busy agent");
        }

        this.CurrentEvent = this.pendingEvent;
        this.pendingEvent = null;
        this.Status       = BehaviorStatus.InEvent;
    }
Ejemplo n.º 17
0
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            RaycastHit hit;
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);

            if (hit.transform.parent != null && hit.transform.parent.gameObject.name == "Food Stand")
            {
                BehaviorEvent.Run(this.Eat(hit.transform.parent), player);
            }
            else if (hit.transform.gameObject.name == "Soil")
            {
                Debug.Log(player.Agent.AgentStatus);
                //if()
                BehaviorEvent.Run(this.Dig(hit.transform), player);
            }
        }
    }
Ejemplo n.º 18
0
    public void Update()
    {
        // Skip user input if we are replaying.
        if (ReplayManager.Instance.mIsReplaying) {
            return;
        }

        foreach (KeyValuePair<ControlSignal, Behavior> key_behavior in mBehaviors)
        {
            ControlSignal controlSignal = key_behavior.Key;
            float signal = controlSignal.PollSignal();

            Behavior behavior = key_behavior.Value;
            bool shouldRecord = behavior.Operate(signal);

            if (shouldRecord)
            {
                BehaviorEvent behavior_event = new BehaviorEvent(behavior.GenerateRecordedBehavior(), signal);
                ReplayManager.Instance.AddEvent(behavior_event);
            }
        }
    }
Ejemplo n.º 19
0
        public bool SendBehaviorEvent <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
        {
            var success = false;

            foreach (var fireBehaviorEventDelegate in this.FireBehaviorEventDelegates)
            {
                if (fireBehaviorEventDelegate.Invoke(behaviorEvent))
                {
                    success = true;
                }
            }

            if (success == false)
            {
                var @base = this.Parent as ViewBase;
                if (@base != null)
                {
                    success = @base.SendBehaviorEvent(behaviorEvent);
                }
            }

            return(success);
        }
    /// <summary>
    /// Notification that our pending event has become our current event
    /// </summary>
    internal void LaunchEvent()
    {
        if (this.CurrentEvent != null)
            throw new ApplicationException(
                this + ".EventStarted(): Clearing active event");
        else if (this.Status != BehaviorStatus.Idle)
            throw new ApplicationException(
                this + ".EventStarted(): Starting evt on busy agent");

        this.CurrentEvent = this.pendingEvent;
        this.pendingEvent = null;
        this.Status = BehaviorStatus.InEvent;
    }
    /// <summary>
    /// Returns true if and only if the candidate event is higher
    /// priority than both the running and next pending event, if any
    /// </summary>
    internal RunStatus IsElegible(BehaviorEvent candidate)
    {
        if (this.CurrentEvent != null && pendingEvent != candidate
            && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0)
            return RunStatus.Failure;

        if (this.pendingEvent != null && pendingEvent != candidate
            && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0)
            return RunStatus.Failure;

        return RunStatus.Success;
    }
Ejemplo n.º 22
0
 /// <summary>
 /// Constructs a new BehaviorObject capable of participating in events
 /// </summary>
 /// <param name="root">The root node of the tree</param>
 /// <param name="statusChanged">An OnStatusChanged delegate for receiving 
 /// status change events</param>
 public BehaviorObject()
 {
     this.CurrentEvent = null;
     this.PendingEvent = null;
     this.Status = BehaviorStatus.Idle;
     this.Register();
 }
Ejemplo n.º 23
0
 protected virtual void OnBeforeBehaviorLookup <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
 }
Ejemplo n.º 24
0
 public static int ComparePriority(BehaviorEvent a, BehaviorEvent b)
 {
    // Debug.Log(a.Priority + " " +  b.Priority);
     return Comparer<float>.Default.Compare(a.Priority, b.Priority);
 }
Ejemplo n.º 25
0
 protected virtual void OnBehaviorEvent <T>(IExecutableBehavior <T> executableBehavior, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
     executableBehavior.Execute(behaviorEvent);
 }
Ejemplo n.º 26
0
        private void TransitionView <T>(ICanChangeMyVisibility sender, string viewName, BehaviorEvent <T> behaviorEvent)  where T : IViewModel, new()
        {
            this.TransitionView(sender, viewName);

            this.FireTransitionEvent(behaviorEvent, this.OnTransitionEvent, viewName);


            //if (sender is IBehaviorEventSender<T>) this.CurrentViewReference = viewName;
        }
Ejemplo n.º 27
0
 public virtual void OnAfterTransition <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
 }
Ejemplo n.º 28
0
 public bool _ <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
     return(this.SendBehaviorEvent(behaviorEvent));
 }
Ejemplo n.º 29
0
    /// <summary>
    /// Void methods are self contained behaviors of an agent
    /// </summary>
    /// <param name="code"></param>
    public void Behavior_DoTimedGesture(GESTURE_CODE code)
    {
        BehaviorEvent be = new BehaviorEvent(doEvent => NPCBehavior_DoTimedGesture(code), new IHasBehaviorObject[] { this });

        be.StartEvent(1f);
    }
Ejemplo n.º 30
0
 public static int ComparePriority(BehaviorEvent a, BehaviorEvent b)
 {
     return(Comparer <float> .Default.Compare(a.Priority, b.Priority));
 }
Ejemplo n.º 31
0
 public static int ComparePriority(BehaviorEvent a, BehaviorEvent b)
 {
     return Comparer<float>.Default.Compare(a.Priority, b.Priority);
 }
Ejemplo n.º 32
0
 protected abstract void OnEventCompleted(BehaviorEvent evt);
Ejemplo n.º 33
0
 public static int ComparePriority(BehaviorEvent a, BehaviorEvent b)
 {
     // Debug.Log(a.Priority + " " +  b.Priority);
     return(Comparer <float> .Default.Compare(a.Priority, b.Priority));
 }
Ejemplo n.º 34
0
 protected virtual void OnAfterBehaviorEvent <T>(IBehaviorEventSender <T> sender, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
 }
Ejemplo n.º 35
0
 protected abstract void OnEventCompleted(BehaviorEvent evt);
Ejemplo n.º 36
0
        private bool OnBehaviorEventFired <T>(IBehaviorEventSender <T> sender, BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
        {
            this.OnBeforeBehaviorLookup(behaviorEvent);
            if (this.Behaviors.ContainsKey(behaviorEvent.BehaviorReference) == false)
            {
                return(false);
            }

            var behavior = this.Behaviors[behaviorEvent.BehaviorReference] as IExecutableBehavior <T>;

            if (behavior == null)
            {
                return(false);
            }

            behavior.BehaviorContext = this;

            this.OnBeforeBehaviorEvent(sender, behaviorEvent);
            try
            {
                this.OnBehaviorEvent(behavior, behaviorEvent);
            }
            catch (Exception ex)
            {
                this.OnErrorBehaviorEvent(ex);
                return(false);
            }
            this.OnAfterBehaviorEvent(sender, behaviorEvent);

            string viewName = null;

            if (this.BehaviorBinding.ContainsKey(behaviorEvent.BehaviorReference))
            {
                viewName = this.BehaviorBinding[behaviorEvent.BehaviorReference];
            }

            this.OnBeforeTransitionEvent(viewName, behavior);
            var view = sender as ViewBase;

            if (view != null)
            {
                view.BehaviorContext = this;
            }

            this.TransitionView(view, viewName, behaviorEvent);

            if (viewName == null && sender is ViewBase)
            {
                this.BindingViewModel(sender as ViewBase, behaviorEvent.ViewModel);
            }
            else if (viewName != null)
            {
                var next = this.GetNextView(viewName);
                if (next != null)
                {
                    this.BindingViewModel(next, behaviorEvent.ViewModel);

                    next.OnAfterTransition(behaviorEvent);
                    foreach (var sub in next.Controls.OfType <ViewBase>())
                    {
                        sub.BehaviorContext = next.BehaviorContext;
                        sub.OnAfterTransition(behaviorEvent);
                    }
                }
            }

            this.OnAfterTransitionEvent(viewName, behavior);

            return(true);
        }
Ejemplo n.º 37
0
 public bool FireBehaviorEvent <T>(BehaviorEvent <T> behaviorEvent) where T : IViewModel, new()
 {
     return(this.OnBehaviorEventFired(null, behaviorEvent));
 }
Ejemplo n.º 38
0
    public void StartEvent(Node behavior)
    {
        BehaviorEvent ev = new BehaviorEvent(doEvent => behavior, new IHasBehaviorObject[] { this });

        ev.StartEvent(InEvent ? g_BehaviorObject.CurrentPriority + 1f : 1f);
    }
Ejemplo n.º 39
0
    /// <summary>
    /// Returns true if and only if the candidate event is higher
    /// priority than both the running and next pending event, if any
    /// </summary>
    internal RunStatus IsElegible(BehaviorEvent candidate)
    {
      //  Debug.Log("start");
        


        if (this.CurrentEvent != null && pendingEvent != candidate
            && BehaviorEvent.ComparePriority(candidate, this.CurrentEvent) <= 0)
        {
        //    Debug.Log("fail 1");
          //  Debug.Log("candidate " + candidate.Priority + " " + this.CurrentEvent.Priority);
            
            return RunStatus.Failure;
        }

        if (this.pendingEvent != null && pendingEvent != candidate
            && BehaviorEvent.ComparePriority(candidate, this.pendingEvent) <= 0)
        {


            //Debug.Log("fail 2 " + candidate.Priority + " " + this.pendingEvent.Priority + " ");

            return RunStatus.Failure;
        }

      //  Debug.Log("success");
        
        return RunStatus.Success;
    }