--价格表
local buling_sellitem = {
    turf_rocky = 25,
    turf_savanna = 25,
    turf_grass = 25,
    turf_forest = 25,
    turf_marsh = 25,
    turf_cave = 25,
    turf_fungus = 25,
    turf_fungus_red = 25,
    turf_fungus_green = 25,
    turf_sinkhole = 25,
    turf_underrock = 25,
    turf_mud = 25,
    turf_desertdirt = 25,
    turf_deciduous = 25,
    turf_beach = 25,
    turf_jungle = 25,
    turf_magmafield = 25,
    turf_tidalmarsh = 25,
    turf_meadow = 25,
    turf_volcano = 25,
    turf_ash = 25,
    turf_woodfloor = 25,
    turf_road = 25,
    gunpowder = 456,
    amulet = 747,
    marble = 347,
    gears = 447,
    tentaclespots = 167,
    blueamulet = 834,
    purpleamulet = 1234,
    orangeamulet = 2663,
    greenamulet = 7747,
    yellowamulet = 2521,
    purplegem = 4334,
    bluegem = 3734,
    redgem = 3747,
    orangegem = 5763,
    yellowgem = 5821,
    greengem = 7747,
    icestaff = 1834,
    firestaff = 747,
    telestaff = 1234,
    orangestaff = 2663,
    greenstaff = 7747,
    yellowstaff = 2521,
    beargervest = 4834,
    bearger_fur = 4834,
    eyebrellahat = 1834,
    deerclops_eyeball = 3834,
    tigereye = 3834,
    minotaurhorn = 6834,
    dragon_scales = 4834,
    goose_feather = 347,
    shark_gills = 1347,
    cane = 3847,
    walrus_tusk = 3747,
    walrushat = 3834,
    cookedmandrake = 7747,
    panflute = 7747,
    mandrake = 7747,
    mandrakesoup = 7747,
    krampus_sack = 10000,
    fireflies = 835,
    bioluminescence = 634,
    messagebottle = 1835,
    tallbirdegg = 634,
    tallbirdegg_cracked = 634,
    tallbirdegg_cooked = 134,
    lureplantbulb = 334,
    spidereggsack = 634,
    spiderhat = 367,
    horn = 747,
    beefalohat = 947,
    blubber = 747,
    ox_horn = 547,
    lightninggoathorn = 447,
    pigskin = 2,
    coontail = 323,
    venomgland = 323,
    manrabbit_tail = 46,
    snakeskin = 53,
    cutreeds = 60,
    dug_sapling = 220,
    dug_berrybush = 340,
    dug_berrybush2 = 360,
    dug_grass = 230,
    dug_marsh_bush = 170,
    dug_bambootree = 240,
    dug_bush_vine = 220,
    dug_elephantcactus = 200,
    dug_coffeebush = 300,
    ironwind = 2834,
    turbine_blades = 2834,
    dragoonheart = 452,
    magic_seal = 1834,
    obsidian = 62,
    goldnugget = 23,
    coral = 15,
    rocks = 19,
    flint = 19,
    nitre = 34,
    log = 3,
    pinecone = 3,
    acorn = 53,
    coconut = 43,
    jungletreeseed = 3,
    cutgrass = 17,
    bamboo = 34,
    sand = 13,
    boneshard = 31,
    palmleaf = 13,
    vine = 21,
    twigs = 17,
    dubloon = 107,
    meat = 2,
    nightmarefuel = 45,
    seashell = 32,
    seaweed = 32,
    smallmeat = 22,
    froglegs = 22,
    honey = 13,
    honeycomb = 749,
    stinger = 10,
    butter = 430,
    drumstick = 45,
    batwing = 58,
    plantmeat = 35,
    fish = 25,
    tropical_fish = 25,
    eel = 75,
    cutlichen = 30,
    berries = 15,
    carrot = 15,
    green_cap = 22,
    blue_cap = 18,
    bird_egg = 12,
    houndstooth = 52,
    thulecite = 350,
    livinglog = 139,
    charcoal = 25,
    cactus_meat = 36,
    goatmilk = 134,
    silk = 26,
    seeds = 9,
    poop = 23,
    guano = 43,
    wormlight = 234,
    thulecite_pieces = 200,
    armorwood = 180,
    footballhat = 170,
    glommerfuel = 200,
}
local function OnGetItemFromPlayer(inst, giver, item)
    --I eat food
    if item.components.edible then
        --meat makes us friends (unless I'm a guard)
        if item.components.edible.foodtype == "MEAT" or item.components.edible.foodtype == "HORRIBLE" or item.prefab == "carrot" or item.prefab == "carrot_cooked" then
            if inst.components.combat.target and inst.components.combat.target == giver then
                inst.components.combat:SetTarget(nil)
			end
        end
        if inst.components.sleeper:IsAsleep() then
            inst.components.sleeper:WakeUp()
        end
    end
    --I wear hats
    if item.components.equippable and item.components.equippable.equipslot == EQUIPSLOTS.HEAD then
        local current = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
        if current then
            inst.components.inventory:DropItem(current)
        end
        
        inst.components.inventory:Equip(item)
        inst.AnimState:Show("hat")
    end
end
AddPrefabPostInit("pigman", function(inst)
	if GetPlayer().prefab == "bulingbuling" then
		inst.components.trader.onaccept = OnGetItemFromPlayer
	end
end)
AddPrefabPostInit("wildbore", function(inst)
	if GetPlayer().prefab == "bulingbuling" then
		inst.components.trader.onaccept = OnGetItemFromPlayer
	end
end)
AddPrefabPostInit("bunnyman", function(inst)
	if GetPlayer().prefab == "bulingbuling" then
		inst.components.trader.onaccept = OnGetItemFromPlayer
	end
end)
--我鲨克雷码佬,一句话的事我还得用api，留个接口会死啊
local tabs  = {}
local rec 
local function crafttabspostinit(self)
    self.HandleMultiCraftingStationTabs = function(self,valid_tabs)
	-- if there's more than one tab at an index replace it with a multitab that has all these tabs
	local tabcounts = {}
	local multitab 
	for i,v in pairs(self.tabbyfilter) do
		if v ~= self.multitab then
			local isValid = valid_tabs[v]
			if isValid then
				local index = i.sort
				tabcounts[index] = tabcounts[index] or {}
				table.insert(tabcounts[index],{i,v})
			end
		end
	end

	-- do we have to create the multitab?
	for i,v in pairs(tabcounts) do
		if #v > 1 then
			-- show the multitab, hide the subtabs	
			if self.multitab then

				-- hide the specific subtabs
				for i,v in pairs(v) do   
					valid_tabs[v[2]] = false
				end
				-- show the multitab
				valid_tabs[self.multitab] = true

				-- and add them to the multitab
				self.multitab_crafting_stations = {}

				-- sort these guys, recipes are shown in the order they're added (or re-added)
			    table.sort(v, function(a, b) 
									local tabname_a = a[1].str
									local tabname_b = b[1].str
									local tabdef_a = RECIPETABS[tabname_a]
									local tabdef_b = RECIPETABS[tabname_b]
									return tabdef_a.priority < tabdef_b.priority 
								end)
				
				local highlighted = false
				local alternatehighlighted = false
				local overlayshow = false

				for i,v in pairs(v) do
					-- Create RecipeCategories for these guys, and add tehm to the multitab
					local tabdef = v[1]
					local actualTab = v[2]

					local name = tabdef.str
					local tabname = name
					local imagename = actualTab.icon
					-- strip off the .tex if it exists
					if imagename:endsWith(".tex") then
						imagename = imagename:left(-4)
					end
					local tooltip = STRINGS.TABS[string.upper(name)]
					local category = RecipeCategory(tabname, RECIPETABS[name], RECIPETABS.CRAFTINGSTATIONS, TECH.NONE, RECIPE_GAME_TYPE.COMMON, imagename, tooltip)
					category.atlas = actualTab.icon_atlas or actualTab.atlas
					category.imageScale = 0.5
					category.imageNudge = -6
					category.skipCategoryCheck = true -- to prevent some expensive work that is not needed on these guys

					self.multitab_crafting_stations[tabname] = true
					-- does this one have an alt-highlight?
					category.alternatehighlighted = actualTab.alternatehighlighted
					alternatehighlighted = alternatehighlighted or actualTab.alternatehighlighted
					-- or a highlight? (takes precedence)
					category.highlighted = actualTab.highlighted
					highlighted = highlighted or actualTab.highlighted
					-- an overlay?
					category.overlayshow = actualTab.overlayshow
					overlayshow = overlayshow or actualTab.overlayshow
				end
				-- handle ourselves as well
				if highlighted or alternatehighlighted then
					if highlighted then
						self.multitab:Highlight(1)
					else
						self.multitab:UnHighlight(true)
						self.multitab:AlternateHighlight(1)
					end
				else
					self.multitab:UnHighlight()
				end
				if overlayshow then
					self.multitab:Overlay()
				else
					self.multitab:HideOverlay()
				end
				-- force a refresh of the known recipes
				local recipes = GetAllRecipes(true)
			end
		end
	end
	
        --self.tabbyfilter[v] = tab
	end
end
AddClassPostConstruct("widgets/crafttabs", crafttabspostinit)
