enchantments pt2

master
darkrose 2015-08-01 21:29:32 +10:00
parent f4113b0cf1
commit befcd235a5
9 changed files with 113 additions and 17 deletions

View File

@ -25,6 +25,7 @@
#include "content_mapnode.h"
#include <map>
#include "intl.h"
#include "enchantment.h"
std::map<content_t,struct ToolItemFeatures> g_content_toolitem_features;
@ -48,7 +49,7 @@ ToolItemFeatures & content_toolitem_features(std::string subname)
return g_content_toolitem_features[CONTENT_IGNORE];
}
DiggingProperties getDiggingProperties(content_t content, content_t tool)
DiggingProperties getDiggingProperties(content_t content, content_t tool, u16 data)
{
ToolItemFeatures t_features = content_toolitem_features(tool);
ContentFeatures &c_features = content_features(content);
@ -104,6 +105,20 @@ DiggingProperties getDiggingProperties(content_t content, content_t tool)
}
}
if (data != 0 && diggable) {
EnchantmentInfo info;
while (enchantment_get(&data,&info)) {
switch (info.type) {
case ENCHANTMENT_FAST:
time /= (info.level+1);
break;
case ENCHANTMENT_LONGLASTING:
wear /= (info.level+1);
break;
default:;
}
}
}
return DiggingProperties(diggable,time,wear);
}

View File

@ -105,7 +105,7 @@ struct DiggingProperties
};
// For getting the default properties, set toolid=CONTENT_IGNORE
DiggingProperties getDiggingProperties(content_t material, content_t toolid);
DiggingProperties getDiggingProperties(content_t material, content_t toolid, u16 data=0);
std::string toolitem_overlay(content_t content, std::string ol);
void content_toolitem_init();
ToolItemFeatures & content_toolitem_features(content_t i);

View File

@ -145,3 +145,14 @@ bool enchantment_get(uint16_t *data, EnchantmentInfo *info)
return true;
}
/* check if data contains an enchantment */
bool enchantment_have(uint16_t data, uint16_t enchantment)
{
EnchantmentInfo info;
while (enchantment_get(&data,&info)) {
if (info.type == enchantment)
return true;
}
return false;
}

View File

@ -40,5 +40,6 @@ struct EnchantmentInfo {
};
bool enchantment_get(uint16_t *data, EnchantmentInfo *info);
bool enchantment_have(uint16_t data, uint16_t enchantment);
#endif

View File

