public override void OnEnemyShapeChosen(PlayerIndex player, Shapes.Shape shape)
 {
     if (player == PlayerIndex.One)
     {
         MsgGameEnemyShapeChosen msg = new MsgGameEnemyShapeChosen();
         msg.SetShape(shape);
         Steam_Manager.SendP2PMessage(Steam_Manager.ConnectedPlayer, msg, EP2PSend.k_EP2PSendReliable);
     }
 }
Example #2
0
        /// <summary>
        /// Serialises a list of objects to <paramref name="writer"/>
        /// </summary>
        /// <param name="writer">The writer to serialise to.</param>
        /// <param name="objects">The object to write.</param>
        /// <param name="processedCount">Number of objects processed.</param>
        /// <returns>An error code on failure.</returns>
        /// <remarks>
        /// Default serialisation uses the following logic on each object:
        /// <list type="bullet">
        /// <item>Call <see cref="CreateSerialisationShape(ShapeComponent)"/> to
        ///       create a temporary shape to match the unity object</item>
        /// <item>Call <see cref="Shapes.Shape.WriteCreate(PacketBuffer)"/> to generate the creation message
        ///       and serialise the packet.</item>
        /// <item>For complex shapes, call <see cref="Shapes.Shape.WriteData(PacketBuffer, ref uint)"/> as required
        ///       and serialise the packets.</item>
        /// </list>
        ///
        /// Using the <see cref="Shapes.Shape"/> classes ensures serialisation is consistent with the server code
        /// and reduces the code maintenance to one code path.
        /// </remarks>
        protected virtual Error SerialiseObjects(BinaryWriter writer, IEnumerator <GameObject> objects, ref uint processedCount)
        {
            // Serialise transient objects.
            PacketBuffer packet = new PacketBuffer();
            Error        err;

            Shapes.Shape tempShape  = null;
            uint         dataMarker = 0;
            int          dataResult = 0;

            Debug.Assert(tempShape != null && tempShape.RoutingID == RoutingID);

            processedCount = 0;
            while (objects.MoveNext())
            {
                ++processedCount;
                GameObject obj = objects.Current;
                tempShape = CreateSerialisationShape(obj.GetComponent <ShapeComponent>());
                if (tempShape != null)
                {
                    tempShape.WriteCreate(packet);
                    packet.FinalisePacket();
                    packet.ExportTo(writer);

                    if (tempShape.IsComplex)
                    {
                        dataResult = 1;
                        dataMarker = 0;
                        while (dataResult > 0)
                        {
                            dataResult = tempShape.WriteData(packet, ref dataMarker);
                            packet.FinalisePacket();
                            packet.ExportTo(writer);
                        }

                        if (dataResult < 0)
                        {
                            return(new Error(ErrorCode.SerialisationFailure));
                        }

                        // Post serialisation extensions.
                        err = PostSerialiseCreateObject(packet, writer, obj.GetComponent <ShapeComponent>());
                        if (err.Failed)
                        {
                            return(err);
                        }
                    }
                }
                else
                {
                    return(new Error(ErrorCode.SerialisationFailure));
                }
            }

            return(new Error());
        }
Example #3
0
        /// <summary>
        /// A helper functio to configure the TES <paramref name="shape"/> to match the Unity object <paramref name="shapeComponent"/>.
        /// </summary>
        /// <param name="shape">The shape object to configure to match the Unity representation.</param>
        /// <param name="shapeComponent">The Unity shape representation.</param>
        protected void ConfigureShape(Shapes.Shape shape, ShapeComponent shapeComponent)
        {
            ObjectAttributes attr = new ObjectAttributes();

            shape.ID       = shapeComponent.ObjectID;
            shape.Category = shapeComponent.Category;
            shape.Flags    = shapeComponent.ObjectFlags;
            EncodeAttributes(ref attr, shapeComponent.gameObject, shapeComponent);
            shape.SetAttributes(attr);
        }
        /// <summary>
        /// Obtient les entités vivantes se trouvant dans la forme passée en paramètre.
        /// </summary>
        public EntityCollection GetAliveEntitiesIn(Shapes.Shape shape, EntityType type)
        {
            EntityCollection entitiesIn = new EntityCollection();

            foreach (var kvp in this)
            {
                if (shape.Intersects(kvp.Value.Shape) && !kvp.Value.IsDead && kvp.Value.Type.HasFlag(type))
                {
                    entitiesIn.Add(kvp.Key, kvp.Value);
                }
            }
            return(entitiesIn);
        }
 public override void OnEnemyShapeChosen(PlayerIndex player, Shapes.Shape shape)
 {
     if (gameMode == Games.Pick)
     {
         if (player == PlayerIndex.One)
         {
             playerTwoLevel.shapeQueue.Add(shape);
         }
         else if (player == PlayerIndex.Two)
         {
             playerOneLevel.shapeQueue.Add(shape);
         }
     }
 }
