コード例 #1
0
        public void Handle(CreateModelCommand <HorseModel> command)
        {
            var horse = new HorseEntity
            {
                Name = command.Model.Name,
            };

            this.horseRepository.Add(horse);
        }
コード例 #2
0
ファイル: ImportExport.cs プロジェクト: webba/WurmAssistant2
 string GetGender(HorseEntity horseEntity)
 {
     if (horseEntity.IsMale == null) return string.Empty;
     else return horseEntity.IsMale.Value ? "male" : "female";
 }
コード例 #3
0
ファイル: ImportExport.cs プロジェクト: webba/WurmAssistant2
 IEnumerable<XElement> GetTraitListXML(HorseEntity horseEntity)
 {
     var result = new List<XElement>();
     foreach (var trait in horseEntity.Traits)
     {
         result.Add(new XElement("Trait", new XAttribute("TraitId", (int)trait.Trait), trait.ToString()));
     }
     return result;
 }
コード例 #4
0
ファイル: ImportExport.cs プロジェクト: webba/WurmAssistant2
        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(string.Format("there is already a herd with named {0} in database", newHerdName));
            }

            XDocument doc = XDocument.Load(xmlFilePath);
            var horseEntities = new List<HorseEntity>();       
            var elements = doc.Root.Elements("Horse");
            foreach (var x in elements)
            {
                var entity = new HorseEntity();
                entity.Herd = newHerdName;
                entity.Name = x.Element("Name").Value;

                // verify this name is not present in current list
                if (horseEntities.Any(y => y.Name.Equals(entity.Name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw new GrangerException(string.Format("Horse named {0} was already added from this XML file. Review the file for any errors.", entity.Name));
                }

                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 = HorseAge.CreateAgeFromEnumString(x.Element("Age").Value);
                entity.Color = HorseColor.CreateColorFromEnumString(x.Element("Color").Value);
                entity.Comments = x.Element("Comments").Value;
                entity.SpecialTagsRaw = x.Element("Tags").Value;
                entity.BrandedFor = x.Element("BrandedFor").Value;

                horseEntities.Add(entity);
            }

            context.InsertHerd(newHerdName);
            foreach (var horseEntity in horseEntities)
            {
                horseEntity.ID = HorseEntity.GenerateNewHorseID(context);
                context.InsertHorse(horseEntity);
            }
        }
コード例 #5
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (!ValidateHorseIdentity())
            {
                this.DialogResult = System.Windows.Forms.DialogResult.None;
            }
            else
            {
                try
                {
                    if (OpMode == HorseViewEditOpType.New)
                    {
                        var newEntity = new HorseEntity() { ID = HorseEntity.GenerateNewHorseID(Context) };
                        horse = new Horse(MainForm, newEntity, Context);
                    }
                    horse.Name = textBoxName.Text;
                    horse.Father = comboBoxFather.Text;
                    horse.Mother = comboBoxMother.Text;
                    horse.TakenCareOfBy = textBoxCaredForBy.Text;
                    horse.BrandedFor = textBoxBrandedFor.Text;

                    List<HorseTrait> traitlist = new List<HorseTrait>();
                    foreach (var item in checkedListBoxTraits.CheckedItems)
                    {
                        try
                        {
                            traitlist.Add(HorseTrait.FromWurmTextRepr(item.ToString()));
                        }
                        catch (Exception _e)
                        {
                            Logger.LogError("failed to create horse trait from text:" + item.ToString(), this, _e);
                        }
                    }
                    var traitlistArray = traitlist.ToArray();
                    horse.Traits = traitlistArray;

                    horse.TraitsInspectSkill = (float)numericUpDownAHskill.Value;
                    float traitSkill = HorseTrait.GetMinSkillForTraits(traitlistArray, checkBoxEpic.Checked);
                    if (horse.TraitsInspectSkill < traitSkill)
                        horse.TraitsInspectSkill = traitSkill;
                    horse.EpicCurve = checkBoxEpic.Checked;

                    horse.Comments = textBoxComment.Text;
                    horse.IsMale = radioButtonMale.Checked;
                    horse.Color = HorseColor.CreateColorFromEnumString(comboBoxColor.Text);
                    horse.Age = HorseAge.CreateAgeFromEnumString(comboBoxAge.Text);

                    horse.NotInMoodUntil = dateTimePickerBred.Value;
                    horse.GroomedOn = dateTimePickerGroomed.Value;
                    horse.PregnantUntil = dateTimePickerPregnant.Value;
                    horse.BirthDate = dateTimePickerBirthDate.Value;

                    horse.SetTag("diseased", checkBoxDiseased.Checked);
                    horse.SetTag("dead", checkBoxDead.Checked);
                    horse.SetTag("sold", checkBoxSold.Checked);

                    if (OpMode == HorseViewEditOpType.New)
                    {
                        horse.Herd = HerdID;
                        Context.InsertHorse(horse.Entity);
                    }
                    else
                    {
                        Context.SubmitChangesToHorses();
                    }
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                catch (Exception _e)
                {
                    Logger.LogError("problem while updating database, op: " + OpMode, this, _e);
                    MessageBox.Show("There was a problem on submitting to database.\r\n" + _e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = System.Windows.Forms.DialogResult.None;
                }
            }
        }
コード例 #6
0
        private void AddNewHorse(string selectedHerd, HorseBuilder newHorse)
        {
            var newEntity = new HorseEntity
            {
                ID = HorseEntity.GenerateNewHorseID(_context),
                Name = newHorse.Name,
                Herd = selectedHerd,
                Age = _newHorse.Age,
                TakenCareOfBy = newHorse.CaredBy,
                BrandedFor = newHorse.BrandedBy,
                FatherName = newHorse.Father,
                MotherName = newHorse.Mother,
                Traits = newHorse.Traits,
                TraitsInspectedAtSkill = newHorse.InspectSkill,
                IsMale = newHorse.IsMale,
                PregnantUntil = newHorse.PregnantUntil,
                SecondaryInfoTagSetter = newHorse.SecondaryInfo
            };

            newEntity.EpicCurve = newHorse.ServerGroup == WurmServer.ServerInfo.ServerGroup.Epic;
            if (newHorse.ServerGroup == WurmServer.ServerInfo.ServerGroup.Unknown)
            {
                Logger.LogError("Adding horse with unknown server group, name: "+newHorse.Name);
            }

            _context.InsertHorse(newEntity);
            _grangerDebug.Log("successfully inserted horse to db");
            Popup.Schedule("HORSE ADDED", String.Format("Added new horse to herd {0}: {1}", selectedHerd, newEntity));
        }
コード例 #7
0
 internal void DeleteHorses(HorseEntity[] horses)
 {
     Horses.DeleteAllOnSubmit(horses);
     SubmitChanges();
     if (OnHorsesModified != null) OnHorsesModified(this, new EventArgs());
 }
コード例 #8
0
 /// <summary>
 /// throws DuplicateKeyException
 /// </summary>
 /// <param name="herdName"></param>
 public void InsertHorse(HorseEntity horse)
 {
     Horses.InsertOnSubmit(horse);
     SubmitChanges(); //DuplicateKeyException if duplicate key
     if (OnHorsesModified != null) OnHorsesModified(this, new EventArgs());
 }
コード例 #9
0
 private void ExtractBreedingPairHorse(string fixedName, HorseEntity[] horses)
 {
     if (horses.Length == 1)
     {
         HorseEntity horse = horses[0];
         if (horse.IsMale ?? false)
         {
             _lastBreedingMale = horse;
         }
         else
         {
             _lastBreedingFemale = horse;
         }
     }
     else
     {
         string title = null;
         string message = null;
         if (horses.Length > 1)
         {
             message = (EntireDbSetting ? "Database has" : "Selected herds have")
                       + " more than one horse named: " + fixedName;
         }
         else if (horses.Length == 0)
         {
             if (GrangerHelpers.IsBlacklistedCreatureName_EqualCheck(fixedName))
             {
                 _grangerDebug.Log("Discared breeding candidate due not a horse: " + fixedName);
             }
             else
             {
                 message = "Not a horse or " + (EntireDbSetting ? "" : "selected")
                           + " herds don't have a horse named: " + fixedName;
             }
         }
         if (message != null) Popup.Schedule(title ?? "BREED UPDATE PROBLEM", message, 6000);
     }
 }
コード例 #10
0
        //this should not be called if user disabled capturing data from logs
        //this should not contain any update logic that has tu run regardless of above setting
        internal void ProcessEventForHorseUpdates(string line)
        {
            //this runs if updating on any event is enabled
            if (HorseUpdateAnyEvent && MaybeHorseAgeLine(line))
            {
                // first try selected herds
                HorseData data = GetHorseDataFromAnyLogEvent(line, false);

                bool cont = true;

                if (data != null && data.TooManyHorsesFound)
                {
                    // if we found too many same named in selected, can't continue
                    var partialMessage = "selected herds";
                    Popup.Schedule(
                        "HORSE UPDATE PROBLEM",
                        String.Format(
                            "There are multiple horses named {0} in {1}, can't update health/age!",
                            data.Horse.Name, partialMessage),
                        5000);
                    cont = false;
                }
                else if (data == null && EntireDbSetting)
                {
                    // if we found nothing but EDS is set, try searching entire db
                    data = GetHorseDataFromAnyLogEvent(line, true);
                    if (data != null && data.TooManyHorsesFound)
                    {
                        // again if multiple found in db, we can't continue
                        var partialMessage = "database";
                        Popup.Schedule(
                            "HORSE UPDATE PROBLEM",
                            String.Format(
                                "There are multiple horses named {0} in {1}, can't update health/age!",
                                data.Horse.Name, partialMessage),
                            5000);
                        cont = false;
                    }
                }

                // at this point, either we got single, nothing or many
                // but cont == true means single or nothing

                if (data != null && cont)
                {
                    // if we got single and something, update
                    if (data.SecondaryInfo != null)
                    {
                        string notify = null;
                        if (data.SecondaryInfo == String.Empty)
                        {
                            if (data.Horse.CheckTag("diseased")
                                || data.Horse.CheckTag("starving")
                                || data.Horse.CheckTag("fat"))
                            {
                                notify = "cleared";
                            }
                            data.Horse.SetSecondaryInfoTag(HorseEntity.SecondaryInfoTag.None);
                        }
                        else if (data.SecondaryInfo == "diseased")
                        {
                            if (!data.Horse.CheckTag("diseased"))
                            {
                                notify = "diseased";
                            }
                            data.Horse.SetSecondaryInfoTag(HorseEntity.SecondaryInfoTag.Diseased);
                        }
                        else if (data.SecondaryInfo == "starving")
                        {
                            if (!data.Horse.CheckTag("starving"))
                            {
                                notify = "starving";
                            }
                            data.Horse.SetSecondaryInfoTag(HorseEntity.SecondaryInfoTag.Starving);
                        }
                        else if (data.SecondaryInfo == "fat")
                        {
                            if (!data.Horse.CheckTag("fat"))
                            {
                                notify = "fat";
                            }
                            data.Horse.SetSecondaryInfoTag(HorseEntity.SecondaryInfoTag.Fat);
                        }


                        bool ageChanged = data.Age > data.Horse.Age;

                        if (notify != null || ageChanged)
                        {
                            string health = null;
                            if (notify != null)
                            {
                                if (notify == "cleared")
                                {
                                    health = "Cleared health tags.";
                                }
                                else
                                {
                                    health = "Set health tag to " + notify + ".";
                                }
                            }

                            string age = null;
                            if (ageChanged) age = "updated age to " + data.Age;

                            Popup.Schedule("HEALTH/AGE UPDATE", data.Horse + ": " + health + " " + age);
                        }
                        
                        data.Horse.Age = data.Age;
                    }
                    _context.SubmitChangesToHorses();
                }
            }

            _processor.HandleLogEvent(line);

            //apply updates
            //[13:47:19] Venerable fat Kisspick is dead. R.I.P.
            if (line.Contains("is dead."))
            {
                Match match = Regex.Match(line, @".+ (\w+) is dead\. R\.I\.P\.");
                TryApplyDeadFlag(line, match);
            }
            //[03:10:29] You bury the corpse of venerable tammyrain.
            if (line.StartsWith("You bury the corpse", StringComparison.Ordinal))
            {
                Match match = Regex.Match(line, @"You bury the corpse of .+ (\w+)");
                TryApplyDeadFlag(line, match);
            }

            //[11:34:44] You have now tended to Aged fat Lightningzoe and she seems pleased.
            if (line.StartsWith("You have now tended", StringComparison.Ordinal))
            {
                Match match = Regex.Match(line, @"You have now tended to (.+) and \w+ seems pleased");
                if (match.Success)
                {
                    _grangerDebug.Log("LIVETRACKER: applying groomed flag due to: " + line);
                    string prefixedName = match.Groups[1].Value;
                    HorseAge newAge = GrangerHelpers.ExtractHorseAge(prefixedName);
                    string fixedName = GrangerHelpers.RemoveAllPrefixes(prefixedName);
                    HorseEntity[] horses = GetHorseToUpdate(fixedName, _playerMan.GetCurrentServerGroup());
                    if (EntireDbSetting && horses.Length > 1)
                    {
                        Popup.Schedule(
                            "GROOMING ISSUE DETECTED",
                            String.Format(
                                "There are multiple horses named {0} in database, going to mark them all!",
                                fixedName),
                            6000);
                    }
                    foreach (var horse in horses)
                    {
                        horse.GroomedOn = DateTime.Now;
                        _context.SubmitChangesToHorses();
                    }
                }
            }
            //[04:23:27] The Aged fat Dancedog and the Aged fat Cliffdog get intimate.
            if (line.Contains("get intimate"))
            {
                Match match = Regex.Match(line, @"The (.+) and the (.+) get intimate.");
                if (match.Success)
                {
                    _grangerDebug.Log("LIVETRACKER: attempting to cache last bred pair data due to: " + line);
                    _lastBreedingFemale = null;
                    _lastBreedingMale = null;
                    _lastBreedingOn = DateTime.Now;

                    string name1 = match.Groups[1].Value;
                    string name2 = match.Groups[2].Value;
                    string fixedName1 = GrangerHelpers.RemoveAllPrefixes(name1);
                    string fixedName2 = GrangerHelpers.RemoveAllPrefixes(name2);
                    HorseEntity[] horses1 = GetHorseToUpdate(fixedName1, _playerMan.GetCurrentServerGroup());
                    HorseEntity[] horses2 = GetHorseToUpdate(fixedName2, _playerMan.GetCurrentServerGroup());

                    ExtractBreedingPairHorse(fixedName1, horses1);
                    ExtractBreedingPairHorse(fixedName2, horses2);
                }
            }
            //The Old fat Ebonycloud will probably give birth in a while!
            //[04:23:47] The Aged fat Dancedog will probably give birth in a while!
            if (line.Contains("will probably give birth"))
            {
                if (_lastBreedingOn > DateTime.Now - TimeSpan.FromMinutes(3))
                {
                    _grangerDebug.Log("LIVETRACKER: applying breeding update due to: " + line);

                    // we don't need to requery female horse entity, because any other changes done to this horse
                    // will be reflected on current entity. 
                    // This is true only as long, as entire module uses only a single GrangerContext !!!

                    Match match = Regex.Match(line, @"The (.+) will probably give birth in a while");
                    if (match.Success)
                    {
                        string prefixedName = match.Groups[1].Value;
                        string fixedName = GrangerHelpers.RemoveAllPrefixes(prefixedName);

                        if (_lastBreedingFemale != null)
                        {
                            if (_lastBreedingFemale.Name == fixedName) //sanity check
                            {
                                _lastBreedingFemale.PregnantUntil = DateTime.Now + GrangerHelpers.LongestPregnancyPossible;
                                Popup.Schedule(
                                    "BREED UPDATE",
                                    String.Format("({0}) is now marked as pregnant. Be sure to smilexamine to get more accurate pregnancy duration!", _lastBreedingFemale.Name),
                                    6000);
                                _context.SubmitChangesToHorses();
                            }
                            else
                            {
                                Popup.Schedule(
                                    "BREED UPDATE PROBLEM",
                                    String.Format("Female name ({0}) does not match the cached name ({1})!", _lastBreedingFemale.Name, fixedName),
                                    6000);
                            }
                        }
                        if (_lastBreedingMale != null)
                        {
                            _lastBreedingMale.NotInMood = DateTime.Now + GrangerHelpers.Breeding_NotInMood_Duration;
                            Popup.Schedule(
                                "BREED UPDATE",
                                String.Format("({0}) is now marked as Not In Mood. You can't breed this horse for next 45 minutes.", _lastBreedingMale.Name),
                                6000);
                            _context.SubmitChangesToHorses();
                        }
                    }

                }
            }
            //[06:18:19] The Aged fat Umasad shys away and interrupts the action.
            if (line.Contains("shys away and interrupts"))
            {
                if (_lastBreedingOn > DateTime.Now - TimeSpan.FromMinutes(1))
                {
                    _grangerDebug.Log("LIVETRACKER: processing failed breeding update due to: " + line);
                    Match match = Regex.Match(line, @"The (.+) shys away and interrupts the action");
                    if (match.Success)
                    {
                        string prefixedName = match.Groups[1].Value;
                        string fixedName = GrangerHelpers.RemoveAllPrefixes(prefixedName);
                        if (_lastBreedingMale != null) _lastBreedingMale.NotInMood = DateTime.Now + GrangerHelpers.Breeding_NotInMood_Duration;
                        if (_lastBreedingFemale != null) _lastBreedingFemale.NotInMood = DateTime.Now + GrangerHelpers.Breeding_NotInMood_Duration;
                        Popup.Schedule(
                            "BREED UPDATE",
                            String.Format("Breeding appears to have failed, {0} and {1} will be Not In Mood for next 45 minutes.",
                                _lastBreedingMale == null ? "Some horse" : _lastBreedingMale.Name,
                                _lastBreedingFemale == null ? "Some horse" : _lastBreedingFemale.Name),
                            6000);
                    }
                }
            }
            // disease tracking
            //[20:48:42] You smile at Adolescent diseased Mountainheart.
            string diseaseCheck = GrangerHelpers.LineContainsDiseased(line);
            if ((diseaseCheck) != null)
            {
                string possibleHorseName = diseaseCheck;
                var horsesToUpdate = _context.Horses.Where(x => x.Name == possibleHorseName).ToArray();
                if (horsesToUpdate.Length > 0)
                {
                    foreach (var horse in horsesToUpdate)
                    {
                        _grangerDebug.Log("Marking horse diseased: " + horse);
                        horse.SetTag("diseased", true);
                    }
                    _context.SubmitChangesToHorses();
                }
            }
            // genesis handling (add a horse to dict after genesis cast, 
            // ignore horse for smile-examine trait sanity check next time
            //[2013-08-02] [23:08:54] You cast 'Genesis' on Old fat Jollyhalim.
            if (line.Contains("You cast"))
            {
                _grangerDebug.Log("Found maybe genesis log event: " + line);
                Match match = Regex.Match(line, @"You cast 'Genesis' on (.+)\.");
                if (match.Success)
                {

                    string prefixedHorseName = match.Groups[1].Value;
                    string horseName = GrangerHelpers.ExtractHorseName(prefixedHorseName);
                    _grangerDebug.Log(string.Format("Recognized Genesis cast on: {0} (raw name: {1})", horseName, prefixedHorseName));
                    _parentModule.Settings.Value.AddGenesisCast(DateTime.Now, horseName);
                }
            }
        }
コード例 #11
0
ファイル: Horse.cs プロジェクト: webba/WurmAssistant2
        //other data?

        public Horse(FormGrangerMain mainForm, HorseEntity entity, GrangerContext context)
        {
            MainForm = mainForm;
            Entity = entity;
            Context = context;
        }