OneCompiler

Lets Go Fisching

272

-- Untitled Fishing Engine
-- Version 1.7
-- WIP
-- Things To be added:
-- currency (gaining and saving money from fish)
-- Bait [might be possible] (second input is choosing your bait)

-- ================================
-- Rod Definitions
-- ================================
local rods = {
["Basic Rod"] = {luck = 1, description = "A simple rod suitable for beginners."},
["Lucky Rod"] = {luck = 1.5, description = "A well-crafted rod with special bait."},
["Divine Rod"] = {luck = 5, description = "A legendary rod blessed by the fishing gods."},
["Cursed Rod"] = {luck = .0001, description = "Test you rng with x1000 rarity"},
}

-- ================================
-- Fish Definitions
-- ================================
local fishEncounterRarity = {
Goldfish = 1500,
Salmon = 1000,
Crab = 800,
Shark = 500,
GiantSquid = 250,
SeaSerpent = 200,
Megalodon = 10,
Nessie = 5,
Kraken = 5
}

local fishCatchRarity = {
Goldfish = 5,
Salmon = 7,
Crab = 50,
Shark = 20,
GiantSquid = 75,
SeaSerpent = 90,
Megalodon = 100,
Nessie = 5,
Kraken = 1000
}

-- ================================
-- Function to Catch Fish
-- ================================
function catchFish(selectedRodLuck)
local fishTypes = {}

-- Adjusting fish rarity based on the selected rod's luck
for fish, rarity in pairs(fishEncounterRarity) do
    local adjustedEncounterRarity = math.floor(rarity / selectedRodLuck)
    local adjustedCatchRarity = math.floor(fishCatchRarity[fish] / selectedRodLuck)

    table.insert(fishTypes, {
        name = fish, 
        encounterChance = adjustedEncounterRarity, 
        catchChance = adjustedCatchRarity
    })
end

-- Calculate total weight for weighted random selection
local totalWeight = 0
for _, fish in ipairs(fishTypes) do
    totalWeight = totalWeight + fish.encounterChance
end

-- Select a fish based on encounter weights
local randomWeight = math.random(1, totalWeight)
local selectedFish

for _, fish in ipairs(fishTypes) do
    if randomWeight <= fish.encounterChance then
        selectedFish = fish
        break
    else
        randomWeight = randomWeight - fish.encounterChance
    end
end

-- Display encounter information
print("\n--- Encounter Information ---")
print("You encountered a " .. selectedFish.name .. "!")
print("Catch rarity: 1 in " .. selectedFish.catchChance .. "!\n")

-- Check for mutation (shiny, mythical, ancient)
local mutationChance = math.random(1, 100)  -- Random number between 1 and 100
local mutationType = ""

if mutationChance > 5 then  -- 95% chance for no mutation
    mutationType = ""  -- No mutation
elseif mutationChance <= 1 then  -- 1% chance for Shiny
    mutationType = "Shiny"
elseif mutationChance <= 0.1 then  -- 0.1% chance for Mythical
    mutationType = "Mythical"
elseif mutationChance <= 0.01 then  
    mutationType = "Ancient"  -- 0.01% chance for Ancient
elseif mutationChance <= 0.001 then
    mutationType = "Skibidi"  -- I DID NOT CHOOSE THIS! 0.001 chance for Skibidi
end


-- Display results
if mutationType ~= "" then
    print("You caught a " .. mutationType .. " " .. selectedFish.name .. "!")
else
    if math.random(1, selectedFish.catchChance) == 1 then
        print("Fish caught: " .. selectedFish.name)
    else
        print("The fish got away!")
    end
end

print("-----------------------------\n")

end

-- ================================
-- Main Function (mostly printing and error calls)
-- ================================
print("Choose your fishing rod:")
print("Basic Rod, Lucky Rod, Divine Rod")
local selectedRod = io.read("*l")
if rods[selectedRod] then
local selectedRodLuck = rods[selectedRod].luck
local selectedRodDescription = rods[selectedRod].description
print("\n--- Rod Information ---")
print("Rod: " .. selectedRod .. ": luck multiplier of " .. selectedRodLuck .. ".")
print("Description: " .. selectedRodDescription .. "\n")
catchFish(selectedRodLuck)
else
print("\nInvalid rod name. Please choose a valid rod.\n")
end