예제 #1
0
        public override List <Race> GetAllRecords()
        {
            var races = new List <Race>();

            List <RaceMD> rawData = MDFileReader.FileReader <RaceMD>(MDFiles.RACES_FILE);

            if (rawData == null)
            {
                Console.WriteLine($"Unable to read file {MDFiles.RACES_FILE} - not parsing Races");
                return(races);
            }

            foreach (RaceMD race in rawData)
            {
                Race newRace = new Race()
                {
                    ID                       = race.RaceId,
                    Name                     = race.RaceName,
                    MinimumStrength          = race.MinimumStrength,
                    MaximumStrength          = race.MaximumStrength,
                    MinimumIntellect         = race.MinimumIntellect,
                    MaximumIntellect         = race.MaximumIntellect,
                    MinimumWillpower         = race.MinimumWillpower,
                    MaximumWillpower         = race.MaximumWillpower,
                    MinimumAgility           = race.MinimumAgility,
                    MaximumAgility           = race.MaximumAgility,
                    MinimumHealth            = race.MinimumHealth,
                    MaximumHealth            = race.MaximumHealth,
                    MinimumCharm             = race.MinimumCharm,
                    MaximumCharm             = race.MaximumCharm,
                    HitpointModifierPerLevel = race.HitpointModifierPerLevel,
                    ExperiencePercentage     = race.ExperiencePercentage,
                    AbilitiesAndMods         = new Dictionary <Race.AbilitiesAndModifiers, short>(),
                };

                // Abilities and Mods
                for (int i = 0; i < 8; i++)
                {
                    byte[] abilityBytes       = race.AbilityKeys.Skip(i * 2).Take(2).ToArray();
                    byte[] abilityValuesBytes = race.AbilityValues.Skip(i * 2).Take(2).ToArray();

                    var abilityCode      = BitConverter.ToUInt16(abilityBytes, 0);
                    var abilityValueCode = BitConverter.ToInt16(abilityValuesBytes, 0);

                    // If the ability is zero, the value is zero or garbage, so ignore it
                    if (abilityCode != 0)
                    {
                        newRace.AbilitiesAndMods.Add((Race.AbilitiesAndModifiers)abilityCode, abilityValueCode);
                    }
                }

                races.Add(newRace);
            }

            return(races);
        }
예제 #2
0
        public override List <IRecord> GetAllRecords()
        {
            var classes = new List <IRecord>();

            List <ClassMD> rawData = MDFileReader.FileReader <ClassMD>(MDFiles.CLASSES_FILE);

            if (rawData == null)
            {
                Console.WriteLine($"Unable to read file {MDFiles.CLASSES_FILE} - not parsing Classes");
                return(classes);
            }

            foreach (ClassMD cls in rawData)
            {
                Class newClass = new Class()
                {
                    ID   = cls.ClassId,
                    Name = cls.ClassName,
                    ExperiencePercentage = BitConverter.ToUInt16(cls.ExperienceBase, 0),
                    Combat = cls.CombatLevel,
                    HitpointPerLevelMinimum = cls.MinHPPerLevel,
                    HitpointPerLevelMaximum = cls.MaxHPPerLevel,
                    WeaponType       = (Class.WeaponClasses)cls.WeaponsUsable,
                    ArmorType        = (Class.ArmorClasses)cls.ArmorUseable,
                    MagicLevel       = cls.MagicLevel,
                    MagicType        = (Class.MagicTypes)cls.MagicLevel,
                    AbilitiesAndMods = new Dictionary <Common.Abilities, short>()
                };

                // Abilities and Mods
                for (int i = 0; i < Common.MAX_NUMBER_OF_ABILITIES; i++)
                {
                    byte[] abilityBytes       = cls.AbilityKeys.Skip(i * 2).Take(2).ToArray();
                    byte[] abilityValuesBytes = cls.AbilityValues.Skip(i * 2).Take(2).ToArray();

                    Array.Reverse(abilityBytes);
                    Array.Reverse(abilityValuesBytes);

                    var abilityCode      = BitConverter.ToUInt16(abilityBytes, 0);
                    var abilityValueCode = BitConverter.ToInt16(abilityValuesBytes, 0);


                    var ability = (Common.Abilities)abilityCode;
                    if (ability != Common.Abilities.NoAbility)
                    {
                        newClass.AbilitiesAndMods.Add(ability, abilityValueCode);
                    }
                }

                classes.Add(newClass);
            }

            return(classes);
        }
