using Fantasy.Entitas; using Fantasy.Serialize; #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. namespace Fantasy; public static class MailFactory { public static readonly ISerialize Serializer = SerializerManager.GetSerializer(FantasySerializerType.Bson); /// /// 创建一个基础的邮件 /// /// /// /// /// /// /// /// public static Mail Create(Scene scene, MailType mailType, string title, string content, int money = 0, List items = null) { var mail = Entity.Create(scene, true, true); mail.Title = title; mail.Content = content; mail.Money = money; mail.MailType = mailType; mail.MailState = MailState.Unread; // if (items is not { Count: > 0 }) // { // // } if (items != null && items.Count > 0) { foreach (var item in items) { // 最好的是要个这个Item给克隆出一份来。 // 这样就可以保证,无论外面怎么改变也不会影响这个邮件的东西了。 var cloneItem = Serializer.Clone(item); mail.Items.Add(cloneItem); } } return mail; } }