mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-25 21:29:06 +02:00
updates
This commit is contained in:
parent
93119f0da5
commit
bdcd1f68d2
@ -24,7 +24,7 @@ local function on_entity_damaged(event)
|
||||
if not event.cause then return end
|
||||
if not event.cause.valid then return end
|
||||
if not whitelist[event.cause.name] then return end
|
||||
if math.random(1,3) == 1 then
|
||||
if math.random(1,5) == 1 then
|
||||
event.cause.surface.create_entity({
|
||||
name = "flying-text",
|
||||
position = event.cause.position,
|
||||
|
285
modules/rpg.lua
285
modules/rpg.lua
@ -13,98 +13,153 @@ VITALITY > character_health_bonus + damage resistance
|
||||
|
||||
local visuals_delay = 60
|
||||
|
||||
local gui_width = 360
|
||||
local gui_height = 480
|
||||
local font = "default-bold"
|
||||
local font_color = {222, 222, 222}
|
||||
|
||||
local experience_levels = {0}
|
||||
for a = 1, 9999, 1 do
|
||||
experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 2
|
||||
end
|
||||
|
||||
local function draw_gui(player)
|
||||
if player.gui.left.rpg then player.gui.left.rpg.destroy() end
|
||||
local frame = player.gui.left.add({type = "frame", name = "rpg", direction = "vertical"})
|
||||
frame.style.maximal_width = gui_width
|
||||
frame.style.minimal_width = gui_width
|
||||
|
||||
local t = frame.add({type = "table", column_count = 2})
|
||||
local element = t.add({type = "sprite-button", caption = player.name})
|
||||
local element = t.add({type = "sprite-button", caption = "Rogue"})
|
||||
for _, element in pairs(t.children) do
|
||||
element.style.maximal_width = math.floor(gui_width * 0.46)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.46)
|
||||
element.style.font = font
|
||||
element.style.font_color = font_color
|
||||
local classes = {
|
||||
["engineer"] = "ENGINEER",
|
||||
["strength"] = "WARRIOR",
|
||||
["magic"] = "SORCEROR",
|
||||
["dexterity"] = "ROGUE",
|
||||
["vitality"] = "TANK",
|
||||
}
|
||||
|
||||
local function get_class(player)
|
||||
local high_attribute = global.rpg[player.index].strength
|
||||
local high_attribute_name = "engineer"
|
||||
for _, attribute in pairs({"strength", "magic", "dexterity", "vitality"}) do
|
||||
if global.rpg[player.index][attribute] > high_attribute then
|
||||
high_attribute = global.rpg[player.index][attribute]
|
||||
high_attribute_name = attribute
|
||||
end
|
||||
end
|
||||
|
||||
local element = frame.add({type = "line"})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.96)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.96)
|
||||
|
||||
local t = frame.add({type = "table", column_count = 4})
|
||||
local element = t.add({type = "label", caption = "LEVEL"})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.15)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.15)
|
||||
local element = t.add({type = "sprite-button", caption = global.rpg[player.index].level})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.15)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.15)
|
||||
local element = t.add({type = "label", caption = "EXPERIENCE"})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.25)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.25)
|
||||
local element = t.add({type = "sprite-button", caption = math.floor(global.rpg[player.index].xp)})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.33)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.33)
|
||||
local element = t.add({type = "label", caption = " "})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.15)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.15)
|
||||
local element = t.add({type = "label", caption = " "})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.15)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.15)
|
||||
local element = t.add({type = "label", caption = "NEXT LEVEL"})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.25)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.25)
|
||||
local element = t.add({type = "sprite-button", caption = experience_levels[global.rpg[player.index].level + 1]})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.33)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.33)
|
||||
for _, element in pairs(t.children) do
|
||||
element.style.font = font
|
||||
element.style.font_color = font_color
|
||||
end
|
||||
local element = frame.add({type = "line"})
|
||||
element.style.maximal_width = math.floor(gui_width * 0.96)
|
||||
element.style.minimal_width = math.floor(gui_width * 0.96)
|
||||
|
||||
return classes[high_attribute_name]
|
||||
end
|
||||
|
||||
local function add_gui_description(element, value, width)
|
||||
local e = element.add({type = "label", caption = value})
|
||||
e.style.single_line = false
|
||||
e.style.maximal_width = width
|
||||
e.style.minimal_width = width
|
||||
e.style.font = "default-bold"
|
||||
e.style.font_color = {175, 175, 200}
|
||||
e.style.horizontal_align = "right"
|
||||
e.style.vertical_align = "center"
|
||||
return e
|
||||
end
|
||||
|
||||
local function add_gui_stat(element, value, width)
|
||||
local e = element.add({type = "sprite-button", caption = value})
|
||||
e.style.maximal_width = width
|
||||
e.style.minimal_width = width
|
||||
e.style.maximal_height = 40
|
||||
e.style.minimal_height = 40
|
||||
e.style.font = "default-bold"
|
||||
e.style.font_color = {222, 222, 222}
|
||||
e.style.horizontal_align = "center"
|
||||
e.style.vertical_align = "center"
|
||||
return e
|
||||
end
|
||||
|
||||
local function add_gui_increase_stat(element, player, width)
|
||||
local sprite = "virtual-signal/signal-red"
|
||||
if global.rpg[player.index].points_to_distribute <= 0 then sprite = "virtual-signal/signal-black" end
|
||||
local t = frame.add({type = "table", column_count = 2})
|
||||
local tt = frame.add({type = "table", column_count = 3})
|
||||
local element = tt.add({type = "label", caption = "STRENGTH"})
|
||||
local element = tt.add({type = "sprite-button", caption = global.rpg[player.index].strength})
|
||||
local element = tt.add({type = "sprite-button", caption = "+", sprite = sprite})
|
||||
local element = tt.add({type = "label", caption = "MAGIC"})
|
||||
local element = tt.add({type = "sprite-button", caption = global.rpg[player.index].magic})
|
||||
local element = tt.add({type = "sprite-button", caption = "+", sprite = sprite})
|
||||
local element = tt.add({type = "label", caption = "DEXTERITY"})
|
||||
local element = tt.add({type = "sprite-button", caption = global.rpg[player.index].dexterity})
|
||||
local element = tt.add({type = "sprite-button", caption = "+", sprite = sprite})
|
||||
local element = tt.add({type = "label", caption = "VITALITY"})
|
||||
local element = tt.add({type = "sprite-button", caption = global.rpg[player.index].vitality})
|
||||
local element = tt.add({type = "sprite-button", caption = "+", sprite = sprite})
|
||||
local element = tt.add({type = "label", caption = "POINTS TO DISTRIBUTE"})
|
||||
element.style.minimal_width = 96
|
||||
element.style.maximal_width = 96
|
||||
element.style.single_line = false
|
||||
local element = tt.add({type = "sprite-button", caption = global.rpg[player.index].points_to_distribute})
|
||||
local element = tt.add({type = "label", caption = " "})
|
||||
local element = tt.add({type = "label", caption = " "})
|
||||
local element = tt.add({type = "label", caption = " "})
|
||||
local element = tt.add({type = "label", caption = " "})
|
||||
local element = tt.add({type = "label", caption = "LIFE"})
|
||||
local element = tt.add({type = "sprite-button", caption = player.character.health})
|
||||
local element = tt.add({type = "sprite-button", caption = player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus})
|
||||
local e = element.add({type = "sprite-button", caption = "✚", sprite = sprite})
|
||||
e.style.maximal_height = 40
|
||||
e.style.minimal_height = 40
|
||||
e.style.maximal_width = width
|
||||
e.style.minimal_width = width
|
||||
e.style.font = "default-large-semibold"
|
||||
e.style.font_color = {0,0,0}
|
||||
e.style.horizontal_align = "center"
|
||||
e.style.vertical_align = "center"
|
||||
e.style.padding = 0
|
||||
e.style.margin = 0
|
||||
return e
|
||||
end
|
||||
|
||||
local function add_separator(element, width)
|
||||
local e = element.add({type = "line"})
|
||||
e.style.maximal_width = width
|
||||
e.style.minimal_width = width
|
||||
e.style.minimal_height = 12
|
||||
return e
|
||||
end
|
||||
|
||||
local function draw_gui(player)
|
||||
if player.gui.left.rpg then player.gui.left.rpg.destroy() end
|
||||
|
||||
local frame = player.gui.left.add({type = "frame", name = "rpg", direction = "vertical"})
|
||||
frame.style.maximal_width = 425
|
||||
frame.style.minimal_width = 425
|
||||
|
||||
local t = frame.add({type = "table", column_count = 2})
|
||||
local e = add_gui_stat(t, player.name, 200)
|
||||
e.style.font_color = player.chat_color
|
||||
e.style.font = "default-large-bold"
|
||||
local e = add_gui_stat(t, get_class(player), 200)
|
||||
e.style.font = "default-large-bold"
|
||||
|
||||
add_separator(frame, 400)
|
||||
|
||||
local t = frame.add({type = "table", column_count = 4})
|
||||
t.style.cell_padding = 1
|
||||
|
||||
add_gui_description(t, "LEVEL", 80)
|
||||
add_gui_stat(t, global.rpg[player.index].level, 80)
|
||||
|
||||
add_gui_description(t, "EXPERIENCE", 100)
|
||||
add_gui_stat(t, math.floor(global.rpg[player.index].xp), 125)
|
||||
|
||||
add_gui_description(t, " ", 75)
|
||||
add_gui_description(t, " ", 75)
|
||||
|
||||
add_gui_description(t, "NEXT LEVEL", 100)
|
||||
add_gui_stat(t, experience_levels[global.rpg[player.index].level + 1], 125)
|
||||
|
||||
add_separator(frame, 400)
|
||||
|
||||
local t = frame.add({type = "table", column_count = 2})
|
||||
local tt = t.add({type = "table", column_count = 3})
|
||||
tt.style.cell_padding = 1
|
||||
local w1 = 115
|
||||
local w2 = 40
|
||||
|
||||
local e = add_gui_description(tt, "STRENGTH", w1)
|
||||
e.tooltip = "Increases inventory slots and mining speed."
|
||||
add_gui_stat(tt, global.rpg[player.index].strength, w2)
|
||||
add_gui_increase_stat(tt, player, w2)
|
||||
|
||||
local e = add_gui_description(tt, "MAGIC", w1)
|
||||
e.tooltip = "Increases reach distance."
|
||||
add_gui_stat(tt, global.rpg[player.index].magic, w2)
|
||||
add_gui_increase_stat(tt, player, w2)
|
||||
|
||||
local e = add_gui_description(tt, "DEXTERITY", w1)
|
||||
e.tooltip = "Increases running and crafting speed."
|
||||
add_gui_stat(tt, global.rpg[player.index].dexterity, w2)
|
||||
add_gui_increase_stat(tt, player, w2)
|
||||
|
||||
local e = add_gui_description(tt, "VITALITY", w1)
|
||||
e.tooltip = "Increases health and damage resistance."
|
||||
add_gui_stat(tt, global.rpg[player.index].vitality, w2)
|
||||
add_gui_increase_stat(tt, player, w2)
|
||||
|
||||
add_gui_description(tt, "POINTS TO\nDISTRIBUTE", w1)
|
||||
local e = add_gui_stat(tt, global.rpg[player.index].points_to_distribute, w2)
|
||||
e.style.font_color = {200, 0, 0}
|
||||
add_gui_description(tt, " ", w2)
|
||||
|
||||
add_gui_description(tt, " ", w1)
|
||||
add_gui_description(tt, " ", w2)
|
||||
add_gui_description(tt, " ", w2)
|
||||
|
||||
add_gui_description(tt, "LIFE", w1)
|
||||
add_gui_stat(tt, player.character.health, w2)
|
||||
add_gui_stat(tt, player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus, w2)
|
||||
|
||||
local shield = 0
|
||||
local shield_max = 0
|
||||
local i = player.character.get_inventory(defines.inventory.character_armor)
|
||||
@ -114,13 +169,63 @@ local function draw_gui(player)
|
||||
shield_max = math.floor(i[1].grid.max_shield)
|
||||
end
|
||||
end
|
||||
local element = tt.add({type = "label", caption = "SHIELD"})
|
||||
local element = tt.add({type = "sprite-button", caption = shield})
|
||||
local element = tt.add({type = "sprite-button", caption = shield_max})
|
||||
for _, element in pairs(tt.children) do
|
||||
element.style.font = font
|
||||
element.style.font_color = font_color
|
||||
end
|
||||
add_gui_description(tt, "SHIELD", w1)
|
||||
add_gui_stat(tt, shield, w2)
|
||||
add_gui_stat(tt, shield_max, w2)
|
||||
|
||||
|
||||
local tt = t.add({type = "table", column_count = 3})
|
||||
tt.style.cell_padding = 1
|
||||
local w0 = 18
|
||||
local w1 = 80
|
||||
local w2 = 80
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "MINING\nSPEED", w1)
|
||||
local value = (player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "SLOT\nBONUS", w1)
|
||||
local value = "+" .. player.force.character_inventory_slots_bonus + player.character_inventory_slots_bonus
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "REACH\nDISTANCE", w1)
|
||||
local value = (player.force.character_reach_distance_bonus + player.character_reach_distance_bonus + 1) * 100 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "CRAFTING\nSPEED", w1)
|
||||
local value = (player.force.manual_crafting_speed_modifier + player.character_crafting_speed_modifier + 1) * 100 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "RUNNING\nSPEED", w1)
|
||||
local value = (player.force.character_running_speed_modifier + player.character_running_speed_modifier + 1) * 100 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, " ", w0)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "HEALTH\nBONUS", w1)
|
||||
local value = (player.force.character_health_bonus + player.character_health_bonus + 1) * 100 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
|
||||
add_gui_description(tt, " ", w0)
|
||||
add_gui_description(tt, "DAMAGE\nRESISTANCE", w1)
|
||||
local value = 0 .. "%"
|
||||
add_gui_stat(tt, value, w2)
|
||||
end
|
||||
|
||||
local function draw_level_text(player)
|
||||
|
Loading…
x
Reference in New Issue
Block a user