Beispiel #1
0
        bool CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount)
        {
            var player = itemCrafter.GetComponent <BasePlayer>();
            var item   = bp.GetComponent <ItemDefinition>();

            if (player == null || item == null)
            {
                return(false);
            }

            if (permission.UserHasPermission(player.UserIDString, perm1))
            {
                return(true);
            }

            if (permission.UserHasPermission(player.UserIDString, perm2))
            {
                SendReply(player, "You are not allowed to craft at all");
                return(false);
            }

            if (blacklist.Contains(item.shortname))
            {
                SendReply(player, "You are not allowed to craft <color=#eb4034>" + item.shortname + "</color>");
                return(false);
            }

            return(true);
        }
 public void Clear()
 {
     this.itemBlueprint = null;
     icon.gameObject.SetActive(false);
     icon.sprite   = null;
     nameText.text = string.Empty;
 }
Beispiel #3
0
 /// <summary>
 /// Checks that the neighbors of the cell allow this option
 /// </summary>
 private bool GetIsValidByPlacement(ItemBlueprint item)
 {
     return(UpNeighbor.DoesDownConnectTo(item.Up) &&
            DownNeighbor.DoesUpConnectTo(item.Down) &&
            LeftNeighbor.DoesRightConnectTo(item.Left) &&
            RightNeighbor.DoesLeftConnectTo(item.Right));
 }
        private object OnIngredientsCollect(ItemCrafter itemCrafter, ItemBlueprint blueprint, ItemCraftTask task, int amount, BasePlayer player)
        {
            var ruleset = GetPlayerRuleset(player.UserIDString);

            if (ruleset == null)
            {
                return(null);
            }

            var collect = new List <Item>();

            ruleset.TakeFromContainers(itemCrafter.containers, blueprint.ingredients, amount, collect);

            // Re-implementing some vanilla logic.
            task.potentialOwners = new List <ulong>();
            foreach (var item in collect)
            {
                item.CollectedForCrafting(player);
                if (!task.potentialOwners.Contains(player.userID))
                {
                    task.potentialOwners.Add(player.userID);
                }
            }
            task.takenItems = collect;

            // Return non-null to skip vanilla ingredient collection.
            return(false);
        }
Beispiel #5
0
    public void AddItem(ItemBlueprint newItem)
    {
        item = newItem;

        itemIcon.sprite  = item.itemIcon;
        itemIcon.enabled = true;
    }
Beispiel #6
0
 public void UpdateSlot(ItemBlueprint item, int quantity)
 {
     SetState(true);
     itemName.text   = item.ItemName;
     itemCount.text  = quantity.ToString();
     itemIcon.sprite = item.InventoryIcon;
 }
Beispiel #7
0
    public bool CanCraft(ItemBlueprint bp, int amount = 1)
    {
        float num = (float)amount / (float)bp.targetItem.craftingStackable;

        foreach (ItemCraftTask itemCraftTask in this.queue)
        {
            if (!itemCraftTask.cancelled)
            {
                num += (float)itemCraftTask.amount / (float)itemCraftTask.blueprint.targetItem.craftingStackable;
            }
        }
        if ((double)num > 8.0 || amount < 1 || amount > bp.targetItem.craftingStackable)
        {
            return(false);
        }
        object obj = Interface.CallHook(nameof(CanCraft), (object)this, (object)bp, (object)amount);

        if (obj is bool)
        {
            return((bool)obj);
        }
        foreach (ItemAmount ingredient in bp.ingredients)
        {
            if (!this.DoesHaveUsableItem(ingredient.itemid, (int)ingredient.amount * amount))
            {
                return(false);
            }
        }
        return(true);
    }
Beispiel #8
0
    private void RPC_CreateKey(RPCMessage rpc)
    {
        if (!rpc.player.CanInteract() || (IsLocked() && !HasLockPermission(rpc.player)))
        {
            return;
        }
        ItemDefinition itemDefinition = ItemManager.FindItemDefinition(keyItemType.itemid);

        if (itemDefinition == null)
        {
            Debug.LogWarning("RPC_CreateKey: Itemdef is missing! " + keyItemType);
            return;
        }
        ItemBlueprint bp = ItemManager.FindBlueprint(itemDefinition);

        if (rpc.player.inventory.crafting.CanCraft(bp))
        {
            ProtoBuf.Item.InstanceData instanceData = Facepunch.Pool.Get <ProtoBuf.Item.InstanceData>();
            instanceData.dataInt = keyCode;
            rpc.player.inventory.crafting.CraftItem(bp, rpc.player, instanceData);
            if (!firstKeyCreated)
            {
                LockLock(rpc.player);
                SendNetworkUpdate();
                firstKeyCreated = true;
            }
        }
    }
