Пример #1
0
		public override bool OnCheck () {

			target = blackboard.Get< Transform > ( KEY_Target );

			if ( target == null ) {
				Debug.Log ( $"CheckTargetInRange: {KEY_Target} is null." );
				return false;
			}

			Vector3 centerOffset = Vector3.zero;
			if ( statCollection.ContainStat ( GlobalSymbol.CENTER_OFFSET_X ) ) {
				centerOffset.x = statCollection.GetStatValue ( GlobalSymbol.CENTER_OFFSET_X );
			}

			if ( statCollection.ContainStat ( GlobalSymbol.CENTER_OFFSET_Y ) ) {
				centerOffset.y = statCollection.GetStatValue ( GlobalSymbol.CENTER_OFFSET_Y );
			}

			bool xOK = string.IsNullOrEmpty ( KEY_RANGE_X ) || Mathf.Abs ( target.position.x - ( transform.position.x + centerOffset.x ) ) <
				statCollection.GetStatValue ( KEY_RANGE_X );
			bool yOK = string.IsNullOrEmpty ( KEY_RANGE_Y ) || Mathf.Abs ( target.position.y - ( transform.position.y + centerOffset.y ) ) <
				statCollection.GetStatValue ( KEY_RANGE_Y );
			
			// Debug.Log ( $"CheckTargetInRange: xOK {target} => {transform} {target.position.x} - {( transform.position.x + centerOffset.x )} = {Mathf.Abs ( target.position.x - ( transform.position.x + centerOffset.x ) )} < {statCollection.GetStatValue ( KEY_RANGE_X )} {xOK} yOK {KEY_RANGE_Y} {yOK}" );

			return xOK && yOK;
		}
        public override bool OnCheck()
        {
            target = blackboard.GetValue <Transform> ("Target");

            if (target == null)
            {
                return(false);
            }

            Vector3 centerOffset = Vector3.one;

            if (statCollection.ContainStat(GlobalSymbol.CENTER_OFFSET_X))
            {
                centerOffset.x = statCollection.GetStatValue(GlobalSymbol.CENTER_OFFSET_X);
            }

            if (statCollection.ContainStat(GlobalSymbol.CENTER_OFFSET_Y))
            {
                centerOffset.y = statCollection.GetStatValue(GlobalSymbol.CENTER_OFFSET_Y);
            }

            bool xOK = string.IsNullOrEmpty(KEY_RANGE_X) || Mathf.Abs(target.position.x - (transform.position.x + centerOffset.x)) <
                       statCollection.GetStatValue(KEY_RANGE_X);
            bool yOK = string.IsNullOrEmpty(KEY_RANGE_Y) || Mathf.Abs(target.position.y - (transform.position.y + centerOffset.y)) <
                       statCollection.GetStatValue(KEY_RANGE_Y);

            return(xOK && yOK);
        }
Пример #3
0
    /// <summary>
    /// A的攻击是否被B格挡?
    /// 结构如下:
    /// RPGStatCollection
    ///     ‖―― FLAG_DEFENSE 0/1
    ///     ‖―― DEFENSE_DIR 0/1/-1
    /// </summary>
    static public bool IsBlocked(Transform t_A, Transform t_B)
    {
        RPGStatCollection statCollection = t_B.GetComponentInChildren <RPGStatCollection>();

        if (statCollection == null ||
            !statCollection.ContainStat(GlobalSymbol.FLAG_DEFENSE) ||
            !statCollection.ContainStat(GlobalSymbol.DEFENSE_DIR))
        {
            return(false);
        }

        if (statCollection.GetStatValue(GlobalSymbol.FLAG_DEFENSE) == 0f)
        {
            return(false);
        }

        // 格挡方向
        int blockDirection = (int)statCollection.GetStatValue(GlobalSymbol.DEFENSE_DIR);

        // A相对于B的方向
        int A_relative_to_the_B_direction = (int)Mathf.Sign(t_A.position.x - t_B.position.x);

//        BoxCollider2D dBodyCollider = t_B.Find("DefenseBody")?.GetComponent<BoxCollider2D>();

//        if (dBodyCollider != null && dBodyCollider.enabled)
//            blockDirection = (int)Mathf.Sign(dBodyCollider.offset.x);

//        Debug.Log($"DamageDealer::IsBlocked() blockDirection = {blockDirection}" +
//                       $", A_relative_to_the_B_direction = {A_relative_to_the_B_direction}");

        // 标志为0时视为无死角防御
        if (blockDirection == 0)
        {
            return(true);
        }

        if ((A_relative_to_the_B_direction == 1 && blockDirection == 1) ||
            (A_relative_to_the_B_direction == -1 && blockDirection == -1))
        {
            return(true);
        }

        if ((A_relative_to_the_B_direction == 1 && blockDirection == -1) ||
            (A_relative_to_the_B_direction == -1 && blockDirection == 1))
        {
            return(false);
        }

        Debug.LogError($"DamageDealer::IsBlocked() 方法出现问题, blockDirection = {blockDirection}" +
                       $", A_relative_to_the_B_direction = {A_relative_to_the_B_direction}");
        return(false);
    }
