Пример #1
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

            SimulationObjectProxy prox = null;

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }

            //Set State info?
            //AD: This is kind of a quick fix.  Gabe would have a better idea on a more permanent
            //solution.
            DataValue stv = new DataValue();

            stv = prox["StateTable"].GetDataValue();
            Dictionary <string, DataValue> tempDict = ((StateTableValue)stv).states;

            tempDict = ((AttributeCollectionValue)tempDict[((StringValue)atts["State"]).value]).attributes;

            foreach (KeyValuePair <String, DataValue> kvp in tempDict)
            {
                if (!atts.attributes.ContainsKey(kvp.Key))
                {//if att exists in atts, it should NOT overwrite reveal attributes.
                    atts.attributes.Add(kvp.Key, kvp.Value);
                }
            }
            ////AD
            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                    if (attname == "Sensors")
                    {
                        double           maxSensor = -1.0;
                        SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                        foreach (SensorValue sv in sav.sensors)
                        {
                            maxSensor = Math.Max(maxSensor, sv.maxRange);
                        }
                        if (maxSensor >= 0)
                        {
                            ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                        }
                    }
                }
            }
            Dictionary <string, DataValue> x = new Dictionary <string, DataValue>();

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();

            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));
        }
Пример #2
0
        private void StateChange(SimulationEvent e)
        {
            string id = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy prox = null; // objectProxies[id];

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }

            string newState = ((StringValue)e["NewState"]).value;

            DataValue dv = prox["StateTable"].GetDataValue();

            if (((StateTableValue)dv).states.ContainsKey(newState))
            {
                DataValue dv2 = ((StateTableValue)dv).states[newState];
                //AD: Added state to attributes
                DataValue temp = new StringValue();
                ((StringValue)temp).value = newState;
                ((AttributeCollectionValue)dv2).attributes["State"] = temp;
                //AD
                foreach (string attname in ((AttributeCollectionValue)dv2).attributes.Keys)
                {
                    if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                    {
                        prox[attname].SetDataValue(((AttributeCollectionValue)dv2).attributes[attname]);
                        if (attname == "Sensors")
                        {
                            double           maxSensor = -1.0;
                            SensorArrayValue sav       = ((AttributeCollectionValue)dv2).attributes[attname] as SensorArrayValue;
                            foreach (SensorValue sv in sav.sensors)
                            {
                                maxSensor = Math.Max(maxSensor, sv.maxRange);
                            }
                            if (maxSensor >= 0)
                            {
                                ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                            }
                        }
                    }
                }
            }
            CustomAttributesValue cav = prox["CustomAttributes"].GetDataValue() as CustomAttributesValue;

            Dictionary <string, DataValue> x = new Dictionary <string, DataValue>();

            if (cav != null)
            {
                x = cav.attributes;
            }

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();

            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));
        }
Пример #3
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record

            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary <string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);

            if (prox == null)
            {
                return;
            }
            if (!objectProxies.ContainsKey(id))
            {
                objectProxies.Add(id, prox);
            }
            else
            {
                objectProxies[id] = prox;
            }

            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

            string id2 = ((StringValue)e["ID"]).value;
            SimulationObjectProxy proxi = objectProxies[id2];

            if (proxi.GetKeys().Contains("StateTable"))
            {
                proxi["StateTable"].SetDataValue(e["StateTable"]);
            }


            if (objectProxies.ContainsKey(id2))
            {
                // initialize any object values I own.

                foreach (string attname in atts.attributes.Keys)
                {
                    if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner())
                    {
                        proxi[attname].SetDataValue(atts[attname]);
                        if (attname == "Sensors")
                        {
                            double           maxSensor = -1.0;
                            SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                            foreach (SensorValue sv in sav.sensors)
                            {
                                maxSensor = Math.Max(maxSensor, sv.maxRange);
                            }
                            if (maxSensor >= 0)
                            {
                                ObjectDistances.UpdateObjectSensorRange(id2, maxSensor);
                            }
                        }
                    }
                }
            }
        }