Exemple #1
0
        private void DetonateExplosion(ExplosionSpec spec, Vector3 origin)
        {
            double adjustedRadius = spec.Radius * spec.Density;

            int numExplosions = (int)Math.Ceiling(2.0 / 3.0 * Math.Pow(adjustedRadius, 3) * Math.PI);

            float speed        = Math.Max(spec.Speed, 0.1f);
            float stepDuration = spec.Radius / speed / numExplosions;
            float stepDistance = spec.Radius / numExplosions;

            float rocketTravelTime = 0.3f;

            for (int i = 0; i < numExplosions; i++)
            {
                var stepStartTime     = stepDuration * i;
                var stepEndTime       = stepDuration * (i + 1);
                var stepStartDistance = stepDistance * i;
                var stepEndDistance   = stepDistance * (i + 1);

                timer.Once(Core.Random.Range(stepStartTime, stepEndTime), () =>
                {
                    var rocketDistance = Core.Random.Range(stepStartDistance, stepEndDistance);
                    var rocketSpeed    = rocketDistance / rocketTravelTime;

                    var rocketVector = MakeRandomDomeVector();
                    var skipDistance = rocketVector.normalized * 1f;

                    rocketVector *= rocketSpeed;
                    FireRocket(PrefabExplosiveRocket, origin + skipDistance, rocketVector, rocketTravelTime, spec.BlastRadiusMult, spec.DamageMult);
                });
            }
        }
Exemple #2
0
    private bool GetExplosionCollision(ExplosionSpec spec, GameObject player, Vector3 position)
    {
        var playerPosition    = new Vector2(player.transform.position.x, player.transform.position.y);
        var explosionPosition = new Vector2(position.x, position.y);
        var distance          = Vector2.Distance(playerPosition, explosionPosition);

        if (distance <= spec._range)
        {
            return(true);
        }

        return(false);
    }
Exemple #3
0
    public void Init(ExplosionType explosionType, GameObject player, GameObject enemy, int damageRatio)
    {
        #region SPEC LOAD

        if (_explosionTypeToSpecPath.ContainsKey(explosionType) == false)
        {
            Debug.LogAssertionFormat("Invalid Dictionay Data Path - {0]", explosionType);
            return;
        }

        var path = _explosionTypeToSpecPath[explosionType];
        var text = Resources.Load <TextAsset>(path).text;
        _spec = ExplosionSpec.CreateFromText(text);

        #endregion

        #region MAKE EFFECT

        _explosion = Instantiate(Resources.Load(_spec._prefabPath)) as GameObject;
        _explosion.transform.position = this.transform.position;
        _explosion.transform.SetParent(this.transform);

        #endregion

        #region COLLISION DETECT

        var damage = (int)(_spec._minDamage + (_spec._maxDamage - _spec._minDamage) * damageRatio / 100);

        if (GetExplosionCollision(_spec, player, this.transform.position))
        {
            player.GetComponent <Player>().Damaged(damage);
        }

        if (GetExplosionCollision(_spec, enemy, this.transform.position))
        {
            enemy.GetComponent <Player>().Damaged(damage);
        }

        #endregion

        #region DELETE SELF

        Destroy(this.gameObject, 3f);

        #endregion
    }
        private IEnumerator ExplosionCoroutine(ExplosionSpec spec, Vector3 origin)
        {
            float  rocketTravelTime = 0.3f;
            double totalTime        = spec.Radius / spec.Speed;
            int    numExplosions    = (int)Math.Ceiling(spec.DensityCoefficient * Math.Pow(spec.Radius, spec.DensityExponent));

            float  timeElapsed  = 0;
            double prevDistance = 0;

            FireRocket(PrefabExplosiveRocket, origin, Vector3.forward, 0, spec.BlastRadiusMult, spec.DamageMult);

            for (var i = 1; i <= numExplosions; i++)
            {
                if (_pluginUnloaded)
                {
                    yield break;
                }

                double timeFraction = timeElapsed / totalTime;
                double stepDistance = spec.Radius * timeFraction;

                double stepStartDistance = prevDistance;
                double stepEndDistance   = stepDistance;

                double rocketDistance = Core.Random.Range(stepStartDistance, stepEndDistance);
                double rocketSpeed    = rocketDistance / rocketTravelTime;

                Vector3 rocketVector = MakeRandomDomeVector();

                // Skip over some space to reduce the frequency of rockets colliding with each other.
                Vector3 skipDistance = rocketVector;

                rocketVector *= Convert.ToSingle(rocketSpeed);
                FireRocket(PrefabExplosiveRocket, origin + skipDistance, rocketVector + skipDistance, rocketTravelTime, spec.BlastRadiusMult, spec.DamageMult);

                float timeToNext = Convert.ToSingle(Math.Pow(i / spec.DensityCoefficient, 1.0 / spec.DensityExponent) / spec.Speed - timeElapsed);

                yield return(new WaitForSeconds(timeToNext));

                prevDistance = stepDistance;
                timeElapsed += timeToNext;
            }
        }
 private void DetonateExplosion(ExplosionSpec spec, Vector3 origin) =>
 ServerMgr.Instance.StartCoroutine(ExplosionCoroutine(spec, origin));