Advertisement
Lavallet

StealthRC.reds by Lavallet v1.0

May 22nd, 2024 (edited)
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 10.43 KB | Gaming | 0 0
  1. @wrapMethod(TargetTrackingExtension)
  2.   public final static func OnHit(ownerPuppet: wref<ScriptedPuppet>, evt: ref<gameHitEvent>) -> Void {
  3.     let instigator: wref<GameObject>;
  4.     let vehicle: ref<VehicleObject>;
  5.     let controlledObject: wref<GameObject>;
  6.     let isControlled: Bool = false;
  7.     let traceCost: Float;
  8.  
  9.     if !IsDefined(evt.attackData) {
  10.       return;
  11.     };
  12.     instigator = evt.attackData.GetInstigator();
  13.     if IsDefined(instigator) && instigator.IsPlayer() {
  14.       if instigator.GetTakeOverControlSystem().IsDeviceControlled() {
  15.         isControlled = true;
  16.         traceCost = 1.5;
  17.         controlledObject = instigator.GetTakeOverControlSystem().GetControlledObject();
  18.       };
  19.       vehicle = evt.attackData.GetSource() as VehicleObject;
  20.       if IsDefined(vehicle) && (vehicle.IsVehicleRemoteControlled() || vehicle.IsVehicleAccelerateQuickhackActive()) {
  21.         isControlled = true;
  22.         traceCost = 6.0;
  23.         controlledObject = vehicle as GameObject;
  24.       };
  25.     };
  26.  
  27.     if !isControlled {
  28.       wrappedMethod(ownerPuppet, evt);
  29.       return;
  30.     }
  31.  
  32.     let id: TweakDBID;
  33.     let targetTracker: wref<TargetTrackingExtension>;
  34.  
  35.     let player: ref<PlayerPuppet>;
  36.     if !IsDefined(ownerPuppet) || !IsDefined(evt) {
  37.       return;
  38.     };
  39.     instigator = evt.attackData.GetInstigator();
  40.     if !IsDefined(instigator) {
  41.       return;
  42.     };
  43.     if ownerPuppet.GetEntityID() == instigator.GetEntityID() {
  44.       return;
  45.     };
  46.     if ScriptedPuppet.IsPlayerCompanion(instigator) {
  47.       return;
  48.     };
  49.     if !ownerPuppet.IsActive() {
  50.       return;
  51.     };
  52.     if Equals(GameObject.GetAttitudeTowards(ownerPuppet, instigator), EAIAttitude.AIA_Friendly) {
  53.       return;
  54.     };
  55.     if !ownerPuppet.IsAggressive() {
  56.       return;
  57.     };
  58.     if evt.attackData.HasFlag(hitFlag.WasKillingBlow) {
  59.       return;
  60.     };
  61.     if evt.attackData.HasFlag(hitFlag.QuickHack) {
  62.       return;
  63.     };
  64.     if evt.attackData.HasFlag(hitFlag.DealNoDamage) {
  65.       return;
  66.     };
  67.     NPCStatesComponent.AlertPuppet(ownerPuppet);
  68.     if IsDefined(evt.attackData.GetSource() as Device) && !IsDefined(evt.attackData.GetWeapon()) {
  69.       return;
  70.     };
  71.     if !TargetTrackingExtension.Get(ownerPuppet, targetTracker) {
  72.       return;
  73.     };
  74.     if SenseComponent.ShouldIgnoreIfPlayerCompanion(ownerPuppet, instigator) {
  75.       return;
  76.     };
  77.     if AIActionHelper.TryChangingAttitudeToHostile(ownerPuppet, instigator) {
  78.       id = targetTracker.GetCurrentPreset();
  79.       TDBID.Append(id, t".droppingCooldownPerHit");
  80.       NPCPuppet.RevealPlayerPositionIfNeeded(ownerPuppet, instigator.GetEntityID());
  81.       player = instigator as PlayerPuppet;
  82.       if player.IsBeingRevealed() && GameInstance.GetStatsSystem(GetGameInstance()).GetStatValue(Cast<StatsObjectID>(player.GetEntityID()), gamedataStatType.IgnoreAwarenessCostWhenOverclocked) != 1.00 {
  83.         GameInstance.GetStatPoolsSystem(GetGameInstance()).RequestChangingStatPoolValue(Cast<StatsObjectID>(player.GetEntityID()), gamedataStatPoolType.QuickHackUpload, traceCost, player, true, true);
  84.       };
  85.       instigator = controlledObject;
  86.       GameObject.ChangeAttitudeToHostile(ownerPuppet, instigator);
  87.       targetTracker.AddDroppingCooldown(instigator, TweakDBInterface.GetFloat(id, 0.00));
  88.       targetTracker.AddThreat(instigator, true, instigator.GetWorldPosition(), 1.00, -1.00, false);
  89.       if instigator.IsSensor() {
  90.         instigator.QueueEvent(new TurnOnVisibilitySenseComponent());
  91.       };
  92.     };
  93.   }
  94.  
  95. @wrapMethod(NPCPuppet)
  96.   protected cb func OnRagdollImpactEvent(evt: ref<RagdollImpactEvent>) -> Bool {
  97.     let otherVehicleObject: ref<VehicleObject>;
  98.     if evt.triggeredSimulation {
  99.       otherVehicleObject = evt.otherEntity as VehicleObject;
  100.       if !IsDefined(otherVehicleObject) || !(otherVehicleObject.IsVehicleRemoteControlled() || otherVehicleObject.IsVehicleAccelerateQuickhackActive()) {
  101.           return wrappedMethod(evt);
  102.       };
  103.     };
  104.    
  105.     let attackInstigator: ref<GameObject>;
  106.     let currentPosition: Vector4;
  107.     let damageEvent: ref<StartRagdollDamageEvent>;
  108.     let i: Int32;
  109.     let impactData: RagdollImpactPointData;
  110.     let isDead: Bool;
  111.     let isDefeated: Bool;
  112.     let isHighFall: Bool;
  113.     let isHitByPlayerVehicle: Bool;
  114.     let isImpactedThrownNPC: Bool;
  115.     let isThrownNPC: Bool;
  116.     let otherNPCPuppet: ref<NPCPuppet>;
  117.     let player: ref<PlayerPuppet>;
  118.     let terminalVelocityReached: Bool;
  119.     let vehicleHitEvent: ref<gameVehicleHitEvent>;
  120.     vehicleHitEvent = new gameVehicleHitEvent();
  121.     vehicleHitEvent.vehicleVelocity = otherVehicleObject.GetLinearVelocity();
  122.     vehicleHitEvent.preyVelocity = this.GetVelocity();
  123.     vehicleHitEvent.target = this;
  124.     vehicleHitEvent.hitPosition = WorldPosition.ToVector4(evt.impactPoints[0].worldPosition);
  125.     vehicleHitEvent.hitDirection = evt.impactPoints[0].worldNormal;
  126.     vehicleHitEvent.attackData = new AttackData();
  127.     attackInstigator = VehicleComponent.GetDriver(this.GetGame(), otherVehicleObject, otherVehicleObject.GetEntityID());
  128.     if otherVehicleObject.IsVehicleAccelerateQuickhackActive() {
  129.       attackInstigator = GameInstance.GetPlayerSystem(this.GetGame()).GetLocalPlayerControlledGameObject();
  130.     };
  131.     vehicleHitEvent.attackData.SetInstigator(attackInstigator);
  132.     vehicleHitEvent.attackData.SetSource(otherVehicleObject);
  133.     this.QueueEvent(vehicleHitEvent);
  134.     isDead = this.IsDead() || StatusEffectSystem.ObjectHasStatusEffect(this, t"BaseStatusEffect.ForceKill");
  135.     isDefeated = ScriptedPuppet.IsDefeated(this);
  136.     isHitByPlayerVehicle = VehicleComponent.IsMountedToVehicle(this.GetGame(), GameInstance.GetPlayerSystem(this.GetGame()).GetLocalPlayerControlledGameObject());
  137.     isThrownNPC = StatusEffectSystem.ObjectHasStatusEffect(this, t"BaseStatusEffect.ThrownNPC");
  138.     isImpactedThrownNPC = StatusEffectSystem.ObjectHasStatusEffect(this, t"BaseStatusEffect.ImpactedThrownNPC");
  139.     player = GameInstance.GetPlayerSystem(this.GetGame()).GetLocalPlayerControlledGameObject() as PlayerPuppet;
  140.     otherNPCPuppet = evt.otherEntity as NPCPuppet;
  141.     currentPosition = this.GetWorldPosition();
  142.     i = 0;
  143.     while i < ArraySize(evt.impactPoints) {
  144.       impactData = evt.impactPoints[i];
  145.       if isThrownNPC {
  146.         if IsDefined(otherNPCPuppet) && ScriptedPuppet.IsAlive(otherNPCPuppet) && !ArrayContains(this.m_ragdollImpactedNPCs, otherNPCPuppet) {
  147.           ArrayPush(this.m_ragdollImpactedNPCs, otherNPCPuppet);
  148.         } else {
  149.           this.SpawnRagdollSplatter(impactData, true);
  150.         };
  151.         if impactData.forceMagnitude > this.m_ragdollDamageData.maxForceMagnitude {
  152.           this.SetRagdollDamageData(impactData, currentPosition);
  153.         };
  154.       } else {
  155.         terminalVelocityReached = impactData.velocityChange >= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollImpactKillVelocityThreshold", 11.00);
  156.         isHighFall = impactData.velocityChange >= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollHighFallVelocityThreshold", 8.00) && AbsF(this.m_ragdollInitialPosition.Z - currentPosition.Z) >= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollHighFallHeightThreshold", 6.00);
  157.         if IsDefined(otherNPCPuppet) && !otherNPCPuppet.IsRagdolling() && !ArrayContains(this.m_ragdollImpactedNPCs, otherNPCPuppet) {
  158.           if Vector4.Length(this.GetVelocity()) <= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollTripNPCInstigatorVelThreshold", 0.20) {
  159.             if !GameObject.IsCooldownActive(GameInstance.GetPlayerSystem(this.GetGame()).GetLocalPlayerControlledGameObject(), n"RagdollTripGlobalCooldown") && ScriptedPuppet.CanTripOverRagdolls(otherNPCPuppet) && this.ShouldTripVictim(otherNPCPuppet) {
  160.               otherNPCPuppet.QueueEvent(CreateForceRagdollEvent(n"Tripped over a ragdoll"));
  161.               GameObject.StartCooldown(GameInstance.GetPlayerSystem(this.GetGame()).GetLocalPlayerControlledGameObject(), n"RagdollTripGlobalCooldown", TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollTripGlobalCooldownDuration", 0.00));
  162.             };
  163.           } else {
  164.             if !(isImpactedThrownNPC && Equals(GameObject.GetAttitudeTowards(player, otherNPCPuppet), EAIAttitude.AIA_Friendly)) && impactData.velocityChange >= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollAnotherNPCVelocityThreshold", 1.00) && Equals(otherNPCPuppet.GetNPCType(), gamedataNPCType.Human) && ScriptedPuppet.CanRagdoll(otherNPCPuppet) {
  165.               otherNPCPuppet.QueueEvent(CreateForceRagdollEvent(n"Hit by a ragdolling NPC"));
  166.             } else {
  167.               this.SpawnRagdollBumpAttack(WorldPosition.ToVector4(impactData.worldPosition) + Vector4.Normalize(impactData.worldNormal) * 0.05);
  168.             };
  169.           };
  170.           ArrayPush(this.m_ragdollImpactedNPCs, otherNPCPuppet);
  171.         };
  172.         if this.CanReceiveDamageFromRagdollImpacts(isDead, isDefeated, terminalVelocityReached, isHighFall) {
  173.           if impactData.velocityChange >= TweakDBInterface.GetFloat(t"AIGeneralSettings.ragdollDamageMinimumVelocity", 2.00) {
  174.             if this.m_ragdollDamageData.maxVelocityChange == 0.00 {
  175.               damageEvent = new StartRagdollDamageEvent();
  176.               GameInstance.GetDelaySystem(this.GetGame()).DelayEvent(this, damageEvent, 0.30);
  177.             };
  178.             if impactData.velocityChange > this.m_ragdollDamageData.maxVelocityChange {
  179.               this.SetRagdollDamageData(impactData, currentPosition);
  180.             };
  181.           };
  182.         } else {
  183.           if isHitByPlayerVehicle && (isDefeated || isDead) {
  184.             this.SpawnRagdollSplatter(impactData, isDead);
  185.           };
  186.         };
  187.         if !this.m_ragdollFloorSplashSpawned && (terminalVelocityReached || isHighFall) {
  188.           this.SpawnRagdollFloorSplash(impactData);
  189.         };
  190.       };
  191.       i += 1;
  192.     };
  193.     if isThrownNPC {
  194.       this.OnThrownNPCRagdollImpact();
  195.     };
  196.     if StatusEffectSystem.ObjectHasStatusEffectWithTag(this, n"OnePunchedMark") {
  197.       GameObjectEffectHelper.StartEffectEvent(this, n"blood_nose_punch_strong");
  198.       this.SpawnRagdollSplatter(impactData, isDead);
  199.     };
  200.   }
  201.  
  202. @wrapMethod(ReactionManagerComponent)
  203.   private final func ShouldStimBeProcessed(stimEvent: ref<StimuliEvent>, delayed: Bool) -> Bool {
  204.     if Equals(stimEvent.GetStimType(), gamedataStimType.Bullet) && stimEvent.sourceObject.GetTakeOverControlSystem().IsDeviceControlled() {
  205.         this.LogFailure("player controlled device shot bullet");
  206.         return false;
  207.     };
  208.     return wrappedMethod(stimEvent, delayed);
  209.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement