1
0
Fork 0

- Crafting fixed in 1.0.0

- Server compatible with the weapons and equip again. (Some Packets were incompatible)
- fixed bucket bugs (not all)
- Fixed clients getting crashed by wrong Pickups
- fixed nearly all mob drops. (Check wheather they are burning is missing Big Grin)
- maybe some other things I can´t recall atm Big Grin

git-svn-id: http://mc-server.googlecode.com/svn/trunk@94 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
lapayo94@gmail.com 2011-12-21 20:42:34 +00:00
parent 3ea286fef8
commit 02f05f7496
44 changed files with 326 additions and 275 deletions

View File

@ -314,6 +314,7 @@
<ClCompile Include="..\source\packets\cPacket_EntityEquipment.cpp" />
<ClCompile Include="..\source\packets\cPacket_CreateInventoryAction.cpp" />
<ClCompile Include="..\source\packets\cPacket_Explosion.cpp" />
<ClCompile Include="..\source\packets\cPacket_ItemData.cpp" />
<ClCompile Include="..\source\packets\cPacket_NewInvalidState.cpp" />
<ClCompile Include="..\source\packets\cPacket_SoundEffect.cpp" />
<ClCompile Include="..\source\packets\cPacket_Thunderbolt.cpp" />
@ -462,6 +463,7 @@
<ClInclude Include="..\source\packets\cPacket_EntityEquipment.h" />
<ClInclude Include="..\source\packets\cPacket_CreateInventoryAction.h" />
<ClInclude Include="..\source\packets\cPacket_Explosion.h" />
<ClInclude Include="..\source\packets\cPacket_ItemData.h" />
<ClInclude Include="..\source\packets\cPacket_NewInvalidState.h" />
<ClInclude Include="..\source\packets\cPacket_SoundEffect.h" />
<ClInclude Include="..\source\packets\cPacket_Thunderbolt.h" />

View File

