1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "item_consumable_effect.h"
22 #include "nel/misc/algo.h"
23 #include "nel/misc/i18n.h"
24 #include "../sheet_manager.h"
27 using namespace NLMISC
;
30 CItemConsumableEffectHelper
* CItemConsumableEffectHelper::getInstance()
33 static CItemConsumableEffectHelper
* instance
= NULL
;
35 instance
= new CItemConsumableEffectHelper
;
39 void CItemConsumableEffectHelper::getItemConsumableEffectText(const CItemSheet
*pIS
, string
&itemText
, sint32 itemQuality
)
41 // check if some effects are present on this item
45 for( i
=0; i
<pIS
->Consumable
.Properties
.size(); ++i
)
47 CSString eff
= pIS
->Consumable
.Properties
[i
];
52 // Get name id of effect
53 CSString name
= toUpperAscii(eff
.splitTo(':', true));
55 // Extract parameters from sheet
56 vector
<CSString
> params
;
57 CSString param
= eff
.splitTo(':', true);
58 while (!param
.empty())
60 params
.push_back(param
);
61 param
= eff
.splitTo(':', true);
64 if( name
== "SP_CHG_CHARAC" )
66 CHARACTERISTICS::TCharacteristics charac
= CHARACTERISTICS::toCharacteristic(params
[0]);
67 string characUIId
= "uiCaracId" + toString((uint8
)charac
);
69 double param1
, param2
;
70 fromString(params
[1].c_str(), param1
);
71 fromString(params
[2].c_str(), param2
);
72 sint32 bonus
= (uint32
)(param1
* itemQuality
+ param2
);
75 fromString(params
[3].c_str(), timeInSec
);
80 result
= CI18N::get("uiItemConsumableEffectUpCharac");
82 result
= CI18N::get("uiItemConsumableEffectDownCharac");
84 strFindReplace(result
, "%charac", CI18N::get(characUIId
));
85 strFindReplace(result
, "%bonus", toString(bonus
));
86 strFindReplace(result
, "%minutes", toString(timeInSec
/60));
87 strFindReplace(result
, "%secondes", toString(timeInSec
%60));
93 if ( name
== "SP_LIFE_AURA" )
97 fromString(params
[0].c_str(), regenMod
);
99 fromString(params
[1].c_str(), duration
);
101 fromString(params
[2].c_str(), radius
);
102 uint32 targetDisableTime
;
103 fromString(params
[3].c_str(), targetDisableTime
);
104 uint32 userDisableTime
;
105 fromString(params
[4].c_str(), userDisableTime
);
107 string result
= CI18N::get("uiItemConsumableEffectLifeAura");
108 strFindReplace(result
, "%modifier", toString(regenMod
));
109 strFindReplace(result
, "%minutes", toString(duration
/60));
110 strFindReplace(result
, "%secondes", toString(duration
%60));
111 strFindReplace(result
, "%radius", toString(radius
));
112 strFindReplace(result
, "%targetDisableTime", toString(targetDisableTime
));
113 strFindReplace(result
, "%userDisableTime", toString(userDisableTime
));
119 if ( name
== "SP_LIFE_AURA2" )
123 fromString(params
[0].c_str(), regenMod
);
124 uint32 bonus
= regenMod
* itemQuality
;
126 fromString(params
[1].c_str(), duration
);
128 fromString(params
[2].c_str(), radius
);
129 uint32 targetDisableTime
;
130 fromString(params
[3].c_str(), targetDisableTime
);
131 uint32 userDisableTime
;
132 fromString(params
[4].c_str(), userDisableTime
);
134 string result
= CI18N::get("uiItemConsumableEffectLifeAura");
135 strFindReplace(result
, "%modifier", toString(bonus
));
136 strFindReplace(result
, "%minutes", toString(duration
/60));
137 strFindReplace(result
, "%secondes", toString(duration
%60));
138 strFindReplace(result
, "%radius", toString(radius
));
139 strFindReplace(result
, "%targetDisableTime", "0");
140 strFindReplace(result
, "%userDisableTime", "0");
146 if ( name
== "SP_STAMINA_AURA" )
150 fromString(params
[0].c_str(), regenMod
);
152 fromString(params
[1].c_str(), duration
);
154 fromString(params
[2].c_str(), radius
);
155 uint32 targetDisableTime
;
156 fromString(params
[3].c_str(), targetDisableTime
);
157 uint32 userDisableTime
;
158 fromString(params
[4].c_str(), userDisableTime
);
160 string result
= CI18N::get("uiItemConsumableEffectStaminaAura");
161 strFindReplace(result
, "%modifier", toString(regenMod
));
162 strFindReplace(result
, "%minutes", toString(duration
/60));
163 strFindReplace(result
, "%secondes", toString(duration
%60));
164 strFindReplace(result
, "%radius", toString(radius
));
165 strFindReplace(result
, "%targetDisableTime", toString(targetDisableTime
));
166 strFindReplace(result
, "%userDisableTime", toString(userDisableTime
));
173 if ( name
== "SP_STAMINA_AURA2" )
177 fromString(params
[0].c_str(), regenMod
);
178 uint32 bonus
= regenMod
* itemQuality
;
180 fromString(params
[1].c_str(), duration
);
182 fromString(params
[2].c_str(), radius
);
183 uint32 targetDisableTime
;
184 fromString(params
[3].c_str(), targetDisableTime
);
185 uint32 userDisableTime
;
186 fromString(params
[4].c_str(), userDisableTime
);
188 string result
= CI18N::get("uiItemConsumableEffectStaminaAura");
189 strFindReplace(result
, "%modifier", toString(bonus
));
190 strFindReplace(result
, "%minutes", toString(duration
/60));
191 strFindReplace(result
, "%secondes", toString(duration
%60));
192 strFindReplace(result
, "%radius", toString(radius
));
193 strFindReplace(result
, "%targetDisableTime", "0");
194 strFindReplace(result
, "%userDisableTime", "0");
200 if ( name
== "SP_SAP_AURA" )
204 fromString(params
[0].c_str(), regenMod
);
206 fromString(params
[1].c_str(), duration
);
208 fromString(params
[2].c_str(), radius
);
209 uint32 targetDisableTime
;
210 fromString(params
[3].c_str(), targetDisableTime
);
211 uint32 userDisableTime
;
212 fromString(params
[4].c_str(), userDisableTime
);
214 string result
= CI18N::get("uiItemConsumableEffectSapAura");
215 strFindReplace(result
, "%modifier", toString(regenMod
));
216 strFindReplace(result
, "%minutes", toString(duration
/60));
217 strFindReplace(result
, "%secondes", toString(duration
%60));
218 strFindReplace(result
, "%radius", toString(radius
));
219 strFindReplace(result
, "%targetDisableTime", toString(targetDisableTime
));
220 strFindReplace(result
, "%userDisableTime", toString(userDisableTime
));
226 if ( name
== "SP_SAP_AURA2" )
230 fromString(params
[0].c_str(), regenMod
);
231 uint32 bonus
= regenMod
* itemQuality
;
233 fromString(params
[1].c_str(), duration
);
235 fromString(params
[2].c_str(), radius
);
236 uint32 targetDisableTime
;
237 fromString(params
[3].c_str(), targetDisableTime
);
238 uint32 userDisableTime
;
239 fromString(params
[4].c_str(), userDisableTime
);
241 string result
= CI18N::get("uiItemConsumableEffectSapAura");
242 strFindReplace(result
, "%modifier", toString(bonus
));
243 strFindReplace(result
, "%minutes", toString(duration
/60));
244 strFindReplace(result
, "%secondes", toString(duration
%60));
245 strFindReplace(result
, "%radius", toString(radius
));
246 strFindReplace(result
, "%targetDisableTime", "0");
247 strFindReplace(result
, "%userDisableTime", "0");
253 // skill modifier consumables
254 //---------------------------
257 if( name
== "SP_MOD_DEFENSE" )
259 if( toLowerAscii(params
[0]) == "dodge" )
260 result
= CI18N::get("uiItemConsumableEffectModDodgeSuccess");
262 if( toLowerAscii(params
[0]) == "parry" )
263 result
= CI18N::get("uiItemConsumableEffectModParrySuccess");
265 result
= CI18N::get("uiItemConsumableEffectModDefenseSuccess");
268 if( name
== "SP_MOD_MELEE_SUCCESS" )
270 result
= CI18N::get("uiItemConsumableEffectModMeleeSuccess");
272 if( name
== "SP_MOD_RANGE_SUCCESS" )
274 result
= CI18N::get("uiItemConsumableEffectModRangeSuccess");
276 if( name
== "SP_MOD_MAGIC_SUCCESS" )
278 result
= CI18N::get("uiItemConsumableEffectModMagicSuccess");
280 if( name
== "SP_MOD_CRAFT_SUCCESS" )
282 result
= CI18N::get("uiItemConsumableEffectModCraftSuccess");
284 if( name
== "SP_MOD_FORAGE_SUCCESS" )
286 if( toLowerAscii(params
[0]) == "commonecosystem" )
287 result
= CI18N::get("uiItemConsumableEffectModForageSuccess");
288 if( toLowerAscii(params
[0]) == "desert" )
289 result
= CI18N::get("uiItemConsumableEffectModDesertForageSuccess");
290 if( toLowerAscii(params
[0]) == "forest" )
291 result
= CI18N::get("uiItemConsumableEffectModForestForageSuccess");
292 if( toLowerAscii(params
[0]) == "lacustre" )
293 result
= CI18N::get("uiItemConsumableEffectModLacustreForageSuccess");
294 if( toLowerAscii(params
[0]) == "jungle" )
295 result
= CI18N::get("uiItemConsumableEffectModJungleForageSuccess");
296 if( toLowerAscii(params
[0]) == "primaryroot" )
297 result
= CI18N::get("uiItemConsumableEffectModPrimaryRootForageSuccess");
300 if( !result
.empty() )
302 double param1
, param2
;
303 fromString(params
[paramIdx
], param1
);
304 fromString(params
[paramIdx
+1], param2
);
305 sint32 modifier
= (sint32
)(param1
* itemQuality
+ param2
);
307 strFindReplace(result
, "%modifier", "@{E42F}-"+toString(modifier
)+"@{FFFF}");
309 strFindReplace(result
, "%modifier", "@{0F0F}"+toString(modifier
)+"@{FFFF}");
312 fromString(params
[paramIdx
+2], timeInSec
);
313 strFindReplace(result
, "%minutes", toString(timeInSec
/60));
314 strFindReplace(result
, "%secondes", toString(timeInSec
%60));
321 // Display consumable effects info.
322 strFindReplace(itemText
, "%consumable_effects", effects
);