Formula

CommonFun.calcBuff_8930

function CommonFun.calcBuff_8930(srcUser, targetUser, a, b, c, d, lv)
  local Int = srcUser:GetProperty("Int")
  local Vit = srcUser:GetProperty("Vit")
  local MAtk = srcUser:GetProperty("MAtk")
  local MAtkPer = srcUser:GetProperty("MAtkPer")
  local MaxHp = targetUser:GetProperty("MaxHp")
  local MDamIncrease = CommonFun.calcMDamIncrease(srcUser, targetUser)
  local IgnoreMDef = srcUser:GetProperty("IgnoreMDef")
  if 1 <= IgnoreMDef then
    IgnoreMDef = 1
  end
  local GemValue = srcUser:GetGemValue(216151_REFLECTIONS_OF_DEMON_KING_S_REFLECTION_INHERIT_PERCENTAGE_OF_THE_TARGET_S_M_ATK_M_PIERCE_AND_M_DMG_IN_ADDITION_DOESN_T_WORK_ON_MONSTERS) / 100000
  if targetUser:GetNpcID() ~= 0 then
    GemValue = 0
  end
  local MRefine = srcUser:GetProperty("MRefine")
  local MDamSpike1 = targetUser:GetProperty("MDamSpike_MPEN") * GemValue
  MAtk = MAtk + targetUser:GetProperty("MAtk") * GemValue
  MDamIncrease = MDamIncrease + targetUser:GetProperty("MDamIncrease") * GemValue
  local MDef2 = targetUser:GetProperty("MDef")
  local MDefPer2 = targetUser:GetProperty("MDefPer")
  local Vit2 = targetUser:GetProperty("Vit")
  local VitPer2 = targetUser:GetProperty("VitPer")
  local Int2 = targetUser:GetProperty("Int")
  local IntPer2 = targetUser:GetProperty("IntPer")
  local MDamReduc2 = CommonFun.calcMDamReDuc(srcUser, targetUser)
  local RefineMDamReduc = targetUser:GetProperty("RefineMDamReduc")
  local raceparam = 1
  local srcRace = srcUser.race
  local targetRace = targetUser.race
  if targetUser:HasBuffID(139410_TWO_FACE_DEMON_KING_HUMAN_:MAX_STACK_0) then
    targetRace = 3
  end
  if srcUser:HasBuffID(139411_TWO_FACE_DEMON_KING_DEMON_:MAX_STACK_0) then
    srcRace = 3
  end
  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 = 7
  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 srcUser:HasBuffID(77480_48193_VICTORY_SWALLOW_1_:MAX_STACK_0) then
    ElementRate = ElementRate + 0.1
  end
  if srcUser:HasBuffID(139351_1225_:MAX_STACK_0) then
    local MoroccField = srcUser:GetProperty("DarkJudgePer")
    ElementRate = ElementRate + MoroccField
  end
  if nil == CommonFun.NatureProps[srcAtkElement] or nil == CommonFun.NatureProps[targetDefElement] or nil == targetDefElement then
    return 0
  end
  local elementRed = targetUser:GetProperty(CommonFun.NatureProps[srcAtkElement][2])
  local elementAtk = srcUser:GetProperty(CommonFun.NatureProps[srcAtkElement][3])
  local elementThrough = srcUser:GetProperty(CommonFun.NatureProps[srcAtkElement][4])
  local elementResistance = targetUser:GetProperty(CommonFun.NatureProps[srcAtkElement][5])
  if 0 <= elementRed then
    elementRed = elementRed * math.max(1 - elementThrough, 0)
  end
  if 0 <= elementAtk then
    elementAtk = elementAtk * math.max(1 - elementResistance, 0)
  end
  local elementparam = 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
  if elementparam2 <= 0.1 then
    elementparam2 = 0.1
  end
  local ele = elementparam * elementparam2
  if targetDefElement == nil or ElementRate == nil or elementRed == nil or elementAtk == nil then
    ele = 1
  end
  local skilllv_1 = srcUser:GetLernedSkillLevel(2953_MERCHANT:DEMON_KING_S_REFLECTION)
  local NpcParam = CommonFun.NpcParam(srcUser, targetUser, params, damageParam, logger)
  local BaseMAtk = Int + math.floor(Int * Int / 100)
  local MAtkFinal = ((MAtk - BaseMAtk) * (1 + MAtkPer) + BaseMAtk) * ele * raceparam * NpcParam
  local MDefReduc = CommonFun.CalcMDef(srcUser, targetUser)
  local A = -((MAtkFinal * MDefReduc * (1 - MDamReduc2 + MDamSpike1) + MRefine) * (skilllv_1 * 1 + 6) * (1 - RefineMDamReduc) * (1 + MDamIncrease) - Vit2 / 2 * (1 + VitPer2) - Int2 * (1 + IntPer2))
  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
  return A
end