Пример #1
0
    public static void Interpret(IPEndPoint source, Message message, GameplayMessage gameplay)
    {
        NetworkCommon networkCommon = GameObject.FindObjectOfType <Network> ().NetworkCommon;

        if (networkCommon == null)
        {
            return;
        }

        Player[] players = GameObject.FindObjectsOfType <Player>();

        switch (gameplay.Message)
        {
        case GameplayMessage.MessageValue.MOVE:
            foreach (Player player in players)
            {
                if (player.ID == gameplay.PlayerID)
                {
                    player.Move(gameplay.MoveDelta, gameplay.OldPosition, !(networkCommon is NetworkServer));
                }
            }
            break;

        case GameplayMessage.MessageValue.ATTACK:
            foreach (Player player in players)
            {
                if (player.ID == gameplay.PlayerID)
                {
                    player.Attack();
                }
            }
            break;
        }
    }
Пример #2
0
    public static void Interpret(IPEndPoint source, Message message, GameplayMessage gameplay)
    {
        NetworkCommon networkCommon = GameObject.FindObjectOfType<Network> ().NetworkCommon;

        if (networkCommon == null) return;

        Player[] players = GameObject.FindObjectsOfType<Player>();

        switch (gameplay.Message) {
            case GameplayMessage.MessageValue.MOVE:
                foreach (Player player in players) {
                    if (player.ID == gameplay.PlayerID) {
                        player.Move(gameplay.MoveDelta, gameplay.OldPosition, !(networkCommon is NetworkServer));
                    }
                }
                break;
            case GameplayMessage.MessageValue.ATTACK:
                foreach (Player player in players) {
                    if (player.ID == gameplay.PlayerID)
                    {
                        player.Attack();
                    }
                }
                break;
        }
    }
Пример #3
0
        public override void SendGameplayMessage(int clientId, GameplayMessage message,
                                                 int?param1 = null, int?param2 = null, int?param3 = null)
        {
            var msg = new GameMsg_SvGameMsg()
            {
                Message = message,
                Param1  = param1,
                Param2  = param2,
                Param3  = param3
            };

            Server.SendPackMsg(msg, MsgFlags.Vital, clientId);
        }
Пример #4
0
    private static Message createMessage(int sourceID, int destID, GameplayMessage.MessageValue message, int playerID, Vector2 delta, Vector3 originPosition)
    {
        Message m = new Message () {
            SourceID = sourceID,
            DestID = destID,
            Type = Message.MessageType.GAMEPLAY
        };

        GameplayMessage g = new GameplayMessage () {
            Message = message,
            PlayerID = playerID,
            MoveDelta = delta,
            OldPosition = originPosition
        };

        m.SerializedContent = ToByteArray(g);
        return m;
    }
Пример #5
0
    private static Message createMessage(int sourceID, int destID, GameplayMessage.MessageValue message, int playerID, Vector2 delta, Vector3 originPosition)
    {
        Message m = new Message()
        {
            SourceID = sourceID,
            DestID   = destID,
            Type     = Message.MessageType.GAMEPLAY
        };

        GameplayMessage g = new GameplayMessage()
        {
            Message     = message,
            PlayerID    = playerID,
            MoveDelta   = delta,
            OldPosition = originPosition
        };

        m.SerializedContent = ToByteArray(g);
        return(m);
    }
Пример #6
0
    public static void Send(GameplayMessage.MessageValue messageValue, int id, Vector2 delta, Vector3 originalPosition)
    {
        Network network = GameObject.FindObjectOfType<Network>();

        if (network == null) return;

        NetworkCommon networkCommon = network.NetworkCommon;

        if (networkCommon == null) return;

        Message m = createMessage(	networkCommon.ID,
                                  	1-networkCommon.ID,
                                  	messageValue,
                                  	id,
                                  	delta,
                                    originalPosition );

        if (networkCommon is NetworkClient) {
            (networkCommon as NetworkClient).Send (null, MessageTranslator.ToByteArray (m));
        } else {
            (networkCommon as NetworkServer).Broadcast (MessageTranslator.ToByteArray (m));
        }
    }
Пример #7
0
 private static byte[] ToByteArray(GameplayMessage message)
 {
     return(MessageTranslator.ToByteArray <GameplayMessage>(message));
 }
Пример #8
0
 private static byte[] ToByteArray(GameplayMessage message)
 {
     return MessageTranslator.ToByteArray<GameplayMessage>(message);
 }
Пример #9
0
 public abstract void SendGameplayMessage(int clientId, GameplayMessage message,
                                          int?param1 = null, int?param2 = null, int?param3 = null);