예제 #1
0
        // Called by OnReceiveMessage.
        public override void Damaged(Damageable.DamageMessage damageMessage)
        {
            m_PawnStats.Damage(damageMessage);
            if (GetHealth() <= 0)
            {
                Die(damageMessage);
                return;
            }
            // Set the Hurt parameter of the animator.
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = damageMessage.damageSource - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            OnDamage.Invoke(GetHealth());

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            // Shake the camera.
            //todo CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime);

            // Play an audio clip of being hurt.
            if (hitAudio != null)
            {
                hitAudio.PlayRandomClip();
            }
        }
예제 #2
0
        protected bool Apply(Collision collision)
        {
            if (collision.gameObject != null)
            {
                var health = collision.gameObject.GetComponentInParent <Health>();
                if (health != null)
                {
                    Debug.LogError("Point: " + collision.GetContact(0).point +
                                   "Normal: " + collision.GetContact(0).normal);
                    GameManager.Instance.
                    ConnectionManager.
                    ActiveConnection.
                    SendMessage <PlayerEffectMessage>(
                        new PlayerEffectMessage()
                    {
                        Effect = Effects.Effect.Damage,
                        Point  = collision.GetContact(0).point,
                        Normal = collision.GetContact(0).normal
                    });


                    Damager damager = Creator == null ? new Damager(this.gameObject) : new Damager(Creator);
                    var     args    = health.Modify(-DamageAmount, damager);
                    OnDamage?.Invoke(this, EventArgs.Empty);
                    return(args != null);
                }
            }

            return(false);
        }
예제 #3
0
    public void ApplyDamage(Vector2 position, int damage)
    {
        if (healthPoints == 0)
        {
            return;
        }
        healthPoints = Mathf.Max(0, healthPoints - damage);

        float angle = Mathf.Atan2(transform.position.y - position.y, transform.position.x - position.x);

        FX.Instance.PlayPostProcessEffect(damagePPFX, Camera.main.WorldToScreenPoint(transform.position), angle);

        if (GetComponent <PlayerSound>())
        {
            GetComponent <PlayerSound>().PlaySound();
        }


        if (OnDamage != null)
        {
            OnDamage.Invoke(position, damage);
        }

        if (healthPoints == 0)
        {
            FX.Instance.PlayPostProcessEffect(deathPPFX, Camera.main.WorldToScreenPoint(transform.position), angle);
            if (OnDeath != null)
            {
                OnDeath.Invoke();
            }
        }
    }
예제 #4
0
파일: UnitData.cs 프로젝트: SpyClops/Test
 public void Damage(Weapon.AttackData attackData)
 {
     m_HitCoolDown      = 5f;
     regenerationsBlock = false;
     Stats.Damage(attackData);
     OnDamage?.Invoke();
 }
예제 #5
0
        void Update()
        {
            //debug inputs
            if (DEBUG_MODE)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    OnDamage?.Invoke();
                }
            }

            //movement input
            Vector3 moveDirection = new Vector3(Input.GetAxisRaw("Left Stick Horizontal"), 0, Input.GetAxisRaw("Left Stick Vertical")).normalized;
            Vector3 moveVelocity  = moveDirection * Time.deltaTime * moveSpeed;

            controller.Move(moveVelocity);

            //shoot input
            if (Input.GetButton("Infinite Runner Shoot"))
            {
                equippedGun.Shoot();
            }

            //movement particle
            if (particle_Ship_Movement.isPlaying && moveVelocity == Vector3.zero)
            {
                particle_Ship_Movement.Stop(false, ParticleSystemStopBehavior.StopEmitting);
            }
            else if (particle_Ship_Movement.isStopped)
            {
                particle_Ship_Movement.Play();
            }
        }
 public static void Transmit(DamageMessage message)
 {
     if (OnDamage != null)
     {
         OnDamage.Invoke(message);
     }
 }
예제 #7
0
    public void Damage(float amount, GameObject attacker = null, Vector3?from = null)
    {
        if (Invulnerable)
        {
            return;
        }
        if (Health <= 0)
        {
            return;
        }

        Health -= amount;

        if (DamageRegenDelay > 0)
        {
            regenDelay = DamageRegenDelay;
        }

        OnDamage?.Invoke(amount);

        if (Health < 0 + Mathf.Epsilon)
        {
            if (RagdollOnDeath)
            {
                ActivateRagdoll(true);
            }
            OnDeath?.Invoke();
        }
    }
예제 #8
0
    public void TakeDamage(float proposedDamage, Monster source)
    {
        var actualDamage = (int)(proposedDamage / Defense);

        Health -= actualDamage;
        OnDamage?.Invoke(this, new OnDamageEventArgs()
        {
            DamageAmount = actualDamage, RemainingHealth = Health, DamageSource = source
        });

        if (Health > 0)
        {
            return;
        }

        OnDeath?.Invoke(this, new OnDeathEventArgs()
        {
            DamageSource = source
        });
        if (Health > 0)
        {
            return;             //OnDeath may restore health
        }
        gameObject.SetActive(false);
        Battle.Instance.CalculateTurnOrder();
    }
