示例#1
0
        public bool IsDisabledFor(DisableType type, uint entry, Unit unit, byte flags = 0)
        {
            Cypher.Assert(type < DisableType.Max);
            if (!m_DisableMap.ContainsKey(type) || m_DisableMap[type].Empty())
            {
                return(false);
            }

            var data = m_DisableMap[type].LookupByKey(entry);

            if (data == null)    // not disabled
            {
                return(false);
            }

            switch (type)
            {
            case DisableType.Spell:
            {
                byte spellFlags = data.flags;
                if (unit != null)
                {
                    if ((spellFlags.HasAnyFlag(DisableFlags.SpellPlayer) && unit.IsTypeId(TypeId.Player)) ||
                        (unit.IsTypeId(TypeId.Unit) && ((unit.IsPet() && spellFlags.HasAnyFlag(DisableFlags.SpellPet)) || spellFlags.HasAnyFlag(DisableFlags.SpellCreature))))
                    {
                        if (spellFlags.HasAnyFlag(DisableFlags.SpellMap))
                        {
                            List <uint> mapIds = data.param0;
                            if (mapIds.Contains(unit.GetMapId()))
                            {
                                return(true);                                               // Spell is disabled on current map
                            }
                            if (!spellFlags.HasAnyFlag(DisableFlags.SpellArea))
                            {
                                return(false);                                              // Spell is disabled on another map, but not this one, return false
                            }
                            // Spell is disabled in an area, but not explicitly our current mapId. Continue processing.
                        }

                        if (spellFlags.HasAnyFlag(DisableFlags.SpellArea))
                        {
                            var areaIds = data.param1;
                            if (areaIds.Contains(unit.GetAreaId()))
                            {
                                return(true);                                               // Spell is disabled in this area
                            }
                            return(false);                                                  // Spell is disabled in another area, but not this one, return false
                        }
                        else
                        {
                            return(true);                                                   // Spell disabled for all maps
                        }
                    }

                    return(false);
                }
                else if (spellFlags.HasAnyFlag(DisableFlags.SpellDeprecatedSpell))            // call not from spellcast
                {
                    return(true);
                }
                else if (flags.HasAnyFlag(DisableFlags.SpellLOS))
                {
                    return(spellFlags.HasAnyFlag(DisableFlags.SpellLOS));
                }

                break;
            }

            case DisableType.Map:
            case DisableType.LFGMap:
                Player player = unit.ToPlayer();
                if (player != null)
                {
                    MapRecord mapEntry = CliDB.MapStorage.LookupByKey(entry);
                    if (mapEntry.IsDungeon())
                    {
                        byte       disabledModes    = data.flags;
                        Difficulty targetDifficulty = player.GetDifficultyID(mapEntry);
                        Global.DB2Mgr.GetDownscaledMapDifficultyData(entry, ref targetDifficulty);
                        switch (targetDifficulty)
                        {
                        case Difficulty.Normal:
                            return(disabledModes.HasAnyFlag(DisableFlags.DungeonStatusNormal));

                        case Difficulty.Heroic:
                            return(disabledModes.HasAnyFlag(DisableFlags.DungeonStatusHeroic));

                        case Difficulty.Raid10HC:
                            return(disabledModes.HasAnyFlag(DisableFlags.DungeonStatusHeroic10Man));

                        case Difficulty.Raid25HC:
                            return(disabledModes.HasAnyFlag(DisableFlags.DungeonStatusHeroic25Man));

                        default:
                            return(false);
                        }
                    }
                    else if (mapEntry.InstanceType == MapTypes.Common)
                    {
                        return(true);
                    }
                }
                return(false);

            case DisableType.Quest:
                if (unit == null)
                {
                    return(true);
                }
                Player player1 = unit.ToPlayer();
                if (player1 != null)
                {
                    if (player1.IsGameMaster())
                    {
                        return(false);
                    }
                }
                return(true);

            case DisableType.Battleground:
            case DisableType.OutdoorPVP:
            case DisableType.Criteria:
            case DisableType.MMAP:
                return(true);

            case DisableType.VMAP:
                return(flags.HasAnyFlag(data.flags));
            }

            return(false);
        }