@ -397,6 +397,9 @@
<Filter Include="Packets\cPacket_SoundEffect">
<UniqueIdentifier>{faf55c04-f56e-4f41-a948-54232627c3a9}</UniqueIdentifier>
</Filter>
<Filter Include="Packets\cPacket_ItemData">
<UniqueIdentifier>{fcc08e08-8dba-47b4-89b0-5dc255bb9b8a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\source\cServer.cpp">
@ -796,6 +799,9 @@
<ClCompile Include="..\source\packets\cPacket_SoundEffect.cpp">
<Filter>Packets\cPacket_SoundEffect</Filter>
</ClCompile>
<ClCompile Include="..\source\packets\cPacket_ItemData.cpp">
<Filter>Packets\cPacket_ItemData</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\source\cServer.h">
@ -1230,6 +1236,9 @@
<ClInclude Include="..\source\packets\cPacket_SoundEffect.h">
<Filter>Packets\cPacket_SoundEffect</Filter>
</ClInclude>
<ClInclude Include="..\source\packets\cPacket_ItemData.h">
<Filter>Packets\cPacket_ItemData</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\source\AllToLua.pkg">

View File

@ -2483,7 +2483,7 @@ static int tolua_AllToLua_isValidItem00(lua_State* tolua_S)
{
int a_ItemID = ((int) tolua_tonumber(tolua_S,1,0));
{
bool tolua_ret = (bool) isValidItem(a_ItemID);
bool tolua_ret = (bool) IsValidItem(a_ItemID);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}

View File

@ -29,9 +29,11 @@ inline bool IsValidBlock( int a_BlockID ) //tolua_export
return false;
} //tolua_export
inline bool isValidItem( int a_ItemID ) //tolua_export
// Was old :o
// Changed to fit the style ;)
inline bool IsValidItem( int a_ItemID ) //tolua_export
{ //tolua_export
if( (a_ItemID >= 256 && a_ItemID <= 358)
if( (a_ItemID >= 256 && a_ItemID <= 383)
|| (a_ItemID == 2256 || a_ItemID == 2257) )
{
return true;

View File

@ -19,7 +19,7 @@ enum ENUM_PACKET_ID
E_BLOCK_DIG = 0x0e,
E_BLOCK_PLACE = 0x0f,
E_ITEM_SWITCH = 0x10,
E_ADD_TO_INV = 0x11,
E_ADD_TO_INV = 0x11, //TODO: Sure this is not Use Bed??
E_ANIMATION = 0x12,
E_PACKET_13 = 0x13,
E_NAMED_ENTITY_SPAWN= 0x14,

View File

@ -1,5 +1,6 @@
#include "cBlockToPickup.h"
#include "BlockID.h"
#include "stdlib.h"
ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_UsedItemID )
{
@ -23,6 +24,8 @@ ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_U
if( a_UsedItemID == E_ITEM_SHEARS )
return E_ITEM_LEAVES;
else
if(rand() % 5 == 0)
return E_ITEM_SAPLING;
return E_ITEM_EMPTY;
case E_BLOCK_COAL_ORE:
return E_ITEM_COAL;
@ -51,5 +54,6 @@ ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_U
default:
return (ENUM_ITEM_ID)a_BlockID;
}
//TODO: Whats that? :D
return E_ITEM_EMPTY;
}

View File

@ -46,16 +46,10 @@ void cCavespider::Tick(float a_Dt)
void cCavespider::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_STRING, 0, 2);
cMonster::RandomDropItem(E_ITEM_SPIDER_EYE, 0, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -20,6 +20,8 @@
#include <string>
// TODO: Drop egg every 5-10 minutes
cChicken::cChicken()
: m_ChaseTime( 999999 )
@ -49,16 +51,15 @@ void cChicken::Tick(float a_Dt)
void cChicken::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-2 Feathers
cMonster::RandomDropItem(E_ITEM_FEATHER, 0, 2);
// Raw Chicken
// TODO: (Check wheather it is burning to drop cooked Chicken)
//Drops 0-2 Lether
cMonster::DropItem(E_ITEM_RAW_CHICKEN, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -450,9 +450,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
cPacket_Chat Joined( m_pState->Username + " joined the game!");
cRoot::Get()->GetServer()->Broadcast( Joined, this );
}
int posx = m_Player->GetPosX();
int posy = m_Player->GetPosY();
int posz = m_Player->GetPosZ();
int posx = (int) m_Player->GetPosX();
int posy = (int) m_Player->GetPosY();
int posz = (int) m_Player->GetPosZ();
// Now initialize player (adds to entity list etc.)
cWorld* PlayerWorld = cRoot::Get()->GetWorld( m_Player->GetLoadedWorldName() );
if( !PlayerWorld ) PlayerWorld = cRoot::Get()->GetDefaultWorld();
@ -503,6 +503,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
m_Player->SetLastBlockActionCnt(LastActionCnt+1);
if (LastActionCnt > 3) { //kick if more than 3 interactions per .1 seconds
LOGWARN("Player %s tried to interact with a block too quickly! (could indicate bot) Was Kicked.", GetUsername() );
//To many false-positives :s for example on a minimal server lagg :s should be re checked
Kick("You're a baaaaaad boy!");
break;
}
@ -812,6 +813,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
if( PacketData->m_Direction < 0 ) // clicked in air
break;
//TODO: Wrong Blocks!
int clickedBlock = (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ );
char MetaData = (char)Equipped.m_ItemHealth;
bool LavaBucket = false;
@ -820,6 +822,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
switch( PacketData->m_ItemType ) // Special handling for special items
{
case E_ITEM_BUCKET:
//TODO: Change this, it is just a small hack to get it working a little bit. seems like the Client sends the position from the first hitable block :s
clickedBlock = (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ );
LOG("Bucket Clicked BlockID: %d", clickedBlock);
switch (clickedBlock)
{
case E_BLOCK_WATER:
@ -833,10 +838,24 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
}
break;
case E_ITEM_LAVA_BUCKET:
PacketData->m_ItemType = E_BLOCK_LAVA;
if((m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )))
{
cItem NewItem;
NewItem.m_ItemID = E_ITEM_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
PacketData->m_ItemType = E_BLOCK_LAVA;
}
break;
case E_ITEM_WATER_BUCKET:
PacketData->m_ItemType = E_BLOCK_WATER;
if((m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )))
{
cItem NewItem;
NewItem.m_ItemID = E_ITEM_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
PacketData->m_ItemType = E_BLOCK_WATER;
}
break;
case E_BLOCK_WHITE_CLOTH:
MetaData = (char)PacketData->m_Uses;
@ -932,7 +951,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
NewItem.m_ItemID = E_ITEM_LAVA_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
}
} else if (WaterBucket) {
@ -942,7 +961,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
NewItem.m_ItemID = E_ITEM_WATER_BUCKET;
NewItem.m_ItemCount = 1;
m_Player->GetInventory().AddItem( NewItem );
m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
m_Player->GetWorld()->SetBlock( PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ, E_BLOCK_AIR, 0 );
}
} else if( IsValidBlock( PacketData->m_ItemType) ) {

View File

@ -19,7 +19,7 @@
#include <string>
//TODO: Milk Cow
cCow::cCow()
: m_ChaseTime( 999999 )
@ -49,16 +49,14 @@ void cCow::Tick(float a_Dt)
void cCow::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-2 Lether
cMonster::RandomDropItem(E_ITEM_LEATHER, 0, 2);
//Drops 1-3 Raw beefs
cMonster::RandomDropItem(E_ITEM_LEATHER, 1, 3);
//TODO: Check wheather burning and drop 1-3 steak instead
cMonster::KilledBy( a_Killer );
}

