Skip to content

Commit

Permalink
OneTimeCommands can have cooldowns now and execute before or after co…
Browse files Browse the repository at this point in the history
…oldown.

 - Adjusted Existing Documentation for AllStop, Torpedo, SpaceMine, The Hunger Bauble Commands.
 - Space Mines are slightly cheaper but have a cooldown of 2 seconds.
 - All Stop has a 5 second cooldown.
 - Collecting Baubles and Firing Torpedos have a 0.2 second cooldown.
 - Ejecting Baubles costs energy based on value and time based on mass.
  • Loading branch information
hawkerm committed Jun 2, 2016
1 parent 378e444 commit 6b544f4
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 38 deletions.
11 changes: 9 additions & 2 deletions SBA_Serv/Game/TheHungerBaubles.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,11 @@ class CollectCommand(OneTimeCommand):
NAME = GAME_CMD_COLLECT

def __init__(self, obj, game, id):
super(CollectCommand, self).__init__(obj, CollectCommand.NAME, required=8)
self.target = id
self.game = game

super(CollectCommand, self).__init__(obj, CollectCommand.NAME, True, 0.2, required=8)

def onetime(self):
for wobj in self.game.world.getObjectsInArea(self._obj.body.position, self.game.collect_radius):
if wobj.id == self.target and isinstance(wobj, Bauble):
Expand All @@ -334,10 +335,16 @@ class EjectCommand(OneTimeCommand):
NAME = GAME_CMD_EJECT

def __init__(self, obj, game, id):
super(EjectCommand, self).__init__(obj, EjectCommand.NAME, required=24)
self.target = id
self.game = game

for wobj in obj.player.carrying:
if wobj.id == self.target:
weight = wobj.weight
value = wobj.value

super(EjectCommand, self).__init__(obj, EjectCommand.NAME, ttl=0.5*weight, required=value*3)

