-Started implementing Inventory object
-Revised how Objectives are generated Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
parent
8d6840ac87
commit
b89f594fdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -52,12 +52,15 @@ public class DroneListItem {
|
||||
private int waiting; // Is the drone building another drone or house?
|
||||
private boolean wanted; // Is the drone wanted by the police?
|
||||
private ArrayList<GameObject> inventory;
|
||||
private ArrayList<Objective> currentObjectives;
|
||||
|
||||
// TODO - Implement max number of objectives
|
||||
|
||||
/*
|
||||
* Default constructor, includes all references
|
||||
*/
|
||||
public DroneListItem(DroneListItem theNext, DroneListItem thePrevious,
|
||||
Drone theCurrent, DroneTeam theTeam) {
|
||||
public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, Drone theCurrent,
|
||||
DroneTeam theTeam) {
|
||||
next = theNext;
|
||||
previous = thePrevious;
|
||||
current = theCurrent;
|
||||
@ -404,8 +407,7 @@ public class DroneListItem {
|
||||
return;
|
||||
}
|
||||
|
||||
DroneListItem victimList = Nomads
|
||||
.UIDToListItem(victimNeighbor.getUID());
|
||||
DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID());
|
||||
|
||||
int victimDefence = victimList.getDefenses();
|
||||
|
||||
@ -444,8 +446,7 @@ public class DroneListItem {
|
||||
return;
|
||||
}
|
||||
|
||||
DroneListItem victimList = Nomads
|
||||
.UIDToListItem(victimNeighbor.getUID());
|
||||
DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID());
|
||||
|
||||
int victimDefence = victimList.getDefenses();
|
||||
|
||||
@ -481,13 +482,10 @@ public class DroneListItem {
|
||||
// Not sure what happened here
|
||||
}
|
||||
|
||||
int itemsToTake = (int) Math.ceil(itemsInVictimInventory
|
||||
* percentToTake);
|
||||
while (itemsToTake < 0 && !getInventoryIsFull()
|
||||
&& victimList.inventory.size() > 0) {
|
||||
int itemsToTake = (int) Math.ceil(itemsInVictimInventory * percentToTake);
|
||||
while (itemsToTake < 0 && !getInventoryIsFull() && victimList.inventory.size() > 0) {
|
||||
// Min + (int)(Math.random() * ((Max - Min) + 1))
|
||||
int randIndex = 0 + (int) (Math.random() * (((victimList.inventory
|
||||
.size() - 1) - 0) + 1));
|
||||
int randIndex = 0 + (int) (Math.random() * (((victimList.inventory.size() - 1) - 0) + 1));
|
||||
inventory.add(victimList.inventory.get(randIndex));
|
||||
victimList.inventory.remove(randIndex);
|
||||
}
|
||||
@ -526,16 +524,14 @@ public class DroneListItem {
|
||||
}
|
||||
}
|
||||
|
||||
if (getX() + amountE > Nomads.awesomeWorld.getWorldSize() - 1
|
||||
|| getX() + amountE < 0
|
||||
if (getX() + amountE > Nomads.awesomeWorld.getWorldSize() - 1 || getX() + amountE < 0
|
||||
|| getY() + amountN > Nomads.awesomeWorld.getWorldSize() - 1
|
||||
|| getY() + amountN < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if there is a MoneyPile or Objective there
|
||||
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX()
|
||||
+ amountE, getY() + amountN);
|
||||
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
|
||||
|
||||
if (objectHere != null) {
|
||||
if (inventory.size() < cargoSpace) {
|
||||
@ -576,8 +572,7 @@ public class DroneListItem {
|
||||
private void killOtherDrone(DroneListItem victim) {
|
||||
while (inventory.size() < cargoSpace && !victim.inventory.isEmpty()) {
|
||||
// Take items from their inventory
|
||||
int randIndex = 0 + (int) (Math.random() * (((victim.inventory
|
||||
.size() - 1) - 0) + 1));
|
||||
int randIndex = 0 + (int) (Math.random() * (((victim.inventory.size() - 1) - 0) + 1));
|
||||
inventory.add(victim.inventory.get(randIndex));
|
||||
victim.inventory.remove(randIndex);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class NeighborBuilding implements GameObject {
|
||||
private int x;
|
||||
private int y;
|
||||
private Building building;
|
||||
private DroneListItem drone;
|
||||
protected DroneListItem drone;
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
|
@ -9,8 +9,7 @@ public class TownHall extends NeighborBuilding {
|
||||
|
||||
// TODO - Rewrite class to make more accessible to Drones
|
||||
|
||||
public TownHall(int x, int y, String name, Building building,
|
||||
DroneListItem drone) {
|
||||
public TownHall(int x, int y, String name, Building building, DroneListItem drone) {
|
||||
super(x, y, name, building, drone);
|
||||
}
|
||||
|
||||
@ -21,17 +20,19 @@ public class TownHall extends NeighborBuilding {
|
||||
* @param inventory
|
||||
* @param team
|
||||
*/
|
||||
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) {
|
||||
public void cashInventory() {
|
||||
if (verifyObjectValidity()) {
|
||||
Inventory inventory = drone.getInventory();
|
||||
DroneTeam team = drone.getTeam();
|
||||
|
||||
while (!inventory.isEmpty()) {
|
||||
GameObject currentObject = inventory.get(0);
|
||||
GameObject currentObject = inventory.getItem(0);
|
||||
if (currentObject instanceof MoneyPile) {
|
||||
int value = ((MoneyPile) currentObject).getValue();
|
||||
team.increaseBalance(value);
|
||||
Nomads.awesomeWorld.generateMoneyPile();
|
||||
} else if (currentObject instanceof Objective) {
|
||||
team.increaseBalance(((Objective) currentObject)
|
||||
.getBounty());
|
||||
team.increaseBalance(((Objective) currentObject).getBounty());
|
||||
}
|
||||
inventory.remove(currentObject);
|
||||
}
|
||||
@ -43,14 +44,12 @@ public class TownHall extends NeighborBuilding {
|
||||
/**
|
||||
* Will generate a new objective for the drone that requests it.
|
||||
*
|
||||
* @param UID
|
||||
* Depreciated and going away soon.
|
||||
* @return <code>Point</code> Will return null if the NeighborBuilding was
|
||||
* created in a previous turn.
|
||||
*/
|
||||
public Point requestNewObjective(String UID) {
|
||||
public Point requestNewObjective() {
|
||||
if (verifyObjectValidity()) {
|
||||
return Nomads.awesomeWorld.generateObjective(UID);
|
||||
return Nomads.awesomeWorld.generateObjective(drone);
|
||||
} else {
|
||||
// Object not valid, do nothing
|
||||
return null;
|
||||
|
@ -5,11 +5,12 @@ import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Main class where information about the world is stored
|
||||
*
|
||||
@ -233,9 +234,11 @@ public class World {
|
||||
GameObject objectHere = theWorld[x + i][y + j];
|
||||
if (objectHere != null) {
|
||||
String name = objectHere.getName();
|
||||
if (name.equalsIgnoreCase("TownHall") || name.equalsIgnoreCase("PoliceStation")) {
|
||||
if (name.equalsIgnoreCase("TownHall")
|
||||
|| name.equalsIgnoreCase("PoliceStation")) {
|
||||
return true;
|
||||
} else if ((name.equalsIgnoreCase("RepairShop") || name.equalsIgnoreCase("UpgradeShop")) && i <= 2 && j <= 2) {
|
||||
} else if ((name.equalsIgnoreCase("RepairShop") || name
|
||||
.equalsIgnoreCase("UpgradeShop")) && i <= 2 && j <= 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -297,7 +300,7 @@ public class World {
|
||||
* - The UID of the Drone that is allowed to pick it up.
|
||||
* @return - <code>Point</code> - Within 20x20 of the Objective.
|
||||
*/
|
||||
public Point generateObjective(String UID) {
|
||||
public Point generateObjective(DroneListItem drone) {
|
||||
// Min + (int)(Math.random() * ((Max - Min) + 1))
|
||||
int randX = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
|
||||
int randY = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
|
||||
@ -305,9 +308,10 @@ public class World {
|
||||
int varY = -10 + (int) (Math.random() * ((10 - -10) + 1));
|
||||
int varX = -10 + (int) (Math.random() * ((10 - -10) + 1));
|
||||
|
||||
int bounty = Nomads.MINOBJECTIVEBOUNTY + (int) (Math.random() * ((Nomads.MAXOBJECTIVEBOUNTY - Nomads.MINOBJECTIVEBOUNTY) + 1));
|
||||
int bounty = Nomads.MINOBJECTIVEBOUNTY
|
||||
+ (int) (Math.random() * ((Nomads.MAXOBJECTIVEBOUNTY - Nomads.MINOBJECTIVEBOUNTY) + 1));
|
||||
|
||||
Objective newObjective = new Objective(bounty, UID);
|
||||
Objective newObjective = new Objective(bounty, drone.getCurrent().getUID());
|
||||
setObjectAt(randX, randY, newObjective);
|
||||
|
||||
// Create a point to return that is somewhere nearby the actual location
|
||||
|
Reference in New Issue
Block a user