protected Node[] BuildTreeRoot() { ForEach <GameObject> returnValue = new ForEach <GameObject>((participant) => { Func <bool> act = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) < 5) && (Math.Abs(police.transform.position.x - participant.transform.position.x) < 5)); Func <bool> act2 = () => ((Math.Abs(door.transform.position.z - participant.transform.position.z) < 5) && (Math.Abs(door.transform.position.x - participant.transform.position.x) < 5)); Func <bool> act4 = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) >= 5) && (Math.Abs(police.transform.position.x - participant.transform.position.x) >= 5)); Node trigger = new DecoratorLoop(new LeafAssert(act)); Node trigger4 = new DecoratorLoop(new LeafAssert(act4)); Node roaming = new SequenceParallel( new DecoratorForceStatus(RunStatus.Success, ST_RunAndWait(police.transform, participant.transform)), new LeafInvoke(() => { participant.GetComponent <CanvasController>().enableSpeech(); participant.GetComponent <CanvasController>().setText("AHH, RUN!"); })) ; Node clearText = new LeafInvoke(() => { participant.GetComponent <CanvasController>().disableSpeech(); }); Node trigger2 = new DecoratorLoop(new LeafAssert(act2)); Node open = new DecoratorLoop( new Sequence(CompleteOpenDoor(specialDaniel.transform))); Node root = new DecoratorLoop(new Sequence(new SequenceParallel(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger, roaming)), new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger4, clearText))), new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger2, open)))); return(root); }, participants); Func <bool> act3 = () => (1 < 0); Node trigger3 = new LeafInvoke(() => RunStatus.Failure); Node temp = new Sequence(new LeafInvoke(() => { if (index < 2) { index++; } else { index = 0; } Debug.Log("leafinvoke index: " + index); }), new LeafWait(5000)); //Vector3 policeVector = new Vector3(0,0,0); Node chasing = new DecoratorLoop( new Sequence( ChaseDaniels(police.transform, participants[index].transform))); Func <bool> danny0 = () => (index == 0); Func <bool> danny1 = () => (index == 1); Func <bool> danny2 = () => (index == 2); Node dannyTest0 = new LeafAssert(danny0); Node dannyTest1 = new LeafAssert(danny1); Node dannyTest2 = new LeafAssert(danny2); Node check = new LeafInvoke(() => { foreach (GameObject participant in participants) { Func <bool> measure = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) < 1) && (Math.Abs(police.transform.position.x - participant.transform.position.x) < 1)); Node trigger = new DecoratorLoop(new LeafAssert(measure)); Node root = new Sequence(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger, ChaseDaniels(police.transform, participant.transform)))); } }); Node change = new Sequence(new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[0].transform)), new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[1].transform)), new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[2].transform))); //Node trigger = new DecoratorLoop(new LeafAssert(measure)); //Node change2 = Node returnValue2 = new DecoratorLoop(change); // Node returnValue3 = new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new LeafInvoke(() => { CompleteOpenDoor(specialDaniel.transform); }))); Node[] rv = new Node[2]; rv[0] = returnValue; rv[1] = returnValue2; // rv[2] = returnValue3; return(rv); //Vector3 min = (participants[0].transform.position - police.transform.position); //int index = 0; /* * Node chase = * new Sequence(new LeafInvoke(() => { * //min = (participants[0].transform.position - police.transform.position); * //for (int i = 1; i < participants.Length; i++) * //{ * // if ((Math.Pow((police.transform.position.x - participants[i].transform.position.x), 2) + Math.Pow((police.transform.position.z - participants[i].transform.position.z), 2) < min.sqrMagnitude)) * // { * // min = participants[i].transform.position - police.transform.position; * // index = i; * // } * // * if (index < 2) * index++; * else * index = 0; * }),ST_ApproachAndWait(participants[index].transform, police.transform)); * // new Sequence(ChaseDaniels(police.transform, participants))); */ //return new Sequence(new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger3, chasing))), returnValue); //return new Sequence(new DecoratorLoop(new SequenceParallel(new Sequence(chasing, new LeafWait(1000)),returnValue))); //return returnValue; }
protected Node Simplify(GameObject parta, GameObject partb, GameObject partc) { // A ask B turn off light // A ask C turn on TV //Val<bool> pp = Val.V (() => lamp.enabled); Func <bool> act = () => (lamp.enabled); Node trigger = new DecoratorLoop(new LeafAssert(act)); Func <bool> playerinRangeA = () => (parta.GetComponentInChildren <PlayerinRange>().playerinRange); Func <bool> playerinRangeB = () => (partb.GetComponentInChildren <PlayerinRange>().playerinRange); Func <bool> playerinRangeC = () => (partc.GetComponentInChildren <PlayerinRange>().playerinRange & (angryCount < 3)); Func <RunStatus> switchinRange = () => (lightSwitch.GetComponentInChildren <PlayerinRange>().PlayerInRange()?RunStatus.Success:RunStatus.Running); Func <bool> clicked = () => (Player.GetComponentInChildren <PlayerController>().clicked); Node triggerA = new DecoratorLoop(new LeafAssert(playerinRangeA)); Node triggerB = new DecoratorLoop(new LeafAssert(playerinRangeB)); Node triggerC = new DecoratorLoop(new LeafAssert(playerinRangeC)); Node triggerSwitch = new LeafInvoke(switchinRange); Node triggerClick = new DecoratorLoop(new LeafAssert(clicked)); Func <bool> angry = () => (angryCount >= 3); Node triggerAngry = new DecoratorLoop(new LeafAssert(angry)); Node trigger_preAngry = new LeafAssert(LightOffRole); return(new SequenceParallel( new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel( triggerA, new Sequence( this.Greeting("A: ") // this.TextOn("Hi! I'm A",canvasTV, bubbleTextT) ) )) ), new SequenceParallel( new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel( triggerB, new Sequence( this.Greeting("B: ") // this.TextOn("Hi! I'm B",canvasTV, bubbleTextT) ) )) )), new SequenceParallel( new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel( triggerC, new Sequence( this.Greeting("C: ") // this.TextOn("Hi! I'm C",canvasTV, bubbleTextT) ) )) )), new SequenceParallel( new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel( triggerAngry, new Sequence( // this.Greeting("C: ") this.TextOn("B: HEY!!!!!! STOP TOUCHING THE SWITCH!!!!!!", canvasTV, bubbleTextT) ) )) )), new SequenceParallel( new DecoratorLoop( new Sequence( triggerSwitch, new Sequence(this.LightOff(Player.GetComponent <BehaviorMecanim>()), new LeafInvoke(() => this.LightOffRole())) // this.NPCLightOff() ) )), new SequenceParallel( new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel( triggerClick, new Sequence( Player.GetComponent <BehaviorMecanim>().Node_GoTo(Player.GetComponentInChildren <PlayerController>().dest) ) )) )) )); }