mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-24 03:47:58 +02:00
pets
This commit is contained in:
parent
9711855787
commit
5f72ac69f2
@ -57,6 +57,7 @@ require "modules.floaty_chat"
|
||||
--require "modules.evolution_extended"
|
||||
--require "modules.no_blueprint_library"
|
||||
--require "modules.explosives"
|
||||
--require "modules.biter_pets"
|
||||
-----------------------------
|
||||
|
||||
---- enable maps here ----
|
||||
|
@ -1,7 +1,8 @@
|
||||
-- Mountain digger fortress, protect the cargo wagon! -- by MewMew
|
||||
|
||||
--require "modules.flashlight_toggle_button"
|
||||
require "modules.biter_noms_you"
|
||||
--require "modules.biter_noms_you"
|
||||
require "modules.biter_pets"
|
||||
require "modules.biter_evasion_hp_increaser"
|
||||
require "modules.wave_defense.main"
|
||||
--require "modules.dense_rocks"
|
||||
@ -134,6 +135,18 @@ local function hidden_biter(entity)
|
||||
end
|
||||
end
|
||||
|
||||
local function hidden_biter_pet(event)
|
||||
if math.random(1, 1024) ~= 1 then return end
|
||||
wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.42)
|
||||
local unit
|
||||
if math.random(1,3) == 1 then
|
||||
unit = event.entity.surface.create_entity({name = wave_defense_roll_spitter_name(), position = event.entity.position})
|
||||
else
|
||||
unit = event.entity.surface.create_entity({name = wave_defense_roll_biter_name(), position = event.entity.position})
|
||||
end
|
||||
biter_pets_tame_unit(game.players[event.player_index], unit, true)
|
||||
end
|
||||
|
||||
local function hidden_treasure(event)
|
||||
if math.random(1, 320) ~= 1 then return end
|
||||
if event.entity.type ~= "simple-entity" then return end
|
||||
@ -147,7 +160,8 @@ local function on_player_mined_entity(event)
|
||||
if math.random(1,32) == 1 then
|
||||
hidden_biter(event.entity)
|
||||
return
|
||||
end
|
||||
end
|
||||
hidden_biter_pet(event)
|
||||
hidden_treasure(event)
|
||||
end
|
||||
end
|
||||
|
@ -1,48 +1,68 @@
|
||||
local math_random = math.random
|
||||
local nom_msg = {"munch", "yum"}
|
||||
local nom_msg = {"munch", "munch", "yum"}
|
||||
|
||||
local function tame_unit_effects(player, entity)
|
||||
local function feed_floaty_text(unit)
|
||||
unit.surface.create_entity({name = "flying-text", position = unit.position, text = nom_msg[math_random(1, #nom_msg)], color = {math_random(50, 100), 0, 255}})
|
||||
end
|
||||
|
||||
local function floaty_hearts(entity, c)
|
||||
local position = {x = entity.position.x - 0.75, y = entity.position.y - 1}
|
||||
local b = 1.35
|
||||
for a = 1, 7, 1 do
|
||||
for a = 1, c, 1 do
|
||||
local p = {(position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), position.y + (b * -1 + math_random(0, b * 20) * 0.1)}
|
||||
player.surface.create_entity({name = "flying-text", position = p, text = "♥", color = {math_random(150, 255), 0, 255}})
|
||||
entity.surface.create_entity({name = "flying-text", position = p, text = "♥", color = {math_random(150, 255), 0, 255}})
|
||||
end
|
||||
end
|
||||
|
||||
local function tame_unit_effects(player, entity)
|
||||
floaty_hearts(entity, 7)
|
||||
|
||||
rendering.draw_text{
|
||||
text = "~" .. player.name .. "'s pet~",
|
||||
surface = player.surface,
|
||||
target = entity,
|
||||
target_offset = {0, -2.5},
|
||||
target_offset = {0, -2.6},
|
||||
color = {
|
||||
r = player.color.r * 0.6 + 0.25,
|
||||
g = player.color.g * 0.6 + 0.25,
|
||||
b = player.color.b * 0.6 + 0.25,
|
||||
a = 1
|
||||
},
|
||||
scale = 1.10,
|
||||
scale = 1.05,
|
||||
font = "default-game",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
end
|
||||
|
||||
local function tame_unit(player, entity)
|
||||
local function find_unit(player, entity)
|
||||
local units = player.surface.find_entities_filtered({type = "unit", area = {{entity.position.x - 1, entity.position.y - 1},{entity.position.x + 1, entity.position.y + 1}}, limit = 1})
|
||||
if not units[1] then return end
|
||||
entity.destroy()
|
||||
game.print(math.floor(units[1].prototype.max_health * 0.01) + 1)
|
||||
if math_random(1, math.floor(units[1].prototype.max_health * 0.01) + 1) ~= 1 then
|
||||
player.surface.create_entity({name = "flying-text", position = units[1].position, text = nom_msg[math_random(1, #nom_msg)], color = {math_random(50, 100), 0, 255}})
|
||||
return
|
||||
return units[1]
|
||||
end
|
||||
|
||||
local function feed_pet(unit)
|
||||
if unit.prototype.max_health == unit.health then return end
|
||||
unit.health = unit.health + 8 + math.floor(unit.prototype.max_health * 0.05)
|
||||
feed_floaty_text(unit)
|
||||
floaty_hearts(unit, math_random(1,2))
|
||||
return true
|
||||
end
|
||||
|
||||
function biter_pets_tame_unit(player, unit, forced)
|
||||
if global.biter_pets[player.index] then return false end
|
||||
if not forced then
|
||||
if math_random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then
|
||||
feed_floaty_text(unit)
|
||||
return true
|
||||
end
|
||||
end
|
||||
if units[1].force.index == player.force.index then return end
|
||||
units[1].ai_settings.allow_destroy_when_commands_fail = false
|
||||
units[1].ai_settings.allow_try_return_to_spawner = false
|
||||
units[1].force = player.force
|
||||
units[1].set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
global.biter_pets[player.index] = {last_command = 0, entity = units[1]}
|
||||
tame_unit_effects(player, units[1])
|
||||
if unit.force.index == player.force.index then return false end
|
||||
unit.ai_settings.allow_destroy_when_commands_fail = false
|
||||
unit.ai_settings.allow_try_return_to_spawner = false
|
||||
unit.force = player.force
|
||||
unit.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
global.biter_pets[player.index] = {last_command = 0, entity = unit}
|
||||
tame_unit_effects(player, unit)
|
||||
return true
|
||||
end
|
||||
|
||||
@ -50,12 +70,12 @@ local function command_unit(entity, player)
|
||||
if (player.position.x - entity.position.x) ^ 2 + (player.position.y - entity.position.y) ^ 2 < 256 then
|
||||
entity.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
else
|
||||
entity.set_command({type = defines.command.go_to_location, destination_entity = player.character, radius = 5, distraction = defines.distraction.by_damage})
|
||||
entity.set_command({type = defines.command.go_to_location, destination_entity = player.character, radius = 4, distraction = defines.distraction.by_damage})
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
if math_random(1, 32) ~= 1 then return end
|
||||
if math_random(1, 64) ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not global.biter_pets[player.index] then return end
|
||||
if not global.biter_pets[player.index].entity then global.biter_pets[player.index] = nil return end
|
||||
@ -68,9 +88,11 @@ end
|
||||
|
||||
local function on_player_dropped_item(event)
|
||||
local player = game.players[event.player_index]
|
||||
if global.biter_pets[player.index] then return end
|
||||
if event.entity.stack.name ~= "raw-fish" then return end
|
||||
tame_unit(player, event.entity)
|
||||
local unit = find_unit(player, event.entity)
|
||||
if not unit then return end
|
||||
if biter_pets_tame_unit(player, unit, false) then event.entity.destroy() return end
|
||||
feed_pet(unit)
|
||||
end
|
||||
|
||||
local function on_init(event)
|
||||
|
Loading…
x
Reference in New Issue
Block a user