khanat-opennel-code/code/ryzom/client/src/interface_v3/item_consumable_effect.cpp

322 lines
11 KiB
C++
Raw Normal View History

2010-05-06 00:08:41 +00:00
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdpch.h"
#include "item_consumable_effect.h"
#include "nel/misc/algo.h"
#include "nel/misc/i18n.h"
#include "../sheet_manager.h"
using namespace std;
using namespace NLMISC;
CItemConsumableEffectHelper* CItemConsumableEffectHelper::getInstance()
{
// Singleton
static CItemConsumableEffectHelper* instance = NULL;
if (instance == NULL)
instance = new CItemConsumableEffectHelper;
return instance;
}
void CItemConsumableEffectHelper::getItemConsumableEffectText(const CItemSheet *pIS, ucstring &itemText, sint32 itemQuality)
{
// check if some effects are present on this item
ucstring effects("");
uint i;
for( i=0; i<pIS->Consumable.Properties.size(); ++i )
{
CSString eff = pIS->Consumable.Properties[i];
if (eff == "")
continue;
// Get name id of effect
CSString name = toUpper(eff.splitTo(':', true));
// Extract parameters from sheet
vector<CSString> params;
CSString param = eff.splitTo(':', true);
while (param != "")
{
params.push_back(param);
param = eff.splitTo(':', true);
}
if( name == "SP_CHG_CHARAC" )
{
CHARACTERISTICS::TCharacteristics charac = CHARACTERISTICS::toCharacteristic(params[0]);
string characUIId = "uiCaracId" + toString((uint8)charac);
double param1, param2;
fromString(params[1].c_str(), param1);
fromString(params[2].c_str(), param2);
2010-07-08 14:05:15 +00:00
sint32 bonus = (uint32)(param1 * itemQuality + param2);
2010-05-06 00:08:41 +00:00
uint32 timeInSec;
fromString(params[3].c_str(), timeInSec);
2010-07-08 14:05:15 +00:00
ucstring result;
if (bonus >= 0)
result = CI18N::get("uiItemConsumableEffectUpCharac");
else
result = CI18N::get("uiItemConsumableEffectDownCharac");
strFindReplace(result, "%charac", CI18N::get(characUIId));
strFindReplace(result, "%bonus", toString(bonus));
2010-05-06 00:08:41 +00:00
strFindReplace(result, "%minutes", toString(timeInSec/60));
strFindReplace(result, "%secondes", toString(timeInSec%60));
effects += result;
effects += "\n";
}
2010-07-08 14:05:15 +00:00
if ( name == "SP_LIFE_AURA" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectLifeAura");
strFindReplace(result, "%modifier", toString(regenMod));
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
strFindReplace(result, "%targetDisableTime", toString(targetDisableTime));
strFindReplace(result, "%userDisableTime", toString(userDisableTime));
2010-05-06 00:08:41 +00:00
2010-07-08 14:05:15 +00:00
effects += result;
effects += "\n";
}
2011-05-26 12:33:04 +00:00
if ( name == "SP_LIFE_AURA2" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 bonus = regenMod * itemQuality;
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectLifeAura");
strFindReplace(result, "%modifier", toString(bonus));
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
2011-05-31 19:51:26 +00:00
strFindReplace(result, "%targetDisableTime", "0");
strFindReplace(result, "%userDisableTime", "0");
2011-05-26 12:33:04 +00:00
effects += result;
effects += "\n";
}
2010-07-08 14:05:15 +00:00
if ( name == "SP_STAMINA_AURA" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectStaminaAura");
strFindReplace(result, "%modifier", toString(regenMod));
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
strFindReplace(result, "%targetDisableTime", toString(targetDisableTime));
strFindReplace(result, "%userDisableTime", toString(userDisableTime));
effects += result;
effects += "\n";
}
2011-05-26 12:33:04 +00:00
if ( name == "SP_STAMINA_AURA2" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 bonus = regenMod * itemQuality;
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectStaminaAura");
2011-05-31 19:51:26 +00:00
strFindReplace(result, "%modifier", toString(bonus));
2011-05-26 12:33:04 +00:00
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
2011-05-31 19:51:26 +00:00
strFindReplace(result, "%targetDisableTime", "0");
strFindReplace(result, "%userDisableTime", "0");
2011-05-26 12:33:04 +00:00
effects += result;
effects += "\n";
}
2010-07-08 14:05:15 +00:00
if ( name == "SP_SAP_AURA" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectSapAura");
strFindReplace(result, "%modifier", toString(regenMod));
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
strFindReplace(result, "%targetDisableTime", toString(targetDisableTime));
strFindReplace(result, "%userDisableTime", toString(userDisableTime));
effects += result;
effects += "\n";
}
2010-05-06 00:08:41 +00:00
2011-05-26 12:33:04 +00:00
if ( name == "SP_SAP_AURA2" )
{
uint16 regenMod;
fromString(params[0].c_str(), regenMod);
uint32 bonus = regenMod * itemQuality;
uint32 duration;
fromString(params[1].c_str(), duration);
uint32 radius;
fromString(params[2].c_str(), radius);
uint32 targetDisableTime;
fromString(params[3].c_str(), targetDisableTime);
uint32 userDisableTime;
fromString(params[4].c_str(), userDisableTime);
ucstring result = CI18N::get("uiItemConsumableEffectSapAura");
strFindReplace(result, "%modifier", toString(bonus));
strFindReplace(result, "%minutes", toString(duration/60));
strFindReplace(result, "%secondes", toString(duration%60));
strFindReplace(result, "%radius", toString(radius));
2011-05-31 19:51:26 +00:00
strFindReplace(result, "%targetDisableTime", "0");
strFindReplace(result, "%userDisableTime", "0");
2011-05-26 12:33:04 +00:00
effects += result;
effects += "\n";
}
2010-05-06 00:08:41 +00:00
// skill modifier consumables
//---------------------------
ucstring result("");
uint8 paramIdx = 0;
if( name == "SP_MOD_DEFENSE" )
{
if( toLower(params[0]) == "dodge" )
result = CI18N::get("uiItemConsumableEffectModDodgeSuccess");
else
if( toLower(params[0]) == "parry" )
result = CI18N::get("uiItemConsumableEffectModParrySuccess");
else
result = CI18N::get("uiItemConsumableEffectModDefenseSuccess");
paramIdx++;
}
if( name == "SP_MOD_MELEE_SUCCESS" )
{
result = CI18N::get("uiItemConsumableEffectModMeleeSuccess");
}
if( name == "SP_MOD_RANGE_SUCCESS" )
{
result = CI18N::get("uiItemConsumableEffectModRangeSuccess");
}
if( name == "SP_MOD_MAGIC_SUCCESS" )
{
result = CI18N::get("uiItemConsumableEffectModMagicSuccess");
}
if( name == "SP_MOD_CRAFT_SUCCESS" )
{
result = CI18N::get("uiItemConsumableEffectModCraftSuccess");
}
if( name == "SP_MOD_FORAGE_SUCCESS" )
{
if( toLower(params[0]) == "commonecosystem" )
result = CI18N::get("uiItemConsumableEffectModForageSuccess");
if( toLower(params[0]) == "desert" )
result = CI18N::get("uiItemConsumableEffectModDesertForageSuccess");
if( toLower(params[0]) == "forest" )
result = CI18N::get("uiItemConsumableEffectModForestForageSuccess");
if( toLower(params[0]) == "lacustre" )
result = CI18N::get("uiItemConsumableEffectModLacustreForageSuccess");
if( toLower(params[0]) == "jungle" )
result = CI18N::get("uiItemConsumableEffectModJungleForageSuccess");
if( toLower(params[0]) == "primaryroot" )
result = CI18N::get("uiItemConsumableEffectModPrimaryRootForageSuccess");
paramIdx++;
}
if( !result.empty() )
{
double param1, param2;
fromString(params[paramIdx], param1);
fromString(params[paramIdx+1], param2);
sint32 modifier = (sint32)(param1 * itemQuality + param2);
if( modifier < 0 )
strFindReplace(result, "%modifier", "@{E42F}-"+toString(modifier)+"@{FFFF}");
else
strFindReplace(result, "%modifier", "@{0F0F}"+toString(modifier)+"@{FFFF}");
uint32 timeInSec;
fromString(params[paramIdx+2], timeInSec);
strFindReplace(result, "%minutes", toString(timeInSec/60));
strFindReplace(result, "%secondes", toString(timeInSec%60));
effects += result;
effects += "\n";
}
}
// Display consumable effects info.
strFindReplace(itemText, "%consumable_effects", effects);
}