/*******************************************************************************
 * Copyright (c) 2014, Phenix246
 *
 * This work is made available under the terms of the Creative Commons Attribution License:
 * http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en
 * Contact the author for use the sources
 *
 * Cette œuvre est mise à disposition selon les termes de la Licence Creative Commons Attribution :
 * http://creativecommons.org/licenses/by-nc-sa/4.0/deed.fr
 * Contacter l'auteur pour utiliser les sources
 * 
 * Este trabajo está disponible bajo los términos de la licencia Creative Commons Atribución :
 * http://creativecommons.org/licenses/by-nc-sa/4.0/deed.es
 * Contactar al autor para utilizar las fuentes
 * 
 ******************************************************************************/

package fr.blaze_empire.phenix246.blaze_land_essential.network.packet;

import io.netty.buffer.ByteBuf;

import java.io.IOException;

import net.minecraft.entity.player.EntityPlayer;
import fr.blaze_empire.phenix246.blaze_land_essential.entity.player.PlayerMoneyProperties;
import fr.blaze_empire.phenix246.libs.network.BLPacket;

public class PacketPlayerMoney extends BLPacket
{

	private float copperCoins;
	private byte maxCopperCoins;
	private byte silverCoins;
	private byte maxSilverCoins;
	private short goldCoins;
	private short maxGoldCoins;
	private int emeraldCoins;
	private int maxEmeraldCoins;

	public PacketPlayerMoney()
	{}

	public PacketPlayerMoney(float copperCoins, byte maxCopperCoins, byte silverCoins, byte maxSilverCoins, short goldCoins, short maxGoldCoins, int emeraldCoins, int maxEmeraldCoins)
	{
		this.copperCoins = copperCoins;

		this.maxCopperCoins = maxCopperCoins;
		this.silverCoins = silverCoins;
		this.maxSilverCoins = maxSilverCoins;

		this.goldCoins = goldCoins;
		this.maxGoldCoins = maxGoldCoins;

		this.emeraldCoins = emeraldCoins;
		this.maxEmeraldCoins = maxEmeraldCoins;
	}

	@Override
	public void handleClientSide(EntityPlayer player)
	{
		PlayerMoneyProperties props = PlayerMoneyProperties.get(player);

		props.copperCoins = this.copperCoins;

		props.maxCopperCoins = this.maxCopperCoins;
		props.silverCoins = this.silverCoins;
		props.maxSilverCoins = this.maxSilverCoins;

		props.goldCoins = this.goldCoins;
		props.maxGoldCoins = this.maxGoldCoins;

		props.emeraldCoins = this.emeraldCoins;
		props.maxEmeraldCoins = this.maxEmeraldCoins;
	}

	@Override
	public void handleServerSide(EntityPlayer player)
	{
		PlayerMoneyProperties props = PlayerMoneyProperties.get(player);

		props.copperCoins = this.copperCoins;

		props.maxCopperCoins = this.maxCopperCoins;
		props.silverCoins = this.silverCoins;
		props.maxSilverCoins = this.maxSilverCoins;

		props.goldCoins = this.goldCoins;
		props.maxGoldCoins = this.maxGoldCoins;

		props.emeraldCoins = this.emeraldCoins;
		props.maxEmeraldCoins = this.maxEmeraldCoins;
	}

	@Override
	public void writeData(ByteBuf buffer) throws IOException
	{
		buffer.writeFloat(this.copperCoins);

		buffer.writeByte(this.maxCopperCoins);
		buffer.writeByte(this.silverCoins);
		buffer.writeByte(this.maxSilverCoins);

		buffer.writeShort(this.goldCoins);
		buffer.writeShort(this.maxGoldCoins);

		buffer.writeInt(this.emeraldCoins);
		buffer.writeInt(this.maxEmeraldCoins);
	}

	@Override
	public void readData(ByteBuf buffer)
	{
		this.copperCoins = buffer.readFloat();

		this.maxCopperCoins = buffer.readByte();
		this.silverCoins = buffer.readByte();
		this.maxSilverCoins = buffer.readByte();

		this.goldCoins = buffer.readShort();
		this.maxGoldCoins = buffer.readShort();

		this.emeraldCoins = buffer.readInt();
		this.maxEmeraldCoins = buffer.readInt();
	}
}