Procházet zdrojové kódy

RPG: Fix Spells and add Shadows and fix offsets.

CartBlanche před 1 měsícem
rodič
revize
25d2f1026e

+ 14 - 1
RolePlayingGame/Core/Session/Session.cs

@@ -1368,12 +1368,18 @@ namespace RolePlaying
         /// </summary>
         private void DrawShadows(SpriteBatch spriteBatch)
         {
+            var shadowXOffset = 20;
+            var shadowYOffset = 20;
+
             // draw the shadow of the party leader
             Player player = party.Players[0];
             if (player.ShadowTexture != null)
             {
+                var position = TileEngine.PartyLeaderPosition.ScreenPosition;
+                position.X -= shadowXOffset;
+                position.Y -= shadowYOffset;
                 spriteBatch.Draw(player.ShadowTexture,
-                    TileEngine.PartyLeaderPosition.ScreenPosition, null, Color.White, 0f,
+                    position, null, Color.White, 0f,
                     new Vector2(
                         (player.ShadowTexture.Width - TileEngine.Map.TileSize.X) / 2,
                         (player.ShadowTexture.Height - TileEngine.Map.TileSize.Y) / 2 -
@@ -1392,6 +1398,8 @@ namespace RolePlaying
                 {
                     Vector2 position =
                         TileEngine.GetScreenPosition(playerEntry.MapPosition);
+                    position.X -= shadowXOffset;
+                    position.Y -= shadowYOffset;
                     spriteBatch.Draw(playerEntry.Content.ShadowTexture, position,
                         null, Color.White, 0f,
                         new Vector2(
@@ -1415,6 +1423,8 @@ namespace RolePlaying
                 {
                     Vector2 position =
                         TileEngine.GetScreenPosition(questNpcEntry.MapPosition);
+                    position.X -= shadowXOffset;
+                    position.Y -= shadowYOffset;
                     spriteBatch.Draw(questNpcEntry.Content.ShadowTexture, position,
                         null, Color.White, 0f,
                         new Vector2(
@@ -1441,6 +1451,9 @@ namespace RolePlaying
                 {
                     Vector2 position =
                         TileEngine.GetScreenPosition(fixedCombatEntry.MapPosition);
+                    position.X -= shadowXOffset;
+                    position.Y -= shadowYOffset;
+
                     spriteBatch.Draw(monster.ShadowTexture, position,
                         null, Color.White, 0f,
                         new Vector2(

+ 25 - 42
RolePlayingGame/RolePlayingGameData/Characters/CharacterClass.cs

@@ -185,60 +185,48 @@ namespace RolePlaying.Data
             return spells;
         }
 
-        internal static CharacterClass Load(string path)
+        internal static CharacterClass Load(string characterAssetName, ContentManager contentManager)
         {
-            var asset = XmlHelper.GetAssetElementFromXML(path);
+            var characterAsset = XmlHelper.GetAssetElementFromXML(characterAssetName);
 
             var characterClass = new CharacterClass
             {
-                Name = (string)asset.Element("Name"),
+                Name = (string)characterAsset.Element("Name"),
                 InitialStatistics = new StatisticsValue
                 {
-                    HealthPoints = (int?)asset.Element("InitialStatistics").Element("HealthPoints") ?? 0,
-                    MagicPoints = (int?)asset.Element("InitialStatistics").Element("MagicPoints") ?? 0,
-                    PhysicalOffense = (int?)asset.Element("InitialStatistics").Element("PhysicalOffense") ?? 0,
-                    PhysicalDefense = (int?)asset.Element("InitialStatistics").Element("PhysicalDefense") ?? 0,
-                    MagicalOffense = (int?)asset.Element("InitialStatistics").Element("MagicalOffense") ?? 0,
-                    MagicalDefense = (int?)asset.Element("InitialStatistics").Element("MagicalDefense") ?? 0,
+                    HealthPoints = (int?)characterAsset.Element("InitialStatistics").Element("HealthPoints") ?? 0,
+                    MagicPoints = (int?)characterAsset.Element("InitialStatistics").Element("MagicPoints") ?? 0,
+                    PhysicalOffense = (int?)characterAsset.Element("InitialStatistics").Element("PhysicalOffense") ?? 0,
+                    PhysicalDefense = (int?)characterAsset.Element("InitialStatistics").Element("PhysicalDefense") ?? 0,
+                    MagicalOffense = (int?)characterAsset.Element("InitialStatistics").Element("MagicalOffense") ?? 0,
+                    MagicalDefense = (int?)characterAsset.Element("InitialStatistics").Element("MagicalDefense") ?? 0,
                 },
                 LevelingStatistics = new CharacterLevelingStatistics
                 {
-                    HealthPointsIncrease = (int?)asset.Element("LevelingStatistics").Element("HealthPointsIncrease") ?? 0,
-                    LevelsPerHealthPointsIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerHealthPointsIncrease") ?? 0,
-                    MagicPointsIncrease = (int?)asset.Element("LevelingStatistics").Element("MagicPointsIncrease") ?? 0,
-                    LevelsPerMagicPointsIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerMagicPointsIncrease") ?? 0,
-                    PhysicalOffenseIncrease = (int?)asset.Element("LevelingStatistics").Element("PhysicalOffenseIncrease") ?? 0,
-                    LevelsPerPhysicalOffenseIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerPhysicalOffenseIncrease") ?? 0,
-                    PhysicalDefenseIncrease = (int?)asset.Element("LevelingStatistics").Element("PhysicalDefenseIncrease") ?? 0,
-                    LevelsPerPhysicalDefenseIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerPhysicalDefenseIncrease") ?? 0,
-                    MagicalOffenseIncrease = (int?)asset.Element("LevelingStatistics").Element("MagicalOffenseIncrease") ?? 0,
-                    LevelsPerMagicalOffenseIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerMagicalOffenseIncrease") ?? 0,
-                    MagicalDefenseIncrease = (int?)asset.Element("LevelingStatistics").Element("MagicalDefenseIncrease") ?? 0,
-                    LevelsPerMagicalDefenseIncrease = (int?)asset.Element("LevelingStatistics").Element("LevelsPerMagicalDefenseIncrease") ?? 0,
+                    HealthPointsIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("HealthPointsIncrease") ?? 0,
+                    LevelsPerHealthPointsIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerHealthPointsIncrease") ?? 0,
+                    MagicPointsIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("MagicPointsIncrease") ?? 0,
+                    LevelsPerMagicPointsIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerMagicPointsIncrease") ?? 0,
+                    PhysicalOffenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("PhysicalOffenseIncrease") ?? 0,
+                    LevelsPerPhysicalOffenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerPhysicalOffenseIncrease") ?? 0,
+                    PhysicalDefenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("PhysicalDefenseIncrease") ?? 0,
+                    LevelsPerPhysicalDefenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerPhysicalDefenseIncrease") ?? 0,
+                    MagicalOffenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("MagicalOffenseIncrease") ?? 0,
+                    LevelsPerMagicalOffenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerMagicalOffenseIncrease") ?? 0,
+                    MagicalDefenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("MagicalDefenseIncrease") ?? 0,
+                    LevelsPerMagicalDefenseIncrease = (int?)characterAsset.Element("LevelingStatistics").Element("LevelsPerMagicalDefenseIncrease") ?? 0,
                 },
-                LevelEntries = asset.Element("LevelEntries")
+                LevelEntries = characterAsset.Element("LevelEntries")
                     .Elements("Item")
-                    .Select(item => new CharacterLevelDescription
-                    {
-                        ExperiencePoints = (int?)item.Element("ExperiencePoints") ?? 0,
-                        SpellContentNames = item.Element("SpellContentNames")?
-                            .Elements("Item")
-                            .Select(x => (string)x)
-                            .ToList() ?? new List<string>()
-                    })
+                    .Select(item => CharacterLevelDescription.Load(item, contentManager))
                     .ToList(),
-                BaseExperienceValue = (int?)asset.Element("BaseExperienceValue") ?? 0,
-                BaseGoldValue = (int?)asset.Element("BaseGoldValue") ?? 0
+                BaseExperienceValue = (int?)characterAsset.Element("BaseExperienceValue") ?? 0,
+                BaseGoldValue = (int?)characterAsset.Element("BaseGoldValue") ?? 0
             };
 
             return characterClass;
         }
 
-
-
-
-
-
         /// <summary>
         /// The base experience value of Npcs of this character class.
         /// </summary>
@@ -272,11 +260,6 @@ namespace RolePlaying.Data
             set { baseGoldValue = value; }
         }
 
-
-
-
-
-
         /// <summary>
         /// Reads a CharacterClass object from the content pipeline.
         /// </summary>

+ 31 - 7
RolePlayingGame/RolePlayingGameData/Characters/CharacterLevelDescription.cs

@@ -7,6 +7,9 @@
 
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Xml.Linq;
 using Microsoft.Xna.Framework.Content;
 
 namespace RolePlaying.Data
@@ -68,16 +71,11 @@ namespace RolePlaying.Data
             get { return spells; }
             set { spells = value; }
         }
-        
-
-
-
-
 
         /// <summary>
         /// Read a CharacterLevelDescription object from the content pipeline.
         /// </summary>
-        public class CharacterLevelDescriptionReader : 
+        public class CharacterLevelDescriptionReader :
             ContentTypeReader<CharacterLevelDescription>
         {
             /// <summary>
@@ -106,6 +104,32 @@ namespace RolePlaying.Data
             }
         }
 
+        internal static CharacterLevelDescription Load(XElement item, ContentManager contentManager)
+        {
+            var characterLevelDescription = new CharacterLevelDescription
+            {
+                ExperiencePoints = (int?)item.Element("ExperiencePoints") ?? 0,
+                SpellContentNames = item.Element("SpellContentNames")?
+                    .Elements("Item")
+                    .Select(x =>
+                    {
+                        return (string)x;
+                    })
+                    .ToList() ?? new List<string>(),
+            };
+
+            if (characterLevelDescription.SpellContentNames.Count > 0)
+            {
+                // Load the spells for this level
+                characterLevelDescription.Spells = new List<Spell>();
+                foreach (var spellContentName in characterLevelDescription.SpellContentNames)
+                {
+                    var spell = Spell.Load(System.IO.Path.Combine("Spells", spellContentName), contentManager);
+                    characterLevelDescription.Spells.Add(spell);
+                }
+            }
 
+            return characterLevelDescription;
+        }
     }
-}
+}

+ 2 - 1
RolePlayingGame/RolePlayingGameData/Characters/Monster.cs

@@ -115,7 +115,8 @@ namespace RolePlaying.Data
                     }).ToList()
             };
 
-            monster.CharacterClass = CharacterClass.Load(Path.Combine("CharacterClasses", monster.CharacterClassContentName));
+            monster.CharacterClass = CharacterClass.Load(Path.Combine("CharacterClasses", monster.CharacterClassContentName), contentManager);
+            monster.ShadowTexture = contentManager.Load<Texture2D>(@"Textures\Characters\CharacterShadow");
 
             monster.AddStandardCharacterCombatAnimations();
             monster.AddStandardCharacterIdleAnimations();

+ 2 - 2
RolePlayingGame/RolePlayingGameData/Characters/Player.cs

@@ -346,7 +346,7 @@ namespace RolePlaying.Data
             };
 
             // load the character class
-            player.CharacterClass = CharacterClass.Load(Path.Combine("CharacterClasses", player.CharacterClassContentName));
+            player.CharacterClass = CharacterClass.Load(Path.Combine("CharacterClasses", player.CharacterClassContentName), contentManager);
             foreach (var item in player.InitialEquipmentContentNames)
             {
                 player.EquippedEquipment.Add(Equipment.Load(Path.Combine(@"Gear", item), contentManager));
@@ -358,7 +358,7 @@ namespace RolePlaying.Data
 
             player.ResetAnimation(false);
 
-            // TODO Looks like player is floating. Offset issue.player.ShadowTexture = contentManager.Load<Texture2D>(@"Textures\Characters\CharacterShadow");
+            player.ShadowTexture = contentManager.Load<Texture2D>(@"Textures\Characters\CharacterShadow");
 
             return player;
         }

+ 1 - 1
RolePlayingGame/RolePlayingGameData/Characters/QuestNpc.cs

@@ -55,7 +55,7 @@ namespace RolePlaying.Data
 
             questNpc.ResetAnimation(false);
 
-            // TODO Looks like player is floating. Offset issue. questNpc.ShadowTexture = contentManager.Load<Texture2D>(@"Textures\Characters\CharacterShadow");
+            questNpc.ShadowTexture = contentManager.Load<Texture2D>(@"Textures\Characters\CharacterShadow");
 
             return questNpc;
         }

+ 36 - 6
RolePlayingGame/RolePlayingGameData/Spell.cs

@@ -188,7 +188,7 @@ namespace RolePlaying.Data
         public int Level
         {
             get { return level; }
-            set 
+            set
             {
                 level = value;
                 targetEffectRange = initialTargetEffectRange;
@@ -311,8 +311,8 @@ namespace RolePlaying.Data
         {
             get { return iconTexture; }
         }
-        
-        
+
+
         /// <summary>
         /// The animating sprite used when this spell is in action.
         /// </summary>
@@ -373,7 +373,7 @@ namespace RolePlaying.Data
                     System.IO.Path.Combine(@"Textures\Spells", spell.IconTextureName));
                 spell.IsOffensive = input.ReadBoolean();
                 spell.TargetDuration = input.ReadInt32();
-                spell.targetEffectRange = spell.InitialTargetEffectRange = 
+                spell.targetEffectRange = spell.InitialTargetEffectRange =
                     input.ReadObject<StatisticsRange>();
                 spell.AdjacentTargets = input.ReadInt32();
                 spell.LevelingProgression = input.ReadObject<StatisticsValue>();
@@ -387,7 +387,7 @@ namespace RolePlaying.Data
                     spell.SpellSprite.FrameDimensions.Y);
                 spell.Overlay = input.ReadObject<AnimatingSprite>();
                 spell.Overlay.SourceOffset = new Vector2(
-                    spell.Overlay.FrameDimensions.X / 2, 
+                    spell.Overlay.FrameDimensions.X / 2,
                     spell.Overlay.FrameDimensions.Y);
 
                 spell.Level = 1;
@@ -428,6 +428,36 @@ namespace RolePlaying.Data
             return spell;
         }
 
