Example #1
0
    private void TakeAction(GameObject Target)
    {
        Damager targetDamageDealer = Target.GetComponent <Damager>();

        if (!targetDamageDealer)
        {
            return;
        }
        //jump over stone
        if (Target.GetComponent <Stone>())
        {
            StartCoroutine(Jump());
        }
        else
        {
            var otherDamage = targetDamageDealer.GetDamage();
            if (attacker.TakeDamage(otherDamage) <= 0)
            {
                Die();
            }
            else
            {
                StartCoroutine(Attack());
            }
        }
    }
Example #2
0
        public virtual void FireProyectile(RaycastHit AimRay)
        {
            float percent = Random.Range(0, 1);

            Vector3 AimDirection = (AimRay.point - transform.position).normalized;

            if (C_ReduceAmmoAfterShoot != null)
            {
                StopCoroutine(C_ReduceAmmoAfterShoot);
            }
            C_ReduceAmmoAfterShoot = ReduceAmmoAfterShoot();
            StartCoroutine(C_ReduceAmmoAfterShoot);

            OnFire.Invoke(AimDirection);

            if (AimRay.transform)                                                                                       //If the AIM Ray hit something
            {
                var interactable = AimRay.transform.GetComponent <IInteractable>();
                interactable?.Interact();

                AffectStat.Value = Random.Range(MinDamage, MaxDamage);
                AffectStat.ModifyStat(AimRay.transform.GetComponentInParent <Stats>());

                Damager.SetDamage(AimRay.normal, AimRay.transform, transform);

                if (AimRay.rigidbody)                                                                                          //If the thing we hit has a rigidbody
                {
                    AimRay.rigidbody.AddForceAtPosition(AimDirection * Mathf.Lerp(MinForce, MaxForce, percent), AimRay.point); //Apply the force to it
                }

                BulletHole(AimRay);

                OnHit.Invoke(AimRay.transform);  //Invoke OnHitSomething Event
            }
        }
Example #3
0
    /// <summary>
    /// Gravestone has been destroyed.
    /// </summary>
    /// <param name="damager">The damager script of the object that destroyed this object.</param>
    /// <param name="damageable">The damageable script of the object that destroyed this object.</param>
    public void GravestoneDestroyed(Damager damager, Damageable damageable)
    {
        int random = Random.Range(0, 3);

        if (random == 0)         //Give Coins
        {
            m_Animator.SetBool("CoinDrop", true);
            m_DespawnTimer = m_CoinAnimation.length + 0.5f;
            damager.GetComponentInParent <PlayerCharacter>().CollectCoin();
        }
        else if (random == 1)         //Give Health
        {
            m_Animator.SetBool("HealthDrop", true);
            m_DespawnTimer = m_HealthAnimation.length + 0.5f;
            damager.GetComponentInParent <Damageable>().RegainHealth(1);
        }
        else if (random == 2)         //Deal Damage
        {
            m_Animator.SetBool("DamageDrop", true);
            m_DespawnTimer = m_DamageAnimation.length + 0.5f;
            damager.GetComponentInParent <Damageable>().TakeDamage(m_Damager, true);
        }

        StartCoroutine(Despawn());
    }
    public void Die(Damager damager, Damageable damageable)
    {
        //Vector2 throwVector = new Vector2(0, 2.0f);
        //Vector2 damagerToThis = damager.transform.position - transform.position;

        //throwVector.x = Mathf.Sign(damagerToThis.x) * -4.0f;
        //SetMoveVector(throwVector);
        if (HashDeathPara != 0)
        {
            m_Animator.SetTrigger(HashDeathPara);
        }
        if (dieAudio != null)
        {
            dieAudio.PlayRandomSound();
        }

        m_Dead = true;

        if (deactiveOnDie)
        {
            gameObject.SetActive(false);
        }

        if (hashDeadEffect != 0)
        {
            VFXController.Instance.Trigger(hashDeadEffect, transform.position, 0, m_SpriteForward.x > 0 ? false : true, null);
        }
        //m_Collider.enabled = false;

        //CameraShaker.Shake(0.15f, 0.3f);
    }
