local this = class("heroTpl")

function this:init(config)
  self.data = config
end

function this:getTplById(id)
  if self.data[id] == nil then
    if id == nil then
      errorf("heroTpl  is Null \233\133\141\231\189\174\228\184\141\231\172\166\229\144\136\228\188\160\229\128\188\228\184\186\231\169\186")
    else
      errorf("heroTpl  is Null \233\133\141\231\189\174\228\184\141\231\172\166\229\144\136 id" .. id)
    end
  end
  return self.data[id]
end

function this:getBackupSkillList(tpl)
  return tpl.backupSkillList
end

function this:getBaseAttributeId(tpl)
  return tpl.baseAttributeId
end

function this:getNations(tpl)
  return tpl.groups
end

function this:getFormationGap(tpl)
  return tpl.formationGap
end

function this:getFormationId(tpl)
  return tpl.formationId
end

function this:getCounterAttackRange(tpl)
  return tpl.counterAttackRange
end

function this:getPassiveSkillList(tpl)
  return tpl.passiveSkillList
end

function this:getId(tpl)
  return tpl.id
end

function this:getBattleWidth(tpl)
  return tpl.battleWidth
end

function this:getIsStopPlayer(tpl)
  return tpl.isStopPlayer
end

function this:getAttackRange(tpl)
  return tpl.attackRange
end

function this:getWeaponType(tpl)
  return tpl.weaponType
end

function this:getFormationWidth(tpl)
  return tpl.formationWidth
end

function this:getUnitId(tpl)
  return tpl.unitId
end

function this:getRarity(tpl)
  return tpl.rarity
end

function this:getStrategyPreference(tpl)
  return tpl.strategyPreference
end

function this:getAttackSkill(tpl)
  return tpl.attackSkill
end

function this:getBehavior(tpl)
  return tpl.behavior
end

function this:getSkillSystem(tpl)
  return tpl.skillSystem
end

function this:getSkillIndex(tpl, skillId)
  local skill = self:getSkillSystem(tpl)
  for i, v in ipairs(skill) do
    if skillId == v then
      return i - 1
    end
  end
end

function this:getPosition(tpl)
  return tpl.position
end

function this:getElement(tpl)
  return tpl.element
end

function this:getBehaviorFormation(tpl)
  return tpl.behaviorFormation
end

function this:getDec(tpl)
  return L_Config:provider(tpl.dec)
end

function this:getSkillList(tpl)
  return tpl.skillList
end

function this:getSkillBytesPath(tpl)
  return tpl.skillBytesPath
end

function this:getChaos(tpl)
  return tpl.chaos
end

function this:getName(tpl)
  return L_Config:provider(tpl.name)
end

function this:getFavor(tpl)
  return tpl.favor
end

function this:getMorale(tpl)
  return tpl.morale
end

function this:getWeaponDefault(tpl)
  return tpl.weaponDefault
end

function this:getLevelUpType(tpl)
  return tpl.levelUpType
end

function this:getFormationTraceRange(tpl)
  return tpl.formationTraceRange
end

function this:getCost(tpl)
  return tpl.cost
end

function this:getPropertyId(tpl)
  return tpl.propertyId
end

function this:getLifeskillDesc(tpl)
  return L_Config:provider(tpl.lifeskillDesc)
end

function this:getModelPath(tpl, index)
  local unitTpl = L_GameTpl:getUnitTpl()
  tpl = unitTpl:getTplById(tpl.unitId)
  return unitTpl:getModel(tpl, index)
end

function this:getUnitModelPath(tpl)
  return self:getModelPath(tpl, L_Const.avatarModelIndex.UnitModel)
end

function this:getAnimatorConfigPath(tpl, index)
  local unitTpl = L_GameTpl:getUnitTpl()
  tpl = unitTpl:getTplById(tpl.unitId)
  return unitTpl:getAnimatorConfig(tpl)
end

