User:Shenlebantongying/sandbox lua

&lt!-- -->&lt!-- -->&lt!--

-->&lt!--output: -->

Translation: Attributes → Attributes 点生命值 → health 至少 → at least 点生命恢复 → health regeneration %生命恢复 → % health regeneration 点护甲 → armor 点攻击速度 → attack speed 点移动速度 → movement speed %移动速度 → % movement speed 点魔法值 → mana 点魔法恢复 → mana regeneration %魔法恢复 → % mana regeneration %技能伤害 → % spell damage 对于英雄，还可以获得 → For heroes, it also grants %状态抗性和 → % status resistance and 点 → (nothing in english) 攻击力 → attack damage 攻击力 → attack damage 对于英雄，还可以获得 → For heroes, it also grants %移动速度和 → % movement speed and %移动速度和 → % movement speed and 对于英雄，还可以获得 → For heroes, it also grants %魔法抗性和 → % magic resistance and 和 → and . → . ， →, C++ Code: auto strength = ; auto agility = ; auto intelligence = ;
 * 一个提供一共 → * One grants a total of
 * 1) pragma region define_values

if (0 == (strength + agility + intelligence)) return;

auto attack_damage[3] = { strength, agility, intelligence }; for (auto damage : attack_damage) {   if (damage == 0) continue; damage += ; }

// Strength auto health = + strength * ;

auto health_regeneration_flat = ; auto health_regeneration_percent = strength * * 0.01; auto health_regeneration_flag = FLAT; auto health_regeneration = 0.0; if (health_regeneration_flat != 0) {   health_regeneration = health_regeneration_flat; if (health_regeneration_percent != 0) health_regeneration *= (1 + health_regeneration_percent); } else if (health_regeneration_percent != 0) {   health_regeneration_flag = PERCENT; health_regeneration = health_regeneration_percent; } else {   health_regeneration_flag = UNKNOWN; health_regeneration = 0; }

// non-exist item // auto status_resistance = * 0.01;

auto status_resistance_for_strength = strength * * 0.01;

auto attack_damage_for_strength = attack_damage[0];

// Agility auto armor = + agility * ;

auto attack_speed = + agility * ;

auto movement_speed_flat = ;

auto movement_speed_percent = * 0.01;

auto movement_speed_percent_for_agility = agility * * 0.01;

auto attack_damage_for_agility = attack_damage[1];

// Intelligence auto mana = + intelligence * ;

auto mana_regeneration_flat = ; auto mana_regeneration_percent = intelligence * * 0.01; auto mana_regeneration_flag = FLAT; auto mana_regeneration = 0.0; if (mana_regeneration_flat != 0) {   mana_regeneration = mana_regeneration_flat; if (mana_regeneration_percent != 0) mana_regeneration *= (1 + mana_regeneration_percent); } else if (mana_regeneration_percent != 0) {   mana_regeneration_flag = PERCENT; mana_regeneration = mana_regeneration_percent; } else {   mana_regeneration_flag = UNKNOWN; mana_regeneration = 0; }

auto spell_damage = ( + intelligence * ) * 0.01;

// non-exist item // auto magic_resistance = * 0.01;

auto magic_resistance_for_intelligence = intelligence * * 0.01;

auto attack_damage_for_intelligence = attack_damage[2];
 * 1) pragma endregion define_values

// no longer need /* auto szAttackDamage = ""; if (attack_damage_for_strength == attack_damage_for_agility && attack_damage_for_agility == attack_damage_for_intelligence) {   if (attack_damage_for_strength != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + " attack damage"; } else if (attack_damage_for_strength == attack_damage_for_agility) {   if (attack_damage_for_strength != 0 && attack_damage_for_intelligence != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + "//" + std::to_string(attack_damage_for_intelligence) + "( heroes) attack damage" else if (attack_damage_for_strength != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + "( and heroes) attack damage" else if (attack_damage_for_intelligence != 0) szAttackDamage = std::to_string(attack_damage_for_intelligence) + "( heroes) attack damage"; } else if (attack_damage_for_agility == attack_damage_for_intelligence) {   if (attack_damage_for_agility != 0 && attack_damage_for_strength != 0) szAttackDamage = std::to_string(attack_damage_for_agility) + "//" + std::to_string(attack_damage_for_strength) + "( heroes) attack damage" else if (attack_damage_for_agility != 0) szAttackDamage = std::to_string(attack_damage_for_agility) + "( and heroes) attack damage" else if (attack_damage_for_strength != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + "( heroes) attack damage"; } else if (attack_damage_for_strength == attack_damage_for_intelligence) {   if (attack_damage_for_strength != 0 && attack_damage_for_agility != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + "//" + std::to_string(attack_damage_for_agility) + "( heroes) attack damage" else if (attack_damage_for_strength != 0) szAttackDamage = std::to_string(attack_damage_for_strength) + "( and heroes) attack damage" else if (attack_damage_for_agility != 0) szAttackDamage = std::to_string(attack_damage_for_agility) + "( heroes) attack damage"; } else {   if (attack_damage_for_strength != 0) szAttackDamage += std::to_string(attack_damage_for_strength) + "( heroes)"; if (attack_damage_for_agility != 0) {     if (!szAttackDamage.empty) szAttackDamage += "//"; szAttackDamage += std::to_string(attack_damage_for_agility) + "( heroes)"; }   if (attack_damage_for_intelligence != 0) {     if (!szAttackDamage.empty) szAttackDamage += "//"; szAttackDamage += std::to_string(attack_damage_for_intelligence) + "( heroes)"; }   szAttackDamage += " attack damage"; } */
 * 1) pragma region showing_string

