public static string GetProperty(this Realm realm, RealmPropertyString property)
 {
     return(realm.RealmPropertiesString.FirstOrDefault(x => x.Type == (uint)property)?.Value);
 }
 public static long?GetProperty(this Realm realm, RealmPropertyInt64 property)
 {
     return(realm.RealmPropertiesInt64.FirstOrDefault(x => x.Type == (uint)property)?.Value);
 }
        // =====================================
        // Get
        // Bool, DID, Float, Int, Int64, String
        // =====================================

        public static bool?GetProperty(this Realm realm, RealmPropertyBool property)
        {
            return(realm.RealmPropertiesBool.FirstOrDefault(x => x.Type == (uint)property)?.Value);
        }
 public static double?GetProperty(this Realm realm, RealmPropertyFloat property)
 {
     return(realm.RealmPropertiesFloat.FirstOrDefault(x => x.Type == (ushort)property)?.Value);
 }
Exemple #5
0
        public static ACE.Entity.Models.Realm ConvertToEntityRealm(ACE.Database.Models.World.Realm realm, bool instantiateEmptyCollections = false)
        {
            var jobs = new List <RealmLinkJob>();

            foreach (var jobtype_group in realm.RealmRulesetLinksRealm.GroupBy(x => x.LinkType))
            {
                foreach (var group in jobtype_group.GroupBy(x => x.ProbabilityGroup))
                {
                    if (group.Key == null)
                    {
                        foreach (var unconditionallink in group)
                        {
                            jobs.Add(new RealmLinkJob((RealmRulesetLinkType)unconditionallink.LinkType, new List <AppliedRealmLink>()
                            {
                                new AppliedRealmLink(unconditionallink.LinkedRealmId, 1.0)
                            }.AsReadOnly()));
                        }
                    }
                    else
                    {
                        var linksToAdd = new List <AppliedRealmLink>();
                        foreach (var link in group)
                        {
                            linksToAdd.Add(new AppliedRealmLink(link.LinkedRealmId, link.Probability.Value));
                        }
                        jobs.Add(new RealmLinkJob((RealmRulesetLinkType)jobtype_group.Key, linksToAdd.AsReadOnly()));
                    }
                }
            }

            var result = new ACE.Entity.Models.Realm(jobs);

            result.Id                      = realm.Id;
            result.Name                    = realm.Name;
            result.Type                    = (RealmType)realm.Type;
            result.ParentRealmID           = realm.ParentRealmId;
            result.PropertyCountRandomized = realm.PropertyCountRandomized;

            if (realm.RealmPropertiesBool != null && (instantiateEmptyCollections || realm.RealmPropertiesBool.Count > 0))
            {
                result.PropertiesBool = new Dictionary <RealmPropertyBool, AppliedRealmProperty <bool> > (realm.RealmPropertiesBool.Count);
                foreach (var value in realm.RealmPropertiesBool)
                {
                    result.PropertiesBool[(RealmPropertyBool)value.Type] = ConvertRealmProperty(value);
                }
            }
            if (realm.RealmPropertiesFloat != null && (instantiateEmptyCollections || realm.RealmPropertiesFloat.Count > 0))
            {
                result.PropertiesFloat = new Dictionary <RealmPropertyFloat, AppliedRealmProperty <double> >(realm.RealmPropertiesFloat.Count);
                foreach (var value in realm.RealmPropertiesFloat)
                {
                    result.PropertiesFloat[(RealmPropertyFloat)value.Type] = ConvertRealmProperty(value);
                }
            }
            if (realm.RealmPropertiesInt != null && (instantiateEmptyCollections || realm.RealmPropertiesInt.Count > 0))
            {
                result.PropertiesInt = new Dictionary <RealmPropertyInt, AppliedRealmProperty <int> >(realm.RealmPropertiesInt.Count);
                foreach (var value in realm.RealmPropertiesInt)
                {
                    result.PropertiesInt[(RealmPropertyInt)value.Type] = ConvertRealmProperty(value);
                }
            }
            if (realm.RealmPropertiesInt64 != null && (instantiateEmptyCollections || realm.RealmPropertiesInt64.Count > 0))
            {
                result.PropertiesInt64 = new Dictionary <RealmPropertyInt64, AppliedRealmProperty <long> >(realm.RealmPropertiesInt64.Count);
                foreach (var value in realm.RealmPropertiesInt64)
                {
                    result.PropertiesInt64[(RealmPropertyInt64)value.Type] = ConvertRealmProperty(value);
                }
            }
            if (realm.RealmPropertiesString != null && (instantiateEmptyCollections || realm.RealmPropertiesString.Count > 0))
            {
                result.PropertiesString = new Dictionary <RealmPropertyString, AppliedRealmProperty <string> >(realm.RealmPropertiesString.Count);
                foreach (var value in realm.RealmPropertiesString)
                {
                    result.PropertiesString[(RealmPropertyString)value.Type] = ConvertRealmProperty(value);
                }
            }

            return(result);
        }