Exemplo n.º 1
0
        public static CraftingSlotResponse CancelCraftingJob(string playerId, int slot)
        {
            var job          = craftingJobs[playerId][slot];
            var nextStreamId = GenericUtils.GetNextStreamVersion();
            var resp         = new CraftingSlotResponse {
                result = new CraftingSlotInfo(), updates = new Updates()
            };

            foreach (InputItem item in job.escrow)
            {
                InventoryUtils.AddItemToInv(playerId, item.itemId, item.quantity);
            }

            job.nextCompletionUtc  = null;
            job.available          = 0;
            job.completed          = 0;
            job.recipeId           = null;
            job.sessionId          = null;
            job.state              = "Empty";
            job.total              = 0;
            job.boostState         = null;
            job.totalCompletionUtc = null;
            job.unlockPrice        = null;
            job.output             = null;
            job.streamVersion      = nextStreamId;

            UtilityBlockUtils.UpdateUtilityBlocks(playerId, slot, job);

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

            resp.updates.crafting = nextStreamId;
            return(resp);
        }
Exemplo n.º 2
0
        public static Updates RedeemRewards(string playerId, Rewards rewards)
        {
            Updates updates      = new Updates();
            uint    nextStreamId = GenericUtils.GetNextStreamVersion();

            foreach (var buildplate in rewards.Buildplates)
            {
                BuildplateUtils.AddToPlayer(playerId, buildplate.Id);
                updates.buildplates = nextStreamId;
            }

            foreach (var challenge in rewards.Challenges)
            {
                //ChallengeUtils.AddToPlayer(playerId, challenge.id);
                updates.challenges = nextStreamId;
            }

            foreach (var item in rewards.Inventory)
            {
                InventoryUtils.AddItemToInv(playerId, item.Id, item.Amount);
                updates.inventory     = nextStreamId;
                updates.playerJournal = nextStreamId;
            }

            foreach (var utilityBlock in rewards.UtilityBlocks)
            {
                // TODO: This is most likely unused in the actual game, since crafting tables/furnaces dont have ids
            }

            foreach (var personaItem in rewards.PersonaItems)
            {
                // PersonaUtils.AddToPlayer(playerId, personaItem) If we can ever implement CC, this is already in place
            }

            if (rewards.ExperiencePoints != null)
            {
                ProfileUtils.AddExperienceToPlayer(playerId, rewards.ExperiencePoints.Value);
                updates.characterProfile = nextStreamId;
            }

            return(updates);
        }
Exemplo n.º 3
0
        public static CollectItemsResponse FinishCraftingJob(string playerId, int slot)
        {
            var job           = craftingJobs[playerId][slot];
            var recipe        = recipeList.result.crafting.Find(match => match.id == job.recipeId & !match.deprecated);
            int craftedAmount = 0;

            var nextStreamId = GenericUtils.GetNextStreamVersion();

            var returnResponse = new CollectItemsResponse {
                result = new CollectItemsInfo {
                    rewards = new Rewards(),
                }, updates = new Updates()
            };

            if (job.completed != job.total && job.nextCompletionUtc != null)
            {
                if (DateTime.UtcNow >= job.nextCompletionUtc)
                {
                    craftedAmount++;
                    while (DateTime.UtcNow >= job.nextCompletionUtc && job.nextCompletionUtc.Value.Add(recipe.duration.TimeOfDay) < job.totalCompletionUtc && craftedAmount < job.total - job.completed)
                    {
                        job.nextCompletionUtc = job.nextCompletionUtc.Value.Add(recipe.duration.TimeOfDay);
                        craftedAmount++;
                    }

                    job.nextCompletionUtc = job.nextCompletionUtc.Value.Add(recipe.duration.TimeOfDay);
                    job.completed        += craftedAmount;
                    //job.available -= craftedAmount;
                    for (int i = 0; i < job.escrow.Length - 1; i++)
                    {
                        job.escrow[i].quantity -= recipe.ingredients[i].quantity * craftedAmount;
                    }

                    job.streamVersion = nextStreamId;

                    InventoryUtils.AddItemToInv(playerId, job.output.itemId, job.output.quantity * craftedAmount);
                }
            }
            else
            {
                craftedAmount = job.available;
                InventoryUtils.AddItemToInv(playerId, job.output.itemId, job.output.quantity * craftedAmount);
                // TODO: Add to challenges, tokens, journal (when implemented)
            }

            if (!TokenUtils.GetTokenResponseForUserId(playerId).Result.tokens.Any(match => match.Value.clientProperties.ContainsKey("itemid") && match.Value.clientProperties["itemid"] == job.output.itemId.ToString()))
            {
                //TokenUtils.AddItemToken(playerId, job.output.itemId); -> List of item tokens not known. Could cause issues later, for now we just disable it.
                returnResponse.updates.tokens = nextStreamId;
            }

            returnResponse.result.rewards.Inventory = returnResponse.result.rewards.Inventory.Append(new RewardComponent {
                Amount = job.output.quantity * craftedAmount, Id = job.output.itemId
            }).ToArray();

            returnResponse.updates.crafting      = nextStreamId;
            returnResponse.updates.inventory     = nextStreamId;
            returnResponse.updates.playerJournal = nextStreamId;


            if (job.completed == job.total || job.nextCompletionUtc == null)
            {
                job.nextCompletionUtc  = null;
                job.available          = 0;
                job.completed          = 0;
                job.recipeId           = null;
                job.sessionId          = null;
                job.state              = "Empty";
                job.total              = 0;
                job.boostState         = null;
                job.totalCompletionUtc = null;
                job.unlockPrice        = null;
                job.output             = null;
                job.streamVersion      = nextStreamId;
            }

            UtilityBlockUtils.UpdateUtilityBlocks(playerId, slot, job);

            Log.Debug($"[{playerId}]: Collected results of crafting slot {slot}.");

            return(returnResponse);
        }