- 23 Фев 2019
- 3
- 0
- Проект
- Holy Wat
Решил я создать переключаемую способность, которая будет работать как пассивка бристлбека, только без иголок. Всё значит написал, переключение работает, модификатор накладывается, только урон не режется, один и тот же проходит. Не подскажите, что не так?
Код:
"defend"
{
"BaseClass" "ability_datadriven"
"AbilityTextureName" "defend"
"MaxLevel" "1"
"AbilityBehavior" "DOTA_ABILITY_BEHAVIOR_NO_TARGET | DOTA_ABILITY_BEHAVIOR_TOGGLE | DOTA_ABILITY_BEHAVIOR_IMMEDIATE"
"AbilitySpecial"
{
"01"
{
"var_type" "FIELD_INTEGER"
"side_damage_reduction" "8 12 16 20"
}
"02"
{
"var_type" "FIELD_INTEGER"
"back_damage_reduction" "16 24 32 40"
}
"03"
{
"var_type" "FIELD_INTEGER"
"side_angle" "110"
}
"04"
"var_type" "FIELD_INTEGER"
"back_angle" "70"
}
}
"OnToggleOn"
{
"ApplyModifier"
{
"ModifierName" "bristleback"
"Target" "CASTER"
}
}
"OnToggleOff"
{
"RemoveModifier"
{
"ModifierName" "bristleback"
"Target"
{
"Center" "CASTER"
"Flags" "DOTA_UNIT_TARGET_FLAG_DEAD"
}
}
}
"Modifiers"
{
"bristleback"
{
"Passive" "1"
"IsHidden" "0"
"IsDebuff" "0"
"EffectAttachType" "follow_origin"
"OnTakeDamage"
// "%attack_damage" is set to the damage value after mitigation
{
"RunScript"
{
"ScriptFile" "bristleback.lua"
"Function" "bristleback_takedamage"
"Damage" "%attack_damage"
}
}
}
}
}
Lua:
function bristleback_takedamage(params)
-- Create the threshold counter on the unit if it doesn't exist.
if params.unit.quill_threshold_counter == nil then
params.unit.quill_threshold_counter = 0.0
end
local ability = params.ability
local back_reduction_percentage = ability:GetLevelSpecialValueFor("back_damage_reduction", ability:GetLevel() - 1) / 100
local side_reduction_percentage = ability:GetLevelSpecialValueFor("side_damage_reduction", ability:GetLevel() - 1) / 100
-- The y value of the angles vector contains the angle we actually want: where units are directionally facing in the world.
local victim_angle = params.unit:GetAnglesAsVector().y
local origin_difference = params.unit:GetAbsOrigin() - params.attacker:GetAbsOrigin()
-- Get the radian of the origin difference between the attacker and Bristleback. We use this to figure out at what angle the attacker is at relative to Bristleback.
local origin_difference_radian = math.atan2(origin_difference.y, origin_difference.x)
-- Convert the radian to degrees.
origin_difference_radian = origin_difference_radian * 180
local attacker_angle = origin_difference_radian / math.pi
-- See the opening block comment for why I do this. Basically it's to turn negative angles into positive ones and make the math simpler.
attacker_angle = attacker_angle + 180.0
-- Finally, get the angle at which Bristleback is facing the attacker.
local result_angle = attacker_angle - victim_angle
result_angle = math.abs(result_angle)
-- Check for the side angle first. If the attack doesn't pass this check, we don't have to do back angle calculations.
if result_angle >= (180 - (ability:GetSpecialValueFor("side_angle") / 2)) and result_angle <= (180 + (ability:GetSpecialValueFor("side_angle") / 2)) then
-- Check for back angle. If this check doesn't pass, then do side angle "damage reduction".
if result_angle >= (180 - (ability:GetSpecialValueFor("back_angle") / 2)) and result_angle <= (180 + (ability:GetSpecialValueFor("back_angle") / 2)) then
-- Check if the reduced damage is lethal
if((params.unit:GetHealth() - (params.Damage * (1 - back_reduction_percentage))) >= 1) then
-- This is the actual "damage reduction".
params.unit:SetHealth((params.Damage * back_reduction_percentage) + params.unit:GetHealth())
end
else
-- Check if the reduced damage is lethal
if((params.unit:GetHealth() - (params.Damage * (1 - side_reduction_percentage))) >= 1) then
-- This is the actual "damage reduction".
params.unit:SetHealth((params.Damage * side_reduction_percentage) + params.unit:GetHealth())
-- Play the sound on Bristleback.
end
end
end
end
Последнее редактирование: