local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    mapInfo = require(L_R.store .. "player.data.playerMapInfo").new(),
    baseInfo = require(L_R.store .. "player.data.playerBaseInfo").new(),
    attrInfo = {},
    modAvatar = nil
  }
  self.expUpParam = {
    curLv = 0,
    curExp = 0,
    lastLv = 0,
    lastExp = 0,
    isLevelUp = false,
    isBlock = false
  }
end

function this:getPlayerInfo()
  return self.data
end

function this:getPlayerModHeadImgName()
  return self:getAvatarTexturePath(L_Const.avatarTextureIndex.head)
end

function this:getPlayerModHalfBodyName()
  return self:getAvatarTexturePath(L_Const.avatarTextureIndex.half_raffle)
end

function this:getAvatarTexturePath(index)
  local modData = self.data.modAvatar
  if modData == nil then
    return ""
  end
  if index == L_Const.avatarTextureIndex.painting then
    return modData.paintUrl
  elseif index == L_Const.avatarTextureIndex.half_raffle then
    return modData.halfBodyUrl
  elseif index == L_Const.avatarTextureIndex.half_formation then
    return modData.halfsHeadUrl
  elseif index == L_Const.avatarTextureIndex.head then
    return modData.headImgUrl
  elseif index == L_Const.avatarTextureIndex.head_circle then
    return modData.circleHeadUrl
  elseif index == L_Const.avatarTextureIndex.head_talk then
    return modData.battleHeadUrl
  elseif index == L_Const.avatarTextureIndex.body then
    return modData.bodyUrl
  end
  return ""
end

function this:getPlayerMapInfo()
  return self.data.mapInfo
end

function this:getPlayerMapPos()
  return self.data.mapInfo.position
end

function this:getPlayerMapRot()
  return self.data.mapInfo.rotation
end

function this:getPlayerMount()
  return self.data.mapInfo.mount
end

function this:playerInMountStatus()
  return self:getPlayerStatus() == L_Const.WorldMapPlayerStatusType.WMPST_MOUNT
end

function this:getPlayerStatus()
  return self.data.mapInfo.status
end

function this:getMountStatus()
  return self.data.mapInfo.mount_status
end

function this:getPlayerBaseInfo()
  return self.data.baseInfo
end

function this:getPlayerId()
  return self.data.baseInfo.id
end

function this:getPlayerZoneId()
  return self.data.baseInfo.zone_id
end

function this:getPlayerName()
  return self.data.baseInfo.name
end

function this:getAccount()
  return self.data.baseInfo.account
end

function this:getRegisterTime()
  return self.data.baseInfo.regtm
end

function this:getLv()
  local playerLevelTpl = L_GameTpl:getPlayerLevelTpl()
  local minLv = playerLevelTpl:getId(playerLevelTpl.data[1])
  local maxLv = playerLevelTpl:getId(playerLevelTpl.data[#playerLevelTpl.data])
  local curLv = math.clamp(self.data.baseInfo.lv, minLv, maxLv)
  return curLv, curLv == maxLv
end

function this:getGold()
  return self.data.baseInfo.gold
end

function this:getDiamond()
  return self.data.baseInfo.diamond
end

function this:getNaturel()
  return self.data.baseInfo.naturel
end

function this:getExp()
  return self.data.baseInfo.exp
end

function this:getSex()
  return self.data.baseInfo.sex
end

function this:getSign()
  return self.data.baseInfo.sign
end

function this:getDisplayHero()
  local hero = self.data.baseInfo.info.hero or {}
  local res = {}
  for i, v in pairs(hero) do
    res[v.pos] = v
  end
  return res
end

function this:getDisplayPet()
  return self.data.baseInfo.info.pet or {}
end

function this:getDisplayAchievement()
  local res = {
    0,
    0,
    0
  }
  if self.data.baseInfo.info == nil or self.data.baseInfo.info.achievement == nil then
    return res
  end
  for i, v in pairs(self.data.baseInfo.info.achievement) do
    res[i] = v
  end
  return res
end

function this:getPetLendBaseInfo()
  return self.data.baseInfo.lend_info
end

function this:getWardrobe()
  return self.data.baseInfo.wardrobe
end

function this:getPlayerTitle()
  return self:getPreTitle(), self:getLastTitle()
end

function this:getPreTitle()
  return self.data.baseInfo.preffix_title == 0 and 171000 or self.data.baseInfo.preffix_title
end

function this:getLaterTitle()
  return self.data.baseInfo.suffix_title == 0 and 172000 or self.data.baseInfo.suffix_title
end

function this:getBirthday()
  return self.data.baseInfo.birthday
end

function this:getLastChangeNameTime()
  return self.data.baseInfo.last_change_name_time
end

function this:getExpUpParam()
  return self.expUpParam
end

function this:getCurrency(currencyID, isCreate)
  if currencyID == L_Const.currencyType.accountExp then
    return {
      attr_id = currencyID,
      attr_val = self.data.baseInfo.exp
    }
  end
  local res = self.data.attrInfo[currencyID]
  if res == nil and isCreate then
    res = require(L_R.store .. "player.data.playerAttr").new()
    res.attr_id = currencyID
    self.data.attrInfo[currencyID] = res
  end
  return res
end

function this:getCurrencyNum(currencyID)
  local currency = self:getCurrency(currencyID)
  return currency and currency.attr_val or 0
end

return this
