package com.zivilon.cinder_loe.mixins;

import com.zivilon.cinder_loe.CinderLoE;
import lotr.common.LOTRLevelData;
import lotr.common.entity.npc.*;
import lotr.common.entity.npc.LOTRTradeEntries.TradeType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.Field;
import java.util.Map;

@Mixin(LOTRTraderNPCInfo.class)
public class MixinLOTRTraderNPCInfo {
    @Shadow(remap = false)
    private LOTREntityNPC theEntity;
    @Shadow(remap = false)
    private int valueSinceRefresh;
    @Shadow(remap = false)
    private int timeSinceTrade;
    @Shadow(remap = false)
    public void sendClientPacket(EntityPlayer entityplayer) {}

    public void onTrade(EntityPlayer entityplayer, LOTRTradeEntry trade, LOTRTradeEntries.TradeType type, int value) {
        ItemStack trade_item = trade.createTradeItem();
        ((LOTRTradeable)this.theEntity).onPlayerTrade(entityplayer, type, trade_item);
        LOTRLevelData.getData(entityplayer).getFactionData(this.theEntity.getFaction()).addTrade();
        if (trade_item.getItem() == CinderLoE.spiceIngredient) trade.doTransaction(999999999);
        trade.doTransaction(value);
        this.timeSinceTrade = 0;
        this.valueSinceRefresh += value;
        sendClientPacket(entityplayer);
    }
}
