Exemple #1
0
        public LootTemplate GetById(int?id)
        {
            LootTemplate lootTemplate = _context.LootTemplates
                                        .Include(d => d.RuleSet)
                                        .Include(d => d.LootTemplateRandomizationEngines) //.ThenInclude(x=>x)
                                                                                          //.Include(d=>d.)
                                        .Where(x => x.LootTemplateId == id && x.IsDeleted != true)
                                        .FirstOrDefault();

            if (lootTemplate == null)
            {
                return(lootTemplate);
            }
            else
            {
                if (lootTemplate.LootTemplateRandomizationEngines != null)
                {
                    lootTemplate.LootTemplateRandomizationEngines = lootTemplate.LootTemplateRandomizationEngines.Where(z => z.IsDeleted != true).ToList();
                    if (lootTemplate.LootTemplateRandomizationEngines.Count > 0)
                    {
                        foreach (var item in lootTemplate.LootTemplateRandomizationEngines)
                        {
                            item.ItemMaster = _context.ItemMasters.Where(x => x.ItemMasterId == item.ItemMasterId && x.IsDeleted != true).FirstOrDefault();
                        }
                    }
                }
            }

            return(lootTemplate);
        }
Exemple #2
0
            private LootTemplate CreateTemplate(int Entry)
            {
                LootTemplate newTemplate = new LootTemplate();

                Templates.Add(Entry, newTemplate);
                DataTable MysqlQuery = new DataTable();

                WorldServiceLocator._WorldServer.WorldDatabase.Query(string.Format("SELECT {0}.*,conditions.type,conditions.value1, conditions.value2 FROM {0} LEFT JOIN conditions ON {0}.`condition_id`=conditions.`condition_entry` WHERE entry = {1};", Name, Entry), ref MysqlQuery);
                if (MysqlQuery.Rows.Count == 0)
                {
                    Templates[Entry] = null;
                    return(null);
                }
                IEnumerator enumerator = default;

                try
                {
                    enumerator = MysqlQuery.Rows.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DataRow       row  = (DataRow)enumerator.Current;
                        int           Item = row.As <int>("item");
                        float         ChanceOrQuestChance = row.As <float>("ChanceOrQuestChance");
                        byte          GroupID             = row.As <byte>("groupid");
                        int           MinCountOrRef       = row.As <int>("mincountOrRef");
                        byte          MaxCount            = row.As <byte>("maxcount");
                        ConditionType LootCondition       = ConditionType.CONDITION_NONE;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["type"])))
                        {
                            LootCondition = (ConditionType)row.As <int>("type");
                        }
                        int ConditionValue1 = 0;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["value1"])))
                        {
                            ConditionValue1 = row.As <int>("value1");
                        }
                        int ConditionValue2 = 0;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["value2"])))
                        {
                            ConditionValue2 = row.As <int>("value2");
                        }
                        LootStoreItem newItem = new LootStoreItem(Item, Math.Abs(ChanceOrQuestChance), GroupID, MinCountOrRef, MaxCount, LootCondition, ConditionValue1, ConditionValue2, ChanceOrQuestChance < 0f);
                        newTemplate.AddItem(ref newItem);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                return(newTemplate);
            }
Exemple #3
0
 public async Task <LootTemplate> Create(LootTemplate lootPile)
 {
     try
     {
         lootPile.LootTemplateRandomizationEngines = new List <LootTemplateRandomizationEngine>();
         return(await _repo.Add(lootPile));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #4
0
        public async Task Remove(LootTemplate loot)
        {
            if (string.IsNullOrWhiteSpace(loot.ObjectId))
            {
                return;
            }

            await Task.Run(() =>
            {
                DatabaseManager.Database.DeleteObject(loot);
            });
        }
Exemple #5
0
        public async Task <LootTemplate> Update(LootTemplate item, ICollection <LootTemplateRandomizationEngine> lootTemplateRandomizationEngines)
        {
            try
            {
                var lootTemplate = _context.LootTemplates.FirstOrDefault(x => x.LootTemplateId == item.LootTemplateId);

                if (lootTemplate == null)
                {
                    return(lootTemplate);
                }

                lootTemplate.Name        = item.Name;
                lootTemplate.ImageUrl    = item.ImageUrl;
                lootTemplate.Metatags    = item.Metatags;
                lootTemplate.Description = item.Description;
                lootTemplate.gmOnly      = item.gmOnly;
                lootTemplate.Mode        = item.Mode;
                var mrEngineList = _context.LootTemplateRandomizationEngines.Where(x => x.LootTemplateId == item.LootTemplateId && x.IsDeleted != true).ToList();
                foreach (var MRE in mrEngineList)
                {
                    MRE.IsDeleted = true;
                }
                _context.SaveChanges();

                if (lootTemplate.Mode == Core.MODE.NoItems)
                {
                    var resToDelete = _context.LootTemplateRandomizationEngines.Where(x => x.LootTemplateId == item.LootTemplateId);
                    _context.LootTemplateRandomizationEngines.RemoveRange(resToDelete);
                    _context.SaveChanges();

                    var _randomizationSearchField = _context.LootTemplateRandomizationSearch.Where(x => x.LootTemplateId == item.LootTemplateId);
                    _context.LootTemplateRandomizationSearch.RemoveRange(_randomizationSearchField);
                    await _context.SaveChangesAsync();
                }
                else if (lootTemplateRandomizationEngines != null && lootTemplateRandomizationEngines.Count > 0)
                {
                    var resToDelete = _context.LootTemplateRandomizationEngines.Where(x => x.LootTemplateId == item.LootTemplateId);
                    _context.LootTemplateRandomizationEngines.RemoveRange(resToDelete);
                    _context.SaveChanges();
                    insertRandomizationEngines(lootTemplateRandomizationEngines.ToList(), item.LootTemplateId);
                }

                return(lootTemplate);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #6
0
 public void Process(ref LootObject Loot, byte GroupID)
 {
     if (GroupID > 0)
     {
         if (Groups.ContainsKey(GroupID))
         {
             Groups[GroupID].Process(ref Loot);
         }
         return;
     }
     checked
     {
         int num = Items.Count - 1;
         for (int i = 0; i <= num; i++)
         {
             if (!Items[i].Roll())
             {
                 continue;
             }
             if (Items[i].MinCountOrRef < 0)
             {
                 LootTemplate Referenced = WorldServiceLocator._WS_Loot.LootTemplates_Reference.GetLoot(-Items[i].MinCountOrRef);
                 if (Referenced != null)
                 {
                     int maxCount = Items[i].MaxCount;
                     for (int j = 1; j <= maxCount; j++)
                     {
                         Referenced.Process(ref Loot, Items[i].Group);
                     }
                 }
             }
             else
             {
                 List <LootItem>      items = Loot.Items;
                 List <LootStoreItem> items2;
                 int           index;
                 LootStoreItem Item = (items2 = Items)[index = i];
                 LootItem      item = new LootItem(ref Item);
                 items2[index] = Item;
                 items.Add(item);
             }
         }
         foreach (KeyValuePair <byte, LootGroup> group in Groups)
         {
             group.Value.Process(ref Loot);
         }
     }
 }
        // Item Add
        private async void button3_Click(object sender, EventArgs e)
        {
            if (_model?.MobXLootTemplate == null)
            {
                return;
            }

            var model = new LootTemplate
            {
                TemplateName = _model.MobXLootTemplate.LootTemplateName
            };

            BindingService.SyncData(model, this);

            BindingService.ToggleEnabled(this);
            await _lootTemplateService.Save(model);

            await LoadTemplate(_model.MobXLootTemplate.ObjectId);

            BindingService.ToggleEnabled(this);
        }
Exemple #8
0
        public async Task <LootTemplateVM> GetLootTemplateVMById(int?id)
        {
            LootTemplateVM _LootTemplate = new LootTemplateVM();

            LootTemplate lootTemplate = await _context.LootTemplates
                                        .Include(d => d.RuleSet)
                                        .Include(d => d.LootTemplateRandomizationEngines)
                                        .Where(x => x.LootTemplateId == id && x.IsDeleted != true)
                                        .FirstOrDefaultAsync();

            if (lootTemplate == null)
            {
                return(null);
            }
            else
            {
                _LootTemplate = new LootTemplateVM()
                {
                    Description    = lootTemplate.Description,
                    gmOnly         = lootTemplate.gmOnly,
                    ImageUrl       = lootTemplate.ImageUrl,
                    LootTemplateId = lootTemplate.LootTemplateId,
                    Metatags       = lootTemplate.Metatags,
                    Name           = lootTemplate.Name,
                    RuleSet        = lootTemplate.RuleSet,
                    RuleSetId      = lootTemplate.RuleSetId,
                    IsDeleted      = lootTemplate.IsDeleted,
                    LootTemplateRandomizationEngines = lootTemplate.LootTemplateRandomizationEngines,
                    //LootTemplateRandomizationSearch = lootTemplate.sea
                };

                if (_LootTemplate.LootTemplateRandomizationEngines != null)
                {
                    _LootTemplate.LootTemplateRandomizationEngines = lootTemplate.LootTemplateRandomizationEngines.Where(z => z.IsDeleted != true).ToList();
                    if (_LootTemplate.LootTemplateRandomizationEngines.Count > 0)
                    {
                        foreach (var item in _LootTemplate.LootTemplateRandomizationEngines)
                        {
                            item.ItemMaster = _context.ItemMasters.Where(x => x.ItemMasterId == item.ItemMasterId && x.IsDeleted != true).FirstOrDefault();
                        }
                    }
                }
                _LootTemplate.LootTemplateRandomizationSearch = _context.LootTemplateRandomizationSearch
                                                                .Where(search => search.LootTemplateId == _LootTemplate.LootTemplateId)
                                                                .Select(search => new LootTemplateRandomizationSearch
                {
                    LootTemplateId        = search.LootTemplateId,
                    Quantity              = search.Quantity,
                    QuantityString        = search.QuantityString,
                    String                = search.String,
                    ItemRecord            = search.ItemRecord,
                    IsAnd                 = search.IsAnd,
                    SortOrder             = search.SortOrder,
                    IsDeleted             = false,
                    RandomizationSearchId = search.RandomizationSearchId,
                    Fields                = _context.RandomizationSearchFields.Where(t => t.RandomizationSearchId == search.RandomizationSearchId).ToList()
                }).ToListAsync().Result;


                //_LootTemplate.LootTemplateRandomizationSearch =_context.LootTemplateRandomizationSearch.Include(y => y.Fields).Where(x => x.LootTemplateId == _LootTemplate.LootTemplateId).ToListAsync().Result;
                //_LootTemplate.LootTemplateCurrency = this._lootTemplateCurrencyService.GetByLootTemplateId(_LootTemplate.LootTemplateId).Result;
            }

            return(_LootTemplate);
        }
Exemple #9
0
        // Calls processor of corresponding LootTemplate (which handles everything including references)
        public bool FillLoot(uint lootId, LootStore store, Player lootOwner, bool personal, bool noEmptyError = false, LootModes lootMode = LootModes.Default, ItemContext context = 0)
        {
            // Must be provided
            if (lootOwner == null)
            {
                return(false);
            }

            LootTemplate tab = store.GetLootFor(lootId);

            if (tab == null)
            {
                if (!noEmptyError)
                {
                    Log.outError(LogFilter.Sql, "Table '{0}' loot id #{1} used but it doesn't have records.", store.GetName(), lootId);
                }
                return(false);
            }

            _itemContext = context;

            tab.Process(this, store.IsRatesAllowed(), (byte)lootMode);          // Processing is done there, callback via Loot.AddItem()

            // Setting access rights for group loot case
            Group group = lootOwner.GetGroup();

            if (!personal && group != null)
            {
                roundRobinPlayer = lootOwner.GetGUID();

                for (GroupReference refe = group.GetFirstMember(); refe != null; refe = refe.Next())
                {
                    Player player = refe.GetSource();
                    if (player)   // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter
                    {
                        if (player.IsInMap(lootOwner))
                        {
                            FillNotNormalLootFor(player, player.IsAtGroupRewardDistance(lootOwner));
                        }
                    }
                }

                for (byte i = 0; i < items.Count; ++i)
                {
                    ItemTemplate proto = Global.ObjectMgr.GetItemTemplate(items[i].itemid);
                    if (proto != null)
                    {
                        if (proto.GetQuality() < group.GetLootThreshold())
                        {
                            items[i].is_underthreshold = true;
                        }
                    }
                }
            }
            // ... for personal loot
            else
            {
                FillNotNormalLootFor(lootOwner, true);
            }

            return(true);
        }