2021-04-29 14:45:18 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.entities;
|
2021-04-29 14:40:23 +00:00
|
|
|
|
2021-04-29 14:45:18 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
2021-04-29 14:40:23 +00:00
|
|
|
|
2021-05-11 19:17:06 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Represents a playable character inside a match. */
|
2021-04-29 14:40:23 +00:00
|
|
|
public class Character extends Entity {
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The name of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final String name;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The hp stat of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final Stat hp;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The mp stat of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final Stat mp;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The ap stat of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final Stat ap;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The ranged attack range of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final int attackRange;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The ranged attack damage of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final int rangedDamage;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The melee attack damage of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final int meleeDamage;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The {@link Inventory} of the character */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final Inventory inventory = new Inventory();
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
|
|
|
public Character(EntityID id, IntVector2 position, String name, int hp, int mp, int ap, int attackRange, int rangedDamage, int meleeDamage) {
|
|
|
|
super(id, position);
|
2021-05-01 22:03:03 +00:00
|
|
|
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
|
|
|
|
}
|
2021-04-29 14:40:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Checks if the character is still alive.
|
|
|
|
* @return Whether or not the characters hp is greater than 0
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
|
|
|
public boolean isAlive() {
|
|
|
|
return hp.getValue() > 0;
|
|
|
|
}
|
2021-04-30 19:48:28 +00:00
|
|
|
|
|
|
|
@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);
|
2021-04-30 19:48:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-05-11 19:17:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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 +
|
2021-05-31 22:32:07 +00:00
|
|
|
", position=" + position +
|
2021-05-11 19:17:06 +00:00
|
|
|
'}';
|
|
|
|
}
|
2021-04-29 14:40:23 +00:00
|
|
|
}
|