Supports cloning battles for AI purposes.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -13,6 +13,12 @@ namespace PkmnLib::Battling {
|
||||
const ArbUt::BorrowedPtr<const Library::MoveData> GetMoveData() const {
|
||||
return GetAttack().ForceAs<const Library::MoveData>();
|
||||
}
|
||||
|
||||
LearnedAttack* Clone() const override {
|
||||
auto move = new LearnedMove(GetAttack().ForceAs<const Library::MoveData>(), GetLearnMethod());
|
||||
move->DecreaseUses(GetMaxUses() - GetRemainingUses());
|
||||
return move;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,47 @@ void PkmnLib::Battling::Pokemon::ClearStatus() {
|
||||
if (_battle.HasValue()) {
|
||||
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CreatureLib::Battling::Creature* PkmnLib::Battling::Pokemon::Clone() const {
|
||||
auto moves = std::vector<CreatureLib::Battling::LearnedAttack*>(_attacks.Count());
|
||||
auto i = 0;
|
||||
for (auto* attack : _attacks) {
|
||||
if (attack == nullptr) {
|
||||
moves[i++] = nullptr;
|
||||
} else {
|
||||
moves[i++] = dynamic_cast<LearnedMove*>(attack->Clone());
|
||||
}
|
||||
}
|
||||
|
||||
auto* c = new Pokemon(_library.ForceAs<const BattleLibrary>(), _species.ForceAs<const Library::PokemonSpecies>(),
|
||||
_variant.ForceAs<const Library::PokemonForme>(), _level, _experience, _uniqueIdentifier,
|
||||
_gender, _coloring, _heldItem.ForceAs<const Library::Item>(), _nickname, _talentIndex, moves,
|
||||
_individualValues, _effortValues, _nature, _allowedExperienceGain);
|
||||
c->_displaySpecies = _displaySpecies;
|
||||
c->_displayVariant = _displayVariant;
|
||||
c->_currentHealth = _currentHealth;
|
||||
c->_statBoost = _statBoost;
|
||||
c->_flatStats = _flatStats;
|
||||
c->_boostedStats = _boostedStats;
|
||||
c->_battle = _battle;
|
||||
c->_side = _side;
|
||||
c->_onBattleField = _onBattleField;
|
||||
if (_activeTalent != nullptr) {
|
||||
c->_activeTalent = std::unique_ptr<PkmnScript::BattleScript>(_activeTalent->Clone());
|
||||
}
|
||||
c->_hasOverridenTalent = _hasOverridenTalent;
|
||||
c->_overridenTalentName = _overridenTalentName;
|
||||
if (_status != nullptr) {
|
||||
c->_status = std::unique_ptr<PkmnScript::BattleScript>(_status->Clone());
|
||||
}
|
||||
_volatile.Clone(c->_volatile);
|
||||
c->_types = std::vector<u8>(_types);
|
||||
if (_statusScript != nullptr) {
|
||||
c->_statusScript = std::unique_ptr<PkmnScript::BattleScript>(_statusScript->Clone());
|
||||
}
|
||||
c->_friendship = _friendship;
|
||||
c->RecalculateFlatStats();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,8 @@ namespace PkmnLib::Battling {
|
||||
}
|
||||
_friendship = newValue;
|
||||
}
|
||||
|
||||
Creature* Clone() const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,23 @@ namespace PkmnLib::Battling {
|
||||
: CreatureLib::Battling::CreatureParty(std::move(party)) {}
|
||||
PokemonParty(std::initializer_list<CreatureLib::Battling::Creature*> party)
|
||||
: CreatureLib::Battling::CreatureParty(party) {}
|
||||
PokemonParty(size_t size) : CreatureLib::Battling::CreatureParty(size) {}
|
||||
|
||||
ArbUt::OptionalBorrowedPtr<Pokemon> GetAtIndex(int index) const {
|
||||
return CreatureLib::Battling::CreatureParty::GetAtIndex(index).As<Pokemon>();
|
||||
}
|
||||
|
||||
CreatureParty* Clone() const override {
|
||||
auto party = new PokemonParty(GetParty().Count());
|
||||
auto i = 0;
|
||||
for (auto c : GetParty()) {
|
||||
if (c != nullptr) {
|
||||
party->SwapInto(i, c->Clone());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return party;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user