Ejemplo n.º 1
0
        private static void appendAttributes(StringBuilder sb, StixDataEntityBase entity, bool showDescription)
        {
            var hasAttributes = entity.GetType() == typeof(AttackPattern) || entity.GetType() == typeof(CourseOfAction);

            if (!hasAttributes)
            {
                return;
            }

            if (showDescription)
            {
                sb.AppendLine("<i><size=140%>Attributes</size></i>");
                sb.AppendLine();
            }

            if (entity.GetType() == typeof(AttackPattern))
            {
                appendAttackPatternAttributes(sb, (AttackPattern)entity);
            }
            else if (entity.GetType() == typeof(CourseOfAction))
            {
                appendCourseOfActionAttributes(sb, (CourseOfAction)entity);
            }
            sb.AppendLine("<indent=0>");
        }
Ejemplo n.º 2
0
 private static void appendSources(StringBuilder sb, StixDataEntityBase entity)
 {
     sb.Append("<i><size=140%>Sources</size></i>");
     if (entity.external_references.Any((e) => e.description == null))
     {
         sb.AppendLine("<space=25em><color=#848484><b>Right-click to open all in browser</b></color>");
     }
     else
     {
         sb.AppendLine();
     }
     sb.AppendLine();
     foreach (var externalReference in entity.external_references)
     {
         if (externalReference.description == null)
         {
             sb.AppendFormat(
                 "<indent=2em>\U00002014<indent=7em><b>{0}</b> (from <color=#96c8e9>{1}</color>)",
                 externalReference.id,
                 externalReference.url.ExtractUrlDomain());
         }
         else
         {
             sb.AppendFormat("<i><b><indent=7em>{0}</b></i>", externalReference.description);
         }
         sb.AppendLine("<indent=0>");
     }
 }
Ejemplo n.º 3
0
 public static void OpenExternalReferences(StixDataEntityBase entity)
 {
     ExternalReference[] references = getExternalReferences(entity);
     if (references.Any())
     {
         foreach (var url in references.Select((e) => e.url))
         {
             if (!GameManager.IsQuickPaused)
             {
                 HelperObjects.PauseMenu.Pause();
             }
             Application.OpenURL(url);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets all relationships from the game state that relate to this <see cref="StixDataEntityBase"/>.
        /// </summary>
        /// <param name="entity">The <see cref="StixDataEntityBase"/> to get relationships for.</param>
        /// <param name="whereSource">Include relationships where the <see cref="StixDataEntityBase"/> is the source.</param>
        /// <param name="whereTarget">Include relationships where the <see cref="StixDataEntityBase"/> is the target.</param>
        /// <returns>Relationships related to this <see cref="StixDataEntityBase"/> in the current game state.</returns>
        /// <exception cref="NullReferenceException">Throws an exception if the state hasn't been initialized.</exception>
        public static Relationship[] GetRelationships(
            this StixDataEntityBase entity,
            bool whereSource = true,
            bool whereTarget = true)
        {
            if (State.I.GameEntities == null)
            {
                throw new NullReferenceException("The state has not been initialized with game entities yet.");
            }

            return(State.I.GameEntities.SROs.relationships.Where(
                       (r) => whereSource && r.source_ref == entity.id ||
                       whereTarget && r.target_ref == entity.id)
                   .ToArray());
        }
Ejemplo n.º 5
0
        private static void appendRelationships(StringBuilder sb, StixDataEntityBase entity)
        {
            sb.AppendLine("<i><size=140%>Relationships</size></i>");
            sb.AppendLine();

            if (entity.GetType() == typeof(Asset))
            {
                var asset = (Asset)entity;

                // Is targeted by attack patterns
                var targetedBy = State.I.GameEntities.SDOs.attack_patterns.Where(
                    (aP) => aP.custom.activation_zone.categories.Any(
                        (c) => c == asset.custom.category));
                var targetedByStrings = targetedBy.Select((aP) => aP.name);
                sb.AppendLine(buildAttributeText("Targeted by", targetedByStrings.Join("; ")));
            }
            else if (entity.GetType() == typeof(AttackPattern))
            {
                var attackPattern = (AttackPattern)entity;

                // Targets assets
                var targets =
                    attackPattern.custom.activation_zone.categories.Select(EnumHelper.GetEnumMemberAttributeValue);
                sb.AppendLine(buildAttributeText("Targets", targets.Join("; ")));

                // Mitigated by course of actions
                var mitigatedBy = State.I.GameEntities.SDOs.course_of_actions.Where(
                    (c) => attackPattern.MitigatedByCategories.Contains(c.custom.category));
                var mitigatedByStrings = mitigatedBy.Select((c) => c.custom.mitigation);
                sb.AppendLine(buildAttributeText("Mitigated by", mitigatedByStrings.Join("; ")));
            }
            else if (entity.GetType() == typeof(CourseOfAction))
            {
                var courseOfAction = (CourseOfAction)entity;

                // Mitigates attack patterns
                var mitigates = State.I.GameEntities.SDOs.attack_patterns.Where(
                    (aP) => aP.MitigatedByCategories.Contains(courseOfAction.custom.category));
                var mitigatesStrings = mitigates.Select((c) => c.name);
                sb.AppendLine(buildAttributeText("Mitigates", mitigatesStrings.Join("; ")));
            }
            sb.AppendLine("<indent=0>");
        }
Ejemplo n.º 6
0
        public static bool AddReferencesAsAction(StixDataEntityBase entity, ClickableBehaviour clickableBehaviour)
        {
            ExternalReference[] references = getExternalReferences(entity);
            if (references.Any())
            {
                clickableBehaviour.SecondaryAction = () => {
                    foreach (var url in references.Select((e) => e.url))
                    {
                        if (!GameManager.IsQuickPaused)
                        {
                            HelperObjects.PauseMenu.Pause();
                        }
                        Application.OpenURL(url);
                    }
                };

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        public static string BuildStixDataEntityDescription(
            StixDataEntityBase entity,
            bool showDescription = true,
            bool showSources     = true)
        {
            var sb = new StringBuilder();

            if (showDescription)
            {
                sb.AppendLine(entity.FullDescription);
                sb.AppendLine();
            }
            appendAttributes(sb, entity, showDescription);
            appendRelationships(sb, entity);
            if (showSources)
            {
                appendSources(sb, entity);
            }

            return(sb.ToString());
        }
Ejemplo n.º 8
0
 private static ExternalReference[] getExternalReferences(StixDataEntityBase entity)
 {
     return(entity.external_references.Where((e) => e.description == null).ToArray());
 }
Ejemplo n.º 9
0
 public static bool HasExternalReferences(StixDataEntityBase entity)
 {
     return(entity.external_references.Any((e) => e.description == null));
 }
Ejemplo n.º 10
0
        public static bool RelatedAsSourceTo(this StixDataEntityBase entity, StixDataEntityBase otherEntity)
        {
            IEnumerable <Relationship> relationships = entity.GetRelationships(true, false);

            return(relationships.Any((r) => r.target_ref == otherEntity.id));
        }