Exemplo n.º 1
0
        public static CraftingUpdates RemoveBoost(string playerId, string boostInstanceId)
        {
            var nextStreamId   = GenericUtils.GetNextStreamVersion();
            var baseBoosts     = ReadBoosts(playerId);
            var potionToRemove = baseBoosts.result.potions.Find(match => match.instanceId == boostInstanceId);
            var boostToRemove  = catalog.result.items.Find(match => match.id == potionToRemove.itemId);

            baseBoosts.result.scenarioBoosts.death?.RemoveAll(match => match.instanceId == boostInstanceId);

            baseBoosts.result.potions.Remove(potionToRemove);
            baseBoosts.result.activeEffects.RemoveAll(match =>
                                                      boostToRemove.item.boostMetadata.effects.Contains(match.effect) && match.expiration == potionToRemove.expiration);

            baseBoosts.result.statusEffects = CalculateStatusEffects(baseBoosts);

            WriteBoosts(playerId, baseBoosts);

            var updates = new CraftingUpdates {
                updates = new Updates()
            };

            updates.updates.boosts = nextStreamId;

            return(updates);
        }
Exemplo n.º 2
0
        public static CraftingUpdates UnlockCraftingSlot(string playerId, int slot)
        {
            var job = craftingJobs[playerId][slot];

            RubyUtils.SetRubies(playerId, job.unlockPrice.cost - job.unlockPrice.discount, false);
            job.state       = "Empty";
            job.unlockPrice = null;

            var nextStreamId  = GenericUtils.GetNextStreamVersion();
            var returnUpdates = new CraftingUpdates {
                updates = new Updates()
            };

            UtilityBlockUtils.UpdateUtilityBlocks(playerId, slot, job);

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

            returnUpdates.updates.crafting = nextStreamId;

            return(returnUpdates);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PostNewCraftingJob(int slot)
        {
            string authtoken = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var stream = new StreamReader(Request.Body);
            var body   = await stream.ReadToEndAsync();

            var req = JsonConvert.DeserializeObject <CraftingRequest>(body);

            var craftingJob = CraftingUtils.StartCraftingJob(authtoken, slot, req);


            var updateResponse = new CraftingUpdates {
                updates = new Updates()
            };

            var nextStreamId = GenericUtils.GetNextStreamVersion();

            updateResponse.updates.crafting  = nextStreamId;
            updateResponse.updates.inventory = nextStreamId;

            return(Content(JsonConvert.SerializeObject(updateResponse), "application/json"));
            //return Accepted(Content(returnUpdates, "application/json"));
        }
Exemplo n.º 4
0
        public static CraftingUpdates ActivateBoost(string playerId, Guid boostId)
        {
            var updates = new CraftingUpdates {
                updates = new Updates()
            };

            List <DateTime> expirationTimes = new List <DateTime>();           // This looks bad (and it totally is), but we can optimize it at a later date
            var             currentTime     = DateTime.UtcNow;

            var baseBoosts   = ReadBoosts(playerId);
            var boostToApply = catalog.result.items.Find(match => match.id == boostId);


            var indexNum = 0;

            if (baseBoosts.result.scenarioBoosts.death != null)
            {
                indexNum = baseBoosts.result.scenarioBoosts.death.Count;                 // Only used if boost is scenario specific
            }
            var nextStreamId = GenericUtils.GetNextStreamVersion();

            var locOfEffect = baseBoosts.result.activeEffects.Find(match => match.effect == boostToApply.item.boostMetadata.effects[0]);             // null when not an active effect, e.g scenario boost

            ActiveBoost locOfBoost = null;


            if (baseBoosts.result.scenarioBoosts.death != null)
            {
                locOfBoost = baseBoosts.result.scenarioBoosts.death.Find(match =>
                                                                         match.effects.Any(pred => pred == boostToApply.item.boostMetadata.effects[0]));
            }

            if (locOfEffect != null && boostToApply.item.boostMetadata.additive && boostToApply.item.boostMetadata.scenario == null)
            {
                locOfEffect.effect.duration += boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay;
                baseBoosts.result.potions.Find(match => match.itemId == boostId).expiration +=
                    boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay;
            }
            else if (locOfBoost != null && boostToApply.item.boostMetadata.additive && boostToApply.item.boostMetadata.scenario == "Death")
            {
                indexNum = baseBoosts.result.scenarioBoosts.death.IndexOf(locOfBoost);
                locOfBoost.expiration += boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay;
                baseBoosts.result.potions.Find(match => match.itemId == boostId).expiration += boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay;
            }
            else
            {
                Dictionary <Guid, string> uuidDict = new Dictionary <Guid, string>();
                if (boostToApply.item.boostMetadata.scenario == null)
                {
                    foreach (Item.Effect effect in boostToApply.item.boostMetadata.effects)
                    {
                        baseBoosts.result.activeEffects.Add(new ActiveEffect {
                            effect = effect, expiration = currentTime.Add(effect.duration.Value)
                        });
                    }
                }
                else
                {
                    baseBoosts.result.scenarioBoosts.death ??= new List <ActiveBoost>();

                    baseBoosts.result.scenarioBoosts.death.Add(new ActiveBoost {
                        effects = new List <Item.Effect>(), enabled = true, expiration = currentTime.Add(boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay), instanceId = Guid.NewGuid().ToString()
                    });

                    foreach (Item.Effect effect in boostToApply.item.boostMetadata.effects)
                    {
                        baseBoosts.result.scenarioBoosts.death[indexNum].effects.Add(effect);
                    }

                    uuidDict.Add(boostId, baseBoosts.result.scenarioBoosts.death[indexNum].instanceId);
                }

                Potion potion = null;

                if (boostToApply.item.boostMetadata.activeDuration != null)
                {
                    potion = new Potion {
                        enabled = true, expiration = currentTime.Add(boostToApply.item.boostMetadata.activeDuration.Value.TimeOfDay), instanceId = Guid.NewGuid().ToString(), itemId = boostId
                    };
                }
                else if (boostToApply.item.boostMetadata.effects[0].duration != null)
                {
                    potion = new Potion {
                        enabled = true, expiration = currentTime.Add(boostToApply.item.boostMetadata.effects[0].duration.Value), instanceId = Guid.NewGuid().ToString(), itemId = boostId
                    };
                }

                if (uuidDict.ContainsKey(boostId) && potion != null)
                {
                    potion.instanceId = uuidDict[boostId];
                }

                var nullPotionIndex = baseBoosts.result.potions.FindIndex(match => match == null);
                if (nullPotionIndex != -1)
                {
                    baseBoosts.result.potions[nullPotionIndex] = potion;
                }
            }


            if (boostToApply.item.boostMetadata.canBeRemoved)
            {
                InventoryUtils.RemoveItemFromInv(playerId, boostId);                 // UNCOMMENT/COMMENT THIS LINE TO REMOVE BOOSTS FROM INVENTORY WHEN USED
                updates.updates.inventory = nextStreamId;
            }

            foreach (ActiveEffect effect in baseBoosts.result.activeEffects)
            {
                expirationTimes.Add(effect.expiration.Value);
            }

            if (baseBoosts.result.scenarioBoosts.death != null)
            {
                foreach (ActiveBoost boost in baseBoosts.result.scenarioBoosts.death)
                {
                    expirationTimes.Add(boost.expiration.Value);
                }
            }

            baseBoosts.result.expiration = expirationTimes.Min();

            baseBoosts.result.statusEffects = CalculateStatusEffects(baseBoosts);

            WriteBoosts(playerId, baseBoosts);
            updates.updates.boosts = nextStreamId;
            return(updates);
        }