package rpgEngine.Logic.Game;

import rpgEngine.Data.Abstract.Game;
import rpgEngine.Data.Abstract.Item;
import rpgEngine.Data.Abstract.Party.HumanPlayer;

public class PlayerItemEquip {
	private HumanPlayer player;
	private Item itemToEquip;
	private Game game;

	public PlayerItemEquip(Game g, HumanPlayer p, Item e) {
		player = p;
		itemToEquip = e;
		game = g;
	}
	
	
	public void equipItem() {
		Integer type = itemToEquip.getType();
		Item oldEquipItem = null;
		
		//Get Old Item
		if(type == Item.TYPE_WEAPON) {
			oldEquipItem = player.getWeapon();
			player.setWeapon(null);
		}
		else if(type == Item.TYPE_HELMET) {
			oldEquipItem = player.getHelmet();
			player.setHelmet(null);
		}
		else if(type == Item.TYPE_ARMOR) {
			oldEquipItem = player.getArmor();
			player.setArmor(null);
		}
		else if(type == Item.TYPE_ACCESSORY) {
			oldEquipItem = player.getAccessory();
			player.setAccessory(null);
		}
		
		//Add Old Item To Inventory
		if(oldEquipItem != null) {
			game.getInventory().addItemToInventory(oldEquipItem);
		}
		
		//Remove Item from inventory
		game.getInventory().removeItemFromInventory(itemToEquip);
		
		//Equip item
		if(type == Item.TYPE_WEAPON) {
			player.setWeapon(itemToEquip);
		}
		else if(type == Item.TYPE_HELMET) {
			player.setHelmet(itemToEquip);
		}
		else if(type == Item.TYPE_ARMOR) {
			player.setArmor(itemToEquip);
		}
		else if(type == Item.TYPE_ACCESSORY) {
			player.setAccessory(itemToEquip);
		}
	}
	
	
}