예제 #3
0
        public override List <T> GetAllRecords()
        {
            List <string> roomLines = MDFileReader.RoomsFileReader(MDFiles.ROOMS_FILE);

            var rooms = new List <T>();

            foreach (string roomLine in roomLines)
            {
                // Room format:  CAB00180:00004040:0:0:0:AALY:Ancient Ruin:Ancient Ruin Dark Alley
                string[] roomParts           = roomLine.Split(':');
                string   ChecksumAndExits    = roomParts[0];
                string   RoomFlags           = roomParts[1];
                string   MinimumLevel        = roomParts[2];
                string   MaximumLevel        = roomParts[3];
                string   RestrictedToClassId = roomParts[4];
                string   AbbrevCode          = roomParts[5];
                string   Group = roomParts[6];
                string   Name  = roomParts[7];

                string Checksum = ChecksumAndExits.Substring(0, 3);
                string Exits    = ChecksumAndExits.Substring(3);

                Room r = new Room()
                {
                    Checksum            = Checksum,
                    AvailableExits      = (Room.Exits)Enum.Parse(typeof(Room.Exits), Exits),
                    RoomFlags           = (Room.Flags)Enum.Parse(typeof(Room.Flags), RoomFlags),
                    MinimumLevel        = int.Parse(MinimumLevel),
                    MaximumLevel        = int.Parse(MaximumLevel),
                    RestrictedToClassID = int.Parse(RestrictedToClassId),
                    Code  = AbbrevCode,
                    Group = Group,
                    Name  = Name,
                };

                rooms.Add((T)r);
            }

            return(rooms);
        }
예제 #4
0
        public override List <Monster> GetAllRecords()
        {
            var monsters = new List <Monster>();

            List <MonsterMD> rawData = MDFileReader.FileReader <MonsterMD>(MDFiles.MONSTERS_FILE);

            if (rawData == null)
            {
                Console.WriteLine($"Unable to read file {MDFiles.MONSTERS_FILE} - not parsing Monsters");
                return(monsters);
            }

            foreach (MonsterMD monster in rawData)
            {
                Monster newMonster = new Monster()
                {
                    ID                  = monster.MonsterId,
                    Name                = monster.MonsterName,
                    AttackPriority      = (Monster.Priority)monster.AttackPriority,
                    Attack              = (Monster.AttackType)monster.AttackModifiers,
                    MonsterRelationship = (Monster.Relationship)monster.FearLevel,
                    PreAttackSpell      = monster.PreattackSpellCode,
                    AttackSpell         = monster.AttackSpellCode,
                    Sex                 = (Monster.Gender)monster.SexFlag,
                    Level               = monster.MonsterLevel,
                    Hitpoints           = monster.Hitpoints,
                    Energy              = monster.Energy,
                    MagicResistance     = monster.MagicResistance,
                    Accuracy            = monster.Accuracy,
                    ArmorClass          = monster.ArmorClass,
                    DamageReduction     = monster.DamageReduction,
                    EnslaveLevel        = monster.EnslaveLevel,
                };

                monsters.Add(newMonster);
            }

            return(monsters);
        }
예제 #5
0
        public override List <Spell> GetAllRecords()
        {
            var spells = new List <Spell>();

            List <SpellMD> rawData = MDFileReader.FileReader <SpellMD>(MDFiles.SPELLS_FILE);

            if (rawData == null)
            {
                Console.WriteLine($"Unable to read file {MDFiles.SPELLS_FILE} - not parsing Spells");
                return(spells);
            }

            foreach (SpellMD spell in rawData)
            {
                Spell newSpell = new Spell()
                {
                    ID              = spell.SpellId,
                    Name            = spell.SpellName,
                    Code            = spell.Abbreviation,
                    Flag            = (Spell.SpellFlag)spell.Flags,
                    Command         = spell.Command,
                    Level           = spell.Level,
                    LevelMultiplier = spell.LevelMultiplier,
                    Mana            = spell.ManaCost,
                    EnergyUsed      = spell.EnergyCost,
                    MinimumDamage   = spell.MinimumDamage,
                    MaximumDamage   = spell.MaximumDamage,
                    Duration        = spell.DurationInRounds,
                    Chance          = spell.SCModifier,
                    AreaOfEffect    = (Spell.AreaOfEffectType)spell.AreaOfEffect,
                    Type            = (Spell.SpellType)spell.Type,
                    SpellClass      = (Spell.SpellClasses)spell.SpellClass,
                    LearnedFromItem = spell.LearnedFromItemId,
                    MaximumLevel    = spell.MaximumLevel,
                    LevelDivider    = spell.LevelDivider,
                    UseLevel        = spell.UseLevel, // What is this actually used for?
                    IncEvery        = spell.IncEvery, // What is this actually used for?
                    CastingType     = spell.CastType == 0x03 ? Spell.CastType.Immediate : Spell.CastType.PerRound,
                };

                // Abilities and Mods
                for (int i = 0; i < Common.MAX_NUMBER_OF_ABILITIES; i++)
                {
                    byte[] abilityBytes       = spell.AbilityKeys.Skip(i * 2).Take(2).ToArray();
                    byte[] abilityValuesBytes = spell.AbilityValues.Skip(i * 2).Take(2).ToArray();

                    var abilityCode      = BitConverter.ToUInt16(abilityBytes, 0);
                    var abilityValueCode = BitConverter.ToInt16(abilityValuesBytes, 0);

                    // If the ability is zero, the value is zero or garbage, so ignore it
                    if (abilityCode == 0)
                    {
                        continue;
                    }

                    var ability = (Common.Abilities)abilityCode;

                    if (ability == Common.Abilities.RemoveSpell)
                    {
                        newSpell.RemovesSpell.Add((ushort)abilityValueCode);
                    }
                    else if (ability == Common.Abilities.TerminateSpell)
                    {
                        newSpell.TerminatesSpell.Add((ushort)abilityValueCode);
                    }
                    else if (ability == Common.Abilities.SummonCreature)
                    {
                        newSpell.SummonsCreature.Add((ushort)abilityValueCode);
                    }
                    else if (ability == Common.Abilities.TriggerTextblock)
                    {
                        newSpell.TriggersTextblock.Add((ushort)abilityValueCode);
                    }
                    else if (ability == Common.Abilities.DescriptionMessage)
                    {
                        newSpell.DescriptionMessages.Add((ushort)abilityValueCode);
                    }
                    else if (newSpell.AbilitiesAndMods.TryGetValue(ability, out short currentValue))
                    {
                        if (currentValue != abilityValueCode)
                        {
                            // Spell out archway temp already has the ability NightVision with value 1.  Skipping new value -1
                            Console.WriteLine($"Spell {newSpell.Name} already has the ability {ability} with value {newSpell.AbilitiesAndMods[ability]}.  Skipping new value {abilityValueCode}");
                        }
                    }
                    else
                    {
                        newSpell.AbilitiesAndMods.Add((Common.Abilities)abilityCode, abilityValueCode);
                    }
                }

                spells.Add(newSpell);
            }

            return(spells);
        }
