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); }
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); }
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)); }
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); }
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)); }
public static bool IsActive(this TypeAllowed allowed, TypeAllowedBasic basicAllowed) { return(allowed.GetDB() == basicAllowed || allowed.GetUI() == basicAllowed); }
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())); }
public static TypeAllowedBasic Get(this TypeAllowed allowed, bool userInterface) { return(userInterface ? allowed.GetUI() : allowed.GetDB()); }
public static TypeAllowedBasic GetUI(this TypeAllowed allowed) { return((TypeAllowedBasic)((int)allowed & 0x03)); }
public static TypeAllowedBasic GetDB(this TypeAllowed allowed) { return((TypeAllowedBasic)(((int)allowed >> 2) & 0x03)); }
internal ConditionDebugData(TypeConditionSymbol typeCondition, bool inGroup, TypeAllowed allowed) { this.TypeCondition = typeCondition; this.InGroup = inGroup; this.Allowed = allowed; }
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; }
public TypeConditionRuleBuilder(TypeConditionSymbol typeCondition, TypeAllowed allowed) { this.TypeCondition = typeCondition; this.Allowed = new TypeAllowedBuilder(allowed); }
public TypeConditionRuleEmbedded(TypeConditionSymbol typeCondition, TypeAllowed allowed) { this.TypeCondition = typeCondition; this.Allowed = allowed; }
internal bool Exactly(TypeAllowed current) { return(Fallback == current && Conditions.IsNullOrEmpty()); }
public TypeAllowedBuilder(TypeAllowed? typeAllowed) { this.typeAllowed = typeAllowed; }
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()); }