Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Ranged Combat #330

Draft
wants to merge 4 commits into
base: feature/combat-implementation
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 47 additions & 26 deletions data/config/combat-styles.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,51 @@
"button_id": 3
}
],
"dagger": [
{
"type": "stab",
"exp": "attack",
"anim": "stab",
"button_id": 2
},
{
"type": "stab",
"exp": "strength",
"anim": "stab",
"button_id": 3
},
{
"type": "slash",
"exp": "strength",
"anim": "slash",
"button_id": 4
},
{
"type": "stab",
"exp": "defence",
"anim": "stab",
"button_id": 5
}
]
"dagger": [
{
"type": "stab",
"exp": "attack",
"anim": "stab",
"button_id": 2
},
{
"type": "stab",
"exp": "strength",
"anim": "stab",
"button_id": 3
},
{
"type": "slash",
"exp": "strength",
"anim": "slash",
"button_id": 4
},
{
"type": "stab",
"exp": "defence",
"anim": "stab",
"button_id": 5
}
],
"bow": [
{
"type": "accurate",
"exp": "ranged",
"anim": "ranged",
"button_id": 2
},
{
"type": "rapid",
"exp": "ranged",
"anim": "ranged",
"button_id": 3
},
{
"type": "longrange",
"exp": "ranged",
"anim": "ranged",
"button_id": 4
}
]

}
75 changes: 50 additions & 25 deletions data/config/items/equipment/bows.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,63 @@
{
"rs:shortbow": {
"game_id": 50
},
"rs:longbow": {
"game_id": 48
},
"rs:oak_shortbow": {
"game_id": 54
},
"rs:oak_longbow": {
"game_id": 56
},
"rs:willow_shortbow": {
"game_id": 60
},
"rs:willow_longbow": {
"game_id": 58
},
"rs:maple_shortbow": {
"game_id": 64
"rs:shortbow": {
"game_id": 50
},
"rs:longbow": {
"game_id": 48
},
"rs:oak_shortbow": {
"game_id": 54
},
"rs:oak_longbow": {
"game_id": 56
},
"rs:willow_shortbow": {
"game_id": 60
},
"rs:willow_longbow": {
"game_id": 58
},
"rs:maple_shortbow": {
"game_id": 853,
"examine": "A maple shortbow.",
"tradable": true,
"weight": 1,
"equippable": true,
"equipment_data": {
"equipment_slot": "main_hand",
"equipment_type": "two_handed",
"offensive_bonuses": {
"speed": 4,
"stab": 0,
"slash": 0,
"crush": 0,
"magic": 0,
"ranged": 29
},
"defensive_bonuses": {
"ranged": 0
},
"skill_bonuses": {
"strength": 0
},
"weapon_info": {
"style": "bow"
}
},
"rs:maple_longbow": {
"game_id": 62
"game_id": 62
},
"rs:yew_shortbow": {
"game_id": 68
"game_id": 68
},
"rs:yew_longbow": {
"game_id": 66
"game_id": 66
},
"rs:magic_shortbow": {
"game_id": 72
"game_id": 72
},
"rs:magic_longbow": {
"game_id": 70
"game_id": 70
}
}
}
48 changes: 34 additions & 14 deletions data/config/items/skills/fletching/arrows.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
{
"rs:arrow_shaft": {
"game_id": 52
},
"rs:bronze_arrow": {
"game_id": 882
},
"rs:iron_arrow": {
"game_id": 884
"rs:arrow_shaft": {
"game_id": 52
},
"rs:bronze_arrow": {
"game_id": 882
},
"rs:iron_arrow": {
"game_id": 884,
"tradable": true,
"weight": 0,
"equippable": true,
"equipment_data": {
"equipment_slot": "quiver",
"offensive_bonuses": {
"speed": 0,
"stab": 0,
"slash": 0,
"crush": 0,
"magic": 0,
"ranged": 0
},
"defensive_bonuses": {
"ranged": 0
},
"skill_bonuses": {
"strength": 10
}
},
"rs:steel_arrow": {
"game_id": 886
"game_id": 886
},
"rs:mithril_arrow": {
"game_id": 888
"game_id": 888
},
"rs:broad_arrow": {
"game_id": 4150
"game_id": 4150
},
"rs:adamant_arrow": {
"game_id": 890
"game_id": 890
},
"rs:rune_arrow": {
"game_id": 892
"game_id": 892
}
}
}
}
75 changes: 57 additions & 18 deletions src/game-engine/world/actor/behaviors/auto-attack.behavior.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Actor } from '../actor';
import { regionChangeActionFactory } from '@engine/world/action/region-change.action';
import { Subject } from 'rxjs';
import { logger } from '@runejs/core';
import { Behavior, BehaviorType } from './behavior';
import { Timestamp } from 'rxjs/dist/types/internal/types';
import { timestamp } from 'rxjs/dist/types/operators';
import { Npc } from '../npc/npc';
import { Player } from '../player/player';
import { DamageType } from '../update-flags';
import { Attack, AttackDamageType } from '../player/attack';