View File

@ -73,7 +73,9 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
}
SendWholeWindow( a_Player.GetClientHandle() );
a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
// Separate packet for result =/ Don't know why
//Separate packet for result =/ Don't know why
cPacket_InventorySlot Packet;
Packet.m_WindowID = (char)GetWindowID();
Packet.m_SlotNum = 0;
@ -81,6 +83,7 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
Packet.m_ItemCount = GetSlot(0)->m_ItemCount;
Packet.m_ItemUses = (char)GetSlot(0)->m_ItemHealth;
a_Player.GetClientHandle()->Send( Packet );
}
void cCraftingWindow::Close( cPlayer & a_Player )

View File

@ -45,16 +45,10 @@ void cCreeper::Tick(float a_Dt)
void cCreeper::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
//Todo: Check if killed by a skeleton then drop random music disk
cMonster::KilledBy( a_Killer );
}

View File

@ -48,16 +48,9 @@ void cEnderman::Tick(float a_Dt)
void cEnderman::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-1 Enderpearl
cMonster::RandomDropItem(E_ITEM_ENDER_PEARL, 0, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -45,16 +45,10 @@ void cGhast::Tick(float a_Dt)
void cGhast::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_GUNPOWDER, 0, 2);
cMonster::RandomDropItem(E_ITEM_GHAST_TEAR, 0, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -320,7 +320,7 @@ void cInventory::SendSlot( int a_SlotNum )
{
cPacket_InventorySlot InventorySlot;
InventorySlot.m_ItemCount = Item->m_ItemCount;
InventorySlot.m_ItemID = (short)Item->m_ItemID;
InventorySlot.m_ItemID = Item->m_ItemID;
InventorySlot.m_ItemUses = (char)Item->m_ItemHealth;
InventorySlot.m_SlotNum = (short)a_SlotNum;
InventorySlot.m_WindowID = 0; // Inventory window ID

View File

@ -19,4 +19,26 @@ void cItem::FromJson( const Json::Value & a_Value )
m_ItemCount = (char)a_Value.get("Count", -1 ).asInt();
m_ItemHealth = (short)a_Value.get("Health", -1 ).asInt();
}
}
bool cItem::IsEnchantable(ENUM_ITEM_ID item)
{
if(item >= 256 && item <= 259)
return true;
if(item >= 267 && item <= 279)
return true;
if(item >= 283 && item <= 286)
return true;
if(item >= 290 && item <= 294)
return true;
if(item >= 298 && item <= 317)
return true;
if(item >= 290 && item <= 294)
return true;
if(item == 346 || item == 359 || item == 261)
return true;
return false;
}

