2018-06-23 23:05:36 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2018-06-23 23:05:36 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2018-06-23 23:05:36 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2018-06-23 23:05:36 +02:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2018-06-23 23:05:36 +02:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef ITEM_HPP_
|
|
|
|
#define ITEM_HPP_
|
|
|
|
|
2018-06-25 22:30:38 +02:00
|
|
|
#include <string>
|
|
|
|
|
2018-12-29 02:23:23 +01:00
|
|
|
#include <gk/core/IntTypes.hpp>
|
2020-06-20 01:37:12 +02:00
|
|
|
#include <gk/core/ISerializable.hpp>
|
2018-12-29 02:23:23 +01:00
|
|
|
|
2018-06-25 18:12:15 +02:00
|
|
|
#include "ItemType.hpp"
|
2020-01-30 17:25:48 +09:00
|
|
|
#include "TilesDef.hpp"
|
2018-06-23 23:05:36 +02:00
|
|
|
|
2020-06-20 01:37:12 +02:00
|
|
|
class Item : public gk::ISerializable {
|
2018-06-23 23:05:36 +02:00
|
|
|
public:
|
2020-01-30 17:25:48 +09:00
|
|
|
Item() = default;
|
2020-02-17 15:54:19 +09:00
|
|
|
Item(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label);
|
2020-01-30 17:25:48 +09:00
|
|
|
|
2020-01-31 15:04:04 +09:00
|
|
|
void serialize(sf::Packet &packet) const override;
|
2020-01-30 17:25:48 +09:00
|
|
|
void deserialize(sf::Packet &packet) override;
|
2018-06-25 22:30:38 +02:00
|
|
|
|
2020-02-17 15:54:19 +09:00
|
|
|
const std::string &stringID() const { return m_stringID; }
|
2018-12-28 06:57:34 +01:00
|
|
|
const std::string &label() const { return m_label; }
|
2018-06-23 23:05:36 +02:00
|
|
|
|
2020-02-17 15:54:19 +09:00
|
|
|
std::string modName() const { return m_stringID.substr(0, m_stringID.find_first_of(":")); }
|
2020-01-30 21:53:28 +09:00
|
|
|
|
2018-06-23 23:05:36 +02:00
|
|
|
u32 id() const { return m_id; }
|
2020-01-30 17:25:48 +09:00
|
|
|
const TilesDef &tiles() const { return m_tiles; }
|
2018-06-25 16:32:32 +02:00
|
|
|
|
|
|
|
bool isBlock() const { return m_isBlock; }
|
2018-12-28 21:23:26 +01:00
|
|
|
void setIsBlock(bool isBlock) { m_isBlock = isBlock; }
|
|
|
|
|
2018-06-29 21:55:47 +02:00
|
|
|
u8 harvestCapability() const { return m_harvestCapability; }
|
|
|
|
void setHarvestCapability(u8 harvestCapability) { m_harvestCapability = harvestCapability; }
|
|
|
|
|
|
|
|
float miningSpeed() const { return m_miningSpeed; }
|
|
|
|
void setMiningSpeed(float miningSpeed) { m_miningSpeed = miningSpeed; }
|
|
|
|
|
2020-03-29 12:26:01 +02:00
|
|
|
void addGroup(const std::string &name, u16 value) { m_groups.emplace(name, value); }
|
|
|
|
bool hasGroup(const std::string &name) const { return m_groups.find(name) != m_groups.end(); }
|
|
|
|
|
|
|
|
u16 getGroupValue(const std::string &name) const {
|
|
|
|
auto it = m_groups.find(name);
|
|
|
|
if (it == m_groups.end())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2020-05-22 04:54:34 +02:00
|
|
|
static void initUsertype(sol::state &lua);
|
|
|
|
|
2018-06-25 18:12:15 +02:00
|
|
|
protected:
|
|
|
|
bool m_isBlock = false;
|
|
|
|
|
2018-06-23 23:05:36 +02:00
|
|
|
private:
|
|
|
|
u32 m_id = 0;
|
2020-01-30 17:25:48 +09:00
|
|
|
TilesDef m_tiles;
|
2018-06-29 21:55:47 +02:00
|
|
|
|
2020-02-17 15:54:19 +09:00
|
|
|
std::string m_stringID;
|
2018-12-28 06:57:34 +01:00
|
|
|
std::string m_label;
|
|
|
|
|
2018-06-29 21:55:47 +02:00
|
|
|
u8 m_harvestCapability = 0;
|
|
|
|
float m_miningSpeed = 1;
|
2020-03-29 12:26:01 +02:00
|
|
|
|
|
|
|
std::unordered_map<std::string, u16> m_groups;
|
2018-06-23 23:05:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ITEM_HPP_
|