채팅0

    지언은 안뚫린거냐 안풀린거냐

    조회수 462

    후자겠지?

    댓글2

    회원프로필

    foothold

    2024.02.02 12:45
    회원프로필

    return function (self)
    local m = self.CachedMoveAbility
    local mob = self.Entity
    local fh = mob.RigidbodyComponent:GetCurrentFoothold()
    if (not fh) then
        -- log("no foothold ", mob.Name)
    return
    end
    if (self.LocalInputX == 0) then
        -- log("self.LocalInputX is 0")
    return
    end
    local now = _UtilLogic.ServerElapsedSeconds
    if (now < self.NextUpdateWait) then
        -- log("waiting next update ", self.NextUpdateWait)
    return
    end
    if (m == _MoveAbility.Jump or m == _MoveAbility.Walk) then
    local state = mob.StateComponent.CurrentStateName
    if (state ~= _MobAction.Stand and state ~= _MobAction.Move and state ~= _MobAction.Jump) then
    return
    end

    local forwardDir = mob.SpriteRendererComponent.FlipX and 1 or -1
    local mobPos = mob.TransformComponent.WorldPosition
    local x = mobPos.x
    local map = mob.CurrentMap
    local platform = map.PlatformInfoComponent.FootholdToPlatform[fh.Id]
    if (not platform) then
            log_error("failed to get platform: ", fh.Id)
    return
    end

    local dir = 0
    local wallHeight = 0
    local edgeGap = nil
    local edge = nil
    local bv = map.MapInfoComponent.IsBlockedVertical

    if (forwardDir < 0) then
    edge = platform.left.x
    edgeGap = x - edge
    dir = platform.left.dir
    wallHeight = platform.left.length
                --log(string.format("forward:%d / edge:%.2f / edgeGap:%.2f / dir:%d / isolatedMove:%s",
                --    forwardDir, edge, edgeGap, dir, tostring(mob.RigidbodyComponent.IsolatedMove)))
    else
    edge = platform.right.x
    edgeGap = edge - x
    dir = platform.right.dir
    wallHeight = platform.right.length
                --log(string.format("forward:%d / edge:%.2f / edgeGap:%.2f / dir:%d / isolatedMove:%s",
                --    forwardDir, edge, edgeGap, dir, tostring(mob.RigidbodyComponent.IsolatedMove)))
    end

    local function playJump(jumpDir)
    -- 클라이언트에게 갱신되기 전에 또 업데이트 되는 것 방지
    self.NextUpdateWait = now + 1
    map.LifeControllerComponent:RequestControl(mob, {
    { _MobActionPartType.Jump, jumpDir, 0 }
    }, 1, false)
            --log("playJump")
    end

    local function getHomePlatform()
    local id = mob.MobComponent.HomePlatformId
    if (id > 0) then
    return map.PlatformInfoComponent.Platforms[id]
    end
    return nil
    end

    local function isBelongToHomePlatform()
    local home = getHomePlatform()
    if (home) then
    if (forwardDir < 0) then
    if (home.left.x + 0.6 < edge) then
    return true
    end
    else
    if (home.right.x - 0.6 > edge) then
    return true
    end
    end
    else
    -- log_error(string.format("no home platform '%s' (%s)", self.Entity.Id, self.Entity.Path))
    end
    return false
    end

    local function tryWallJump()
    -- 풋홀드 끝 점프
    if (dir == 0) then
                --log("trying object edge jump")
    if (isBelongToHomePlatform()) then
                playJump(1)
    return true
    end
    if (bv) then
                if (_GlobalRand32:RandomDouble() < 0.2) then
                    playJump(1)
                    return true
                end
    end
    elseif (dir > 0) then
                --log("trying wall jump")
    if (bv) then
    return false
    end
    if (wallHeight > 0.65) then
    return false
    end
    playJump(1)
    return true
    elseif (dir < 0) then
    if (isBelongToHomePlatform()) then
    playJump(-1)
    return true
    end

    -- fallback
                ---@type Foothold
                local forward = _FootholdLogic:GetForwardLink(mob.CurrentMap, fh, forwardDir, x, 1.5)
                if (forward and forward.Variance.x ~= 0) then
                    --log("trying wall down")
                    playJump(-1)
                    return true
                end
    end
    return false
    end

    local function turnAround()
    -- 방향 전환이 다시 클라이언트에게 갱신되기 전에 또 업데이트 되는 것 방지
    self.NextUpdateWait = now + 2
    self.NextRandomJump = now + _GlobalRand32:RandomIntegerRange(1000, 1500) / 1000
    mob.CurrentMap.LifeControllerComponent:RequestControl(mob, {
    { _MobActionPartType.Move, -forwardDir, 0, nil }
    }, 1, false)
    end

    local function tryRandomJump(rate)
    -- 랜덤 점프
    if (now >= self.NextRandomJump) then
    if (_GlobalRand32:RandomDouble() < rate) then
    playJump(1)
    else
                    --log("no random jump")
    end
    self.NextRandomJump = now + _GlobalRand32:RandomIntegerRange(1000, 3000) / 1000
    end
    end

    ---@param target Entity
    local function tryChaseJump(target)
    local wPos = target.TransformComponent.WorldPosition
    local xGap = math.abs(wPos.x - x)
    if (xGap < 1.5) then
    local yGap = wPos.y - mobPos.y
    if (yGap > 0.1 and yGap < 3) then
    if (target.RigidbodyComponent:GetCurrentFoothold()) then
    tryRandomJump(0.75)
    elseif (yGap > 0.6 and _CharacterActionLogic:IsOnLadderOrRope(target.StateComponent.CurrentStateName)) then
    tryRandomJump(0.5)
    end
    end
    end
    end

    if (edgeGap ~= nil) then
    if (edgeGap <= 0.65) then
    if (m == _MoveAbility.Jump) then
    if (tryWallJump()) then
    return
    end
    local target = self.Target
    if (isvalid(target)) then
    tryChaseJump(target)
    end
    end
    turnAround()
    elseif (edgeGap >= 2) then
    if (m == _MoveAbility.Jump) then
    local target = self.Target
    if (isvalid(target)) then
    tryChaseJump(target)
    else
    tryRandomJump(0.2)
    end
    end
    end
    end
    end
    end

    2024.02.05 02:24

      게시글 리스트
      제목작성자작성일조회
      2639102-02140
      2639002-021397
      2638902-02463
      2638802-02131
      2638702-02402
      2638602-02140
      2638502-02230
      2638402-02444
      2638302-02126
      2638202-02183
      2638102-02436
      2638002-02195
      2637902-02198
      2637802-02525
      2637702-02189
      2637602-02437
      2637502-02222
      2637402-02798
      2637302-02197
      2637202-02247
      안내 배너 이미지