Example #5
0
    public void damage(Damager damager, Collider2D collision)
    {
        currentHealth -= damager.damage;

        if (collision.gameObject.tag == "Robot")
        {
            if (kb.triggered)
            {
                iframes      = iframeDuration;
                kb.triggered = false;
            }
            else
            {
                triggered = true;
            }
        }
        else
        {
            iframes = iframeDuration;
        }

        if (currentHealth <= 0)
        {
            die();
        }
    }
Example #6
0
    public void GotHit(Damager damager, Damageable damageable)
    {
        m_Flicker.StartColorFickering(damageable.invulnerabilityDuration, 0.1f);

        //Hit effect
        VFXController.Instance.Trigger(m_HitEffectHash, transform.position, 0.1f, false, null);
    }
Example #7
0
    public void TakeDamage(Damager source, int amount, float knockbackMag)
    {
        health -= amount;
        if (health > maxHealth)
        {
            health = maxHealth;
        }
        if (health < 0)
        {
            health = 0;
        }
        if (OnDamaged != null)
        {
            OnDamaged(this, amount);
        }


        Transform opposedForceSource = source.optionalCenterOfMass != null ? source.optionalCenterOfMass : source.transform;
        Vector3   away = (transform.position - opposedForceSource.transform.position).normalized;

        TakeForce(away, knockbackMag);


        if (health <= 0 && !dying)
        {
            dying = true;
            if (OnDied != null)
            {
                OnDied(this);
            }
        }
    }
Example #8
0
    void OnSceneGUI()
    {
        Damager damager = target as Damager;

        if (!damager.enabled)
        {
            return;
        }

        Matrix4x4 handleMatrix = damager.transform.localToWorldMatrix;

        handleMatrix.SetRow(0, Vector4.Scale(handleMatrix.GetRow(0), new Vector4(1f, 1f, 0f, 1f)));
        handleMatrix.SetRow(1, Vector4.Scale(handleMatrix.GetRow(1), new Vector4(1f, 1f, 0f, 1f)));
        handleMatrix.SetRow(2, new Vector4(0f, 0f, 1f, damager.transform.position.z));
        using (new Handles.DrawingScope(handleMatrix))
        {
            s_BoxBoundsHandle.center = damager.offset;
            s_BoxBoundsHandle.size   = damager.size;

            s_BoxBoundsHandle.SetColor(s_EnabledColor);
            EditorGUI.BeginChangeCheck();
            s_BoxBoundsHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(damager, "Modify Damager");

                damager.size   = s_BoxBoundsHandle.size;
                damager.offset = s_BoxBoundsHandle.center;
            }
        }
    }
Example #9
0
    public override void DoHitReaction(Damager damager)
    {
        if (myStats.health > myStats.skinnableHealth)
        {
            float hitAngle = Vector3.Angle(controller.transform.forward, damager.impactDirection);

            if (hitAngle < 45.0f || hitAngle > 315.0f)
            {
                animator.SetTrigger("HitFront");
            }
            else if (hitAngle > 45.0f && hitAngle < 135.0f)
            {
                animator.SetTrigger("HitRight");
            }
            else if (hitAngle > 225.0f && hitAngle < 315.0f)
            {
                animator.SetTrigger("HitLeft");
            }

            currentHitReactionLayerWeight = 1.0f;
            animator.SetLayerWeight(3, currentHitReactionLayerWeight);
            Timing.RunCoroutine(HitReactionLerp(), CoroutineName);
        }
        base.DoHitReaction(damager);
    }
Example #10
0
    public void OnDamage(Damager iDamager, Damageable iDamageable)
    {
        Monster M = iDamager.GetComponent <Monster>();

        if (M)
        {
            if (M._KnockBack.IsRunning)
            {
                Instantiate(BloodSplashOnDmg, transform.position, transform.rotation);
                KnockBack KB = M._KnockBack;
                OnKnockBack(KB);
                _KnockBack.Power *= 1 / iDamageable.Size;

                iDamageable.CurrentHealth -= iDamager.Damage;
            }
        }
        else
        {
            Instantiate(BloodSplashOnDmg, transform.position, transform.rotation);
            KnockBack KB = iDamager._KnockBack;

            OnKnockBack(KB);
            _KnockBack.Power *= 1 / iDamageable.Size;
            var Player = GameObject.Find("Player");
            var FS     = Player.GetComponent <FameStacker>();
            FS.addFame(FameOnDmg);

            iDamageable.CurrentHealth -= iDamager.Damage;

            iDamageable.CurrentInvincibilityTime = iDamageable.InvincibilityTime;
        }
    }
