This commit is contained in:
FerrDev 2026-05-26 14:55:15 +02:00
parent 05c424e6c1
commit 519f7966b7

View File

@ -9,67 +9,64 @@ local rBotUtils = require(rUtils.sharedBotUtils)
local rData = ReplicatedStorage.Data local rData = ReplicatedStorage.Data
local rWeaponData = require(rData.WeaponData) local rWeaponData = require(rData.WeaponData)
local Component = script.Parent.Component local Component = script.Parent.Component
local HitboxComponent = require(Component.HitboxComponent) local HitboxComponent = require(Component.HitboxComponent)
local ProjectileComponent = require(Component.ProjectileComponent) local ProjectileComponent = require(Component.ProjectileComponent)
local HealthComponent = require(Component.HealthComponent) local HealthComponent = require(Component.HealthComponent)
local DestroyableComponent = require(Component.DestroyableComponent) local DestroyableComponent = require(Component.DestroyableComponent)
local Janitor = require(ReplicatedStorage:WaitForChild("Janitor")) local Janitor = require(workspace:WaitForChild("Janitor"))
GameObject.__index = GameObject GameObject.__index = GameObject
type self = { type self = {
key : string, key: string,
owner : number?, owner: number?,
model : Model?, model: Model?,
type : string, type: string,
active : boolean, active: boolean,
Janitor : typeof(Janitor.new()), Janitor: typeof(Janitor.new()),
Components : { Components: {
Projectile : ProjectileComponent.ProjectileComponent, Projectile: ProjectileComponent.ProjectileComponent,
Hitbox : HitboxComponent.HitboxComponent, Hitbox: HitboxComponent.HitboxComponent,
Health : HealthComponent.HealthComponent, Health: HealthComponent.HealthComponent,
Destroyable : DestroyableComponent.DestroyableComponent Destroyable: DestroyableComponent.DestroyableComponent,
}, },
timepassed : number, timepassed: number,
tickspassed : number, tickspassed: number,
} }
--GameObject(TurnEnd, TurnStart, OnDestroy, Tick) Anything that needs this is a gameobject --GameObject(TurnEnd, TurnStart, OnDestroy, Tick) Anything that needs this is a gameobject
export type GameObject = typeof(setmetatable({} :: self, GameObject))
export type GameObject = typeof( setmetatable({} :: self, GameObject) ) function GameObject.new(key: string?, model: Model, userId: number?, active)
local self = setmetatable({} :: self, GameObject)
function GameObject.new(key : string?,model : Model,userId : number?,active)
local self = setmetatable({} :: self,GameObject)
key = key or HttpServ:GenerateGUID(false) key = key or HttpServ:GenerateGUID(false)
print(key) print(key)
self.owner = userId self.owner = userId
self.model = model self.model = model
self.Janitor = Janitor.new() self.Janitor = Janitor.new()
self.key = key self.key = key
self.timepassed = 0 self.timepassed = 0
self.tickspassed = 0 self.tickspassed = 0
self.active = active self.active = active
self.Components = {} self.Components = {}
return self return self
end end
-- DONT OVERWRITE THESE -- DONT OVERWRITE THESE
function GameObject:_Init() function GameObject:_Init()
if self.model then if self.model then
self.model:SetAttribute("key",self.key) self.model:SetAttribute("key", self.key)
end end
self:_ResetMass() self:_ResetMass()
self:OnCreate() self:OnCreate()
self:_Store() self:_Store()
@ -78,7 +75,7 @@ end
-- DONT OVERWRITE THESE -- DONT OVERWRITE THESE
function GameObject:_Store() function GameObject:_Store()
ObjectManager.Store(self.key,self) ObjectManager.Store(self.key, self)
end end
-- DONT OVERWRITE THESE -- DONT OVERWRITE THESE
@ -93,13 +90,13 @@ function GameObject:_ResetMass()
local self = self :: GameObject local self = self :: GameObject
if self.model then if self.model then
local primaryPart = self.model.PrimaryPart local primaryPart = self.model.PrimaryPart
for i,v in pairs(self.model:GetDescendants()) do for i, v in pairs(self.model:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
if primaryPart == v or v.Parent.Name == "Hitbox" then if primaryPart == v or v.Parent.Name == "Hitbox" then
continue continue
end end
v.Massless = true v.Massless = true
end end
end end
end end
end end
@ -107,7 +104,7 @@ end
-- DONT OVERWRITE THESE -- DONT OVERWRITE THESE
function GameObject:_BeforeTick(dt) function GameObject:_BeforeTick(dt)
local self = self :: GameObject local self = self :: GameObject
self.timepassed += dt self.timepassed += dt
self.tickspassed += 1 self.tickspassed += 1
end end
@ -118,7 +115,7 @@ function GameObject:_Destroy()
pcall(function() pcall(function()
self:BeforeDestroy() self:BeforeDestroy()
end) end)
pcall(function() pcall(function()
if self.model then if self.model then
self.model:Destroy() self.model:Destroy()
@ -126,7 +123,6 @@ function GameObject:_Destroy()
self.Janitor:Destroy() self.Janitor:Destroy()
ObjectManager._Free(self.key) ObjectManager._Free(self.key)
end) end)
end end
----------------------------------------- -----------------------------------------
@ -136,38 +132,30 @@ end
--if true resolve can resolve early(if all gameobjects agree :o) --if true resolve can resolve early(if all gameobjects agree :o)
function GameObject:ShouldEnd() function GameObject:ShouldEnd()
if self.model then if self.model then
return return
end end
end end
function GameObject:GetWeaponData(name) : rWeaponData.WeaponData function GameObject:GetWeaponData(name): rWeaponData.WeaponData
return rWeaponData[name] return rWeaponData[name]
end end
function GameObject:OnHit() function GameObject:OnHit()
local self = self :: GameObject local self = self :: GameObject
end end
function GameObject:OnTurnEnd() function GameObject:OnTurnEnd()
local self = self :: GameObject local self = self :: GameObject
end end
function GameObject:Tick(dt) function GameObject:Tick(dt) end
end
function GameObject:OnCreate() function GameObject:OnCreate()
local self = self :: GameObject local self = self :: GameObject
end end
--Before Destroying --Before Destroying
function GameObject:BeforeDestroy() function GameObject:BeforeDestroy()
local self = self :: GameObject local self = self :: GameObject
end end
return GameObject return GameObject