Esempio n. 1
0
    public override void Init(Vector3 dir, float speed, ProjectileProperties projectile_properties, List <StatusEffect> Status, GameObjectList Targetable, float timer = 5, float damage = 1, float multiplyer = 1, float percentage = 0)
    {
        _Dir                  = dir;
        _speed                = speed;
        _timer                = timer * multiplyer;
        _damage               = damage;
        _multiplyer           = multiplyer;
        _percentage           = percentage;
        _ProjectileProperties = projectile_properties;
        _PlayedCastingAudio   = _PlayedEndingAudio = false;

        if (projectile_properties.GetMovingParticle() != null)
        {
            _MovingParticleCopy = Instantiate(projectile_properties.GetMovingParticle(), gameObject.transform);
        }

        if (projectile_properties.GetImpactParticle() != null)
        {
            ParticleInterface temp = projectile_properties.GetImpactParticle().GetComponent <ParticleInterface>();
            temp.Init();
            _impact_particle_timer = temp.GetLongestParticleEffect();
        }

        if (_Targetable.Count > 0)
        {
            _Targetable.Clear();
        }
        _Targetable.AddRange(Targetable.GetList());

        if (_StatusEffects.Count > 0)
        {
            _StatusEffects.Clear();
        }

        if (Status.Count > 0)
        {
            _StatusEffects.AddRange(Status);
        }
    }
Esempio n. 2
0
    protected virtual void Dead()
    {
        gameObject.SetActive(false);

        if (_PlayedCastingAudio)
        {
            if (_ProjectileProperties.IsCastingLoop())
            {
                AudioManager.Instance.StopSE(_ProjectileProperties.GetCastingAudio().name);
                _PlayedCastingAudio = false;
            }
        }

        if (!_PlayedEndingAudio)
        {
            if (_ProjectileProperties.GetEndingAudio() != null)
            {
                _PlayedEndingAudio = true;
                AudioManager.Instance.PlaySE(_ProjectileProperties.GetEndingAudio().name, _ProjectileProperties.IsEndingLoop());
            }
        }

        if (_ProjectileProperties.ShakeOnImpact())
        {
            for (int i = 0; i < _multiplyer; ++i)
            {
                _ProjectileProperties.GetEvent().InvokeAllListeners();
            }
        }

        if (_MovingParticleCopy != null)
        {
            Destroy(_MovingParticleCopy);
            _MovingParticleCopy = null;
        }

        if (_ProjectileProperties.GetImpactParticle() != null)
        {
            GameObject temp = Instantiate(_ProjectileProperties.GetImpactParticle(), gameObject.transform.position, gameObject.transform.rotation);
            temp.transform.localScale = gameObject.transform.localScale;
            Destroy(temp, _impact_particle_timer);
        }

        if (_damage > 0)
        {
            foreach (GameObject obj in _Targetable)
            {
                if (ObjectManager.Instance.GetActiveObjects(obj) != null)
                {
                    foreach (GameObject entity in ObjectManager.Instance.GetActiveObjects(obj))
                    {
                        if (Vector3.Distance(gameObject.transform.position, entity.transform.position) < _ProjectileProperties.GetImpactRadius() * _multiplyer)
                        {
                            IDamageable dmg = entity.GetComponent <IDamageable>();

                            if (dmg != null)
                            {
                                dmg.TakeDamage(_damage * _multiplyer);

                                Debug.Log("[Damaging (" + _damage * _multiplyer + ")] " + obj.name);

                                if (_StatusEffects.Count > 0)
                                {
                                    if (Random.Range(0, 100) < _percentage * _multiplyer)
                                    {
                                        foreach (StatusEffect se in _StatusEffects)
                                        {
                                            Debug.Log("[Applying (" + se.name + ")] " + obj.name);
                                            se.GetEvent().InvokeSpecificListner(obj.GetInstanceID());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        //SPAWNING
        if (_ProjectileProperties.GetObjectsToSpawn() != null)
        {
            foreach (GameObject obj in _ProjectileProperties.GetObjectsToSpawn().GetList())
            {
                for (int i = 0; i < _ProjectileProperties.GetIteration(); ++i)
                {
                    GameObject temp_obj = ObjectManager.Instance.InstantiateWithObjectPooling(obj, gameObject.transform.position);

                    if (temp_obj.GetComponent <AreaEffect>() != null)
                    {
                        temp_obj.GetComponent <AreaEffect>().Init(_ProjectileProperties.GetProperties());
                    }
                    else if (temp_obj.tag.Equals("Slime"))
                    {
                        Stats     temp           = EnumHolder.Instance.GetStats(obj.name);
                        SlimeBase temp_component = temp_obj.GetComponent <SlimeBase>();

                        if (temp_component != null)
                        {
                            Destroy(temp_component);
                        }

                        int type = Random.Range(0, _ProjectileProperties.GetProperties().GetElement().GetList().Count - 1);

                        System.Type _MyScriptType = System.Type.GetType(((ElementType)_ProjectileProperties.GetProperties().GetElement().GetList()[type]).GetSlimeScriptName());
                        SlimeBase   temp_script   = temp_obj.AddComponent(_MyScriptType) as SlimeBase;

                        temp_script.Init(temp, ((((ElementType)_ProjectileProperties.GetProperties().GetElement().GetList()[type]).name.Equals("Lightning")) ? 2 : 1), ((ElementType)_ProjectileProperties.GetProperties().GetElement().GetList()[type]), _ProjectileProperties.GetTier());
                    }

                    if (_ProjectileProperties._HasRandomMotion)
                    {
                        Rigidbody temp_rb = temp_obj.GetComponent <Rigidbody>();

                        if (temp_rb != null)
                        {
                            float force = 3500;
                            temp_rb.AddForce(new Vector3(Random.Range(-force, force), 0, Random.Range(-force, force)), ForceMode.Acceleration);
                        }
                    }
                }
            }
        }
    }