示例#1
0
 public MessageDialog getMessageDialogByTarget(String target) {
   for (MessageDialog m : messages) {
     if (m.getTarget().equalsIgnoreCase(target)) {
       return m;
     }
   }
   return null;
 }
示例#2
0
 public boolean hasMessage(String target) {
   for (MessageDialog m : messages) {
     if (m.getTarget().equalsIgnoreCase(target)) {
       return true;
     }
   }
   return false;
 }
示例#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);
      }
    }
  }