using CommonAI.Data;
using CommonAI.Zone;
using CommonAI.Zone.Instance;
using CommonLang.IO;
using CommonLang.IO.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XmdsCommon.Plugin;

namespace XmdsCommonServer.Message
{


    /// <summary>
    /// 战斗服通知客户端事件.
    /// </summary>
    [MessageType(0xFF00001)]
    public class PlayerRebirthEventR2B : PlayerEvent
    {
        //1 = 原地复活.
        //2 = 出生点复活.
        //3 = 复活点复活.
        //4 = 技能复活.
        //5 = 随机复活点
        public byte type = 0;

        public int HP = 0;
        public int MP = 0;

        public ConsumeItemEventB2R Callback = null;

        public PlayerRebirthEventR2B() { }

        public PlayerRebirthEventR2B(byte t, ConsumeItemEventB2R c)
        {
            type = t;
            Callback = c;
        }

        override public void WriteExternal(IOutputStream output)
        {
            base.WriteExternal(output);
            output.PutU8(type);
            output.PutExt(Callback);
            output.PutVS32(HP);
            output.PutVS32(MP);
        }
        override public void ReadExternal(IInputStream input)
        {
            base.ReadExternal(input);
            type = input.GetU8();
            Callback = input.GetExt<ConsumeItemEventB2R>();
            HP = input.GetVS32();
            MP = input.GetVS32();
        }
    }

    /// <summary>
    /// 游戏服通知战斗服救人.
    /// </summary>
    [MessageType(0xFF00002)]
    public class PlayerSaveEventR2B : PlayerEvent
    {
        //救助者.
        public InstanceUnit Saver = null;
        //死者.
        public InstanceUnit Decedent = null;
        //复活所需要时间.
        public int SaveTime = 0;

    }

    /// <summary>
    /// 游戏通知战斗服召唤坐骑.
    /// </summary>
    [MessageType(0xFF00003)]
    public class PlayerSummonMountEventR2B : PlayerEvent
    {
        /// <summary>
        /// 召唤时间.
        /// </summary>
        public int TimeMS = 0;
        /// <summary>
        /// 是否为上坐骑.
        /// </summary>
        public bool IsSummonMount = false;

    }

    /// <summary>
    /// 游戏服通知技能变更.
    /// </summary>
    [MessageType(0xFF00004)]
    public class PlayerSkillChangeEventR2B : PlayerEvent
    {
        public enum SkillOperate : byte
        {
            Reset = 0,   //重置所有.
            Replace = 1,   //替换(找到指定ID然后替换).
            Add = 2,   //新增.
            Remove = 3,   //删除.
        }


        /// <summary>
        /// 操作标识.
        /// </summary>
        public SkillOperate OperateID = SkillOperate.Reset;

        /// <summary>
        /// 技能列表(可能包含主动、被动).
        /// </summary>
        public List<GameSkill> SkillList = null;

        override public void WriteExternal(IOutputStream output)
        {
            base.WriteExternal(output);

            output.PutEnum8(OperateID);
            output.PutList<GameSkill>(SkillList, output.PutExt);

        }
        override public void ReadExternal(IInputStream input)
        {
            base.ReadExternal(input);

            OperateID = input.GetEnum8<SkillOperate>();
            SkillList = input.GetList<GameSkill>(input.GetExt<GameSkill>);
        }
    }

    /// <summary>
    /// 同步玩家可用背包数量.
    /// </summary>
    [MessageType(0xFF00005)]
    public class SyncPlayerInventorySizeEventR2B : PlayerEvent
    {
        public int Size = 0;

        override public void WriteExternal(IOutputStream output)
        {
            base.WriteExternal(output);

            output.PutS32(Size);
        }
        override public void ReadExternal(IInputStream input)
        {
            base.ReadExternal(input);

            Size = input.GetS32();
        }

    }

    /// <summary>
    /// 组队信息.
    /// </summary>
    [MessageType(0xFF00006)]
    public class TeamInfoEventR2B
    {
        public List<string> UUIDList = null;
    }

    /// <summary>
    /// 单位PK等级变更事件(游戏服至战斗服).
    /// </summary>
    [MessageType(0xFF00007)]
    public class PlayerPKLevelChangeEventR2B
    {
        /// <summary>
        /// 当前等级.
        /// </summary>
        public PKLevel CurPKLv;
    }

    /// <summary>
    /// 单位PK模式变更.(游戏服至战斗服).
    /// </summary>
    [MessageType(0xFF00008)]
    public class PlayerPKModeChangeEventR2B
    {
        /// <summary>
        /// 当前模式.
        /// </summary>
        public PKMode CurPKMode;
    }

    /// <summary>
    /// 单位PK模式变更.(游戏服至战斗服).
    /// </summary>
    [MessageType(0xFF00009)]
    public class PlayerPKValueChangeEventR2B
    {
        /// <summary>
        /// 更改值,实际计算公式:CurrentValue += ChangeValue.
        /// </summary>
        public int ChangeValue;
    }

    /// <summary>
    /// 属性变更指令.
    /// </summary>
    [MessageType(0xFF00010)]
    public class PropertyChangeEventR2B
    {
        /// <summary>
        /// 属性变更类型.
        /// </summary>
        public enum PropertyChangeType : byte
        {
            HP,
            NPC
        }

        public enum ValueType : byte
        {
            Value,
            Percent // 万分比.
        }

        /// <summary>
        /// 作用类型.
        /// </summary>
        public PropertyChangeType ChangeType;

        /// <summary>
        /// 值类型.
        /// </summary>
        public ValueType ChangeValueType;

        /// <summary>
        /// 值.
        /// </summary>
        public int ChangeValue;

        /// <summary>
        /// 持续时间.
        /// </summary>
        public int Duration;

        /// <summary>
        /// 过期时间戳.
        /// </summary>
        public long TimestampMS;
    }

    /// <summary>
    /// 宠物基础属性变更.
    /// </summary>
    [MessageType(0xFF00011)]
    public class PetBaseInfoChangeEventR2B
    {
        /// <summary>
        /// 基础属性.
        /// </summary>
        public PetBaseInfo BaseInfo;
    }

    /// <summary>
    /// 宠物整体属性变更.
    /// </summary>
    [MessageType(0xFF00012)]
    public class PetDataChangeEventR2B
    {
        /// <summary>
        /// 属性变更类型.
        /// </summary>
        public enum PetDataChangeType : byte
        {
            Add,                //增加.
            Delete,             //删除.
            Replace,            //替换宠物.
            Reset,              //重置当前.
        }

        public PetDataChangeType OpType;

        public PetData Data;
    }

    /// <summary>
    /// 宠物技能变更.
    /// </summary>
    [MessageType(0xFF00013)]
    public class PetSkillChangeEventR2B
    {
        /// <summary>
        /// 操作标识.
        /// </summary>
        public PlayerSkillChangeEventR2B.SkillOperate OperateID;

        /// <summary>
        /// 技能列表(可能包含主动、被动).
        /// </summary>
        public List<GameSkill> SkillList = null;
    }

    /// <summary>
    /// 组队背包更新.
    /// </summary>
    [MessageType(0xFF00014)]
    public class TeamInventorySizeChangeEventR2B
    {
        public int size;
    }

    /// <summary>
    /// 宠物属性变更指令.
    /// </summary>
    [MessageType(0xFF00015)]
    public class PetPropertyChangeEventR2B
    {
        public PropertyChangeEventR2B Order;
    }

    [MessageType(0xFF00016)]
    public class PetFollowModeChangeEventR2B
    {
        public XmdsCommon.Plugin.XmdsPetConifg.XmdsPetFollowMode mode;
    }


    /////////////////////////////////////组队相关////////////////////////////////////////////////
    /// <summary>
    /// 游戏服通知组队信息
    /// </summary>
    public class TeamDataEventR2B
    {
        public string LeaderId;
        public List<TeamMemberEventR2B> TeamMembers;

		public bool ContainMem(String id)
		{
			if(this.TeamMembers == null)
			{
				return false;
			}

			foreach(TeamMemberEventR2B member in this.TeamMembers)
			{
				if(member.uuid != null && member.uuid.Equals(id))
				{
					return true;
				}
			}

			return false;
		}		
    }

    public class TeamMemberEventR2B
    {
        public int followLeader;
        public string uuid;
    }
}