public void Bind(BlueprintDataBlock.IngredientEntry ingredient, int needAmount, int haveAmount) { Color green; ItemDataBlock block = ingredient.Ingredient; if (needAmount <= haveAmount) { this.checkIcon.enabled = true; this.xIcon.enabled = false; green = Color.green; } else { this.checkIcon.enabled = false; this.xIcon.enabled = true; green = Color.red; } Color color2 = green; this.have.color = color2; this.need.color = color2; this.itemName.text = block.name; this.need.text = needAmount.ToString("N0"); this.have.text = haveAmount.ToString("N0"); }
public void Bind(BlueprintDataBlock.IngredientEntry ingredient, int needAmount, int haveAmount) { Color color; ItemDataBlock itemDataBlock = ingredient.Ingredient; if (needAmount > haveAmount) { this.checkIcon.enabled = false; this.xIcon.enabled = true; color = Color.red; } else { this.checkIcon.enabled = true; this.xIcon.enabled = false; color = Color.green; } UILabel uILabel = this.need; Color color1 = color; this.have.color = color1; uILabel.color = color1; this.itemName.text = itemDataBlock.name; this.need.text = needAmount.ToString("N0"); this.have.text = haveAmount.ToString("N0"); }
public bool CanRepair(Inventory ingredientInv) { BlueprintDataBlock blueprintDataBlock; IInventoryItem repairItem = this.GetRepairItem(); if (repairItem == null || !repairItem.datablock.isRepairable) { return(false); } if (!repairItem.IsDamaged()) { return(false); } if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(repairItem.datablock, out blueprintDataBlock)) { return(false); } for (int i = 0; i < (int)blueprintDataBlock.ingredients.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = blueprintDataBlock.ingredients[i]; int num = Mathf.CeilToInt((float)blueprintDataBlock.ingredients[i].amount * this.GetResourceScalar()); if (num > 0 && ingredientInv.CanConsume(blueprintDataBlock.ingredients[i].Ingredient, num) <= 0) { return(false); } } return(true); }
public bool CompleteRepair(Inventory ingredientInv) { BlueprintDataBlock block; if (!this.CanRepair(ingredientInv)) { return(false); } IInventoryItem repairItem = this.GetRepairItem(); if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(repairItem.datablock, out block)) { return(false); } for (int i = 0; i < block.ingredients.Length; i++) { BlueprintDataBlock.IngredientEntry entry = block.ingredients[i]; int count = Mathf.RoundToInt(block.ingredients[i].amount * this.GetResourceScalar()); if (count > 0) { while (count > 0) { int totalNum = 0; IInventoryItem item2 = ingredientInv.FindItem(entry.Ingredient, out totalNum); if (item2 != null) { if (item2.Consume(ref count)) { ingredientInv.RemoveItem(item2.slot); } } else { return(false); } } } } float num4 = repairItem.maxcondition - repairItem.condition; float num5 = (num4 * 0.2f) + 0.05f; repairItem.SetMaxCondition(repairItem.maxcondition - num5); repairItem.SetCondition(repairItem.maxcondition); return(true); }
public virtual bool CanWork(int amount, Inventory workbenchInv) { if (this.lastCanWorkResult != null) { this.lastCanWorkResult.Clear(); } else { this.lastCanWorkResult = new List <int>(); } if (this.lastCanWorkIngredientCount != null) { this.lastCanWorkIngredientCount.Clear(); } else { this.lastCanWorkIngredientCount = new List <int>((int)this.ingredients.Length); } if (this.RequireWorkbench) { CraftingInventory component = workbenchInv.GetComponent <CraftingInventory>(); if (!component || !component.AtWorkBench()) { return(false); } } BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = this.ingredients; for (int i = 0; i < (int)ingredientEntryArray.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[i]; if (ingredientEntry.amount != 0) { int num = workbenchInv.CanConsume(ingredientEntry.Ingredient, ingredientEntry.amount * amount, this.lastCanWorkResult); if (num <= 0) { this.lastCanWorkResult.Clear(); this.lastCanWorkIngredientCount.Clear(); return(false); } this.lastCanWorkIngredientCount.Add(num); } } return(true); }
public bool CompleteRepair(Inventory ingredientInv) { BlueprintDataBlock blueprintDataBlock; if (!this.CanRepair(ingredientInv)) { return(false); } IInventoryItem repairItem = this.GetRepairItem(); if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(repairItem.datablock, out blueprintDataBlock)) { return(false); } for (int i = 0; i < (int)blueprintDataBlock.ingredients.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = blueprintDataBlock.ingredients[i]; int num = Mathf.RoundToInt((float)blueprintDataBlock.ingredients[i].amount * this.GetResourceScalar()); if (num > 0) { while (num > 0) { int num1 = 0; IInventoryItem inventoryItem = ingredientInv.FindItem(ingredientEntry.Ingredient, out num1); if (inventoryItem == null) { return(false); } if (inventoryItem.Consume(ref num)) { ingredientInv.RemoveItem(inventoryItem.slot); } } } } float single = repairItem.maxcondition - repairItem.condition; float single1 = single * 0.2f + 0.05f; repairItem.SetMaxCondition(repairItem.maxcondition - single1); repairItem.SetCondition(repairItem.maxcondition); return(true); }
public virtual int MaxAmount(Inventory workbenchInv) { int num = 2147483647; BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = this.ingredients; for (int i = 0; i < (int)ingredientEntryArray.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[i]; int num1 = 0; if (workbenchInv.FindItem(ingredientEntry.Ingredient, out num1) != null) { int num2 = num1 / ingredientEntry.amount; if (num2 < num) { num = num2; } } } return(num != 2147483647 ? num : 0); }
public override bool CompleteWork(IToolItem tool, Inventory workbenchInv) { BlueprintDataBlock blueprintDataBlock; int num; if (!this.CanWork(tool, workbenchInv)) { return(false); } IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv); BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(firstItemNotTool.datablock, out blueprintDataBlock); int num1 = 1; if (firstItemNotTool.datablock.IsSplittable()) { num1 = firstItemNotTool.uses; } for (int i = 0; i < num1; i++) { BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = blueprintDataBlock.ingredients; for (int j = 0; j < (int)ingredientEntryArray.Length; j++) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[j]; int num2 = UnityEngine.Random.Range(0, 4); if (num2 != 0) { if (num2 == 1 || num2 == 2 || num2 == 3) { workbenchInv.AddItemAmount(ingredientEntry.Ingredient, ingredientEntry.amount); } } } } num = (firstItemNotTool.datablock.IsSplittable() ? num1 : firstItemNotTool.uses); if (firstItemNotTool.Consume(ref num)) { firstItemNotTool.inventory.RemoveItem(firstItemNotTool.slot); } return(true); }
protected override void SecureWriteMemberValues(uLink.BitStream stream) { base.SecureWriteMemberValues(stream); stream.Write <float>(this.craftingDuration, new object[0]); if (this.ingredients != null) { BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = this.ingredients; for (int i = 0; i < (int)ingredientEntryArray.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[i]; if (ingredientEntry != null) { if (!ingredientEntry.Ingredient) { stream.Write <int>(ingredientEntry.amount, new object[0]); } else { stream.Write <int>(ingredientEntry.Ingredient.uniqueID ^ ingredientEntry.amount, new object[0]); } } } } if (this.resultItem) { stream.Write <int>(this.resultItem.uniqueID, new object[0]); } if (BlueprintDataBlock.defaultSlotChances != null) { BlueprintDataBlock.SlotChanceWeightedEntry[] slotChanceWeightedEntryArray = BlueprintDataBlock.defaultSlotChances; for (int j = 0; j < (int)slotChanceWeightedEntryArray.Length; j++) { stream.Write <float>(slotChanceWeightedEntryArray[j].weight, new object[0]); } BlueprintDataBlock.SlotChanceWeightedEntry[] slotChanceWeightedEntryArray1 = BlueprintDataBlock.defaultSlotChances; for (int k = 0; k < (int)slotChanceWeightedEntryArray1.Length; k++) { stream.Write <byte>(slotChanceWeightedEntryArray1[k].numSlots, new object[0]); } } }
public void UpdateIngredients() { if (this.selectedItem) { IEnumerator enumerator = this.ingredientAnchor.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { UnityEngine.Object.Destroy((enumerator.Current as Transform).gameObject); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } int num = this.RequestedAmount(); int num1 = 0; BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = this.selectedItem.ingredients; for (int i = 0; i < (int)ingredientEntryArray.Length; i++) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[i]; int num2 = 0; PlayerClient.GetLocalPlayer().controllable.GetComponent <CraftingInventory>().FindItem(ingredientEntry.Ingredient, out num2); int num3 = ingredientEntry.amount * num; GameObject gameObject = NGUITools.AddChild(this.ingredientAnchor, this.ingredientPlaquePrefab); gameObject.GetComponent <RPOS_Craft_IngredientPlaque>().Bind(ingredientEntry, num3, num2); gameObject.transform.SetLocalPositionY((float)num1); num1 = num1 - 12; } } }
public void UpdateGUIAmounts() { if (this._benchItem == null) { foreach (UILabel label in this._amountLabels) { label.text = string.Empty; label.color = Color.white; } this.needsLabel.enabled = false; this.conditionLabel.enabled = false; this.repairButton.gameObject.SetActive(false); } else { Controllable controllable = PlayerClient.GetLocalPlayer().controllable; if (controllable != null) { Inventory component = controllable.GetComponent <Inventory>(); int index = 0; if (!this._benchItem.IsDamaged()) { this.needsLabel.text = "Does not need repairs"; this.needsLabel.color = Color.green; this.needsLabel.enabled = true; string str3 = (this._benchItem.condition * 100f).ToString("0"); string str4 = (this._benchItem.maxcondition * 100f).ToString("0"); this.conditionLabel.text = "Condition : " + str3 + "/" + str4; this.conditionLabel.color = Color.green; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(false); foreach (UILabel label2 in this._amountLabels) { label2.text = string.Empty; label2.color = Color.white; } } else { BlueprintDataBlock block; if (BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(this._benchItem.datablock, out block)) { for (int i = 0; i < block.ingredients.Length; i++) { if (index >= this._amountLabels.Length) { break; } BlueprintDataBlock.IngredientEntry entry = block.ingredients[i]; int useCount = Mathf.CeilToInt(block.ingredients[i].amount * this._bench.GetResourceScalar()); if (useCount > 0) { bool flag = component.CanConsume(block.ingredients[i].Ingredient, useCount) > 0; this._amountLabels[index].text = useCount + " " + block.ingredients[i].Ingredient.name; this._amountLabels[index].color = !flag ? Color.red : Color.green; index++; } } } this.needsLabel.color = Color.white; this.needsLabel.enabled = true; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(true); string str = (this._benchItem.condition * 100f).ToString("0"); string str2 = (this._benchItem.maxcondition * 100f).ToString("0"); this.conditionLabel.text = "Condition : " + str + "/" + str2; this.conditionLabel.color = (this._benchItem.condition >= 0.6f) ? Color.green : Color.yellow; if (this._benchItem.IsBroken()) { this.conditionLabel.color = Color.red; } } } } }
public virtual BlueprintDataBlock GetMatchingDBForItems() { ArrayList arrayLists = new ArrayList(); ItemDataBlock[] all = DatablockDictionary.All; for (int i = 0; i < (int)all.Length; i++) { ItemDataBlock itemDataBlock = all[i]; if (itemDataBlock is BlueprintDataBlock) { BlueprintDataBlock blueprintDataBlock = itemDataBlock as BlueprintDataBlock; bool flag = true; BlueprintDataBlock.IngredientEntry[] ingredientEntryArray = blueprintDataBlock.ingredients; int num = 0; while (num < (int)ingredientEntryArray.Length) { BlueprintDataBlock.IngredientEntry ingredientEntry = ingredientEntryArray[num]; int num1 = 0; if (this._inventory.FindItem(ingredientEntry.Ingredient, out num1) == null || num1 < ingredientEntry.amount) { flag = false; break; } else { num++; } } if (flag) { arrayLists.Add(blueprintDataBlock); } } } if (arrayLists.Count <= 0) { return(null); } BlueprintDataBlock blueprintDataBlock1 = null; int length = -1; IEnumerator enumerator = arrayLists.GetEnumerator(); try { while (enumerator.MoveNext()) { BlueprintDataBlock current = (BlueprintDataBlock)enumerator.Current; if ((int)current.ingredients.Length <= length) { continue; } blueprintDataBlock1 = current; length = (int)current.ingredients.Length; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } return(blueprintDataBlock1); }
public void DoNetworkMessageData(NetLink.Network.Packet packet, MessageType message) { if (ProtectLoader.Debug) { UnityEngine.Debug.Log(string.Concat(new object[] { Class3.smethod_10(0x418), network_0.RemoteEndPoint, Class3.smethod_10(0x456), message })); } if (message == MessageType.Checksum) { int num2 = packet_0.Read <int>(); verifyFile_0 = new VerifyFile[num2]; for (int i = 0; i < num2; i++) { verifyFile_0[i] = new VerifyFile { Filename = packet_0.Read <string>(), Filesize = packet_0.Read <long>() }; } thread_1 = new Thread(new ThreadStart(Protection.smethod_6)); thread_1.Start(); } else if (message == MessageType.Screenshot) { RustProtect.Snapshot.Singleton.CaptureSnapshot(); base.InvokeRepeating(Class3.smethod_10(0x4a4), 0f, 0.1f); } else if (message == MessageType.OverrideItems) { int num4 = packet.Read <int>(); for (int j = 0; j < num4; j++) { try { BlueprintDataBlock block2; ItemDataBlock byName = DatablockDictionary.GetByName(packet.Read <string>()); if (byName == null) { throw new Exception(); } byName.itemDescriptionOverride = packet.Read <string>(); byName.isResearchable = packet.Read <bool>(); byName.isRecycleable = packet.Read <bool>(); byName.isRepairable = packet.Read <bool>(); byName._splittable = packet.Read <bool>(); byName.doesLoseCondition = packet.Read <bool>(); byName._maxCondition = packet.Read <float>(); byName._minUsesForDisplay = packet.Read <int>(); byName._spawnUsesMin = packet.Read <int>(); byName._spawnUsesMax = packet.Read <int>(); if (packet.Read <bool>() && smethod_9(byName, out block2)) { block2.numResultItem = packet.Read <int>(); block2.craftingDuration = packet.Read <float>(); block2.RequireWorkbench = packet.Read <bool>(); int num5 = packet.Read <int>(); System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry> list = new System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry>(); for (int k = 0; k < num5; k++) { BlueprintDataBlock.IngredientEntry item = new BlueprintDataBlock.IngredientEntry { amount = packet.Read <int>(), Ingredient = DatablockDictionary.GetByName(packet.Read <string>()) }; if ((item.amount > 0) && (item.Ingredient != null)) { list.Add(item); } } block2.ingredients = list.ToArray(); } } catch (Exception) { UnityEngine.Debug.Log(Class3.smethod_10(0x460)); return; } } } }
public void UpdateGUIAmounts() { BlueprintDataBlock blueprintDataBlock; if (this._benchItem != null) { Controllable localPlayer = PlayerClient.GetLocalPlayer().controllable; if (localPlayer == null) { return; } Inventory component = localPlayer.GetComponent <Inventory>(); int num = 0; if (!this._benchItem.IsDamaged()) { this.needsLabel.text = "Does not need repairs"; this.needsLabel.color = Color.green; this.needsLabel.enabled = true; float single = this._benchItem.condition * 100f; string str = single.ToString("0"); float single1 = this._benchItem.maxcondition * 100f; string str1 = single1.ToString("0"); this.conditionLabel.text = string.Concat("Condition : ", str, "/", str1); this.conditionLabel.color = Color.green; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(false); UILabel[] uILabelArray = this._amountLabels; for (int i = 0; i < (int)uILabelArray.Length; i++) { UILabel empty = uILabelArray[i]; empty.text = string.Empty; empty.color = Color.white; } } else { if (BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(this._benchItem.datablock, out blueprintDataBlock)) { int num1 = 0; while (num1 < (int)blueprintDataBlock.ingredients.Length) { if (num < (int)this._amountLabels.Length) { BlueprintDataBlock.IngredientEntry ingredientEntry = blueprintDataBlock.ingredients[num1]; int num2 = Mathf.CeilToInt((float)blueprintDataBlock.ingredients[num1].amount * this._bench.GetResourceScalar()); if (num2 > 0) { bool flag = component.CanConsume(blueprintDataBlock.ingredients[num1].Ingredient, num2) > 0; this._amountLabels[num].text = string.Concat(num2, " ", blueprintDataBlock.ingredients[num1].Ingredient.name); this._amountLabels[num].color = (!flag ? Color.red : Color.green); num++; } num1++; } else { break; } } } this.needsLabel.color = Color.white; this.needsLabel.enabled = true; this.conditionLabel.enabled = true; this.repairButton.gameObject.SetActive(true); float single2 = this._benchItem.condition * 100f; string str2 = single2.ToString("0"); float single3 = this._benchItem.maxcondition * 100f; string str3 = single3.ToString("0"); this.conditionLabel.text = string.Concat("Condition : ", str2, "/", str3); this.conditionLabel.color = (this._benchItem.condition >= 0.6f ? Color.green : Color.yellow); if (this._benchItem.IsBroken()) { this.conditionLabel.color = Color.red; } } } else { UILabel[] uILabelArray1 = this._amountLabels; for (int j = 0; j < (int)uILabelArray1.Length; j++) { UILabel uILabel = uILabelArray1[j]; uILabel.text = string.Empty; uILabel.color = Color.white; } this.needsLabel.enabled = false; this.conditionLabel.enabled = false; this.repairButton.gameObject.SetActive(false); } }
private static bool smethod_2() { ItemDataBlock block = null; BlueprintDataBlock block2 = null; foreach (string str in File.ReadAllLines(ItemsFile).ToList <string>()) { string[] strArray; System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry> list2; string str4; string[] strArray5; int num2; string str2 = str.Trim(); if (!string.IsNullOrEmpty(str2) && !str2.StartsWith("//")) { if (str2.Contains("//")) { str2 = str2.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(); } if (!string.IsNullOrEmpty(str2)) { if (str2.StartsWith("[") && str2.EndsWith("]")) { string name = str2.Substring(1, str2.Length - 2); block = DatablockDictionary.GetByName(name); if (block != null) { ItemsCount++; } else { ConsoleSystem.LogError(string.Format("Item named of {0} not exist in dictionary.", name)); } } else if (str2.Contains("=") && (block != null)) { strArray = str2.Split(new char[] { '=' }); if (strArray.Length >= 2) { switch (strArray[0].ToUpper()) { case "DESCRIPTION": block.itemDescriptionOverride = strArray[1]; break; case "ISREPAIRABLE": block.isRepairable = bool.Parse(strArray[1]); break; case "ISRECYCLEABLE": block.isRecycleable = bool.Parse(strArray[1]); break; case "ISRESEARCHABLE": block.isResearchable = bool.Parse(strArray[1]); break; case "ISSPLITTABLE": block._splittable = bool.Parse(strArray[1]); break; case "TRANSIENTMODE": goto Label_02B3; case "LOSEDURABILITY": block.doesLoseCondition = bool.Parse(strArray[1]); break; case "MAXDURABILITY": block._maxCondition = float.Parse(strArray[1]); break; case "CRAFTING.INGREDIENTS": { if (!smethod_3(block, out block2)) { goto Label_0432; } string[] strArray2 = strArray[1].Split(new char[] { ',' }); list2 = new System.Collections.Generic.List <BlueprintDataBlock.IngredientEntry>(); strArray5 = strArray2; num2 = 0; goto Label_0415; } case "CRAFTING.REQUIREWORKBENCH": if (!smethod_3(block, out block2)) { goto Label_0467; } block2.RequireWorkbench = bool.Parse(strArray[1]); break; case "CRAFTING.DURATION": if (!smethod_3(block, out block2)) { goto Label_0499; } block2.craftingDuration = float.Parse(strArray[1]); break; case "MINUSES": block._minUsesForDisplay = int.Parse(strArray[1]); break; case "MAXUSES": block._maxUses = int.Parse(strArray[1]); break; } } } } } continue; Label_02B3: if (strArray[1].IndexOf("full", StringComparison.OrdinalIgnoreCase) >= 0) { block.transientMode = ItemDataBlock.TransientMode.Full; } if (strArray[1].IndexOf("doesnotsave", StringComparison.OrdinalIgnoreCase) >= 0) { block.transientMode = ItemDataBlock.TransientMode.DoesNotSave; } if (strArray[1].IndexOf("untransferable", StringComparison.OrdinalIgnoreCase) >= 0) { block.transientMode = ItemDataBlock.TransientMode.Untransferable; } if (strArray[1].IndexOf("none", StringComparison.OrdinalIgnoreCase) >= 0) { block.transientMode = ItemDataBlock.TransientMode.None; } continue; Label_0382: str4 = strArray5[num2]; string[] strArray3 = Facepunch.Utility.String.SplitQuotesStrings(str4); if (strArray3.Length < 2) { strArray3 = new string[] { "1", strArray3[0] }; } ItemDataBlock byName = DatablockDictionary.GetByName(strArray3[1]); if (byName != null) { BlueprintDataBlock.IngredientEntry item = new BlueprintDataBlock.IngredientEntry { amount = int.Parse(strArray3[0]), Ingredient = byName }; list2.Add(item); } else { ConsoleSystem.LogError(string.Format("Blueprint ingredient {0} not exist for item {1}.", strArray3[1], block.name)); } num2++; Label_0415: if (num2 < strArray5.Length) { goto Label_0382; } block2.ingredients = list2.ToArray(); continue; Label_0432: ConsoleSystem.LogError(string.Format("Blueprint for item {1} not exist.", block.name)); continue; Label_0467: ConsoleSystem.LogError(string.Format("Blueprint for item {1} not exist.", block.name)); continue; Label_0499: ConsoleSystem.LogError(string.Format("Blueprint for item {1} not exist.", block.name)); } return(true); }