function Trig_Set_Damage takes nothing returns boolean
local unit a = udg_PDD_source
local unit t = udg_PDD_target
local integer ap = GetPlayerId(GetOwningPlayer(a)) + 1
local integer tp = GetPlayerId(GetOwningPlayer(t)) + 1
local integer acv = GetUnitUserData(a)
local integer tcv = GetUnitUserData(t)
local integer rnd = GetRandomInt(0, 99) //random for hit chance
local real dmg = udg_PDD_amount
local real dmgaddon
local real r
local real tr
local real block
local real eva
local real alv
local real dlv
local real crit
local real critdmg
local real pdef
local real mdef
local integer hit
local integer pv
local real attackerlv
local real targetlv
local real PhysicalRed
local real MagicRed
local real ref = udg_Global_Reflect[tcv]
local real ls = udg_Global_LifeSteal[acv]
local real ms = udg_Global_ManaSteal[acv]
local real DmgRed
local integer DDType = udg_PDD_damageType//1=physical, 2=spell, 3=custom dmg
local integer MDType = udg_PDD_magicType//0=physical, 1=fire, 2=water,3=lightning,4=poison,5=earth
if dmg > 0 then
if MDType > 99 then
set MDType = MDType - 100
set DDType = 3
endif
if dmg <= 0 then
set udg_PDD_amount = 1
set dmg = udg_PDD_amount
endif
// call DisplayTextToForce( GetPlayersAll(), I2S(dmgtype)+"-"+I2S(DamageTypeDOT)+R2S(udg_Global_MDmg4[acv]) )
if DDType == 1 and MDType == 0 then
if udg_Global_MDmg1[acv] > 0.00 then
set udg_PDD_magicType = 1
call UnitDamageTargetEx (a, t, udg_Global_MDmg1[acv], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
elseif udg_Global_MDmg2[acv] > 0.00 then
set udg_PDD_magicType = 2
call UnitDamageTargetEx (a, t, udg_Global_MDmg2[acv], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
elseif udg_Global_MDmg3[acv] > 0.00 then
set udg_PDD_magicType = 3
call UnitDamageTargetEx (a, t, udg_Global_MDmg3[acv], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
elseif udg_Global_MDmg4[acv] > 0.00 then
set udg_PDD_magicType = 4
call UnitDamageTargetEx (a, t, udg_Global_MDmg4[acv], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
elseif udg_Global_MDmg5[acv] > 0.00 then
set udg_PDD_magicType = 5
call UnitDamageTargetEx (a, t, udg_Global_MDmg5[acv], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
endif
//call DestroyEffect(AddSpecialEffectTarget(udg_Effects[1], t, "origin"))
//call FT (Player(ap-1), Player(tp-1),I2S(R2I(dmgaddon)), 0.8, t, 20, 100, 100, 255, 200)
endif
if ( IsUnitType(a, UNIT_TYPE_HERO) ) then
set attackerlv = GetHeroLevel(a)
else
set attackerlv = GetUnitLevel(a)
endif
if ( IsUnitType(t, UNIT_TYPE_HERO) ) then
set targetlv = GetHeroLevel(t)
else
set targetlv = GetUnitLevel(t)
endif
//pet power if you got summoner class, i not enabled it
//if ( udg_Pet[GetUnitUserData(udg_Hero[ap])] == a and udg_Class2[ap]==6 ) then
// set dmg = dmg + (udg_Stat_Pet_Power[ap] + GetHeroInt(udg_Hero[ap], true)/100.00) * dmg
//endif
set block = udg_Global_Block[tcv]
set alv = udg_Global_AttLv[acv]
set dlv = udg_Global_DefLv[tcv]
if ( GetPlayerController(GetOwningPlayer(a)) != MAP_CONTROL_USER ) then
set pv = GetUnitPointValue(a)
if pv >= 50 and pv < 55 then
set MDType = pv - 49
endif
set alv = udg_Global_AttLv[acv]
endif
// call DisplayTextToPlayer(Player(0),0,0,GetUnitName(a)+" TYPE"+I2S(DDType)+" mtype"+I2S(MDType)+"-->amount"+" dmg"+R2S(dmg))
if ( GetPlayerController(GetOwningPlayer(t)) != MAP_CONTROL_USER ) and udg_Difficulty != 1 then
set dlv = udg_Global_DefLv[tcv] + udg_Difficulty * 10
else
if GetPlayerController(GetOwningPlayer(t)) == MAP_CONTROL_USER and GetPlayerController(GetOwningPlayer(a)) == MAP_CONTROL_USER then
set dmg = dmg / 4
endif
set dlv = udg_Global_DefLv[tcv]
endif
set crit = udg_Global_Crit[acv]
set critdmg = udg_Global_CritDmg[acv] + DEFAULT_CRITICAL_DAMAGE()
set eva = ( udg_Global_Eva[tcv] - 1.00 ) / ( ( 2.00 * udg_Global_Acc[acv] ) + ( udg_Global_Eva[tcv] - 1.00 ) )
set hit = HitChance(acv, tcv)//R2I((1.00 - eva) * 100.00)
set pdef = udg_Global_Pdef[tcv]
if MDType == 1 then
set mdef = udg_Global_Mdef1[tcv]
elseif MDType == 2 then
set mdef = udg_Global_Mdef2[tcv]
elseif MDType == 3 then
set mdef = udg_Global_Mdef3[tcv]
elseif MDType == 4 then
set mdef = udg_Global_Mdef4[tcv]
elseif MDType == 5 then
set mdef = udg_Global_Mdef5[tcv]
else
set mdef = 0
endif
set dmg = dmg + (udg_Global_DmgInc[acv] - udg_Global_DmgRed[tcv]) / 100.00 * dmg
if mdef < 0 then
set mdef = 0
endif
if pdef < 0 then
set pdef = 0
endif
if rnd < hit and MDType == 0 and DDType == 1 then
set dmg = 0.00
call FT (Player(ap - 1), Player(tp - 1), "Miss!", 0.9 , t, 7, 51, 51, 255, 200)
set DmgRed = 0
else
set rnd = GetRandomInt(0, 99)
if rnd < block and DDType < 3 then
set dmg = 0.00
call FT (Player(ap - 1), Player(tp - 1), "Blocked!", 0.9, t, 7, 0, 0, 255, 200)
set DmgRed = 0
else
set PhysicalRed = pdef / ( 40.00 * attackerlv + pdef + 25.00 )
set MagicRed = mdef / ( 40.00 * attackerlv + mdef + 25.00 )
set rnd = GetRandomInt(0, 99)
if rnd < udg_Global_ArmorBreak[acv] then
//it was completly ignore the defence but seems that op without high hp
//so i changed so i increased the incoming dmg with divide target ressitance% by 2
//set DmgRed = 1
set PhysicalRed = PhysicalRed / 2.00
set MagicRed = MagicRed / 2
endif
if MDType > 1 then
set DmgRed = ( 1 - MagicRed )
else
set DmgRed = 1 - PhysicalRed
endif
set dmg = dmg * DmgRed
if GetPlayerController(GetOwningPlayer(t)) == MAP_CONTROL_USER and DmgRed > 0 then
call DamageDecrease (tcv, 1, DmgRed / 5)
call DamageDecrease (tcv, 2, DmgRed / 5)
call DamageDecrease (tcv, 4, DmgRed / 5)
call DamageDecrease (tcv, 5, DmgRed / 5)
call DamageDecrease (tcv, 6, DmgRed / 5)
call DamageDecrease (tcv, 7, DmgRed / 5)
call DamageDecrease (tcv, 8, DmgRed / 5)
call DamageDecrease (tcv, 9, DmgRed / 5)
if udg_Inv_Sens[tp] and udg_Camera_Lock[tp] > 0 then
call WindowTransition (tp, udg_Camera_Lock[tp], 0)
endif
endif
if GetPlayerController(GetOwningPlayer(a)) == MAP_CONTROL_USER then
if HaveSavedHandle(udg_Stat_Table, acv, 3) then
call DamageDecrease (acv, 3, 0.05)
set rnd = GetHandleId(LoadItemHandle(udg_Stat_Table, acv, 3 ))
set dmg = GetRandomReal(WeaponMinDamageModifier(LoadInteger(udg_CItem_Table, rnd, 3))*dmg, dmg)
endif
endif
if ( alv > dlv ) then
set dmg = dmg * ( 1 + ( alv - dlv ) / 100.00 )
else
set dmg = dmg / ( 1.00 + ( dlv - alv ) / 120.00)
endif
if udg_Global_Act_Id[acv] > 0 then
set rnd = GetRandomInt(0, 99)
if udg_Global_Act_Id[acv] == 1 then
if rnd < 5 then
set dmg = dmg * 2
call DestroyEffect(AddSpecialEffectTarget(EFFECT(1), t, "origin"))
if GetUnitMaxLife(a)*0.05 > GetUnitLife(a) then
call SetUnitLife(a, 1)
else
call SetUnitLife(a, GetUnitLife(a)-(GetUnitMaxLife(a)*0.05))
endif
endif
elseif udg_Global_Act_Id[acv] == 2 then
if rnd < 5 then
call AddOT (a, a, -1, R2I(GetUnitMaxLife(a)*0.1), 20)
endif
elseif udg_Global_Act_Id[acv] == 3 then
if rnd < 5 then
call AddOT (a, t, 0, udg_Stat_Dmg[acv]+50, 20)
endif
elseif udg_Global_Act_Id[acv] == 4 then
if rnd < 5 then
call AddUnitBuff (a, 6, 25, 5, 0, 0)
call AddUnitBuff (a, 7, -25, 5, 0, 0)
endif
elseif udg_Global_Act_Id[acv] == 5 then
if rnd < 5 then
call AddUnitBuff (a, 9, 13, 6, 0, 0)
call AddUnitBuff (a, 10, 13, 6, 0, 0)
endif
elseif udg_Global_Act_Id[acv] == 6 then
if rnd < 5 then
call AddUnitBuff (t, 7, -15, 5, 0, 0)
endif
elseif udg_Global_Act_Id[acv] == 7 then
if rnd < 5 then
call AddUnitBuff (a, 11, 100, 4, 0, 0)
endif
elseif udg_Global_Act_Id[acv] == 8 then
if rnd < 5 then
call AddUnitBuff (a, 15, R2I(udg_Stat_Pdef[acv]*0.6), 20, 0, 0)
call AddUnitBuff (a, 16, R2I(udg_Stat_Mdef1[acv]*0.6), 20, 0, 0)
call AddUnitBuff (a, 17, R2I(udg_Stat_Mdef2[acv]*0.6), 20, 0, 0)
call AddUnitBuff (a, 18, R2I(udg_Stat_Mdef3[acv]*0.6), 20, 0, 0)
call AddUnitBuff (a, 19, R2I(udg_Stat_Mdef4[acv]*0.6), 20, 0, 0)
call AddUnitBuff (a, 20, R2I(udg_Stat_Mdef5[acv]*0.6), 20, 0, 0)
endif
elseif udg_Global_Act_Id[acv] == 9 then
if rnd < 25 then
call AddUnitBuff (a, 5, 50, 4, 0, 0)
endif
endif
endif
if GetRandomReal(0.00, 100) <= crit and DDType < 3 and dmg > 0 then
set dmg = dmg * critdmg / 100.00
call FT (Player(ap - 1), Player(tp - 1), I2S(R2I(dmg)), 1.5, t, 10, 255, 0, 0, 200)
else
call FT (Player(ap - 1), Player(tp - 1), I2S(R2I(dmg)), 0.8, t, 15, 179, 255, 51, 200)
endif
if DDType < 3 and dmg > 5 then
if ls > 0 then
set r = dmg * ls / 100.00
set ls = GetUnitLife(a) + r
call SetUnitLife(a, ls )
if r > 0.99 then
call FT_Ex (Player(ap - 1), Player(tp - 1), "+" + I2S(R2I(r)), 0.8, a, 15, 255, 30, 30, 200, 0)
endif
endif
if ms > 0 then
set r = dmg * ms / 100.00
set ms = GetUnitState(a, UNIT_STATE_MANA) + r
call SetUnitState(a, UNIT_STATE_MANA, ms )
if r > 0.99 then
call FT_Ex (Player(ap - 1), Player(tp - 1), "+" + I2S(R2I(r)), 0.8, a, 15, 30, 30, 255, 200, 180)
endif
endif
if ref > 0 then
set dmgaddon = dmg * ref / 100.00
call UnitDamageTargetEx (a, t, dmgaddon, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
if dmgaddon > 0.99 then
set udg_PDD_magicType = MDType
call FT_Ex (Player(ap - 1), Player(tp - 1), I2S(R2I(dmgaddon)), 1, t, 13, 70, 255, 30, 200, 270)
endif
endif
endif
endif
endif
set udg_PDD_amount = dmg
set udg_PDD_magicType = 0
if udg_CombatTimer[tcv] < 1 then
set udg_CombatTimer[tcv] = 10
set udg_CombatIndex = udg_CombatIndex + 1
set udg_CombatI2CV[udg_CombatIndex] = tcv
call StatRefresh (tcv)
if udg_Camera_Lock[tp] == 1 then
call ShowStat (tp)
endif
else
set udg_CombatTimer[tcv] = 10
endif
if udg_CombatTimer[acv] < 1 then
set udg_CombatTimer[acv] = 10
set udg_CombatIndex = udg_CombatIndex + 1
set udg_CombatI2CV[udg_CombatIndex] = acv
call StatRefresh (acv)
if udg_Camera_Lock[ap] == 1 then
call ShowStat (ap)
endif
else
set udg_CombatTimer[acv] = 10
endif
endif
set a = null
set t = null
return false
endfunction