Formula

CommonFun.calcBuff_3540

function CommonFun.calcBuff_3540(srcUser, targetUser, a, b, c, d, lv)
  local Str = srcUser:GetProperty("Str")
  local Dex = srcUser:GetProperty("Dex")
  local Luk = srcUser:GetProperty("Luk")
  local Atk = srcUser:GetProperty("Atk")
  local AtkPer = srcUser:GetProperty("AtkPer")
  local DamIncrease = srcUser:GetProperty("DamIncrease")
  local IgnoreDef = 0
  local IgnoreDef1 = srcUser:GetProperty("IgnoreDef")
  local IgnoreDef2 = srcUser:GetProperty("IgnoreEquipDef")
  if targetUser.boss or targetUser.mini then
    IgnoreDef = IgnoreDef1
  else
    IgnoreDef = IgnoreDef1 + IgnoreDef2
  end
  if 1 <= IgnoreDef then
    IgnoreDef = 1
  end
  local Refine = srcUser:GetProperty("Refine")
  local Def2 = targetUser:GetProperty("Def")
  local DefPer2 = targetUser:GetProperty("DefPer")
  local Vit2 = targetUser:GetProperty("Vit")
  local VitPer2 = targetUser:GetProperty("VitPer")
  local DamReduc2 = CommonFun.calcDamReDuc(srcUser, targetUser)
  local RefineDamReduc = targetUser:GetProperty("RefineDamReduc")
  local Hp2 = targetUser:GetProperty("Hp")
  local MaxHp2 = targetUser:GetProperty("MaxHp")
  lv = math.min(lv, 10)
  local damChangePer = 0.3 * lv + 3
  local damChangePer1 = 4 * lv
  local AttrEffect = srcUser:GetProperty("AttrEffect")
  local bits = CommonFun.getBits(AttrEffect)
  local raceparam = 1
  local srcRace = srcUser.race
  local targetRace = targetUser.race
  if srcUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) and srcUser:HasBuffID(49325_RACIAL_ANCIENT_RELICS_CD_:MAX_STACK_0) then
  elseif srcUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) then
    targetRace = 2
  end
  if targetUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) and targetUser:HasBuffID(49325_RACIAL_ANCIENT_RELICS_CD_:MAX_STACK_0) then
  elseif targetUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) then
    srcRace = 2
  end
  if nil == CommonFun.RaceProps[targetRace] then
    return 0
  end
  if nil == CommonFun.RaceProps[srcRace] then
    return 0
  end
  local raceInc = srcUser:GetProperty(CommonFun.RaceProps[targetRace][1])
  local raceRed = targetUser:GetProperty(CommonFun.RaceProps[srcRace][2])
  local raceparam = 1 + raceInc - raceRed
  local mapid, maptype = srcUser:GetMapInfo()
  if maptype == PVP_MAPS then
    local B = raceRed - raceInc
    B = B < -1 and -1 or 1 < B and 1 or B
    B = math.floor(B * 1000) / 1000
    B = B + 0.3 * (1 - math.sin(B * 3.14 / 2))
    raceparam = 1 - B
  end
  if raceparam <= 0.1 then
    raceparam = 0.1
  end
  local srcAtkElement = 5
  local targetDefElement = targetUser:GetProperty("DefAttr")
  local ElementRate = CommonFun.GetElementRate(srcUser, srcAtkElement, targetUser, targetDefElement)
  if (srcUser:HasBuffID(69650_8608_:MAX_STACK_0) or srcUser:HasBuffID(71090_10658_:MAX_STACK_0)) and 1 < ElementRate then
    ElementRate = ElementRate * 1.1
  end
  if targetUser:HasBuffID(49130_DIVINE_HYMN_CARVER_:MAX_STACK_0) then
    ElementRate = math.min(ElementRate, 1)
  end
  if srcUser:HasBuffID(49210_7892_:MAX_STACK_0) then
    ElementRate = ElementRate + 0.15
  end
  if nil == CommonFun.NatureProps[srcAtkElement] or nil == CommonFun.NatureProps[targetDefElement] or nil == targetDefElement then
    return 0
  end
  local elementInc = srcUser:GetProperty(CommonFun.NatureProps[targetDefElement][1])
  local elementRed = targetUser:GetProperty(CommonFun.NatureProps[srcAtkElement][2])
  local elementAtk = srcUser:GetProperty(CommonFun.NatureProps[srcAtkElement][3])
  local elementparam = (1 + elementInc) * ElementRate
  local elementparam2 = 1 + elementAtk - elementRed
  local mapid, maptype = srcUser:GetMapInfo()
  if maptype == PVP_MAPS then
    local B = elementRed - elementAtk
    B = B < -1 and -1 or 1 < B and 1 or B
    B = math.floor(B * 1000) / 1000
    B = B + 0.3 * (1 - math.sin(B * 3.14 / 2))
    elementparam2 = 1 - B
  end
  if elementparam2 <= 0.1 then
    elementparam2 = 0.1
  end
  local ele = elementparam * elementparam2
  if targetDefElement == nil or ElementRate == nil or elementInc == nil or elementRed == nil or elementAtk == nil then
    ele = 1
  end
  local NpcParam = CommonFun.NpcParam(srcUser, targetUser, params, damageParam, logger)
  local BaseAtk = Str * 2 + math.floor(Str * Str / 100) + math.floor(Dex / 5) + math.floor(Luk / 5)
  local AtkFinal = ((Atk - BaseAtk) * (1 + AtkPer) * CommonFun.ShapeCorrection(srcUser, targetUser) * ele + BaseAtk) * raceparam * NpcParam
  local DefReduc = CommonFun.CalcDef(srcUser, targetUser)
  local Int2 = targetUser:GetProperty("Int")
  local Numxp = srcUser:GetRunePoint(94050_AESIR_MAGIC_TRAP_DAMAGE_10)
  local RuneDamage = 1 + Numxp * 0.1
  local GemValue = srcUser:GetGemValue(91022_MAGIC_TRAP_DMG_PERCENTAGE)
  local GemDam = 1 + GemValue / 100000
  local bloodrain = 1
  local StateEffect = targetUser:GetProperty("StateEffect")
  local bits3 = CommonFun.getBits(StateEffect)
  if bits3[CommonFun.StateEffect.Poison] == 1 and srcUser:HasBuffID(64350_2982_:MAX_STACK_0) then
    bloodrain = bloodrain + 0.1
  end
  local A = -(((AtkFinal + Int2 * damChangePer1) * DefReduc * (1 - DamReduc2) + Refine) * damChangePer * (1 - RefineDamReduc) * (1 + DamIncrease) - Vit2 * (1 + VitPer2)) * RuneDamage * GemDam * bloodrain
  if bits[CommonFun.AttrEffect.Hualiduanjian] == 1 then
    return A * 1.5
  end
  local AttrFunction = srcUser:GetProperty("AttrFunction")
  local bitfunc = CommonFun.getBits(AttrFunction)
  if (targetUser.boss or targetUser.mini or targetUser.changelinepunish) and (targetUser.zoneType == 1 or targetUser.zoneType == 22) and targetUser.noPunishBoss == false and bitfunc[CommonFun.AttrFunction.JustInViceZone] == 1 and targetUser.isBossFromBranch == false then
    A = 0
  end
  if CommonFun.checkAttrFunctionMiss(targetUser, srcUser) then
    A = 0
  end
  if targetUser.boss and targetUser.zoneType == 22 and CommonFun.CheckStormBossMiss(targetUser, srcUser) then
    A = 0
  end
  if targetUser:GetNpcID() == 30043_YEAR or targetUser:GetNpcID() == 280303_WILDNESS_SPIRIT_BEAST or targetUser:GetNpcID() == 56008_GOMORA or targetUser:GetNpcID() == 56009_BALTAN or targetUser:GetNpcID() == 56010_GOLZA or targetUser:GetNpcID() == 56011_BEMSTAR or targetUser:GetNpcID() == 56012_ELEKING or targetUser:GetNpcID() == 56013_KING_JOE then
    A = -1
  end
  if targetUser:DamageAlways1() then
    A = -1
  end
  if GetNpcID == 280711_DENSE_FOREST_SQUIRREL or GetNpcID == 280413_KLULU or GetNpcID == 280708_DENSE_FOREST_SQUIRREL or GetNpcID == 280434_KLULU then
    A = math.floor(A / 100)
  end
  return A
end