Esempio n. 1
0
        private static void Postfix(Telekinesis __instance)
        {
            var caster = __instance.interactor.bodyHand.caster;

            if (__instance.catchedHandle && caster.currentSpell && caster.currentSpell is SpellLightning)
            {
                float manaCost = Electrical.ItemChargeSettings.manaPerSec * Time.deltaTime;
                if (caster.caster.currentMana > manaCost)
                {
                    caster.caster.currentMana -= manaCost;
                    var existingBolts = __instance.catchedHandle.GetComponents <LightningBolt>();
                    if (existingBolts.Length < 4)
                    {
                        var toHand = __instance.catchedHandle.transform.position - caster.bodyHand.transform.position;
                        if (toHand.sqrMagnitude < 3f)
                        {
                            LightningBolt.QueueLightningBolt(__instance.catchedHandle.gameObject, caster.currentSpell as SpellLightning, Random.Range(0.1f, 0.4f));
                            if (__instance.catchedHandle.item)
                            {
                                ChargeGrabbedPatch.ChargeItem(__instance.catchedHandle.item);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        internal static void Postfix(RagdollHandle __instance, Interactor interactor)
        {
            var caster = interactor.bodyHand.caster;

            if (caster.currentSpell &&
                caster.currentSpell is SpellLightning &&
                PlayerControl.GetHand(interactor.bodyHand.side).indexCurl > 0.5f)
            {
                float manaCost = Electrical.RagdollChargeSettings.launchManaCost;
                if (caster.caster.currentMana > manaCost)
                {
                    caster.caster.currentMana -= manaCost;

                    // Do a final burst of spell damage
                    var          spell       = interactor.bodyHand.caster.currentSpell as SpellLightning;
                    var          ragdoll     = __instance.ragdollPart.ragdoll;
                    DamageStruct shockDamage = spell.damageStruct;
                    shockDamage.damage           = Electrical.RagdollChargeSettings.damagePerSec;
                    shockDamage.hitRagdollPart   = __instance.ragdollPart;
                    shockDamage.knockOutDuration = 2f;
                    CollisionStruct spellCollision = new CollisionStruct(shockDamage);
                    ragdoll.creature.health.Damage(ref spellCollision);

                    // Aim the ragdoll launch
                    Vector3 dir = (__instance.transform.position - interactor.bodyHand.body.creature.transform.position);
                    dir.Set(dir.x, 0.0f, dir.z);
                    dir.Normalize();
                    dir.Set(dir.x, 0.7f, dir.z);

                    // Apply the force to each part with a chance of a visual lightning bolt
                    spell.PlayClipAt(spell.startLowClip, spell.transform.position);
                    foreach (RagdollPart ragdollPart in __instance.ragdollPart.ragdoll.creature.ragdoll.parts)
                    {
                        Vector3 force = dir * 30f;
                        ragdollPart.rb.AddForce(force, ForceMode.Impulse);
                        if (Random.Range(0, 3) == 0)
                        {
                            LightningBolt.QueueLightningBolt(ragdollPart.gameObject, spell, Random.Range(0.1f, 0.5f));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private static bool Prefix(Creature __instance, ref CollisionStruct collisionStruct)
        {
            var damageStruct = collisionStruct.damageStruct;

            if (damageStruct.damager && damageStruct.damager.data.id == "Punch")
            {
                var punch = damageStruct.damager.item;
                var spell = punch.mainHandler.bodyHand.caster.currentSpell;
                if (spell is SpellLightning)
                {
                    // Convert damage to shock, add a bit of bonus damage
                    damageStruct.damageType       = Damager.DamageType.Shock;
                    damageStruct.damage          += 5f;
                    damageStruct.knockOutDuration = 2f;

                    // Apply bonus knockback
                    var direction = punch.rb.velocity.normalized;
                    direction *= 20f;
                    foreach (RagdollPart ragdollPart in __instance.ragdoll.parts)
                    {
                        ragdollPart.rb.AddForce(direction, ForceMode.Impulse);
                    }

                    // Trigger some lightning bolts
                    var lightningSpell = spell as SpellLightning;
                    lightningSpell.PlayClipAt(lightningSpell.startLowClip, spell.transform.position);
                    int bolts = Random.Range(5, 8);
                    for (int i = 0; i < bolts; ++i)
                    {
                        float delay = Random.Range(0.1f, 0.5f);
                        LightningBolt.QueueLightningBolt(damageStruct.hitRagdollPart.gameObject, lightningSpell, delay);
                    }
                }
            }
            return(true);
        }