46static bool mStorageCount =
false;
48static bool mNPCCount =
false;
49static bool mNPCPostCount =
false;
53static std::map<int, Ability> mAbilities;
54static Timer mAbilityRechargeUpdateTimer;
61 event.setInt(
"id",
id);
62 event.setInt(
"oldValue", old);
63 event.setInt(
"newValue", mData.
mAttributes.find(
id)->second);
67void triggerStat(
int id,
const std::string &changed,
int old1,
int old2 = 0)
69 auto it = mData.
mStats.find(
id);
71 event.setInt(
"id",
id);
72 event.setInt(
"base", it->second.base);
73 event.setInt(
"mod", it->second.mod);
74 event.setInt(
"exp", it->second.exp);
75 event.setInt(
"expNeeded", it->second.expNeed);
76 event.setString(
"changed", changed);
77 event.setInt(
"oldValue1", old1);
78 event.setInt(
"oldValue2", old2);
105 auto it = mData.
mStats.find(
id);
106 if (it != mData.
mStats.end())
107 return it->second.base;
114 int old = mData.
mStats[id].base;
115 mData.
mStats[id].base = value;
122 auto it = mData.
mStats.find(
id);
123 if (it != mData.
mStats.end())
124 return it->second.mod;
131 int old = mData.
mStats[id].mod;
132 mData.
mStats[id].mod = value;
139 auto it = mData.
mStats.find(
id);
140 if (it != mData.
mStats.end())
141 return it->second.base + it->second.mod;
148 auto it = mData.
mStats.find(
id);
150 if (it != mData.
mStats.end())
153 b = it->second.expNeed;
165 int oldExp = mData.
mStats[id].exp;
166 int oldExpNeed = mData.
mStats[id].expNeed;
167 mData.
mStats[id].exp = have;
168 mData.
mStats[id].expNeed = need;
188 mInventory->
setItem(index,
id, amount);
203 return mStorageCount;
208 int old = mStorageCount;
209 mStorageCount = count;
214 event.setInt(
"oldCount", old);
215 event.setInt(
"newCount", count);
235 event.setInt(
"oldCount", old);
236 event.setInt(
"newCount", count);
243 return mNPCPostCount;
248 int old = mNPCPostCount;
249 mNPCPostCount = count;
254 event.setInt(
"oldCount", old);
255 event.setInt(
"newCount", count);
264 return mBuySellState;
270 mBuySellState = buySellState;
272 if (buySellState != old)
275 event.setInt(
"oldState", old);
276 event.setInt(
"newState", buySellState);
285 mAbilities.erase(
id);
290 Log::info(
"AbilityUpdate Skill #%d -- (%d/%d) -> %d",
id, current, max,
292 mAbilities[id].currentMana = current;
293 mAbilities[id].neededMana = max;
294 mAbilities[id].recharge = recharge;
317 if (mAbilityRechargeUpdateTimer.
passed())
319 mAbilityRechargeUpdateTimer.
set(100);
321 for (
auto &[
id, ability] : mAbilities)
323 ability.currentMana += ability.recharge;
324 if (ability.currentMana > ability.neededMana)
326 ability.currentMana = ability.neededMana;
347 int newState =
event.getInt(
"newState");
351 if (mInventory ==
nullptr)
366 mInventory =
nullptr;
367 mEquipment =
nullptr;
void clear()
Clears equipment.
Item * getEquipment(int slotIndex) const
Get equipment at the given slot.
void listen(Event::Channel channel)
void clear()
Reset all item slots.
void setItem(int index, int id, int quantity)
Sets the item at the given position.
Represents one or more instances of a certain item type.
void event(Event::Channel channel, const Event &event) override
Simple timer that can be used to check if a certain amount of time has passed.
bool passed() const
Returns whether the timer has passed.
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
void info(const char *log_text,...) LOG_PRINTF_ATTR
InventoryHandler * getInventoryHandler()
A database like namespace which holds global info about the localplayer.
int getStatBase(int id)
Returns the base value of the given stat.
Inventory * getInventory()
Returns the player's inventory.
int getStatEffective(int id)
Returns the current effective value of the given stat.
int getStorageCount()
Returns the number of currently open storage windows.
void setBackend(const PlayerInfoBackend &backend)
Changes the internal PlayerInfoBackend reference;.
const std::map< int, Ability > & getAbilityStatus()
Returns the status all abilities.
void setBuySellState(BuySellState buySellState)
Sets which buy, sell, or related interaction the player is currently involved in.
void setNPCInteractionCount(int count)
Sets the number of currently open NPC interaction windows.
Equipment * getEquipment()
Returns the player's equipment.
void logic()
Does necessary updates every tick.
bool isTalking()
Returns true if the player is involved in a NPC interaction, false otherwise.
void setNPCPostCount(int count)
Sets the number of currently open NPC post windows.
void triggerAttr(int id, int old)
void init()
Initializes some internals.
void setStatExperience(int id, int have, int need, bool notify)
Changes the experience of the given stat.
void triggerStat(int id, const std::string &changed, int old1, int old2=0)
void setAbilityStatus(int id, int current, int max, int recharge)
Changes the status of the given ability.
void setStatBase(int id, int value, bool notify)
Changes the base value of the given stat.
BuySellState getBuySellState()
Returns the current buy, sell, or related interaction the player is involved in.
void setAttribute(int id, int value, bool notify)
Changes the value of the given attribute.
void clearInventory()
Clears the player's inventory and equipment.
void clearAbilityStatus(int id)
Removes the status for the given ability.
int getNPCPostCount()
Returns the number of currently open NPC post windows.
int getAttribute(int id)
Returns the value of the given attribute.
void setStorageCount(int count)
Sets the number of currently open storage windows.
int getStatMod(int id)
Returns the modifier for the given stat.
void setInventoryItem(int index, int id, int amount)
Changes the inventory item at the given slot.
std::pair< int, int > getStatExperience(int id)
Returns the experience of the given stat.
void setStatMod(int id, int value, bool notify)
Changes the modifier for the given stat.
int getNPCInteractionCount()
Returns the number of currently open NPC interaction windows.
Backend for core player information.
std::map< int, Stat > mStats
std::map< int, int > mAttributes