Exemplo n.º 1
0
        public virtual void SendGObj(bool type, Packet packet, List <GObj> objects)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                var gobj = objects[i];
                lock (gobj.m_lock)
                {
                    _sightGObj obj = new _sightGObj {
                        Object = this, Seen = false
                    };
                    int idx = gobj.m_inSightGObjList.IndexOf(obj);

                    if (idx != -1)
                    {
                        if (type)
                        {
                            obj.Seen = true;
                            gobj.m_inSightGObjList[idx] = obj;
                            OnEnterVisibility(gobj);
                            gobj.OnEnterVisibility(this);
                        }
                        else if (!type)
                        {
                            gobj.m_inSightGObjList.RemoveAt(idx);
                            OnLeaveVisibility(gobj);
                            gobj.OnLeaveVisibility(this);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void SendGObj(bool type, Packet packet, GObj gobj)
        {
            lock (gobj.m_lock)
            {
                _sightGObj obj = new _sightGObj {
                    Object = this, Seen = false
                };
                int idx = gobj.m_inSightGObjList.IndexOf(obj);

                if (idx != -1)
                {
                    if (type)
                    {
                        obj.Seen = true;
                        gobj.m_inSightGObjList[idx] = obj;
                        OnEnterVisibility(gobj);
                        gobj.OnEnterVisibility(this);
                    }
                    else
                    {
                        gobj.m_inSightGObjList.RemoveAt(idx);
                        OnLeaveVisibility(gobj);
                        gobj.OnLeaveVisibility(this);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public override bool Equals(object obj)
 {
     try
     {
         _sightGObj sight = (_sightGObj)obj;
         return(this.Object.m_uniqueId == sight.Object.m_uniqueId && this.Seen == sight.Seen);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public bool TryAddSightList(GObj obj)
        {
            lock (m_lock)
            {
                if (!InSight(obj))
                {
                    var sight_item = new _sightGObj {
                        Object = obj, Seen = false
                    };
                    if (obj.IsCharacter)
                    {
                        sight_item.PacketQueue = new Queue <Packet>();
                    }

                    m_inSightGObjList.Add(sight_item);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public void Disappear(bool sendme = true)
        {
            if (!Data.Globals.GObjList.pop((node <GObj>)m_assignedListNode))
            {
                return;
            }
            m_assignedListNode = null;

            Packet      group_despawn = default(Packet);
            List <GObj> obj_removed   = new List <GObj>();

            if (this.IsCharacter)
            {
                group_despawn = new Packet(SCommon.Opcode.Agent.GAMEOBJECT_SPAWN_GROUP_DATA);
            }

            node <GObj> node = Data.Globals.GObjList.first();

            while (node != null)
            {
                lock (node.locker_)
                {
                    if (node.value_ != null)
                    {
                        if (this.IsCharacter || node.value_.IsCharacter)
                        {
                            if (/*Formula.IsInSightRegion(this.m_region, node.value.m_region) &&*/ this.m_uniqueId != node.value_.m_uniqueId)
                            {
                                if (node.value_.TryRemoveSightList(this))
                                {
                                    if (this.IsCharacter)
                                    {
                                        group_despawn.WriteInt32(node.value_.m_uniqueId);
                                    }

                                    obj_removed.Add(node.value_);
                                }

                                if (this.TryRemoveSightList(node.value_))
                                {
                                    Packet despawn = new Packet(SCommon.Opcode.Agent.GAMEOBJECT_DESPAWN_SINGLE);
                                    despawn.WriteInt32(this.m_uniqueId);
                                    despawn.m_data = this;
                                    node.value_.SendGObj(false, despawn, this);
                                }
                            }
                        }
                    }
                    node = node.next_;
                }
            }

            if (this.IsCharacter && sendme)
            {
                if (obj_removed.Count > 0)
                {
                    Packet start = new Packet(SCommon.Opcode.Agent.GAMEOBJECT_SPAWN_GROUP_START);
                    start.WriteByte(2); //despawn
                    start.WriteUInt16(obj_removed.Count);

                    Packet end = new Packet(SCommon.Opcode.Agent.GAMEOBJECT_SPAWN_GROUP_END);

                    this.SendPacket(start);
                    this.SendPacket(group_despawn);
                    this.SendPacket(end);
                }
            }

            for (int i = 0; i < obj_removed.Count; i++)
            {
                lock (obj_removed[i].m_lock)
                {
                    _sightGObj obj = new _sightGObj {
                        Object = this, Seen = false
                    };
                    int idx = obj_removed[i].m_inSightGObjList.IndexOf(obj);
                    if (idx != -1)
                    {
                        obj_removed[i].m_inSightGObjList.RemoveAt(idx);
                    }
                }
            }
        }