/// <summary> /// Reads a <see cref="IMonsterTypeEntity"/> out of a monster file. /// </summary> /// <param name="monsterFileInfo">The information about the monster file.</param> /// <returns>The <see cref="IMonsterTypeEntity"/> instance.</returns> private IMonsterTypeEntity ReadMonsterFile(FileInfo monsterFileInfo) { monsterFileInfo.ThrowIfNull(nameof(monsterFileInfo)); if (!monsterFileInfo.Exists) { return(null); } var monsterType = new MonsterTypeEntity(); foreach ((string name, string value) in this.ReadInDataTuples(File.ReadLines(monsterFileInfo.FullName), monsterFileInfo.FullName)) { switch (name) { case "racenumber": monsterType.RaceId = Convert.ToUInt16(value); break; case "name": monsterType.Name = value; break; case "article": monsterType.Article = value; break; case "outfit": var(lookTypeId, headColor, bodyColor, legsColor, feetColor) = CipFileParser.ParseMonsterOutfit(value); monsterType.Outfit = new Outfit() { Id = lookTypeId, Head = headColor, Body = bodyColor, Legs = legsColor, Feet = feetColor, }; break; case "corpse": monsterType.Corpse = Convert.ToUInt16(value); break; case "blood": if (Enum.TryParse(value, out BloodType bloodType)) { monsterType.BloodType = bloodType; } break; case "experience": monsterType.BaseExperienceYield = Convert.ToUInt32(value); break; case "summoncost": monsterType.SummonCost = Convert.ToUInt16(value); break; case "fleethreshold": monsterType.HitpointFleeThreshold = Convert.ToUInt16(value); break; case "attack": monsterType.BaseAttack = Convert.ToUInt16(value); break; case "defend": monsterType.BaseDefense = Convert.ToUInt16(value); break; case "armor": monsterType.BaseArmorRating = Convert.ToUInt16(value); break; case "poison": monsterType.SetConditionInfect(ConditionFlag.Posion, Convert.ToUInt16(value)); break; case "losetarget": monsterType.LoseTargetDistance = Convert.ToByte(value); break; case "strategy": monsterType.Strategy = CipFileParser.ParseMonsterStrategy(value); break; case "flags": var parsedElements = CipFileParser.Parse(value); foreach (var element in parsedElements) { if (!element.IsFlag || element.Attributes == null || !element.Attributes.Any()) { continue; } if (Enum.TryParse(element.Attributes.First().Name, out CipCreatureFlag flagMatch)) { if (flagMatch.ToCreatureFlag() is CreatureFlag creatureFlag) { monsterType.SetCreatureFlag(creatureFlag); } } } break; case "skills": var skillParsed = CipFileParser.ParseMonsterSkills(value); foreach (var skill in skillParsed) { if (!Enum.TryParse(skill.Name, ignoreCase: true, out CipMonsterSkillType mSkill)) { continue; } switch (mSkill) { case CipMonsterSkillType.Hitpoints: monsterType.MaxHitpoints = skill.CurrentLevel < 0 ? ushort.MaxValue : (ushort)skill.DefaultLevel; break; case CipMonsterSkillType.GoStrength: monsterType.BaseSpeed = skill.CurrentLevel < 0 ? ushort.MinValue : (ushort)skill.DefaultLevel; break; case CipMonsterSkillType.CarryStrength: monsterType.Capacity = skill.CurrentLevel < 0 ? ushort.MinValue : (ushort)skill.DefaultLevel; break; case CipMonsterSkillType.FistFighting: if (skill.CurrentLevel > 0) { monsterType.SetSkill(SkillType.NoWeapon, skill.CurrentLevel, skill.DefaultLevel, skill.MaximumLevel, skill.TargetCount, skill.CountIncreaseFactor, skill.IncreaserPerLevel); } break; } } break; case "spells": monsterType.SetSpells(CipFileParser.ParseMonsterSpells(value)); break; case "inventory": monsterType.SetInventory(CipFileParser.ParseMonsterInventory(value)); break; case "talk": monsterType.SetPhrases(CipFileParser.ParsePhrases(value)); break; } } monsterType.Lock(); return(monsterType); }
/// <summary> /// Reads a <see cref="IMonsterType"/> out of a monster file. /// </summary> /// <param name="monsterFileInfo">The information about the monster file.</param> /// <returns>The <see cref="IMonsterType"/> instance.</returns> private IMonsterType ReadMonsterFile(FileInfo monsterFileInfo) { monsterFileInfo.ThrowIfNull(nameof(monsterFileInfo)); if (!monsterFileInfo.Exists) { return(null); } var monsterType = new MonsterType(); foreach ((string name, string value) in this.ReadInDataTuples(File.ReadLines(monsterFileInfo.FullName), monsterFileInfo.FullName)) { switch (name) { case "racenumber": monsterType.SetId(Convert.ToUInt16(value)); break; case "name": monsterType.SetName(value.Trim('\"')); break; case "article": monsterType.SetArticle(value.Trim('\"')); break; case "outfit": monsterType.SetOutfit(value.Trim('(', ')')); break; case "corpse": monsterType.SetCorpse(Convert.ToUInt16(value)); break; case "blood": monsterType.SetBlood(value); break; case "experience": monsterType.SetExperience(Convert.ToUInt32(value)); break; case "summoncost": monsterType.SetSummonCost(Convert.ToUInt16(value)); break; case "fleethreshold": monsterType.SetFleeTreshold(Convert.ToUInt16(value)); break; case "attack": monsterType.SetAttack(Convert.ToUInt16(value)); break; case "defend": monsterType.SetDefense(Convert.ToUInt16(value)); break; case "armor": monsterType.SetArmor(Convert.ToUInt16(value)); break; case "poison": monsterType.SetConditionInfect(ConditionFlag.Posion, Convert.ToUInt16(value)); break; case "losetarget": monsterType.SetLoseTarget(Convert.ToByte(value)); break; case "strategy": monsterType.SetStrategy(CipFileParser.ParseMonsterStrategy(value)); break; case "flags": monsterType.SetFlags(CipFileParser.Parse(value)); break; case "skills": monsterType.SetSkills(CipFileParser.ParseMonsterSkills(value)); break; case "spells": monsterType.SetSpells(CipFileParser.ParseMonsterSpells(value)); break; case "inventory": monsterType.SetInventory(CipFileParser.ParseMonsterInventory(value)); break; case "talk": monsterType.SetPhrases(CipFileParser.ParsePhrases(value)); break; } } monsterType.Lock(); return(monsterType); }