mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-05 13:15:03 +02:00
planet_prison minor adjustments
This commit is contained in:
parent
01dfffa392
commit
3e0e4841a1
@ -29,6 +29,7 @@ local ceil = math.ceil
|
||||
local Public = {}
|
||||
local insert = table.insert
|
||||
local remove = table.remove
|
||||
local random = math.random
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
@ -806,6 +807,8 @@ local function init_player(p)
|
||||
p.force = pf
|
||||
end
|
||||
p.force.set_friend('neutral', true)
|
||||
p.force.set_friend('player', false)
|
||||
p.force.share_chart = false
|
||||
this.perks[p.name] = {
|
||||
flashlight_enable = true,
|
||||
minimap = false,
|
||||
@ -1339,6 +1342,7 @@ local function on_player_died(e)
|
||||
if game.forces[p.name] then
|
||||
game.merge_forces(p.name, 'neutral')
|
||||
end
|
||||
p.force = 'player'
|
||||
if p.connected then
|
||||
return
|
||||
end
|
||||
@ -1389,7 +1393,9 @@ local function on_player_dropped_item(e)
|
||||
|
||||
if this.last_friend[peer.name] == p.name then
|
||||
p.force.set_cease_fire(peer.name, true)
|
||||
p.force.set_friend(peer.name, true)
|
||||
peer.force.set_cease_fire(p.name, true)
|
||||
peer.force.set_friend(p.name, true)
|
||||
p.print(string.format('The NAP was formed with %s', peer.name))
|
||||
peer.print(string.format('The NAP was formed with %s', p.name))
|
||||
this.last_friend[p.name] = ''
|
||||
@ -1431,7 +1437,9 @@ local function on_player_dropped_item(e)
|
||||
end
|
||||
|
||||
p.force.set_cease_fire(peer.name, false)
|
||||
p.force.set_friend(peer.name, false)
|
||||
peer.force.set_cease_fire(p.name, false)
|
||||
peer.force.set_friend(p.name, false)
|
||||
|
||||
this.last_friend[p.name] = ''
|
||||
this.last_friend[peer.name] = ''
|
||||
@ -1520,18 +1528,19 @@ local function merchant_death(e)
|
||||
return true
|
||||
end
|
||||
|
||||
local coin_drops = {
|
||||
['character'] = true,
|
||||
['gun-turret'] = true
|
||||
}
|
||||
|
||||
local function hostile_death(e)
|
||||
local ent = e.entity
|
||||
local loot = e.loot
|
||||
if ent.name ~= 'character' then
|
||||
if not coin_drops[ent.name] then
|
||||
return false
|
||||
end
|
||||
|
||||
if ent.player then
|
||||
loot.insert({name = 'coin', count = 70})
|
||||
else
|
||||
loot.insert({name = 'coin', count = 10})
|
||||
end
|
||||
loot.insert({name = 'coin', count = random(30, 70)})
|
||||
|
||||
return true
|
||||
end
|
||||
|
@ -72,6 +72,26 @@ local function _move_to(ent, trgt, min_distance)
|
||||
return state.walking
|
||||
end
|
||||
|
||||
local function refill_ammo(ent)
|
||||
if not ent or not ent.valid then
|
||||
return
|
||||
end
|
||||
local weapon = ent.get_inventory(defines.inventory.character_guns)[ent.selected_gun_index]
|
||||
if weapon and weapon.valid_for_read then
|
||||
local selected_ammo = ent.get_inventory(defines.inventory.character_ammo)[ent.selected_gun_index]
|
||||
if selected_ammo then
|
||||
if not selected_ammo.valid_for_read then
|
||||
if weapon.name == 'shotgun' then
|
||||
ent.insert({name = 'shotgun-shell', count = 20})
|
||||
end
|
||||
if weapon.name == 'pistol' then
|
||||
ent.insert({name = 'firearm-magazine', count = 20})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function _shoot_at(ent, trgt)
|
||||
ent.shooting_state = {
|
||||
state = defines.shooting.shooting_enemies,
|
||||
@ -88,31 +108,26 @@ end
|
||||
|
||||
local function _do_job_seek_and_destroy_player(surf)
|
||||
for _, player in pairs(game.players) do
|
||||
if player.character == nil then
|
||||
goto continue
|
||||
end
|
||||
if player and player.valid and player.character then
|
||||
local search_info = {
|
||||
name = 'character',
|
||||
position = player.character.position,
|
||||
radius = 20,
|
||||
force = 'enemy'
|
||||
}
|
||||
|
||||
local search_info = {
|
||||
name = 'character',
|
||||
position = player.character.position,
|
||||
radius = 20,
|
||||
force = 'enemy'
|
||||
}
|
||||
|
||||
local ents = surf.find_entities_filtered(search_info)
|
||||
if not ents or #ents == 0 then
|
||||
goto continue
|
||||
end
|
||||
|
||||
for _, e in pairs(ents) do
|
||||
if not _move_to(e, player.character, CommonFunctions.rand_range(5, 10)) then
|
||||
_shoot_at(e, player.character)
|
||||
else
|
||||
_shoot_stop(e)
|
||||
local ents = surf.find_entities_filtered(search_info)
|
||||
if ents and #ents > 0 then
|
||||
for _, e in pairs(ents) do
|
||||
refill_ammo(e)
|
||||
if not _move_to(e, player.character, CommonFunctions.rand_range(5, 10)) then
|
||||
_shoot_at(e, player.character)
|
||||
else
|
||||
_shoot_stop(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,6 +5,8 @@ local Public = {}
|
||||
local this = {}
|
||||
local insert = table.insert
|
||||
local remove = table.remove
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
@ -184,7 +186,10 @@ Public.clear_player_base = function(player)
|
||||
for i = 1, #entities do
|
||||
local e = entities[i]
|
||||
if e and e.valid then
|
||||
e.destroy()
|
||||
e.health = e.health - random(30, 180)
|
||||
if e.health <= 0 then
|
||||
e.die('enemy')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user