Ejemplo n.º 1
0
        private void AdjustLoots()
        {
            ResetRequiredItems();

            foreach (var item in FirstTrader.Items.ToArray())
            {
                var requiredItem = GetRequiredItem(item.Template.Id);
                if (requiredItem != null)
                {
                    requiredItem.Count += item.Stack;
                }
                else
                {
                    FirstTrader.MoveItemToInventory(item, (int)item.Stack);
                }
            }

            var dofusLegendaire = ItemManager.Instance.TryGetTemplate(NpcDofus.RewardItemId);
            var itemDofus       = SecondTrader.Items.FirstOrDefault(item => item.Template.Id == dofusLegendaire.Id);

            if (itemDofus == null)
            {
                if (!CanExchange())
                {
                    return;
                }

                SecondTrader.AddItem(dofusLegendaire, 1);
                return;
            }

            SecondTrader.RemoveItem(itemDofus.Template, itemDofus.Stack);
            InventoryHandler.SendExchangeObjectRemovedMessage(FirstTrader.Character.Client, true, itemDofus.Guid);
        }
Ejemplo n.º 2
0
        public void AdjustLoots()
        {
            SecondTrader.Clear();

            if (FirstTrader.Items.Count != 2)
            {
                return;
            }

            var eniripsaPowder    = FirstTrader.Items.FirstOrDefault(x => x.Template.Id == (int)ItemIdEnum.POUDRE_DENIRIPSA_2239)?.Stack ?? 0;
            var resurectionPowder = FirstTrader.Items.FirstOrDefault(x => x.Template.Id == (int)ItemIdEnum.POUDRE_DE_RESURRECTION_8012)?.Stack ?? 0;

            if ((eniripsaPowder == 0 && resurectionPowder == 0) || (eniripsaPowder != 0 && resurectionPowder != 0))
            {
                return;
            }

            var ghost = FirstTrader.Items.OfType <PlayerTradeItem>().FirstOrDefault(x => x.Template.Type.ItemType == ItemTypeEnum.FANTÔME_DE_FAMILIER ||
                                                                                    x.Template.Type.ItemType == ItemTypeEnum.FANTÔME_DE_MONTILIER);
            var pet = FirstTrader.Items.OfType <PlayerTradeItem>().FirstOrDefault(x => x.Template.Type.ItemType == ItemTypeEnum.FAMILIER ||
                                                                                  x.Template.Type.ItemType == ItemTypeEnum.MONTILIER);

            if (ghost != null)
            {
                var petTemplate = PetManager.Instance.Pets.Values.FirstOrDefault(x => x.GhostItemId == ghost.Template.Id);

                if (petTemplate == null)
                {
                    logger.Error($"Ghost {ghost.Template.Id} has no matching pet");
                    return;
                }

                var itemTemplate = ItemManager.Instance.TryGetTemplate(petTemplate.Id);

                if (itemTemplate == null)
                {
                    logger.Error($"Pet {petTemplate.Id} is no valid item !");
                    return;
                }

                var effects  = ghost.Effects.Clone();
                var hpEffect = effects.OfType <EffectInteger>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_LifePoints);

                if (hpEffect == null)
                {
                    effects.Add(hpEffect = new EffectInteger(EffectsEnum.Effect_LifePoints, 0));
                }

                var maxHp = itemTemplate.Effects.OfType <EffectDice>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_LifePoints)?.Value ?? 0;
                if (eniripsaPowder > 0)
                {
                    if (petTemplate.PossibleEffects.Count > 0)
                    {
                        effects.RemoveAll(x => x != hpEffect && x.EffectId != EffectsEnum.Effect_MealCount);
                    }

                    hpEffect.Value = (short)Math.Min(maxHp, eniripsaPowder);
                }
                else
                {
                    hpEffect.Value = maxHp;
                }

                SecondTrader.AddItem(itemTemplate, 1, effects);
            }
            else if (pet != null && eniripsaPowder > 0)
            {
                var petItem = pet.PlayerItem as PetItem;

                if (petItem == null)
                {
                    return;
                }

                var effects  = pet.Effects.Clone();
                var hpEffect = effects.OfType <EffectInteger>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_LifePoints);

                if (hpEffect == null)
                {
                    return;
                }

                hpEffect.Value += (short)eniripsaPowder;

                if (hpEffect.Value > petItem.MaxLifePoints)
                {
                    hpEffect.Value = (short)petItem.MaxLifePoints;
                }

                SecondTrader.AddItem(petItem.Template, 1, effects);
            }
        }
Ejemplo n.º 3
0
        public void AdjustLoots()
        {
            SecondTrader.Clear();
            Kamas = 0;

            if (FirstTrader.Items.Count != 1 || FirstTrader.Items.Any(x => x.Stack != 1))
            {
                return;
            }


            if (FirstTrader.Items.OfType <PlayerTradeItem>().FirstOrDefault(x => x.PlayerItem is PetItem)?.PlayerItem is PetItem pet)
            {
                Kamas = (int)((DateTime.Now - pet.LastMealDate)?.TotalHours ?? 0);

                if (FirstTrader.Character.Inventory.Kamas < Kamas)
                {
                    //Le montant de la transaction s'élève à %1 kamas. Malheureusement vous n'avez actuellement pas cette somme sur vous.
                    FirstTrader.Character.SendInformationMessage(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 128, Kamas);
                    return;
                }

                var certificateTemplate = ItemManager.Instance.TryGetTemplate(pet.PetTemplate.CertificateItemId.Value);

                if (certificateTemplate == null)
                {
                    return;
                }

                var effects = pet.Effects.Clone();

                var lastMealEffect = effects.OfType <EffectDate>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_LastMealDate);

                if (lastMealEffect == null)
                {
                    effects.Add(new EffectDate(EffectsEnum.Effect_LastMealDate, DateTime.Now));
                }
                else
                {
                    lastMealEffect.SetDate(DateTime.Now);
                }

                SecondTrader.AddItem(certificateTemplate, 1, effects);
                InventoryHandler.SendExchangeKamaModifiedMessage(FirstTrader.Character.Client, false, Kamas);
            }
            else
            {
                var certificate = FirstTrader.Items.OfType <PlayerTradeItem>().FirstOrDefault(x =>
                                                                                              x.Template.Type.ItemType == ItemTypeEnum.CERTIFICAT_DE_FAMILIER ||
                                                                                              x.Template.Type.ItemType == ItemTypeEnum.CERTIFICAT_DE_MONTILIER);

                if (certificate == null)
                {
                    return;
                }

                var lastMealEffect = certificate.Effects.OfType <EffectDate>().FirstOrDefault(x => x.EffectId == EffectsEnum.Effect_LastMealDate)?.GetDate() ?? DateTime.Now;

                Kamas = (int)(DateTime.Now - lastMealEffect).TotalHours;

                if (FirstTrader.Character.Inventory.Kamas < Kamas)
                {
                    //Le montant de la transaction s'élève à %1 kamas. Malheureusement vous n'avez actuellement pas cette somme sur vous.
                    FirstTrader.Character.SendInformationMessage(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 128, Kamas);
                    return;
                }

                var petTemplate = PetManager.Instance.Pets.Values.FirstOrDefault(x => x.CertificateItemId == certificate.Template.Id);

                if (petTemplate == null)
                {
                    logger.Error($"Certificate {certificate.Template.Id} has no matching pet");
                    return;
                }

                var itemTemplate = ItemManager.Instance.TryGetTemplate(petTemplate.Id);

                if (itemTemplate == null)
                {
                    logger.Error($"Pet {petTemplate.Id} is no valid item !");
                    return;
                }

                SecondTrader.AddItem(itemTemplate, 1, certificate.Effects);
                InventoryHandler.SendExchangeKamaModifiedMessage(FirstTrader.Character.Client, false, Kamas);
            }
        }