채팅0

    펫박 만들고있는데

    조회수 589

    return function (self)

    local owner = self.Owner

    if (not isvalid(owner)) then

    return

    end

    local now = _UtilLogic.ServerElapsedSeconds

    if (self.WaitingForServer > now) then

    return

    end

    local pet = self.Entity

    local userState = owner.StateComponent.CurrentStateName

    local userIsOnRope = userState == "LADDER" or userState == "CLIMB"

    local petState = pet.StateComponent.CurrentStateName


    local function clearSweepTarget()

    self.SweepTemporaryExceptions[self.SweepTargetId] = nil

    self.SweepTarget = nil

    self.SweepTargetId = 0

    self.SweepOrigin = Vector3.zero

    end


    local function setWaitingServer()

    self.WaitingForServer = now + 5

    end


    -- ?щ떎由?泥댄겕

    if (userIsOnRope) then

    if (petState ~= "HANG") then

    setWaitingServer()

    self:RequestPetAction("ATTACH", 0)

    clearSweepTarget()

    end

    return

    end


    -- ?щ떎由ъ뿉???섏삤硫??댄깭移??댁젣

    if (petState == "HANG") then

    local dir = 0

    if (userState == "FALL" or userState == "JUMP") then

    dir = owner.PlayerControllerComponent.LookDirectionX

    end

    setWaitingServer()

    self:RequestPetAction("DETACH", dir)

    return

    end


    local userPos = owner.TransformComponent.WorldPosition

    local petPos = pet.TransformComponent.WorldPosition

    local xDiff = userPos.x - petPos.x

    local yDiff = userPos.y - petPos.y

    local abs = math.abs

    local absXDiff = abs(xDiff)


    -- ?좎? ?꾩튂濡??쒓컙?대룞

    if (absXDiff> 3 or abs(yDiff) > 2) then

    setWaitingServer()

    self:RequestPetAction("TELEPORT", 0)

    clearSweepTarget()

    return

    end


    -- ?좎??먭쾶 ?곕씪媛湲?if (_PetLogic.PetMovableState[petState]) then

    if (self.InputX == 0) then

    if (petState == "ACTION") then

    if (self.MoveAvailable > _UtilLogic.ServerElapsedSeconds) then

    return

    end

    end

    end

    local isLongRange = false
    local petMoveRange = isLongRange and 1.5 or 0.6
    local maxMoveRange = petMoveRange + 0.2
    
    ---@return table<Entity>
    local function getSweepableDrops()
    	local box = BoxShape(petPos:ToVector2(), Vector2(2.8, 0.1), 0)
    	local simulator = _CollisionService:GetSimulator(pet.CurrentMap)
    	local result = {}
    	local cnt = simulator:OverlapAllFast(CollisionGroups.MapleDrop, box, result)
    	local user = _UserService.LocalPlayer
    	local final = {}
    	for i=1,cnt do
    		---@type DropComponent
    		local d = result[i].Entity.DropComponent
    		if (d.ReservedDestroy == 0) then
    			if (_ItemDropLogic:CheckDropOwner(d.OwnType, d.OwnId, d.CreateTime, user, true)) then
    				if (d.CreateTime + 1 <= now) then
    					final[#final + 1] = d.Entity
    				end
    			end
    		end
    	end
    	return final
    end
    local stop = petState == "IDLE" or petState == "ACTION"
    if (isvalid(self.SweepTarget)) then
    	-- ?뚮젅?댁뼱 ?대룞 -> clear
    	if (abs(userPos.x - self.SweepOrigin.x) >= 0.05) then
    		clearSweepTarget()
    		return
    	end
    	
    	local drop = self.SweepTarget.DropComponent
    	if (isvalid(drop) and drop.DropId == self.SweepTargetId and drop.ReservedDestroy == 0) then
    		local lastInputX = self.InputX
    		local dropPos = drop.Position
    		if (dropPos.x > petPos.x) then
    			if (lastInputX ~= 1) then
    				setWaitingServer()
    				self:RequestPetAction("MOVE", 1)
    			end
    		elseif (dropPos.x < petPos.x) then
    			if (lastInputX ~= -1) then
    				setWaitingServer()
    				self:RequestPetAction("MOVE", -1)
    			end
    		end
    	else
    		clearSweepTarget()
    	end
    elseif ((stop and absXDiff > 0.8) or (absXDiff > maxMoveRange)) then
    	setWaitingServer()
    	self:RequestPetAction("MOVE", xDiff / absXDiff)
    	clearSweepTarget()
    elseif (_Items:HasPetSkillAttr2(self, _PetSkillAttribute.DropSweep)) then
    	local sdrops = getSweepableDrops()
    	if (#sdrops > 0) then
    		for i=1,#sdrops do
    			local first = sdrops[i]
    			local dropId = first.DropComponent.DropId
    			local timeout = self.SweepTemporaryExceptions[dropId] or 0
    			if (timeout > now) then
    				continue
    			end
    			self.SweepTarget = first
    			self.SweepTargetId = dropId
    			self.SweepTemporaryExceptions[dropId] = now + 10
    			self.SweepOrigin = userPos:Clone()
    			return
    		end
    	end
    end
    
    if (not isvalid(self.SweepTarget)) then
    	-- 媛源뚯썙吏硫?硫덉텛湲?		if (self.InputX ~= 0) then
    		if (absXDiff <= 0.8) then
    			setWaitingServer()
    			self:RequestPetAction("STOP", 0)
    			return
    		end
    	end
    end
    
    -- ?꾩씠??二쇱슱??	if (isvalid(self.SweepTarget)) then
    	local dropPos = self.SweepTarget.TransformComponent.WorldPosition
    	if (dropPos.y - petPos.y > 0.3) then
    		if (self.InputX ~= 0) then
    			if (abs(dropPos.x - petPos.x) <= 0.5) then
    				setWaitingServer()
    				self:RequestPetAction("STOP", 0)
    			end
    		else
    			setWaitingServer()
    			self:RequestPetAction("JUMP", 0)
    		end
    		return
    	end
    end
    
    -- ?뚮옯??泥댄겕
    if (self.InputX ~= 0) then
    	local petFh = pet.RigidbodyComponent:GetCurrentFoothold()
    	if (petFh) then
    		local petDir = pet.SpriteRendererComponent.FlipX and 1 or -1
    		local x = petPos.x
            ---@type Foothold
            local forward = _FootholdLogic:GetForwardLink(pet.CurrentMap, petFh, petDir, x, 0.65)
            if (forward == nil or (forward.Variance.x == 0 and forward.Variance.y * petDir > 0)) then
                setWaitingServer()
                self:RequestPetAction("JUMP", petDir)
            end
    	end
    end

    end

    end


    드랍된 아이템으로 텔레포트 시키려면 명령어 어떻게 짜는게 효율적이지.. 흠.. 버벅거리네..

    댓글7

    회원프로필

    엔티티 체크하심 되지 않나요

    2024.01.17 18:00
    회원프로필

    -- ... (existing code)

    -- Function to teleport the pet to a specific position
    local function teleportToPosition(position)
        setWaitingServer()
        self:RequestPetAction("TELEPORT", 0, position.x, position.y)
        clearSweepTarget()
    end

    -- ... (existing code)

    -- Check for sweepable drops
    local sdrops = getSweepableDrops()
    if (#sdrops > 0) then
        for i = 1, #sdrops do
            local drop = sdrops[i]
            local dropPos = drop.TransformComponent.WorldPosition
            local dropId = drop.DropComponent.DropId
            local timeout = self.SweepTemporaryExceptions[dropId] or 0

            if (timeout > now) then
                -- Drop is temporarily excluded
                continue
            end

            -- Teleport the pet to the drop position
            teleportToPosition(dropPos)
            self.SweepTemporaryExceptions[dropId] = now + 10
            self.SweepTarget = nil  -- No need to set a sweep target as we are teleporting
            return
        end
    end

    -- ... (remaining code)

    2024.01.17 18:01
    회원프로필

    한번 넣어볼게유 ㄳㄳ

    2024.01.17 18:03
    회원프로필

    넣고 되면 말좀

    2024.01.17 18:04
    회원프로필

    getSweepableDrops에서 vector2 안에 있는 값 그대로 써도 상관없음? 맵 전범위로 안해도?

    2024.01.17 18:46
    회원프로필

    먹긴먹어? 난 범위이상 주으러도 안가던데

    2024.01.17 18:06
    회원프로필

    일댈확인점

    2024.01.17 18:52

      게시글 리스트
      제목작성자작성일조회
      1030901-17426
      1030801-17385
      1030701-17279
      1030601-17268
      1030501-17502
      1030401-17649
      1030301-17700
      1030201-17443
      1030101-17154
      1030001-17344
      1029901-17590
      1029801-17831
      1029701-17284
      1029601-17451
      1029501-17151
      1029401-17215
      1029301-17307
      1029201-171033
      1029101-17214
      1029001-17230
      안내 배너 이미지