Example #1
0
        /// <summary>
        /// Adds an object.
        /// </summary>
        /// <param name="o"></param>
        /// <returns>The object's ID. IDs are unique within any any given object type but not across types.</returns>
        public int Add(object o)
        {
            if (o == null)
            {
                return(-1);
            }
            var type = o.GetType();

            if (!KnownTypes.ContainsKey(type.AssemblyQualifiedName))
            {
                KnownTypes.Add(type.AssemblyQualifiedName, type);
            }
            if (!KnownObjects.ContainsKey(type))
            {
                KnownObjects.Add(type, new List <object>());
            }
//			if (!KnownObjects[type].Contains(o))
            KnownObjects[type].Add(o);
            if (!KnownIDs.ContainsKey(type))
            {
                KnownIDs.Add(type, new SafeDictionary <object, int>());
            }
            var id = KnownObjects[type].Count - 1;

            KnownIDs[type].Add(o, id);
            AddProperties(type);
            return(id);
        }
Example #2
0
        /// <summary>
        /// Adds an object to the list of known objects
        /// only maintained for players
        /// </summary>
        /// <returns>true if previously an unknown object</returns>
        public bool AddKnownObject(PhysicsObj obj)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (KnownObjects.ContainsKey(obj.ID))
                {
                    return(false);
                }

                KnownObjects.Add(obj.ID, obj);

                // maintain KnownPlayers for both parties
                if (obj.IsPlayer)
                {
                    AddKnownPlayer(obj);
                }

                obj.ObjMaint.AddKnownPlayer(PhysicsObj);

                return(true);
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
 /// <summary>
 /// Is called whenever a new object appears within vision range of this Character
 /// </summary>
 public void OnEncountered(WorldObject obj)
 {
     if (obj != this)
     {
         obj.OnEncounteredBy(this);
     }
     KnownObjects.Add(obj);
 }
Example #4
0
        public void Update()
        {
            if (Owner == null || Owner.Data == null || Owner.Data.GetBody() == null)
            {
                Active = false;
                return;
            }

            bool isPlayer = Owner is Player;

            Collider2D[] hits = Physics2D.OverlapCircleAll(Owner.Data.GetBody().transform.position, VisibleRadius);

            if (isPlayer)
            {
                foreach (GameObject o in KnownObjects)
                {
                    if (o == null)
                    {
                        continue;
                    }

                    AbstractData d = o.GetData();

                    if (d != null)
                    {
                        d.IsVisibleToPlayer = false;
                    }
                }
            }

            KnownObjects.Clear();

            foreach (Collider2D h in hits)
            {
                if ("Cave Generator".Equals(h.gameObject.name) || h.gameObject.Equals(Owner.GetData().gameObject))
                {
                    continue;
                }

                if (isPlayer)
                {
                    AbstractData d = h.gameObject.GetData();

                    if (d != null)
                    {
                        d.IsVisibleToPlayer = true;
                    }
                }

                KnownObjects.Add(h.gameObject);
            }
        }
Example #5
0
        /// <summary>
        /// Adds an object to the list of known objects
        /// only maintained for players
        /// </summary>
        /// <returns>true if previously an unknown object</returns>
        public bool AddKnownObject(PhysicsObj obj)
        {
            if (KnownObjects.ContainsKey(obj.ID))
            {
                return(false);
            }

            KnownObjects.Add(obj.ID, obj);

            // maintain KnownPlayers for both parties
            if (obj.IsPlayer)
            {
                AddKnownPlayer(obj);
            }

            obj.ObjMaint.AddKnownPlayer(PhysicsObj);

            return(true);
        }
Example #6
0
 public void AddKnownObject(GameObject o)
 {
     KnownObjects.Add(o);
 }