public override void InvokeServer(Dictionary <string, string> contents) { string username = contents["Target"]; string idStr = contents["Id"]; string amtStr = contents["Amount"]; if (!int.TryParse(amtStr, out int amt)) { amt = 1; } NetworkUser user = UnityUtils.GetNetworkUserWithName(username); if (user == null) { SandboxMain.Log($"Unable to find user with name {username}"); return; } if (Enum.TryParse(idStr, true, out ItemIndex item)) { user.GetCurrentBody().inventory.GiveItem(item, amt); } else if (Enum.TryParse(idStr, true, out EquipmentIndex _)) { user.GetCurrentBody().inventory.GiveEquipmentString(idStr); } }
public void SetHale(NetworkUser networkUser) { if (networkUser) { if (networkUsers.Contains(networkUser)) { currentHale = networkUser; bossMemory = new BossGroup.BossMemory() { cachedMaster = currentHale.master, cachedBody = currentHale.GetCurrentBody() }; combatSquad = new CombatSquad(); combatSquad.AddMember(currentHale.master); bossGroup = new BossGroup() { combatSquad = this.combatSquad, bestObservedName = currentHale.userName, bestObservedSubtitle = "The Boss", }; bossGroup.AddBossMemory(currentHale.master); bossGroup.combatSquad = combatSquad; } else { Debug.LogError("Couldn't find NetworkUser" + networkUser + "in list of available NetworkUsers"); } } else { Debug.LogError("NetworkUser " + networkUser + " does not exist!"); } }
public void FixedUpdate() { if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "lobby" && PlayerCharacterMasterController.instances[0]?.master?.gameObject.GetComponent <LAIIntializer>()) { if (!hasTeleported) { if (sender.GetCurrentBody()) { RoR2.Console.instance.SubmitCmd(sender, "setpos 1 1 11", true); hasTeleported = true; } } if (MainCamera) { MainCamera.SetActive(enableMainCamera); } if (CharacterPadAlignments) { CharacterPadAlignments.SetActive(enableCharacterPadAlignments); } if (CharacterSelectUI) { CharacterSelectUI.SetActive(enableCharacterSelectUI); } // Pseudo-Commands if (PrintCurrentPosition) { RoR2.Console.instance.SubmitCmd(sender, "getpos", true); PrintCurrentPosition = false; } } }
IEnumerator WaitForStart(NetworkUser player) { yield return(null); var healthComponent = player.GetCurrentBody().healthComponent; healthComponent.health = health; healthComponent.shield = shields; }
public override void Set(NetworkUser user, string value) { var b = user.GetCurrentBody(); if (b == null) { return; } b.baseJumpCount = int.Parse(value); }
public override string Get(NetworkUser user) { var b = user.GetCurrentBody(); if (b == null) { return("null"); } return(b.baseJumpCount.ToString()); }
public override void Set(NetworkUser user, string value) { var b = user.GetCurrentBody(); if (b == null) { return; } Traverse.Create(b).Field(Name).SetValue(float.Parse(value)); }
public override string Get(NetworkUser user) { var b = user.GetCurrentBody(); if (b == null) { return("null"); } return(((float)Traverse.Create(b).Field(Name).GetValue()).ToString()); }
public PlayerData(NetworkUser player) { var inventory = player.master.inventory; var healthComponent = player.GetCurrentBody().GetComponent <HealthComponent>(); deployables = new List <DeployableData>(); transform = new SerializableTransform(player.GetCurrentBody().transform); username = player.userName; alive = player.master.alive; money = (int)player.master.money; health = (int)healthComponent.health; shields = (int)healthComponent.shield; infusion = (int)inventory.infusionBonus; items = new int[(int)ItemIndex.Count - 1]; for (int i = 0; i < (int)ItemIndex.Count - 1; i++) { items[i] = inventory.GetItemCount((ItemIndex)i); } equipItem0 = (int)inventory.GetEquipment(0).equipmentIndex; equipItem1 = (int)inventory.GetEquipment(1).equipmentIndex; equipItemCount = inventory.GetEquipmentSlotCount(); characterBodyName = player.master.bodyPrefab.name; var deployablesList = player.master.GetFieldValue <List <DeployableInfo> >("deployablesList"); if (deployablesList != null) { foreach (var item in deployablesList) { deployables.Add(new DeployableData(item.deployable)); } } }
// Spawn on another player (or self) by default to avoid softlocking by spawning outside a restricted area private static Transform GetSpawnTransformForPlayer(NetworkUser player) { Transform spawnTransform = player.GetCurrentBody()?.transform; if (spawnTransform == null) { Logger.LogMessage($"{player.userName} does not have a current body, spawning on another player"); spawnTransform = NetworkUser.readOnlyInstancesList .Where(user => user.GetCurrentBody() != null).FirstOrDefault()?.GetCurrentBody().transform; } if (spawnTransform == null) { Logger.LogMessage($"Unable to find alive player for {player.userName} to spawn on, defaulting to map spawn"); spawnTransform = Stage.instance.GetPlayerSpawnTransform(); } return(spawnTransform); }
private static JoinAsResult RespawnExistingPlayerWithBody(NetworkUser player, BodyIndex newBodyIndex) { GameObject oldBodyPrefab = player.master.bodyPrefab; player.CmdSetBodyPreference(newBodyIndex); JoinAsResult result = JoinAsResult.Success; if (player.GetCurrentBody() == null && player.master.lostBodyToDeath && !DropInConfig.AllowRespawn.Value) { Logger.LogMessage($"Unable immediately to spawn {player.userName} with bodyIndex = {newBodyIndex} due to being player being dead and AllowRespawn being set to false"); result = JoinAsResult.DeadAndNotAllowRespawn; } else { Transform spawnTransform = GetSpawnTransformForPlayer(player); player.master.Respawn(spawnTransform.position, spawnTransform.rotation); } HandleBodyItems(player, oldBodyPrefab, BodyCatalog.GetBodyPrefab(newBodyIndex)); return(result); }
private static void CCCreatePickup(ConCommandArgs args) { args.CheckArgumentCount(1); if (args.sender == null) { if (args.Count <= 3) { Log.Message(Lang.DS_REQUIREFULLQUALIFY, LogLevel.Error); return; } } NetworkUser player = args.sender; if (args.Count >= 3) { player = Util.GetNetUserFromString(args.userArgs, 2); if (player == null) { Log.Message(Lang.PLAYER_NOTFOUND, LogLevel.MessageClientOnly); if (args.sender == null) { return; } player = args.sender; } } Transform transform = player.GetCurrentBody().gameObject.transform; bool searchEquip = true, searchItem = true; if (args.Count == 2) { if (args[1].Equals("item", StringComparison.OrdinalIgnoreCase)) { searchEquip = false; } if (args[1].ToUpper().StartsWith("EQUIP")) { searchItem = false; } } PickupIndex final = PickupIndex.none; EquipmentIndex equipment = EquipmentIndex.None; ItemIndex item = ItemIndex.None; if (searchEquip) { equipment = StringFinder.Instance.GetEquipFromPartial(args[0]); final = PickupCatalog.FindPickupIndex(equipment); } if (searchItem) { item = StringFinder.Instance.GetItemFromPartial(args[0]); final = PickupCatalog.FindPickupIndex(item); } if (item != ItemIndex.None && equipment != EquipmentIndex.None) { Log.MessageNetworked(string.Format(Lang.CREATEPICKUP_AMBIGIOUS_2, item, equipment), args, LogLevel.MessageClientOnly); return; } if (item == ItemIndex.None && equipment == EquipmentIndex.None) { if (args[0].ToUpper().Contains("COIN")) { final = PickupCatalog.FindPickupIndex("LunarCoin.Coin0"); } else { Log.MessageNetworked(Lang.CREATEPICKUP_NOTFOUND, args, LogLevel.MessageClientOnly); return; } } Log.MessageNetworked(string.Format(Lang.CREATEPICKUP_SUCCES_1, final), args); PickupDropletController.CreatePickupDroplet(final, transform.position, transform.forward * 40f); }
public void Awake() { // Load in our assets Assembly execAssembly = Assembly.GetExecutingAssembly(); using (Stream stream = execAssembly.GetManifestResourceStream("MP4Player.mp4player")) { AssetBundle bundle = AssetBundle.LoadFromStream(stream); _mp4Prefab = bundle.LoadAsset <GameObject>("Assets/mp4player.prefab"); } // Intercept people typing URLs in chat so we can put a video player on their head On.RoR2.Chat.UserChatMessage.ConstructChatString += (orig, self) => { if (self.sender) { NetworkUser component = self.sender.GetComponent <NetworkUser>(); if (component != null && self.text != null && self.sender != null && component.GetCurrentBody() != null) { if (self.text.StartsWith("http")) // when a user sends a message containing a link, load it into the videoplayer { GameObject mp4Player; if (component.GetCurrentBody().GetComponentInChildren <VideoPlayer>() == null) { mp4Player = UnityEngine.Object.Instantiate <GameObject>(_mp4Prefab, component.GetCurrentBody().transform.position + new Vector3(0f, 0.4f, 0f), Quaternion.identity); mp4Player.transform.parent = component.GetCurrentBody().transform; } else { mp4Player = component.GetCurrentBody().GetComponentInChildren <VideoPlayer>().gameObject; } mp4Player.GetComponent <VideoPlayer>().enabled = true; mp4Player.GetComponent <VideoPlayer>().url = self.text; } else // if they send any other message disable the current videoplayer { if (component.GetCurrentBody().GetComponentInChildren <VideoPlayer>() != null) { component.GetCurrentBody().GetComponentInChildren <VideoPlayer>().enabled = false; } } } } return(orig(self)); }; On.RoR2.AudioManager.VolumeConVar.SetString += (orig, self, newValue) => { orig(self, newValue); if (self.name == "volume_master") { _volumeMaster = float.Parse(newValue); } else if (self.name == "volume_sfx") { _volumeSFX = float.Parse(newValue); } var dbVolume = Mathf.Log10(_volumeSFX * _volumeMaster / 100) * 20 - 40f; // convert % volume to decibels -80 dB to 0 dB if (_volumeSFX == 0.0f || _volumeMaster == 0.0f) { dbVolume = -80.0f; } _mp4Prefab.GetComponent <AudioSource>().outputAudioMixerGroup.audioMixer.SetFloat("sfx_volume", dbVolume); }; }