require( 'timer' )
if GameMode == nil then
_G.GameMode = class({})
end
GameMode.current_units = {}
GameMode.line_interval = {}
GameMode.wave_number = 0
GameMode.wave_list = {
[1]={reward_gold=1000,reward_exp=500,
units={["npc_dota_creep_goodguys_melee_upgraded_mega"]=6}},
[2]={reward_gold=5000,reward_exp=1000,
units={["npc_dota_hero_slardar"]=2}},
-- [3]={reward_gold=1000,reward_exp=2000,
-- units={"npc_line_boss_1",["npc_line_creep_4"]=2}},
}
function Precache( context )
--[[
Precache things we know we'll use. Possible file types include (but not limited to):
PrecacheResource( "model", "*.vmdl", context )
PrecacheResource( "soundfile", "*.vsndevts", context )
PrecacheResource( "particle", "*.vpcf", context )
PrecacheResource( "particle_folder", "particles/folder", context )
]]
end
-- Create the game mode when we activate
function Activate()
GameRules.AddonTemplate = GameMode()
GameRules.AddonTemplate:InitGameMode()
end
function GameMode:InitGameMode()
print( "Template addon is loaded. GameMode:InitGameMode()" )
ListenToGameEvent('game_rules_state_change', Dynamic_Wrap(self, 'OnGameRulesStateChange'), self)
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 2 )
ListenToGameEvent('entity_killed', Dynamic_Wrap(self, 'OnEntityKilled'), self)
end
function GameMode:OnGameRulesStateChange()
local newState = GameRules:State_Get()
print("State "..newState)
GameRules:SendCustomMessage("#State "..newState,0,0)
if newState == 7 then
print("SPAAAAAAAAAAAAAAAAAAWWN ")
GameMode:LineBossSpawner()
end
-- if newState == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
-- GameMode:LineBossSpawner()
-- end
end
function GameMode:LineBossSpawner()
self.wave_number = self.wave_number + 1
local current_boss = self.wave_list[self.wave_number]
--if current_boss == nil then
-- GameRules:SetGameWinner(DOTA_TEAM_GOODGUYS)
-- return
--end
GameMode:SpawnLineUnits(self.wave_number)
end
function GameMode:SpawnLineUnits(index)
local current_wave = self.wave_list[index]
local flag = 1;
if current_wave == nil then
print( "Array of wawes index out of range")
return
end
local point = Entities:FindByName( nil, "z1"):GetAbsOrigin()
-- local POINTS = class({})
-- for i=0,10 do
-- -- POINTS.vectors[i]= Vector(RandomInt(-2000,2000),RandomInt(-2000,2000),RandomInt(0,0))
-- -- POINTS[i] = Entities:CreateByClassname ("path_corner"):SetAbsOrigin(Vector(RandomInt(-2000,2000),RandomInt(-2000,2000),RandomInt(0,0)))
-- -- print (POINTS[i]:GetAbsOrigin())
-- print ("i = "..i)
-- end
local v = Vector(RandomInt(-2000,2000),RandomInt(-2000,2000),RandomInt(0,0))
local v2 = Entities:CreateByClassname ("path_corner")
v2:SetAbsOrigin(v)
print (v2:GetAbsOrigin())
local waypoint = v2 --Entities:FindByName( nil, "p1")
local units = current_wave.units
for key, value in pairs (units) do
if type(key) == "string" then
unit_count = value
unit_name = key
else
unit_count =1
unit_name = value
end
-- print ("self.current_units[ent_index]")
for i=1, unit_count do
local unit = CreateUnitByName( unit_name , point + RandomVector( RandomFloat( 0, 200 ) ), true, nil, nil, DOTA_TEAM_BADGUYS )
unit:SetInitialGoalEntity( waypoint )
unit:MoveToPosition( v )
unit.reward = true
local ent_index = unit:entindex()
-- table.insert(self.current_units, ent_index, unit)
self.current_units[ent_index]= unit
-- local q1 = self.current_units[ent_index]:GetUnitName();
-- print ("index "..ent_index)
-- print (self.current_units[ent_index])
-- print ( q1)
end
end
-- тута будет какоенить умное зацикливание
Timers:CreateTimer(15, function()
GameRules:SendCustomMessage("#kanec ",0,0)
local r = Vector(RandomInt(-2000,2000),RandomInt(-2000,2000),RandomInt(0,0))
local r2 = Entities:CreateByClassname ("path_corner")
r2:SetAbsOrigin(r)
print (r2:GetAbsOrigin())
local XX = FindUnitsInRadius(DOTA_TEAM_BADGUYS,v2:GetAbsOrigin(), nil, 350, DOTA_UNIT_TARGET_TEAM_FRIENDLY, DOTA_UNIT_TARGET_BASIC, 0, 0, false )
if XX ~= nil then
v2:Destroy()
for k, unit in pairs(XX) do
unit:SetInitialGoalEntity( r2 )
-- unit:Stop()
-- unit:MoveToPosition( r )
print ("unit name = "..unit:GetUnitName())
end
end
GameRules:SendCustomMessage("#kanec2 ",0,0)
end)
end
-- Evaluate the state of the game
function GameMode:OnThink()
if GameRules:State_Get() == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
--print( "Template addon script is running." )
elseif GameRules:State_Get() >= DOTA_GAMERULES_STATE_POST_GAME then
return nil
end
return 1
end
function GameMode:OnEntityKilled(keys)
local unit = EntIndexToHScript(keys.entindex_killed)
local unit_name = unit:GetUnitName()
if unit_name == "npc_goodguys_fort" then
GameRules:SetGameWinner(DOTA_TEAM_BADGUYS)
end
if unit.reward then
local ent_index = unit:entindex()
self.current_units[ent_index] = nil
local units = 0
for key,value in pairs(self.current_units) do
units = units + 1
end
if units == 0 then
local current_wave = self.wave_list[self.wave_number]
local reward_gold = current_wave.reward_gold
local reward_exp = current_wave.reward_exp
GiveGoldPlayers( reward_gold )
GiveExperiencePlayers( reward_exp )
GameMode:LineBossSpawner()
end
end
end
function GiveGoldPlayers( gold )
for index=0 ,4 do
if PlayerResource:HasSelectedHero(index) then
local player = PlayerResource:GetPlayer(index)
local hero = PlayerResource:GetSelectedHeroEntity(index)
hero:ModifyGold(gold, false, 0)
SendOverheadEventMessage( player, OVERHEAD_ALERT_GOLD, hero, gold, nil )
end
end
end
function GiveExperiencePlayers( experience )
for index=0 ,4 do
if PlayerResource:HasSelectedHero(index) then
local player = PlayerResource:GetPlayer(index)
local hero = PlayerResource:GetSelectedHeroEntity(index)
hero:AddExperience(experience, 0, false, true )
end
end
end