Пример #1
0
        private int EvadeDamageWithStats(CollisionEvent arg)
        {
            if (_vitalStat == null)
            {
                return(arg.Hit);
            }
            if (_fxComponent != null)
            {
                _fxComponent.TriggerEvent(
                    new ActionStateEvent(arg.Origin, arg.Target, arg.HitPoint, Quaternion.LookRotation(arg.HitNormal),
                                         ActionStateEvents.Collision));
            }

            _vitalStat.Current -= _finalCost;
            return(CollisionResult.Miss);
        }
Пример #2
0
 private static void CheckColliderList(Entity originEntity, Entity ignoreEntity, Vector3 position, int limit, bool limitEnemy)
 {
     for (int i = 0; i < limit; i++)
     {
         if (originEntity.IsDestroyed())
         {
             return;
         }
         var collider  = _colliders[i];
         var hitEntity = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(collider));
         if (hitEntity == ignoreEntity || hitEntity == null)
         {
             continue;
         }
         if (IsValidCollision(originEntity, limitEnemy, hitEntity, collider, out var sourceNode, out var targetNode))
         {
             CollisionExtensions.GenerateHitLocDir(position, hitEntity, collider, out var hitPnt, out var hitNormal);
             var ce = new CollisionEvent(originEntity, sourceNode, targetNode, hitPnt, hitNormal);
             hitEntity.Post(ce);
             originEntity.Post(new PerformedCollisionEvent(sourceNode, targetNode, hitPnt, hitNormal));
         }
     }
 }
Пример #3
0
        private IEnumerator DissolveFx(Entity owner, CollisionEvent collisionEvent, SpriteRenderer sprite, float amt)
        {
            var power = Mathf.Clamp(amt, _minDamage, _maxDamage);
            var tr    = owner.Get <TransformComponent>();

            sprite.GetPropertyBlock(_block);
            var hitPnt        = collisionEvent.HitPoint;
            var localPosition = tr != null?tr.InverseTransformPoint(hitPnt) : hitPnt;

            //DebugExtension.DebugWireSphere(hitPnt, power, 2.5f);
            _block.SetVector("_DissolveMaskPosition", hitPnt);
            _block.SetFloat("_DissolveMaskRadius", power);
            sprite.SetPropertyBlock(_block);
            var  start   = TimeManager.TimeUnscaled;
            bool started = false;

            if (owner.IsDestroyed())
            {
                yield break;
            }
            var modelComponent = owner.Get <RenderingComponent>();
            var animator       = owner.Get <AnimatorComponent>()?.Value;

            if (animator == null)
            {
                owner.Destroy();
                yield break;
            }
            var startFx = 0f;
            var fxTime  = 0f;

            owner.Tags.Remove(EntityTags.CanUnityCollide);
            if (animator.CurrentAnimation != AnimationIds.Death)
            {
                var loopLimiter = new WhileLoopLimiter(500);
                int lastTried   = 0;
                while (loopLimiter.Advance())
                {
                    if (animator.CurrentAnimation == AnimationIds.Death)
                    {
                        break;
                    }
                    if (lastTried > 5)
                    {
                        animator.PlayAnimation(AnimationIds.Death, false, null);
                        lastTried = 0;
                    }
                    lastTried++;
                    yield return(null);
                }
                if (loopLimiter.HitLimit)
                {
                    Debug.LogFormat("{0} could not start Death animation", owner.Name);
                    owner.Destroy();
                    yield break;
                }
            }
            var timeOut = animator.CurrentAnimationLength * 2.5f;

            while (TimeManager.TimeUnscaled < start + timeOut)
            {
                var worldPnt = tr != null?tr.TransformPoint(localPosition) : hitPnt;

                //DebugExtension.DebugWireSphere(worldPnt, power, 0.5f);
                sprite.GetPropertyBlock(_block);
                _block.SetVector("_DissolveMaskPosition", worldPnt);
                if (!started)
                {
                    if (animator.IsAnimationEventComplete("Death"))
                    {
                        started = true;
                        startFx = TimeManager.TimeUnscaled;
                        fxTime  = animator.CurrentAnimationRemaining * 1.5f;
                    }
                    else
                    {
                        sprite.SetPropertyBlock(_block);
                        yield return(null);

                        continue;
                    }
                }
                var percent = (TimeManager.TimeUnscaled - startFx) / fxTime;
                _block.SetFloat("_DissolveMaskRadius", Mathf.Lerp(power, _maxFinish, percent));
                sprite.SetPropertyBlock(_block);
                yield return(null);
            }
            _block.SetFloat("_DissolveMaskRadius", 0);
            sprite.SetPropertyBlock(_block);
            modelComponent.SetVisible(RenderingMode.None);
            owner.Destroy();
        }
