Commit f45acd8ab38656f337785682497332c1c625edec

Authored by dg
1 parent 278f67b7

betetr tooltip compare



git-svn-id: http://svn.net-core.org/repos/t-engine4@3561 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -240,24 +240,26 @@ function _M:getTextualDesc(compare_with)
240 240
241 241 -- Stop here if unided
242 242 if not self:isIdentified() then return desc end
243   -
244   - local compare_fields = function(item1, items, infield, field, outformat, text, mod, isinversed)
  243 +
  244 + local compare_fields = function(item1, items, infield, field, outformat, text, mod, isinversed, isdiffinversed, add_table)
  245 + add_table = add_table or {}
245 246 mod = mod or 1
246 247 isinversed = isinversed or false
  248 + isdiffinversed = isdiffinversed or false
247 249 local ret = tstring{}
248 250 local added = 0
249 251 local add = false
250 252 ret:add(text)
251 253 if isinversed then
252   - ret:add((item1[field] or 0) > 0 and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((item1[field] or 0) * mod), {"color", "LAST"})
  254 + ret:add(((item1[field] or 0) + (add_table[field] or 0)) > 0 and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) + (add_table[field] or 0)) * mod), {"color", "LAST"})
253 255 else
254   - ret:add((item1[field] or 0) < 0 and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((item1[field] or 0) * mod), {"color", "LAST"})
  256 + ret:add(((item1[field] or 0) + (add_table[field] or 0)) < 0 and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) + (add_table[field] or 0)) * mod), {"color", "LAST"})
255 257 end
256 258 if item1[field] then
257 259 add = true
258 260 end
259 261 for i=1, #items do
260   - if items[i][infield] and items[i][infield][field] and items[i][infield][field] ~= (item1[field] or 0) then
  262 + if items[i][infield] and items[i][infield][field] then
261 263 if added == 0 then
262 264 ret:add(" (")
263 265 elseif added > 1 then
... ... @@ -265,10 +267,14 @@ function _M:getTextualDesc(compare_with)
265 267 end
266 268 added = added + 1
267 269 add = true
268   - if isinversed then
269   - ret:add(items[i][infield][field] < (item1[field] or 0) and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) - items[i][infield][field]) * mod), {"color", "LAST"})
  270 + if items[i][infield][field] ~= (item1[field] or 0) then
  271 + if isdiffinversed then
  272 + ret:add(items[i][infield][field] < (item1[field] or 0) and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) - items[i][infield][field]) * mod), {"color", "LAST"})
  273 + else
  274 + ret:add(items[i][infield][field] > (item1[field] or 0) and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) - items[i][infield][field]) * mod), {"color", "LAST"})
  275 + end
270 276 else
271   - ret:add(items[i][infield][field] > (item1[field] or 0) and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format(((item1[field] or 0) - items[i][infield][field]) * mod), {"color", "LAST"})
  277 + ret:add("-")
272 278 end
273 279 end
274 280 end
... ... @@ -280,7 +286,7 @@ function _M:getTextualDesc(compare_with)
280 286 desc:add(true)
281 287 end
282 288 end
283   -
  289 +
284 290 local compare_table_fields = function(item1, items, infield, field, outformat, text, kfunct, mod, isinversed)
285 291 mod = mod or 1
286 292 isinversed = isinversed or false
... ... @@ -296,7 +302,7 @@ function _M:getTextualDesc(compare_with)
296 302 end
297 303 end
298 304 for i=1, #items do
299   - if items[i][infield] and items[i][infield][field] and items[i][infield][field] ~= (item1[field] or 0) then
  305 + if items[i][infield] and items[i][infield][field] then
300 306 for k, v in pairs(items[i][infield][field]) do
301 307 tab[k] = tab[k] or {}
302 308 tab[k][i + 1] = v
... ... @@ -316,16 +322,20 @@ function _M:getTextualDesc(compare_with)
316 322 add = true
317 323 end
318 324 for kk, vv in pairs(v) do
319   - if kk > 1 and (v[1] or 0) ~= vv then
  325 + if kk > 1 then
320 326 if count == 0 then
321 327 ret:add("(")
322 328 elseif count > 0 then
323 329 ret:add(" / ")
324 330 end
325   - if isinversed then
326   - ret:add((v[1] or 0) > vv and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((v[1] or 0) - vv), {"color","LAST"})
  331 + if vv ~= (v[1] or 0) then
  332 + if isinversed then
  333 + ret:add((v[1] or 0) > vv and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((v[1] or 0) - vv), {"color","LAST"})
  334 + else
  335 + ret:add((v[1] or 0) < vv and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((v[1] or 0) - vv), {"color","LAST"})
  336 + end