function this:getHeroConfigAtt(heroId, heroLevel, heroRank)
  local unitPropertyTpl = L_GameTpl:getUnitPropertyTpl()
  local templateHeroTpl = L_GameTpl:getTemplateHeroTpl()
  local templateValueTpl = L_GameTpl:getTemplateValueTpl()
  local propertyId = self:getPropertyId(self:getTplById(heroId))
  local heroAttId = unitPropertyTpl:getBaseAttributeId(unitPropertyTpl:getTplById(propertyId))
  local heroBaseAttId = templateHeroTpl:getBaseAttributeByRankAndLevel(heroRank, heroLevel)
  local baseValue = templateValueTpl:getBaseAttribute(templateValueTpl:getTplById(heroBaseAttId))
  local factorValue = templateValueTpl:getBaseAttribute(templateValueTpl:getTplById(heroAttId))
  local newValue = {}
  local factorIndex = {
    [L_Const.battleAtt.ATK] = 10000,
    [L_Const.battleAtt.DEF] = 10000,
    [L_Const.battleAtt.MDEF] = 10000,
    [L_Const.battleAtt.MAXHP] = 10000,
    [L_Const.battleAtt.WEEKNESS_VALUE] = 10000
  }
  for i, v in pairs(baseValue) do
    if factorValue[i] then
      if factorIndex[i] then
        newValue[i] = math.integrate(v * factorValue[i] / factorIndex[i])
      else
        newValue[i] = math.integrate(v * factorValue[i])
      end
    end
  end
  return newValue
end

function this:getVoice(tpl)
  return tpl.voice
end

function this:getIsUsable(tpl)
  return tpl.isUsable == 1
end

function this:getAvatarTexture(tpl, index)
  if tpl == nil then
    return
  end
  return tpl.avatarTexture[index]
end

function this:getMainElementld(tpl)
  return tpl.mainElementld
end

function this:getAerialSkillList(tpl)
  return tpl.aerialSkillList
end

function this:getFavor(tpl)
  return tpl.favor
end

function this:getEnglishName(tpl)
  return tpl.englishName
end

function this:getKiBoDuelHeroPrepareTransOffset(tpl)
  if not tpl.kiboDuelInfo or not tpl.kiboDuelInfo[1] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelInfo[1][1] or 0, tpl.kiboDuelInfo[1][2] or 0, tpl.kiboDuelInfo[1][3] or 0)
end

function this:getKiBoDuelHeroPrepareTransEuler(tpl)
  if not tpl.kiboDuelInfo or not tpl.kiboDuelInfo[2] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelInfo[2][1] or 0, tpl.kiboDuelInfo[2][2] or 0, tpl.kiboDuelInfo[2][3] or 0)
end

function this:getKiBoDuelHeroPrepareTransScale(tpl)
  if not tpl.kiboDuelInfo or not tpl.kiboDuelInfo[3] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelInfo[3][1] or 0, tpl.kiboDuelInfo[3][2] or 0, tpl.kiboDuelInfo[3][3] or 0)
end

function this:getKiBoDuelFormationHeroTransOffset(tpl)
  if not tpl.kiboDuelFormation or not tpl.kiboDuelFormation[1] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelFormation[1][1] or 0, tpl.kiboDuelFormation[1][2] or 0, tpl.kiboDuelFormation[1][3] or 0)
end

function this:getKiBoDuelFormationHeroTransEuler(tpl)
  if not tpl.kiboDuelFormation or not tpl.kiboDuelFormation[2] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelFormation[2][1] or 0, tpl.kiboDuelFormation[2][2] or 0, tpl.kiboDuelFormation[2][3] or 0)
end

function this:getKiBoDuelFormationHeroTransScale(tpl)
  if not tpl.kiboDuelFormation or not tpl.kiboDuelFormation[3] then
    return C_Vector3(0, 0, 0)
  end
  return C_Vector3(tpl.kiboDuelFormation[3][1] or 0, tpl.kiboDuelFormation[3][2] or 0, tpl.kiboDuelFormation[3][3] or 0)
end

function this:getBattleTag(tpl)
  return tpl.battleTag
end

function this:getFishAction(tpl)
  return tpl.fishAction
end

function this:getFishHero(curMainControlHero)
  local configId = L_HeroStore:getHeroConfigId(L_HeroStore:getHero(curMainControlHero))
  local tpl_hero = self:getTplById(configId)
  if tpl_hero.fishAction == L_FishingConst.HeroFishSize.None then
    tpl_hero = self:getTplById(L_GameUtil.getDefaultHeroId())
  end
  return tpl_hero.id, tpl_hero.fishAction
end

function this:getUIChargingParam(tpl)
  return tpl.uiChargingParam
end

function this:getLevelUpParam(tpl)
  local p = tpl.levelUpParam
  return {
    x = p[1],
    y = p[2],
    z = p[3]
  }
end

function this:getPathByHash(heroId)
  local tpl = self:getTplById(heroId)
  return L_Config:getPathByHash(tpl.uiperform)
end

return this
