summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/protocol.cpp23
-rw-r--r--src/net/protocol.h3
2 files changed, 26 insertions, 0 deletions
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);