public static PacketWriter UpdateStat(Stat <StatType> stat, StatCollectionType statCollectionType) { var pw = GetWriter(); UpdateStat(pw, stat, statCollectionType); return(pw); }
public static void UpdateStat(PacketWriter pw, Stat <StatType> stat, StatCollectionType statCollectionType) { var isBaseStat = (statCollectionType == StatCollectionType.Base); pw.Write(ServerPacketID.UpdateStat); pw.Write(isBaseStat); pw.Write(stat); }
/// <summary> /// Initializes a new instance of the <see cref="StatCollection{TStatType}"/> class. /// </summary> /// <param name="collectionType">The type of stat collection.</param> /// <param name="stats">The initial values to assign to the stats.</param> public StatCollection(StatCollectionType collectionType, IEnumerable <Stat <TStatType> > stats) : this(collectionType) { // Copy over the stat values for each stat if (stats != null) { foreach (var stat in stats) { this[stat.StatType] = stat.Value; } } }
static IEnumerable<ColumnCollectionItem> GetStatColumnCollectionItems(CodeFormatter formatter, StatCollectionType statCollectionType) { var columnItems = new List<ColumnCollectionItem>(); foreach (var statType in EnumHelper<StatType>.Values) { var dbField = statType.GetDatabaseField(statCollectionType); var item = ColumnCollectionItem.FromEnum(formatter, dbField, statType); columnItems.Add(item); } return columnItems; }
static IEnumerable <ColumnCollectionItem> GetStatColumnCollectionItems(CodeFormatter formatter, StatCollectionType statCollectionType) { var columnItems = new List <ColumnCollectionItem>(); foreach (var statType in EnumHelper <StatType> .Values) { var dbField = statType.GetDatabaseField(statCollectionType); var item = ColumnCollectionItem.FromEnum(formatter, dbField, statType); columnItems.Add(item); } return(columnItems); }
/// <summary> /// Gets the database field name for a given <see cref="StatType"/>. /// </summary> /// <param name="statType"><see cref="StatType"/> to get the database field name for.</param> /// <param name="statCollectionType">The <see cref="StatCollectionType"/> of the <see cref="StatType"/> to get /// the field for.</param> /// <returns>The database field name for the <paramref name="statType"/>.</returns> /// <exception cref="ArgumentException">StatCollectionType.Modified is not allowed in the database.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="statCollectionType"/> is not a valid /// <see cref="StatCollectionType"/> enum value.</exception> public static string GetDatabaseField(this StatType statType, StatCollectionType statCollectionType) { switch (statCollectionType) { case StatCollectionType.Base: return("stat_" + statType.ToString().ToLowerInvariant()); case StatCollectionType.Requirement: return("stat_req_" + statType.ToString().ToLowerInvariant()); case StatCollectionType.Modified: throw new ArgumentException("StatCollectionType.Modified is not allowed in the database.", "statCollectionType"); default: throw new ArgumentOutOfRangeException("statCollectionType"); } }
/// <summary> /// Gets the database field name for a given <see cref="StatType"/>. /// </summary> /// <param name="statType"><see cref="StatType"/> to get the database field name for.</param> /// <param name="statCollectionType">The <see cref="StatCollectionType"/> of the <see cref="StatType"/> to get /// the field for.</param> /// <returns>The database field name for the <paramref name="statType"/>.</returns> /// <exception cref="ArgumentException">StatCollectionType.Modified is not allowed in the database.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="statCollectionType"/> is not a valid /// <see cref="StatCollectionType"/> enum value.</exception> public static string GetDatabaseField(this StatType statType, StatCollectionType statCollectionType) { switch (statCollectionType) { case StatCollectionType.Base: return "stat_" + statType.ToString().ToLowerInvariant(); case StatCollectionType.Requirement: return "stat_req_" + statType.ToString().ToLowerInvariant(); case StatCollectionType.Modified: throw new ArgumentException("StatCollectionType.Modified is not allowed in the database.", "statCollectionType"); default: throw new ArgumentOutOfRangeException("statCollectionType"); } }
/// <summary> /// Ensures that the columns needed for <see cref="StatType"/>s exist in a table. /// </summary> /// <param name="db">The <see cref="IDbController"/>.</param> /// <param name="dbTable">The name of the table to check.</param> /// <param name="columns">The <see cref="StatType"/>s to ensure exist.</param> /// <param name="statCollectionType">The <see cref="StatCollectionType"/> to use for checking.</param> static void EnsureStatColumnsExist(IDbController db, string dbTable, IEnumerable <StatType> columns, StatCollectionType statCollectionType) { EnsureColumnsExist(db, dbTable, columns.Select(x => x.GetDatabaseField(statCollectionType))); }
/// <summary> /// When overridden in the derived class, creates the CharacterStatsBase for this Character. /// </summary> /// <param name="statCollectionType">The type of <see cref="StatCollectionType"/> to create.</param> /// <returns>The CharacterStatsBase for this Character.</returns> protected abstract StatCollection<StatType> CreateStats(StatCollectionType statCollectionType);
/// <summary> /// Creates a <see cref="StatCollection{StatType}"/> from the given collection of stats. /// </summary> /// <exception cref="ArgumentException">ItemEntity does not use StatCollectionType.Modified.</exception> /// <exception cref="ArgumentOutOfRangeException"><c>statCollectionType</c> is not a defined enum value.</exception> StatCollection <StatType> NewItemStats(IEnumerable <Stat <StatType> > statValues, StatCollectionType statCollectionType) { var ret = new StatCollection <StatType>(statCollectionType, statValues); switch (statCollectionType) { case StatCollectionType.Base: case StatCollectionType.Requirement: ret.StatChanged += StatCollection_StatChanged; break; case StatCollectionType.Modified: throw new ArgumentException("ItemEntity does not use StatCollectionType.Modified.", "statCollectionType"); default: throw new ArgumentOutOfRangeException("statCollectionType"); } return(ret); }
/// <summary> /// When overridden in the derived class, creates the CharacterStatsBase for this Character. /// </summary> /// <param name="statCollectionType">The type of <see cref="StatCollectionType"/> to create.</param> /// <returns> /// The CharacterStatsBase for this Character. /// </returns> protected override StatCollection <StatType> CreateStats(StatCollectionType statCollectionType) { return(new StatCollection <StatType>(statCollectionType)); }
/// <summary> /// Ensures that the columns needed for <see cref="StatType"/>s exist in a table. /// </summary> /// <param name="db">The <see cref="IDbController"/>.</param> /// <param name="dbTable">The name of the table to check.</param> /// <param name="columns">The <see cref="StatType"/>s to ensure exist.</param> /// <param name="statCollectionType">The <see cref="StatCollectionType"/> to use for checking.</param> static void EnsureStatColumnsExist(IDbController db, string dbTable, IEnumerable<StatType> columns, StatCollectionType statCollectionType) { EnsureColumnsExist(db, dbTable, columns.Select(x => x.GetDatabaseField(statCollectionType))); }
public static PacketWriter UpdateStat(Stat<StatType> stat, StatCollectionType statCollectionType) { var pw = GetWriter(); UpdateStat(pw, stat, statCollectionType); return pw; }
public static void UpdateStat(PacketWriter pw, Stat<StatType> stat, StatCollectionType statCollectionType) { var isBaseStat = (statCollectionType == StatCollectionType.Base); pw.Write(ServerPacketID.UpdateStat); pw.Write(isBaseStat); pw.Write(stat); }
/// <summary> /// Creates a <see cref="StatCollection{StatType}"/> from the given collection of stats. /// </summary> /// <exception cref="ArgumentException">ItemEntity does not use StatCollectionType.Modified.</exception> /// <exception cref="ArgumentOutOfRangeException"><c>statCollectionType</c> is not a defined enum value.</exception> StatCollection<StatType> NewItemStats(IEnumerable<Stat<StatType>> statValues, StatCollectionType statCollectionType) { var ret = new StatCollection<StatType>(statCollectionType, statValues); switch (statCollectionType) { case StatCollectionType.Base: case StatCollectionType.Requirement: ret.StatChanged += StatCollection_StatChanged; break; case StatCollectionType.Modified: throw new ArgumentException("ItemEntity does not use StatCollectionType.Modified.", "statCollectionType"); default: throw new ArgumentOutOfRangeException("statCollectionType"); } return ret; }
/// <summary> /// Initializes a new instance of the <see cref="UserStats"/> class. /// </summary> /// <param name="statCollectionType">Type of the stat collection.</param> public UserStats(StatCollectionType statCollectionType) : base(statCollectionType) { _changedStats = new ChangedStatsTracker <StatType>(this); }
/// <summary> /// Initializes a new instance of the <see cref="StatCollection{TStatType}"/> class. /// </summary> /// <param name="collectionType">The type of stat collection.</param> public StatCollection(StatCollectionType collectionType) { _collectionType = collectionType; _stats = EnumTable.Create <TStatType, StatValueType>(); }