Example #6
0
        /// <summary>
        /// Serialises a list of objects to <paramref name="writer"/>
        /// </summary>
        /// <param name="writer">The writer to serialise to.</param>
        /// <param name="objects">The object to write.</param>
        /// <param name="processedCount">Number of objects processed.</param>
        /// <returns>An error code on failure.</returns>
        /// <remarks>
        /// Default serialisation uses the following logic on each object:
        /// <list type="bullet">
        /// <item>Call <see cref="CreateSerialisationShape(ShapeCache, int, CreateMessage)"/> to
        ///       create a temporary shape to match the unity object</item>
        /// <item>Call <see cref="Shapes.Shape.WriteCreate(PacketBuffer)"/> to generate the creation message
        ///       and serialise the packet.</item>
        /// <item>For complex shapes, call <see cref="Shapes.Shape.WriteData(PacketBuffer, ref uint)"/> as required
        ///       and serialise the packets.</item>
        /// </list>
        ///
        /// Using the <see cref="Shapes.Shape"/> classes ensures serialisation is consistent with the server code
        /// and reduces the code maintenance to one code path.
        /// </remarks>
        protected virtual Error SerialiseShapes(BinaryWriter writer, ShapeCache cache, ref uint processedCount)
        {
            // Serialise transient objects.
            PacketBuffer packet = new PacketBuffer();
            Error        err;

            Shapes.Shape        tempShape      = null;
            List <Shapes.Shape> multiShapeList = new List <Shapes.Shape>();
            uint dataMarker = 0;
            int  dataResult = 0;

            Debug.Assert(tempShape != null && tempShape.RoutingID == RoutingID);

            processedCount = 0;
            foreach (int shapeIndex in cache.ShapeIndices)
            {
                tempShape = null;
                ++processedCount;
                CreateMessage shapeData = cache.GetShapeByIndex(shapeIndex);
                if ((shapeData.Flags & (ushort)ObjectFlag.MultiShape) != 0)
                {
                    // Multi-shape. Follow the link.
                    multiShapeList.Clear();
                    int nextIndex = cache.GetMultiShapeChainByIndex(shapeIndex);
                    while (nextIndex != -1)
                    {
                        CreateMessage multiShapeData = cache.GetShapeByIndex(nextIndex);
                        tempShape    = CreateSerialisationShape(cache, shapeIndex, multiShapeData);
                        tempShape.ID = shapeData.ObjectID;
                        if (tempShape != null)
                        {
                            // Successfully created the child. Add to the list.
                            multiShapeList.Add(tempShape);
                        }
                        else
                        {
                            Debug.LogError($"{Name} failed to create multi-shape entry");
                        }
                        nextIndex = cache.GetMultiShapeChainByIndex(nextIndex);
                    }

                    // Create the multi-shape
                    tempShape          = new Shapes.MultiShape(multiShapeList.ToArray());
                    tempShape.ID       = shapeData.ObjectID;
                    tempShape.Category = shapeData.Category;
                    tempShape.SetAttributes(shapeData.Attributes);
                }
                else if (shapeData.ObjectID != ShapeCache.MultiShapeID)
                {
                    tempShape = CreateSerialisationShape(cache, shapeIndex, shapeData);
                }

                if (tempShape != null)
                {
                    tempShape.WriteCreate(packet);
                    packet.FinalisePacket();
                    packet.ExportTo(writer);

                    if (tempShape.IsComplex)
                    {
                        dataResult = 1;
                        dataMarker = 0;
                        while (dataResult > 0)
                        {
                            dataResult = tempShape.WriteData(packet, ref dataMarker);
                            packet.FinalisePacket();
                            packet.ExportTo(writer);
                        }

                        if (dataResult < 0)
                        {
                            return(new Error(ErrorCode.SerialisationFailure));
                        }

                        // Post serialisation extensions.
                        err = PostSerialiseCreateObject(packet, writer, cache, shapeIndex);
                        if (err.Failed)
                        {
                            return(err);
                        }
                    }
                }
                else if (shapeData.ObjectID != ShapeCache.MultiShapeID)
                {
                    return(new Error(ErrorCode.SerialisationFailure));
                }
            }

            return(new Error());
        }