예제 #1
0
        private void doRecipe(Smod2.API.Item item, Scp914 objectOfType, Smod2.API.Player player, Smod2.API.KnobSetting knobSetting)
        {
            sbyte outputitem = -2;

            try
            {
                outputitem = (sbyte)(objectOfType.recipes[(byte)item.ItemType].outputs[(byte)knobSetting].outputs[getrandom.Next(0, objectOfType.recipes[(byte)item.ItemType].outputs[(byte)knobSetting].outputs.Count)]);
            }
            catch (System.Exception)
            {
                if (outputitem >= 0)
                {
                    this.plugin.Error("Recipe for " + item.ItemType + "does not exist!  Ask the game devs to add a recipe for it!");
                }
            }
            if (outputitem != -2)
            {
                item.Remove();
                this.plugin.Debug(item.ItemType + " ==> " + (ItemType)outputitem);
            }
            if (outputitem >= 0)
            {
                player.GiveItem((ItemType)outputitem);
            }
        }
예제 #2
0
        public void OnSCP914Activate(SCP914ActivateEvent ev)
        {
            if (!SI_Config.si_914enable)
            {
                return;
            }
            Scp914 scp914 = GameObject.FindObjectOfType <Scp914>();

            if (scp914 == null)
            {
                plugin.Error("914 cannot be found.");
                return;
            }
            foreach (UnityEngine.Collider collider in ev.Inputs)
            {
                if (collider.GetComponent <Inventory>() != null)
                {
                    Smod2.API.Player play = new ServerMod2.API.SmodPlayer(collider.gameObject);

                    if (SI_Config.si_914handorinv == 1)                     // Don't know if passing the collider will work the way I want it to work so I'm just gonna pray to the unity gods for a bug free experience.
                    {
                        _914Manager.DoHand914(collider, ev.OutputPos, ev.KnobSetting, scp914);
                    }
                    else if (SI_Config.si_914handorinv == 2)
                    {
                        _914Manager.DoInventory914(collider, ev.OutputPos, ev.KnobSetting, scp914);
                    }
                    else if (SI_Config.si_914handorinv == 0)
                    {
                        CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
                        CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject, true);
                    }
                }
            }
        }
