|
1 | 1 | package com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.item; |
2 | 2 |
|
3 | | -import com.etheller.warsmash.units.manager.MutableObjectData; |
4 | 3 | import com.etheller.warsmash.util.War3ID; |
| 4 | +import com.etheller.warsmash.util.WarsmashConstants; |
5 | 5 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation; |
6 | 6 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit; |
7 | 7 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CWidget; |
8 | 8 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.generic.AbstractGenericSingleIconNoSmartActiveAbility; |
9 | | -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.skills.CAbilityNoTargetSpellBase; |
| 9 | +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.skills.CAbilitySpellBase; |
10 | 10 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.targeting.AbilityPointTarget; |
11 | 11 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.targeting.AbilityTarget; |
12 | | -import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.types.definitions.impl.AbilityFields; |
13 | 12 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.CBehavior; |
14 | 13 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds; |
15 | 14 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.trigger.enumtypes.CEffectType; |
16 | 15 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityActivationReceiver; |
17 | 16 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.AbilityTargetCheckReceiver; |
18 | 17 | import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.CommandStringErrorKeys; |
19 | 18 |
|
20 | | -public class CAbilityItemManaRegain extends CAbilityNoTargetSpellBase { |
21 | | - private int manaToRegain; |
| 19 | +public class CAbilityItemManaRegain extends AbstractGenericSingleIconNoSmartActiveAbility { |
| 20 | + public static final War3ID CODE = War3ID.fromString("AIma"); |
| 21 | + private final int manaToRegain; |
| 22 | + private final float cooldown; |
22 | 23 |
|
23 | | - public CAbilityItemManaRegain(int handleId, War3ID alias) { |
| 24 | + public CAbilityItemManaRegain(final int handleId, final War3ID alias, final int manaToRegain, |
| 25 | + final float cooldown) { |
24 | 26 | super(handleId, alias); |
| 27 | + this.manaToRegain = manaToRegain; |
| 28 | + this.cooldown = cooldown; |
25 | 29 | } |
26 | 30 |
|
27 | 31 | @Override |
28 | | - public int getBaseOrderId() { |
29 | | - return OrderIds.itemmanapotion; |
| 32 | + protected void innerCheckCanTarget(final CSimulation game, final CUnit unit, final int orderId, |
| 33 | + final CWidget target, final AbilityTargetCheckReceiver<CWidget> receiver) { |
| 34 | + receiver.orderIdNotAccepted(); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + protected void innerCheckCanTarget(final CSimulation game, final CUnit unit, final int orderId, |
| 39 | + final AbilityPointTarget target, final AbilityTargetCheckReceiver<AbilityPointTarget> receiver) { |
| 40 | + receiver.orderIdNotAccepted(); |
30 | 41 | } |
31 | 42 |
|
32 | 43 | @Override |
33 | | - protected void innerCheckCanUseSpell(CSimulation game, CUnit unit, int orderId, AbilityActivationReceiver receiver) { |
34 | | - if (unit.getMana() >= unit.getMaximumMana()) { |
| 44 | + protected void innerCheckCanTargetNoTarget(final CSimulation game, final CUnit unit, final int orderId, |
| 45 | + final AbilityTargetCheckReceiver<Void> receiver) { |
| 46 | + if (orderId == getBaseOrderId()) { |
| 47 | + receiver.targetOk(null); |
| 48 | + } |
| 49 | + else { |
| 50 | + receiver.orderIdNotAccepted(); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void innerCheckCanUse(final CSimulation game, final CUnit unit, final int orderId, |
| 56 | + final AbilityActivationReceiver receiver) { |
| 57 | + final float cooldownRemaining = CAbilitySpellBase.getCooldownRemaining(game, unit, CODE); |
| 58 | + if (cooldownRemaining > 0) { |
| 59 | + final float cooldownLengthDisplay = unit.getCooldownLengthDisplayTicks(game, CODE) |
| 60 | + * WarsmashConstants.SIMULATION_STEP_TIME; |
| 61 | + receiver.cooldownNotYetReady(cooldownRemaining, cooldownLengthDisplay); |
| 62 | + } |
| 63 | + else if (unit.getMana() >= unit.getMaximumMana()) { |
35 | 64 | receiver.activationCheckFailed(CommandStringErrorKeys.ALREADY_AT_FULL_MANA); |
36 | 65 | } |
37 | 66 | else { |
38 | | - super.innerCheckCanUseSpell(game, unit, orderId, receiver); |
| 67 | + receiver.useOk(); |
39 | 68 | } |
40 | 69 | } |
41 | 70 |
|
42 | 71 | @Override |
43 | | - public void populateData(MutableObjectData.MutableGameObject worldEditorAbility, int level) { |
44 | | - this.manaToRegain = worldEditorAbility.getFieldAsInteger(AbilityFields.ItemManaRegainLesser.MANA_POINTS_GAINED, level); |
| 72 | + public int getBaseOrderId() { |
| 73 | + return OrderIds.replenishmana; |
45 | 74 | } |
46 | 75 |
|
47 | 76 | @Override |
48 | | - public boolean doEffect(CSimulation simulation, CUnit caster, AbilityTarget target) { |
49 | | - caster.restoreMana(simulation, this.manaToRegain); |
50 | | - simulation.createSpellEffectOnUnit(caster, getAlias(), CEffectType.CASTER); |
| 77 | + public boolean isToggleOn() { |
51 | 78 | return false; |
52 | 79 | } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void onAdd(final CSimulation game, final CUnit unit) { |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void onRemove(final CSimulation game, final CUnit unit) { |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void onTick(final CSimulation game, final CUnit unit) { |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void onCancelFromQueue(final CSimulation game, final CUnit unit, final int orderId) { |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId, |
| 103 | + final AbilityTarget target) { |
| 104 | + if ((target == null) && (orderId == getBaseOrderId())) { |
| 105 | + caster.restoreMana(game, this.manaToRegain); |
| 106 | + game.createSpellEffectOnUnit(caster, getAlias(), CEffectType.CASTER); |
| 107 | + caster.beginCooldown(game, CODE, cooldown); |
| 108 | + return false; |
| 109 | + } |
| 110 | + return super.checkBeforeQueue(game, caster, orderId, target); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, final CWidget target) { |
| 115 | + return null; |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public CBehavior begin(final CSimulation game, final CUnit caster, final int orderId, |
| 120 | + final AbilityPointTarget point) { |
| 121 | + return null; |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public CBehavior beginNoTarget(final CSimulation game, final CUnit caster, final int orderId) { |
| 126 | + return null; |
| 127 | + } |
53 | 128 | } |
0 commit comments