Skip to content

Commit

Permalink
mode: Fix bots stuck in secret shop
Browse files Browse the repository at this point in the history
Signed-off-by: AdamQQQ <[email protected]>
  • Loading branch information
adamqqqplay committed May 21, 2023
1 parent e1f146f commit 59fe042
Showing 1 changed file with 83 additions and 13 deletions.
96 changes: 83 additions & 13 deletions mode_secret_shop_generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,22 @@ function OnEnd()

end

function Think()
local fullInvCheck = -90

local earlyGameItem = {
"item_clarity",
"item_faerie_fire",
"item_tango",
"item_flask",
-- "item_orb_of_venom",
"item_bracer",
"item_wraith_band",
"item_null_talisman",
"item_infused_raindrop",
"item_bottle",
}

function Think()
if bot:IsChanneling()
or bot:NumQueuedActions() > 0
or bot:IsCastingAbility()
Expand All @@ -79,6 +93,59 @@ function Think()
return
end

local botLevel = bot:GetLevel()
local currentTime = DotaTime()
local botWorth = bot:GetNetWorth()

--卖掉一些早期的低端物品用来腾格子
if (GetGameMode() ~= 23 and botLevel > 6 and currentTime > fullInvCheck + 1.0
and (bot:DistanceFromFountain() <= 200 or bot:DistanceFromSecretShop() <= 200))
or (GetGameMode() == 23 and botLevel > 9 and currentTime > fullInvCheck + 1.0)
then
local emptySlot = X.GetEmptyInventoryAmount(bot)
local slotToSell = nil

local preEmpty = 2
if botLevel <= 17 then preEmpty = 1 end
if emptySlot <= preEmpty - 1
then
for i = 1, #earlyGameItem
do
local itemName = earlyGameItem[i]
local itemSlot = bot:FindItemSlot(itemName)
if itemSlot >= 0 and itemSlot <= 8
then
slotToSell = itemSlot
break
end
end
end

--避免过早卖掉大魔棒
if botWorth > 9999
then
local wand = bot:FindItemSlot("item_magic_wand")
local assitItem = bot:FindItemSlot("item_infused_raindrop")
if assitItem < 0 then assitItem = bot:FindItemSlot("item_bracer") end
if assitItem < 0 then assitItem = bot:FindItemSlot("item_null_talisman") end
if assitItem < 0 then assitItem = bot:FindItemSlot("item_wraith_band") end
if assitItem >= 0
and wand >= 6
and wand <= 8
then
slotToSell = assitItem
end
end

if slotToSell ~= nil
then
bot:ActionImmediate_SellItem(bot:GetItemInSlot(slotToSell))
return
end

fullInvCheck = currentTime
end

if bot:DistanceFromSecretShop() == 0
then
bot:Action_MoveToLocation(preferedShop + RandomVector(200))
Expand All @@ -90,23 +157,26 @@ function Think()
bot:Action_MoveToLocation(preferedShop + RandomVector(20));
return;
end
end

function X.GetEmptyInventoryAmount( bot )

local amount = 0
for i = 0, 8
do
local item = bot:GetItemInSlot( i )
if item == nil
then
amount = amount + 1
end
end

return amount

end

--这些是AI会主动走到商店出售的物品
function X.HaveItemToSell()
local earlyGameItem = {
"item_clarity",
"item_faerie_fire",
"item_tango",
"item_flask",
-- "item_orb_of_venom",
"item_bracer",
"item_wraith_band",
"item_null_talisman",
"item_infused_raindrop",
"item_bottle",
}
for _, item in pairs(earlyGameItem) do
local slot = bot:FindItemSlot(item)
if slot >= 0 and slot <= 8 then
Expand Down

0 comments on commit 59fe042

Please sign in to comment.