Ejemplo n.º 1
0
        internal EntityState InstantiateNextState(KnifeDeployableSync knife)
        {
            var state = EntityStateCatalog.InstantiateState(slashState);

            (state as KnifePickupSlash).knifeObject = knife.gameObject;
            return(state);
        }
Ejemplo n.º 2
0
            internal EntityState InstantiateNextState()
            {
                var state = EntityStateCatalog.InstantiateState(this.def.reactivationState) as ReactivationBaseState <TSkillData>;

                state.skillData          = this.data;
                state.activatorSkillSlot = this.skillSlot;

                return(state);
            }
        public sealed override EntityState InstantiateNextState(GenericSkill skillSlot)
        {
            var data  = skillSlot.skillInstanceData as SniperPrimaryInstanceData;
            var state = EntityStateCatalog.InstantiateState(data.isReloading ? this.reloadActivationState : base.activationState);

            if (state is BaseSkillState skillState)
            {
                skillState.activatorSkillSlot = skillSlot;
            }
            if (state is ISniperReloadState reloadState)
            {
                reloadState.reloadTier = data.ReadReload();
            }
            return(state);
        }
Ejemplo n.º 4
0
            public void OnReceived()
            {
                if (!_target)
                {
                    return;
                }
                var cpt = _target.GetComponent <RewindComponent>();

                if (!cpt || cpt.frames.Count == 0)
                {
                    return;
                }
                var esm = EntityStateMachine.FindByCustomName(_target.gameObject, "Body");

                if (esm == null || esm.state is RewindState)
                {
                    return;
                }
                esm.SetState(EntityStateCatalog.InstantiateState(Rewind.instance.rewindStateType));
            }
