mirror of
https://github.com/Retera/WarsmashModEngine.git
synced 2022-07-31 17:38:59 +02:00
Update couple instant to support gold and lumber cost for some fun testing
This commit is contained in:
parent
b3256b125d
commit
71b9ac486e
@ -1,36 +0,0 @@
|
||||
package com.etheller.warsmash;
|
||||
|
||||
import com.etheller.warsmash.util.War3ID;
|
||||
|
||||
public class TestMain {
|
||||
public static void main(final String[] args) {
|
||||
if (true) {
|
||||
System.out.println(War3ID.fromString("hwat").getValue());
|
||||
System.out.println(Integer.toHexString(War3ID.fromString("hwat").getValue()));
|
||||
System.out.println(new War3ID(0x68776174));
|
||||
return;
|
||||
}
|
||||
// System.out.println(Integer.parseInt("4294967295"));
|
||||
for (int i = 1; i <= 30; i++) {
|
||||
// System.out.println(a(i));
|
||||
}
|
||||
|
||||
int checkX = 0;
|
||||
int checkY = 0;
|
||||
for (int i = 0; i < 300; i++) {
|
||||
System.out.println(checkX + "," + checkY);
|
||||
final double angle = ((((int) Math.floor(Math.sqrt((4 * i) + 1))) % 4) * Math.PI) / 2;
|
||||
checkX += (int) Math.sin(angle);
|
||||
checkY += (int) Math.cos(angle);
|
||||
}
|
||||
}
|
||||
|
||||
public static int a(final int n) {
|
||||
if (n == 1) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return a(n - 1) - (int) Math.sin(((Math.floor(Math.sqrt((4 * (n - 2)) + 1)) % 4) * Math.PI) / 2);
|
||||
}
|
||||
}
|
||||
}
|
@ -117,7 +117,8 @@ public class CommandCardPopulatingAbilityVisitor implements CAbilityVisitor<Void
|
||||
if ((this.menuBaseOrderId == 0) && ability.isIconShowing()) {
|
||||
final AbilityUI ui = this.abilityDataUI.getUI(ability.getAlias());
|
||||
addCommandButton(ability, ability.isToggleOn() ? ui.getOffIconUI() : ui.getOnIconUI(),
|
||||
ability.getHandleId(), ability.getBaseOrderId(), 0, false, false);
|
||||
ability.getHandleId(), ability.getBaseOrderId(), 0, false, false, ability.getUIGoldCost(),
|
||||
ability.getUILumberCost(), 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ public abstract class AbstractGenericSingleIconActiveAbility extends AbstractCAb
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId, AbilityTarget target) {
|
||||
public boolean checkBeforeQueue(final CSimulation game, final CUnit caster, final int orderId,
|
||||
final AbilityTarget target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,4 +90,14 @@ public abstract class AbstractGenericSingleIconActiveAbility extends AbstractCAb
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUIGoldCost() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUILumberCost() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,4 +9,8 @@ public interface GenericSingleIconActiveAbility extends CAbility {
|
||||
int getBaseOrderId();
|
||||
|
||||
boolean isToggleOn();
|
||||
|
||||
int getUIGoldCost();
|
||||
|
||||
int getUILumberCost();
|
||||
}
|
||||
|
@ -16,8 +16,10 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.test.CBeh
|
||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.combat.CTargetType;
|
||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.COrderTargetWidget;
|
||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds;
|
||||
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;
|
||||
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.ResourceType;
|
||||
|
||||
public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiveAbility {
|
||||
|
||||
@ -28,10 +30,12 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv
|
||||
private final float area;
|
||||
private final EnumSet<CTargetType> targetsAllowed;
|
||||
private CBehaviorCoupleInstant behaviorCoupleInstant;
|
||||
private final int goldCost;
|
||||
private final int lumberCost;
|
||||
|
||||
public CAbilityCoupleInstant(final int handleId, final War3ID alias, final War3ID resultingUnitType,
|
||||
final War3ID partnerUnitType, final boolean moveToPartner, final float castRange, final float area,
|
||||
final EnumSet<CTargetType> targetsAllowed) {
|
||||
final EnumSet<CTargetType> targetsAllowed, final int goldCost, final int lumberCost) {
|
||||
super(handleId, alias);
|
||||
this.resultingUnitType = resultingUnitType;
|
||||
this.partnerUnitType = partnerUnitType;
|
||||
@ -39,6 +43,8 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv
|
||||
this.castRange = castRange;
|
||||
this.area = area;
|
||||
this.targetsAllowed = targetsAllowed;
|
||||
this.goldCost = goldCost;
|
||||
this.lumberCost = lumberCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,8 +129,19 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv
|
||||
@Override
|
||||
protected void innerCheckCanUse(final CSimulation game, final CUnit unit, final int orderId,
|
||||
final AbilityActivationReceiver receiver) {
|
||||
final CPlayer player = game.getPlayer(unit.getPlayerIndex());
|
||||
if (player.getGold() >= this.goldCost) {
|
||||
if (player.getLumber() >= this.lumberCost) {
|
||||
receiver.useOk();
|
||||
}
|
||||
else {
|
||||
receiver.notEnoughResources(ResourceType.LUMBER);
|
||||
}
|
||||
}
|
||||
else {
|
||||
receiver.notEnoughResources(ResourceType.GOLD);
|
||||
}
|
||||
}
|
||||
|
||||
public float getCastRange() {
|
||||
return this.castRange;
|
||||
@ -142,6 +159,14 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv
|
||||
return this.resultingUnitType;
|
||||
}
|
||||
|
||||
public int getGoldCost() {
|
||||
return this.goldCost;
|
||||
}
|
||||
|
||||
public int getLumberCost() {
|
||||
return this.lumberCost;
|
||||
}
|
||||
|
||||
private final class PossiblePairFinderEnum implements CUnitEnumFunction {
|
||||
private final CUnit unit;
|
||||
private CUnit pairMatchFound = null;
|
||||
@ -176,4 +201,13 @@ public class CAbilityCoupleInstant extends AbstractGenericSingleIconNoSmartActiv
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUIGoldCost() {
|
||||
return this.goldCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUILumberCost() {
|
||||
return this.lumberCost;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class CAbilityTypeDefinitionCoupleInstant
|
||||
|
||||
final EnumSet<CTargetType> targetsAllowedAtLevel = CTargetType.parseTargetTypeSet(targetsAllowedAtLevelString);
|
||||
return new CAbilityTypeCoupleInstantLevelData(targetsAllowedAtLevel, resultingUnitTypeId, partnerUnitTypeId,
|
||||
moveToPartner, castRange, area);
|
||||
moveToPartner, castRange, area, goldCost, lumberCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,7 @@ public class CAbilityTypeCoupleInstant extends CAbilityType<CAbilityTypeCoupleIn
|
||||
final CAbilityTypeCoupleInstantLevelData levelData = getLevelData(0);
|
||||
return new CAbilityCoupleInstant(handleId, getAlias(), levelData.getResultingUnitTypeId(),
|
||||
levelData.getPartnerUnitTypeId(), levelData.isMoveToPartner(), levelData.getCastRange(),
|
||||
levelData.getArea(), levelData.getTargetsAllowed());
|
||||
levelData.getArea(), levelData.getTargetsAllowed(), levelData.getGoldCost(), levelData.getLumberCost());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,16 +12,20 @@ public class CAbilityTypeCoupleInstantLevelData extends CAbilityTypeLevelData {
|
||||
private final boolean moveToPartner;
|
||||
private final float castRange;
|
||||
private final float area;
|
||||
private final int goldCost;
|
||||
private final int lumberCost;
|
||||
|
||||
public CAbilityTypeCoupleInstantLevelData(final EnumSet<CTargetType> targetsAllowed,
|
||||
final War3ID resultingUnitTypeId, final War3ID partnerUnitTypeId, final boolean moveToPartner,
|
||||
final float castRange, final float area) {
|
||||
final float castRange, final float area, final int goldCost, final int lumberCost) {
|
||||
super(targetsAllowed);
|
||||
this.resultingUnitTypeId = resultingUnitTypeId;
|
||||
this.partnerUnitTypeId = partnerUnitTypeId;
|
||||
this.moveToPartner = moveToPartner;
|
||||
this.castRange = castRange;
|
||||
this.area = area;
|
||||
this.goldCost = goldCost;
|
||||
this.lumberCost = lumberCost;
|
||||
}
|
||||
|
||||
public War3ID getResultingUnitTypeId() {
|
||||
@ -44,4 +48,12 @@ public class CAbilityTypeCoupleInstantLevelData extends CAbilityTypeLevelData {
|
||||
return this.area;
|
||||
}
|
||||
|
||||
public int getGoldCost() {
|
||||
return this.goldCost;
|
||||
}
|
||||
|
||||
public int getLumberCost() {
|
||||
return this.lumberCost;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,10 @@ public class CBehaviorCoupleInstant extends CAbstractRangedBehavior {
|
||||
if (targetBehavior instanceof CBehaviorCoupleInstant) {
|
||||
if (((CBehaviorCoupleInstant) targetBehavior).isWithinRange(simulation)) {
|
||||
// we are both within range
|
||||
final int goldCost = this.abilityCoupleInstant.getGoldCost();
|
||||
final int lumberCost = this.abilityCoupleInstant.getLumberCost();
|
||||
if (((goldCost == 0) && (lumberCost == 0))
|
||||
|| simulation.getPlayer(this.unit.getPlayerIndex()).charge(goldCost, lumberCost)) {
|
||||
final CUnit newUnit = simulation.createUnit(this.abilityCoupleInstant.getResultingUnitType(),
|
||||
this.unit.getPlayerIndex(), this.unit.getX(), this.unit.getY(), this.unit.getFacing());
|
||||
simulation.unitPreferredSelectionReplacement(this.unit, newUnit);
|
||||
@ -61,6 +65,7 @@ public class CBehaviorCoupleInstant extends CAbstractRangedBehavior {
|
||||
simulation.removeUnit(this.unit);
|
||||
simulation.removeUnit((CUnit) this.target);
|
||||
simulation.unitSoundEffectEvent(newUnit, this.abilityCoupleInstant.getAlias());
|
||||
}
|
||||
return this.unit.pollNextOrderBehavior(simulation);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class CAbilityData {
|
||||
if (mutableGameObject == null) {
|
||||
return null;
|
||||
}
|
||||
final War3ID code = mutableGameObject.getCode();
|
||||
final War3ID code = War3ID.fromString(mutableGameObject.readSLKTag("code"));
|
||||
final CAbilityTypeDefinition abilityTypeDefinition = this.codeToAbilityTypeDefinition.get(code);
|
||||
if (abilityTypeDefinition != null) {
|
||||
abilityType = abilityTypeDefinition.createAbilityType(alias, mutableGameObject);
|
||||
|
@ -121,6 +121,17 @@ public class CPlayer extends CBasePlayer {
|
||||
this.stateNotifier.goldChanged();
|
||||
}
|
||||
|
||||
public boolean charge(final int gold, final int lumber) {
|
||||
if ((this.lumber >= lumber) && (this.gold >= gold)) {
|
||||
this.lumber -= lumber;
|
||||
this.gold -= gold;
|
||||
this.stateNotifier.lumberChanged();
|
||||
this.stateNotifier.goldChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void refundFor(final CUnitType unitType) {
|
||||
this.lumber += unitType.getLumberCost();
|
||||
this.gold += unitType.getGoldCost();
|
||||
|
Loading…
Reference in New Issue
Block a user