using PSO2SERVER.Models;
using PSO2SERVER.Party;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static Mysqlx.Notice.Warning.Types;

namespace PSO2SERVER.Protocol.Packets
{
    public class GainedEXPPacket : Packet
    {
        /// Packet receiver.
        public ObjectHeader sender { get; set; } = new ObjectHeader();
        /// All players that gained EXP.
        public List<EXPReceiver> receivers { get; set; } = new List<EXPReceiver>();

        public GainedEXPPacket(Client c, ulong gainedxp)
        {
            sender = new ObjectHeader((uint)c._account.AccountId, ObjectType.Player);

            foreach (Client cl in PartyManager.instance.GetCurrentPartyForClient(c).getMembers())
            {
                EXPReceiver receiver = new EXPReceiver
                {
                    Object = new ObjectHeader((uint)cl._account.AccountId, ObjectType.Player),
                    //Unk1 = unk1,
                    //Unk2 = unk2,
                    //Unk3 = unk3 ?? new byte[6],  // 默认值为6字节数组
                    Gained = gainedxp,
                    //Total = total,
                    //Level2 = level2,
                    //Level = level,
                    Class = cl.Character.Jobs.mainClass,
                    //Pad1 = pad1 ?? new byte[3],  // 默认值为3字节数组
                    //GainedSub = gainedSub,
                    //TotalSub = totalSub,
                    //Level2Sub = level2Sub,
                    //LevelSub = levelSub,
                    //Subclass = subclass,
                    //Pad2 = pad2 ?? new byte[3],  // 默认值为3字节数组
                };
                receivers.Add(receiver);
            }
        }

        #region implemented abstract members of Packet

        public override byte[] Build()
        {
            var pkt = new PacketWriter();
            pkt.WriteStruct(sender);
            pkt.WriteMagic((uint)receivers.Count, 0x7C49, 0x9E);
            foreach (var entry in receivers)
            {
                pkt.WriteStruct(entry);
            }
            return pkt.ToArray();
        }

        public override PacketHeader GetHeader()
        {
            return new PacketHeader(0x06, 0x05, PacketFlags.PACKED);
        }

        #endregion
    }
}