예제 #9
0
        public void ApplyDamage(AttackPayload payload)
        {
            var config = _damageConfigLookUp[payload.AttackType];

            _rigidbody.AddForce(payload.Direction * (payload.Force * config.Force), ForceMode2D.Impulse);
            OnDamage?.Invoke(payload.AttackType);
        }
예제 #10
0
    public override void GetDamage(int damage, Entity attacker, AttackType attackType)
    {
        AddToHistory(attackType);

        SwitchWindowState();

        OnDamage?.Invoke(this, damage);
    }
예제 #11
0
파일: HealthSystem.cs 프로젝트: mz000/QQ
 public virtual void Damage(float damage)
 {
     amount -= damage;
     OnDamage?.Invoke();
     if (amount <= 0)
     {
         Die();
     }
 }
예제 #12
0
        void RpcOwnerHurt()
        {
            if (isServer)
            {
                return;
            }

            OnDamage?.Invoke(null);
        }
예제 #13
0
 public void Damage(int damageAmount)
 {
     healthAmount -= damageAmount;
     healthAmount  = Mathf.Clamp(healthAmount, 0, healtAmountMax);
     OnDamage?.Invoke(this, EventArgs.Empty);
     if (IsDead())
     {
         OnDide?.Invoke(this, EventArgs.Empty);
     }
 }
예제 #14
0
        /// <summary>
        /// Apply change to health by value
        /// </summary>
        /// <param name="value"></param>
        public void ApplyChange(int value)
        {
            int temp = this.health + value;

            SetHealth(temp);
            if (value < 0)
            {
                OnDamage?.Invoke();
            }
        }
        public void TakeDamage(int amount)
        {
            currentHealth -= amount;
            OnDamage?.Invoke();
            SoundController.Instance.PlayAudio(TypeAudio.PlayerDamage);

            if (currentHealth <= 0 && !isDead)
            {
                Death();
            }
        }
예제 #16
0
    public void Damage(GameObject damager, float damage, Vector2 point, Vector2 direction)
    {
        currentHealth -= damage;

        OnDamage?.Invoke(damager, damage, point, direction);

        if (currentHealth < 0)
        {
            Kill(damager, damage, point, direction);
        }
    }
예제 #17
0
        public void TakeDamage(int damage)
        {
            CurrentHealth -= damage;

            OnDamage?.Invoke(damage);

            if (CurrentHealth <= 0)
            {
                OnDied?.Invoke();
            }
        }
예제 #18
0
        public virtual void Damage(GameObject DamageSource, int Points)
        {
            HP -= Points;

            OnDamage?.Invoke(this, new DamageEventArgs
            {
                Source      = DamageSource,
                Target      = this,
                Points      = Points,
                IsDestroyed = CurrentState == State.DESTROYED,
            });
        }
예제 #19
0
파일: UnitHealth.cs 프로젝트: solkar/GGJ19
    public void TakeDamage(float damage)
    {
        health -= damage;

        if (health < 0)
        {
            stateMachine.RequestChangePlayerState(CharacterStateMachine.CharacterState.dead);
            StartCoroutine(RemoveUnit());
            Debug.Log("Dead!!");
        }

        OnDamage?.Invoke(damage);
    }
예제 #20
0
 void Damage()
 {
     lives -= 1;
     hearts[lives].color = new Color(1, 1, 1, .1f);
     if (lives > 0)
     {
         TemporarilySwapFace(sad, new Color(1, .4f, .4f), .85f);
         OnDamage.Invoke();
     }
     else
     {
         GameOver();
     }
 }
        /// <summary>
        /// Alters the health of this object.
        /// </summary>
        /// <param name="damage"></param>
        public void Damage(float damage, BaseObject objectDoingTheDamage)
        {
            if (CalculateDamage != null)
            {
                // Override the damage we are inputting
                damage = CalculateDamage(objectDoingTheDamage, damage);
            }

            float damageDealt = Math.Min(Health, damage);       // If our health is less than the damage we are dealing we only want to pass the amount of damage we are actually doing

            Health -= damage;

            OnDamage?.Invoke(this, damageDealt);
        }
예제 #22
0
 public void TakeDamage(Damage damage)
 {
     if (Hp <= 0)
     {
         return;
     }
     damage = Weakness.ApplyAdditionalDamage(damage);
     Hp    -= damage.Amount;
     OnDamage?.Invoke();
     if (Hp <= 0)
     {
         OnDeath?.Invoke();
     }
 }
