private static RulesetTemplate BuildRuleset(ACE.Entity.Models.Realm realm) { if (realm.ParentRealmID == null) { return(RulesetTemplate.MakeTopLevelRuleset(realm)); } var parent = GetRealm(realm.ParentRealmID.Value); return(RulesetTemplate.MakeRuleset(parent.RulesetTemplate, realm)); }
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); }