View File

@ -16,7 +16,7 @@ public:
, m_ItemCount ( a_ItemCount )
, m_ItemHealth ( a_ItemHealth )
{ //tolua_export
if(!isValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY;
if(!IsValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY;
} //tolua_export
void Empty() //tolua_export
{ //tolua_export
@ -35,6 +35,8 @@ public:
void GetJson( Json::Value & a_OutValue ); //tolua_export
void FromJson( const Json::Value & a_Value ); //tolua_export
static bool IsEnchantable(ENUM_ITEM_ID item);
ENUM_ITEM_ID m_ItemID; //tolua_export
char m_ItemCount; //tolua_export

View File

@ -8,6 +8,8 @@
#include "cPlayer.h"
#include "BlockID.h"
#include "Defines.h"
#include "cPickup.h"
#include "cItem.h"
#include "packets/cPacket_SpawnMob.h"
#include "packets/cPacket_EntityLook.h"
@ -607,3 +609,18 @@ void cMonster::SetAttackDamage(float ad) {
void cMonster::SetSightDistance(float sd) {
m_SightDistance = sd;
}
void cMonster::DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count)
{
if(a_Count > 0)
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( a_Item, a_Count ) );
Pickup->Initialize( GetWorld() );
}
}
void cMonster::RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max)
{
return cMonster::DropItem(a_Item, rand() % (a_Max + 1) + a_Min);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "cPawn.h"
#include "BlockID.h"
class Vector3f;
class cClientHandle;
@ -82,4 +83,7 @@ protected:
float m_AttackInterval;
float m_FireDamageInterval;
float m_BurnPeriod;
void DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count);
void RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max);
}; //tolua_export

View File

@ -54,7 +54,8 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
PickupSpawn.m_Rotation = (char)(m_Speed->x * 8);
PickupSpawn.m_Pitch = (char)(m_Speed->y * 8);
PickupSpawn.m_Roll = (char)(m_Speed->z * 8);
cRoot::Get()->GetServer()->Broadcast( PickupSpawn );
if(PickupSpawn.m_Item != E_ITEM_EMPTY)
cRoot::Get()->GetServer()->Broadcast( PickupSpawn );
m_EntityType = E_PICKUP;
}
@ -216,7 +217,8 @@ void cPickup::HandlePhysics(float a_Dt)
bool cPickup::CollectedBy( cPlayer* a_Dest )
{
if(m_bCollected) return false; // It's already collected!
if(m_Timer < 800.f) return false; // Not old enough
// 800 is to long
if(m_Timer < 500.f) return false; // Not old enough
if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_COLLECT_ITEM, 2, this, a_Dest ) ) return false;

View File

@ -49,16 +49,11 @@ void cPig::Tick(float a_Dt)
void cPig::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-2 meat
cMonster::RandomDropItem(E_ITEM_RAW_MEAT, 0, 2);
//TODO: Check for burning state
cMonster::KilledBy( a_Killer );
}

View File

@ -325,11 +325,7 @@ void cPlayer::Heal( int a_Health )
{
if( m_Health < 20 )
{
m_Health += (short)a_Health;
if( m_Health > 20 )
{
m_Health = 20;
}
m_Health = MIN(a_Health + m_Health, 20);
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
@ -344,7 +340,9 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
m_ClientHandle->Send( Health );
//TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked)
if(m_ClientHandle != 0)
m_ClientHandle->Send( Health );
}
}

View File

@ -195,7 +195,7 @@ void cRecipeChecker::ReloadRecipes()
if( c == '@' ) bLoadResult = true;
if( c != ',' ) bLoadSlot = false;
if( !isValidItem( ItemID ) )
if( !IsValidItem( ItemID ) )
{
LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID );
bDontAddRecipe = true;
@ -307,7 +307,7 @@ void cRecipeChecker::ReloadRecipes()
f >> c; if( c != ':' ) { bError=true; break; }
f >> Amount;
//LOG("%i %i", ItemID, Amount );
if( !isValidItem( ItemID ) )
if( !IsValidItem( ItemID ) )
{
LOGERROR("Error in recipes file (%s): Invalid Item ID %i", a_File, ItemID );
bDontAddRecipe = true;

View File

@ -19,7 +19,7 @@
#include <string>
//Todo: Implement color
cSheep::cSheep()
: m_ChaseTime( 999999 )
@ -49,16 +49,11 @@ void cSheep::Tick(float a_Dt)
void cSheep::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Todo: Check wheather it is sheared
//Todo: Check color
cMonster::DropItem(E_ITEM_WHITE_CLOTH, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -45,16 +45,7 @@ void cSilverfish::Tick(float a_Dt)
void cSilverfish::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::KilledBy( a_Killer );
}

View File

@ -48,16 +48,10 @@ void cSkeleton::Tick(float a_Dt)
void cSkeleton::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_ARROW, 0, 2);
cMonster::RandomDropItem(E_ITEM_BONE, 0, 2);
cMonster::KilledBy( a_Killer );
}

View File

@ -18,6 +18,8 @@
#include <cstring>
#endif
//TODO Implement sized slimes
cSlime::cSlime() : m_ChaseTime(999999) {
m_bBurnable = true;
m_EMPersonality = AGGRESSIVE;
@ -45,16 +47,9 @@ void cSlime::Tick(float a_Dt)
void cSlime::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//TODO: only when tiny
cMonster::RandomDropItem(E_ITEM_SLIMEBALL, 0, 2);
cMonster::KilledBy( a_Killer );
}

View File

@ -46,16 +46,10 @@ void cSpider::Tick(float a_Dt)
void cSpider::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_STRING, 0, 2);
cMonster::RandomDropItem(E_ITEM_SPIDER_EYE, 0, 1);
cMonster::KilledBy( a_Killer );
}

View File

@ -49,16 +49,9 @@ void cSquid::Tick(float a_Dt)
void cSquid::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-3 Ink Sacs
cMonster::RandomDropItem(E_ITEM_DYE, 0, 3);
cMonster::KilledBy( a_Killer );
}

View File

@ -3,6 +3,7 @@
#include "cMCLogger.h"
#include "cClientHandle.h"
#include "cPlayer.h"
#include "cPickup.h"
#include "cInventory.h"
#include "cWindowOwner.h"
@ -195,6 +196,15 @@ void cWindow::Open( cPlayer & a_Player )
void cWindow::Close( cPlayer & a_Player )
{
//Checks wheather the player is still holding an item
if(m_DraggingItem && m_DraggingItem->m_ItemCount > 0)
{
LOG("Player holds item! Dropping it...");
a_Player.TossItem( true, m_DraggingItem->m_ItemCount );
}
cPacket_WindowClose WindowClose;
WindowClose.m_Close = (char)m_WindowID;
cClientHandle* ClientHandle = a_Player.GetClientHandle();
@ -205,6 +215,8 @@ void cWindow::Close( cPlayer & a_Player )
{
Destroy();
}
}
void cWindow::OwnerDestroyed()

View File

@ -45,16 +45,7 @@ void cWolf::Tick(float a_Dt)
void cWolf::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::KilledBy( a_Killer );
}

View File

@ -48,16 +48,9 @@ void cZombie::Tick(float a_Dt)
void cZombie::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
cMonster::KilledBy( a_Killer );
}

View File

@ -48,16 +48,12 @@ void cZombiepigman::Tick(float a_Dt)
void cZombiepigman::KilledBy( cEntity* a_Killer )
{
if( (rand() % 5) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_EGG, 1 ) );
Pickup->Initialize( GetWorld() );
}
if( (rand() % 1) == 0 )
{
cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), cItem( E_ITEM_FEATHER, 1 ) );
Pickup->Initialize( GetWorld() );
}
//Drops 0-1 Rottenflesh
cMonster::RandomDropItem(E_ITEM_ROTTEN_FLESH, 0, 2);
//Drops 0-1 gold nuggets
cMonster::RandomDropItem(E_ITEM_GOLD_NUGGET, 0, 2);
cMonster::KilledBy( a_Killer );
}

View File

@ -1,15 +1,22 @@
#include "cPacket_AddToInventory.h"
#include "cPacket_WholeInventory.h"
#include "cItem.h"
#include "cPacket_ItemData.h"
bool cPacket_AddToInventory::Send( cSocket & a_Socket )
{
unsigned int TotalSize = c_Size;
cPacket_ItemData Item;
TotalSize += Item.GetSize(m_ItemType);
char* Message = new char[TotalSize];
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendShort ( m_ItemType, Message, i );
AppendByte ( m_Count, Message, i );
AppendShort ( m_Life, Message, i );
AppendByte ( (char) m_PacketID, Message, i );
Item.AppendItem(Message, i, m_ItemType, m_Count, this->m_Life);
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;

View File

@ -2,12 +2,13 @@
#include "cPacket.h"
#include "PacketID.h"
#include "../BlockID.h"
class cPacket_AddToInventory : public cPacket
{
public:
cPacket_AddToInventory()
: m_ItemType( 0 )
: m_ItemType( E_ITEM_EMPTY )
, m_Count( 0 )
, m_Life( 0 )
{ m_PacketID = E_ADD_TO_INV; }
@ -16,8 +17,8 @@ public:
bool Parse( cSocket & a_Socket );
bool Send( cSocket & a_Socket );
short m_ItemType;
ENUM_ITEM_ID m_ItemType;
char m_Count;
short m_Life;
static const unsigned int c_Size = 1 + 2 + 1 + 2;
static const unsigned int c_Size = 1;
};

View File

@ -1,4 +1,5 @@
#include "cPacket_BlockPlace.h"
#include "cPacket_ItemData.h"
bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
{
@ -8,11 +9,21 @@ bool cPacket_BlockPlace::Parse(cSocket & a_Socket)
if( !ReadInteger( m_PosZ ) ) return false;
if( !ReadByte ( m_Direction ) ) return false;
/*
if( !ReadShort ( m_ItemType ) ) return false;
if( m_ItemType > -1 )
{
if( !ReadByte ( m_Count ) ) return false;
if( !ReadShort ( m_Uses ) ) return false;
}
}*/
cPacket_ItemData Item;
Item.Parse(m_Socket);
m_ItemType = Item.m_ItemID;
m_Count = Item.m_ItemCount;
m_Uses = Item.m_ItemUses;
return true;
}

View File

@ -1,42 +1,59 @@
#include "cPacket_CreateInventoryAction.h"
cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy )
{
m_PacketID = E_CREATE_INVENTORY_ACTION;
m_Slot = a_Copy.m_Slot;
m_ItemID = a_Copy.m_ItemID;
m_Quantity = 0;
m_Damage = 0;
}
bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket)
{
m_Socket = a_Socket;
if( !ReadShort ( m_Slot ) ) return false;
if( !ReadShort ( m_ItemID ) ) return false;
if( !ReadShort ( m_Quantity ) ) return false;
if( !ReadShort ( m_Damage ) ) return false;
return true;
}
bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket)
{
//LOG("InventoryChange:");
unsigned int TotalSize = c_Size;
char* Message = new char[TotalSize];
if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
//LOG("cPacket_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendShort ( m_Slot, Message, i );
AppendShort ( m_ItemID, Message, i );
AppendShort ( m_Quantity, Message, i );
AppendShort ( m_Damage, Message, i );
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
return RetVal;
}
#include "cPacket_CreateInventoryAction.h"
#include "cPacket_ItemData.h"
cPacket_CreateInventoryAction::cPacket_CreateInventoryAction( const cPacket_CreateInventoryAction & a_Copy )
{
m_PacketID = E_CREATE_INVENTORY_ACTION;
m_Slot = a_Copy.m_Slot;
m_ItemID = a_Copy.m_ItemID;
m_Quantity = 0;
m_Damage = 0;
}
bool cPacket_CreateInventoryAction::Parse(cSocket & a_Socket)
{
m_Socket = a_Socket;
if( !ReadShort ( m_Slot ) ) return false;
/*
if( !ReadShort ( m_ItemID ) ) return false;
if( !ReadShort ( m_Quantity ) ) return false;
if( !ReadShort ( m_Damage ) ) return false;
*/
cPacket_ItemData Item;
Item.Parse(m_Socket);
m_ItemID = Item.m_ItemID;
m_Quantity = Item.m_ItemCount;
m_Damage = Item.m_ItemUses;
return true;
}
bool cPacket_CreateInventoryAction::Send(cSocket & a_Socket)
{
//LOG("InventoryChange:");
unsigned int TotalSize = c_Size;
cPacket_ItemData Item;
TotalSize += Item.GetSize(m_ItemID);
char* Message = new char[TotalSize];
if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
// WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
//LOG("cPacket_CreateInventoryAction: Sending Creative item ID: %i", m_ItemID );
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendShort ( m_Slot, Message, i );
Item.AppendItem(Message, i, m_ItemID, m_Quantity, m_Damage);
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
return RetVal;
}

View File

@ -3,6 +3,8 @@
#include "cPacket.h"
#include "PacketID.h"
//Sure it´s not Creative Inventory?
class cPacket_CreateInventoryAction : public cPacket
{
public:
@ -20,8 +22,8 @@ public:
short m_Slot; // 0 = hold 1-4 = armor
short m_ItemID;
short m_Quantity;
char m_Quantity; //Byte not short ;)
short m_Damage;
static const unsigned int c_Size = 1 + 2 + 2 + 2 + 2;
static const unsigned int c_Size = 1 + 2;
};

View File

@ -1,21 +1,25 @@
#include "cPacket_InventorySlot.h"
#include "cPacket_WholeInventory.h"
#include "cPacket_ItemData.h"
bool cPacket_InventorySlot::Send(cSocket & a_Socket)
{
unsigned int TotalSize = c_Size;
if( m_ItemID > -1 ) TotalSize += 1 + 2;
cPacket_ItemData Item;
TotalSize += Item.GetSize(m_ItemID);
char* Message = new char[TotalSize];
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendByte ( (char)m_PacketID, Message, i );
AppendByte ( m_WindowID, Message, i );
AppendShort ( m_SlotNum, Message, i );
AppendShort ( m_ItemID, Message, i );
if( m_ItemID > -1 )
{
AppendByte ( m_ItemCount, Message, i );
AppendShort ( m_ItemUses, Message, i );
}
Item.AppendItem(Message, i, m_ItemID, m_ItemCount, m_ItemUses);
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;

View File

@ -2,6 +2,7 @@
#include "cPacket.h"
#include "PacketID.h"
#include "../BlockID.h"
class cPacket_InventorySlot : public cPacket // Set item [S -> C] ?
{
@ -9,7 +10,7 @@ public:
cPacket_InventorySlot()
: m_WindowID( 0 )
, m_SlotNum( 0 )
, m_ItemID( 0 )
, m_ItemID( E_ITEM_EMPTY )
, m_ItemCount( 0 )
, m_ItemUses( 0 )
{ m_PacketID = E_INVENTORY_SLOT; }
@ -30,5 +31,5 @@ public:
char m_ItemCount;
short m_ItemUses;
static const unsigned int c_Size = 1 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max)
};

