mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 05:19:41 +00:00
Burst and Dual Mode + Variant Ability Support
This commit is contained in:
1 parent
af02b0ab1d
commit
74cae17ebd
27 files changed
+2055
-2982
No files matched your search
@@ -174,11 +174,23 @@ public class DataAbilities {
|
||||
// Handle phase-specific logic
|
||||
switch (currentAbility.getPhase()) {
|
||||
case WINDUP:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.BURST_DELAY) {
|
||||
// Burst replay: re-enter windup - set up telegraph, sound, animation, locks
|
||||
if (currentAbility.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (currentAbility.isMovementLockedDuringWindup() && !currentAbility.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
spawnTelegraph(currentAbility, target);
|
||||
playAbilitySound(currentAbility.getWindUpSound());
|
||||
playAbilityAnimation(currentAbility.getWindUpAnimation());
|
||||
}
|
||||
currentAbility.onWindUpTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
|
||||
if (phaseChanged && (oldPhase == AbilityPhase.WINDUP || oldPhase == AbilityPhase.BURST_DELAY)) {
|
||||
// Just entered ACTIVE phase - lock telegraph position if it was following
|
||||
// This commits the ability to its current target position
|
||||
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
|
||||
@@ -207,6 +219,11 @@ public class DataAbilities {
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Burst re-fire without replay: let entity-spawning abilities spawn+fire in one step
|
||||
if (oldPhase == AbilityPhase.BURST_DELAY && !currentAbility.isBurstReplayAnimations()) {
|
||||
currentAbility.onBurstRefire(npc, target, npc.worldObj);
|
||||
}
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(currentAbility.getActiveSound());
|
||||
playAbilityAnimation(currentAbility.getActiveAnimation());
|
||||
@@ -240,6 +257,31 @@ public class DataAbilities {
|
||||
handleAbilityCompletion(target);
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-complete for burst overlap mode (entities fly independently)
|
||||
// This allows entity-spawning abilities to immediately chain next burst
|
||||
// without each type needing to check burst state in their onActiveTick()
|
||||
// Wait until all staggered projectiles have been fired before auto-completing
|
||||
if (currentAbility.isBurstEnabled() && currentAbility.isBurstOverlap()
|
||||
&& currentAbility.getBurstIndex() < currentAbility.getBurstAmount()
|
||||
&& currentAbility.getPhase() == AbilityPhase.ACTIVE
|
||||
&& currentAbility.isReadyForBurstCompletion(currentAbility.getCurrentTick())) {
|
||||
currentAbility.signalCompletion();
|
||||
}
|
||||
|
||||
// Check if ability entered burst delay during onActiveTick or overlap auto-complete
|
||||
if (currentAbility.getPhase() == AbilityPhase.BURST_DELAY) {
|
||||
// Release all locks - free movement/rotation during delay
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
if (hitScanActive) releaseRotationControl();
|
||||
}
|
||||
break;
|
||||
|
||||
case BURST_DELAY:
|
||||
// Free movement and rotation during burst delay
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
break;
|
||||
|
||||
case DAZED:
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
|
||||
@@ -61,6 +62,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Existing preset names for duplicate checking
|
||||
private final Set<String> existingPresetNames = new HashSet<>();
|
||||
|
||||
// Pending variant selection
|
||||
private String pendingTypeId = null;
|
||||
|
||||
public static int modIndex = 0;
|
||||
public static ScrollType scrollType = ScrollType.CNPC;
|
||||
|
||||
@@ -197,8 +201,17 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
String displayName = availableTypesScroll.getSelected();
|
||||
String typeId = displayNameToTypeId.get(displayName);
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
npcSlots.add(AbilitySlot.inline(newAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
@@ -633,7 +646,24 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
|
||||
int idx = variantGui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
variantGui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
npcSlots.add(AbilitySlot.inline(newAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
save();
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
initGui();
|
||||
} else if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
int mode = ((SubGuiAbilityEditMode) subgui).getResult();
|
||||
if (mode < 0) return; // cancelled
|
||||
|
||||
|
||||
@@ -324,7 +324,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
if (textField.id < DECLARATIVE_ID_START) return;
|
||||
builder.handleTextFieldEvent(textField.id, textField);
|
||||
if (builder.handleTextFieldEvent(textField.id, textField)) {
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiScrollWindow;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SubGui for selecting a variant/template when creating a new ability.
|
||||
* Uses a scroll window so external mods can register many variants.
|
||||
*/
|
||||
public class SubGuiAbilityVariantSelect extends SubGuiInterface {
|
||||
|
||||
private static final int VARIANT_BTN_START = 10;
|
||||
private static final int BTN_H = 20;
|
||||
private static final int BTN_PAD = 2;
|
||||
|
||||
private final List<AbilityVariant> variants;
|
||||
private final List<String> displayNames = new ArrayList<>();
|
||||
private int selectedIndex = -1;
|
||||
|
||||
public SubGuiAbilityVariantSelect(List<AbilityVariant> variants) {
|
||||
this.variants = variants;
|
||||
for (AbilityVariant variant : variants) {
|
||||
displayNames.add(StatCollector.translateToLocal(variant.getDisplayKey()));
|
||||
}
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 216;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.selectVariant", guiLeft + 10, guiTop + 8));
|
||||
|
||||
// Scroll window for variant buttons
|
||||
int swX = guiLeft + 5;
|
||||
int swY = guiTop + 22;
|
||||
int swW = 190;
|
||||
int swH = 155;
|
||||
|
||||
GuiScrollWindow sw = new GuiScrollWindow(this, swX, swY, swW, swH, 0);
|
||||
addScrollableGui(0, sw); // Must register BEFORE adding components (initGui clears them)
|
||||
|
||||
int localY = 2;
|
||||
int btnW = swW - 14; // Leave room for scrollbar
|
||||
for (int i = 0; i < displayNames.size(); i++) {
|
||||
GuiNpcButton btn = new GuiNpcButton(VARIANT_BTN_START + i, 2, localY, btnW, BTN_H, displayNames.get(i));
|
||||
if (i == selectedIndex) {
|
||||
btn.packedFGColour = 0x55FF55;
|
||||
}
|
||||
sw.addButton(btn);
|
||||
localY += BTN_H + BTN_PAD;
|
||||
}
|
||||
sw.maxScrollY = Math.max(localY - swH, 0);
|
||||
|
||||
// Select / Cancel buttons
|
||||
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.select"));
|
||||
getButton(0).setEnabled(selectedIndex >= 0);
|
||||
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == 0 && selectedIndex >= 0) {
|
||||
close();
|
||||
} else if (id == 1) {
|
||||
selectedIndex = -1;
|
||||
close();
|
||||
} else if (id >= VARIANT_BTN_START && id < VARIANT_BTN_START + displayNames.size()) {
|
||||
selectedIndex = id - VARIANT_BTN_START;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public List<AbilityVariant> getVariants() {
|
||||
return variants;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,9 @@ public class GuiFieldBuilder {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip invisible fields
|
||||
if (!def.isVisible()) continue;
|
||||
|
||||
// Section header
|
||||
if (def.getType() == FieldType.SECTION_HEADER) {
|
||||
y += 3;
|
||||
@@ -391,7 +394,7 @@ public class GuiFieldBuilder {
|
||||
|
||||
/**
|
||||
* Handles text field unfocus events for declarative fields.
|
||||
* Call from parent GUI's unFocused(). Returns true if the event was handled.
|
||||
* Call from parent GUI's unFocused(). Returns true if the value actually changed.
|
||||
*/
|
||||
public boolean handleTextFieldEvent(int textFieldId, GuiNpcTextField field) {
|
||||
FieldDef def = textFieldMap.get(textFieldId);
|
||||
@@ -399,14 +402,36 @@ public class GuiFieldBuilder {
|
||||
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
try { def.setValue(Float.parseFloat(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
try {
|
||||
float newVal = Float.parseFloat(field.getText());
|
||||
Object old = def.getValue();
|
||||
float oldVal = old instanceof Number ? ((Number) old).floatValue() : 0f;
|
||||
if (newVal != oldVal) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
return false;
|
||||
case INT:
|
||||
try { def.setValue(Integer.parseInt(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
try {
|
||||
int newVal = Integer.parseInt(field.getText());
|
||||
Object old = def.getValue();
|
||||
int oldVal = old instanceof Number ? ((Number) old).intValue() : 0;
|
||||
if (newVal != oldVal) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
return false;
|
||||
case STRING:
|
||||
def.setValue(field.getText());
|
||||
return true;
|
||||
String newVal = field.getText();
|
||||
Object old = def.getValue();
|
||||
String oldVal = old != null ? old.toString() : "";
|
||||
if (!newVal.equals(oldVal)) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityTypeSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityVariantSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiDuplicateNameConfirm;
|
||||
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
|
||||
import noppes.npcs.client.gui.util.GuiAbilityInterface;
|
||||
@@ -68,6 +70,9 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private Ability pendingSaveAbility = null;
|
||||
private boolean pendingNewCreation = false;
|
||||
|
||||
// ==================== PENDING VARIANT ====================
|
||||
private String pendingTypeId = null;
|
||||
|
||||
// ==================== PREVIEW ====================
|
||||
private AbilityPreviewExecutor previewExecutor;
|
||||
private long prevTick = 0;
|
||||
@@ -343,11 +348,41 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
|
||||
int idx = variantGui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
variantGui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
saveAndOpenConfig(newAbility);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
} else if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
String typeId = ((SubGuiAbilityTypeSelect) subgui).getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
|
||||
Reference in new issue
Block a user