//TODO: Simplify method body public void Read() { using (FileStream fstream = File.Open(@"dlc\skillenchant.dlc", FileMode.Open, FileAccess.Read)) { byte[] dlcheader = new byte[3]; fstream.Read(dlcheader, 0, dlcheader.Length); if (Encoding.UTF8.GetString(dlcheader) == "DLC") { DlcStream dlc = new DlcStream(fstream, CompressionMode.Decompress); int cnt = dlc.ReadD(); for (int a = 0; a < cnt; a++) { SkillEnchantInfo inf = new SkillEnchantInfo { Id = dlc.ReadD(), Lv = dlc.ReadD() }; int len = dlc.ReadD(); for (int b = 0; b < len; b++) { SkillEnchantInfoDetail nfo = new SkillEnchantInfoDetail { RouteId = dlc.ReadD(), EnchantId = dlc.ReadD(), EnchantedSkillLevel = dlc.ReadD(), Importance = dlc.ReadC(), R1 = dlc.ReadD(), R2 = dlc.ReadD(), R3 = dlc.ReadD(), R4 = dlc.ReadD() }; dlc.ReadS(10); inf.Details.Add(nfo.EnchantedSkillLevel, nfo); } EnchantInfo.Add((inf.Id * 65536) + inf.Lv, inf); } } } SortedList <int, object> ids = new SortedList <int, object>(); Initreg(); using (FileStream fstream = File.Open(@"dlc\skilldb_edit.dlc", FileMode.Open, FileAccess.Read)) { byte[] dlcheader = new byte[3]; fstream.Read(dlcheader, 0, dlcheader.Length); if (Encoding.UTF8.GetString(dlcheader) == "DLC") { DlcStream dlc = new DlcStream(fstream, CompressionMode.Decompress); int cnt = dlc.ReadD(); for (int a = 0; a < cnt; a++) { byte len = dlc.ReadC(); Skill skill = new Skill(); for (byte p = 0; p < len; p++) { byte keyId = dlc.ReadC(); SkillLevelParam slp = _ps[keyId]; int lenx; string value; switch (slp.Id) { case 1: skill.SkillId = dlc.ReadD(); break; case 2: skill.Level = dlc.ReadD(); break; case 3: lenx = dlc.ReadD(); value = dlc.ReadS(lenx); skill.OpType = (SkillOperational)Enum.Parse(typeof(SkillOperational), value); break; case 4: skill.MagicLevel = dlc.ReadD(); break; case 6: lenx = dlc.ReadD(); value = dlc.ReadS(lenx); skill.SetEffect_effect(value); break; case 8: lenx = dlc.ReadD(); value = dlc.ReadS(lenx); skill.SetOperateCond(value); break; case 15: skill.IsMagic = (short)dlc.ReadD(); break; case 16: skill.MpConsume1 = dlc.ReadD(); break; case 17: skill.MpConsume2 = dlc.ReadD(); break; case 18: skill.CastRange = dlc.ReadD(); break; case 19: skill.EffectiveRange = dlc.ReadD(); break; case 20: skill.SkillHitTime = (short)(dlc.ReadF() * 1000); break; case 21: skill.SkillCoolTime = (short)(dlc.ReadF() * 1000); break; case 23: skill.ReuseDelay = dlc.ReadF(); break; case 26: double rate = dlc.ReadF(); if (rate != -1) { skill.ActivateRate = (short)(rate * 1000); } break; case 29: skill.AbnormalTime = dlc.ReadD(); break; case 30: skill.AbnormalLv = dlc.ReadD(); break; case 31: lenx = dlc.ReadD(); skill.AbnormalType = dlc.ReadS(lenx); break; case 39: //target_type lenx = dlc.ReadD(); value = dlc.ReadS(lenx); try { var newValue = StringHelper.ToTitleCase(value, '_'); skill.TargetType = (SkillTarget)Enum.Parse(typeof(SkillTarget), newValue); } catch (Exception ex) { Log.Error($"Exception {ex.Message}"); skill.TargetType = SkillTarget.Target; Log.Error($"skill # {skill.SkillId} invalid target {value}"); } break; case 40: //affect_scope lenx = dlc.ReadD(); value = dlc.ReadS(lenx); try { var newValue = StringHelper.ToTitleCase(value, '_'); skill.AffectScope = (SkillScope)Enum.Parse(typeof(SkillScope), newValue); } catch { skill.AffectScope = SkillScope.Single; Log.Error($"skill # {skill.SkillId} invalid scope {value}"); } break; case 49: skill.HpConsume = dlc.ReadD(); break; default: switch (slp.Type) { case 1: dlc.ReadD(); break; case 2: dlc.ReadF(); break; case 3: int f = dlc.ReadD(); dlc.ReadS(f); break; } break; } } if (EnchantInfo.ContainsKey(skill.HashId())) { skill.EnchantEnabled = 1; } Skills.Add(skill.HashId(), skill); if (!ids.ContainsKey(skill.SkillId)) { ids.Add(skill.SkillId, null); } } } } //using (StreamReader sreader = File.OpenText(@"scripts\skills.txt")) //{ // while (!sreader.EndOfStream) // { // string line = sreader.ReadLine(); // if (line.Length == 0 || line.StartsWithIgnoreCase("#")) // continue; // string[] pt = line.Split('\t'); // TSkill skill = new TSkill(); // skill.ClientID = Convert.ToInt32(pt[0].Split('-')[0]); // skill.Level = Convert.ToInt32(pt[0].Split('-')[1]); // if (_idsEnchant.Contains(skill.HashID())) // skill.EnchantEnabled = 1; // skill.OpType = (TSkillOperational)Enum.Parse(typeof(TSkillOperational), pt[1]); // for (byte ord = 2; ord < pt.Length; ord++) // { // string parameter = pt[ord]; // switch (parameter.Split('{')[0].ToLower()) // { // case "effect": // skill.parseEffects(parameter.Substring(7)); // break; // case "is_magic": // skill.IsMagic = Convert.ToInt16(parameter.Remove(parameter.Length - 1).Substring(9)); // break; // case "mpconsume": // break; // case "hit_time": // skill.HitTime = Convert.ToInt16(parameter.Remove(parameter.Length - 1).Substring(9)); // break; // case "cool_time": // skill.CoolTime = Convert.ToInt32(parameter.Remove(parameter.Length - 1).Substring(10)); // break; // case "reuse": // string reuse = parameter.Remove(parameter.Length - 1).Substring(6); // if (reuse.Contains(".")) // skill.Reuse = double.Parse(reuse); // else // skill.Reuse = int.Parse(reuse); // break; // case "activate_rate": // skill.ActivateRate = Convert.ToInt16(parameter.Remove(parameter.Length - 1).Substring(14)); // break; // case "target": // skill.setTarget(parameter.Substring(7)); // break; // case "cond": // break; // case "bonus": // break; // case "next": // break; // case "abnormal_time": // skill.AbnormalTime = Convert.ToInt32(parameter.Remove(parameter.Length - 1).Substring(14)); // break; // case "abnormal_id": // break; // } // } // _skills.Add(skill.HashID(), skill); // if (!_ids.ContainsKey(skill.ClientID)) // _ids.Add(skill.ClientID, null); // } //} Log.Info($"SkillTable: loaded {ids.Count} skills, {EnchantInfo.Count} enchants."); }
private void LoadDlc() { FileStream fstream = new FileStream(@"dlc\skilltree.dlc", FileMode.Open, FileAccess.Read); byte[] dlcheader = new byte[3]; fstream.Read(dlcheader, 0, dlcheader.Length); if (Encoding.UTF8.GetString(dlcheader) != "DLC") { return; } AcquireSkills = new Dictionary <string, AcquireSkillsEntry>(); DlcStream dlc = new DlcStream(fstream, CompressionMode.Decompress); int cnt = dlc.ReadD(), cntTotal = 0; for (int a = 0; a < cnt; a++) { AcquireSkillsEntry list = new AcquireSkillsEntry(); byte len = dlc.ReadC(); list.Type = dlc.ReadS(len); len = dlc.ReadC(); if (len > 0) { list.Include = dlc.ReadS(len); List <AcquireSkill> s = AcquireSkills[list.Include].Skills; cntTotal += s.Count; list.Skills.AddRange(s); } int skLen = dlc.ReadD(); cntTotal += skLen; for (int s = 0; s < skLen; s++) { AcquireSkill skill = new AcquireSkill { Id = dlc.ReadD(), Lv = dlc.ReadD(), GetLv = dlc.ReadD(), LvUpSp = dlc.ReadD(), AutoGet = dlc.ReadC() == 1 }; if (dlc.ReadC() == 1) { skill.ItemId = dlc.ReadD(); skill.ItemCount = dlc.ReadD(); } skill.SocialClass = dlc.ReadD(); skill.ResidenceSkill = dlc.ReadC() == 1; len = dlc.ReadC(); if (len > 0) { skill.PledgeType = dlc.ReadS(len); } len = dlc.ReadC(); for (byte b = 0; b < len; b++) { skill.Races.Add(dlc.ReadC()); } skill.IdPrerequisiteSkill = dlc.ReadD(); skill.LvPrerequisiteSkill = dlc.ReadD(); int qcn = dlc.ReadD(); for (int i = 0; i < qcn; i++) { skill.Quests.Add(dlc.ReadD()); } list.Skills.Add(skill); } if (!string.IsNullOrEmpty(list.Type)) { AcquireSkills.Add(list.Type, list); } } dlc.Close(); Log.Info($"SkillTable: learnable {AcquireSkills.Count} groups, #{cntTotal} skills."); }