def onetime(self):
for wobj in self._obj.player.carrying:
if wobj.id == self.target:
Expand Down
4 changes: 2 additions & 2 deletions SBA_Serv/Tests/SpaceMineTestCases.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_mine_explosion_moves_ship(self):
start = self.game.world.mid_point(0, 0)
ship = AIShip_SetList("Miner", start, self.game, [
"IdleCommand(self, 2.0)",
"DeploySpaceMineCommand(self, 6.0, 2, 0, 1, 0.0)", #Auto
"DeploySpaceMineCommand(self, 8.0, 2, 0, 1, 0.0)", #Auto
"ThrustCommand(self, 'B', 2.5, 1.0)",
"IdleCommand(self, 3.0)",
"ThrustCommand(self, 'F', 2.5, 1.0)"
Expand All @@ -227,7 +227,7 @@ def test_mine_explosion_moves_ship(self):
self.assertIn(ship, self.game.world, "Ship not in world.")
self.assertEqual(len(self.game.world), 1, "More than just ship in world.")

time.sleep(4.5)
time.sleep(6.5)

self.assertIn(ship, self.game.world, "Ship not in world.")
self.assertEqual(len(self.game.world), 2, "No extra mine in world.")
Expand Down
14 changes: 7 additions & 7 deletions SBA_Serv/Tests/WorldTestCases.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,40 +795,40 @@ def test_all_stop(self):
self.assertAlmostEqual(ship.health.value, 50, None, "Player Health not Halved", 1)
self.assertLess(ship.energy.value, 100, "Player Energy didn't decrease")

time.sleep(5.5)
time.sleep(10.5)

print ship.health
ship.energy.full() # replenish
self.assertAlmostEqual(ship.health.value, 25, None, "Player Health not Halved 2", 1)

time.sleep(5.5)
time.sleep(10.5)

print ship.health
self.assertAlmostEqual(ship.health.value, 13, None, "Player Health not Halved 3", 1)

time.sleep(5.5)
time.sleep(10.5)

print ship.health
ship.energy.full() # replenish
self.assertAlmostEqual(ship.health.value, 7, None, "Player Health not Halved 4", 1)

time.sleep(5.5)
time.sleep(10.5)

print ship.health
self.assertAlmostEqual(ship.health.value, 4, None, "Player Health not Halved 5", 1)

time.sleep(5.5)
time.sleep(10.5)

print ship.health
ship.energy.full() # replenish
self.assertAlmostEqual(ship.health.value, 2, None, "Player Health not Halved 6", 1)

time.sleep(5.5)
time.sleep(10.5)

print ship.health
self.assertAlmostEqual(ship.health.value, 1, None, "Player Health not Halved 7", 1)

time.sleep(6)
time.sleep(11)

print ship.health
self.assertFalse(ship in self.game.world, "Doomed Ship not destroyed")
Expand Down
16 changes: 12 additions & 4 deletions SBA_Serv/World/Messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,26 @@ def __repr__(self):
return "Command(#" + str(self._obj.id) + ", " + self.message + ", " + repr(self.timeToLive) + ", " + repr(self.blocking) + ", " + repr(self.initialrequiredenergy) + ")"

class OneTimeCommand(Command):
def __init__(self, obj, msg, ttl=4, required=0):
def __init__(self, obj, msg, executefirst=False, ttl=4, required=0):
super(OneTimeCommand, self).__init__(obj, msg, ttl, block=True, required=required)
self.__executed = False
self.__done = False
if executefirst:
self.__executed = True
self.onetime()

def isComplete(self):
return self.__executed
return self.__done and self.__executed

def execute(self, t):
def isExpired(self):
self.__done = super(OneTimeCommand, self).isExpired()
if not self.__executed:
self.onetime()
self.__executed = True
self.onetime()

def execute(self, t):
self.isExpired()

def onetime(self):
pass

Expand Down
13 changes: 6 additions & 7 deletions SBA_Serv/World/WorldCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ class AllStopCommand(OneTimeCommand):

def __init__(self, obj):
if obj.body.velocity.length < 1:
super(AllStopCommand, self).__init__(obj, AllStopCommand.NAME, 0)
super(AllStopCommand, self).__init__(obj, AllStopCommand.NAME, True, 1)
else:
# TODO: TTL doesn't work here on a OneTimeCommand...
super(AllStopCommand, self).__init__(obj, AllStopCommand.NAME, 15, required=40)
super(AllStopCommand, self).__init__(obj, AllStopCommand.NAME, True, 5, required=40)
#eif

def onetime(self):
Expand Down Expand Up @@ -435,22 +434,22 @@ class DeployLaserBeaconCommand(OneTimeCommand):
def __init__(self, obj):
obj.lasernodes.append(intpos(obj.body.position))

super(DeployLaserBeaconCommand, self).__init__(obj, DeployLaserBeaconCommand.NAME)
super(DeployLaserBeaconCommand, self).__init__(obj, DeployLaserBeaconCommand.NAME, True, ttl=0.05)

class DestroyAllLaserBeaconsCommand(OneTimeCommand):
NAME = SHIP_CMD_DESTROY_ALL_BEACONS

def __init__(self, obj):
obj.lasernodes = []

super(DestroyAllLaserBeaconsCommand, self).__init__(obj, DestroyAllLaserBeaconsCommand.NAME)
super(DestroyAllLaserBeaconsCommand, self).__init__(obj, DestroyAllLaserBeaconsCommand.NAME, True, ttl=0.1)

class FireTorpedoCommand(OneTimeCommand):
NAME = SHIP_CMD_TORPEDO

def __init__(self, ship, direction):
self.__direction = direction
super(FireTorpedoCommand, self).__init__(ship, FireTorpedoCommand.NAME, required=12)
super(FireTorpedoCommand, self).__init__(ship, FireTorpedoCommand.NAME, True, 0.2, required=12)

def onetime(self):
self._obj.player.sound = "LASER"
Expand All @@ -469,7 +468,7 @@ def __init__(self, ship, delay, wmode, direction=None, speed=None, duration=None
self.__direction = direction
self.__speed = speed
self.__duration = duration
super(DeploySpaceMineCommand, self).__init__(ship, DeploySpaceMineCommand.NAME, required=(33 + self.__wmode * 11))
super(DeploySpaceMineCommand, self).__init__(ship, DeploySpaceMineCommand.NAME, True, 2, required=(22 + self.__wmode * 11))

def onetime(self):
self._obj.player.sound = "MINE"
Expand Down
2 changes: 1 addition & 1 deletion SBA_Serv/buildnum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1121
1122
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* A command to bring a ship to an immediate full stop.
* <p>
* Will deplete energy by 40 and health by 50%.
* Will deplete energy by 40 and health by 50% and wait for 5 seconds.
* @author Brett Wortzman
*
* @since 0.9
* @version 1.1
* @version 1.2
*/
public class AllStopCommand extends ShipCommand {

Expand All @@ -31,9 +31,10 @@ public String getName() {
public static int getInitialEnergyCost() { return 40; }

/**
* AllStop executes immediately.
* AllStop executes immediately and has a cooldown of 5 seconds.
*
* @since 1.1
* @version 1.2
* @return true
*/
public static boolean executesImmediately() { return true; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getName() {
public static int getInitialEnergyCost() { return 8; }

/**
* Collecting Baubles executes immediately.
* Collecting Baubles executes immediately but has a cooldown of 0.2 seconds.
*
* @return true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ public String getName() {

/**
* Gets the energy cost for the constructed command.
* @return (44, 55, 66)
* @return (33, 44, 55)
*/
public int getEnergyCost()
{
return 33 + this.MODE * 11;
return 22 + this.MODE * 11;
}

/**
* Gets the one-time energy cost to initiate this command.
* @return the amount of energy consumed by initiating this command (44, 55, or 66)
* @return the amount of energy consumed by initiating this command (33, 44, or 55)
*/
public static int getInitialEnergyCost() { return 44; }
public static int getInitialEnergyCost() { return 33; }

/**
* Deploy Space Mine executes immediately.
* Deploy Space Mine executes immediately and has a cooldown of 2 seconds.
*
* @return true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ public String getName() {
}

/**
* Gets the one-time energy cost to initiate this command.
* @return the amount of energy consumed by initiating this command (24)
* Gets the energy cost for the constructed command.
* @return (3 * baubleValue)
*/
public static int getInitialEnergyCost() { return 24; }
public int getEnergyCost(int baubleValue)
{
return 3 * baubleValue;
}

/**
* Gets the average one-time energy cost to initiate this command.
* @return the amount of energy consumed by initiating this command (3 * Bauble Value)
*/
public static int getInitialEnergyCost() { return 12; }

/**
* Ejecting Baubles executes immediately.
* Ejecting Baubles executes immediately after a cooldown of 0.5 seconds * mass of Bauble to eject.
*
* @return true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Brett Wortzman
*
* @since 0.9
* @version 1.1
* @version 1.2
*/
public class FireTorpedoCommand extends ShipCommand {
@SuppressWarnings("unused")
Expand Down Expand Up @@ -38,9 +38,10 @@ public String getName() {
public static int getInitialEnergyCost() { return 12; }

/**
* Fire Torpedo executes immediately.
* Fire Torpedo executes immediately with a cooldown of 0.2 seconds.
*
* @since 1.1
* @version 1.2
* @return true
*/
public static boolean executesImmediately() { return true; }
Expand Down

0 comments on commit 6b544f4

Please sign in to comment.