Skip to content

Commit

Permalink
feat: correct seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Aug 27, 2024
1 parent 98da619 commit 2754600
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 71 deletions.
24 changes: 18 additions & 6 deletions assets/scripts/_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ end
---highlight_warn some value with warning colors
---@param val any
function highlight_warn(val)
return text_underline(text_bold(_escape_color("38;5;161") .. "[" .. tostring(val) .. "]" .. string.char(27) .. "[0m"))
return text_underline(text_bold(_escape_color("38;5;161") .. "[" .. tostring(val) .. "]" .. string.char(27) .. "[0m"))
end

---highlight_success some value with success colors
---@param val any
function highlight_success(val)
return text_underline(text_bold(_escape_color("38;5;119") .. "[" .. tostring(val) .. "]" .. string.char(27) .. "[0m"))
return text_underline(text_bold(_escape_color("38;5;119") .. "[" .. tostring(val) .. "]" .. string.char(27) .. "[0m"))
end

---choose_weighted chooses an item from a list of choices, with a weight for each item.
Expand All @@ -33,7 +33,7 @@ function choose_weighted(choices, weights)
total_weight = total_weight + weight
end

local random = math.random() * total_weight
local random = random() * total_weight
for i, weight in ipairs(weights) do
random = random - weight
if random <= 0 then
Expand Down Expand Up @@ -83,27 +83,39 @@ end
---@param tags string[]
---@return artifact[]
function find_artifacts_by_tags(tags)
return find_by_tags(registered.artifact, tags)
local found = find_by_tags(registered.artifact, tags)
table.sort(found, function(a, b) return a.id:upper() < b.id:upper() end)
return found
end

---find_cards_by_tags find all cards with the given tags.
---@param tags string[]
---@return card[]
function find_cards_by_tags(tags)
return find_by_tags(registered.card, tags)
local found = find_by_tags(registered.card, tags)
table.sort(found, function(a, b) return a.id:upper() < b.id:upper() end)
return found
end

---find_events_by_tags find all events with the given tags.
---@param tags string[]
---@return event[]
function find_events_by_tags(tags)
return find_by_tags(registered.event, tags)
local found = find_by_tags(registered.event, tags)
--table.sort(found, function(a, b) return a.id:upper() < b.id:upper() end)
return found
end

