Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor issues in purchasing and courier #122

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions util/ItemPurchaseSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local TeamItemThink = require(GetScriptDirectory() .. "/util/TeamItemThink")
local A = require(GetScriptDirectory() .. "/util/MiraDota")
local fullInvCheck = -90
local MAX_INVENTORY_SLOT = 8
local STASH_SLOT_COUNT = 6

function M.SellExtraItem(ItemsToBuy)
local npcBot = GetBot()
Expand Down Expand Up @@ -586,7 +587,8 @@ local UseCourier = function()
end
local nearSecretShop = courier:DistanceFromSecretShop() <= 180
local function IsWaitingAtSecretShop()
return courierState == COURIER_STATE_IDLE and nearSecretShop and npcBot:GetGold() >= GetItemCost(sNextItem) * 0.9
return courierState == COURIER_STATE_IDLE and nearSecretShop and
npcBot:GetGold() >= GetItemCost(sNextItem) * 0.9 and IsItemPurchasedFromSecretShop(sNextItem)
end

if courier.returnWhenCarryingTooMany then
Expand All @@ -604,6 +606,7 @@ local UseCourier = function()
npcBot:ActionImmediate_Courier(courier, COURIER_ACTION_RETURN)
return
end

if AbilityExtensions:GetEmptyItemSlots(npcBot) == 0 and courierItemNumber > 0 and
GetUnitToUnitDistance(npcBot, courier) <= 400 then
courier.returnCarryNumber = courierItemNumber
Expand All @@ -628,14 +631,11 @@ local UseCourier = function()
npcBot:ActionImmediate_Courier(courier, COURIER_ACTION_SECRET_SHOP)
return
end
if nearSecretShop and npcBot:GetGold() >= GetItemCost(sNextItem) then
npcBot:ActionImmediate_PurchaseItem(sNextItem)
return
end
end
end
UseCourier = AbilityExtensions:EveryManySeconds(0.5, UseCourier)
M.ItemPurchaseExtend = function(self, ItemsToBuy)

M.ItemPurchaseSelf = function(self, ItemsToBuy)
local function GetTopItemToBuy()
local itemInformationTable = GetBot().itemInformationTable
if #itemInformationTable == 0 then
Expand Down Expand Up @@ -689,6 +689,7 @@ M.ItemPurchaseExtend = function(self, ItemsToBuy)

if #GetBot().itemInformationTable == 0 then
npcBot:SetNextItemPurchaseValue(0)
sNextItem="Out_of_items"
return
end
sNextItem = GetTopItemToBuy()
Expand Down Expand Up @@ -719,7 +720,8 @@ M.ItemPurchaseExtend = function(self, ItemsToBuy)
if courier:DistanceFromSecretShop() <= 250 and ItemCount < 9 then
PurchaseResult = courier:ActionImmediate_PurchaseItem(sNextItem)
end
else
elseif #AbilityExtensions:GetStashItems(npcBot) < STASH_SLOT_COUNT then
-- Buying at fountain
PurchaseResult = npcBot:ActionImmediate_PurchaseItem(sNextItem)
end
if PurchaseResult == PURCHASE_ITEM_SUCCESS then
Expand Down Expand Up @@ -748,8 +750,13 @@ M.ItemPurchaseExtend = function(self, ItemsToBuy)
else
npcBot.secretShopMode = false
end
end

M.ItemPurchaseExtend = function(self, ItemsToBuy)
M.ItemPurchaseSelf(ItemsToBuy)
UseCourier()
end

M.RemoveItemPurchase = function(self, itemTable, itemName)
local num = #itemTable
local i = 1
Expand Down