forked from Mirrorlandia_minetest/minetest
Rats are now eatable. Also made their selection box move smoothly.
This commit is contained in:
parent
4556c212db
commit
d62ae0e18b
@ -187,7 +187,8 @@ public:
|
|||||||
core::aabbox3d<f32>* getSelectionBox()
|
core::aabbox3d<f32>* getSelectionBox()
|
||||||
{return &m_selection_box;}
|
{return &m_selection_box;}
|
||||||
v3f getPosition()
|
v3f getPosition()
|
||||||
{return m_position;}
|
{return pos_translator.vect_show;}
|
||||||
|
//{return m_position;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::aabbox3d<f32> m_selection_box;
|
core::aabbox3d<f32> m_selection_box;
|
||||||
|
@ -122,3 +122,18 @@ InventoryItem* item_craft_create_cook_result(const std::string &subname)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool item_craft_is_eatable(const std::string &subname)
|
||||||
|
{
|
||||||
|
if(subname == "cooked_rat")
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
s16 item_craft_eat_hp_change(const std::string &subname)
|
||||||
|
{
|
||||||
|
if(subname == "cooked_rat")
|
||||||
|
return 6; // 3 hearts
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ ServerActiveObject* item_craft_create_object(const std::string &subname,
|
|||||||
s16 item_craft_get_drop_count(const std::string &subname);
|
s16 item_craft_get_drop_count(const std::string &subname);
|
||||||
bool item_craft_is_cookable(const std::string &subname);
|
bool item_craft_is_cookable(const std::string &subname);
|
||||||
InventoryItem* item_craft_create_cook_result(const std::string &subname);
|
InventoryItem* item_craft_create_cook_result(const std::string &subname);
|
||||||
|
bool item_craft_is_eatable(const std::string &subname);
|
||||||
|
s16 item_craft_eat_hp_change(const std::string &subname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -215,6 +215,18 @@ InventoryItem * ItemSAO::createInventoryItem()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemSAO::rightClick(Player *player)
|
||||||
|
{
|
||||||
|
dstream<<__FUNCTION_NAME<<std::endl;
|
||||||
|
InventoryItem *item = createInventoryItem();
|
||||||
|
if(item == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool to_be_deleted = item->use(m_env, player);
|
||||||
|
|
||||||
|
if(to_be_deleted)
|
||||||
|
m_removed = true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RatSAO
|
RatSAO
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
std::string getStaticData();
|
std::string getStaticData();
|
||||||
InventoryItem* createInventoryItem();
|
InventoryItem* createInventoryItem();
|
||||||
InventoryItem* createPickedUpItem(){return createInventoryItem();}
|
InventoryItem* createPickedUpItem(){return createInventoryItem();}
|
||||||
|
void rightClick(Player *player);
|
||||||
private:
|
private:
|
||||||
std::string m_inventorystring;
|
std::string m_inventorystring;
|
||||||
v3f m_speed_f;
|
v3f m_speed_f;
|
||||||
|
@ -1656,6 +1656,8 @@ void the_game(
|
|||||||
else if(input->getRightClicked())
|
else if(input->getRightClicked())
|
||||||
{
|
{
|
||||||
std::cout<<DTIME<<"Right-clicked object"<<std::endl;
|
std::cout<<DTIME<<"Right-clicked object"<<std::endl;
|
||||||
|
client.clickActiveObject(1,
|
||||||
|
selected_active_object->getId(), g_selected_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // selected_object == NULL
|
else // selected_object == NULL
|
||||||
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "content_mapnode.h"
|
#include "content_mapnode.h"
|
||||||
#include "content_inventory.h"
|
#include "content_inventory.h"
|
||||||
#include "content_sao.h"
|
#include "content_sao.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
InventoryItem
|
InventoryItem
|
||||||
@ -168,6 +169,20 @@ InventoryItem *CraftItem::createCookResult()
|
|||||||
return item_craft_create_cook_result(m_subname);
|
return item_craft_create_cook_result(m_subname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CraftItem::use(ServerEnvironment *env, Player *player)
|
||||||
|
{
|
||||||
|
if(item_craft_is_eatable(m_subname))
|
||||||
|
{
|
||||||
|
s16 hp_change = item_craft_eat_hp_change(m_subname);
|
||||||
|
if(player->hp + hp_change > 20)
|
||||||
|
player->hp = 20;
|
||||||
|
else
|
||||||
|
player->hp += hp_change;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MapBlockObjectItem DEPRECATED
|
MapBlockObjectItem DEPRECATED
|
||||||
TODO: Remove
|
TODO: Remove
|
||||||
|
@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
class ServerActiveObject;
|
class ServerActiveObject;
|
||||||
class ServerEnvironment;
|
class ServerEnvironment;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class InventoryItem
|
class InventoryItem
|
||||||
{
|
{
|
||||||
@ -99,12 +100,19 @@ public:
|
|||||||
/*
|
/*
|
||||||
Other properties
|
Other properties
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Whether it can be cooked
|
// Whether it can be cooked
|
||||||
virtual bool isCookable(){return false;}
|
virtual bool isCookable(){return false;}
|
||||||
// Time of cooking
|
// Time of cooking
|
||||||
virtual float getCookTime(){return 3.0;}
|
virtual float getCookTime(){return 3.0;}
|
||||||
// Result of cooking
|
// Result of cooking (can randomize)
|
||||||
virtual InventoryItem *createCookResult(){return NULL;}
|
virtual InventoryItem *createCookResult(){return NULL;}
|
||||||
|
|
||||||
|
// Eat, press, activate, whatever.
|
||||||
|
// Called when item is right-clicked when lying on ground.
|
||||||
|
// If returns true, item shall be deleted.
|
||||||
|
virtual bool use(ServerEnvironment *env,
|
||||||
|
Player *player){return false;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
u16 m_count;
|
u16 m_count;
|
||||||
@ -298,11 +306,16 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
return QUANTITY_ITEM_MAX_COUNT - m_count;
|
return QUANTITY_ITEM_MAX_COUNT - m_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Other properties
|
Other properties
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool isCookable();
|
bool isCookable();
|
||||||
InventoryItem *createCookResult();
|
InventoryItem *createCookResult();
|
||||||
|
|
||||||
|
bool use(ServerEnvironment *env, Player *player);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Special methods
|
Special methods
|
||||||
*/
|
*/
|
||||||
|
127
src/server.cpp
127
src/server.cpp
@ -2368,76 +2368,93 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip if object has been removed
|
||||||
|
if(obj->m_removed)
|
||||||
|
return;
|
||||||
|
|
||||||
//TODO: Check that object is reasonably close
|
//TODO: Check that object is reasonably close
|
||||||
|
|
||||||
// Left click, pick object up (usually)
|
// Left click, pick object up (usually)
|
||||||
if(button == 0)
|
if(button == 0)
|
||||||
{
|
{
|
||||||
InventoryList *ilist = player->inventory.getList("main");
|
/*
|
||||||
if(g_settings.getBool("creative_mode") == false && ilist != NULL)
|
Try creating inventory item
|
||||||
{
|
*/
|
||||||
|
InventoryItem *item = obj->createPickedUpItem();
|
||||||
|
|
||||||
// Skip if inventory has no free space
|
if(item)
|
||||||
if(ilist->getUsedSlots() == ilist->getSize())
|
{
|
||||||
|
if(g_settings.getBool("creative_mode") == false)
|
||||||
{
|
{
|
||||||
dout_server<<"Player inventory has no free space"<<std::endl;
|
InventoryList *ilist = player->inventory.getList("main");
|
||||||
return;
|
if(ilist != NULL)
|
||||||
}
|
|
||||||
|
|
||||||
// Skip if object has been removed
|
|
||||||
if(obj->m_removed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Create the inventory item
|
|
||||||
*/
|
|
||||||
InventoryItem *item = obj->createPickedUpItem();
|
|
||||||
|
|
||||||
if(item)
|
|
||||||
{
|
|
||||||
// Add to inventory and send inventory
|
|
||||||
ilist->addItem(item);
|
|
||||||
UpdateCrafting(player->peer_id);
|
|
||||||
SendInventory(player->peer_id);
|
|
||||||
|
|
||||||
// Remove object from environment
|
|
||||||
obj->m_removed = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Item cannot be picked up. Punch it instead.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ToolItem *titem = NULL;
|
|
||||||
std::string toolname = "";
|
|
||||||
|
|
||||||
InventoryList *mlist = player->inventory.getList("main");
|
|
||||||
if(mlist != NULL)
|
|
||||||
{
|
{
|
||||||
InventoryItem *item = mlist->getItem(item_i);
|
// Skip if inventory has no free space
|
||||||
if(item && (std::string)item->getName() == "ToolItem")
|
if(ilist->getUsedSlots() == ilist->getSize())
|
||||||
{
|
{
|
||||||
titem = (ToolItem*)item;
|
dout_server<<"Player inventory has no free space"<<std::endl;
|
||||||
toolname = titem->getToolName();
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
v3f playerpos = player->getPosition();
|
// Add to inventory and send inventory
|
||||||
v3f objpos = obj->getBasePosition();
|
ilist->addItem(item);
|
||||||
v3f dir = (objpos - playerpos).normalize();
|
UpdateCrafting(player->peer_id);
|
||||||
|
|
||||||
u16 wear = obj->punch(toolname, dir);
|
|
||||||
|
|
||||||
if(titem)
|
|
||||||
{
|
|
||||||
bool weared_out = titem->addWear(wear);
|
|
||||||
if(weared_out)
|
|
||||||
mlist->deleteItem(item_i);
|
|
||||||
SendInventory(player->peer_id);
|
SendInventory(player->peer_id);
|
||||||
|
|
||||||
|
// Remove object from environment
|
||||||
|
obj->m_removed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Item cannot be picked up. Punch it instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ToolItem *titem = NULL;
|
||||||
|
std::string toolname = "";
|
||||||
|
|
||||||
|
InventoryList *mlist = player->inventory.getList("main");
|
||||||
|
if(mlist != NULL)
|
||||||
|
{
|
||||||
|
InventoryItem *item = mlist->getItem(item_i);
|
||||||
|
if(item && (std::string)item->getName() == "ToolItem")
|
||||||
|
{
|
||||||
|
titem = (ToolItem*)item;
|
||||||
|
toolname = titem->getToolName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v3f playerpos = player->getPosition();
|
||||||
|
v3f objpos = obj->getBasePosition();
|
||||||
|
v3f dir = (objpos - playerpos).normalize();
|
||||||
|
|
||||||
|
u16 wear = obj->punch(toolname, dir);
|
||||||
|
|
||||||
|
if(titem)
|
||||||
|
{
|
||||||
|
bool weared_out = titem->addWear(wear);
|
||||||
|
if(weared_out)
|
||||||
|
mlist->deleteItem(item_i);
|
||||||
|
SendInventory(player->peer_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Right click, do something with object
|
||||||
|
if(button == 1)
|
||||||
|
{
|
||||||
|
// Track hp changes super-crappily
|
||||||
|
u16 oldhp = player->hp;
|
||||||
|
|
||||||
|
// Do stuff
|
||||||
|
obj->rightClick(player);
|
||||||
|
|
||||||
|
// Send back stuff
|
||||||
|
if(player->hp != oldhp)
|
||||||
|
{
|
||||||
|
SendPlayerHP(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(command == TOSERVER_GROUND_ACTION)
|
else if(command == TOSERVER_GROUND_ACTION)
|
||||||
|
@ -42,6 +42,7 @@ Some planning
|
|||||||
|
|
||||||
class ServerEnvironment;
|
class ServerEnvironment;
|
||||||
class InventoryItem;
|
class InventoryItem;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class ServerActiveObject : public ActiveObject
|
class ServerActiveObject : public ActiveObject
|
||||||
{
|
{
|
||||||
@ -105,6 +106,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual u16 punch(const std::string &toolname, v3f dir)
|
virtual u16 punch(const std::string &toolname, v3f dir)
|
||||||
{return 0;}
|
{return 0;}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
virtual void rightClick(Player *player){}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Number of players which know about this object. Object won't be
|
Number of players which know about this object. Object won't be
|
||||||
|
Loading…
Reference in New Issue
Block a user