"use strict"
class Base
{
constructor(params) {
params = params || Base.defaultParams
this.name = params.name
this.cost = params.cost
this.type = params.type
this.count = params.count
this.use = this.bind (this.use, this.onUse)
}
bind () {
return function (decorate, handler) {
decorate.apply(this, [arguments, handler])
}
}
static control(instance) {
if (instance.count <= 0) delete instance
}
use (player) {
throw new Error("Method must be Implemented!")
}
onUse(player) {
this.count--
console.log(`${player.name} только что съел ${this.name}`)
Base.control(this)
}
}
class Food extends Base
{
static get defaultParams() { return { name: "Pizza", cost: 12, type: "food", count: 1 } }
use (args, callback) {
let [player, ...values] = args
if (player.hungry) {
player.health = player.health + this.health >= 100 ? 100 : player.health + this.health
callback(player)
}
}
}
let pizza = new Food(Food.defaultParams)
pizza.use(player)