示例#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 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
            });
        }