class_name BattleMove extends BattleAction

enum MoveType {
  PHYSICAL,
  ABILITY,
  MAGICAL,
}

enum BattleMoveResult {
  HIT,
  MISS,
  CRIT,
}

var power:int
var mpCost:int
var accuracy:float
var moveType:MoveType
var fieldUse:bool

func _init(params:Dictionary) -> void:
  super(params)
  self.power = params.get("power", 0)
  self.mpCost = params.get("mpCost", 0)
  self.speedModifier = params.get("speedModifier", 1.0)
  self.accuracy = params.get("accuracy", 1.0)
  self.moveType = params.get("moveType", MoveType.PHYSICAL)
  self.fieldUse = params.get("fieldUse", false)

func perform(params:Dictionary):
  super.perform(params)

  var user:BattleFighter = params.get("user")
  var targets:Array[BattleFighter] = params.get("targets")
  
  # What to do if target is dead?
  for target in targets:
    if target.status == BattleFighter.Status.DEAD:
      print("Target is already dead. Move has no effect.")
      assert(false)

  # TODO: Determine damage
  var damage:int = 0
  var isCrit:bool = false
  var isMiss:bool = false
  user.mpConsume(self.mpCost)

  if isMiss:
    print("ATTACK MISS")
    assert(false)
  
  if isCrit:
    print("CRITICAL HIT!")
  for target in targets:
    target.damage(damage, isCrit)
  print("DAMAGE DONE")

func canFighterUse(fighter:BattleFighter) -> bool:
  if !super.canFighterUse(fighter):
    return false
  
  if fighter.mp < self.mpCost:
    return false

  return true

# Moves
static var MOVE_PUNCH = BattleMove.new({
  "handle": "punch",
  "power": 15,
  "accuracy": 0.95,
  "moveType": MoveType.PHYSICAL
})

static var MOVE_FIRE1 = BattleMove.new({
  "handle": "fire1",
  "power": 25,
  "mpCost": 5,
  "accuracy": 0.9,
  "moveType": MoveType.MAGICAL,
  "canTargetMultiple": true
})

static var MOVE_HEAL1 = BattleMove.new({
  "handle": "heal1",
  "power": -20,
  "mpCost": 8,
  "accuracy": 1.0,
  "moveType": MoveType.ABILITY,
  "canTargetMultiple": true,
  "preferAlly": true
})