using BulletHellTemplate; using Cysharp.Threading.Tasks; using System; using System.Collections.Generic; using UnityEngine; namespace BulletHellTemplate { public sealed class WebSocketSqlBackendService : IBackendService { private readonly WebsocketAuthHandler _auth; public WebsocketAuthHandler Auth => _auth; public WebSocketSqlBackendService(BackendSettings cfg) { _auth = new WebsocketAuthHandler(cfg.serverUrl); } /*──────────── AUTH ───────────*/ public UniTask AccountRegister(string email, string pass, string confirm) => WebsocketDataLoadHandler.RegisterAndLoadAsync(this, email, pass, confirm); public UniTask AccountLogin(string email, string pass) => WebsocketDataLoadHandler.LoginAndLoadAsync(this, email, pass); public UniTask PlayAsGuest() => WebsocketDataLoadHandler.GuestAndLoadAsync(this); public UniTask TryAutoLoginAsync() => WebsocketDataLoadHandler.TryAutoLoginAndLoadAsync(this); public UniTask Logout() { _auth.LogOut(); return UniTask.CompletedTask; } /*──────────────────── LOAD ────────────────────*/ public UniTask LoadAllAccountDataAsync() => WebsocketDataLoadHandler.ApplyToPlayerSaveAsync(this); /*──────────────────── ACCOUNT ────────────────────*/ public async UniTask ChangePlayerFrameAsync(string frameId) => await WebsocketProfileHandler.ChangePlayerFrameAsync(this, frameId); public async UniTask ChangePlayerIconAsync(string iconId) => await WebsocketProfileHandler.ChangePlayerIconAsync(this, iconId); public async UniTask ChangePlayerNameAsync(string newName) => await WebsocketProfileHandler.ChangePlayerNameAsync(this, newName); /*──────────────────── CURRENCY ───────────────────*/ /*──────────────────── CHARACTERS & ITEMS ─────────*/ public UniTask UpdateSelectedCharacterAsync(int characterId) => WebsocketCharacterHandler.SelectCharacterAsync(this, characterId); public UniTask UpdatePlayerCharacterFavouriteAsync(int characterId) => WebsocketCharacterHandler.FavouriteCharacterAsync(this, characterId); public UniTask UnlockCharacterSkin(int characterId, int skinId) => WebsocketCharacterHandler.UnlockCharacterSkinAsync(this, characterId, skinId); public UniTask UpdateCharacterSkin(int characterId, int skinId) => WebsocketCharacterHandler.SetCharacterSkinAsync(this, characterId, skinId); public UniTask UpdateCharacterLevelUP(int characterId) => WebsocketCharacterHandler.LevelUpCharacterAsync(this, characterId); public UniTask UpdateCharacterStatUpgradeAsync(StatUpgrade stat, CharacterStatsRuntime stats, int characterId) => WebsocketCharacterHandler.TryUpgradeStatAsync(this, stat, stats, characterId); public UniTask SetCharacterItemAsync(int characterId, string slotName, string uniqueItemGuid) => WebsocketCharacterHandler.SetCharacterSlotItemAsync(this, characterId, slotName, uniqueItemGuid); /*──────────────────── PURCHASING ───────────────────*/ public UniTask PurchaseShopItemAsync(ShopItem shopItem) => WebsocketPurchasesHandler.PurchaseShopItemAsync(this, shopItem); public UniTask ClaimBattlePassRewardAsync(BattlePassItem reward) => WebsocketPurchasesHandler.ClaimBattlePassRewardAsync(this, reward); public UniTask DeletePurchasedInventoryItemAsync(string uniqueItemGuid) => WebsocketCharacterHandler.DeletePurchasedItemAsync(this, uniqueItemGuid); /*──────────────────── MAP / SCORE ────────────────*/ public UniTask CompleteGameSessionAsync(EndGameSessionData data) => WebsocketProgressHandler.CompleteGameSessionAsync(this, data); /*──────────────────── QUESTS / COUPON ────────────*/ public UniTask CompleteQuestAsync(int questId) => WebsocketProgressHandler.CompleteQuestAsync(this, questId); public UniTask RefreshQuestLevelProgressAsync() => WebsocketProgressHandler.RefreshQuestLevelProgressAsync(this); public UniTask RedeemCouponAsync(string code) => WebsocketRewardsHandler.RedeemCouponAsync(this, code); /*──────────────────── BATTLE-PASS ───────────────*/ public UniTask UnlockBattlePassPremiumAsync() => WebsocketPurchasesHandler.UnlockBattlePassPremiumAsync(this); /*──────────────────── INVENTORY ───────────────*/ public UniTask UpgradeInventoryItemAsync(string uniqueItemGuid, InventoryItem inventorySO) => WebsocketInventoryHandler.UpgradeInventoryItemAsync(this, uniqueItemGuid, inventorySO); public UniTask ApplyMapRewardsAsync(MapCompletionRewardData mapCompletionData) => WebsocketRewardsHandler.ApplyMapRewardsAsync(this, mapCompletionData); public UniTask InitCurrencyRechargeAsync() { throw new NotImplementedException(); } /*──────────────────── REWARDS (daily/new) ───────*/ public UniTask ClaimDailyRewardAsync(int day, BattlePassItem reward) => WebsocketRewardsHandler.ClaimDailyRewardAsync(this, day, reward); public UniTask ClaimNewPlayerRewardAsync(int day, BattlePassItem reward) => WebsocketRewardsHandler.ClaimNewPlayerRewardAsync(this, day, reward); /*──────────────────── LEADERBOARD ───────────────*/ public UniTask GetPlayerRankAsync() => WebsocketProgressHandler.GetPlayerRankAsync(this); public UniTask>> GetTopPlayersAsync(int limit = 20) => WebsocketProgressHandler.GetTopPlayersAsync(this); /*──────────────────── DEBUG ───────────────*/ public UniTask TestAddAccountExpAsync(int exp) => WebsocketExpHandler.AddAccountExpAsync(this, exp); public UniTask TestAddCharacterExpAsync(int cid, int exp) => WebsocketExpHandler.AddCharacterExpAsync(this, cid, exp); public UniTask TestAddCharacterMasteryExpAsync(int cid, int exp) => WebsocketExpHandler.AddCharacterMasteryExpAsync(this, cid, exp); public UniTask TestAddBattlePassXpAsync(int amount) => WebsocketExpHandler.AddBattlePassXpAsync(this, amount); } }