From 49e4b2bca38acfdc4f219771057aa09f47e002e9 Mon Sep 17 00:00:00 2001 From: Glasir Date: Sun, 5 Nov 2023 09:33:02 -0500 Subject: [PATCH] Refactored Passive abilities! * AB: Brought passives up-to-date with actives * AB: Implemented Chaos to demonstrate passives with requirements * AB: Added cooldown indicator for Passives * AB: Refactored Instant transformation actions (not slow ones) to function with passives * AB: Fixed transform edge case with a paid transformation that has a duration * AB: Fixed transform edge case where the timing of altitude adjustment could be messed up * AB: Fixed cast animation timing where it would sometimes play over morph * AB: Removed unneeded classes related to failed first Buff implementation * Core: Changed selection method of animations to default to stand when others not found * Core: Fixed crash when ability removed itself as part of onAdd actions * Core: Fixed issue with change to requirements string --- .../abilityBehaviors/Transformations.json | 100 +++++++++ .../viewer5/handlers/w3x/SequenceUtils.java | 5 +- ...CardActivationReceiverPreviewCallback.java | 6 +- .../handlers/w3x/simulation/CUnit.java | 7 +- .../ability/AbilityBuilderAbility.java | 29 +++ .../ability/AbilityBuilderActiveAbility.java | 2 +- .../ability/AbilityBuilderPassiveAbility.java | 5 + .../ability/CAbilityAbilityBuilderBuff.java | 31 --- .../CAbilityAbilityBuilderGenericActive.java | 20 +- .../ability/CAbilityAbilityBuilderNoIcon.java | 155 ++++++++++++- .../CAbilityAbilityBuilderPassive.java | 170 +++++++++++++- .../ability/GetABAbilityByRawcodeVisitor.java | 67 +++--- .../GetInstantTransformationBuffVisitor.java | 209 ++++++++++++++++++ .../behavior/CBehaviorAbilityBuilderBase.java | 8 +- .../CBehaviorAbilityBuilderNoTarget.java | 8 +- .../CBehaviorFinishTransformation.java | 4 +- .../action/ABActionCreateBuffFromId.java | 30 --- .../action/ability/ABActionResetCooldown.java | 6 +- .../action/ability/ABActionStartCooldown.java | 6 +- .../unit/ABActionTransformUnitInstant.java | 15 +- .../ABActionTransformedUnitAbilityAdd.java | 30 ++- .../ABCallbackGetAbilityArea.java | 8 +- .../ABTimedInstantTransformationBuff.java | 57 +++++ .../abilitybuilder/core/ABLocalStoreKeys.java | 4 +- .../core/AbilityBuilderGsonBuilder.java | 1 - .../handler/TransformationHandler.java | 144 +++++++----- .../parser/AbilityBuilderType.java | 1 - .../DelayInstantTransformationTimer.java | 8 +- .../abilitybuilder/timer/DelayTimerTimer.java | 8 +- .../impl/CAbilityTypeAbilityBuilder.java | 2 - .../w3x/simulation/data/CAbilityData.java | 20 +- 31 files changed, 936 insertions(+), 230 deletions(-) create mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderAbility.java create mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderPassiveAbility.java delete mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderBuff.java create mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetInstantTransformationBuffVisitor.java delete mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ABActionCreateBuffFromId.java create mode 100644 core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/buff/ABTimedInstantTransformationBuff.java diff --git a/core/assets/abilityBehaviors/Transformations.json b/core/assets/abilityBehaviors/Transformations.json index 8ce59d5a..8c295415 100644 --- a/core/assets/abilityBehaviors/Transformations.json +++ b/core/assets/abilityBehaviors/Transformations.json @@ -278,6 +278,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -716,6 +730,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -1185,6 +1213,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -1683,6 +1725,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -2170,6 +2226,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -2655,6 +2725,20 @@ } } }, + "requiresPayment": { + "type": "i2b", + "value": { + "type": "i&", + "value1": { + "type": "getAbilityDataAsInteger", + "dataField": "B" + }, + "value2": { + "type": "rawInteger", + "value": 16 + } + } + }, "altitudeAdjustmentDelay": { "type": "getAbilityCastTime" }, @@ -3221,5 +3305,21 @@ } }] }] + },{ + "ids": [{"id":"Acha"}], + "type": "HIDDEN", + "onAddAbility": [{ + "type": "transformUnitInstant", + "unit": { + "type": "getCastingUnit" + }, + "alternateUnitId": { + "type": "getAbilityUnitId" + }, + "permanent": { + "type": "rawBoolean", + "value": "true" + } + }] }] } \ No newline at end of file diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/SequenceUtils.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/SequenceUtils.java index 85917d39..4c5dedd0 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/SequenceUtils.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/SequenceUtils.java @@ -115,7 +115,7 @@ public static int matchRank(final EnumSet goalTagS return matchRank; } - public static IndexedSequence selectSequence(final AnimationTokens.PrimaryTag type, + public static IndexedSequence selectSequence(AnimationTokens.PrimaryTag type, final EnumSet tags, final List sequences, final boolean allowRarityVariations) { List filtered = filterSequences(type, tags, sequences); @@ -141,6 +141,9 @@ public static IndexedSequence selectSequence(final AnimationTokens.PrimaryTag ty } } if (fallbackTags == null) { + if (type == null) { + type = PrimaryTag.STAND; + } for (int i = 0, l = sequences.size(); i < l; i++) { final Sequence sequence = sequences.get(i); if (sequence.getPrimaryTags().contains(type) || (type == null)) { diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardActivationReceiverPreviewCallback.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardActivationReceiverPreviewCallback.java index 6b659c4d..84a7b741 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardActivationReceiverPreviewCallback.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/rendersim/commandbuttons/CommandCardActivationReceiverPreviewCallback.java @@ -56,7 +56,11 @@ public void missingRequirement(final War3ID type, final int level) { final CUnitType unitType = unitData.getUnitType(type); String requirementString; if (unitType != null) { - requirementString = level + " " + unitType.getName() + (level > 1 ? "s" : ""); + if (level > 1) { + requirementString = level + " " + unitType.getName() + "s"; + } else { + requirementString = unitType.getName(); + } } else { final CUpgradeType upgradeType = upgradeData .getType(type); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java index 5e0dd3aa..76bf4f6b 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CUnit.java @@ -1339,16 +1339,13 @@ public void checkDisabledAbilities(final CSimulation simulation, final boolean d } } } else { - final Iterator abilityIterator = this.disabledAbilities.iterator(); - while (abilityIterator.hasNext()) { - final CAbility ability = abilityIterator.next(); + for (CAbility ability : new ArrayList<>(this.disabledAbilities)) { if (ability.isRequirementsMet(simulation, this)) { ability.setDisabled(false, CAbilityDisableType.REQUIREMENTS); } if (!ability.isDisabled()) { -// System.err.println("Enabling ability: " + ability.getAlias().asStringValue()); ability.onAdd(simulation, this); - abilityIterator.remove(); + this.disabledAbilities.remove(ability); } } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderAbility.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderAbility.java new file mode 100644 index 00000000..9e8f9d4a --- /dev/null +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderAbility.java @@ -0,0 +1,29 @@ +package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability; + +import java.util.List; +import java.util.Map; + +import com.etheller.warsmash.util.War3ID; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.Aliased; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.generic.CLevelingAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.parser.AbilityBuilderConfiguration; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; + +public interface AbilityBuilderAbility extends CLevelingAbility, Aliased { + public List getLevelData(); + + public AbilityBuilderConfiguration getConfig(); + + public Map getLocalStore(); + + public float getArea(); + + public void startCooldown(CSimulation game, CUnit unit); + + public void resetCooldown(CSimulation game, CUnit unit); + + War3ID getOnTooltipOverride(); + +} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderActiveAbility.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderActiveAbility.java index 32687f10..ca76adc2 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderActiveAbility.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderActiveAbility.java @@ -16,7 +16,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityTargetCheckReceiver; -public interface AbilityBuilderActiveAbility extends GenericSingleIconActiveAbility { +public interface AbilityBuilderActiveAbility extends AbilityBuilderAbility, GenericSingleIconActiveAbility { public List getLevelData(); public AbilityBuilderConfiguration getConfig(); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderPassiveAbility.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderPassiveAbility.java new file mode 100644 index 00000000..47a2001b --- /dev/null +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/AbilityBuilderPassiveAbility.java @@ -0,0 +1,5 @@ +package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability; + +public interface AbilityBuilderPassiveAbility extends AbilityBuilderAbility { + +} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderBuff.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderBuff.java deleted file mode 100644 index 4559eef5..00000000 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderBuff.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability; - -import java.util.List; -import java.util.Map; - -import com.etheller.warsmash.util.War3ID; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.parser.AbilityBuilderConfiguration; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; - -public class CAbilityAbilityBuilderBuff extends CAbilityAbilityBuilderNoIcon { - - public CAbilityAbilityBuilderBuff(int handleId, War3ID code, War3ID alias, List levelData, - AbilityBuilderConfiguration config, Map localStore) { - super(handleId, code, alias, levelData, config, localStore); - } - - public void setParentLevelData(List parentLevelData) { - this.localStore.put(ABLocalStoreKeys.PARENTLEVELDATA, parentLevelData); - } - - public void setParentCaster(CUnit parentCaster) { - this.localStore.put(ABLocalStoreKeys.PARENTCASTER, parentCaster); - } - - public void setParentLocalStore(Map parentLocalStore) { - this.localStore.put(ABLocalStoreKeys.PARENTLOCALSTORE, parentLocalStore); - } - -} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderGenericActive.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderGenericActive.java index af050f7b..1bf9f87c 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderGenericActive.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderGenericActive.java @@ -205,17 +205,6 @@ private void determineToggleableFields(CSimulation game, CUnit unit) { this.active = true; } } - - if (this.config.getOverrideFields() != null) { - if (this.config.getOverrideFields().getOnTooltipOverride() != null) { - this.onTooltipOverride = this.config.getOverrideFields().getOnTooltipOverride().callback(game, unit, - localStore, castId); - } - if (this.config.getOverrideFields().getOffTooltipOverride() != null) { - this.offTooltipOverride = this.config.getOverrideFields().getOffTooltipOverride().callback(game, - unit, localStore, castId); - } - } } } @@ -241,6 +230,15 @@ protected void setSpellFields(CSimulation game, CUnit unit) { this.manaCost = this.config.getOverrideFields().getManaCostOverride().callback(game, unit, localStore, castId); } + + if (this.config.getOverrideFields().getOnTooltipOverride() != null) { + this.onTooltipOverride = this.config.getOverrideFields().getOnTooltipOverride().callback(game, unit, + localStore, castId); + } + if (this.config.getOverrideFields().getOffTooltipOverride() != null) { + this.offTooltipOverride = this.config.getOverrideFields().getOffTooltipOverride().callback(game, + unit, localStore, castId); + } } if (this.config.getDisplayFields() != null && this.config.getDisplayFields().getHideAreaCursor() != null) { diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderNoIcon.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderNoIcon.java index 5b21aa71..1b3ae4e1 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderNoIcon.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderNoIcon.java @@ -4,9 +4,12 @@ import java.util.Map; import com.etheller.warsmash.util.War3ID; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CItem; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitTypeRequirement; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityVisitor; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.generic.AbstractGenericNoIconAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.targeting.AbilityPointTarget; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABAction; @@ -14,31 +17,117 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.parser.AbilityBuilderConfiguration; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.CBehavior; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityActivationReceiver; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityTargetCheckReceiver; -public class CAbilityAbilityBuilderNoIcon extends AbstractGenericNoIconAbility { +public class CAbilityAbilityBuilderNoIcon extends AbstractGenericNoIconAbility implements AbilityBuilderAbility { protected List levelData; protected AbilityBuilderConfiguration config; protected Map localStore; + protected CItem item = null; + + protected float cooldown = 0; + protected float area = 0; + public CAbilityAbilityBuilderNoIcon(int handleId, War3ID code, War3ID alias, List levelData, AbilityBuilderConfiguration config, Map localStore) { super(handleId, code, alias); this.levelData = levelData; this.config = config; this.localStore = localStore; + localStore.put(ABLocalStoreKeys.ABILITY, this); + } + + protected void setSpellFields(CSimulation game, CUnit unit) { + CAbilityTypeAbilityBuilderLevelData levelDataLevel = this.levelData.get(this.getLevel() - 1); + this.cooldown = levelDataLevel.getCooldown(); + this.area = levelDataLevel.getArea(); + if (this.config.getOverrideFields() != null) { + if (this.config.getOverrideFields().getAreaOverride() != null) { + this.area = this.config.getOverrideFields().getAreaOverride().callback(game, unit, localStore, 0); + } + if (this.config.getOverrideFields().getCooldownOverride() != null) { + this.cooldown = this.config.getOverrideFields().getCooldownOverride().callback(game, unit, localStore, + 0); + } + } + } + + @Override + public List getLevelData() { + return this.levelData; + } + + @Override + public AbilityBuilderConfiguration getConfig() { + return this.config; + } + + @Override + public Map getLocalStore() { + return this.localStore; + } + + @Override + public float getArea() { + return area; + } + + @Override + public void startCooldown(CSimulation game, CUnit unit) { + War3ID cdID = getCooldownId(); + if (cdID != War3ID.NONE) { + unit.beginCooldown(game, cdID, this.cooldown); + } + } + + @Override + public void resetCooldown(CSimulation game, CUnit unit) { + War3ID cdID = getCooldownId(); + if (cdID != War3ID.NONE) { + unit.beginCooldown(game, cdID, 0); + } + } + + private War3ID getCooldownId() { + if (this.item != null) { + if (item.getItemType().isIgnoreCooldown()) { + return War3ID.NONE; + } else { + if (item.getItemType().getCooldownGroup() != null) { + return item.getItemType().getCooldownGroup(); + } + } + } + return getCode(); + } + + @Override + public void setItemAbility(final CItem item, int slot) { + this.item = item; + this.localStore.put(ABLocalStoreKeys.ITEM, item); + this.localStore.put(ABLocalStoreKeys.ITEMSLOT, slot); } @Override public void setLevel(CSimulation game, CUnit unit, int level) { super.setLevel(game, unit, level); localStore.put(ABLocalStoreKeys.CURRENTLEVEL, level); + setSpellFields(game, unit); + if (config.getOnLevelChange() != null) { + for (ABAction action : config.getOnLevelChange()) { + action.runAction(game, unit, localStore, 0); + } + } } @Override public void onAdd(CSimulation game, CUnit unit) { + localStore.put(ABLocalStoreKeys.GAME, game); + localStore.put(ABLocalStoreKeys.THISUNIT, unit); if (config.getOnAddAbility() != null) { for (ABAction action : config.getOnAddAbility()) { action.runAction(game, unit, localStore, 0); @@ -46,6 +135,18 @@ public void onAdd(CSimulation game, CUnit unit) { } } + @Override + public void onAddDisabled(CSimulation game, CUnit unit) { + localStore.put(ABLocalStoreKeys.GAME, game); + localStore.put(ABLocalStoreKeys.THISUNIT, unit); + setSpellFields(game, unit); + if (config.getOnAddDisabledAbility() != null) { + for (ABAction action : config.getOnAddDisabledAbility()) { + action.runAction(game, unit, localStore, 0); + } + } + } + @Override public void onRemove(CSimulation game, CUnit unit) { if (config.getOnRemoveAbility() != null) { @@ -55,6 +156,15 @@ public void onRemove(CSimulation game, CUnit unit) { } } + @Override + public void onRemoveDisabled(CSimulation game, CUnit unit) { + if (config.getOnRemoveDisabledAbility() != null) { + for (ABAction action : config.getOnRemoveDisabledAbility()) { + action.runAction(game, unit, localStore, 0); + } + } + } + @Override public void onTick(CSimulation game, CUnit unit) { } @@ -68,6 +178,44 @@ public void onDeath(CSimulation game, CUnit unit) { } } + @Override + public T visit(final CAbilityVisitor visitor) { + return visitor.accept(this); + } + + @Override + public void checkRequirementsMet(CSimulation game, CUnit unit, AbilityActivationReceiver receiver) { + List reqs = this.levelData.get(this.getLevel() - 1).getRequirements(); + CPlayer player = game.getPlayer(unit.getPlayerIndex()); + if (reqs != null) { + for (final CUnitTypeRequirement requirement : reqs) { + if (player.getTechtreeUnlocked(requirement.getRequirement()) < requirement.getRequiredLevel()) { + receiver.missingRequirement(requirement.getRequirement(), requirement.getRequiredLevel()); + } + } + } + } + + @Override + public boolean isRequirementsMet(CSimulation game, CUnit unit) { + List reqs = this.levelData.get(this.getLevel() - 1).getRequirements(); + CPlayer player = game.getPlayer(unit.getPlayerIndex()); + boolean requirementsMet = player.isTechtreeAllowedByMax(this.getAlias()); + if (reqs != null) { + for (final CUnitTypeRequirement requirement : reqs) { + if (player.getTechtreeUnlocked(requirement.getRequirement()) < requirement.getRequiredLevel()) { + requirementsMet = false; + } + } + } + return requirementsMet; + } + + + + + + // Unneeded Methods @Override public void onCancelFromQueue(CSimulation game, CUnit unit, int orderId) { @@ -110,4 +258,9 @@ public void checkCanTargetNoTarget(CSimulation game, CUnit unit, int orderId, AbilityTargetCheckReceiver receiver) { receiver.orderIdNotAccepted(); } + + @Override + public War3ID getOnTooltipOverride() { + return null; + } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderPassive.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderPassive.java index 5a4e31d3..3f4586b8 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderPassive.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/CAbilityAbilityBuilderPassive.java @@ -4,20 +4,35 @@ import java.util.Map; import com.etheller.warsmash.util.War3ID; +import com.etheller.warsmash.util.WarsmashConstants; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CItem; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitTypeRequirement; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityVisitor; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.generic.AbilityGenericSingleIconPassiveAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABAction; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.parser.AbilityBuilderConfiguration; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityActivationReceiver; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.CommandStringErrorKeys; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.MeleeUIAbilityActivationReceiver; -public class CAbilityAbilityBuilderPassive extends AbilityGenericSingleIconPassiveAbility { +public class CAbilityAbilityBuilderPassive extends AbilityGenericSingleIconPassiveAbility implements AbilityBuilderAbility { protected List levelData; protected AbilityBuilderConfiguration config; protected Map localStore; + protected CItem item = null; + + protected float cooldown = 0; + protected float area = 0; + + private War3ID onTooltipOverride = null; + public CAbilityAbilityBuilderPassive(int handleId, War3ID code, War3ID alias, List levelData, AbilityBuilderConfiguration config, Map localStore) { @@ -25,12 +40,96 @@ public CAbilityAbilityBuilderPassive(int handleId, War3ID code, War3ID alias, this.levelData = levelData; this.config = config; this.localStore = localStore; + localStore.put(ABLocalStoreKeys.ABILITY, this); + } + + protected void setSpellFields(CSimulation game, CUnit unit) { + CAbilityTypeAbilityBuilderLevelData levelDataLevel = this.levelData.get(this.getLevel() - 1); + this.cooldown = levelDataLevel.getCooldown(); + this.area = levelDataLevel.getArea(); + if (this.config.getOverrideFields() != null) { + if (this.config.getOverrideFields().getAreaOverride() != null) { + this.area = this.config.getOverrideFields().getAreaOverride().callback(game, unit, localStore, 0); + } + if (this.config.getOverrideFields().getCooldownOverride() != null) { + this.cooldown = this.config.getOverrideFields().getCooldownOverride().callback(game, unit, localStore, + 0); + } + if (this.config.getOverrideFields().getOnTooltipOverride() != null) { + this.onTooltipOverride = this.config.getOverrideFields().getOnTooltipOverride().callback(game, unit, + localStore, 0); + } + } + } + + @Override + public List getLevelData() { + return this.levelData; + } + + @Override + public AbilityBuilderConfiguration getConfig() { + return this.config; + } + + @Override + public Map getLocalStore() { + return this.localStore; + } + + @Override + public float getArea() { + return area; + } + + @Override + public void startCooldown(CSimulation game, CUnit unit) { + War3ID cdID = getCooldownId(); + if (cdID != War3ID.NONE) { + unit.beginCooldown(game, cdID, this.cooldown); + } + } + + @Override + public void resetCooldown(CSimulation game, CUnit unit) { + War3ID cdID = getCooldownId(); + if (cdID != War3ID.NONE) { + unit.beginCooldown(game, cdID, 0); + } + } + + private War3ID getCooldownId() { + if (this.item != null) { + if (item.getItemType().isIgnoreCooldown()) { + return War3ID.NONE; + } else { + if (item.getItemType().getCooldownGroup() != null) { + return item.getItemType().getCooldownGroup(); + } + } + } + return getCode(); + } + + @Override + public void setItemAbility(final CItem item, int slot) { + this.item = item; + this.localStore.put(ABLocalStoreKeys.ITEM, item); + this.localStore.put(ABLocalStoreKeys.ITEMSLOT, slot); } + @Override + public War3ID getOnTooltipOverride() { + return onTooltipOverride; + } + + + @Override public void setLevel(CSimulation game, CUnit unit, int level) { super.setLevel(game, unit, level); localStore.put(ABLocalStoreKeys.CURRENTLEVEL, level); + setSpellFields(game, unit); if (config.getOnLevelChange() != null) { for (ABAction action : config.getOnLevelChange()) { action.runAction(game, unit, localStore, 0); @@ -49,6 +148,18 @@ public void onAdd(CSimulation game, CUnit unit) { } } + @Override + public void onAddDisabled(CSimulation game, CUnit unit) { + localStore.put(ABLocalStoreKeys.GAME, game); + localStore.put(ABLocalStoreKeys.THISUNIT, unit); + setSpellFields(game, unit); + if (config.getOnAddDisabledAbility() != null) { + for (ABAction action : config.getOnAddDisabledAbility()) { + action.runAction(game, unit, localStore, 0); + } + } + } + @Override public void onRemove(CSimulation game, CUnit unit) { if (config.getOnRemoveAbility() != null) { @@ -58,6 +169,15 @@ public void onRemove(CSimulation game, CUnit unit) { } } + @Override + public void onRemoveDisabled(CSimulation game, CUnit unit) { + if (config.getOnRemoveDisabledAbility() != null) { + for (ABAction action : config.getOnRemoveDisabledAbility()) { + action.runAction(game, unit, localStore, 0); + } + } + } + @Override public void onTick(CSimulation game, CUnit unit) { } @@ -71,4 +191,52 @@ public void onDeath(CSimulation game, CUnit unit) { } } + @Override + public T visit(final CAbilityVisitor visitor) { + return visitor.accept(this); + } + + @Override + public void checkRequirementsMet(CSimulation game, CUnit unit, AbilityActivationReceiver receiver) { + List reqs = this.levelData.get(this.getLevel() - 1).getRequirements(); + CPlayer player = game.getPlayer(unit.getPlayerIndex()); + if (reqs != null) { + for (final CUnitTypeRequirement requirement : reqs) { + if (player.getTechtreeUnlocked(requirement.getRequirement()) < requirement.getRequiredLevel()) { + receiver.missingRequirement(requirement.getRequirement(), requirement.getRequiredLevel()); + } + } + } + } + + @Override + public boolean isRequirementsMet(CSimulation game, CUnit unit) { + List reqs = this.levelData.get(this.getLevel() - 1).getRequirements(); + CPlayer player = game.getPlayer(unit.getPlayerIndex()); + boolean requirementsMet = player.isTechtreeAllowedByMax(this.getAlias()); + if (reqs != null) { + for (final CUnitTypeRequirement requirement : reqs) { + if (player.getTechtreeUnlocked(requirement.getRequirement()) < requirement.getRequiredLevel()) { + requirementsMet = false; + } + } + } + return requirementsMet; + } + + @Override + protected void innerCheckCanUse(final CSimulation game, final CUnit unit, final int orderId, + final AbilityActivationReceiver receiver) { + final int cooldownRemaining = unit.getCooldownRemainingTicks(game, getCooldownId()); + + if (cooldownRemaining > 0) { + float cooldownLengthDisplay = unit.getCooldownLengthDisplayTicks(game, getCooldownId()) + * WarsmashConstants.SIMULATION_STEP_TIME; + receiver.cooldownNotYetReady(cooldownRemaining * WarsmashConstants.SIMULATION_STEP_TIME, + cooldownLengthDisplay); + } + + super.innerCheckCanUse(game, unit, orderId, receiver); + } + } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetABAbilityByRawcodeVisitor.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetABAbilityByRawcodeVisitor.java index 30b1efef..57383a7a 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetABAbilityByRawcodeVisitor.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetABAbilityByRawcodeVisitor.java @@ -25,7 +25,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.queue.CAbilityReviveHero; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.upgrade.CAbilityUpgrade; -public class GetABAbilityByRawcodeVisitor implements CAbilityVisitor { +public class GetABAbilityByRawcodeVisitor implements CAbilityVisitor { private static final GetABAbilityByRawcodeVisitor INSTANCE = new GetABAbilityByRawcodeVisitor(); public static GetABAbilityByRawcodeVisitor getInstance() { @@ -40,138 +40,141 @@ public GetABAbilityByRawcodeVisitor reset(final War3ID rawcode) { } @Override - public AbilityBuilderActiveAbility accept(final AbilityBuilderActiveAbility ability) { - return ability; + public AbilityBuilderAbility accept(final AbilityBuilderActiveAbility ability) { + if (this.rawcode.equals(ability.getAlias())) { + return (AbilityBuilderAbility) ability; + } + return null; } @Override - public AbilityBuilderActiveAbility accept(final GenericSingleIconActiveAbility ability) { + public AbilityBuilderAbility accept(final GenericSingleIconActiveAbility ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(GenericSingleIconPassiveAbility ability) { - if (ability instanceof AbilityBuilderActiveAbility && this.rawcode.equals(ability.getAlias())) { - return (AbilityBuilderActiveAbility) ability; + public AbilityBuilderAbility accept(GenericSingleIconPassiveAbility ability) { + if (ability instanceof AbilityBuilderAbility && this.rawcode.equals(ability.getAlias())) { + return (AbilityBuilderAbility) ability; } return null; } @Override - public AbilityBuilderActiveAbility accept(final GenericNoIconAbility ability) { - if (ability instanceof AbilityBuilderActiveAbility && this.rawcode.equals(ability.getAlias())) { - return (AbilityBuilderActiveAbility) ability; + public AbilityBuilderAbility accept(final GenericNoIconAbility ability) { + if (ability instanceof AbilityBuilderAbility && this.rawcode.equals(ability.getAlias())) { + return (AbilityBuilderAbility) ability; } return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityAttack ability) { + public AbilityBuilderAbility accept(final CAbilityAttack ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityMove ability) { + public AbilityBuilderAbility accept(final CAbilityMove ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityOrcBuild ability) { + public AbilityBuilderAbility accept(final CAbilityOrcBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityHumanBuild ability) { + public AbilityBuilderAbility accept(final CAbilityHumanBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityUndeadBuild ability) { + public AbilityBuilderAbility accept(final CAbilityUndeadBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityNightElfBuild ability) { + public AbilityBuilderAbility accept(final CAbilityNightElfBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityGenericDoNothing ability) { + public AbilityBuilderAbility accept(final CAbilityGenericDoNothing ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityColdArrows ability) { + public AbilityBuilderAbility accept(final CAbilityColdArrows ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityNagaBuild ability) { + public AbilityBuilderAbility accept(final CAbilityNagaBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityNeutralBuild ability) { + public AbilityBuilderAbility accept(final CAbilityNeutralBuild ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityBuildInProgress ability) { + public AbilityBuilderAbility accept(final CAbilityBuildInProgress ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityQueue ability) { + public AbilityBuilderAbility accept(final CAbilityQueue ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilitySellItems ability) { + public AbilityBuilderAbility accept(final CAbilitySellItems ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityUpgrade ability) { + public AbilityBuilderAbility accept(final CAbilityUpgrade ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityReviveHero ability) { + public AbilityBuilderAbility accept(final CAbilityReviveHero ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityRoot ability) { + public AbilityBuilderAbility accept(final CAbilityRoot ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityRally ability) { + public AbilityBuilderAbility accept(final CAbilityRally ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CBuff ability) { + public AbilityBuilderAbility accept(final CBuff ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityReturnResources ability) { + public AbilityBuilderAbility accept(final CAbilityReturnResources ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityHero ability) { + public AbilityBuilderAbility accept(final CAbilityHero ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityJass ability) { + public AbilityBuilderAbility accept(final CAbilityJass ability) { return null; } @Override - public AbilityBuilderActiveAbility accept(final CAbilityNeutralBuilding ability) { + public AbilityBuilderAbility accept(final CAbilityNeutralBuilding ability) { return null; } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetInstantTransformationBuffVisitor.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetInstantTransformationBuffVisitor.java new file mode 100644 index 00000000..42f35ae2 --- /dev/null +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/ability/GetInstantTransformationBuffVisitor.java @@ -0,0 +1,209 @@ +package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability; + +import java.util.Map; + +import com.etheller.warsmash.util.War3ID; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitType; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityAttack; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityGenericDoNothing; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityMove; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityVisitor; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityBuildInProgress; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityHumanBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityNagaBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityNeutralBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityNightElfBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityOrcBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityUndeadBuild; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.combat.CAbilityColdArrows; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.generic.*; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.harvest.CAbilityReturnResources; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.hero.CAbilityHero; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.item.shop.CAbilityNeutralBuilding; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.item.shop.CAbilitySellItems; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.jass.CAbilityJass; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.nightelf.root.CAbilityRoot; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.queue.CAbilityQueue; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.queue.CAbilityRally; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.queue.CAbilityReviveHero; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.upgrade.CAbilityUpgrade; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff.ABBuff; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff.ABTimedInstantTransformationBuff; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff.ABTimedTransformationBuff; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.handler.TransformationHandler.OnTransformationActions; + +public class GetInstantTransformationBuffVisitor implements CAbilityVisitor { + private static final GetInstantTransformationBuffVisitor INSTANCE = new GetInstantTransformationBuffVisitor(); + + public static GetInstantTransformationBuffVisitor getInstance() { + return INSTANCE; + } + + private CSimulation game; + private Map localStore; + private CUnitType newType; + private OnTransformationActions actions; + private War3ID buffId; + private boolean addAlternateTagAfter; + private float transformationTime; + private float duration; + private boolean permanent; + + public GetInstantTransformationBuffVisitor reset(CSimulation game, Map localStore, + CUnitType newType, OnTransformationActions actions, War3ID buffId, boolean addAlternateTagAfter, + float transformationTime, float duration, boolean permanent) { + this.game = game; + this.localStore = localStore; + this.newType = newType; + this.actions = actions; + this.buffId = buffId; + this.addAlternateTagAfter = addAlternateTagAfter; + this.transformationTime = transformationTime; + this.duration = duration; + this.permanent = permanent; + return this; + } + + @Override + public ABBuff accept(final AbilityBuilderActiveAbility ability) { + return new ABTimedTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, + buffId == null ? ability.getAlias() : buffId, duration, ability, newType, !addAlternateTagAfter, + permanent, transformationTime); + } + + @Override + public ABBuff accept(final GenericSingleIconActiveAbility ability) { + return null; + } + + @Override + public ABBuff accept(GenericSingleIconPassiveAbility ability) { + if (ability instanceof AbilityBuilderPassiveAbility) { + return new ABTimedInstantTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, + buffId == null ? ability.getAlias() : buffId, duration, (AbilityBuilderPassiveAbility)ability, newType, !addAlternateTagAfter, + permanent, transformationTime); + } + return null; + } + + @Override + public ABBuff accept(final GenericNoIconAbility ability) { + if (ability instanceof AbilityBuilderPassiveAbility) { + return new ABTimedInstantTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, + buffId == null ? ability.getAlias() : buffId, duration, (AbilityBuilderPassiveAbility)ability, newType, !addAlternateTagAfter, + permanent, transformationTime); + } + return null; + } + + @Override + public ABBuff accept(final CAbilityAttack ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityMove ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityOrcBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityHumanBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityUndeadBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityNightElfBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityGenericDoNothing ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityColdArrows ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityNagaBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityNeutralBuild ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityBuildInProgress ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityQueue ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilitySellItems ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityUpgrade ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityReviveHero ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityRoot ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityRally ability) { + return null; + } + + @Override + public ABBuff accept(final CBuff ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityReturnResources ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityHero ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityJass ability) { + return null; + } + + @Override + public ABBuff accept(final CAbilityNeutralBuilding ability) { + return null; + } +} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderBase.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderBase.java index 3a41b587..e7a8811b 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderBase.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderBase.java @@ -93,10 +93,6 @@ public ABBehavior reset(int orderId) { @Override public CBehavior update(final CSimulation game, boolean withinFacingWindow) { boolean wasChanneling = this.channeling; - if (!instant) { - this.unit.getUnitAnimationListener().playAnimation(false, this.ability.getCastingPrimaryTag(), - this.ability.getCastingSecondaryTags(), 1.0f, true); - } if (this.castStartTick == 0) { this.castStartTick = game.getGameTurnTick(); @@ -118,6 +114,10 @@ public CBehavior update(final CSimulation game, boolean withinFacingWindow) { localStore.remove(ABLocalStoreKeys.NEWBEHAVIOR); return newBehavior; } + if (!instant) { + this.unit.getUnitAnimationListener().playAnimation(false, this.ability.getCastingPrimaryTag(), + this.ability.getCastingSecondaryTags(), 1.0f, true); + } this.channeling = (boolean) localStore.get(ABLocalStoreKeys.CHANNELING); } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderNoTarget.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderNoTarget.java index 6e46b647..7bddf08b 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderNoTarget.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorAbilityBuilderNoTarget.java @@ -77,10 +77,6 @@ public ABBehavior reset(int orderId) { @Override public CBehavior update(final CSimulation game) { boolean wasChanneling = this.channeling; - if (!instant) { - this.unit.getUnitAnimationListener().playAnimation(false, this.ability.getCastingPrimaryTag(), - this.ability.getCastingSecondaryTags(), 1.0f, true); - } if (this.castStartTick == 0) { this.castStartTick = game.getGameTurnTick(); @@ -97,6 +93,10 @@ public CBehavior update(final CSimulation game) { localStore.remove(ABLocalStoreKeys.NEWBEHAVIOR); return newBehavior; } + if (!instant) { + this.unit.getUnitAnimationListener().playAnimation(false, this.ability.getCastingPrimaryTag(), + this.ability.getCastingSecondaryTags(), 1.0f, true); + } this.channeling = (boolean) localStore.get(ABLocalStoreKeys.CHANNELING); } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorFinishTransformation.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorFinishTransformation.java index b196337c..da642652 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorFinishTransformation.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/CBehaviorFinishTransformation.java @@ -97,11 +97,11 @@ public CBehavior update(CSimulation game) { if (instantTransformAtDurationEnd) { TransformationHandler.createInstantTransformBackBuff(game, localStore, unit, baseTypeForDuration, - new OnTransformationActions(actions.getOnUntransformActions()), ability, buffId, + actions.createUntransformActions(), ability, buffId, addAlternateTagAfter, transformationTime, duration, permanent); } else { TransformationHandler.createSlowTransformBackBuff(game, localStore, unit, baseTypeForDuration, - new OnTransformationActions(actions.getOnUntransformActions()), ability, buffId, + actions.createUntransformActions(), ability, buffId, addAlternateTagAfter, transformationTime, duration, permanent, takingOff, landing, immediateTakeoff, immediateLanding, altitudeAdjustmentDelay, landingDelay, altitudeAdjustmentDuration); diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ABActionCreateBuffFromId.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ABActionCreateBuffFromId.java deleted file mode 100644 index 5d252c8a..00000000 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ABActionCreateBuffFromId.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.behavior.action; - -import java.util.List; -import java.util.Map; - -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbility; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.CAbilityAbilityBuilderBuff; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.behavior.callback.idcallbacks.ABIDCallback; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABAction; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.types.impl.CAbilityTypeAbilityBuilderLevelData; - -public class ABActionCreateBuffFromId implements ABAction { - - private ABIDCallback abilityId; - - @SuppressWarnings("unchecked") - public void runAction(final CSimulation game, final CUnit caster, final Map localStore, final int castId) { - CAbility ability = game.getAbilityData().getBuffType(abilityId.callback(game, caster, localStore, castId)) - .createAbility(game.getHandleIdAllocator().createId()); - ((CAbilityAbilityBuilderBuff) ability).setParentLevelData( - (List) localStore.get(ABLocalStoreKeys.LEVELDATA)); - ((CAbilityAbilityBuilderBuff) ability).setParentCaster(caster); - ((CAbilityAbilityBuilderBuff) ability).setParentLocalStore(localStore); - - localStore.put(ABLocalStoreKeys.LASTCREATEDABILITY, ability); - } -} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ability/ABActionResetCooldown.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ability/ABActionResetCooldown.java index 0f8279d2..077872e5 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ability/ABActionResetCooldown.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/ability/ABActionResetCooldown.java @@ -5,7 +5,7 @@ import com.etheller.warsmash.util.War3ID; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderActiveAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.GetABAbilityByRawcodeVisitor; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.behavior.callback.idcallbacks.ABIDCallback; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.behavior.callback.unitcallbacks.ABUnitCallback; @@ -24,12 +24,12 @@ public void runAction(final CSimulation game, final CUnit caster, final Map localS CPlayer pl = game.getPlayer(u1.getPlayerIndex()); boolean charge = false; boolean addAlternateTagAfter = false; + boolean perm = false; + if (permanent != null) { + perm = permanent.callback(game, caster, localStore, castId); + } if (this.requiresPayment != null) { charge = this.requiresPayment.callback(game, caster, localStore, castId); } - AbilityBuilderActiveAbility abil = (AbilityBuilderActiveAbility) localStore.get(ABLocalStoreKeys.ABILITY); + AbilityBuilderAbility abil = (AbilityBuilderAbility) localStore.get(ABLocalStoreKeys.ABILITY); CUnitType baseType = null; if (baseUnitId == null) { @@ -72,7 +76,7 @@ public void runAction(CSimulation game, CUnit caster, Map localS if (u1.getTypeId().equals(altId)) { // Transforming back targetType = baseType; - if (targetType.equals(u1.getUnitType())) { + if (perm || targetType.equals(u1.getUnitType())) { // No need to do anything return; } @@ -110,8 +114,9 @@ public void runAction(CSimulation game, CUnit caster, Map localS } OnTransformationActions actions = new OnTransformationActions(goldCost, lumberCost, foodCost, onTransformActions, onUntransformActions); + OnTransformationActions unActions = new OnTransformationActions(-goldCost, -lumberCost, null, + null, onUntransformActions); - boolean perm = false; float dur = 0; float transTime = 0; War3ID theBuffId = null; @@ -138,7 +143,7 @@ public void runAction(CSimulation game, CUnit caster, Map localS addAlternateTagAfter, perm, true); if (dur > 0) { TransformationHandler.createInstantTransformBackBuff(game, localStore, u1, baseType, - new OnTransformationActions(onUntransformActions), abil, theBuffId, addAlternateTagAfter, + unActions, abil, theBuffId, addAlternateTagAfter, transTime, dur, perm); } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/unit/ABActionTransformedUnitAbilityAdd.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/unit/ABActionTransformedUnitAbilityAdd.java index 2dc0ccf2..456887de 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/unit/ABActionTransformedUnitAbilityAdd.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/action/unit/ABActionTransformedUnitAbilityAdd.java @@ -27,6 +27,7 @@ public class ABActionTransformedUnitAbilityAdd implements ABAction { private ABBooleanCallback instantTransformAtDurationEnd; // should the transform back be instant? private ABBooleanCallback permanent; // remove ability after transform + private ABBooleanCallback requiresPayment; private ABFloatCallback duration; // the time before the unit is forced to change back (doesn't charge for it) private ABFloatCallback transformTime; // the time the unit is locked for the transformation (for slow) or spends // animating (for instant) @@ -70,6 +71,7 @@ public void runAction(CSimulation game, CUnit caster, Map localS boolean instant = false; boolean perm = false; + boolean charge = false; float dur = 0; float transTime = 0; float landTime = 0; @@ -84,6 +86,9 @@ public void runAction(CSimulation game, CUnit caster, Map localS if (permanent != null) { perm = permanent.callback(game, caster, localStore, castId); } + if (this.requiresPayment != null) { + charge = this.requiresPayment.callback(game, caster, localStore, castId); + } if (duration != null) { dur = duration.callback(game, caster, localStore, castId); } @@ -118,17 +123,36 @@ public void runAction(CSimulation game, CUnit caster, Map localS action.runAction(game, u1, localStore, castId); } } - if (dur > 0) { + + if (dur > 0 && !perm) { + OnTransformationActions actions; + if (charge) { + int goldCost = 0; + int lumberCost = 0; + Integer foodCost = null; + if (game.getGameplayConstants().isRelativeUpgradeCosts()) { + + goldCost = baseType.getGoldCost() - u1.getUnitType().getGoldCost(); + lumberCost = baseType.getLumberCost() - u1.getUnitType().getLumberCost(); + } else { + goldCost = baseType.getGoldCost(); + lumberCost = baseType.getLumberCost(); + } + actions = new OnTransformationActions(goldCost, lumberCost, foodCost, null, onUntransformActions); + } else { + actions = new OnTransformationActions(onUntransformActions); + } + if (instant) { TransformationHandler.createInstantTransformBackBuff(game, localStore, u1, baseType, - new OnTransformationActions(onUntransformActions), abil, theBuffId, true, transTime, dur, perm); + actions, abil, theBuffId, true, transTime, dur, perm); } else { boolean takingOff = u1.getMovementType() != MovementType.FLY && baseType.getMovementType() == MovementType.FLY; boolean landing = u1.getMovementType() == MovementType.FLY && baseType.getMovementType() != MovementType.FLY; TransformationHandler.createSlowTransformBackBuff(game, localStore, u1, baseType, - new OnTransformationActions(onUntransformActions), abil, theBuffId, true, transTime, dur, perm, + actions, abil, theBuffId, true, transTime, dur, perm, takingOff, landing, imTakeOff, imLand, atlAdDelay, landTime, altAdTime); } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/callback/floatcallbacks/ABCallbackGetAbilityArea.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/callback/floatcallbacks/ABCallbackGetAbilityArea.java index 3d656586..d62c9457 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/callback/floatcallbacks/ABCallbackGetAbilityArea.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/behavior/callback/floatcallbacks/ABCallbackGetAbilityArea.java @@ -5,7 +5,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbility; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderActiveAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.behavior.callback.abilitycallbacks.ABAbilityCallback; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; @@ -16,12 +16,12 @@ public class ABCallbackGetAbilityArea extends ABFloatCallback { @Override public Float callback(CSimulation game, CUnit caster, Map localStore, final int castId) { if (ability == null) { - AbilityBuilderActiveAbility abil = (AbilityBuilderActiveAbility) localStore.get(ABLocalStoreKeys.ABILITY); + AbilityBuilderAbility abil = (AbilityBuilderAbility) localStore.get(ABLocalStoreKeys.ABILITY); return abil.getArea(); } else { CAbility abil = ability.callback(game, caster, localStore, castId); - if (abil instanceof AbilityBuilderActiveAbility) { - return ((AbilityBuilderActiveAbility)abil).getArea(); + if (abil instanceof AbilityBuilderAbility) { + return ((AbilityBuilderAbility)abil).getArea(); } else { return 0f; } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/buff/ABTimedInstantTransformationBuff.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/buff/ABTimedInstantTransformationBuff.java new file mode 100644 index 00000000..50736010 --- /dev/null +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/buff/ABTimedInstantTransformationBuff.java @@ -0,0 +1,57 @@ +package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff; + +import java.util.Map; + +import com.etheller.warsmash.util.War3ID; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitType; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderPassiveAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.handler.TransformationHandler; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.handler.TransformationHandler.OnTransformationActions; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.timer.DelayInstantTransformationTimer; + +public class ABTimedInstantTransformationBuff extends ABGenericTimedBuff { + + private Map localStore; + private OnTransformationActions actions; + private AbilityBuilderPassiveAbility abil; + private CUnitType targetType; + private boolean addAlternateTagAfter; + private boolean perm; + private float dur; + private float transTime; + + public ABTimedInstantTransformationBuff(int handleId, Map localStore, OnTransformationActions actions, War3ID alias, float duration, AbilityBuilderPassiveAbility ability, + CUnitType newType, boolean addAlternateTagAfter, boolean permanent, float transformationDuration) { + super(handleId, alias, duration, true); + this.setIconShowing(false); + this.localStore = localStore; + this.actions = actions; + this.abil = ability; + this.targetType = newType; + this.addAlternateTagAfter = addAlternateTagAfter; + this.perm = permanent; + this.dur = transformationDuration; + } + + @Override + protected void onBuffAdd(CSimulation game, CUnit unit) { + } + + @Override + protected void onBuffRemove(CSimulation game, CUnit unit) { + } + + @Override + protected void onBuffExpire(CSimulation game, CUnit unit) { + if (dur > 0) { + TransformationHandler.playMorphAnimation(unit, addAlternateTagAfter); + new DelayInstantTransformationTimer(game, localStore, unit, actions, addAlternateTagAfter, transTime, null, targetType, abil, + null, transTime, 0).start(game); + } else { + TransformationHandler.instantTransformation(game, localStore, unit, targetType, actions, abil, addAlternateTagAfter, perm, true); + } + } + +} diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/ABLocalStoreKeys.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/ABLocalStoreKeys.java index 7efb0d6a..63b22576 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/ABLocalStoreKeys.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/ABLocalStoreKeys.java @@ -95,7 +95,9 @@ public class ABLocalStoreKeys { public static final String ABILITYPAIREDUNIT = "_abilityPairedUnit#"; public static final String LASTPARTNERABILITY = "_lastPartnerAbility"; - + // Transforming + public static final String ACTIVE_ALTITUDE_ADJUSTMENT = "_activeAltAdj"; + public static final String WAITING_ANIMATION = "_morphTimer"; diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/AbilityBuilderGsonBuilder.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/AbilityBuilderGsonBuilder.java index d6e5d0df..1def11fb 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/AbilityBuilderGsonBuilder.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/core/AbilityBuilderGsonBuilder.java @@ -439,7 +439,6 @@ private static void registerActions(RuntimeTypeAdapterFactory factory) .registerSubtype(ABActionStoreValueLocally.class, "storeValueLocally") .registerSubtype(ABActionRemoveSpellEffect.class, "removeSpellEffect") .registerSubtype(ABActionCreateAbilityFromId.class, "createAbilityFromId") - .registerSubtype(ABActionCreateBuffFromId.class, "createBuffFromId") .registerSubtype(ABActionAddDefenseBonus.class, "addDefenseBonus") .registerSubtype(ABActionRemoveDefenseBonus.class, "removeDefenseBonus") .registerSubtype(ABActionAddRallyAbility.class, "addRallyAbility") diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/handler/TransformationHandler.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/handler/TransformationHandler.java index 9e1bcb55..a748fae6 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/handler/TransformationHandler.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/handler/TransformationHandler.java @@ -12,29 +12,33 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitType; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderActiveAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.GetInstantTransformationBuffVisitor; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff.ABBuff; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.buff.ABTimedTransformationBuff; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABAction; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.timer.AltitudeAdjustmentTimer; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.timer.DelayTimerTimer; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.timer.TransformationMorphAnimationTimer; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.timers.CTimer; public class TransformationHandler { - public static void setUnitID(CSimulation game, Map localStore, CUnit unit, CUnitType newType, boolean addAlternateTagAfter, OnTransformationActions actions, CAbility ability) { + public static void setUnitID(CSimulation game, Map localStore, CUnit unit, CUnitType newType, + boolean addAlternateTagAfter, OnTransformationActions actions, CAbility ability) { setUnitID(game, localStore, unit, newType, addAlternateTagAfter, actions, ability, false); } - public static void setUnitID(CSimulation game, Map localStore, CUnit unit, CUnitType newType, boolean addAlternateTagAfter, OnTransformationActions actions, CAbility ability, boolean updateArt) { + public static void setUnitID(CSimulation game, Map localStore, CUnit unit, CUnitType newType, + boolean addAlternateTagAfter, OnTransformationActions actions, CAbility ability, boolean updateArt) { CPlayer pl = game.getPlayer(unit.getPlayerIndex()); if (actions != null) { - if (actions.foodCost != null) { - pl.setUnitFoodUsed(unit, actions.foodCost); - } - pl.setGold(Math.max(pl.getGold()-actions.goldCost, 0)); - pl.setLumber(Math.max(pl.getLumber()-actions.lumberCost, 0)); - + pl.setGold(Math.max(pl.getGold() - actions.goldCost, 0)); + pl.setLumber(Math.max(pl.getLumber() - actions.lumberCost, 0)); + if (!addAlternateTagAfter) { if (actions.onUntransformActions != null) { for (ABAction action : actions.onUntransformActions) { @@ -43,15 +47,17 @@ public static void setUnitID(CSimulation game, Map localStore, C } } } - + unit.setTypeId(game, newType.getTypeId(), updateArt); + pl.setUnitFoodUsed(unit, newType.getFoodUsed()); + pl.setUnitFoodMade(unit, newType.getFoodMade()); if (addAlternateTagAfter) { unit.getUnitAnimationListener().addSecondaryTag(SecondaryTag.ALTERNATE); } else { unit.getUnitAnimationListener().removeSecondaryTag(SecondaryTag.ALTERNATE); } game.unitSoundEffectEvent(unit, ability.getAlias()); - + if (addAlternateTagAfter && actions != null) { if (actions.onTransformActions != null) { for (ABAction action : actions.onTransformActions) { @@ -64,11 +70,10 @@ public static void setUnitID(CSimulation game, Map localStore, C public static void playMorphAnimation(CUnit unit, boolean addAlternateTagAfter) { if (addAlternateTagAfter) { unit.getUnitAnimationListener().removeSecondaryTagForFutureAnimations(SecondaryTag.ALTERNATE); - unit.getUnitAnimationListener().playAnimation(false, PrimaryTag.MORPH, - SequenceUtils.EMPTY, 1.0f, true); + unit.getUnitAnimationListener().playAnimation(false, PrimaryTag.MORPH, SequenceUtils.EMPTY, 1.0f, true); } else { - unit.getUnitAnimationListener().playAnimation(false, PrimaryTag.MORPH, - EnumSet.of(SecondaryTag.ALTERNATE), 1.0f, true); + unit.getUnitAnimationListener().playAnimation(false, PrimaryTag.MORPH, EnumSet.of(SecondaryTag.ALTERNATE), + 1.0f, true); } unit.getUnitAnimationListener().queueAnimation(PrimaryTag.STAND, addAlternateTagAfter ? EnumSet.of(SecondaryTag.ALTERNATE) : SequenceUtils.EMPTY, true); @@ -89,48 +94,66 @@ public static void setTags(CUnit unit, boolean addAlternateTagAfter) { addAlternateTagAfter ? EnumSet.of(SecondaryTag.ALTERNATE) : SequenceUtils.EMPTY, 1.0f, true); } - public static void beginTakingOff(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, CAbility ability, - boolean addAlternateTagAfter, boolean immediateTakeoff, float altitudeAdjustmentDelay, - float altitudeAdjustmentDuration) { - (new DelayTimerTimer( + public static void beginTakingOff(CSimulation game, Map localStore, CUnit unit, CUnitType newType, + OnTransformationActions actions, CAbility ability, boolean addAlternateTagAfter, boolean immediateTakeoff, + float altitudeAdjustmentDelay, float altitudeAdjustmentDuration) { + CTimer timer = (CTimer) localStore.get(ABLocalStoreKeys.ACTIVE_ALTITUDE_ADJUSTMENT); + if (timer != null) { + game.unregisterTimer(timer); + } + timer = (new DelayTimerTimer( new AltitudeAdjustmentTimer(game, unit, newType.getDefaultFlyingHeight(), altitudeAdjustmentDuration), - altitudeAdjustmentDelay)).start(game); + localStore, altitudeAdjustmentDelay)); + timer.start(game); + localStore.put(ABLocalStoreKeys.ACTIVE_ALTITUDE_ADJUSTMENT, timer); TransformationHandler.setUnitID(game, localStore, unit, newType, addAlternateTagAfter, actions, ability); if (immediateTakeoff) { TransformationHandler.playMorphAnimation(unit, addAlternateTagAfter); } else { - new TransformationMorphAnimationTimer(game, unit, addAlternateTagAfter, altitudeAdjustmentDelay) - .start(game); + CTimer t2 = new TransformationMorphAnimationTimer(game, unit, addAlternateTagAfter, altitudeAdjustmentDelay); + t2.start(game); + localStore.put(ABLocalStoreKeys.WAITING_ANIMATION, t2); } } - public static void beginLanding(CSimulation game, CUnit unit, CUnitType newType, boolean addAlternateTagAfter, + public static void beginLanding(CSimulation game, Map localStore, CUnit unit, CUnitType newType, boolean addAlternateTagAfter, boolean immediateLanding, float landingDelay, float altitudeAdjustmentDuration) { unit.setFacing(225); if (immediateLanding) { TransformationHandler.playMorphAnimation(unit, addAlternateTagAfter); } else { - new TransformationMorphAnimationTimer(game, unit, addAlternateTagAfter, landingDelay).start(game); + CTimer timer = new TransformationMorphAnimationTimer(game, unit, addAlternateTagAfter, landingDelay); + timer.start(game); + localStore.put(ABLocalStoreKeys.WAITING_ANIMATION, timer); + } + CTimer timer = (CTimer) localStore.get(ABLocalStoreKeys.ACTIVE_ALTITUDE_ADJUSTMENT); + if (timer != null) { + game.unregisterTimer(timer); } - new AltitudeAdjustmentTimer(game, unit, newType.getDefaultFlyingHeight(), altitudeAdjustmentDuration) - .start(game); + timer = new AltitudeAdjustmentTimer(game, unit, newType.getDefaultFlyingHeight(), altitudeAdjustmentDuration); + timer.start(game); + localStore.put(ABLocalStoreKeys.ACTIVE_ALTITUDE_ADJUSTMENT, timer); } - public static void startSlowTransformation(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, CAbility ability, - boolean addAlternateTagAfter, boolean takingOff, boolean landing, boolean immediateTakeoff, - boolean immediateLanding, float altitudeAdjustmentDelay, float landingDelay, - float altitudeAdjustmentDuration) { + public static void startSlowTransformation(CSimulation game, Map localStore, CUnit unit, + CUnitType newType, OnTransformationActions actions, CAbility ability, boolean addAlternateTagAfter, + boolean takingOff, boolean landing, boolean immediateTakeoff, boolean immediateLanding, + float altitudeAdjustmentDelay, float landingDelay, float altitudeAdjustmentDuration) { + CTimer timer = (CTimer) localStore.get(ABLocalStoreKeys.WAITING_ANIMATION); + if (timer != null) { + game.unregisterTimer(timer); + } unit.getUnitAnimationListener().queueAnimation(PrimaryTag.STAND, addAlternateTagAfter ? SequenceUtils.EMPTY : EnumSet.of(SecondaryTag.ALTERNATE), true); if (takingOff || landing) { if (takingOff) { - TransformationHandler.beginTakingOff(game, localStore, unit, newType, actions, ability, addAlternateTagAfter, - immediateTakeoff, altitudeAdjustmentDelay, altitudeAdjustmentDuration); + TransformationHandler.beginTakingOff(game, localStore, unit, newType, actions, ability, + addAlternateTagAfter, immediateTakeoff, altitudeAdjustmentDelay, altitudeAdjustmentDuration); } if (landing) { - TransformationHandler.beginLanding(game, unit, newType, addAlternateTagAfter, immediateLanding, + TransformationHandler.beginLanding(game, localStore, unit, newType, addAlternateTagAfter, immediateLanding, landingDelay, altitudeAdjustmentDuration); } } else { @@ -138,8 +161,9 @@ public static void startSlowTransformation(CSimulation game, Map } } - public static void finishSlowTransformation(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, - AbilityBuilderActiveAbility ability, boolean addAlternateTagAfter, boolean permanent, boolean takingOff) { + public static void finishSlowTransformation(CSimulation game, Map localStore, CUnit unit, + CUnitType newType, OnTransformationActions actions, AbilityBuilderAbility ability, + boolean addAlternateTagAfter, boolean permanent, boolean takingOff) { if (!takingOff) { TransformationHandler.setUnitID(game, localStore, unit, newType, addAlternateTagAfter, actions, ability); } @@ -147,9 +171,10 @@ public static void finishSlowTransformation(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, - AbilityBuilderActiveAbility ability, boolean addAlternateTagAfter, boolean permanent, boolean playMorph) { + + public static void instantTransformation(CSimulation game, Map localStore, CUnit unit, + CUnitType newType, OnTransformationActions actions, AbilityBuilderAbility ability, + boolean addAlternateTagAfter, boolean permanent, boolean playMorph) { setUnitID(game, localStore, unit, newType, addAlternateTagAfter, actions, ability, false); if (playMorph) { TransformationHandler.playMorphAnimation(unit, addAlternateTagAfter); @@ -159,44 +184,45 @@ public static void instantTransformation(CSimulation game, Map l } } - public static void createSlowTransformBackBuff(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, - AbilityBuilderActiveAbility ability, War3ID buffId, boolean addAlternateTagAfter, float transformationTime, - float duration, boolean permanent, boolean takingOff, boolean landing, boolean immediateTakeoff, - boolean immediateLanding, float altitudeAdjustmentDelay, float landingDelay, - float altitudeAdjustmentDuration) { + public static void createSlowTransformBackBuff(CSimulation game, Map localStore, CUnit unit, + CUnitType newType, OnTransformationActions actions, AbilityBuilderActiveAbility ability, War3ID buffId, + boolean addAlternateTagAfter, float transformationTime, float duration, boolean permanent, + boolean takingOff, boolean landing, boolean immediateTakeoff, boolean immediateLanding, + float altitudeAdjustmentDelay, float landingDelay, float altitudeAdjustmentDuration) { if (addAlternateTagAfter && duration > 0) { unit.add(game, - new ABTimedTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, buffId == null ? ability.getAlias() : buffId, - duration, ability, newType, !addAlternateTagAfter, permanent, duration, transformationTime, - landingDelay, altitudeAdjustmentDelay, altitudeAdjustmentDuration, immediateLanding, - immediateTakeoff)); + new ABTimedTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, + buffId == null ? ability.getAlias() : buffId, duration, ability, newType, + !addAlternateTagAfter, permanent, duration, transformationTime, landingDelay, + altitudeAdjustmentDelay, altitudeAdjustmentDuration, immediateLanding, immediateTakeoff)); } } - public static void createInstantTransformBackBuff(CSimulation game, Map localStore, CUnit unit, CUnitType newType, OnTransformationActions actions, - AbilityBuilderActiveAbility ability, War3ID buffId, boolean addAlternateTagAfter, float transformationTime, - float duration, boolean permanent) { + public static void createInstantTransformBackBuff(CSimulation game, Map localStore, CUnit unit, + CUnitType newType, OnTransformationActions actions, AbilityBuilderAbility ability, War3ID buffId, + boolean addAlternateTagAfter, float transformationTime, float duration, boolean permanent) { if (addAlternateTagAfter && duration > 0) { - unit.add(game, - new ABTimedTransformationBuff(game.getHandleIdAllocator().createId(), localStore, actions, buffId == null ? ability.getAlias() : buffId, - duration, ability, newType, !addAlternateTagAfter, permanent, transformationTime)); + ABBuff thebuff = ability.visit(GetInstantTransformationBuffVisitor.getInstance().reset(game, localStore, + newType, actions, buffId, addAlternateTagAfter, transformationTime, duration, permanent)); + if (thebuff != null) { + unit.add(game, thebuff); + } } } - - - + public static class OnTransformationActions { private int goldCost; private int lumberCost; private Integer foodCost; private List onTransformActions; private List onUntransformActions; - + public OnTransformationActions(List onUntransformActions) { this.onUntransformActions = onUntransformActions; } - public OnTransformationActions(int goldCost, int lumberCost, Integer foodCost, List onTransformActions, List onUntransformActions) { + public OnTransformationActions(int goldCost, int lumberCost, Integer foodCost, + List onTransformActions, List onUntransformActions) { this.goldCost = goldCost; this.lumberCost = lumberCost; this.foodCost = foodCost; @@ -204,8 +230,8 @@ public OnTransformationActions(int goldCost, int lumberCost, Integer foodCost, L this.onUntransformActions = onUntransformActions; } - public List getOnUntransformActions() { - return onUntransformActions; + public OnTransformationActions createUntransformActions() { + return new OnTransformationActions(-goldCost, -lumberCost, foodCost != null ? -foodCost : null, null, onUntransformActions); } public void setOnUntransformActions(List onUntransformActions) { diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/parser/AbilityBuilderType.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/parser/AbilityBuilderType.java index f04e0bba..b7f7003b 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/parser/AbilityBuilderType.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/parser/AbilityBuilderType.java @@ -13,7 +13,6 @@ public enum AbilityBuilderType { NORMAL_NOTARGET, TOGGLE, SMART, - BUFF, PASSIVE, TEMPLATE, HIDDEN; diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayInstantTransformationTimer.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayInstantTransformationTimer.java index b97d9586..a8710872 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayInstantTransformationTimer.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayInstantTransformationTimer.java @@ -6,7 +6,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitType; -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderActiveAbility; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.ability.AbilityBuilderAbility; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.handler.TransformationHandler; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.handler.TransformationHandler.OnTransformationActions; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.timers.CTimer; @@ -18,7 +18,7 @@ public class DelayInstantTransformationTimer extends CTimer { private boolean addAlternateTagAfter; private CUnitType baseType; private CUnitType targetType; - private AbilityBuilderActiveAbility abil; + private AbilityBuilderAbility abil; private boolean perm; private War3ID theBuffId; private float transTime; @@ -26,7 +26,7 @@ public class DelayInstantTransformationTimer extends CTimer { public DelayInstantTransformationTimer(CSimulation game, Map localStore, CUnit unit, OnTransformationActions actions, boolean addAlternateTagAfter, float delay, CUnitType baseType, - CUnitType targetType, AbilityBuilderActiveAbility ability, War3ID buffId, float transformationTime, + CUnitType targetType, AbilityBuilderAbility ability, War3ID buffId, float transformationTime, float duration) { super(); this.localStore = localStore; @@ -48,7 +48,7 @@ public void onFire(CSimulation game) { addAlternateTagAfter, perm, false); if (dur > 0) { TransformationHandler.createInstantTransformBackBuff(game, localStore, unit, baseType, - new OnTransformationActions(actions.getOnUntransformActions()), abil, theBuffId, + actions.createUntransformActions(), abil, theBuffId, addAlternateTagAfter, transTime, dur, perm); } } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayTimerTimer.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayTimerTimer.java index 7a418d97..310823b5 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayTimerTimer.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/timer/DelayTimerTimer.java @@ -1,20 +1,26 @@ package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.timer; +import java.util.Map; + import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilitybuilder.core.ABLocalStoreKeys; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.timers.CTimer; public class DelayTimerTimer extends CTimer { private CTimer timer; + Map localStore; - public DelayTimerTimer(CTimer timer, float delay) { + public DelayTimerTimer(CTimer timer, Map localStore, float delay) { super(); this.timer = timer; + this.localStore = localStore; this.setRepeats(false); this.setTimeoutTime(delay); } public void onFire(CSimulation game) { + localStore.put(ABLocalStoreKeys.ACTIVE_ALTITUDE_ADJUSTMENT, timer); timer.start(game); } diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/types/impl/CAbilityTypeAbilityBuilder.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/types/impl/CAbilityTypeAbilityBuilder.java index 7517c9c1..268c1880 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/types/impl/CAbilityTypeAbilityBuilder.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/abilitybuilder/types/impl/CAbilityTypeAbilityBuilder.java @@ -38,8 +38,6 @@ public CAbility createAbility(int handleId) { CAbilitySpell ability; switch (parser.getType()) { - case BUFF: - return new CAbilityAbilityBuilderBuff(handleId, getCode(), getAlias(), getLevelData(), parser, localStore); case PASSIVE: return new CAbilityAbilityBuilderPassive(handleId, getCode(), getAlias(), getLevelData(), parser, localStore); case HIDDEN: diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java index 735f3930..61be91da 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/data/CAbilityData.java @@ -109,7 +109,6 @@ public class CAbilityData { private final ObjectData abilityData; private Map> aliasToAbilityType = new HashMap<>(); private final Map codeToAbilityTypeDefinition = new HashMap<>(); - private final Map codeToBuffTypeDefinition = new HashMap<>(); public CAbilityData(final ObjectData abilityData) { this.abilityData = abilityData; @@ -301,13 +300,7 @@ private void registerCodes() { try { behaviors = gson.fromJson(new FileReader(abilityBehaviorFile), AbilityBuilderFile.class); for (AbilityBuilderParser behavior : behaviors.getAbilityList()) { - if (behavior.getType().equals(AbilityBuilderType.BUFF)) { - for (AbilityBuilderDupe dupe : behavior.getIds()) { - AbilityBuilderConfiguration config = new AbilityBuilderConfiguration(behavior, dupe); - this.codeToBuffTypeDefinition.put(War3ID.fromString(config.getId()), - config.createDefinition()); - } - } else if (behavior.getType().equals(AbilityBuilderType.TEMPLATE)) { + if (behavior.getType().equals(AbilityBuilderType.TEMPLATE)) { for (AbilityBuilderDupe dupe : behavior.getIds()) { this.codeToAbilityTypeDefinition.put(War3ID.fromString(dupe.getId()), new CAbilityTypeDefinitionAbilityTemplateBuilder(behavior)); @@ -360,17 +353,6 @@ public CAbilityType getAbilityType(final War3ID alias) { return abilityType; } - public CAbilityType getBuffType(final War3ID code) { - CAbilityType abilityType = null; - final CAbilityTypeDefinition buffTypeDefinition = this.codeToBuffTypeDefinition.get(code); - if (buffTypeDefinition != null) { - abilityType = buffTypeDefinition.createAbilityType(code, null); - this.aliasToAbilityType.put(code, abilityType); - } - - return abilityType; - } - public int getHeroRequiredLevel(final CSimulation game, final War3ID alias, final int currentLevelOfAbility) { // TODO maybe use CAbilityType for this to avoid hashtable lookups and just do // fast symbol table resolution.