---choose_weighted_by_price choose a random item from the given list, weighted by price.
---@param items artifact|card
---@return string
function choose_weighted_by_price(items)
table.sort(items, function(a, b)
if a.id == nil then
return a.type_id < b.type_id
end
return a.id < b.id
end)
return choose_weighted(
fun.iter(items):map(function(item) return item.id or item.type_id end):totable(),
fun.iter(items):map(function(item) return item.price end):totable()
Expand Down
10 changes: 10 additions & 0 deletions assets/scripts/definitions/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ function fetch(key) end
---@return guid
function guid() end

--- Returns a random number between 0 and 1
---@return number
function random() end

--- Returns a random number between min and max
---@param min number
---@param max number
---@return number
function random_int(min, max) end

--- Stores a persistent value for this run that will be restored after a save load. Can store any lua basic value or table.
---@param key string
---@param value any
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/enemies/_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function cast_random(guid, target)
if #cards == 0 then
print("can't cast_random with zero cards available!")
else
cast_card(cards[math.random(#cards)], target)
cast_card(cards[random_int(0, #cards)], target)
end
end

Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/enemies/cyber_slime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ register_enemy("CYBER_SLIME", {

add_actor_by_enemy("CYBER_SLIME_MINION")
add_actor_by_enemy("CYBER_SLIME_MINION")
if math.random() < 0.25 then
if random() < 0.25 then
add_actor_by_enemy("CYBER_SLIME_MINION")
end
return nil
Expand Down
20 changes: 10 additions & 10 deletions assets/scripts/events/act_0/enemies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ It seems to be eating the metal from the walls. It looks at you and after a few
description = "Fight!",
callback = function()
add_actor_by_enemy("RUST_MITE")
if math.random() < 0.25 then
if random() < 0.25 then
add_actor_by_enemy("RUST_MITE")
end
if math.random() < 0.15 then
if random() < 0.15 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand All @@ -41,10 +41,10 @@ It looks at you and says "Corpse. Clean. Engage.".
description = "Fight!",
callback = function()
add_actor_by_enemy("CLEAN_BOT")
if math.random() < 0.25 then
if random() < 0.25 then
add_actor_by_enemy("CLEAN_BOT")
end
if math.random() < 0.15 then
if random() < 0.15 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand All @@ -66,10 +66,10 @@ It seems to be waiting for its prey to come closer and there is no way around it
description = "Fight!",
callback = function()
add_actor_by_enemy("CYBER_SPIDER")
if math.random() < 0.25 then
if random() < 0.25 then
add_actor_by_enemy("CYBER_SPIDER")
end
if math.random() < 0.15 then
if random() < 0.15 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand All @@ -93,10 +93,10 @@ As you explore the facility, you hear a high-pitched whirring sound. A drone equ
description = "Fight!",
callback = function()
add_actor_by_enemy("LASER_DRONE")
if math.random() < 0.10 then
if random() < 0.10 then
add_actor_by_enemy("LASER_DRONE")
end
if math.random() < 0.15 then
if random() < 0.15 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand All @@ -120,7 +120,7 @@ As you delve deeper into the facility, you notice a bright glow emanating from a
description = "Fight!",
callback = function()
add_actor_by_enemy("PLASMA_GOLEM")
if math.random() < 0.05 then
if random() < 0.05 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand All @@ -144,7 +144,7 @@ As you explore the facility, you come across a strange cybernetic slime. It seem
description = "Fight!",
callback = function()
add_actor_by_enemy("CYBER_SLIME")
if math.random() < 0.10 then
if random() < 0.10 then
add_actor_by_enemy("REPAIR_DRONE")
end
return GAME_STATE_FIGHT
Expand Down
4 changes: 2 additions & 2 deletions assets/scripts/events/act_0/other.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ You find a room with a strange device in the middle. It seems to be some kind of
:filter(function(card)
return card.does_consume
end):totable()
if math.random() < 0.5 then
if random() < 0.5 then
local choosen = choose_weighted_by_price(possible_artifacts)
if choosen then
give_artifact(choosen, PLAYER_ID)
Expand Down Expand Up @@ -232,7 +232,7 @@ You find a old automatic workstation. You are able to get it working again. You
return nil
end

local choosen = cards[math.random(#cards)]
local choosen = cards[random_int(0, #cards)]
upgrade_card(choosen)
deal_damage(PLAYER_ID, PLAYER_ID, 2, true)

Expand Down
6 changes: 3 additions & 3 deletions assets/scripts/libs/fun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local string_gen = function(param, state)
return state, r
end

local ipairs_gen = ipairs({}) -- get the generating function from ipairs
local ipairs_gen = ipairs({}) -- get the generating function from ipairs

local pairs_gen = pairs({ a = 0 }) -- get the generating function from pairs
local map_gen = function(tab, key)
Expand Down Expand Up @@ -262,11 +262,11 @@ end
exports.ones = ones

local rands_gen = function(param_x, _state_x)
return 0, math.random(param_x[1], param_x[2])
return 0, random_int(param_x[1], param_x[2])
end

local rands_nil_gen = function(_param_x, _state_x)
return 0, math.random()
return 0, random()
end

local rands = function(n, m)
Expand Down
8 changes: 6 additions & 2 deletions assets/scripts/story_teller/act_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ register_story_teller("_ACT_0", {
if #possible == 0 then
possible = find_events_by_tags({ "_ACT_0_FIGHT" })
end
set_event(possible[math.random(#possible)].id)

local choosen = possible[random_int(0, #possible)]
if choosen ~= nil then
set_event(choosen.id)
end

-- if we cleared a stage, give the player a random artifact
local last_stage_count = fetch("last_stage_count")
local current_stage_count = get_stages_cleared()
if last_stage_count ~= current_stage_count then
local gets_random_artifact = math.random() < 0.25
local gets_random_artifact = random() < 0.25

if gets_random_artifact then
local player_artifacts = fun.iter(get_actor(PLAYER_ID).artifacts):map(function(id)
Expand Down
2 changes: 2 additions & 0 deletions cmd/game_win/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func initSystems(hasAudio bool) {
}

func main() {
os.Setenv("EOE_IMG_TRUECOLOR", "1")

testArgs := testargs.New()
flag.Parse()

Expand Down
Loading

0 comments on commit 2754600

Please sign in to comment.