File size: 2,307 Bytes
0712d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
-- src/ServerScriptService/MutationManager.server.lua

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MutationConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("MutationConfig"))

local function applyMutation(treeModel, hazardType)
    local config = MutationConfig.Hazards[hazardType]
    if not config then return end
    
    -- In Lumber Tycoon style, trees are models containing segments
    treeModel:SetAttribute("Mutated", hazardType)
    
    for _, part in pairs(treeModel:GetDescendants()) do
        if part:IsA("BasePart") and CollectionService:HasTag(part, "TreeSegment") then
            part:SetAttribute("TreeType", config.ModifiedType)
            part.Material = config.Material
            part.Color = config.Color
            
            -- Optional: Add a ParticleEmitter
            if hazardType == "Toxic" then
                local particles = Instance.new("ParticleEmitter")
                particles.Color = ColorSequence.new(config.Color)
                particles.Size = NumberSequence.new(0.5, 0)
                particles.Rate = 5
                particles.Parent = part
            end
        end
    end
end

-- Scan all hazard zones at startup (and potentially periodically)
local function scanForMutations()
    for _, hazardZone in pairs(CollectionService:GetTagged("HazardZone")) do
        local hazardType = hazardZone:GetAttribute("HazardType")
        local config = MutationConfig.Hazards[hazardType]
        
        if config then
            -- Find all trees near the hazard
            for _, tree in pairs(CollectionService:GetTagged("TreeModel")) do
                if not tree:GetAttribute("Mutated") then
                    local distance = (tree.PrimaryPart.Position - hazardZone.Position).Magnitude
                    if distance <= config.Radius then
                        if math.random() <= config.MutationChance then
                            applyMutation(tree, hazardType)
                        end
                    end
                end
            end
        end
    end
end

-- Run scan after a brief delay to ensure map has loaded
task.delay(5, scanForMutations)