327 337 else
328   - ret:add((v[1] or 0) < vv and {"color","RED"} or {"color","LIGHT_GREEN"}, outformat:format((v[1] or 0) - vv), {"color","LAST"})
  338 + ret:add("-")
329 339 end
330 340 add = true
331 341 count = count + 1
... ... @@ -336,32 +346,35 @@ function _M:getTextualDesc(compare_with)
336 346 end
337 347 ret:add(kfunct(k))
338 348 end
339   -
  349 +
340 350 if add then
341 351 desc:merge(ret)
342 352 desc:add(true)
343 353 end
344 354 end
345 355
346   - local desc_combat = function(combat, compare_with, field)
  356 + local desc_combat = function(combat, compare_with, field, add_table)
  357 + add_table = add_table or {}
  358 + add_table.dammod = add_table.dammod or {}
347 359 combat = combat[field] or {}
348 360 compare_with = compare_with or {}
349 361 local dm = {}
350 362 for stat, i in pairs(combat.dammod or {}) do
351   - dm[#dm+1] = ("%d%% %s"):format(i * 100, Stats.stats_def[stat].short_name:capitalize())
  363 + dm[#dm+1] = ("%d%% %s"):format((i + (add_table.dammod[stat] or 0)) * 100, Stats.stats_def[stat].short_name:capitalize())
352 364 end
353 365 if #dm > 0 or combat.dam then
354   - desc:add(("Base power: %.1f - %.1f"):format(combat.dam or 0, (combat.damrange or 1.1) * (combat.dam or 0)), true)
  366 + desc:add(("Base power: %.1f - %.1f"):format((combat.dam or 0) + (add_table.dam or 0), ((combat.damrange or 1.1) + (add_table.damrange or 1.1)) * ((combat.dam or 0) + (add_table.dam or 0))), true)
355 367 desc:add(("Uses stat%s: %s"):format(#dm > 1 and "s" or "",table.concat(dm, ', ')), true)
356 368 local col = lpeg.match("#" * lpeg.C((lpeg.R"AZ" + "_")^3) * "#", combat.damtype and DamageType:get(combat.damtype) and DamageType:get(combat.damtype).text_color or "#GREY#")
357 369 desc:add("Damage type: ",col and {"color",col} or {"color","GREY"},DamageType:get(combat.damtype or DamageType.PHYSICAL).name:capitalize(),{"color","LAST"}, true)
358 370 end
359   -
360   - compare_fields(combat, compare_with, field, "atk", "%+d", "Accuracy: ")
361   - compare_fields(combat, compare_with, field, "apr", "%+d", "Armor Penetration: ")
362   - compare_fields(combat, compare_with, field, "physcri", "%+d%%", "Physical crit. chance: ")
363   -
364   - compare_fields(combat, compare_with, field, "range", "%+d", "Firing range: ")
  371 +
  372 + compare_fields(combat, compare_with, field, "atk", "%+d", "Accuracy: ", 1, false, false, add_table)
  373 + compare_fields(combat, compare_with, field, "apr", "%+d", "Armor Penetration: ", 1, false, false, add_table)
  374 + compare_fields(combat, compare_with, field, "physcri", "%+d%%", "Physical crit. chance: ", 1, false, false, add_table)
  375 + compare_fields(combat, compare_with, field, "physspeed", "%.0f%%", "Attack speed: ", 100, false, true, add_table)
  376 +
  377 + compare_fields(combat, compare_with, field, "range", "%+d", "Firing range: ", 1, false, false, add_table)
365 378
366 379 if combat.talent_on_hit then
367 380 for tid, data in pairs(combat.talent_on_hit) do
... ... @@ -377,14 +390,14 @@ function _M:getTextualDesc(compare_with)
377 390 desc:add("When used from stealth a simple attack with it will not break stealth.", true)
378 391 end
379 392
380   - compare_fields(combat, compare_with, field, "travel_speed", "%+d%%", "Travel speed: ")
  393 + compare_fields(combat, compare_with, field, "travel_speed", "%+d%%", "Travel speed: ", 1, false, false, add_table)
381 394
382   - compare_table_fields(combat, compare_with, field, "melee_project", "%+d", "Damage on strike(melee): ", function(item)
  395 + compare_table_fields(combat, compare_with, field, "melee_project", "%+d", "Damage on strike(melee): ", function(item)
383 396 local color = DamageType.dam_def[item].text_color and DamageType.dam_def[item].text_color:gsub("#","") or "GREY"
384 397 return {"color",color},(" %s"):format(DamageType.dam_def[item].name),{"color","LAST"}
385 398 end)
386   -
387   - compare_table_fields(combat, compare_with, field, "inc_damage_type", "%+d%%", "Damage against: ", function(item)
  399 +
  400 + compare_table_fields(combat, compare_with, field, "inc_damage_type", "%+d%%", "Damage against: ", function(item)
388 401 local _, _, t, st = item:find("^([^/]+)/?(.*)$")
389 402 if st and st ~= "" then
390 403 return st
... ... @@ -401,42 +414,42 @@ function _M:getTextualDesc(compare_with)
401 414 compare_fields(w, compare_with, field, "combat_apr", "%+d", "Armor penetration: ")
402 415 compare_fields(w, compare_with, field, "combat_physcrit", "%+d%%", "Physical crit. chance: ")
403 416 compare_fields(w, compare_with, field, "combat_dam", "%+d", "Physical power: ")
404   -
  417 +
405 418 compare_fields(w, compare_with, field, "combat_armor", "%+d", "Armor: ")
406 419 compare_fields(w, compare_with, field, "combat_def", "%+d", "Defense: ")
407 420 compare_fields(w, compare_with, field, "combat_def_ranged", "%+d", "Ranged Defense: ")
408   -
  421 +
409 422 compare_fields(w, compare_with, field, "fatigue", "%+d%%", "Fatigue: ", 1, true)
410   -
411   - compare_table_fields(w, compare_with, field, "inc_stats", "%+d", "Changes stats: ", function(item)
  423 +
  424 + compare_table_fields(w, compare_with, field, "inc_stats", "%+d", "Changes stats: ", function(item)
412 425 return (" %s"):format(Stats.stats_def[item].short_name:capitalize())
413 426 end)
414   -
415   - compare_table_fields(w, compare_with, field, "melee_project", "%d", "Damage on hit(melee): ", function(item)
  427 +
  428 + compare_table_fields(w, compare_with, field, "melee_project", "%d", "Damage on hit(melee): ", function(item)
416 429 local color = DamageType.dam_def[item].text_color and DamageType.dam_def[item].text_color:gsub("#","") or "GREY"
417 430 return {"color",color},(" %s"):format(DamageType.dam_def[item].name),{"color","LAST"}
418 431 end)
419   -
420   - compare_table_fields(w, compare_with, field, "ranged_project", "%d", "Damage on hit(ranged): ", function(item)
  432 +
  433 + compare_table_fields(w, compare_with, field, "ranged_project", "%d", "Damage on hit(ranged): ", function(item)
421 434 local color = DamageType.dam_def[item].text_color and DamageType.dam_def[item].text_color:gsub("#","") or "GREY"
422 435 return {"color",color},(" %s"):format(DamageType.dam_def[item].name),{"color","LAST"}
423 436 end)
424   -
425   - compare_table_fields(w, compare_with, field, "on_melee_hit", "%d", "Damage when hit: ", function(item)
  437 +
  438 + compare_table_fields(w, compare_with, field, "on_melee_hit", "%d", "Damage when hit: ", function(item)
426 439 local color = DamageType.dam_def[item].text_color and DamageType.dam_def[item].text_color:gsub("#","") or "GREY"
427 440 return {"color",color},(" %s"):format(DamageType.dam_def[item].name),{"color","LAST"}
428 441 end)
429   -
  442 +
430 443 compare_table_fields(w, compare_with, field, "resists", "%+d%%", "Changes resistances: ", function(item)
431 444 local col = lpeg.match("#" * lpeg.C((lpeg.R"AZ" + "_")^3) * "#", DamageType.dam_def[item] and DamageType.dam_def[item].text_color or "#GREY#")
432 445 return col and {"color",col} or {"color","GREY"}, (" %s"):format(item == "all" and "all" or DamageType.dam_def[item].name), {"color","LAST"}
433 446 end)
434   -
  447 +
435 448 compare_table_fields(w, compare_with, field, "resists_cap", "%+d%%", "Changes resistances cap: ", function(item)
436 449 local col = lpeg.match("#" * lpeg.C((lpeg.R"AZ" + "_")^3) * "#", DamageType.dam_def[item] and DamageType.dam_def[item].text_color or "#GREY#")
437 450 return col and {"color",col} or {"color","GREY"}, (" %s"):format(item == "all" and "all" or DamageType.dam_def[item].name), {"color","LAST"}
438 451 end)
439   -
  452 +
440 453 compare_table_fields(w, compare_with, field, "inc_damage", "%+d%%", "Changes damage: ", function(item)
441 454 local col = lpeg.match("#" * lpeg.C((lpeg.R"AZ" + "_")^3) * "#", DamageType.dam_def[item] and DamageType.dam_def[item].text_color or "#GREY#")
442 455 return col and {"color",col} or {"color","GREY"}, (" %s"):format(item == "all" and "all" or DamageType.dam_def[item].name), {"color","LAST"}
... ... @@ -487,84 +500,80 @@ function _M:getTextualDesc(compare_with)
487 500 desc:add(("Allows you to breathe in: %s."):format(table.concat(ts, ', ')), true)
488 501 end
489 502 end
490   -
  503 +
491 504 compare_fields(w, compare_with, field, "combat_critical_power", "%+.2f%%", "Critical mult.: ")
492   -
  505 +
493 506 compare_fields(w, compare_with, field, "disarm_bonus", "%+d", "Trap disarming bonus: ")
494 507 compare_fields(w, compare_with, field, "inc_stealth", "%+d", "Stealth bonus: ")
495 508 compare_fields(w, compare_with, field, "max_encumber", "%+d", "Maximum encumberance: ")
496   -
  509 +
497 510 compare_fields(w, compare_with, field, "combat_physresist", "%+d", "Physical save: ")
498 511 compare_fields(w, compare_with, field, "combat_spellresist", "%+d", "Spell save: ")
499 512 compare_fields(w, compare_with, field, "combat_mentalresist", "%+d", "Mental save: ")
500   -
  513 +
501 514 compare_fields(w, compare_with, field, "blind_immune", "%+d%%", "Blindness immunity: ", 100)
502 515 compare_fields(w, compare_with, field, "poison_immune", "%+d%%", "Poison immunity: ", 100)
503 516 compare_fields(w, compare_with, field, "disease_immune", "%+d%%", "Disease immunity: ", 100)
504 517 compare_fields(w, compare_with, field, "cut_immune", "%+d%%", "Cut immunity: ", 100)
505   -
  518 +
506 519 compare_fields(w, compare_with, field, "silence_immune", "%+d%%", "Silence immunity: ", 100)
507 520 compare_fields(w, compare_with, field, "disarm_immune", "%+d%%", "Disarm immunity: ", 100)
508 521 compare_fields(w, compare_with, field, "confusion_immune", "%+d%%", "Confusion immunity: ", 100)
509 522 compare_fields(w, compare_with, field, "pin_immune", "%+d%%", "Pinning immunity: ", 100)
510   -
  523 +
511 524 compare_fields(w, compare_with, field, "stun_immune", "%+d%%", "Stun/Freeze immunity: ", 100)
512 525 compare_fields(w, compare_with, field, "fear_immune", "%+d%%", "Fear immunity: ", 100)
513 526 compare_fields(w, compare_with, field, "knockback_immune", "%+d%%", "Knockback immunity: ", 100)
514 527 compare_fields(w, compare_with, field, "instakill_immune", "%+d%%", "Instant-death immunity: ", 100)
515 528 compare_fields(w, compare_with, field, "teleport_immune", "%+d%%", "Teleport immunity: ", 100)
516   -
  529 +
517 530 compare_fields(w, compare_with, field, "life_regen", "%+.2f", "Hitpoints each turn: ")
518 531 compare_fields(w, compare_with, field, "stamina_regen", "%+.2f", "Stamina each turn: ")
519 532 compare_fields(w, compare_with, field, "mana_regen", "%+.2f", "Mana each turn: ")
520   -
  533 +
521 534 compare_fields(w, compare_with, field, "stamina_regen_on_hit", "%+.2f", "Stamina when hit: ")
522 535 compare_fields(w, compare_with, field, "mana_regen_on_hit", "%+.2f", "Mana when hit: ")
523 536 compare_fields(w, compare_with, field, "equilibrium_regen_on_hit", "%+.2f", "Equilibrium when hit: ")
524   -
  537 +
525 538 compare_fields(w, compare_with, field, "max_life", "%+.2f", "Maximum life: ")
526 539 compare_fields(w, compare_with, field, "max_mana", "%+.2f", "Maximum mana: ")
527 540 compare_fields(w, compare_with, field, "max_stamina", "%+.2f", "Maximum stamina: ")
528   -
  541 +
529 542 compare_fields(w, compare_with, field, "combat_spellpower", "%+d", "Spellpower: ")
530 543 compare_fields(w, compare_with, field, "combat_spellcrit", "%+d%%", "Spell crit. chance: ")
531   -
  544 +
532 545 compare_fields(w, compare_with, field, "lite", "%+d", "Light radius: ")
533 546 compare_fields(w, compare_with, field, "infravision", "%+d", "Infravision radius: ")
534 547 compare_fields(w, compare_with, field, "heightened_senses", "%+d", "Heightened senses radius: ")
535   -
  548 +
536 549 compare_fields(w, compare_with, field, "see_invisible", "%+d", "See invisible: ")
537 550 compare_fields(w, compare_with, field, "invisible", "%+d", "Invisibility: ")
538   -
  551 +
539 552 compare_fields(w, compare_with, field, "movement_speed", "%+d%%", "Movement speed: ", 100)
540 553 compare_fields(w, compare_with, field, "combat_physspeed", "%+d%%", "Combat speed: ", 100)
541 554 compare_fields(w, compare_with, field, "combat_spellspeed", "%+d%%", "Casting speed: ", 100)
542   -
  555 +
543 556 compare_fields(w, compare_with, field, "healing_factor", "%+d%%", "Healing mod.: ", 100)
544   -
545   - compare_fields(w, compare_with, field, "life_leech_chance", "%+d%%", "Life leech chance: ")
  557 +
  558 + compare_fields(w, compare_with, field, "life_leech_chance", "%+d%%", "Life leech chance: ")
546 559 compare_fields(w, compare_with, field, "life_leech_value", "%+d%%", "Life leech: ")
547   -
  560 +
548 561 compare_fields(w, compare_with, field, "size_category", "%+d", "Size category: ")
549   -
550   - --compare_fields(w, compare_with, field, "mana_regen", "%+d", "a: ")
551   -
552   - if w and w.combat then
553   - desc:add({"color","YELLOW"}, "When used to modify unarmed attacks:", {"color", "LAST"}, true)
554   -
555   - -- clone the table to show modified values
556   - local unarmed = table.clone(w.combat)
557   - if unarmed.damrange then unarmed.damrange = unarmed.damrange + 1.1 end
558   - if unarmed.dammod.str then unarmed.dammod.str = unarmed.dammod.str + 1 end
559   -
560   - desc_combat(unarmed)
561   -
562   - -- subtract the modified values to keep the tooltips correct
563   - if unarmed.damrange then unarmed.damrange = unarmed.damrange - 1.1 end
564   - if unarmed.dammod.str then unarmed.dammod.str = unarmed.dammod.str - 1 end
565   -
  562 +
  563 + local can_combat_unarmed = false
  564 + local compare_unarmed = {}
  565 + for i, v in ipairs(compare_with) do
  566 + if v.wielder and v.wielder.combat then
  567 + can_combat_unarmed = true
  568 + end
  569 + compare_unarmed[i] = compare_with[i].wielder or {}
566 570 end
567 571
  572 + if w and w.combat or can_combat_unarmed then
  573 + desc:add({"color","YELLOW"}, "When used to modify unarmed attacks:", {"color", "LAST"}, true)
  574 + compare_tab = { dam=1, atk=1, apr=0, physcrit=0, physspeed =1, dammod={str=1}, damrange=1.1 }
  575 + desc_combat(w, compare_unarmed, "combat", compare_tab)
  576 + end
568 577 end
569 578 local can_combat = false
570 579 local can_special_combat = false
... ... @@ -572,30 +581,30 @@ function _M:getTextualDesc(compare_with)
572 581 local can_wielder = false
573 582 local can_carrier = false
574 583 local can_imbue_powers = false
575   -
  584 +
576 585 for i, v in ipairs(compare_with) do
577   - if v.combat then
  586 + if v.combat then
578 587 can_combat = true
579 588 end
580   - if v.special_combat then
  589 + if v.special_combat then
581 590 can_special_combat = true
582 591 end
583   - if v.basic_ammo then
  592 + if v.basic_ammo then
584 593 can_basic_ammo = true
585 594 end
586   - if v.wielder then
  595 + if v.wielder then
587 596 can_wielder = true
588 597 end
589   - if v.carrier then
  598 + if v.carrier then
590 599 can_carrier = true
591 600 end
592   - if v.imbue_powers then
  601 + if v.imbue_powers then
593 602 can_imbue_powers = true
594 603 end
595 604 end
596 605
597   - if self.combat or can_combat then
598   - desc_combat(self, compare_with, "combat")
  606 + if self.combat or can_combat then
  607 + desc_combat(self, compare_with, "combat")
599 608 end
600 609
601 610 if self.special_combat or can_special_combat then
... ...