Exemplo n.º 1
0
        private void ObjectSelected(SimulationEvent ev)
        {
            if (((StringValue)ev["UserID"]).value != MyDM)
            {
                return;
            }
            String objectID = ((StringValue)ev["ObjectID"]).value;

            _mostRecentlyClickedObject = objectID;
            DDDObj d = GetFromAllObjects(objectID);

            if (d == null)
            {
                return;
            }
            String tag = "unknown";

            if (d.Name != String.Empty)
            {
                tag = d.Name;
            }
            SimulationEvent evnt = new SimulationEvent();

            evnt.eventType = "UpdateTag";
            evnt.parameters.Add("Time", DataValueFactory.BuildInteger(time));
            evnt.parameters.Add("UnitID", DataValueFactory.BuildString(objectID));
            evnt.parameters.Add("Tag", DataValueFactory.BuildString(tag));
            List <String> dms = new List <string>();

            if (MyDM.Contains("Individ"))
            {
                dms.Add(MyDM);
            }
            else
            {
                dms.Add("BAMS DM");
                dms.Add("Firescout DM");
            }
            evnt.parameters.Add("TeamMembers", DataValueFactory.BuildStringList(dms));
            DDDConnection.SendSimEvent(evnt);//.SendObjectAttributeUpdateEvent(objectID, "InitialTag", DataValueFactory.BuildString(tag));
        }
Exemplo n.º 2
0
        private void ChangeObjectVulnerability(VulnerabilityValue newVulnerabilitySet, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }

            VulnerabilityValue previousVulnerabilityValue = obj["Vulnerability"].GetDataValue() as VulnerabilityValue;
            List <string>      previousVulnerabilityNames = new List <string>();

            foreach (VulnerabilityValue.Transition tr in previousVulnerabilityValue.transitions)
            {
                foreach (VulnerabilityValue.TransitionCondition tc in tr.conditions)
                {
                    if (!previousVulnerabilityNames.Contains(tc.capability))
                    {
                        previousVulnerabilityNames.Add(tc.capability);
                    }
                }
            }
            List <string> newVulnerabilityNames = new List <string>();

            foreach (VulnerabilityValue.Transition tr in newVulnerabilitySet.transitions)
            {
                foreach (VulnerabilityValue.TransitionCondition tc in tr.conditions)
                {
                    if (!newVulnerabilityNames.Contains(tc.capability))
                    {
                        newVulnerabilityNames.Add(tc.capability);
                    }
                }
            }
            List <string> missingVulnerabilityNames = new List <string>();

            foreach (string capName in previousVulnerabilityNames)
            {
                if (!newVulnerabilityNames.Contains(capName))
                {
                    if (!missingVulnerabilityNames.Contains(capName))
                    {
                        missingVulnerabilityNames.Add(capName);
                    }
                }
            }
            List <string> attackerList        = ((StringListValue)obj["AttackerList"].GetDataValue()).strings;
            List <string> updatedAttackerList = new List <string>();

            foreach (string attacker in attackerList)
            {
                //get attacker's current attacks
                AttackCollectionValue currentAttacks = objectProxies[attacker]["CurrentAttacks"].GetDataValue() as AttackCollectionValue;
                List <AttackCollectionValue.AttackValue> attacksOnTarget = currentAttacks.GetCurrentAttacksOnTarget(objectID);
                List <AttackCollectionValue.AttackValue> allAttacks      = currentAttacks.GetCurrentAttacks();

                //foreach attack
                foreach (AttackCollectionValue.AttackValue av in attacksOnTarget)
                {
                    if (missingVulnerabilityNames.Contains(av.capabilityName))
                    {
//if this attack is targetting my object with a capability that's in missingVulnerabilities, cancel the attack
                        CancelAttack(attacker, objectID, av.capabilityName);
                    }
                }
                if (allAttacks.Count > attacksOnTarget.Count)
                {
                    updatedAttackerList.Add(attacker);
                }
            }
            obj["AttackerList"].SetDataValue(DataValueFactory.BuildStringList(updatedAttackerList));
            obj["Vulnerability"].SetDataValue(newVulnerabilitySet);
            previousVulnerabilityNames.Clear();
            newVulnerabilityNames.Clear();
        }