public override void Update(TimeSpan elapsed)
        {
            foreach (var player in World.Instance.Players)
            {
                BaseMessage message = new PositionMessage(GetVisibleEntities(player));
                SendMessage(player, message);

                if (player.MapToUpdate)
                {
                    message = GetMapUpdate(player);
                    SendMessage(player, message);

                    player.MapToUpdate = false;
                }

                if (player.TeamToUpdate)
                {
                    player.RemoteConnection.Send(GetTeamUpdate(player));
                    player.TeamToUpdate = false;
                }
            }

            base.Update(elapsed);
        }
Esempio n. 2
0
    private void MessageReceived(IRemoteConnection sender, string message)
    {
        messageCount++;
        if (messageCount < 10)
        {
            Debug.Log("received " + message);
        }

        var prefix = "entities:";
        if (message.StartsWith(prefix) && CurrentScene == "scene_map")
        {
            var notif = new PositionMessage();
            notif.DeserializeArguments(message.Remove(0, prefix.Length));

            foreach (var entity in notif.Entities)
            {
                MoveMessages.Enqueue(entity);
            }
        }

        prefix = "team:";
        if (message.StartsWith(prefix))
        {
            var teamStr = message.Remove(0, prefix.Length);
            var pokemonCount = teamStr.Split(',').Count();
            Team = new List<Pokemon>();
            for (int i = 0; i < pokemonCount; i++)
            {
                var pokemonStr = teamStr.Split(',')[i];
                var id = Int32.Parse(pokemonStr.Split('.')[0]);
                var level = Int32.Parse(pokemonStr.Split('.')[1]);
                Team.Add(new Pokemon(id, level));
            }
        }

        prefix = "map:";
        if (message.StartsWith(prefix))
        {
            Debug.Log("map received");

            var map = new MapMessage();
            map.DeserializeArguments(message.Remove(0, prefix.Length));

            //Debug.Log(map);

            MapMessages.Enqueue(map);
        }

        prefix = "battlestart:";
        if (message.StartsWith(prefix))
        {
            Debug.Log("battle start received");
            var battleStart = message.Remove(0, prefix.Length);

            BattleStartMessage battle = new BattleStartMessage(battleStart);
            BattleStartMessages.Enqueue(battle);
        }

        prefix = "battleaction:";
        if (message.StartsWith(prefix))
        {
            Debug.Log("battle action received");
            var battleActionStr = message.Remove(0, prefix.Length);
            Debug.Log(battleActionStr);

            BattleActionMessage battleAction = new BattleActionMessage(battleActionStr);
            BattleActionMessages.Enqueue(battleAction);
        }
    }