void PrepareFieldsForNew() { checkedListBoxTraits.Items.Clear(); checkedListBoxTraits.Items.AddRange(CreatureTrait.GetAllTraitWurmText().Cast <object>().ToArray()); EnableAllFields(); this.Text = "Adding new creature to herd: " + herdId; }
List <CreatureTrait> GetTraitsFromXML(XElement xTraits) { var result = new List <CreatureTrait>(); foreach (var xTrait in xTraits.Elements("Trait")) { result.Add(CreatureTrait.FromEnumIntStr(xTrait.Attribute("TraitId").Value)); } return(result); }
public static CreatureTrait[] ParseTraitsFromLine(string line) { List <CreatureTrait> result = new List <CreatureTrait>(); foreach (var trait in CreatureTrait.GetAllPossibleTraits()) { if (line.Contains(trait.ToString())) { result.Add(trait); } } return(result.ToArray()); }
void BuildTraits() { checkedListBoxTraits.Items.Clear(); var traits = creature.Traits; var allTraits = CreatureTrait.GetAllTraitEnums(); foreach (var trait in allTraits) { checkedListBoxTraits.Items.Add( CreatureTrait.GetWurmTextForTrait(trait), traits.Count(x => x.CreatureTraitId == trait) == 1); } }
public int GetValueForTrait(CreatureTrait trait) { if (thisValueMapIsNoMore) { usingDefault = true; mainForm.InvalidateTraitValuator(); } if (usingDefault) { return(CreatureTrait.GetDefaultValue(trait)); } int result = 0; valueMap.TryGetValue(trait, out result); return(result); }
private void UpdateTraitView() { flowLayoutPanel1.Controls.Clear(); if (currentTraitValueMap != null) { foreach (var keyval in currentTraitValueMap.ValueMap) { CreatureTrait trait = new CreatureTrait(keyval.Key); var control = new UcGrangerTraitValueEditBox() { Trait = trait, Value = keyval.Value, ReadOnly = currentTraitValueMap.ReadOnly }; flowLayoutPanel1.Controls.Add(control); control.TraitValueChanged += control_TraitValueChanged; } } }
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; } } }
private void buttonOK_Click(object sender, EventArgs e) { if (!ValidateCreatureIdentity()) { this.DialogResult = System.Windows.Forms.DialogResult.None; } else { try { if (OpMode == CreatureViewEditOpType.New) { var newEntity = new CreatureEntity() { Id = CreatureEntity.GenerateNewCreatureId(context) }; creature = new Creature(mainForm, newEntity, context, creatureColorDefinitions); } List <CreatureTrait> traitlist = new List <CreatureTrait>(); foreach (var item in checkedListBoxTraits.CheckedItems) { try { traitlist.Add(CreatureTrait.FromWurmTextRepr(item.ToString())); } catch (Exception _e) { logger.Error(_e, "failed to create creature trait from text:" + item.ToString()); } } var traitlistArray = traitlist.ToArray(); creature.Name = textBoxName.Text.Trim(); creature.Father = comboBoxFather.Text.Trim(); creature.Mother = comboBoxMother.Text.Trim(); creature.TakenCareOfBy = textBoxCaredForBy.Text.Trim(); creature.BrandedFor = textBoxBrandedFor.Text.Trim(); creature.Traits = traitlistArray; creature.TraitsInspectSkill = (float)numericUpDownAHskill.Value; float traitSkill = CreatureTrait.GetMinSkillForTraits(traitlistArray, checkBoxEpic.Checked); if (creature.TraitsInspectSkill < traitSkill) { creature.TraitsInspectSkill = traitSkill; } creature.EpicCurve = checkBoxEpic.Checked; creature.Comments = textBoxComment.Text; creature.IsMale = radioButtonMale.Checked; creature.Color = creatureColorDefinitions.GetForId(comboBoxColor.Text); creature.Age = CreatureAge.CreateAgeFromEnumString(comboBoxAge.Text); creature.NotInMoodUntil = dateTimePickerBred.Value; creature.GroomedOn = dateTimePickerGroomed.Value; creature.PregnantUntil = dateTimePickerPregnant.Value; creature.BirthDate = dateTimePickerBirthDate.Value; creature.SetTag("diseased", checkBoxDiseased.Checked); creature.SetTag("dead", checkBoxDead.Checked); creature.SetTag("sold", checkBoxSold.Checked); creature.ServerName = comboBoxServerName.Text.Trim(); if (OpMode == CreatureViewEditOpType.New) { creature.Herd = herdId; context.InsertCreature(creature.Entity); } else { context.SubmitChanges(); } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception _e) { logger.Error(_e, "problem while updating database, op: " + OpMode); 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; } } }
public override BreedingEvalResults?Evaluate(Creature creature1, Creature creature2, TraitValuator valuator) { if (creature1 == creature2) { return(null); } BreedingEvalResults results = new BreedingEvalResults(); var allPossibleTraits = CreatureTrait.GetAllPossibleTraits(); var traits1 = creature1.Traits; var traits2 = creature2.Traits; var concatTraits = traits1.Concat <CreatureTrait>(traits2).ToArray(); var distinctConcatTraits = concatTraits.Distinct().ToArray(); if (creature1.IsMale == creature2.IsMale) { results.Ignored = true; } if (options.IgnoreNotInMood) { if (creature1.NotInMood || creature2.NotInMood) { results.Ignored = true; } } if (options.IgnorePregnant) { if (creature1.Pregnant || creature2.Pregnant) { results.Ignored = true; } } if (options.IgnoreRecentlyPregnant) { if (creature1.PregnantInLast24H || creature2.PregnantInLast24H) { results.Ignored = true; } } if (options.IgnoreOtherHerds) { if (creature1.Herd != creature2.Herd) { results.Ignored = true; } } if (options.IgnorePairedCreatures) { if (creature1.HasMate() || creature2.HasMate()) { results.Ignored = true; } } if (options.IgnoreSold) { if (creature1.CheckTag("sold") || creature2.CheckTag("sold")) { results.Ignored = true; } } if (options.IgnoreDead) { if (creature1.CheckTag("dead") || creature2.CheckTag("dead")) { results.Ignored = true; } } if (options.IgnoreFoals) { if ((creature1.IsFoal() && !options.AgeIgnoreOnlyOtherCreatures) || creature2.IsFoal()) { results.Ignored = true; } } if (options.IgnoreYoung) { if (((creature1.Age.CreatureAgeId == CreatureAgeId.Young) && !options.AgeIgnoreOnlyOtherCreatures) || creature2.Age.CreatureAgeId == CreatureAgeId.Young) { results.Ignored = true; } } if (options.IgnoreAdolescent) { if (((creature1.Age.CreatureAgeId == CreatureAgeId.Adolescent) && !options.AgeIgnoreOnlyOtherCreatures) || creature2.Age.CreatureAgeId == CreatureAgeId.Adolescent) { results.Ignored = true; } } if (options.ExcludeExactAgeEnabled) { if (DateTime.Now - creature1.BirthDate < options.ExcludeExactAgeValue || DateTime.Now - creature2.BirthDate < options.ExcludeExactAgeValue) { results.Ignored = true; } } if (creature1.IsInbreedWith(creature2)) { if (options.DiscardOnInbreeding) { results.Discarded = true; } else { var potentialBadTraits = CreatureTrait.GetInbreedBadTraits().Where(x => !distinctConcatTraits.Contains(x)).ToArray(); double sum = 0; foreach (var trait in potentialBadTraits) { sum += trait.GetTraitValue(valuator); } sum /= potentialBadTraits.Length; sum *= options.InbreedingPenaltyWeight * 2; results.Value += sum; } } if (options.DiscardOnAnyNegativeTraits) { if (creature2.Traits.Any(x => x.GetTraitValue(valuator) < 0)) { results.Discarded = true; } } if (results.Discarded != true && results.Ignored != true) { Dictionary <CreatureTrait, int> uniqueTraitCounter = new Dictionary <CreatureTrait, int>(); foreach (var trait in concatTraits) { if (uniqueTraitCounter.ContainsKey(trait)) { uniqueTraitCounter[trait] += 1; } else { uniqueTraitCounter[trait] = 1; } var traitval = trait.GetTraitValue(valuator); double result = 0; if (traitval < 0) { result += traitval * options.BadTraitWeight; } else if (traitval > 0) { result += traitval; } results.Value += result; } if (options.PreferUniqueTraits) { foreach (var keyval in uniqueTraitCounter) { if (keyval.Value == 1) { var traitval = keyval.Key.GetTraitValue(valuator); if (traitval > 0) { results.Value += (traitval * options.UniqueTraitWeight) - traitval; } } } } if (options.IncludePotentialValue) { foreach (var trait in allPossibleTraits) { double result = 0; result += EvaluatePotentialValue(creature1, valuator, trait); result += EvaluatePotentialValue(creature2, valuator, trait); results.Value += result; } } if (results.Value > 0) { var h1ColVal = options.GetValueForColor(creature1.Color); var h2ColVal = options.GetValueForColor(creature2.Color); var colValAdj = (h1ColVal + h2ColVal) * 0.5f; results.Value *= colValAdj; } } return(results); }
private double EvaluatePotentialValue(Creature creature, TraitValuator valuator, CreatureTrait trait) { double result = 0; if (trait.IsUnknownForThisCreature(creature)) { var traitval = trait.GetTraitValue(valuator); if (traitval > 0) { result += traitval * options.PotentialValuePositiveWeight; } else if (traitval < 0) { result += traitval * options.PotentialValueNegativeWeight; } } return(result); }
public void HandleLogEvent(string line) { // Smile emote triggers processing of new creature. // If previous processing is still active, it should be finalized. if (line.StartsWith("You smile at", StringComparison.Ordinal)) { debugLogger.Log("smile cond: " + line); AttemptToStartProcessing(line); } // While processing creature, log events are parsed and valid data buffered into the current buffer. if (isProcessing) { //[20:23:18] It has fleeter movement than normal. It has a strong body. It has lightning movement. It can carry more than average. It seems overly aggressive. if (!verifyList.Traits && CreatureTrait.CanThisBeTraitLogMessage(line)) { debugLogger.Log("found maybe trait line: " + line); var extractedTraits = GrangerHelpers.ParseTraitsFromLine(line); foreach (var trait in extractedTraits) { debugLogger.Log("found trait: " + trait); creatureBuffer.Traits.Add(trait); verifyList.Traits = true; } debugLogger.Log("trait parsing finished"); if (creatureBuffer.InspectSkill == 0 && creatureBuffer.Traits.Count > 0) { var message = String.Format( "{0} ({1}) can see traits, but Granger found no Animal Husbandry skill for him. Is this a bug? Creature will be added anyway.", playerMan.PlayerName, creatureBuffer.Server); logger.Error(message); trayPopups.Schedule(message, "POSSIBLE PROBLEM", 5000); } } //[20:23:18] She is very strong and has a good reserve of fat. if (line.StartsWith("He", StringComparison.Ordinal) && !verifyList.Gender) { creatureBuffer.IsMale = true; verifyList.Gender = true; debugLogger.Log("creature set to male"); } if (line.StartsWith("She", StringComparison.Ordinal) && !verifyList.Gender) { creatureBuffer.IsMale = false; verifyList.Gender = true; debugLogger.Log("creature set to female"); } //[22:34:28] His mother is the old fat Painthop. His father is the venerable fat Starkclip. //[22:34:28] Her mother is the old fat Painthop. Her father is the venerable fat Starkclip. if (IsParentIdentifyingLine(line) && !verifyList.Parents) { debugLogger.Log("found maybe parents line"); Match motherMatch = ParseMother(line); if (motherMatch.Success) { string mother = motherMatch.Groups["g"].Value; mother = GrangerHelpers.ExtractCreatureName(mother); creatureBuffer.MotherName = mother; debugLogger.Log("mother set to: " + mother); } Match fatherMatch = ParseFather(line); if (fatherMatch.Success) { string father = fatherMatch.Groups["g"].Value; father = GrangerHelpers.ExtractCreatureName(father); creatureBuffer.FatherName = father; debugLogger.Log("father set to: " + father); } verifyList.Parents = true; debugLogger.Log("finished parsing parents line"); } //[20:23:18] It is being taken care of by Darkprincevale. if (line.Contains("It is being taken care") && !verifyList.CaredBy) { debugLogger.Log("found maybe take care of line"); Match caredby = Regex.Match(line, @"care of by (\w+)"); if (caredby.Success) { creatureBuffer.CaredBy = caredby.Groups[1].Value; debugLogger.Log("cared set to: " + creatureBuffer.CaredBy); } verifyList.CaredBy = true; debugLogger.Log("finished parsing care line"); } //[17:11:42] She will deliver in about 4 days. //[17:11:42] She will deliver in about 1 day. if (line.Contains("She will deliver in") && !verifyList.Pregnant) { debugLogger.Log("found maybe pregnant line"); Match match = Regex.Match(line, @"She will deliver in about (\d+)"); if (match.Success) { double length = Double.Parse(match.Groups[1].Value) + 1D; creatureBuffer.PregnantUntil = DateTime.Now + TimeSpan.FromDays(length); debugLogger.Log("found creature to be pregnant, estimated delivery: " + creatureBuffer.PregnantUntil); } verifyList.Pregnant = true; debugLogger.Log("finished parsing pregnant line"); } //[20:58:26] A foal skips around here merrily //[01:59:09] This calf looks happy and free. if ((line.Contains("A foal skips around here merrily") || line.Contains("This calf looks happy and free") || line.Contains("A small cuddly ball of fluff")) && !verifyList.Foalization) { debugLogger.Log("applying foalization to the creature"); try { creatureBuffer.Age = CreatureAge.Foalize(creatureBuffer.Age); verifyList.Foalization = true; } catch (InvalidOperationException exception) { logger.Error(exception, "The creature appears to be a foal, but has invalid age for a foal!"); } } //[20:57:27] It has been branded by and belongs to the settlement of Silver Hill Estate. if (line.Contains("It has been branded") && !verifyList.Branding) { debugLogger.Log("found maybe branding line"); Match match = Regex.Match(line, @"belongs to the settlement of (.+)\."); if (match.Success) { string settlementName = match.Groups[1].Value; creatureBuffer.BrandedBy = settlementName; debugLogger.Log("found creature to be branded for: " + creatureBuffer.BrandedBy); verifyList.Branding = true; } } //[11:43:35] Its colour is ash. if (line.Contains("Its colour is")) { debugLogger.Log("found maybe color line"); Match match = Regex.Match(line, @"Its colour is (.+)\."); if (match.Success) { string colorName = match.Groups[1].Value; creatureBuffer.ColorWurmLogText = colorName; debugLogger.Log("found creature to have color: " + creatureBuffer.ColorWurmLogText); verifyList.Branding = true; } } } }
bool TryUpdateExistingCreature(CreatureEntity[] herdsFinds) { if (herdsFinds.Length == 1) { CreatureEntity oldCreature = herdsFinds[0]; bool sanityFail = false; #region SANITY_CHECKS string sanityFailReason = null; // Verifying if creature parents match. // Wurm trivia: // If a creature has a mother name or a father name, these names cannot change. // However when parent dies, Wurm loses reference and the name is no longer in the log event! // father checks if (String.IsNullOrEmpty(oldCreature.FatherName) && !String.IsNullOrEmpty(creatureBuffer.FatherName)) { sanityFail = true; if (sanityFailReason == null) { sanityFailReason = "Old father was blank but new data has a father name"; } } if (!String.IsNullOrEmpty(oldCreature.FatherName) && !String.IsNullOrEmpty(creatureBuffer.FatherName) && oldCreature.FatherName != creatureBuffer.FatherName) { sanityFail = true; if (sanityFailReason == null) { sanityFailReason = "Old data father name was different than new father name"; } } // mother checks if (String.IsNullOrEmpty(oldCreature.MotherName) && !String.IsNullOrEmpty(creatureBuffer.MotherName)) { sanityFail = true; if (sanityFailReason == null) { sanityFailReason = "Old mother was blank but new data has a mother name"; } } if (!String.IsNullOrEmpty(oldCreature.MotherName) && !String.IsNullOrEmpty(creatureBuffer.MotherName) && oldCreature.MotherName != creatureBuffer.MotherName) { sanityFail = true; if (sanityFailReason == null) { sanityFailReason = "Old data mother name was different than new mother name"; } } // Verifying if creature traits match. // Have to take into account current AH level of the player, // as well as the level this creature has been previously inspected at. if (oldCreature.TraitsInspectedAtSkill.HasValue) { // Skip this check if creature had genesis cast within last 1 hour. // Genesis clears some negative traits. debugLogger.Log(string.Format("Checking creature for Genesis cast (creature name: {0}", creatureBuffer.Name)); if (!parentModule.Settings.HasGenesisCast(creatureBuffer.Name)) { debugLogger.Log("No genesis cast found"); var lowskill = Math.Min(oldCreature.TraitsInspectedAtSkill.Value, creatureBuffer.InspectSkill); CreatureTrait[] certainTraits = CreatureTrait.GetTraitsUpToSkillLevel(lowskill, oldCreature.EpicCurve ?? false); var oldCreatureTraits = oldCreature.Traits.ToArray(); var newCreatureTraits = creatureBuffer.Traits.ToArray(); foreach (var trait in certainTraits) { if (oldCreatureTraits.Contains(trait) != newCreatureTraits.Contains(trait)) { sanityFail = true; if (sanityFailReason == null) { sanityFailReason = "Trait mismatch below inspect skill treshhold (" + lowskill + "): " + trait.ToCompactString(); } break; } } } else { debugLogger.Log("Genesis cast found, skipping trait sanity check"); parentModule.Settings.RemoveGenesisCast(creatureBuffer.Name); debugLogger.Log(string.Format("Removed cached genesis cast data for {0}", creatureBuffer.Name)); } } #endregion if (sanityFail) { debugLogger.Log("sanity check failed for creature update: " + oldCreature + ". Reason: " + sanityFailReason); trayPopups.Schedule("There was data mismatch when trying to update creature, reason: " + sanityFailReason, "ERROR AT UPDATE CREATURE", 8000); } else { oldCreature.Age = creatureBuffer.Age; oldCreature.TakenCareOfBy = creatureBuffer.CaredBy; oldCreature.BrandedFor = creatureBuffer.BrandedBy; if (creatureBuffer.HasFatherName) { oldCreature.FatherName = creatureBuffer.FatherName; } if (creatureBuffer.HasMotherName) { oldCreature.MotherName = creatureBuffer.MotherName; } oldCreature.ServerName = creatureBuffer.Server.ServerName.Original; if (oldCreature.TraitsInspectedAtSkill <= creatureBuffer.InspectSkill || creatureBuffer.InspectSkill > CreatureTrait.GetFullTraitVisibilityCap(oldCreature.EpicCurve ?? false)) { oldCreature.Traits = creatureBuffer.Traits; oldCreature.TraitsInspectedAtSkill = creatureBuffer.InspectSkill; } else { debugLogger.Log("old creature data had more accurate trait info, skipping"); } oldCreature.SetTag("dead", false); oldCreature.SetSecondaryInfoTag(creatureBuffer.SecondaryInfo); oldCreature.IsMale = creatureBuffer.IsMale; oldCreature.PregnantUntil = creatureBuffer.PregnantUntil; if (oldCreature.Name != creatureBuffer.Name) { if (NameIsUniqueInHerd(creatureBuffer.Name, oldCreature.Herd)) { trayPopups.Schedule(String.Format("Updating name of creature {0} to {1}", oldCreature.Name, creatureBuffer.Name), "CREATURE NAME UPDATE"); oldCreature.Name = creatureBuffer.Name; } else { trayPopups.Schedule(String.Format("Could not update name of creature {0} to {1}, " + "because herd already has a creature with such name.", oldCreature.Name, creatureBuffer.Name), "WARNING"); } } oldCreature.SmilexamineLastDate = DateTime.Now; if (creatureBuffer.HasColorWurmLogText && grangerSettings.UpdateCreatureColorOnSmilexamines) { oldCreature.CreatureColorId = creatureColorDefinitions.GetColorIdByWurmLogText(creatureBuffer.ColorWurmLogText); } context.SubmitChanges(); debugLogger.Log("successfully updated creature in db"); trayPopups.Schedule(String.Format("Updated creature: {0}", oldCreature), "CREATURE UPDATED"); } debugLogger.Log("processor buffer cleared"); return(true); } return(false); }
int GetPotentialValueForCreature(Creature creature, bool positive) { var missingTraits = CreatureTrait.GetMissingTraits(creature.Traits, creature.TraitsInspectSkill, creature.EpicCurve); return(Evaluate(missingTraits, positive)); }
private void Start() { aggression = new CreatureTrait(0f, CREATURE_TRAIT_FALLOFF); lastTarget = GetComponent <LastTarget>(); }