Archived
1
0

- (Mostly) finished Upgrade class

- Finished upgrade process in DroneListItem

Still need to check that a max level on the requested upgrade has not been reached.

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-08-29 21:13:31 -07:00
parent 2de93e31e6
commit 3bd4981079
4 changed files with 129 additions and 15 deletions

View File

@ -146,6 +146,15 @@ public class DroneListItem {
return reliability;
}
/**
* Retrieve the attack factor of this drone
*
* @return <code>int</code>
*/
public int getAttack() {
return attack;
}
/**
* Retrieve the defenses factor of this drone
*
@ -216,7 +225,7 @@ public class DroneListItem {
*
* @return <code>boolean</code>
*/
public boolean getWanted() {
public boolean isWanted() {
return wanted;
}
@ -489,15 +498,61 @@ public class DroneListItem {
/**
* Finds the upgrade that the drone would like to purchase.
* Determines if upgrade is possible and performs action accordingly
*/
private void doUpgrade() {
Upgrade newUpgrade = current.upgrade();
int price = newUpgrade.getPrice();
//TODO - Hand price of upgrade being null
Integer price = newUpgrade.getPrice();
if (price == null) {
// Invalid upgrade selection, turn lost.
return;
}
if (team.getBalance() >= price) {
// TODO - Implement purchasing upgrades
switch (newUpgrade.getUpgradeType()) {
case visibleDistance: {
visibleDistance++;
break;
}
case lumaLocatorDistance: {
lumaLocatorDistance++;
break;
}
case objectLocatorDistance: {
objectLocatorDistance++;
break;
}
case reliability: {
reliability++;
break;
}
case attack: {
attack++;
break;
}
case defenses: {
defenses++;
break;
}
case speed: {
speed++;
break;
}
case cargoSpace: {
cargoSpace++;
break;
}
case theft: {
theft++;
break;
}
default: {
// Must specify an Upgrade Type
}
}
team.deductFromBalance(price);
return;
} else {
// Not enough money, do nothing.
return;

View File

@ -6,50 +6,109 @@ public class Upgrade {
visibleDistance, lumaLocatorDistance, objectLocatorDistance, reliability, attack, defenses, speed, cargoSpace, theft
}
/**
* The upgrade that is to be performed.
*/
private UpgradeType typeToUpgrade;
/**
* Drone to be upgraded. Used to find the current levels of this drone.
*/
private DroneListItem oldBrokenDrone;
public Upgrade(UpgradeType type) {
typeToUpgrade = type;
}
/**
* Provides the prices for a given update type
* Algorithm: (((Current Level - Original Level) + 5) * Multiplier)^2
* Provides the prices for a given update type Algorithm: (((Current Level -
* Original Level) + 5) * Multiplier)^2
*
* @return <code>int</code>
*/
public int getPrice() {
double multiplier;
double currentLevel;
double originalLevel;
switch (typeToUpgrade) {
case visibleDistance: {
multiplier = 2;
currentLevel = oldBrokenDrone.getVisibleDistance();
originalLevel = Nomads.BASE_VISIBLEDISTANCE;
break;
}
case lumaLocatorDistance: {
multiplier = 2.5;
currentLevel = oldBrokenDrone.getLumaLocatorDistance();
originalLevel = Nomads.BASE_LUMALOCATORDISTANCE;
break;
}
case objectLocatorDistance: {
multiplier = 2.5;
currentLevel = oldBrokenDrone.getObjectLocatorDistance();
originalLevel = Nomads.BASE_OBJECTLOCATORDISTANCE;
break;
}
case reliability: {
multiplier = 2.4;
currentLevel = oldBrokenDrone.getReliability();
originalLevel = Nomads.BASE_RELIABILITY;
break;
}
case attack: {
multiplier = 2.7;
currentLevel = oldBrokenDrone.getAttack();
originalLevel = Nomads.BASE_ATTACK;
break;
}
case defenses: {
multiplier = 2.8;
currentLevel = oldBrokenDrone.getDefenses();
originalLevel = Nomads.BASE_DEFENSES;
break;
}
case speed: {
multiplier = 3.5;
currentLevel = oldBrokenDrone.getSpeed();
originalLevel = Nomads.BASE_SPEED;
break;
}
case cargoSpace: {
multiplier = 3.5;
currentLevel = oldBrokenDrone.getCargoSpace();
originalLevel = Nomads.BASE_CARGOSPACE;
break;
}
case theft: {
multiplier = 4;
currentLevel = oldBrokenDrone.getTheft();
originalLevel = Nomads.BASE_THEFT;
break;
}
default: {
// Must specify an Upgrade Type
return (Integer) null;
}
}
double price = Math.pow(
(currentLevel - originalLevel + 5) * multiplier, 2.0);
return (int) Math.ceil(price);
}
/**
* Determines if the statistic wanting to be upgraded is already at the
* maximum level.
*
* @return <code>boolean</code>
*/
public boolean isMaxLevel() {
// TODO - Implement max levels
return false;
}
public UpgradeType getUpgradeType() {
return typeToUpgrade;
}
}