Beispiel #1
0
    private IEnumerator SetPlayerCharacterIfAppropriateInternal(PlayerCharacterMasterController playerCharArg)
    {
        // wait to ensure that player's network component properties are fully setup
        yield return(new WaitForEndOfFrame());

        // get net identity comp from player obj
        NetworkIdentity netIdentity = playerCharArg.GetComponent <NetworkIdentity>();

        // if NO such component found
        if (netIdentity == null)
        {
            // DONT continue code
            yield break;
        }

        // if player is online but NOT associated with the machine running this
        if (GeneralMethods.IsNetworkConnectedButNotLocalClient(netIdentity))
        {
            // DONT continue code
            yield break;
        }

        //set UI player char to given char
        uiPlayerCharacter = playerCharArg;
        // trigger event to denote that the UI player char has been changed
        UiPlayerCharChangedEvent.Trigger(uiPlayerCharacter);
    }
    /// <summary>
    /// Add functions to be called for given player's action events.
    /// </summary>
    /// <param name="playerCharArg"></param>
    private void AddPlayerEventListening(PlayerCharacterMasterController playerCharArg)
    {
        playerCharArg.OnCharDataSecondaryChangedAction += RefreshAbilityFullDisplay;

        // find the char's action ability component
        _charActionAbility = playerCharArg.GetComponent <
            CharacterActionActiveAbilityController>();
        // if comp found
        if (_charActionAbility != null)
        {
            _charActionAbility.OnActiveAbilityUseAction += RefreshCooldownTimer;
        }
    }
Beispiel #3
0
        internal static void SetBodyOverrideHook(On.RoR2.PlayerCharacterMasterController.orig_SetBody orig, PlayerCharacterMasterController self, GameObject newBody)
        {
            orig(self, newBody);

            var extraMaster = self.GetComponent <CustomPlayerCharacterMasterController>();

            if (!extraMaster)
            {
                return;
            }

            extraMaster.customInputBank = self.body ? self.body.GetComponent <CustomInputBank>() : null;
        }
    /// <summary>
    /// Add functions to be called for given player's action events.
    /// </summary>
    /// <param name="playerCharArg"></param>
    private void AddPlayerEventListening(PlayerCharacterMasterController playerCharArg)
    {
        playerCharArg.OnCharDataChangedAction += RefreshAmmoBarFull;
        playerCharArg.OnEquippedWeaponSlotNumChangedAction += RefreshAmmoBarFull;

        // find the char's action attack component
        CharacterActionAttackController charActionAttack = playerCharArg.
                                                           GetComponent <CharacterActionAttackController>();

        // if comp found
        if (charActionAttack != null)
        {
            charActionAttack.OnCharacterAttackAction += RefreshAmmoBarCount;
        }
    }
    /// <summary>
    /// Add functions to be called for given player's action events.
    /// </summary>
    /// <param name="playerCharArg"></param>
    private void AddPlayerEventListening(PlayerCharacterMasterController playerCharArg)
    {
        playerCharArg.OnCharDataChangedAction += RefreshWeaponModel;
        playerCharArg.OnEquippedWeaponSlotNumChangedAction += RefreshWeaponModel;

        playerCharArg.CharMovement.OnIsMovingChangedAction += RefreshWeaponMovingAnimation;

        // find the char's action attack component
        CharacterActionAttackController charActionAttack = playerCharArg.
                                                           GetComponent <CharacterActionAttackController>();

        // if comp found
        if (charActionAttack != null)
        {
            charActionAttack.OnCharacterAttackAction += PlayAttackAnimation;
        }
    }
        // Token: 0x06001CF5 RID: 7413 RVA: 0x00086D30 File Offset: 0x00084F30
        private static void OnBodyFirstStart(CharacterBody body)
        {
            CharacterMaster master = body.master;

            if (master)
            {
                master.onBodyStart -= StatManager.OnBodyFirstStart;
                PlayerCharacterMasterController component = master.GetComponent <PlayerCharacterMasterController>();
                if (component)
                {
                    PlayerStatsComponent component2 = component.GetComponent <PlayerStatsComponent>();
                    if (component2)
                    {
                        StatSheet currentStats = component2.currentStats;
                        currentStats.PushStatValue(PerBodyStatDef.timesPicked.FindStatDef(body.name), 1UL);
                        currentStats.PushStatValue(StatDef.totalGamesPlayed, 1UL);
                    }
                }
            }
        }
        // Token: 0x060027EE RID: 10222 RVA: 0x000AB700 File Offset: 0x000A9900
        private void OnMasterChanged()
        {
            PlayerCharacterMasterController cachedMasterController = base.localUser.cachedMasterController;

            this.playerStatsComponent = ((cachedMasterController != null) ? cachedMasterController.GetComponent <PlayerStatsComponent>() : null);
        }
