import Phaser from "phaser";
import Graphics from "../assets/Graphics";

export default class Item {
  public sprite: Phaser.Physics.Arcade.Sprite;
  private body: Phaser.Physics.Arcade.Body;

  constructor(x: number, y: number, scene: Phaser.Scene, player: any, itemname: any, displayName: any) {
	this.player = player;
    this.sprite = scene.physics.add.sprite(x, y, Graphics.professor.name, 0);
    //this.sprite.setSize(16, 6);
	//this.sprite.setOffset(0, 10);
    this.sprite.anims.play(Graphics.items.animations[itemname].name);
	this.sprite.setScale(1.0);
	this.sprite.depth = this.sprite.y;
	
	function hit() {
		if (displayName === "bloodShrine") {
			this.player.hp = this.player.maxhp;
			this.body.checkCollision.none = true;
			this.sprite.setVisible(false);
			window.pickup.play();
		} else if (displayName == "Blood") {
			this.player.hp = Math.min(this.player.maxhp, this.player.hp + 10);
			this.body.checkCollision.none = true;
			this.sprite.setVisible(false);
			window.pickup.play();
		} else if (window.inventory.indexOf(displayName) === -1) {
			window.inventory.push(displayName);
			this.body.checkCollision.none = true;
			this.sprite.setVisible(false);
			window.pickup.play();
		}
	}
	
    this.body = <Phaser.Physics.Arcade.Body>this.sprite.body;
	this.body.immovable = true;
	var me = this;
	setTimeout(function() {
		scene.physics.add.collider(player.sprite, me.sprite, hit, null, me);
	}, 500);
  }

  update(fov: any, map: any, time: number) {
	
  }
}
