Beispiel #1
0
 private const float messageDelay = 3.0f;         // seconds in between each message
 void DialogueForest.IClient.Choice(DialogueForest.Node node, IEnumerable <DialogueForest.Node> choices)
 {
     this.ActiveAnswers.Clear();
     this.ActiveAnswers.AddAll(choices.Select(x => new Ans {
         ParentID = node.id, ID = x.id, Name = x.name
     }));
     this.WaitForAnswer.Value = true;
 }
Beispiel #2
0
        public override void Awake()
        {
            base.Awake();
            this.PlayerEnteredRange.Action = delegate()
            {
                Phone phone = PlayerDataFactory.Instance.Get <Phone>();

                if (!string.IsNullOrEmpty(this.Initial))
                {
                    DialogueForest      forest = WorldFactory.Instance.Get <World>().DialogueForest;
                    DialogueForest.Node n      = forest.GetByName(this.Initial);
                    if (n == null)
                    {
                        Log.d(string.Format("Could not find dialogue node {0}", this.Initial));
                    }
                    else
                    {
                        if (n.type == DialogueForest.Node.Type.Choice)
                        {
                            throw new Exception("Cannot start dialogue tree with a choice");
                        }
                        phone.Execute(n);
                    }

                    if (phone.Schedules.Length > 0)                     // We sent a message. That means this signal tower cannot execute again.
                    {
                        this.Initial.Value = null;
                    }

                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_SIGNAL_TOWER_ACTIVATE, this.Entity);
                }

                PlayerFactory.Instance.Get <Player>().SignalTower.Value = this.Entity;
            };

            this.PlayerExitedRange.Action = delegate()
            {
                Phone phone = PlayerDataFactory.Instance.Get <Phone>();

                if (!string.IsNullOrEmpty(this.Initial))                 // The player did not interact.
                {
                    phone.ActiveAnswers.Clear();
                }

                if (PlayerFactory.Instance != null)
                {
                    PlayerFactory.Instance.Get <Player>().SignalTower.Value = null;
                }
            };

            if (!this.main.EditorEnabled)
            {
                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_SIGNAL_TOWER_LOOP, this.Entity);
            }

            SignalTower.All.Add(this);
        }
Beispiel #3
0
 public void Execute(DialogueForest.Node node)
 {
     this.execute(node);
     if (this.Schedules.Length == 0)
     {
         // If there are choices available, they will initiate a conversation.
         // The player should be able to pull up the phone, see the choices, and walk away without picking any of them.
         // Normally, you can't put the phone down until you've picked an answer.
         this.WaitForAnswer.Value = false;
     }
 }
Beispiel #4
0
        public void Answer(Ans answer)
        {
            string messageID;

            if (string.IsNullOrEmpty(answer.ParentID))
            {
                messageID = this.LastMessageID();
            }
            else
            {
                messageID = answer.ParentID;
            }

            this.Messages.Add(new Message {
                Sender = Sender.Player, Name = answer.Name,
            });
            if (answer.Exclusive)
            {
                this.ActiveAnswers.Clear();
            }
            else
            {
                this.ActiveAnswers.Remove(answer);
            }

            this.WaitForAnswer.Value = false;

            if (messageID != null)
            {
                Command <string> callback;
                this.answerCallbacks.TryGetValue(messageID, out callback);
                if (callback != null)
                {
                    callback.Execute(answer.Name);
                }

                Command cmd;
                this.visitCallbacks.TryGetValue(answer.Name, out cmd);
                if (cmd != null)
                {
                    cmd.Execute();
                }

                DialogueForest.Node selectedChoice = this.forest[answer.ID];
                if (selectedChoice != null)
                {
                    DialogueForest.Node next = selectedChoice.next != null ? forest[selectedChoice.next] : null;
                    if (next != null)
                    {
                        this.execute(next);
                    }
                }
            }
        }
Beispiel #5
0
 void DialogueForest.IClient.Visit(DialogueForest.Node node)
 {
     if (!string.IsNullOrEmpty(node.name) && node.type != DialogueForest.Node.Type.Text)
     {
         Command cmd;
         this.visitCallbacks.TryGetValue(node.name, out cmd);
         if (cmd != null)
         {
             cmd.Execute();
         }
     }
 }
Beispiel #6
0
        public static void Run(Entity script)
        {
            Property <string> lastNode = property <string>(script, "LastNode");
            Property <string> nextNode = property <string>(script, "NextNode");

            Phone phone = PlayerDataFactory.Instance.Get <Phone>();

            script.Add(new CommandBinding(phone.OnVisit(lastNode), new Command
            {
                Action = delegate()
                {
                    DialogueForest forest = WorldFactory.Instance.Get <World>().DialogueForest;
                    DialogueForest.Node n = forest.GetByName(nextNode);
                    phone.Execute(n);
                }
            }));
        }
Beispiel #7
0
 void DialogueForest.IClient.Text(DialogueForest.Node node, int level)
 {
     this.Delay(messageDelay * level, this.CurrentPartner, node.name, node.id);
 }
Beispiel #8
0
 private void execute(DialogueForest.Node node)
 {
     this.forest.Execute(node, this);
 }