Пример #4
0
        public override void OnEnter()
        {
            target = blackboard.GetValue <Transform> ("Target");

            if (!dynamicMove)
            {
                var relDir = Util.GetPlayerDirectionRelative(target.position, platformController.transform.position);
                moveTargetX = target.position.x - relDir * statCollection.GetStatValue(KEY_RANGE_X);
            }

            if (!dynamicFaceTo)
            {
                faceDirectionComponent.SetFaceDirection(faceToTarget
                                        ? Util.GetPlayerDirectionRelative(target.position, platformController.transform.position)
                                        : -Util.GetPlayerDirectionRelative(target.position, platformController.transform.position));
            }
        }
Пример #5
0
        public override bool OnCheck()
        {
            if (statCollection == null || statCollection.ContainStat(key))
            {
                return(false);
            }

            return(OperationTools.Compare(statCollection.GetStatValue(key), value, checkType, 0));
        }
Пример #6
0
    private void Awake()
    {
        stateMachine = new StateMachineBuilder()
                       .State(STATE_Idle)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "idle");
        })
                       .Condition(() => statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL) != 0, state => stateMachine.ChangeState(STATE_Run))
                       .Condition(() => playerInput.GetButtonDown(GlobalSymbol.INPUTACTION_Jump), state => stateMachine.ChangeState(STATE_Jump))
                       .Condition(() => !movement.isGrounded, state => stateMachine.ChangeState(STATE_Fall))
                       .Update((state, dt) => {
        })
                       .End()
                       .State(STATE_Run)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "run");
        })
                       .Condition(() => statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL) == 0, state => stateMachine.ChangeState(STATE_Idle))
                       .Condition(() => playerInput.GetButtonDown(GlobalSymbol.INPUTACTION_Jump), state => stateMachine.ChangeState(STATE_Jump))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
            faceDirectionComponent.SetFaceDirection(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL));
        })
                       .End()
                       .State(STATE_Jump)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "jump");
            movement.Jump(statCollection.GetStatValue(GlobalSymbol.JUMP_HEIGHT));
        })
                       .Exit(state => {
        })
                       .Condition(() => movement.isGrounded, state => stateMachine.ChangeState(STATE_Idle))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
        })
                       .End()
                       .State(STATE_Fall)
                       .Enter(state => {
            animator.Play(hand.equipped ? getEquippedAnimation(stateMachine.CurrentStateStr) : "jump");
        })
                       .Condition(() => movement.isGrounded, state => stateMachine.ChangeState(STATE_Idle))
                       .Update((state, dt) => {
            movement.Move(new Vector2(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL), 0));
            faceDirectionComponent.SetFaceDirection(statCollection.GetStatValue(GlobalSymbol.INPUTVAR_MOVE_HORIZONTAL));
        })
                       .End()
                       .Build() as RSG.AbstractState;

        // movement.onMoved += onMovementMove;
        hand.onEquipped   += onHandGearEquipped;
        hand.onUnequipped += onHandGearUnequipped;

        stateMachine.PushState(STATE_Idle);
    }
        private bool checkDistance(Transform a)
        {
            Vector3 centerOffset = Vector3.zero;

            if (statCollection.ContainStat(GlobalSymbol.CENTER_OFFSET_X))
            {
                centerOffset.x = statCollection.GetStatValue(GlobalSymbol.CENTER_OFFSET_X);
            }

            if (statCollection.ContainStat(GlobalSymbol.CENTER_OFFSET_Y))
            {
                centerOffset.y = statCollection.GetStatValue(GlobalSymbol.CENTER_OFFSET_Y);
            }
            bool xOK = string.IsNullOrEmpty(KEY_RANGE_X) || Mathf.Abs(a.position.x - (transform.position.x + centerOffset.x)) <
                       statCollection.GetStatValue(KEY_RANGE_X);
            bool yOK = string.IsNullOrEmpty(KEY_RANGE_Y) || Mathf.Abs(a.position.y - (transform.position.y + centerOffset.y)) <
                       statCollection.GetStatValue(KEY_RANGE_Y);

            return(xOK && yOK);
        }
        public override void OnUpdate()
        {
            _timer += CupheadTime.Delta[CupheadTime.Layer.Enemy];

            if (_timer > _dashDuration)
            {
                Fsm.Event(finishEvent);
                return;
            }

            var movementX = _dashDirection * statCollection.GetStatValue(Key_DASH_SPEED) * CupheadTime.Delta[CupheadTime.Layer.Enemy];

            platformController.Move(new Vector2(movementX, 0f));
        }
