コード例 #1
0
        public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            if (!forClient)
            {
                ITreeAttribute ctree = WatchedAttributes.GetTreeAttribute("commandQueue");
                if (ctree == null)
                {
                    return;
                }

                ITreeAttribute commands = ctree.GetTreeAttribute("commands");
                if (commands == null)
                {
                    return;
                }

                foreach (var val in commands)
                {
                    ITreeAttribute attr = val.Value as ITreeAttribute;
                    string         type = attr.GetString("type");

                    INpcCommand command = null;

                    switch (type)
                    {
                    case "tp":
                        command = new NpcTeleportCommand(this, null);
                        break;

                    case "goto":
                        command = new NpcGotoCommand(this, null, null, 0);
                        break;

                    case "anim":
                        command = new NpcPlayAnimationCommand(this, null, 1f);
                        break;
                    }

                    command.FromAttribute(attr);
                    Commands.Add(command);
                }
            }
        }
コード例 #2
0
        public override void OnGameTick(float dt)
        {
            base.OnGameTick(dt);

            pathTraverser.OnGameTick(dt);

            if (commandQueueActive)
            {
                if (ExecutingCommands.Count > 0)
                {
                    INpcCommand nowCommand = ExecutingCommands.Peek();
                    if (nowCommand.IsFinished())
                    {
                        ExecutingCommands.Dequeue();
                        if (ExecutingCommands.Count > 0)
                        {
                            ExecutingCommands.Peek().Start();
                        }
                        else
                        {
                            if (LoopCommands)
                            {
                                StartExecuteCommands();
                            }
                            else
                            {
                                commandQueueActive = false;
                            }
                        }
                    }
                }
                else
                {
                    if (LoopCommands)
                    {
                        StartExecuteCommands();
                    }
                    else
                    {
                        commandQueueActive = false;
                    }
                }
            }
        }