Formula

CommonFun.calcBuff_8900

function CommonFun.calcBuff_8900(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 MDamIncrease = CommonFun.calcMDamIncrease(srcUser, targetUser)
  local IgnoreMDef = srcUser:GetProperty("IgnoreMDef")
  if 1 <= IgnoreMDef then
    IgnoreMDef = 1
  end
  local MRefine = srcUser:GetProperty("MRefine")
  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 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
  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 DarkAtk = srcUser:GetProperty("DarkAtk")
  local ele = ElementRate * (1 + DarkAtk)
  local RefineMDamReduc = targetUser:GetProperty("RefineMDamReduc")
  local NpcParam = CommonFun.NpcParam(srcUser, targetUser, params, damageParam, logger)
  local BaseMAtk = Int + math.floor(Int * Int / 100)
  local MAtkFinal = ((MAtk - BaseMAtk) * (1 + MAtkPer) + BaseMAtk) * NpcParam
  local skilllv_1 = srcUser:GetLernedSkillLevel(2950_MERCHANT:DARKNESS_DOMINATOR)
  local damChangePer = 0.6 + skilllv_1 * 0.6
  local MDamSpike = srcUser:GetProperty("MDamSpike_MPEN")
  local ResultDamInc = srcUser:GetProperty("ResultDamInc")
  local ResultDamRes = targetUser:GetProperty("ResultDamRes")
  if srcUser:HasBuffID(57200_DEVIL_GOVERNOR_CARD_:MAX_STACK_0) then
    ResultDamInc = ResultDamInc + 0.15
  end
  local Result = 1 + ResultDamInc - ResultDamRes
  Result = math.max(Result, 0.1)
  local Yichang = 1
  if skilllv_1 == 7 then
    local NumDebuff = targetUser:GetStatusNum()
    if targetUser:HasBuffID(139314_1225_:MAX_STACK_0) then
      NumDebuff = NumDebuff + 1
    end
    if targetUser:HasBuffID(139320_DEMON_S_REFLECTION_:MAX_STACK_0) then
      NumDebuff = NumDebuff + 1
    end
    if targetUser:HasBuffID(139370_DEMON_KING_S_CHAIN_:MAX_STACK_0) then
      NumDebuff = NumDebuff + 1
    end
    if 1 <= NumDebuff then
      Yichang = NumDebuff * NumDebuff * 0.05 + 1
    end
  end
  local A = -((MAtkFinal * (1 + MDamSpike) + MRefine) * damChangePer * (1 - RefineMDamReduc) * (1 + MDamIncrease)) * ele * Result * Yichang
  if targetUser:GetNpcID() ~= 0 then
    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
    if elementparam2 <= 0.1 then
      elementparam2 = 0.1
    end
    ele = elementparam * elementparam2
    if targetDefElement == nil or ElementRate == nil or elementRed == nil or elementAtk == nil then
      ele = 1
    end
    MAtkFinal = ((MAtk - BaseMAtk) * (1 + MAtkPer) + BaseMAtk) * ele * raceparam
    local MDefReduc = CommonFun.CalcMDef(srcUser, targetUser)
    A = -((MAtkFinal * MDefReduc * (1 - MDamReduc2) + MRefine) * damChangePer * (1 + Int * 0.04) * (1 - RefineMDamReduc) * (1 + MDamIncrease) - Vit2 / 2 * (1 + VitPer2) - Int2 * (1 + IntPer2)) * Result * Yichang
  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
  return A
end