package Heropick import HeropickObjectGen import Config import HeroType import PlayerData import ChatEvent import SpellList constant vec2 heroStartPos = vec2(-10250, 4390) unit ship unit array heroPicker // Hero picker unit for all players. /** Starts hero pick. Only call this function, if the old PlayerData has been destroyed before. */ public function startHeropick(player p) if isPicking(p) printWarning("startHeropick(..): hero is picking") return heroPicker[p.getId()] = createUnit(p, RAW_DUMMY_PICK, HERO_PICK_POS, angle(0.)) SetCameraPositionForPlayer(p, HERO_PICK_POS.x, HERO_PICK_POS.y) public function cancelHeropick(player p) if not isPicking(p) printWarning("cancelHeropick(..): hero is not picking") return heroPicker[p.getId()].remove() heroPicker[p.getId()] = null public function isPicking(player p) returns boolean return heroPicker[p.getId()] != null function repick(player p) if isPicking(p) print("You can only repick after you loaded or picked a hero!") else destroy xGetPlayerData(p.getId()) startHeropick(p) function heroPickedAction() let p = GetBuyingUnit().getOwner() let pid = p.getId() // Sanity check: if heroPicker[pid] == null printWarning("heroPickedAction(..): heroPicker[pid] == null") return if heroPicker[pid] != GetBuyingUnit() printWarning("heroPickedAction(..): heroPicker[pid] != GetBuyingUnit()") return // end sanity check. HeroType heroType = HeroType.WARRIOR // requires initialization switch GetSoldUnit().getTypeId() case RAW_DUMMY_WARRIOR heroType = HeroType.WARRIOR case RAW_DUMMY_PRIEST heroType = HeroType.PRIEST case RAW_DUMMY_RANGER heroType = HeroType.RANGER case RAW_DUMMY_DRUID heroType = HeroType.DRUID new PlayerData(pid, heroType, heroStartPos) let hero = xGetPlayerHero(pid) // Learn first 3 spells: playerHeroLearnSpell(pid, 1) playerHeroLearnSpell(pid, 2) playerHeroLearnSpell(pid, 3) printTimed(p.getName() + " picked: |cffffcc00" + hero.getName(), 4.) GetSoldUnit().remove() cancelHeropick(p) init ship = createUnit(Player(PLAYER_NEUTRAL_PASSIVE), RAW_SHIP, HERO_PICK_POS, angle(0.)) CreateTrigger() ..registerUnitEvent(ship, EVENT_UNIT_SELL) ..addAction(function heroPickedAction) getTimer().start(2, () -> begin for int pid = 0 to NUM_OF_PLAYERS-1 startHeropick(players[pid]) GetExpiredTimer().release() end) allPlayerChatEvent("-repick", true, () -> begin repick(GetTriggerPlayer()) end)