Files
caliverse_server/GameServer/z.Backup/OwnedCart.cs
2025-05-01 07:20:41 +09:00

267 lines
9.5 KiB
C#

//using Nettention.Proud;
//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 ClientToGameRes.Types;
//using Amazon.DynamoDBv2.DocumentModel;
//using ServerCommon;
//using Amazon.OpenSearchService.Model;
//using System.Linq.Expressions;
//using Microsoft.VisualBasic;
//namespace GameServer
//{
// public class OwnedCart
// {
// string accountGuid = string.Empty;
// CartEntity cartEntity = new();
// public async Task<bool> LoadDB(string accountGuid)
// {
// this.accountGuid = accountGuid;
// var cartEntity = await GameServerApp.Instance.MainDB.GetCart(accountGuid);
// if (cartEntity is null)
// {
// Log.getLogger().error("cartEntity == null");
// return false;
// }
// foreach(var selltype in Enum.GetValues<ECurrencyType>())
// {
// if(cartEntity.Attr.ItemCartInfo.ContainsKey(selltype) == false)
// {
// cartEntity.Attr.ItemCartInfo[selltype] = new List<CartItemInfo>();
// }
// }
// this.cartEntity = cartEntity;
// return true;
// }
// public void UpdateDBToMemory(Document document)
// {
// cartEntity.ReadFrom(document);
// }
// public Dictionary<ECurrencyType,List<CartItemInfo>> GetCart()
// {
// return cartEntity.Attr.ItemCartInfo;
// }
// private bool GetBuyType(int itemId, out ECurrencyType type)
// {
// type = ECurrencyType.GOLD;
// if (TableData.Instance._ItemTable.TryGetValue(itemId, out var itemData) == false)
// {
// Log.getLogger().error($"Not Found ItemTableId. itemTableId:{itemId}");
// return false;
// }
// type = itemData.BuyType;
// return true;
// }
// public CartItemInfo? FindItem(CartEntity newCartEntity, CartItemInfo itemInfo, ECurrencyType sellType)
// {
// foreach (var Item in newCartEntity.Attr.ItemCartInfo[sellType])
// {
// if (Item.ItemGuid == string.Empty)
// {
// if (Item.ItemId != itemInfo.ItemId)
// {
// continue;
// }
// }
// else
// {
// if (Item.ItemGuid != itemInfo.ItemGuid)
// {
// continue;
// }
// }
// return Item;
// }
// return null;
// }
// public ServerErrorCode AddCart(CartItemInfo itemInfo, out CartEntity newCartEntity, out CartItemInfo? newCartItemInfo)
// {
// newCartEntity = new CartEntity(cartEntity.DocumentForUpdate());
// newCartItemInfo = default;
// if (itemInfo.ItemGuid != string.Empty)
// {
// //상점 구현후 구현
// return ServerErrorCode.NotImplemented;
// }
// if (CompareBuyType(itemInfo.ItemId, itemInfo.BuyType, out var buyType) == false)
// {
// Log.getLogger().error("CompareBuyType Failed.");
// return ServerErrorCode.CartSellTypeMissMatchWithTable;
// }
// newCartItemInfo = FindItem(newCartEntity, itemInfo, buyType);
// if(newCartItemInfo == null)
// {
// if(newCartEntity.Attr.ItemCartInfo[buyType].Count >= 20)
// {
// Log.getLogger().error($"cart is Full. itemId : {itemInfo.ItemId}");
// return ServerErrorCode.CartisFull;
// }
// newCartEntity.Attr.ItemCartInfo[buyType].Add(itemInfo);
// newCartItemInfo = itemInfo;
// }
// else
// {
// if(newCartItemInfo.Count + itemInfo.Count > 99)
// {
// Log.getLogger().error($"FullStack of this item in cart. itemId : {newCartItemInfo.ItemId}");
// return ServerErrorCode.CartFullStackofItem;
// }
// newCartItemInfo.Count += itemInfo.Count;
// }
// return ServerErrorCode.Success;
// }
// public void DelCart(List<CartItemInfo> itemInfos, out Document? dBDocument, out bool isRemoveItem)
// {
// CartEntity newCartEntity = new CartEntity(cartEntity.DocumentForUpdate());
// isRemoveItem = false;
// dBDocument = null;
// foreach (CartItemInfo itemInfo in itemInfos)
// {
// if (CompareBuyType(itemInfo.ItemId, itemInfo.BuyType, out var buyType) == false)
// {
// Log.getLogger().error("CompareBuyType Failed.");
// return;
// }
// var findItem = FindItem(newCartEntity, itemInfo, buyType);
// if (findItem == null)
// {
// Log.getLogger().error("Not found itemid.");
// return;
// }
// else
// {
// if (findItem.Count < itemInfo.Count)
// {
// Log.getLogger().error("Invalid item Count.");
// return;
// }
// else if (findItem.Count - itemInfo.Count == 0)
// {
// newCartEntity.Attr.ItemCartInfo[buyType].Remove(findItem);
// isRemoveItem = true;
// }
// else
// {
// findItem.Count -= itemInfo.Count;
// }
// }
// }
// dBDocument = newCartEntity.DocumentForUpdate();
// }
// public void BuyCart(List<CartItemInfo> itemInfoList, out Document? dBDocument)
// {
// CartEntity newCartEntity = new CartEntity(cartEntity.DocumentForUpdate());
// dBDocument = null;
// foreach (var itemInfo in itemInfoList)
// {
// if (CompareBuyType(itemInfo.ItemId, itemInfo.BuyType, out var buyType) == false)
// {
// Log.getLogger().error("CompareBuyType Failed.");
// return;
// }
// var findItem = FindItem(newCartEntity, itemInfo, buyType);
// if (findItem == null)
// {
// Log.getLogger().error("Not found itemid.");
// return;
// }
// else
// {
// if (findItem.Count < itemInfo.Count)
// {
// Log.getLogger().error("Argument count is bigger then cart Item count.");
// return;
// }
// }
// }
// foreach (var itemInfo in itemInfoList)
// {
// if(CompareBuyType(itemInfo.ItemId, itemInfo.BuyType, out var buyType) == false)
// {
// Log.getLogger().error("CompareBuyType Failed.");
// return;
// }
// var findItem = FindItem(newCartEntity, itemInfo, buyType);
// if (findItem != null)
// {
// findItem.Count -= itemInfo.Count;
// if (findItem.Count == 0)
// {
// newCartEntity.Attr.ItemCartInfo[buyType].Remove(findItem);
// }
// }
// }
// dBDocument = newCartEntity.DocumentForUpdate();
// }
// private bool CompareBuyType(int itemId, string compareBuyType, out ECurrencyType requestBuyType)
// {
// requestBuyType = ECurrencyType.GOLD;
// try
// {
// requestBuyType = Enum.Parse<ECurrencyType>(compareBuyType);
// }
// catch (Exception ex)
// {
// Log.getLogger().error($"IteamTable BuyType is invalid. exception : {ex.ToString()}");
// return false;
// }
// ECurrencyType BuyType;
// if (GetBuyType(itemId, out BuyType) == false)
// {
// Log.getLogger().error($"Miss Match SellType. Table SellType : {BuyType}, request item SellType : {compareBuyType}");
// return false;
// }
// if (BuyType != requestBuyType)
// {
// Log.getLogger().error($"Miss Match SellType. Table SellType : {BuyType}, request item SellType : {compareBuyType}");
// return false;
// }
// return true;
// }
// public void SendInfoFromLogin(HostID hostId)
// {
// ClientToGame clientToGame = new ClientToGame();
// clientToGame.Message = new ClientToGameMessage();
// clientToGame.Message.CartNoti = new ClientToGameMessage.Types.CartNoti();
// foreach(var itemCartInfoList in cartEntity.Attr.ItemCartInfo)
// {
// clientToGame.Message.CartNoti.ItemList.AddRange(itemCartInfoList.Value);
// }
// GameServer.Instance._proxy.Message(hostId, RmiContext.ReliableSend, clientToGame);
// }
// }
//}