Example #1
0
 internal static void RegisterBody() => BodiesCore.Add(SniperMain.sniperBodyPrefab);
Example #2
0
        private static GameObject CreateDecoyPrefab()
        {
            GameObject obj = PrefabsCore.CreatePrefab("SniperDecoy", true);

            TeamComponent teamComp = obj.AddOrGetComponent <TeamComponent>();

            teamComp.hideAllyCardDisplay = false;
            teamComp.teamIndex           = TeamIndex.None;


            NetworkIdentity netId = obj.AddOrGetComponent <NetworkIdentity>();


            Transform modelBase = new GameObject("ModelBase").transform;

            modelBase.parent        = obj.transform;
            modelBase.localPosition = new Vector3(0f, -0.81f, 0f);
            modelBase.localScale    = Vector3.one;
            modelBase.localRotation = Quaternion.identity;


            GameObject mdlSniper = UnityEngine.Object.Instantiate <GameObject>(ModelModule.GetModel(), modelBase);

            mdlSniper.transform.localPosition = Vector3.zero;
            mdlSniper.transform.localScale    = Vector3.one;
            mdlSniper.transform.localRotation = Quaternion.identity;



            CharacterBody body = obj.AddOrGetComponent <CharacterBody>();

            body.bodyIndex             = (BodyIndex)(-1);
            body.baseNameToken         = Properties.Tokens.SNIPER_NAME;
            body.subtitleNameToken     = Properties.Tokens.SNIPER_SUBTITLE;
            body.bodyFlags             = CharacterBody.BodyFlags.ResistantToAOE | CharacterBody.BodyFlags.ImmuneToExecutes;
            body.rootMotionInMainState = false;
            body.mainRootSpeed         = 0f;

            // CLEANUP: Abstract out base stats for decoy and sniper
            body.baseMaxHealth  = 130f;
            body.levelMaxHealth = 39f;

            body.baseRegen  = 1f;
            body.levelRegen = 0.2f;

            body.baseMaxShield  = 0f;
            body.levelMaxShield = 0f;

            body.baseMoveSpeed  = 0f;
            body.levelMoveSpeed = 0f;

            body.baseAcceleration = 0f;

            body.baseJumpPower  = 0f;
            body.levelJumpPower = 0f;

            body.baseDamage  = 12f;
            body.levelDamage = 2.4f;

            body.baseAttackSpeed  = 1f;
            body.levelAttackSpeed = 0f;

            body.baseCrit  = 0f;
            body.levelCrit = 0f;

            body.baseArmor  = 50f;
            body.levelArmor = 10f;

            body.baseJumpCount = 1;

            body.sprintingSpeedMultiplier = 0f;

            //body.killCount = 0;
            body.wasLucky                  = false;
            body.spreadBloomDecayTime      = 0.45f;
            body.spreadBloomCurve          = new AnimationCurve();
            body.crosshairPrefab           = null;
            body.hideCrosshair             = false;
            body.aimOriginTransform        = body.transform;
            body.hullClassification        = HullClassification.Human;
            body.portraitIcon              = UIModule.GetPortraitIcon();
            body.isChampion                = false;
            body.currentVehicle            = null;
            body.preferredPodPrefab        = null;
            body.preferredInitialStateType = SkillsCore.StateType <GenericCharacterMain>();
            body.skinIndex                 = 0u;



            CharacterModel model = mdlSniper.AddOrGetComponent <CharacterModel>();

            model.body = body;
            model.itemDisplayRuleSet = ItemDisplayModule.GetSniperItemDisplay(model.AddOrGetComponent <ChildLocator>());



            HealthComponent health = obj.AddOrGetComponent <HealthComponent>();

            health.health            = 100;
            health.shield            = 0;
            health.barrier           = 0;
            health.magnetiCharge     = 0;
            health.body              = null;
            health.dontShowHealthbar = false;
            health.globalDeathEventChanceCoefficient = 1f;



            HurtBoxGroup hurtBoxGroup = model.AddOrGetComponent <HurtBoxGroup>();
            HurtBox      tempHb       = model.GetComponentInChildren <HurtBox>();

            tempHb.gameObject.layer = LayerIndex.entityPrecise.intVal;
            tempHb.healthComponent  = health;
            tempHb.isBullseye       = true;
            tempHb.damageModifier   = HurtBox.DamageModifier.Normal;
            tempHb.hurtBoxGroup     = hurtBoxGroup;
            tempHb.indexInGroup     = 0;

            hurtBoxGroup.hurtBoxes = new[]
            {
                tempHb,
            };
            hurtBoxGroup.mainHurtBox   = tempHb;
            hurtBoxGroup.bullseyeCount = 1;


            InputBankTest inputs = obj.AddOrGetComponent <InputBankTest>();

            inputs.moveVector = Vector3.zero;


            CameraTargetParams cameraTargetParams = obj.AddOrGetComponent <CameraTargetParams>();

            cameraTargetParams.cameraParams         = MiscModule.GetCharCameraParams();
            cameraTargetParams.cameraPivotTransform = null;
            cameraTargetParams.aimMode             = CameraTargetParams.AimType.Standard;
            cameraTargetParams.recoil              = Vector2.zero;
            cameraTargetParams.idealLocalCameraPos = Vector3.zero;
            cameraTargetParams.dontRaycastToPivot  = false;



            ModelLocator modelLocator = obj.AddOrGetComponent <ModelLocator>();

            modelLocator.modelTransform           = mdlSniper.transform;
            modelLocator.modelBaseTransform       = modelBase;
            modelLocator.dontReleaseModelOnDeath  = false;
            modelLocator.autoUpdateModelTransform = true;
            modelLocator.dontDetatchFromParent    = false;
            modelLocator.noCorpse         = true;
            modelLocator.normalizeToFloor = false;
            modelLocator.preserveModel    = false;


            EntityStateMachine esm = obj.AddOrGetComponent <EntityStateMachine>();

            esm.customName       = "Body";
            esm.initialStateType = SkillsCore.StateType <BeingADecoy>();
            esm.mainStateType    = SkillsCore.StateType <BeingADecoy>();


            SkillLocator skillLocator = obj.AddOrGetComponent <SkillLocator>();

            skillLocator.primary   = null;
            skillLocator.secondary = null;
            skillLocator.utility   = null;
            skillLocator.special   = null;


            CharacterDeathBehavior deathBehaviour = obj.AddOrGetComponent <CharacterDeathBehavior>();

            deathBehaviour.deathStateMachine = esm;
            deathBehaviour.deathState        = SkillsCore.StateType <DecoyDeathState>();
            deathBehaviour.idleStateMachine  = Array.Empty <EntityStateMachine>();


            CharacterNetworkTransform netTrans = obj.AddOrGetComponent <CharacterNetworkTransform>();

            netTrans.positionTransmitInterval = 0.1f;
            netTrans.lastPositionTransmitTime = Single.NegativeInfinity;
            netTrans.interpolationFactor      = 2f;
            netTrans.debugDuplicatePositions  = false;
            netTrans.debugSnapshotReceived    = false;


            NetworkStateMachine netStates = obj.AddOrGetComponent <NetworkStateMachine>();

            //netStates._SetStateMachines( esm );
            netStates.stateMachines = new[] { esm };


            Interactor interactor = obj.AddOrGetComponent <Interactor>();

            interactor.maxInteractionDistance = 1f;


            InteractionDriver interactionDriver = obj.AddOrGetComponent <InteractionDriver>();

            interactionDriver.highlightInteractor = false;


            CapsuleCollider cap = obj.AddOrGetComponent <CapsuleCollider>();

            cap.isTrigger = false;
            cap.material  = null;
            cap.center    = Vector3.zero;
            cap.radius    = 0.5f;
            cap.height    = 1.82f;
            cap.direction = 1;


            SetStateOnHurt hurtState = obj.AddOrGetComponent <SetStateOnHurt>();

            hurtState.hitThreshold       = 5f;
            hurtState.targetStateMachine = esm;
            hurtState.idleStateMachine   = Array.Empty <EntityStateMachine>();
            hurtState.hurtState          = SkillsCore.StateType <Idle>();
            hurtState.canBeHitStunned    = false;
            hurtState.canBeFrozen        = true;
            hurtState.canBeStunned       = false;


            SfxLocator sfx = obj.AddOrGetComponent <SfxLocator>();
            // FUTURE: Death sounds for decoy


            Rigidbody rb = obj.AddOrGetComponent <Rigidbody>();

            rb.mass                   = 1000f;
            rb.drag                   = 0f;
            rb.angularDrag            = 0f;
            rb.useGravity             = false;
            rb.isKinematic            = true;
            rb.interpolation          = RigidbodyInterpolation.None;
            rb.collisionDetectionMode = CollisionDetectionMode.Discrete;


            CharacterMotor charMot = obj.AddOrGetComponent <CharacterMotor>();

            charMot.walkSpeedPenaltyCoefficient = 1f;
            CharacterDirection charDir = charMot.characterDirection = obj.AddOrGetComponent <CharacterDirection>();

            charMot.muteWalkMotion = false;
            charMot.mass           = 1000f;
            charMot.airControl     = 0.25f;
            charMot.disableAirControlUntilCollision = false;
            charMot.generateParametersOnAwake       = true;
            charMot.useGravity = true;
            charMot.isFlying   = false;


            charDir.moveVector      = Vector3.zero;
            charDir.targetTransform = modelBase;
            charDir.overrideAnimatorForwardTransform = null;
            charDir.rootMotionAccumulator            = null;
            charDir.modelAnimator         = null;
            charDir.driveFromRootRotation = false;
            charDir.driveFromRootRotation = false;
            charDir.turnSpeed             = 180f;


            KinematicCharacterController.KinematicCharacterMotor kinCharMot = obj.AddOrGetComponent <KinematicCharacterController.KinematicCharacterMotor>();
            kinCharMot.CharacterController               = charMot;
            kinCharMot.Capsule                           = cap;
            kinCharMot.Rigidbody                         = rb;
            kinCharMot.CapsuleRadius                     = 0.5f;
            kinCharMot.CapsuleHeight                     = 1.8f;
            kinCharMot.CapsuleYOffset                    = 0f;
            kinCharMot.DetectDiscreteCollisions          = false;
            kinCharMot.GroundDetectionExtraDistance      = 0f;
            kinCharMot.MaxStepHeight                     = 0.5f;
            kinCharMot.MinRequiredStepDepth              = 0.1f;
            kinCharMot.MaxStableSlopeAngle               = 55f;
            kinCharMot.MaxStableDistanceFromLedge        = 0.5f;
            kinCharMot.PreventSnappingOnLedges           = false;
            kinCharMot.MaxStableDenivelationAngle        = 55f;
            kinCharMot.RigidbodyInteractionType          = KinematicCharacterController.RigidbodyInteractionType.None;
            kinCharMot.PreserveAttachedRigidbodyMomentum = true;
            kinCharMot.HasPlanarConstraint               = false;
            kinCharMot.PlanarConstraintAxis              = Vector3.up;
            kinCharMot.StepHandling                      = KinematicCharacterController.StepHandlingMethod.Standard;
            kinCharMot.LedgeHandling                     = true;
            kinCharMot.InteractiveRigidbodyHandling      = true;
            kinCharMot.SafeMovement                      = false;


            _ = obj.AddComponent <DecoyDeployableSync>();


            obj.layer = LayerIndex.fakeActor.intVal;


            foreach (IRuntimePrefabComponent comp in obj.GetComponents <IRuntimePrefabComponent>())
            {
                comp.InitializePrefab();
            }


            BodiesCore.Add(obj);

            return(obj);
        }