Skip to content

fix: remove shop and spawn heros in formation of circle #20

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

Merged
merged 6 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ All other information should be explored by reading the source code!
- [liangjs](https://github.com/liangjs)
- [kdxcxs](https://github.com/kdxcxs)
- [xljkqq](https://github.com/xljkqq)

## Changelog

- [2023/3/21 21:13] fix: remove shop and spawn heros as a circle.([#20](https://github.com/Escapingbug/dotaxctf/pull/20))
11 changes: 1 addition & 10 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,14 @@ function Config:Init()
self.candidates_per_team = 0

self.round_time = 5 * 60
self.hero_locations = {}
self.hero_locations_radius = 600

self.total_rounds_count = 60 -- 5 hours in total, 5 minutes per round

for i = 0, 15 do
self.hero_locations[i + 1] = Vector((i % 4) * 200 - 400, math.floor(i / 4) * 200 - 400)
end

-- how many seconds to wait after choosing hero
-- and action
self.round_begin_delay = 3

self.shop = {
location = Vector(0, 0),
radius = 1e6,
}

end

if not Config.config_inited then Config:Init() end
Expand Down
28 changes: 11 additions & 17 deletions rounds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ require("lib/base64")
require("lib/json")

AVAILABLE_TEAMS = {
DOTA_TEAM_GOODGUYS,
DOTA_TEAM_BADGUYS,
DOTA_TEAM_CUSTOM_1,
DOTA_TEAM_CUSTOM_2,
DOTA_TEAM_CUSTOM_3,
Expand Down Expand Up @@ -270,8 +268,6 @@ function Rounds:BeginGame()
Rounds:SetupBotPlayers()
Rounds:SetupLastHitListener()

Rounds:SetupShop()

Rounds:PrepareBeginRound()
self.game_started = true
-- all next rounds should be called on timer set by next round
Expand Down Expand Up @@ -326,6 +322,15 @@ function Rounds:ChooseHeros(chooser_scripts, attributes)
team_config = table.shuffle(team_config)
print("[xctf Rounds:ChooseHeros()]" .. "team config " .. GameRules.inspect(team_config))

local hero_locations = {}
for i = 1, Config.candidate_count do
hero_locations[i] = Vector(
math.cos(2 * math.pi * i / Config.candidate_count) * Config.hero_locations_radius,
math.sin(2 * math.pi * i / Config.candidate_count) * Config.hero_locations_radius
)
end

local cur_id = 1
for i = 1, Config.team_count do
local cur_candidates = {}
for _ = 1, Config.candidates_per_team do
Expand All @@ -334,7 +339,6 @@ function Rounds:ChooseHeros(chooser_scripts, attributes)

local cur_team_id = AVAILABLE_TEAMS[i]

local cur_id = 1
for _, candidate_id in ipairs(cur_candidates) do
local chooser = Sandbox:LoadChooseHeroScript(chooser_scripts[candidate_id])
local hero_name = Sandbox:RunChooseHero(chooser)
Expand All @@ -343,7 +347,7 @@ function Rounds:ChooseHeros(chooser_scripts, attributes)
print("[xctf Rounds:ChooseHeros()]" .. "player owner: " .. tostring(player_owner) .. "team id " .. tostring(cur_team_id))
local candidate_hero = CreateUnitByName(
hero_name,
Config.hero_locations[cur_id],
hero_locations[cur_id],
true, -- findClearSpace
nil, -- npcowner
player_owner, -- entity owner
Expand Down Expand Up @@ -406,7 +410,7 @@ function Rounds:PrepareBeginRound()
attributes = attributes,
}
-- if total_rounds_count is odd, candidates will rest in turns
if Config.candidate_count % 2 ~= 0 then
if Config.candidate_count > 8 and Config.candidate_count % 2 ~= 0 then
RestTeamId = self.candidate_rest_order[(self.round_count - 1) % Config.candidate_count + 1]
end
Rounds:NextRound(scripts)
Expand Down Expand Up @@ -536,16 +540,6 @@ function Rounds:BeginRound(bot_scripts)
end
end

function Rounds:SetupShop()
local location = Config.shop.location
local shop = CreateUnitByName("dota_fountain", location, true, nil, nil, DOTA_TEAM_NEUTRALS)
shop:SetCanSellItems(true)
shop:SetIdleAcquire(false)
-- shop:SetShopType(DOTA_SHOP_HOME) -- not a shop
local trigger = SpawnDOTAShopTriggerRadiusApproximate(shop:GetAbsOrigin(), Config.shop.radius)
trigger:SetShopType(DOTA_SHOP_HOME)
end

if not Rounds.heros then Rounds:Init() end

Sandbox:SetupGameInfo{
Expand Down