-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFishManager.lua
More file actions
154 lines (121 loc) · 3.72 KB
/
FishManager.lua
File metadata and controls
154 lines (121 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
local FishManager = {}
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
--// Variables
local fishTypes = {}
local fishRarityWeights = {
Common = 100,
Uncommon = 50,
Rare = 25,
Epic = 10,
Legendary = 2
}
--// Initialize the Fish Manager
function FishManager.Init(fishConfig)
assert(typeof(fishConfig) == "table", "Fish config must be a table")
fishTypes = fishConfig
end
function FishManager.GetRandomFish(zone, rodRarityBonus)
local zoneMultipliers = {
Common = 1,
Uncommon = 1,
Rare = 1,
Epic = 1,
Legendary = 1
}
if zone then
zoneMultipliers = {
Common = zone.CommonFishMultiplier or 1,
Uncommon = zone.UncommonFishMultiplier or 1,
Rare = zone.RareFishMultiplier or 1,
Epic = zone.EpicFishMultiplier or 1,
Legendary = zone.LegendaryFishMultiplier or 1
}
end
rodRarityBonus = rodRarityBonus or 0
local rarityPool = {}
local totalWeight = 0
for rarity, baseWeight in pairs(fishRarityWeights) do
local adjustedWeight = baseWeight * zoneMultipliers[rarity] * (1 + rodRarityBonus)
rarityPool[rarity] = adjustedWeight
totalWeight = totalWeight + adjustedWeight
end
local randomValue = math.random() * totalWeight
local currentTotal = 0
local selectedRarity = "Common"
for rarity, weight in pairs(rarityPool) do
currentTotal = currentTotal + weight
if randomValue <= currentTotal then
selectedRarity = rarity
break
end
end
local fishesOfRarity = fishTypes[selectedRarity]
if not fishesOfRarity or #fishesOfRarity == 0 then
return nil
end
local randomFishIndex = math.random(1, #fishesOfRarity)
local fishTemplate = fishesOfRarity[randomFishIndex]
local weightRange = fishTemplate.Weight
local randomWeight = weightRange.Min + math.random() * (weightRange.Max - weightRange.Min)
local fish = {
Id = fishTemplate.Name .. "_" .. tostring(tick()),
Name = fishTemplate.Name,
Model = fishTemplate.Model,
Rarity = fishTemplate.Rarity,
Weight = randomWeight,
Value = fishTemplate.Value,
CatchDifficulty = fishTemplate.CatchDifficulty
}
return fish
end
function FishManager.GetCatchTime(fish, rodReelSpeed)
assert(fish, "Fish must be provided")
assert(typeof(fish.CatchDifficulty) == "number", "Fish must have a catch difficulty")
rodReelSpeed = rodReelSpeed or 1
local baseTime = fish.CatchDifficulty * 2
local scaledTime = baseTime / rodReelSpeed
local randomVariation = math.random(-1, 1)
local finalTime = scaledTime + randomVariation
return math.max(2, finalTime)
end
function FishManager.GetFishValue(fish)
if not fish then return 0 end
local baseValue = fish.Value
local weightMultiplier = 1 + (fish.Weight / 10)
local rarityMultipliers = {
Common = 1,
Uncommon = 1.5,
Rare = 2.5,
Epic = 5,
Legendary = 10
}
local rarityMultiplier = rarityMultipliers[fish.Rarity] or 1
return math.floor(baseValue * weightMultiplier * rarityMultiplier)
end
function FishManager.CreateFishInstance(fish)
if not fish then return nil end
local fishModel = ReplicatedStorage:FindFirstChild("FishModels") and
ReplicatedStorage.FishModels:FindFirstChild(fish.Model)
if not fishModel then
warn("Fish model not found: " .. fish.Model)
return nil
end
local fishInstance = fishModel:Clone()
local rarityColors = {
Common = Color3.fromRGB(255, 255, 255),
Uncommon = Color3.fromRGB(100, 255, 100),
Rare = Color3.fromRGB(100, 100, 255),
Epic = Color3.fromRGB(200, 100, 255),
Legendary = Color3.fromRGB(255, 215, 0)
}
if fish.Rarity and rarityColors[fish.Rarity] then
local primary = fishInstance:FindFirstChild("Primary")
if primary and primary:IsA("BasePart") then
primary.Color = rarityColors[fish.Rarity]
end
end
return fishInstance
end
return FishManager