Exemple #1
0
        /// <summary>
        /// Reads a value from the packet
        /// </summary>
        /// <returns>value</returns>
        public int ReadInt()
        {
            int res = ByteManipulator.ReadInt32(Data, CurrentSeek);

            CurrentSeek += sizeof(int);
            return(res);
        }
Exemple #2
0
    public void TestCharsConversionsRedLight()
    {
        char[] s   = "dngsgnsiongDDDD@@#[ffa ".ToCharArray();
        char[] s2  = new char[s.Length];
        byte[] arr = new byte[Encoding.UTF8.GetByteCount(s) + sizeof(int)];
        ByteManipulator.Write(arr, 0, s, encoder);
        int n = ByteManipulator.ReadInt32(arr, 0);

        Assert.That(Encoding.UTF8.GetString(arr, sizeof(int), n), Is.Not.EqualTo("dngsgnsiongDDDD@@#[ffa"));
    }
Exemple #3
0
    public void TestListIntReadRedLight()
    {
        List <byte> arr = new List <byte>(sizeof(int));

        for (int i = 0; i < sizeof(int); i++)
        {
            arr.Add(0);
        }
        ByteManipulator.Write(arr, 0, -25);
        Assert.That(ByteManipulator.ReadInt32(arr, 0), Is.Not.EqualTo(9));
    }
    //OnEnemyDeath will be called when command EnemyDeath is received from host
    private void OnEnemyDeath(byte[] data, uint length, CSteamID senderId)
    {
        int   Id  = ByteManipulator.ReadInt32(data, 0);
        Enemy obj = netEntities[Id].GetComponent <Enemy>();

        if (!obj)
        {
            throw new NullReferenceException("NetId does not correspond to an enemy");
        }

        obj.Reset();
        obj.Pool.Recycle(obj.gameObject);
        OnEnemyRemoveEvent.Raise(obj.GetComponent <GameNetworkObject>());
    }
    private void OnNetObjHit(byte[] data, uint length, CSteamID sender)
    {
        int id = ByteManipulator.ReadInt32(data, 0);

        Enemy e = netEntities[id].GetComponent <Enemy>();

        //Debug.Log("hit received");
        e.DecreaseLife();
        if (CheckLife(e))
        {
            Client.SendPacketToInGameUsers(data, 0, (int)length, PacketType.ShootHit, EP2PSend.k_EP2PSendReliable, false);
        }
        //send to all but this client a packet with hit command only if e life is not 0
        //else send enemy death;
    }
    public void TestSendToAllOthersCorrectPayloadDataRedLight()
    {
        BytePacket p = new BytePacket(10);

        p.Write(750);
        p.Write((ushort)110);
        p.Write((sbyte)-5);
        p.Write(false);
        p.Write((short)short.MinValue);
        p.CurrentSeek = 0;
        transport.SendToAll(p, new VoicePacketInfo(), new List <ulong>()
        {
            1
        });
        Assert.That(ByteManipulator.ReadInt32(workflow.receivedData, 4), Is.Not.EqualTo(0));
    }
    //public GameObject EnemyCreation(GameObject obj, GameObject parent) //TODO: is this needed ? no one calls it
    //{
    //    GameObject o = Instantiate(obj, parent.transform);
    //    //if (OnEnemyAddEvent != null)
    //    //    OnEnemyAddEvent.Invoke(o.GetComponent<GameNetworkObject>());
    //    return o;
    //}

    //InstantiateEnemy will be called when command EnemySpawn is received from host
    private void InstantiateEnemy(byte[] data, uint length, CSteamID senderId)
    {
        if (!poolRoot && PoolRoot)
        {
            poolRoot      = GameObject.Instantiate(PoolRoot).transform;
            poolRoot.name = "Enemies Root";
        }

        int Id = ByteManipulator.ReadInt32(data, 0);
        //Debug.Log("received: " + Id);
        float   positionX = ByteManipulator.ReadSingle(data, 4);
        float   positionY = ByteManipulator.ReadSingle(data, 8);
        float   positionZ = ByteManipulator.ReadSingle(data, 12);
        Vector3 position  = new Vector3(positionX, positionY, positionZ);

        SOPool pool = EnemyPools[UnityEngine.Random.Range(0, EnemyPools.Length)];

        bool       parented;
        int        nullObjsRemovedFromPool;
        GameObject enemy = pool.DirectGet(poolRoot, out nullObjsRemovedFromPool, out parented);

        enemy.GetComponent <Enemy>().Pool = pool;
        GameNetworkObject NObj = enemy.GetComponent <GameNetworkObject>();

        NObj.SetNetworkId(Id);
        //cb.transform.position = position;
        NavMeshHit hit;

        if (NavMesh.SamplePosition(position, out hit, 1f, Mask))
        {
            enemy.GetComponent <NavMeshAgent>().Warp(hit.position);
        }
        else
        {
            Debug.LogWarning("NavMesh point for enemy spawn not found , souce pos = " + position);
        }

        enemy.SetActive(true);
        OnEnemyAddEvent.Raise(NObj);
        //if (!activeEnemyList.Contains(enemy.GetComponent<Enemy>()))
        //    enemiesToAdd.Add(enemy.GetComponent<Enemy>());
    }
Exemple #8
0
    private void NetObjTransformReceive(byte[] data, uint dataLength, CSteamID sender)
    {
        int id = ByteManipulator.ReadInt32(data, 0);

        if (!netEntities.Elements.ContainsKey(id))
        {
            return;
        }

        NetObjTransformSync sync = netEntities[id].GetComponent <NetObjTransformSync>();

        if (!sync)
        {
            return;
        }

        Vector3    position = new Vector3(ByteManipulator.ReadSingle(data, 4), ByteManipulator.ReadSingle(data, 8), ByteManipulator.ReadSingle(data, 12));
        Quaternion rotation = new Quaternion(ByteManipulator.ReadSingle(data, 16), ByteManipulator.ReadSingle(data, 20), ByteManipulator.ReadSingle(data, 24), ByteManipulator.ReadSingle(data, 28));

        sync.ReceiveTransform(position, rotation);
    }
    private void ShootCall(byte[] data, uint length, CSteamID sender)
    {
        int id = ByteManipulator.ReadInt32(data, 0);

        netEntities[id].GetComponent <EnemyShootSync>().ReceiveShotCall();
    }
    private void SetHealthStat(byte[] data, uint length, CSteamID sender)
    {
        int id = ByteManipulator.ReadInt32(data, 0);

        netEntities[id].GetComponent <Enemy>().DecreaseLife();
    }
Exemple #11
0
 public void TestIntReadRedLight()
 {
     byte[] arr = new byte[sizeof(int)];
     ByteManipulator.Write(arr, 0, -25);
     Assert.That(ByteManipulator.ReadInt32(arr, 0), Is.Not.EqualTo(9));
 }
Exemple #12
0
 public void TestIntRead()
 {
     byte[] arr = new byte[sizeof(int)];
     ByteManipulator.Write(arr, 0, -2500001);
     Assert.That(ByteManipulator.ReadInt32(arr, 0), Is.EqualTo(-2500001));
 }