예제 #1
0
        public override void LoadContent()
        {
            var abilityIcon = _content.Load <Texture2D>("Battle/AbilityIcon");

            var position = new Vector2(200, 500);

            _actors = _players.Select(c =>
            {
                var player = new Player(_content, position, _graphics.GraphicsDevice)
                {
                    ActorModel     = c,
                    LeftHandWeapon = GetWeapon(c.EquipmentModel.EquipmentType, c.EquipmentModel.LeftHandEquipmentPath),
                    Lower          = !string.IsNullOrEmpty(c.Lower) ? new Clothing(_content.Load <Texture2D>(c.Lower)) : null,
                    Upper          = !string.IsNullOrEmpty(c.Upper) ? new Clothing(_content.Load <Texture2D>(c.Upper)) : null,
                };

                position += new Vector2(200, 0);

                return(player);
            }).Cast <Actor>().ToList();

            var grassTexture = _content.Load <Texture2D>("Battle/Grasses/Grass");

            _background = new Sprite(grassTexture)
            {
                Position = new Vector2(grassTexture.Width / 2, grassTexture.Height / 2),
            };

            EnemyLoader eLoader = new EnemyLoader(_content);

            var enemies = eLoader.Load(EnemyLoader.Areas.CalmLands);

            var enemyPosition = new Vector2(200, 100);

            _actors.AddRange(enemies.Select(c =>
            {
                var enemy = new Enemy(_content, enemyPosition, _graphics.GraphicsDevice)
                {
                    ActorModel     = c,
                    LeftHandWeapon = GetWeapon(c.EquipmentModel.EquipmentType, c.EquipmentModel.LeftHandEquipmentPath),
                };
                enemyPosition += new Vector2(200, 0);

                return(enemy);
            }
                                            ).Cast <Actor>().ToList());

            _actors = _actors.OrderByDescending(c => c.ActorModel.Speed).ToList();

            _battleGUI = new BattleStateGUI(_gameModel);
            _battleGUI.SetAbilities(_actors.First().ActorModel);
            _battleGUI.SetTurns(_actors.Select(c => c.ActorModel).ToList());

            _chatBox = new ChatBox(_gameModel, _content.Load <SpriteFont>("Fonts/Font"));

            if (_conversation != null && _conversation.Count > 0)
            {
                _chatBox.Write(_conversation.First());
            }
        }
예제 #2
0
        private void ProcessTurns()
        {
            var buttons = _battleGUI.AbilityButtons
                          .Where(c => c.Value.IsClicked)
                          .ToDictionary(c => c.Key, v => v.Value);

            string ability = null;


            var actor = _actors.Where(c => c.State == Actor.States.Alive).ToList()[_currentActor];

            actor.ShowTurnBar = true;

            if (buttons.Count > 0)
            {
                var button = buttons.First();

                ability = button.Key;
                actor.ActionResult.State = Engine.ActionStates.Waiting;
            }

            var actionResult = actor.GetAction(ability);

            if (actionResult == null)
            {
                return;
            }

            if (actionResult.State == Engine.ActionStates.WaitingForTarget)
            {
                if (actor is Player)
                {
                    _targets = actor.GetTargets(Enemies.Cast <Actor>());
                }
                else if (actor is Enemy)
                {
                    _targets = actor.GetTargets(Players.Cast <Actor>());
                }
                else
                {
                    throw new Exception("Unexpected type: " + actor.ToString());
                }
            }

            if (actionResult.State == Engine.ActionStates.Running)
            {
                actionResult.Action();
            }

            if (actionResult.State != Engine.ActionStates.Finished)
            {
                return;
            }

            // Since the attack is finished, we need to remove health from whoever has been hit

            foreach (var target in _targets)
            {
                var damage = GetDamage(actor, target);

                target.CurrentHealth -= damage;
                target.ActorModel.BattleStats.DamageReceived += damage;
                actor.ActorModel.BattleStats.DamageDealt     += damage;

                if (target.CurrentHealth <= 0)
                {
                    target.State = Actor.States.Dying;

                    actor.ActorModel.BattleStats.FinalBlows += 1;

                    if (_actors.IndexOf(target) < _currentActor)
                    {
                        _currentActor--;
                    }
                }
            }

            var validActors = _actors.Where(c => c.State == Actor.States.Alive).ToList();

            _currentActor = (_currentActor + 1) % validActors.Count;
            _battleGUI.SetAbilities(validActors[_currentActor].ActorModel);
            _battleGUI.SetTurns(validActors.Select(c => c.ActorModel).Skip(_currentActor).ToList());

            // As the move is over, there is no longer a target
            _targets = new List <Actor>();
        }