示例#1
0
        public void HandleCommand(string topic, string command)
        {
            if (_state == State.Dialog && topic == "UI" && command == "Continue")
            {
                _state             = State.Choice;
                _currentNodeInited = false;
                return;
            }

            if (_state == State.Choice && topic == "UI")
            {
                if (!_currentNode.Responses.ContainsKey(command))
                {
                    throw new ExceptionNullNode(command);
                }

                _currentNode = _currentNode.Responses[command];

                if (_currentNode.Type == Scenario.Node.NodeType.Dialog)
                {
                    _state             = State.Dialog;
                    _currentNodeInited = false;
                    return;
                }
                else if (_currentNode.Type == Scenario.Node.NodeType.Battle)
                {
                    _state             = State.Battle;
                    _currentNodeInited = false;
                    return;
                }
            }
        }
示例#2
0
        public override void Initialize(World world)
        {
            _scenarioEntity = world.CreateEntity();

            _lua.LoadCLRPackage();

            var characters = new Characters();

            _lua["Characters"] = characters;

            var scenario = new Scenario();

            _lua["Scenario"] = scenario;

            _lua.DoFile(_startScript);

            if (_lua.GetString("Background") != "")
            {
                _backgroundSprite = new SpriteComponent(_content.GetType().GetProperty(_lua.GetString("Background")).GetValue(_content) as Texture2D);
                _backgroundSprite.IsBackground = true;
                _scenarioEntity.Attach(_backgroundSprite);
            }

            // Create character's entity

            foreach (var chr in characters.Pool)
            {
                var name       = chr.Value.Name;
                var spritePath = chr.Value.SpritePath;

                _l.Debug(String.Format("Add chr: name {0}, sprite {1}", name, spritePath));

                _characterEntities[name] = world.CreateEntity();

                var tex             = _content.GetType().GetProperty(spritePath).GetValue(_content) as Texture2D;
                var spriteComponent =
                    new SpriteComponent(tex);
                spriteComponent.Position = new Rectangle(150, 30, tex.Width / 2, tex.Height / 2);
                spriteComponent.Depth    = 0.0f;

                _characterSprites.Add(name, spriteComponent);
                _characterEntities[name].Attach(spriteComponent);
            }

            _currentNode = scenario.Start;
            // TODO: check node type
            _state = State.Dialog;
            _ui.IsDialogBackgroundVisible = true;
        }