示例#1
0
        /// <summary>
        /// Refresh list of nearby objects to service related systems.
        /// </summary>
        void UpdateNearbyObjects()
        {
            nearbyObjects.Clear();

            // Get entities
            DaggerfallEntityBehaviour[] entities = FindObjectsOfType <DaggerfallEntityBehaviour>();
            if (entities != null)
            {
                for (int i = 0; i < entities.Length; i++)
                {
                    if (entities[i] == GameManager.Instance.PlayerEntityBehaviour)
                    {
                        continue;
                    }

                    NearbyObject no = new NearbyObject()
                    {
                        gameObject = entities[i].gameObject,
                        distance   = Vector3.Distance(transform.position, entities[i].transform.position),
                    };

                    no.flags = GetEntityFlags(entities[i]);
                    nearbyObjects.Add(no);
                }
            }

            // Get treasure - this assumes loot containers will never carry entity component
            DaggerfallLoot[] lootContainers = FindObjectsOfType <DaggerfallLoot>();
            if (lootContainers != null)
            {
                for (int i = 0; i < lootContainers.Length; i++)
                {
                    NearbyObject no = new NearbyObject()
                    {
                        gameObject = lootContainers[i].gameObject,
                        distance   = Vector3.Distance(transform.position, lootContainers[i].transform.position),
                    };

                    no.flags = GetLootFlags(lootContainers[i]);
                    nearbyObjects.Add(no);
                }
            }
        }
示例#2
0
    //later on add mechanism to avoid redundant object sending (at least for fixed position objects), and smooth landmark/colloseums drawing since they are in a fixed position
    private void updateDriver(IAsyncResult ar)
    {
        try
        {
            //complete async data read
            if (client.EndReceive(ar) == 0)
            {
                return;
            }

            //UnityEngine.Debug.Log(responseTime.ElapsedMilliseconds);

            int    nearby = BitConverter.ToInt32(size, 0);
            int    numObjects;
            byte[] numObjectsArr = new byte[4];
            client.Receive(numObjectsArr, 4, 0);
            numObjects = BitConverter.ToInt32(numObjectsArr, 0);
            byte[] buf = new byte[nearby];

            int nearbyDetailsIndex = numObjects * 24;

            //int numNearbyPlayers = 0;

            //read in each nearby items
            client.Receive(buf, nearby, 0);

            byte[] idBytes = new byte[16];

            float lat;

            nearbyObjects = new List <NearbyObject>();

            for (int i = 0; i < numObjects; i++)
            {
                NearbyObject o = new NearbyObject();

                lat = BitConverter.ToSingle(buf, i * 8);
                if (lat < 91)
                {
                    o.Type     = 0;
                    o.Latitude = lat;
                    //char temp = 't';
                    int strLen = 0;
                    //name strings are null terminated, find where the players name ends
                    while (buf[nearbyDetailsIndex + strLen] != '\0')
                    {
                        strLen++;
                    }
                    o.Name = Encoding.ASCII.GetString(buf, nearbyDetailsIndex, strLen);
                    UnityEngine.Debug.Log(o.Name);
                    //add one to move past null character
                    o.FactionNo = buf[nearbyDetailsIndex + strLen + 1];
                    UnityEngine.Debug.Log(o.FactionNo);
                    o.PlayerLevel = buf[nearbyDetailsIndex + strLen + 2];
                    UnityEngine.Debug.Log(o.PlayerLevel);
                    o.FactionLevel = buf[nearbyDetailsIndex + strLen + 3];
                    UnityEngine.Debug.Log(o.FactionLevel);
                    //move the index past the current player's details
                    nearbyDetailsIndex += strLen + 4;
                    //numNearbyPlayers++;
                }
                else if (lat < 272)
                {
                    o.Type     = 1;
                    o.Latitude = lat - 181;
                }
                else
                {
                    o.Type     = 2;
                    o.Latitude = lat - 362;
                }


                o.Longtitude = BitConverter.ToSingle(buf, i * 8 + 4);
                Buffer.BlockCopy(buf, 8 * numObjects + i * 16, idBytes, 0, 16);
                o.Id = new Guid(idBytes);

                //UnityEngine.Debug.Log(o.Id);

                /*-----------------TEMPORARY TEST CODE----------------------
                 *
                 * if (o.Type == 0 && o.Id != Player.playerID)
                 * {
                 *  menuScript.opponentID = o.Id;
                 *  UnityEngine.Debug.Log("Opponent ID set: " + o.Id);
                 * }
                 *
                 * //----------------------------------------------------------*/

                //UnityEngine.Debug.Log("Am I not being added?   " + o.Type);
                nearbyObjects.Add(o);
                //UnityEngine.Debug.Log(o.Longtitude);
            }



            //upNearbyObj = true;
            waitUpdate.Reset();
            waitUpdate.WaitOne();

            //recursively read data while battle is going
            client.BeginReceive(size, 0, 4, 0, new AsyncCallback(updateDriver), null);
        }
        catch (Exception)
        {
        }
    }