Example #11
0
        private void Awake()
        {
            myActor      = GetComponent <Actor> ();
            myTimer      = GetComponent <Timer> ();
            myFsmManager = GetComponent <FSMManager> ();
            myAnimator   = GetComponent <Animator> ();
            myDamager    = GetComponentInChildren <Damager> ();
            myShooter    = GetComponentInChildren <Shooter> ();

            myActor.solidLayer = solidLayer;
            myActor.maxFall    = maxFall;
            myActor.gravity    = gravity;
            myFsmManager.RegisterState("Direction", "Left");
            myFsmManager.RegisterState("Direction", "Right", true, true);

            myFsmManager.RegisterState("FullBody", "Jump");
            myFsmManager.RegisterState("FullBody", "Fall");
            myFsmManager.RegisterState("FullBody", "Dash");
            myFsmManager.RegisterState("FullBody", "Idle", true, true);
            myFsmManager.RegisterState("FullBody", "Run");
            myFsmManager.RegisterState("Action", "Attack", false);
            myFsmManager.RegisterState("Action", "Shoot");

            myTimer.RegisterAction("DashDuration", Timer.types.Auto);
            myTimer.RegisterAction("DashLock", Timer.types.Auto);
            myTimer.RegisterAction("AttackDuration", Timer.types.Auto);
            myTimer.RegisterAction("AttackLock", Timer.types.Auto);
            myTimer.RegisterAction("ShootLock", Timer.types.Auto);
            // We can have several action cold down. Can cold down AttackLock/DashLock... -> parallel mode
            // we can only have one action is performed at the moment. Can only Jump/Fall/Dash -> sequential mode. Transfer to the other state when the action is performed and allowed.
            // we can only either have left or right -> sequential mode
            // Maybe Manual mode becomes useless...
        }
    public void GotHit(Damager damager, Damageable damageable)
    {
        //throw player away a little bit
        m_ThrowVector = new Vector2(0, throwSpeed.y);
        Vector2 damagerToThis = damager.transform.position - transform.position;

        m_ThrowVector.x = Mathf.Sign(damagerToThis.x) * -throwSpeed.x;
        SetMoveVector(m_ThrowVector);
        m_ExternalForceTimer = 0.5f;

        //Set animation
        m_Animator.SetTrigger(m_HashHurtPara);

        //Flicker
        m_Flicker.StartFlickering(damageable.invulnerabilityDuration, timeBetweenFlickering);

        //Shake camera a little
        CameraShaker.Shake(0.15f, 0.3f);

        if (damager.forceRespawn)
        {
            damageable.SetHealth(0);
            StartCoroutine(DieRespawnCoroutine(true));
        }
    }
    public void OnHurt(Damager damager, Damageable damageable) // Called when player gets hurt. Calculates damage, triggers invulnerability, respawns if needed.
    {
        if (!PlayerInput.Instance.HaveControl)
        {
            return;
        }

        ForceFacing(damageable.GetDamageDirection().x > 0f); // Force player to face direction of damage, so they are knocked "back".
        damageable.EnableInvulnerability();

        animator.SetTrigger(hashHurtParameter);

        if (damageable.CurrentHealth > 0 && damager.forceRespawn)
        {
            animator.SetTrigger(hashForcedRespawnParameter);
        }

        animator.SetBool(hashGroundedParameter, false);
        hurtAudioPlayer.PlayRandomSound();

        if (damager.forceRespawn && damageable.CurrentHealth > 0)
        {
            StartCoroutine(DieRespawnCoroutine(false, true, 1.0f));
        }
    }
    private void OnAttackHit(Damager damager)
    {
        //push back player a little bit
        float pushSpeed;

        if (m_IsLeftAttacking == false)
        {
            //set position of slash contact effect to be displayed
            slashContactTransform.position = transform.position + m_OffsetFromSlashEffectToAlessia;

            pushSpeed = -pushBackSpeed;
        }
        else
        {
            //set position of slash contact effect to be displayed
            Vector3 m_ReverseOffset = m_OffsetFromSlashEffectToAlessia;
            m_ReverseOffset.x *= -1;
            slashContactTransform.position = transform.position + m_ReverseOffset;

            pushSpeed = pushBackSpeed;
        }

        //Display slash contact effect
        slashContactTransform.rotation = Quaternion.Euler(0, 0, Random.Range(-50f, 50f));
        m_SlashContactEffect.Play();

        //Push back
        //m_Rigidbody2D.AddForce(m_PushBackVector, ForceMode2D.Impulse);

        SetHorizontalMovement(pushSpeed);

        m_ExternalForceTimer = 0.1f;

        CameraShaker.Shake(0.05f, 0.05f);
    }
