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.
352 lines
13 KiB
352 lines
13 KiB
1 year ago
|
#pragma region License
|
||
1 year ago
|
/*
|
||
|
License (OLC-3)
|
||
|
~~~~~~~~~~~~~~~
|
||
|
|
||
11 months ago
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||
1 year ago
|
|
||
|
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.
|
||
1 year ago
|
|
||
|
Portions of this software are copyright © 2023 The FreeType
|
||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||
|
All rights reserved.
|
||
1 year ago
|
*/
|
||
1 year ago
|
#pragma endregion
|
||
1 year ago
|
#pragma once
|
||
|
#include <string>
|
||
|
#include <functional>
|
||
|
#include <map>
|
||
|
#include "olcPixelGameEngine.h"
|
||
1 year ago
|
#include "olcUTIL_DataFile.h"
|
||
1 year ago
|
#include "AttributableStat.h"
|
||
1 year ago
|
#include "BitwiseEnum.h"
|
||
1 year ago
|
#include <optional>
|
||
12 months ago
|
#include "Merchant.h"
|
||
12 months ago
|
#include "CraftingRequirement.h"
|
||
12 months ago
|
#include "FunctionPriming.h"
|
||
1 year ago
|
|
||
11 months ago
|
class AiL;
|
||
1 year ago
|
class ItemInfo;
|
||
1 year ago
|
class ItemProps;
|
||
1 year ago
|
|
||
1 year ago
|
using IT=std::string;
|
||
|
using ITCategory=std::string;
|
||
1 year ago
|
|
||
11 months ago
|
using ItemScript=std::function<bool(AiL*,ItemProps)>;
|
||
1 year ago
|
|
||
1 year ago
|
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,
|
||
|
};
|
||
|
|
||
1 year ago
|
enum class CompactText{
|
||
|
COMPACT,
|
||
12 months ago
|
NON_COMPACT,
|
||
|
CRAFTING_INFO
|
||
1 year ago
|
};
|
||
|
|
||
|
using enum CompactText;
|
||
|
|
||
1 year ago
|
struct Stats:ItemAttributable{
|
||
12 months ago
|
static safemap<int,float>maxDamageReductionTable;
|
||
|
static void InitializeDamageReductionTable();
|
||
1 year ago
|
public:
|
||
12 months ago
|
inline static const float&GetDamageReductionPct(int defense){
|
||
|
return maxDamageReductionTable.at(std::clamp(defense,0,1000));
|
||
|
}
|
||
1 year ago
|
inline Stats&operator+=(Stats&rhs){
|
||
12 months ago
|
for(auto&[key,value]:ItemAttribute::attributes){
|
||
|
A(value)+=rhs.get_readOnly(value);
|
||
1 year ago
|
}
|
||
1 year ago
|
return *this;
|
||
1 year ago
|
};
|
||
1 year ago
|
inline Stats&operator+=(ItemAttributable&rhs){
|
||
12 months ago
|
for(auto&[key,value]:ItemAttribute::attributes){
|
||
|
A(value)+=rhs.get_readOnly(value);
|
||
1 year ago
|
}
|
||
|
return *this;
|
||
|
};
|
||
1 year ago
|
auto begin()const{
|
||
|
return attributes.begin();
|
||
|
}
|
||
|
auto end()const{
|
||
|
return attributes.end();
|
||
|
}
|
||
12 months ago
|
const size_t size()const{
|
||
|
return attributes.size();
|
||
|
}
|
||
1 year ago
|
const std::string GetStatsString(CompactText compact=NON_COMPACT)const;
|
||
12 months ago
|
friend const bool operator==(const Stats&lhs,const Stats&rhs){return lhs.attributes==rhs.attributes;}
|
||
1 year ago
|
};
|
||
|
|
||
12 months ago
|
class Stats;
|
||
|
class CraftingRequirement;
|
||
|
|
||
|
struct EnhancementLevelInfo{
|
||
|
const Stats&stats;
|
||
|
const CraftingRequirement&craftingRequirement;
|
||
|
EnhancementLevelInfo(const Stats&stats,const CraftingRequirement&craftingRequirement);
|
||
|
};
|
||
|
|
||
1 year ago
|
struct EnhancementInfo{
|
||
|
private:
|
||
|
std::vector<Stats>enhancementStats;
|
||
12 months ago
|
std::vector<CraftingRequirement>craftingRequirements;
|
||
12 months ago
|
uint8_t availableChapter=1;
|
||
1 year ago
|
public:
|
||
12 months ago
|
void SetAttribute(int enhanceLevel,ItemAttribute attribute,float value);
|
||
12 months ago
|
void SetCraftingRequirements(const int enhanceLevel,const std::vector<std::pair<IT,int>>&requiredItems,const uint32_t goldCost,const uint8_t availableChapter);
|
||
12 months ago
|
const bool CanBeEnhanced()const;
|
||
12 months ago
|
const uint8_t AvailableChapter()const;
|
||
12 months ago
|
const EnhancementLevelInfo operator[](int level)const;
|
||
1 year ago
|
const size_t size()const;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
//You cannot create instances of this class, access sets from ItemSet::sets and add the appropriate set bonuses.
|
||
1 year ago
|
class ItemSet{
|
||
1 year ago
|
friend class ItemInfo;
|
||
1 year ago
|
static std::map<std::string,ItemSet>sets;
|
||
|
std::array<Stats,8>setBonuses;
|
||
1 year ago
|
std::string name;
|
||
1 year ago
|
std::vector<std::pair<int,Stats>>setBonusBreakpoints;
|
||
1 year ago
|
public:
|
||
1 year ago
|
//NO CONSTRUCTOR REQUIRED!
|
||
1 year ago
|
//Specify the piece count(1-8) for a set bonus to be applied.
|
||
1 year ago
|
static void AddSetBonus(std::string setName,int pieceCount,Stats&bonuses);
|
||
1 year ago
|
//Gets a set bonus based on number of pieces (1-8)
|
||
1 year ago
|
const Stats&operator[](int setPieces)const;
|
||
1 year ago
|
const std::string&GetSetName()const;
|
||
|
bool operator<(const ItemSet&rhs)const{
|
||
|
return name<rhs.name;
|
||
|
}
|
||
1 year ago
|
const std::vector<std::pair<int,Stats>>&GetSetBonusBreakpoints()const;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
class Item{
|
||
1 year ago
|
friend class Inventory;
|
||
11 months ago
|
friend class AiL;
|
||
1 year ago
|
friend class Menu;
|
||
12 months ago
|
friend class SaveFile;
|
||
12 months ago
|
friend void Merchant::PurchaseItem(IT item,uint32_t amt);
|
||
12 months ago
|
friend void Merchant::SellItem(std::weak_ptr<Item>,uint32_t amt);
|
||
1 year ago
|
private:
|
||
1 year ago
|
//The amount in the current item stack.
|
||
1 year ago
|
uint32_t amt;
|
||
1 year ago
|
uint8_t enhancementLevel;
|
||
1 year ago
|
ItemInfo*it;
|
||
12 months ago
|
Stats randomizedStats;
|
||
|
|
||
12 months ago
|
void SetAmt(uint32_t newAmt);
|
||
12 months ago
|
static ItemEnhancementFunctionPrimingData enhanceFunctionPrimed;
|
||
12 months ago
|
static int IsBlankStaticCallCounter;
|
||
|
const bool _IsBlank()const;
|
||
1 year ago
|
public:
|
||
1 year ago
|
Item();
|
||
1 year ago
|
Item(uint32_t amt,IT item,uint8_t enhancementLevel=0);
|
||
12 months ago
|
uint32_t Amt()const;
|
||
|
//Use this for places where the item name is used for item tracking. NOT for drawing. Hooks directly into item info's base item name.
|
||
|
const std::string&ActualName()const;
|
||
|
//Use for places where the item name is actually displayed. Provides modified text that shows additional information like enhancement levels.
|
||
|
const std::string DisplayName()const;
|
||
|
const std::string Description(CompactText compact=COMPACT)const;
|
||
1 year ago
|
const ITCategory Category()const;
|
||
12 months ago
|
const EquipSlot GetEquipSlot()const;
|
||
|
const::Decal*const Decal()const;
|
||
1 year ago
|
const Stats GetStats()const;
|
||
12 months ago
|
const ItemScript&OnUseAction()const;
|
||
|
const float CastTime()const;
|
||
12 months ago
|
const bool UseDuringCast()const; //When true, the item is activated during the cast instead of after the cast.
|
||
12 months ago
|
const float CooldownTime()const;
|
||
12 months ago
|
//Use ISBLANK macro instead!! This should not be called directly!!
|
||
12 months ago
|
const bool IsBlank()const;
|
||
|
const uint8_t EnhancementLevel()const;
|
||
12 months ago
|
//NOTE: This function must be primed with CanEnhanceItem()! Otherwise it will cause a runtime error.
|
||
12 months ago
|
void EnhanceItem(uint8_t qty=1);
|
||
12 months ago
|
//Whether or not this item can be enhanced/crafted.
|
||
|
const bool EnhancementIsPossible()const;
|
||
|
//A verification function that confirms if we are allowed to perform an enhancement. MUST BE CALLED to prime EnhanceItem() function!!
|
||
12 months ago
|
const bool CanEnhanceItem(uint8_t qty=1)const;
|
||
12 months ago
|
static std::shared_ptr<Item>BLANK;
|
||
12 months ago
|
const std::optional<const::ItemSet*const>ItemSet()const;
|
||
12 months ago
|
const bool IsEquippable()const;
|
||
12 months ago
|
const bool IsCraftable()const;
|
||
12 months ago
|
const bool IsWeapon()const;
|
||
|
const bool IsArmor()const;
|
||
|
const bool IsAccessory()const;
|
||
12 months ago
|
const uint32_t BuyValue()const;
|
||
|
const uint32_t SellValue()const;
|
||
|
const bool CanBeSold()const;
|
||
|
const bool CanBePurchased()const;
|
||
12 months ago
|
const Stats&RandomStats()const;
|
||
12 months ago
|
void RandomizeStats();
|
||
12 months ago
|
const bool HasRandomizedStats()const;
|
||
12 months ago
|
const EnhancementInfo&GetEnhancementInfo()const;
|
||
12 months ago
|
//Use ISBLANK macro instead!! This should not be called directly!!
|
||
|
static bool IsBlank(std::shared_ptr<Item>item);
|
||
|
//Use ISBLANK macro instead!! This should not be called directly!!
|
||
|
static bool IsBlank(std::weak_ptr<Item>item);
|
||
12 months ago
|
friend const bool operator==(std::shared_ptr<Item>lhs,std::shared_ptr<Item>rhs){return lhs->it==rhs->it&&lhs->randomizedStats==rhs->randomizedStats;};
|
||
12 months ago
|
friend const bool operator==(std::shared_ptr<Item>lhs,const IT&rhs){return lhs->ActualName()==rhs;};
|
||
12 months ago
|
friend const bool operator==(std::weak_ptr<Item>lhs,std::weak_ptr<Item>rhs){return !lhs.expired()&&!rhs.expired()&&lhs.lock()->it==rhs.lock()->it&&lhs.lock()->randomizedStats==rhs.lock()->randomizedStats;};
|
||
12 months ago
|
friend const bool operator==(std::weak_ptr<Item>lhs,const IT&rhs){return !lhs.expired()&&lhs.lock()->ActualName()==rhs;};
|
||
|
friend const bool operator==(const IT&lhs,std::weak_ptr<Item>rhs){return operator==(rhs,lhs);};
|
||
|
friend const bool operator==(const IT&lhs,std::shared_ptr<Item>rhs){return operator==(rhs,lhs);};
|
||
1 year ago
|
};
|
||
|
|
||
|
class Inventory{
|
||
1 year ago
|
friend class ItemInfo;
|
||
1 year ago
|
friend class Item;
|
||
12 months ago
|
friend class SaveFile;
|
||
1 year ago
|
public:
|
||
12 months ago
|
static std::weak_ptr<Item>AddItem(IT it,uint32_t amt=1,bool monsterDrop=false);
|
||
1 year ago
|
//Returns the actual amount available in your main inventory.
|
||
12 months ago
|
[[nodiscard]] static uint32_t GetItemCount(IT it);
|
||
12 months ago
|
static std::vector<std::shared_ptr<Item>>CopyItem(IT it);
|
||
|
static std::vector<std::weak_ptr<Item>>GetItem(IT it);
|
||
1 year ago
|
//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.
|
||
1 year ago
|
static bool UseItem(IT it,uint32_t amt=1);
|
||
12 months ago
|
static bool RemoveItem(std::weak_ptr<Item>itemRef,ITCategory inventory,uint32_t amt = 1);
|
||
|
static bool RemoveItem(std::weak_ptr<Item>itemRef,uint32_t amt=1);
|
||
12 months ago
|
static const std::vector<std::shared_ptr<Item>>&get(ITCategory itemCategory);
|
||
12 months ago
|
static const std::weak_ptr<Item>GetInventorySlot(ITCategory itemCategory,size_t slot);
|
||
1 year ago
|
static void Clear(ITCategory itemCategory);
|
||
12 months ago
|
static void EquipItem(const std::weak_ptr<Item>it,EquipSlot slot);
|
||
1 year ago
|
static void UnequipItem(EquipSlot slot);
|
||
12 months ago
|
static EquipSlot GetSlotEquippedIn(const std::weak_ptr<Item>it);
|
||
|
static std::weak_ptr<Item>GetEquip(EquipSlot slot);
|
||
1 year ago
|
static const std::map<ItemSet,int>GetEquippedItemSets();
|
||
1 year ago
|
|
||
1 year ago
|
static bool SwapItems(ITCategory itemCategory,uint32_t slot1,uint32_t slot2);
|
||
1 year ago
|
//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;
|
||
|
}
|
||
1 year ago
|
private:
|
||
12 months ago
|
static void InsertIntoSortedInv(std::shared_ptr<Item>itemRef);
|
||
1 year ago
|
static void InsertIntoStageInventoryCategory(IT item,uint32_t amt,bool monsterDrop);
|
||
1 year ago
|
static bool ExecuteAction(IT item);
|
||
12 months ago
|
static std::multimap<IT,std::shared_ptr<Item>>_inventory;
|
||
12 months ago
|
static std::map<EquipSlot,std::weak_ptr<Item>>equipment;
|
||
1 year ago
|
//Only contains "1" of every item, as this is a map to index items and not the actual storage of items!
|
||
12 months ago
|
static std::map<ITCategory,std::vector<std::shared_ptr<Item>>>sortedInv;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
class ItemProps{
|
||
|
friend class ItemInfo;
|
||
|
utils::datafile*scriptProps;
|
||
|
utils::datafile*customProps;
|
||
|
public:
|
||
|
ItemProps(utils::datafile*scriptProps,utils::datafile*customProps);
|
||
12 months ago
|
int GetIntProp(const std::string&prop,size_t index=0)const;
|
||
|
float GetFloatProp(const std::string&prop,size_t index=0)const;
|
||
|
std::string GetStringProp(const std::string&prop,size_t index=0)const;
|
||
|
const uint32_t PropCount(const std::string&prop)const;
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
class ItemInfo{
|
||
1 year ago
|
friend class Inventory;
|
||
12 months ago
|
friend class Menu;
|
||
1 year ago
|
std::string name;
|
||
1 year ago
|
std::string description;
|
||
|
std::string category;
|
||
1 year ago
|
float castTime=0;
|
||
|
float cooldownTime=0;
|
||
1 year ago
|
EquipSlot slot;
|
||
1 year ago
|
EnhancementInfo enhancement;
|
||
1 year ago
|
::Decal*img;
|
||
1 year ago
|
std::string set="";
|
||
1 year ago
|
//Returns true if the item can be used, false otherwise
|
||
1 year ago
|
std::string useFunc="";
|
||
|
//Custom properties for this specific item's script.
|
||
|
static utils::datafile NOPROPS;
|
||
|
ItemProps customProps;
|
||
12 months ago
|
uint32_t buyValue=0;
|
||
|
uint32_t sellValue=0;
|
||
12 months ago
|
//If true, this item's action is activated at the beginning of the cast instead of after the cast completes.
|
||
|
bool useDuringCast=false;
|
||
12 months ago
|
Stats minStats;
|
||
|
Stats maxStats;
|
||
1 year ago
|
private:
|
||
|
static void InitializeScripts();
|
||
1 year ago
|
static void InitializeSets();
|
||
1 year ago
|
static std::map<std::string,EquipSlot>nameToEquipSlot;
|
||
12 months ago
|
static std::vector<std::shared_ptr<Item>>craftableConsumables;
|
||
1 year ago
|
public:
|
||
|
static void InitializeItems();
|
||
1 year ago
|
ItemInfo();
|
||
12 months ago
|
const std::string&Name()const;
|
||
|
const std::string&Description()const;
|
||
|
const ITCategory Category()const;
|
||
|
const::Decal*const Decal()const;
|
||
1 year ago
|
/*
|
||
1 year ago
|
For the useFunc, return true if the item can be used, false otherwise.
|
||
1 year ago
|
*/
|
||
12 months ago
|
const ItemScript&OnUseAction()const;
|
||
12 months ago
|
const Stats GetStats(int enhancementLevel)const;
|
||
12 months ago
|
const float CastTime()const;
|
||
|
const float CooldownTime()const;
|
||
|
const EquipSlot Slot()const;
|
||
12 months ago
|
const std::optional<const::ItemSet*const>ItemSet()const;
|
||
12 months ago
|
ItemInfo&operator[](const IT&item);
|
||
12 months ago
|
const uint32_t GetBuyValue()const;
|
||
|
const uint32_t GetSellValue()const;
|
||
|
const bool CanBeSold()const;
|
||
|
const bool CanBePurchased()const;
|
||
12 months ago
|
const bool UseDuringCast()const;
|
||
12 months ago
|
const EnhancementInfo&GetEnhancementInfo()const;
|
||
12 months ago
|
const bool IsEquippable()const;
|
||
12 months ago
|
const bool IsCraftable()const;
|
||
12 months ago
|
const bool IsWeapon()const;
|
||
|
const bool IsArmor()const;
|
||
|
const bool IsAccessory()const;
|
||
12 months ago
|
const Stats GetMinStats()const;
|
||
|
const Stats GetMaxStats()const;
|
||
|
Stats RandomizeStats();
|
||
1 year ago
|
};
|
||
|
|
||
|
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();
|
||
1 year ago
|
void ResetTimer();
|
||
12 months ago
|
};
|
||
|
|
||
|
#define ISBLANK(itemRef) Item::IsBlank(itemRef)
|