// Strength auto szHealth = ""; if (health != 0) {   szHealth = std::to_string(health) + " health"; }

auto szHealthRegeneration = ""; if (health_regeneration_flag == FLAT) {   szHealthRegeneration = "at least " + std::to_string(health_regeneration) + " health regeneration"; } else if (health_regeneration_flag == PERCENT) {   szHealthRegeneration = std::to_string(health_regeneration * 100) + "% health regeneration"; }

// non-exist item /* auto szStatusResistance = ""; if (status_resistance == status_resistance_for_strength) {   if (status_resistance != 0) szStatusResistance = std::to_string(status_resistance * 100) + "% spell damage"; } else {   if (status_resistance != 0) szStatusResistance = std::to_string(status_resistance * 100) + "//"; szStatusResistance += std::to_string(status_resistance_for_strength * 100) + "%( heroes) status resistance"; } */

// Agility auto szArmor = ""; if (armor != 0) {   szArmor = std::to_string(armor) + " armor"; }

auto szAttackSpeed = ""; if (attack_speed != 0) {   szAttackSpeed = std::to_string(attack_speed) + " attack speed"; }

// no need accroding to Psion1C /* auto szMovementSpeed = ""; if (movement_speed_flat != 0) {   szMovementSpeed = std::to_string(movement_speed_flat) + " movement speed"; } if (movement_speed_percent != 0) {   szMovementSpeed = std::to_string(movement_speed_percent * 100) + "% movement speed"; } */

// Intelligence auto szMana = ""; if (mana != 0) {   szMana = std::to_string(mana) + " mana"; }

auto szManaRegeneration = ""; if (mana_regeneration_flag == FLAT) {   szManaRegeneration = "at least " + std::to_string(mana_regeneration) + " mana regeneration"; } else if (mana_regeneration_flag == PERCENT) {   szManaRegeneration = std::to_string(mana_regeneration * 100) + "% mana regeneration"; }

auto szSpellDamage = ""; if (spell_damage != 0) {   szSpellDamage = std::to_string(spell_damage * 100) + "% spell damage" }

// non-exist item /* auto szMagicResistance = ""; if (magic_resistance == magic_resistance_for_intelligence) {   if (magic_resistance != 0) szMagicResistance = std::to_string(magic_resistance * 100) + "% magic resistance"; } else {   if (magic_resistance != 0) szMagicResistance = std::to_string(magic_resistance * 100) + "%//"; szMagicResistance += std::to_string(magic_resistance_for_intelligence * 100) + "%( heroes) magic resistance"; } */  // Perk auto damage_flag = 0; auto szStrength = "For heroes, " + Unique2 ? Unique2 : "it also grants "; if (!status_resistance_for_strength && !attack_damage_for_strength) {   szStrength = ""; } if (status_resistance_for_strength != 0) {   szStrength += std::to_string(status_resistance_for_strength * 100) + "% status resistance and "; } if (attack_damage_for_strength != 0) {   szStrength += std::to_string(attack_damage_for_strength) + " " + damage_flag++ ? "attack damage" : "attack damage"; }

auto szAgility = "For heroes, " + Unique2 ? Unique2 : "it also grants "; if (!movement_speed_percent_for_agility && !attack_damage_for_agility) {   szAgility = ""; } if (movement_speed_percent_for_agility != 0) {   szAgility += std::to_string(movement_speed_percent_for_agility * 100) + /*!szMovementSpeed.empty ? "% movement speed and " : */"% movement speed and "; } if (attack_damage_for_agility != 0) {   szAgility += std::to_string(attack_damage_for_agility) + " " + damage_flag++ ? "attack damage" : "attack damage"; }

auto szIntelligence = "For heroes, " + Unique2 ? Unique2 : "it also grants "; if (!magic_resistance_for_intelligence && !attack_damage_for_intelligence) {   szIntelligence = ""; } if (magic_resistance_for_intelligence != 0) {   szIntelligence += std::to_string(magic_resistance_for_intelligence * 100) + "% magic resistance and "; } if (attack_damage_for_intelligence != 0) {   szIntelligence += std::to_string(attack_damage_for_intelligence) + " " + damage_flag++ ? "attack damage" : "attack damage"; }
 * 1) pragma endregion showing_string

auto strings[8] = { szHealth, szHealthRegeneration, szArmor, szAttackSpeed, szMana, szManaRegeneration, szSpellDamage/*, szMovementSpeed*/ }
 * 1) pragma region counting

auto iCount = 0; for (auto sz : strings) {   if (!sz.empty) iCount++; } if (iCount == 0 || iCount == 1) return;
 * 1) pragma endregion counting

auto iIndex = 0; auto szResult = Unique ? Unique : "* One grants a total of" + " ";
 * 1) pragma region combine

for (auto sz : strings) {   if (!sz.empty) {     if (iIndex == 0) szResult += sz; else if (iIndex == iCount - 1) szResult += " and " + sz + "."; else szResult += ", " + sz; iIndex++; } }

auto PerkStrings[3] = { szStrength, szAgility, szIntelligence }

for (auto sz : PerkStrings) {   if (!sz.empty) {     szResult += "\r\n** " + sz; } } lua code (done on Template:Item stats)
 * 1) pragma endregion combine