1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00

RPG mode integration

This commit is contained in:
MewMew 2019-10-02 21:13:14 +02:00
parent 4520b5c4f2
commit 0836fe94c2
9 changed files with 208 additions and 221 deletions

View File

@ -15,11 +15,12 @@ require "antigrief"
require "antigrief_admin_panel"
require "group"
require "player_list"
require "player_modifiers"
require "poll"
require "score"
require "modules.autostash"
require "modules.corpse_markers"
require "modules.floaty_chat"
--require "modules.floaty_chat"
--require "modules.autohotbar"
--require "on_tick_schedule"
@ -53,8 +54,7 @@ require "modules.floaty_chat"
--require "modules.surrounded_by_worms"
--require "modules.more_attacks"
--require "modules.evolution_extended"
--require "modules.shopping_chests"
--require "modules.fog_of_war"
--require "modules.no_blueprint_library"
-----------------------------
---- enable maps here ----
@ -69,10 +69,10 @@ require "modules.floaty_chat"
--require "maps.wave_of_death.WoD"
--require "maps.stone_maze.main"
--require "maps.overgrowth"
require "maps.quarters"
--require "maps.quarters"
--require "maps.tetris.main"
--require "maps.maze_challenge"
--require "maps.cave_miner"
require "maps.cave_miner"
--require "maps.rocky_waste"
--require "maps.labyrinth"
--require "maps.junkyard"

View File

