The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
257 lines
7.8 KiB
257 lines
7.8 KiB
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2018 - 2023 OneLoneCoder.com
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
be used to endorse or promote products derived from this software without specific
|
|
prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
SUCH DAMAGE.
|
|
|
|
Portions of this software are copyright © 2023 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
#pragma once
|
|
#include <string>
|
|
#include <functional>
|
|
#include <map>
|
|
#include "olcPixelGameEngine.h"
|
|
#include "olcUTIL_DataFile.h"
|
|
#include "AttributableStat.h"
|
|
#include "BitwiseEnum.h"
|
|
|
|
class Crawler;
|
|
class ItemInfo;
|
|
class ItemProps;
|
|
|
|
using IT=std::string;
|
|
using ITCategory=std::string;
|
|
|
|
using ItemScript=std::function<bool(Crawler*,ItemProps)>;
|
|
|
|
enum class EquipSlot{
|
|
HELMET= 0b0000'0001,
|
|
WEAPON= 0b0000'0010,
|
|
ARMOR= 0b0000'0100,
|
|
GLOVES= 0b0000'1000,
|
|
PANTS= 0b0001'0000,
|
|
SHOES= 0b0010'0000,
|
|
RING1= 0b0100'0000,
|
|
RING2= 0b1000'0000,
|
|
NONE= 0b0000'0000,
|
|
};
|
|
|
|
enum class CompactText{
|
|
COMPACT,
|
|
NON_COMPACT
|
|
};
|
|
|
|
using enum CompactText;
|
|
|
|
struct Stats:ItemAttributable{
|
|
public:
|
|
inline Stats&operator+=(Stats&rhs){
|
|
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
|
|
A(a)+=rhs.get_readOnly(a);
|
|
}
|
|
return *this;
|
|
};
|
|
inline Stats&operator+=(ItemAttributable&rhs){
|
|
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
|
|
A(a)+=rhs.get_readOnly(a);
|
|
}
|
|
return *this;
|
|
};
|
|
auto begin()const{
|
|
return attributes.begin();
|
|
}
|
|
auto end()const{
|
|
return attributes.end();
|
|
}
|
|
const std::string GetStatsString(CompactText compact=NON_COMPACT)const;
|
|
};
|
|
|
|
struct EnhancementInfo{
|
|
private:
|
|
std::vector<Stats>enhancementStats;
|
|
public:
|
|
void SetAttribute(int enhanceLevel,ItemAttribute attribute,int value);
|
|
const Stats&operator[](int level)const;
|
|
const size_t size()const;
|
|
};
|
|
|
|
//You cannot create instances of this class, access sets from ItemSet::sets and add the appropriate set bonuses.
|
|
class ItemSet{
|
|
friend class ItemInfo;
|
|
static std::map<std::string,ItemSet>sets;
|
|
std::array<Stats,8>setBonuses;
|
|
std::string name;
|
|
std::vector<std::pair<int,Stats>>setBonusBreakpoints;
|
|
public:
|
|
//NO CONSTRUCTOR REQUIRED!
|
|
//Specify the piece count(1-8) for a set bonus to be applied.
|
|
static void AddSetBonus(std::string setName,int pieceCount,Stats&bonuses);
|
|
//Gets a set bonus based on number of pieces (1-8)
|
|
const Stats&operator[](int setPieces)const;
|
|
const std::string&GetSetName()const;
|
|
bool operator<(const ItemSet&rhs)const{
|
|
return name<rhs.name;
|
|
}
|
|
const std::vector<std::pair<int,Stats>>&GetSetBonusBreakpoints()const;
|
|
};
|
|
|
|
class Item{
|
|
friend class Inventory;
|
|
friend class Crawler;
|
|
friend class Menu;
|
|
private:
|
|
//The amount in the current item stack.
|
|
uint32_t amt;
|
|
uint8_t enhancementLevel;
|
|
ItemInfo*it;
|
|
bool IsEquippable()const;
|
|
public:
|
|
Item();
|
|
Item(uint32_t amt,IT item,uint8_t enhancementLevel=0);
|
|
uint32_t Amt();
|
|
std::string Name();
|
|
std::string Description(CompactText compact=COMPACT);
|
|
const ITCategory Category()const;
|
|
EquipSlot GetEquipSlot();
|
|
Decal*Decal();
|
|
const Stats GetStats()const;
|
|
ItemScript&OnUseAction();
|
|
float CastTime();
|
|
float CooldownTime();
|
|
bool IsBlank();
|
|
uint8_t EnhancementLevel()const;
|
|
void EnhanceItem();
|
|
static Item BLANK;
|
|
bool operator==(const Item&rhs)const;
|
|
const std::optional<const ItemSet *const>&ItemSet()const;
|
|
};
|
|
|
|
class Inventory{
|
|
friend class ItemInfo;
|
|
friend class Item;
|
|
public:
|
|
static void AddItem(IT it,uint32_t amt=1,bool monsterDrop=false);
|
|
//Returns the actual amount available in your main inventory.
|
|
static uint32_t GetItemCount(IT it);
|
|
static Item CopyItem(IT it);
|
|
static Item&GetItem(IT it);
|
|
//Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times.
|
|
static bool UseItem(IT it,uint32_t amt=1);
|
|
static bool RemoveItem(IT it,ITCategory inventory,uint32_t amt = 1);
|
|
static bool RemoveItem(IT it,uint32_t amt=1);
|
|
static std::vector<Item>&get(ITCategory itemCategory);
|
|
static void Clear(ITCategory itemCategory);
|
|
static void EquipItem(Item&it,EquipSlot slot);
|
|
static void UnequipItem(EquipSlot slot);
|
|
static EquipSlot GetSlotEquippedIn(Item&it);
|
|
static Item*GetEquip(EquipSlot slot);
|
|
static const std::map<ItemSet,int>GetEquippedItemSets();
|
|
|
|
static bool SwapItems(ITCategory itemCategory,uint32_t slot1,uint32_t slot2);
|
|
//Makes sure this is a valid category. Will error out if it doesn't exist! Use for ERROR HANDLING!
|
|
static bool ValidateItemCategory(ITCategory itemCategory){
|
|
get(itemCategory);
|
|
return true;
|
|
}
|
|
private:
|
|
static void InsertIntoSortedInv(IT item);
|
|
static void InsertIntoStageInventoryCategory(IT item,uint32_t amt,bool monsterDrop);
|
|
static bool ExecuteAction(IT item);
|
|
static std::map<IT,Item>_inventory;
|
|
static std::map<EquipSlot,Item*>equipment;
|
|
//Only contains "1" of every item, as this is a map to index items and not the actual storage of items!
|
|
static std::map<ITCategory,std::vector<Item>>sortedInv;
|
|
};
|
|
|
|
class ItemProps{
|
|
friend class ItemInfo;
|
|
utils::datafile*scriptProps;
|
|
utils::datafile*customProps;
|
|
public:
|
|
ItemProps(utils::datafile*scriptProps,utils::datafile*customProps);
|
|
int GetIntProp(std::string prop);
|
|
float GetFloatProp(std::string prop);
|
|
std::string GetStringProp(std::string prop);
|
|
};
|
|
|
|
class ItemInfo{
|
|
friend class Inventory;
|
|
std::string name;
|
|
std::string description;
|
|
std::string category;
|
|
float castTime=0;
|
|
float cooldownTime=0;
|
|
EquipSlot slot;
|
|
EnhancementInfo enhancement;
|
|
Decal*img;
|
|
std::string set="";
|
|
//Returns true if the item can be used, false otherwise
|
|
std::string useFunc="";
|
|
//Custom properties for this specific item's script.
|
|
static utils::datafile NOPROPS;
|
|
ItemProps customProps;
|
|
|
|
private:
|
|
static void InitializeScripts();
|
|
static void InitializeSets();
|
|
static std::map<std::string,EquipSlot>nameToEquipSlot;
|
|
public:
|
|
static void InitializeItems();
|
|
ItemInfo();
|
|
std::string Name();
|
|
std::string Description();
|
|
ITCategory Category();
|
|
Decal*Decal();
|
|
/*
|
|
For the useFunc, return true if the item can be used, false otherwise.
|
|
*/
|
|
ItemScript&OnUseAction();
|
|
Stats GetStats(int enhancementLevel);
|
|
float CastTime();
|
|
float CooldownTime();
|
|
EquipSlot Slot();
|
|
const std::optional<const ItemSet *const>ItemSet()const;
|
|
};
|
|
|
|
class ItemOverlay{
|
|
ItemInfo it;
|
|
float timer=0;
|
|
float xOffset=0;
|
|
float width=0; //How wide the entire label is.
|
|
static std::vector<ItemOverlay>items;
|
|
ItemOverlay(ItemInfo item);
|
|
public:
|
|
static void AddToItemOverlay(const ItemInfo&it);
|
|
static void Update();
|
|
static void Draw();
|
|
void ResetTimer();
|
|
}; |