com.cardshifter.modapi.cards.ZoneComponent类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(65)

本文整理了Java中com.cardshifter.modapi.cards.ZoneComponent类的一些代码示例,展示了ZoneComponent类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneComponent类的具体详情如下:
包路径:com.cardshifter.modapi.cards.ZoneComponent
类名称:ZoneComponent

ZoneComponent介绍

暂无

代码示例

代码示例来源:origin: Cardshifter/Cardshifter

/**
 * Zones are treated differently when they are known to the target player.
 * 
 * @param zone The zone component object
 * @param player The target player for the message
 * @return A zone message constructed based on the zone component object properties.
 */
private ZoneMessage constructZoneMessage(ZoneComponent zone, Entity player) {
  return new ZoneMessage(zone.getZoneId(), zone.getName(), 
      zone.getOwner().getId(), zone.size(), zone.isKnownTo(player), zone.stream().mapToInt(e -> e.getId()).toArray());
}

代码示例来源:origin: Cardshifter/Cardshifter

public Entity getComponentEntity() {
  return this.getEntity();
}

代码示例来源:origin: Cardshifter/Cardshifter

private void moveTo(ZoneComponent target, boolean top) {
  Entity card = getEntity();
  ZoneChangeEvent event = new ZoneChangeEvent(currentZone, target, card);
  
  executeEvent(event, () -> {
    if (event.getSource() != null) {
      event.getSource().cardMoveFrom(card);
    }
    ZoneComponent dest = event.getDestination();
    if (dest != null) {
      if (top) {
        dest.cardMoveAtTop(card);
      }
      else {
        dest.cardMoveAtBottom(card);
      }
    }
    this.currentZone = dest;
  });
}

代码示例来源:origin: Cardshifter/Cardshifter

private void createCards(ZoneComponent hand) {
  for (int i = 0; i < 5; i++) {
    Entity entity = hand.getOwner().getGame().newEntity();
    ECSResourceMap.createFor(entity)
        .set(CyborgChroniclesGame.CyborgChroniclesResources.HEALTH, 3)
        .set(CyborgChroniclesGame.CyborgChroniclesResources.MAX_HEALTH, 3);
    ECSAttributeMap.createFor(entity).set(Attributes.NAME, "Test");
    ActionComponent action = new ActionComponent();
    entity.addComponent(action);
    action.addAction(moveAction("Field", entity, BattlefieldComponent.class, false));
    action.addAction(moveAction("Hand", entity, HandComponent.class, false));
    action.addAction(moveAction("Deck", entity, DeckComponent.class, false));
    action.addAction(moveAction("2-Field", entity, BattlefieldComponent.class, true));
    action.addAction(moveAction("2-Hand", entity, HandComponent.class, true));
    action.addAction(moveAction("2-Deck", entity, DeckComponent.class, true));
    action.addAction(damageAction(entity));
    hand.addOnBottom(entity);
  }
}

代码示例来源:origin: Cardshifter/Cardshifter

@Override
public String toString() {
  return "Zone '" + name + "' [size=" + size() + ", owner=" + owner
      + ", known=" + known + ", publicKnown=" + publicKnown + "]";
}

代码示例来源:origin: Cardshifter/Cardshifter

public Entity getOwner() {
    ZoneComponent zone = getCurrentZone();
//        Objects.requireNonNull(getCurrentZone(), "Card is not on any zone: " + Entity.debugInfo(getEntity()));
    return zone == null ? null : zone.getOwner();
  }

代码示例来源:origin: Cardshifter/Cardshifter

/**
 * Sends the zone to all players. If the zone is known, also sends the cards.
 * 
 * @param zone The zone component to send
 */
private void sendZone(ZoneComponent zone) {
  for (ClientIO io : this.getPlayers()) {
    Entity player = playerFor(io);
    io.sendToClient(constructZoneMessage(zone, player));
    if (zone.isKnownTo(player)) {
      zone.forEach(card -> this.sendCard(io, card));
    }
  }
}

代码示例来源:origin: Cardshifter/Cardshifter

private void removeEntity(EntityRemoveEvent event) {
  CardComponent card = zones.get(event.getEntity());
  if (card != null) {
    ZoneComponent currentZone = card.getCurrentZone();
    currentZone.cardMoveFrom(event.getEntity());
  }
}

代码示例来源:origin: Cardshifter/Cardshifter

public static double scrapScore(ECSAction action, ScoreParameters<Entity> params) {
  if (!action.getName().equals(CyborgChroniclesGame.SCRAP_ACTION)) {
    return 0;
  }
  
  Entity entity = action.getOwner();
  ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class);
  
  ZoneComponent battlefield = card.get(entity).getCurrentZone();
  
  List<Entity> creatures = battlefield.getCards();
  if (creatures.size() <= 3) {
    return -health.getFor(entity);
  }
  
  creatures.sort(Comparator.comparingInt(e -> health.getFor(e) + attack.getFor(e)));
  if (entity == creatures.get(0)) {
    // Only consider scrapping the creature with lowest health
    return 4 - health.getFor(entity);
  }
  return -1;
}

代码示例来源:origin: Cardshifter/Cardshifter

private void drawCard(DrawCardEvent event) {
  if (event.getToZone().size() >= limit) {
    event.setCancelled(true);
    actionWhenFull.accept(event);
  }
}

代码示例来源:origin: Cardshifter/Cardshifter

public static boolean isOwnedByCurrentPlayer(Entity entity) {
  CardComponent cardData = card.required(entity);
  
  return cardData.getCurrentZone().getOwner() == phase.get(entity).getCurrentPhase().getOwner();
}

相关文章