Go Back   EQEmulator Home > EQEmulator Forums > Support > Support::Windows Servers

Support::Windows Servers Support forum for Windows EQEMu users.

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2014, 09:55 PM
Furniture
Hill Giant
 
Join Date: Aug 2012
Posts: 205
Default Implementing "melee push" with doknockback?

I am trying to code in the old school melee push from melee hits on my server but I am stuck.

In the attack code for npc attacks, i added this in:

Code:
if (!(other->IsRooted())) {

	other->DoKnockback(this,(MakeRandomFloat(0,.1)),0);
	}
This works as intended, but the downside is that when a player is fleeing and a mob is chasing him down, with each hit the player is moved a little closer to the enemy. If the player is not moving, the push works on the player as intended.

And I realize that DoKnockback() is a mob method but it has a IfClient() check in the beginning so I'm not sure if this would even be able to work on npcs until i attempt to remove the client restriction.

There has to be an easier way to do this. Can anyone point me in the right direction?
Reply With Quote
  #2  
Old 07-16-2014, 11:03 PM
Zaela_S
Hill Giant
 
Join Date: Jun 2012
Posts: 216
Default

Vector math, yay.

I'm not sure if the server codebase has a complete vector implementation, and vector math always confuses me, but I believe you'd want something like this pseudocode:

Code:
Vector a(pusher->GetX(), pusher->GetY(), 0);
Vector b(target->GetX(), target->GetY(), 0);

Vector c = a - b;
c.normalize();
c *= MakeRandomFloat(0, 0.1f); //can leave out if the amount of push should equal 1 unit

b -= c;
Where b ends up being the X+Y position of the target pushed back by the randomized number of units away relative to the pusher's X+Y position. For NPCs you'd just update their position to that and then send out position update packets. Not sure how to apply to Clients; same kind of thing might be okay.

I leave it to you to look up the vector operations if needed cuz I hate em. Maybe we already have functions for that stuff though, too lazy to look right now.
Reply With Quote
  #3  
Old 07-17-2014, 12:56 PM
Furniture
Hill Giant
 
Join Date: Aug 2012
Posts: 205
Default

Luckily, there is a function where this is taken care of:

Code:
void Mob::DoKnockback(Mob *caster, float pushback, uint32 pushup)
{
	if(IsClient())
	{
		CastToClient()->SetKnockBackExemption(true);

		EQApplicationPacket* outapp_push = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
		PlayerPositionUpdateServer_Struct* spu = (PlayerPositionUpdateServer_Struct*)outapp_push->pBuffer;

		double look_heading = caster->CalculateHeadingToTarget(GetX(), GetY());
		look_heading /= 256;
		look_heading *= 360;
		if(look_heading > 360)
			look_heading -= 360;

		//x and y are crossed mkay
		double new_x = pushback * sin(double(look_heading * 3.141592 / 180.0));
		double new_y = pushback * cos(double(look_heading * 3.141592 / 180.0));


		spu->spawn_id	= GetID();
		spu->x_pos		= FloatToEQ19(GetX());
		spu->y_pos		= FloatToEQ19(GetY());
		spu->z_pos		= FloatToEQ19(GetZ());
		spu->delta_x	= NewFloatToEQ13(static_cast<float>(new_x));
		spu->delta_y	= NewFloatToEQ13(static_cast<float>(new_y));
		spu->delta_z	= NewFloatToEQ13(static_cast<float>(pushup));
		spu->heading	= FloatToEQ19(GetHeading());
		spu->padding0002	=0;
		spu->padding0006	=7;
		spu->padding0014	=0x7f;
		spu->padding0018	=0x5df27;
		spu->animation = 0;
		spu->delta_heading = NewFloatToEQ13(0);
		outapp_push->priority = 6;
		entity_list.QueueClients(this, outapp_push, true);
		CastToClient()->FastQueuePacket(&outapp_push);
	}
}
The problem isnt that it isnt getting hit and pushed in the right angle, but when a player is fleeing and is hit by a mob, they are "summoned" a little bit backward toward the mob. When a player is going toe to toe with a mob everything works as intended.
Reply With Quote
  #4  
Old 07-17-2014, 05:00 PM
Zaela_S
Hill Giant
 
Join Date: Jun 2012
Posts: 216
Default

Well I'm not 100% sure, but it looks like that is dependent on the player's heading. So it doesn't push in the right angle, unless the player is facing exactly the right direction (i.e., square centered on the thing pushing them.) It just sends them backwards from whichever way they are currently facing, I assume. Which isn't what you want at all, really.

You might be able to get that packet to do what you want by changing the "spu->heading" to be the inverse of the caster's heading (or this->CalculateHeadingToTarget(caster->GetX(), caster->GetY()) I should say), rather than the player's current heading. Or maybe play with the "spu->delta_heading" field? dunno what that's for... actually, nevermind, that would probably just spin the client around. You wouldn't be able to rely on that packet (at least not alone) for NPCs though since it doesn't actually change their serverside position.

(Vectors and trig are equivalent in this case I guess, but I hate trig even more ;p)
Reply With Quote
  #5  
Old 07-17-2014, 07:28 PM
Furniture
Hill Giant
 
Join Date: Aug 2012
Posts: 205
Default

I didnt realize that the knockback method was working like that. Anyway the code I actually am using that is still reproducing these results is the following:

Code:
void Mob::PushClient(Mob *pusher)
 {

float distance = 0.02;
 
if(distance > 0.0)
 {
 float angle = pusher->GetHeading() / 128.0f * 3.14159;
 // Warp(x_pos + sin(angle) * distance, y_pos + cos(angle) * distance, z_pos);
 
x_pos += sin(angle) * distance;
 y_pos += cos(angle) * distance;
 
EQApplicationPacket* app = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
 PlayerPositionUpdateServer_Struct* spu = (PlayerPositionUpdateServer_Struct*)app->pBuffer;
 MakeSpawnUpdateNoDelta(spu);
 // move_tic_count = 0; Commented because this section was copied and I don't think it applies
 app->priority = 6;
 entity_list.QueueClients(this, app, true);
 CastToClient()->FastQueuePacket(&app);
 safe_delete(app);
 }
 }

This seems to work just fine at least when I use that calculation with players hitting mobs. I am still getting the results with clients however. I didnt write the formula I took it from elsewhere.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 03:41 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3