Example #1
0
        public CharacterDialog(Combatant character)
        {
            InitializeComponent();

            _character = character;

            ResetCharacter();
        }
 public void SetCharacter(Combatant character)
 {
     _name.Text = character.Name;
     _class.Text = character.Class;
     _health.Text = character.CurrentHealth.ToString();
     _mana.Text = character.CurrentMana.ToString();
     _healthBar.Progress = (float)character.CurrentHealth/(float)character.MaxHealth;
     _manaBar.Progress = (float)character.CurrentMana/(float)character.MaxMana;
 }
        public void SetCharacter(Combatant character)
        {
            _character = character;

            _overviewDialog.UpdateCharacter(_character);
            _statsDialog.UpdateCharacter(_character);
            _inventoryDialog.UpdateCharacter(_character);
            _abilityDialog.UpdateCharacter(_character);
        }
        public void UpdateCharacter(Combatant character)
        {
            var weapon = character.GetEquippedWeapon();
            var armor = character.GetEquippedArmor();
            var acc = character.GetEquippedAccessory();

            _weaponText.Text = weapon == null ? "---" : weapon.Name;
            _armorText.Text = armor == null ? "---" : armor.Name;
            _accText.Text = acc == null ? "---" : acc.Name;
        }
        public void UpdateCharacter(Combatant character)
        {
            _nameText.Text = character.Name;
            _classText.Text = character.Class;

            _picture.Frame = "avatar.icon." + character.Avatar.Icon;

            _healthText.Text = character.MaxHealth.ToString();
            _manaText.Text = character.MaxMana.ToString();
        }
 public void UpdateCharacter(Combatant character)
 {
     Children.Clear();
     var abilities = character.GetAbilities();
     for (var i = 0; i < abilities.Count(); i++)
     {
         var ability = abilities.ElementAt(i);
         var exp = character.AbilityExperienceLevels.ContainsKey(ability) ? character.AbilityExperienceLevels[ability] : 0;
         var display = new AbilityDisplay(ability, exp);
         display.Bounds.Location.Y.Offset = 10 + 30 * i;
         Children.Add(display);
     }
 }
Example #7
0
        public BattleDecision CalculateAction(Combatant character)
        {
            var decision = new BattleDecision();
            decision.Destination = new Point((int)character.Avatar.Location.X, (int)character.Avatar.Location.Y);

            if (_threat.Count == 0) return decision;

            // find the enemy with the highest threat
            var enemy = (from ckv in _threat orderby ckv.Value descending select ckv.Key).First();

            // find the point that brings you closest to them
            var grid = character.GetMovementGrid(BattleBoard.GetAccessibleGrid(character.Faction));

            var distance = 65535;
            for (var x = 0; x < grid.Size.Width; x++)
            {
                for (var y = 0; y < grid.Size.Height; y++)
                {
                    if (grid.Weight[x, y] != 1) continue;

                    var d = BattleBoard.Sandbag.Pathfind(
                        new Point(x, y),
                        new Point((int)enemy.Avatar.Location.X, (int)enemy.Avatar.Location.Y)
                    ).Count();

                    if (d >= distance || d > 2 || BattleBoard.GetCharacterAt(new Point(x, y)) != null) continue;

                    decision.Destination = new Point(x, y);
                    distance = d;
                }
            }

            var ability = Ability.Factory(_game, "attack");
            ability.Character = character;

            // attack
            decision.Command = new Command
                {
                    Ability = ability,
                    Character = character,
                    Target = new Point((int)enemy.Avatar.Location.X, (int)enemy.Avatar.Location.Y)
                };

            return decision;
        }
        public void UpdateCharacter(Combatant character)
        {
            _defLevel.Text = (character.Stats[Stat.Defense] / 100).ToString();
            _attLevel.Text = (character.Stats[Stat.Attack] / 100).ToString();
            _wisLevel.Text = (character.Stats[Stat.Wisdom] / 100).ToString();
            _intLevel.Text = (character.Stats[Stat.Intelligence] / 100).ToString();
            _spdLevel.Text = (character.Stats[Stat.Speed] / 100).ToString();
            _hitLevel.Text = (character.Stats[Stat.Hit] / 100).ToString();

            _defProg.Progress = (character.Stats[Stat.Defense] % 100) / 100f;
            _attProg.Progress = (character.Stats[Stat.Attack] % 100) / 100f;
            _wisProg.Progress = (character.Stats[Stat.Wisdom] % 100) / 100f;
            _intProg.Progress = (character.Stats[Stat.Intelligence] % 100) / 100f;
            _spdProg.Progress = (character.Stats[Stat.Speed] % 100) / 100f;
            _hitProg.Progress = (character.Stats[Stat.Hit] % 100) / 100f;

            _defExp.Text = (character.Stats[Stat.Defense] % 100).ToString();
            _attExp.Text = (character.Stats[Stat.Attack] % 100).ToString();
            _wisExp.Text = (character.Stats[Stat.Wisdom] % 100).ToString();
            _intExp.Text = (character.Stats[Stat.Intelligence] % 100).ToString();
            _spdExp.Text = (character.Stats[Stat.Speed] % 100).ToString();
            _hitExp.Text = (character.Stats[Stat.Hit] % 100).ToString();
        }
