public override void HandleNetMessage(EntitySystemMessage sysMsg)
        {
            if (sysMsg is InventorySystemPickUp)
            {
                InventorySystemPickUp message = sysMsg as InventorySystemPickUp;
                Entity user = EntityManager.GetEntity(message.uidUser);
                Entity obj = EntityManager.GetEntity(message.uidObject);

                if(user != null && obj != null)
                    PickUpEntity(user, obj);
            }

            else if (sysMsg is InventorySystemDrop)
            {
                InventorySystemDrop message = sysMsg as InventorySystemDrop;
                Entity user = EntityManager.GetEntity(message.uidUser);
                Entity obj = EntityManager.GetEntity(message.uidObject);
                Entity dropping = EntityManager.GetEntity(message.uidDroppingInventory);

                if (user != null && obj != null && dropping != null)
                    RemoveEntity(user, dropping, obj);
            }

            else if (sysMsg is InventorySystemExchange) //TODO: Add argument for target inventory type.
            {
                InventorySystemExchange message = sysMsg as InventorySystemExchange;
                Entity user = EntityManager.GetEntity(message.uidUser);
                Entity obj = EntityManager.GetEntity(message.uidObject);
                Entity prevInv = EntityManager.GetEntity(message.uidPreviousInventory);
                Entity newInv = EntityManager.GetEntity(message.uidNewInventory);

                if (user != null && obj != null && prevInv != null && newInv != null)
                    ExchangeEntity(user, prevInv, newInv, obj);
            }
        }
        /// <summary>
        /// Sends a message to the relevant system(s) serverside.
        /// </summary>
        public void SendSystemNetworkMessage(EntitySystemMessage message,
                                             NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
        {
            NetOutgoingMessage newMsg = CreateEntityMessage();
            newMsg.Write((byte)EntityMessage.SystemMessage);

            var stream = new MemoryStream();
            Serializer.Serialize(stream, message);
            newMsg.Write((int)stream.Length);
            newMsg.Write(stream.ToArray());

            if (_messageProfiling)
            {
                //Log the message
            }

            //Send the message
            _networkManager.SendMessage(newMsg, method);
        }
        /// <summary>
        /// Sends a message to the relevant system(s) on the target client.
        /// </summary>
        public void SendSystemNetworkMessage(EntitySystemMessage message, 
                                     NetConnection targetConnection = null,
                                     NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
        {
            NetOutgoingMessage newMsg = CreateEntityMessage();
            newMsg.Write((byte)EntityMessage.SystemMessage);

            var stream = new MemoryStream();
            Serializer.Serialize(stream, message);
            newMsg.Write((int)stream.Length);
            newMsg.Write(stream.ToArray());

            if (_messageProfiling)
            {
                //Log the message
            }

            //Send the message
            if (targetConnection != null)
            {
                m_netServer.SendMessage(newMsg, targetConnection, method);
            }
            else
            {
                m_netServer.SendToAll(newMsg, method);
            }
            
        }
 /// <summary>
 /// Sends a message to the relevant system(s) on all clients.
 /// </summary>
 public void SendSystemNetworkMessage(EntitySystemMessage message,
                                      NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
 {
     SendSystemNetworkMessage(message, null, method);
 }
Esempio n. 5
0
 public virtual void HandleNetMessage(EntitySystemMessage sysMsg)
 {
     return;
 }
 public override void HandleNetMessage(EntitySystemMessage sysMsg)
 {
     base.HandleNetMessage(sysMsg);
 }