//using Amazon.OpenSearchService.Model.Internal.MarshallTransformations; //using Amazon.Runtime.Internal.Transform; //using Google.Protobuf.WellKnownTypes; //using Nettention.Proud; //using Newtonsoft.Json; //using ServerCommon; //using ServerCore; using ServerBase; //using System; //using System.Collections.Concurrent; //using System.Collections.Generic; //using System.Linq; //using System.Text; //using System.Threading.Tasks; //using static ServerCommon.BuffData; //namespace GameServer //{ // public class OwnedBuff // { // Dictionary> BuffInfo = new (); // string AccountId = string.Empty; // Player? player = null; // public async Task InitLoadRedisBuff(string accountId, Player player) // { // AccountId = accountId; // this.player = player; // List attributeList = new(); // foreach (EBuffCategory category in System.Enum.GetValues(typeof(EBuffCategory))) // { // var buffchannelInfo = new ConcurrentDictionary(); // BuffInfo.TryAdd(category, buffchannelInfo); // } // var BuffList = await GameServerApp.Instance.buffStorage.GetBuffInfo(AccountId); // if (BuffList != null) // { // foreach(var buff in BuffList) // { // if (!TableData.Instance._BuffTable.TryGetValue(buff.BuffId, out var buffData)) // { // Log.getLogger().error($"Not Found Table key : {buff.BuffId}"); // continue; // } // if(BuffInfo[buffData.BuffCategory].TryAdd(buffData.BuffChannel, buff) == false) // { // Log.getLogger().error($"TryAdd Failed. buffCategoty : {buffData.BuffCategory}, BuffChannel {buffData.BuffChannel}"); // continue; // } // changeAttribute(buff.BuffId, false); // } // } // } // private void changeAttribute(int buffId, bool isDelete) // { // if(player == null) // { // return; // } // int constant = isDelete ? -1 : 1; // if (!TableData.Instance._BuffTable.TryGetValue(buffId, out var buffData)) // { // Log.getLogger().error($"Not Found Table key : {buffId}"); // return; // } // foreach (var buffAttribute in buffData.traitsInfos) // { // if (TableData.Instance._AttributeDefinitionDataTable.TryGetValue(buffAttribute.Attrivute, out var attributeData) == false) // { // Log.getLogger().error($"TryAdd Failed. buffAttribute.Attrivute : {buffAttribute.Attrivute}"); // continue; // } // if (buffAttribute.Operation == "Sub") // { // constant *= -1; // } // player.ApplyAttribute(attributeData.ID, buffAttribute.Value * constant); // } // } // //안의 값까지의 깊은 복사가 아닌 컨테이너만 복사. // public Dictionary> getCopyBuff() // { // Dictionary> copyBuff = BuffInfo.ToDictionary(a => a.Key, b => new Dictionary()); // foreach (var buffChannel in BuffInfo) // { // copyBuff[buffChannel.Key] = buffChannel.Value.ToDictionary(a => a.Key, b => b.Value); // } // return copyBuff; // } // public bool getBuff(EBuffCategory category, int channel, out Buff? buff) // { // return BuffInfo[category].TryGetValue(channel, out buff); // } // public ServerErrorCode AddBuffProcess(int buffId, out Buff? startBuff, out Buff? endBuff) // { // startBuff = null; // endBuff = null; // if (!TableData.Instance._BuffTable.TryGetValue(buffId, out var buffData)) // { // Log.getLogger().error($"Not Found Table key : {buffId}"); // return ServerErrorCode.NotFoundBuffTableId; // } // var copyBuffInfo = getCopyBuff(); // //카테고리별 버프 // if (copyBuffInfo.TryGetValue(buffData.BuffCategory, out var buffchannelInfo) == false) // { // Log.getLogger().error($"Not Found Table key : {buffData.BuffCategory}"); // return ServerErrorCode.NotFoundBuffTableId; // } // //이미 동일한 채널의 버프가 있는경우 // if (buffchannelInfo.TryGetValue(buffData.BuffChannel, out var buffInfo) == true) // { // if (!TableData.Instance._BuffTable.TryGetValue(buffInfo.BuffId, out var oldBuffData)) // { // Log.getLogger().error($"Not Found Table key : {buffInfo.BuffId}"); // return ServerErrorCode.NotFoundBuffTableId; // } // //새로운것이 더 높거나 같으면 교체 // if(oldBuffData.BuffPriority <= buffData.BuffPriority) // { // DelBuff(buffData.BuffCategory, buffData.BuffChannel, out var delBuff); // AddBuff(buffData, out startBuff); // } // return ServerErrorCode.Success; // } // string MaxBuffCategoty = ""; // switch (buffData.BuffCategory) // { // case EBuffCategory.NORMAL: MaxBuffCategoty = "MaxNormalBuffNum"; break; // case EBuffCategory.INSTANCE: MaxBuffCategoty = "MaxInstanceBuffNum"; break; // case EBuffCategory.EVENT: MaxBuffCategoty = "MaxEventBuffNum"; break; // case EBuffCategory.TOOL: MaxBuffCategoty = "MaxToolBuffNum";break; // case EBuffCategory.WEAR: MaxBuffCategoty = "MaxWearBuffNum"; break; // default: // break; // } // if (!TableData.Instance._GameConfigDataTable.TryGetValue(MaxBuffCategoty, out var strMaxBuffCount)) // { // Log.getLogger().error($"Not Found Table key : {MaxBuffCategoty}"); // return ServerErrorCode.NotFoundTable; // } // if(ServerUtil.MakeStringToInt(strMaxBuffCount, out var maxBuffCount) == false) // { // Log.getLogger().error($"string to int parse failed. data : {strMaxBuffCount}"); // return ServerErrorCode.TableError; // } // Timestamp? removeBuffStartTime = null; // int removeBuffChannel = -1; // //최대 버퍼수량을 초과했을경우 가장 오래된 버프 제거 // if (buffchannelInfo.Count >= maxBuffCount) // { // foreach(var oldBuffInfo in buffchannelInfo) // { // if(removeBuffStartTime == null || removeBuffStartTime > oldBuffInfo.Value.BuffStartTime) // { // removeBuffStartTime = oldBuffInfo.Value.BuffStartTime; // removeBuffChannel = oldBuffInfo.Key; // } // } // if(removeBuffStartTime != null) // { // DelBuff(buffData.BuffCategory, removeBuffChannel, out var delBuff); // } // } // AddBuff(buffData, out startBuff); // return ServerErrorCode.Success; // } // public ServerErrorCode DelBuffProcess(int buffId, out Buff? delBuff) // { // delBuff = null; // if (!TableData.Instance._BuffTable.TryGetValue(buffId, out var buffData)) // { // return ServerErrorCode.NotFoundBuffTableId; // } // if(DelBuff(buffData.BuffCategory, buffData.BuffChannel, out delBuff) == false) // { // return ServerErrorCode.NotFoundBuff; // } // return ServerErrorCode.Success; // } // public async Task MovePlace(EPlaceType toMove) // { // var copyBuffInfo = getCopyBuff(); // List buffListForRedis = new (); // List delBuff = new(); // foreach (var ChannelBuff in copyBuffInfo) // { // foreach(var buff in ChannelBuff.Value) // { // if (!TableData.Instance._BuffTable.TryGetValue(buff.Value.BuffId, out var buffData)) // { // Log.getLogger().error($"Not Found Table key : {buff.Value.BuffId}"); // continue; // } // if(isRemainBuff(toMove, buffData) == true) // { // buffListForRedis.Add(buff.Value); // continue; // } // delBuff.Add(buff.Value); // } // } // if(await GameServerApp.Instance.buffStorage.SaveBuff(AccountId, buffListForRedis) == false) // { // Log.getLogger().error($"SaveBuff Failed. AccountId : {AccountId}"); // return false; // } // foreach(var buff in delBuff) // { // changeAttribute(buff.BuffId, true); // } // var session = ClientSessionManager.Instance.GetSessionByName(AccountId); // if (session == null) // { // return true; // } // ClientToGame message = new(); // message.Message = new(); // message.Message.DelBuffListNoti = new(); // message.Message.DelBuffListNoti.DelBuffList.AddRange(delBuff); // session.Send(RmiContext.ReliableSend, message); // return true; // } // private bool isRemainBuff(EPlaceType toMove, BuffData buffData) // { // switch (toMove) // { // case EPlaceType.Concert: return buffData.IsConcertRemain; // case EPlaceType.Meeting: return buffData.IsMeetingRemain; // case EPlaceType.MyHome: return buffData.IsMyhomeRemain; // case EPlaceType.Movie: return buffData.IsMovieRemain; // case EPlaceType.World: return buffData.IsNormalRemain; // case EPlaceType.Instance: // case EPlaceType.DressRoom: // default: // return false; // } // } // private bool AddBuff(BuffData buffData, out Buff? buff) // { // buff = null; // if (BuffInfo.TryGetValue(buffData.BuffCategory, out var buffchannelInfo) == false) // { // return false; // } // buff = new(); // buff.BuffId = buffData.BuffId; // buff.BuffStartTime = DateTime.UtcNow.ToTimestamp(); // buff.Step = 0; // buff.RandomState = 0; // buff.ActionStartTime = 0; // if(buffchannelInfo.TryAdd(buffData.BuffChannel, buff) == false) // { // return false; // } // changeAttribute(buffData.BuffId, false); // return true; // } // private bool DelBuff(EBuffCategory category, int channel, out Buff? delBuff) // { // delBuff = null; // if (BuffInfo.TryGetValue(category, out var buffchannelInfo) == false) // { // return false; // } // if(buffchannelInfo.Remove(channel, out delBuff) == false) // { // return false; // } // changeAttribute(delBuff.BuffId, true); // return true; // } // public void SendInfo(HostID hostId) // { // ClientToGame clientToGame = new ClientToGame(); // clientToGame.Message = new ClientToGameMessage(); // clientToGame.Message.LoginBuffNoti = new ClientToGameMessage.Types.LoginBuffNoti(); // clientToGame.Message.LoginBuffNoti.BuffInfo = new BuffInfo(); // var buffInfo = getCopyBuff(); // foreach (var channelBuff in buffInfo) // { // clientToGame.Message.LoginBuffNoti.BuffInfo.Buff.AddRange(channelBuff.Value.Values.AsEnumerable()); // } // GameServer.Instance._proxy.Message(hostId, RmiContext.ReliableSend, clientToGame); // } // } //}