export class AutoAttackBehavior extends Behavior {

Expand All @@ -17,12 +16,14 @@ export class AutoAttackBehavior extends Behavior {
private _CoolDown: number = 3;
private _lastAttack = new Date();
private _player: Player;

private _attackType: AttackType;
//this should be called when combat starts
public async init(me: Actor, them: Actor): Promise<void> {
this.Me = me;
this.Them = them;

this._player = (me as Player);
console.log(this._player.damageType);
console.log('all set to auto attack!');
(this.Them as Npc).npcEvents.on('death', (npc) => this._player.onNpcKill);
await super.init(me, them);
Expand All @@ -45,41 +46,79 @@ export class AutoAttackBehavior extends Behavior {
console.log('target too far away - ending combat');
resolve();
}
this._player.face(this.Them);

//If we are not in range move there
if (this.Distance > this.Me.meleeDistance) this.Me.moveTo(this.Them);
//Are you in range to attack?
if (this.Distance <= this.Me.meleeDistance && this.coolDownElapsed) {
this.doAttack();
this.resetCoolDown(this._CoolDown);

if (this.getAttackType() == AttackType.Melee && this.Distance <= this.Me.meleeDistance && this.coolDownElapsed) {
//If we are not in range move there
if (this.Distance > this.Me.meleeDistance) this.Me.moveTo(this.Them);
if (this.coolDownElapsed) this.doAttack();
}
if (this.getAttackType() == AttackType.Ranged) {
this._player.walkingQueue.clear();
if (this.coolDownElapsed) {
console.log("doing ranged attack");
this.doRangedattack();
}
}

this.resetCoolDown(this._CoolDown);

if (this.Them.hitPoints <= 0) {
(this.Them as Npc).npcEvents.emit('death', this.Me, this.Them);
}

if (!this.Me.isDead) super.tick();

resolve();
}


});
}

public async doAttack(): Promise<void> {
return new Promise<void>(resolve => {
//do attack stuff
const attack = this.Me.getAttackRoll(this.Them);
console.log(`you attack ${(this.Them as Npc).name} for ${attack.damage} damage! (after the CD)`);
console.log(`you attack ${(this.Them as Npc).name} for ${attack.damage} damage!`);
this.Them.damage(attack.damage);
if (this.Them.hitPoints <= 0) {
(this.Them as Npc).npcEvents.emit('death', this.Me, this.Them);
}


});
}
public async doRangedattack() {
return new Promise<void>(resolve => {
const attackerX = this._player.position.x;
const attackerY = this._player.position.y
const victimX = this.Them.position.x
const victimY = this.Them.position.y;
const offsetX = ((victimY - attackerY));
const offsetY = ((victimX - attackerX));

this._player.playAnimation(426);
//graphic ids - these are correct
//http://rspscodes.synthasite.com/gfx-list.php
this._player.outgoingPackets.sendProjectile(this._player.position, offsetX, offsetY, 10, 40, 36, 100, this.Them.worldIndex + 1, 1);

this.Them.damage(this.Me.getAttackRoll(this.Them).damage);
});
}
public get coolDownElapsed(): boolean {
if (new Date() > this._lastAttack) return true;
console.log(new Date() > this._lastAttack, (new Date().getSeconds() - this._lastAttack.getSeconds()));
if (new Date().getSeconds() > this._lastAttack.getSeconds()) return true;
return false;
}
public resetCoolDown(seconds: number): void {
this._lastAttack.setSeconds(this._lastAttack.getSeconds() + seconds);
}
public getAttackType() {
var damage = AttackDamageType[AttackDamageType[this._player.damageType]];
if (damage == AttackDamageType.Crush || damage == AttackDamageType.Slash || damage == AttackDamageType.Stab) return AttackType.Melee;
if (damage == AttackDamageType.Range || damage == AttackDamageType.Magic) return AttackType.Ranged;
}

}

enum AttackType {
Melee,
Ranged

}