Formula

CommonFun.CalcDef

formula.lua
1function CommonFun.CalcDef(srcUser, targetUser, params)
2  local Buff = srcUser:HasBuffID(24700_STELLER_S_AXE_:MAX_STACK_0)
3  local targetRace = targetUser.race
4  if targetUser:HasBuffID(139410_TWO_FACE_DEMON_KING_HUMAN_:MAX_STACK_0) then
5    targetRace = 3
6  end
7  if srcUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) and srcUser:HasBuffID(49325_RACIAL_ANCIENT_RELICS_CD_:MAX_STACK_0) then
8  elseif srcUser:HasBuffID(49320_RACIAL_ANCIENT_RELICS_PERMANENT_:MAX_STACK_0) then
9    targetRace = 2
10  end
11  local Def2 = targetUser:GetProperty("Def")
12  local Vit2 = targetUser:GetProperty("Vit")
13  local VitPer2 = targetUser:GetProperty("VitPer")
14  local DefPer2 = targetUser:GetProperty("DefPer")
15  local RealDef = Def2 - Vit2
16  local MDef2 = targetUser:GetProperty("MDef")
17  local MDefPer2 = targetUser:GetProperty("MDefPer")
18  if Def2 <= 0 then
19    Def2 = 0
20  end
21  if Buff == true and targetRace == 1 then
22    RealDef = 0
23  end
24  if RealDef <= 0 then
25    RealDef = 0
26  end
27  local IgnoreDef = 0
28  local IgnoreDef1 = srcUser:GetProperty("IgnoreDef")
29  local IgnoreDef2 = srcUser:GetProperty("IgnoreEquipDef")
30  if targetUser.boss or targetUser.mini then
31    IgnoreDef = IgnoreDef1
32  else
33    IgnoreDef = IgnoreDef1 + IgnoreDef2
34  end
35  if params ~= nil then
36    local SkillID, SkillLevel = CommonFun.UnmergeSkillID(params.skillIDAndLevel)
37    if SkillID == 4717 or SkillID == 4718 or SkillID == 4702 or SkillID == 4714 then
38      Def2 = math.min(MDef2, Def2)
39      DefPer2 = math.min(MDefPer2, DefPer2)
40      RealDef = Def2 - Vit2
41    end
42  end
43  if params ~= nil then
44    local SkillID, SkillLevel = CommonFun.UnmergeSkillID(params.skillIDAndLevel)
45    local BuffIDs, IgnoreDefAdd = CommonFun.EquipBuffAndIgnoreDef(SkillID)
46    local TempAdd = true
47    for i = 1, #BuffIDs do
48      if BuffIDs[i] ~= 0 and srcUser:HasBuffID(BuffIDs[i]) == false then
49        TempAdd = false
50        break
51      end
52    end
53    if TempAdd then
54      IgnoreDef = IgnoreDef + IgnoreDefAdd
55    end
56  end
57  local Card1 = srcUser:GetEquipCardNum(7, 24667_MAPLE_FAIRY_YZMA_STAR_CARD)
58  if (targetUser.boss or targetUser.mini) and 0 < Card1 and srcUser:HasBuffID(81002110_10677_:MAX_STACK_0) then
59    IgnoreDef = IgnoreDef + Card1 * 0.25 + 0.05
60  elseif (targetUser.boss or targetUser.mini) and 0 < Card1 then
61    IgnoreDef = IgnoreDef + Card1 * 0.25
62  end
63  if (targetUser.boss or targetUser.mini) and srcUser:HasBuffID(57710_BLUE_MOON_WITCH_CARD_:MAX_STACK_0) then
64    local RefineLv2 = srcUser:GetEquipedRefineLv(2)
65    IgnoreDef = IgnoreDef + RefineLv2 * 0.01
66  end
67  local CardNumS1 = srcUser:GetEquipCardNum(5, 23329)
68  local CardNumS2 = srcUser:GetEquipCardNum(6, 23329)
69  if (targetUser.boss or targetUser.mini) and srcUser:HasBuffID(57770_STEVEN_JACK_ONESTO_WARF_CARD_:MAX_STACK_0) then
70    IgnoreDef = IgnoreDef + CardNumS1 * 0.05 + CardNumS2 * 0.05
71  end
72  local Card2 = srcUser:GetEquipCardNum(7, 23238_ALIEN_THANATOS_CARD)
73  if (targetUser.boss or targetUser.mini or targetUser:GetNpcID() ~= 0) and 0 < Card2 then
74    local RefineLv = srcUser:GetEquipedRefineLv(7_WEAPON)
75    IgnoreDef = IgnoreDef + Card2 * (0.2 + RefineLv * 0.02)
76  end
77  local Card22 = srcUser:GetEquipCardNum(7, 23331)
78  if (targetUser.boss or targetUser.mini or targetUser:GetNpcID() ~= 0) and 0 < Card22 then
79    local RefineLv = srcUser:GetEquipedRefineLv(7_WEAPON)
80    IgnoreDef = IgnoreDef + Card22 * (0.2 + RefineLv * 0.02)
81  end
82  if nil ~= CommonFun.Shape and CommonFun.Shape.L == targetUser.shape and srcUser:HasBuffID(90004494_PUNISHING_GUILLOTINE_1_TIER_5_:MAX_STACK_0) then
83    IgnoreDef = IgnoreDef + 0.2
84  end
85  if nil ~= CommonFun.Shape and CommonFun.Shape.L == targetUser.shape and srcUser:HasBuffID(90004384_TITAN_1_TIER_5_:MAX_STACK_0) then
86    IgnoreDef = IgnoreDef + 0.3
87  end
88  if srcUser:HasBuffID(138002_23_:MAX_STACK_0) then
89    local IgnoreMDef = srcUser:GetProperty("IgnoreMDef")
90    IgnoreDef = IgnoreDef + IgnoreMDef
91  end
92  if targetUser:GetBuffActive(137321) then
93    IgnoreDef = 0
94  end
95  local pvpReduce = 0
96  local mapid, maptype = srcUser:GetMapInfo()
97  if (maptype == PVP_MAPS) and targetUser:GetNpcID() ~= 40022_EMPERIUM then
98    DefPer2 = DefPer2 < -1 and -1 or 2 < DefPer2 and 2 or DefPer2
99    DefPer2 = math.floor(DefPer2 * 1000) / 1000
100    DefPer2 = DefPer2 + 0.5 * (1 - math.sin(DefPer2 * 3.14 / 2))
101    local Master = targetUser:GetMasterUser()
102    if targetUser:GetNpcID() == 0 or Master ~= nil then
103      pvpReduce = 0.2
104    end
105  end
106  local DefFinal = RealDef * (1 + DefPer2 - IgnoreDef + pvpReduce) + Vit2 * (1 + VitPer2 + pvpReduce * 5)
107  if DefFinal < 0 then
108    DefFinal = 0
109  end
110  local div = 4000 + DefFinal * 10
111  div = div ~= 0 and div or 1
112  local DefReduc1 = (4000 + DefFinal) / div
113  local Atk = srcUser:GetProperty("Atk")
114  local AtkPer = srcUser:GetProperty("AtkPer")
115  local AtkFinal = Atk * (1 + AtkPer)
116  local DefReduc2 = 1 / (1 + 6 * DefFinal / AtkFinal)
117  local DefReduc = math.max(DefReduc1, DefReduc2)
118  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
119    DefReduc = 1
120  end
121  return DefReduc
122end
Formula Graph

Connected Archive Data

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

Loading graph filters

CommonFun.CalcDef

commonfun-calcdef

Nodes

0

Edges

0

Related Nodes

Select at least one node type.