1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-24 03:47:58 +02:00

Merge pull request #144 from ComfyFactory/mtn_v3

Mtn v3
This commit is contained in:
Gerkiz 2021-10-29 00:09:15 +02:00 committed by GitHub
commit 7e4fbfcf5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 365 additions and 46 deletions

View File

@ -61,6 +61,7 @@ chest_bought_info=__1__ __2__ has bought the chest limit upgrade for __3__ coins
health_bought_info=__1__ __2__ has bought the locomotive health modifier for __3__ coins.
aura_bought_info=__1__ __2__ has bought the locomotive xp aura modifier for __3__ coins.
xp_bought_info=__1__ __2__ has bought the XP points modifier for __3__ coins.
mystical_bought_info=__1__ __2__ has rerolled the mystical chest for __3__ coins.
reroll_bought_info=__1__ __2__ has rerolled the market items for __3__ coins.
pickaxe_bought_info=__1__ __2__ has upgraded the teams pickaxe to tier __3__ for __4__ coins.
explosive_bullet_bought_info=__1__ __2__ has bought the explosive bullet modifier for __3__ coins.
@ -76,6 +77,13 @@ notify_full_inventory_2=Your inventory is full. Join the warrior club today! Pum
new_items_at_market=New items have been unlocked at the locomotive market!
discharge_unlocked=Discharge defense has now been unlocked at the market!
artillery_unlocked=Artillery has now been unlocked at the market!
wd_paused=unlocked the last missing piece for the mystical chest!\n[color=yellow]Wave Defense has been paused for 15 minutes![/color]
mining_bonus=unlocked the last missing piece for the mystical chest!\n[color=yellow]Mining bonus has been applied for 15 minutes![/color]
movement_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Movement speed bonus has been applied for 15 minutes![/color]
coin_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Coins has been distributed![/color]
xp_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]XP has been granted to Global pool![/color]
inventory_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Inventory slot upgrade has been applied![/color]
locomotive_health=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Locomotive health has been replenished![/color]
[main_market]
@ -84,6 +92,7 @@ locomotive_max_health=Upgrades the train health.\nCan be purchased multiple time
locomotive_xp_aura=Upgrades the XP aura that is around the train. [__1__]
global_car_health_modifier=Grants all cars/tanks/spidertrons a global health modifier.
xp_points_boost=Upgrades the amount of XP points you get inside the XP aura [__1__]
mystical_chest=Rerolls the mystical chest.
explosive_bullets=Upgrades ordinary SMG ammo to explosive bullets.
reroll_market_items=Will reroll the items in the market and shuffle prices.
purchase_pickaxe=Upgrade the teams Pickaxe to tier: __1__ [__2__/58]

View File

@ -684,6 +684,27 @@ local mining_events = {
128,
'Enemy Compilatron'
},
{
function(entity, index)
local chest = 'crash-site-chest-' .. random(1, 2)
if entity.surface.can_place_entity({name = chest, position = entity.position, force = 'neutral'}) then
local container = entity.surface.create_entity({name = chest, position = entity.position, force = 'neutral'})
if container and container.health then
container.insert({name = 'vehicle-machine-gun', count = 1})
container.health = random(1, container.health)
end
end
local position = entity.position
local surface = entity.surface
surface.create_entity({name = 'car', position = position, force = 'player'})
Public.unstuck_player(index)
local player = game.players[index]
local msg = ({'entity.found_car', player.name})
Alert.alert_player(player, 15, msg)
end,
64,
'VSMG'
},
{
function(entity, index)
local position = entity.position
@ -1477,6 +1498,8 @@ local on_player_or_robot_built_tile = function(event)
end
end
Public.get_random_weighted = get_random_weighted
Event.add_event_filter(defines.events.on_entity_damaged, {filter = 'final-damage-amount', comparison = '>', value = 0})
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)

View File

