Gamelib/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java

142 lines
5.3 KiB
Java

package uulm.teamname.marvelous.gamelibrary.entities;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import java.util.Objects;
/** Represents a playable character inside a match. */
public class Character extends Entity {
/** The name of the character */
public final String name;
/** The hp stat of the character */
public final Stat hp;
/** The mp stat of the character */
public final Stat mp;
/** The ap stat of the character */
public final Stat ap;
/** The ranged attack range of the character */
public final int attackRange;
/** The ranged attack damage of the character */
public final int rangedDamage;
/** The melee attack damage of the character */
public final int meleeDamage;
/** The {@link Inventory} of the character */
public final Inventory inventory = new Inventory();
/**
* Constructs a new {@link Character} with an empty inventory.
* @param id The {@link EntityID} of the character
* @param position The position of the character
* @param name The name of the character
* @param hp The maximum hp of the character
* @param mp The maximum mp of the character
* @param ap The maximum ap of the character
* @param attackRange The ranged attack range of the character
* @param rangedDamage The ranged damage of the character
* @param meleeDamage The melee damage of the character
*/
public Character(EntityID id, IntVector2 position, String name, int hp, int mp, int ap, int attackRange, int rangedDamage, int meleeDamage) {
super(id, position);
solid = false;
opaque = true;
if(id.type == EntityType.NPC && id.id == NPCType.Thanos.getID()) {
solid = true; //characters cannot walk into thanos
}
this.name = name;
this.hp = new Stat(StatType.HP, hp);
this.mp = new Stat(StatType.MP, mp);
this.ap = new Stat(StatType.AP, ap);
this.attackRange = attackRange;
this.rangedDamage = rangedDamage;
this.meleeDamage = meleeDamage;
}
/**
* Constructs a new {@link Character} with an empty inventory.
* @param id The {@link EntityID} of the character
* @param position The position of the character
* @param name The name of the character
* @param maxHp The maximum hp of the character
* @param maxMp The maximum mp of the character
* @param maxAp The maximum ap of the character
* @param hp The current hp of the character
* @param mp The current mp of the character
* @param ap The current ap of the character
* @param attackRange The ranged attack range of the character
* @param rangedDamage The ranged damage of the character
* @param meleeDamage The melee damage of the character
*/
public Character(EntityID id, IntVector2 position, String name, int maxHp, int maxMp, int maxAp, int hp, int mp, int ap, int attackRange, int rangedDamage, int meleeDamage) {
super(id, position);
solid = false;
opaque = true;
if(id.type == EntityType.NPC && id.id == NPCType.Thanos.getID()) {
solid = true; //characters cannot walk into thanos
}
this.name = name;
this.hp = new Stat(StatType.HP, hp, maxHp);
this.mp = new Stat(StatType.MP, mp, maxMp);
this.ap = new Stat(StatType.AP, ap, maxAp);
this.attackRange = attackRange;
this.rangedDamage = rangedDamage;
this.meleeDamage = meleeDamage;
}
/**
* Checks if the character is still alive.
* @return Whether or not the characters hp is greater than 0
*/
public boolean isAlive() {
return hp.getValue() > 0;
}
@Override
public Character clone() {
Character clone = new Character(id, position, name, hp.getMax(), mp.getMax(), ap.getMax(), attackRange, rangedDamage, meleeDamage);
for(StoneType stone: inventory) {
clone.inventory.addStone(stone);
}
clone.hp.setValue(hp.getValue());
clone.mp.setValue(mp.getValue());
clone.ap.setValue(ap.getValue());
return clone;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Character character = (Character) o;
return attackRange == character.attackRange && rangedDamage == character.rangedDamage && meleeDamage == character.meleeDamage && Objects.equals(name, character.name) && Objects.equals(hp, character.hp) && Objects.equals(mp, character.mp) && Objects.equals(ap, character.ap) && Objects.equals(inventory, character.inventory);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), name, hp, mp, ap, attackRange, rangedDamage, meleeDamage, inventory);
}
@Override
public String toString() {
return "Character{" +
"name='" + name + '\'' +
", hp=" + hp +
", mp=" + mp +
", ap=" + ap +
", attackRange=" + attackRange +
", rangedDamage=" + rangedDamage +
", meleeDamage=" + meleeDamage +
", inventory=" + inventory +
", position=" + position +
'}';
}
}