2013-12-19 17:34:03 +01:00
|
|
|
|
|
|
|
// ItemFishingRod.h
|
|
|
|
|
|
|
|
// Declares the various fishing rod ItemHandlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../Entities/Floater.h"
|
|
|
|
#include "../Entities/Entity.h"
|
2013-12-19 22:16:15 +01:00
|
|
|
#include "../Item.h"
|
2013-12-19 17:34:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cItemFishingRodHandler :
|
|
|
|
public cItemHandler
|
|
|
|
{
|
|
|
|
typedef cItemHandler super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cItemFishingRodHandler(int a_ItemType) :
|
|
|
|
super(a_ItemType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
|
|
|
{
|
|
|
|
if (a_Player->IsFishing())
|
|
|
|
{
|
2013-12-19 22:16:15 +01:00
|
|
|
class cFloaterCallback :
|
|
|
|
public cEntityCallback
|
2013-12-19 17:34:03 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-12-19 22:16:15 +01:00
|
|
|
cFloaterCallback(void) :
|
|
|
|
m_CanPickup(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanPickup(void) const { return m_CanPickup; }
|
|
|
|
Vector3d GetPos(void) const { return m_Pos; }
|
|
|
|
|
2013-12-19 17:34:03 +01:00
|
|
|
virtual bool Item(cEntity * a_Entity) override
|
|
|
|
{
|
2013-12-19 22:16:15 +01:00
|
|
|
m_CanPickup = ((cFloater *)a_Entity)->CanPickup();
|
|
|
|
m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ());
|
2013-12-19 17:34:03 +01:00
|
|
|
a_Entity->Destroy(true);
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-19 22:16:15 +01:00
|
|
|
protected:
|
|
|
|
bool m_CanPickup;
|
|
|
|
Vector3d m_Pos;
|
|
|
|
} Callbacks;
|
|
|
|
a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callbacks);
|
2013-12-19 17:34:03 +01:00
|
|
|
a_Player->SetIsFishing(false);
|
2013-12-19 22:16:15 +01:00
|
|
|
|
|
|
|
if (Callbacks.CanPickup())
|
2013-12-19 17:34:03 +01:00
|
|
|
{
|
2013-12-19 22:16:15 +01:00
|
|
|
cItems Drops;
|
|
|
|
Drops.Add(cItem(E_ITEM_RAW_FISH));
|
|
|
|
Vector3d FloaterPos(Callbacks.GetPos());
|
|
|
|
Vector3d FlyDirection(a_Player->GetPosition() - FloaterPos);
|
2013-12-20 18:35:13 +01:00
|
|
|
a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.Length() / (FlyDirection.y * 2), FlyDirection.z);
|
2013-12-19 22:16:15 +01:00
|
|
|
// TODO: More types of pickups.
|
2013-12-19 17:34:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-20 19:49:30 +01:00
|
|
|
cFloater * Floater = new cFloater(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 15, a_Player->GetUniqueID());
|
2013-12-19 17:34:03 +01:00
|
|
|
Floater->Initialize(a_World);
|
|
|
|
a_Player->SetIsFishing(true, Floater->GetUniqueID());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ;
|