예제 #6
0
        public override List <Item> GetAllRecords()
        {
            var items = new List <Item>();

            List <ItemMD> rawData = MDFileReader.FileReader <ItemMD>(MDFiles.ITEMS_FILE);

            if (rawData == null)
            {
                Console.WriteLine($"Unable to read file {MDFiles.ITEMS_FILE} - not parsing Items");
                return(items);
            }

            foreach (ItemMD item in rawData)
            {
                Item newItem = new Item
                {
                    ID                   = item.ItemId,
                    Name                 = item.ItemName,
                    Shop                 = item.BoughtAndSoldAt,
                    Path                 = item.IfNeededDoPath,
                    MinimumToKeep        = item.MinimumToKeep,
                    MaximumToGet         = item.MaximumToGet,
                    Type                 = (Item.ItemType)BitConverter.ToUInt16(item.ItemType, 0),
                    Weight               = item.Weight,
                    Price                = item.Cost,
                    MinimumStrengthToUse = item.RequiredStrength,
                    MinimumDamage        = item.MinimumDamage,
                    MaximumDamage        = item.MaximumDamage,
                    Accuracy             = item.AccuracyModifier,
                    Speed                = item.WeaponSpeed,
                    ArmorClass           = item.AC,
                    DamageReduction      = item.DR,
                };

                int flag = item.Flags[2] << 16 | item.Flags[1] << 8 | item.Flags[0];
                newItem.Flags = (Item.ItemFlags)flag;

                // Abilities and Mods
                for (int i = 0; i < Common.MAX_BYTES_FOR_ABILITIES / 2; i++)
                {
                    byte[] abilityBytes       = item.AbilityKeys.Skip(i * 2).Take(2).ToArray();
                    byte[] abilityValuesBytes = item.AbilityValues.Skip(i * 2).Take(2).ToArray();

                    ushort abilityCode      = BitConverter.ToUInt16(abilityBytes, 0);
                    short  abilityValueCode = BitConverter.ToInt16(abilityValuesBytes, 0);

                    // If the ability is zero, the value is zero or garbage, so ignore it
                    if (abilityCode == 0)
                    {
                        continue;
                    }

                    var ability = (Common.Abilities)abilityCode;

                    // Handle special-case, multiple valued ability: NegateAbility
                    if (ability == Common.Abilities.NegateAbility) // TODO:  TerminateSpell
                    {
                        newItem.NegatesSpells.Add(abilityValueCode);
                    }
                    // Handle special-case, multiple valued ability: ClassItemInclusion
                    else if (ability == Common.Abilities.ClassItemInclusion)
                    {
                        newItem.Classes.Add(abilityValueCode);
                    }
                    // Handle special-case, multiple valued ability: ????
                    else if (false) // TODO:  Is there actually an ability for race allowance?
                    {
                        //<int> Races { get; set; }                // Allowed races, max 10
                    }
                    // Handle general case, testing for disallowed duplicates
                    else if (newItem.Abilities.ContainsKey(ability))
                    {
                        Console.WriteLine($"Item {newItem.Name} already has the ability {ability} with value {newItem.Abilities[ability]}.  Skipping new value {abilityValueCode}");
                    }
                    else
                    {
                        newItem.Abilities.Add(ability, abilityValueCode);
                    }
                }

                items.Add(newItem);
            }

            return(items);
        }