Example #1
0
        public FormHerdMerge(
            [NotNull] GrangerContext context,
            [NotNull] FormGrangerMain mainForm,
            [NotNull] string sourceHerdName,
            [NotNull] ILogger logger)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            if (sourceHerdName == null)
            {
                throw new ArgumentNullException(nameof(sourceHerdName));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            this.context        = context;
            this.mainForm       = mainForm;
            this.sourceHerdName = sourceHerdName;
            this.logger         = logger;

            InitializeComponent();

            textBoxFromHerd.Text = this.sourceHerdName;
            comboBoxToHerd.Items.AddRange(
                this.context.Herds.Where(x => x.HerdId != sourceHerdName).Cast <object>().ToArray());
            listBoxFromHerd.Items.AddRange(
                this.context.Creatures.Where(x => x.Herd == this.sourceHerdName).Cast <object>().ToArray());
        }
Example #2
0
        internal void Init(
            [NotNull] FormGrangerMain formGrangerMain,
            [NotNull] GrangerContext context,
            [NotNull] ILogger logger)
        {
            if (formGrangerMain == null)
            {
                throw new ArgumentNullException(nameof(formGrangerMain));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            this.mainForm          = formGrangerMain;
            this.context           = context;
            this.logger            = logger;
            _debugMainFormAssigned = true;

            if (mainForm.Settings.AdjustForDarkThemes)
            {
                MakeDarkHighContrastFriendly();
            }

            if (mainForm.Settings.TraitViewState != null)
            {
                objectListView1.RestoreState(mainForm.Settings.TraitViewState);
            }
            traitViewManager = new TraitViewManager(mainForm, this.context, objectListView1);
        }
Example #3
0
        public FormHerdName(
            [NotNull] GrangerContext context,
            [NotNull] Form mainForm,
            [NotNull] ILogger logger,
            [CanBeNull] string renamingHerd = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            this.mainForm     = mainForm;
            this.logger       = logger;
            this.renamingHerd = renamingHerd;
            this.context      = context;

            InitializeComponent();

            allHerdNames = context.Herds.Select(x => x.HerdId).ToArray();
        }
 public SmileXamineProcessor(
     [NotNull] GrangerFeature parentModule,
     [NotNull] GrangerContext context,
     [NotNull] PlayerManager playerMan,
     [NotNull] GrangerDebugLogger debugLogger,
     [NotNull] ITrayPopups trayPopups, [NotNull] ILogger logger,
     [NotNull] IWurmAssistantConfig wurmAssistantConfig,
     [NotNull] CreatureColorDefinitions creatureColorDefinitions,
     [NotNull] GrangerSettings grangerSettings)
 {
     if (parentModule == null)
     {
         throw new ArgumentNullException(nameof(parentModule));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (playerMan == null)
     {
         throw new ArgumentNullException(nameof(playerMan));
     }
     if (debugLogger == null)
     {
         throw new ArgumentNullException(nameof(debugLogger));
     }
     if (trayPopups == null)
     {
         throw new ArgumentNullException(nameof(trayPopups));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (wurmAssistantConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmAssistantConfig));
     }
     if (creatureColorDefinitions == null)
     {
         throw new ArgumentNullException(nameof(creatureColorDefinitions));
     }
     if (grangerSettings == null)
     {
         throw new ArgumentNullException(nameof(grangerSettings));
     }
     this.debugLogger              = debugLogger;
     this.trayPopups               = trayPopups;
     this.logger                   = logger;
     this.wurmAssistantConfig      = wurmAssistantConfig;
     this.creatureColorDefinitions = creatureColorDefinitions;
     this.parentModule             = parentModule;
     this.context                  = context;
     this.playerMan                = playerMan;
     this.grangerSettings          = grangerSettings;
 }
        public CreatureColorDefinitions([NotNull] GrangerContext grangerContext)
        {
            if (grangerContext == null)
            {
                throw new ArgumentNullException(nameof(grangerContext));
            }
            this.grangerContext = grangerContext;

            SetupDefaultColors();
        }
Example #6
0
        public FormChooseHerd([NotNull] GrangerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            InitializeComponent();

            listBox1.Items.AddRange(context.Herds.Cast <object>().ToArray());
        }
Example #7
0
 public FormEditValuePresets([NotNull] GrangerContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     this.context = context;
     InitializeComponent();
     RebuildAllPresetsList();
 }
Example #8
0
        public XDocument CreateXml(GrangerContext context, string herdName)
        {
            if (herdName == null)
            {
                throw new GrangerException("No herd specified");
            }

            var creatures = context.Creatures.Where(x => x.Herd == herdName).ToArray();

            if (creatures.Length == 0)
            {
                throw new GrangerException(string.Format("No creatures found in {0} herd or herd did not exist", herdName));
            }

            XElement root = new XElement("Herd", new XAttribute("OriginalHerdName", herdName));

            foreach (CreatureEntity creatureEntity in creatures)
            {
                var creature =
                    new XElement("Creature",
                                 new XElement("Name", creatureEntity.Name),
                                 new XElement("Father", creatureEntity.FatherName),
                                 new XElement("Mother", creatureEntity.MotherName),
                                 new XElement("Traits", GetTraitListXML(creatureEntity)),
                                 new XElement("NotInMoodUntil",
                                              creatureEntity.NotInMood?.ToString(CultureInfo.InvariantCulture) ?? string.Empty),
                                 new XElement("PregnantUntil",
                                              creatureEntity.PregnantUntil?.ToString(
                                                  CultureInfo.InvariantCulture) ?? string.Empty),
                                 new XElement("GroomedOn",
                                              creatureEntity.GroomedOn?.ToString(CultureInfo.InvariantCulture) ?? string.Empty),
                                 new XElement("Gender", GetGender(creatureEntity)),
                                 new XElement("CaredBy", creatureEntity.TakenCareOfBy),
                                 new XElement("InspectSkill",
                                              creatureEntity.TraitsInspectedAtSkill,
                                              new XAttribute("IsEpic",
                                                             creatureEntity.EpicCurve.HasValue
                                    ? creatureEntity.EpicCurve.ToString()
                                    : bool.FalseString)),
                                 new XElement("Age", creatureEntity.Age),
                                 new XElement("CreatureColorId", creatureEntity.CreatureColorId),
                                 new XElement("Comments", creatureEntity.Comments),
                                 new XElement("Tags", creatureEntity.SpecialTagsRaw),
                                 new XElement("BrandedFor", creatureEntity.BrandedFor),
                                 new XElement("ServerName", creatureEntity.ServerName),
                                 new XElement("SmilexamineLastDate",
                                              creatureEntity.SmilexamineLastDate?.ToString(CultureInfo.InvariantCulture) ?? string.Empty));
                root.Add(creature);
            }

            return(new XDocument(
                       new XDeclaration("1.0", "utf-8", "yes"),
                       root));
        }
 public LogsFeedManager(
     [NotNull] GrangerFeature parentModule,
     [NotNull] GrangerContext context,
     [NotNull] IWurmApi wurmApi,
     [NotNull] ILogger logger,
     [NotNull] ITrayPopups trayPopups,
     [NotNull] IWurmAssistantConfig wurmAssistantConfig,
     [NotNull] CreatureColorDefinitions creatureColorDefinitions,
     [NotNull] GrangerSettings grangerSettings,
     [NotNull] ITelemetry telemetry)
 {
     if (parentModule == null)
     {
         throw new ArgumentNullException(nameof(parentModule));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (wurmApi == null)
     {
         throw new ArgumentNullException(nameof(wurmApi));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (trayPopups == null)
     {
         throw new ArgumentNullException(nameof(trayPopups));
     }
     if (wurmAssistantConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmAssistantConfig));
     }
     if (creatureColorDefinitions == null)
     {
         throw new ArgumentNullException(nameof(creatureColorDefinitions));
     }
     if (grangerSettings == null)
     {
         throw new ArgumentNullException(nameof(grangerSettings));
     }
     this.parentModule             = parentModule;
     this.context                  = context;
     this.wurmApi                  = wurmApi;
     this.logger                   = logger;
     this.trayPopups               = trayPopups;
     this.wurmAssistantConfig      = wurmAssistantConfig;
     this.creatureColorDefinitions = creatureColorDefinitions;
     this.grangerSettings          = grangerSettings;
     this.telemetry                = telemetry ?? throw new ArgumentNullException(nameof(telemetry));
 }
Example #10
0
 /// <summary>
 /// Creates new valuator with values loaded from database
 /// </summary>
 public TraitValuator(FormGrangerMain mainForm, string valueMapId, GrangerContext context)
 {
     this.mainForm = mainForm;
     this.context  = context;
     ValueMapId    = valueMapId;
     if (valueMapId == DefaultId)
     {
         usingDefault = true;
     }
     else
     {
         RebuildValues();
         context.OnTraitValuesModified += context_OnTraitValuesModified;
     }
 }
Example #11
0
 public Creature(
     FormGrangerMain mainForm,
     CreatureEntity entity,
     GrangerContext context,
     [NotNull] CreatureColorDefinitions creatureColorDefinitions)
 {
     if (creatureColorDefinitions == null)
     {
         throw new ArgumentNullException(nameof(creatureColorDefinitions));
     }
     BreedHintColor = null;
     this.mainForm  = mainForm;
     Entity         = entity;
     this.context   = context;
     this.creatureColorDefinitions = creatureColorDefinitions;
 }
        public FormGrangerImportExport([NotNull] GrangerContext context, [NotNull] ILogger logger)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            this.context = context;
            this.logger  = logger;

            InitializeComponent();

            comboBoxExportedHerd.Items.AddRange(context.Herds.Select(x => x.ToString()).Cast <object>().ToArray());
        }
Example #13
0
        public BreedingAdvisor(
            [NotNull] FormGrangerMain mainForm,
            [NotNull] string advisorId,
            [NotNull] GrangerContext context,
            [NotNull] ILogger logger,
            [NotNull] DefaultBreedingEvaluatorOptions defaultBreedingEvaluatorOptions)
        {
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            if (advisorId == null)
            {
                throw new ArgumentNullException(nameof(advisorId));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (defaultBreedingEvaluatorOptions == null)
            {
                throw new ArgumentNullException(nameof(defaultBreedingEvaluatorOptions));
            }
            this.mainForm  = mainForm;
            this.AdvisorId = advisorId;
            this.context   = context;
            this.logger    = logger;

            IsDisabled = false;
            if (advisorId == DisabledId)
            {
                breedEvalutator = new DisabledBreedingEvaluator(logger);
                IsDisabled      = true;
            }

            if (advisorId == DefaultId)
            {
                breedEvalutator = new DefaultBreedingEvaluator(logger, defaultBreedingEvaluatorOptions);
            }
        }
Example #14
0
        public TraitValueMap(GrangerContext context, string traitValueMapId)
        {
            this.context         = context;
            this.traitValueMapId = traitValueMapId;

            valueMap = CreatureTrait.GetAllDefaultValues();

            if (traitValueMapId == TraitValuator.DefaultId)
            {
                ReadOnly = true;
            }
            else
            {
                ReadOnly = false;
                var entities = this.context.TraitValues.Where(x => x.ValueMapId == traitValueMapId);
                foreach (var entity in entities)
                {
                    valueMap[entity.Trait.CreatureTraitId] = entity.Value;
                }
            }
        }
Example #15
0
        public void Init(
            [NotNull] FormGrangerMain mainForm,
            [NotNull] GrangerContext context,
            [NotNull] ILogger logger,
            [NotNull] IWurmApi wurmApi,
            [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.context  = context;
            this.logger   = logger;
            this.wurmApi  = wurmApi;
            this.creatureColorDefinitions = creatureColorDefinitions;

            CustomizeOlv();

            this.context.OnHerdsModified += RefreshHerdList;
            RefreshHerdList(this, EventArgs.Empty);
        }
Example #16
0
        public string CreateCsv(GrangerContext context, string herdName)
        {
            if (herdName == null)
            {
                throw new GrangerException("No herd specified");
            }

            var creatures = context.Creatures.Where(x => x.Herd == herdName).ToArray();

            if (creatures.Length == 0)
            {
                throw new GrangerException(string.Format("No creatures found in {0} herd or herd did not exist", herdName));
            }

            var builder = new EnumerableToCsvBuilder <CreatureEntity>(creatures)
                          .AddMapping("Name", entity => entity.Name)
                          .AddMapping("Server", entity => entity.ServerName)
                          .AddMapping("Herd", entity => entity.Herd)
                          .AddMapping("Father", entity => entity.FatherName)
                          .AddMapping("Mother", entity => entity.MotherName)
                          .AddMapping("Traits", entity => string.Join(",", entity.Traits.Select(trait => trait.ToShortcutString())))
                          .AddMapping("Not in mood", entity => entity.NotInMood?.ToString(CultureInfo.InvariantCulture))
                          .AddMapping("Give birth", entity => entity.PregnantUntil?.ToString(CultureInfo.InvariantCulture))
                          .AddMapping("Last groomed", entity => entity.GroomedOn?.ToString(CultureInfo.InvariantCulture))
                          .AddMapping("Gender", entity => entity.GenderAspect)
                          .AddMapping("Age", entity => entity.Age.ToString())
                          .AddMapping("Color", entity => entity.CreatureColorId)
                          .AddMapping("Inspect skill", entity => entity.TraitsInspectedAtSkill?.ToString())
                          .AddMapping("Cared by", entity => entity.TakenCareOfBy)
                          .AddMapping("Tags", entity => entity.SpecialTagsRaw)
                          .AddMapping("Comments", entity => entity.Comments)
                          .AddMapping("Birth date", entity => entity.BirthDate?.ToString(CultureInfo.InvariantCulture))
                          .AddMapping("Branded for", entity => entity.BrandedFor)
                          .AddMapping("SmileXamined", entity => entity.SmilexamineLastDate?.ToString(CultureInfo.InvariantCulture));

            return(builder.BuildCsv());
        }
Example #17
0
        public TraitViewManager(
            [NotNull] FormGrangerMain mainForm,
            [NotNull] GrangerContext context,
            [NotNull] ObjectListView listview)
        {
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (listview == null)
            {
                throw new ArgumentNullException(nameof(listview));
            }
            this.mainForm = mainForm;
            this.context  = context;
            this.olv      = listview;

            olv.FormatRow += OLV_FormatRow;

            allTraits = CreatureTrait.GetAllTraitEnums().Select(x => new CreatureTrait(x)).ToArray();
            BuildClearTraitView();

            listview.SetObjects(items);
            Decide();

            this.mainForm.GrangerSelectedSingleCreatureChanged += MainFormGrangerSelectedCreaturesChanged;
            this.mainForm.GrangerValuatorChanged             += MainForm_Granger_ValuatorChanged;
            this.mainForm.GrangerTraitViewDisplayModeChanged += MainForm_Granger_TraitViewDisplayModeChanged;
            this.context.OnHerdsModified       += Context_OnHerdsModified;
            this.context.OnCreaturesModified   += ContextOnCreaturesModified;
            this.context.OnTraitValuesModified += Context_OnTraitValuesModified;
        }
Example #18
0
        public GrangerFeature(
            [NotNull] ILogger logger,
            [NotNull] IWurmAssistantDataDirectory dataDirectory,
            [NotNull] ISoundManager soundManager,
            [NotNull] ITrayPopups trayPopups,
            [NotNull] IWurmApi wurmApi,
            [NotNull] GrangerSettings grangerSettings,
            [NotNull] DefaultBreedingEvaluatorOptions defaultBreedingEvaluatorOptions,
            [NotNull] IWurmAssistantConfig wurmAssistantConfig,
            [NotNull] ITimerFactory timerFactory,
            [NotNull] CreatureColorDefinitions creatureColorDefinitions,
            [NotNull] GrangerContext grangerContext,
            [NotNull] IFormEditCreatureColorsFactory formEditCreatureColorsFactory,
            [NotNull] ITelemetry telemetry)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (dataDirectory == null)
            {
                throw new ArgumentNullException(nameof(dataDirectory));
            }
            if (soundManager == null)
            {
                throw new ArgumentNullException(nameof(soundManager));
            }
            if (trayPopups == null)
            {
                throw new ArgumentNullException(nameof(trayPopups));
            }
            if (wurmApi == null)
            {
                throw new ArgumentNullException(nameof(wurmApi));
            }
            if (grangerSettings == null)
            {
                throw new ArgumentNullException(nameof(grangerSettings));
            }
            if (defaultBreedingEvaluatorOptions == null)
            {
                throw new ArgumentNullException(nameof(defaultBreedingEvaluatorOptions));
            }
            if (wurmAssistantConfig == null)
            {
                throw new ArgumentNullException(nameof(wurmAssistantConfig));
            }
            if (timerFactory == null)
            {
                throw new ArgumentNullException(nameof(timerFactory));
            }
            if (creatureColorDefinitions == null)
            {
                throw new ArgumentNullException(nameof(creatureColorDefinitions));
            }
            if (grangerContext == null)
            {
                throw new ArgumentNullException(nameof(grangerContext));
            }
            if (formEditCreatureColorsFactory == null)
            {
                throw new ArgumentNullException(nameof(formEditCreatureColorsFactory));
            }

            this.logger        = logger;
            this.dataDirectory = dataDirectory;
            this.soundManager  = soundManager;
            this.trayPopups    = trayPopups;

            settings = grangerSettings;
            this.defaultBreedingEvaluatorOptions = defaultBreedingEvaluatorOptions;
            this.creatureColorDefinitions        = creatureColorDefinitions;

            context = grangerContext;
            this.formEditCreatureColorsFactory = formEditCreatureColorsFactory;
            this.telemetry = telemetry ?? throw new ArgumentNullException(nameof(telemetry));

            grangerUi = new FormGrangerMain(this,
                                            settings,
                                            context,
                                            logger,
                                            wurmApi,
                                            defaultBreedingEvaluatorOptions,
                                            creatureColorDefinitions,
                                            formEditCreatureColorsFactory,
                                            telemetry);

            logsFeedMan = new LogsFeedManager(this, context, wurmApi, logger, trayPopups, wurmAssistantConfig, creatureColorDefinitions, grangerSettings, telemetry);
            logsFeedMan.UpdatePlayers(settings.CaptureForPlayers);
            grangerUi.GrangerPlayerListChanged += GrangerUI_Granger_PlayerListChanged;

            updateLoop          = timerFactory.CreateUiThreadTimer();
            updateLoop.Interval = TimeSpan.FromMilliseconds(500);
            updateLoop.Tick    += (sender, args) => Update();
            updateLoop.Start();
        }
Example #19
0
        public void ImportHerd(GrangerContext context, string newHerdName, string xmlFilePath)
        {
            if (newHerdName == null || newHerdName.Trim() == string.Empty)
            {
                throw new GrangerException("new herd name cannot be empty");
            }

            // check if this herd already exists in database
            if (context.Herds.Any(x => x.HerdId == newHerdName))
            {
                throw new GrangerException($"there is already a herd with named {newHerdName} in database");
            }

            XDocument doc = XDocument.Load(xmlFilePath);
            var       creatureEntities = new List <CreatureEntity>();
            var       elements         = doc.Root.Elements("Horse").Union(doc.Root.Elements("Creature"));

            foreach (var x in elements)
            {
                var entity = new CreatureEntity();
                entity.Herd = newHerdName;
                entity.Name = x.Element("Name").Value;

                if (creatureEntities.Any(y => y.Name.Equals(entity.Name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw new GrangerException(
                              $"Creature named {entity.Name} was already added from this XML file. Review the file for any errors.");
                }

                entity.FatherName = x.Element("Father").Value;
                entity.MotherName = x.Element("Mother").Value;
                entity.Traits     = GetTraitsFromXML(x.Element("Traits"));

                var notInMood = x.Element("NotInMoodUntil").Value;
                if (string.IsNullOrEmpty(notInMood))
                {
                    entity.NotInMood = null;
                }
                else
                {
                    entity.NotInMood = DateTime.Parse(notInMood, CultureInfo.InvariantCulture);
                }

                var pregnantUntil = x.Element("PregnantUntil").Value;
                if (string.IsNullOrEmpty(pregnantUntil))
                {
                    entity.PregnantUntil = null;
                }
                else
                {
                    entity.PregnantUntil = DateTime.Parse(pregnantUntil, CultureInfo.InvariantCulture);
                }

                var groomedOn = x.Element("GroomedOn").Value;
                if (string.IsNullOrEmpty(groomedOn))
                {
                    entity.GroomedOn = null;
                }
                else
                {
                    entity.GroomedOn = DateTime.Parse(groomedOn, CultureInfo.InvariantCulture);
                }

                var gender = x.Element("Gender").Value;
                if (string.IsNullOrEmpty(gender))
                {
                    entity.IsMale = null;
                }
                else
                {
                    entity.IsMale = gender.Equals("male", StringComparison.InvariantCultureIgnoreCase);
                }

                entity.TakenCareOfBy = x.Element("CaredBy").Value;

                var xInspect = x.Element("InspectSkill");
                if (string.IsNullOrEmpty(xInspect.Value))
                {
                    entity.TraitsInspectedAtSkill = null;
                }
                else
                {
                    entity.TraitsInspectedAtSkill = float.Parse(xInspect.Value, CultureInfo.InvariantCulture);
                }
                var xInspectAttr = xInspect.Attribute("IsEpic");
                if (string.IsNullOrEmpty(xInspectAttr.Value))
                {
                    entity.EpicCurve = null;
                }
                else
                {
                    entity.EpicCurve = bool.Parse(xInspectAttr.Value);
                }

                entity.Age             = CreatureAge.CreateAgeFromEnumString(x.Element("Age").Value);
                entity.CreatureColorId = x.Element("CreatureColorId")?.Value ?? CreatureColorEntity.Unknown.Id;
                entity.Comments        = x.Element("Comments").Value;
                entity.SpecialTagsRaw  = x.Element("Tags").Value;
                entity.BrandedFor      = x.Element("BrandedFor").Value;
                var smilexaminedElement = x.Element("SmilexamineLastDate");
                if (smilexaminedElement != null && !string.IsNullOrWhiteSpace(smilexaminedElement.Value))
                {
                    entity.SmilexamineLastDate = DateTime.Parse(smilexaminedElement.Value, CultureInfo.InvariantCulture);
                }

                var serverNameElem = x.Element("ServerName");
                entity.ServerName = serverNameElem?.Value;

                creatureEntities.Add(entity);
            }

            context.InsertHerd(newHerdName);
            foreach (var creatureEntity in creatureEntities)
            {
                creatureEntity.Id = CreatureEntity.GenerateNewCreatureId(context);
                context.InsertCreature(creatureEntity);
            }
        }
        public void Init(
            [NotNull] FormGrangerMain mainForm,
            [NotNull] GrangerContext context,
            [NotNull] ILogger logger,
            [NotNull] IWurmApi wurmApi,
            [NotNull] CreatureColorDefinitions creatureColorDefinitons)
        {
            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 (creatureColorDefinitons == null)
            {
                throw new ArgumentNullException(nameof(creatureColorDefinitons));
            }
            this.logger   = logger;
            this.wurmApi  = wurmApi;
            this.mainForm = mainForm;
            this.context  = context;
            this.creatureColorDefinitons = creatureColorDefinitons;

            _debugMainFormAssigned = true;

            if (this.mainForm.Settings.AdjustForDarkThemes)
            {
                MakeDarkHighContrastFriendly();
            }

            if (mainForm.Settings.CreatureListState != null)
            {
                this.objectListView1.RestoreState(mainForm.Settings.CreatureListState);
            }

            SetupOlvCustomizations();

            this.context.OnHerdsModified         += Context_OnHerdsModified;
            this.context.OnCreaturesModified     += ContextOnCreaturesModified;
            this.mainForm.GrangerUserViewChanged += MainForm_UserViewChanged;
            this.mainForm.GrangerAdvisorChanged  += MainForm_Granger_AdvisorChanged;
            this.mainForm.GrangerValuatorChanged += MainForm_Granger_ValuatorChanged;

            creatureColorMenuManager = new CreatureColorMenuManager(setColorToolStripMenuItem,
                                                                    creatureColorDefinitons,
                                                                    SetColorMenuItemClickAction);

            UpdateCurrentCreaturesData();
            UpdateDataForView();
            timer1.Enabled = true;
        }
        public FormEditValuePresetsNewNameDialog(FormEditValuePresets formEditValuePresets, GrangerContext context)
        {
            this.formEditValuePresets = formEditValuePresets;

            InitializeComponent();

            var uniqueValMapIDs = context.TraitValues.AsEnumerable().Select(x => x.ValueMapId).Distinct();

            foreach (var mapId in uniqueValMapIDs)
            {
                takenValueMapIDs.Add(mapId);
            }
        }
        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;
        }
Example #23
0
        public FormGrangerMain(
            [NotNull] GrangerFeature grangerFeature,
            [NotNull] GrangerSettings settings,
            [NotNull] GrangerContext context,
            [NotNull] ILogger logger,
            [NotNull] IWurmApi wurmApi,
            [NotNull] DefaultBreedingEvaluatorOptions defaultBreedingEvaluatorOptions,
            [NotNull] CreatureColorDefinitions creatureColorDefinitions,
            [NotNull] IFormEditCreatureColorsFactory formEditCreatureColorsFactory,
            [NotNull] ITelemetry telemetry)
        {
            if (grangerFeature == null)
            {
                throw new ArgumentNullException(nameof(grangerFeature));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            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 (defaultBreedingEvaluatorOptions == null)
            {
                throw new ArgumentNullException(nameof(defaultBreedingEvaluatorOptions));
            }
            if (creatureColorDefinitions == null)
            {
                throw new ArgumentNullException(nameof(creatureColorDefinitions));
            }
            if (formEditCreatureColorsFactory == null)
            {
                throw new ArgumentNullException(nameof(formEditCreatureColorsFactory));
            }
            this.parentModule = grangerFeature;
            this.settings     = settings;
            this.context      = context;
            this.logger       = logger;
            this.wurmApi      = wurmApi;
            this.defaultBreedingEvaluatorOptions = defaultBreedingEvaluatorOptions;
            this.creatureColorDefinitions        = creatureColorDefinitions;
            this.formEditCreatureColorsFactory   = formEditCreatureColorsFactory;
            this.telemetry = telemetry ?? throw new ArgumentNullException(nameof(telemetry));

            InitializeComponent();

            RebuildValuePresets();
            RefreshValuator();
            RebuildAdvisors();
            RefreshAdvisor();

            ucGrangerHerdList1.Init(this, context, logger, wurmApi, creatureColorDefinitions);
            ucGrangerCreatureList1.Init(this, context, logger, wurmApi, creatureColorDefinitions);
            ucGrangerTraitView1.Init(this, context, logger);

            this.context.OnTraitValuesModified += Context_OnTraitValuesModified;

            this.Size = this.settings.MainWindowSize;

            this.checkBoxCapturingEnabled.Checked = this.settings.LogCaptureEnabled;
            this.UpdateViewsVisibility();
            this.Update_textBoxCaptureForPlayers();

            _windowInitCompleted = true;
        }
        public CreatureUpdatesManager(
            [NotNull] GrangerFeature parentModule,
            [NotNull] GrangerContext context,
            [NotNull] PlayerManager playerManager,
            [NotNull] ITrayPopups trayPopups,
            [NotNull] ILogger logger,
            [NotNull] IWurmAssistantConfig wurmAssistantConfig,
            [NotNull] CreatureColorDefinitions creatureColorDefinitions,
            [NotNull] GrangerSettings grangerSettings)
        {
            if (parentModule == null)
            {
                throw new ArgumentNullException(nameof(parentModule));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (playerManager == null)
            {
                throw new ArgumentNullException(nameof(playerManager));
            }
            if (trayPopups == null)
            {
                throw new ArgumentNullException(nameof(trayPopups));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (wurmAssistantConfig == null)
            {
                throw new ArgumentNullException(nameof(wurmAssistantConfig));
            }
            if (creatureColorDefinitions == null)
            {
                throw new ArgumentNullException(nameof(creatureColorDefinitions));
            }
            if (grangerSettings == null)
            {
                throw new ArgumentNullException(nameof(grangerSettings));
            }

            this.parentModule  = parentModule;
            this.context       = context;
            this.playerManager = playerManager;
            this.trayPopups    = trayPopups;
            this.logger        = logger;

            grangerDebug = new GrangerDebugLogger(logger);

            smileXamineProcessor = new SmileXamineProcessor(this.parentModule,
                                                            this.context,
                                                            this.playerManager,
                                                            grangerDebug,
                                                            trayPopups,
                                                            logger,
                                                            wurmAssistantConfig,
                                                            creatureColorDefinitions,
                                                            grangerSettings);
        }
Example #25
0
        public PlayerManager(
            [NotNull] GrangerFeature parentModule,
            [NotNull] GrangerContext context,
            [NotNull] string playerName,
            [NotNull] IWurmApi wurmApi,
            [NotNull] ILogger logger,
            [NotNull] ITrayPopups trayPopups,
            [NotNull] IWurmAssistantConfig wurmAssistantConfig,
            [NotNull] CreatureColorDefinitions creatureColorDefinitions,
            [NotNull] GrangerSettings grangerSettings,
            [NotNull] ITelemetry telemetry)
        {
            if (parentModule == null)
            {
                throw new ArgumentNullException(nameof(parentModule));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (playerName == null)
            {
                throw new ArgumentNullException(nameof(playerName));
            }
            if (wurmApi == null)
            {
                throw new ArgumentNullException(nameof(wurmApi));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (trayPopups == null)
            {
                throw new ArgumentNullException(nameof(trayPopups));
            }
            if (wurmAssistantConfig == null)
            {
                throw new ArgumentNullException(nameof(wurmAssistantConfig));
            }
            if (creatureColorDefinitions == null)
            {
                throw new ArgumentNullException(nameof(creatureColorDefinitions));
            }
            if (grangerSettings == null)
            {
                throw new ArgumentNullException(nameof(grangerSettings));
            }
            if (telemetry == null)
            {
                throw new ArgumentNullException(nameof(telemetry));
            }
            this.parentModule = parentModule;
            this.wurmApi      = wurmApi;
            this.logger       = logger;
            this.PlayerName   = playerName;

            creatureUpdateManager = new CreatureUpdatesManager(this.parentModule, context, this, trayPopups, logger, wurmAssistantConfig, creatureColorDefinitions, grangerSettings, telemetry);

            wurmApi.LogsMonitor.Subscribe(PlayerName, LogType.Event, OnNewEventLogEvents);

            character = wurmApi.Characters.Get(PlayerName);
            character.LogInOrCurrentServerPotentiallyChanged += CharacterOnLogInOrCurrentServerPotentiallyChanged;
            character.Skills.SkillsChanged += SkillsOnSkillsChanged;

            BeginUpdateSkillInfo();
        }