aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/mobeditor.js
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-08 19:59:14 -0400
committerhistoria <[not public]>2026-07-08 19:59:14 -0400
commit09d325dcf5e779eab5550d3fd3377bde50101428 (patch)
treea433be903aabbf1d2eadce2aacdac12a9eb8dde0 /internal/admin/static/mobeditor.js
parent9184377301c2604e003f36426788c032fb0ca524 (diff)
downloadthehouseoficarus-09d325dcf5e779eab5550d3fd3377bde50101428.tar.gz
feat: unify on use, on look, and on kill. all support same conditions/actions now.
Diffstat (limited to 'internal/admin/static/mobeditor.js')
-rw-r--r--internal/admin/static/mobeditor.js163
1 files changed, 162 insertions, 1 deletions
diff --git a/internal/admin/static/mobeditor.js b/internal/admin/static/mobeditor.js
index b5d2395..7f8c0e3 100644
--- a/internal/admin/static/mobeditor.js
+++ b/internal/admin/static/mobeditor.js
@@ -120,6 +120,16 @@ var MOB_SECTIONS = [
]}
]
},
+ {
+ id: 'on_kill', label: 'On Kill', labelHint: '(fired when this mob is defeated or its task completes — additive over drops)', path: 'on_kill', isArray: true, fullWidth: true, interactionStyle: true,
+ detect: function(d) { return d.on_kill && Array.isArray(d.on_kill); },
+ fields: [
+ ['item_id', 'Item ID', 'search', '(optional — only fires if you wield this weapon when the mob is defeated)', '', null, 'items'],
+ ['condition', 'Condition', 'json', 'e.g. {"global_flag":"quest_active"}'],
+ ['action', 'Action', 'json', 'e.g. {"set_global_flags":{"boss_killed":true},"broadcast":"%p has slain the boss!","spawn_mob":"mini_boss"}'],
+ ['message', 'Message', 'text', 'Shown to the killer when this fires...'],
+ ]
+ },
];
function mobCardPath(sec) { return ced_cardPath(sec); }
@@ -236,6 +246,8 @@ function renderMobCard(sec, data) {
h += renderMobCoreCard(data);
} else if (sec.id === 'combat') {
h += renderMobCombatCard(data);
+ } else if (sec.isArray) {
+ h += renderMobArraySection(sec, data);
} else if (sec.subtables) {
h += '<div class="obj-card-grid">';
sec.fields.forEach(function(f) {
@@ -423,6 +435,135 @@ function renderMobField(sec, f, data, idx, subPath, optStyle) {
return ced_renderField(sec, f, data, idx, subPath, optStyle, mobCardPath, mobFieldID, mobGetVal);
}
+// ---- Interaction-style array rendering (On Kill) ----
+
+function renderMobArraySection(sec, data) {
+ var arr = data[mobCardPath(sec)] || [];
+ var h = '';
+ var isInter = !!sec.interactionStyle;
+ if (isInter) {
+ window._mobInterVis = window._mobInterVis || {};
+ if (!window._mobInterVis[sec.id]) window._mobInterVis[sec.id] = {};
+ }
+ arr.forEach(function(item, idx) {
+ var visMap = window._mobInterVis[sec.id];
+ var vis = visMap[idx] || {};
+ visMap[idx] = vis;
+ var showItem = vis.item_id || (item.item_id && item.item_id !== '');
+ var showCond = vis.condition || (item.condition && item.condition !== '');
+ var showAct = vis.action || (item.action && item.action !== '');
+ var showMsg = vis.message || (item.message && item.message !== '');
+
+ h += '<div class="obj-sub-row" data-idx="' + idx + '" style="flex-direction:column;align-items:stretch;position:relative;gap:6px">';
+ h += '<button class="btn btn-sm btn-danger" style="position:absolute;top:0;right:0;white-space:nowrap;z-index:1" onclick="mobRemoveArrayItem(\'' + sec.id + '\',' + idx + ')">Remove Interaction</button>';
+ h += '<div style="display:flex;gap:4px;align-items:flex-end;flex-wrap:wrap;padding-right:135px">';
+ if (!showItem) {
+ h += '<button class="btn btn-sm" style="background:var(--accent);color:var(--text);border:1px solid #1a5a8e;align-self:flex-end;margin-bottom:3px;white-space:nowrap" onclick="mobShowInterField(\'' + sec.id + '\',' + idx + ',\'item_id\')">+ Add Required Item</button>';
+ h += '<div style="width:1px;background:var(--border);align-self:stretch;margin:2px 0;flex-shrink:0"></div>';
+ }
+ if (!showCond) {
+ h += '<button class="btn btn-sm" style="background:var(--accent);color:var(--text);border:1px solid #1a5a8e;align-self:flex-end;margin-bottom:3px;white-space:nowrap" onclick="mobShowInterField(\'' + sec.id + '\',' + idx + ',\'condition\')">+ Add Condition</button>';
+ }
+ if (!showAct) {
+ h += '<button class="btn btn-sm" style="background:var(--accent);color:var(--text);border:1px solid #1a5a8e;align-self:flex-end;margin-bottom:3px;white-space:nowrap" onclick="mobShowInterField(\'' + sec.id + '\',' + idx + ',\'action\')">+ Add Action</button>';
+ }
+ if (!showMsg) {
+ h += '<button class="btn btn-sm" style="background:var(--accent);color:var(--text);border:1px solid #1a5a8e;align-self:flex-end;margin-bottom:3px;white-space:nowrap" onclick="mobShowInterField(\'' + sec.id + '\',' + idx + ',\'message\')">+ Add Message</button>';
+ }
+ h += '</div>';
+ h += '<div style="display:' + (showItem ? 'flex' : 'none') + ';gap:6px;align-items:flex-start">';
+ h += renderMobField(sec, sec.fields[0], data, idx, null, 'flex:1;min-width:0');
+ h += '<button class="btn btn-sm btn-danger" onclick="mobHideInterField(\'' + sec.id + '\',' + idx + ',\'item_id\')" style="margin-top:14px">X</button>';
+ h += '</div>';
+ h += '<div style="display:' + (showCond ? 'flex' : 'none') + ';gap:6px;align-items:flex-start">';
+ h += renderMobField(sec, sec.fields[1], data, idx, null, 'flex:1;min-width:0');
+ h += '<button class="btn btn-sm btn-danger" onclick="mobHideInterField(\'' + sec.id + '\',' + idx + ',\'condition\')" style="margin-top:14px">X</button>';
+ h += '</div>';
+ h += '<div style="display:' + (showAct ? 'flex' : 'none') + ';gap:6px;align-items:flex-start">';
+ h += renderMobField(sec, sec.fields[2], data, idx, null, 'flex:1;min-width:0');
+ h += '<button class="btn btn-sm btn-danger" onclick="mobHideInterField(\'' + sec.id + '\',' + idx + ',\'action\')" style="margin-top:14px">X</button>';
+ h += '</div>';
+ h += '<div style="display:' + (showMsg ? 'flex' : 'none') + ';gap:6px;align-items:flex-start">';
+ h += renderMobField(sec, sec.fields[3], data, idx, null, 'flex:1;min-width:0');
+ h += '<button class="btn btn-sm btn-danger" onclick="mobHideInterField(\'' + sec.id + '\',' + idx + ',\'message\')" style="margin-top:14px">X</button>';
+ h += '</div>';
+ h += '</div>';
+ });
+ h += '<button class="btn btn-sm obj-sub-add" onclick="mobAddArrayItem(\'' + sec.id + '\')">+ Add ' + esc(sec.label) + '</button>';
+ if (isInter) {
+ var helpKey = 'mob_' + sec.id + '_helpCollapsed';
+ var helpCollapsed = window[helpKey] === undefined ? true : window[helpKey];
+ h += '<div style="margin-top:8px;border:1px solid rgba(100,160,255,.15);border-radius:4px;overflow:hidden">';
+ h += '<div style="padding:6px 10px;background:rgba(100,160,255,.08);cursor:pointer;font-size:10px;color:#6af;font-weight:bold;text-transform:uppercase;letter-spacing:.5px" onclick="mobToggleInterHelp(\'' + sec.id + '\')">';
+ h += '<span style="font-size:8px;margin-right:4px">' + (helpCollapsed ? '&#9654;' : '&#9660;') + '</span>';
+ h += 'How Conditions &amp; Actions Work';
+ h += '</div>';
+ if (!helpCollapsed) {
+ h += '<div style="padding:8px;background:rgba(100,160,255,.05);font-size:10px;color:#aaa;line-height:1.6">';
+ h += 'Entries checked top-to-bottom, first match wins (one fires per kill; additive to standard loot).<br><br>';
+ h += '<b>Item ID</b>: only fires if you wield this weapon (in main_hand or off_hand) when the mob is defeated. Leave empty to fire unconditionally.<br>';
+ h += '<b>Condition</b>: JSON gate. <code>{"global_flag":"boss_quest"}</code>, <code>{"player_flag":"step","value":2}</code>, <code>{"has_item":"trophy"}</code>, <code>{"all_of":[...]}</code>, <code>{"any_of":[...]}</code>.<br>';
+ h += '<b>Action</b>: JSON effects. <code>{"set_global_flags":{...}}</code>, <code>{"set_player_flags":{...}}</code>, <code>{"give_item":"gem"}</code>, <code>{"take_item":"key"}</code>, <code>{"teleport":5}</code>, <code>{"heal":10}</code>, <code>{"credits":100}</code>, <code>{"aps_node":true}</code>, <code>{"spawn_mob":"mini_boss"}</code>, <code>{"despawn_mob":"boss"}</code>, <code>{"broadcast":"%p vanquished the boss!"}</code>, <code>{"broadcast_global":"..."}</code>.<br>';
+ h += '<b>Message</b>: shown to the killer when this interaction fires.';
+ h += '</div>';
+ }
+ h += '</div>';
+ }
+ return h;
+}
+
+function mobAddArrayItem(cardID) {
+ var sec = MOB_SECTIONS.find(function(s) { return s.id === cardID; });
+ if (!sec || !sec.isArray) return;
+ var arr = mobData[sec.path] || [];
+ var empty = {};
+ sec.fields.forEach(function(f) {
+ empty[f[0]] = f[2] === 'checkbox' ? false : (f[2] === 'number' ? 0 : '');
+ });
+ arr.push(empty);
+ mobData[sec.path] = arr;
+ renderCurrent();
+}
+
+function mobRemoveArrayItem(cardID, idx) {
+ var sec = MOB_SECTIONS.find(function(s) { return s.id === cardID; });
+ if (!sec || !sec.isArray) return;
+ ced_syncDOMToData(mobData);
+ var arr = mobData[sec.path] || [];
+ arr.splice(idx, 1);
+ renderMobEditor(mobID, mobData);
+}
+
+function mobShowInterField(secId, idx, key) {
+ window._mobInterVis = window._mobInterVis || {};
+ if (!window._mobInterVis[secId]) window._mobInterVis[secId] = {};
+ if (!window._mobInterVis[secId][idx]) window._mobInterVis[secId][idx] = {};
+ window._mobInterVis[secId][idx][key] = true;
+ renderCurrent();
+}
+
+function mobHideInterField(secId, idx, key) {
+ window._mobInterVis = window._mobInterVis || {};
+ if (!window._mobInterVis[secId]) window._mobInterVis[secId] = {};
+ if (!window._mobInterVis[secId][idx]) window._mobInterVis[secId][idx] = {};
+ window._mobInterVis[secId][idx][key] = false;
+ ced_syncDOMToData(mobData);
+ if (mobData[secId] && mobData[secId][idx]) {
+ mobData[secId][idx][key] = '';
+ }
+ renderMobEditor(mobID, mobData);
+}
+
+function mobToggleInterHelp(secId) {
+ var key = 'mob_' + secId + '_helpCollapsed';
+ if (window[key] === undefined) {
+ window[key] = false;
+ } else {
+ window[key] = !window[key];
+ }
+ renderCurrent();
+}
+
// ---- Subtable rendering ----
function renderMobSubField(sec, stKey, idx, f, val) {
@@ -602,7 +743,9 @@ function mobAddSection() {
if (!sec) return;
if (sec.path) {
- if (id === 'combat') {
+ if (sec.isArray) {
+ mobData[sec.path] = [];
+ } else if (id === 'combat') {
mobData[sec.path] = {
kind: 'combat',
aggressive: false,
@@ -694,6 +837,24 @@ function saveMob() {
return;
}
+ if (sec.isArray) {
+ var arr = [];
+ var card = document.querySelector('.obj-card[data-card="' + sec.id + '"]');
+ if (!card) return;
+ var rows = card.querySelectorAll('.obj-sub-row');
+ rows.forEach(function(row, idx) {
+ var item = {};
+ sec.fields.forEach(function(f) {
+ var fid = mobFieldID(sec, f[0], idx);
+ var el = document.getElementById(fid);
+ if (el) item[f[0]] = ced_collectFieldValue(el, f[2]);
+ });
+ if (Object.keys(item).length > 0) arr.push(item);
+ });
+ if (arr.length > 0) out[sec.path] = arr;
+ return;
+ }
+
var sectionObj = {};
var hasValues = sec.always;