Example #1
0
 public static string FormatRequest(CraftingRequest req, bool showCompleted = false)
 {
     if (req.status == OrderStatus.Completed && !showCompleted)
     {
         return("");
     }
     return($"[ID:{req.id}] {req.quantity}x {req.itemName} | Crafter: {req.assignedCrafter} | Status: {req.status} | Requester: {req.Requester} {Environment.NewLine}");
 }
Example #2
0
        public void Craft_CraftingRequest()
        {
            //Give resources to craft
            GiveResources();

            CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)];

            craftingSubSystem.MakeRequest(shopAgent, (int)randomSword);

            Dictionary <ShopAgent, CraftingRequest> shopRequest = craftingSubSystem.GetShopRequests();
            CraftingRequest craftingRequest = shopRequest[shopAgent];

            Assert.AreEqual(0, craftingRequest.CraftingTime);
            Assert.AreEqual(3, craftingRequest.CraftingRequirements.timeToCreation);

            UsableItem craftedItem = GetUsableItemByCraftingChoice(randomSword);

            Assert.AreEqual(craftedItem, craftingRequest.CraftingRequirements.resultingItem);
        }
Example #3
0
        public void Craft_MakeRequest()
        {
            //To be sure to have the correct agent
            shopAgent = getShopAgent.CurrentAgent;

            Time.timeScale = 100;

            //Give resources to craft
            GiveResources();
            GiveResources();

            //Craft one sword of each type
            foreach (CraftingChoice choice in listCraftingChoices)
            {
                craftingSubSystem.MakeRequest(shopAgent, (int)choice);

                Debug.Log("CraftingChoice : " + choice);
                Debug.Log("craftingSubSystem null : " + (craftingSubSystem == null));
                Debug.Log("craftingSubSystem.GetShopRequests().Count : " + craftingSubSystem.GetShopRequests().Count);
                Debug.Log("craftingSubSystem.GetShopRequests().Contains(agent) : " + craftingSubSystem.GetShopRequests().ContainsKey(shopAgent));
                Debug.Log("shopAgent : " + shopAgent);

                CraftingRequest cr = craftingSubSystem.GetShopRequests()[shopAgent];

                int a = 20;                 //To avoid infinite loop
                while (a > 0 && cr.Complete == false)
                {
                    craftingSubSystem.Update();
                    a--;
                }

                //No more Crafting
                Assert.True(cr.Complete, "Craft never complete : " + a);
                Assert.False(craftingSubSystem.HasRequest(shopAgent));

                //AgentInventory contains the item
                Assert.True(shopAgent.agentInventory.ContainsItem(GetUsableItemByCraftingChoice(choice)), "Do not contain the crafted item");
            }

            Time.timeScale = 1;
        }
Example #4
0
        public static bool StartCraftingJob(string playerId, int slot, CraftingRequest request)         // TODO: Check if slot not unlocked (not a big priority)
        {
            recipeList ??= Recipes.FromFile("./data/recipes");

            var recipe = recipeList.result.crafting.Find(match => match.id == request.RecipeId);

            if (recipe != null)
            {
                var itemsToReturn = recipe.returnItems.ToList();

                foreach (RecipeIngredients ingredient in recipe.ingredients)
                {
                    if (itemsToReturn.Find(match =>
                                           match.id == ingredient.items[0] && match.amount == ingredient.quantity) == null)
                    {
                        InventoryUtils.RemoveItemFromInv(playerId, ingredient.items[0], ingredient.quantity * request.Multiplier);
                    }
                }

                var nextStreamId = GenericUtils.GetNextStreamVersion();

                CraftingSlotInfo job = new CraftingSlotInfo
                {
                    available          = 0,
                    boostState         = null,
                    completed          = 0,
                    escrow             = request.Ingredients,
                    nextCompletionUtc  = null,
                    output             = recipe.output,
                    recipeId           = recipe.id,
                    sessionId          = request.SessionId,
                    state              = "Active",
                    streamVersion      = nextStreamId,
                    total              = request.Multiplier,
                    totalCompletionUtc = DateTime.UtcNow.Add(recipe.duration.TimeOfDay * request.Multiplier),
                    unlockPrice        = null
                };

                if (request.Multiplier != 1)
                {
                    job.nextCompletionUtc = DateTime.UtcNow.Add(recipe.duration.TimeOfDay);
                }

                if (!craftingJobs.ContainsKey(playerId))
                {
                    craftingJobs.Add(playerId, new Dictionary <int, CraftingSlotInfo>());
                    craftingJobs[playerId].Add(1, new CraftingSlotInfo());
                    craftingJobs[playerId].Add(2, new CraftingSlotInfo());
                    craftingJobs[playerId].Add(3, new CraftingSlotInfo());
                }

                craftingJobs[playerId][slot] = job;

                UtilityBlockUtils.UpdateUtilityBlocks(playerId, slot, job);

                Log.Debug($"[{playerId}]: Initiated crafting job in slot {slot}.");

                return(true);
            }

            return(false);
        }