コード例 #1
0
ファイル: PathHandler.cs プロジェクト: zeaf/NexusForever
        public static void HandlePathActivate(WorldSession session, ClientPathActivate clientPathActivate)
        {
            log.Debug($"ClientPathActivate: Path: {clientPathActivate.Path}, UseTokens: {clientPathActivate.UseTokens}");
            Player player = session.Player;

            if (clientPathActivate.UseTokens)
            {
                // TODO: Implement block if not enough tokens
                // TODO: Remove tokens from account and send relevant packet updates
            }
            player.PathManager.ActivatePath(clientPathActivate.Path);
        }
コード例 #2
0
ファイル: PathHandler.cs プロジェクト: sergeev/NexusForever
        public static void HandlePathActivate(WorldSession session, ClientPathActivate clientPathActivate)
        {
            uint activateCooldown = GameTableManager.Instance.GameFormula.GetEntry(2366).Dataint0;
            uint bypassCost       = GameTableManager.Instance.GameFormula.GetEntry(2366).Dataint01;
            bool needToUseTokens  = DateTime.UtcNow.Subtract(session.Player.PathActivatedTime).TotalSeconds < activateCooldown;

            GenericError CanActivatePath()
            {
                if (needToUseTokens && !clientPathActivate.UseTokens)
                {
                    return(GenericError.PathChangeOnCooldown);
                }

                bool hasEnoughTokens = session.AccountCurrencyManager.CanAfford(AccountCurrencyType.ServiceToken, bypassCost); // TODO: Check user has enough tokens

                if (needToUseTokens && clientPathActivate.UseTokens && !hasEnoughTokens)
                {
                    return(GenericError.PathChangeInsufficientFunds);
                }

                if (!session.Player.PathManager.IsPathUnlocked(clientPathActivate.Path))
                {
                    return(GenericError.PathChangeNotUnlocked);
                }

                if (session.Player.PathManager.IsPathActive(clientPathActivate.Path))
                {
                    return(GenericError.PathChangeRequested);
                }

                return(GenericError.Ok);
            }

            GenericError result = CanActivatePath();

            if (result != GenericError.Ok)
            {
                session.Player.PathManager.SendServerPathActivateResult(result);
                return;
            }

            if (needToUseTokens && clientPathActivate.UseTokens)
            {
                session.AccountCurrencyManager.CurrencySubtractAmount(AccountCurrencyType.ServiceToken, bypassCost);
            }

            session.Player.PathManager.ActivatePath(clientPathActivate.Path);
        }