public void SubscribeToUMACreate()
        {
            // is this stuff necessary on ai characters?
            AnimatedUnit animatedUnit = dynamicCharacterAvatar.gameObject.GetComponent <AnimatedUnit>();

            animatedUnit.OrchestrateStartup();
            if (animatedUnit != null && animatedUnit.MyCharacterAnimator != null)
            {
                animatedUnit.MyCharacterAnimator.InitializeAnimator();
            }
            else
            {
            }
            dynamicCharacterAvatar.Initialize();
            // is this stuff necessary end

            UMAData umaData = dynamicCharacterAvatar.umaData;

            umaData.OnCharacterCreated += HandleCharacterCreated;
        }
Beispiel #2
0
 public void GetComponentReferences()
 {
     anyRPGCharacterController = GetComponent <AnyRPGCharacterController>();
     if (anyRPGCharacterController == null)
     {
         //Debug.Log(gameObject.name + ".PlayerUnitMovementController.GetComponentReferences(): unable to get AnyRPGCharacterController");
     }
     if (characterUnit == null)
     {
         characterUnit = GetComponent <CharacterUnit>();
         if (characterUnit == null)
         {
             //Debug.Log(gameObject.name + ".PlayerUnitMovementController.GetComponentReferences(): unable to get characterUnit");
         }
     }
     animatedUnit = GetComponent <AnimatedUnit>();
     if (animatedUnit == null)
     {
         //Debug.Log(gameObject.name + ".PlayerUnitMovementController.GetComponentReferences(): unable to get animatedUnit");
     }
 }
        /*
         * [SerializeField]
         * private Vector3 spawnLocation = Vector3.zero;
         */

        public override Dictionary <PrefabProfile, GameObject> Cast(BaseCharacter source, GameObject target, GameObject originalTarget, AbilityEffectOutput abilityEffectInput)
        {
            if (target == null)
            {
                return(null);
            }

            AnimatedUnit animatedUnit = target.GetComponent <AnimatedUnit>();

            if (animatedUnit == null || animatedUnit.MyCharacterMotor == null)
            {
                return(null);
            }

            Dictionary <PrefabProfile, GameObject> returnObjects = base.Cast(source, target, originalTarget, abilityEffectInput);

            Vector3 sourcePosition = source.MyCharacterUnit.transform.position;
            Vector3 targetPosition = target.transform.position;

            // get vector from source to target for flight direction
            Vector3 originalDirection = (targetPosition - sourcePosition).normalized;

            // create a generic rotation 45 degrees upward
            Vector3 rotationDirection = Quaternion.Euler(-knockBackAngle, 0, 0) * Vector3.forward;

            // take that generic rotation and rotate it so it is now facing in the direction of flight
            Vector3 finalDirection = Quaternion.LookRotation(originalDirection) * rotationDirection;

            // add velocity to the now correct flight direction
            finalDirection *= knockBackVelocity;

            //Debug.Log("KnockBackEffect.Cast(): originalDirection: " + originalDirection + "; rotationDirection: " + rotationDirection + "; finalDirection: " + finalDirection + "; knockbackAngle: " + knockBackAngle);
            animatedUnit.MyCharacterMotor.Move(finalDirection, true);

            return(returnObjects);
        }
        public override Dictionary <PrefabProfile, GameObject> Cast(IAbilityCaster source, GameObject target, GameObject originalTarget, AbilityEffectContext abilityEffectContext)
        {
            //Debug.Log(DisplayName + ".KnockBackEffect.Cast()");
            if (target == null)
            {
                return(null);
            }

            Dictionary <PrefabProfile, GameObject> returnObjects = base.Cast(source, target, originalTarget, abilityEffectContext);

            Vector3 sourcePosition = source.UnitGameObject.transform.position;
            Vector3 targetPosition = target.transform.position;

            AnimatedUnit  animatedUnit        = target.GetComponent <AnimatedUnit>();
            CharacterUnit targetCharacterUnit = target.GetComponent <CharacterUnit>();

            if (targetCharacterUnit != null && targetCharacterUnit.MyCharacter != null && targetCharacterUnit.MyCharacter.CharacterAbilityManager)
            {
                //Debug.Log("KnockBackEffect.Cast(): stop casting");
                targetCharacterUnit.MyCharacter.CharacterAbilityManager.StopCasting();
            }

            if (knockbackType == KnockbackType.Knockback)
            {
                if (animatedUnit != null && animatedUnit.MyCharacterMotor != null)
                {
                    //Debug.Log("KnockBackEffect.Cast(): casting on character");
                    animatedUnit.MyCharacterMotor.Move(GetKnockBackVelocity(sourcePosition, targetPosition), true);
                }
                else
                {
                    Rigidbody rigidbody = target.GetComponent <Rigidbody>();
                    if (rigidbody != null)
                    {
                        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
                        rigidbody.AddForce(GetKnockBackVelocity(sourcePosition, targetPosition), ForceMode.VelocityChange);
                    }
                }
            }
            else
            {
                Collider[] colliders = new Collider[0];
                //int playerMask = 1 << LayerMask.NameToLayer("Default");
                //int characterMask = 1 << LayerMask.NameToLayer("CharacterUnit");
                //int validMask = (playerMask | characterMask);
                //int validMask = playerMask;
                //colliders = Physics.OverlapSphere(targetPosition, explosionRadius, validMask);
                Vector3 explosionCenter = Vector3.zero;
                if (abilityEffectContext.groundTargetLocation != Vector3.zero)
                {
                    explosionCenter = abilityEffectContext.groundTargetLocation;
                }
                else
                {
                    explosionCenter = targetPosition;
                }
                colliders = Physics.OverlapSphere(explosionCenter, explosionRadius, explosionMask);
                foreach (Collider collider in colliders)
                {
                    //Debug.Log(DisplayName + ".KnockBackEffect.Cast() hit: " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);
                    Rigidbody rigidbody = collider.gameObject.GetComponent <Rigidbody>();
                    if (rigidbody != null)
                    {
                        //Debug.Log(DisplayName + ".KnockBackEffect.Cast() rigidbody was not null on : " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);

                        //rigidbody.AddForce(GetKnockBackVelocity(targetPosition, collider.gameObject.transform.position), ForceMode.VelocityChange);

                        // we have to handle player knockback specially, as they need to be in knockback state or the idle update will freeze them in place
                        PlayerUnitMovementController playerUnitMovementController = collider.gameObject.GetComponent <PlayerUnitMovementController>();
                        if (playerUnitMovementController != null)
                        {
                            playerUnitMovementController.KnockBack();
                        }

                        // if this is a character, we want to freeze their rotation.  for inanimate objects, we want rotation
                        targetCharacterUnit = collider.gameObject.GetComponent <CharacterUnit>();
                        if (targetCharacterUnit != null)
                        {
                            rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
                        }
                        rigidbody.AddExplosionForce(explosionForce, explosionCenter, 0, upwardModifier, ForceMode.VelocityChange);
                    }
                }
            }

            return(returnObjects);
        }
        public override Dictionary <PrefabProfile, GameObject> Cast(IAbilityCaster source, GameObject target, GameObject originalTarget, AbilityEffectContext abilityEffectInput)
        {
            //Debug.Log(DisplayName + ".KnockBackEffect.Cast()");
            if (target == null)
            {
                return(null);
            }

            Dictionary <PrefabProfile, GameObject> returnObjects = base.Cast(source, target, originalTarget, abilityEffectInput);

            Vector3 sourcePosition = source.UnitGameObject.transform.position;
            Vector3 targetPosition = target.transform.position;

            AnimatedUnit  animatedUnit        = target.GetComponent <AnimatedUnit>();
            CharacterUnit targetCharacterUnit = target.GetComponent <CharacterUnit>();

            if (targetCharacterUnit != null && targetCharacterUnit.MyCharacter != null && targetCharacterUnit.MyCharacter.CharacterAbilityManager)
            {
                //Debug.Log("KnockBackEffect.Cast(): stop casting");
                targetCharacterUnit.MyCharacter.CharacterAbilityManager.StopCasting();
            }
            if (animatedUnit != null && animatedUnit.MyCharacterMotor != null)
            {
                //Debug.Log("KnockBackEffect.Cast(): casting on character");
                animatedUnit.MyCharacterMotor.Move(GetKnockBackVelocity(sourcePosition, targetPosition), true);
            }
            else
            {
                Rigidbody rigidbody = target.GetComponent <Rigidbody>();
                if (rigidbody != null)
                {
                    rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
                    rigidbody.AddForce(GetKnockBackVelocity(sourcePosition, targetPosition), ForceMode.VelocityChange);
                }
            }

            if (isExplosion)
            {
                Collider[] colliders = new Collider[0];
                //int playerMask = 1 << LayerMask.NameToLayer("Default");
                //int characterMask = 1 << LayerMask.NameToLayer("CharacterUnit");
                //int validMask = (playerMask | characterMask);
                //int validMask = playerMask;
                //colliders = Physics.OverlapSphere(targetPosition, explosionRadius, validMask);
                colliders = Physics.OverlapSphere(targetPosition, explosionRadius, explosionMask);
                foreach (Collider collider in colliders)
                {
                    //Debug.Log(MyName + "KnockBackEffect.Cast() hit: " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);
                    Rigidbody rigidbody = collider.gameObject.GetComponent <Rigidbody>();
                    if (rigidbody != null)
                    {
                        //Debug.Log(MyName + "KnockBackEffect.Cast() rigidbody was not null on : " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);

                        //rigidbody.AddForce(GetKnockBackVelocity(targetPosition, collider.gameObject.transform.position), ForceMode.VelocityChange);
                        rigidbody.AddExplosionForce(explosionForce, targetPosition, 0, 0, ForceMode.VelocityChange);
                    }
                }
            }


            return(returnObjects);
        }