✓ ESS21仅限 【特性】非官方的特性教程练习题-参考答案

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
此贴为非官方的特性教程练习题的参考答案,练习题可见原帖:https://bbs.pokefans.xyz/threads/550/

专门开一贴用来放参考答案。

我的答案并不是唯一的,也可能不是最好的;欢迎每个人都发出你的答案来,互相参考,一起进步。

请务必自己认真思考原题并且动手实践后,再来对答案。

那么下面开始。

感谢阅读。
 
最后编辑:

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
1.Majestic Moth(粉墨登场):
出场时,数值最高的那项能力增加1级。

以下是最难的版本的代码实现(考虑能力等级,手选最高项,方法重写优化,一次性):
Ruby:
Battle::AbilityEffects::OnSwitchIn.add(:MAJESTICMOTH,
  proc { |ability, battler, battle, switch_in|
    highest_stats = battler.highestStats.dup
    next if highest_stats.empty?
    highest_stats.delete_if { |stat| !battler.pbCanRaiseStatStage?(stat, battler) }
    next if highest_stats.empty?
    next if battle.battle_abilityTrigger?(battler)
    stat = highest_stats.sample
    battle.pbShowAbilitySplash(battler)
    if battler.pbOwnedByPlayer? && highest_stats.length >= 2
      stats_name = highest_stats.map { |stat| GameData::Stat.get(stat).name }
      index = pbMessage(_INTL("想要让{1}增加什么能力?", battler.pbThis), stats_name, -1)
      stat = highest_stats[index] if index != -1
    end
    battler.pbRaiseStatStageByAbility(stat, 1, battler, false)
    battle.pbHideAbilitySplash(battler)
  }
)

class Battle::Battler
  def realStats
    real_stats = {}
    stageMul = STAT_STAGE_MULTIPLIERS
    stageDiv = STAT_STAGE_DIVISORS
    plainStats.each do |stat, val|
      stage = @stages[stat] + STAT_STAGE_MAXIMUM
      real_stat = (val.to_f * stageMul[stage] / stageDiv[stage]).floor
      real_stats[stat] = real_stat
    end
    real_stats
  end

  def highestStats
    highest_stats = []
    highest_value = realStats.values.max
    realStats.each { |stat, val| highest_stats << stat if val == highest_value }
    highest_stats
  end
end

视频预览——

浏览附件2024-09-12 20-34-23.mp4
 
最后编辑:

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
2.Champion Belt(冠军卫冕):
受到的格斗属性的精灵的伤害减少33%;
每击倒一只格斗属性的精灵,回复50%的HP。

Ruby:
Battle::AbilityEffects::DamageCalcFromTarget.add(:CHAMPIONBELT,
  proc { |ability, user, target, move, mults, power, type|
    mults[:final_damage_multiplier] *= 0.67 if user.pbHasType?(:FIGHTING)
  }
)

Battle::AbilityEffects::OnEndOfUsingMove.add(:CHAMPIONBELT,
  proc { |ability, user, targets, move, battle|
    next if !user.canHeal?
    num_fainted = targets.count { |b| b.damageState.fainted && b.pbHasType?(:FIGHTING) }
    next if num_fainted == 0
    battle.pbShowAbilitySplash(user)
    user.pbRecoverHP(num_fainted * user.totalhp / 2)
    if Battle::Scene::USE_ABILITY_SPLASH
      battle.pbDisplay(_INTL("{1}'s HP was restored.", user.pbThis))
    else
      battle.pbDisplay(_INTL("{1}'s {2} restored its HP.", user.pbThis, user.abilityName))
    end
    battle.pbHideAbilitySplash(user)
  }
)

视频预览——

浏览附件2024-09-12 21-15-42.mp4
 
最后编辑:

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
3.Omnigrowth(无限潜能):
和训练家对战时,每击败一只精灵,自身的双攻和速度增加0.5%,但是双防减少0.1%;
同时,击倒对手的那个技能的威力增加0.5%。

Ruby:
Battle::AbilityEffects::OnSwitchIn.add(:OMNIGROWTH,
  proc { |ability, battler, battle, switch_in|
    battle.pbShowAbilitySplash(battler)
    if !battler.pbOwnedByPlayer?
      wild_omnigrowth_count = Pokemon::WILD_OMNIGROWTH_COUNT
      wild_random_omnigrowth_count = battle.pbRandom(wild_omnigrowth_count)
      battler.update_omnigrowth_count(wild_random_omnigrowth_count)
    end
    battle.pbDisplay(_INTL("{1}渴望有价值的对手!", battler.pbThis))
    battle.pbDisplay(_INTL("{1}已经打倒了{2}名对手!", battler.pbThis, battler.omnigrowth_count)) if battler.omnigrowth_count > 0
    battle.pbHideAbilitySplash(battler)
  }
)

Battle::AbilityEffects::SpeedCalc.add(:OMNIGROWTH,
  proc { |ability, battler, mult|
    next mult * (1 + battler.omnigrowth_count_power_speed_up)
  }
)

Battle::AbilityEffects::DamageCalcFromUser.add(:OMNIGROWTH,
  proc { |ability, user, target, move, mults, power, type|
    mults[:attack_multiplier] *= 1 + user.omnigrowth_count_power_speed_up
    mults[:power_multiplier] *= 1 + user.omnigrowth_move_power_up(move.id)
  }
)