@ -3,11 +3,10 @@
require "modules.rocks_broken_paint_tiles"
require "maps.cave_miner_kaboomsticks"
require "modules.satellite_score"
--require "modules.explosive_biters"
require "modules.spawners_contain_biters"
--require "modules.teleporting_worms"
--require "modules.splice_double"
--require "modules.biters_double_damage"
require "modules.biter_noms_you"
require "modules.rpg"
require "modules.hunger"
local enable_fishbank_terminal = false
local simplex_noise = require 'utils.simplex_noise'
@ -15,7 +14,7 @@ local Event = require 'utils.event'
local market_items = require "maps.cave_miner_market_items"
local math_random = math.random
local spawn_dome_size = 8000
local spawn_dome_size = 7500
local darkness_messages = {
"Something is lurking in the dark...",
@ -66,44 +65,6 @@ local worm_raffle_table = {
[10] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"}
}
local player_hunger_fish_food_value = 10
local player_hunger_spawn_value = 80
local player_hunger_stages = {}
for x = 1, 200, 1 do
if x <= 200 then player_hunger_stages[x] = "Obese" end
if x <= 179 then player_hunger_stages[x] = "Stuffed" end
if x <= 150 then player_hunger_stages[x] = "Bloated" end
if x <= 130 then player_hunger_stages[x] = "Sated" end
if x <= 110 then player_hunger_stages[x] = "Well Fed" end
if x <= 89 then player_hunger_stages[x] = "Nourished" end
if x <= 70 then player_hunger_stages[x] = "Hungry" end
if x <= 35 then player_hunger_stages[x] = "Starving" end
end
local player_hunger_color_list = {}
for x = 1, 50, 1 do
player_hunger_color_list[x] = {r = 0.5 + x*0.01, g = x*0.01, b = x*0.005}
player_hunger_color_list[50+x] = {r = 1 - x*0.02, g = 0.5 + x*0.01, b = 0.25}
player_hunger_color_list[100+x] = {r = 0 + x*0.02, g = 1 - x*0.01, b = 0.25}
player_hunger_color_list[150+x] = {r = 1 - x*0.01, g = 0.5 - x*0.01, b = 0.25 - x*0.005}
end
local player_hunger_buff = {}
local buff_top_value = 0.70
for x = 1, 200, 1 do
player_hunger_buff[x] = buff_top_value
end
local y = 1
for x = 89, 1, -1 do
player_hunger_buff[x] = buff_top_value - y * 0.015
y = y + 1
end
local y = 1
for x = 111, 200, 1 do
player_hunger_buff[x] = buff_top_value - y * 0.015
y = y + 1
end
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
@ -118,10 +79,7 @@ local function create_cave_miner_button(player)
local b = player.gui.top.add({ type = "sprite-button", name = "caver_miner_stats_toggle_button", sprite = "item/dummy-steel-axe" })
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
b.style.padding = 1
end
local function create_cave_miner_info(player)
@ -157,7 +115,6 @@ local function create_cave_miner_info(player)
end
local function create_cave_miner_stats_gui(player)
if player.gui.top["hunger_frame"] then player.gui.top["hunger_frame"].destroy() end
if player.gui.top["caver_miner_stats_frame"] then player.gui.top["caver_miner_stats_frame"].destroy() end
local captions = {}
@ -165,17 +122,7 @@ local function create_cave_miner_stats_gui(player)
local stat_numbers = {}
local stat_number_style = {{"font", "default-bold"}, {"font_color",{ r=0.77, g=0.77, b=0.77}}, {"top_padding",2}, {"left_padding",0},{"right_padding",0},{"minimal_width",0}}
local separators = {}
local separator_style = {{"font", "default-bold"}, {"font_color",{ r=0.15, g=0.15, b=0.89}}, {"top_padding",2}, {"left_padding",2},{"right_padding",2},{"minimal_width",0}}
local frame = player.gui.top.add { type = "frame", name = "hunger_frame"}
local str = tostring(global.player_hunger[player.name])
str = str .. "% "
str = str .. player_hunger_stages[global.player_hunger[player.name]]
local caption_hunger = frame.add { type = "label", caption = str }
caption_hunger.style.font = "default-bold"
caption_hunger.style.font_color = player_hunger_color_list[global.player_hunger[player.name]]
caption_hunger.style.top_padding = 2
local separator_style = {{"font", "default-bold"}, {"font_color",{ r=0.15, g=0.15, b=0.89}}, {"top_padding",2}, {"left_padding",2},{"right_padding",2},{"minimal_width",0}}
local frame = player.gui.top.add { type = "frame", name = "caver_miner_stats_frame" }
@ -195,7 +142,7 @@ local function create_cave_miner_stats_gui(player)
separators[2] = t.add { type = "label", caption = "|"}
captions[3] = t.add { type = "label", caption = "Efficiency" }
local x = math.floor(game.forces.player.manual_mining_speed_modifier * 100 + player_hunger_buff[global.player_hunger[player.name]] * 100)
local x = math.floor(game.forces.player.manual_mining_speed_modifier * 100 + player.character_mining_speed_modifier * 100)
local str = ""
if x > 0 then str = str .. "+" end
str = str .. tostring(x)
@ -794,47 +741,6 @@ local function on_chunk_generated(event)
surface.regenerate_decorative(decorative_names, {{x=math.floor(event.area.left_top.x/32),y=math.floor(event.area.left_top.y/32)}})
end
local function hunger_update(player, food_value)
if not player.character then return end
if food_value == -1 and player.character.driving == true then return end
local past_hunger = global.player_hunger[player.name]
global.player_hunger[player.name] = global.player_hunger[player.name] + food_value
if global.player_hunger[player.name] > 200 then global.player_hunger[player.name] = 200 end
if past_hunger == 200 and global.player_hunger[player.name] + food_value > 200 then
global.player_hunger[player.name] = player_hunger_spawn_value
player.character.die("player")
local t = {" ate too much and exploded.", " should have gone on a diet.", " needs to work on their bad eating habbits.", " should have skipped dinner today."}
game.print(player.name .. t[math_random(1,#t)], { r=0.75, g=0.0, b=0.0})
end
if global.player_hunger[player.name] < 1 then
global.player_hunger[player.name] = player_hunger_spawn_value
player.character.die("player")
local t = {" ran out of foodstamps.", " starved.", " should not have skipped breakfast today."}
game.print(player.name .. t[math_random(1,#t)], { r=0.75, g=0.0, b=0.0})
end
if player.character then
if player_hunger_stages[global.player_hunger[player.name]] ~= player_hunger_stages[past_hunger] then
local print_message = "You feel " .. player_hunger_stages[global.player_hunger[player.name]] .. "."
if player_hunger_stages[global.player_hunger[player.name]] == "Obese" then
print_message = "You have become " .. player_hunger_stages[global.player_hunger[player.name]] .. "."
end
if player_hunger_stages[global.player_hunger[player.name]] == "Starving" then
print_message = "You are starving!"
end
player.print(print_message, player_hunger_color_list[global.player_hunger[player.name]])
end
end
player.character.character_running_speed_modifier = player_hunger_buff[global.player_hunger[player.name]] * 0.15
player.character.character_mining_speed_modifier = player_hunger_buff[global.player_hunger[player.name]]
end
local function on_player_joined_game(event)
local surface = game.surfaces[1]
local player = game.players[event.player_index]
@ -868,8 +774,7 @@ All they need is a container and a well aimed shot.
Darkness is a hazard in the mines, stay near your lamps..
]]
global.player_hunger = {}
global.damaged_rocks = {}
global.biter_spawn_amount_weights = {}
@ -918,8 +823,6 @@ Darkness is a hazard in the mines, stay near your lamps..
end
if player.online_time < 10 then
create_cave_miner_info(player)
global.player_hunger[player.name] = player_hunger_spawn_value
hunger_update(player, 0)
global.darkness_threat_level[player.name] = 0
player.insert {name = 'pistol', count = 1}
player.insert {name = 'firearm-magazine', count = 16}
@ -1088,6 +991,10 @@ local function on_tick(event)
end
end
end
if game.tick % 900 == 0 then
refresh_gui()
end
end
if game.tick % 240 == 0 then
@ -1096,12 +1003,7 @@ local function on_tick(event)
heal_rocks()
end
if game.tick % 5400 == 2700 then
for _, player in pairs(game.connected_players) do
if player.afk_time < 18000 then hunger_update(player, -1) end
end
refresh_gui()
if game.tick % 5400 == 2700 then
if math_random(1,2) == 1 then biter_attack_event() end
end
@ -1181,11 +1083,11 @@ local function pre_player_mined_item(event)
if tile_distance_to_center > 1450 then tile_distance_to_center = 1450 end
if math_random(1,3) == 1 then hunger_update(player, -1) end
surface.spill_item_stack(player.position,{name = "raw-fish", count = math_random(3,4)},true)
local bonus_amount = math.floor((tile_distance_to_center - math.sqrt(spawn_dome_size)) * 0.10, 0)
if bonus_amount < 1 then bonus_amount = 0 end
local amount = math_random(45,55) + bonus_amount
if amount > 200 then amount = 200 end
surface.spill_item_stack(player.position,{name = "raw-fish", count = math_random(2,4)},true)
local bonus_amount = math.floor((tile_distance_to_center - math.sqrt(spawn_dome_size)) * 0.115) + 1
if bonus_amount < 0 then bonus_amount = 0 end
local amount = math_random(25,35) + bonus_amount
if amount > 500 then amount = 500 end
amount = amount * (1+game.forces.player.mining_drill_productivity_bonus)
amount = math.round(amount, 0)
@ -1332,8 +1234,6 @@ end
local function on_player_respawned(event)
local player = game.players[event.player_index]
player.character.disable_flashlight()
global.player_hunger[player.name] = player_hunger_spawn_value
hunger_update(player, 0)
refresh_gui()
end
@ -1355,7 +1255,6 @@ local function on_gui_click(event)
if name == "caver_miner_stats_toggle_button" and frame then
if player.gui.left["cave_miner_info"] then
frame.destroy()
player.gui.top["hunger_frame"].destroy()
player.gui.left["cave_miner_info"].destroy()
else
create_cave_miner_info(player)
@ -1364,16 +1263,6 @@ local function on_gui_click(event)
if name == "close_cave_miner_info" then player.gui.left["cave_miner_info"].destroy() end
end
local function on_player_used_capsule(event)
if event.item.name == "raw-fish" then
local player = game.players[event.player_index]
if player.character.health < 250 then return end
hunger_update(player, player_hunger_fish_food_value)
player.play_sound{path="utility/armor_insert", volume_modifier=1}
refresh_gui()
end
end
local bank_messages = {
"Caves are dangerous. Did you hear about our insurance programs?",
"Get your wealth flowing today with Fishbank!",
@ -1436,9 +1325,15 @@ local function on_market_item_purchased(event)
end
end
local function on_player_used_capsule(event)
if event.item.name == "raw-fish" then
refresh_gui()
end
end
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_player_respawned, on_player_respawned)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -179,10 +179,10 @@ local function create_gui_button(player)
b.style.font = "heading-1"
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
b.style.maximal_height = 38
b.style.maximal_width = 38
b.style.padding = 1
b.style.margin = 0
end
local function on_player_joined_game(event)

View File

@ -1,8 +1,6 @@
-- hunger module by mewmew --
local event = require 'utils.event'
local math_random = math.random
local player_hunger_fish_food_value = 10
local player_hunger_spawn_value = 80
local player_hunger_stages = {}
@ -26,36 +24,56 @@ for x = 1, 50, 1 do
end
local player_hunger_buff = {}
local buff_top_value = 0.70
for x = 1, 200, 1 do
player_hunger_buff[x] = buff_top_value
local max_buff = 0.50
local max_buff_high = 110
local max_buff_low = 89
local max_debuff = -0.85
local max_debuff_high = 180
local max_debuff_low = 20
for x = 1, max_debuff_low, 1 do
player_hunger_buff[x] = max_debuff
end
local y = 1
for x = 89, 1, -1 do
player_hunger_buff[x] = buff_top_value - y * 0.015
y = y + 1
for x = max_debuff_high, 200, 1 do
player_hunger_buff[x] = max_debuff
end
local y = 1
for x = 111, 200, 1 do
player_hunger_buff[x] = buff_top_value - y * 0.015
y = y + 1
for x = max_buff_low, max_buff_high, 1 do
player_hunger_buff[x] = max_buff
end
for x = max_debuff_low, max_buff_low, 1 do
local step = (max_buff - max_debuff) / (max_buff_low - max_debuff_low)
player_hunger_buff[x] = math.round(max_debuff + (x - max_debuff_low) * step, 2)
end
for x = max_buff_high, max_debuff_high, 1 do
local step = (max_buff - max_debuff) / (max_debuff_high - max_buff_high)
player_hunger_buff[x] = math.round(max_buff - (x - max_buff_high) * step, 2)
end
local function create_hunger_gui(player)
if player.gui.top["hunger_frame"] then player.gui.top["hunger_frame"].destroy() end
local frame = player.gui.top.add { type = "frame", name = "hunger_frame"}
local element = player.gui.top.add { type = "sprite-button", name = "hunger_frame", caption = " "}
element.style.font = "default-bold"
element.style.minimal_height = 38
element.style.minimal_width = 128
element.style.maximal_height = 38
element.style.padding = 0
element.style.margin = 0
element.style.vertical_align = "center"
element.style.horizontal_align = "center"
end
local function update_hunger_gui(player)
if not player.gui.top["hunger_frame"] then create_hunger_gui(player) end
local str = tostring(global.player_hunger[player.name])
str = str .. "% "
str = str .. player_hunger_stages[global.player_hunger[player.name]]
local caption_hunger = frame.add { type = "label", caption = str }
caption_hunger.style.font = "default-bold"
caption_hunger.style.font_color = player_hunger_color_list[global.player_hunger[player.name]]
caption_hunger.style.top_padding = 2
player.gui.top["hunger_frame"].caption = str
player.gui.top["hunger_frame"].style.font_color = player_hunger_color_list[global.player_hunger[player.name]]
end
local function hunger_update(player, food_value)
function hunger_update(player, food_value)
if not player.character then return end
if food_value == -1 and player.character.driving == true then return end
@ -91,21 +109,26 @@ local function hunger_update(player, food_value)
player.print(print_message, player_hunger_color_list[global.player_hunger[player.name]])
end
end
if player_hunger_buff[global.player_hunger[player.name]] < 0 then
global.player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.75
else
global.player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.15
end
global.player_modifiers[player.index].character_mining_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]]
update_player_modifiers(player)
player.character.character_running_speed_modifier = player_hunger_buff[global.player_hunger[player.name]] * 0.5
player.character.character_mining_speed_modifier = player_hunger_buff[global.player_hunger[player.name]]
create_hunger_gui(player)
update_hunger_gui(player)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.player_hunger then global.player_hunger = {} end
if player.online_time < 2 then
if player.online_time == 0 then
global.player_hunger[player.name] = player_hunger_spawn_value
hunger_update(player, 0)
end
create_hunger_gui(player)
update_hunger_gui(player)
end
local function on_player_used_capsule(event)
@ -113,18 +136,24 @@ local function on_player_used_capsule(event)
local player = game.players[event.player_index]
if player.character.health < 250 then return end
hunger_update(player, player_hunger_fish_food_value)
player.play_sound{path="utility/armor_insert", volume_modifier=0.65}
player.play_sound{path="utility/armor_insert", volume_modifier=0.9}
end
end
local function on_tick()
if game.tick % 3600 == 0 then
for _, player in pairs(game.connected_players) do
if player.afk_time < 18000 then hunger_update(player, -1) end
end
end
local function on_player_respawned(event)
local player = game.players[event.player_index]
global.player_hunger[player.name] = player_hunger_spawn_value
hunger_update(player, 0)
end
event.add(defines.events.on_tick, on_tick)
local function on_tick()
for _, player in pairs(game.connected_players) do
if player.afk_time < 18000 then hunger_update(player, -1) end
end
end
local event = require 'utils.event'
event.on_nth_tick(3600, on_tick)
event.add(defines.events.on_player_respawned, on_player_respawned)
event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -1,5 +1,5 @@
--[[
Character Experience Gain RPG module by MewMew
Character Experience Gain RPG by MewMew
STRENGTH > character_inventory_slots_bonus , character_mining_speed_modifier
@ -11,8 +11,9 @@ DEXTERITY > character_running_speed_modifier, character_crafting_speed_modifier
VITALITY > character_health_bonus
]]
local visuals_delay = 60
local visuals_delay = 900
local level_up_floating_text_color = {255, 255, 0}
local xp_floating_text_color = {157, 157, 157}
local experience_levels = {0}
for a = 1, 9999, 1 do
experience_levels[#experience_levels + 1] = experience_levels[#experience_levels] + a * 8
@ -40,7 +41,7 @@ end
local function update_char_button(player)
if not player.gui.top.rpg then draw_gui_char_button(player) end
if global.rpg[player.index].points_to_distribute > 0 then
player.gui.top.rpg.style.font_color = {255, 50, 50}
player.gui.top.rpg.style.font_color = {245, 0, 0}
else
player.gui.top.rpg.style.font_color = {175,175,175}
end
@ -48,23 +49,24 @@ end
local function update_player_stats(player)
local strength = global.rpg[player.index].strength - 10
player.character_inventory_slots_bonus = strength * 0.1
player.character_mining_speed_modifier = strength * 0.005
global.player_modifiers[player.index].character_inventory_slots_bonus["rpg"] = strength * 0.1
global.player_modifiers[player.index].character_mining_speed_modifier["rpg"] = strength * 0.003
local magic = global.rpg[player.index].magic - 10
local v = magic * 0.2
player.character_build_distance_bonus = v
player.character_item_drop_distance_bonus = v
player.character_reach_distance_bonus = v
--player.character_resource_reach_distance_bonus = v
player.character_item_pickup_distance_bonus = v
player.character_loot_pickup_distance_bonus = v
global.player_modifiers[player.index].character_build_distance_bonus["rpg"] = v
global.player_modifiers[player.index].character_item_drop_distance_bonus["rpg"] = v
global.player_modifiers[player.index].character_reach_distance_bonus["rpg"] = v
global.player_modifiers[player.index].character_item_pickup_distance_bonus["rpg"] = v
global.player_modifiers[player.index].character_loot_pickup_distance_bonus["rpg"] = v
local dexterity = global.rpg[player.index].dexterity - 10
player.character_running_speed_modifier = dexterity * 0.002
player.character_crafting_speed_modifier = dexterity * 0.01
global.player_modifiers[player.index].character_running_speed_modifier["rpg"] = dexterity * 0.002
global.player_modifiers[player.index].character_crafting_speed_modifier["rpg"] = dexterity * 0.01
player.character_health_bonus = (global.rpg[player.index].vitality - 10) * 8
global.player_modifiers[player.index].character_health_bonus["rpg"] = (global.rpg[player.index].vitality - 10) * 6
update_player_modifiers(player)
end
local function get_class(player)
@ -96,7 +98,7 @@ local function add_gui_description(element, value, width)
end
local function add_gui_stat(element, value, width)
local e = element.add({type = "textfield", text = value, read_only = true})
local e = element.add({type = "sprite-button", caption = value})
e.style.maximal_width = width
e.style.minimal_width = width
e.style.maximal_height = 42
@ -304,13 +306,21 @@ local function draw_level_text(player)
local scale = 1.0 + global.rpg[player.index].level * 0.01
if scale > 2 then scale = 2 end
local players = {}
for _, p in pairs(game.players) do
if p.index ~= player.index then
players[#players + 1] = p.index
end
end
if #players == 0 then return end
global.rpg[player.index].text = rendering.draw_text{
text = "lvl " .. global.rpg[player.index].level,
surface = player.surface,
target = player.character,
target_offset = {-0.05, -3},
color = player.chat_color,
--time_to_live = 600,
players = players,
scale = scale,
font = "scenario-message-dialog",
alignment = "center",
@ -327,18 +337,23 @@ local function level_up(player)
break
end
end
draw_level_text(player)
if global.rpg[player.index].level == 1 then return end
global.rpg[player.index].points_to_distribute = global.rpg[player.index].points_to_distribute + 5
update_char_button(player)
player.create_local_flying_text{text="LEVEL UP", position=player.position, color={r = 255, g = 255, b = 0}, time_to_live=180, speed=1}
player.play_sound{path="utility/achievement_unlocked", volume_modifier=0.80}
if player.gui.left.rpg then draw_gui(player) end
player.surface.create_entity({name = "flying-text", position = {player.position.x - 0.8, player.position.y}, text = "LEVEL UP", color = level_up_floating_text_color})
for _, p in pairs(game.connected_players) do
if p.index == player.index then
p.play_sound{path="utility/achievement_unlocked", volume_modifier=0.80}
else
p.play_sound{path="utility/achievement_unlocked", position = player.position, volume_modifier=0.80}
end
end
end
local function gain_xp(player, amount)
amount = math.round(amount, 3)
amount = math.round(amount, 2)
global.rpg[player.index].xp = global.rpg[player.index].xp + amount
global.rpg[player.index].xp_since_last_floaty_text = global.rpg[player.index].xp_since_last_floaty_text + amount
if not experience_levels[global.rpg[player.index].level + 1] then return end
@ -347,7 +362,7 @@ local function gain_xp(player, amount)
return
end
if global.rpg[player.index].last_floaty_text > game.tick then return end
player.create_local_flying_text{text="+" .. global.rpg[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color={r = 177, g = 177, b = 177}, time_to_live=120, speed=2}
player.create_local_flying_text{text="+" .. global.rpg[player.index].xp_since_last_floaty_text .. " xp", position=player.position, color=xp_floating_text_color, time_to_live=120, speed=2}
if player.gui.left.rpg then draw_gui(player) end
global.rpg[player.index].xp_since_last_floaty_text = 0
global.rpg[player.index].last_floaty_text = game.tick + visuals_delay
@ -413,10 +428,10 @@ end
local function on_entity_damaged(event)
if not event.entity.valid then return end
if event.final_damage_amount == 0 then return end
if event.final_damage_amount == 0 then return end
if event.entity.name ~= "character" then return end
if not event.entity.player then return end
if event.entity.name ~= "character" then return end
gain_xp(event.entity.player, event.final_damage_amount * 0.25)
gain_xp(event.entity.player, event.final_damage_amount * 0.05)
end
local function on_player_changed_position(event)
@ -426,21 +441,35 @@ local function on_player_changed_position(event)
gain_xp(player, 0.01)
end
local function on_player_mined_entity(event)
local function on_pre_player_mined_item(event)
if not event.entity.valid then return end
local player = game.players[event.player_index]
if event.entity.force.name == "neutral" then gain_xp(player, 1.5 + event.entity.prototype.max_health * 0.005) return end
if event.entity.type == "resource" then gain_xp(player, 0.5) return end
if event.entity.force.name == "neutral" then gain_xp(player, 1.25 + event.entity.prototype.max_health * 0.0025) return end
gain_xp(player, 0.1 + event.entity.prototype.max_health * 0.0005)
end
local function on_built_entity(event)
if not event.created_entity.valid then return end
if event.created_entity.type == "entity-ghost" then return end
local player = game.players[event.player_index]
gain_xp(player, 0.1)
end
local function on_player_crafted_item(event)
if not event.recipe.energy then return end
local player = game.players[event.player_index]
gain_xp(player, event.recipe.energy * 0.2)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.rpg[player.index] then
global.rpg[player.index] = {level = 0, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0}
global.rpg[player.index] = {level = 1, xp = 0, strength = 10, magic = 10, dexterity = 10, vitality = 10, points_to_distribute = 0, last_floaty_text = visuals_delay, xp_since_last_floaty_text = 0}
end
draw_gui_char_button(player)
level_up(player)
draw_gui_char_button(player)
update_player_stats(player)
draw_level_text(player)
end
local function on_init(event)
@ -449,9 +478,11 @@ end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_built_entity, on_built_entity)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_player_changed_position, on_player_changed_position)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_crafted_item, on_player_crafted_item)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)

View File

@ -16,10 +16,7 @@ local function satellite_score_toggle_button(player)
button.style.font = "default-bold"
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
button.style.padding = 1
end
local function level_up_popup(player)

View File

@ -361,10 +361,7 @@ local function on_player_joined_game(event)
local button = player.gui.top.add({ type = "sprite-button", name = "player_list_button", sprite = "item/heavy-armor", tooltip = "Player List" })
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
button.style.padding = 1
end
if player.gui.left["player-list-panel"] then

41
player_modifiers.lua Normal file
View File

@ -0,0 +1,41 @@
--Central to add all player modifiers together.
local modifiers = {
"character_build_distance_bonus",
"character_crafting_speed_modifier",
"character_health_bonus",
"character_inventory_slots_bonus",
"character_item_drop_distance_bonus",
"character_item_pickup_distance_bonus",
"character_loot_pickup_distance_bonus",
"character_mining_speed_modifier",
"character_reach_distance_bonus",
"character_resource_reach_distance_bonus",
"character_running_speed_modifier",
}
function update_player_modifiers(player)
for _, modifier in pairs(modifiers) do
local sum_value = 0
for _, value in pairs(global.player_modifiers[player.index][modifier]) do
sum_value = sum_value + value
end
player[modifier] = sum_value
end
end
local function on_player_joined_game(event)
if global.player_modifiers[event.player_index] then return end
global.player_modifiers[event.player_index] = {}
for _, modifier in pairs(modifiers) do
global.player_modifiers[event.player_index][modifier] = {}
end
end
local function on_init(event)
global.player_modifiers = {}
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -8,10 +8,7 @@ local function create_score_button(player)
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo", tooltip = "Scoreboard" })
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
button.style.padding = 1
end
end