예제 #3
0
        public void OnSCP914Activate(SCP914ActivateEvent ev)
        {
            if (!enabled)
            {
                return;
            }
            object[] inputs       = ev.Inputs;
            Scp914   objectOfType = UnityEngine.Object.FindObjectOfType <Scp914>();

            if ((UnityEngine.Object)objectOfType == (UnityEngine.Object)null)
            {
                this.plugin.Error("Couldnt find SCP-914");
                return;
            }
            //            string[] strArray = new string[5] { "Very Rough", "Rough", "1 to 1", "Fine", "Very Fine" };
            //            for (byte index1 = 0; index1 < objectOfType.recipes.Length; ++index1) //item id
            //            {
            //                this.plugin.Debug("==== Recipe for: " + component.availableItems[index1].label + " ====");
            //                for (byte index2 = 0; index2 < objectOfType.recipes[index1].outputs.Count; ++index2) //knob setting id
            //                {
            //                    foreach(sbyte itm in objectOfType.recipes[index1].outputs[index2].outputs) //output item id
            //                    {
            //                        this.plugin.Debug(strArray[index2] + ": " + (itm == -1 ? "NULL" : component.availableItems[itm].label));
            //                    }
            //                }
            //            }
            foreach (UnityEngine.Collider collider in inputs)
            {
                Pickup component1 = collider.GetComponent <Pickup>();
                if ((UnityEngine.Object)component1 == (UnityEngine.Object)null)
                {
                    NicknameSync          component2 = collider.GetComponent <NicknameSync>();
                    CharacterClassManager component3 = collider.GetComponent <CharacterClassManager>();
                    PlyMovementSync       component4 = collider.GetComponent <PlyMovementSync>();
                    PlayerStats           component5 = collider.GetComponent <PlayerStats>();
                    if ((UnityEngine.Object)component2 != (UnityEngine.Object)null && (UnityEngine.Object)component3 != (UnityEngine.Object)null && ((UnityEngine.Object)component4 != (UnityEngine.Object)null && (UnityEngine.Object)component5 != (UnityEngine.Object)null) && (UnityEngine.Object)collider.gameObject != (UnityEngine.Object)null)
                    {
                        UnityEngine.GameObject    gameObject = collider.gameObject;
                        ServerMod2.API.SmodPlayer player     = new ServerMod2.API.SmodPlayer(gameObject);
                        if (player.TeamRole.Team != Smod2.API.Team.SCP && player.TeamRole.Team != Smod2.API.Team.NONE && player.TeamRole.Team != Smod2.API.Team.SPECTATOR)
                        {
                            if (currentonly)
                            {
                                Smod2.API.Item item = player.GetCurrentItem();
                                doRecipe(item, objectOfType, player, ev.KnobSetting);
                            }
                            else
                            {
                                foreach (Smod2.API.Item item in player.GetInventory())
                                {
                                    doRecipe(item, objectOfType, player, ev.KnobSetting);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        private static bool Prefix(Scp914Machine __instance)
        {
            if (!NetworkServer.active)
            {
                return(true);
            }
            Collider[] colliderArray = Physics.OverlapBox(__instance.intake.position, __instance.inputSize / 2f);
            __instance.players.Clear();
            __instance.items.Clear();
            foreach (Collider collider in colliderArray)
            {
                CharacterClassManager component1 = collider.GetComponent <CharacterClassManager>();
                if (component1 != null)
                {
                    __instance.players.Add(component1);
                }
                else
                {
                    Pickup component2 = collider.GetComponent <Pickup>();
                    if (component2 != null)
                    {
                        __instance.items.Add(component2);
                    }
                }
            }

            var ev = new UpgradingItemsEventArgs(__instance, __instance.players.Select(player => API.Features.Player.Get(player.gameObject)).ToList(), __instance.items, __instance.knobState);

            Scp914.OnUpgradingItems(ev);

            var players = ev.Players.Select(player => player.ReferenceHub.characterClassManager).ToList();

            __instance.MoveObjects(ev.Items, players);

            if (ev.IsAllowed)
            {
                __instance.UpgradeObjects(ev.Items, players);
            }

            return(false);
        }
예제 #5
0
        private static bool Prefix(PlayerInteract __instance)
        {
            if (!__instance._playerInteractRateLimit.CanExecute(true) ||
                (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract) ||
                (Scp914Machine.singleton.working || !__instance.ChckDis(Scp914Machine.singleton.button.position)))
            {
                return(false);
            }

            var ev = new ActivatingEventArgs(API.Features.Player.Get(__instance.gameObject), 0);

            Scp914.OnActivating(ev);

            if (ev.IsAllowed)
            {
                Scp914Machine.singleton.RpcActivate(NetworkTime.time + ev.Duration);
                __instance.OnInteract();
            }

            return(false);
        }
예제 #6
0
        private static bool Prefix(PlayerInteract __instance)
        {
            if (!__instance._playerInteractRateLimit.CanExecute(true) ||
                (__instance._hc.CufferId > 0 && !PlayerInteract.CanDisarmedInteract) ||
                Scp914Machine.singleton.working || !__instance.ChckDis(Scp914Machine.singleton.knob.position) ||
                Math.Abs(Scp914Machine.singleton.curKnobCooldown) > 0.001f)
            {
                return(false);
            }

            var ev = new ChangingKnobSettingEventArgs(API.Features.Player.Get(__instance.gameObject), Scp914Machine.singleton.knobState + 1);

            Scp914.OnChangingKnobSetting(ev);

            if (ev.IsAllowed)
            {
                Scp914Machine.singleton.NetworkknobState = ev.KnobSetting;
                Scp914Machine.singleton.curKnobCooldown  = Scp914Machine.singleton.knobCooldown;
                __instance.OnInteract();
            }

            return(false);
        }
예제 #7
0
        private void ParseRecipies(byte mode)
        {
            Scp914 objectOfType = UnityEngine.Object.FindObjectOfType <Scp914>();

            if ((UnityEngine.Object)objectOfType == (UnityEngine.Object)null)
            {
                this.plugin.Error("Couldnt find SCP-914");
            }
            else
            {
                string createText = "THIS IS NOT THE CONFIG FILE, JUST A REFERENCE!" + System.Environment.NewLine;
                for (byte index1 = 0; index1 < objectOfType.recipes.Length; ++index1)                 //item id
                {
                    if (mode == 0)
                    {
                        createText = createText + "==== Recipe for: " + (ItemType)index1 + " ====" + System.Environment.NewLine;
                    }
                    for (byte index2 = 0; index2 < objectOfType.recipes[index1].outputs.Count; ++index2)                     //knob setting id
                    {
                        if (mode == 1)
                        {
                            string[] configsetting = this.plugin.GetConfigList((ItemType)index1 + "__" + (KnobSetting)index2);
                            if (configsetting.Length != 0)
                            {
                                System.Collections.Generic.List <int> bak = objectOfType.recipes[index1].outputs[index2].outputs;
                                objectOfType.recipes[index1].outputs[index2].outputs.Clear();
                                foreach (string confitm in configsetting)
                                {
                                    this.plugin.Debug("converting/checking: " + confitm);
                                    sbyte result;
                                    bool  error = false;
                                    if (System.SByte.TryParse(confitm, out result))
                                    {
                                        //they used an itemid
                                        this.plugin.Debug("used an itemid of " + result);
                                        if (!System.Enum.IsDefined(typeof(ItemType), (int)result))
                                        {
                                            error = true;
                                        }
                                    }
                                    else if (System.Enum.IsDefined(typeof(ItemType), confitm))
                                    {
                                        //they used an enum
                                        this.plugin.Debug(confitm + " is a valid itemENUM");
                                        result = (sbyte)(ItemType)System.Enum.Parse(typeof(ItemType), confitm);
                                    }
                                    else
                                    {
                                        error = true;
                                    }
                                    if (error)
                                    {
                                        objectOfType.recipes[index1].outputs[index2].outputs = bak;
                                        this.plugin.Error("Config for " + (ItemType)index1 + "__" + (KnobSetting)index2 + " Contains an illegal value of " + confitm + ",  It must be an ItemID or a ItemENUM that exist.  The default value backup was restored.");
                                    }
                                    else
                                    {
                                        objectOfType.recipes[index1].outputs[index2].outputs.Add(result);
                                    }
                                }
                            }
                        }

                        foreach (sbyte itm in objectOfType.recipes[index1].outputs[index2].outputs)                         //output item id
                        {
                            if (mode == 0)
                            {
                                createText = createText + (KnobSetting)index2 + ": " + (ItemType)itm + System.Environment.NewLine;
                            }
                        }
                        if (mode == 0)
                        {
                            this.plugin.AddConfig(new Smod2.Config.ConfigSetting((ItemType)index1 + "__" + (KnobSetting)index2, new string[] { }, Smod2.Config.SettingType.LIST, true, ""));
                        }
                    }
                    if (mode == 0)
                    {
                        createText = createText + System.Environment.NewLine;
                    }
                }
                if (mode == 0)
                {
                    initialload = false;
                    System.IO.File.WriteAllText("./914.txt", createText);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Does a full 914 pass on the user's held item.
        /// </summary>
        /// <param name="collider">Player</param>
        /// <param name="OutputPos">Smod2 Vector on the output of 914</param>
        /// <param name="knobSetting">Current 914 knob setting</param>
        /// <param name="scp914">914</param>
        public void DoHand914(UnityEngine.Collider collider, Vector OutputPos, KnobSetting knobSetting, Scp914 scp914)
        {
            Smod2.API.Player play = new ServerMod2.API.SmodPlayer(collider.gameObject);

            if (play.GetCurrentItem() == null || play.GetCurrentItemIndex() == -1 || play.GetCurrentItem().ItemType == ItemType.USP || stackManager.ContainsWeapon((int)play.GetCurrentItem().ItemType) && knobSetting == KnobSetting.ONE_TO_ONE)
            {
                StackEventHandler.CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
                StackEventHandler.CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject, true);
                return;
            }
            Smod2.API.ItemType currentItem = play.GetCurrentItem().ItemType;
            int itemIndex = -1;

            Dictionary <int, List <Inventory.SyncItemInfo> > TempGetItemsByItemType = new Dictionary <int, List <Inventory.SyncItemInfo> >();       //This is for seeing a item's index in inventory

            foreach (var item in collider.gameObject.GetComponent <Inventory>().items)
            {
                if (TempGetItemsByItemType.ContainsKey(item.id))
                {
                    TempGetItemsByItemType[item.id].Add(item);
                    if (item.uniq == collider.gameObject.GetComponent <Inventory>().GetItemInHand().uniq)
                    {
                        itemIndex = TempGetItemsByItemType[item.id].IndexOf(item) + 1;
                    }
                }
                else
                {
                    TempGetItemsByItemType.Add(item.id, new List <Inventory.SyncItemInfo> {
                        item
                    });
                    if (item.uniq == collider.gameObject.GetComponent <Inventory>().GetItemInHand().uniq)
                    {
                        itemIndex = TempGetItemsByItemType[item.id].IndexOf(item) + 1;
                    }
                }
            }
            play.GetCurrentItem().Remove();
            int AmountOfItems = -1;

            if (TempGetItemsByItemType[(int)currentItem].Count == itemIndex)
            {
                AmountOfItems = (int)Math.Ceiling(StackEventHandler.CheckSteamIDItemNum[play.SteamId].GetItemAmount((int)currentItem) % (float)stackManager.GetStackSize((int)currentItem));
                if (AmountOfItems == 0)
                {
                    AmountOfItems = stackManager.GetStackSize((int)currentItem);
                }
            }
            else
            {
                AmountOfItems = stackManager.GetStackSize((int)currentItem);
            }

            if (stackManager.GetStackSize((int)currentItem) == 1)
            {
                AmountOfItems = 1;
            }

            StackEventHandler.CheckSteamIDItemNum[play.SteamId].AddItemAmount((int)currentItem, AmountOfItems * -1);

            for (int i = 0; i < AmountOfItems; i++)
            {
                int newitem = GetRandom914ItemByKnob(scp914, (int)currentItem, (int)knobSetting);
                if (newitem != -1 || ConfigOptions.si_914itemstosave.Contains(newitem))
                {
                    if (play.GetInventory().Count == 8)
                    {
                        Smod2.PluginManager.Manager.Server.Map.SpawnItem((ItemType)newitem, OutputPos, new Vector(0, 0, 0));
                    }
                    else
                    {
                        StackEventHandler.CheckSteamIDItemNum[play.SteamId].AddItemAmount(newitem, 1);
                    }
                }
            }

            StackEventHandler.CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
            StackEventHandler.CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject, true);
        }
예제 #9
0
 /// <summary>
 /// Gets randomized 914 outout recipe
 /// </summary>
 /// <param name="scp914">914</param>
 /// <param name="item">item to get recipe for</param>
 /// <param name="KnobSetting">914 knob setting</param>
 /// <returns></returns>
 public int GetRandom914ItemByKnob(Scp914 scp914, int item, int KnobSetting)
 {
     return(scp914.recipes[(byte)((ItemType)item)].outputs[(byte)KnobSetting].outputs[UnityEngine.Random.Range(0, scp914.recipes[(byte)((ItemType)item)].outputs[(byte)KnobSetting].outputs.Count)]);
     //shoutout to https://github.com/storm37000/SCPSL_Smod_914_held_items/blob/99cfbc282524412018d5fd53bb6fa92838a5ebc1/EventHandler.cs#L85
 }
예제 #10
0
        /// <summary>
        /// Does a pass on every item in the user's inventory
        /// </summary>
        /// <param name="collider">player collider</param>
        /// <param name="OutputPos">smod2 vector of output pos of 914</param>
        /// <param name="knobSetting">current knobsetting of 914</param>
        /// <param name="scp914">scp914</param>
        public void DoInventory914(UnityEngine.Collider collider, Vector OutputPos, KnobSetting knobSetting, Scp914 scp914)
        {
            Smod2.API.Player play = new ServerMod2.API.SmodPlayer(collider.gameObject);
            List <Inventory.SyncItemInfo> TempItems = new List <Inventory.SyncItemInfo>();

            TempItems.AddRange(collider.GetComponent <Inventory>().items);

            Dictionary <int, int> TempListOfItems = new Dictionary <int, int>();

            foreach (KeyValuePair <int, int> TypeAndAmount in StackEventHandler.CheckSteamIDItemNum[play.SteamId].checkItemTypeForNumOfItems)
            {
                TempListOfItems[TypeAndAmount.Key] = TypeAndAmount.Value;
            }
            StackEventHandler.CheckSteamIDItemNum[play.SteamId].ResetToZero();

            foreach (Inventory.SyncItemInfo item in TempItems)
            {
                if (!ConfigOptions.si_914itemstosave.Contains(item.id) && item.id != 30)
                {
                    double ItemAmount;

                    if (TempListOfItems.ContainsKey(item.id) && !stackManager.ContainsWeapon(item.id))
                    {
                        int TempItemAmount = (int)(TempListOfItems[item.id] - Math.Ceiling(TempListOfItems[item.id] / (float)stackManager.GetStackSize(item.id)));
                        if (TempItemAmount >= stackManager.GetStackSize(item.id))
                        {
                            ItemAmount = stackManager.GetStackSize(item.id);
                            TempListOfItems[item.id] -= stackManager.GetStackSize(item.id);
                        }
                        else
                        {
                            ItemAmount = TempListOfItems[item.id];
                            TempListOfItems[item.id] = 0;
                        }
                    }
                    else
                    {
                        ItemAmount = 1;
                    }
                    collider.GetComponent <Inventory>().items.Remove(item);
                    for (int i = 0; i < (int)ItemAmount; i++)
                    {
                        int newitem = GetRandom914ItemByKnob(scp914, item.id, (int)knobSetting);
                        if (newitem != -1)
                        {
                            if (play.GetInventory().Count == 8)
                            {
                                Smod2.PluginManager.Manager.Server.Map.SpawnItem((ItemType)newitem, OutputPos, new Vector(0, 0, 0));
                            }
                            else
                            {
                                StackEventHandler.CheckSteamIDItemNum[play.SteamId].AddItemAmount(newitem, 1);
                            }
                        }
                    }
                }
            }

            StackEventHandler.CheckSteamIDItemNum[play.SteamId].TransferItems(collider.gameObject);
            StackEventHandler.CheckSteamIDItemNum[play.SteamId].ApplyTransferedItems(collider.gameObject);
        }