package PlayerData import UnitData import StatHandler import initlater Bag import HeroType import TalentList import initlater PQuest import QuestProvingYourWorth public function xGetPlayerHero(int playerId) returns unit if playerData[playerId] == null return null return playerData[playerId].hero public function xGetPlayerData(int playerId) returns PlayerData return playerData[playerId] PlayerData array playerData function createHero(player p, HeroType heroType, vec2 pos) returns unit unit hero = createUnit(p, heroType.getRaw(), pos, angle(0.)) switch heroType case WARRIOR hero..addAbility(BOOK_TALENT_WARRIOR) case PRIEST hero..addAbility(BOOK_TALENT_PRIEST) case RANGER hero..addAbility(BOOK_TALENT_RANGER) case DRUID hero..addAbility(BOOK_TALENT_DRUID) SetCameraPositionForPlayer(p, pos.x, pos.y) SelectUnitForPlayerSingle(hero, p) return hero /** Represents the players data and his hero. * Simply create a new object of this class to create a new player/hero. * Destroy the object to remove the hero and reset the player data. * Creating a new object will automatically remove the old hero and reset the data. */ public class PlayerData private int playerId protected unit hero // learn points: private int learnPointsStats private int learnPointsTalents // learned stats: private StatList learnedStats private int learnedStr private int learnedAgi private int learnedInt construct(int playerId, HeroType heroType, vec2 heroSpawnPos) if playerData[playerId] != null destroy playerData[playerId] playerData[playerId] = this // must be first, for xIsHero(..) check this.playerId = playerId this.hero = createHero(Player(playerId), heroType, heroSpawnPos) new UnitData(hero) // Create a bag: playerCreateBag(playerId) // Set first quest discoverable: pqProveWorth.setDiscoverable(playerId, udg_npc_bryce) // learn points: learnPointsStats = 0 learnPointsTalents = 0 players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_USED, learnPointsStats) players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_CAP, learnPointsTalents) // learned attributes: learnedStats = new StatList() learnedStr = 0 learnedAgi = 0 learnedInt = 0 hero.xGetUnitData().unitStatBuffer.apply(learnedStats) Player(playerId).setState(PLAYER_STATE_RESOURCE_GOLD, 0) function getLearnPointsStats() returns int return learnPointsStats function setLearnPointsStats(int newValue) learnPointsStats = newValue players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_USED, learnPointsStats) function incLearnPointsStats(int add) learnPointsStats += add players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_USED, learnPointsStats) function getLearnPointsTalents() returns int return learnPointsTalents function setLearnPointsTalents(int newValue) learnPointsTalents = newValue players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_CAP, learnPointsTalents) function incLearnPointsTalents(int add) learnPointsTalents += add players[playerId].setState(PLAYER_STATE_RESOURCE_FOOD_CAP, learnPointsTalents) function getLearnedAttributeStr() returns int return learnedStr function getLearnedAttributeAgi() returns int return learnedAgi function getLearnedAttributeInt() returns int return learnedInt function setLearnedAttributes(int str, int agi, int inte) learnedStr = str learnedAgi = agi learnedInt = inte hero.xGetUnitData().unitStatBuffer.remove(learnedStats) destroy learnedStats learnedStats = new StatList() learnedStats.add(Stat.STRE, learnedStr) learnedStats.add(Stat.AGIL, learnedAgi) learnedStats.add(Stat.INTE, learnedInt) learnedStats.add(Stat.STRW, learnedStr) learnedStats.add(Stat.AGIW, learnedAgi) learnedStats.add(Stat.INTW, learnedInt) hero.xGetUnitData().unitStatBuffer.apply(learnedStats) function incLearnedAttributes(int str, int agi, int inte) learnedStr += str learnedAgi += agi learnedInt += inte hero.xGetUnitData().unitStatBuffer.remove(learnedStats) destroy learnedStats learnedStats = new StatList() learnedStats.add(Stat.STRE, learnedStr) learnedStats.add(Stat.AGIL, learnedAgi) learnedStats.add(Stat.INTE, learnedInt) learnedStats.add(Stat.STRW, learnedStr) learnedStats.add(Stat.AGIW, learnedAgi) learnedStats.add(Stat.INTW, learnedInt) hero.xGetUnitData().unitStatBuffer.apply(learnedStats) ondestroy destroy learnedStats destroy hero.xGetUnitData() hero.remove() playerRemoveBag(playerId) PQuest.resetAllQuests(playerId) playerData[playerId] = null