|
|
|
#pragma region License
|
|
|
|
/*
|
|
|
|
License (OLC-3)
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.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 © 2024 The FreeType
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
All rights reserved.
|
|
|
|
*/
|
|
|
|
#pragma endregion
|
|
|
|
#include "AttributableStat.h"
|
|
|
|
#include "olcUTIL_DataFile.h"
|
|
|
|
#include "DEFINES.h"
|
|
|
|
#include "Item.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "Monster.h"
|
|
|
|
|
|
|
|
INCLUDE_DATA
|
|
|
|
|
|
|
|
ItemAttributable&ItemAttributable::operator+=(Stats&rhs){
|
|
|
|
for(auto&[key,value]:ItemAttribute::attributes){
|
|
|
|
A(value)+=rhs.get_readOnly(value);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
};
|
|
|
|
|
|
|
|
ItemAttributable&ItemAttributable::operator+=(ItemAttributable&rhs){
|
|
|
|
for(auto&[key,value]:ItemAttribute::attributes){
|
|
|
|
A(value)+=rhs.get_readOnly(value);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
};
|
|
|
|
|
|
|
|
ItemAttribute::ItemAttribute(std::string_view originalName,std::string_view name,bool isPct,bool showDecimal,std::string_view modifies)
|
|
|
|
:originalName(std::string(originalName)),name(std::string(name)),isPct(isPct),showDecimal(showDecimal),modifies(std::string(modifies)){}
|
|
|
|
|
|
|
|
void ItemAttribute::Initialize(){
|
|
|
|
for(auto&[key,size]:DATA["Stats"]){
|
|
|
|
std::string modifies="";
|
|
|
|
if(DATA["Stats"][key].HasProperty("Modifies")){
|
|
|
|
modifies=DATA["Stats"][key]["Modifies"].GetString();
|
|
|
|
}
|
|
|
|
bool showDecimal=false;
|
|
|
|
if(DATA["Stats"][key].HasProperty("Show Decimal")){
|
|
|
|
showDecimal=DATA["Stats"][key]["Show Decimal"].GetBool();
|
|
|
|
}
|
|
|
|
attributes.insert(key,ItemAttribute(key,DATA["Stats"][key]["Display Name"].GetString(),DATA["Stats"][key]["Percentage"].GetBool(),showDecimal,modifies));
|
|
|
|
}
|
|
|
|
attributes.SetInitialized();
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemAttribute&ItemAttribute::Get(const std::string_view name,const std::optional<std::variant<Player*,Monster*>>target){
|
|
|
|
if(target.has_value()){
|
|
|
|
attributes.at(std::string(name)).target=target;
|
|
|
|
}
|
|
|
|
return attributes.at(std::string(name));
|
|
|
|
}
|
|
|
|
const std::string_view ItemAttribute::Name()const{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
const bool ItemAttribute::DisplayAsPercent()const{
|
|
|
|
return isPct;
|
|
|
|
}
|
|
|
|
|
|
|
|
//WARNING! Implemented for map sorting!!!
|
|
|
|
const bool ItemAttribute::operator<(const ItemAttribute&rhs)const{
|
|
|
|
return originalName<rhs.originalName;
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string_view ItemAttribute::Modifies()const{
|
|
|
|
return modifies;
|
|
|
|
};
|
|
|
|
|
|
|
|
float&operator+=(float&lhs,const ItemAttribute&rhs){
|
|
|
|
if(rhs.target){
|
|
|
|
#pragma region Acquire Stats based on Object Type
|
|
|
|
float statModifierTotal=0;
|
|
|
|
std::vector<Buff>statUpBuffs;
|
|
|
|
const ItemAttributable*stats=nullptr;
|
|
|
|
if(std::holds_alternative<Player*>(rhs.target.value())){
|
|
|
|
statUpBuffs=std::get<Player*>(rhs.target.value())->GetBuffs(STAT_UP);
|
|
|
|
stats=&std::get<Player*>(rhs.target.value())->GetStats();
|
|
|
|
}else{
|
|
|
|
statUpBuffs=std::get<Monster*>(rhs.target.value())->GetBuffs(STAT_UP);
|
|
|
|
stats=&std::get<Monster*>(rhs.target.value())->GetStats();
|
|
|
|
}
|
|
|
|
for(const Buff&b:statUpBuffs){
|
|
|
|
if(b.attr.count(rhs)){
|
|
|
|
statModifierTotal+=b.intensity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#pragma endregion
|
|
|
|
if(rhs.DisplayAsPercent()){ //This is a percentage-based stat modifier.
|
|
|
|
if(rhs.Modifies().length()>0){
|
|
|
|
lhs+=stats->A_Read(rhs.Modifies())*statModifierTotal;
|
|
|
|
}else{
|
|
|
|
lhs+=stats->A_Read(rhs)*statModifierTotal;
|
|
|
|
}
|
|
|
|
}else{ //This is a flat stat modifier.
|
|
|
|
lhs+=statModifierTotal;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
ERR("WARNING! Did not specify a target using the Get() ItemAttribute parameter!");
|
|
|
|
}
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
float&operator-=(float&lhs,const ItemAttribute&rhs){
|
|
|
|
if(rhs.target){
|
|
|
|
#pragma region Acquire Stats based on Object Type
|
|
|
|
float statModifierTotal=0;
|
|
|
|
std::vector<Buff>statUpBuffs;
|
|
|
|
const ItemAttributable*stats=nullptr;
|
|
|
|
if(std::holds_alternative<Player*>(rhs.target.value())){
|
|
|
|
statUpBuffs=std::get<Player*>(rhs.target.value())->GetBuffs(STAT_UP);
|
|
|
|
stats=&std::get<Player*>(rhs.target.value())->GetStats();
|
|
|
|
}else{
|
|
|
|
statUpBuffs=std::get<Monster*>(rhs.target.value())->GetBuffs(STAT_UP);
|
|
|
|
stats=&std::get<Monster*>(rhs.target.value())->GetStats();
|
|
|
|
}
|
|
|
|
for(const Buff&b:statUpBuffs){
|
|
|
|
if(b.attr.count(rhs)){
|
|
|
|
statModifierTotal+=b.intensity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#pragma endregion
|
|
|
|
if(rhs.DisplayAsPercent()){ //This is a percentage-based stat modifier.
|
|
|
|
if(rhs.Modifies().length()>0){
|
|
|
|
lhs-=stats->A_Read(rhs.Modifies())*statModifierTotal;
|
|
|
|
}else{
|
|
|
|
lhs-=stats->A_Read(rhs)*statModifierTotal;
|
|
|
|
}
|
|
|
|
}else{ //This is a flat stat modifier.
|
|
|
|
lhs-=statModifierTotal;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
ERR("WARNING! Did not specify a target using the Get() ItemAttribute parameter!");
|
|
|
|
}
|
|
|
|
return lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool ItemAttribute::operator==(const ItemAttribute&rhs)const{
|
|
|
|
return originalName==rhs.originalName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const bool ItemAttribute::ShowAsDecimal()const{
|
|
|
|
return showDecimal;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string_view ItemAttribute::ActualName()const{
|
|
|
|
return originalName;
|
|
|
|
}
|