Inheritance: MonoBehaviour
Example #1
0
    protected override void OnBeHit(DamageBase damage)
    {
        if (Player.IsDefence)
        {
            return;
        }

        if (damage.AttackPolarity != Polarity.None)
        {
            Vector2 myPoistion2Target = (damage.AttackPosition - new Vector2(Player.transform.position.x, Player.transform.position.y)).normalized;

            if (damage.AttackPolarity != Player.PlayerPolarity)
            {
                PlayerRigidbody2D.AddForce(myPoistion2Target * damage.AttackForce * AttackForceCoefficient);
            }
            else
            {
                PlayerRigidbody2D.AddForce(-myPoistion2Target * damage.AttackForce * AttackForceCoefficient);
            }
            if (Player.OnBeHit != null)
            {
                Player.OnBeHit(damage);
            }
        }
    }
Example #2
0
    public int Damage(DamageBase damage)
    {
        if (!NetworkManagerCustom.IsServer)
        {
            return(0);
        }

        DamageEvent e = GetEventSystem <DamageEvent>().CallListners(new DamageEvent(gameObject, damage));

        if (e.IsCancel)
        {
            return(0);
        }

        int preDamage = HealthValue;

        HealthValue -= e.Damage.Value;
        if (HealthValue <= 0)
        {
            HealthValue = 0;
            if (GetComponent <IDeath>() != null && !GetComponent <IDeath>().Death(damage))
            {
                HealthValue = 1;
                preDamage   = 0;
            }
        }
        return(HealthValue - preDamage);
    }
Example #3
0
    public void CmdRequestThrowObject(Vector3 position, Quaternion rotation, string itemID, Vector3 force)
    {
        ItemData itemdata = UnitZ.itemManager.GetItemDataByID(itemID);

        if (itemdata)
        {
            if (itemdata.ItemFPS)
            {
                FPSItemThrow fpsthrow = itemdata.ItemFPS.GetComponent <FPSItemThrow>();
                if (fpsthrow)
                {
                    if (fpsthrow.Item)
                    {
                        GameObject obj = UnitZ.gameNetwork.RequestSpawnObject(fpsthrow.Item, position, rotation);
                        if (obj)
                        {
                            DamageBase dm = obj.GetComponent <DamageBase>();
                            if (dm)
                            {
                                dm.OwnerID   = NetID;
                                dm.OwnerTeam = Team;
                            }
                            if (obj.GetComponent <Rigidbody>())
                            {
                                obj.GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse);
                            }
                        }
                    }
                }
            }
        }
    }
Example #4
0
 public void OnBeHitBefore(DamageBase damage)
 {
     OnBeHit(damage);
     for (int i = 0; i < damage.Buffes.Count; i++)
     {
         Player.BuffManager.AddBuff(damage.Buffes[i]);
     }
 }
Example #5
0
    void Start()
    {
        if (GetComponent <Collider>())
        {
            Physics.IgnoreCollision(GetComponent <Collider>(), Owner.GetComponent <Collider>());
            if (Owner.transform.root)
            {
                foreach (Collider col in Owner.transform.root.GetComponentsInChildren <Collider>())
                {
                    Physics.IgnoreCollision(GetComponent <Collider>(), col);
                }
            }
        }
        DamagePackage dm = new DamagePackage();

        dm.Damage = Damage;
        dm.Owner  = Owner;
        RaycastHit hit;
        GameObject explosion = null;

        startPosition = this.transform.position;

        if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range))
        {
            AimPoint = hit.point;
            if (Explosion != null)
            {
                explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, Explosion.transform.rotation);
            }
            hit.collider.gameObject.SendMessage("ApplyDamage", dm, SendMessageOptions.DontRequireReceiver);
        }
        else
        {
            AimPoint = this.transform.forward * Range;
            if (Explosion != null)
            {
                explosion = (GameObject)GameObject.Instantiate(Explosion, AimPoint, Explosion.transform.rotation);
            }
        }
        if (explosion)
        {
            DamageBase dmg = explosion.GetComponent <DamageBase> ();
            if (dmg)
            {
                dmg.TargetTag = TargetTag;
            }
        }


        if (Trail)
        {
            Trail.SetPosition(0, startPosition);
            Trail.SetPosition(1, this.transform.position + this.transform.forward * 10000);
        }
        Destroy(this.gameObject, LifeTime);
    }
