diff --git a/data/config/combat-styles.json b/data/config/combat-styles.json index 2c6cafa89..a4fb3e261 100644 --- a/data/config/combat-styles.json +++ b/data/config/combat-styles.json @@ -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 + } + ] + } diff --git a/data/config/items/equipment/bows.json b/data/config/items/equipment/bows.json index dc9e9510f..ad022de30 100644 --- a/data/config/items/equipment/bows.json +++ b/data/config/items/equipment/bows.json @@ -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 } + } } diff --git a/data/config/items/skills/fletching/arrows.json b/data/config/items/skills/fletching/arrows.json index 1003b76c3..963d1018b 100644 --- a/data/config/items/skills/fletching/arrows.json +++ b/data/config/items/skills/fletching/arrows.json @@ -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 } -} + } +} \ No newline at end of file diff --git a/src/game-engine/world/actor/behaviors/auto-attack.behavior.ts b/src/game-engine/world/actor/behaviors/auto-attack.behavior.ts index f50991cef..ab94a3e59 100644 --- a/src/game-engine/world/actor/behaviors/auto-attack.behavior.ts +++ b/src/game-engine/world/actor/behaviors/auto-attack.behavior.ts @@ -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 { @@ -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 { 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); @@ -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 { return new Promise(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(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 + } \ No newline at end of file