Example #9
0
        /// <summary>
        /// Process a character that has been selected by the player, showing a radial menu of options.
        /// </summary>
        /// <param name="character">The character whose options are to be displayed.</param>
        public void SelectCharacter(Combatant character)
        {
            // if they clicked on the character already being shown, assume they want to close the menu
            if (character == _selectedCharacter)
            {
                DeselectCharacter();
                return;
            }

            // you can only click on your characters during your turn
            if (_state != BattleState.PlayerTurn) return;
            if (character.Faction != 0) return;

            if (_radialMenuControl != null)
            {
                Gui.Screen.Desktop.Children.Remove(_radialMenuControl);
                _radialMenuControl = null;
            }

            var menu = new RadialMenuControl(((IInputService)Game.Services.GetService(typeof(IInputService))).GetMouse())
                {
                    CenterX = (int)character.Avatar.Sprite.X + character.Avatar.Sprite.Width/2 - 10,
                    CenterY = (int)character.Avatar.Sprite.Y + character.Avatar.Sprite.Height/2,
                    OnExit = DeselectCharacter
                };

            // move icon, plus event handlers
            var icon = new RadialButtonControl {ImageFrame = "move", Bounds = new UniRectangle(0, 0, 64, 64)};
            if (character.CanMove)
            {
                icon.MouseOver += () =>
                    {
                        if (!character.CanMove) return;

                        _battleBoardLayer.SetTargettingGrid(
                            character.GetMovementGrid(BattleBoard.GetAccessibleGrid(character.Faction)),
                            new Grid(1, 1)
                            );
                    };
                icon.MouseOut += () => { if (_aimAbility == null) _battleBoardLayer.ResetGrid(); };
                icon.MouseClick += () => { SelectAbilityTarget(character, Ability.Factory(Game, "move"));
                                             _aimTime = DateTime.Now;
                };
            }
            else
            {

                // if they can't move, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }

            menu.AddOption("move", icon);

            //// attack icon, plus handlers
            icon = new RadialButtonControl { ImageFrame = "attack", Bounds = new UniRectangle(0, 0, 64, 64) };
            if (character.CanAct)
            {
                var ability = Ability.Factory(Game, "attack");
                ability.Character = character;

                icon.MouseOver += () =>
                    {
                        if (!character.CanAct) return;

                        _battleBoardLayer.SetTargettingGrid(
                            ability.GenerateTargetGrid(BattleBoard.Sandbag.Clone()),
                            new Grid(1, 1)
                            );
                    };
                icon.MouseOut += () => { if (_aimAbility == null) _battleBoardLayer.ResetGrid(); };

                icon.MouseRelease += () => { SelectAbilityTarget(character, ability);
                                               _aimTime = DateTime.Now;
                };
            }
            else
            {
                // if they can't act, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }

            menu.AddOption("attack", icon);

            //// special abilities icon, plus event handlers
            icon = new RadialButtonControl { ImageFrame = "special", Bounds = new UniRectangle(0, 0, 64, 64) };
            if (character.CanAct)
            {
                icon.MouseRelease += () => SelectSpecialAbility(character);
            }
            else
            {
                // if they can't act, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }
            menu.AddOption("special", icon);

            icon = new RadialButtonControl
                {ImageFrame = "item", Bounds = new UniRectangle(0, 0, 64, 64), Enabled = false};
            menu.AddOption("item", icon);

            _radialMenuControl = menu;
            Gui.Screen.Desktop.Children.Add(_radialMenuControl);

            _selectedCharacter = character;
            _state = BattleState.CharacterSelected;
        }
Example #10
0
 private void ChangeCharacter(Combatant combatant)
 {
     OnCharacterChange.Invoke(combatant);
 }
Example #11
0
        private void UpdateBattleStateEnemyTurn()
        {
            var combatants = (from c in BattleBoard.Characters where c.Faction == 1 && c.CanMove select c).ToArray();

            if (combatants.Any())
            {
                // find first character that can move
                _selectedCharacter = combatants[0];

                // find the optimal location
                var decision = _commander.CalculateAction(_selectedCharacter);

                // create move command to that location
                var moveCommand = new Command
                    {
                        Ability = Ability.Factory(Game, "move"),
                        Character = _selectedCharacter,
                        Target = decision.Destination
                    };

                QueuedCommands.Add(moveCommand);

                if (decision.Command.Ability != null)
                    QueuedCommands.Add(decision.Command);

                ExecuteQueuedCommands();

                return;
            }

            ExecuteQueuedCommands();

            // all enemy players have moved / attacked
            ChangeFaction(0);
        }
Example #12
0
        /// <summary>
        /// Show a list of special abilities that a character may use
        /// </summary>
        /// <param name="character">The character being selected for special abilities</param>
        /// <returns>An event handler to execute to show the abilities.</returns>
        private void SelectSpecialAbility(Combatant character)
        {
            // delete the current radial menu options, which should be move/attack/special/item for the character.
            // should.
            _radialMenuControl.ClearOptions();

            // go through each ability the character can currently use
            foreach (var ability in character.GetAbilities().Where(character.CanUseAbility).Where(a => a.AbilityType == AbilityType.Active))
            {
                var tempAbility = ability;

                var button = new RadialButtonControl
                    {ImageFrame = ability.ImageName, Bounds = new UniRectangle(0, 0, 64, 64), Enabled = false};

                // only bind event handlers onto abilities that are cheap enough to use
                if (ability.ManaCost <= character.CurrentMana)
                {
                    button.Enabled = true;
                    button.MouseOver = () => PreviewAbility(tempAbility);
                    button.MouseOut = () =>
                        {
                            if (_aimAbility != null) return;

                            HideGui(_abilityStatLayer);
                            _battleBoardLayer.ResetGrid();
                        };
                    button.MouseClick = () => { };
                    button.MouseRelease += () => { SelectAbilityTarget(character, tempAbility);
                                                     _aimTime = DateTime.Now;
                    };
                }
                else
                {
                    button.MouseRelease =  () => { };
                }

                _radialMenuControl.AddOption(ability.Name, button);
            }
        }
Example #13
0
        /// <summary>
        /// Create a callback function to process if the player chooses to have a character attack. This callback will display the targetting grid
        /// and bind _aimAbility to a function that queues an attack command from the character onto the target.
        /// </summary>
        /// <param name="character">The character whose attack is being chosen.</param>
        /// <param name="ability">The ability currently being aimed.</param>
        /// <returns></returns>
        private void SelectAbilityTarget(Combatant character, Ability ability)
        {
            _state = BattleState.AimingAbility;
            Gui.Screen.Desktop.Children.Remove(_radialMenuControl);

            _battleBoardLayer.SetTargettingGrid(
                ability.Name == "Move" ?
                    character.GetMovementGrid(BattleBoard.GetAccessibleGrid(character.Faction)) :
                    ability.GenerateTargetGrid(BattleBoard.Sandbag.Clone()),
                ability.GenerateImpactGrid()
            );

            _battleBoardLayer.AbilityAim = true;

            _aimAbility = (x, y) =>
                {
                    // only target enemies with angry spells and allies with friendly spells
                    if (!ability.CanTarget(BattleBoard.IsOccupied(new Point(x, y))))
                        return false;

                    character.Avatar.UpdateVelocity(x - character.Avatar.Location.X, y - character.Avatar.Location.Y);
                    character.Avatar.UpdateVelocity(0, 0);

                    // make sure the ability knows who is casting it. this probably shouldn't
                    // be done here, but there are issues doing it elsewhere.
                    ability.Character = character;

                    var command = new Command
                        {
                            Character = character,
                            Target = new Point(x, y),
                            Ability = ability
                        };

                    if(ability.Name == "Move")
                    {
                        ExecuteCommand(command);
                        return true;
                    }

                    character.CanAct = false;
                    QueuedCommands.Add(command);
                    _queuedCommands.UpdateControls();
                    _state = BattleState.Delay;
                    _delayState = BattleState.PlayerTurn;
                    _delayTimer = 0.05F;
                    ResetState();

                    return true;
                };
        }
Example #14
0
 /// <summary>
 /// General purpose function during PlayerTurn state to undo various options and settings
 /// and hide panels.
 /// </summary>
 private void ResetState()
 {
     _battleBoardLayer.ResetGrid();
     _aimAbility = null;
     _selectedCharacter = null;
     HideCharacterStats();
     HideGui(_abilityStatLayer);
 }
Example #15
0
        /// <summary>
        /// Display a HUD element indicating basic stats for a specified character
        /// </summary>
        /// <param name="character">The character to be shown.</param>
        public void ShowCharacterStats(Combatant character)
        {
            if (_state != BattleState.PlayerTurn && _state != BattleState.AimingAbility) return;

            _characterStats.SetCharacter(character);
            ShowGui(_characterStats);
        }
Example #16
0
        private void ChangeItem(Combatant character, ItemEquipType type)
        {
            if (_changingItem) return;
            _changingItem = true;

            var dialog = new ChangeItemDialog();
            dialog.Bounds = new UniRectangle(
                new UniScalar(0.5f, 0 - 100), new UniScalar(0.5f, 0 - 200),
                200, 400
            );
            var items = new List<Item>();
            var inventory = ((SRPGGame) Game).Inventory;
            foreach(var item in inventory)
            {
                switch(type)
                {
                    case ItemEquipType.Armor:
                        if (character.CanEquipArmor(item)) items.Add(item);
                        break;
                    case ItemEquipType.Weapon:
                        if (character.CanEquipWeapon(item)) items.Add(item);
                        break;
                    case ItemEquipType.Accessory:
                        items.Add(item);
                        break;
                }
            }
            dialog.SetItems(items);
            _characterInfoDialog.Children.Add(dialog);
            dialog.BringToFront();

            dialog.ItemSelected += i =>
                {
                    inventory.Remove(i);
                    inventory.Add(character.EquipItem(i));
                    SetCharacter(character);
                    dialog.Close();
                    _changingItem = false;
                };

            dialog.ItemCancelled += () =>
                {
                    dialog.Close();
                    _changingItem = false;
                };
        }
Example #17
0
 public void SetCharacter(Combatant character)
 {
     _characterInfoDialog.SetCharacter(character);
     ShowGui(_characterInfoDialog);
 }
Example #18
0
        /// <summary>
        /// Load a specified file number.
        /// </summary>
        /// <param name="game">the game being loaded</param>
        /// <param name="fileNumber">The file number to be loaded.</param>
        public static SaveGame Load(SRPGGame game, int fileNumber)
        {
            var save = new SaveGame()
            {
                Number = fileNumber
            };

            var filename = string.Format(
                "{0}\\Armadillo\\Save\\save{1}.asg",
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                fileNumber
                );

            if (File.Exists(filename) == false)
            {
                throw new Exception("file does not exist, can't load");
            }

            var r = new BinaryReader(File.OpenRead(filename));

            var guid     = r.ReadBytes(16);
            var filetype = r.ReadInt16();
            var version  = r.ReadInt16();

            // confirm the file is correct
            if (!guid.SequenceEqual(Guid) || filetype != 1 || version != 1)
            {
                throw new Exception("file is not in correct format");
            }

            // skip save date
            r.ReadInt64();
            save.Name     = r.ReadString();
            save.GameTime = r.ReadInt64();
            save.Zone     = r.ReadString();
            save.Door     = r.ReadString();

            // how many party members (16-bit int)
            var partyCount = r.ReadInt16();

            for (var i = 0; i < partyCount; i++)
            {
                // name (length-prefixed string)
                var character = Combatant.FromTemplate(game, "party/" + r.ReadString().ToLower());

                // stat xp levels - dawish + hp/mp (32-bit int)
                character.Stats[Stat.Health]       = r.ReadInt32();
                character.Stats[Stat.Mana]         = r.ReadInt32();
                character.Stats[Stat.Defense]      = r.ReadInt32();
                character.Stats[Stat.Attack]       = r.ReadInt32();
                character.Stats[Stat.Wisdom]       = r.ReadInt32();
                character.Stats[Stat.Intelligence] = r.ReadInt32();
                character.Stats[Stat.Speed]        = r.ReadInt32();
                character.Stats[Stat.Hit]          = r.ReadInt32();

                character.AbilityExperienceLevels.Clear();

                var abilityCount = r.ReadInt16();
                for (var j = 0; j < abilityCount; j++)
                {
                    var ability = Ability.Factory(game, r.ReadString());
                    character.AbilityExperienceLevels.Add(ability, r.ReadInt32());
                }

                character.EquipItem(Item.Factory(game, r.ReadString()));
                character.EquipItem(Item.Factory(game, r.ReadString()));
                //character.EquipItem(Item.Factory(game, r.ReadString()));

                save.Party.Add(character);
            }

            save.Money = r.ReadInt32();


            var inventoryCount = r.ReadInt16();

            for (var i = 0; i < inventoryCount; i++)
            {
                var item = Item.Factory(game, r.ReadString());
                // todo process quantity properly
                r.ReadInt16();
                save.Inventory.Add(item);
            }

            var roomCount = r.ReadInt32();

            for (var i = 0; i < roomCount; i++)
            {
                var roomName     = r.ReadString();
                var roomDataSize = r.ReadInt32();
                var roomData     = r.ReadBytes(roomDataSize);
                save.RoomDetails.Add(roomName, roomData);
            }

            /*
             * // number of battles completed (16-bit int)
             * binaryWriter.Write(BattlesCompleted.Count);
             * // foreach battle
             * foreach (var battle in BattlesCompleted)
             * {
             *  //   battle name (length-prefixed string)
             *  binaryWriter.Write(battle.Key);
             *  //   score (32-bit int)
             *  binaryWriter.Write(battle.Value);
             *
             * }
             * // 64 bit tutorial details
             * binaryWriter.Write(TutorialsCompleted);
             */
            r.Close();

            return(save);
        }
Example #19
0
        /// <summary>
        /// Generate a combatant based on a predefined template
        /// </summary>
        /// <param name="template">Template to be used to generate a combatant</param>
        /// <param name="level">Experience level to be applied to this combatant's skills</param>
        /// <returns>A combatant generated from the template, modified to be at the specified level.</returns>
        public static Combatant FromTemplate(Microsoft.Xna.Framework.Game game, string template)
        {
            var combatant = new Combatant(game);

            var templateType = template.Split('/')[0];
            var templateName = template.Split('/')[1];

            string settingString = String.Join("\r\n", File.ReadAllLines("Content/Battle/Combatants/" + templateType + ".js"));

            var nodeList = JObject.Parse(settingString);

            if (nodeList[templateName].SelectToken("name") != null)
                combatant.Name = nodeList[templateName]["name"].ToString();
            combatant.Class = nodeList[templateName]["class"].ToString();
            combatant.Avatar = Avatar.GenerateAvatar(game, null, nodeList[templateName]["avatar"].ToString());

            if (nodeList[templateName].SelectToken("icon") != null)
                combatant.Avatar.Icon = (nodeList[templateName]["icon"]).ToString();

            combatant.CurrentHealth = (int)(nodeList[templateName]["health"]);
            combatant.MaxHealth = (int)(nodeList[templateName]["health"]);
            combatant.CurrentMana = (int)(nodeList[templateName]["mana"]);
            combatant.MaxMana = (int)(nodeList[templateName]["mana"]);

            combatant.ArmorTypes = Item.StringToItemType(nodeList[templateName]["armortype"].ToString());
            combatant.WeaponTypes = Item.StringToItemType(nodeList[templateName]["weapontype"].ToString());

            combatant.Inventory = nodeList[templateName]["inventory"].Select(item => Item.Factory(game, item.ToString())).ToList();

            combatant.Stats = new Dictionary<Stat, int>
                {
                    {Stat.Health, 0},
                    {Stat.Mana, 0},
                    {Stat.Defense, (int)(nodeList[templateName]["stats"]["defense"])},
                    {Stat.Attack, (int)(nodeList[templateName]["stats"]["attack"])},
                    {Stat.Wisdom, (int)(nodeList[templateName]["stats"]["wisdom"])},
                    {Stat.Intelligence, (int)(nodeList[templateName]["stats"]["intelligence"])},
                    {Stat.Speed, (int)(nodeList[templateName]["stats"]["speed"])},
                    {Stat.Hit, (int)(nodeList[templateName]["stats"]["hit"])},
                };

            combatant.AbilityExperienceLevels = nodeList[templateName]["abilities"].ToDictionary(
                ability => Ability.Factory(game, ability["name"].ToString()),
                ability => (int) ability["experience"]
            );

            return combatant;
        }
Example #20
0
 public void RemoveCharacter(Combatant character)
 {
     Components.Remove(_characters[character.Name]);
     _characters.Remove(character.Name);
 }