#include "main.h" // For g_profiler
#include "profiler.h"
#include "serialization.h" // For compressZlib
+#include "materials.h" // For MaterialProperties
+#include "tooldef.h" // ToolDiggingProperties
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
}
}
-void ItemSAO::punch(ServerActiveObject *puncher)
+void ItemSAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
InventoryItem *item = createInventoryItem();
bool fits = puncher->addToInventory(item);
delete item;
}
-void ItemSAO::rightClick(ServerActiveObject *clicker)
-{
- infostream<<__FUNCTION_NAME<<std::endl;
- InventoryItem *item = createInventoryItem();
- if(item == NULL)
- return;
-
- bool to_be_deleted = item->use(m_env, clicker);
-
- if(to_be_deleted)
- m_removed = true;
- else
- // Reflect changes to the item here
- m_inventorystring = item->getItemString();
-
- delete item; // Delete temporary item
-}
-
/*
RatSAO
*/
return os.str();
}
-void RatSAO::punch(ServerActiveObject *puncher)
+void RatSAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
std::istringstream is("CraftItem rat 1", std::ios_base::binary);
IGameDef *gamedef = m_env->getGameDef();
return os.str();
}
-void Oerkki1SAO::punch(ServerActiveObject *puncher)
+void Oerkki1SAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
+ if(!puncher)
+ return;
+
v3f dir = (getBasePosition() - puncher->getBasePosition()).normalize();
+ m_speed_f += dir*12*BS;
- std::string toolname = "";
- InventoryItem *item = puncher->getWieldedItem();
- if(item && (std::string)item->getName() == "ToolItem"){
- ToolItem *titem = (ToolItem*)item;
- toolname = titem->getToolName();
- }
+ // "Material" properties of an oerkki
+ MaterialProperties mp;
+ mp.diggability = DIGGABLE_NORMAL;
+ mp.crackiness = -1.0;
+ mp.cuttability = 1.0;
- m_speed_f += dir*12*BS;
+ ToolDiggingProperties tp;
+ puncher->getWieldDiggingProperties(&tp);
- u16 amount = 5;
- /* See tool names in inventory.h */
- if(toolname == "WSword")
- amount = 10;
- if(toolname == "STSword")
- amount = 12;
- if(toolname == "SteelSword")
- amount = 16;
- if(toolname == "STAxe")
- amount = 7;
- if(toolname == "SteelAxe")
- amount = 9;
- if(toolname == "SteelPick")
- amount = 7;
- doDamage(amount);
-
- puncher->damageWieldedItem(65536/100);
+ HittingProperties hitprop = getHittingProperties(&mp, &tp,
+ time_from_last_punch);
+
+ doDamage(hitprop.hp);
+ puncher->damageWieldedItem(hitprop.wear);
}
void Oerkki1SAO::doDamage(u16 d)
}
}
-void MobV2SAO::punch(ServerActiveObject *puncher)
+void MobV2SAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
+ if(!puncher)
+ return;
+
v3f dir = (getBasePosition() - puncher->getBasePosition()).normalize();
- std::string toolname = "";
- InventoryItem *item = puncher->getWieldedItem();
- if(item && (std::string)item->getName() == "ToolItem"){
- ToolItem *titem = (ToolItem*)item;
- toolname = titem->getToolName();
- }
-
// A quick hack; SAO description is player name for player
std::string playername = puncher->getDescription();
Map *map = &m_env->getMap();
actionstream<<playername<<" punches mob id="<<m_id
- <<" with a \""<<toolname<<"\" at "
- <<PP(m_base_position/BS)<<std::endl;
+ <<" at "<<PP(m_base_position/BS)<<std::endl;
m_disturb_timer = 0;
m_disturbing_player = playername;
}
sendPosition();
- u16 amount = 2;
- /* See tool names in inventory.h */
- if(toolname == "WSword")
- amount = 4;
- if(toolname == "STSword")
- amount = 6;
- if(toolname == "SteelSword")
- amount = 8;
- if(toolname == "STAxe")
- amount = 3;
- if(toolname == "SteelAxe")
- amount = 4;
- if(toolname == "SteelPick")
- amount = 3;
- doDamage(amount);
-
- puncher->damageWieldedItem(65536/100);
+
+ // "Material" properties of the MobV2
+ MaterialProperties mp;
+ mp.diggability = DIGGABLE_NORMAL;
+ mp.crackiness = -1.0;
+ mp.cuttability = 1.0;
+
+ ToolDiggingProperties tp;
+ puncher->getWieldDiggingProperties(&tp);
+
+ HittingProperties hitprop = getHittingProperties(&mp, &tp,
+ time_from_last_punch);
+
+ doDamage(hitprop.hp);
+ puncher->damageWieldedItem(hitprop.wear);
}
bool MobV2SAO::isPeaceful()
return item;
}
-void LuaEntitySAO::punch(ServerActiveObject *puncher)
+void LuaEntitySAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
{
if(!m_registered)
return;
lua_State *L = m_env->getLua();
- scriptapi_luaentity_punch(L, m_id, puncher);
+ scriptapi_luaentity_punch(L, m_id, puncher, time_from_last_punch);
}
void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
m_acceleration = acceleration;
}
+v3f LuaEntitySAO::getAcceleration()
+{
+ return m_acceleration;
+}
+
+void LuaEntitySAO::setTextureMod(const std::string &mod)
+{
+ std::ostringstream os(std::ios::binary);
+ // command (1 = set texture modification)
+ writeU8(os, 1);
+ // parameters
+ os<<serializeString(mod);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), false, os.str());
+ m_messages_out.push_back(aom);
+}
+
+void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength,
+ bool select_horiz_by_yawpitch)
+{
+ std::ostringstream os(std::ios::binary);
+ // command (2 = set sprite)
+ writeU8(os, 2);
+ // parameters
+ writeV2S16(os, p);
+ writeU16(os, num_frames);
+ writeF1000(os, framelength);
+ writeU8(os, select_horiz_by_yawpitch);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), false, os.str());
+ m_messages_out.push_back(aom);
+}
+
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
m_last_sent_move_precision = m_base_position.getDistanceFrom(
m_messages_out.push_back(aom);
}
-