jurpe.combat
Class DualCombat

java.lang.Object
  extended by jurpe.combat.DualCombat
All Implemented Interfaces:
ICombat

public class DualCombat
extends java.lang.Object
implements ICombat

Class for combat between PCs. Every instance of DualCombat represents an entire combat, from the beginning to the end. Variabile "isAlive" check if current combat is still taking place. For instance, in a combat between JOE and JAK we will have:

 DualCombat combat = new DualCombat(Joe, Jak); // Joe vs. Jack
 
 
 
Remember to swap fighters at the end of every turn with combat.swapFighters()

Author:
Alessio Saltarin
See Also:
Combat

Field Summary
 
Fields inherited from interface jurpe.combat.ICombat
AVAILABLE_COMBAT_COMMANDS, CM_AIM, CM_ALLOATT, CM_ALLODEF, CM_ATTAK, CM_MOVE, CM_RDYWPN, CM_RELOAD
 
Constructor Summary
DualCombat()
          Creates a random, default Dual Combat for test purposes.
DualCombat(TurnTable tt)
          Constructor.
 
Method Summary
 boolean aim()
          Aim combat option
 boolean allOutAttack()
          All Out Attack (AOA) combat option.
 boolean allOutDefense()
          All Out Defense combat option.
 boolean attack()
          Attack routine for DualCombat.
 float earnedExperiencePoints()
          Returns the experience points earned in this combat.
 int earnedScore(int turnsPlayed)
          Returns the score points earned in this combat.
 PC getFightee()
          Get Fightee (first attacked) in this DualCombat
 PC getFighter()
          Get Fighter (first attacker) in this DualCombat
 PCharacter getHumanFighter()
          In a DualCombat one of the combatants could be a PCharacter.
 Monster getMonsterFighter()
          In a DualCombat one of the combatants could be a Monster.
 TurnTable getTurnTable()
          Return Turn Table associated with this DualCombat
 boolean isAlive()
          Return true combat is alive (ie: will not terminate next turn).
 java.lang.String log()
          Returns log, appending LINEFEED after every item.
 boolean move()
          Combatants use this command to try to escape.
 boolean readyWeapon()
          Ready Weapon combat option.
 boolean reload()
          Reload combat option.
 void setAlive(boolean alive)
          Use this method to quit a combat when combatants are still living.
 void setFighters(PC fighter, PC fightee)
          Set fighters.
 void swapFighters()
          Call this method at the end of every combat turn, if combatants are still alive.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DualCombat

public DualCombat()
Creates a random, default Dual Combat for test purposes.


DualCombat

public DualCombat(TurnTable tt)
Constructor. Initialize fighters, fighters' names. It sets isAlive=true

Parameters:
tt - is the active TurnTable
See Also:
TurnTable
Method Detail

getFightee

public PC getFightee()
Get Fightee (first attacked) in this DualCombat

Returns:
PC character
See Also:
PC

getHumanFighter

public PCharacter getHumanFighter()
In a DualCombat one of the combatants could be a PCharacter. In every case this method returns the first PCharacter between fighter and fightee. If noone is human, it returns null

Returns:
The Human Playing Character in combat

getMonsterFighter

public Monster getMonsterFighter()
In a DualCombat one of the combatants could be a Monster. In every case this method returns the first Monster between fighter and fightee. If noone is monster, it returns null.

Returns:
The AI Monster fighter

getTurnTable

public TurnTable getTurnTable()
Return Turn Table associated with this DualCombat

Returns:
current turns table
See Also:
TurnTable

getFighter

public PC getFighter()
Get Fighter (first attacker) in this DualCombat

Returns:
PC character
See Also:
PC

swapFighters

public void swapFighters()
Call this method at the end of every combat turn, if combatants are still alive.


setFighters

public void setFighters(PC fighter,
                        PC fightee)
Set fighters. Order is important: first parameter is fighter (the one that attacks), second is fightee (defender).

Parameters:
fighter - PC who is making the attack
fightee - PC who is defending

isAlive

public boolean isAlive()
Return true combat is alive (ie: will not terminate next turn). Combat is not alive when one combatants is dead or escaped.

Returns:
true if fighters are both still alive

setAlive

public void setAlive(boolean alive)
Use this method to quit a combat when combatants are still living. IE: one of them escapes.

Parameters:
alive - set boolean condition. If true, character is alive.

move

public boolean move()
Combatants use this command to try to escape. You succeed in escaping if fighter's movement points are greater than fightee's

Specified by:
move in interface ICombat
Returns:
true if combat ends after this command

readyWeapon

public boolean readyWeapon()
Ready Weapon combat option. Use this command to ready an unready weapon.

Specified by:
readyWeapon in interface ICombat
Returns:
true

reload

public boolean reload()
Reload combat option.

Specified by:
reload in interface ICombat
Returns:
true if combat ends after this command

aim

public boolean aim()
Aim combat option

Specified by:
aim in interface ICombat
Returns:
true if combat ends after this command

attack

public boolean attack()
Attack routine for DualCombat.

1. Check if fighter is ready 2. If so makes an attack with current weapon 3. If attacks suceeds, fightee executes its defense 4. If defense fails, it rolls for damages

Specified by:
attack in interface ICombat
Returns:
true if combat ends after this command

allOutAttack

public boolean allOutAttack()
All Out Attack (AOA) combat option. When a character chooses to do an All Out Attack, she may make no active defenses at all until next turn.

Specified by:
allOutAttack in interface ICombat
Returns:
true if combat ends after this command

allOutDefense

public boolean allOutDefense()
All Out Defense combat option.
"Defend yourself; do nothing else this turn. If you fail your defense roll against any attack, you may try another (different) defense". In this implementation, we arbitrarily choose to make a first roll with the active defense choosen by the character and the second one from dodging, blocking and parrying, in this order. Of course, if character has just one active defense available, he cannot make an All Out Defense. Parrying is considered unavailable if character wears an unbalanced weapon.
If character has only two active defenses available, he will have two rolls: the first one with the AD he choose, the second one with the other.
If character has three active defenses available, he will have two rolls: the first one with the AD he choose, the second one with blocking, or with dodging, if blocking is its first choose. (Beware: this is not a Jurpe Rule!). The All Out Defense Command is implemented as follows. When the command is issued, it sets BOTH active defenses for the fighter. When, during an attack (the next turn) the defenseFromAttack() method is called, a check is done. If fightee.getActiveDefenses returns an array of length=2 then the fightee chose All Out Defense in the turn before. The defenseFromAttack() method will then perform an All Out Defense for that character and, after that, will restore the ActiveDefenses to length=1.

Specified by:
allOutDefense in interface ICombat
Returns:
true if combat ends after this command

log

public java.lang.String log()
Returns log, appending LINEFEED after every item.

Specified by:
log in interface ICombat
Returns:
String log separated by LF

earnedScore

public int earnedScore(int turnsPlayed)
Returns the score points earned in this combat. If fighter is PC and combat is not alive -> PC earned a score. If fighter is NPC and combat is not alive -> PC earned nothing.

Parameters:
turnsPlayed - number of turns played in this combat
Returns:
score points

earnedExperiencePoints

public float earnedExperiencePoints()
Returns the experience points earned in this combat. If fighter is PC and combat is not alive -> PC earned experience points If fighter is NPC and combat is not alive -> PC earned nothing. There is a chance you get no points even if you won the combat.

Returns:
score points

Jurpe - Java Universal Role Playing Engine - http://jurpe.sourceforge.net