/// <summary> /// 파일에서 캐릭터 데이터를 불러온다. /// 닉네임, 레벨, 경험치, 직업, 골드, 아이템, 장착중인 장비, 스킬 /// </summary> /// <param name="fileName">캐릭터 파일 이름</param> public static void LoadFromFile(string fileName) { using (FileStream stream = new FileStream(fileName, FileMode.Open)) { using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { try { /* * * * Format * * * * MyNickName * 12 * 7789 * Gunner * 5815 * * [Item] * 붉은 구슬|24 * 초콜릿3|21 * 비밀상자|1 * * * [MountEquipment] * 견고한 투구 * 견고한 갑옷 * 견고한 부츠 * * * [Skill] * 스킬이름1|2 * 스킬이름2|12 * 스킬이름3|1 * * * *** */ bool End = false; Name = reader.ReadLine(); Level = int.Parse(reader.ReadLine()); Exp = long.Parse(reader.ReadLine()); Class = new Class(reader.ReadLine()); Gold = long.Parse(reader.ReadLine()); reader.ReadLine(); while (true) { string keyword = reader.ReadLine(); switch (keyword) { case "[Item]": while (true) { string str = reader.ReadLine(); if (str == "*") { break; } string[] data = str.Split('|'); Inventory.Add(ItemDictionary.MakeItem(data[0]), int.Parse(data[1])); } break; case "[MountEquipment]": while (true) { string str = reader.ReadLine(); if (str == "*") { break; } MountEquipments.Add(ItemDictionary.MakeItem(str)); } break; case "[Skill]": while (true) { string str = reader.ReadLine(); if (str == "*") { break; } string[] data = str.Split('|'); SkillBook.Add(new Skill(data[0]), int.Parse(data[1])); } break; default: End = true; break; } if (End) { break; } } } catch { throw new Exception("Character Load Failed."); } } } }
/// <summary> /// 몬스터를 만든다. /// </summary> public Monster Make(Monster frame) { // 이름 Name = frame.Name; // 능력치 var basicAbility = new Ability(frame.TotalAbility.Power, frame.TotalAbility.Stamina, frame.TotalAbility.Intelli, frame.TotalAbility.Willpower, frame.TotalAbility.Concentration, frame.TotalAbility.Agility); // 경험치, 골드 var basicExp = frame.Exp; var basicGold = frame.Gold; // 드랍아이템 DropItemFormattedInfo = frame.DropItemFormattedInfo; /* 돌연변이 */ SmartRandom r = new SmartRandom(); // 편차 (+-3%) 구간 100 Bounds staminaBounds = new Bounds(Convert.ToInt64(basicAbility.Stamina * 0.97), Convert.ToInt64(basicAbility.Stamina * 1.03)); Bounds expBounds = new Bounds(Convert.ToInt64(basicExp * 0.97), Convert.ToInt64(basicExp * 1.03)); Bounds goldBounds = new Bounds(Convert.ToInt64(basicGold * 0.97), Convert.ToInt64(basicGold * 1.03)); int staminaSection = staminaBounds.Range > 100 ? 100 : staminaBounds.Range > 5 ? 5 : 0; int expSection = expBounds.Range > 100 ? 100 : expBounds.Range > 5 ? 5 : 0; int goldSection = goldBounds.Range > 100 ? 100 : goldBounds.Range > 5 ? 5 : 0; long convertedStamina = staminaBounds.Get(staminaSection); long convertedExp = expBounds.Get(expSection); long convertedGold = goldBounds.Get(goldSection); // 능력치 설정 TotalAbility = new Ability(basicAbility.Power, convertedStamina, basicAbility.Intelli, basicAbility.Willpower, basicAbility.Concentration, basicAbility.Agility); TotalAbility.Calculate(); // HP, MP TotalAbility.HP = TotalAbility.HPMax; TotalAbility.MP = TotalAbility.MPMax; // 경험치, 골드 Exp = convertedExp; Gold = convertedGold; // 드랍아이템 DropItems = new List <Item>(); string[] dropData = DropItemFormattedInfo.Split('/'); for (int i = 0; i < dropData.Length / 2; i++) { Item item = ItemDictionary.MakeItem(dropData[i * 2]); int dropNumber = int.Parse(dropData[i * 2 + 1]); // 몬스터가 아이템을 가지고 있다! if (r.Next(dropNumber) == 0) { DropItems.Add(item); } } return(this); }
/// <summary> /// 해당 부위의 장비를 얻는다. /// </summary> /// <param name="part">장비 부위</param> /// <returns>해당 부위의 장비</returns> public Item GetEquipment(Item.EquipmentPart part) { var equipment = equipments.Find(eq => eq.Part.Equals(part)); return(equipment == null?ItemDictionary.MakeItem("없음") : equipment); }