Beispiel #9
0
    public bool CanCraft(ItemBlueprint bp, int amount = 1, bool free = false)
    {
        float num = (float)amount / (float)bp.targetItem.craftingStackable;

        foreach (ItemCraftTask item in queue)
        {
            if (!item.cancelled)
            {
                num += (float)item.amount / (float)item.blueprint.targetItem.craftingStackable;
            }
        }
        if (num > 8f)
        {
            return(false);
        }
        if (amount < 1 || amount > bp.targetItem.craftingStackable)
        {
            return(false);
        }
        object obj = Interface.CallHook("CanCraft", this, bp, amount, free);

        if (obj is bool)
        {
            return((bool)obj);
        }
        foreach (ItemAmount ingredient in bp.ingredients)
        {
            if (!DoesHaveUsableItem(ingredient.itemid, (int)ingredient.amount * amount))
            {
                return(false);
            }
        }
        return(true);
    }
    private void RPC_CreateKey(BaseEntity.RPCMessage rpc)
    {
        if (!rpc.player.CanInteract())
        {
            return;
        }
        if (base.IsLocked() && !this.HasLockPermission(rpc.player))
        {
            return;
        }
        ItemDefinition itemDefinition = ItemManager.FindItemDefinition(this.keyItemType.itemid);

        if (itemDefinition == null)
        {
            Debug.LogWarning(string.Concat("RPC_CreateKey: Itemdef is missing! ", this.keyItemType));
            return;
        }
        ItemBlueprint itemBlueprint = ItemManager.FindBlueprint(itemDefinition);

        if (!rpc.player.inventory.crafting.CanCraft(itemBlueprint, 1))
        {
            return;
        }
        ProtoBuf.Item.InstanceData instanceDatum = Facepunch.Pool.Get <ProtoBuf.Item.InstanceData>();
        instanceDatum.dataInt = this.keyCode;
        rpc.player.inventory.crafting.CraftItem(itemBlueprint, rpc.player, instanceDatum, 1, 0, null);
        if (!this.firstKeyCreated)
        {
            this.LockLock(rpc.player);
            base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            this.firstKeyCreated = true;
        }
    }
Beispiel #11
0
        public void TestValidate_BadBehaviour()
        {
            WorldValidator v = new WorldValidator();

            var w    = new World();
            var blue = new ItemBlueprint
            {
                Name       = "Hammer",
                Behaviours =
                    new List <BehaviourBlueprint>()
                {
                    new BehaviourBlueprint()
                    {
                        OnPush = new BehaviourEventHandlerBlueprint()
                        {
                            Effect = new List <EffectBlueprint> {
                                new EffectBlueprint {
                                    Lua = "aa + bb + cc"
                                }
                            }
                        }
                    }
                }
            };

            v.ValidateItem(w, w.ItemFactory.Create(w, blue), new Room("Test Room", w, 't'));

            StringAssert.Contains(@"Error testing OnPush of Behaviour Unnamed Object of on 'Hammer' in room 'Test Room' with test actor 'test actor'", v.Warnings.ToString());
        }
    private void DrawElement(Rect rect, int index, bool active, bool focused)
    {
        ItemBlueprint item = items[index];

        EditorGUI.BeginChangeCheck();

        int labelWidth = 45;

        Rect labelBox = new Rect(rect.x, rect.y, rect.width / 6, rect.height / 3);
        Rect valueBox = new Rect(rect.x + labelWidth, rect.y, rect.width / 6 - labelWidth, rect.height / 3);

        EditorGUI.LabelField(labelBox, "Name:");
        item.name = EditorGUI.TextField(valueBox, item.name);

        labelBox = new Rect(rect.x, rect.y + rect.height / 3, rect.width / 6, rect.height / 3);
        valueBox = new Rect(rect.x + labelWidth, rect.y + rect.height / 3, rect.width / 6 - labelWidth, rect.height / 3);
        EditorGUI.LabelField(labelBox, "Value:");
        item.value = EditorGUI.IntField(valueBox, item.value);

        valueBox    = new Rect(rect.x + labelWidth, rect.y + 2 * rect.height / 3, rect.width / 6 - labelWidth, rect.height / 3);
        item.rarity = (Rarity)EditorGUI.EnumPopup(valueBox, item.rarity);

        valueBox = new Rect(rect.x + 0 * rect.width / 6, rect.y + rect.height / 3, rect.width / 6, rect.height / 3);
        Rect col3 = new Rect(rect.x + 2 * rect.width / 6, rect.y, rect.width / 6, rect.height / 3);
        Rect col4 = new Rect(rect.x + 3 * rect.width / 6, rect.y, rect.width / 6, rect.height);

        item.rarity = (Rarity)EditorGUI.EnumPopup(col3, item.rarity);
        item.icon   = (Sprite)EditorGUI.ObjectField(col4, item.icon, typeof(Sprite), false);
        //item.description = EditorGUI.TextField(col4, item.description);

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(this);
        }
    }
Beispiel #13
0
    public override void ServerCommand(Item item, string command, BasePlayer player)
    {
        if (item.GetOwnerPlayer() != player)
        {
            bool flag = false;
            foreach (ItemContainer container in player.inventory.loot.containers)
            {
                if (item.GetRootContainer() == container)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                return;
            }
        }
        if (!(command == "study") || !item.IsBlueprint())
        {
            return;
        }
        ItemDefinition blueprintTargetDef = item.blueprintTargetDef;
        ItemBlueprint  blueprint          = blueprintTargetDef.Blueprint;
        bool           flag2 = player.blueprints.IsUnlocked(blueprintTargetDef);

        if (flag2 && blueprint != null && blueprint.additionalUnlocks != null && blueprint.additionalUnlocks.Count > 0)
        {
            foreach (ItemDefinition additionalUnlock in blueprint.additionalUnlocks)
            {
                if (!player.blueprints.IsUnlocked(additionalUnlock))
                {
                    flag2 = false;
                }
            }
        }
        if (flag2 || Interface.CallHook("OnPlayerStudyBlueprint", player, item) != null)
        {
            return;
        }
        Item item2 = item;

        if (item.amount > 1)
        {
            item2 = item.SplitItem(1);
        }
        item2.UseItem();
        player.blueprints.Unlock(blueprintTargetDef);
        if (blueprint != null && blueprint.additionalUnlocks != null && blueprint.additionalUnlocks.Count > 0)
        {
            foreach (ItemDefinition additionalUnlock2 in blueprint.additionalUnlocks)
            {
                player.blueprints.Unlock(additionalUnlock2);
            }
        }
        if (studyEffect.isValid)
        {
            Effect.server.Run(studyEffect.resourcePath, player, StringPool.Get("head"), Vector3.zero, Vector3.zero);
        }
    }
Beispiel #14
0
        object OnCanCraft(ItemCrafter item_crafter, ItemBlueprint blueprint, int amount)
        {
            if (item_crafter.containers.Count < 1)
            {
                return(false);
            }

            var item = blueprint.targetItem;

            if (!item)
            {
                return(null);
            }

            var player = item_crafter.containers[0].playerOwner;

            if (!player)
            {
                return(null);
            }

            if (!player.IsAdmin() && item.shortname.StartsWith("sign."))
            {
                PrintToChat(player, notAllowedMessage);
                return(false);
            }

            return(null);
        }
Beispiel #15
0
    public void GetRepairCostList(ItemBlueprint bp, List <ItemAmount> allIngredients)
    {
        foreach (ItemAmount ingredient in bp.ingredients)
        {
            allIngredients.Add(new ItemAmount(ingredient.itemDef, ingredient.amount));
        }
        foreach (ItemAmount itemAmount in bp.ingredients)
        {
            if (itemAmount.itemDef.category != ItemCategory.Component || !(itemAmount.itemDef.Blueprint != null))
            {
                continue;
            }
            bool       flag = false;
            ItemAmount item = itemAmount.itemDef.Blueprint.ingredients[0];
            foreach (ItemAmount allIngredient in allIngredients)
            {
                if (allIngredient.itemDef != item.itemDef)
                {
                    continue;
                }
                ItemAmount itemAmount1 = allIngredient;
                itemAmount1.amount = itemAmount1.amount + item.amount * itemAmount.amount;
                flag = true;
                goto Label0;
            }
Label0:
            if (flag)
            {
                continue;
            }
            allIngredients.Add(new ItemAmount(item.itemDef, item.amount * itemAmount.amount));
        }
    }
Beispiel #16
0
        private object CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount)
        {
            var player = itemCrafter.GetComponent <BasePlayer>();
            var item   = bp.GetComponent <ItemDefinition>();

            if (permission.UserHasPermission(player.UserIDString, Perm))
            {
                return(null);
            }

            if (CFile.BlockAll.Enabled)
            {
                if (CFile.BlockAll.SendMessage)
                {
                    PrintToChat(player, Lang(Msg.CraftingDisabled, player.UserIDString));
                }
                return(false);
            }

            if (CFile.BlockedItems.ContainsKey(item.shortname))
            {
                if (CFile.BlockedItems[item.shortname])
                {
                    PrintToChat(player, Lang(Msg.CantCraft, player.UserIDString, item.displayName.english));
                }
                return(false);
            }

            return(null);
        }
Beispiel #17
0
 public CraftEvent(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData)
 {
     Crafter     = Server.GetPlayer(owner);
     Target      = bp.targetItem;
     itemCrafter = self;
     bluePrint   = bp;
 }
Beispiel #18
0
    private void RPC_CreateKey(BaseEntity.RPCMessage rpc)
    {
        if (!rpc.player.CanInteract() || this.IsLocked() && !this.HasLockPermission(rpc.player))
        {
            return;
        }
        ItemDefinition itemDefinition = ItemManager.FindItemDefinition(this.keyItemType.itemid);

        if (Object.op_Equality((Object)itemDefinition, (Object)null))
        {
            Debug.LogWarning((object)("RPC_CreateKey: Itemdef is missing! " + (object)this.keyItemType));
        }
        else
        {
            ItemBlueprint blueprint = ItemManager.FindBlueprint(itemDefinition);
            if (!rpc.player.inventory.crafting.CanCraft(blueprint, 1))
            {
                return;
            }
            Item.InstanceData instanceData = (Item.InstanceData)Pool.Get <Item.InstanceData>();
            instanceData.dataInt = (__Null)this.keyCode;
            rpc.player.inventory.crafting.CraftItem(blueprint, rpc.player, instanceData, 1, 0, (Item)null);
            if (this.firstKeyCreated)
            {
                return;
            }
            this.LockLock(rpc.player);
            this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
            this.firstKeyCreated = true;
        }
    }
        private void UpdateBlueprint(ItemBlueprint bp, JSONObject o)
        {
            bp.rarity = GetRarity(o);
            if (!_craftingController)
            {
                bp.time = o.GetFloat("time", 0);
            }
            bp.amountToCreate = o.GetInt("amountToCreate", 1);
            //bp.UnlockPrice = o.GetInt("UnlockPrice", 0);
            //bp.UnlockLevel = o.GetInt("UnlockLevel", 10);
            bp.blueprintStackSize = o.GetInt("blueprintStackSize");
            //bp.userCraftable = o.GetBoolean("userCraftable", true);
            bp.isResearchable = o.GetBoolean("isResearchable", true);
            bp.NeedsSteamItem = o.GetBoolean("NeedsSteamItem", false);
            var ingredients = o.GetArray("ingredients");

            bp.ingredients.Clear();
            foreach (var ingredient in ingredients)
            {
                var itemDef = GetItem(ingredient.Obj, "shortname");
                if (itemDef == null)
                {
                    continue;
                }
                bp.ingredients.Add(new ItemAmount(itemDef, ingredient.Obj.GetFloat("amount", 0)));
            }
        }
Beispiel #20
0
 public void GetRepairCostList(ItemBlueprint bp, List <ItemAmount> allIngredients)
 {
     foreach (ItemAmount ingredient in bp.ingredients)
     {
         allIngredients.Add(new ItemAmount(ingredient.itemDef, ingredient.amount));
     }
     foreach (ItemAmount ingredient1 in bp.ingredients)
     {
         if (ingredient1.itemDef.category == ItemCategory.Component && Object.op_Inequality((Object)ingredient1.itemDef.Blueprint, (Object)null))
         {
             bool       flag        = false;
             ItemAmount ingredient2 = ingredient1.itemDef.Blueprint.ingredients[0];
             foreach (ItemAmount allIngredient in allIngredients)
             {
                 if (Object.op_Equality((Object)allIngredient.itemDef, (Object)ingredient2.itemDef))
                 {
                     allIngredient.amount += ingredient2.amount * ingredient1.amount;
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 allIngredients.Add(new ItemAmount(ingredient2.itemDef, ingredient2.amount * ingredient1.amount));
             }
         }
     }
 }
Beispiel #21
0
 public void ResetSlot()
 {
     item                      = null;
     SlotIcon.sprite           = null;
     SlotIcon.enabled          = false;
     DeleteButton.interactable = false;
     ItemCounter.enabled       = false;
 }
Beispiel #22
0
 public void AddItemToSlot(ItemBlueprint SlotItem)
 {
     item                      = SlotItem;
     SlotIcon.sprite           = item.ItemIcon;
     SlotIcon.enabled          = true;
     DeleteButton.interactable = true;
     ItemCounter.enabled       = true;
 }
Beispiel #23
0
 public void RemoveFromInv(ItemBlueprint item)
 {
     items.Remove(item);
     if (onItemChangeCallback != null)
     {
         onItemChangeCallback.Invoke();
     }
 }
Beispiel #24
0
 public CraftEvent(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData, int amount)
 {
     Crafter = Server.GetPlayer(owner);
     Target = bp.targetItem;
     itemCrafter = self;
     Amount = amount;
     bluePrint = bp;
 }
Beispiel #25
0
 public CraftEvent(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData, int amount, int skinid)
 {
     Crafter     = Server.GetPlayer(owner);
     Target      = bp.targetItem;
     itemCrafter = self;
     Amount      = amount;
     bluePrint   = bp;
     SkinID      = skinid;
 }
        private void CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount)
        {
            var oplayer = itemCrafter?.GetComponent <BasePlayer>();

            if (oplayer != null && TrackedPlayers.ContainsKey(oplayer.userID))
            {
                TrackedPlayers[oplayer.userID].ResetAFKTime();
            }
        }
Beispiel #27
0
 public void SelectItemBlueprint(ItemBlueprint blueprint, GetItemAmountDelegate getItemAmountCallback)
 {
     if (blueprint != null && blueprint.TargetItem != null)
     {
         itemInfoView.SetView(new ItemRef(blueprint.TargetItem, getItemAmountCallback(blueprint.TargetItem)));
         SetStatViews(blueprint.TargetItem);
         SetCraftingItemViews(blueprint, getItemAmountCallback);
     }
 }
Beispiel #28
0
        void AdjustCraftingTime(BasePlayer player, ItemBlueprint bp, ItemCraftTask task)
        {
            var multipler = 1.0f;

            if (!c_craftingMultiplierBlacklist.Contains(bp.targetItem.shortname) &&
                player.net.connection.authLevel >= c_craftingMultiplierAuthLevel)
            {
                multipler = bp.targetItem.shortname == "gunpowder" ? c_gunpowderMultiplier : c_craftingMultiplier;
            }

            if (UserIsAuthorizedOnAnyCupboard(player) &&
                !c_benchMultiplierBlacklist.Contains(bp.targetItem.shortname) &&
                player.net.connection.authLevel >= c_benchMultiplierAuthLevel)
            {
                multipler *= c_benchMultiplier;
            }

            var crafter = player.inventory.crafting;

            if (CanBulk(player) && !c_bulkCraftBlacklist.Contains(bp.targetItem.shortname))
            {
                int amount    = task.blueprint.amountToCreate * task.amount;
                int stackable = 1;
                try { stackable = GetStackSize(task.blueprint.targetItem.shortname); } catch { }

                if (amount / stackable > 30)
                {
                    player.ChatMessage($"Could not bulkcraft {task.blueprint.targetItem.displayName.translated} X{amount}, try a smaller amount.");
                    return;
                }

                var tick = DateTime.Now;
                GiveItemsToPlayer(player, task.blueprint.targetItem.shortname, task.skinID, amount);
                var elapsed = (DateTime.Now - tick).TotalMilliseconds;
                if (elapsed > 10)
                {
                    Puts($"Warning: Bulkcraft took {elapsed} ms");
                }

                crafter.CancelTask(task.taskUID, false);
                task.cancelled = true;

                return;
            }

            float stockTime = 0;
            var   ret       = r_blueprintTimes.TryGetValue(bp.targetItem.itemid, out stockTime);

            if (ret)
            {
                bp.time = stockTime * multipler;
            }
            else
            {
                Puts($"Dictionary access error trying to get stock crafting time for <{bp.targetItem.shortname}>");
            }
        }
Beispiel #29
0
    public void ApplyTraitsToPlayer(ItemBlueprint Item)
    {
        // apply the positive trait values of the equipment to the player stat
        foreach (Positives PosTraits in Item.equipBP.PositiveTraits)
        {
            Debug.Log("Applying " + PosTraits.traitLevel.ToString() + " level(s) of " + PosTraits.traits.ToString());

            switch (PosTraits.traits)
            {
            case PositiveTraits.Protection:
            {
                characterStats.Protection += PosTraits.traitLevel;
            }
            break;

            case PositiveTraits.Speed:
            {
                characterStats.Speed += PosTraits.traitLevel;
            }
            break;

            case PositiveTraits.Damage:
            {
                characterStats.Damage += PosTraits.traitLevel;
            }
            break;

            default:
                break;
            }
        }

        // apply the negative trait values of the equipment to the player stat
        foreach (Negatives NegTraits in Item.equipBP.NegativeTraits)
        {
            Debug.Log("Applying " + NegTraits.traitLevel.ToString() + " level(s) of " + NegTraits.traits.ToString());

            switch (NegTraits.traits)
            {
            case NegativeTraits.Slowness:
            {
                characterStats.Speed -= NegTraits.traitLevel;
            }
            break;

            case NegativeTraits.Exposure:
            {
                characterStats.Damage -= NegTraits.traitLevel;
            }
            break;

            default:
                break;
            }
        }
    }
 public void SetItemBlueprint(ItemBlueprint blueprint)
 {
     if (blueprint != null)
     {
         this.itemBlueprint = blueprint;
         icon.gameObject.SetActive(true);
         icon.sprite   = itemBlueprint.TargetItem.Icon;
         nameText.text = itemBlueprint.TargetItem.Name;
     }
 }
Beispiel #31
0
    public bool CanCraft(ItemDefinition def, int amount = 1, bool free = false)
    {
        ItemBlueprint component = def.GetComponent <ItemBlueprint>();

        if (CanCraft(component, amount, free))
        {
            return(true);
        }
        return(false);
    }
Beispiel #32
0
 public CraftEvent(ItemCrafter itemCrafter,
                   ItemBlueprint itemBlueprint,
                   BasePlayer owner,
                   ProtoBuf.Item.InstanceData instanceData,
                   int amount,
                   int skinid)
 {
     this.itemCrafter = itemCrafter;
     bluePrint = itemBlueprint;
     Crafter = Server.GetPlayer(owner);
     Target = itemBlueprint.targetItem;
     Amount = amount;
     SkinID = skinid;
 }
Beispiel #33
0
        // ItemCrafter.CraftItem()
        public static bool PlayerStartCrafting(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData = null, int amount = 1)
        {
            /*ItemBlueprint bpcopy = new ItemBlueprint();
            bpcopy.amountToCreate = bp.amountToCreate;
            bpcopy.defaultBlueprint = bp.defaultBlueprint;
            bpcopy.ingredients = bp.ingredients;
            bpcopy.rarity = bp.rarity;
            bpcopy.targetItem = bp.targetItem;
            bpcopy.time = bp.time / Server.GetInstance().CraftingTimeScale;
            bpcopy.userCraftable = bp.userCraftable;*/
            CraftEvent ce = new CraftEvent(self, bp, owner, instanceData, amount);
            OnPlayerStartCrafting.OnNext(ce);
            if (!self.CanCraft(bp, 1)) {
                return false;
            }
            if (ce.Cancel) {
                if (ce.cancelReason != "")
                    owner.SendConsoleCommand("chat.add", 0, String.Format("{0}: {1}", Server.server_message_name.ColorText("fa5"), ce.cancelReason));
                return false;
            }

            self.taskUID++;
            ItemCraftTask itemCraftTask = new ItemCraftTask();
            itemCraftTask.blueprint = bp;
            if (!ce.FreeCraft) {
                List<Item> list = new List<Item>();
                foreach (ItemAmount current in bp.ingredients) {
                    int amount2 = (int)current.amount * amount;
                    foreach (ItemContainer current2 in self.containers) {
                        amount2 -= current2.Take(list, current.itemid, amount2);
                    }
                }
                foreach (Item current2 in list) {
                    current2.Remove(0f);
                }
            }
            itemCraftTask.endTime = 0;
            itemCraftTask.taskUID = self.taskUID;
            itemCraftTask.owner = owner;
            itemCraftTask.instanceData = instanceData;
            itemCraftTask.amount = amount;
            self.queue.Enqueue(itemCraftTask);
            if (itemCraftTask.owner != null) {
                itemCraftTask.owner.Command("note.craft_add", new object[] {
                    itemCraftTask.taskUID,
                    itemCraftTask.blueprint.targetItem.itemid,
                    amount
                });
            }
            return true;
        }
Beispiel #34
0
 public bool LearnBlueprint(ItemBlueprint itembp)
 {
     ProtoBuf.PersistantPlayer playerInfo = ServerMgr.Instance.persistance.GetPlayerInfo(GameID);
     int itemID = itembp.targetItem.itemid;
     if (!playerInfo.blueprints.complete.Contains(itemID)) {
         playerInfo.blueprints.complete.Add(itemID);
         ServerMgr.Instance.persistance.SetPlayerInfo(GameID, playerInfo);
         basePlayer.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
         basePlayer.ClientRPCPlayer(null, basePlayer, "UnlockedBlueprint", itemID);
         return true;
     }
     return false;
 }
Beispiel #35
0
 public bool KnowsBlueprint(ItemBlueprint itembp)
 {
     ProtoBuf.PersistantPlayer playerInfo = ServerMgr.Instance.persistance.GetPlayerInfo(GameID);
     return playerInfo.blueprints.complete.Contains(itembp.targetItem.itemid);
 }
Beispiel #36
0
        /// <summary>
        /// Called from <c>ItemCrafter.CraftItem(ItemBlueprint, BasePlayer, ProtoBuf.Item.InstanceData, int, int, Item)</c> .
        /// </summary>
        public static bool On_PlayerStartCrafting(ItemCrafter self,
                                                  ItemBlueprint bp,
                                                  BasePlayer owner,
                                                  ProtoBuf.Item.InstanceData instanceData = null,
                                                  int amount = 1,
                                                  int skinID = 0,
                                                  Item fromTempBlueprint = null)
        {
            var ce = new CraftEvent(self, bp, owner, instanceData, amount, skinID);

            OnNext("On_PlayerStartCrafting", ce);

            if (!self.CanCraft(bp, ce.Amount))
                return false;

            if (ce.Cancel) {
                if (ce.cancelReason != String.Empty)
                    ce.Crafter.Message(ce.cancelReason);
                return false;
            }

            self.taskUID++;

            ItemCraftTask itemCraftTask = Facepunch.Pool.Get<ItemCraftTask>();
            itemCraftTask.blueprint = bp;
            self.CallMethod("CollectIngredients", bp, itemCraftTask, ce.Amount, owner);
            itemCraftTask.endTime = 0;
            itemCraftTask.taskUID = self.taskUID;
            itemCraftTask.owner = owner;
            itemCraftTask.instanceData = instanceData;

            if (itemCraftTask.instanceData != null) {
                itemCraftTask.instanceData.ShouldPool = false;
            }

            itemCraftTask.amount = ce.Amount;
            itemCraftTask.skinID = ce.SkinID;

            if (fromTempBlueprint != null) {
                fromTempBlueprint.RemoveFromContainer();
                itemCraftTask.takenItems.Add(fromTempBlueprint);
                itemCraftTask.conditionScale = 0.5f;
            }

            self.queue.Enqueue(itemCraftTask);

            if (itemCraftTask.owner != null) {
                itemCraftTask.owner.Command("note.craft_add", new object[] {
                    itemCraftTask.taskUID,
                    itemCraftTask.blueprint.targetItem.itemid,
                    amount
                });
            }

            return true;
        }