--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void OnBeginPlay()
{
self._T.monsterModel = "model://225a99de-b931-4e51-9c1d-b8fa15ab2eca" --임시용
self._T.mobIdx = 1 --오브젝트 풀링용 몬스터 번호 --디버그용
self._T.posIdx = 0 --pos 테이블 인덱스 저장용
self:SetTables()
self:SetSpawnTimers(1)
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SetTables()
{
self._T.objects = {}
self:SetMobInfo()
self:SetMobComp()
self:SetPosTable()
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SetMobInfo()
{
--임시용
self._T.mobInfo = {}
self._T.mobInfo[1] = {img = "0b2d276b59754f46a9f7009a53e7fb89", hp = 5, spd = 0.3, dmg = 6, exp = 2}
self._T.mobInfo[2] = {img = "000931d9164248eaadacc497b30978ee", hp = 10, spd = 0.7, dmg = 7, exp = 3}
self._T.mobInfo[3] = {img = "c96c11f9a3f845a4b6a27d9ca10ab103", hp = 15, spd = 1.3, dmg = 7, exp = 3}
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SetMobComp()
{
--임시용
self._T.mobComp = {}
self._T.mobComp[1] = {
{idx = 1, cnt = 10},
{idx = 2, cnt = 5}
}
self._T.mobComp[2] = {
{idx = 2, cnt = 3},
{idx = 3, cnt = 4}
}
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SetPosTable()
{
--임시용
self._T.posTable = {}
self._T.posTable[1] = Vector3.zero
self._T.posTable[2] = Vector3(6, 0, 0)
self._T.posTable[3] = Vector3(0, 6, 0)
self._T.posTable[4] = Vector3(6, 6, 0)
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SetSpawnTimers(number stage)
{
local mobs = self._T.mobComp[stage]
local maxTime = self.stageManager.maxTime
for k, v in pairs(mobs) do
local callBack = function() self:SpawnMob(v.idx) end
local interval = maxTime / v.cnt
_TimerService:SetTimerRepeat(callBack, interval, interval)
end
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void SpawnMob(number idx)
{
local mob = self:GetPooledMob()
local mi = self._T.mobInfo[idx]
mob.MonsterStat:SetMobStat(mi.img, mi.hp, mi.spd, mi.dmg, mi.exp)
mob.Enable = true
log("spawned "..tostring(idx))
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
Entity GetPooledMob()
{
local mob = self._T.objects[1]
if mob then
table.remove(self._T.objects, 1)
return mob
end
return self:CreateNewMob()
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
Entity CreateNewMob()
{
self._T.posIdx = self._T.posIdx + 1
if (self._T.posIdx > #self._T.posTable) then self._T.posIdx = 1 end
local pos = self._T.posTable[self._T.posIdx]
local mob = _SpawnService:SpawnByModelId(self._T.monsterModel, "Monster"..self._T.mobIdx, pos, self.map)
self._T.mobIdx = self._T.mobIdx + 1
return mob
}
--@ EndMethod
--@ BeginMethod
--@ MethodExecSpace=ServerOnly
void DisableMob(Entity mob)
{
mob.Enable = false
table.insert(self._T.objects, mob)
}
--@ EndMethod
몬스터 스폰을 오브젝트 풀링 방식으로 구현하였다.

잘 작동한다.
'Game > MSW' 카테고리의 다른 글
메이플스토리 월드로 게임 만들기 - 7 (0) | 2022.10.30 |
---|---|
메이플스토리 월드로 게임 만들기 - 6 (0) | 2022.10.27 |
메이플스토리 월드로 게임 만들기 - 4 (0) | 2022.10.23 |
메이플스토리 월드로 게임 만들기 - 3 (4) | 2022.10.22 |
메이플스토리 월드로 게임 만들기 - 2 (0) | 2022.10.22 |