59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using ServerCommon;
|
|
using ServerCore; using ServerBase;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GameServer
|
|
{
|
|
public class Cart : EntityBase
|
|
{
|
|
public Cart(Player parent)
|
|
: base(EntityType.Cart, parent)
|
|
{
|
|
}
|
|
|
|
public override async Task<Result> onInit()
|
|
{
|
|
var direct_parent = getDirectParent();
|
|
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
|
|
addEntityAttribute(new CartAttribute(this, direct_parent));
|
|
|
|
return await base.onInit();
|
|
}
|
|
|
|
public override string toBasicString()
|
|
{
|
|
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
|
}
|
|
|
|
public override string toSummaryString()
|
|
{
|
|
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
|
}
|
|
|
|
public List<CartItemInfo> toCartItemData4Client()
|
|
{
|
|
var cart_item_list_4_client = new List<CartItemInfo>();
|
|
var cart_attribute = getEntityAttribute<CartAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(cart_attribute, () => $"cart_attribute is null !!!");
|
|
|
|
foreach (var cart_category_item in cart_attribute.CartItems)
|
|
{
|
|
foreach(var cartitem in cart_category_item.Value)
|
|
{
|
|
CartItemInfo cart_item = new CartItemInfo();
|
|
cart_item.BuyType = cart_category_item.Key.ToString();
|
|
cart_item.ItemId = (Int32)cartitem.Key;
|
|
cart_item.Count = cartitem.Value;
|
|
cart_item_list_4_client.Add(cart_item);
|
|
}
|
|
}
|
|
|
|
return cart_item_list_4_client;
|
|
}
|
|
}
|
|
}
|