public static void BlueprintUse(IBlueprintItem item, BlueprintDataBlock bdb) { Contract.Requires(item != null); Contract.Requires(bdb != null); if (item.controllable == null) throw new InvalidOperationException("IBlueprintItem's controllable is null."); if (item.controllable.playerClient == null) throw new InvalidOperationException("IBlueprintItem's playerClient is null."); Fougerite.Player player = Fougerite.Player.FindByPlayerClient(item.controllable.playerClient); if (player == null) return; BPUseEvent ae = new BPUseEvent(bdb); if (OnBlueprintUse != null) OnBlueprintUse(player, ae); if (ae.Cancel) return; PlayerInventory internalInventory = player.Inventory.InternalInventory as PlayerInventory; if (internalInventory.BindBlueprint(bdb)) { int count = 1; if (item.Consume(ref count)) { internalInventory.RemoveItem(item.slot); } player.Notice("", "You can now craft: " + bdb.resultItem.name, 4f); } else { player.Notice("", "You already have this blueprint", 4f); } }
public BPUseEvent(BlueprintDataBlock bdb) { Contract.Requires(bdb != null); this.DataBlock = bdb; this.Cancel = false; }
public bool Restart(Inventory inventory, int amount, BlueprintDataBlock blueprint, ulong startTimeMillis) { if (!blueprint || !blueprint.CanWork(amount, inventory)) { this = new CraftingSession(); return false; } this.blueprint = blueprint; this.startTime = (float)((double)((float)startTimeMillis) / 1000); this.duration = blueprint.craftingDuration * (float)amount; this.progressPerSec = 1f; this.progressSeconds = 0f; this.amount = amount; this.inProgress = true; return true; }
void BlueprintUse_Test() { try { BlueprintDataBlock BDB = new BlueprintDataBlock(); Log("BlueprintUse_Test: Test 1"); Hooks.BlueprintUse(null, BDB); Log("BlueprintUse_Test: Test 2"); Hooks.BlueprintUse(null, null); } catch (Exception ex) { Logger.LogException(ex); } }
private void OnBlueprintUse(BlueprintDataBlock bp, IBlueprintItem item) { HookCalled("OnBlueprintUse"); // TODO: Complete parameters var netUser = item.inventory.GetComponent<Character>()?.netUser; if (netUser == null) return; Puts(netUser.displayName + " used the blueprint " + item.datablock.name + " to learn how to craft " + bp.resultItem.name); }
private void OnItemCraft(CraftingInventory inventory, BlueprintDataBlock blueprint, int amount, ulong startTime) { HookCalled("OnItemCraft"); // Print item crafting var netUser = inventory.GetComponent<Character>().netUser; Puts(netUser.displayName + " started crafting " + blueprint.resultItem.name + " x " + amount.ToString()); }
protected void UpdateCrafting(BlueprintDataBlock blueprint, int amount, float start, float dur, float progress, float progresspersec) { Debug.Log(string.Format("Craft network update :{0}:", (!blueprint ? "NONE" : blueprint.name)), this); this._lastThinkTime = NetCull.time; this.crafting.blueprint = blueprint; this.crafting.inProgress = blueprint; this.crafting.startTime = start; this.crafting.duration = dur; this.crafting.progressSeconds = progress; this.crafting.progressPerSec = progresspersec; this.crafting.amount = amount; this.Refresh(); }
public bool ValidateCraftRequirements(BlueprintDataBlock bp) { if (!bp.RequireWorkbench) { return true; } if (this.AtWorkBench()) { return true; } return false; }
public bool StartCrafting(BlueprintDataBlock blueprint, int amount) { if (!blueprint.CanWork(amount, this)) { return false; } base.networkView.RPC("CRFS", uLink.RPCMode.Server, new object[] { amount, blueprint.uniqueID }); return true; }
public static void ResearchItem(IBlueprintItem item, BlueprintDataBlock BDB) { PlayerInventory inventory = item.inventory as PlayerInventory; if (inventory != null) { bool b = false; PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == inventory.networkView.owner); if (!restrictBlueprints.Contains(BDB.resultItem.name) || craftList.Contains(playerClient.userID.ToString())) { if (inventory.BindBlueprint(BDB)) { int count = 1; if (item.Consume(ref count)) { inventory.RemoveItem(item.slot); } Rust.Notice.Popup(inventory.networkView.owner, "", "You can now craft: " + BDB.resultItem.name, 4f); } else { Rust.Notice.Popup(inventory.networkView.owner, "", "You already researched this.", 4f); } } else Broadcast.noticeTo(inventory.networkView.owner, "", "You cannot research this item!", 4); } }
public static bool CraftItem(int amount, Inventory workbenchInv, BlueprintDataBlock BDB) { if (!BDB.CanWork(amount, workbenchInv)) { return false; } int num = 0; PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == workbenchInv.networkView.owner); if (playerClient != null) { if (!restrictCrafting.Contains(BDB.resultItem.name) || craftList.Contains(playerClient.userID.ToString())) { for (int i = 0; i < BDB.ingredients.Length; i++) { int count = BDB.ingredients[i].amount * amount; if (count != 0) { int num4 = BDB.lastCanWorkIngredientCount[i]; for (int j = 0; j < num4; j++) { IInventoryItem item; int slot = BDB.lastCanWorkResult[num++]; if (workbenchInv.GetItem(slot, out item) && item.Consume(ref count)) { workbenchInv.RemoveItem(slot); } } } } } else { Broadcast.noticeTo(workbenchInv.networkView.owner, "♨", "You cannot craft this item!", 4); return false; } } else { if (!restrictCrafting.Contains(BDB.resultItem.name)) { for (int i = 0; i < BDB.ingredients.Length; i++) { int count = BDB.ingredients[i].amount * amount; if (count != 0) { int num4 = BDB.lastCanWorkIngredientCount[i]; for (int j = 0; j < num4; j++) { IInventoryItem item; int slot = BDB.lastCanWorkResult[num++]; if (workbenchInv.GetItem(slot, out item) && item.Consume(ref count)) { workbenchInv.RemoveItem(slot); } } } } } else { Broadcast.noticeTo(workbenchInv.networkView.owner, "♨", "You cannot craft this item!", 4); return false; } } workbenchInv.AddItemAmount(BDB.resultItem, amount * BDB.numResultItem); return true; }
public static bool CanCraft(int amount, Inventory workbenchInv, BlueprintDataBlock BDB) { if (BDB.lastCanWorkResult == null) { BDB.lastCanWorkResult = new List<int>(); } else { BDB.lastCanWorkResult.Clear(); } if (BDB.lastCanWorkIngredientCount == null) { BDB.lastCanWorkIngredientCount = new List<int>(BDB.ingredients.Length); } else { BDB.lastCanWorkIngredientCount.Clear(); } PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == workbenchInv.networkView.owner); if (playerClient != null) { if (!craftList.Contains(playerClient.userID.ToString())) { if (BDB.RequireWorkbench && craftAtBench) { CraftingInventory component = workbenchInv.GetComponent<CraftingInventory>(); if ((component == null) || !component.AtWorkBench()) { return false; } } } } else { if (BDB.RequireWorkbench && craftAtBench) { CraftingInventory component = workbenchInv.GetComponent<CraftingInventory>(); if ((component == null) || !component.AtWorkBench()) { return false; } } } if (playerClient != null) { if (!craftList.Contains(playerClient.userID.ToString())) { foreach (BlueprintDataBlock.IngredientEntry entry in BDB.ingredients) { if (entry.amount != 0) { int item = workbenchInv.CanConsume(entry.Ingredient, entry.amount * amount, BDB.lastCanWorkResult); if (item <= 0) { BDB.lastCanWorkResult.Clear(); BDB.lastCanWorkIngredientCount.Clear(); return false; } BDB.lastCanWorkIngredientCount.Add(item); } } } } else { foreach (BlueprintDataBlock.IngredientEntry entry in BDB.ingredients) { if (entry.amount != 0) { int item = workbenchInv.CanConsume(entry.Ingredient, entry.amount * amount, BDB.lastCanWorkResult); if (item <= 0) { BDB.lastCanWorkResult.Clear(); BDB.lastCanWorkIngredientCount.Clear(); return false; } BDB.lastCanWorkIngredientCount.Add(item); } } } return true; }
private void OnItemCraft(CraftingInventory inventory, BlueprintDataBlock blueprint, int amount, ulong startTime) { HookCalled("OnItemCraft"); // TODO: Print item crafting }
public bool HasBlueprint(BlueprintDataBlock dataBlock) { PlayerInventory invent = this.Inventory.InternalInventory as PlayerInventory; if (invent.KnowsBP(dataBlock)) return true; return false; }
public void SetSelectedItem(BlueprintDataBlock newSel) { !this.selectedItem; this.selectedItem = newSel; this.SetRequestedAmount(1); !this.selectedItem; this.ShowCraftingOptions(this.selectedItem != null); this.UpdateWorkbenchRequirements(); }