package org.project.item.weapons;

import org.project.entity.Entity;
import org.project.entity.players.Player;
import org.project.item.Item;

import java.lang.foreign.PaddingLayout;
import java.util.ArrayList;
import java.util.List;

public abstract class Weapon implements Item {
    private int damage;

    private static int upgradeCost = 2;
    private int cost;
    private int x;

    public Weapon(int damage, int cost, int x) {
        this.damage = damage;
        this.cost = cost;
        this.x = x;
    }

    @Override
    public boolean buy(Player player) {
        List<Weapon> W = player.getWeaponsList();
        for (Weapon w : W) {
            if (w.getClass() == this.getClass()) {
                return false;
            }
        }
        boolean res = player.addItem(this, cost);
        return res;
    }

    public boolean upgrade(Player player) {
        boolean res = player.pay(upgradeCost);
        if (res) {
            upgradeCost *= x;
            damage += x;
        }
        return res;
    }

    public int getDamage() {
        return damage;
    }

    @Override
    public int getCost() { return cost; }
}