@ -1752,18 +1752,20 @@ void the_game(
// Get tool name. Default is "" = bare hands
content_t toolid = CONTENT_IGNORE;
u16 tooldata = 0;
InventoryList *mlist = local_inventory.getList("main");
if (mlist != NULL) {
InventoryItem *item = mlist->getItem(g_selected_item);
if (item && (item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
ToolItem *titem = (ToolItem*)item;
toolid = titem->getContent();
tooldata = titem->getData();
}
}
// Get digging properties for material and tool
content_t material = n.getContent();
DiggingProperties prop = getDiggingProperties(material, toolid);
DiggingProperties prop = getDiggingProperties(material, toolid, tooldata);
float dig_time_complete = 0.0;

View File

@ -190,6 +190,34 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f
/*
MaterialItem
*/
#ifndef SERVER
video::ITexture * MaterialItem::getImage() const
{
//if (m_data == 0 || content_features(m_content).param_type != CPT_MINERAL)
return content_features(m_content).inventory_texture;
//std::string name = content_features(m_content).inventory_texture;
//std::ostringstream os;
//os<<name;
//u8 mineral = m_data;
//std::string mineral_texture_name = mineral_features(mineral).texture;
//if (mineral_texture_name != "") {
//u32 orig_id = spec.texture.id;
//std::string texture_name = g_texturesource->getTextureName(orig_id);
////texture_name += "^blit:";
//texture_name += "^";
//texture_name += mineral_texture_name;
//u32 new_id = g_texturesource->getTextureId(texture_name);
//spec.texture = g_texturesource->getTexture(new_id);
//}
//// Get such a texture
//return g_texturesource->getTextureRaw(os.str());
}
#endif
std::wstring MaterialItem::getGuiText()
{
std::wstring txt(L" ");
@ -329,6 +357,17 @@ std::wstring CraftItem::getGuiText()
sprintf(buff,"%02d",(int)f->fuel_time%60);
txt += narrow_to_wide(buff);
}
if (m_data > 0) {
EnchantmentInfo info;
u16 data = m_data;
txt += L"\n";
while (enchantment_get(&data,&info)) {
txt += L"\n";
txt += info.name;
txt += L" ";
txt += itows(info.level);
}
}
return txt;
}
@ -487,13 +526,10 @@ std::wstring ToolItem::getGuiText()
sprintf(buff,"%02d",(int)f->fuel_time%60);
txt += narrow_to_wide(buff);
}
//if (m_data > 0) {
if (m_content == CONTENT_TOOLITEM_MITHRIL_PICK) {
if (m_data > 0) {
EnchantmentInfo info;
u16 data = m_data;
txt += L"\n";
if (m_content == CONTENT_TOOLITEM_MITHRIL_PICK)
data = (1<<15)|(1<<3);
while (enchantment_get(&data,&info)) {
txt += L"\n";
txt += info.name;

View File

@ -189,10 +189,7 @@ public:
return new MaterialItem(m_content, m_count, m_data);
}
#ifndef SERVER
video::ITexture * getImage() const
{
return content_features(m_content).inventory_texture;
}
video::ITexture * getImage() const;
#endif
std::wstring getGuiName()
{

View File

@ -24,6 +24,7 @@
************************************************************************/
#include "mineral.h"
#include "enchantment.h"
struct MineralFeatures g_mineral_features[MINERAL_MAX+1];
@ -52,12 +53,32 @@ CraftItem *getDiggedMineralItem(u8 mineral, Player *player, InventoryItem *tool)
return NULL;
u16 count = m.dug_count_min;
if (m.dug_count_min != m.dug_count_max && t->level > count) {
count = myrand_range(m.dug_count_min,t->level);
if (count > m.dug_count_max)
count = m.dug_count_max;
u16 count_max = t->level;
u16 data = tool->getData();
if (data != 0) {
EnchantmentInfo info;
while (enchantment_get(&data,&info)) {
switch (info.type) {
case ENCHANTMENT_MORE: // amplius increases the amount given
count += info.level;
count_max += info.level;
break;
case ENCHANTMENT_DONTBREAK: // gives no mineral
return NULL;
break;
default:;
}
}
}
if (count > count_max && count_max > count) {
count = myrand_range(m.dug_count_min,count_max);
}
if (count > m.dug_count_max)
count = m.dug_count_max;
return new CraftItem(m.dug_item, count, 0);
}

View File

@ -51,6 +51,7 @@
#include "base64.h"
#include "sound.h"
#include "http.h"
#include "enchantment.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -3310,7 +3311,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if (item && (std::string)item->getName() == "ToolItem") {
ToolItem *titem = (ToolItem*)item;
// Get digging properties for material and tool
DiggingProperties prop = getDiggingProperties(selected_content, titem->getContent());
DiggingProperties prop = getDiggingProperties(selected_content, titem->getContent(),titem->getData());
if (prop.diggable == false) {
infostream<<"Server: WARNING: Player digged"
@ -3411,7 +3412,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
}else if (selected_node_features.liquid_type == LIQUID_NONE) {
std::string &dug_s = selected_node_features.dug_item;
if (dug_s != "") {
if (wielded_tool_features.type != TT_NONE && enchantment_have(wielditem->getData(),ENCHANTMENT_DONTBREAK)) {
u16 data = 0;
if (selected_node_features.param_type == CPT_MINERAL)
data = selected_node.param1;
item = InventoryItem::create(selected_content,1,data);
}else if (
wielded_tool_features.type != TT_NONE
&& enchantment_have(wielditem->getData(),ENCHANTMENT_FLAME)
&& selected_node_features.cook_result != ""
) {
std::istringstream is(selected_node_features.cook_result, std::ios::binary);
item = InventoryItem::deSerialize(is);
}else if (dug_s != "") {
std::istringstream is(dug_s, std::ios::binary);
item = InventoryItem::deSerialize(is);
}else if (selected_node_features.param2_type == CPT_PLANTGROWTH) {