2017-01-05 1 views
3
function GetDamage(spell, unit) 
    if spell == _Q and (isReady(_Q) or qActive) and not HasItem(3025) and not HasItem(3100) and not HasItem(3057) and not HasItem(3078) then 
     return myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3057) or sheenActive) then 
     return myHero:CalcDamage(unit, myHero.damage) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3025) or fActive) then 
     return myHero:CalcDamage(unit, myHero.damage) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3100) or lActive) then 
     return myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    elseif spell == _Q and (isReady(_Q) or qActive) and (HasItem(3078) or tActive) then 
     return myHero:CalcDamage(unit, (myHero.damage * 2)) + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    elseif spell == _E and isReady(_E) then 
     return myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6))) 
    else 
     return 0 
    end 
end 

이 코드는 x 개의 적에게 피해를 입 힙니다.하지만 의도 한대로 작동하는 동안 비효율적이며 추악한 것처럼 보입니다. 조금 다르게 작동하고 싶습니다. 그런 식으로 코딩하는 방법을 모르겠습니다. 나는 그것이 내가 isReady(spell) 수익을 제공 할 수있는 총 손상을 반환하고 싶은 비슷한 예를 GetDamage(all) 또는 뭔가를 할 경우 내가 할 싶은 무엇더 깨끗하고 효율적인 방법을 찾고

입니다 즉 qe 그것의 전체를 반환 할 준비가 주문하는 경우는 true qe 만 제공되었거나 모두 준비가 되었다면 추가로 모든 것을 반환 할 수 있습니다. 또한 r의 손상을 알 필요가 있으면 GetDamage(_R)을 계속 수행 할 수 있습니다.

필요한 결과를 얻으 려면 테이블을 사용하거나 더 효율적인 방법으로 더 깨끗한 방법이 있습니까? 현재 GetDamage(spell) + GetDamage(spell2) + GetDamage(spell3) 등을 사용하는 것은 매우 나쁜 코딩처럼 보입니다.

답변

2

새로운 주문 "ALL"

function GetDamage(spell, unit) 
    local result = 0 
    if (spell == "ALL" or spell == _Q) and (isReady(_Q) or qActive) then 
     local bonus = 0 
     if (HasItem(3057) or sheenActive) then 
     bonus = myHero:CalcDamage(unit, myHero.damage) 
     elseif (HasItem(3025) or fActive) then 
     bonus = myHero:CalcDamage(unit, myHero.damage) 
     elseif (HasItem(3100) or lActive) then 
     bonus = myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) 
     elseif (HasItem(3078) or tActive) then 
     bonus = myHero:CalcDamage(unit, (myHero.damage * 2)) 
     end 
     result = result + bonus + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
    end 
    if (spell == "ALL" or spell == _E) and isReady(_E) then 
     result = result + myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6))) 
    end 
    return result 
end 

사용 예를 소개 :

dmg = GetDamage("ALL", unit) 
dmg = GetDamage(_Q, unit) 
dmg = GetDamage(_E, unit) 

편집 : 주문과 함께 테이블을 사용하여 동일한을 구현하는 또 다른 방법이있다

,745 : 값으로 키와 같은 기능
spell_dmg_func = { 
    [_Q] = 
     function(unit) 
     if (isReady(_Q) or qActive) then 
      local bonus = 0 
      if (HasItem(3057) or sheenActive) then 
       bonus = myHero:CalcDamage(unit, myHero.damage) 
      elseif (HasItem(3025) or fActive) then 
       bonus = myHero:CalcDamage(unit, myHero.damage) 
      elseif (HasItem(3100) or lActive) then 
       bonus = myHero:CalcMagicDamage(unit, ((myHero.damage * 0.75) + (myHero.ap * 0.5))) 
      elseif (HasItem(3078) or tActive) then 
       bonus = myHero:CalcDamage(unit, (myHero.damage * 2)) 
      end 
      return bonus + myHero:CalcDamage(unit, ((((myHero:GetSpellData(_Q).level * 20) + 10) + myHero.totalDamage) + qStacks)) 
     end 
     end, 
    [_E] = 
     function(unit) 
     if isReady(_E) then 
      return myHero:CalcMagicDamage(unit, (((myHero:GetSpellData(_E).level * 40) + 15) + (myHero.ap * 0.6))) 
     end 
     end, 
} 

function GetDamage(spell, unit) 
    if spells == "ALL" then 
     local sum = 0 
     for spell, func in pairs(spell_dmg_func) do 
     sum = sum + (func(unit) or 0) 
     end 
     return sum 
    else 
     return spell_dmg_func[spell](unit) or 0 
    end 
end 
+0

감사합니다. 그러나이 기능을 코딩하는 가장 효율적인 방법입니까? 아니면 더 깨끗한 방법이 있다고 생각합니까? – loveroflua

+0

@loveroflua - 답변 됨. –

+0

완벽이 내가 정확히 당신을 위해 무엇을 찾고 있었는지 고마워요. – loveroflua

관련 문제