Example #15
0
    public void OnEnemyGetHurt(Damager damager, Damageable damageable)
    {
        Vector2 forceDir =
            Mathf.Sign(damager.transform.position.x - damageable.transform.position.x) > 0 ? Vector2.left : Vector2.right;

        m_CharacterController2D.Rigidbody2D.AddForce(forceDir * 500f);
    }
Example #16
0
    /// <summary>
    /// Apply damage to this object.
    /// </summary>
    /// <param name="damager">Damager dealing damage to this object.</param>
    /// <param name="ignoreInvincible">Should invincibility be ignored.</param>
    public void TakeDamage(Damager damager, bool ignoreInvincible = false)
    {
        //If the character should not take damage at this point return
        if ((m_IsInvulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
        {
            return;
        }

        //If the character is not invulnerable apply damage to them and invoke the OnHealthSet event to trigger any subscribed functions
        if (!m_IsInvulnerable)
        {
            if (damager.Damage < m_CurrentHealth)
            {
                m_CurrentHealth -= damager.Damage;
            }
            else
            {
                m_CurrentHealth = 0;
            }
            m_OnHeathSet.Invoke(this);
        }

        //Invoke the OnTakeDamage event to trigger any subscribed functions
        m_OnTakeDamage.Invoke(damager, this);

        if (m_CurrentHealth <= 0)
        {
            m_OnDie.Invoke(damager, this);
            EnableInvulnerability();
            if (m_DisableOnDeath)
            {
                gameObject.SetActive(false);
            }
        }
    }
Example #17
0
    protected override void Start()
    {
        base.Start();
        deltaAttack = 2f;

        d = damager.GetComponent <Damager>();
    }
    public void Hit(Damager damager, Damageable damageable)
    {
        if (damageable.CurrentHealth <= 0)
        {
            return;
        }

        animator.SetTrigger(hashHitParameter);

        //Vector2 throwVector = new Vector2(0, 5.0f);
        //Vector2 damagerToThis = damager.transform.position - transform.position;

        //throwVector.x = Mathf.Sign(damagerToThis.x) * 2.0f;
        //moveVector = throwVector;

        moveVector = Vector2.zero;
        moveVector = new Vector2(0, knockback.y);

        if (flickeringCoroutine != null)
        {
            StopCoroutine(flickeringCoroutine);
            spriteRenderer.color = originalColor;
        }

        flickeringCoroutine = StartCoroutine(Flicker(damageable));
        CameraShaker.Shake(0.15f, 0.3f);
    }
Example #19
0
 void Start()
 {
     InitializeActor();
     punch    = damagers[0];
     kick     = damagers[1];
     jumpKick = damagers[2];
 }
    public void Damaged(Damager damager, Damageable damageable)
    {
        takingDamage.PlayRandomSound();

        currentHealth     -= damager.damage;
        healthSlider.value = currentHealth;
    }
 private void Awake()
 {
     boulder   = transform.Find("Boulder");
     boulderRB = boulder.GetComponent <Rigidbody2D>();
     collider  = boulder.GetComponent <BoxCollider2D>();
     damager   = boulder.GetComponent <Damager>();
 }
Example #22
0
    public void TakeDamage(Damager damager, bool ignoreInvincible = false)
    {
        if ((m_Invulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
        {
            return;
        }

        //we can reach that point if the damager was one that was ignoring invincible state.
        //We still want the callback that we were hit, but not the damage to be removed from health.
        if (!m_Invulnerable)
        {
            m_CurrentHealth -= damager.damage;
            //OnHealthSet.Invoke(this);
        }

        OnTakeDamage.Invoke(damager, this);

        if (m_CurrentHealth <= 0)
        {
            OnDie.Invoke(damager, this);
            m_ResetHealthOnSceneReload = true;
            EnableInvulnerability();
            if (disableOnDeath)
            {
                gameObject.SetActive(false);
            }
        }
    }
Example #23
0
 // Start is called before the first frame update
 void Start()
 {
     _damager           = GetComponent <Damager>();
     _attackTimeElapsed = 0.0F;
     _spear             = transform.Find("Spear");
     _damager.DisableDamager();
 }
Example #24
0
    public void TakeDamage(Damager damager, bool ignoreInvincible = false)
    {
        if ((m_Invulnerable && !ignoreInvincible) || m_CurrentHealth <= 0)
        {
            return;
        }

        print("IGNORING INVINCIBILITY");

        //we can reach that point if the damager was one that was ignoring invincible state.
        //We still want the callback that we were hit, but not the damage to be removed from health.
        if (!m_Invulnerable)
        {
            m_CurrentHealth -= damager.damage;
            OnHealthSet.Invoke(this);
            EnableInvulnerability(invulnerableAfterDamage);
        }

        m_DamageDirection = transform.position + (Vector3)centreOffset - damager.transform.position;

        OnTakeDamage.Invoke(damager, this);

        if (m_CurrentHealth <= 0)
        {
            OnDie.Invoke(damager, this);
            m_ResetHealthOnSceneReload = true;
            EnableInvulnerability();
            if (disableOnDeath)
            {
                gameObject.SetActive(false);
            }
        }
    }
Example #25
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == Strings.Tags.ENEMY)
        {
            IDamageable damageable = other.gameObject.GetComponent <IDamageable>();
            if (!damageable.IsNull())
            {
                Damager damager = new Damager();
                // HACK - This isn't perfect.. but I think it will suffice for our type of gameplay.
                damager.Set(currentDamage, DamagerType.SpreadGun, transform.forward);
                damageable.TakeDamage(damager);

                GameObject blood = ObjectPool.Instance.GetObject(PoolObjectType.VFXBloodSpurt);
                if (blood)
                {
                    blood.transform.position = damageable.GetPosition();
                }
            }
            GameObject vfx = ObjectPool.Instance.GetObject(impactVFX);
            if (vfx)
            {
                vfx.transform.position = other.transform.position;
            }
        }
        else if (other.tag == Strings.Tags.WALL)
        {
            GameObject vfx = ObjectPool.Instance.GetObject(impactVFX);
            if (vfx)
            {
                vfx.transform.position = other.transform.position;
            }
            gameObject.SetActive(false);
        }
    }
Example #26
0
    public void TakeDamage(Damager damager, bool ignoreInvincible = false)
    {
        if ((invulnerable && !ignoreInvincible) || currentHealth <= 0)
        {
            return;
        }

        if (!invulnerable)
        {
            currentHealth -= damager.damage;
            OnHealthSet.Invoke(this);
        }

        damageDirection = transform.position + (Vector3)centerOffset - damager.transform.position;

        if (damager.forceRespawn)
        {
            damageDirection = Vector3.zero;
        }
        OnTakeDamage.Invoke(damager, this);

        if (currentHealth <= 0)
        {
            OnDie.Invoke(damager, this);
            resetHealthOnSceneReload = true;
            EnableInvulnerability();
            if (disableOnDeath)
            {
                gameObject.SetActive(false);
            }
        }
    }
Example #27
0
 // TODO : remove
 public void OnDieBoss(Damager damager, Damageable damageable)
 {
     _agent.speed  = 0;
     _defaultSpeed = 0;
     _berserkSpeed = 0;
     _chargeSpeed  = 0;
 }
Example #28
0
 private void Start()
 {
     m_Damager          = GetComponent <Damager>();
     fireWall           = GetComponent <BoxCollider>();
     self               = transform.parent.parent.transform;
     collisionParticles = m_Damager.collisionParticles;
 }
    public void Hit(Damager damager, Damageable damageable)
    {
        //if (damageable.CurrentHealth <= 0)
        //    return;

        if (HashHitPara != 0)
        {
            m_Animator.SetTrigger(HashHitPara);
        }

        if (hashHitEffect != 0)
        {
            VFXController.Instance.Trigger(hashHitEffect, transform.position, 0, m_SpriteForward.x > 0 ? false : true, null);
        }

        PlayHitAudio();

        //Vector2 throwVector = new Vector2(0, 3.0f);
        //Vector2 damagerToThis = damager.transform.position - transform.position;

        //throwVector.x = Mathf.Sign(damagerToThis.x) * -2.0f;
        //m_MoveVector = throwVector;

        if (m_FlickeringCoroutine != null)
        {
            StopCoroutine(m_FlickeringCoroutine);
            m_SpriteRenderer.color = m_OriginalColor;
        }

        m_FlickeringCoroutine = StartCoroutine(Flicker(damageable));

        //CameraShaker.Shake(0.15f, 0.3f);
    }
Example #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="damager"></param>
        /// <param name="damageable"></param>
        public void OnDie(Damager damager, Damageable damageable)
        {
            GameController.Instance.actionsMapsHelper.DisableMap("Gameplay");

            // After animation :
            GameController.Instance.SceneController.FadeAndLoadScene("MainMenu");
        }
    public void Hurt(Damager damager)
    {
        health -= damager.damage;

        if (health > 0f) {
            animator.SetTrigger("Hurt");
            audioSource.PlayOneShot(audioClips.hurtclip);
        } else {
            Die();
        }
    }
Example #32
0
    public void TakeDamage(Damager cause, int damage)
    {
        if (!CanBeHit(cause))
        {
            return;
        }
		
		currentHealth = Mathf.Max(0, currentHealth - damage);

		if (currentHealth > 0)
        {
			Hit();
		}
        else
        {
			Die();
		}
	}
Example #33
0
    IEnumerator RaisePillar()
    {
        pillarInst = (GameObject)Instantiate (pillar, pillarSpawnPos, transform.rotation);
        Vector3 targetPos = stopPos;
        targetPos.y -= collider.bounds.extents.y;
        float speed = 7;

        foreach (Transform child in pillarInst.transform) //might cause lag
            damager = child.GetComponent<Damager>();
        damager.damage = damage;

        while (pillarInst.transform.position != targetPos) {
            speed *= 1.17f;
            pillarInst.transform.position = Vector3.MoveTowards(pillarInst.transform.position, targetPos, speed * Time.deltaTime);
            yield return null;
        }

        transform.position = stopPos;
        negativeHover.enabled = false;
        Destroy (damager);
        yield return new WaitForSeconds (lowerDelay);
        StartCoroutine (LowerPillar (pillarSpawnPos));
    }
Example #34
0
    protected bool CanBeHit(Damager cause)
    {
        if (invulnerable)
        {
            return false;
        }

        if (Immune(cause))
        {
            return false;
        }
        
        if (cause.dodgeable && dodging)
        {
            return false;
        }

        if (currentHitTimeout > 0)
        {
            return false;
        }

        return true;
    }
Example #35
0
 protected virtual bool Immune(Damager cause)
 {
     return false;
 }
Example #36
0
 void RecieveDamage(Damager damager)
 {
     UpdateHealth(-damager.damage);
     StartCoroutine(InvincibilityMode());
 }
Example #37
0
 private void landedAttack(Damager damager, int damageDone, bool killingBlow)
 {
     int points = killingBlow ? ProgressData.POINTS_FOR_KILL : ProgressData.POINTS_FOR_HIT;
     ProgressData.ApplyPointsDeltaForPlayer(_allegianceInfo.MemberId, points);
     GlobalEvents.Notifier.SendEvent(new PlayerPointsReceivedEvent(_allegianceInfo.MemberId, points));
 }
Example #38
0
 protected override bool Immune(Damager cause)
 {
     return !cause.GetComponent<Explosion>();
 }
	//------------------------------------------------------------------------------------------------------------------
	// Adciona o metodo que chama a animaçao de invencibilidade ao metodo principal
	//------------------------------------------------------------------------------------------------------------------
	public override void runCommand(){
		invencibilityEffect();
		base.runCommand();
		damager = null;
	}
    // Use this for initialization
    void Start()
    {
        //slash = new movement(new Vector3(1, 1, 1), new Vector3(-1, 0, 1), 0.3f);
        //slashRecoverP1 = new movement(slash.endVec, new Vector3(-0.4f, -0.3f, 1), 0.2f);
        //slashRecoverP2 = new movement(slashRecoverP1.endVec, slash.startVec, 0.5f);

        slashAttack.fixUpConnectivity();
        MH1.fixUpConnectivity();

        chargeLight = GetComponentInChildren<Light>();

        damage = GetComponent<Damager>();
        //emit = GetComponentInChildren<ParticleSystem>();

        billboard = GameObject.Find("LightBillboard");
        billboard.SetActive(false);

        if(chargeup.moveList.Count < 1)
        {
            Debug.Log("Chargeup is definitely going to crash, movelist < 1");
            ///should find out how to throw c# exceptions and throw one
        }

        swordTransform.localRotation = Quaternion.LookRotation(MH1.moveList[0].startVec);

        /*if(emit == null)
        {
            Debug.Log("no emitter, likely crash");
        }*/

        //emit.Stop();
    }
Example #41
0
    public void ReceiveDamage(Damager other)
    {
        _alreadyHitThisUpdate.Add(other.gameObject);

        if (this.ApplyDamageLocally)
            this.Health -= other.Damage;

        if (!this.IgnoreHealthCallbacks)
        {
            foreach (HealthCallback callback in this.OnHealthChangeCallbacks)
                callback(this, this.Health >= 0 ? other.Damage : other.Damage + this.Health);
        }

        Vector2 impactVector = Vector2.zero;

        if (!this.Stationary)
        {
            Vector2 difference = this.integerPosition - other.integerPosition;
            Actor2D otherActor = other.gameObject.GetComponent<Actor2D>();
            Vector2 otherV = otherActor != null ? otherActor.Velocity : Vector2.zero;
            difference.Normalize();
            otherV.Normalize();
            impactVector = (difference + otherV).normalized;
        }

        if (this.Health <= 0)
        {
            _deathKnockback = other.Knockback * this.KnockbackMultiplier;
            _deathImpactVector = impactVector;
            markForDeath();
        }
        else
        {
            if (!this.Stationary)
            {
                _actor.SetVelocityModifier(VELOCITY_MODIFIER_KEY, new VelocityModifier(impactVector * other.Knockback * this.KnockbackMultiplier, VelocityModifier.CollisionBehavior.bounce));

                _nonInvincibleCollisionMask = _actor.CollisionMask;
                _actor.CollisionMask = this.InvincibilityCollisionMask;
            }

            this.Invincible = true;
            _invincibilityTimer = other.HitInvincibilityDuration * this.HitInvincibilityMultiplier;
            this.integerCollider.RemoveFromCollisionPool();

            this.localNotifier.SendEvent(new InvincibilityToggleEvent(true));

            if (_audio != null && this.AudioOnHit != null)
            {
                _audio.clip = this.AudioOnHit;
                _audio.Play();
            }
        }

        if (this.BaseShakeHitMagnitude > 0.0f || this.ShakeHitToDamageRatio > 0.0f)
        {
            Camera.main.GetComponent<ShakeHandler>().ApplyImpact(this.BaseShakeHitMagnitude + this.ShakeHitToDamageRatio * other.Damage);
        }
    }