Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / item_consumable_effect.cpp
blob2e4499228a3665215b10fc80bd138d07ac79903c
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
20 #include "stdpch.h"
21 #include "item_consumable_effect.h"
22 #include "nel/misc/algo.h"
23 #include "nel/misc/i18n.h"
24 #include "../sheet_manager.h"
26 using namespace std;
27 using namespace NLMISC;
30 CItemConsumableEffectHelper* CItemConsumableEffectHelper::getInstance()
32 // Singleton
33 static CItemConsumableEffectHelper* instance = NULL;
34 if (instance == NULL)
35 instance = new CItemConsumableEffectHelper;
36 return instance;
39 void CItemConsumableEffectHelper::getItemConsumableEffectText(const CItemSheet *pIS, string &itemText, sint32 itemQuality)
41 // check if some effects are present on this item
42 string effects("");
44 uint i;
45 for( i=0; i<pIS->Consumable.Properties.size(); ++i )
47 CSString eff = pIS->Consumable.Properties[i];
49 if (eff.empty())
50 continue;
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);
74 uint32 timeInSec;
75 fromString(params[3].c_str(), timeInSec);
77 string result;
79 if (bonus >= 0)
80 result = CI18N::get("uiItemConsumableEffectUpCharac");
81 else
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));
89 effects += result;
90 effects += "\n";
93 if ( name == "SP_LIFE_AURA" )
96 uint16 regenMod;
97 fromString(params[0].c_str(), regenMod);
98 uint32 duration;
99 fromString(params[1].c_str(), duration);
100 uint32 radius;
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));
115 effects += result;
116 effects += "\n";
119 if ( name == "SP_LIFE_AURA2" )
122 uint16 regenMod;
123 fromString(params[0].c_str(), regenMod);
124 uint32 bonus = regenMod * itemQuality;
125 uint32 duration;
126 fromString(params[1].c_str(), duration);
127 uint32 radius;
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");
142 effects += result;
143 effects += "\n";
146 if ( name == "SP_STAMINA_AURA" )
149 uint16 regenMod;
150 fromString(params[0].c_str(), regenMod);
151 uint32 duration;
152 fromString(params[1].c_str(), duration);
153 uint32 radius;
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));
168 effects += result;
169 effects += "\n";
173 if ( name == "SP_STAMINA_AURA2" )
176 uint16 regenMod;
177 fromString(params[0].c_str(), regenMod);
178 uint32 bonus = regenMod * itemQuality;
179 uint32 duration;
180 fromString(params[1].c_str(), duration);
181 uint32 radius;
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");
196 effects += result;
197 effects += "\n";
200 if ( name == "SP_SAP_AURA" )
203 uint16 regenMod;
204 fromString(params[0].c_str(), regenMod);
205 uint32 duration;
206 fromString(params[1].c_str(), duration);
207 uint32 radius;
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));
222 effects += result;
223 effects += "\n";
226 if ( name == "SP_SAP_AURA2" )
229 uint16 regenMod;
230 fromString(params[0].c_str(), regenMod);
231 uint32 bonus = regenMod * itemQuality;
232 uint32 duration;
233 fromString(params[1].c_str(), duration);
234 uint32 radius;
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");
249 effects += result;
250 effects += "\n";
253 // skill modifier consumables
254 //---------------------------
255 string result("");
256 uint8 paramIdx = 0;
257 if( name == "SP_MOD_DEFENSE" )
259 if( toLowerAscii(params[0]) == "dodge" )
260 result = CI18N::get("uiItemConsumableEffectModDodgeSuccess");
261 else
262 if( toLowerAscii(params[0]) == "parry" )
263 result = CI18N::get("uiItemConsumableEffectModParrySuccess");
264 else
265 result = CI18N::get("uiItemConsumableEffectModDefenseSuccess");
266 paramIdx++;
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");
298 paramIdx++;
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);
306 if( modifier < 0 )
307 strFindReplace(result, "%modifier", "@{E42F}-"+toString(modifier)+"@{FFFF}");
308 else
309 strFindReplace(result, "%modifier", "@{0F0F}"+toString(modifier)+"@{FFFF}");
311 uint32 timeInSec;
312 fromString(params[paramIdx+2], timeInSec);
313 strFindReplace(result, "%minutes", toString(timeInSec/60));
314 strFindReplace(result, "%secondes", toString(timeInSec%60));
316 effects += result;
317 effects += "\n";
321 // Display consumable effects info.
322 strFindReplace(itemText, "%consumable_effects", effects);