Beispiel #8
0
        private void RegisterMiniRpcCMDs(MiniRpcInstance miniRpc)
        {
            // This command will be called by a client (including the host), and executed on the server (host)
            ExampleCommandHostCustom = miniRpc.RegisterAction(Target.Server, (user, x) =>
            {
                // This is what the server will execute when a client invokes the IRpcAction

                var str = x.ReadString();

                Debug.Log($"[Host] {user?.userName} sent us: {str}");

                if (str == "Buymenu")
                {
                    //Get a user id, starts from 0

                    List <NetworkUser> instancesList = typeof(NetworkUser).GetFieldValue <List <NetworkUser> >("instancesList");
                    int id = instancesList.IndexOf(user);
                    if (id < 0)
                    {
                        return;
                    }

                    //When the id is bigger than the count add items, with a default value of false
                    if (AllBuyMenuStates.Count - 1 < id)
                    {
                        for (int i = AllBuyMenuStates.Count - 1; i < id; i++)
                        {
                            AllBuyMenuStates.Add(false);
                        }
                    }

                    var doubleVal = x.ReadDouble();

                    bool state = doubleVal == 0.0 ? false : true;

                    AllBuyMenuStates[id] = state;

                    int check = AllBuyMenuStates.FindAll(a => a == true).Count;
                    Debug.Log(check);
                    if (check > 0)
                    {
                        ExampleCommandClientCustom.Invoke(y =>
                        {
                            y.Write("Timescale");
                            y.Write(.25);
                        });
                    }
                    else
                    {
                        ExampleCommandClientCustom.Invoke(y =>
                        {
                            y.Write("Timescale");
                            y.Write(1.0);
                        });
                    }
                }

                if (str == "CreatePickupDroplet_Item")
                {
                    ItemIndex item          = x.ReadItemIndex();
                    PickupIndex pickupIndex = new PickupIndex(item);
                    Vector3 pos             = x.ReadVector3();

                    RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos, Vector3.up * 10f);
                }

                if (str == "CreatePickupDroplet_Equipment")
                {
                    EquipmentIndex item     = x.ReadEquipmentIndex();
                    PickupIndex pickupIndex = new PickupIndex(item);
                    Vector3 pos             = x.ReadVector3();

                    RoR2.PickupDropletController.CreatePickupDroplet(pickupIndex, pos, Vector3.up * 10f);
                }

                if (str == "AddMoney")
                {
                    GameObject go = x.ReadGameObject();
                    int amount    = (int)x.ReadDouble();
                    PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>();

                    playerCharacterMaster.master.GiveMoney((uint)amount);
                }

                if (str == "AddExp")
                {
                    GameObject go = x.ReadGameObject();
                    int amount    = (int)x.ReadDouble();
                    PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>();

                    playerCharacterMaster.master.GiveExperience((uint)amount);
                }

                if (str == "FullHP")
                {
                    GameObject go = x.ReadGameObject();
                    PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>();

                    playerCharacterMaster.master.GetBody().healthComponent.health = playerCharacterMaster.master.GetBody().healthComponent.fullHealth;
                }

                if (str == "FullShield")
                {
                    GameObject go = x.ReadGameObject();
                    PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>();

                    playerCharacterMaster.master.GetBody().healthComponent.shield = playerCharacterMaster.master.GetBody().healthComponent.fullShield;
                }
            });

            // This command will be called by the host, and executed on all clients
            ExampleCommandClientCustom = miniRpc.RegisterAction(Target.Client, (user, x) =>
            {
                // This is what all clients will execute when the server invokes the IRpcAction

                var str = x.ReadString();

                Debug.Log($"[Client] Host sent us: {str}");

                if (str == "Reset")
                {
                    playerCharacterMaster = null;
                    //kills = 0;
                    if (this.playerCharacterMaster == null)
                    {
                        this.playerCharacterMaster = LocalUserManager.GetFirstLocalUser().cachedMasterController;
                    }

                    if (this.playerCharacterMaster.GetComponent <PlayerScript>() == null)
                    {
                        this.playerCharacterMaster.gameObject.AddComponent <PlayerScript>();
                        this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().ExampleCommandHostCustom = this.ExampleCommandHostCustom;
                        this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().config = config;
                        this.playerCharacterMaster.gameObject.GetComponent <PlayerScript>().AwakeManual();
                    }
                }

                if (str == "Timescale")
                {
                    var floatVal   = (float)x.ReadDouble();
                    Time.timeScale = floatVal;
                }


                if (str == "Kill")
                {
                    GameObject go = x.ReadGameObject();
                    PlayerCharacterMasterController playerCharacterMaster = go.GetComponent <PlayerCharacterMasterController>();

                    /*
                     * if (this.playerCharacterMaster == null)
                     *  this.playerCharacterMaster = LocalUserManager.GetFirstLocalUser().cachedMasterController;
                     */


                    if (playerCharacterMaster == this.playerCharacterMaster)
                    {
                        ++playerCharacterMaster.GetComponent <PlayerScript>().kills;
                        //Chat.AddMessage("Added Kill!\n\rNew Kill count is: " + ++playerCharacterMaster.GetComponent<PlayerScript>().kills);
                    }
                }
            });
        }