Exemplo n.º 1
0
        public override void process(Entity entity)
        {
            var sprite = entity.getComponent <AnimatedSprite>();

            if (sprite.getCurrentAnimation().FramesToAttack.Contains(sprite.CurrentFrame))
            {
                var fIsEnemy = entity.getComponent <EnemyComponent>() != null;
                foreach (var otherEntity in _entities)
                {
                    if (otherEntity == entity)
                    {
                        continue;
                    }
                    var otherBattler = otherEntity.getComponent <BattleComponent>();
                    if (otherBattler.isOnImmunity() || otherBattler.Dying || !otherBattler.battleEntity.canTakeDamage)
                    {
                        continue;
                    }
                    var tIsEnemy = otherBattler.getComponent <EnemyComponent>() != null;
                    if (fIsEnemy && tIsEnemy)
                    {
                        return;
                    }
                    var collider = getBattleCollider(otherEntity);
                    foreach (var attackCollider in sprite.getCurrentFrame().AttackColliders)
                    {
                        CollisionResult collisionResult;
                        if (attackCollider.collidesWith(collider, out collisionResult))
                        {
                            var freezeTime        = 0.01f;
                            var freezeScale       = 0.18f;
                            var playerFreezeTime  = _playerComponent.CurrentFreezeScreenDuration();
                            var playerFreezeScale = _playerComponent.CurrentFreezeScreenScale();
                            if (!fIsEnemy && playerFreezeTime > 0.0f)
                            {
                                freezeTime = playerFreezeTime;
                            }
                            if (!fIsEnemy && playerFreezeScale > 0.0f)
                            {
                                freezeScale = playerFreezeScale;
                            }
                            // Freeze time
                            Time.timeScale = freezeScale;
                            Core.schedule(freezeTime, t =>
                            {
                                Time.timeScale = 1;
                            });
                            otherBattler.onHit(collisionResult);
                            if (!fIsEnemy)
                            {
                                playHitEffects(attackCollider.bounds, collider.bounds);
                            }
                        }
                    }
                }
            }
        }