示例#1
0
        public static PacketWriter UpdateStat(Stat <StatType> stat, StatCollectionType statCollectionType)
        {
            var pw = GetWriter();

            UpdateStat(pw, stat, statCollectionType);
            return(pw);
        }
示例#2
0
        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);
        }
示例#3
0
 /// <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;
         }
     }
 }
示例#4
0
文件: Program.cs 项目: Furt/netgore
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        /// <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");
            }
        }
示例#7
0
        /// <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");
            }
        }
示例#8
0
 /// <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)));
 }
示例#9
0
 /// <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);
示例#10
0
        /// <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);
        }
示例#11
0
 /// <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));
 }
示例#12
0
 /// <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)));
 }
示例#13
0
 public static PacketWriter UpdateStat(Stat<StatType> stat, StatCollectionType statCollectionType)
 {
     var pw = GetWriter();
     UpdateStat(pw, stat, statCollectionType);
     return pw;
 }
示例#14
0
        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);
        }
示例#15
0
        /// <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;
        }
示例#16
0
 /// <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);
 }
示例#17
0
 /// <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>();
 }