void DamageTarget()
 {
     if (damagingTarget != null)
     {
         damagingTarget.TakeDamage(25f, clawObject.transform.position, DamageType.Normal, gameObject);
     }
 }
Ejemplo n.º 2
0
        public void ProcessRemoteHealthChange(NitroxId id, float LifeChanged, Optional <DamageTakenData> opDamageTakenData, float totalHealth)
        {
            if (simulationOwnership.HasAnyLockType(id))
            {
                Log.Error($"Got LiveMixin change health for {id} but we have the simulation already. This should not happen!");
                return;
            }
            LiveMixin liveMixin = NitroxEntity.RequireObjectFrom(id).GetComponent <LiveMixin>();

            // For remote processing, we add an outstanding health change that makes it possible to pass execution
            outstandingChangeHealth.Add(id, new Tuple <float, float>(LifeChanged, liveMixin.health));
            if (LifeChanged < 0)
            {
                DamageTakenData       damageTakenData = opDamageTakenData.OrElse(null);
                Optional <GameObject> opDealer        = damageTakenData.DealerId.HasValue ? NitroxEntity.GetObjectFrom(damageTakenData.DealerId.Value) : Optional.Empty;
                GameObject            dealer          = opDealer.HasValue ? opDealer.Value : null;
                if (!dealer && damageTakenData.DealerId.HasValue)
                {
                    Log.Warn($"Could not find entity {damageTakenData.DealerId.Value} for damage calculation. This could lead to problems.");
                }
                liveMixin.TakeDamage(-LifeChanged, damageTakenData.Position.ToUnity(), (DamageType)damageTakenData.DamageType, dealer);
            }
            else
            {
                liveMixin.AddHealth(LifeChanged);
            }

            // Check if the health calculated by the game is the same as the calculated damage from the simulator
            if (liveMixin.health != totalHealth)
            {
                Log.Warn($"Calculated health and send health for {id} do not align (Calculated: {liveMixin.health}, send:{totalHealth}). This will be correted but should be investigated");
                liveMixin.health = totalHealth;
            }
        }
        private void AddDamage(GameObject gameObject)
        {
            Vector3 position = gameObject.transform.position;

            if (gameObject != null)
            {
                LiveMixin liveMixin = gameObject.GetComponent <LiveMixin>();
                if (!liveMixin)
                {
                    liveMixin = Utils.FindEnabledAncestorWithComponent <LiveMixin>(gameObject);
                }
                if (liveMixin)
                {
                    if (liveMixin.IsAlive())
                    {
                        liveMixin.TakeDamage(laserDamage, position, DamageType.Explosive, null);
                        WorldForces.AddExplosion(position, DayNightCycle.main.timePassed, 5f, 4f);
                    }
                }
                else
                {
                    if (gameObject.GetComponent <BreakableResource>() != null)
                    {
                        gameObject.SendMessage("BreakIntoResources", null, SendMessageOptions.DontRequireReceiver);
                        WorldForces.AddExplosion(position, DayNightCycle.main.timePassed, 5f, 4f);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void AddDamageToTarget(GameObject gameObject)
        {
            Vector3 position = gameObject.transform.position;

            if (gameObject != null)
            {
                LiveMixin liveMixin = gameObject.GetComponent <LiveMixin>();
                if (!liveMixin)
                {
                    liveMixin = Utils.FindEnabledAncestorWithComponent <LiveMixin>(gameObject);
                }
                if (liveMixin)
                {
                    if (liveMixin.IsAlive())
                    {
                        liveMixin.TakeDamage(laserDamage, position, DamageType.Normal, null);
                    }
                }
                else
                {
                    if (gameObject.GetComponent <BreakableResource>() != null)
                    {
                        gameObject.SendMessage("BreakIntoResources", null, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // Returns true if discharge occurred, false otherwise
        internal bool Discharge(GameObject attacker)
        {
            if (this.charge < 1)
            {
                Log.LogDebug($"DiverPerimeterDefenceBehaviour.Discharge(): chip TechType {techType.AsString()} battery is dead");
                return(false);
            }

            LiveMixin mixin = attacker.GetComponent <LiveMixin>();

            if (mixin == null)
            {
                Log.LogDebug($"DiverPerimeterDefenceBehaviour.Discharge(): chip TechType {techType.AsString()} could not find LiveMixin component on attacker");
                return(false);
            }

            Log.LogDebug($"DiverPerimeterDefenceBehaviour.Discharge(): chip TechType {techType.AsString()} discharging");
            mixin.TakeDamage(DischargeDamage, gameObject.transform.position, DamageType.Electrical, gameObject);
            this.charge = Mathf.Max(this.charge - JuicePerDischarge, 0f);
            Log.LogDebug($"DiverPerimeterDefenceBehaviour.Discharge(): Discharged, available charge now {this.charge}");
            if (this.charge < 1f)
            {
                if (bDestroyWhenEmpty)
                {
                    Log.LogDebug($"DiverPerimeterDefenceBehaviour.Discharge(): bDestroyWhenEmpty = true, destroying chip");
                    CoroutineHost.StartCoroutine(AddBrokenChipAndDestroy());
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static bool Prefix(ref Knife __instance, GUIHand hand)
        {
            if (!Config.NONVIOLENT.Equals(DeathRun.config.nonViolent))
            {
                return(true);
            }

            Vector3    position   = default(Vector3);
            GameObject gameObject = null;

            UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, __instance.attackDist, ref gameObject, ref position, true);
            if (gameObject == null)
            {
                InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();
                if (component != null && component.GetMostRecent() != null)
                {
                    gameObject = component.GetMostRecent().gameObject;
                }
            }
            if (gameObject)
            {
                LiveMixin liveMixin = gameObject.FindAncestor <LiveMixin>();
                if (Knife.IsValidTarget(liveMixin))
                {
                    if (liveMixin)
                    {
                        bool     wasAlive = liveMixin.IsAlive();
                        TechType t        = CraftData.GetTechType(gameObject);
                        if ((t == TechType.GenericJeweledDisk) ||
                            (t == TechType.BlueJeweledDisk) ||
                            (t == TechType.GreenJeweledDisk) ||
                            (t == TechType.PurpleJeweledDisk) ||
                            (t == TechType.RedJeweledDisk))
                        {
                            liveMixin.TakeDamage(__instance.damage, position, __instance.damageType, null);
                        }
                        __instance.GiveResourceOnDamage(gameObject, liveMixin.IsAlive(), wasAlive);
                    }
                    global::Utils.PlayFMODAsset(__instance.attackSound, __instance.transform, 20f);
                    //VFXSurface component2 = gameObject.GetComponent<VFXSurface>();
                    //Vector3 euler = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0f);
                    //VFXSurfaceTypeManager.main.Play(component2, __instance.vfxEventType, position, Quaternion.Euler(euler), Player.main.transform);
                }
                else
                {
                    gameObject = null;
                }
            }
            if (gameObject == null && hand.GetActiveTarget() == null)
            {
                if (Player.main.IsUnderwater())
                {
                    global::Utils.PlayFMODAsset(__instance.underwaterMissSound, __instance.transform, 20f);
                    return(false);
                }
                global::Utils.PlayFMODAsset(__instance.surfaceMissSound, __instance.transform, 20f);
            }
            return(false);
        }
        public static bool InflictDamage(LiveMixin instance, float originalDamage, Vector3 position = default(Vector3), DamageType type = DamageType.Normal, GameObject dealer = null)
        {
            Log.LogDebug($"ExosuitClawArmPatches.InflictDamage running, instance {instance?.name}, originalDamage {originalDamage}, position ({position.ToString()}, type {type.ToString()}, dealer "
                         + (dealer == null ? "null" : dealer.name));
            bool result = instance.TakeDamage(originalDamage, position, type, dealer);

            if (type != DamageType.Electrical)
            {
                Exosuit exosuit = Player.main.GetVehicle() as Exosuit;
                if (exosuit?.modules != null &&              // This shouldn't fail, but this is here for paranoia's sake
                    exosuit.modules.GetCount(LightningGeneratorTechType) > 0)
                {
                    result |= instance.TakeDamage(originalDamage * damageMultiplier, position, DamageType.Electrical, dealer);
                }
            }
            return(result);
        }
        new public void OnHit()
        {
            Exosuit componentInParent = base.GetComponentInParent <Exosuit>();

            if (componentInParent.CanPilot() && componentInParent.GetPilotingMode())
            {
                Vector3    position   = default;
                GameObject gameObject = null;
                Vector3    vector;
                UWE.Utils.TraceFPSTargetPosition(componentInParent.gameObject, 6.5f, ref gameObject, ref position, out vector, true);
                if (gameObject == null)
                {
                    InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();
                    if (component != null && component.GetMostRecent() != null)
                    {
                        gameObject = component.GetMostRecent().gameObject;
                    }
                }
                if (gameObject)
                {
                    LiveMixin liveMixin = gameObject.FindAncestor <LiveMixin>();
                    if (liveMixin)
                    {
                        liveMixin.IsAlive();
                        liveMixin.TakeDamage(50f, position, DamageType.Normal, null);
                        // Originally the change was from Normal to Electrical, but there should be a Normal component and an Electrical.
                        // Without a Normal component to the damage, Eye Jellies (to use one example) give no f***s about being twatted in the eye with a Lightning Claw.
                        // That's not right; even if the electrical damage does nothing for them, it's a chunk of heavy metal being propelled at high speed by precision hydraulics.
                        Log.LogDebug($"ExosuitLightningClaw: inflicting Electrical damage on target {gameObject.ToString()}");
                        liveMixin.TakeDamage(30f, position, DamageType.Electrical, null);                         // Animals treat this as over 1000 damage when deciding whether to flee or not.
                        // Curiously, Snow Stalkers appear to give no f***s about any sort of damage, and will continue pursuing until you either get beyond their
                        // "bollocks to this" range, or until they are dead.
                        global::Utils.PlayFMODAsset(base.hitFishSound, this.front, 50f);
                    }
                    else
                    {
                        global::Utils.PlayFMODAsset(base.hitTerrainSound, this.front, 50f);
                    }
                    VFXSurface component2 = gameObject.GetComponent <VFXSurface>();
                    Vector3    euler      = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0f);
                    VFXSurfaceTypeManager.main.Play(component2, base.vfxEventType, position, Quaternion.Euler(euler), componentInParent.gameObject.transform);
                    gameObject.SendMessage("BashHit", this, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
Ejemplo n.º 9
0
        public override void OnToolUseAnim(GUIHand guiHand)
        {
            Vector3    position      = default(Vector3);
            GameObject closestObject = null;

            UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, attackDist, ref closestObject, ref position, true);

            if (closestObject == null)
            {
                InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();

                if (component != null && component.GetMostRecent() != null)
                {
                    closestObject = component.GetMostRecent().gameObject;
                }
            }

            if (closestObject)
            {
                LiveMixin mixin = closestObject.FindAncestor <LiveMixin>();

                if (IsTarget(mixin))
                {
                    if (mixin)
                    {
                        bool alive = mixin.IsAlive();
                        mixin.TakeDamage(damage, position, damageType, null);
                        GiveResource(closestObject, mixin.IsAlive(), alive);
                    }

                    //Utils.PlayFMODAsset(swingSound, transform, 20f);
                    VFXSurface component2 = closestObject.GetComponent <VFXSurface>();
                    Vector3    euler      = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0f);
                    VFXSurfaceTypeManager.main.Play(component2, vfxEventType, position, Quaternion.Euler(euler), Player.main.transform);
                }

                else
                {
                    closestObject = null;
                }
            }

            if (closestObject == null && guiHand.GetActiveTarget() == null)
            {
                if (Player.main.IsUnderwater())
                {
                    //Utils.PlayFMODAsset(missSoundWater, transform, 20f);
                }
                else
                {
                    //Utils.PlayFMODAsset(missSoundNoWater, transform, 20f);
                }
            }
        }
Ejemplo n.º 10
0
        /**
         * DecoDamage - this actually applies the decompression damage from getting the bends. Includes "anti-one-shotting" protection. Also
         * resets the "safe depth" higher after each shot of damage.
         */
        private static void DecoDamage(ref NitrogenLevel __instance, float depthOf, int ticks)
        {
            LiveMixin component = Player.main.gameObject.GetComponent <LiveMixin>();

            float damageBase = (Config.DEATHRUN.Equals(DeathRun.config.nitrogenBends)) ? 20f : 10f;

            if ((DeathRun.saveData.nitroSave.safeDepth - depthOf) < 5)
            {
                damageBase /= 2;
            }

            if ((DeathRun.saveData.nitroSave.safeDepth - depthOf) < 2)
            {
                damageBase /= 2;
            }

            float damage = damageBase + UnityEngine.Random.value * damageBase + (DeathRun.saveData.nitroSave.safeDepth - depthOf);

            if (damage >= component.health)
            {
                if (component.health > 0.1f)
                {
                    damage = component.health - 0.05f;
                    if (damage <= 0)
                    {
                        return;
                    }
                }
            }

            if (component.health - damage > 0f)
            {
                if (!Config.NEVER.Equals(DeathRun.config.showWarnings))
                {
                    if ((DeathRun.saveData.nitroSave.reallyTookDamageTicks == 0) ||
                        Config.WHENEVER.Equals(DeathRun.config.showWarnings) ||
                        (Config.OCCASIONAL.Equals(DeathRun.config.showWarnings) && (ticks - DeathRun.saveData.nitroSave.reallyTookDamageTicks > 600)))
                    {
                        ErrorMessage.AddMessage("You have the bends from ascending too quickly!");
                        DeathRunUtils.CenterMessage("You have the bends!", 6);
                        DeathRunUtils.CenterMessage("Slow your ascent!", 6, 1);
                    }
                }
            }
            //else
            //{
            //    ErrorMessage.AddMessage("You died of the bends!");
            //    DeathRunUtils.CenterMessage("You died of the bends!", 5);
            //}

            DeathRun.setCause("The Bends");
            component.TakeDamage(damage, default, DamageType.Starve, null);
Ejemplo n.º 11
0
        public static bool Prefix(ref NitrogenLevel __instance)
        {
            if (__instance.nitrogenEnabled && GameModeUtils.RequiresOxygen() && Time.timeScale > 0f)
            {
                float depthOf = Ocean.main.GetDepthOf(Player.main.gameObject);

                if (depthOf < __instance.safeNitrogenDepth - 10f && UnityEngine.Random.value < 0.0125f)
                {
                    LiveMixin component = Player.main.gameObject.GetComponent <LiveMixin>();
                    float     damage    = 1f + damageScaler * (__instance.safeNitrogenDepth - depthOf) / 10f;
                    if (component.health - damage > 0f)
                    {
                        component.TakeDamage(damage, default, DamageType.Normal, null);
Ejemplo n.º 12
0
        public void OnCollisionEnter(Collision col)
        {
            LiveMixin mixin = UWE.Utils.GetComponentInHierarchy <LiveMixin>(col.gameObject);



            if (mixin)
            {
                mixin.TakeDamage(100f, transform.position, DamageType.LaserCutter);
                Destroy(GetComponent <SphereCollider>());
                Destroy(body);
                Destroy(gameObject, 0.2f);
            }
        }
Ejemplo n.º 13
0
        public static void CreateExplosiveForce() // Should only be called when Aurora explodes
        {
            float     depth     = Ocean.main.GetDepthOf(Player.main.gameObject);
            LiveMixin component = Player.main.gameObject.GetComponent <LiveMixin>();

            if (component == null)
            {
                return;
            }

            float damage;

            if (Config.EXPLOSION_DEATHRUN.Equals(DeathRun.config.explodeDepth))
            {
                damage = 500f;
            }
            else if (Config.EXPLOSION_HARD.Equals(DeathRun.config.explodeDepth))
            {
                damage = 300f;
            }
            else
            {
                return;
            }

            if (depth > 10)
            {
                if (depth > 100)
                {
                    damage = 0;
                }
                else
                {
                    damage /= (depth + 5) / 10;
                }

                if (!Player.main.IsSwimming() && (depth > 0))
                {
                    damage /= 2;
                }

                if (component.TakeDamage(damage, default, DamageType.Explosive, null))
                {
                    ErrorMessage.AddMessage("You were killed by the shockwave from the Aurora's explosion.");
                }
                else
                {
                    ErrorMessage.AddMessage("You have been injured by the shockwave from the Aurora's explosion.");
                }
            }
        public void OnHit()
        {
            if (TruckHelper.IsPiloted())
            {
                Vector3    position     = default(Vector3);
                GameObject targetObject = null;

                UWE.Utils.TraceFPSTargetPosition(TruckHelper.MainCab, 6.5f, ref targetObject, ref position, out Vector3 normal, true);

                if (targetObject == null)
                {
                    InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();

                    if (component != null && component.GetMostRecent() != null)
                    {
                        targetObject = component.GetMostRecent().gameObject;
                    }
                }
                if (targetObject)
                {
                    LiveMixin liveMixin = targetObject.FindAncestor <LiveMixin>();

                    if (liveMixin)
                    {
                        bool flag = liveMixin.IsAlive();
                        liveMixin.TakeDamage(50f, position, DamageType.Normal, null);
                        Utils.PlayFMODAsset(hitFishSound, front, 50f);
                    }
                    else
                    {
                        Utils.PlayFMODAsset(hitTerrainSound, front, 50f);
                    }

                    VFXSurface component2 = targetObject.GetComponent <VFXSurface>();

                    Vector3 euler = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0f);

                    VFXSurfaceTypeManager.main.Play(component2, vfxEventType, position, Quaternion.Euler(euler), TruckHelper.MainCab.transform);

                    targetObject.SendMessage("BashHit", this, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
Ejemplo n.º 15
0
        void Drill(SeaMoth moth)
        {
            var pos    = Vector3.zero;
            var hitObj = default(GameObject);

            // Get the GameObject we're looking at
            UWE.Utils.TraceFPSTargetPosition(moth.gameObject, 6f, ref hitObj, ref pos, true);

            // Check if not null
            if (hitObj)
            {
                // Find the BetterDrillable component and play sounds.
                var drillable = hitObj.FindAncestor <BetterDrillable>();
                Main.DrillLoopHit.Play();

                // If we found the drillable
                if (drillable)
                {
                    // Send the "drill" message to the Drillable
                    drillable.OnDrill(transform.position, moth, out GameObject hitMesh);
                }
                else // Otherwise if we did not hit a drillable object
                {
                    // Get the LiveMixin component in the found GameObject
                    LiveMixin liveMixin = hitObj.FindAncestor <LiveMixin>();
                    if (liveMixin) // If not null
                    {
                        // Make it take a bit of damage
                        liveMixin.TakeDamage(4f, pos, DamageType.Drill, null);
                    }

                    // Also send a "hit" message.
                    hitObj.SendMessage("BashHit", this, SendMessageOptions.DontRequireReceiver);
                }
            }
            else // If its null
            {
                // Stop all sounds
                StopEffects();
            }
        }
Ejemplo n.º 16
0
        public void OnCollisionEnter(Collision col)
        {
            LiveMixin mixin = col.collider.GetComponent <LiveMixin>();

            if (mixin && mixin != Player.main.liveMixin)
            {
                mixin.TakeDamage(500f);
                transform.GetChild(0).parent = null;
                Destroy(gameObject);
                return;
            }
            BreakableResource res = col.collider.GetComponent <BreakableResource>();

            if (res)
            {
                res.BreakIntoResources();
                transform.GetChild(0).parent = null;
                Destroy(gameObject);
                return;
            }
        }
Ejemplo n.º 17
0
        void OnHit()
        {
            if (seamoth.CanPilot() && seamoth.GetPilotingMode())
            {
                Vector3    position   = default(Vector3);
                GameObject gameObject = null;
                UWE.Utils.TraceFPSTargetPosition(seamoth.gameObject, 6.5f, ref gameObject, ref position, true);
                if (gameObject == null)
                {
                    InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();
                    if (component != null && component.GetMostRecent() != null)
                    {
                        gameObject = component.GetMostRecent().gameObject;
                    }
                }
                if (gameObject)
                {
                    LiveMixin liveMixin = gameObject.FindAncestor <LiveMixin>();
                    if (liveMixin)
                    {
                        bool flag = liveMixin.IsAlive();
                        liveMixin.TakeDamage(50f, position, DamageType.Normal, null);
                        global::Utils.PlayFMODAsset(hitFishSound, this.front, 5f);
                    }
                    else
                    {
                        global::Utils.PlayFMODAsset(hitTerrainSound, this.front, 5f);
                    }
                    VFXSurface component2 = gameObject.GetComponent <VFXSurface>();
                    Vector3    euler      = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0f);
                    VFXSurfaceTypeManager.main.Play(component2, VFXEventTypes.impact, position, Quaternion.Euler(euler), seamoth.gameObject.transform);
                    gameObject.SendMessage("BashHit", this, SendMessageOptions.DontRequireReceiver);
                }
            }

            this.cooldownTime = Time.time + cooldownHit;
        }
Ejemplo n.º 18
0
        public override void OnToolUseAnim(GUIHand hand)
        {
            Vector3    position   = new Vector3();
            GameObject closestObj = null;

#if SUBNAUTICA_STABLE
            UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, this.attackDist, ref closestObj, ref position);
#elif BELOWZERO
            Vector3 normal = new Vector3();

            UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, this.attackDist, ref closestObj, ref position, out normal);
#endif
            if (closestObj == null)
            {
                InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();
                if (component != null && component.GetMostRecent() != null)
                {
                    closestObj = component.GetMostRecent().gameObject;
                }
            }



            if (closestObj != null)
            {
                LiveMixin ancestor = closestObj.FindAncestor <LiveMixin>();
                if (Knife.IsValidTarget(ancestor))
                {
                    if (ancestor != null)
                    {
                        bool  wasAlive   = ancestor.IsAlive();
                        float thisDamage = this.damage * (closestObj.GetComponent <Creature>() != null ? FaunaDamageMultiplier : 1f);
                        ancestor.TakeDamage(thisDamage, position, this.damageType);
                        this.GiveResourceOnDamage(closestObj, ancestor.IsAlive(), wasAlive);
                    }
#if SUBNAUTICA_STABLE
                    Utils.PlayFMODAsset(this.attackSound, this.transform);
                    VFXSurface component = closestObj.GetComponent <VFXSurface>();
                    Vector3    euler     = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0.0f);
                    VFXSurfaceTypeManager.main.Play(component, this.vfxEventType, position, Quaternion.Euler(euler), Player.main.transform);
                }
                else
                {
                    closestObj = (GameObject)null;
                }
#elif BELOWZERO
                }

                VFXSurface component = closestObj.GetComponent <VFXSurface>();
                Vector3 euler        = MainCameraControl.main.transform.eulerAngles + new Vector3(300f, 90f, 0.0f);
                VFXSurfaceTypeManager.main.Play(component, this.vfxEventType, position, Quaternion.Euler(euler), Player.main.transform);
                VFXSurfaceTypes vfxSurfaceTypes = Utils.GetObjectSurfaceType(closestObj);
                if (vfxSurfaceTypes == VFXSurfaceTypes.none)
                {
                    vfxSurfaceTypes = Utils.GetTerrainSurfaceType(position, normal, VFXSurfaceTypes.sand);
                }
                EventInstance fmodEvent = Utils.GetFMODEvent(this.hitSound, this.transform.position);
                int num1 = (int)fmodEvent.setParameterValueByIndex(this.surfaceParamIndex, (float)vfxSurfaceTypes);
                int num2 = (int)fmodEvent.start();
                int num3 = (int)fmodEvent.release();
#endif
            }
Ejemplo n.º 19
0
        void Shoot()
        {
            currentPosition = Vector3.Lerp(currentPosition, startPosition - Vector3.forward * 0.5f, 0.3f);

            Vector3 rot = startRotation.eulerAngles;

            rot.x -= 30f;
            Quaternion rotq = Quaternion.Euler(rot);

            currentRotation = Quaternion.Lerp(currentRotation, rotq, 0.3f);

            Transform aimTrans = Player.main.camRoot.GetAimingTransform();

            if (Targeting.GetTarget(Player.main.gameObject, 200f, out GameObject hit, out float dist))
            {
                Vector3 hitpoint = aimTrans.forward * dist + transform.position;

                GameObject   beam = Instantiate(beamPrefab);
                LineRenderer line = beam.GetComponent <LineRenderer>();
                beam.AddComponent <LineFade>();
                line.positionCount = 2;
                line.SetPosition(0, transform.GetChild(0).position);
                line.SetPosition(1, hitpoint);
                Destroy(beam, 0.3f);

                LiveMixin health = hit.GetComponent <LiveMixin>();
                if (health != null)
                {
                    health.TakeDamage(500f);
                }
                else
                {
                    health = hit.GetComponentInChildren <LiveMixin>();
                    if (health != null)
                    {
                        health.TakeDamage(500f);
                    }
                }

                BreakableResource res = hit.GetComponent <BreakableResource>();
                if (res != null)
                {
                    res.hitsToBreak = 1;
                    res.HitResource();
                }
                else
                {
                    res = hit.GetComponentInChildren <BreakableResource>();
                    if (res != null)
                    {
                        res.hitsToBreak = 1;
                        res.HitResource();
                    }
                }

                Rigidbody rb = hit.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rb.AddForce(aimTrans.forward.normalized * 20f, ForceMode.Impulse);
                }
                else
                {
                    rb = hit.GetComponentInChildren <Rigidbody>();
                    if (rb != null)
                    {
                        rb.AddForce(aimTrans.forward.normalized * 20f, ForceMode.Impulse);
                    }
                }
            }
        public virtual void OnTouch(Collider collider)
        {
            Debugger.Log("Attack 0");

            if (!base.enabled)
            {
                return;
            }

            if (this.frozen)
            {
                return;
            }

            if (this.creature.Aggression.Value < this.biteAggressionThreshold)
            {
                return;
            }

            if (Time.time < this.timeLastBite + this.biteInterval)
            {
                return;
            }

            GameObject target = this.GetTarget(collider);

            if (this.ignoreSameKind && global::Utils.CompareTechType(base.gameObject, target))
            {
                return;
            }

            Debugger.Log("Attack 1");

            if (this.CanBite(target))
            {
                Debugger.Log("Attack 2");

                this.timeLastBite = Time.time;

                LiveMixin component2 = target.GetComponent <LiveMixin>();

                if (component2 != null && component2.IsAlive())
                {
                    component2.TakeDamage(this.GetBiteDamage(target), default(Vector3), DamageType.Normal, null);
                    component2.NotifyCreatureDeathsOfCreatureAttack();
                }

                Vector3 position = collider.ClosestPointOnBounds(this.mouth.transform.position);

                if (this.damageFX != null)
                {
                    UnityEngine.Object.Instantiate <GameObject>(this.damageFX, position, this.damageFX.transform.rotation);
                }

                if (this.attackSound != null)
                {
                    global::Utils.PlayEnvSound(this.attackSound, position, 20f);
                }

                this.creature.Aggression.Add(-this.biteAggressionDecrement);

                if (component2 != null && !component2.IsAlive())
                {
                    this.TryEat(component2.gameObject, false);
                }

                base.gameObject.SendMessage("OnMeleeAttack", target, SendMessageOptions.DontRequireReceiver);
            }
        }
 public override void OnTouch(Collider collider)
 {
     if (frozen)
     {
         return;
     }
     if (liveMixin.IsAlive() && Time.time > timeLastBite + biteInterval)
     {
         Creature component = GetComponent <Creature>();
         if (component.Aggression.Value >= 0.1f)
         {
             GameObject target = GetTarget(collider);
             if (!playerDeathCinematic.IsCinematicModeActive())
             {
                 Player player = target.GetComponent <Player>();
                 if (player != null)
                 {
                     if (Time.time > timeCinematicAgain && player.CanBeAttacked() && player.liveMixin.IsAlive() && !player.cinematicModeActive)
                     {
                         float num = DamageSystem.CalculateDamage(biteDamage, DamageType.Normal, player.gameObject, null);
                         if (player.liveMixin.health - num <= 0f)
                         {
                             Invoke("KillPlayer", 2.5f);
                             playerDeathCinematic.StartCinematicMode(player);
                             attackSource.clip = cinematicClipPool.GetRandomClip();
                             attackSource.Play();
                             timeCinematicAgain = Time.time + 5f;
                             timeLastBite       = Time.time;
                             return;
                         }
                     }
                 }
                 LiveMixin liveMixin = target.GetComponent <LiveMixin>();
                 if (liveMixin == null)
                 {
                     return;
                 }
                 if (!liveMixin.IsAlive())
                 {
                     return;
                 }
                 if (liveMixin == Player.main.liveMixin)
                 {
                     if (!player.CanBeAttacked())
                     {
                         return;
                     }
                 }
                 if (!CanAttackTargetFromPosition(target))
                 {
                     return;
                 }
                 liveMixin.TakeDamage(GetBiteDamage(target));
                 attackSource.clip = biteClipPool.GetRandomClip();
                 attackSource.Play();
                 timeLastBite = Time.time;
                 creature.GetAnimator().SetTrigger("bite");
                 component.Aggression.Value -= 0.15f;
             }
         }
     }
 }
Ejemplo n.º 22
0
        public void OnHit()
        {
            if (Exosuit.CanPilot() && Exosuit.GetPilotingMode())
            {
                Vector3    pos       = Vector3.zero;
                GameObject hitObject = null;
                drillTarget = null;

                UWE.Utils.TraceFPSTargetPosition(Exosuit.gameObject, attackDist, ref hitObject, ref pos, true);

                if (hitObject == null)
                {
                    InteractionVolumeUser component = Player.main.gameObject.GetComponent <InteractionVolumeUser>();

                    if (component != null && component.GetMostRecent() != null)
                    {
                        hitObject = component.GetMostRecent().gameObject;
                    }
                }
                if (hitObject && drilling)
                {
                    var drillable = hitObject.FindAncestor <Drillable>();

                    loopHit.Play();

                    if (drillable)
                    {
                        drillable.OnDrill(fxSpawnPoint.position, Exosuit, out GameObject gameObject2);

                        if (!gameObject2)
                        {
                            StopEffects();
                        }

                        drillTarget = gameObject2;

                        if (fxControl.emitters[0].fxPS != null && !fxControl.emitters[0].fxPS.emission.enabled)
                        {
                            fxControl.Play(0);
                        }
                    }
                    else
                    {
                        LiveMixin liveMixin = hitObject.FindAncestor <LiveMixin>();

                        if (liveMixin)
                        {
                            bool flag = liveMixin.IsAlive();
                            liveMixin.TakeDamage(4f, pos, DamageType.Drill, null);
                            drillTarget = hitObject;
                        }

                        VFXSurface component2 = hitObject.GetComponent <VFXSurface>();

                        if (drillFXinstance == null)
                        {
                            drillFXinstance = VFXSurfaceTypeManager.main.Play(component2, vfxEventType, fxSpawnPoint.position, fxSpawnPoint.rotation, fxSpawnPoint);
                        }
                        else if (component2 != null && prevSurfaceType != component2.surfaceType)
                        {
                            VFXLateTimeParticles component3 = drillFXinstance.GetComponent <VFXLateTimeParticles>();
                            component3.Stop();
                            Destroy(drillFXinstance.gameObject, 1.6f);
                            drillFXinstance = VFXSurfaceTypeManager.main.Play(component2, vfxEventType, fxSpawnPoint.position, fxSpawnPoint.rotation, fxSpawnPoint);
                            prevSurfaceType = component2.surfaceType;
                        }

                        hitObject.SendMessage("BashHit", this, SendMessageOptions.DontRequireReceiver);
                    }
                }
                else
                {
                    StopEffects();
                }
            }
        }
Ejemplo n.º 23
0
        private static void DamagePlayer(float depthOf)
        {
            LiveMixin component = Player.main.gameObject.GetComponent <LiveMixin>();

            component.TakeDamage(UnityEngine.Random.value * depthOf / 50f, default, DamageType.Normal, null);
Ejemplo n.º 24
0
        public static void Prefix(ExosuitDrillArm __instance)
        {
            try
            {
                var damage = Config.Instance.AddOtherDamage;
                if (damage <= 0)
                {
                    return;
                }

                var exosuit = ExosuitField.GetValue(__instance) as Exosuit;

                if (exosuit == null)
                {
                    QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, "Error: exosuit is null", null, true);
                    return;
                }

                if (exosuit.CanPilot() && exosuit.GetPilotingMode())
                {
                    Vector3    zero       = Vector3.zero;
                    GameObject gameObject = null;
                    Vector3    vector;
                    UWE.Utils.TraceFPSTargetPosition(exosuit.gameObject, 5f, ref gameObject, ref zero, out vector, true);

                    if (gameObject != null && gameObject && (bool)DrillingField.GetValue(__instance))
                    {
                        Drillable drillable = gameObject.FindAncestor <Drillable>();

                        if (!drillable)
                        {
                            LiveMixin liveMixin = gameObject.FindAncestor <LiveMixin>();
                            if (liveMixin)
                            {
                                liveMixin.IsAlive();
                                liveMixin.TakeDamage(damage, zero, DamageType.Drill, null);

                                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "Drill Extra Damaging: " + damage, null, true);

                                // Leave this for the real one
                                // this.drillTarget = gameObject;
                            }
                            return;
                        }

                        var maxHealth = Config.Instance.MaxDrillHealth;
                        var healths   = drillable.health;

                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, $"Hitting drillable with healths: " + healths.Length, null, true);

                        for (int i = 0; i < healths.Length; i++)
                        {
                            if (healths[i] > maxHealth)
                            {
                                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, $"Drillable health reduced from {healths[i]} to {maxHealth}", null, true);

                                healths[i] = maxHealth;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, "Error: " + ex.ToString(), ex, true);
            }
        }
Ejemplo n.º 25
0
        public override void OnTouch(Collider collider)
        {
            if (frozen)
            {
                return;
            }
            if (liveMixin.IsAlive() && Time.time > timeLastBite + biteInterval)
            {
                Creature component = GetComponent <Creature>();

                GameObject      target          = GetTarget(collider);
                GulperBehaviour gulperBehaviour = GetComponent <GulperBehaviour>();
                if (!gulperBehaviour.IsHoldingVehicle() && !playerDeathCinematic.IsCinematicModeActive())
                {
                    Player player = target.GetComponent <Player>();
                    if (player != null)
                    {
                        if (Time.time > timeCinematicAgain && player.CanBeAttacked() && player.liveMixin.IsAlive() && !player.cinematicModeActive)
                        {
                            Invoke("KillPlayer", 0.9f);
                            playerDeathCinematic.StartCinematicMode(player);
                            attackSource.clip = clipPool.GetRandomClip();
                            attackSource.Play();
                            timeCinematicAgain = Time.time + 4f;
                            timeLastBite       = Time.time;
                            return;
                        }
                    }
                    else if (gulperBehaviour.GetCanGrabVehicle() && component.Aggression.Value > 0.1f)
                    {
                        SeaMoth seamoth = target.GetComponent <SeaMoth>();
                        if (seamoth && !seamoth.docked)
                        {
                            gulperBehaviour.GrabGenericSub(seamoth);
                            component.Aggression.Value -= 0.5f;
                            return;
                        }
                        Exosuit exosuiit = target.GetComponent <Exosuit>();
                        if (exosuiit && !exosuiit.docked)
                        {
                            gulperBehaviour.GrabExosuit(exosuiit);
                            component.Aggression.Value -= 0.5f;
                            return;
                        }
                    }
                    LiveMixin liveMixin = target.GetComponent <LiveMixin>();
                    if (liveMixin == null)
                    {
                        return;
                    }
                    if (!liveMixin.IsAlive())
                    {
                        return;
                    }
                    if (!CanAttackTargetFromPosition(target))
                    {
                        return;
                    }
                    if (CanSwallowWhole(collider.gameObject, liveMixin))
                    {
                        Destroy(liveMixin.gameObject, 0.5f);
                        var suckInWhole = collider.gameObject.AddComponent <BeingSuckedInWhole>();
                        suckInWhole.animationLength = 0.5f;
                        suckInWhole.target          = throat;
                        creature.GetAnimator().SetTrigger("bite");
                        return;
                    }
                    else
                    {
                        if (component.Aggression.Value >= 0.2f && target.GetComponentInParent <Vehicle>() == null)
                        {
                            liveMixin.TakeDamage(GetBiteDamage(target));
                            timeLastBite      = Time.time;
                            attackSource.clip = clipPool.GetRandomClip();
                            attackSource.Play();
                            creature.GetAnimator().SetTrigger("bite");
                            component.Aggression.Value = 0f;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        private static void DamagePlayer(float ouch)
        {
            LiveMixin component = Player.main.gameObject.GetComponent <LiveMixin>();

            DeathRun.setCause("Crushed By Pressure");
            component.TakeDamage(UnityEngine.Random.value * ouch / 2 + ouch / 2, default, DamageType.Normal, null);