Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1. require("timers")
  2.  
  3. if TowerWarsGameRound == nil then
  4.     TowerWarsGameRound = class({})
  5. end
  6.  
  7. ListenToGameEvent("entity_killed", Dynamic_Wrap(TowerWarsGameRound, "OnEntityKilled"), self)
  8.  
  9. --[[
  10.     TowerWarsGameRound - A single round of Tower Wars fichier TowerWarsGameRound.lua ne pas oublier le require
  11. ]]
  12.  
  13.  
  14. function TowerWarsGameRound:ReadConfiguration( kv, gameMode, roundNumber )
  15.     print(kv)
  16.     print("quest title",kv.round_quest_title)
  17.     print("titre:",kv.round_title)
  18.     print("maxunit",kv.round_maxUnit)
  19.     self._gameMode = gameMode
  20.     self._nRoundNumber = roundNumber
  21.     self._szRoundQuestTitle = kv.round_quest_title
  22.     self._szRoundTitle = kv.round_title
  23.     self._maxUnit = tonumber(kv.round_maxUnit) or 9001
  24.  
  25. --[[ Tableaux nécéssaire car le round contient plusieurs vagues]]
  26.     self._npc = {}
  27.     self._numberToSpawn = {}
  28.   self._nextWaveIn = {}
  29.  
  30.  
  31. --[[Tableaux des loots du round ainsi que chance de drop de la vague]]
  32.  
  33.   self._dropRate = kv.DropRate
  34.   self._loots = {}
  35.  
  36.  
  37.  
  38.     for k, v in pairs( kv ) do
  39.       print(k)
  40.       if type(v) == "table" and k == "ItemDrops" then -- si la valeur est une table et que c'est la table des loots k vaut exactement "ItemDrops" ici
  41.         print("le parseur marche-t-il?")
  42.         for _,loot in pairs (v) do -- on itere dans la table des loots
  43.             self._loots[loot.ItemName] = loot.Chance
  44.         end
  45.  
  46.         elseif type( v ) == "table"  then--Si la valeur est une table et que c'est pas la table des loots, c'est que c'est la config des sous vagues, k vaudra string(1),string(2) etc
  47.         --obligé de mettre tonumber(k) sinon la clef c'est un string
  48.             self._npc[tonumber(k)] = v.NPCName
  49.            
  50.             self._numberToSpawn[tonumber(k)] = v.TotalUnitsToSpawn
  51.  
  52.         self._nextWaveIn[tonumber(k)] = v.NextWaveIn
  53.         print("k est un:",type(tonumber(k)))
  54.         end
  55.      
  56.     end
  57.  
  58. end
  59.  
  60.  
  61. -- Courtesy of ArthurAutomaton, this guy rocks!
  62. function TowerWarsGameRound:BeginRound()
  63.    SPAWNLOCATION_RADIANT = "path_customspawn_radiant"
  64.    SPAWNLOCATION_DIRE = "path_customspawn_dire"
  65.    WAYPOINTNAME_RADIANT = "path_radiant_wp1"
  66.    WAYPOINTNAME_DIRE = "path_dire_wp1"
  67.    
  68.    local spawnLocationRadiant = Entities:FindByName( nil, SPAWNLOCATION_RADIANT )
  69.    local waypointlocationRadiant = Entities:FindByName ( nil, WAYPOINTNAME_RADIANT)
  70.    local spawnLocationDire = Entities:FindByName( nil, SPAWNLOCATION_DIRE )
  71.    local waypointlocationDire = Entities:FindByName ( nil, WAYPOINTNAME_DIRE)
  72.    local creature
  73.  
  74.    local waveNumber = 1
  75.    print("Spawning round number:", self._nRoundNumber)
  76.   print("Taux de drop:", tonumber(self._dropRate))
  77.    Timers:CreateTimer(function()            -- on se sert du timer pour spawn toutes les vagues apres le delai spécifié dans le fichier de configuration
  78.          local numberToSpawn = self._numberToSpawn[waveNumber]
  79.          local unitToSpawn = self._npc[waveNumber]
  80.          if numberToSpawn == nil or unitToSpawn == nil then
  81.             print("Spawned all units for round:", self._nRoundNumber)
  82.             return
  83.          end
  84.          for i = 1, numberToSpawn do -- on spawn toute la sous vague
  85.             creature = CreateUnitByName( unitToSpawn , spawnLocationRadiant:GetAbsOrigin() + RandomVector( RandomFloat( 0, 200 ) ), true, nil, nil, DOTA_TEAM_BADGUYS )
  86.             creature:SetInitialGoalEntity( waypointlocationRadiant )
  87.            
  88.                   creature = CreateUnitByName( unitToSpawn , spawnLocationDire:GetAbsOrigin() + RandomVector( RandomFloat( 0, 200 ) ), true, nil, nil, DOTA_TEAM_GOODGUYS )
  89.             creature:SetInitialGoalEntity( waypointlocationDire )
  90.  
  91.             print("Spawning wave number:" , waveNumber, "Creature:", unitToSpawn)
  92.          end
  93.          waveNumber = waveNumber + 1 -- on incremente la vague, comme ça lors du prochain appel on spawn la vague suivante
  94.          return self._nextWaveIn[waveNumber - 1] -- -1 car sinon c'est le temps de la vague d'apres !
  95.    end)
  96. end
  97.  
  98.  
  99.  
  100. --[[
  101.  
  102. function TowerWarsGameRound:ShowTimerRound(texte,duree)
  103.   local duree = duration
  104.       Timers:CreateTimer(function()
  105.         if _duree == -1 then
  106.           self.BeginRound()
  107.             return
  108.         end
  109.           _duree = _duree - 1
  110.           towerWars:_vRounds[round]:BeginRound()
  111.           FireGameEvent("towerWars_show_generic_timer", {text = texte, countdown = _duree})
  112.           FireGameEvent("towerWars_show_generic_timer", {text = texte, countdown = _duree})
  113.           return 1.0
  114.         end
  115.       )
  116.  
  117. end
  118. ]]
  119. function TowerWarsGameRound:BeginRoundLater(delay)
  120.       local _duree = tonumber(delay)
  121.       titre = "Starting Round #" .. self._nRoundNumber .. ":"
  122.       Timers:CreateTimer(function()
  123.            if _duree == -1 then
  124.                FireGameEvent("towerWars_hide_timer",{})
  125.                self:BeginRound()
  126.                  return
  127.               end
  128.  
  129.           FireGameEvent("towerWars_show_generic_timer", {text = titre, countdown = tostring(_duree)})
  130.           FireGameEvent("towerWars_show_generic_timer", {text = titre, countdown = tostring(_duree)})
  131.           _duree = _duree - 1
  132.           return 1.0
  133.         end
  134.        )
  135.  
  136.  
  137.  
  138. end
  139.  
  140.  
  141. function TowerWarsGameRound:SetUpLoots()
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. end
  149.  
  150.  
  151. function TowerWarsGameRound:OnEntityKilled(entity)
  152.    --[[ for k,v in pairs(entity) do
  153.         print(k,v)
  154.  
  155.     end]]
  156.     print("mais wtf")
  157.  
  158.  
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement