private void AddNewCreature(string selectedHerd, CreatureBuffer newCreature) { var newEntity = new CreatureEntity { Id = CreatureEntity.GenerateNewCreatureId(context), Name = newCreature.Name, Herd = selectedHerd, Age = newCreature.Age, TakenCareOfBy = newCreature.CaredBy, BrandedFor = newCreature.BrandedBy, FatherName = newCreature.FatherName, MotherName = newCreature.MotherName, Traits = newCreature.Traits, TraitsInspectedAtSkill = newCreature.InspectSkill, IsMale = newCreature.IsMale, PregnantUntil = newCreature.PregnantUntil, SecondaryInfoTagSetter = newCreature.SecondaryInfo, ServerName = newCreature.Server != null ? newCreature.Server.ServerName.Original : string.Empty, SmilexamineLastDate = DateTime.Now, CreatureColorId = newCreature.HasColorWurmLogText ? creatureColorDefinitions.GetColorIdByWurmLogText(newCreature.ColorWurmLogText) : CreatureColor.GetDefaultColor().CreatureColorId }; newEntity.EpicCurve = newCreature.Server != null && newCreature.Server.ServerGroup.ServerGroupId == ServerGroup.EpicId; context.InsertCreature(newEntity); debugLogger.Log("successfully inserted creature to db"); trayPopups.Schedule(String.Format("Added new creature to herd {0}: {1}", selectedHerd, newEntity), "CREATURE ADDED"); }
public FormCreatureViewEdit( [NotNull] FormGrangerMain mainForm, [NotNull] GrangerContext context, [NotNull] ILogger logger, [NotNull] IWurmApi wurmApi, [CanBeNull] Creature creature, CreatureViewEditOpType optype, string herdId, [NotNull] CreatureColorDefinitions creatureColorDefinitions) { if (mainForm == null) { throw new ArgumentNullException(nameof(mainForm)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (wurmApi == null) { throw new ArgumentNullException(nameof(wurmApi)); } if (creatureColorDefinitions == null) { throw new ArgumentNullException(nameof(creatureColorDefinitions)); } this.mainForm = mainForm; this.creature = creature; this.context = context; this.herdId = herdId; this.creatureColorDefinitions = creatureColorDefinitions; this.logger = logger; this.wurmApi = wurmApi; InitializeComponent(); DisableAllFields(); comboBoxServerName.Items.AddRange( wurmApi.Servers.All.Select(server => server.ServerName.Original).Cast <object>().ToArray()); List <string> list = new List <string>(); list.AddRange(this.context.Creatures.Select(x => x.Name)); list.AddRange(this.context.Creatures.Select(x => x.MotherName)); list.AddRange(this.context.Creatures.Select(x => x.FatherName)); var allCreatureNamesInDatabase = list.Distinct().Where(x => x != null).Cast <object>().ToArray(); comboBoxFather.Items.AddRange(allCreatureNamesInDatabase); comboBoxMother.Items.AddRange(allCreatureNamesInDatabase); ; comboBoxColor.Items.AddRange( creatureColorDefinitions.GetColors().Select(color => color.CreatureColorId).Cast <object>().ToArray()); comboBoxColor.Text = CreatureColor.GetDefaultColor().CreatureColorId; comboBoxAge.Items.AddRange(CreatureAge.GetColorsEnumStrArray().Cast <object>().ToArray()); comboBoxAge.Text = CreatureAge.GetDefaultAgeStr(); this.OpMode = optype; }