﻿using System;
using EndlessWorlds.Lib.Serialization.Attributes;
using EndlessWorlds.Lib.Data;
using EndlessWorlds.Lib.Data.GameTypes;
using EndlessWorlds.Lib.Networking.Packets;

namespace Assets.Client.Networking.Packets.ServerPackets
{
    /// <summary>
    /// Usually sent when the player logs in with a character. This packet initializes the player's character's data.
    /// </summary>
    [DataContract]
    [PacketId(0x01, PacketTypes.ServerPacket)]
    public class OwnedCharacterDataServerPacket : PacketBase
    {
        [DataMember] public string Name;
        [DataMember] public int Level;
        [DataMember] public PlayerRace Race;
        [DataMember] public Gender Gender;
        [DataMember] public Point Position;

        public override void Handle(Connection connection)
        {
            // for now, just overwrite the character for testing
            var character = new CharacterData
            {
                Name = Name,
                Race = Race,
                Level = Level,
                Gender = Gender,
                Position = Position
            };

            ((ConnectionData) connection.ConnectionData).Account.EnteredCharacter = character;
            Console.WriteLine("Character logged in. Welcome [Lv. {0}] {1} {2} {3}!", Level, Gender, Race, Name);
        }
    }
}
