public void AddBehavior(Behavior b) { if (b == Behavior.NullBehavior) return; if (behaviors.ContainsKey(b.Id)) behaviors[b.Id] = b; else behaviors.Add(b.Id, b); DebugIf("behaviorLoad", "Added behavior '" + b.Id + "': " + b.ToString()); }
public BehaviorExecutionContext(Behavior behavior, List<BehaviorNode> nodes) : this(behavior, nodes, new Character()) { }
public BehaviorExecutionContext(Behavior behavior, List<BehaviorNode> nodes, Character character) { Behavior = behavior; Nodes = nodes; Character = character; }
public void PublishEvent(string messageId, string clientId, string eventName, bool dontLogDescription, string[] parameters, string[] types, string[] values, string syncEvent = "") { ThalamusClientProxy sourceClient = null; inboundEventsCounter++; if (remoteClients.ContainsKey(clientId)) sourceClient = remoteClients[clientId]; PML pml = new PML(eventName, parameters, types, values); pml.DontLogDescription = dontLogDescription; if (sourceClient != null) { Environment.Instance.DebugIf("messages", "[T][" + sourceClient.Name + "]Publishing... " + pml.ToString() + "."); } else { Environment.Instance.DebugIf("messages", "[T][Unknown]Publishing... " + pml.ToString() + "."); } Environment.Instance.LogEvent(false, character, sourceClient, pml); if (syncEvent != "") { Behavior b = new Behavior(); b.AddNode(new Actions.SyncAction(new Actions.SyncPoint(eventName), sourceClient, pml)); BehaviorPlan.Instance.Add(b); } else { Character.SendPerception(pml); BroadcastEvent(messageId, sourceClient, eventName, parameters, types, values, pml); } }
public float SolveSyncPoint(SyncPoint syncPoint, Behavior localBehavior) { if (syncPoint.Type==SyncPointType.Absolute) return syncPoint.AbsoluteValue; else { Behavior b = null; string[] references = syncPoint.ReferenceValue.Split(':'); if (references.Length==3) { if (BehaviorManager.Instance.Behaviors.ContainsKey(references[0])) b = BehaviorManager.Instance.Behaviors[references[0]]; } else if (references.Length == 2 && localBehavior != null) { b = localBehavior; } if (b!=null) { BehaviorNodes.Action a = b.GetActionById(references[1]); if(a!=null) { SyncPoint sp = a.GetEvent(references[2]); if (sp.Type==SyncPointType.Absolute) return sp.AbsoluteValue; else { //can support here recursive solving return -1; } }else{ return -1; } }else{ return -1; } } }
private void ReplaceBehavior(Behavior behavior, Character character) { DebugIf("all", "ReplaceBehavior '" + behavior.Id + "' on character '" + character.ToString() + "'"); CancelCurrentPlan(); List<BehaviorNode> nodes = SolveConstraints(behavior.Nodes); if (character != null) ScheduleBehavior(new BehaviorExecutionContext(behavior, nodes, character)); else ScheduleBehavior(new BehaviorExecutionContext(behavior, nodes)); }
public void Add(Behavior behavior, Character character) { switch (behavior.Composition) { case Behavior.CompositionType.Append: AppendBehavior(behavior, character); break; case Behavior.CompositionType.Merge: MergeBehavior(behavior, character); break; case Behavior.CompositionType.Replace: ReplaceBehavior(behavior, character); break; } }
public void Add(Behavior behavior) { if (!BehaviorManager.Instance.Behaviors.ContainsValue(behavior)) BehaviorManager.Instance.AddBehavior(behavior); if (defaultCharacter != null && behavior.Character==null) Add(behavior, defaultCharacter); else Add(behavior, behavior.Character); }