Пример #1
0
        public void OnNewCharacter(CharacterModel model)
        {
            characterEntitlements.Clear();
            foreach (CharacterEntitlementModel entitlementModel in model.Entitlement)
            {
                EntitlementEntry entry = GameTableManager.Instance.Entitlement.GetEntry(entitlementModel.EntitlementId);
                if (entry == null)
                {
                    throw new DatabaseDataException($"Character {model.Id} has invalid entitlement {entitlementModel.EntitlementId} stored!");
                }

                var entitlement = new CharacterEntitlement(entitlementModel, entry);
                characterEntitlements.Add(entitlement.Type, entitlement);
            }
        }
Пример #2
0
        /// <summary>
        /// Create a new <see cref="EntitlementManager"/> from existing database model.
        /// </summary>
        public EntitlementManager(WorldSession session, AccountModel model)
        {
            this.session = session;

            foreach (AccountEntitlementModel entitlementModel in model.AccountEntitlement)
            {
                EntitlementEntry entry = GameTableManager.Instance.Entitlement.GetEntry(entitlementModel.EntitlementId);
                if (entry == null)
                {
                    throw new DatabaseDataException($"Account {model.Id} has invalid entitlement {entitlementModel.EntitlementId} stored!");
                }

                var entitlement = new AccountEntitlement(entitlementModel, entry);
                accountEntitlements.Add(entitlement.Type, entitlement);
            }
        }
Пример #3
0
        /// <summary>
        /// Create or update character <see cref="EntitlementType"/> with supplied value.
        /// </summary>
        /// <remarks>
        /// A positive value must be supplied for new entitlements otherwise an <see cref="ArgumentException"/> will be thrown.
        /// For existing entitlements a positive value will increment and a negative value will decrement the entitlement value.
        /// </remarks>
        public void SetCharacterEntitlement(EntitlementType type, int value)
        {
            EntitlementEntry entry = GameTableManager.Instance.Entitlement.GetEntry((ulong)type);

            if (entry == null)
            {
                throw new ArgumentException($"Invalid entitlement type {type}!");
            }

            CharacterEntitlement entitlement = SetEntitlement(characterEntitlements, entry, value,
                                                              () => new CharacterEntitlement(session.Player.CharacterId, entry, (uint)value));

            session.EnqueueMessageEncrypted(new ServerEntitlement
            {
                Entitlement = type,
                Count       = entitlement.Amount
            });
        }
Пример #4
0
        /// <summary>
        /// Create or update account <see cref="EntitlementType"/> with supplied value.
        /// </summary>
        /// <remarks>
        /// A positive value must be supplied for new entitlements otherwise an <see cref="ArgumentException"/> will be thrown.
        /// For existing entitlements a positive value will increment and a negative value will decrement the entitlement value.
        /// </remarks>
        public void SetAccountEntitlement(EntitlementType type, int value)
        {
            EntitlementEntry entry = GameTableManager.Instance.Entitlement.GetEntry((ulong)type);

            if (entry == null)
            {
                throw new ArgumentException($"Invalid entitlement type {type}!");
            }

            AccountEntitlement entitlement = SetEntitlement(accountEntitlements, entry, value,
                                                            () => new AccountEntitlement(session.Account.Id, entry, (uint)value));

            session.EnqueueMessageEncrypted(new ServerAccountEntitlement
            {
                Entitlement = type,
                Count       = entitlement.Amount
            });

            UpdateRewardProperty(type, value);
        }
Пример #5
0
 /// <summary>
 /// Create a new <see cref="CharacterEntitlement"/> from supplied <see cref="EntitlementEntry"/> and value.
 /// </summary>
 public CharacterEntitlement(ulong characterId, EntitlementEntry entry, uint value)
     : base(entry, value, true)
 {
     this.characterId = characterId;
 }
Пример #6
0
 /// <summary>
 /// Create a new <see cref="CharacterEntitlement"/> from an existing database model.
 /// </summary>
 public CharacterEntitlement(CharacterEntitlementModel model, EntitlementEntry entry)
     : base(entry, model.Amount, false)
 {
     characterId = model.Id;
 }
Пример #7
0
 /// <summary>
 /// Create a new <see cref="AccountEntitlement"/> from supplied <see cref="EntitlementEntry"/> and value.
 /// </summary>
 public AccountEntitlement(uint accountId, EntitlementEntry entry, uint value)
     : base(entry, value, true)
 {
     this.accountId = accountId;
 }
Пример #8
0
 /// <summary>
 /// Create a new <see cref="AccountEntitlement"/> from an existing database model.
 /// </summary>
 public AccountEntitlement(AccountEntitlementModel model, EntitlementEntry entry)
     : base(entry, model.Amount, false)
 {
     accountId = model.Id;
 }
Пример #9
0
        private static T SetEntitlement <T>(IDictionary <EntitlementType, T> collection, EntitlementEntry entry, int value, Func <T> creator)
            where T : Entitlement
        {
            if (!collection.TryGetValue((EntitlementType)entry.Id, out T entitlement))
            {
                if (value < 1)
                {
                    throw new ArgumentException($"Failed to create entitlement {entry.Id}, {value} isn't positive!");
                }

                if (value > entry.MaxCount)
                {
                    throw new ArgumentException($"Failed to create entitlement {entry.Id}, {value} is larger than max value {entry.MaxCount}!");
                }

                entitlement = creator.Invoke();
                collection.Add(entitlement.Type, entitlement);
            }
            else
            {
                if (value > 0 && entitlement.Amount + (uint)value > entry.MaxCount)
                {
                    throw new ArgumentException($"Failed to update entitlement {entry.Id}, incrementing by {value} exceeds max value!");
                }

                if (value < 0 && (int)entitlement.Amount + value < 0)
                {
                    throw new ArgumentException($"Failed to update entitlement {entry.Id}, decrementing by {value} subceeds 0!");
                }

                entitlement.Amount = (uint)((int)entitlement.Amount + value);
            }

            return(entitlement);
        }