From 1e9af56a67ae3765291361d9bf01e9009cfb4dcc Mon Sep 17 00:00:00 2001 From: "lapayo94@gmail.com" Date: Wed, 28 Dec 2011 02:10:05 +0000 Subject: - Implemented Drops from Burning animals - added right monster health and attack strength - refactored the Pawn/Monster/Player class a little bit - changed some namings to fit the style git-svn-id: http://mc-server.googlecode.com/svn/trunk@140 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- VC2010/MCServer.vcxproj.filters | 63 ++++++++++++++-------- monsters.ini | 100 ++++++++++++++++++++++++++++++++++ source/Bindings.cpp | 97 +++++---------------------------- source/Bindings.h | 2 +- source/cChicken.cpp | 8 ++- source/cCow.cpp | 9 ++-- source/cEnderman.cpp | 4 +- source/cFluidSimulator.cpp | 2 +- source/cMonster.cpp | 75 +++----------------------- source/cMonster.h | 6 --- source/cMonsterConfig.cpp | 4 ++ source/cPawn.cpp | 96 ++++++++++++++++++++++++++++++--- source/cPawn.h | 23 ++++++++ source/cPlayer.cpp | 105 +++++++++--------------------------- source/cPlayer.h | 31 +++++------ source/cSkeleton.cpp | 4 +- source/cSquid.cpp | 11 +--- source/cZombie.cpp | 4 +- source/cZombiepigman.cpp | 6 +-- source/packets/cPacket_Metadata.cpp | 25 +++++---- source/packets/cPacket_Metadata.h | 3 +- 21 files changed, 360 insertions(+), 318 deletions(-) diff --git a/VC2010/MCServer.vcxproj.filters b/VC2010/MCServer.vcxproj.filters index 67decbf26..a2ec4b5e8 100644 --- a/VC2010/MCServer.vcxproj.filters +++ b/VC2010/MCServer.vcxproj.filters @@ -397,15 +397,6 @@ {0d6f822b-71eb-406f-b17a-d188c4924283} - - {6f92474b-e2a5-4685-abf1-053b09dbc4f1} - - - {02fd457d-3735-4f4b-aaf2-f7701a7ee7bc} - - - {b0401fd9-4021-4ab7-bf61-c8de112b4196} - {b0f7c883-e2ca-4bba-89e3-c36656c3de39} @@ -430,6 +421,24 @@ {c86f4c53-af06-4b42-97dd-ffb7035041ce} + + {ad41fc50-2d3d-4f6f-addd-a8bcb15b8518} + + + {4b21067c-b137-4c25-91b4-addf7d67bd0a} + + + {6f92474b-e2a5-4685-abf1-053b09dbc4f1} + + + {02fd457d-3735-4f4b-aaf2-f7701a7ee7bc} + + + {b0401fd9-4021-4ab7-bf61-c8de112b4196} + + + {c5389fa9-20dd-4c52-ac16-2ef0a1115cf1} + @@ -752,7 +761,7 @@ Packets\cPacket_EntityStatus - cFluidSimulator\cWaterSimulator + Simulator\cSimulator\cFluidSimulator\cWaterSimulator Threading\cSocket @@ -815,7 +824,7 @@ cPiston - cFluidSimulator\cLavaSimulator + Simulator\cSimulator\cFluidSimulator\cLavaSimulator LuaBindings\SquirrelBindings @@ -836,7 +845,7 @@ cChunkGenerator - cFluidSimulator + Simulator\cSimulator\cFluidSimulator cEntity\cPawn\cMonster\Personalities\Aggressive @@ -853,12 +862,18 @@ cWorldGenerator - - - cWorldGenerator\cWorldGenerator_Test + + Simulator + + + Simulator\cSimulator + + + Simulator\cSimulator\SandSimulator + @@ -1213,7 +1228,7 @@ Packets\cPacket_EntityStatus - cFluidSimulator\cWaterSimulator + Simulator\cSimulator\cFluidSimulator\cWaterSimulator Threading\cSocket @@ -1279,7 +1294,7 @@ cPiston - cFluidSimulator\cLavaSimulator + Simulator\cSimulator\cFluidSimulator\cLavaSimulator LuaBindings\SquirrelBindings @@ -1300,7 +1315,7 @@ cChunkGenerator - cFluidSimulator + Simulator\cSimulator\cFluidSimulator cEntity\cPawn\cMonster\Personalities\Aggressive @@ -1317,12 +1332,18 @@ cWorldGenerator - - - cWorldGenerator\cWorldGenerator_Test + + Simulator + + + Simulator\cSimulator + + + Simulator\cSimulator\SandSimulator + diff --git a/monsters.ini b/monsters.ini index b04eb2c21..6634c5bef 100644 --- a/monsters.ini +++ b/monsters.ini @@ -3,9 +3,109 @@ AttackRange=5.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 +MaxHealth=10 [Chicken] AttackRange=5.0 AttackRate=1 AttackDamage=1.0 SightDistance=25.0 +MaxHealth=4 + +[Cow] +AttackRange=5.0 +AttackRate=1 +AttackDamage=1.0 +SightDistance=25.0 +MaxHealth=10 + +[Pig] +AttackRange=5.0 +AttackRate=1 +AttackDamage=1.0 +SightDistance=25.0 +MaxHealth=10 + +[Sheep] +AttackRange=5.0 +AttackRate=1 +AttackDamage=1.0 +SightDistance=25.0 +MaxHealth=8 + +[Squid] +AttackRange=5.0 +AttackRate=1 +AttackDamage=1.0 +SightDistance=25.0 +MaxHealth=10 + +[Enderman] +AttackRange=5.0 +AttackRate=1 +AttackDamage=4.0 +SightDistance=25.0 +MaxHealth=40 + +[Zombiepigman] +AttackRange=5.0 +AttackRate=1 +AttackDamage=5.0 +SightDistance=25.0 +MaxHealth=20 + +[Cavespider] +AttackRange=5.0 +AttackRate=1 +AttackDamage=2.0 +SightDistance=25.0 +MaxHealth=12 + +[Creeper] +AttackRange=5.0 +AttackRate=1 +AttackDamage=0.0 +SightDistance=25.0 +MaxHealth=20 + +[Ghast] +AttackRange=5.0 +AttackRate=1 +AttackDamage=0.0 +SightDistance=25.0 +MaxHealth=10 + +[Silverfish] +AttackRange=5.0 +AttackRate=1 +AttackDamage=1.0 +SightDistance=25.0 +MaxHealth=8 + +[Skeleton] +AttackRange=5.0 +AttackRate=1 +AttackDamage=4.0 +SightDistance=25.0 +MaxHealth=20 + +[Slime] +AttackRange=5.0 +AttackRate=1 +AttackDamage=10.0 +SightDistance=25.0 +MaxHealth=32 + +[Spider] +AttackRange=5.0 +AttackRate=1 +AttackDamage=2.0 +SightDistance=25.0 +MaxHealth=16 + +[Zombie] +AttackRange=5.0 +AttackRate=1 +AttackDamage=4.0 +SightDistance=25.0 +MaxHealth=20 \ No newline at end of file diff --git a/source/Bindings.cpp b/source/Bindings.cpp index d6ea00987..33d6427d4 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/26/11 15:45:21. +** Generated automatically by tolua++-1.0.92 on 12/28/11 01:31:37. */ #ifndef __cplusplus @@ -5036,38 +5036,6 @@ static int tolua_AllToLua_cPlayer_GetInventory00(lua_State* tolua_S) static int tolua_AllToLua_cPlayer_TeleportTo00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"cEntity",0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); - cEntity* a_Entity = ((cEntity*) tolua_tousertype(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'TeleportTo'", NULL); -#endif - { - self->TeleportTo(a_Entity); - } - } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'TeleportTo'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: TeleportTo of class cPlayer */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_TeleportTo01 -static int tolua_AllToLua_cPlayer_TeleportTo01(lua_State* tolua_S) -{ tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || @@ -5078,6 +5046,7 @@ static int tolua_AllToLua_cPlayer_TeleportTo01(lua_State* tolua_S) ) goto tolua_lerror; else +#endif { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); const double a_PosX = ((const double) tolua_tonumber(tolua_S,2,0)); @@ -5094,8 +5063,11 @@ static int tolua_AllToLua_cPlayer_TeleportTo01(lua_State* tolua_S) } } return 3; -tolua_lerror: - return tolua_AllToLua_cPlayer_TeleportTo00(tolua_S); +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'TeleportTo'.",&tolua_err); + return 0; +#endif } #endif //#ifndef TOLUA_DISABLE @@ -5929,17 +5901,9 @@ public: } else { return ( void ) cPlayer:: Initialize(a_World); }; - }; - void TeleportTo( cEntity* a_Entity) { - if (push_method("TeleportTo", tolua_AllToLua_cPlayer_TeleportTo00)) { - tolua_pushusertype(lua_state, (void*)a_Entity, "cEntity"); - ToluaBase::dbcall(lua_state, 2, 0); - } else { - return ( void ) cPlayer:: TeleportTo(a_Entity); - }; }; void TeleportTo( const double& a_PosX, const double& a_PosY, const double& a_PosZ) { - if (push_method("TeleportTo", tolua_AllToLua_cPlayer_TeleportTo01)) { + if (push_method("TeleportTo", tolua_AllToLua_cPlayer_TeleportTo00)) { tolua_pushnumber(lua_state, (lua_Number)a_PosX); tolua_pushnumber(lua_state, (lua_Number)a_PosY); tolua_pushnumber(lua_state, (lua_Number)a_PosZ); @@ -6035,9 +5999,6 @@ public: void cPlayer__Initialize( cWorld* a_World) { return ( void )cPlayer::Initialize(a_World); - }; - void cPlayer__TeleportTo( cEntity* a_Entity) { - return ( void )cPlayer::TeleportTo(a_Entity); }; void cPlayer__TeleportTo( const double& a_PosX, const double& a_PosY, const double& a_PosZ) { return ( void )cPlayer::TeleportTo(a_PosX,a_PosY,a_PosZ); @@ -6133,38 +6094,6 @@ static int tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00(lua_State* tolua_S) static int tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"Lua__cPlayer",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"cEntity",0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - Lua__cPlayer* self = (Lua__cPlayer*) tolua_tousertype(tolua_S,1,0); - cEntity* a_Entity = ((cEntity*) tolua_tousertype(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlayer__TeleportTo'", NULL); -#endif - { - self->cPlayer__TeleportTo(a_Entity); - } - } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'cPlayer__TeleportTo'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: cPlayer__TeleportTo of class Lua__cPlayer */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01 -static int tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01(lua_State* tolua_S) -{ tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"Lua__cPlayer",0,&tolua_err) || @@ -6175,6 +6104,7 @@ static int tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01(lua_State* tolua_S) ) goto tolua_lerror; else +#endif { Lua__cPlayer* self = (Lua__cPlayer*) tolua_tousertype(tolua_S,1,0); const double a_PosX = ((const double) tolua_tonumber(tolua_S,2,0)); @@ -6191,8 +6121,11 @@ static int tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01(lua_State* tolua_S) } } return 3; -tolua_lerror: - return tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00(tolua_S); +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'cPlayer__TeleportTo'.",&tolua_err); + return 0; +#endif } #endif //#ifndef TOLUA_DISABLE @@ -15992,7 +15925,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"GetStance",tolua_AllToLua_cPlayer_GetStance00); tolua_function(tolua_S,"GetInventory",tolua_AllToLua_cPlayer_GetInventory00); tolua_function(tolua_S,"TeleportTo",tolua_AllToLua_cPlayer_TeleportTo00); - tolua_function(tolua_S,"TeleportTo",tolua_AllToLua_cPlayer_TeleportTo01); tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cPlayer_GetGameMode00); tolua_function(tolua_S,"GetIP",tolua_AllToLua_cPlayer_GetIP00); tolua_function(tolua_S,"GetLastBlockActionTime",tolua_AllToLua_cPlayer_GetLastBlockActionTime00); @@ -16024,7 +15956,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cPlayer_tolua__set_instance00); tolua_function(tolua_S,"cPlayer__Initialize",tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00); tolua_function(tolua_S,"cPlayer__TeleportTo",tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00); - tolua_function(tolua_S,"cPlayer__TeleportTo",tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01); tolua_function(tolua_S,"cPlayer__MoveTo",tolua_AllToLua_Lua__cPlayer_cPlayer__MoveTo00); tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"cPluginManager","cPluginManager","",NULL); diff --git a/source/Bindings.h b/source/Bindings.h index 150efff75..7fede45f8 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/26/11 15:45:21. +** Generated automatically by tolua++-1.0.92 on 12/28/11 01:31:37. */ /* Exported function */ diff --git a/source/cChicken.cpp b/source/cChicken.cpp index 33d5d0755..201ea7f45 100644 --- a/source/cChicken.cpp +++ b/source/cChicken.cpp @@ -25,8 +25,12 @@ void cChicken::KilledBy( cEntity* a_Killer ) cMonster::RandomDropItem(E_ITEM_FEATHER, 0, 2); // Raw Chicken - // TODO: (Check wheather it is burning to drop cooked Chicken) - cMonster::DropItem(E_ITEM_RAW_CHICKEN, 1); + if(GetMetaData() == BURNING) + { + cMonster::DropItem(E_ITEM_COOKED_CHICKEN, 1); + }else{ + cMonster::DropItem(E_ITEM_RAW_CHICKEN, 1); + } cMonster::KilledBy( a_Killer ); } \ No newline at end of file diff --git a/source/cCow.cpp b/source/cCow.cpp index 3d20bf2d9..de9815a9d 100644 --- a/source/cCow.cpp +++ b/source/cCow.cpp @@ -23,10 +23,13 @@ void cCow::KilledBy( cEntity* a_Killer ) //Drops 0-2 Lether cMonster::RandomDropItem(E_ITEM_LEATHER, 0, 2); - //Drops 1-3 Raw beefs - cMonster::RandomDropItem(E_ITEM_LEATHER, 1, 3); + if(GetMetaData() == BURNING) + { + cMonster::RandomDropItem(E_ITEM_STEAK, 1, 3); + }else{ + cMonster::RandomDropItem(E_ITEM_RAW_BEEF, 1, 3); + } - //TODO: Check wheather burning and drop 1-3 steak instead cMonster::KilledBy( a_Killer ); } diff --git a/source/cEnderman.cpp b/source/cEnderman.cpp index c7c785a9f..36982b1e8 100644 --- a/source/cEnderman.cpp +++ b/source/cEnderman.cpp @@ -21,8 +21,8 @@ void cEnderman::Tick(float a_Dt) cMonster::Tick(a_Dt); //TODO Same as stated in cSkeleton - if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight - m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D } } diff --git a/source/cFluidSimulator.cpp b/source/cFluidSimulator.cpp index 2ede7ba49..bc9bc8aae 100644 --- a/source/cFluidSimulator.cpp +++ b/source/cFluidSimulator.cpp @@ -224,7 +224,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a */ char LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted - int X, Y, Z; //Lowest Pos will be stored here + int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here if(IsAllowedBlock(m_World->GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction { diff --git a/source/cMonster.cpp b/source/cMonster.cpp index 2f7567b15..cee068b08 100644 --- a/source/cMonster.cpp +++ b/source/cMonster.cpp @@ -56,25 +56,12 @@ cMonster::cMonster() , m_AttackInterval(0) , m_AttackRate(3) , idle_interval(0) - , m_bBurnable(true) - , m_EMMetaState(NORMAL) - , m_FireDamageInterval(0) - , m_BurnPeriod(0) { LOG("cMonster::cMonster()"); - LOG("In state: %s",GetState()); - m_Health = 10; + LOG("In state: %s", GetState()); - MTRand r1; - int RandVal = r1.randInt() % 4; - if( RandVal == 0 ) - m_MobType = 90; // Pig - else if( RandVal == 1 ) - m_MobType = 91; // Sheep - else if( RandVal == 2 ) - m_MobType = 92; // Cow - else - m_MobType = 93; // Hen + m_bBurnable = true; + m_MetaData = NORMAL; } cMonster::~cMonster() @@ -131,6 +118,8 @@ bool cMonster::ReachedDestination() void cMonster::Tick(float a_Dt) { + cPawn::Tick(a_Dt); + if( m_Health <= 0 ) { m_DestroyTimer += a_Dt/1000; @@ -196,12 +185,6 @@ void cMonster::Tick(float a_Dt) SetPitch( Pitch ); } - CheckMetaDataBurn(); //Check to see if Enemy should burn based on block they are on - - if(m_EMMetaState == BURNING) { - InStateBurning(a_Dt); - } - if(m_EMState == IDLE) { //If enemy passive we ignore checks for player visibility InStateIdle(a_Dt); } @@ -448,37 +431,6 @@ void cMonster::InStateIdle(float a_Dt) { } } -//What to do if On fire -void cMonster::InStateBurning(float a_Dt) { - m_FireDamageInterval += a_Dt; - char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); - char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y +1, (int)m_Pos->z ); - if(m_FireDamageInterval > 1) { - - m_FireDamageInterval -= 1; - TakeDamage(1, this); - - m_BurnPeriod++; - if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE - || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) { - m_BurnPeriod = 0; - TakeDamage(6, this); - }else{ - TakeDamage(1, this); - } - - if(m_BurnPeriod > 8) { - cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - m_EMMetaState = NORMAL; - cPacket_Metadata md(NORMAL, GetUniqueID()); - InChunk->Broadcast(md); - m_BurnPeriod = 0; - - } - } - -} - //What to do if in Chasing State //This state should always be defined in each child class void cMonster::InStateChasing(float a_Dt) { @@ -508,20 +460,7 @@ void cMonster::Attack(float a_Dt) { ((cPawn *)m_Target)->TakeDamage((int)m_AttackDamage,this); } } -//----Change Entity MetaData -void cMonster::CheckMetaDataBurn() { - char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); - char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y -1, (int)m_Pos->z ); - if(m_bBurnable && m_EMMetaState != BURNING && (block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE - || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE)) { - cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - if(!InChunk) - return; - m_EMMetaState = BURNING; - cPacket_Metadata md(BURNING,GetUniqueID()); - InChunk->Broadcast(md); - } -} + //----Debug @@ -601,5 +540,5 @@ void cMonster::DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count) void cMonster::RandomDropItem(ENUM_ITEM_ID a_Item, unsigned int a_Min, unsigned int a_Max) { MTRand r1; - return cMonster::DropItem(a_Item, r1.randInt() % (a_Max + 1) + a_Min); + return cMonster::DropItem(a_Item, r1.randInt() % (a_Max + 1 - a_Min) + a_Min); } \ No newline at end of file diff --git a/source/cMonster.h b/source/cMonster.h index 90340311e..faf54b04f 100644 --- a/source/cMonster.h +++ b/source/cMonster.h @@ -43,7 +43,6 @@ public: virtual void InStateIdle(float a_Dt); virtual void InStateChasing(float a_Dt); virtual void InStateEscaping(float a_Dt); - virtual void InStateBurning(float a_Dt); virtual void Attack(float a_Dt); int GetMobType() {return m_MobType;} @@ -52,11 +51,9 @@ public: void SetAttackRange(float ar); void SetAttackDamage(float ad); void SetSightDistance(float sd); - virtual void CheckMetaDataBurn(); enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState; enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality; - enum MMetaState{NORMAL,BURNING,CROUCHED,RIDING} m_EMMetaState; protected: @@ -67,7 +64,6 @@ protected: Vector3f* m_Destination; bool m_bMovingToDestination; bool m_bPassiveAggressive; - bool m_bBurnable; Vector3f* m_Speed; float m_DestinationTime; @@ -84,8 +80,6 @@ protected: float m_AttackDamage; float m_AttackRange; 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); diff --git a/source/cMonsterConfig.cpp b/source/cMonsterConfig.cpp index 456da1fc3..1226c74e2 100644 --- a/source/cMonsterConfig.cpp +++ b/source/cMonsterConfig.cpp @@ -17,6 +17,7 @@ struct cMonsterConfig::sAttributesStruct float m_AttackDamage; float m_AttackRange; float m_AttackRate; + int m_MaxHealth; }; struct cMonsterConfig::sMonsterConfigState @@ -68,6 +69,8 @@ void cMonsterConfig::Initialize() { printf("Got SightDistance: %3.3f \n",Attributes.m_SightDistance); Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i].c_str(),"AttackRate",0); printf("Got AttackRate: %3.3f \n",Attributes.m_AttackRate); + Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i].c_str(),"MaxHealth",0); + printf("Got MaxHealth: %d \n",Attributes.m_MaxHealth); m_pState->AttributesList.push_front(Attributes); } } @@ -84,6 +87,7 @@ void cMonsterConfig::AssignAttributes(cMonster *m, const char* n) m->SetAttackRange(itr->m_AttackRange); m->SetSightDistance(itr->m_SightDistance); m->SetAttackRate((int)itr->m_AttackRate); + m->SetMaxHealth((int)itr->m_AttackRate); } } } diff --git a/source/cPawn.cpp b/source/cPawn.cpp index 2c1471156..e696ffc18 100644 --- a/source/cPawn.cpp +++ b/source/cPawn.cpp @@ -6,9 +6,14 @@ #include "cChunk.h" #include "cMCLogger.h" #include "cPluginManager.h" +#include "Vector3d.h" +#include "BlockID.h" + +#include "Defines.h" #include "packets/cPacket_TeleportEntity.h" #include "packets/cPacket_EntityStatus.h" +#include "packets/cPacket_Metadata.h" CLASS_DEFINITION( cPawn, cEntity ) @@ -18,8 +23,11 @@ cPawn::cPawn() , m_LastPosY( 0.0 ) , m_LastPosZ( 0.0 ) , m_TimeLastTeleportPacket( 0.f ) + , m_bBurnable(true) + , m_MetaData(NORMAL) + , m_FireDamageInterval(0.f) { - m_Health = 20; + SetMaxHealth(20); } cPawn::~cPawn() @@ -83,14 +91,88 @@ void cPawn::TeleportTo( cEntity* a_Entity ) void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ) { SetPosition( a_PosX, a_PosY, a_PosZ ); + cPacket_TeleportEntity TeleportEntity( this ); - if( IsA("cPlayer") ) - { - cPlayer* Player = (cPlayer*)this; - cRoot::Get()->GetServer()->Broadcast( TeleportEntity, Player->GetClientHandle() ); + + cRoot::Get()->GetServer()->Broadcast( TeleportEntity ); + +} + +void cPawn::Tick(float a_Dt) +{ + CheckMetaDataBurn(); //Check to see if pawn should burn based on block they are on + + if(GetMetaData() == BURNING) + InStateBurning(a_Dt); + +} + + +void cPawn::SetMetaData(MetaData a_MetaData) +{ + cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); + + if(InChunk) + { //Broadcast new status to clients in the chunk + m_MetaData = a_MetaData; + cPacket_Metadata md(a_MetaData, GetUniqueID()); + InChunk->Broadcast(md); } - else +} + +//----Change Entity MetaData +void cPawn::CheckMetaDataBurn() +{ + char Block = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y, (int) m_Pos->z); + + char BlockAbove = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y + 1, (int) m_Pos->z); + if(GetMetaData() == BURNING + && (IsBlockWater(Block) + || IsBlockWater(BlockAbove))) { - cRoot::Get()->GetServer()->Broadcast( TeleportEntity ); + SetMetaData(NORMAL); + }else if(m_bBurnable && GetMetaData() != BURNING + && (IsBlockLava(Block) || Block == E_BLOCK_FIRE + || IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE)) { + SetMetaData(BURNING); + } +} + +//What to do if On fire +void cPawn::InStateBurning(float a_Dt) +{ + m_FireDamageInterval += a_Dt; + char Block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); + char BlockAbove = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y + 1, (int)m_Pos->z ); + if(m_FireDamageInterval > 800) { + + m_FireDamageInterval = 0; + TakeDamage(1, this); + + m_BurnPeriod++; + if(IsBlockLava(Block) || Block == E_BLOCK_FIRE + || IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE) { + m_BurnPeriod = 0; + TakeDamage(6, this); + }else{ + TakeDamage(1, this); + } + + if(m_BurnPeriod > 7) { + SetMetaData(NORMAL); + m_BurnPeriod = 0; + + } } + } + +void cPawn::SetMaxHealth(short a_MaxHealth) +{ + this->m_MaxHealth = a_MaxHealth; + + //Reset health + m_Health = a_MaxHealth; +} + + diff --git a/source/cPawn.h b/source/cPawn.h index 2339bde03..ff90e7276 100644 --- a/source/cPawn.h +++ b/source/cPawn.h @@ -18,14 +18,37 @@ public: virtual void TeleportTo( cEntity* a_Entity ); //tolua_export virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export + virtual void Tick(float a_Dt); + void Heal( int a_Health ); //tolua_export virtual void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export virtual void KilledBy( cEntity* a_Killer ); //tolua_export int GetHealth() { return m_Health; } //tolua_export + enum MetaData {NORMAL, BURNING, CROUCHED, RIDING, SPRINTING, EATING, BLOCKING}; + + virtual inline void SetMetaData(MetaData a_MetaData); + virtual inline MetaData cPawn::GetMetaData() { return m_MetaData; } + + virtual inline void InStateBurning(float a_Dt); + + virtual void CheckMetaDataBurn(); + + virtual inline void SetMaxHealth(short a_MaxHealth); + virtual inline short GetMaxHealth() { return m_MaxHealth; } + protected: short m_Health; + short m_MaxHealth; + + bool m_bBurnable; + + MetaData m_MetaData; double m_LastPosX, m_LastPosY, m_LastPosZ; float m_TimeLastTeleportPacket; + + float m_FireDamageInterval; + float m_BurnPeriod; + }; //tolua_export diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index aca2879ca..b3d0e74b3 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -63,12 +63,10 @@ struct cPlayer::sPlayerState }; cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName) - : m_bBurnable(true) - , m_GameMode( 0 ) + : m_GameMode( 0 ) , m_IP("") , m_LastBlockActionTime( 0 ) , m_LastBlockActionCnt( 0 ) - , e_EPMetaState(NORMAL) , m_bVisible( true ) , m_LastGroundHeight( 0 ) , m_bTouchGround( false ) @@ -77,12 +75,11 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName) , m_CurrentWindow( 0 ) , m_TimeLastPickupCheck( 0.f ) , m_Color('-') - , m_FireDamageInterval(0) - , m_BurnPeriod(0) , m_ClientHandle( a_Client ) , m_pState( new sPlayerState ) { m_EntityType = E_PLAYER; + SetMaxHealth(20); m_Inventory = new cInventory( this ); cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); @@ -154,14 +151,14 @@ void cPlayer::Tick(float a_Dt) cChunk* InChunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ ); if( !InChunk ) return; + cPawn::Tick(a_Dt); + if(m_bDirtyOrientation && !m_bDirtyPosition) { cPacket_EntityLook EntityLook( this ); InChunk->Broadcast( EntityLook, m_ClientHandle ); m_bDirtyOrientation = false; - } - - if(m_bDirtyPosition ) + } else if(m_bDirtyPosition ) { cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_MOVE, 1, this ); @@ -233,10 +230,6 @@ void cPlayer::Tick(float a_Dt) Chunk->UnlockEntities(); } } - CheckMetaDataBurn(); - if(e_EPMetaState == BURNING){ - InStateBurning(a_Dt); - } cTimer t1; // Send Player List (Once per m_LastPlayerListTime/1000 ms) @@ -254,61 +247,6 @@ void cPlayer::Tick(float a_Dt) } -void cPlayer::InStateBurning(float a_Dt) { - m_FireDamageInterval += a_Dt; - char block = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) ); - char bblock = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y)+1, float2int(m_Pos->z) ); - if(m_FireDamageInterval > 800) { - - m_FireDamageInterval = 0; - - m_BurnPeriod++; - if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE - || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) { - m_BurnPeriod = 0; - TakeDamage(6, this); - }else{ - TakeDamage(1, this); - } - if(m_BurnPeriod > 7) { - - cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - e_EPMetaState = NORMAL; - cPacket_Metadata md(NORMAL, GetUniqueID()); - //md.m_UniqueID = GetUniqueID(); - InChunk->Broadcast(md); - m_BurnPeriod = 0; - - } - - } - -} - -//----Change Entity MetaData -void cPlayer::CheckMetaDataBurn() { - char block = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) ); - char bblock = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y)+1, float2int(m_Pos->z) ); - if(e_EPMetaState == BURNING && (block == E_BLOCK_WATER || block == E_BLOCK_STATIONARY_WATER - || bblock == E_BLOCK_WATER || bblock == E_BLOCK_STATIONARY_WATER)) { - cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - if(!InChunk) - return; - e_EPMetaState = NORMAL; - cPacket_Metadata md(NORMAL,GetUniqueID()); - InChunk->Broadcast(md); - }else if(m_bBurnable && e_EPMetaState != BURNING && (block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE - || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE)) { - cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - if(!InChunk) - return; - printf("I should burn\n"); - e_EPMetaState = BURNING; - cPacket_Metadata md(BURNING,GetUniqueID()); - InChunk->Broadcast(md); - } -} - void cPlayer::SetTouchGround( bool a_bTouchGround ) { m_bTouchGround = a_bTouchGround; @@ -345,9 +283,9 @@ void cPlayer::SetTouchGround( bool a_bTouchGround ) void cPlayer::Heal( int a_Health ) { - if( m_Health < 20 ) + if( m_Health < GetMaxHealth() ) { - m_Health = (short) MIN(a_Health + m_Health, 20); + m_Health = (short) MIN(a_Health + m_Health, GetMaxHealth()); cPacket_UpdateHealth Health; Health.m_Health = m_Health; @@ -396,17 +334,27 @@ void cPlayer::KilledBy( cEntity* a_Killer ) void cPlayer::Respawn() { - m_Health = 20; + m_Health = GetMaxHealth(); // Create Respawn player packet cPacket_Respawn Packet; //Set Gamemode for packet by looking at world's gamemode (Need to check players gamemode.) //Packet.m_CreativeMode = (char)GetWorld()->GetGameMode(); Packet.m_CreativeMode = (char)m_GameMode; //Set GameMode packet based on Player's GameMode; + + //TODO Less hardcoded + Packet.m_World = 0; + + Packet.m_MapSeed = GetWorld()->GetWorldSeed(); + //Send Packet - e_EPMetaState = NORMAL; m_ClientHandle->Send( Packet ); + + //Set non Burning + SetMetaData(NORMAL); + TeleportTo( GetWorld()->GetSpawnX(), GetWorld()->GetSpawnY(), GetWorld()->GetSpawnZ() ); + SetVisible( true ); } @@ -496,17 +444,16 @@ void cPlayer::SendMessage( const char* a_Message ) m_ClientHandle->Send( cPacket_Chat( a_Message ) ); } -void cPlayer::TeleportTo( cEntity* a_Entity ) -{ - cPawn::TeleportTo( a_Entity ); - cPacket_PlayerPosition PlayerPosition( this ); - m_ClientHandle->Send( PlayerPosition ); -} - void cPlayer::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ) { - cPawn::TeleportTo( a_PosX, a_PosY, a_PosZ ); + SetPosition( a_PosX, a_PosY, a_PosZ ); + + cPacket_TeleportEntity TeleportEntity( this ); + cRoot::Get()->GetServer()->Broadcast( TeleportEntity, GetClientHandle() ); + + cPacket_PlayerPosition PlayerPosition( this ); + m_ClientHandle->Send( PlayerPosition ); } diff --git a/source/cPlayer.h b/source/cPlayer.h index 621b1031c..b0d446434 100644 --- a/source/cPlayer.h +++ b/source/cPlayer.h @@ -28,21 +28,21 @@ public: inline bool GetFlying() { return m_bTouchGround; } //tolua_export inline const double & GetStance() { return m_Stance; } //tolua_export cInventory & GetInventory() { return *m_Inventory; } //tolua_export - virtual void TeleportTo( cEntity* a_Entity ); //tolua_export - virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export - - int GetGameMode() { return m_GameMode; } //tolua_export - std::string GetIP() { return m_IP; } //tolua_export - float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export - int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export - void SetLastBlockActionCnt( int ); //tolua_export - void SetLastBlockActionTime(); //tolua_export - void SetGameMode( int a_GameMode ); //tolua_export + + virtual void TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ ); //tolua_export + + int GetGameMode() { return m_GameMode; } //tolua_export + std::string GetIP() { return m_IP; } //tolua_export + float GetLastBlockActionTime() { return m_LastBlockActionTime; } //tolua_export + int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } //tolua_export + void SetLastBlockActionCnt( int ); //tolua_export + void SetLastBlockActionTime(); //tolua_export + void SetGameMode( int a_GameMode ); //tolua_export void LoginSetGameMode( int a_GameMode ); void SetIP( std::string a_IP ); // Tries to move to a new position, with collision checks and stuff - virtual void MoveTo( const Vector3d & a_NewPos ); //tolua_export + virtual void MoveTo( const Vector3d & a_NewPos ); //tolua_export cWindow* GetWindow() { return m_CurrentWindow; } void OpenWindow( cWindow* a_Window ); @@ -81,12 +81,7 @@ public: bool LoadFromDisk(); const char* GetLoadedWorldName(); - - //Burning logic - bool m_bBurnable; - enum PMetaState{NORMAL,BURNING,CROUCHED,RIDING} e_EPMetaState; - virtual void CheckMetaDataBurn(); - virtual void InStateBurning(float a_Dt); + protected: struct sPlayerState; @@ -106,8 +101,6 @@ protected: void ResolveGroups(); char m_Color; - float m_FireDamageInterval; - float m_BurnPeriod; float m_LastBlockActionTime; int m_LastBlockActionCnt; diff --git a/source/cSkeleton.cpp b/source/cSkeleton.cpp index ea1fd5a77..77a0984de 100644 --- a/source/cSkeleton.cpp +++ b/source/cSkeleton.cpp @@ -22,8 +22,8 @@ void cSkeleton::Tick(float a_Dt) //TODO Outsource //TODO should do lightcheck, not daylight -> mobs in the dark donīt burn - if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight - m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING ) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D } } diff --git a/source/cSquid.cpp b/source/cSquid.cpp index af4b167f2..7ff964ce5 100644 --- a/source/cSquid.cpp +++ b/source/cSquid.cpp @@ -35,16 +35,9 @@ void cSquid::Tick(float a_Dt) //TODO Not a real behavior, but cool :D - if(!IsBlockWater(GetWorld()->GetBlock(Pos.x, Pos.y, Pos.z))) + if(!IsBlockWater(GetWorld()->GetBlock((int) Pos.x, (int) Pos.y, (int) Pos.z)) && GetMetaData() != BURNING) { - //Die slowly Muhahaha :D (To prevent all this squids on the land :D) - m_NoWater += a_Dt; - - if(m_NoWater > 1000.f) - { - m_NoWater -= 1000.f; - TakeDamage(1, this); - } + SetMetaData(BURNING); } } \ No newline at end of file diff --git a/source/cZombie.cpp b/source/cZombie.cpp index 4530cc42f..62ba163e4 100644 --- a/source/cZombie.cpp +++ b/source/cZombie.cpp @@ -21,8 +21,8 @@ void cZombie::Tick(float a_Dt) cMonster::Tick(a_Dt); //TODO Same as in cSkeleton :D - if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight - m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D } } diff --git a/source/cZombiepigman.cpp b/source/cZombiepigman.cpp index 51e817a2b..95a78a4f2 100644 --- a/source/cZombiepigman.cpp +++ b/source/cZombiepigman.cpp @@ -20,9 +20,9 @@ void cZombiepigman::Tick(float a_Dt) { cMonster::Tick(a_Dt); - //TODO Same as noticed in cSkeleton AND Do they really burn? :D In the neather there is no sun :D - if (GetWorld()->GetWorldTime() < (12000 + 1000) ) { //if daylight - m_EMMetaState = BURNING; // BURN, BABY, BURN! >:D + //TODO Same as noticed in cSkeleton AND Do they really burn by sun?? :D In the neather is no sun :D + if (GetWorld()->GetWorldTime() < (12000 + 1000) && GetMetaData() != BURNING ) { //if daylight + SetMetaData(BURNING); // BURN, BABY, BURN! >:D } } diff --git a/source/packets/cPacket_Metadata.cpp b/source/packets/cPacket_Metadata.cpp index 3d3df3b9c..d06bdacbe 100644 --- a/source/packets/cPacket_Metadata.cpp +++ b/source/packets/cPacket_Metadata.cpp @@ -1,7 +1,7 @@ #include "cPacket_Metadata.h" cPacket_Metadata::cPacket_Metadata(int s, int id) - : EMetaState( (MetaState)s ) + : m_EMetaData( (cPawn::MetaData)s ) , m_UniqueID( id ) , m_Type( 0 ) , m_MetaData( 0 ) @@ -11,12 +11,12 @@ cPacket_Metadata::cPacket_Metadata(int s, int id) } cPacket_Metadata::cPacket_Metadata() - : EMetaState(NORMAL) - , m_UniqueID( 0 ) + : m_UniqueID( 0 ) , m_Type( 0 ) , m_MetaData( 0 ) { m_PacketID = E_METADATA; + m_EMetaData = cPawn::NORMAL; FormPacket(); } @@ -30,21 +30,28 @@ void cPacket_Metadata::FormPacket() { m_MetaDataSize = 3; //m_UniqueID = GetUniqueID(); m_MetaData[0] = 0x00; - //m_MetaData[1] = 0x01; //Burning + m_MetaData[2] = 0x7f; - switch(EMetaState) { - case NORMAL: + switch(m_EMetaData) { + case cPawn::NORMAL: m_MetaData[1] = 0x00; break; - case BURNING: + case cPawn::BURNING: m_MetaData[1] = 0x01; break; - case CROUCHED: + case cPawn::CROUCHED: m_MetaData[1] = 0x02; break; - case RIDING: + case cPawn::RIDING: m_MetaData[1] = 0x04; break; + case cPawn::SPRINTING: + m_MetaData[1] = 0x08; + break; + case cPawn::EATING: + case cPawn::BLOCKING: + m_MetaData[1] = 0x10; + break; default: m_MetaData[1] = 0x00; break; diff --git a/source/packets/cPacket_Metadata.h b/source/packets/cPacket_Metadata.h index f96178a2c..00d0ae7d3 100644 --- a/source/packets/cPacket_Metadata.h +++ b/source/packets/cPacket_Metadata.h @@ -1,6 +1,7 @@ #pragma once #include "cPacket.h" #include "PacketID.h" +#include "cPawn.h" class cPacket_Metadata : public cPacket { @@ -13,7 +14,7 @@ public: void FormPacket(); virtual cPacket* Clone() const { return new cPacket_Metadata( *this ); } - enum MetaState{NORMAL,BURNING,CROUCHED,RIDING} EMetaState; + cPawn::MetaData m_EMetaData; static const unsigned int c_Size = 4 + 1; int m_UniqueID; -- cgit v1.2.3