#if !SERVICE_HOST using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using asap.core; namespace game.PlayerDataStorage { // Bind the existing game container. Missing registrations fail closed; no parallel fixture objects. internal static class PlayerKVGameplayBindings { static T Require() where T:class => GContext.container.Resolve() ?? throw new InvalidOperationException("KV game module is not registered: "+typeof(T).FullName); internal static PlayerKVSchemaSnapshot Snapshot(DateTime nowUtc,string version="kv-loop") { var tables=Require(); return new PlayerKVSchemaSnapshot(version,tables.TbRodData.DataMap.Keys,tables.TbMapData.DataMap.Keys, Enum.GetNames(typeof(cfg.ConditionType)).ToDictionary(n=>n,n=>(int)Enum.Parse(typeof(cfg.ConditionType),n)),CultureInfo.InvariantCulture, nowUtc,tables.TbGlobalConfig.InitWheelTicket, tables.TbEventPackManager.DataMap.ToDictionary(p=>p.Key,p=>p.Value.PackType), tables.TbFishingEvent.DataMap.ToDictionary(p=>p.Key,p=>new PlayerKVEventConfig(p.Value.RedirectID,(p.Value.TimeDefinition as cfg.LimitedTime)?.EndTime)),tables.TbGlobalConfig.GlobalTimeOffset, tables.TbFishData.DataMap.ToDictionary(p=>p.Key,p=>new PlayerKVFishConfig(p.Key,p.Value.AreaID,p.Value.Quality,p.Value.FishCardID,p.Value.BaseWeight,p.Value.PointExtraParam,p.Value.WeightRandom)), tables.TbFishCard.DataMap.ToDictionary(p=>p.Key,p=>new PlayerKVFishCardConfig(p.Key,p.Value.MaxLevel,p.Value.CardsRequiredList,p.Value.WeightMagList))); } internal static PlayerKVGameLoadTransaction Bind(IKVUserLoadReceiver user) { var player=Require(); var small=Require(); var fish=Require(); var shop=Require(); var eventBase=Require(); var buffs=Require(); var camp=Require(); var achievements=Require(); var box=Require(); var guide=Require(); var battle=Require(); var sign=Require(); var trigger=Require(); var club=Require(); var challenge=Require(); var chains=Require(); var disco=Require(); var partner=Require(); var cube=Require(); var eventPack=Require(); var piggy=Require(); var bargain=Require(); var foot=Require() as FootPrintService ?? throw new InvalidOperationException("M23 FootPrint binding mismatch."); var shooting=Require(); var potion=Require(); var pinball=Require(); var scratch=Require(); var progress=eventBase.ThanksGivingPackData; var migration=eventBase.ChainPackWithProgressMigrationData; var pinata=Require(); var digging=Require(); var modules=new List(); void Add(int id,Action reset,Action replace) where T:class => modules.Add(new PlayerKVLoadModule(id,reset,d=>replace(d.Module(id)))); Add(1,player.ResetForKVLoad,player.ReplaceFromKVDecoded); Add(2,small.ResetForKVLoad,small.ReplaceFromKVDecoded); Add(3,fish.ResetForKVLoad,fish.ReplaceFromKVDecoded); Add(4,shop.ResetForKVLoad,shop.ReplaceFromKVDecoded); Add(5,eventBase.ResetForKVLoad,eventBase.ReplaceFromKVDecoded); Add(6,buffs.ResetForKVLoad,buffs.ReplaceFromKVDecoded); Add(7,camp.ResetForKVLoad,camp.ReplaceFromKVDecoded); Add(8,achievements.ResetForKVLoad,achievements.ReplaceFromKVDecoded); Add(9,box.ResetForKVLoad,box.ReplaceFromKVDecoded); Add(10,guide.ResetForKVLoad,guide.ReplaceFromKVDecoded); Add(11,battle.ResetForKVLoad,battle.ReplaceFromKVDecoded); Add(12,sign.ResetForKVLoad,sign.ReplaceFromKVDecoded); Add(13,trigger.ResetForKVLoad,trigger.ReplaceFromKVDecoded); Add(14,club.ResetForKVLoad,club.ReplaceFromKVDecoded); Add(15,challenge.ResetForKVLoad,challenge.ReplaceFromKVDecoded); Add(16,chains.ResetForKVLoad,chains.ReplaceFromKVDecoded); Add(17,disco.ResetForKVLoad,disco.ReplaceFromKVDecoded); Add(18,partner.ResetForKVLoad,partner.ReplaceFromKVDecoded); Add(19,cube.ResetForKVLoad,cube.ReplaceFromKVDecoded); Add(20,eventPack.ResetForKVLoad,eventPack.ReplaceFromKVDecoded); Add(21,piggy.ResetForKVLoad,piggy.ReplaceFromKVDecoded); Add(22,bargain.ResetForKVLoad,bargain.ReplaceFromKVDecoded); Add(23,foot.ResetForKVLoad,foot.ReplaceFromKVDecoded); Add(24,shooting.ResetForKVLoad,shooting.ReplaceFromKVDecoded); Add(25,potion.ResetForKVLoad,potion.ReplaceFromKVDecoded); Add(26,pinball.ResetForKVLoad,pinball.ReplaceFromKVDecoded); Add(27,scratch.ResetForKVLoad,scratch.ReplaceFromKVDecoded); Add(28,()=>{progress.ResetForKVLoad();migration.ResetForKVLoad();},p=>{progress.ReplaceFromKVDecoded(p.Current);migration.ReplaceFromKVDecoded(p.Migration);}); Add(29,pinata.ResetForKVLoad,pinata.ReplaceFromKVDecoded); Add(30,digging.ResetForKVLoad,digging.ReplaceFromKVDecoded); modules.Add(new PlayerKVLoadModule(31,user.ResetForKVLoad,d=>user.ReplaceFromKVDecoded(d.Module(31),d.Epoch,d.Raw))); return new PlayerKVGameLoadTransaction(modules,System.Threading.Thread.CurrentThread.ManagedThreadId,user.DiscardKVIntents); } } } #endif