예제 #23
0
    public void SetBattleStage(EBattleStage nextStage, RythmMove move = null)
    {
        _currentBattleStage = nextStage;
        if (move != null)
        {
            currentMove = move;
        }
        switch (_currentBattleStage)
        {
        case EBattleStage.Intro:
            SetCharacterValues();
            pauseController.CanPause = false;
            OnIntro?.Invoke();
            break;

        case EBattleStage.PlayerTurn:
            SetEnemyAnimation(enemy.IdleAnimation);
            pauseController.CanPause = true;
            OnPlayerTurn?.Invoke();
            break;

        case EBattleStage.PlayerMove:
            _lastToMoveIsPlayer = true;
            OnPlayerMove?.Invoke();
            break;

        case EBattleStage.EnemyTurn:
            SetPlayerAnimation(player.IdleAnimation);
            pauseController.CanPause = true;
            OnEnemyTurn?.Invoke();
            StartCoroutine(WaitToEnemyMove());
            break;

        case EBattleStage.EnemyMove:
            _lastToMoveIsPlayer = false;
            OnEnemyMove?.Invoke();
            break;

        case EBattleStage.DamageStep:
            OnDamage?.Invoke();
            StartCoroutine(DelayedDamage());
            break;

        case EBattleStage.Conclusion:
            pauseController.CanPause = false;
            OnConclusion?.Invoke();
            break;
        }
    }
예제 #24
0
        public void TakeDamage(int amount)
        {
            CurHp -= amount;
            if (CurHp < 0)
            {
                CurHp = 0;
            }

            OnDamage?.Invoke(CurHp, MaxHp);

            if (CurHp == 0)
            {
                OnKilled?.Invoke(Id);
            }
        }
    static void checkBustState(int strikes)
    {
        maxBusts -= strikes;
        OnDamage.Invoke(strikes);

        if (maxBusts < 0)
        {
            gameFailEnd();
        }
        if (maxBusts > 0)
        {
            Flag flag = new Flag("PLAYER_LOST_HP", 0, false);
            flag.FireFlag();
            PlayerDataHolder.Current.PlayerMoney.resetMoney();
            PaerToolBox.changePlayerMoney(100);
        }
    }
예제 #26
0
        /// <summary>
        /// Damage the Character by the AttackData given as parameter. See the documentation for that class for how to
        /// add damage to that attackData. (this will be done automatically by weapons, but you may need to fill it
        /// manually when writing special elemental effect)
        /// </summary>
        /// <param name="attackData"></param>
        public void Damage(Weapon.AttackData attackData)
        {
            if (HitClip.Length != 0)
            {
                SFXManager.PlaySound(SFXManager.Use.Player, new SFXManager.PlayData()
                {
                    Clip     = HitClip[Random.Range(0, HitClip.Length)],
                    PitchMax = 1.1f,
                    PitchMin = 0.8f,
                    Position = transform.position
                });
            }

            Stats.Damage(attackData);

            OnDamage?.Invoke();
        }
예제 #27
0
 public void ReceivedDamage(int amount, Vector3 worldOrigin)
 {
     if (Time.time <= _lastDamage + damageCooldown)
     {
         return;
     }
     if (_isDead)
     {
         return;
     }
     _currentHp -= amount;
     _lastDamage = Time.time;
     OnDamage?.Invoke(amount, worldOrigin);
     if (_currentHp <= 0)
     {
         _isDead = true;
         OnDead?.Invoke();
     }
 }
예제 #28
0
        public override void Deserialize(BitStream bs)
        {
            var newHealth = bs.ReadByte();

            if (newHealth != Health)
            {
                if (newHealth < Health)
                {
                    OnDamage?.Invoke(null);
                    if (isOwner)
                    {
                        EventHub <HurtEvent> .Emit(new HurtEvent(this));
                    }
                }
                if (newHealth > Health)
                {
                    EventHub <HealedEvent> .Emit(new HealedEvent(this));
                }
                Health = newHealth;
            }
        }
예제 #29
0
        public HitResult HitCheck(int ballColorId, int targetColorId)
        {
            HitResult hitResult;

            if (ballColorId == targetColorId)
            {
                playerState.Regen();
                scoreKeeper.IncrementCurrentScore(playerState.Combo);
                hitResult = new HitResult {
                    successfulHit = true, playerDead = false
                };
                OnSuccessfulHit?.Invoke();
            }
            else
            {
                playerState.TakeDamage();
                OnDamage?.Invoke();

                if (playerState.IsDead)
                {
                    GameState = GameState.GameOver;
                    OnGameOver?.Invoke();

                    hitResult = new HitResult {
                        successfulHit = false, playerDead = true
                    };
                }
                else
                {
                    hitResult = new HitResult {
                        successfulHit = false, playerDead = false
                    };
                }
            }

            OnHit?.Invoke();
            return(hitResult);
        }
예제 #30
0
        public void ApplyDamage(DamageInfo info)
        {
            if (IsDead)
            {
                return;
            }

            Health = Math.Max(Health - info.Amount, 0);
            if (Health == 0)
            {
                if (isServer)
                {
                    Kill(info);
                }
            }
            else
            {
                OnDamage?.Invoke(info);
                if (isServer)
                {
                    RpcOwnerHurt();
                }
            }
        }