local this = class("heroEntity", require(L_EcsConst.aliveType.default))

function this:ctor(...)
  this.super.ctor(self, ...)
  self.fsmComponent = self:addComponent(L_EcsConst.componentType.fsm)
  self.animatorComponent = self:addComponent(L_EcsConst.componentType.animator)
  self.stateComponent = self:addComponent(L_EcsConst.componentType.state)
  self.voiceComponent = self:addComponent(L_EcsConst.componentType.voice)
  self.lookAtIKComponent = self:addComponent(L_EcsConst.componentType.lookAtIK)
  self.modelControlComponent = self:addComponent(L_EcsConst.componentType.modelControl)
end

function this:initialize(heroData)
  this.super.initialize(self, heroData)
  local biologyData = self.modelControl:GetComponentByType(typeof(C_BiologyData))
  if biologyData then
    biologyData.priority = 99
  end
  self.voiceComponent:initialize(self:getConfigId())
end

function this:activeTrans(...)
  this.super.activeTrans(self, ...)
  self:callAllComponent(L_EcsConst.triggerName.onSetActive)
end

function this:reset()
  self.stateComponent:reset()
  self.fsmComponent:reset()
end

function this:getGuid()
  return self.entityData.id
end

function this:getId()
  return self.entityData.id
end

function this:getConfigId()
  return self.entityData:getConfigId()
end

function this:getUnitId()
  local id = self.entityData:getConfigId()
  local unitId = L_GameUtil.getUnitIdByRole(id)
  return unitId
end

function this:getEntityName()
  local heroTpl = L_GameTpl.getHeroTpl()
  local tpl = heroTpl:getTplById(self:getId())
  local name = heroTpl:getName(tpl)
  return name
end

function this:getBelongId()
  return self.entityData.belongId
end

function this:getPetData()
  return self.entityData:getPetData()
end

function this:getHp()
  return self.csEntity.data.aliveProperty.luaHp
end

function this:getSp()
  return self.csEntity.data.aliveProperty.luaSp
end

function this:transfer(pos, rot)
  self:reset()
  self:putIn(pos, rot)
end

function this:setPlayerUnit(playerUnit)
  self.playerUnit = playerUnit
end

function this:getPlayerUnit()
  return self.playerUnit
end

function this:showOrHideHero(b)
  self.csEntity.data.controlProperty:SetShow(b)
  self.csEntity:Transmit(CS.Lens.Gameplay.Modules.BigWorld.ETransmitType.ChangeModelActiveState)
end

function this:playVoice(cvType, index)
  self:getVoiceComponent(true):playVoice(cvType, index)
end

function this:getTarget()
  return self.target or nil
end

function this:bindTarget(targetEntity)
  self.target = targetEntity
end

function this:onComponent_rangeChanged(isIn)
end

return this
