-
Notifications
You must be signed in to change notification settings - Fork 39
ItemPurchasing
To create item purchasing logic for a hero it is necessary to first create a file named item_purchase_HeroName.
In the newly created file both items.lua and item_purchase_generic_test.lua need to be integrated.
There are six tables that can be filled with different item purchase routes:
- ItemsToBuyAsHardCarry
- ItemsToBuyAsMid
- ItemsToBuyAsOfflane
- ItemsToBuyAsSupport
- ItemsToBuyAsJungler
- ItemsToBuyAsRoamer
Note that you do not have to provide a complete table for each role.
The roles are generated at the beginning of a match, so keep that in mind.
If Antimage only has a support path he might not buy any items!
Support items such as courier and wards are being bought automatically,
so there is no need to add that to the starting items (unless you want several couriers).
The last step is to fill the tables with life, you need to specifiy:
- Which items should be bought with starting gold or early into the game; StartingItems
- Which items are utility items, such as raindrops or flasks; UtilityItems
- Which items are absolute core, e.g. a battlefury on Antimage; CoreItems
- What items can be bought in the later stages of the game; ExtensionItems
Starting items will be bought first, then core and then extension items.
Utility items are being bought whenever available or necessary.
The purchase logic splits heroes into cores and supports,
supports will buy wards, courier upgradeds, dust etc. when needed / available.
Cores will not buy any of those items unless they are specified under utility items.
Extension items are divided into two seperate tables, OffensiveItems and DefensiveItems.
The bot will decide throughout the game which items he wants to buy depending on
the enemies and the state of the game. It is important to consider which items are
defensive and which ones are offensive, since that can vary on different the hero.
local ItemsToBuyAsHardCarry = {
..
ExtensionItems = {
{
"item_butterfly", -- Could be good but won't be bought if an enemy already has monkey king bar
..
}
{
"item_black_king_bar", -- Could probably be in offensive items on e.g. Sven!
..
}
}
}
Items that are not needed anymore will be sold, like poor man's shields or unneeded tangoes.
But don't worry: Items that are going to be used in more expensive items will not be sold!
It is possible to buy parts of an item and then the rest, e.g. buying RoH first on Antimage.
The purchase function detects if an item was already purchased and won't buy it a second time.
local ItemsToBuyAsHardCarry = {
..
CoreItems = {
"item_ring_of_health",
..
"item_bfury"
}
..
}
The item names have to be the ones stated in items.lua.
You can add single items (stout shield) or the "crafted" items (poor man's shield),
you do not have to add every single part of the item to your table.
local ItemsToBuyAsHardCarry = {
StartingItems = {
"item_stout_shield",
..
},
..
CoreItems = {
"item_poor_mans_shield",
..
}
..
}
The last thing to do is to create a new instance of the generic item purchase class,
then create an init function for that instance (second layer, otherwise there will be hereditary problems).
Create a new instance of that buy class and set the tables of that instance to our local versions of them.
The following code is an empty item purchase file which only
needs to be filled with the purchase paths and the name of the hero:
local item_purchase = require( GetScriptDirectory().."/item_purchase_generic_test" )
--[[
This is an example of how the tables have to be set up.
Copy the structure into any table you want to use (mid, offlane..)
You can look up the item strings in items.lua
--]]
local ItemsToBuyAsHardCarry = {
StartingItems = {
},
UtilityItems = {
},
CoreItems = {
},
ExtensionItems = {
{
},
{
}
}
}
local ItemsToBuyAsMid = {}
local ItemsToBuyAsOfflane = {}
local ItemsToBuyAsSupport = {}
local ItemsToBuyAsJungler = {}
local ItemsToBuyAsRoamer = {}
ToBuy = item_purchase:new()
function ToBuy:new(o)
o = o or item_purchase:new(o)
setmetatable(o, self)
self.__index = self
return o
end
local myPurchaseOrder = {}
local myBoughtItems = {}
local myStartingItems = {}
local myUtilityItems = {}
local myCoreItems = {}
local myExtensionItems = {
OffensiveItems = {},
DefensiveItems = {}
}
local Init = false
myBuy = ToBuy:new()
myBuy.PurchaseOrder = myPurchaseOrder
myBuy.BoughtItems = myBoughtItems
myBuy.StartingItems = myStartingItems
myBuy.UtilityItems = myUtilityItems
myBuy.CoreItems = myCoreItems
myBuy.ExtensionItems = myExtensionItems
myBuy.ItemsToBuyAsHardCarry = ItemsToBuyAsHardCarry
myBuy.ItemsToBuyAsMid = ItemsToBuyAsMid
myBuy.ItemsToBuyAsOfflane = ItemsToBuyAsOfflane
myBuy.ItemsToBuyAsSupport = ItemsToBuyAsSupport
myBuy.ItemsToBuyAsJungler = ItemsToBuyAsJungler
myBuy.ItemsToBuyAsRoamer = ItemsToBuyAsRoamer
function ItemPurchaseThink()
local npcBot = GetBot()
if not Init then
init = myBuy:InitTable()
end
myBuy:Think(npcBot)
end