Esempio n. 1
0
  public void changeMap(int map_id) {
    this.map_id = map_id;

    map.reload();
    map.updateTileset(map_id);
    map.setCenterCharacter(centerCharacter);
    map.addEntity(centerCharacter);

    Network.getInstance()
        .send(new GamePacket(GamePacket.changeMap, centerCharacter.getEntityId(), map_id));
  }
Esempio n. 2
0
  public void create() {
    this.stage = new Stage(new ScreenViewport());
    this.skin = new Skin(Gdx.files.internal("skin/uiskin.json"));

    this.mapInputListener = new MapInputListener(this);
    stage.addListener(this.mapInputListener);
    chattingDialog = new ChattingDialog("chatting", skin);
    stage.addActor(chattingDialog);
    stage.setKeyboardFocus(chattingDialog.chatField);

    Gdx.input.setInputProcessor(stage);

    TopPacket packet = null;
    while (packet == null) packet = Network.getInstance().pollPacket();

    map_id = ((CharacterPacket) packet).getMapIndex();
    this.map = new Map(map_id, skin);

    Character entity = new Character(this, (CharacterPacket) packet);
    this.map.addEntity(entity);
    this.setCenterCharacter(entity);

    messages = new ArrayList<MessageDialog>();
  }
Esempio n. 3
0
  public void render() {
    this.map.update();
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();

    this.mapInputListener.update();

    while (Client.getCurrentState() == this) {
      TopPacket packet = Network.getInstance().pollPacket();
      if (packet == null) break;

      if (packet.getType() == TopPacket.CHARACTER) {
        if (((CharacterPacket) packet).getType2() == CharacterPacket.Add) {
          Character entity = new Character(this, (CharacterPacket) packet);
          this.map.addEntity(entity);
        } else if (((CharacterPacket) packet).getType2() == CharacterPacket.Del) {
          Entity entity = getEntityByEntityId(((CharacterPacket) packet).getEntityId());
          this.map.removeEntity(entity);
        }
      } else if (packet.getType() == TopPacket.MONSTER) {
        if (((MonsterPacket) packet).getType2() == MonsterPacket.Add) {
          Monster monster = new Monster(this, (MonsterPacket) packet);
          this.map.addEntity(monster);
        } else if (((MonsterPacket) packet).getType2() == MonsterPacket.Del) {
          Entity entity = getEntityByEntityId(((MonsterPacket) packet).getEntityId());
          this.map.removeEntity(entity);
        }
      } else if (packet.getType() == TopPacket.MOVE) {
        Entity target = getEntityByEntityId(((MovePacket) packet).getEntityId());
        if (target == null) break;

        int src_x = ((MovePacket) packet).getSx();
        int src_y = ((MovePacket) packet).getSy();
        int dest_x = ((MovePacket) packet).getDx();
        int dest_y = ((MovePacket) packet).getDy();

        target.move(src_x, src_y, dest_x, dest_y);
      } else if (packet.getType() == TopPacket.UPDATE) {
        Entity target = getEntityByEntityId(((UpdatePacket) packet).getEntityId());
        if (target == null) break;

        target.update((UpdatePacket) packet);
      } else if (packet.getType() == TopPacket.CHAT) {
        chattingDialog.append((ChatPacket) packet);
      } else if (packet.getType() == TopPacket.PARTY) {
        PartyPacket p = (PartyPacket) packet;
        if (p.getType2() == PartyPacket.info) {
          centerCharacterParty = new Party();
          int[] entityIds = p.getPartyMemberEntityIds();
          for (int i = 0; i < p.getPartyNumber(); i++) {
            Character c = (Character) getEntityByEntityId(entityIds[i]);
            centerCharacterParty.addMember(c);
          }
        } else if (p.getType2() == PartyPacket.withdraw) {
          centerCharacterParty = null;
        } else if (p.getType2() == PartyPacket.add) {
          centerCharacterParty.addMember((Character) getEntityByEntityId(p.getTargetEntityId()));
        } else if (p.getType2() == PartyPacket.del) {
          centerCharacterParty.removeMember(p.getTargetEntityId());
        } else if (p.getType2() == PartyPacket.invite) {
          stage.addActor(new ServerMsgDialog("", skin, p));
        }
      } else if (packet.getType() == TopPacket.MESSAGE) {
        MessagePacket p = (MessagePacket) packet;
        MessageDialog m = getMessageDialogByTarget(p.getName());
        if (m == null) {
          m = new MessageDialog("", skin, p.getName());
          messages.add(m);
          stage.addActor(m);
        }
        m.append(p);
      } else if (packet.getType() == TopPacket.SERVER) {
        SystemMessage.getInstance()
            .show(((ServerMsg) packet).getMsg(), 2000, 1.0f, 1.0f, 1.0f, 1.0f);
      }
    }
  }