private static EphemeralRealm Initialize(Player owner, WorldRealm baseRealm, List <Realm> appliedRealms) { string key = baseRealm.Realm.Id.ToString(); RulesetTemplate template = null; RulesetTemplate prevTemplate = baseRealm.RulesetTemplate; for (int i = 0; i < appliedRealms.Count; i++) { var appliedRealm = appliedRealms[i]; key += $".{appliedRealm.Id}"; template = RealmManager.GetEphemeralRealmRulesetTemplate(key); if (template == null) { template = RulesetTemplate.MakeRuleset(prevTemplate, appliedRealm); RealmManager.CacheEphemeralRealmTemplate(key, template); } prevTemplate = template; } if (template == null) { template = prevTemplate; } return(new EphemeralRealm(owner, template)); }
private static AppliedRealmProperty GetRandomProperty(RulesetTemplate template) { if (template.PropertiesForRandomization?.Count == 0) { return(null); } return(template.PropertiesForRandomization[random.Next(template.PropertiesForRandomization.Count - 1)]); }
protected void CopyDicts(RulesetTemplate copyFrom) { if (copyFrom.Realm.PropertyCountRandomized.HasValue) { var count = copyFrom.Realm.PropertyCountRandomized.Value; var props = TakeRandomProperties(count, copyFrom); foreach (var prop in props) { if (prop is AppliedRealmProperty <bool> a) { PropertiesBool.Add((RealmPropertyBool)a.PropertyKey, new AppliedRealmProperty <bool>(a)); } else if (prop is AppliedRealmProperty <int> b) { PropertiesInt.Add((RealmPropertyInt)b.PropertyKey, new AppliedRealmProperty <int>(b)); } else if (prop is AppliedRealmProperty <double> c) { PropertiesFloat.Add((RealmPropertyFloat)c.PropertyKey, new AppliedRealmProperty <double>(c)); } else if (prop is AppliedRealmProperty <long> d) { PropertiesInt64.Add((RealmPropertyInt64)d.PropertyKey, new AppliedRealmProperty <long>(d)); } else if (prop is AppliedRealmProperty <string> e) { PropertiesString.Add((RealmPropertyString)e.PropertyKey, new AppliedRealmProperty <string>(e)); } } } else { foreach (var item in copyFrom.PropertiesBool) { PropertiesBool.Add(item.Key, new AppliedRealmProperty <bool>(item.Value)); } foreach (var item in copyFrom.PropertiesFloat) { PropertiesFloat.Add(item.Key, new AppliedRealmProperty <double>(item.Value)); } foreach (var item in copyFrom.PropertiesInt) { PropertiesInt.Add(item.Key, new AppliedRealmProperty <int>(item.Value)); } foreach (var item in copyFrom.PropertiesInt64) { PropertiesInt64.Add(item.Key, new AppliedRealmProperty <long>(item.Value)); } foreach (var item in copyFrom.PropertiesString) { PropertiesString.Add(item.Key, new AppliedRealmProperty <string>(item.Value)); } } }
private void ComposeFrom(RulesetTemplate parentTemplate, bool invertRules = false) { if (parentTemplate == null) { return; } var parent = MakeRerolledRuleset(parentTemplate); ApplyRulesetDict(parent.PropertiesBool, PropertiesBool, invertRules); ApplyRulesetDict(parent.PropertiesFloat, PropertiesFloat, invertRules); ApplyRulesetDict(parent.PropertiesInt, PropertiesInt, invertRules); ApplyRulesetDict(parent.PropertiesInt64, PropertiesInt64, invertRules); ApplyRulesetDict(parent.PropertiesString, PropertiesString, invertRules); }
public static RulesetTemplate MakeTopLevelRuleset(Realm entity) { var ruleset = new RulesetTemplate(); ruleset.Realm = entity; ruleset.PropertiesBool = new Dictionary <RealmPropertyBool, AppliedRealmProperty <bool> >(entity.PropertiesBool); ruleset.PropertiesFloat = new Dictionary <RealmPropertyFloat, AppliedRealmProperty <double> >(entity.PropertiesFloat); ruleset.PropertiesInt = new Dictionary <RealmPropertyInt, AppliedRealmProperty <int> >(entity.PropertiesInt); ruleset.PropertiesInt64 = new Dictionary <RealmPropertyInt64, AppliedRealmProperty <long> >(entity.PropertiesInt64); ruleset.PropertiesString = new Dictionary <RealmPropertyString, AppliedRealmProperty <string> >(entity.PropertiesString); ruleset.Jobs = entity.Jobs; ruleset.MakeRandomizationList(); return(ruleset); }
/// <summary> /// Imprints a ruleset template onto a new Active Ruleset, applying all rules as configured /// </summary> /// <param name="template"></param> /// <returns></returns> internal static AppliedRuleset MakeRerolledRuleset(RulesetTemplate template) { var result = new AppliedRuleset(template); result.CopyDicts(template); if (template.ParentRuleset != null) { result.ComposeFrom(template.ParentRuleset); } foreach (var job in template.Jobs.Where(x => x.Type == RealmRulesetLinkType.apply_after_inherit)) { result.ApplyJob(job); } // Composition needs to happen first before rerolling, // so that random properties that depend on other random // properties with a composition rule can be applied in sequence result.RerollAllRules(); return(result); }
public static RulesetTemplate MakeRuleset(RulesetTemplate baseset, Realm subset) { if (baseset.Realm.Type == ACE.Entity.Enum.RealmType.Ruleset && subset.Type == ACE.Entity.Enum.RealmType.Realm) { throw new Exception("Realms may not inherit from rulesets at this time."); } var ruleset = new RulesetTemplate(); ruleset.ParentRuleset = baseset; ruleset.Realm = subset; ruleset.PropertiesBool = new Dictionary <RealmPropertyBool, AppliedRealmProperty <bool> >(subset.PropertiesBool); ruleset.PropertiesFloat = new Dictionary <RealmPropertyFloat, AppliedRealmProperty <double> >(subset.PropertiesFloat); ruleset.PropertiesInt = new Dictionary <RealmPropertyInt, AppliedRealmProperty <int> >(subset.PropertiesInt); ruleset.PropertiesInt64 = new Dictionary <RealmPropertyInt64, AppliedRealmProperty <long> >(subset.PropertiesInt64); ruleset.PropertiesString = new Dictionary <RealmPropertyString, AppliedRealmProperty <string> >(subset.PropertiesString); ruleset.Jobs = subset.Jobs; ruleset.MakeRandomizationList(); return(ruleset); }
private EphemeralRealm(Player owner, RulesetTemplate template) { this.Owner = owner; this.RulesetTemplate = template; }
//Deep copy private AppliedRuleset(RulesetTemplate template) { Template = template; InitializePropertyDictionaries(); }
private IEnumerable <AppliedRealmProperty> TakeRandomProperties(ushort amount, RulesetTemplate template) { if (PropertiesString.TryGetValue(RealmPropertyString.Description, out var desc)) { amount++; } var total = PropertiesBool.Count + PropertiesInt.Count + PropertiesInt64.Count + PropertiesFloat.Count + PropertiesString.Count; if (amount <= total / 2) { var set = new HashSet <AppliedRealmProperty>(); if (desc != null) { set.Add(desc); } while (set.Count < amount) { set.Add(GetRandomProperty(template)); } return(set); } else { var all = new List <AppliedRealmProperty>(template.PropertiesForRandomization); if (amount >= all.Count) { return(all); } var set = new HashSet <AppliedRealmProperty>(all); while (set.Count > amount) { var next = GetRandomProperty(template); if (next is AppliedRealmProperty <string> s && s.PropertyKey == (ushort)RealmPropertyString.Description) { continue; } set.Remove(next); } return(set); } }
public WorldRealm(Realm realmEntity, RulesetTemplate ruleset) { Realm = realmEntity; RulesetTemplate = ruleset; StandardRules = AppliedRuleset.MakeRerolledRuleset(RulesetTemplate); }