Update 'mbchc-dev.user.js'

This commit is contained in:
Mute 2022-06-27 20:36:31 +00:00
parent c719d2ae91
commit 0d9e284d44
1 changed files with 93 additions and 3 deletions

View File

@ -18,6 +18,8 @@
// Static data
window.MBCHC = {
NEXT_MESSAGE: 1,
LOG_MESSAGES: false,
LOADED: false,
VERSION: 'dev',
AUTOHACK_ENABLED: false,
@ -69,11 +71,73 @@
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
},
},
{ Tag: "nod",
Description: ": Nod",
Action: (argline, cmdline, args) => {
try {
window.MBCHC.run_activity(window.Player, "ItemHead", "Nod")
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
},
},
{ Tag: "shake",
Description: ": Shake your head",
Action: (argline, cmdline, args) => {
try {
window.MBCHC.run_activity(window.Player, "ItemHead", "Wiggle")
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
},
},
{ Tag: "shrug",
Description: ": Shrug",
Action: (argline, cmdline, args) => {
try {
window.MBCHC.send_activity(`${window.CharacterNickname(window.Player)} shrugs.`)
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
},
},
{ Tag: "myself",
Description: "[Message]: Send a custom activity as yourself (or \"@Message\")",
Action: (argline, cmdline, args) => {
if (!window.MBCHC.empty(argline)) {
try {
let message = window.MBCHC.add_full_stop(argline)
window.MBCHC.send_activity(`${window.CharacterNickname(window.Player)} ${message}`)
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
}
},
},
{ Tag: "activity",
Description: "[Message]: Send a custom activity (or \"@@Message\")",
Action: (argline, cmdline, args) => {
if (!window.MBCHC.empty(argline)) {
try {
let message = window.MBCHC.add_full_stop(window.MBCHC.capitalise(argline))
window.MBCHC.send_activity(message)
} catch (x) { window.ChatRoomSendLocal(`(Error: ${x.toString()})`) }
}
},
},
],
log: function(msg) {return("MBCHC: " + msg.toString())},
empty: function(text) {
if (!text) return(true)
if (String(text).trim().length < 1) return(true)
return(false)
},
add_full_stop: function(text) {
if (text.endsWith('.')) return(text)
return(`${text}.`)
},
capitalise: function(text, lower = false) {
let first = text.at(0).toLocaleUpperCase()
let rest = text.slice(1)
if (lower) rest = rest.toLocaleLowerCase()
return(first + rest)
},
orig_AsylumGGTSSAddItems: window.AsylumGGTSSAddItems,
orig_ChatRoomMessageInvolvesPlayer: window.ChatRoomMessageInvolvesPlayer,
orig_ChatRoomReceiveSuitcaseMoney: window.ChatRoomReceiveSuitcaseMoney,
orig_ChatRoomSendChat: window.ChatRoomSendChat,
} // MBCHC
// Loader
@ -101,7 +165,20 @@
window.ServerSend("ChatRoomChat", {Content: "ReceiveSuitcaseMoney", Type: "Hidden", Target: id})
return({cost: cost, name: (char.Nickname || char.Name)})
}
window.MBCHC.run_activity = function(char, ag, action) {
try {
char.FocusGroup = window.AssetGroupGet(char.AssetFamily, ag)
if (!char.FocusGroup) throw "invalid AssetGroup"
let activity = window.ActivityAllowedForGroup(char, char.FocusGroup.Name).find( a => a.Name === action)
if (!activity) throw "invalid activity"
window.ActivityRun(char, activity)
} finally {
char.FocusGroup = null
}
}
window.MBCHC.send_activity = function(msg) {
window.ServerSend("ChatRoomChat", {Type: "Action", Content: "lef_wie234jf_owhwi", Dictionary: [{Tag: 'MISSING PLAYER DIALOG: lef_wie234jf_owhwi', Text: msg}]})
}
// Command actions
window.MBCHC.action_title = function(args) {
let title = args.shift()
@ -130,8 +207,12 @@
// Hooks
window.ChatRoomMessageInvolvesPlayer = function(data) {
//console.log({data: data})
if (("ReceiveSuitcaseMoney" === data.Content) && ("Hidden" === data.Type)) { window.MBCHC.LAST_HACKED = data.Sender }
if (!data.MBCHC_ID) {
data.MBCHC_ID = window.MBCHC.NEXT_MESSAGE
window.MBCHC.NEXT_MESSAGE += 1
if (window.MBCHC.LOG_MESSAGES) console.debug(data)
if (("ReceiveSuitcaseMoney" === data.Content) && ("Hidden" === data.Type)) { window.MBCHC.LAST_HACKED = data.Sender }
}
return(window.MBCHC.orig_ChatRoomMessageInvolvesPlayer(data))
}
window.ChatRoomReceiveSuitcaseMoney = function() {
@ -143,6 +224,15 @@
}
return(result)
}
window.ChatRoomSendChat = function() {
let input = window.ElementValue("InputChat")
if (!input.startsWith("@@@")) {
input = input.replace(/^@@/, "/activity ")
input = input.replace(/^@/, "/myself ")
window.ElementValue("InputChat", input)
}
return(window.MBCHC.orig_ChatRoomSendChat())
}
// Actions
window.CommandCombine(window.MBCHC.COMMANDS)