Example #6
0
    public bool Death(DamageBase lastDamage)
    {
        DeathEvent result = GetEventSystem <DeathEvent>().CallListners(new DeathEvent(gameObject, lastDamage));

        if (!result.IsCancel)
        {
            OnDeath(lastDamage);
        }
        return(!result.IsCancel);
    }
    protected override void OnBeHit(DamageBase damage)
    {
        base.OnBeHit(damage);

        if (damage.AttackPolarity == Polarity.None)
        {
            Vector2 myPoistion2Target = (damage.AttackPosition - new Vector2(Player.transform.position.x, Player.transform.position.y)).normalized;
            PlayerRigidbody2D.AddForce(-myPoistion2Target * damage.AttackForce * AttackForceCoefficient);
            Player.OnBeHit?.Invoke(damage);
        }
    }
Example #8
0
 void OnDestroy()
 {
     if (!isQuitting && Spawn)
     {
         GameObject fx = (GameObject)GameObject.Instantiate(Spawn, this.transform.position, this.transform.rotation);
         DamageBase dm = fx.GetComponent <DamageBase> ();
         if (dm)
         {
             dm.OwnerID   = OwnerID;
             dm.OwnerTeam = OwnerTeam;
         }
     }
 }
Example #9
0
    public DamageBase Copy()
    {
        DamageBase copy = new DamageBase();

        copy.AttackForce    = AttackForce;
        copy.AttackPolarity = AttackPolarity.Copy();
        for (int i = 0; i < Buffes.Count; i++)
        {
            copy.Buffes.Add(Buffes[i].Copy());
        }
        copy.AttackPosition = AttackPosition;
        copy.Attacker       = Attacker;
        return(copy);
    }
Example #10
0
    virtual protected void OnBeHit(DamageBase damage)
    {
        Vector2 orgin2Attacker = damage.Attacker.Player.transform.position - Player.transform.position;
        float   attackAngle    = Vector2.Angle(orgin2Attacker, Vector2.up) * 2.0f;

        if (attackAngle > HitAngle)
        {
            return;
        }

        BeHitEffectTime.Start();

        m_platformEffector.useOneWay       = true;
        m_platformEffector.useColliderMask = true;
    }
Example #11
0
    public virtual void DoDamage(DamageBase aDamage)
    {
        //Color curColor = gameObject.GetComponent<CanvasRenderer>().GetColor();

        if (_isDead)
        {
            return;
        }

        if (_fraction == aDamage.fraction)
        {
            return;
        }

        if (aDamage.isOverTime)
        {
            hitPoint -= aDamage.value * Time.fixedDeltaTime;
            //gameObject.GetComponent<CanvasRenderer>().SetColor(Color.red);
        }
        else
        {
            hitPoint -= aDamage.value;
            //gameObject.GetComponent<CanvasRenderer>().SetColor(Color.red);
        }

        if (hitPoint <= 0)
        {
            hitPoint = 0;
            _isDead  = true;
            if (_fraction == Fraction.Player)
            {
                NotificationManager.Instance.PostEvent(NotificationType.playerIsDied);
            }
            if (_fraction == Fraction.Alien)
            {
                Destroy(this.gameObject); //todo: Efect
                //Instantiate(_onDeathEffect, tr.position, tr.rotation);
            }
        }
        //gameObject.GetComponentInChildren<CanvasRenderer>().SetColor(curColor);
    }
Example #12
0
    protected override void OnAttack(Collider2D collision)
    {
        BeHitBase beHit = collision.GetComponent <BeHitBase>();

        if (beHit)
        {
            AttackDamage.AttackPolarity = Player.PlayerPolarity;
            AttackDamage.AttackPosition = transform.position;
            DamageBase damage = AttackDamage.Copy();

            float u = (collision.transform.position - transform.position).magnitude / collider.radius;

            damage.AttackForce = AttackDamage.AttackForce * Mathf.Lerp(1, centerForce, u);
            beHit.OnBeHitBefore(damage);
            if (Player.OnAttack != null)
            {
                Player.OnAttack.Invoke(beHit.Player);
            }
        }
        base.OnAttack(collision);
    }
