示例#1
0
        private void Player_PlayerSetClassEvent(PlayerSetClassEventArgs ev)
        {
            Timing.CallDelayed(0.01f, () =>
            {
                if (CustomLoadout.Config.RoleInventory.Any((_) => _.RoleID == ev.Player.RoleID))
                {
                    var loadout = CustomLoadout.Config.RoleInventory.FirstOrDefault((_) => _.RoleID == ev.Player.RoleID);
                    if (loadout is null)
                    {
                        return;
                    }

                    uint ammo5 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo5 : ev.Player.Ammo5;
                    uint ammo7 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo7 : ev.Player.Ammo7;
                    uint ammo9 = loadout.AmmoConfig.ReplaceAmmo ? loadout.AmmoConfig.Ammo9 : ev.Player.Ammo9;

                    if (loadout.ReplaceDefault)
                    {
                        ev.Player.Inventory.Clear();
                    }

                    foreach (var item in loadout.Items)
                    {
                        if (UnityEngine.Random.Range(0f, 100f) <= item.Chance)
                        {
                            ev.Player.Inventory.AddItem(item.Item.Parse());
                        }

                        ev.Player.Ammo5 = ammo5;
                        ev.Player.Ammo7 = ammo7;
                        ev.Player.Ammo9 = ammo9;
                    }
                }
            });
        }
示例#2
0
 private void Player_PlayerSetClassEvent(PlayerSetClassEventArgs ev)
 {
     if (ev.Role != RoleType.ClassD && ev.Role != RoleType.Scp173)
     {
         ev.Allow = false;
     }
 }
示例#3
0
 private void Player_PlayerSetClassEvent(PlayerSetClassEventArgs ev)
 {
     if (ev.Role == RoleType.Scp049)
     {
         Doctors.Add(new DoctorStats()
         {
             Player = ev.Player, Streak = 0
         });
     }
 }
 public void OnSetClass(PlayerSetClassEventArgs ev)
 {
     if (ev.Player.RealTeam != Team.SCP)
     {
         return;
     }
     if (_plugin.LockdownService.TryGetCoroutines(ev.Player, out IEnumerable <CoroutineHandle> coroutines))
     {
         Timing.KillCoroutines(coroutines.ToArray());
         ev.Player.GodMode = false;
     }
 }
示例#5
0
 public void OnSetClass(PlayerSetClassEventArgs ev)
 {
     if (ev.Role == RoleType.Scp93989)
     {
         int s = Random.Range(1, 100);
         if (s <= SCP682.Config.spawn_chance)
         {
             Timing.CallDelayed(0.1f, () =>
             {
                 ev.Player.RoleID = 682;
             });
         }
     }
 }
