public void RetractInstantly()
        {
            Deactivate();
            transform.position = sheath.transform.position;
            sheath.PutBackKnife(this);
            if (stuckOn != null)
            {
                Vector2 force = Vector2.zero;
                stuckOn.Remove(this.gameObject);
            }
            stuckOn     = null;
            stuckAttack = null;

            Stuck            = false;
            hoverTimer       = 0;
            traveledDistance = 0;
            State            = KnifeState.InSheath;

            if (flyingVFX)
            {
                List <ParticleSystem> particles = new List <ParticleSystem>();
                flyingVFX.GetComponentsInChildren(particles);
                flyingVFX.SetParent(null);
                foreach (var particle in particles)
                {
                    particle.Stop();
                }
            }

            if (chargeFlyingEffect)
            {
                chargeFlyingEffect.StopDraw();
            }
        }
        public bool Withdraw()
        {
            if (State == KnifeState.InSheath || State == KnifeState.Returning)
            {
                return(false);
            }

            transform.parent = null;
            State            = KnifeState.Returning;

            _attackMove     = piercing ? chargedAttack : normalAttack;
            _defaultType    = piercing ? AttackType.ChargedRange : AttackType.Range;
            _baseAttackRate = normalAttackRate;
            Activate(AttackPackage.CreateNewPackage(), _attackMove);

            if (stuckOn != null)
            {
                Vector2 toStuckOn = (stuckOn as Component).transform.position - this.transform.position;
                toStuckOn = toStuckOn.normalized * PullingForce;
                if (stuckOn.TryPullOut(this.gameObject, ref toStuckOn))
                {
                    var direction = sheath.transform.position - this.transform.position;
                    direction    = DirectionalHelper.NormalizeHorizonalDirection(direction);
                    _defaultType = AttackType.StuckNDraw;
                    TryAttack(stuckAttack, direction);
                }

                stuckOn = null;
            }

            Returning();


            if (flyingVFX)
            {
                flyingVFX.SetParent(this.transform);
                flyingVFX.position = transform.position;
                flyingVFX.rotation = transform.rotation;
            }

            if (chargeFlyingEffect && piercing)
            {
                chargeFlyingEffect.StartDraw();
            }

            return(true);
        }
        private void HandleFlyingCollision(RaycastHit2D hit)
        {
            var stickable  = hit.collider.GetComponent <ICanStickKnife>();
            var attackable = hit.collider.GetComponentInParent <IAttackable>();

            if (!piercing && !Stuck && stickable != null && stickable.TryStick(this.gameObject))
            {
                Stuck = true;
                State = KnifeState.Stuck;
                transform.position = (Vector3)hit.point + transform.right * sinkingLength;
                transform.SetParent(hit.collider.transform);
                stuckOn = stickable;
            }

            if (IsAttackable(attackable))
            {
                var direction = hit.collider.transform.position - transform.position;
                direction = DirectionalHelper.NormalizeHorizonalDirection(direction);

                if (Stuck)
                {
                    _defaultType = AttackType.StuckNDraw;
                    _attackMove  = drawStuckAttack;
                }

                if (TryAttack(attackable, direction) && Stuck)
                {
                    stuckAttack = attackable;
                }
            }

            if (attackable == null && !Stuck)
            {
                Hover();
            }
        }
Esempio n. 4
0
 public void OnPullingKnife(ICanStickKnife canStick, ThrowingKnife knife)
 {
     //if (!_state._stamina.IsFull())
     //	_state._stamina += canStick.RestoredStamina;
 }