+        internal static Spell Load(string spellAssetName, ContentManager contentManager)
+        {
+            var asset = XmlHelper.GetAssetElementFromXML(spellAssetName);
+            var spell = new Spell()
+            {
+                AssetName = spellAssetName,
+                Name = asset.Element("Name")?.Value ?? "Unknown Spell",
+                Description = asset.Element("Description")?.Value ?? "No Description",
+                MagicPointCost = int.Parse(asset.Element("MagicPointCost")?.Value ?? "0"),
+                IconTextureName = asset.Element("IconTextureName")?.Value ?? "UnknownIcon",
+                iconTexture = contentManager.Load<Texture2D>(
+                    System.IO.Path.Combine(@"Textures\Spells", asset.Element("IconTextureName").Value)),
+                IsOffensive = bool.Parse(asset.Element("IsOffensive")?.Value ?? "false"),
+                TargetDuration = int.Parse(asset.Element("TargetDuration")?.Value ?? "0"),
+                /*targetEffectRange = StatisticsRange.FromString(
+                    asset.Element("TargetEffectRange")?.Value ?? "0");
+                initialTargetEffectRange = targetEffectRange;*/
+                AdjacentTargets = int.Parse(asset.Element("AdjacentTargets")?.Value ?? "0"),
+                /*LevelingProgression = StatisticsValue.FromString(
+                    asset.Element("LevelingProgression")?.Value ?? "0");*/
+                CreatingCueName = asset.Element("CreatingCueName")?.Value ?? "UnknownCue",
+                TravelingCueName = asset.Element("TravelingCueName")?.Value ?? "UnknownCue",
+                ImpactCueName = asset.Element("ImpactCueName")?.Value ?? "UnknownCue",
+                BlockCueName = asset.Element("BlockCueName")?.Value ?? "UnknownCue",
+                SpellSprite = asset.Element("SpellSprite") != null ? AnimatingSprite.Load(asset.Element("SpellSprite"), contentManager) : null,
+                Overlay = asset.Element("Overlay") != null ? AnimatingSprite.Load(asset.Element("Overlay"), contentManager) : null,
+                Level = int.Parse(asset.Element("Level")?.Value ?? "1")
+            };
 
+            return spell;
+        }
     }
-}
+}