public void EveryoneGain(Party party, EntityAttributeTypes attributeType, int amountGained) { AddEntityGain(party.Derpus, attributeType, amountGained); foreach (var companion in party.GetCompanions()) { AddEntityGain(companion, attributeType, amountGained); } }
/// <summary> /// Initializes a new instance of the <see cref="EntityAttributeDefinition"/> struct. /// </summary> /// <param name="entityPath"> /// The entity Path. /// </param> /// <param name="propertyInfo"> /// The property info for the attribute. /// </param> /// <param name="physicalName"> /// The name of the attribute. /// </param> /// <param name="attributeTypes"> /// The type of the attribute. /// </param> /// <param name="ordinal"> /// The attribute ordinal on the entity. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="entityPath"/>, <paramref name="propertyInfo"/>, or <paramref name="physicalName"/> is null or empty or whitespace. /// </exception> public EntityAttributeDefinition( [NotNull] LinkedList <EntityLocation> entityPath, [NotNull] PropertyInfo propertyInfo, [NotNull] string physicalName, EntityAttributeTypes attributeTypes, int ordinal) : this(entityPath, propertyInfo, physicalName, attributeTypes, ordinal, null) { }
// Setter for soft attribute that checks input value against expected type for that attribute. public void SetAttribute(EntityAttributes attribute, object newValue) { if (!object.ReferenceEquals(newValue.GetType(), EntityAttributeTypes.GetType(attribute))) { Debug.Log("Tried to update SoftAttribute with invalid type."); Debug.Log("Attribute:"); Debug.Log(attribute); Debug.Log("Value:"); Debug.Log(newValue); Debug.Log("Expected type:"); Debug.Log(EntityAttributeTypes.GetType(attribute)); return; } Attributes[attribute] = newValue; }
public void AddEntityLoss(Entity targetEntity, EntityAttributeTypes attributeType, int amountLost) { if (EntityAttributeLosses == null) { EntityAttributeLosses = new Dictionary <Entity, List <KeyValuePair <EntityAttributeTypes, int> > >(); } var loss = new KeyValuePair <EntityAttributeTypes, int>(attributeType, amountLost); if (!EntityAttributeLosses.ContainsKey(targetEntity)) { EntityAttributeLosses.Add(targetEntity, new List <KeyValuePair <EntityAttributeTypes, int> > { loss }); } else { EntityAttributeLosses[targetEntity].Add(loss); } }
public void AddEntityGain(Entity targetEntity, EntityAttributeTypes attributeType, int amountGained) { if (EntityAttributeGains == null) { EntityAttributeGains = new Dictionary <Entity, List <KeyValuePair <EntityAttributeTypes, int> > >(); } var gain = new KeyValuePair <EntityAttributeTypes, int>(attributeType, amountGained); if (!EntityAttributeGains.ContainsKey(targetEntity)) { EntityAttributeGains.Add(targetEntity, new List <KeyValuePair <EntityAttributeTypes, int> > { gain }); } else { EntityAttributeGains[targetEntity].Add(gain); } }
public string BuildCompanionLossTextItem(Entity companion, int value, EntityAttributeTypes lossType) { return($"{companion.Name} lost {value} {GlobalHelper.GetEnumDescription(lossType)}!"); }
private string BuildCompanionRewardTextItem(Entity companion, int attributeGainValue, EntityAttributeTypes gainType) { return($"{companion.Name} gained {attributeGainValue} {GlobalHelper.GetEnumDescription(gainType)}!"); }
/// <summary> /// Initializes a new instance of the <see cref="EntityAttributeDefinition"/> struct. /// </summary> /// <param name="entityPath"> /// The entity Path. /// </param> /// <param name="propertyInfo"> /// The property info for the attribute. /// </param> /// <param name="physicalName"> /// The name of the attribute. /// </param> /// <param name="attributeTypes"> /// The type of the attribute. /// </param> /// <param name="ordinal"> /// The attribute ordinal on the entity. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="entityPath"/>, <paramref name="propertyInfo"/>, or <paramref name="physicalName"/> is null or empty or whitespace. /// </exception> public EntityAttributeDefinition( [NotNull] LinkedList <EntityLocation> entityPath, [NotNull] PropertyInfo propertyInfo, [NotNull] string physicalName, EntityAttributeTypes attributeTypes, int ordinal, string alias) : this() { if (entityPath == null) { throw new ArgumentNullException(nameof(entityPath)); } if (string.IsNullOrWhiteSpace(physicalName)) { throw new ArgumentNullException(nameof(physicalName)); } if (propertyInfo == null) { throw new ArgumentNullException(nameof(propertyInfo)); } // Clone the path in case it changes. this.entityPath = new LinkedList <EntityLocation>(entityPath); this.PropertyName = propertyInfo.Name; this.PhysicalName = physicalName; this.AttributeTypes = attributeTypes; this.Ordinal = ordinal; // If the alias matches the physical name then it isn't an alias. this.Alias = this.PhysicalName == alias ? null : alias; this.IsDirect = this.AttributeTypes.HasFlag(EntityAttributeTypes.DirectAttribute); this.IsPrimaryKey = this.AttributeTypes.HasFlag(EntityAttributeTypes.PrimaryKey); this.IsIdentityColumn = this.AttributeTypes.HasFlag(EntityAttributeTypes.IdentityColumn); this.IsComputed = this.AttributeTypes.HasFlag(EntityAttributeTypes.Computed); this.IsReferencedDirect = this.IsDirect || this.AttributeTypes.HasFlag(EntityAttributeTypes.ExplicitRelatedAttribute); this.IsMetadata = this.AttributeTypes.HasFlag(EntityAttributeTypes.Relation); this.ResolvedLocation = new ResolvedAttributeLocation(this.Entity.Container, this.Entity.Name, this.PhysicalName); this.PropertyInfo = propertyInfo; var getMethodInfo = propertyInfo.GetGetMethod(true); this.GetValueMethod = getMethodInfo; this.GetValueDelegate = DelegateMemoryCache.GetOrAdd( $"{nameof(getMethodInfo)}.{propertyInfo.DeclaringType}.{propertyInfo.Name}", key => new Lazy <Delegate>(() => CreateFunctionDelegate(propertyInfo, getMethodInfo))).Value; var setMethodInfo = propertyInfo.GetSetMethod(true); this.SetValueMethod = setMethodInfo ?? throw new InvalidOperationException( $"The property '{propertyInfo.PropertyType.Name}.{propertyInfo.Name}' requires a set method for this delegate to be built."); this.SetValueDelegate = DelegateMemoryCache.GetOrAdd( $"{nameof(setMethodInfo)}.{propertyInfo.DeclaringType}.{propertyInfo.Name}", key => new Lazy <Delegate>(() => CreateActionDelegate(propertyInfo, setMethodInfo))).Value; this.hashCode = new Lazy <int>(this.CreateHashCode); }