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

110 lines
3.8 KiB
Java
Raw Normal View History

2021-04-29 14:45:18 +00:00
package uulm.teamname.marvelous.gamelibrary.entities;
2021-04-29 14:45:18 +00:00
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;
2021-05-31 20:54:13 +00:00
if(id.type == EntityType.NPC && id.id == 2) {
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;
}
/**
* 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() {
2021-05-31 20:54:13 +00:00
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 +
'}';
}
}