1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "item_special_effect.h"
19 #include "nel/misc/algo.h"
20 #include "nel/misc/i18n.h"
21 #include "../sheet_manager.h"
24 using namespace NLMISC
;
26 CItemSpecialEffectHelper::CItemSpecialEffectHelper()
28 // Register special effects
29 registerItemSpecialEffect("ISE_FIGHT_ADD_CRITICAL");
30 registerItemSpecialEffect("ISE_FIGHT_VAMPIRISM");
31 registerItemSpecialEffect("ISE_MAGIC_DIVINE_INTERVENTION");
32 registerItemSpecialEffect("ISE_MAGIC_SHOOT_AGAIN");
33 registerItemSpecialEffect("ISE_CRAFT_ADD_STAT_BONUS");
34 registerItemSpecialEffect("ISE_CRAFT_ADD_LIMIT");
35 registerItemSpecialEffect("ISE_FORAGE_ADD_RM");
36 registerItemSpecialEffect("ISE_FORAGE_NO_RISK");
39 CItemSpecialEffectHelper
* CItemSpecialEffectHelper::getInstance()
42 static CItemSpecialEffectHelper
* instance
= NULL
;
44 instance
= new CItemSpecialEffectHelper
;
48 void CItemSpecialEffectHelper::registerItemSpecialEffect(const string
&name
)
50 // store parameters to be replaced in UIstring
51 vector
<string
> params
;
54 string ucs
= CI18N::get("uiItemFX_" + name
);
57 // locate and store parameters
62 p
= s
.splitTo('%', true);
63 while (!p
.empty() && !s
.empty())
65 if (s
[0] == 'p' || s
[0] == 'n' || s
[0] == 'r' || s
[0] == 's')
69 if (s
.size() >=2 && (uint8
)s
[1] < (uint8
)'\x80' && isdigit(s
[1]))
71 params
.push_back(tmp
);
73 p
= s
.splitTo('%', true);
76 effectMap
.insert(make_pair(name
, params
));
79 void CItemSpecialEffectHelper::getItemSpecialEffectText(const CItemSheet
*pIS
, string
&itemText
)
81 // check if some effects are present on this item
82 bool firstEffect
= false;
84 effects
+= getEffect(pIS
->getEffect1(), firstEffect
);
85 effects
+= getEffect(pIS
->getEffect2(), firstEffect
);
86 effects
+= getEffect(pIS
->getEffect3(), firstEffect
);
87 effects
+= getEffect(pIS
->getEffect4(), firstEffect
);
89 if(!effects
.empty()) effects
+= "\n";
91 // Display special effects info.
92 strFindReplace(itemText
, "%special_effects", effects
);
95 string
CItemSpecialEffectHelper::getEffect(const std::string
&effect
, bool &first
)
98 CSString eff
= effect
;
103 // Get name id of effect
104 CSString name
= toUpperAscii(eff
.splitTo(':', true));
106 // Extract parameters from sheet
107 vector
<CSString
> params
;
108 CSString param
= eff
.splitTo(':', true);
109 while (!param
.empty())
111 params
.push_back(param
);
112 param
= eff
.splitTo(':', true);
115 // Check number of arguments
116 uint n
= (uint
)(effectMap
[name
]).size();
117 if (params
.size() != n
)
119 nlinfo("Bad arguments for : %s", effect
.c_str());
123 // Get translated ui string
124 result
= CI18N::get("uiItemFX_" + name
);
126 // Add endline if it's not the first
130 result
= "\n" + result
;
132 // Replace each parameters with value from sheet
133 //nlinfo("name = %s", name.c_str());
134 for (uint i
=0 ; i
<n
; i
++)
136 string replace
, p
= effectMap
[name
][i
];
137 //nlinfo("param = %s : %s", p.c_str(), params[i].c_str());
139 // %p : percent format
143 fromString(params
[i
], f
);
144 replace
= toString("%.1f", f
*100);
146 // %n : integer format
147 else if (p
[1] == 'n')
150 fromString(params
[i
], a
);
151 replace
= toString("%d", a
);
154 else if (p
[1] == 'r')
157 fromString(params
[i
], f
);
158 replace
= toString("%.1f", f
);
160 // %s : string format
161 else if (p
[1] == 's')
170 strFindReplace(result
, p
.c_str(), replace
);