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 override InventoryItem.MergeResult TryCombine(IInventoryItem otherItem) { PlayerInventory inventory = base.inventory as PlayerInventory; if ((inventory != null) && (otherItem.inventory == inventory)) { ItemDataBlock datablock = otherItem.datablock; if ((datablock != null) && datablock.isResearchable) { BlueprintDataBlock block2; if (!inventory.AtWorkBench()) { Notice.Popup("", "You must be at a workbench to do this.", 4f); return(InventoryItem.MergeResult.Failed); } if (!BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(otherItem.datablock, out block2)) { Notice.Popup("", "You can't research this.. No Blueprint Available!...", 4f); return(InventoryItem.MergeResult.Failed); } if (inventory.KnowsBP(block2)) { Notice.Popup("", "You already know how to make this!", 4f); return(InventoryItem.MergeResult.Failed); } return(InventoryItem.MergeResult.Combined); } Notice.Popup("", "You can't research this", 4f); } return(InventoryItem.MergeResult.Failed); }
public override bool CompleteWork(IToolItem tool, Inventory workbenchInv) { BlueprintDataBlock block; if (this.CanWork(tool, workbenchInv) && BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(base.GetFirstItemNotTool(tool, workbenchInv).datablock, out block)) { workbenchInv.AddItem(block, Inventory.Slot.Preference.Define(Inventory.Slot.Kind.Default, block.IsSplittable(), Inventory.Slot.Kind.Belt), 1); return(true); } return(false); }
public override bool CanWork(IToolItem tool, Inventory workbenchInv) { if (workbenchInv.occupiedSlotCount > 2) { Debug.Log("Too many items for research"); return(false); } IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv); if (firstItemNotTool != null && firstItemNotTool.datablock.isResearchable && BlueprintDataBlock.FindBlueprintForItem(firstItemNotTool.datablock)) { return(true); } Debug.Log("Can't work!?!!?"); return(false); }
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 override bool CanWork(IToolItem tool, Inventory workbenchInv) { if (workbenchInv.occupiedSlotCount > 2) { Debug.Log("Too many items for recycle"); return(false); } IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv); if (!firstItemNotTool.datablock.isRecycleable) { return(false); } if (!BlueprintDataBlock.FindBlueprintForItem(firstItemNotTool.datablock)) { return(false); } return(true); }
public override bool CompleteWork(IToolItem tool, Inventory workbenchInv) { BlueprintDataBlock block; int num5; if (!this.CanWork(tool, workbenchInv)) { return(false); } IInventoryItem firstItemNotTool = base.GetFirstItemNotTool(tool, workbenchInv); BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(firstItemNotTool.datablock, out block); int uses = 1; if (firstItemNotTool.datablock.IsSplittable()) { uses = firstItemNotTool.uses; } for (int i = 0; i < uses; i++) { foreach (BlueprintDataBlock.IngredientEntry entry in block.ingredients) { int num4 = Random.Range(0, 4); if ((num4 != 0) && (((num4 == 1) || (num4 == 2)) || (num4 == 3))) { workbenchInv.AddItemAmount(entry.Ingredient, entry.amount); } } } if (!firstItemNotTool.datablock.IsSplittable()) { num5 = firstItemNotTool.uses; } else { num5 = uses; } if (firstItemNotTool.Consume(ref num5)) { firstItemNotTool.inventory.RemoveItem(firstItemNotTool.slot); } 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 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); }
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 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); } }
public static bool FindBlueprintForItem(ItemDataBlock item) { BlueprintDataBlock blueprintDataBlock; return(BlueprintDataBlock.FindBlueprintForItem <BlueprintDataBlock>(item, out blueprintDataBlock)); }