Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        void VerifyAndApplyProcessing()
        {
            if (creatureBuffer != null)
            {
                try
                {
                    telemetry.TrackEvent("Granger: Smilexamine");

                    debugLogger.Log("finishing processing creature: " + creatureBuffer.Name);

                    if (verifyList.IsValid)
                    {
                        debugLogger.Log("Creature data is valid");

                        var selectedHerds = GetSelectedHerds();

                        var herdsFinds = GetHerdsFinds(selectedHerds, creatureBuffer, checkInnerName: false);
                        if (herdsFinds.Length == 0 && !parentModule.Settings.DoNotMatchCreaturesByBrandName)
                        {
                            herdsFinds = GetHerdsFinds(selectedHerds, creatureBuffer, checkInnerName: true);
                        }
                        var selectedHerdsFinds = herdsFinds;

                        bool allHerdSearch = false;
                        if (herdsFinds.Length == 0 &&
                            parentModule.Settings.DoNotBlockDataUpdateUnlessMultiplesInEntireDb)
                        {
                            allHerdSearch = true;
                            string[] allHerds = GetAllHerds();

                            herdsFinds = GetHerdsFinds(allHerds, creatureBuffer, checkInnerName: false);
                            if (herdsFinds.Length == 0 && !parentModule.Settings.DoNotMatchCreaturesByBrandName)
                            {
                                herdsFinds = GetHerdsFinds(allHerds, creatureBuffer, checkInnerName: true);
                            }
                        }

                        if (!TryUpdateExistingCreature(herdsFinds))
                        {
                            if (!TryAddNewCreature(selectedHerds, selectedHerdsFinds))
                            {
                                AnalyzeWhyNothingHappened(herdsFinds, allHerdSearch, selectedHerds);
                            }
                        }
                    }
                    else
                    {
                        debugLogger.Log("creature data was invalid, data: " + GetVerifyListData(verifyList));
                    }
                }
                finally
                {
                    //clear the buffer
                    creatureBuffer = null;
                    debugLogger.Log("processor buffer cleared");
                }
            }
        }
Ejemplo n.º 3
0
        private CreatureEntity[] GetHerdsFinds(IEnumerable <string> viableHerds, CreatureBuffer creatureBuffer, bool checkInnerName)
        {
            IEnumerable <CreatureEntity> query;

            if (checkInnerName)
            {
                var bufferInnerNameInfo = Creature.GetInnerNameInfo(creatureBuffer.Name);
                if (!bufferInnerNameInfo.HasInnerName)
                {
                    return(new CreatureEntity[0]);
                }
                query = context.Creatures
                        .Where(x =>
                {
                    var iteratedInnerNameInfo = Creature.GetInnerNameInfo(x.Name);
                    if (!iteratedInnerNameInfo.HasInnerName)
                    {
                        return(false);
                    }
                    return(iteratedInnerNameInfo.InnerName == bufferInnerNameInfo.InnerName &&
                           viableHerds.Contains(x.Herd));
                });
            }
            else
            {
                query = context.Creatures
                        .Where(x =>
                               x.Name == creatureBuffer.Name &&
                               viableHerds.Contains(x.Herd));
            }

            if (parentModule.Settings.UseServerNameAsCreatureIdComponent)
            {
                query =
                    query.Where(
                        entity =>
                        string.IsNullOrEmpty(entity.ServerName) ||
                        creatureBuffer.Server.ServerName.Matches(entity.ServerName));
            }
            return(query.ToArray());
        }
Ejemplo n.º 4
0
        void AttemptToStartProcessing(string line)
        {
            debugLogger.Log("attempting to start processing creature due to line: " + line);
            // Apply previous processing, if still active.
            VerifyAndApplyProcessing();

            try
            {
                debugLogger.Log("extracting object name");

                // [20:48:42] You smile at the Adolescent diseased Mountainheart.
                // This regex preserves condition from before WO Rift update, where determiner was not present.
                // This is kept, because WU servers cannot be guaranteed to have been updated by their administrators.
                Match match = Regex.Match(line,
                                          @"You smile at (a|an|the) (?<g>.+)\.|You smile at (?<g>.+)\.",
                                          RegexOptions.IgnoreCase | RegexOptions.Compiled);
                string objectNameWithPrefixes = string.Empty;
                if (match.Success)
                {
                    objectNameWithPrefixes = match.Groups["g"].Value;
                }

                if (GrangerHelpers.HasAgeInName(objectNameWithPrefixes, ignoreCase: true))
                {
                    debugLogger.Log("object assumed to be a creature");
                    var server = playerMan.CurrentServer;
                    var skill  = playerMan.CurrentServerAhSkill;

                    if (grangerSettings.RequireServerAndSkillToBeKnownForSmilexamine &&
                        (server == null || skill == null))
                    {
                        trayPopups.Schedule(
                            "Server or AH skill level unknown for " + playerMan.PlayerName +
                            ". If WA was just started, give it a few seconds. (This check can be disabled in Granger options)", "CAN'T PROCESS CREATURE", 5000);
                        debugLogger.Log(string.Format(
                                            "processing creature cancelled, AH skill or server group unknown for player {0} (skill: {1} ; server: {2}",
                                            playerMan.PlayerName, skill, server));
                    }
                    else
                    {
                        debugLogger.Log("building new creature object and moving to processor");

                        isProcessing        = true;
                        startedProcessingOn = DateTime.Now;
                        verifyList          = new ValidationList();
                        creatureBuffer      = new CreatureBuffer
                        {
                            Name         = GrangerHelpers.ExtractCreatureName(objectNameWithPrefixes),
                            Age          = GrangerHelpers.ExtractCreatureAge(objectNameWithPrefixes),
                            Server       = server,
                            InspectSkill = skill ?? 0,
                        };

                        var fat = GrangerHelpers.TryParseCreatureNameIfLineContainsFat(objectNameWithPrefixes);
                        if (fat != null)
                        {
                            creatureBuffer.SecondaryInfo = CreatureEntity.SecondaryInfoTag.Fat;
                        }

                        var starving = GrangerHelpers.TryParseCreatureNameIfLineContainsStarving(objectNameWithPrefixes);
                        if (starving != null)
                        {
                            creatureBuffer.SecondaryInfo = CreatureEntity.SecondaryInfoTag.Starving;
                        }

                        var diseased = GrangerHelpers.TryParseCreatureNameIfLineContainsDiseased(objectNameWithPrefixes);
                        if (diseased != null)
                        {
                            creatureBuffer.SecondaryInfo = CreatureEntity.SecondaryInfoTag.Diseased;
                        }

                        verifyList.Name = true;
                        debugLogger.Log("finished building");
                    }
                }
                else
                {
                    debugLogger.Log(objectNameWithPrefixes + " was not recognized as a named creature.");
                }
            }
            catch (Exception exception)
            {
                debugLogger.Log("! Granger: error while BeginProcessing, event: " + line, true, exception);
            }
        }