package player;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

import animations.PlayerAnimations;
import engine.Game;
import hud.inventory.InvenHelper;
import interfaces.PlayerAnimationIDs;
import rendercalculator.player.HandSlotRenderer;
import utils.Utils;

/**  ------------- Nihilne ------------
    *** @author Mitch Weaver - 2016 ***
      ~~~~ All Rights Reserved ~~~~ */

public final class PlayerRender implements PlayerAnimationIDs {
	
	public static final int AMOUNT = 5; /* fast = 2, smooth = 4 */

	private static Graphics2D copy; private static final AffineTransform transform = new AffineTransform();
	public static final void render(final Graphics2D g2d) {
//		if (Game.dontDrawPlayer || !Player.animate) return;
		
		if(Player.health <= 0) { PlayerDeath.render(g2d); return; }
		
		if(Player.attacking) { PlayerAttackSequence.render(g2d); return; }

		transform.setToRotation(-Utils._45 * (Game.rotation - 1), Player.center.x, Player.center.y); copy = (Graphics2D) g2d.create(); copy.transform(transform);
		
		if (Game.drawCollisionBounds) {
			g2d.setColor(Color.BLUE);
			g2d.drawOval((int) (Player.center.x - Player.radius), (int) (Player.center.y - Player.radius), (int) Player.radius * 2, (int) Player.radius * 2);
			g2d.setColor(Color.BLUE);
			g2d.draw(Player.bounds);
		}
		
		drawAnimation(copy); /* BASE PLAYER ANIMATION */
		drawEquippedItems(copy);
		
		copy.dispose(); copy = null;
	}

	private static final void drawAnimation(final Graphics2D copy) {
		switch (Player.currentAnimation) {
			case IDLE: 			PlayerAnimations.base.renderIdle(copy); break;
			case WALK: 			PlayerAnimations.base.renderWalk(copy); break;
			case AXE_CHOP: 		PlayerAnimations.base.renderChop(copy); break;
			case MINE_ROCK: 	PlayerAnimations.base.renderMine(copy); break;
			case GET_HIT:		PlayerAnimations.base.renderGetHit(copy); break;
		}
	}
	
	private static final void drawEquippedItems(final Graphics2D copy){
		try{ if(Player.equipmentSlots[InvenHelper.HAND_SLOT].itemId != InvenHelper.NULL_ITEM) HandSlotRenderer.render(copy);
		} catch(ArrayIndexOutOfBoundsException e){ // must catch these
		}
	}
}
