我正在Lua制作战斗桌,我对Lua很新。输出应如下所示:
上次战斗的结果:
Damage Done:
1 >>>> Alice 200 (CRITICAL)
2 Bob 60
3 Alice 30
4 Alice 30
5 >>>> Alice 45 (CRITICAL)
6 >>>> Bob 120 (CRITICAL)
7 Bob 300
8 Alice 100
9 Bob 50
完成总伤害百分比:
1 Bob 57%
1 Heavy Attack (1) 57%
2 Lava Whip (2) 34%
3 Light Attack (1) 9%
2 Alice 43%
1 Crystal Shard (2) 74%
2 Lightning Splash (3) 26%
您的伤害统计数据:
Average: 81
Min: 30
Max: 200
治疗完成:
1 >>>> Carol 400 (CRITICAL)
2 Carol 200
3 Alice 200
完成总治疗百分比:
1 Carol 75%
1 Regeneration (2) 100%
2 Alice 25%
1 Regeneration (1) 100%
你的治疗统计数据:
Average: 200
Min: 200
Max: 200
我已经在关键部分进行了编码,现在我不知道如何计算总损伤的百分比。任何帮助,将不胜感激。这是一大堆代码:
function CombatReport:OnEndCombat(combatEndTime)
combatDurationTime = combatEndTime - self.combatStartTime + 1
print("*****************************************")
print("** Combat Report".." ("..combatDurationTime.." seconds)")
print("*****************************************")
print("Results of the last combat:\n")
damageEvents = "Damage Done:\n"
count = 1
for i = 1, self.numCombatEvents do
damage = self.combatEvents[i][3]
sourceName = self.combatEvents[i][1]
isCrit = self.combatEvents[i][5]
if damage > 0 then
damageEvents = damageEvents .. "#"
damageEvents = damageEvents .. count
if isCrit then
damageEvents = damageEvents .. " >>>>"
end
damageEvents = damageEvents .. " "
damageEvents = damageEvents .. sourceName
damageEvents = damageEvents .. " "
damageEvents = damageEvents .. damage
if isCrit then
damageEvents = damageEvents .. " (CRITICAL)"
end
damageEvents = damageEvents .. "\n"
count = count + 1
end
end
print(damageEvents)
这是我编辑添加到暴击中的部分。
以下是我的战斗事件:
local COMBAT_EVENTS =
{
{ "Alice", "Molag Bal", 200, 0, true, 1, "Crystal Shard" },
{ "Bob", "Molag Bal", 60, 0, false, 2, "Lava Whip" },
{ "Alice", "Molag Bal", 30, 0, false, 3, "Lightning Splash" },
{ "Carol", "Alice", 0, 400, true, 4, "Regeneration" },
{ "Alice", "Molag Bal", 30, 0, false, 5, "Lightning Splash" },
{ "Alice", "Molag Bal", 45, 0, true, 6, "Lightning Splash" },
{ "Bob", "Molag Bal", 120, 0, true, 7, "Lava Whip" },
{ "Bob", "Molag Bal", 300, 0, false, 8, "Heavy Attack" },
{ "Carol", "Bob", 0, 200, false, 9, "Regeneration" },
{ "Alice", "Molag Bal", 100, 0, false, 10, "Crystal Shard" },
{ "Bob", "Molag Bal", 50, 0, false, 11, "Light Attack" },
{ "Alice", "Alice", 0, 200, false, 12, "Regeneration" }
}