Example #13
0
    public void Shoot()
    {
        if (InfinityAmmo)
        {
            Ammo = 1;
        }
        if (Ammo > 0)
        {
            if (Time.time > nextFireTime + FireRate)
            {
                nextFireTime = Time.time;
                torqueTemp   = TorqueSpeedAxis;
                Ammo        -= 1;
                Vector3    missileposition = this.transform.position;
                Quaternion missilerotate   = this.transform.rotation;
                if (MissileOuter.Length > 0)
                {
                    missilerotate   = MissileOuter [currentOuter].transform.rotation;
                    missileposition = MissileOuter [currentOuter].transform.position;
                }

                if (MissileOuter.Length > 0)
                {
                    currentOuter += 1;
                    if (currentOuter >= MissileOuter.Length)
                    {
                        currentOuter = 0;
                    }
                }

                if (Muzzle)
                {
                    GameObject muzzle = (GameObject)GameObject.Instantiate(Muzzle, missileposition, missilerotate);
                    muzzle.transform.parent = this.transform;
                    GameObject.Destroy(muzzle, MuzzleLifeTime);
                    if (MissileOuter.Length > 0)
                    {
                        muzzle.transform.parent = MissileOuter [currentOuter].transform;
                    }
                }

                for (int i = 0; i < NumBullet; i++)
                {
                    if (Missile)
                    {
                        Vector3 spread    = new Vector3(Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), Random.Range(-Spread, Spread)) / 100;
                        Vector3 direction = this.transform.forward + spread;



                        GameObject bullet      = (GameObject)Instantiate(Missile, missileposition, missilerotate);
                        DamageBase damangeBase = bullet.GetComponent <DamageBase> ();
                        if (damangeBase)
                        {
                            damangeBase.Owner     = Owner;
                            damangeBase.TargetTag = TargetTag;
                        }
                        WeaponBase weaponBase = bullet.GetComponent <WeaponBase> ();
                        if (weaponBase)
                        {
                            weaponBase.Owner     = Owner;
                            weaponBase.Target    = target;
                            weaponBase.TargetTag = TargetTag;
                        }
                        bullet.transform.forward = direction;
                        if (RigidbodyProjectile)
                        {
                            if (bullet.GetComponent <Rigidbody>())
                            {
                                if (Owner != null && Owner.GetComponent <Rigidbody>())
                                {
                                    bullet.GetComponent <Rigidbody>().velocity = Owner.GetComponent <Rigidbody>().velocity;
                                }
                                bullet.GetComponent <Rigidbody>().AddForce(direction * ForceShoot);
                            }
                        }
                    }
                }
                if (Shell)
                {
                    Transform shelloutpos = this.transform;
                    if (ShellOuter.Length > 0)
                    {
                        shelloutpos = ShellOuter [currentOuter];
                    }

                    GameObject shell = (GameObject)Instantiate(Shell, shelloutpos.position, Random.rotation);
                    GameObject.Destroy(shell.gameObject, ShellLifeTime);
                    if (shell.GetComponent <Rigidbody>())
                    {
                        shell.GetComponent <Rigidbody>().AddForce(shelloutpos.forward * ShellOutForce);
                    }
                }

                if (SoundGun.Length > 0)
                {
                    if (audio)
                    {
                        audio.PlayOneShot(SoundGun [Random.Range(0, SoundGun.Length)]);
                    }
                }

                nextFireTime += FireRate;
            }
        }
    }
Example #14
0
 void OnBeHit(DamageBase damage)
 {
     m_attacker = damage.Attacker.Player;
     AttackerLoginTime.Start();
 }
Example #15
0
 public DamageEvent(GameObject sender, DamageBase damage) : base(sender, true)
 {
     Damage = damage;
 }
Example #16
0
 public DeathEvent(GameObject sender, DamageBase lastDamage) : base(sender, true)
 {
     LastDamage = lastDamage;
 }
Example #17
0
 protected virtual void OnDeath(DamageBase lastDamage)
 {
     Destroy(gameObject);
 }
 void OnAttack(DamageBase damage)
 {
     VertigoEffectEnableTime.Start();
 }
 protected override void OnDeath(DamageBase lastDamage)
 {
     GetComponent <Health>().enabled     = false;
     GetComponent <Collider2D>().enabled = false;
 }
    void OnLockOption(DamageBase player)
    {
        Delay delay = new Delay(DelayTime);

        Player.BuffManager.AddBuff(delay);
    }