From 0c6830040481247a96ccc8fe15f9b1022506c0ae Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Sun, 22 May 2005 13:02:47 +0000 Subject: An attemp on auto attack, not bug free for sure --- src/net/protocol.cpp | 23 +++++++++++++++++++++++ src/net/protocol.h | 3 +++ 2 files changed, 26 insertions(+) (limited to 'src/net') diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index e3b84457..7dc83cfa 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -248,3 +248,26 @@ void attack(unsigned short x, unsigned short y, unsigned char direction) // implement charging attacks here char_info->lastAttackTime = 0; } + +void attack(Being *target) { + int dist_x = target->x - player_node->x; + int dist_y = target->y - player_node->y; + if (abs(dist_y) >= abs(dist_x)) { + if (dist_y > 0) + player_node->direction = SOUTH; + else + player_node->direction = NORTH; + } else { + if (dist_x > 0) + player_node->direction = EAST; + else + player_node->direction = WEST; + } + player_node->action = ATTACK; + action(0, target->id); + player_node->walk_time = tick_time; + if (player_node->weapon == 2) + sound.playSfx("sfx/bow_shoot_1.ogg"); + else + sound.playSfx("sfx/fist-swish.ogg"); +} diff --git a/src/net/protocol.h b/src/net/protocol.h index 14c21d59..dd6b36e2 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -83,6 +83,9 @@ void speak(char *speech); /** Request to attack */ void attack(unsigned short x, unsigned short y, unsigned char direction); +/** Request to attack */ +void attack(Being *target); + /** Request action */ void action(char type, int id); -- cgit v1.2.3-70-g09d2