|
| 1 | +/*Copyright(c) 2024, LastBattle https://github.com/lastbattle/Harepacker-resurrected |
| 2 | +
|
| 3 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +of this software and associated documentation files (the "Software"), to deal |
| 5 | +in the Software without restriction, including without limitation the rights |
| 6 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +copies of the Software, and to permit persons to whom the Software is |
| 8 | +furnished to do so, subject to the following conditions: |
| 9 | +
|
| 10 | +The above copyright notice and this permission notice shall be included in all |
| 11 | +copies or substantial portions of the Software. |
| 12 | +
|
| 13 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +SOFTWARE. |
| 20 | +*/ |
| 21 | + |
| 22 | +using System.Collections.Generic; |
| 23 | +using System.Linq; |
| 24 | +using System.Text.RegularExpressions; |
| 25 | + |
| 26 | +namespace MapleLib.WzLib.WzStructure.Data.CharacterStructure |
| 27 | +{ |
| 28 | + /// <summary> |
| 29 | + /// The bitfield values for job categories |
| 30 | + /// for Quest Act.img 'job' WZ values before big-bang update. |
| 31 | + /// </summary> |
| 32 | + public enum CharacterJobPreBBType |
| 33 | + { |
| 34 | + None = 0x0, |
| 35 | + |
| 36 | + // Basic Classes (0x1 - 0x20) |
| 37 | + Beginner = 0x1, // 0 |
| 38 | + ExplorerWarrior = 0x2, // 100 |
| 39 | + ExplorerMagician = 0x4, // 200 |
| 40 | + ExplorerArcher = 0x8, // 300 |
| 41 | + ExplorerThief = 0x10, // 400 |
| 42 | + ExplorerPirate = 0x20, // 500 |
| 43 | + |
| 44 | + // Cygnus Knights (0x400 - 0x8000) |
| 45 | + Noblesse = 0x400, // 1000 |
| 46 | + DawnWarrior = 0x800, // 1100 |
| 47 | + BlazeWizard = 0x1000, // 1200 |
| 48 | + WindArcher = 0x2000, // 1300 |
| 49 | + NightWalker = 0x4000, // 1400 |
| 50 | + ThunderBreaker = 0x8000, // 1500 |
| 51 | + |
| 52 | + // Heroes/Legends (0x20000 - 0x400000) |
| 53 | + Evan = 0x20000, // 2001, 2200 |
| 54 | + Aran = 0x100000, // 2000, 2001 |
| 55 | + AranWarrior = 0x200000, // 2100 |
| 56 | + EvanMagician = 0x400000, // 2001, 2200 |
| 57 | + |
| 58 | + // Resistance (0x40000000) |
| 59 | + Resistance = 0x40000000, // 3000, 3200, 3300, 3500 |
| 60 | + |
| 61 | + // Combined Group Masks |
| 62 | + AllExplorers = ExplorerWarrior | ExplorerMagician | ExplorerArcher | ExplorerThief | ExplorerPirate, |
| 63 | + AllCygnus = DawnWarrior | BlazeWizard | WindArcher | NightWalker | ThunderBreaker, |
| 64 | + AllHeroes = Aran | AranWarrior | Evan | EvanMagician, |
| 65 | + |
| 66 | + // Class Type Masks (for similar class types across factions) |
| 67 | + AllWarriors = ExplorerWarrior | DawnWarrior | AranWarrior, |
| 68 | + AllMagicians = ExplorerMagician | BlazeWizard | Evan | EvanMagician, |
| 69 | + AllArchers = ExplorerArcher | WindArcher, |
| 70 | + AllThieves = ExplorerThief | NightWalker, |
| 71 | + AllPirates = ExplorerPirate | ThunderBreaker |
| 72 | + } |
| 73 | + |
| 74 | + public static class CharacterJobPreBBTypeExt |
| 75 | + { |
| 76 | + public static IEnumerable<CharacterJob> DecodeJobCodes(this CharacterJobPreBBType encoded) |
| 77 | + { |
| 78 | + var jobs = new List<CharacterJob>(); |
| 79 | + |
| 80 | + // Basic Classes |
| 81 | + if (encoded.HasFlag(CharacterJobPreBBType.Beginner)) |
| 82 | + jobs.Add(CharacterJob.Beginner); |
| 83 | + if (encoded.HasFlag(CharacterJobPreBBType.ExplorerWarrior)) |
| 84 | + jobs.Add(CharacterJob.Warrior); |
| 85 | + if (encoded.HasFlag(CharacterJobPreBBType.ExplorerMagician)) |
| 86 | + jobs.Add(CharacterJob.Magician); |
| 87 | + if (encoded.HasFlag(CharacterJobPreBBType.ExplorerArcher)) |
| 88 | + jobs.Add(CharacterJob.Archer); |
| 89 | + if (encoded.HasFlag(CharacterJobPreBBType.ExplorerThief)) |
| 90 | + jobs.Add(CharacterJob.Rogue); |
| 91 | + if (encoded.HasFlag(CharacterJobPreBBType.ExplorerPirate)) |
| 92 | + jobs.Add(CharacterJob.Pirate); |
| 93 | + |
| 94 | + // Cygnus Knights |
| 95 | + if (encoded.HasFlag(CharacterJobPreBBType.Noblesse)) |
| 96 | + jobs.Add(CharacterJob.Noblesse); |
| 97 | + if (encoded.HasFlag(CharacterJobPreBBType.DawnWarrior)) |
| 98 | + jobs.Add(CharacterJob.DawnWarrior1); |
| 99 | + if (encoded.HasFlag(CharacterJobPreBBType.BlazeWizard)) |
| 100 | + jobs.Add(CharacterJob.BlazeWizard1); |
| 101 | + if (encoded.HasFlag(CharacterJobPreBBType.WindArcher)) |
| 102 | + jobs.Add(CharacterJob.WindArcher1); |
| 103 | + if (encoded.HasFlag(CharacterJobPreBBType.NightWalker)) |
| 104 | + jobs.Add(CharacterJob.NightWalker1); |
| 105 | + if (encoded.HasFlag(CharacterJobPreBBType.ThunderBreaker)) |
| 106 | + jobs.Add(CharacterJob.ThunderBreaker1); |
| 107 | + |
| 108 | + // Heroes/Legends |
| 109 | + if (encoded.HasFlag(CharacterJobPreBBType.Evan)) |
| 110 | + { |
| 111 | + jobs.Add(CharacterJob.EvanBeginner); |
| 112 | + jobs.Add(CharacterJob.Evan1); |
| 113 | + } |
| 114 | + if (encoded.HasFlag(CharacterJobPreBBType.Aran)) |
| 115 | + { |
| 116 | + jobs.Add(CharacterJob.AranBeginner); |
| 117 | + jobs.Add(CharacterJob.EvanBeginner); |
| 118 | + } |
| 119 | + if (encoded.HasFlag(CharacterJobPreBBType.AranWarrior)) |
| 120 | + jobs.Add(CharacterJob.Aran1); |
| 121 | + |
| 122 | + if (encoded.HasFlag(CharacterJobPreBBType.EvanMagician)) |
| 123 | + { |
| 124 | + jobs.Add(CharacterJob.EvanBeginner); |
| 125 | + jobs.Add(CharacterJob.Evan1); |
| 126 | + } |
| 127 | + |
| 128 | + // Resistance |
| 129 | + if (encoded.HasFlag(CharacterJobPreBBType.Resistance)) |
| 130 | + { |
| 131 | + jobs.Add(CharacterJob.Citizen); |
| 132 | + jobs.Add(CharacterJob.BattleMage1); |
| 133 | + jobs.Add(CharacterJob.WildHunter1); |
| 134 | + jobs.Add(CharacterJob.Mechanic1); |
| 135 | + } |
| 136 | + |
| 137 | + return jobs.Distinct().OrderBy(x => (int)x); |
| 138 | + } |
| 139 | + |
| 140 | + public static CharacterJobPreBBType EncodeJobs(IEnumerable<int> jobs) |
| 141 | + { |
| 142 | + CharacterJobPreBBType encoded = CharacterJobPreBBType.None; |
| 143 | + |
| 144 | + foreach (var job in jobs) |
| 145 | + { |
| 146 | + switch (job) |
| 147 | + { |
| 148 | + case 0: encoded |= CharacterJobPreBBType.Beginner; break; |
| 149 | + case 100: encoded |= CharacterJobPreBBType.ExplorerWarrior; break; |
| 150 | + case 200: encoded |= CharacterJobPreBBType.ExplorerMagician; break; |
| 151 | + case 300: encoded |= CharacterJobPreBBType.ExplorerArcher; break; |
| 152 | + case 400: encoded |= CharacterJobPreBBType.ExplorerThief; break; |
| 153 | + case 500: encoded |= CharacterJobPreBBType.ExplorerPirate; break; |
| 154 | + case 1000: encoded |= CharacterJobPreBBType.Noblesse; break; |
| 155 | + case 1100: encoded |= CharacterJobPreBBType.DawnWarrior; break; |
| 156 | + case 1200: encoded |= CharacterJobPreBBType.BlazeWizard; break; |
| 157 | + case 1300: encoded |= CharacterJobPreBBType.WindArcher; break; |
| 158 | + case 1400: encoded |= CharacterJobPreBBType.NightWalker; break; |
| 159 | + case 1500: encoded |= CharacterJobPreBBType.ThunderBreaker; break; |
| 160 | + case 2000: |
| 161 | + encoded |= CharacterJobPreBBType.Aran; |
| 162 | + break; |
| 163 | + case 2100: |
| 164 | + encoded |= CharacterJobPreBBType.AranWarrior; |
| 165 | + break; |
| 166 | + case 2001: |
| 167 | + encoded |= CharacterJobPreBBType.Evan; |
| 168 | + break; |
| 169 | + case 2200: |
| 170 | + encoded |= CharacterJobPreBBType.EvanMagician; |
| 171 | + break; |
| 172 | + case 3000: |
| 173 | + case 3200: |
| 174 | + case 3300: |
| 175 | + case 3500: |
| 176 | + encoded |= CharacterJobPreBBType.Resistance; |
| 177 | + break; |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + return encoded; |
| 182 | + } |
| 183 | + |
| 184 | + /// <summary> |
| 185 | + /// Gets the formatted job name from enum |
| 186 | + /// </summary> |
| 187 | + /// <param name="job"></param> |
| 188 | + /// <returns></returns> |
| 189 | + public static string GetFormattedJobName(this CharacterJobPreBBType job) |
| 190 | + { |
| 191 | + string jobName = job.ToString(); |
| 192 | + |
| 193 | + // Add spaces between words |
| 194 | + jobName = string.Concat(jobName.Select(x => char.IsUpper(x) ? " " + x : x.ToString())).Trim(); |
| 195 | + |
| 196 | + return jobName; |
| 197 | + } |
| 198 | + |
| 199 | + // Helper methods for common job checks |
| 200 | + public static bool IsExplorer(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllExplorers) != 0; |
| 201 | + public static bool IsCygnus(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllCygnus) != 0; |
| 202 | + public static bool IsHero(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllHeroes) != 0; |
| 203 | + |
| 204 | + public static bool IsWarrior(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllWarriors) != 0; |
| 205 | + public static bool IsMagician(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllMagicians) != 0; |
| 206 | + public static bool IsArcher(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllArchers) != 0; |
| 207 | + public static bool IsThief(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllThieves) != 0; |
| 208 | + public static bool IsPirate(this CharacterJobPreBBType codes) => (codes & CharacterJobPreBBType.AllPirates) != 0; |
| 209 | + |
| 210 | + // Helper method to convert from integer to JobCodes enum |
| 211 | + public static CharacterJobPreBBType ToJobCodes(this int encoded) => (CharacterJobPreBBType)encoded; |
| 212 | + } |
| 213 | +} |
0 commit comments