What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Need someone to translate some addon code into c#

handnavi

Well-Known Member
Joined
Jan 15, 2010
Messages
2,489
Reaction score
55
Hey folks,

i'd like to have a function, that calculates the time to die of my current target.
I've found a addon that does the same - but somehow i am to dumb to do it on my own.

Code:
  -- VARIABLES

  --first lookup percentage
  local first_life  
  local first_life_max
  --first time target seen
  local first_time
  --current
  local current_life
  local current_time

Code:
--calculate the time to death
  local function calculate_time_to_death()
    if current_life == 0 then
      am("TTD: "..UnitName("target").." is dead!")
      if script_running == 1 then
        stop_this("target is dead")
      end
    else
      local time_diff = current_time-first_time
      local hp_diff = first_life-current_life
      if hp_diff > 0 then
        -- Rule of three (Dreisatz): 
        -- If in a given timespan a certain value of damage is done, what timespan is needed to do 100% damage?
        -- The longer the timespan the more precise the prediction
        -- time_diff/hp_diff = x/first_life_max 
        -- x = time_diff*first_life_max/hp_diff
        local full_time = time_diff*first_life_max/hp_diff
        --if unit was not at 100% at first time seen this is very important we need to calculate backwards in time then too
        -- second rule of three needed
        --if first_life == max life this will be 0 but otherwise a time will be the result
        local past_first_time = (first_life_max-first_life)*time_diff/hp_diff
        calc_time = first_time-past_first_time+full_time-current_time
        --SecondsToTime can only display values >= 1
        if calc_time < 1 then
          calc_time = 1
        end
        local time_to_die = SecondsToTime(calc_time)
        local fight_length
        local dps
        if show_dps == 1 then
          dps = floor(hp_diff/time_diff)
          dps = " (DPS "..dps..")"
        else
          dps = ""
        end
        if show_fightlength == 1 then
          fight_length = SecondsToTime(full_time)
          fight_length = " after "..fight_length
        else
          fight_length = ""
        end
        last_string = "TTD: "..UnitName("target").." dies in "..time_to_die..fight_length..dps
        am(last_string)
        
      elseif hp_diff < 0 then
        --unit has healed, reseting the initial values
        first_life = current_life
        first_time = current_time
        am("TTD: "..UnitName("target").." has healed. :/")
      else
        if current_life == first_life_max then
          --since unit is at full health we can reset the time and hp values
          --thus data will be tracked from the point on when the unit starts to loose life
          first_life = current_life
          first_time = current_time
          am("TTD: "..UnitName("target").." is at full health.")
        else
          --no damage occured in the timespan
          --do nothing but wait
        end
      end
    end
  end

Maybe someone has got nothing to do and can help me out? ^^
 
not that hard :)
I'll give u a working version in the evening (10 pm?)
Contact me on skype
It's only a little bit of math, very simple.
Do u need multi-target support?!? (all mobs around me, only mobs targetting me or my party, only current target?)
What do u need as return-value? int,uint, timespan?
 
not that hard :)
I'll give u a working version in the evening (10 pm?)
Contact me on skype
It's only a little bit of math, very simple.
Do u need multi-target support?!? (all mobs around me, only mobs targetting me or my party, only current target?)
What do u need as return-value? int,uint, timespan?

Wow, thanks alot!
I tried it - but couldnt solve it... :(

I need that only for my currenttarget :-)
Best would be an int.
 
Back
Top