From ce1a603bfa8a347159bcb1dd30ece0d8b8534138 Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Thu, 2 Jun 2022 16:07:17 +0300 Subject: [PATCH] In progress --- control.lua | 4 +-- locale/en/pirates.cfg | 2 ++ maps/pirates/api_events.lua | 37 +++++++++++++++++++++++---- maps/pirates/balance.lua | 15 +++++++++++ maps/pirates/commands.lua | 34 +++++++++++++++++++++++- maps/pirates/common.lua | 1 - maps/pirates/main.lua | 4 +-- maps/pirates/memory.lua | 2 ++ maps/pirates/roles/classes.lua | 9 ++++++- maps/pirates/roles/roles.lua | 13 +++++++--- maps/pirates/roles/tick_functions.lua | 28 ++++++++++---------- 11 files changed, 120 insertions(+), 29 deletions(-) diff --git a/control.lua b/control.lua index 14b826b9..21182d2e 100644 --- a/control.lua +++ b/control.lua @@ -1,6 +1,6 @@ require 'utils.data_stages' _LIFECYCLE = _STAGE.control -- Control stage -_DEBUG = false +_DEBUG = true _DUMP_ENV = false require 'utils.server' @@ -112,7 +112,7 @@ require 'utils.freeplay' --require 'maps.chronosphere.main' --![[Adventure as a crew of pirates]]-- ---require 'maps.pirates.main' +require 'maps.pirates.main' --![[Launch rockets in increasingly harder getting worlds.]]-- --require 'maps.journey.main' diff --git a/locale/en/pirates.cfg b/locale/en/pirates.cfg index 3006dd9e..fa8e3213 100644 --- a/locale/en/pirates.cfg +++ b/locale/en/pirates.cfg @@ -150,8 +150,10 @@ parrot_captain_first_time_in_cabin_hint=The captain can buy items in the cabin, class_deckhand=Deckhand class_deckhand_explanation=They move faster and generate ore for the cabin whilst onboard above deck. +class_deckhand_explanation_advanced=Their move __1__x times faster and generate iron/copper ore(with current crew size +__2__ roughly every __3__ seconds) for the cabin whilst onboard above deck. class_fisherman=Fisherman class_fisherman_explanation=They fish at greater distance. +class_fisherman_explanation_advanced=They fish() at greater distance(__1__ extra tile range). class_scout=Scout class_scout_explanation=They are faster, but frail and deal less damage. class_samurai=Samurai diff --git a/maps/pirates/api_events.lua b/maps/pirates/api_events.lua index b9ab959b..227bed28 100644 --- a/maps/pirates/api_events.lua +++ b/maps/pirates/api_events.lua @@ -276,6 +276,8 @@ local function damage_to_players_changes(event) local damage_multiplier = 1 + --game.print('on damage info: {name: ' .. event.damage_type.name .. ', object_name: ' .. event.damage_type.object_name .. '}') + if event.damage_type.name == 'poison' then --make all poison damage stronger against players damage_multiplier = damage_multiplier * 1.85 else @@ -306,6 +308,24 @@ local function damage_to_players_changes(event) elseif damage_multiplier < 1 and event.final_health > 0 then --lethal damage needs to be unaffected, else they never die event.entity.health = event.entity.health + event.final_damage_amount * (1 - damage_multiplier) end + + + -- deal with damage reduction on lethal damage for players + local player = game.players[player_index] + if not (player and player.valid and player.character and player.character.valid) then + return + end + + local global_memory = Memory.get_global_memory() + + if damage_multiplier < 1 and event.final_health <= 0 then + local damage_dealt = event.final_damage_amount * damage_multiplier + if damage_dealt < global_memory.last_players_health[player_index] then + event.entity.health = global_memory.last_players_health[player_index] - damage_dealt + end + end + + global_memory.last_players_health[player_index] = event.entity.health end @@ -398,13 +418,13 @@ local function damage_dealt_by_players_changes(event) if physical then -- QUARTERMASTER BUFFS - local nearby_players = player.surface.find_entities_filtered{position = player.position, radius = Common.quartermaster_range, type = {'character'}} + local nearby_players = player.surface.find_entities_filtered{position = player.position, radius = Balance.quartermaster_range, type = {'character'}} for _, p2 in pairs(nearby_players) do if p2.player and p2.player.valid then local p2_index = p2.player.index if event.entity.valid and player_index ~= p2_index and memory.classes_table[p2_index] and memory.classes_table[p2_index] == Classes.enum.QUARTERMASTER then - event.entity.damage(0.1 * event.final_damage_amount, character.force, 'impact', character) --triggers this function again, but not physical this time + event.entity.damage(Balance.quartermaster_bonus_damage * event.final_damage_amount, character.force, 'impact', character) --triggers this function again, but not physical this time end end end @@ -759,13 +779,13 @@ local function event_on_player_mined_entity(event) if memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.MASTER_ANGLER then - Common.give(player, {{name = 'raw-fish', count = 4}, {name = 'coin', count = 10}}, entity.position) + Common.give(player, {{name = 'raw-fish', count = Balance.base_caught_fish_amount + Balance.master_angler_fish_bonus}, {name = 'coin', count = Balance.master_angler_coin_bonus}}, entity.position) elseif memory.classes_table and memory.classes_table[event.player_index] and memory.classes_table[event.player_index] == Classes.enum.DREDGER then - local to_give = {{name = 'raw-fish', count = 4}} + local to_give = {{name = 'raw-fish', count = Balance.base_caught_fish_amount + Balance.dredger_fish_bonus}} to_give[#to_give + 1] = Loot.dredger_loot()[1] Common.give(player, to_give, entity.position) else - Common.give(player, {{name = 'raw-fish', count = 3}}, entity.position) + Common.give(player, {{name = 'raw-fish', count = Balance.base_caught_fish_amount}}, entity.position) end event.buffer.clear() @@ -1251,6 +1271,8 @@ local function event_on_player_joined_game(event) Gui.info.toggle_window(player) end + global_memory.last_players_health[event.player_index] = player.character.health + -- player.teleport(surface.find_non_colliding_position('character', spawnpoint, 32, 0.5), surface) -- -- for item, amount in pairs(Balance.starting_items_player) do -- -- player.insert({name = item, count = amount}) @@ -1320,6 +1342,8 @@ local function event_on_pre_player_left_game(event) break end end + + global_memory.last_players_health[event.player_index] = nil end @@ -1774,6 +1798,9 @@ local function event_on_player_respawned(event) if player.character and player.character.valid then Task.set_timeout_in_ticks(360, boost_movement_speed_on_respawn, {player = player, crew_id = crew_id}) + + local global_memory = Memory.get_global_memory() + global_memory.last_players_health[event.player_index] = player.character.health end end end diff --git a/maps/pirates/balance.lua b/maps/pirates/balance.lua index 1fdb61f0..3bc8aee8 100644 --- a/maps/pirates/balance.lua +++ b/maps/pirates/balance.lua @@ -298,9 +298,24 @@ function Public.class_resource_scale() return 1 / (Public.crew_scale()^(2/5)) --already helped by longer timescales end +Public.base_caught_fish_amount = 3 +Public.class_reward_tick_rate_in_seconds = 7 + Public.samurai_resistance = 0.74 Public.hatamoto_resistance = 0.84 Public.iron_leg_resistance = 0.82 +Public.deckhand_extra_speed = 0.25 +Public.boatswain_extra_speed = 0.25 +Public.shoresman_extra_speed = 0.07 +Public.quartermaster_range = 19 +Public.quartermaster_bonus_damage = 0.1 +Public.scout_extra_speed = 0.35 +Public.fisherman_reach_bonus = 10 +Public.master_angler_reach_bonus = 16 +Public.master_angler_fish_bonus = 1 +Public.master_angler_coin_bonus = 10 +Public.dredger_reach_bonus = 16 +Public.dredger_fish_bonus = 1 function Public.biter_base_density_scale() local p = Public.crew_scale() diff --git a/maps/pirates/commands.lua b/maps/pirates/commands.lua index 550ee587..d8f6e4ba 100644 --- a/maps/pirates/commands.lua +++ b/maps/pirates/commands.lua @@ -69,7 +69,7 @@ function(cmd) if not Common.validate_player(player) then return end if param and param ~= 'nil' then - local string = Roles.get_class_print_string(param) + local string = Roles.get_class_print_string(param, false) if string then Common.notify_player_expected(player, {'', 'Class definition for ', string}) else @@ -80,6 +80,26 @@ function(cmd) end end) +commands.add_command( +'classinfofull', +'{classname} returns detailed definition of the named class.', +function(cmd) + local param = tostring(cmd.parameter) + local player = game.players[cmd.player_index] + if not Common.validate_player(player) then return end + + if param and param ~= 'nil' then + local string = Roles.get_class_print_string(param, true) + if string then + Common.notify_player_expected(player, {'', 'Class definition for ', string}) + else + Common.notify_player_error(player, 'Command error: Class ' .. param .. ' not found.') + end + else + Common.notify_player_expected(player, '/classinfofull {classname} returns detailed definition of the named class.') + end +end) + commands.add_command( 'take', '{classname} takes a spare class with the given name for yourself.', @@ -990,4 +1010,16 @@ if _DEBUG then Server.to_discord_embed_raw(CoreData.comfy_emojis.monkas) end end) + + commands.add_command( + 'piratux_test', + 'is a dev command of piratux.', + function(cmd) + local param = tostring(cmd.parameter) + if check_admin(cmd) then + local player = game.players[cmd.player_index] + + player.print('speed: ' .. player.character.speed .. 'effective_speed: ' .. player.character.effective_speed) + end + end) end \ No newline at end of file diff --git a/maps/pirates/common.lua b/maps/pirates/common.lua index 92c8b799..d437c8ff 100644 --- a/maps/pirates/common.lua +++ b/maps/pirates/common.lua @@ -36,7 +36,6 @@ Public.deepwater_distance_from_leftmost_shore = 32 Public.lobby_spawnpoint = {x = -72, y = -8} Public.structure_ensure_chunk_radius = 2 -Public.quartermaster_range = 19 Public.allow_barreling_off_ship = true Public.fraction_of_map_loaded_at_sea = 1 diff --git a/maps/pirates/main.lua b/maps/pirates/main.lua index 056d7563..ef99f993 100644 --- a/maps/pirates/main.lua +++ b/maps/pirates/main.lua @@ -308,8 +308,8 @@ local function crew_tick() PiratesApiOnTick.LOS_tick(240) end - if tick % 420 == 0 then - ClassPiratesApiOnTick.class_rewards_tick(420) + if tick % (60 * Balance.class_reward_tick_rate_in_seconds) == 0 then + ClassPiratesApiOnTick.class_rewards_tick(60 * Balance.class_reward_tick_rate_in_seconds) end if tick % 300 == 0 then diff --git a/maps/pirates/memory.lua b/maps/pirates/memory.lua index 83f77d03..93837bda 100644 --- a/maps/pirates/memory.lua +++ b/maps/pirates/memory.lua @@ -35,6 +35,8 @@ function Public.global_reset_memory() pirates_global_memory.global_delayed_tasks = {} pirates_global_memory.global_buffered_tasks = {} + + pirates_global_memory.last_players_health = {} --used to make damage reduction work somewhat properly end diff --git a/maps/pirates/roles/classes.lua b/maps/pirates/roles/classes.lua index f159f86d..70782a90 100644 --- a/maps/pirates/roles/classes.lua +++ b/maps/pirates/roles/classes.lua @@ -68,6 +68,10 @@ function Public.explanation(class) return {'pirates.class_' .. class .. '_explanation'} end +function Public.explanation_advanced(class) + return {'pirates.class_' .. class .. '_explanation_advanced', Balance.deckhand_extra_speed} +end + -- Public.display_form = { -- [enum.DECKHAND] = {'pirates.class_deckhand'}, -- } @@ -88,7 +92,7 @@ Public.class_unlocks = { Public.class_purchase_requirement = { [enum.MASTER_ANGLER] = enum.FISHERMAN, - [enum.WOOD_LORD] = enum.LUMBERJACK, + -- [enum.WOOD_LORD] = enum.LUMBERJACK, -- [enum.CHIEF_EXCAVATOR] = enum.PROSPECTOR, [enum.HATAMOTO] = enum.SAMURAI, [enum.DREDGER] = enum.MASTER_ANGLER, @@ -225,6 +229,9 @@ local function class_on_player_used_capsule(event) local item = event.item if not (item and item.name and item.name == 'raw-fish') then return end + local global_memory = Memory.get_global_memory() + global_memory.last_players_health[event.player_index] = player.character.health + if memory.classes_table and memory.classes_table[player_index] then local class = memory.classes_table[player_index] if class == Public.enum.GOURMET then diff --git a/maps/pirates/roles/roles.lua b/maps/pirates/roles/roles.lua index dd96b85d..0b065a85 100644 --- a/maps/pirates/roles/roles.lua +++ b/maps/pirates/roles/roles.lua @@ -130,14 +130,21 @@ end -- return str -- end -function Public.get_class_print_string(class) +function Public.get_class_print_string(class, full) for _, class2 in pairs(Classes.enum) do if Classes.eng_form[class2]:lower() == class:lower() or class2 == class:lower() then + local explanation = nil + if full then + explanation = Classes.explanation_advanced(class2) + else + explanation = Classes.explanation(class2) + end + if Classes.class_purchase_requirement[class2] then - return {'pirates.class_explanation_upgraded_class', Classes.display_form(class2), Classes.display_form(Classes.class_purchase_requirement[class2]), Classes.explanation(class2)} + return {'pirates.class_explanation_upgraded_class', Classes.display_form(class2), Classes.display_form(Classes.class_purchase_requirement[class2]), explanation} else - return {'pirates.class_explanation', Classes.display_form(class2), Classes.explanation(class2)} + return {'pirates.class_explanation', Classes.display_form(class2), explanation} end end end diff --git a/maps/pirates/roles/tick_functions.lua b/maps/pirates/roles/tick_functions.lua index 3b5c532d..202d703d 100644 --- a/maps/pirates/roles/tick_functions.lua +++ b/maps/pirates/roles/tick_functions.lua @@ -167,7 +167,7 @@ function Public.update_character_properties(tickinterval) local player_index = player.index local character = player.character if memory.classes_table and memory.classes_table[player_index] then - local max_reach_bonus = 0 + --local max_reach_bonus = 0 -- if memory.classes_table[player_index] == Classes.enum.DECKHAND then -- max_reach_bonus = Math.max(max_reach_bonus, 6) -- character.character_build_distance_bonus = 6 @@ -176,16 +176,16 @@ function Public.update_character_properties(tickinterval) -- end if memory.classes_table[player_index] == Classes.enum.FISHERMAN then - max_reach_bonus = Math.max(max_reach_bonus, 10) - character.character_resource_reach_distance_bonus = 10 - elseif memory.classes_table[player_index] == Classes.enum.MASTER_ANGLER or memory.classes_table[player_index] == Classes.enum.DREDGER then - max_reach_bonus = Math.max(max_reach_bonus, 16) - character.character_resource_reach_distance_bonus = 16 + character.character_reach_distance_bonus = Balance.fisherman_reach_bonus + elseif memory.classes_table[player_index] == Classes.enum.MASTER_ANGLER then + character.character_reach_distance_bonus = Balance.master_angler_reach_bonus + elseif memory.classes_table[player_index] == Classes.enum.DREDGER then + character.character_reach_distance_bonus = Balance.dredger_reach_bonus else - character.character_resource_reach_distance_bonus = 0 + character.character_reach_distance_bonus = 0 end - character.character_reach_distance_bonus = max_reach_bonus + --character.character_reach_distance_bonus = max_reach_bonus end local health_boost = 0 -- base health is 250 @@ -213,7 +213,7 @@ function Public.update_character_properties(tickinterval) if memory.classes_table and memory.classes_table[player_index] then local class = memory.classes_table[player_index] if class == Classes.enum.SCOUT then - speed_boost = speed_boost + 0.35 + speed_boost = speed_boost + Balance.scout_extra_speed elseif class == Classes.enum.DECKHAND or class == Classes.enum.BOATSWAIN or class == Classes.enum.SHORESMAN then local surfacedata = Surfaces.SurfacesCommon.decode_surface_name(player.surface.name) local type = surfacedata.type @@ -222,15 +222,15 @@ function Public.update_character_properties(tickinterval) if class == Classes.enum.DECKHAND then if on_ship_bool and (not hold_bool) then - speed_boost = speed_boost + 0.25 + speed_boost = speed_boost + Balance.deckhand_extra_speed end elseif class == Classes.enum.BOATSWAIN then if hold_bool then - speed_boost = speed_boost + 0.25 + speed_boost = speed_boost + Balance.boatswain_extra_speed end elseif class == Classes.enum.SHORESMAN then if not on_ship_bool then - speed_boost = speed_boost + 0.07 + speed_boost = speed_boost + Balance.shoresman_extra_speed end end end @@ -242,7 +242,7 @@ function Public.update_character_properties(tickinterval) end function Public.class_rewards_tick(tickinterval) - --assuming tickinterval = 6 seconds for now + --assuming tickinterval = 7 seconds for now local memory = Memory.get_crew_memory() local crew = Common.crew_get_crew_members() @@ -288,7 +288,7 @@ function Public.class_rewards_tick(tickinterval) elseif class == Classes.enum.SHORESMAN and (not on_ship_bool) then Classes.class_ore_grant(player, 2) elseif class == Classes.enum.QUARTERMASTER then - local nearby_players = #player.surface.find_entities_filtered{position = player.position, radius = Common.quartermaster_range, name = 'character'} + local nearby_players = #player.surface.find_entities_filtered{position = player.position, radius = Balance.quartermaster_range, name = 'character'} if nearby_players > 1 then Classes.class_ore_grant(player, nearby_players - 1, true)