@ -20,6 +20,7 @@ local MapFunctions = require 'tools.map_functions'
local SpamProtection = require 'utils.spam_protection'
local AI = require 'utils.ai'
local MysticalChest = require 'maps.mountain_fortress_v3.mystical_chest'
local Color = require 'utils.color_presets'
local format_number = require 'util'.format_number
@ -53,6 +54,24 @@ local space = {
bottom_padding = 0
}
local function get_random_weighted(weighted_table, weight_index)
local total_weight = 0
weight_index = weight_index or 1
for _, w in pairs(weighted_table) do
total_weight = total_weight + w[weight_index]
end
local index = random() * total_weight
local weight_sum = 0
for k, w in pairs(weighted_table) do
weight_sum = weight_sum + w[weight_index]
if weight_sum >= index then
return w, k
end
end
end
local function initial_cargo_boxes()
return {
{name = 'loader', count = 1},
@ -1038,6 +1057,30 @@ local function gui_opened(event)
redraw_market_items(pane, player, search_text)
end
local function init_price_check(locomotive, mystical_chest)
local roll = 48 + abs(locomotive.position.y) * 1.75
roll = roll * random(25, 1337) * 0.01
local item_stacks = {}
local roll_count = 2
for _ = 1, roll_count, 1 do
for _, stack in pairs(MysticalChest.roll(floor(roll / roll_count), 2)) do
if not item_stacks[stack.name] then
item_stacks[stack.name] = stack.count
else
item_stacks[stack.name] = item_stacks[stack.name] + stack.count
end
end
end
local price = {}
for k, v in pairs(item_stacks) do
insert(price, {name = k, count = v})
end
mystical_chest.price = price
end
local function gui_click(event)
local players = WPT.get('players')
if not players then
@ -1242,6 +1285,25 @@ local function gui_click(event)
return
end
if name == 'redraw_mystical_chest' then
player.remove_item({name = item.value, count = item.price})
local message = ({'locomotive.mystical_bought_info', shopkeeper, player.name, format_number(item.price, true)})
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has rerolled the mystical chest for ' .. format_number(item.price) .. ' coins.'
}
)
init_price_check(this.locomotive, this.mystical_chest)
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
return
end
if name == 'explosive_bullets' then
player.remove_item({name = item.value, count = item.price})
local message = ({
@ -1808,32 +1870,203 @@ local function divide_contents()
::final::
end
local function mystical_chest_reward()
-- something fancy to reward players
end
local pause_wd_token =
Token.register(
function()
WD.pause(false)
local mc_rewards = WPT.get('mc_rewards')
mc_rewards.temp_boosts.wave_defense = nil
end
)
local function init_price_check(locomotive, mystical_chest)
local roll = 48 + abs(locomotive.position.y) * 1.75
roll = roll * random(25, 2455) * 0.01
local item_stacks = {}
local roll_count = 2
for _ = 1, roll_count, 1 do
for _, stack in pairs(MysticalChest.roll(floor(roll / roll_count), 2)) do
if not item_stacks[stack.name] then
item_stacks[stack.name] = stack.count
else
item_stacks[stack.name] = item_stacks[stack.name] + stack.count
end
local restore_mining_speed_token =
Token.register(
function()
local mc_rewards = WPT.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.mining then
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier - 1
mc_rewards.temp_boosts.mining = nil
end
end
)
local price = {}
for k, v in pairs(item_stacks) do
insert(price, {name = k, count = v})
local restore_movement_speed_token =
Token.register(
function()
local mc_rewards = WPT.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.movement then
force.character_running_speed_modifier = force.character_running_speed_modifier - 1
mc_rewards.temp_boosts.movement = nil
end
end
)
local mc_random_rewards = {
{
name = 'XP',
color = {r = 0.00, g = 0.45, b = 0.00},
tooltip = 'Selecting this will insert random XP onto the global xp pool!',
func = (function(player)
local rng = random(1024, 10240)
RPG.add_to_global_pool(rng)
local message = ({'locomotive.xp_bonus', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
512
},
{
name = 'Coins',
color = {r = 0.00, g = 0.35, b = 0.00},
tooltip = 'Selecting this will grant each player some coins!',
func = (function(p)
local rng = random(256, 512)
local players = game.connected_players
for i = 1, #players do
local player = players[i]
if player and player.valid then
if player.can_insert({name = 'coin', count = rng}) then
player.insert({name = 'coin', count = rng})
end
end
end
local message = ({'locomotive.coin_bonus', p.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
512
},
{
name = 'Movement bonus',
str = 'movement',
color = {r = 0.00, g = 0.25, b = 0.00},
tooltip = 'Selecting this will grant the team a bonus movement speed for 15 minutes!',
func = (function(player)
local mc_rewards = WPT.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.movement then
return false, '[Rewards] Movement bonus is already applied. Please choose another reward.'
end
mc_rewards.temp_boosts.movement = true
Task.set_timeout_in_ticks(54000, restore_movement_speed_token)
force.character_running_speed_modifier = force.character_running_speed_modifier + 1
local message = ({'locomotive.movement_bonus', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
512
},
{
name = 'Mining bonus',
str = 'mining',
color = {r = 0.00, g = 0.00, b = 0.25},
tooltip = 'Selecting this will grant the team a bonus mining speed for 15 minutes!',
func = (function(player)
local mc_rewards = WPT.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.mining then
return false, '[Rewards] Mining bonus is already applied. Please choose another reward.'
end
mc_rewards.temp_boosts.mining = true
Task.set_timeout_in_ticks(54000, restore_mining_speed_token)
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 1
local message = ({'locomotive.mining_bonus', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
512
},
{
name = 'Inventory Bonus',
color = {r = 0.00, g = 0.00, b = 0.25},
tooltip = 'Selecting this will grant the team permanent inventory bonus!',
func = (function(player)
local force = game.forces.player
force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + 1
local message = ({'locomotive.inventory_bonus', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
512
},
{
name = 'Heal Locomotive',
color = {r = 0.00, g = 0.00, b = 0.25},
tooltip = 'Selecting this will heal the main locomotive to full health!',
func = (function(player)
local locomotive_max_health = WPT.get('locomotive_max_health')
WPT.set('locomotive_health', locomotive_max_health)
local message = ({'locomotive.locomotive_health', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
256
},
{
name = 'Wave Defense',
str = 'wave_defense',
color = {r = 0.35, g = 0.00, b = 0.00},
tooltip = 'Selecting this will pause the wave defense for 15 minutes. Ideal if you want to take a break!',
func = (function(player)
local mc_rewards = WPT.get('mc_rewards')
if mc_rewards.temp_boosts.wave_defense then
return false, '[Rewards] Wave Defense break is already applied. Please choose another reward.'
end
mc_rewards.temp_boosts.wave_defense = true
WD.pause(true)
Task.set_timeout_in_ticks(54000, pause_wd_token)
local message = ({'locomotive.wd_paused', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
end),
64
}
}
local function mystical_chest_reward(player)
if player.gui.screen['reward_system'] then
player.gui.screen['reward_system'].destroy()
return
end
mystical_chest.price = price
local frame = player.gui.screen.add {type = 'frame', caption = 'Mystical Reward:', name = 'reward_system', direction = 'vertical'}
frame.auto_center = true
frame = frame.add {type = 'frame', name = 'reward_system_1', direction = 'vertical', style = 'inside_shallow_frame'}
frame.style.padding = 4
local mc_rewards = WPT.get('mc_rewards')
mc_rewards.current = {}
for i = 1, 3 do
local d, key = get_random_weighted(mc_random_rewards)
if not mc_rewards.current[key] and not mc_rewards.temp_boosts[d.str] then
mc_rewards.current[key] = {
id = i,
name = d.name
}
local b = frame.add({type = 'button', name = tostring(i), caption = d.name})
b.style.font_color = d.color
b.style.font = 'heading-2'
b.style.minimal_width = 180
b.style.horizontal_align = 'center'
b.tooltip = d.tooltip
end
end
if not next(mc_rewards.current) then
if player.gui.screen['reward_system'] then
player.gui.screen['reward_system'].destroy()
end
return player.print('[Rewards] No rewards are available.', Color.fail)
end
-- something fancy to reward players
end
local function place_market()
@ -2052,13 +2285,12 @@ local function container_opened(event)
return
end
local has_succeeded = Public.add_mystical_chest()
if has_succeeded then
local player = game.players[event.player_index]
local colored_player_name =
table.concat({'[color=', player.color.r * 0.6 + 0.35, ',', player.color.g * 0.6 + 0.35, ',', player.color.b * 0.6 + 0.35, ']', player.name, '[/color]'})
game.print(colored_player_name .. ' unlocked the last missing piece for the mystical chest!')
local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end
Public.add_mystical_chest(player)
end
local function on_gui_opened(event)
@ -2069,6 +2301,42 @@ local function on_gui_closed(event)
container_opened(event)
end
local function on_gui_click(event)
local element = event.element
if not (element and element.valid) then
return
end
if element.type ~= 'button' then
return
end
if element.parent.name ~= 'reward_system_1' then
return
end
local i = tonumber(element.name)
local mc_rewards = WPT.get('mc_rewards')
local current = mc_rewards.current
local player = game.get_player(element.player_index)
if not (player and player.valid) then
return
end
for id, data in pairs(current) do
if data.id == i then
local success, msg = mc_random_rewards[id].func(player)
if not success then
return player.print(msg, Color.fail)
end
break
end
end
element.parent.parent.destroy()
end
function Public.close_gui_player(frame)
if not frame then
return
@ -2304,6 +2572,7 @@ function Public.get_items()
local aura_cost = round(fixed_prices.aura_cost * (1 + aura_upgrades))
local xp_point_boost_cost = round(fixed_prices.xp_point_boost_cost * (1 + xp_points_upgrade))
local explosive_bullets_cost = round(fixed_prices.explosive_bullets_cost)
local redraw_mystical_chest_cost = round(fixed_prices.redraw_mystical_chest_cost)
local flamethrower_turrets_cost = round(fixed_prices.flamethrower_turrets_cost * (1 + flame_turret))
local land_mine_cost = round(fixed_prices.land_mine_cost * (1 + landmine))
local car_health_upgrade_pool = fixed_prices.car_health_upgrade_pool_cost
@ -2428,6 +2697,18 @@ function Public.get_items()
upgrade = true,
static = true
}
main_market_items['redraw_mystical_chest'] = {
stack = 1,
value = 'coin',
price = redraw_mystical_chest_cost,
tooltip = ({'main_market.mystical_chest'}),
sprite = 'achievement/logistic-network-embargo',
enabled = true,
upgrade = true,
static = true
}
if WPT.get('explosive_bullets') then
main_market_items['explosive_bullets'] = {
stack = 1,
@ -2672,7 +2953,7 @@ function Public.get_items()
main_market_items['vehicle-machine-gun'] = {
stack = 1,
value = 'coin',
price = 2000,
price = 500,
tooltip = ({'item-name.vehicle-machine-gun'}),
upgrade = false,
static = true,
@ -2752,7 +3033,7 @@ function Public.enable_robotic_defense(pos)
end
end
function Public.add_mystical_chest()
function Public.add_mystical_chest(player)
local locomotive = WPT.get('locomotive')
if not locomotive then
return
@ -2784,7 +3065,9 @@ function Public.add_mystical_chest()
if #mystical_chest.price == 0 then
init_price_check(locomotive, mystical_chest)
mystical_chest_reward()
if player and player.valid then
mystical_chest_reward(player)
end
return true
end
@ -2831,10 +3114,8 @@ Public.init_price_check = init_price_check
Event.on_nth_tick(5, tick)
Event.add(defines.events.on_gui_click, gui_click)
Event.add(defines.events.on_gui_opened, gui_opened)
Event.add(defines.events.on_gui_value_changed, slider_changed)
Event.add(defines.events.on_gui_text_changed, text_changed)
Event.add(defines.events.on_gui_closed, gui_closed)
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_built_entity, on_built_entity)
@ -2846,7 +3127,10 @@ Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_player_changed_surface, on_player_changed_surface)
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
Event.add(defines.events.on_train_created, set_carriages)
Event.add(defines.events.on_gui_opened, gui_opened)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_gui_closed, gui_closed)
Event.add(defines.events.on_gui_closed, on_gui_closed)
Event.add(defines.events.on_gui_click, on_gui_click)
return Public

View File

@ -37,12 +37,6 @@ local item_worths = {
['train-stop'] = 64,
['rail-signal'] = 16,
['rail-chain-signal'] = 16,
['locomotive'] = 512,
['cargo-wagon'] = 256,
['fluid-wagon'] = 256,
['artillery-wagon'] = 16384,
['car'] = 128,
['tank'] = 4096,
['logistic-robot'] = 256,
['construction-robot'] = 256,
['logistic-chest-active-provider'] = 256,
@ -138,13 +132,11 @@ local item_worths = {
['production-science-pack'] = 256,
['utility-science-pack'] = 256,
['space-science-pack'] = 512,
['pistol'] = 4,
['submachine-gun'] = 32,
['shotgun'] = 16,
['combat-shotgun'] = 256,
['rocket-launcher'] = 128,
['flamethrower'] = 512,
['land-mine'] = 8,
['firearm-magazine'] = 4,
['piercing-rounds-magazine'] = 8,
['uranium-rounds-magazine'] = 64,
@ -154,7 +146,6 @@ local item_worths = {
['explosive-cannon-shell'] = 16,
['uranium-cannon-shell'] = 64,
['explosive-uranium-cannon-shell'] = 64,
['artillery-shell'] = 128,
['rocket'] = 8,
['explosive-rocket'] = 8,
['atomic-bomb'] = 16384,
@ -178,8 +169,6 @@ local item_worths = {
['battery-equipment'] = 128,
['battery-mk2-equipment'] = 2048,
['personal-laser-defense-equipment'] = 2048,
['discharge-defense-equipment'] = 2048,
['discharge-defense-remote'] = 32,
['belt-immunity-equipment'] = 256,
['exoskeleton-equipment'] = 1024,
['personal-roboport-equipment'] = 512,
@ -190,7 +179,6 @@ local item_worths = {
['gun-turret'] = 64,
['laser-turret'] = 1024,
['flamethrower-turret'] = 2048,
['artillery-turret'] = 8192,
['radar'] = 32,
['rocket-silo'] = 65536
}

View File

@ -175,7 +175,8 @@ function Public.reset_table()
explosive_bullets_cost = 10000,
flamethrower_turrets_cost = 3000,
land_mine_cost = 2,
car_health_upgrade_pool_cost = 100000
car_health_upgrade_pool_cost = 100000,
redraw_mystical_chest_cost = 3000
}
this.collapse_grace = true
this.explosive_bullets = false
@ -211,7 +212,11 @@ function Public.reset_table()
this.check_heavy_damage = true
this.prestige_system_enabled = false
this.has_upgraded_health_pool = false
this.mystical_chest_enabled = false -- needs rewards before enabling
this.mystical_chest_enabled = true
this.mc_rewards = {
current = {},
temp_boosts = {}
}
this.alert_zone_1 = false -- alert the players
for k, _ in pairs(this.players) do

View File

@ -506,7 +506,7 @@ function Public.get_heal_modifier_from_using_fish(player)
local position = player.position
if char and char.valid then
local health = player.character_health_bonus + 250
local multiplier = (vit - 10) * 0.018
local multiplier = (vit - 10) * 0.011
local final = multiplier * base_amount / 2
if final < 80 then
final = base_amount

View File

@ -1044,6 +1044,11 @@ local function on_tick()
return
end
local paused = WD.get('paused')
if paused then
return
end
local next_wave = WD.get('next_wave')
if tick > next_wave then
set_next_wave()

View File

@ -28,6 +28,7 @@ function Public.reset_wave_defense()
this.average_unit_group_size = 35
this.biter_raffle = {}
this.debug = false
this.paused = false
this.game_lost = false
this.get_random_close_spawner_attempts = 5
this.group_size = 2
@ -222,6 +223,10 @@ function Public.set_biter_health_boost(number)
return this.biter_health_boost
end
function Public.pause(boolean)
this.paused = boolean or false
end
local on_init = function()
Public.reset_wave_defense()
end