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);
        }
Пример #2
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;
		}
Пример #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 bool OnCheck()
        {
            if (statCollection == null || statCollection.ContainStat(key))
            {
                return(false);
            }

            return(OperationTools.Compare(statCollection.GetStatValue(key), value, checkType, 0));
        }
        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);
        }
Пример #6
0
        public override bool OnCheck()
        {
            return(true);

            Transform target = blackboard.GetValue <Transform> ("Target");

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

            RPGStatCollection statCollection = DamageDealer.FindObjectStatCollection(target.gameObject);

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

            return(statCollection.GetStat <RPGVital> (GlobalSymbol.HP).StatValueCurrent > 0f);
        }