Battle::AbilityEffects::DamageCalcFromTarget.add(:OMNIGROWTH,
  proc { |ability, user, target, move, mults, power, type|
    mults[:defense_multiplier] *= 1 - user.omnigrowth_count_defense_down
  }
)

Battle::AbilityEffects::OnEndOfUsingMove.add(:OMNIGROWTH,
  proc { |ability, user, targets, move, battle|
    num_fainted = targets.count { |b| b.damageState.fainted }
    next if num_fainted == 0
    battle.pbShowAbilitySplash(user)
    user.update_omnigrowth_count(num_fainted)
    user.update_omnigrowth_move(move.id, num_fainted)
    battle.pbDisplay(_INTL("{1}变得更加强大了!", user.pbThis))
    battle.pbDisplay(_INTL("{1}已经打倒了{2}名对手!", user.pbThis, user.omnigrowth_count))
    battle.pbHideAbilitySplash(user)
  }
)

class Pokemon
  WILD_OMNIGROWTH_COUNT = 30
  POWER_SPEED_UP_RATE = 0.5
  DENFESE_DOWN_RATE = 0.1

  def omnigrowth_count
    @omnigrowth_count ||= 0
  end

  def update_omnigrowth_count(amount = 1)
    @omnigrowth_count += amount
  end

  def omnigrowth_count_power_speed_up
    omnigrowth_count * 0.01 * POWER_SPEED_UP_RATE
  end

  def omnigrowth_count_defense_down
    omnigrowth_count * 0.01 * DENFESE_DOWN_RATE
  end

  def omnigrowth_move
    @omnigrowth_move ||= Hash.new(0)
  end

  def update_omnigrowth_move(move_id, amount = 1)
    @omnigrowth_move[move_id] += amount
  end

  def omnigrowth_move_power_up(move_id)
    omnigrowth_move[move_id] * 0.01 * POWER_SPEED_UP_RATE
  end
end

class Battle::Battler
  def omnigrowth_count
    @pokemon.omnigrowth_count
  end

  def omnigrowth_count_power_speed_up
    @pokemon.omnigrowth_count_power_speed_up
  end

  def omnigrowth_count_defense_down
    @pokemon.omnigrowth_count_defense_down
  end

  def update_omnigrowth_count(amount = 1)
    @pokemon.update_omnigrowth_count(amount)
  end

  def omnigrowth_move_power_up(move_id)
    @pokemon.omnigrowth_move_power_up(move_id)
  end

  def update_omnigrowth_move(move_id, amount = 1)
    @pokemon.update_omnigrowth_move(move_id, amount)
  end
end

视频预览——
 
最后编辑:

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
4.Evoboost Sync(伊伊伊布):
首次出场时,自身的某些能力增加1级,增加的能力项数由队伍中除自身外伊布家族的数量决定,增加能力的顺序为从最高项到最低项。

Ruby:
Battle::AbilityEffects::OnSwitchIn.add(:EVOBOOSTSYNC,
  proc { |ability, battler, battle, switch_in|
    evo_boost = battler.evoBoostStats.dup
    next if evo_boost.empty?
    evo_boost.delete_if { |stat| !battler.pbCanRaiseStatStage?(stat, battler) }
    next if evo_boost.empty?
    next if battle.battle_abilityTrigger?(battler)
    battle.pbShowAbilitySplash(battler)
    anim = true   
    evo_boost.each do |stat|
      battler.pbRaiseStatStageByAbility(stat, 1, battler, false, anim)
      anim = false
    end
    battle.pbHideAbilitySplash(battler)
  }
)

class Pokemon
  def is_eevee?
    %i[EEVEE VAPOREON JOLTEON FLAREON LEAFEON GLACEON SYLVEON ESPEON UMBREON].include?(@species)
  end
end

class Battle
  def eevee_count(battler)
    party = battler.index & 1 == 0 ? @party1 : @party2
    party.count { |pokemon| pokemon.is_eevee? }
  end
end

class Battle::Battler
  def sortedStats
    sorted_stats = realStats.sort_by { |key, value| value }
    sorted_stats.map { |stat| stat[0] }
  end

  def reversedSortedStats
    sortedStats.reverse
  end

  def evoBoostStats
    eevee_count = @battle.eevee_count(self)
    eevee_count = 1 if eevee_count == 0
    reversedSortedStats[0...(eevee_count - 1)]
  end
end

视频预览——
 
最后编辑:

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
5.Second Chance(倒计时)预估难度:4星。
此特性的精灵在濒死后经过4个回合就会复活,复活时回复50%的HP;这个特性一场战斗最多发动3次。
 

TAAAAAAA

天王
管理成员
2024/06/16
200
3
27
1,210
这个帖子我本人目前已不会再更新,原因在于我对于写这些特性失去了兴趣和热情。

目前还未给出参考答案的特性还剩两个,分别是Second Chance(倒计时)和Sky Guardian(天空守护者)。

等哪天来了兴趣再说吧。
 

komeiji514

馆主
2022/09/01
79
1
9
675
20
我自己一段时间也不愿意且不需要继续撰写新的特性了,先告一段落罢。
 

在线成员

论坛统计

主题
474
消息
2,137
成员
2,909
最新成员
小灵喵~