Create IAbilityEffect + Concurrent Ability Support for Chained Abilities

This commit is contained in:
Kam committed 2026-02-19 12:55:37 -05:00
1 parent 1e45d96253
commit e54a9a83bb
32 files changed
+1754 -382

No files matched your search

@@ -5,6 +5,7 @@ import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.ConcurrentSlot;
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import net.minecraft.entity.EntityLivingBase;
@@ -13,6 +14,7 @@ import noppes.npcs.controllers.AnimationController;
import noppes.npcs.controllers.data.Animation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -74,6 +76,12 @@ public abstract class AbstractDataAbilities {
*/
protected boolean interruptCooldownRolled = false;
/**
* Concurrent ability execution slots. Ticked independently alongside the primary ability.
* Concurrent abilities skip animations, sounds, and movement/rotation locks.
*/
protected List<ConcurrentSlot> concurrentSlots = new ArrayList<>();
// ═══════════════════════════════════════════════════════════════════
// ABSTRACT METHODS - Subclasses must implement
// ═══════════════════════════════════════════════════════════════════
@@ -606,8 +614,12 @@ public abstract class AbstractDataAbilities {
return;
}
}
startChainEntry(chainTarget);
if (startChainEntry(chainTarget)) {
launchConsecutiveConcurrentEntries(chainTarget);
}
}
// Tick concurrent slots even during chain delay
tickConcurrentSlots();
return;
}
@@ -747,6 +759,9 @@ public abstract class AbstractDataAbilities {
// Post-phase hook (NPC: hit scan + movement control)
onPostPhaseTick(currentAbility, target);
// Tick concurrent slots independently
tickConcurrentSlots();
}
// ═══════════════════════════════════════════════════════════════════
@@ -784,6 +799,10 @@ public abstract class AbstractDataAbilities {
int delay = completedEntry.getDelayTicks();
chainEntryIndex++;
// Skip any consecutive concurrent entries — launch them to concurrent slots
launchConsecutiveConcurrentEntries(target);
if (chainEntryIndex < currentChain.getEntries().size()) {
// Check if target died and retarget
if (target != null && target.isDead) {
@@ -884,6 +903,9 @@ public abstract class AbstractDataAbilities {
chainDelayRemaining = -1;
}
// Interrupt all concurrent slots
interruptConcurrentSlots();
// Let subclass handle cleanup
onInterruptComplete();
}
@@ -915,7 +937,11 @@ public abstract class AbstractDataAbilities {
chainDelayRemaining = -1;
// AFTER semantics: no delay before first entry (delay applies after each entry completes)
return startChainEntry(target);
boolean started = startChainEntry(target);
if (started) {
launchConsecutiveConcurrentEntries(target);
}
return started;
}
/**
@@ -983,8 +1009,74 @@ public abstract class AbstractDataAbilities {
return true;
}
// ═══════════════════════════════════════════════════════════════════
// CONCURRENT SLOT MANAGEMENT
// ═══════════════════════════════════════════════════════════════════
/**
* Tick all active concurrent slots. Remove completed ones.
* Called from tickCurrentAbility() and during chain delay countdown.
*/
protected void tickConcurrentSlots() {
if (concurrentSlots.isEmpty()) return;
EntityLivingBase entity = getEntity();
EntityLivingBase target = getTarget();
Iterator<ConcurrentSlot> it = concurrentSlots.iterator();
while (it.hasNext()) {
ConcurrentSlot slot = it.next();
slot.tick(entity, target);
if (slot.isCompleted()) {
it.remove();
}
}
}
/**
* After starting a primary chain entry, scan forward and launch any consecutive
* concurrent entries (with delay=0) to concurrent slots immediately.
* This enables simultaneous execution of Effect abilities alongside the primary.
*/
protected void launchConsecutiveConcurrentEntries(EntityLivingBase target) {
if (currentChain == null) return;
List<ChainedAbilityEntry> entries = currentChain.getEntries();
while (chainEntryIndex + 1 < entries.size()) {
ChainedAbilityEntry nextEntry = entries.get(chainEntryIndex + 1);
Ability resolved = nextEntry.resolve();
if (resolved == null || !resolved.isConcurrentCapable()
|| !nextEntry.isConcurrentEnabled()) break;
// Only auto-launch concurrent entries with 0 delay
if (nextEntry.getDelayTicks() > 0) break;
// Advance past this entry in the chain (it runs concurrently, not sequentially)
chainEntryIndex++;
// Deep copy the ability so it has its own state
Ability concurrentCopy = AbilityController.Instance.fromNBT(resolved.writeNBT());
if (concurrentCopy == null) continue;
ConcurrentSlot slot = new ConcurrentSlot(concurrentCopy);
concurrentSlots.add(slot);
slot.start(getEntity(), target);
}
}
/**
* Interrupt all active concurrent slots. Called on ability interrupt or combat reset.
*/
protected void interruptConcurrentSlots() {
for (ConcurrentSlot slot : concurrentSlots) {
slot.interrupt();
}
concurrentSlots.clear();
}
/**
* Complete the chain execution. Rolls chain cooldown and clears all chain state.
* NOTE: Does NOT clear concurrent slots — they outlive the chain and tick independently.
*/
protected void completeChain() {
if (currentChain != null) {
+3 -1
View File
@@ -326,10 +326,11 @@ public class DataAbilities extends AbstractDataAbilities {
if (rotationLocked || hitScanActive) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
}
// Clear chain state
// Clear chain and concurrent state
currentChain = null;
chainEntryIndex = -1;
chainDelayRemaining = -1;
interruptConcurrentSlots();
return;
}
@@ -724,6 +725,7 @@ public class DataAbilities extends AbstractDataAbilities {
public void reset() {
stopCurrentAbility();
clearActiveToggles();
interruptConcurrentSlots();
// Roll cooldown so NPC doesn't immediately attack after reset
rollCooldownOnReset();
@@ -34,6 +34,7 @@ import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -187,7 +188,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
}
availableTypesScroll.guiLeft = guiLeft + 5;
availableTypesScroll.guiTop = y + 12;
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
addScroll(availableTypesScroll);
// Search bar for types
@@ -541,7 +542,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
filteredAbilityTypes.putAll(getFilteredData(allAbilityTypes));
if (availableTypesScroll != null) {
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
}
} else if (type == EnumScrollData.CUSTOM_ABILITIES) {
existingPresetNames.clear();
@@ -605,7 +606,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
if (search.equals(getTextField(TF_SEARCH).getText()))
return;
search = getTextField(TF_SEARCH).getText().toLowerCase();
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
availableTypesScroll.resetScroll();
}
}
@@ -640,16 +641,21 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
displayNameToTypeId.clear();
for (String typeId : filteredAbilityTypes.keySet()) {
String displayName = I18n.format(typeId);
// Search matches either the display name or the typeId
if (search.isEmpty() || displayName.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
// Gray out built-in types to distinguish them from configurable types
if (AbilityController.Instance.isBuiltInType(typeId)) {
// Search matches either the display name or the typeId (strip color codes for matching)
String stripped = displayName.replaceAll("\u00A7.", "");
if (search.isEmpty() || stripped.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
// Yellow for concurrent-capable types, gray for other built-in types
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
} else if (AbilityController.Instance.isBuiltInType(typeId)) {
displayName = "\u00A77" + displayName;
}
list.add(displayName);
displayNameToTypeId.put(displayName, typeId);
}
}
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
return list;
}
@@ -144,9 +144,12 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
int y = 5;
int labelCounter = LABEL_ID_START;
// General tab: type label at top — need to reserve space before building
// General tab: type label + optional concurrent label at top — reserve space
if (activeTab == TAB_GENERAL) {
y += ROW_H;
if (ability.isConcurrentCapable()) {
y += 15;
}
}
// Build declarative fields into an auto-created scroll window
@@ -157,10 +160,15 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
// General tab: add type label at top of scroll window
// General tab: add type label + optional concurrent label at top of scroll window
if (activeTab == TAB_GENERAL) {
sw.addLabel(new GuiNpcLabel(builder.getNextLabelId(), "gui.type", 5, 5 + 5, 0xFFFFFF));
sw.addLabel(new GuiNpcLabel(builder.getNextLabelId() + 1, ability.getTypeId(), 55, 5 + 5, 0xFFFFFF));
int baseId = builder.getNextLabelId();
sw.addLabel(new GuiNpcLabel(baseId, "gui.type", 5, 10, 0xFFFFFF));
sw.addLabel(new GuiNpcLabel(baseId + 1, ability.getTypeId(), 55, 10, 0xFFFFFF));
if (ability.isConcurrentCapable()) {
sw.addLabel(new GuiNpcLabel(baseId + 2,
StatCollector.translateToLocal("ability.concurrentInfo"), 5, 25, 0x55FF55));
}
}
// Conditions on target tab — appended after field defs
@@ -11,6 +11,7 @@ import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -47,7 +48,7 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
addScroll(scroll);
buildAllTypes();
scroll.setList(getFilteredTypeList());
scroll.setUnsortedList(getFilteredTypeList());
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.add"));
getButton(0).setEnabled(scroll.hasSelected());
@@ -59,6 +60,9 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
String[] types = AbilityController.Instance.getTypes();
for (String typeId : types) {
String displayName = I18n.format(typeId);
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
}
allDisplayNameToTypeId.put(displayName, typeId);
}
}
@@ -68,11 +72,14 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
displayNameToTypeId.clear();
for (Map.Entry<String, String> entry : allDisplayNameToTypeId.entrySet()) {
String displayName = entry.getKey();
if (search.isEmpty() || displayName.toLowerCase().contains(search) || entry.getValue().toLowerCase().contains(search)) {
String stripped = displayName.replaceAll("\u00A7.", "");
if (search.isEmpty() || stripped.toLowerCase().contains(search) || entry.getValue().toLowerCase().contains(search)) {
list.add(displayName);
displayNameToTypeId.put(displayName, entry.getValue());
}
}
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
return list;
}
@@ -144,7 +144,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
// Computed "Valid For" label (derived from child abilities)
fieldDefs.add(FieldDef.labelField("ability.validFor", () -> {
UserType ut = computeAllowedBy();
return StatCollector.translateToLocal("ability.validFor") + ": \u00A7e" + StatCollector.translateToLocal("ability.userType." + ut.name());
return "\u00A7e" + StatCollector.translateToLocal("ability.userType." + ut.name());
}).tab("General"));
fieldDefs.add(FieldDef.boolField("gui.enabled", chain::isEnabled, chain::setEnabled).tab("General"));
fieldDefs.add(FieldDef.intField("ability.weight", chain::getWeight, chain::setWeight).range(1, 100).tab("General"));
@@ -325,12 +325,22 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
sw.addButton(entryBtn);
if (!readOnlyEntries) {
// Check if this entry is concurrent-active (delay disabled)
Ability resolvedAbility = entry.resolve();
boolean isConcurrentActive = resolvedAbility != null
&& resolvedAbility.isConcurrentCapable()
&& entry.isConcurrentEnabled();
// Delay label + field
sw.addLabel(new GuiNpcLabel(labelCounter++, "ability.delay", L_LABEL_X + 160, y + 5, 0xAAAAAA));
sw.addLabel(new GuiNpcLabel(labelCounter++, "ability.delay", L_LABEL_X + 160, y + 5,
isConcurrentActive ? 0x555555 : 0xAAAAAA));
GuiNpcTextField delayField = new GuiNpcTextField(ENTRY_BASE + i * ENTRY_STRIDE + 1, this, fontRendererObj,
L_LABEL_X + 195, y, 40, 20, String.valueOf(entry.getDelayTicks()));
delayField.setIntegersOnly();
delayField.setMinMaxDefault(0, 6000, 0);
if (isConcurrentActive) {
delayField.setEnabled(false);
}
sw.addTextField(delayField);
// Up button
@@ -343,8 +353,16 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 3, L_LABEL_X + 263, y, 20, 20, "\u2193"));
}
// Concurrent toggle (only shown if resolved ability is concurrent-capable, never for first entry)
if (i > 0 && resolvedAbility != null && resolvedAbility.isConcurrentCapable()) {
String cLabel = entry.isConcurrentEnabled() ? "\u00A7aC" : "\u00A77C";
GuiNpcButton cBtn = new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 5, L_LABEL_X + 288, y, 20, 20, cLabel);
cBtn.setHoverText("ability.hover.concurrent");
sw.addButton(cBtn);
}
// Delete button
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 4, L_LABEL_X + 288, y, 20, 20, "X"));
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 4, L_LABEL_X + 313, y, 20, 20, "X"));
} else {
// Read-only: show delay as label only
int delay = entry.getDelayTicks();
@@ -549,6 +567,10 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
if (entryIndex > 0) {
ChainedAbilityEntry entry = entries.remove(entryIndex);
entries.add(entryIndex - 1, entry);
// Can't be concurrent at position 0
if (entryIndex - 1 == 0) {
entry.setConcurrentEnabled(false);
}
initGui();
}
return true;
@@ -563,6 +585,15 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
entries.remove(entryIndex);
initGui();
return true;
case 5: // Concurrent toggle
ChainedAbilityEntry toggleEntry = entries.get(entryIndex);
boolean newState = !toggleEntry.isConcurrentEnabled();
toggleEntry.setConcurrentEnabled(newState);
if (newState) {
toggleEntry.setDelayTicks(0);
}
initGui();
return true;
}
}
@@ -0,0 +1,149 @@
package noppes.npcs.client.gui.advanced;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.data.CustomEffect;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* SubGui for selecting a custom effect from CustomEffectController.
*/
@SideOnly(Side.CLIENT)
public class SubGuiCustomEffectSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
private GuiCustomScroll scroll;
private final HashMap<String, Integer> displayNameToId = new HashMap<>();
private final HashMap<String, Integer> allDisplayNameToId = new HashMap<>();
private int selectedEffectId = -1;
private String search = "";
private final int preselectedId;
public SubGuiCustomEffectSelect(int preselectedId) {
this.preselectedId = preselectedId;
setBackground("menubg.png");
xSize = 200;
ySize = 216;
}
@Override
public void initGui() {
super.initGui();
addTextField(new GuiNpcTextField(10, this, fontRendererObj, guiLeft + 5, guiTop + 5, 190, 18, search));
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
scroll.setSize(190, 145);
}
scroll.guiLeft = guiLeft + 5;
scroll.guiTop = guiTop + 26;
addScroll(scroll);
buildAllEffects();
List<String> filtered = getFilteredList();
scroll.setUnsortedList(filtered);
// Pre-select current effect
if (preselectedId >= 0 && !scroll.hasSelected()) {
for (String name : filtered) {
Integer id = displayNameToId.get(name);
if (id != null && id == preselectedId) {
scroll.setSelected(name);
break;
}
}
}
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.select"));
getButton(0).setEnabled(scroll.hasSelected());
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
}
private void buildAllEffects() {
allDisplayNameToId.clear();
HashMap<Integer, CustomEffect> effects = CustomEffectController.getInstance().getCustomEffects();
if (effects == null) return;
for (CustomEffect ce : effects.values()) {
if (ce.getName() != null && !ce.getName().isEmpty()) {
allDisplayNameToId.put(ce.getName(), ce.id);
}
}
}
private List<String> getFilteredList() {
List<String> list = new ArrayList<>();
displayNameToId.clear();
for (Map.Entry<String, Integer> entry : allDisplayNameToId.entrySet()) {
String name = entry.getKey();
if (search.isEmpty() || name.toLowerCase().contains(search)) {
list.add(name);
displayNameToId.put(name, entry.getValue());
}
}
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
}
@Override
public void buttonEvent(GuiButton guibutton) {
if (guibutton.id == 0 && scroll.hasSelected()) {
String name = scroll.getSelected();
Integer id = displayNameToId.get(name);
selectedEffectId = id != null ? id : -1;
close();
} else if (guibutton.id == 1) {
selectedEffectId = -1;
close();
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0) {
getButton(0).setEnabled(scroll.hasSelected());
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0 && selection != null) {
Integer id = displayNameToId.get(selection);
selectedEffectId = id != null ? id : -1;
close();
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(10) != null && getTextField(10).isFocused()) {
String newSearch = getTextField(10).getText().toLowerCase();
if (!search.equals(newSearch)) {
search = newSearch;
scroll.setUnsortedList(getFilteredList());
scroll.resetScroll();
}
}
}
@Override
public void unFocused(GuiNpcTextField textField) {
}
public int getSelectedEffectId() {
return selectedEffectId;
}
}
@@ -15,5 +15,7 @@ public enum FieldType {
SECTION_HEADER,
LABEL,
EFFECTS_LIST,
CUSTOM_EFFECTS_LIST,
EFFECT_ACTIONS_LIST,
ROW
}
@@ -635,10 +635,11 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
releaseLockedPosition();
}
// Clear chain state
// Clear chain and concurrent state
currentChain = null;
chainEntryIndex = -1;
chainDelayRemaining = -1;
interruptConcurrentSlots();
// Clear all transient state
currentAbility = null;