Created
August 27, 2024 06:55
-
-
Save notarikon-nz/82bbdc6da6a8e3e19d4d6d3ce7d977a2 to your computer and use it in GitHub Desktop.
HackMUD Upgrade Sorting Script aka Shfflr solver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function(context, args) | |
| { | |
| // swap and extend as needed | |
| const lockPriority = ['acct_nt','sn_w_glock','shfflr','sn_w_usac','l0ckjaw','l0ckbox','DATA_CHECK_V4','DATA_CHECK_V3','l0g_wr1t3r','magnara','CONSPEC','EZ40']; | |
| unloadKeys(); | |
| // sort locks to front | |
| let sortedLocks = #hs.sys.upgrades({filter:{type:"lock",loaded:true}}).sort(lockSort).map(a => a.i); | |
| let sortedArray = #hs.sys.upgrades({filter:{type:{"$ne":"lock"}}}).sort(genericSort).map(a => a.i); | |
| reorderUpgrades(sortedLocks,0); | |
| reorderUpgrades(sortedArray,sortedLocks.length); | |
| // sort locks by lockPriority array | |
| function lockSort(a,b) { | |
| let indexA = lockPriority.indexOf(a.name); | |
| let indexB = lockPriority.indexOf(b.name); | |
| if (indexA === -1) indexA = lockPriority.length; | |
| if (indexB === -1) indexB = lockPriority.length; | |
| return indexA - indexB; | |
| } | |
| // sort all other upgrades by loaded, name, and rarity | |
| function genericSort(a, b) { | |
| if (a.loaded === b.loaded) { | |
| if (a.name === b.name) { | |
| return a.rarity - b.rarity; | |
| } | |
| return a.name.localeCompare(b.name); | |
| } | |
| return a.loaded ? -1 : 1; | |
| } | |
| function reorderUpgrades(sortedArray, offset = 0) { | |
| for (let s = sortedArray.length - 1; s >= 0; s--) { | |
| let from = sortedArray[s]; | |
| let to = offset; | |
| #ms.sys.manage({ reorder: { from, to } }); | |
| sortedArray[s] = to; | |
| for (let ss = 0; ss < sortedArray.length; ss++) { | |
| if (sortedArray[ss] < from) sortedArray[ss]++; | |
| } | |
| } | |
| } | |
| function unloadKeys() { | |
| const keyArray = #hs.sys.upgrades({ filter: { type:'tool',loaded:true } }) | |
| if (!Array.isArray(keyArray)) return; | |
| keyArray.forEach(u => { | |
| #ms.sys.manage({ unload: u.i }) | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment