Exemple #1
0
        // ItemCrafter.CraftItem()
        public static bool PlayerStartCrafting(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData = null)
        {
            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, bpcopy, owner, instanceData);

            OnPlayerStartCrafting.OnNext(ce);
            if (!self.CanCraft(bpcopy, 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 = bpcopy;
            if (!ce.FreeCraft)
            {
                foreach (ItemAmount current in bpcopy.ingredients)
                {
                    float amount = current.amount;
                    foreach (ItemContainer current2 in self.containers)
                    {
                        amount -= current2.Take(itemCraftTask.ingredients, current.itemid, (int)amount);
                    }
                }
            }
            itemCraftTask.endTime      = 0;
            itemCraftTask.taskUID      = self.taskUID;
            itemCraftTask.owner        = owner;
            itemCraftTask.instanceData = instanceData;
            self.queue.Enqueue(itemCraftTask);
            if (itemCraftTask.owner != null)
            {
                itemCraftTask.owner.Command(String.Format("note.craft_add {0} {1}",
                                                          itemCraftTask.taskUID,
                                                          itemCraftTask.blueprint.targetItem.itemid));
            }
            return(true);
        }
Exemple #2
0
        // ItemCrafter.CraftItem()
        public static bool On_PlayerStartCrafting(ItemCrafter self, ItemBlueprint bp, BasePlayer owner, ProtoBuf.Item.InstanceData instanceData = null, int amount = 1, int skinID = 0)
        {
            CraftEvent 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, 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;
            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);
        }
        void BulkCraft(BasePlayer player, ItemCraftTask task, int amount)
        {
            ItemCrafter crafter = player.inventory.crafting;

            if (crafter.queue.ToArray()[0] == task)
            {
                amount--;
            }

            for (int i = 1; i <= amount; i++)
            {
                if (!crafter.CanCraft(task.blueprint, 1))
                {
                    break;
                }

                crafter.taskUID++;
                ItemCraftTask item = new ItemCraftTask {
                    blueprint = task.blueprint
                };

                CollectIngredients.Invoke(crafter, new object[] { item.blueprint, item.ingredients });
                if (craftingRate == 0)
                {
                    item.endTime = 1f;
                }
                else
                {
                    item.endTime = 0f;
                }
                item.taskUID      = crafter.taskUID;
                item.owner        = player;
                item.instanceData = null;
                crafter.queue.Enqueue(item);

                if (item.owner != null)
                {
                    object[] args = new object[] { item.taskUID, item.blueprint.targetItem.itemid };
                    item.owner.Command("note.craft_add", args);
                }
            }
        }
        private void CmdCraft(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, config.Permission))
            {
                player.ChatMessage(GetMsg("NoPermission", player));
                return;
            }
            if (player.currentCraftLevel < config.Workbench)
            {
                player.ChatMessage(GetMsg("Workbench", player, config.Workbench));
                return;
            }
            foreach (var ingredient in bp.ingredients)
            {
                var playeram = player.inventory.GetAmount(ingredient.itemDef.itemid);
                if (playeram >= ingredient.amount)
                {
                    continue;
                }
                var reply = bp.ingredients.Select(x =>
                                                  GetMsg(player.inventory.GetAmount(x.itemDef.itemid) >= x.amount
                            ? "EnoughtIngridient"
                            : "NotEnoughtIngridient"
                                                         , player, x.itemDef.displayName.translated, player.inventory.GetAmount(x.itemDef.itemid),
                                                         x.amount)).ToArray();
                player.ChatMessage(GetMsg("Noingridient", player, string.Join("\n", reply)));
                return;
            }
            ItemCrafter itemCrafter = player.inventory.crafting;

            if (!itemCrafter.CanCraft(bp))
            {
                return;
            }
            ++itemCrafter.taskUID;
            ItemCraftTask task = Facepunch.Pool.Get <ItemCraftTask>();

            task.blueprint = bp;
            List <Item> items = new List <Item>();

            foreach (var ingridient in bp.ingredients)
            {
                var amount = (int)ingridient.amount;
                foreach (var container in itemCrafter.containers)
                {
                    amount -= container.Take(items, ingridient.itemid, amount);
                    if (amount > 0)
                    {
                        continue;
                    }
                    break;
                }
            }
            task.potentialOwners = new List <ulong>();
            foreach (var item in items)
            {
                item.CollectedForCrafting(player);
                if (task.potentialOwners.Contains(player.userID))
                {
                    continue;
                }
                task.potentialOwners.Add(player.userID);
            }
            task.takenItems   = items;
            task.endTime      = 0.0f;
            task.taskUID      = itemCrafter.taskUID;
            task.owner        = player;
            task.instanceData = null;
            task.amount       = 1;
            task.skinID       = 0;
            object obj = Interface.CallHook("OnItemCraft", task, player, null);

            if (obj is bool)
            {
                return;
            }
            itemCrafter.queue.Enqueue(task);
            if (task.owner != null)
            {
                player.Command("note.craft_add", task.taskUID, task.blueprint.targetItem.itemid, 1);
            }
        }
Exemple #5
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;
        }
Exemple #6
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;
        }