Formula

CommonFun.CalcMDef

formula.lua
1function CommonFun.CalcMDef(srcUser, targetUser)
2  local MDef2 = targetUser:GetProperty("MDef")
3  local Int2 = targetUser:GetProperty("Int")
4  local RealMDef = MDef2 - Int2
5  if MDef2 <= 0 then
6    MDef2 = 0
7  end
8  if RealMDef <= 0 then
9    RealMDef = 0
10  end
11  local IgnoreMDef = srcUser:GetProperty("IgnoreMDef")
12  if params ~= nil then
13    local SkillID, SkillLevel = CommonFun.UnmergeSkillID(params.skillIDAndLevel)
14    local BuffIDs, IgnoreDefAdd = CommonFun.EquipBuffAndIgnoreMDef(SkillID)
15    local TempAdd = true
16    for i = 1, #BuffIDs do
17      if BuffIDs[i] ~= 0 and srcUser:HasBuffID(BuffIDs[i]) == false then
18        TempAdd = false
19        break
20      end
21    end
22    if TempAdd then
23      IgnoreMDef = IgnoreMDef + IgnoreDefAdd
24    end
25  end
26  local MDefPer2 = targetUser:GetProperty("MDefPer")
27  local Card2 = srcUser:GetEquipCardNum(7, 24668_FIRE_BIRD_CHIRI_STAR_CARD)
28  if (targetUser.boss or targetUser.mini) and 0 < Card2 and srcUser:HasBuffID(81002120_10678_:MAX_STACK_0) then
29    IgnoreMDef = IgnoreMDef + Card2 * 0.25 + 0.05
30  elseif (targetUser.boss or targetUser.mini) and 0 < Card2 then
31    IgnoreMDef = IgnoreMDef + Card2 * 0.25
32  end
33  if (targetUser.boss or targetUser.mini) and srcUser:HasBuffID(57710_BLUE_MOON_WITCH_CARD_:MAX_STACK_0) then
34    local RefineLv2 = srcUser:GetEquipedRefineLv(2)
35    IgnoreMDef = IgnoreMDef + RefineLv2 * 0.01
36  end
37  if srcUser:HasBuffID(138002_23_:MAX_STACK_0) then
38    local IgnoreDef = srcUser:GetProperty("IgnoreDef")
39    IgnoreMDef = IgnoreMDef + IgnoreDef
40  end
41  if targetUser:GetBuffActive(137321) then
42    IgnoreMDef = 0
43  end
44  local pvpReduce = 0
45  local mapid, maptype = srcUser:GetMapInfo()
46  if (maptype == PVP_MAPS) and targetUser:GetNpcID() ~= 40022_EMPERIUM then
47    MDefPer2 = MDefPer2 < -1 and -1 or 2 < MDefPer2 and 2 or MDefPer2
48    MDefPer2 = math.floor(MDefPer2 * 1000) / 1000
49    MDefPer2 = MDefPer2 + 0.5 * (1 - math.sin(MDefPer2 * 3.14 / 2))
50    local Master = targetUser:GetMasterUser()
51    if targetUser:GetNpcID() == 0 or Master ~= nil then
52      pvpReduce = 0.2
53    end
54  end
55  local MDefFinal = RealMDef * (1 + MDefPer2 - IgnoreMDef + pvpReduce) + Int2 * (1 + pvpReduce * 5)
56  if MDefFinal < 0 then
57    MDefFinal = 0
58  end
59  local div = 1000 + MDefFinal * 10
60  div = div ~= 0 and div or 1
61  local MDefReduc1 = (1000 + MDefFinal) / div
62  local MAtk = srcUser:GetProperty("MAtk")
63  local MAtkPer = srcUser:GetProperty("MAtkPer")
64  local MAtkFinal = MAtk * (1 + MAtkPer)
65  local MDefReduc2 = 1 / (1 + 13 * MDefFinal / MAtkFinal)
66  local MDefReduc = math.max(MDefReduc1, MDefReduc2)
67  if srcUser:HasBuffID(138840_SOUL_BRAND_FIRE_TEAMMATE_:MAX_STACK_0) or srcUser:HasBuffID(138843_SOUL_BRAND_FIRE_ONESELF_:MAX_STACK_0) or srcUser:HasBuffID(138846_SOUL_BRAND_FIRE_FEATURE_7_:MAX_STACK_0) then
68    MDefReduc = 1
69  end
70  return MDefReduc
71end
Formula Graph

Connected Archive Data

See which cards, equipment, headwears, buffs, and other archived records connect to this formula.

Loading graph filters

CommonFun.CalcMDef

commonfun-calcmdef

Nodes

0

Edges

0

Related Nodes

Select at least one node type.