protected void HandleInheritance(HasStatsBlueprint blueprint) { if (blueprint.Ref != null) { var baseBlue = GetBlueprint(blueprint.Ref); if (!string.IsNullOrWhiteSpace(baseBlue.Ref)) { throw new NotSupportedException($"Ref blueprints cannot have their own base blueprint (maximum inheritance depth is 1). Bad base blueprint was '{baseBlue}'"); } //copy properties from the base blueprint foreach (var prop in typeof(T1).GetProperties()) { var currentVal = prop.GetValue(blueprint); var baseVal = prop.GetValue(baseBlue); //where the current blueprint doesn't have a value for it yet (is null/empty) if (currentVal == null) { prop.SetValue(blueprint, baseVal); } else if (currentVal is IList l && l.Count == 0 && baseVal != null) { prop.SetValue(blueprint, baseVal); } } //now clear the Ref so we don't do it again later! blueprint.Ref = null; } }
/// <summary> /// True if the blueprint should be included in randomization choices /// </summary> /// <param name="b"></param> /// <returns></returns> public virtual bool Spawnable(HasStatsBlueprint b) { //don't return fixed location stuff as a random choice if (b is RoomBlueprint r && r.FixedLocation != null) { return(false); } if (!b.Unique) { return(true); } return(!UniquesSpawned.Contains(b.Identifier ?? Guid.Empty)); }
public void AddAdjectives(IWorld world, IHasStats owner, HasStatsBlueprint ownerBlueprint) { //Adjectives the user definitely wants included if (ownerBlueprint.MandatoryAdjectives.Any()) { foreach (var a in ownerBlueprint.MandatoryAdjectives) { Create(world, owner, a); } } //pick 1 random adjective if blueprint lists any to pick from if (ownerBlueprint.OptionalAdjectives.Any()) { Create(world, owner, ownerBlueprint.OptionalAdjectives.GetRandom(world.R)); } }