示例#6
0
 internal void InvokeSetClassEvent(PlayerSetClassEventArgs ev) => PlayerSetClassEvent?.Invoke(ev);
        private static bool Prefix(CharacterClassManager __instance, ref PlayerSetClassEventArgs __state, ref RoleType classid, GameObject ply, ref bool escape, bool lite)
        {
            try
            {
                if (!NetworkServer.active || ply == null)
                {
                    return(false);
                }
                var player = ply.GetPlayer();
                if (player.Hub.isDedicatedServer || !player.Hub.Ready)
                {
                    return(false);
                }

                __state = new PlayerSetClassEventArgs
                {
                    EscapeItems = new List <SynapseItem>(),
                    IsEscaping  = escape,
                    Allow       = true,
                    Player      = player,
                    Role        = classid,
                    Items       = new List <SynapseItem>(),
                    Position    = Vector3.zero,
                    Rotation    = 0f
                };

                if (escape && CharacterClassManager.KeepItemsAfterEscaping && !lite)
                {
                    __state.EscapeItems = player.Inventory.Items;
                }

                if (!lite)
                {
                    foreach (var id in __instance.Classes.SafeGet(classid).startItems)
                    {
                        var synapseitem = new SynapseItem(id, 0, 0, 0, 0);
                        var item        = new Item(player.VanillaInventory.GetItemByID(id));
                        synapseitem.Durabillity = item.durability;

                        for (int i = 0; i < player.VanillaInventory._weaponManager.weapons.Length; i++)
                        {
                            if (player.VanillaInventory._weaponManager.weapons[i].inventoryID == id)
                            {
                                synapseitem.Sight  = player.VanillaInventory._weaponManager.modPreferences[i, 0];
                                synapseitem.Barrel = player.VanillaInventory._weaponManager.modPreferences[i, 1];
                                synapseitem.Other  = player.VanillaInventory._weaponManager.modPreferences[i, 2];
                            }
                        }

                        __state.Items.Add(synapseitem);
                    }
                }

                if (__instance.Classes.SafeGet(classid).team != Team.RIP)
                {
                    if (lite)
                    {
                        __state.Position = player.Position;
                    }
                    else
                    {
                        if (Synapse.Api.Map.Get.RespawnPoint != Vector3.zero)
                        {
                            __state.Position = Synapse.Api.Map.Get.RespawnPoint;
                        }
                        else
                        {
                            var randomPosition = CharacterClassManager._spawnpointManager.GetRandomPosition(classid);
                            if (randomPosition != null)
                            {
                                __state.Position = randomPosition.transform.position;
                                __state.Rotation = randomPosition.transform.rotation.eulerAngles.y;
                            }
                            else
                            {
                                __state.Position = player.DeathPosition;
                            }
                        }
                    }
                }

                try
                {
                    Server.Get.Events.Player.InvokeSetClassEvent(__state);
                }
                catch (Exception e)
                {
                    Logger.Get.Error($"Synapse-Event: PlayerSetClass failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
                }

                if (!__state.Allow)
                {
                    return(false);
                }
                classid = __state.Role;

                foreach (var item in __state.EscapeItems)
                {
                    item.Despawn();
                }

                //WHY THE F**K DOES SCP NOT USE THEIR OWN METHODS TO CLEAR THE INVENTORY THAT I ALREADY PATCHED?
                player.Inventory.Clear();

                player.spawnPosition = __state.Position;
                player.spawnRotation = __state.Rotation;
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerSetClass Prefix failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
            }
            return(true);
        }
        private static void Postfix(CharacterClassManager __instance, PlayerSetClassEventArgs __state, RoleType classid, bool lite)
        {
            try
            {
                if (lite)
                {
                    return;
                }
                if (__state == null)
                {
                    return;
                }
                if (!__state.Allow)
                {
                    return;
                }

                var player = __state.Player;

                player.Inventory.Clear();
                var role = player.ClassManager.Classes.SafeGet(classid);
                if (role.roleId != RoleType.Spectator)
                {
                    player.Ammo5 = role.ammoTypes[0];
                    player.Ammo7 = role.ammoTypes[1];
                    player.Ammo9 = role.ammoTypes[2];
                }
                foreach (var item in __state.Items)
                {
                    player.Inventory.AddItem(item);
                }

                if (__state.EscapeItems.Count == 0)
                {
                    return;
                }
                foreach (var item in __state.EscapeItems)
                {
                    if (CharacterClassManager.PutItemsInInvAfterEscaping)
                    {
                        var itemByID   = player.VanillaInventory.GetItemByID(item.ItemType);
                        var flag       = false;
                        var categories = __instance._search.categories;
                        int i          = 0;
                        while (i < categories.Length)
                        {
                            var invcategorie = categories[i];
                            if (invcategorie.itemType == itemByID.itemCategory && itemByID.itemCategory != ItemCategory.None)
                            {
                                int num = 0;
                                foreach (var sync in player.VanillaInventory.items)
                                {
                                    if (player.VanillaInventory.GetItemByID(sync.id).itemCategory == itemByID.itemCategory)
                                    {
                                        num++;
                                    }
                                }

                                if (num >= (int)invcategorie.maxItems)
                                {
                                    flag = true;
                                    break;
                                }
                                break;
                            }
                            else
                            {
                                i++;
                            }
                        }

                        if (player.VanillaInventory.items.Count >= 8 || (flag && !item.IsCustomItem))
                        {
                            item.Drop(__instance._pms.RealModelPosition);
                        }
                        else
                        {
                            item.PickUp(player);
                        }
                    }
                    else
                    {
                        item.Drop(__instance._pms.RealModelPosition);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerSetClass Postfix failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
            }
        }
        private static bool OnSetClass(ref RoleType classid, GameObject ply, CharacterClassManager.SpawnReason spawnReason)
        {
            try
            {
                var player = ply.GetPlayer();

                if (player.Hub.isDedicatedServer || !player.Hub.Ready)
                {
                    return(false);
                }

                //Initialise eventargs
                var eventargs = new PlayerSetClassEventArgs
                {
                    Allow       = true,
                    Player      = player,
                    Role        = classid,
                    SpawnReason = spawnReason,
                    EscapeItems = new List <SynapseItem>(),
                    Position    = Vector3.zero,
                    Rotation    = 0f,
                    Items       = new List <SynapseItem>(),
                    Ammo        = new Dictionary <AmmoType, ushort>(),
                };

                //Set EscapeItems if the Player is escaping
                if (eventargs.IsEscaping)
                {
                    eventargs.EscapeItems = player.Inventory.Items;
                }

                //Find the Position and Rotation if the player becomes a living Role
                if (classid != RoleType.Spectator && classid != RoleType.None)
                {
                    var randomPosition = SpawnpointManager.GetRandomPosition(classid);
                    if (Map.Get.RespawnPoint != Vector3.zero)
                    {
                        eventargs.Position = Map.Get.RespawnPoint;
                    }
                    else if (randomPosition != null)
                    {
                        eventargs.Position = randomPosition.transform.position;
                        eventargs.Rotation = randomPosition.transform.rotation.eulerAngles.y;
                    }
                    else
                    {
                        eventargs.Position = player.ClassManager.DeathPosition;
                    }
                }

                //Find and create the Items that the Player should spawn with
                if (InventorySystem.Configs.StartingInventories.DefinedInventories.TryGetValue(classid, out var roleitems))
                {
                    foreach (var ammo in roleitems.Ammo)
                    {
                        eventargs.Ammo[(AmmoType)ammo.Key] = ammo.Value;
                    }

                    foreach (var itemtype in roleitems.Items)
                    {
                        eventargs.Items.Add(new SynapseItem(itemtype));
                    }
                }

                Server.Get.Events.Player.InvokeSetClassEvent(eventargs);

                classid = eventargs.Role;

                if (eventargs.Allow)
                {
                    player.setClassEventArgs = eventargs;
                }

                return(eventargs.Allow);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerSetClass(SetPlayersClass) failed!!\n{e}");
                return(true);
            }
        }