3 #include <BLIB/Logging.hpp>
7 #include <unordered_map>
16 const std::string UnknownName =
"<Unknown Item>";
17 const std::string UnknownDescription =
"<This item is not known to Peoplemon>";
19 void refreshIds(std::unordered_map<Id, std::string>* names) {
21 ids.reserve(names->size());
22 for (
const auto& p : *names) { ids.emplace_back(p.first); }
23 std::sort(ids.begin(), ids.end());
27 std::unordered_map<Id, std::string>* Item::names =
nullptr;
28 std::unordered_map<Id, std::string>* Item::descriptions =
nullptr;
29 std::unordered_map<Id, int>* Item::values =
nullptr;
32 const Id result =
static_cast<Id>(id);
34 if (names->find(result) != names->end()) {
return result; }
36 BL_LOG_WARN <<
"Unknown item id: " << id;
50 const unsigned int id =
static_cast<unsigned int>(item);
77 const unsigned int id =
static_cast<unsigned int>(item);
92 const auto it = names->find(item);
93 if (it == names->end()) {
96 static std::string tmName;
97 tmName =
"TM " + std::to_string(
static_cast<int>(mid));
106 const auto it = descriptions->find(item);
107 if (it == descriptions->end()) {
110 static std::string tmDesc;
114 return UnknownDescription;
120 const auto it = values->find(item);
126 #ifdef PEOPLEMON_DEBUG
145 const auto checkStat = [&ppl](
pplmn::Stat stat) ->
bool {
162 for (
int i = 0; i < 4; ++i) {
173 for (
int i = 0; i < 4; ++i) {
223 std::vector<pplmn::OwnedPeoplemon>* team,
224 std::vector<pplmn::BattlePeoplemon>* battleTeam) {
228 for (
int i = 0; i < 4; ++i) {
230 m.
curPP = std::min(m.curPP + pp, m.maxPP);
253 restorePP(ppl, 1000);
265 BL_LOG_ERROR <<
"Used PP 6 pack but not given team";
270 for (
int i = 0; i < 4; ++i) {
274 const int ppp = npp - m.maxPP;
332 return ppl.
name() +
" had it's HP restored.";
334 return ppl.
name() +
" was healed completely.";
338 return ppl.
name() +
" had it's PP restored!";
341 return ppl.
name() +
" and all their friends had their PP restored.";
343 return ppl.
name() +
" had their PP raised.";
352 return ppl.
name() +
" had their " +
365 return ppl.
name() +
" is no longer Annoyed.";
367 return ppl.
name() +
" is no longer Frustrated.";
369 return ppl.
name() +
" is no longer Sleeping.";
371 return ppl.
name() +
" is no longer Sticky.";
373 return ppl.
name() +
" is no longer Frozen.";
376 return "ERROR: " +
getName(item) +
" does not generate a useLine on a peoplemon.";
412 return "Now you smell bad enough to keep Peoplemon away.";
414 return "ERROR: " +
getName(item) +
" does not generate a useLine on the player.";
419 using T = std::underlying_type_t<Id>;
420 const T
id =
static_cast<T
>(tm);
422 const T mid =
id - 200;
443 return turnNumber == 1 ? 4.f : 1.f;
445 if (levelRatio >= 4.f)
return 8.f;
446 if (levelRatio >= 2.f)
return 4.f;
447 if (levelRatio > 1.f)
return 2.f;
450 return (
static_cast<float>(turnNumber) + 10.f) / 10.f;
457 BL_LOG_WARN <<
"Got a clone or masterball unexpectedly";
460 BL_LOG_ERROR <<
"Got a non-peopleball: " << ball;
Type
The type classification of an item. This is used to determine when an item may be used and how to use...
Category
Represents a category that an item can belong to. Used for bag sorting.
Id
Represents an item in its simplist form.
@ EvolveStone
The item is used to evolve peoplemon.
@ Useless
Items who's only use is to be sold.
@ Peopleball
The item is used to catch peoplemon.
@ Unknown
Invalid type for Unknown items.
@ KeyItem
The item is a key item.
@ TargetPeoplemon
The item is used on a peoplemon.
@ PlayerModifier
The item modifiers player state (ie repel)
@ HoldItem
The item may be held by Peoplemon.
@ Unknown
Unknown item category.
@ Key
Key items. Covers ids [101, 200].
@ TM
TM's. Covers ids [201, 499].
@ Regular
Regular items. Covers ids [1, 100].
Stat
Represents a single stat. Used as an offset to access Stats as an array.
Core classes and functionality for both the editor and game.
Base class for battlers in the game. This provides storage for peoplemon and turn choices.
Loads and stores metadata surrounding items in the game.
std::unordered_map< item::Id, std::string > names
std::unordered_map< item::Id, std::string > descriptions
std::unordered_map< item::Id, std::int32_t > values
static std::string getUseLine(Id item, const pplmn::OwnedPeoplemon &ppl)
Returns the text to display when the item is used on the given peoplemon.
static void setDataSource(file::ItemDB &source)
Set the data source for the item methods.
static const std::string & getDescription(item::Id item)
Returns the description of the given item.
static Category getCategory(Id item)
Returns the category of the given item.
static pplmn::MoveId getTmMove(Id tm)
Returns the move taught by the TM.
static void useOnPlayer(Id item, player::State &state)
Uses the given item on the player.
static const std::string & getName(item::Id item)
Returns the name of the given item.
static bool canUseInBattle(Id item)
Returns whether or not the item can be used in battle.
static Type getType(Id item)
Returns the type of the given item.
static void useOnPeoplemon(Id item, pplmn::OwnedPeoplemon &ppl, std::vector< pplmn::OwnedPeoplemon > *team=nullptr, std::vector< pplmn::BattlePeoplemon > *battleTeam=nullptr)
Applies the given item to the peoplemon.
static float getPeopleballRate(Id ball, pplmn::Id ppl, int turnNumber, float levelRatio)
Returns the catch rate for the given peopleball.
static const std::vector< Id > & validIds()
Returns the list of valid item ids.
static int getValue(item::Id item)
Returns the value of the given item.
static Id cast(unsigned int id)
Helper function to cast a raw id to an item Id.
static bool hasEffectOnPeoplemon(Id item, const pplmn::OwnedPeoplemon &ppl)
Returns whether or not the given item will affect the peoplemon.
static bool hasEffectOnPlayer(Id item, const player::State &state)
Returns whether or not the given item will affect the player.
Represents a Peoplemon in battle. Stores some extra state that only exists in battle....
OwnedPeoplemon & base()
Returns the wrapped peoplemon.
static unsigned int pp(MoveId move)
Returns the max pp of the given move.
static const std::string & name(MoveId move)
Returns the name of the given move.
static MoveId cast(unsigned int id)
Converts the given raw id to a move id, or Unknown if invalid.
unsigned int maxPP
The pp to restore to. Increased max pp is stored here.
unsigned int curPP
The current pp of the move.
MoveId id
The id of the move.
Represents an instance of a peoplemon. Can be a wild peoplemon, trainer, or player peoplemon....
const Stats & currentEVs() const
Returns the current EVs of this peoplemon.
Ailment & currentAilment()
Access the current ailment of this peoplemon.
std::uint16_t & currentHp()
Access the current HP.
void awardEVs(const Stats &evs)
Award EVs to this peoplemon.
Stats currentStats() const
Returns the computed stats for the peoplemon. Does not take into account changes during battle.
void giveHealth(int hp)
Restores HP and ensures it does not go over max HP.
const OwnedMove * knownMoves() const
Returns the moves known by this Peoplemon.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static Type type(Id id)
Returns the type of the Peoplemon.
Stats for Peoplemon. This struct is used for base stats, EVs, IVs, battle increases/decreases,...
static constexpr int MaxEVStat
The maximum amount that a single EV can be.
int & get(Stat stat)
Returns a reference to the given stat.
static const char * statToString(Stat stat)
Converts the given stat to its string representation.
static constexpr int MaxEVSum
The maximum amount that EVs or IVs can sum to.
int sum() const
Returns the sum of the 6 stats that are used for EV calculations.