Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <vector>
- #include <string>
- #include <map>
- #include <cstdint>
- using int8 = int8_t;
- using int16 = int16_t;
- using int32 = int32_t;
- using uint8 = uint8_t;
- using uint16 = uint16_t;
- using uint32 = uint32_t;
- namespace RpgGame
- {
- class Player;
- class Game;
- enum class GameState { CreatePlayer, Menu, Battle, Inventory, Instruction };
- enum class BattleAction { Attack, Magic, Item, Run };
- enum class BattleState { SelectAction, SelectTarget, SelectSkill, SelectItem, Animation, Result };
- enum class BattlePhase { PlayerTurn, EnemyTurn, EndBattle };
- enum class Elemental { Fire, Water, Earth, Air, Ice, Lava, Dark, Light, None };
- enum class Specialization { Archer, Magician, Warrior, Thief, None };
- enum class EnemiesNames {};
- struct Point { int32 x{0}, y{0}; };
- struct Location { Point coord{}; std::string name; int32 h{0}, w{0}; bool isSafe{false}; };
- struct Quest { bool finished{ false }; bool isMoney{ false }; std::string name; std::vector<bool> aims; uint16 reward; };
- struct Item { int id{0}; int8 cost{0}; std::string name; };
- struct Skill { int id{0}; std::string name; uint32 damage{0}, manaCost{0}; uint8 cooldown{0}, aimCount{0}; bool isDamaging{true}; Elemental damageType{Elemental::None}; };
- struct Spec { Specialization name{Specialization::None}; uint32 buffXp{0}; uint32 buffCurrentMp{0}; };
- class GamePerson
- {
- public:
- [[nodiscard]] virtual uint32 getAttackPower(const Skill* skill = nullptr) const = 0;
- [[nodiscard]] virtual uint32 getDefense() const = 0;
- [[nodiscard]] virtual uint32 getSpeed() const = 0;
- [[nodiscard]] virtual std::vector<int> getAvailableSkills() const = 0;
- void killPerson() noexcept { isAlive = false; currentHp = 0; }
- void resurrectPerson(int32 hp = 1) noexcept { isAlive = true; currentHp = hp; }
- [[nodiscard]] uint32 getCurrentHp() const noexcept { return currentHp; }
- void setCurrentHp(uint32 hp) noexcept { currentHp = (hp < maxHp) ? hp : maxHp; }
- [[nodiscard]] uint32 getCurrentMp() const noexcept { return currentMp; }
- void setCurrentMp(uint32 mp) noexcept { currentMp = (mp < maxMp) ? mp : maxMp; }
- protected:
- uint32 attack{0}, defence{0}, agility{0};
- bool isAlive{false};
- uint32 currentHp{0}, maxHp{0};
- uint32 currentMp{0}, maxMp{0};
- uint8 level{1};
- std::vector<int> skills;
- std::vector<Elemental> resists, vulnerability;
- std::map<int, uint16> currentCooldowns;
- };
- class NPS
- {
- std::string name;
- std::vector<std::string> dialogs;
- };
- class Hero : public GamePerson
- {
- public:
- void levelUp();
- Spec spec;
- };
- class Enemy : public GamePerson
- {
- public:
- explicit Enemy(EnemiesNames enemy, const Player&) : name(enemy) { resurrectPerson(); }
- bool killPerson() { GamePerson::killPerson(); return true; }
- private:
- EnemiesNames name{};
- uint32 experience{0}, gold{0};
- std::vector<uint8> items;
- };
- class Game
- {
- public:
- GameState state{GameState::CreatePlayer};
- std::map<int, Item> items;
- std::map<int, Skill> skills;
- std::vector<Location> locations;
- std::vector<Player> players;
- std::vector<NPS> npss;
- std::vector<Quest> quests;
- std::string pathToSave;
- };
- class Player
- {
- public:
- explicit Player(const std::string& name) : name(name) {}
- [[nodiscard]] int getAverageLevel() const
- {
- int total = 0, count = 0;
- for (const auto& hero : heroes)
- total += hero.level, ++count;
- return (count > 0) ? total / count : 0;
- }
- [[nodiscard]] uint32 getPlayerGold() const noexcept { return gold; }
- [[nodiscard]] int32 getPlayerSpeed() const noexcept { return speed; }
- void setPlayerSpeed(int32 newSpeed) noexcept { speed = newSpeed; }
- [[nodiscard]] std::vector<EnemiesNames> getDiscoveredEnemies() const { return discoveredEnemies; }
- [[nodiscard]] std::vector<int> getAvailableItems() const
- {
- std::vector<int> available;
- available.reserve(itemIds.size());
- for (const auto& [id, _] : itemIds)
- available.push_back(id);
- return available;
- }
- [[nodiscard]] Location getPlayerPlace(const Game& game) const
- {
- for (const auto& loc : game.locations)
- if (coords.x > loc.coord.x && coords.x < loc.coord.x + loc.w &&
- coords.y > loc.coord.y && coords.y < loc.coord.y + loc.h)
- return loc;
- return {};
- }
- void addDiscoveredEnemy(EnemiesNames enemy) { discoveredEnemies.push_back(enemy); }
- void addItem(int itemId, uint8 count) { itemIds[itemId] += count; }
- private:
- std::string name;
- uint32 gold{0};
- Point coords{};
- int32 speed{0};
- std::vector<Hero> heroes;
- std::vector<EnemiesNames> discoveredEnemies;
- std::map<int, uint8> itemIds;
- };
- std::vector<Enemy> createEnemies(const Player& player);
- void initializeGameDatabase(std::map<int, Skill>& skills, std::map<int, Item>& items);
- }
Advertisement
Add Comment
Please, Sign In to add comment