Skip to content

Commit

Permalink
Implement RaidPokemon::GetForm
Browse files Browse the repository at this point in the history
  • Loading branch information
zaksabeast committed Apr 5, 2020
1 parent 8fdf709 commit cfdcb0d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions libcsight/include/csight/RaidPokemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace csight::raid {
class RaidPokemon : public PKM {
public:
RaidPokemon(u64 seed, u32 flawlessIvs, u16 species, ability::raid::AbilityRaidSetting abilitySetting);
RaidPokemon(u64 seed, RaidEncounter spawn);
u32 GetEC();
u32 GetPID();
u16 GetSpecies();
Expand All @@ -26,7 +26,7 @@ namespace csight::raid {
u64 m_seed;
u32 m_EC;
u32 m_PID;
u16 m_species;
RaidEncounter m_spawn;
std::vector<u8> m_IVs;
shiny::ShinyType m_shineType;
ability::Ability m_ability = ability::First;
Expand Down
2 changes: 1 addition & 1 deletion libcsight/source/csight/CalculateRaidPKMList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace csight::raid {
auto encounter = searchSettings->GetRaidEncounter();

for (u32 advance = 0; advance < advancesToSearch; advance++) {
auto raid = std::make_shared<RaidPokemon>(nextSeed, encounter.flawlessIVs, encounter.species, encounter.ability);
auto raid = std::make_shared<RaidPokemon>(nextSeed, encounter);
nextSeed = rng::xoroshiro(nextSeed).nextulong();

if (checkIfPassesFilters(searchSettings, raid))
Expand Down
5 changes: 4 additions & 1 deletion libcsight/source/csight/CalculateRaidSeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace csight::raid {

// Only compare bits of the PID guaranteed with the missing seed bytes
if (testPID == maskedPID) {
// tmp spawn for testing generated IVs
RaidEncounter spawn = { 1, 1, ability::raid::FirstOrSecond, 0, {} };
for (u64 k = 0; k <= 0xffff; k++) {
auto seed = (k << 48) + partialTestSeed;
res = xoroshiro(seed, s1); // ec
Expand All @@ -51,7 +53,8 @@ namespace csight::raid {

if (generatedPID == pid) {
for (u32 flawlessIVs = 1; flawlessIVs <= 5; flawlessIVs++) {
auto ivsToCheck = RaidPokemon(seed, flawlessIVs, 0, ability::raid::FirstOrSecond).GetIVs();
spawn.flawlessIVs = flawlessIVs;
auto ivsToCheck = RaidPokemon(seed, spawn).GetIVs();
bool hasCorrectIVs = std::equal(ivs.begin(), ivs.end(), ivsToCheck.begin());

if (hasCorrectIVs)
Expand Down
11 changes: 2 additions & 9 deletions libcsight/source/csight/Den.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ namespace csight::raid {

u8 Den::GetDenDisplayId() { return m_denId + 1; }

std::shared_ptr<RaidPokemon> Den::GetPKM() {
return std::make_shared<RaidPokemon>(this->GetSeed(), m_spawn.flawlessIVs, m_spawn.species, m_spawn.ability);
};
std::shared_ptr<RaidPokemon> Den::GetPKM() { return std::make_shared<RaidPokemon>(this->GetSeed(), m_spawn); };

RaidEncounter Den::FindSpawn(std::vector<RaidEncounter> raidEncounters) {
u32 userProbability = 1;
Expand All @@ -100,11 +98,6 @@ namespace csight::raid {
}
}

return {
species : 0,
flawlessIVs : 1,
ability : ability::raid::FirstOrSecond,
probabilities : { 0, 0, 0, 0, 0 },
};
return raidEncounters[0];
}
} // namespace csight::raid
13 changes: 6 additions & 7 deletions libcsight/source/csight/RaidPokemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#define EMPTY_IV 255

namespace csight::raid {
RaidPokemon::RaidPokemon(u64 seed, u32 flawlessIvs, u16 species, ability::raid::AbilityRaidSetting abilitySetting) :
PKM::PKM() {
RaidPokemon::RaidPokemon(u64 seed, RaidEncounter spawn) : PKM::PKM() {
m_seed = seed;
m_species = species;
m_spawn = spawn;
auto rng = rng::xoroshiro(m_seed);
m_EC = rng.next(0xFFFFFFFF);
u32 SIDTID = rng.next(0xFFFFFFFF);
Expand All @@ -22,7 +21,7 @@ namespace csight::raid {

m_IVs = { EMPTY_IV, EMPTY_IV, EMPTY_IV, EMPTY_IV, EMPTY_IV, EMPTY_IV };

for (u32 i = 0; i < flawlessIvs; i++) {
for (u32 i = 0; i < m_spawn.flawlessIVs; i++) {
s32 ivIndex;

do {
Expand All @@ -40,7 +39,7 @@ namespace csight::raid {

// Thanks to
// https://github.com/Leanny/leanny.github.io/blob/17916ebde2bc984f325f7b103865416f226492fb/seedchecker/common.js#L207
switch (abilitySetting) {
switch (m_spawn.ability) {
case ability::raid::First:
m_ability = ability::First;
break;
Expand All @@ -61,7 +60,7 @@ namespace csight::raid {

u32 RaidPokemon::GetPID() { return m_PID; }

u16 RaidPokemon::GetSpecies() { return m_species; }
u16 RaidPokemon::GetSpecies() { return m_spawn.species; }

std::string RaidPokemon::GetSpeciesString() { return utils::getSpeciesName(this->GetSpecies()); }

Expand All @@ -77,5 +76,5 @@ namespace csight::raid {

u64 RaidPokemon::GetRaidSeed() { return m_seed; }

u16 RaidPokemon::GetForm() { return 0; }
u16 RaidPokemon::GetForm() { return m_spawn.form; }
} // namespace csight::raid

0 comments on commit cfdcb0d

Please sign in to comment.