//Called by UserManager after updating total exp to database and returning its result
        internal void SetTotalExp(ulong totalExp)
        {
            this.TotalExp = totalExp;

            //Lets recalc rank and exp, tho dont keep instantly update these to database if they are wrong, wait for AddExp to correct it
            (uint rank, ulong exp) = ExpUtils.GetRankAndExpFromTotalExp(totalExp);
            this.Rank = rank;
            this.Exp  = exp;

            //Update to redis
            RedisConnection.GetDatabase().HashSetAsync($"users:{this.Id}", new HashEntry[]
            {
                new HashEntry("total_exp", totalExp),
                new HashEntry("rank", rank),
                new HashEntry("exp", exp),
            }, CommandFlags.FireAndForget);
        }
Пример #2
0
    public virtual void AddExp(ulong exp)
    {
        if (exp == 0 || this.TotalExp == ulong.MaxValue)
        {
            return;
        }

        try
        {
            checked
            {
                this.TotalExp += exp;
            }
        }
        catch (StackOverflowException)
        {
            this.TotalExp = ulong.MaxValue;
        }

        (uint rank, ulong expLeft) = ExpUtils.GetRankAndExpFromTotalExp(this.TotalExp);

        this.Rank = rank;
        this.Exp  = expLeft;
    }