XGM Forum
Сайт - Статьи - Проекты - Ресурсы - Блоги

Форуме в режиме ТОЛЬКО ЧТЕНИЕ. Вы можете задать вопросы в Q/A на сайте, либо создать свой проект или ресурс.
Вернуться   XGM Forum > Warcraft> Академия: форум для вопросов> Jass
Ник
Пароль
Войти через VK в один клик
Сайт использует только имя.

Закрытая тема
 
Hate
конь вакуумный
offline
Опыт: 43,030
Активность:
Есть ли тут утечки?
вопсчем код
» нажминаминя
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    if GetSpellAbilityId() == 'A000' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetConvertedPlayerId(GetOwningPlayer(uCaster))] / 100) *20)
    else
    set Dispersion = (((GetUnitAbilityLevelSwapped('A00E', uCaster) * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A002' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetConvertedPlayerId(GetOwningPlayer(uCaster))] / 100) *12)
    else
    set Dispersion = (((GetUnitAbilityLevelSwapped('A00E', uCaster) * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A003' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetConvertedPlayerId(GetOwningPlayer(uCaster))] / 100) *17)
    else
    set Dispersion = (((GetUnitAbilityLevelSwapped('A00E', uCaster) * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set PAtk = (udg_PhysAttack[GetConvertedPlayerId(GetOwningPlayer(uCaster))] + FinalDispersion)
    else
    set PAtk = ((GetUnitAbilityLevelSwapped('A00E', uCaster) * 80) + FinalDispersion)
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set CritChance = udg_CritChance[GetConvertedPlayerId(GetOwningPlayer(uCaster))]
    else
    set CritChance = GetUnitAbilityLevelSwapped('A00H', uCaster) * 8
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set CritChanceRed = udg_CritChanceRed[GetConvertedPlayerId(GetOwningPlayer(uTarg))]
    else
    set CritChanceRed = GetUnitAbilityLevelSwapped('A00D', uTarg) * 8
    endif
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
    set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
    if GetSpellAbilityId() == 'A000' then
    set PAtk = R2I ( PAtk * 2.2)
    endif
    if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
    set PAtk = R2I ( PAtk * 1.8)
    endif
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set PDef = udg_PhysDef[GetConvertedPlayerId(GetOwningPlayer(uTarg))]
    else
    set PDef = GetUnitAbilityLevelSwapped('A006', uTarg) * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
    set FinalDmg = 1
    endif
    if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set Accuracy = udg_Accuracy[GetConvertedPlayerId(GetOwningPlayer(uCaster))]
    set EvadeChance = udg_Evade[GetConvertedPlayerId(GetOwningPlayer(uTarg))]
    else
    set Accuracy = GetUnitAbilityLevelSwapped('A00I', uTarg) * 80
    set EvadeChance = GetUnitAbilityLevelSwapped('A008', uTarg) * 80
    endif
    set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
    if EvadeChance <= 5 then
    set EvadeChance = 5
    endif
    if EvadeChance >= 40 then
    set EvadeChance = 40
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= EvadeChance then
    set FinalDmg = 0
    call CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
    set text = GetLastCreatedTextTag()
    set Text1 = true
    set Def = true
    endif
    endif
     if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set ParryChance = udg_Parry[GetConvertedPlayerId(GetOwningPlayer(uTarg))]
    else
    set ParryChance = GetUnitAbilityLevelSwapped('A009', uTarg) * 80
    endif
    set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
    if ParryChance <= 5 then
    set ParryChance = 5
    endif
    if ParryChance >= 45 then
    set ParryChance = 45
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= ParryChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
    call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = GetLastCreatedTextTag()
    set Text1 = true
    set Def = true
    endif
    endif
    if GetUnitAbilityLevelSwapped('A00G', uTarg) == 2 and Def == false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set BlockChance = udg_Block[GetConvertedPlayerId(GetOwningPlayer(uTarg))]
    else
    set BlockChance = GetUnitAbilityLevelSwapped('A00A', uTarg) * 80
    endif
    set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
    if BlockChance <= 5 then
    set BlockChance = 5
    endif
    if BlockChance >= 50 then
    set BlockChance = 50
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= BlockChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
    call CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = GetLastCreatedTextTag()
    set Text1 = true
    set Def = true
    endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
    call CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = GetLastCreatedTextTag()
    set Text1 = true
    endif
    if Text1 ==  false then
    call CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = GetLastCreatedTextTag()
    set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
    set uTarg = null
    set uCaster = null
    set text = null
    endfunction
опытные люди, просмотрите и отпишитесь, ибо собираюсь брать это как каркас для других, и нехочетсо узнать о чем либо поздновато
Старый 13.04.2012, 17:53
Vadik29
Choice Battle 1.6а
offline
Опыт: 15,845
Активность:
Hatsume_Hate, тонна
GetUnitAbilityLevelSwapped('A00E', uCaster) //- утечка
GetUnitAbilityLevel(uCaster,'A00E') //- нет

[GetConvertedPlayerId(GetOwningPlayer(uCaster))] // - утечка 
[GetPlayerId(GetOwningPlayer(u))+1]  // - нет
дальше идут BJ
call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 ) 
call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
call SetTextTagPermanentBJ( text, false )
call SetTextTagLifespanBJ(text,2)
call SetTextTagFadepointBJ(text,0.0)
set text = GetLastCreatedTextTag()
[+] замечание от Suite: дезинформация

Отредактировано Vadik29, 13.04.2012 в 18:10.
Старый 13.04.2012, 17:58
Hate
конь вакуумный
offline
Опыт: 43,030
Активность:
Vadik29:
Hatsume_Hate, тонна
например?)
Hatsume_Hate добавил:
как все печально)
Старый 13.04.2012, 18:05
Nerevar
I'll be back!
offline
Опыт: 18,352
Активность:
передаваемых юнитов не надо обнулять
Старый 13.04.2012, 18:07
Klop
Папа римский
offline
Опыт: 13,006
Активность:
Vadik29:
GetUnitAbilityLevelSwapped('A00E', uCaster) - утечка
лол),незнаешь не пиши уже
это не утечка это функция вызываеь функцию GetUnitAbilityLevel для оптимизации лучше использовать это GetUnitAbilityLevel ибо происходит ненужный вызов функции ,но это не является утечкой
Vadik29:
[GetConvertedPlayerId(GetOwningPlayer(uCaster))] - утечка
щас расплачусь,тоже самое что и в первом варианте)
а вот что касаеться текстагов то утечек много,найди нормальную готовую функцию текстага безутечный и юзай и раскрой все функции БЖ
Старый 13.04.2012, 18:08
Vadik29
Choice Battle 1.6а
offline
Опыт: 15,845
Активность:
Klop, эти функции унылое говно,т.к. вызывают тормоза и кратковременный засор памяти имхо это вовсе не нужно, так что я все правильно сказал....
[+] замечание от Suite: если функции уг это не означает что они утечны
Старый 13.04.2012, 18:11
Klop
Папа римский
offline
Опыт: 13,006
Активность:
Vadik29:
кратковременный
ты ответил на свой вопрос сам,утечка это не временный засор
Старый 13.04.2012, 18:15
Nerevar
I'll be back!
offline
Опыт: 18,352
Активность:
Vadik29, не надо дезинформировать автора и других людей
почитай чтоли статьи,ибо пропускаешь настоящие утечки
у автора только лишнее обнуление передаваемых аргументов,все остальное в норме,включая использование текстагов
Старый 13.04.2012, 18:15
DaeDR

offline
Опыт: 8,074
Активность:
Hatsume_Hate, Слегка оптимизировал:
Не стал раскрывать BJ-texttage
» Код
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    if GetSpellAbilityId() == 'A000' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *20)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A002' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *12)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A003' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *17)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
    else
    set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
    else
    set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
    endif
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
    set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
    if GetSpellAbilityId() == 'A000' then
    set PAtk = R2I ( PAtk * 2.2)
    endif
    if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
    set PAtk = R2I ( PAtk * 1.8)
    endif
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set PDef = udg_PhysDef[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set PDef = GetUnitAbilityLevel(uTarg, 'A006') * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
    set FinalDmg = 1
    endif
    if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set Accuracy = udg_Accuracy[GetPlayerId(GetOwningPlayer(uCaster))+1]
    set EvadeChance = udg_Evade[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set Accuracy = GetUnitAbilityLevel(uTarg, 'A00I') * 80
    set EvadeChance = GetUnitAbilityLevel(uTarg, 'A008') * 80
    endif
    set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
    if EvadeChance <= 5 then
    set EvadeChance = 5
    endif
    if EvadeChance >= 40 then
    set EvadeChance = 40
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= EvadeChance then
    set FinalDmg = 0
    call CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
     if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set ParryChance = udg_Parry[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set ParryChance = GetUnitAbilityLevel(uTarg, 'A009') * 80
    endif
    set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
    if ParryChance <= 5 then
    set ParryChance = 5
    endif
    if ParryChance >= 45 then
    set ParryChance = 45
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= ParryChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
    call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
    if GetUnitAbilityLevel(uTarg, 'A00G') == 2 and Def == false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set BlockChance = udg_Block[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set BlockChance = GetUnitAbilityLevel(uTarg, 'A00A') * 80
    endif
    set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
    if BlockChance <= 5 then
    set BlockChance = 5
    endif
    if BlockChance >= 50 then
    set BlockChance = 50
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= BlockChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
    call CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
    call CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    endif
    if Text1 ==  false then
    call CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
    set uTarg = null
    set uCaster = null
    set text = null
endfunction
А вообще стоит подумать над оптимизацией и как-то сделать это через цикл что-ли
Старый 13.04.2012, 18:19
Vadik29
Choice Battle 1.6а
offline
Опыт: 15,845
Активность:
Nerevar, да с учетом, что можно сделать лучше, то у него все в норме.....
да и в добавок я сказал как будет лучше, а остальное уже за автором....
Старый 13.04.2012, 18:20
Nerevar
I'll be back!
offline
Опыт: 18,352
Активность:
DaeDR:
это через цикл что-ли
цикл ведь дает прирост читаемости,но не производительности(!)
Старый 13.04.2012, 18:20
DaeDR

offline
Опыт: 8,074
Активность:
И еще читабельность бы повысить. Например:
if () then
    ....
    if () then
        ...
    endif
endif
Так будет удобнее разбирать, что в каком if'e находится
Старый 13.04.2012, 18:21
16GB
GhostOne User
offline
Опыт: 60,317
Активность:
if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
подобное пишется так
if IsUnitType(uCaster, UNIT_TYPE_HERO)  then
Старый 13.04.2012, 18:21
Nerevar
I'll be back!
offline
Опыт: 18,352
Активность:
Vadik29:
да и в добавок я сказал как будет лучше, а остальное уже за автором...
раскрытие бж,в которых просто вызов другой функции - можно
раскрытие бж,в которых много строк - тут уже надо подумать что лучше - мизерный прирост скорости или читаемость и размер кода
Старый 13.04.2012, 18:23
DaeDR

offline
Опыт: 8,074
Активность:
И вообще стрит вынести IsUnitType(uCaster, UNIT_TYPE_HERO)
local boolen b = IsUnitType(uCaster, UNIT_TYPE_HERO)
// и дальше не вытаскивать уже тип юнита
if b then
...
endif
Старый 13.04.2012, 18:24
Hate
конь вакуумный
offline
Опыт: 43,030
Активность:
DaeDR:
Hatsume_Hate, Слегка оптимизировал:
Не стал раскрывать BJ-texttage
» Код
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    if GetSpellAbilityId() == 'A000' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *20)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A002' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *12)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A003' then
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *17)
    else
    set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
    endif
    set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
    else
    set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
    endif
    if IsUnitType(uCaster, UNIT_TYPE_HERO) == true then
    set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
    else
    set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
    endif
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
    set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
    if GetSpellAbilityId() == 'A000' then
    set PAtk = R2I ( PAtk * 2.2)
    endif
    if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
    set PAtk = R2I ( PAtk * 1.8)
    endif
    endif
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set PDef = udg_PhysDef[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set PDef = GetUnitAbilityLevel(uTarg, 'A006') * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
    set FinalDmg = 1
    endif
    if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set Accuracy = udg_Accuracy[GetPlayerId(GetOwningPlayer(uCaster))+1]
    set EvadeChance = udg_Evade[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set Accuracy = GetUnitAbilityLevel(uTarg, 'A00I') * 80
    set EvadeChance = GetUnitAbilityLevel(uTarg, 'A008') * 80
    endif
    set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
    if EvadeChance <= 5 then
    set EvadeChance = 5
    endif
    if EvadeChance >= 40 then
    set EvadeChance = 40
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= EvadeChance then
    set FinalDmg = 0
    call CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
     if Def ==  false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set ParryChance = udg_Parry[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set ParryChance = GetUnitAbilityLevel(uTarg, 'A009') * 80
    endif
    set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
    if ParryChance <= 5 then
    set ParryChance = 5
    endif
    if ParryChance >= 45 then
    set ParryChance = 45
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= ParryChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
    call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
    if GetUnitAbilityLevel(uTarg, 'A00G') == 2 and Def == false then
    if IsUnitType(uTarg, UNIT_TYPE_HERO) == true then
    set BlockChance = udg_Block[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
    set BlockChance = GetUnitAbilityLevel(uTarg, 'A00A') * 80
    endif
    set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
    if BlockChance <= 5 then
    set BlockChance = 5
    endif
    if BlockChance >= 50 then
    set BlockChance = 50
    endif
    set Random = GetRandomInt (1, 100)
    if Random <= BlockChance then
    set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
    call CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    set Def = true
    endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
    call CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    endif
    if Text1 ==  false then
    call CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
    set text = bj_lastCreatedTextTag
    set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
    set uTarg = null
    set uCaster = null
    set text = null
endfunction
А вообще стоит подумать над оптимизацией и как-то сделать это через цикл что-ли
и что изменилось, не замечаю)
раскрывать неумею)
DaeDR:
И вообще стрит вынести IsUnitType(uCaster, UNIT_TYPE_HERO)
local boolen b = IsUnitType(uCaster, UNIT_TYPE_HERO)
// и дальше не вытаскивать уже тип юнита
if b then
...
endif
хорошая мысль
Старый 13.04.2012, 18:24
DaeDR

offline
Опыт: 8,074
Активность:
И зачем делать так?
» Код
   if b then
        set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
    else
        set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
    endif
    if b then
        set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
    else
        set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
    endif
    if b then
        set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
    endif
Если проще так:
    if b then
        set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
        set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
        set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
        set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
        set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
    endif
Старый 13.04.2012, 18:28
Vadik29
Choice Battle 1.6а
offline
Опыт: 15,845
Активность:
вот с отступами,также провел оптимизацию
» код
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    local boolean b = IsUnitType(uCaster, UNIT_TYPE_HERO)
    if GetSpellAbilityId() == 'A000' then
        if b then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *20)
        else
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A002' then
        if b then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *12)
        else
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if GetSpellAbilityId() == 'A003' then
        if b then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *17)
        else
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        set FinalDispersion = GetRandomInt ((0 - Dispersion), (0 + Dispersion))
    endif
    if b then
        set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
    else
        set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
    endif
    if b then
        set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
    else
        set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
    endif
    if b then
        set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
    endif
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
        set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
        if GetSpellAbilityId() == 'A000' then
            set PAtk = R2I ( PAtk * 2.2)
        endif
        if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
            set PAtk = R2I ( PAtk * 1.8)
        endif
    endif
    if b then
        set PDef = udg_PhysDef[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set PDef = GetUnitAbilityLevel(uTarg, 'A006') * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
        set FinalDmg = 1
    endif
    if Def ==  false then
        if b then
            set Accuracy = udg_Accuracy[GetPlayerId(GetOwningPlayer(uCaster))+1]
            set EvadeChance = udg_Evade[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set Accuracy = GetUnitAbilityLevel(uTarg, 'A00I') * 80
            set EvadeChance = GetUnitAbilityLevel(uTarg, 'A008') * 80
        endif
        set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
        if EvadeChance <= 5 then
            set EvadeChance = 5
        endif
        if EvadeChance >= 40 then
            set EvadeChance = 40
        endif
        set Random = GetRandomInt (1, 100)
        if Random <= EvadeChance then
            set FinalDmg = 0
            set text = CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
            set Text1 = true
            set Def = true
        endif
    endif
    if Def ==  false then
        if b then
            set ParryChance = udg_Parry[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set ParryChance = GetUnitAbilityLevel(uTarg, 'A009') * 80
        endif
        set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
        if ParryChance <= 5 then
            set ParryChance = 5
        endif
        if ParryChance >= 45 then
            set ParryChance = 45
        endif
        set Random = GetRandomInt (1, 100)
        if Random <= ParryChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
            set text = CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set Text1 = true
            set Def = true
        endif
    endif
    if GetUnitAbilityLevel(uTarg, 'A00G') == 2 and Def == false then
        if b then
            set BlockChance = udg_Block[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set BlockChance = GetUnitAbilityLevel(uTarg, 'A00A') * 80
        endif
        set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
        if BlockChance <= 5 then
            set BlockChance = 5
        endif
        if BlockChance >= 50 then
            set BlockChance = 50
        endif
        set Random = GetRandomInt (1, 100)
        if Random <= BlockChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
            set text = CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set Text1 = true
            set Def = true
        endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
        set text = CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set Text1 = true
    endif
    if Text1 ==  false then
        set text = CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
endfunction

Отредактировано Vadik29, 13.04.2012 в 18:35.
Старый 13.04.2012, 18:29
DaeDR

offline
Опыт: 8,074
Активность:
Если я ничего не напутал, то начало функции улучшил слегка:
Надеюсь, хоть половина будет понятна
Еще чуть поправил
» Код
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    local boolean b = IsUnitType(uCaster, UNIT_TYPE_HERO)
    if b then
        set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
        set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
        set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
        // ====
        if GetSpellAbilityId() == 'A000' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *20)
        else
        if GetSpellAbilityId() == 'A002' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *12)
        else
        if GetSpellAbilityId() == 'A003' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *17)
        endif
        endif
	endif
        // ====
    else
        set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
        set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
        set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
        // ====
        if GetSpellAbilityId() == 'A000' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        else
        if GetSpellAbilityId() == 'A002' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        else
        if GetSpellAbilityId() == 'A003' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
	endif
	endif
        // ====
    endif
    set FinalDispersion = GetRandomInt ((-Dispersion), (Dispersion))
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
        set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
        if GetSpellAbilityId() == 'A000' then
            set PAtk = R2I ( PAtk * 2.2)
        endif
        if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
            set PAtk = R2I ( PAtk * 1.8)
        endif
    endif
    local boolean b2 = IsUnitType(uTarg, UNIT_TYPE_HERO)
    if b2 then
        set PDef = udg_PhysDef[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set PDef = GetUnitAbilityLevel(uTarg, 'A006') * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
        set FinalDmg = 1
    endif
    if Def ==  false then
        if b2 then
            set Accuracy = udg_Accuracy[GetPlayerId(GetOwningPlayer(uCaster))+1]
            set EvadeChance = udg_Evade[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set Accuracy = GetUnitAbilityLevel(uTarg, 'A00I') * 80
            set EvadeChance = GetUnitAbilityLevel(uTarg, 'A008') * 80
        endif
            set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
        if EvadeChance <= 5 then
            set EvadeChance = 5
        endif
        if EvadeChance >= 40 then
            set EvadeChance = 40
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= EvadeChance then
            set FinalDmg = 0
            call CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    if Def ==  false then
        if b2 then
            set ParryChance = udg_Parry[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set ParryChance = GetUnitAbilityLevel(uTarg, 'A009') * 80
        endif
            set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
        if ParryChance <= 5 then
            set ParryChance = 5
        endif
        if ParryChance >= 45 then
            set ParryChance = 45
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= ParryChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
            call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    if GetUnitAbilityLevel(uTarg, 'A00G') == 2 and Def == false then
        if b2 then
            set BlockChance = udg_Block[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set BlockChance = GetUnitAbilityLevel(uTarg, 'A00A') * 80
        endif
            set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
        if BlockChance <= 5 then
            set BlockChance = 5
        endif
        if BlockChance >= 50 then
            set BlockChance = 50
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= BlockChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
            call CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
        call CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set text = bj_lastCreatedTextTag
        set Text1 = true
    endif
    if Text1 ==  false then
        call CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set text = bj_lastCreatedTextTag
        set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
    set uTarg = null
    set uCaster = null
    set text = null
endfunction
DaeDR добавил:
Дальше уже "темный лес", который понятен только автору как и бывает в 80% случаях
Старый 13.04.2012, 18:42
Hate
конь вакуумный
offline
Опыт: 43,030
Активность:
DaeDR:
Если я ничего не напутал, то начало функции улучшил слегка:
Надеюсь, хоть половина будет понятна
» Код
function PhysStrikesMechanic takes unit uCaster, unit uTarg returns nothing
    local integer Dispersion
    local integer FinalDispersion
    local integer PAtk
    local integer Accuracy
    local integer Random
    local integer EvadeChance
    local integer ParryChance
    local integer BlockChance
    local integer PDef
    local integer Critical
    local integer CritChanceRed
    local integer CritChance
    local integer FinalDmg
    local boolean Def = false
    local boolean Text1 = false
    local texttag text
    local boolean b = IsUnitType(uCaster, UNIT_TYPE_HERO)
    if b then
        set PAtk = (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] + FinalDispersion)
        set CritChance = udg_CritChance[GetPlayerId(GetOwningPlayer(uCaster))+1]
        set CritChanceRed = udg_CritChanceRed[GetPlayerId(GetOwningPlayer(uTarg))+1]
        // ====
        if GetSpellAbilityId() == 'A000' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *20)
        endif
        if GetSpellAbilityId() == 'A002' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *12)
        endif
        if GetSpellAbilityId() == 'A003' then
            set Dispersion = ( (udg_PhysAttack[GetPlayerId(GetOwningPlayer(uCaster))+1] / 100) *17)
        endif
        // ====
    else
        set PAtk = ((GetUnitAbilityLevel(uCaster, 'A00E') * 80) + FinalDispersion)
        set CritChance = GetUnitAbilityLevel(uCaster, 'A00H') * 8
        set CritChanceRed = GetUnitAbilityLevel(uTarg, 'A00D') * 8
        // ====
        if GetSpellAbilityId() == 'A000' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        if GetSpellAbilityId() == 'A002' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        if GetSpellAbilityId() == 'A003' then
            set Dispersion = (((GetUnitAbilityLevel(uCaster, 'A00E') * 80) / 100) * 20)
        endif
        // ====
    endif
    set FinalDispersion = GetRandomInt ((-Dispersion), (Dispersion))
    set CritChance = CritChance - CritChanceRed
    if CritChance <= 0 then
        set CritChance = 1
    endif
    set Critical = GetRandomInt (1, 100)
    if Critical <= CritChance then
        if GetSpellAbilityId() == 'A000' then
            set PAtk = R2I ( PAtk * 2.2)
        endif
        if GetSpellAbilityId() == 'A002' or GetSpellAbilityId() == 'A003' then
            set PAtk = R2I ( PAtk * 1.8)
        endif
    endif
    local boolean b2 = IsUnitType(uTarg, UNIT_TYPE_HERO)
    if b2 then
        set PDef = udg_PhysDef[GetPlayerId(GetOwningPlayer(uTarg))+1]
    else
        set PDef = GetUnitAbilityLevel(uTarg, 'A006') * 80
    endif
    set FinalDmg = PAtk - PDef
    if FinalDmg <= 0 then
        set FinalDmg = 1
    endif
    if Def ==  false then
        if b2 then
            set Accuracy = udg_Accuracy[GetPlayerId(GetOwningPlayer(uCaster))+1]
            set EvadeChance = udg_Evade[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set Accuracy = GetUnitAbilityLevel(uTarg, 'A00I') * 80
            set EvadeChance = GetUnitAbilityLevel(uTarg, 'A008') * 80
        endif
            set EvadeChance = R2I ((EvadeChance - Accuracy) * 0.1)
        if EvadeChance <= 5 then
            set EvadeChance = 5
        endif
        if EvadeChance >= 40 then
            set EvadeChance = 40
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= EvadeChance then
            set FinalDmg = 0
            call CreateTextTagUnitBJ( "Уклон!", uTarg, 0, 10, 100.00, 100.00, 100.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    if Def ==  false then
        if b2 then
            set ParryChance = udg_Parry[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set ParryChance = GetUnitAbilityLevel(uTarg, 'A009') * 80
        endif
            set ParryChance = R2I ((ParryChance - Accuracy) * 0.1)
        if ParryChance <= 5 then
            set ParryChance = 5
        endif
        if ParryChance >= 45 then
            set ParryChance = 45
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= ParryChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 45))
            call CreateTextTagUnitBJ( ("|c005FFFFFПарир.!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    if GetUnitAbilityLevel(uTarg, 'A00G') == 2 and Def == false then
        if b2 then
            set BlockChance = udg_Block[GetPlayerId(GetOwningPlayer(uTarg))+1]
        else
            set BlockChance = GetUnitAbilityLevel(uTarg, 'A00A') * 80
        endif
            set BlockChance = R2I ((BlockChance - Accuracy) * 0.1)
        if BlockChance <= 5 then
            set BlockChance = 5
        endif
        if BlockChance >= 50 then
            set BlockChance = 50
        endif
            set Random = GetRandomInt (1, 100)
        if Random <= BlockChance then
            set FinalDmg = (FinalDmg - ((FinalDmg / 100) * 70))
            call CreateTextTagUnitBJ( ("|c0089ABFFБлок!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
            set text = bj_lastCreatedTextTag
            set Text1 = true
            set Def = true
        endif
    endif
    call UnitDamageTarget(uCaster, uTarg, I2R(FinalDmg), true, false, ATTACK_TYPE_CHAOS ,  DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    if Critical <= CritChance and Text1 == false then
        call CreateTextTagUnitBJ( ("|c00FFFF00Крит!|r" + I2S(FinalDmg)), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set text = bj_lastCreatedTextTag
        set Text1 = true
    endif
    if Text1 ==  false then
        call CreateTextTagUnitBJ( I2S(FinalDmg), uTarg, 0, 10, 100.00, 20.00, 20.00, 0 )
        set text = bj_lastCreatedTextTag
        set Text1 = true
    endif
    call SetTextTagVelocityBJ( text, 64, ( GetUnitFacing(uCaster)) )
    call SetTextTagPermanentBJ( text, false )
    call SetTextTagLifespanBJ(text,2)
    call SetTextTagFadepointBJ(text,0.0)
    set uTarg = null
    set uCaster = null
    set text = null
endfunction
DaeDR добавил:
Дальше уже "темный лес", который понятен только автору как и бывает в 80% случаях
=)
  1. высчитывается разброс урона (Dispersion) по типу одноручное(12% разброса)/двуручное(20%)/дальнее(17%)
  2. вычисляется чистая атака с разбросом
  3. вычисляется шанс на крит и уменьшение шанса крита
  4. к атаке с разбросом добавляется урон от крита (множитель 2.2 для одноручного и 1.8 для двуручного и дальнего)
  5. порезка урона по физ защите
  6. вычисление уклонения (нулевой урон)
  7. парирования (-45% урона при парировании)
  8. блока (-70% урона при блоке)
  9. итоговый урон
ты вообще сначала не рассчитал разброс)
Старый 13.04.2012, 18:47
Закрытая тема

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы можете скачивать файлы

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 07:16.