Ejemplo n.º 5
0
 private void UnrestirctTarget()
 {
     if (this.restricted && this.visualState == 1 && this.parentTransform)
     {
         this.restricted = false;
         if (NetworkServer.active)
         {
             var entityStateMachines = this.parentTransform.GetComponents <EntityStateMachine>();
             if (entityStateMachines != null && entityStateMachines.Length > 0)
             {
                 foreach (var entityStateMachine in entityStateMachines)
                 {
                     if (entityStateMachine.state is GurrenLagannShadesConstrictState)
                     {
                         entityStateMachine.SetInterruptState(EntityStateCatalog.InstantiateState(entityStateMachine.mainStateType), InterruptPriority.Death);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void Update()
 {
     // emotes
     if (isNetwork && characterBody.characterMotor.isGrounded && !this.localUser.isUIFocused)
     {
         if (Input.GetKeyDown(Modules.Config.disablePoseKeybind.Value))
         {
             canTaunt = !canTaunt;
             Chat.AddMessage($"Survivor Taunts: {(canTaunt ? "En" : "Dis")}abled");
         }
         else if (Input.GetKeyDown(Modules.Config.displayKeybind.Value))
         {
             this.outer.SetInterruptState(EntityStateCatalog.InstantiateState(new SerializableEntityStateType(typeof(Emotes.Display))), InterruptPriority.Any);
             return;
         }
         else if (Input.GetKeyDown(Modules.Config.poseKeybind.Value))
         {
             this.outer.SetInterruptState(EntityStateCatalog.InstantiateState(new SerializableEntityStateType(typeof(Emotes.Pose))), InterruptPriority.Any);
             return;
         }
     }
 }
Ejemplo n.º 7
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();

            bool flag = false;

            if (base.characterMotor)
            {
                if (!base.characterMotor.isGrounded)
                {
                    flag = true;
                }
                if (base.characterMotor.velocity != Vector3.zero)
                {
                    flag = true;
                }
            }

            if (base.inputBank)
            {
                if (base.inputBank.skill1.down)
                {
                    flag = true;
                }
                if (base.inputBank.skill2.down)
                {
                    flag = true;
                }
                if (base.inputBank.skill3.down)
                {
                    flag = true;
                }
                if (base.inputBank.skill4.down)
                {
                    flag = true;
                }
                if (base.inputBank.jump.down)
                {
                    flag = true;
                }

                if (base.inputBank.moveVector != Vector3.zero)
                {
                    flag = true;
                }
            }

            //emote cancels
            if (base.isAuthority && base.characterMotor.isGrounded && !this.localUser.isUIFocused)
            {
                if (Input.GetKeyDown(Modules.Config.displayKeybind.Value))
                {
                    this.outer.SetInterruptState(EntityStateCatalog.InstantiateState(new SerializableEntityStateType(typeof(Display))), InterruptPriority.Any);
                    return;
                }
                else if (Input.GetKeyDown(Modules.Config.poseKeybind.Value))
                {
                    this.outer.SetInterruptState(EntityStateCatalog.InstantiateState(new SerializableEntityStateType(typeof(Pose))), InterruptPriority.Any);
                    return;
                }
            }

            if (this.duration > 0 && base.fixedAge >= this.duration)
            {
                flag = true;
            }

            CameraTargetParams ctp = base.cameraTargetParams;
            float   denom          = (1 + Time.fixedTime - this.initialTime);
            float   smoothFactor   = 8 / Mathf.Pow(denom, 2);
            Vector3 smoothVector   = new Vector3(-3 / 20, 1 / 16, -1);

            ctp.idealLocalCameraPos = new Vector3(0f, -1.4f, -6f) + smoothFactor * smoothVector;

            if (this.animator)
            {
                this.animator.SetBool("inCombat", true);
            }

            if (flag)
            {
                this.outer.SetNextStateToMain();
            }
        }
Ejemplo n.º 8
0
        public static void AddHooks()
        {
            // Ugh.
            On.RoR2.CharacterAI.BaseAI.OnBodyLost += (orig, self, body) =>
            {
                if (self.name.Equals("PlayerBot"))
                {
                    // Reset player bot state when body is lost so errors dont pop up
                    self.stateMachine.SetNextState(EntityStateCatalog.InstantiateState(self.scanState));
                    return;
                }
                orig(self, body);
            };

            // Random fix to make captains spawnable without errors in PlayerMode, theres probably a better way of doing this too
            On.RoR2.CaptainDefenseMatrixController.OnServerMasterSummonGlobal += (orig, self, summonReport) =>
            {
                if (self.GetFieldValue <CharacterBody>("characterBody") == null)
                {
                    return;
                }
                orig(self, summonReport);
            };

            // Maybe there is a better way to do this
            if (PlayerBotManager.ShowNameplates.Value && !PlayerBotManager.PlayerMode.Value)
            {
                IL.RoR2.TeamComponent.SetupIndicator += il =>
                {
                    ILCursor c = new ILCursor(il);
                    c.GotoNext(x => x.MatchCallvirt <CharacterBody>("get_isPlayerControlled"));
                    bool isPlayerBot = false;
                    c.EmitDelegate <Func <CharacterBody, CharacterBody> >(x =>
                    {
                        isPlayerBot = x.master.name.Equals("PlayerBot");
                        return(x);
                    }
                                                                          );
                    c.Index += 1;
                    c.EmitDelegate <Func <bool, bool> >(x =>
                    {
                        if (isPlayerBot)
                        {
                            return(true);
                        }
                        return(x);
                    }
                                                        );
                };
            }

            if (!PlayerBotManager.PlayerMode.Value && PlayerBotManager.AutoPurchaseItems.Value)
            {
                // Give bots money
                On.RoR2.TeamManager.GiveTeamMoney += (orig, self, teamIndex, money) =>
                {
                    orig(self, teamIndex, money);

                    if (PlayerBotManager.playerbots.Count > 0)
                    {
                        int num = Run.instance ? Run.instance.livingPlayerCount : 0;
                        if (num != 0)
                        {
                            money = (uint)Mathf.CeilToInt(money / (float)num);
                        }
                        foreach (GameObject playerbot in PlayerBotManager.playerbots)
                        {
                            if (!playerbot)
                            {
                                continue;
                            }
                            CharacterMaster master = playerbot.GetComponent <CharacterMaster>();
                            if (master && !master.IsDeadAndOutOfLivesServer() && master.teamIndex == teamIndex)
                            {
                                master.GiveMoney(money);
                            }
                        }
                    }
                };
            }

            if (PlayerBotManager.AutoPurchaseItems.Value)
            {
                On.RoR2.Run.BeginStage += (orig, self) =>
                {
                    foreach (GameObject playerbot in PlayerBotManager.playerbots.ToArray())
                    {
                        if (!playerbot)
                        {
                            PlayerBotManager.playerbots.Remove(playerbot);
                            continue;
                        }

                        ItemManager itemManager = playerbot.GetComponent <ItemManager>();
                        if (itemManager)
                        {
                            itemManager.ResetPurchases();
                            itemManager.master.money = 0;
                        }
                    }
                    orig(self);
                };
            }

            On.RoR2.Stage.Start += (orig, self) =>
            {
                orig(self);
                if (NetworkServer.active)
                {
                    if (PlayerBotManager.PlayerMode.Value)
                    {
                        foreach (GameObject playerbot in PlayerBotManager.playerbots.ToArray())
                        {
                            if (!playerbot)
                            {
                                PlayerBotManager.playerbots.Remove(playerbot);
                                continue;
                            }

                            CharacterMaster master = playerbot.GetComponent <CharacterMaster>();
                            if (master)
                            {
                                Stage.instance.RespawnCharacter(master);
                            }
                        }
                    }
                    // Spawn starting bots
                    if (Run.instance.stageClearCount == 0)
                    {
                        if (PlayerBotManager.InitialRandomBots.Value > 0)
                        {
                            PlayerBotManager.SpawnRandomPlayerbots(NetworkUser.readOnlyInstancesList[0].master, PlayerBotManager.InitialRandomBots.Value);
                        }
                        for (int randomSurvivorsIndex = 0; randomSurvivorsIndex < PlayerBotManager.InitialBots.Length; randomSurvivorsIndex++)
                        {
                            if (PlayerBotManager.InitialBots[randomSurvivorsIndex].Value > 0)
                            {
                                PlayerBotManager.SpawnPlayerbots(NetworkUser.readOnlyInstancesList[0].master, PlayerBotManager.RandomSurvivorsList[randomSurvivorsIndex], PlayerBotManager.InitialBots[randomSurvivorsIndex].Value);
                            }
                        }
                    }
                }
            };

            // Fix custom targets
            On.RoR2.CharacterAI.BaseAI.Target.GetBullseyePosition += Hook_GetBullseyePosition;

            if (PlayerBotManager.PlayerMode.Value)
            {
                On.RoR2.SceneDirector.PlaceTeleporter += (orig, self) =>
                {
                    if (PlayerBotManager.DontScaleInteractables.Value)
                    {
                        int              count     = PlayerCharacterMasterController.instances.Count((PlayerCharacterMasterController v) => v.networkUser);
                        float            num       = 0.5f + (float)count * 0.5f;
                        ClassicStageInfo component = SceneInfo.instance.GetComponent <ClassicStageInfo>();
                        int              credit    = (int)((float)component.sceneDirectorInteractibleCredits * num);
                        if (component.bonusInteractibleCreditObjects != null)
                        {
                            for (int i = 0; i < component.bonusInteractibleCreditObjects.Length; i++)
                            {
                                ClassicStageInfo.BonusInteractibleCreditObject bonusInteractibleCreditObject = component.bonusInteractibleCreditObjects[i];
                                if (bonusInteractibleCreditObject.objectThatGrantsPointsIfEnabled.activeSelf)
                                {
                                    credit += bonusInteractibleCreditObject.points;
                                }
                            }
                        }
                        self.interactableCredit = credit;
                    }
                    else if (Run.instance.stageClearCount == 0 && PlayerBotManager.GetInitialBotCount() > 0)
                    {
                        int count = PlayerCharacterMasterController.instances.Count((PlayerCharacterMasterController v) => v.networkUser);
                        count += PlayerBotManager.GetInitialBotCount();
                        float            num       = 0.5f + (float)count * 0.5f;
                        ClassicStageInfo component = SceneInfo.instance.GetComponent <ClassicStageInfo>();
                        int credit = (int)((float)component.sceneDirectorInteractibleCredits * num);
                        if (component.bonusInteractibleCreditObjects != null)
                        {
                            for (int i = 0; i < component.bonusInteractibleCreditObjects.Length; i++)
                            {
                                ClassicStageInfo.BonusInteractibleCreditObject bonusInteractibleCreditObject = component.bonusInteractibleCreditObjects[i];
                                if (bonusInteractibleCreditObject.objectThatGrantsPointsIfEnabled.activeSelf)
                                {
                                    credit += bonusInteractibleCreditObject.points;
                                }
                            }
                        }
                        self.interactableCredit = credit;
                    }

                    orig(self);
                };

                // Required for bots to even move, maybe switch to il later
                On.RoR2.PlayerCharacterMasterController.Update += (orig, self) =>
                {
                    if (self.name.Equals("PlayerBot"))
                    {
                        //self.InvokeMethod("SetBody", new object[] { self.master.GetBodyObject() });
                        return;
                    }
                    orig(self);
                };

                IL.RoR2.UI.AllyCardManager.PopulateCharacterDataSet += il =>
                {
                    ILCursor c = new ILCursor(il);
                    c.GotoNext(x => x.MatchCallvirt <CharacterMaster>("get_playerCharacterMasterController"));
                    c.Index += 2;
                    c.EmitDelegate <Func <bool, bool> >(x => false);
                };

                // Spectator fix
                On.RoR2.CameraRigController.CanUserSpectateBody += (orig, viewer, body) =>
                {
                    return(body.isPlayerControlled || orig(viewer, body));
                };

                // Dont end game on dying
                if (PlayerBotManager.ContinueAfterDeath.Value)
                {
                    IL.RoR2.Stage.FixedUpdate += il =>
                    {
                        ILCursor c = new ILCursor(il);
                        c.GotoNext(x => x.MatchCallvirt <PlayerCharacterMasterController>("get_isConnected"));
                        c.Index += 1;
                        c.EmitDelegate <Func <bool, bool> >(x => true);
                    };
                }
            }
        }