View File

@ -2,6 +2,7 @@
#include "../cItem.h"
#include "../cInventory.h"
#include "../cWindow.h"
#include "cPacket_ItemData.h"
cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone )
{
@ -39,11 +40,11 @@ bool cPacket_WholeInventory::Send(cSocket & a_Socket)
{
unsigned int TotalSize = c_Size;
cPacket_ItemData Item;
for(int i = 0; i < m_Count; i++)
{
if( m_Items[i].m_ItemID > -1 )
TotalSize+=3;
TotalSize+=2;
TotalSize += Item.GetSize(m_Items[i].m_ItemID);
}
char* Message = new char[TotalSize];
@ -51,18 +52,16 @@ bool cPacket_WholeInventory::Send(cSocket & a_Socket)
unsigned int i = 0;
AppendByte ( (char)m_PacketID, Message, i );
AppendByte ( m_WindowID, Message, i );
AppendShort ( m_Count, Message, i );
AppendShort ( m_Count, Message, i );
for(int j = 0; j < m_Count; j++)
{
AppendShort ( (short)m_Items[j].m_ItemID, Message, i );
if( m_Items[j].m_ItemID > -1 )
{
AppendByte ( m_Items[j].m_ItemCount, Message, i );
AppendShort ( m_Items[j].m_ItemHealth, Message, i );
}
Item.AppendItem(Message, i, &(m_Items[j]));
}
bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
delete [] Message;
return RetVal;
}
}

View File

@ -2,6 +2,7 @@
#include "cPacket.h"
#include "PacketID.h"
#include "BlockID.h"
class cInventory;
class cWindow;
@ -18,6 +19,8 @@ public:
, m_Count( 0 )
, m_Items( 0 )
{ m_PacketID = E_INVENTORY_WHOLE; }
virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); }
bool Send(cSocket & a_Socket);

View File

@ -1,5 +1,6 @@
#include "cPacket_WindowClick.h"
#include "cPacket_WholeInventory.h"
#include "cPacket_ItemData.h"
bool cPacket_WindowClick::Parse(cSocket & a_Socket)
{
@ -17,20 +18,15 @@ bool cPacket_WindowClick::Parse(cSocket & a_Socket)
// LOG("Right/Le: %i", m_RightMouse );
// LOG("NumClick: %i", m_NumClicks );
if( !ReadShort(m_ItemID) ) return false;
// LOG("ItemID: %i", m_ItemID );
if( m_ItemID > -1 )
{
if( !ReadByte(m_ItemCount) ) return false;
if( !ReadShort(m_ItemUses) ) return false;
// LOG("Count : %i", m_ItemCount );
// LOG("Uses : %i", m_ItemUses );
}
else
{
m_ItemCount = 0;
m_ItemUses = 0;
}
cPacket_ItemData Item;
Item.Parse(m_Socket);
m_ItemID = Item.m_ItemID;
m_ItemCount = Item.m_ItemCount;
m_ItemUses = Item.m_ItemUses;
m_EnchantNums = Item.m_EnchantNums;
return true;
}

View File

@ -15,6 +15,7 @@ public:
, m_ItemID( 0 )
, m_ItemCount( 0 )
, m_ItemUses( 0 )
, m_EnchantNums(-1)
{ m_PacketID = E_WINDOW_CLICK; }
virtual cPacket* Clone() const { return new cPacket_WindowClick(*this); }
@ -30,12 +31,14 @@ public:
char m_RightMouse; // 0 = left 1 = Right mb
short m_NumClicks; // Num clicks
bool m_Bool; // unkown????????????
bool m_Bool; // unkown???????????? SHIFT clicked
// Below = item
short m_ItemID; // if this is -1 the next stuff dont exist
char m_ItemCount;
short m_ItemUses;
short m_EnchantNums;
static const unsigned int c_Size = 1 + 1 + 2 + 1 + 2 + 2; // Minimal size ( +1+1 = max)
};