Esempio n. 1
0
 public override void Run(ExplosionModule module, Grenade grenade)
 {
     for (int i = 0; i < this.count; i++)
     {
         PoolSpawner.SpawnProjectile(grenade.transform.position, UnityEngine.Random.rotation, this.projectile, grenade.name, null);
     }
 }
Esempio n. 2
0
 public override void Run(ExplosionModule module, Grenade grenade)
 {
     source.transform.parent      = null;
     source.transform.position    = grenade.transform.position;
     source.outputAudioMixerGroup = BoneworksModdingToolkit.Audio.sfxMixer;
     source.Play();
 }
Esempio n. 3
0
            public override void Run(ExplosionModule module, Grenade grenade)
            {
                List <Rigidbody> bodies = new List <Rigidbody>();

                foreach (var col in Physics.OverlapSphere(grenade.transform.position, this.radius))
                {
                    if (col.attachedRigidbody != null && !col.attachedRigidbody.isKinematic && !bodies.Contains(col.attachedRigidbody))
                    {
                        bodies.Add(col.attachedRigidbody);
                    }
                }

                if (duration > 0f)
                {
                    coro = RunCoro(grenade, bodies);
                    MelonLoader.MelonCoroutines.Start(coro);
                }
                else
                {
                    foreach (var body in bodies)
                    {
                        body?.AddExplosionForce(this.force, grenade.transform.position, this.radius, 1f, ForceMode.Impulse);
                    }
                }
            }
Esempio n. 4
0
 public override void Reset(ExplosionModule module, Grenade grenade)
 {
     if (coro != null)
     {
         MelonLoader.MelonCoroutines.Stop(coro);
         coro = null;
     }
 }
Esempio n. 5
0
            public override void Reset(ExplosionModule module, Grenade grenade)
            {
                if (this.coro != null)
                {
                    MelonLoader.MelonCoroutines.Stop(this.coro);
                    this.coro = null;
                }

                if (this.transform != null)
                {
                    this.transform.localPosition = this.originalPos;
                    this.transform.localRotation = this.originalRot;
                    this.transform.localScale    = this.originalScale;
                }
            }
Esempio n. 6
0
            private IEnumerator RunCoro(Grenade grenade, List <Rigidbody> bodies)
            {
                float timer = 0f;

                while (timer < this.duration)
                {
                    foreach (var body in bodies)
                    {
                        body.AddExplosionForce(this.force, grenade.transform.position, this.radius, 1f, ForceMode.Acceleration);
                    }
                    yield return(null);

                    timer += Time.deltaTime;
                }
            }
Esempio n. 7
0
            private IEnumerator RunCoro(ExplosionModule module, Grenade grenade)
            {
                float timer = 0f;

                while (timer < this.duration)
                {
                    timer += Time.deltaTime;

                    float t = timer / this.duration;
                    this.transform.localPosition = Vector3.Lerp(this.startPos, this.position, t);
                    this.transform.localRotation = Quaternion.Lerp(this.startRot, this.rotation, t);
                    this.transform.localScale    = Vector3.Lerp(this.startScale, this.scale, t);

                    yield return(null);
                }
            }
Esempio n. 8
0
        public void Init(XElement xml, Grenade parent)
        {
            this.grenade = parent;

            ExplosionAction Process(XElement el)
            {
                switch (el.Name.LocalName)
                {
                case "Effect":
                    return(new Effect(el, this));

                case "Force":
                    return(new Force(el, this));

                case "Shrapnel":
                    return(new Shrapnel(el, this));

                case "Audio":
                    return(new Audio(el, this));

                case "Despawn":
                    return(new Despawn(el, this));

                case "Transform":
                    return(new Transformation(el, this));
                }

                if (CustomActions.ContainsKey(el.Name.LocalName))
                {
                    return(CustomActions[el.Name.LocalName](el, this));
                }

                MelonLoader.MelonLogger.LogWarning("Unknown explosion effect: " + el.Name.LocalName);
                return(null);
            }

            foreach (var el in xml.Elements())
            {
                var res = Process(el);
                if (res != null)
                {
                    this.actions.Add(res);
                }
            }
        }
Esempio n. 9
0
        public void Init(XElement xml, Grenade grenade)
        {
            this.grenade = grenade;

            this.open        = (float?)xml.Attribute("open") ?? 30f;
            this.released    = (float?)xml.Attribute("released") ?? 150f;
            this.threshold   = (float?)xml.Attribute("threshold") ?? 27f;
            this.rotateSpeed = (float?)xml.Attribute("degreesPerSecond") ?? 100f;
            this.grip        = grenade.transform.Find((string)xml.Attribute("grip") ?? "HandleGrip")?.GetComponent <Grip>();
            var fingers = (string)xml.Attribute("fingers");

            this.audio = grenade.transform.Find((string)xml.Attribute("audio") ?? "HandleSound")?.GetComponent <AudioSource>();
            if (fingers != null)
            {
                var strings = fingers.Split(',');
                this.fingers = new float[strings.Length];
                for (int i = 0; i < strings.Length; i++)
                {
                    if (!float.TryParse(strings[i], out this.fingers[i]))
                    {
                        this.fingers[i] = 0f;
                    }
                }
            }

            if (xml.Attribute("axis") != null) // legacy handling
            {
                var legacy = new RotateHandle();
                legacy.Init(xml, this);
                elements.Add(legacy);
            }

            foreach (var el in xml.Elements())
            {
                if (Elements.TryGetValue(el.Name.LocalName, out var factory))
                {
                    var x = factory();
                    x.Init(el, this);
                    this.elements.Add(x);
                }
            }
        }
Esempio n. 10
0
            public override void Run(ExplosionModule module, Grenade grenade)
            {
                if (this.transform == null)
                {
                    return;
                }

                if (this.duration > 0f)
                {
                    this.startPos   = this.transform.localPosition;
                    this.startRot   = this.transform.localRotation;
                    this.startScale = this.transform.localScale;
                    this.coro       = this.RunCoro(module, grenade);
                    MelonLoader.MelonCoroutines.Start(this.coro);
                }
                else
                {
                    this.transform.localPosition = this.position;
                    this.transform.localRotation = this.rotation;
                    this.transform.localScale    = this.scale;
                }
            }
Esempio n. 11
0
        /// <summary>
        /// Gets the XML element for grenade.
        /// </summary>
        /// <param name="g">The grenade.</param>
        /// <returns>The grenade definition xml.</returns>
        public XElement GetXMLForGrenade(Grenade g)
        {
            var nm = g.gameObject.name;

            if (nm.StartsWith(guidPrefix))
            {
                string s = nm.Substring(guidPrefix.Length);
                int    x;
                if ((x = s.IndexOf(' ')) != -1)
                {
                    s = s.Substring(0, x);
                }

                if (Guid.TryParse(s, out Guid guid))
                {
                    if (definitions.ContainsKey(guid))
                    {
                        return(definitions[guid]);
                    }
                }
            }

            return(null);
        }
Esempio n. 12
0
 public override void Run(ExplosionModule module, Grenade grenade)
 {
     grenade.gameObject.SetActive(false);
 }
Esempio n. 13
0
 public override void Run(ExplosionModule module, Grenade grenade)
 {
     PoolSpawner.SpawnBlaster(this.type, grenade.transform.position, Quaternion.identity, Vector3.one * this.scale);
 }
Esempio n. 14
0
 public virtual void Reset(ExplosionModule module, Grenade grenade)
 {
 }
Esempio n. 15
0
 public abstract void Run(ExplosionModule module, Grenade grenade);