Пример #4
0
 public static void StartFx(Entity entity, CollisionEvent collisionEvent, SpriteRenderer sprite, float amt)
 {
     TimeManager.StartUnscaled(main.DissolveFx(entity, collisionEvent, sprite, amt));
 }
Пример #5
0
 public void ProcessImpact(CollisionEvent collisionEvent, ActionStateEvent stateEvent)
 {
 }
Пример #6
0
        private static CollisionEvent?CheckRayList(Entity originEntity, Ray ray, int limit, bool limitEnemy)
        {
            for (int i = 0; i < limit; i++)
            {
                if (originEntity.IsDestroyed())
                {
                    return(null);
                }
                var hit = _rayHits[i];

                Entity hitEntity     = EntityController.GetEntity(UnityToEntityBridge.GetEntityId(hit.collider));
                bool   isEnvironment = hitEntity == null && hit.transform.IsEnvironment();

#if DEBUG_RAYCAST
                Color pointColor = Color.white;
                if (isEnvironment)
                {
                    pointColor = Color.green;
                }
                else if (hit.transform.CompareTag(StringConst.TagInvalidCollider))
                {
                    pointColor = Color.magenta;
                }
                else if (hitEntity != null)
                {
                    pointColor = Color.red;
                }
                DebugExtension.DrawPoint(_rayHits[i].point + (Vector3.up * (i * 0.1f)), pointColor, 0.25f, 2.5f);
#endif
                if (isEnvironment)
                {
#if DEBUG
                    DebugLog.Add(originEntity.DebugId + " hit environment " + _rayHits[i].transform.name);
#endif
                    originEntity.Post(new EnvironmentCollisionEvent(originEntity, _rayHits[i].point, _rayHits[i].normal));
                    return(null);
                }
                if (hitEntity == null)
                {
                    continue;
                }
                if (IsValidCollision(originEntity, limitEnemy, hitEntity, _rayHits[i].collider, out var sourceNode, out var targetNode))
                {
                    if (targetNode.DetailCollider != null)
                    {
                        var detailTr   = targetNode.DetailCollider.Collider.transform;
                        var localPoint = hit.transform.InverseTransformPoint(ray.origin);
                        var localDir   = hit.transform.InverseTransformDirection(ray.direction);
                        var rayCast    = new Ray(detailTr.TransformPoint(localPoint), detailTr.TransformDirection(localDir));
                        if (!targetNode.DetailCollider.Collider.Raycast(rayCast, out var childHit, 500))
                        {
                            DebugExtension.DrawPoint(childHit.point, Color.yellow, 0.25f, 2.5f);
                            continue;
                        }
                    }
                    var ce = new CollisionEvent(originEntity, sourceNode, targetNode, _rayHits[i].point, _rayHits[i].normal);
                    hitEntity.Post(ce);
                    originEntity.Post(new PerformedCollisionEvent(sourceNode, targetNode, _rayHits[i].point, _rayHits[i].normal));
                    return(ce);
                }
            }
            return(null);
        }