Пример #9
0
    public override void OnEnter()
    {
        controller.ClearVelocity();
        controller.ActiveGravity = false;

        var  target        = blackboard.GetValue <Transform> ("Target");
        var  dir           = 0;
        var  groundY       = 0f;
        var  startPosition = Owner.transform.position;
        bool leftBlocked   = false;
        bool rightBlocked  = false;

        var range = statCollection.GetStatValue(KEY_RANGE_X);

        // 传送方向选择
        var hit = Physics2D.Raycast(target.position, Vector2.left, range, LayerMask.GetMask("Platform", "Wall"));

        if (hit.transform != null)
        {
            leftBlocked = true;
        }
        hit = Physics2D.Raycast(target.position, Vector2.right, range, LayerMask.GetMask("Platform", "Wall"));
        if (hit.transform != null)
        {
            rightBlocked = true;
        }

        hit = Physics2D.Raycast(target.position, Vector2.down, range, LayerMask.GetMask("Platform", "Wall"));
        if (hit.collider != null)
        {
            groundY = hit.collider.bounds.max.y;
        }

        if (leftBlocked && !rightBlocked)
        {
            dir = 1;
        }
        else if (!leftBlocked && rightBlocked)
        {
            dir = -1;
        }
        if (dir == 0)
        {
            dir = MathUtils.RandomBool() ? 1 : -1;
        }

        // 坐标修正
        var teleportPoint = new Vector2(target.position.x + dir * range, target.position.y + height);

        if (height < 0)
        {
            teleportPoint.y = groundY;
        }
        teleportPoint = TerrainDetectionSystem.TerrainOverlapHorizontalFix(teleportPoint, boxCollider2D.size,
                                                                           boxCollider2D.offset, Owner.transform.localScale);

        // 特效
        // EffectManager.ApplySpecificEffectAt ( "Boss_08_yuandian", Owner.transform.position );

        Owner.transform.SetPosition(teleportPoint.x, teleportPoint.y);

        // var line = EffectManager.ApplySpecificEffectAt ( "Boss_08_chuansongdianlu", ( startPosition + Owner.transform.position ) / 2f );
        // line.transform.SetEulerAngles ( null, null, MathUtils.DirectionToAngle ( ( Owner.transform.position - startPosition ).normalized ) );
        // line.transform.SetScale ( 1f / LINE_LENGTH * Vector2.Distance ( startPosition, Owner.transform.position ) );
        //
        // // 特效
        // EffectManager.ApplySpecificEffectAt ( "Boss_08_yuandian", Owner.transform.position );
    }
Пример #10
0
        protected virtual void Update()
        {
            /// 重力加速度
            if (ActiveGravity)
            {
                velocity.y += gravity * CupheadTime.Delta[timeLayer];
            }

            if (MoveByDirectionInput)
            {
                float targetVelocityX = directionalInput.x * StatCollection.GetStatValue(GlobalSymbol.RUN_SPEED);

                velocity.x = Mathf.MoveTowards(velocity.x, targetVelocityX,
                                               isGrounded ? StatCollection.GetStatValue(GlobalSymbol.ACCELERATION_TIME_GROUND) : StatCollection.GetStatValue(GlobalSymbol.ACCELERATION_TIME_AIR));
            }

            if (!_activeControl)
            {
                velocity.x = 0;
            }

            /// 平台碰撞
            //if (controller.collisions.above || controller.collisions.below)
            //    velocity.y = 0;

            controller.Move(velocity * CupheadTime.Delta[timeLayer]);

            /// 平台碰撞
            if (controller.collisionState.above && velocity.y > 0f || controller.collisionState.below && velocity.y < 0f)
            {
                velocity.y = 0.0f;
            }
            if (controller.collisionState.left && velocity.x < 0f || controller.collisionState.right && velocity.x > 0f)
            {
                velocity.x = 0.0f;
            }
        }