Fix Ability Cloning Behavior for Scripts

This commit is contained in:
Kam committed 2026-03-10 21:55:25 -04:00
1 parent 9b0c364e13
commit 0cc3a48f0b
2 files changed
+73 -15

No files matched your search

@@ -994,12 +994,18 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
if (slot.isChain() && selectedEntryIndex == -1) {
// Chain header (must be CHAIN_REFERENCE)
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
String sourceChainName = slot.getReferenceId();
if (slot.convertToInline()) {
ChainedAbility chain = slot.getInlineChain();
if (chain != null) {
pendingChain = chain;
pendingChainSlotIdx = selectedSlotIndex;
setSubGui(new SubGuiChainedAbilityConfig(chain, this, true, npcSlots));
// Copy chain scripts server-side (client never has script handlers)
if (sourceChainName != null && !sourceChainName.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(
CopyAbilityScriptsPacket.MODE_CHAINED, sourceChainName, chain.getId()));
}
}
updateNpcAbilitiesList();
save();
@@ -1028,6 +1034,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
ChainedAbility chain = slot.getInlineChain();
if (chain != null && selectedEntryIndex < chain.getEntries().size()) {
ChainedAbilityEntry entry = chain.getEntries().get(selectedEntryIndex);
// Capture source ability reference before convertToInline clears it
String sourceAbilityRef = entry.getAbilityReference();
if (entry.convertToInline()) {
Ability a = entry.getInlineAbility();
if (a != null && !a.isBuiltIn()) {
@@ -1036,6 +1044,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
editChainEntryIdx = selectedEntryIndex;
a.setNpcInlineEdit(true);
setSubGui(a.createConfigGui(this));
// Copy ability scripts server-side (client never has script handlers)
if (sourceAbilityRef != null && !sourceAbilityRef.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(sourceAbilityRef, a.getId()));
}
}
}
}
@@ -1056,12 +1068,18 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
// Standalone ability reference → convert to inline
Ability preCheck = slot.getAbility();
if (preCheck != null && preCheck.isBuiltIn()) return;
// Capture source reference before convertToInline clears it
String sourceAbilityRef = slot.getReferenceId();
if (slot.convertToInline()) {
Ability ability = slot.getAbility();
if (ability != null && !ability.isBuiltIn()) {
// UUID already generated by convertToInline() - don't reassign or script handler is orphaned
ability.setNpcInlineEdit(true);
setSubGui(ability.createConfigGui(this));
// Copy ability scripts server-side (client never has script handlers)
if (sourceAbilityRef != null && !sourceAbilityRef.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(sourceAbilityRef, ability.getId()));
}
}
updateNpcAbilitiesList();
save();