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); } } } } } } }
/// <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); }