Advertisement
Guest User

checkskills.lua

a guest
Dec 17th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.50 KB | None | 0 0
  1. -- Print skill levels of a unit
  2. -- modified by gameboy17 from make-legendary by vjek
  3. local help = [====[
  4.  
  5. checkskills
  6. ==============
  7. Prints the level and exp of each of the unit's skills.
  8. Color is based on skill level.
  9. By default, only shows skills of Novice level or greater.
  10.  
  11. `-help`
  12. Print this message.
  13.  
  14. `-all`
  15. Do not hide skills below Novice level.
  16.  
  17. `-attr`
  18. Also print the unit's current and maximum attributes.
  19.  
  20. Cosmetic:
  21.  
  22. `-decimal`
  23. Show skill level to two decimal places rather than a separate Exp%.
  24.  
  25. `-nodim`
  26. Print attribute maximum values in same colors as current values.
  27.  
  28. `-altcol`
  29. Prints skills with same palette used for skills ingame.
  30. The default is more of a gradient.
  31.  
  32. ]====]
  33.  
  34. local utils=require('utils')
  35. validArgs = validArgs or utils.invert({
  36.  'help',
  37.  'unit',
  38.  'dabbling',
  39.  'all',
  40.  'decimal',
  41.  'attr',
  42.  'nodim',
  43.  'altcol'
  44. })
  45. local args = utils.processArgs({...}, validArgs)
  46.  
  47.  
  48. function main()
  49.  
  50.     if args.help then print(help); return; end
  51.  
  52.     local unit = tonumber(args.unit) and df.unit.find(tonumber(args.unit)) or dfhack.gui.getSelectedUnit(true)
  53.     if not unit then print("No unit - watch me swooce right out!"); return; end
  54.  
  55.     print(dfhack.TranslateName(unit.name))
  56.     PrintSkills(unit,args.all or args.dabbling)
  57.     if args.attr then
  58.         PrintAttrs(unit)
  59.     end
  60.  
  61. end
  62.  
  63.  
  64.  
  65. function PrintSkills(unit,showdabbling)
  66.     local soul = unit.status.current_soul
  67.     local skillid
  68.     local skillname
  69.     local skilllevel
  70.     local skillexp
  71.     local nextexp
  72.     local exppercent
  73.     for k,v in ipairs(soul.skills) do
  74.         skillid = v.id
  75.         skillname = df.job_skill.attrs[skillid].caption
  76.         skilllevel = v.rating
  77.         skillexp = v.experience
  78.         nextexp = 400+100*(skilllevel+1)
  79.         exppercent = math.floor(100*skillexp/nextexp)
  80.        
  81.         if skilllevel > 0 or showdabbling then
  82.             ColorByNumbers(skilllevel)
  83.             dfhack.print(string.format("\t%-20s", skillname, skilllevel, skillexp))
  84.             ColorByStatus(skilllevel)
  85.             dfhack.print("Lv  ")
  86.             ColorByNumbers(skilllevel)
  87.             dfhack.print(string.format("%2d", skilllevel))
  88.             if args.decimal then
  89.                 dfhack.print(string.format(".%02d\t", exppercent))
  90.             else
  91.                 ColorByStatus(skilllevel)
  92.                 dfhack.print("\tExp: ")
  93.                 ColorByNumbers(skilllevel)
  94.                 dfhack.print(string.format("%2d", exppercent).."%")
  95.             end
  96.             ColorByStatus(skilllevel)
  97.             dfhack.print(string.format("\t(%-4d/%4d)",skillexp,nextexp))
  98.             dfhack.color(COLOR_RESET)
  99.             print()
  100.         end
  101.     end
  102. end
  103.  
  104. function PrintAttrs(unit)
  105.     body = unit.body
  106.     soul = unit.status.current_soul
  107.     --local attrid
  108.     --local attrname
  109.     --local attrval
  110.     --local attrmax
  111.     --local attrlevel
  112.     --local attrpercent
  113.    
  114.     bodyattrnames = {"Strength","Agility","Toughness","Endurance","Recuperation","Disease Resistance"}
  115.     soulattrnames = {"Analytical Ability","Focus","Memory","Creativity","Intuition","Focus","Willpower","Patience","Spatial Sense","Kinesthetic Sense","Linguistic Ability","Empathy","Social Awareness"}
  116.    
  117.     -- printall(body.physical_attrs)
  118.     -- printall(bodyattrnames)
  119.     -- printall(soul.mental_attrs)
  120.     -- printall(soulattrnames)
  121.    
  122.     print("Body:")
  123.     for k,v in ipairs(body.physical_attrs) do
  124.         PrintAttr(v,bodyattrnames[k+1])
  125.     end
  126.     print("Soul:")
  127.     for k,v in ipairs(soul.mental_attrs) do
  128.         PrintAttr(v,soulattrnames[k+1])
  129.     end
  130.    
  131. end
  132.  
  133. function PrintAttr(attr,attrname)
  134.     if not attrname then return end
  135.    
  136.     local attrval = attr.value
  137.     local attrmax = attr.max_value
  138.     local attrpercent = math.floor(100*attrval/attrmax)
  139.     local attrlevel = math.floor((attrval-400)/100 - 1)
  140.  
  141.     ColorByAttr(attrval,attrname,false)
  142.     dfhack.print(string.format("\t%4d",attrval))
  143.     ColorByStatus(attrlevel)
  144.     dfhack.print("/")
  145.     ColorByAttr(attrmax,attrname,true)
  146.     dfhack.print(string.format("%-4d",attrmax))
  147.     ColorByAttr(attrval,attrname,false)
  148.     dfhack.print(string.format("  %-20s", attrname))
  149.     ColorByStatus(attrlevel)
  150.     dfhack.print("\tPotential: ")
  151.     ColorByPercent(attrpercent)
  152.     dfhack.print(string.format("%2d", attrpercent).."%")
  153.     dfhack.color(COLOR_RESET)
  154.     print()
  155. end
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. --Set print color based on level of skill
  163. function ColorByNumbers(lvl)
  164.     if not args.altcol then
  165.         if     lvl >19 then dfhack.color(COLOR_LIGHTMAGENTA)
  166.         elseif lvl >14 then dfhack.color(COLOR_LIGHTCYAN)
  167.         elseif lvl > 9 then dfhack.color(COLOR_LIGHTGREEN)
  168.         elseif lvl > 5 then dfhack.color(COLOR_YELLOW)
  169.         elseif lvl > 2 then dfhack.color(COLOR_BROWN)   --RED
  170.         elseif lvl > 0 then dfhack.color(COLOR_RED)     --BROWN
  171.         else                dfhack.color(COLOR_DARKGREY)
  172.         end
  173.     else
  174.         if     lvl >14 then dfhack.color(COLOR_LIGHTMAGENTA)
  175.         elseif lvl > 8 then dfhack.color(COLOR_LIGHTGREEN)
  176.         elseif lvl > 5 then dfhack.color(COLOR_LIGHTCYAN)
  177.         elseif lvl > 2 then dfhack.color(COLOR_GREEN)
  178.         elseif lvl > 1 then dfhack.color(COLOR_WHITE)
  179.         elseif lvl > 0 then dfhack.color(COLOR_LIGHTGRAY)
  180.         else                dfhack.color(COLOR_BROWN)
  181.         end
  182.     end
  183. end
  184.  
  185. --Set print color based on whether skill is dabbling, normal, or legendary
  186. function ColorByStatus(lvl)
  187.     if     lvl < 1 then dfhack.color(COLOR_DARKGREY)
  188.     elseif lvl <15 then dfhack.color(COLOR_LIGHTGRAY)
  189.     else                dfhack.color(COLOR_WHITE)
  190.     end
  191. end
  192. --dfhack.color(skilllevel==0 and COLOR_DARKGREY or COLOR_RESET)
  193.  
  194.  
  195.  
  196. --Set print color based on "level" of attribute
  197. --Switched some stuff around
  198. function ColorByAttrLvl(lvl)
  199.     if     lvl >19 then dfhack.color(COLOR_LIGHTMAGENTA)
  200.     elseif lvl >14 then dfhack.color(COLOR_LIGHTCYAN)
  201.     elseif lvl > 9 then dfhack.color(COLOR_LIGHTGREEN)
  202.     elseif lvl > 5 then dfhack.color(COLOR_YELLOW)
  203.     elseif lvl > 2 then dfhack.color(COLOR_BROWN)
  204.     elseif lvl > 0 then dfhack.color(COLOR_RED)
  205.     else                dfhack.color(COLOR_LIGHTRED)
  206.     end
  207. end
  208.  
  209.  
  210. --Set print color based on attribute value
  211. --Based on attribute ranges for dwarves
  212. function ColorByAttr(val,attr,dark)
  213.     local thresh
  214.     --Body
  215.     if attr == "Strength"       then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
  216.     if attr == "Agility"        then thresh = {1900,1650,1400,1150,651,401,151,0,-1} end
  217.     if attr == "Toughness"      then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
  218.     if attr == "Endurance"      then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  219.     if attr == "Recuperation"   then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  220.     if attr == "Disease Resistance" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  221.     --Soul
  222.     if attr == "Analytical Ability" then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
  223.     if attr == "Focus"          then thresh = {2542,2292,2042,1792,1293,1043,793,543,0} end
  224.     if attr == "Willpower"      then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  225.     if attr == "Creativity"     then thresh = {2250,2000,1751,1500,1001,751,501,251,0} end
  226.     if attr == "Intuition"      then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  227.     if attr == "Patience"       then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
  228.     if attr == "Memory"         then thresh = {2250,2000,1750,1500,1001,751,501,251,0} end
  229.     if attr == "Linguistic Ability" then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  230.     if attr == "Spatial Sense"  then thresh = {2542,2292,2042,1792,1293,1043,793,543,0} end
  231.     if attr == "Musicality"     then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  232.     if attr == "Kinesthetic Sense"  then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  233.     if attr == "Empathy"        then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  234.     if attr == "Social Awareness"   then thresh = {2000,1750,1500,1250,751,501,251,1,0} end
  235.  
  236.     if not thresh then thresh = {5000,5000,5000,5000,5000,5000,5000,5000,0} end
  237.    
  238.     local colors = {
  239.         COLOR_LIGHTMAGENTA,
  240.         COLOR_LIGHTCYAN,
  241.         COLOR_LIGHTGREEN,
  242.         COLOR_GREEN,
  243.         COLOR_YELLOW,
  244.         COLOR_BROWN,
  245.         COLOR_RED,
  246.         COLOR_LIGHTRED,
  247.         COLOR_DARKGREY
  248.     }
  249.     if dark and not args.nodim then colors = {
  250.         COLOR_MAGENTA,
  251.         COLOR_CYAN,
  252.         COLOR_GREEN,
  253.         COLOR_GREEN,
  254.         COLOR_BROWN,
  255.         COLOR_DARKGREY,
  256.         COLOR_DARKGREY,
  257.         COLOR_DARKGREY,
  258.         COLOR_BLACK
  259.     } end
  260.    
  261. --  print(attr)
  262. --  print(val)
  263. --  printall(thresh)
  264.    
  265.     for i = 0, 9, 1 do
  266.         if val >= thresh[i+1] then
  267.             dfhack.color(colors[i+1])
  268.             break
  269.         end
  270.     end
  271.    
  272. end
  273.  
  274.  
  275. --Set print color based on range from 0..100
  276. --Intended for attribute potential percentage
  277. function ColorByPercent(pct)
  278.     if     pct >=100 then dfhack.color(COLOR_LIGHTMAGENTA)
  279.     elseif pct >= 85 then dfhack.color(COLOR_LIGHTCYAN)
  280.     elseif pct >= 70 then dfhack.color(COLOR_LIGHTGREEN)
  281.     elseif pct >= 40 then dfhack.color(COLOR_YELLOW)
  282.     elseif pct >= 20 then dfhack.color(COLOR_RED)
  283.     elseif pct >   5 then dfhack.color(COLOR_BROWN)
  284.     else                  dfhack.color(COLOR_DARKGREY)
  285.     end
  286. end
  287.  
  288.  
  289. --Execution starts
  290.  
  291. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement