Ejemplo n.º 1
0
        public static bool IsAllowed(Entity serial)
        {
            if (serial == null)
            {
                return(false);
            }

            if (TypeAllowed == NameOverheadTypeAllowed.All)
            {
                return(true);
            }

            if (SerialHelper.IsItem(serial.Serial) && TypeAllowed == NameOverheadTypeAllowed.Items)
            {
                return(true);
            }

            if (SerialHelper.IsMobile(serial.Serial) && TypeAllowed.HasFlag(NameOverheadTypeAllowed.Mobiles))
            {
                return(true);
            }

            if (TypeAllowed.HasFlag(NameOverheadTypeAllowed.Corpses) && SerialHelper.IsItem(serial.Serial) && World.Items.Get(serial)?.IsCorpse == true)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static TypeAllowed Create(TypeAllowedBasic database, TypeAllowedBasic ui)
        {
            TypeAllowed result = (TypeAllowed)(((int)database << 2) | (int)ui);

            if (!Enum.IsDefined(typeof(TypeAllowed), result))
            {
                throw new FormatException("Invalid TypeAllowed");
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static string ToStringParts(this TypeAllowed allowed)
        {
            TypeAllowedBasic db = allowed.GetDB();
            TypeAllowedBasic ui = allowed.GetUI();

            if (db == ui)
            {
                return(db.ToString());
            }

            return("{0},{1}".FormatWith(db, ui));
        }
Ejemplo n.º 4
0
    static TypeAllowed MaxTypeAllowed(IEnumerable <TypeAllowed> collection)
    {
        TypeAllowed result = TypeAllowed.None;

        foreach (var item in collection)
        {
            if (item > result)
            {
                result = item;
            }

            if (result == TypeAllowed.Write)
            {
                return(result);
            }
        }
        return(result);
    }
Ejemplo n.º 5
0
 internal static string Comment(Lite <RoleEntity> role, TypeEntity resource, TypeAllowed from, TypeAllowed to)
 {
     return("{0} {1} for {2} ({3} -> {4})".FormatWith(typeof(TypeEntity).NiceName(), resource.ToString(), role, from, to));
 }
Ejemplo n.º 6
0
 public static bool IsActive(this TypeAllowed allowed, TypeAllowedBasic basicAllowed)
 {
     return(allowed.GetDB() == basicAllowed || allowed.GetUI() == basicAllowed);
 }
Ejemplo n.º 7
0
    public static TypeAllowedAndConditions MergeBase(IEnumerable <TypeAllowedAndConditions> baseRules, Func <IEnumerable <TypeAllowed>, TypeAllowed> maxMerge, TypeAllowed max, TypeAllowed min)
    {
        TypeAllowedAndConditions?only = baseRules.Only();

        if (only != null)
        {
            return(only);
        }

        if (baseRules.Any(a => a.Fallback == null))
        {
            return(new TypeAllowedAndConditions(null));
        }

        if (baseRules.Any(a => a.Exactly(max)))
        {
            return(new TypeAllowedAndConditions(max));
        }

        TypeAllowedAndConditions?onlyNotOposite = baseRules.Where(a => !a.Exactly(min)).Only();

        if (onlyNotOposite != null)
        {
            return(onlyNotOposite);
        }

        var first = baseRules.FirstOrDefault(c => !c.Conditions.IsNullOrEmpty());

        if (first == null)
        {
            return(new TypeAllowedAndConditions(maxMerge(baseRules.Select(a => a.Fallback !.Value))));
        }

        var conditions = first.Conditions.Select(c => c.TypeCondition).ToList();

        if (baseRules.Where(c => !c.Conditions.IsNullOrEmpty() && c != first).Any(br => !br.Conditions.Select(c => c.TypeCondition).SequenceEqual(conditions)))
        {
            return(new TypeAllowedAndConditions(null));
        }

        return(new TypeAllowedAndConditions(maxMerge(baseRules.Select(a => a.Fallback !.Value)),
                                            conditions.Select((c, i) => new TypeConditionRuleEmbedded(c, maxMerge(baseRules.Where(br => !br.Conditions.IsNullOrEmpty()).Select(br => br.Conditions[i].Allowed)))).ToArray()));
    }
Ejemplo n.º 8
0
 public static TypeAllowedBasic Get(this TypeAllowed allowed, bool userInterface)
 {
     return(userInterface ? allowed.GetUI() : allowed.GetDB());
 }
Ejemplo n.º 9
0
 public static TypeAllowedBasic GetUI(this TypeAllowed allowed)
 {
     return((TypeAllowedBasic)((int)allowed & 0x03));
 }
Ejemplo n.º 10
0
 public static TypeAllowedBasic GetDB(this TypeAllowed allowed)
 {
     return((TypeAllowedBasic)(((int)allowed >> 2) & 0x03));
 }
Ejemplo n.º 11
0
 internal ConditionDebugData(TypeConditionSymbol typeCondition, bool inGroup, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.InGroup       = inGroup;
     this.Allowed       = allowed;
 }
Ejemplo n.º 12
0
 public DebugData(Lite <IEntity> lite, TypeAllowedBasic requested, bool userInterface, TypeAllowed fallback, List <ConditionDebugData> groups)
 {
     this.Lite          = lite;
     this.Requested     = requested;
     this.Fallback      = fallback;
     this.UserInterface = userInterface;
     this.Conditions    = groups;
 }
Ejemplo n.º 13
0
 public TypeConditionRuleBuilder(TypeConditionSymbol typeCondition, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.Allowed       = new TypeAllowedBuilder(allowed);
 }
Ejemplo n.º 14
0
 public TypeConditionRuleEmbedded(TypeConditionSymbol typeCondition, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.Allowed       = allowed;
 }
Ejemplo n.º 15
0
 internal bool Exactly(TypeAllowed current)
 {
     return(Fallback == current && Conditions.IsNullOrEmpty());
 }
 public TypeAllowedBuilder(TypeAllowed? typeAllowed)
 {
     this.typeAllowed = typeAllowed;
 }
 public TypeConditionRuleBuilder(TypeConditionSymbol typeCondition, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.Allowed = new TypeAllowedBuilder(allowed);
 }
Ejemplo n.º 18
0
        private static string ToString(TypeAllowed? typeAllowed)
        {
            if (typeAllowed == null)
                return "MERGE ERROR!";

            if (typeAllowed.Value.GetDB() == typeAllowed.Value.GetUI())
                return typeAllowed.Value.GetDB().NiceToString();

            return "DB {0} / UI {1}".FormatWith(typeAllowed.Value.GetDB().NiceToString(), typeAllowed.Value.GetUI().NiceToString());
        }