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_special_effect.h"
22 #include "nel/misc/algo.h"
23 #include "nel/misc/i18n.h"
24 #include "../sheet_manager.h"
27 using namespace NLMISC
;
29 CItemSpecialEffectHelper::CItemSpecialEffectHelper()
31 // Register special effects
32 registerItemSpecialEffect("ISE_FIGHT_ADD_CRITICAL");
33 registerItemSpecialEffect("ISE_FIGHT_VAMPIRISM");
34 registerItemSpecialEffect("ISE_MAGIC_DIVINE_INTERVENTION");
35 registerItemSpecialEffect("ISE_MAGIC_SHOOT_AGAIN");
36 registerItemSpecialEffect("ISE_CRAFT_ADD_STAT_BONUS");
37 registerItemSpecialEffect("ISE_CRAFT_ADD_LIMIT");
38 registerItemSpecialEffect("ISE_FORAGE_ADD_RM");
39 registerItemSpecialEffect("ISE_FORAGE_NO_RISK");
42 CItemSpecialEffectHelper
* CItemSpecialEffectHelper::getInstance()
45 static CItemSpecialEffectHelper
* instance
= NULL
;
47 instance
= new CItemSpecialEffectHelper
;
51 void CItemSpecialEffectHelper::registerItemSpecialEffect(const string
&name
)
53 // store parameters to be replaced in UIstring
54 vector
<string
> params
;
57 string ucs
= CI18N::get("uiItemFX_" + name
);
60 // locate and store parameters
65 p
= s
.splitTo('%', true);
66 while (!p
.empty() && !s
.empty())
68 if (s
[0] == 'p' || s
[0] == 'n' || s
[0] == 'r' || s
[0] == 's')
72 if (s
.size() >=2 && (uint8
)s
[1] < (uint8
)'\x80' && isdigit(s
[1]))
74 params
.push_back(tmp
);
76 p
= s
.splitTo('%', true);
79 effectMap
.insert(make_pair(name
, params
));
82 void CItemSpecialEffectHelper::getItemSpecialEffectText(const CItemSheet
*pIS
, string
&itemText
)
84 // check if some effects are present on this item
85 bool firstEffect
= false;
87 effects
+= getEffect(pIS
->getEffect1(), firstEffect
);
88 effects
+= getEffect(pIS
->getEffect2(), firstEffect
);
89 effects
+= getEffect(pIS
->getEffect3(), firstEffect
);
90 effects
+= getEffect(pIS
->getEffect4(), firstEffect
);
92 if(!effects
.empty()) effects
+= "\n";
94 // Display special effects info.
95 strFindReplace(itemText
, "%special_effects", effects
);
98 string
CItemSpecialEffectHelper::getEffect(const std::string
&effect
, bool &first
)
101 CSString eff
= effect
;
106 // Get name id of effect
107 CSString name
= toUpperAscii(eff
.splitTo(':', true));
109 // Extract parameters from sheet
110 vector
<CSString
> params
;
111 CSString param
= eff
.splitTo(':', true);
112 while (!param
.empty())
114 params
.push_back(param
);
115 param
= eff
.splitTo(':', true);
118 // Check number of arguments
119 uint n
= (uint
)(effectMap
[name
]).size();
120 if (params
.size() != n
)
122 nlinfo("Bad arguments for : %s", effect
.c_str());
126 // Get translated ui string
127 result
= CI18N::get("uiItemFX_" + name
);
129 // Add endline if it's not the first
133 result
= "\n" + result
;
135 // Replace each parameters with value from sheet
136 //nlinfo("name = %s", name.c_str());
137 for (uint i
=0 ; i
<n
; i
++)
139 string replace
, p
= effectMap
[name
][i
];
140 //nlinfo("param = %s : %s", p.c_str(), params[i].c_str());
142 // %p : percent format
146 fromString(params
[i
], f
);
147 replace
= toString("%.1f", f
*100);
149 // %n : integer format
150 else if (p
[1] == 'n')
153 fromString(params
[i
], a
);
154 replace
= toString("%d", a
);
157 else if (p
[1] == 'r')
160 fromString(params
[i
], f
);
161 replace
= toString("%.1f", f
);
163 // %s : string format
164 else if (p
[1] == 's')
173 strFindReplace(result
, p
.c_str(), replace
);