コード例 #1
0
 @Override
 protected void onCast(
     GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
   int hpAdjustment = desc.getValue(SpellArg.HP_BONUS, context, player, target, source, 0);
   Actor targetActor = (Actor) target;
   int boardPosition = SpellUtils.getBoardPosition(context, player, desc, source);
   MinionCard minionCard = (MinionCard) targetActor.getSourceCard();
   Minion minion = minionCard.summon();
   if (hpAdjustment != 0) {
     minion.setHp(hpAdjustment);
   }
   context.getLogic().summon(player.getId(), minion, null, boardPosition, false);
 }
コード例 #2
0
ファイル: ActionLogic.java プロジェクト: webadict/metastone
  private List<GameAction> getPhysicalAttackActions(GameContext context, Player player) {
    List<GameAction> physicalAttackActions = new ArrayList<GameAction>();
    physicalAttackActions.addAll(getHeroAttackActions(context, player));

    for (Minion minion : player.getMinions()) {
      if (!minion.canAttackThisTurn()) {
        continue;
      }

      rollout(
          new PhysicalAttackAction(minion.getReference()), context, player, physicalAttackActions);
    }
    return physicalAttackActions;
  }
コード例 #3
0
 @Override
 protected void onCast(
     GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
   int manaCostModifier = desc.getInt(SpellArg.MANA_MODIFIER, 0);
   Minion minion = (Minion) target;
   Player owner = context.getPlayer(minion.getOwner());
   if (owner.getHand().getCount() >= GameLogic.MAX_HAND_CARDS) {
     logger.debug("{} is destroyed because {}'s hand is full", minion, owner.getName());
     context.getLogic().markAsDestroyed((Actor) target);
   } else {
     logger.debug("{} is returned to {}'s hand", minion, owner.getName());
     context.getLogic().removeMinion(minion);
     Card sourceCard = minion.getSourceCard().getCopy();
     context.getLogic().receiveCard(minion.getOwner(), sourceCard);
     sourceCard.setAttribute(Attribute.MANA_COST_MODIFIER, manaCostModifier);
   }
 }
コード例 #4
0
  private static ThreatLevel calcuateThreatLevel(GameContext context, int playerId) {
    int damageOnBoard = 0;
    Player player = context.getPlayer(playerId);
    Player opponent = context.getOpponent(player);
    for (Minion minion : opponent.getMinions()) {
      damageOnBoard += minion.getAttack() * minion.getAttributeValue(Attribute.NUMBER_OF_ATTACKS);
    }
    damageOnBoard += getHeroDamage(opponent.getHero());

    int remainingHp = player.getHero().getEffectiveHp() - damageOnBoard;
    if (remainingHp < 1) {
      return ThreatLevel.RED;
    } else if (remainingHp < 15) {
      return ThreatLevel.YELLOW;
    }

    return ThreatLevel.GREEN;
  }
コード例 #5
0
ファイル: MergeSpell.java プロジェクト: demilich1/metastone
 @Override
 protected void onCast(
     GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
   List<Entity> entities =
       context.resolveTarget(player, source, EntityReference.OTHER_FRIENDLY_MINIONS);
   SpellDesc destroySpell = DestroySpell.create(target.getReference());
   SpellUtils.castChildSpell(context, player, destroySpell, source, target);
   String cardId = desc.getString(SpellArg.CARD);
   for (Entity entity : entities) {
     Minion minion = (Minion) entity;
     if (minion.getSourceCard().getCardId().equalsIgnoreCase(cardId)) {
       destroySpell = DestroySpell.create(minion.getReference());
       SpellUtils.castChildSpell(context, player, destroySpell, source, target);
       SpellUtils.castChildSpell(context, player, ForceDeathPhaseSpell.create(), source, target);
       return;
     }
   }
 }
コード例 #6
0
ファイル: CopyCardSpell.java プロジェクト: hugin7/metastone
  @Override
  protected void onCast(
      GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
    if (target != null) {
      Card targetCard = null;
      if (target.getEntityType() == EntityType.CARD) {
        targetCard = (Card) target;
      } else if (target.getEntityType() == EntityType.MINION) {
        Minion minion = (Minion) target;
        targetCard = minion.getSourceCard();
      }
      context.getLogic().receiveCard(player.getId(), targetCard.getCopy());
      return;
    }

    CardLocation cardLocation = (CardLocation) desc.get(SpellArg.CARD_LOCATION);
    int numberOfCardsToCopy = desc.getInt(SpellArg.VALUE, 1);

    Player opponent = context.getOpponent(player);
    CardCollection sourceCollection = null;
    switch (cardLocation) {
      case DECK:
        sourceCollection = opponent.getDeck();
        break;
      case HAND:
        sourceCollection = opponent.getHand();
        break;
      default:
        logger.error("Trying to copy cards from invalid cardLocation {}", cardLocation);
        break;
    }

    for (int i = 0; i < numberOfCardsToCopy; i++) {
      if (sourceCollection.isEmpty()) {
        return;
      }
      Card clone = sourceCollection.getRandom().getCopy();
      context.getLogic().receiveCard(player.getId(), clone);
    }
  }
コード例 #7
0
  private double calculateMinionScore(Minion minion, ThreatLevel threatLevel) {
    if (minion.hasAttribute(Attribute.MARKED_FOR_DEATH)) {
      return 0;
    }
    double minionScore = weights.get(WeightedFeature.MINION_INTRINSIC_VALUE);
    minionScore +=
        weights.get(WeightedFeature.MINION_ATTACK_FACTOR)
            * (minion.getAttack() - minion.getAttributeValue(Attribute.TEMPORARY_ATTACK_BONUS));
    minionScore += weights.get(WeightedFeature.MINION_HP_FACTOR) * minion.getHp();

    if (minion.hasAttribute(Attribute.TAUNT)) {
      switch (threatLevel) {
        case RED:
          minionScore += weights.get(WeightedFeature.MINION_RED_TAUNT_MODIFIER);
          break;
        case YELLOW:
          minionScore += weights.get(WeightedFeature.MINION_YELLOW_TAUNT_MODIFIER);
          break;
        default:
          minionScore += weights.get(WeightedFeature.MINION_DEFAULT_TAUNT_MODIFIER);
          break;
      }
    }

    if (minion.hasAttribute(Attribute.WINDFURY)) {
      minionScore += weights.get(WeightedFeature.MINION_WINDFURY_MODIFIER);
    } else if (minion.hasAttribute(Attribute.MEGA_WINDFURY)) {
      minionScore += 2 * weights.get(WeightedFeature.MINION_WINDFURY_MODIFIER);
    }

    if (minion.hasAttribute(Attribute.DIVINE_SHIELD)) {
      minionScore += weights.get(WeightedFeature.MINION_DIVINE_SHIELD_MODIFIER);
    }
    if (minion.hasAttribute(Attribute.SPELL_DAMAGE)) {
      minionScore +=
          minion.getAttributeValue(Attribute.SPELL_DAMAGE)
              * weights.get(WeightedFeature.MINION_SPELL_POWER_MODIFIER);
    }

    if (minion.hasAttribute(Attribute.STEALTH)) {
      minionScore += weights.get(WeightedFeature.MINION_STEALTHED_MODIFIER);
    }
    if (minion.hasAttribute(Attribute.UNTARGETABLE_BY_SPELLS)) {
      minionScore += weights.get(WeightedFeature.MINION_UNTARGETABLE_BY_SPELLS_MODIFIER);
    }

    return minionScore;
  }