mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
* Refactor custom start * Refactor afk kick * Fix use of assert get player * Refactor chat popup * Refactor chat auto reply * Refactor help bubbles * Refactor damage popups * Refactor death markers * Refactor deconstruction log * Remove FAGC logging * Refactor discord alerts * Refactor insert pickup * Refactor inventory clear * Refactor extra logging * Refactor nuke protection * Refactor pollution grading * Refactor protection jail * Refactor report jail * Refactor mine depletion * Refactor degrading tiles * Refactor station auto name * Refactor spawn area * Refactor fast deconstruction * Bug Fixes
51 lines
1.7 KiB
Lua
51 lines
1.7 KiB
Lua
--[[-- Control - Damage PopUps
|
|
Displays the amount of dmg that is done by players to entities;
|
|
also shows player health when a player is attacked
|
|
]]
|
|
|
|
local FlyingText = require("modules/exp_util/flying_text")
|
|
local config = require("modules.exp_legacy.config.popup_messages")
|
|
|
|
local random = math.random
|
|
local floor = math.floor
|
|
local max = math.max
|
|
|
|
--- Called when entity entity is damaged including the player character
|
|
--- @param event EventData.on_entity_damaged
|
|
local function on_entity_damaged(event)
|
|
local message
|
|
local cause = event.cause
|
|
local entity = event.entity
|
|
|
|
-- Check which message to display
|
|
if config.show_player_health and entity.name == "character" then
|
|
message = { "exp_damage-popup.flying-text-health", floor(entity.health) }
|
|
elseif config.show_player_damage and entity.name ~= "character" and cause and cause.name == "character" then
|
|
message = { "exp_damage-popup.flying-text-damage", floor(event.original_damage_amount) }
|
|
end
|
|
|
|
-- Outputs the message as floating text
|
|
if message then
|
|
local entity_radius = max(1, entity.get_radius())
|
|
local offset = (random() - 0.5) * entity_radius * config.damage_location_variance
|
|
local position = { x = entity.position.x + offset, y = entity.position.y - entity_radius }
|
|
|
|
local health_percentage = entity.get_health_ratio()
|
|
local color = { r = 1 - health_percentage, g = health_percentage, b = 0 }
|
|
|
|
FlyingText.create{
|
|
text = message,
|
|
position = position,
|
|
color = color,
|
|
}
|
|
end
|
|
end
|
|
|
|
local e = defines.events
|
|
|
|
return {
|
|
events = {
|
|
[e.on_entity_damaged] = on_entity_damaged,
|
|
},
|
|
}
|