1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00
This commit is contained in:
Gerkiz 2020-07-28 19:55:28 +02:00
parent 5957ab4997
commit fb8c153cc5
3 changed files with 112 additions and 39 deletions

View File

@ -166,7 +166,7 @@ function Public.suicidal_comfylatron(pos, surface)
}
)
local nearest_player_unit =
surface.find_nearest_enemy({position = e.position, max_distance = 256, force = 'player'})
surface.find_nearest_enemy({position = e.position, max_distance = 512, force = 'player'})
if nearest_player_unit and nearest_player_unit.active and nearest_player_unit.force.name ~= 'player' then
e.set_command(
@ -220,6 +220,11 @@ function Public.update_mana(player)
if not rpg_extra.enable_mana then
return
end
if not rpg_t[player.index] then
return
end
if player.gui.left[main_frame_name] then
local f = player.gui.left[main_frame_name]
local data = Gui.get_data(f)
@ -227,6 +232,7 @@ function Public.update_mana(player)
data.mana.caption = rpg_t[player.index].mana
end
end
if rpg_t[player.index].mana < 1 then
return
end
@ -250,47 +256,90 @@ function Public.update_mana(player)
end
end
function Public.reward_mana(player, mana_to_add)
local rpg_extra = RPG.get('rpg_extra')
local rpg_t = RPG.get('rpg_t')
if not rpg_extra.enable_mana then
return
end
if not mana_to_add then
return
end
if not rpg_t[player.index] then
return
end
if player.gui.left[main_frame_name] then
local f = player.gui.left[main_frame_name]
local data = Gui.get_data(f)
if data.mana and data.mana.valid then
data.mana.caption = rpg_t[player.index].mana
end
end
if rpg_t[player.index].mana_max < 1 then
return
end
if rpg_t[player.index].mana >= rpg_t[player.index].mana_max then
rpg_t[player.index].mana = rpg_t[player.index].mana_max
return
end
rpg_t[player.index].mana = rpg_t[player.index].mana + mana_to_add
end
function Public.update_health(player)
local rpg_extra = RPG.get('rpg_extra')
local rpg_t = RPG.get('rpg_t')
if rpg_extra.enable_health_and_mana_bars then
if rpg_t[player.index].show_bars then
if player and player.valid then
if player.character and player.character.valid then
local max_life =
math.floor(
player.character.prototype.max_health + player.character_health_bonus +
player.force.character_health_bonus
)
if not rpg_t[player.index].health_bar then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].health_bar) then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
end
set_bar(player.character.health, max_life, rpg_t[player.index].health_bar)
if player.gui.left[main_frame_name] then
local f = player.gui.left[main_frame_name]
local data = Gui.get_data(f)
if data.health and data.health.valid then
data.health.caption = (math.round(player.character.health * 10) / 10)
end
local shield_gui = player.character.get_inventory(defines.inventory.character_armor)
if not shield_gui.is_empty() then
if shield_gui[1].grid then
local shield = math.floor(shield_gui[1].grid.shield)
local shield_max = math.floor(shield_gui[1].grid.max_shield)
if data.shield and data.shield.valid then
data.shield.caption = shield
end
if data.shield_max and data.shield_max.valid then
data.shield_max.caption = shield_max
end
end
end
end
if not player or not player.valid then
return
end
if not player.character or not player.character.valid then
return
end
if not rpg_t[player.index] then
return
end
if player.gui.left[main_frame_name] then
local f = player.gui.left[main_frame_name]
local data = Gui.get_data(f)
if data.health and data.health.valid then
data.health.caption = (math.round(player.character.health * 10) / 10)
end
local shield_gui = player.character.get_inventory(defines.inventory.character_armor)
if not shield_gui.is_empty() then
if shield_gui[1].grid then
local shield = math.floor(shield_gui[1].grid.shield)
local shield_max = math.floor(shield_gui[1].grid.max_shield)
if data.shield and data.shield.valid then
data.shield.caption = shield
end
if data.shield_max and data.shield_max.valid then
data.shield_max.caption = shield_max
end
end
end
end
if rpg_extra.enable_health_and_mana_bars then
if rpg_t[player.index].show_bars then
local max_life =
math.floor(
player.character.prototype.max_health + player.character_health_bonus +
player.force.character_health_bonus
)
if not rpg_t[player.index].health_bar then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
elseif not rendering.is_valid(rpg_t[player.index].health_bar) then
rpg_t[player.index].health_bar = create_healthbar(player, 0.5)
end
set_bar(player.character.health, max_life, rpg_t[player.index].health_bar)
else
if rpg_t[player.index].health_bar then
if rendering.is_valid(rpg_t[player.index].health_bar) then

View File

@ -159,6 +159,7 @@ local function on_entity_died(event)
end
end
Functions.gain_xp(event.entity.last_user, 1)
Functions.reward_mana(event.entity.last_user, 1)
return
end
end
@ -280,9 +281,10 @@ local function regen_health_player(players)
player.character.health = player.character.health + heal_per_tick
end
end
Functions.update_health(player)
::continue::
Functions.update_health(player)
end
end
@ -314,9 +316,9 @@ local function regen_mana_player(players)
end
end
Functions.update_mana(player)
::continue::
Functions.update_mana(player)
end
end
@ -449,9 +451,11 @@ local function on_entity_damaged(event)
if event.cause.name ~= 'character' then
return
end
if event.damage_type.name ~= 'physical' then
return
end
if not event.entity.valid then
return
end
@ -465,6 +469,8 @@ local function on_entity_damaged(event)
return
end
Functions.reward_mana(event.cause.player, 2)
--Grant the player life-on-hit.
event.cause.health = event.cause.health + Functions.get_life_on_hit(event.cause.player)
@ -575,6 +581,7 @@ local function on_player_repaired_entity(event)
return
end
Functions.gain_xp(player, 0.05)
Functions.reward_mana(player, 0.2)
local repair_speed = Functions.get_magicka(player)
if repair_speed <= 0 then
@ -667,6 +674,7 @@ local function on_pre_player_mined_item(event)
end
Functions.gain_xp(player, xp_amount)
Functions.reward_mana(player, 0.5 * distance_multiplier)
end
local function on_player_crafted_item(event)
@ -685,6 +693,7 @@ local function on_player_crafted_item(event)
local amount = 0.30 * math.random(1, 2)
Functions.gain_xp(player, event.recipe.energy * amount)
Functions.reward_mana(player, amount)
end
local function on_player_respawned(event)
@ -981,6 +990,13 @@ local function on_player_used_capsule(event)
rpg_t[player.index].last_spawned = game.tick + object.tick
Functions.update_mana(player)
local reward_xp = object.mana_cost * 0.009
if reward_xp < 1 then
reward_xp = 1
end
Functions.gain_xp(player, reward_xp)
AntiGrief.insert_into_capsule_history(player, position, msg)
return

View File

@ -380,6 +380,14 @@ function Public.extra_settings(player)
end
enable_entity_gui_input = create_input_element(entity_input, 'boolean', entity_mod)
if not trusted[player.name] then
enable_entity_gui_input.enabled = false
enable_entity_gui_input.tooltip = 'Not trusted.\nChecked = true\nUnchecked = false'
else
enable_entity_gui_input.enabled = true
enable_entity_gui_input.tooltip = 'Checked = true\nUnchecked = false'
end
local conjure_label =
mana_grid.add(
{