diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index c29ad70..6c28696 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -63,6 +63,8 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI { direction: number; //1 for right, -1 for left + exp_val: number =0; //exp value to give player when this dies + initializeAI(owner: AnimatedSprite, options: Record): void { this.owner = owner; @@ -101,6 +103,9 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI { //this.getPlayerPosition(); this.direction = 1; //default moving to the right + + //exp value + this.exp_val = options.exp; } diff --git a/src/shattered_sword/GameSystems/BattleManager.ts b/src/shattered_sword/GameSystems/BattleManager.ts index 140e82b..ba62595 100644 --- a/src/shattered_sword/GameSystems/BattleManager.ts +++ b/src/shattered_sword/GameSystems/BattleManager.ts @@ -2,13 +2,14 @@ import GameNode from "../../Wolfie2D/Nodes/GameNode"; import BattlerAI from "../AI/BattlerAI"; import Weapon from "./items/Weapon"; +import PlayerController from "../Player/PlayerController"; export default class BattleManager { players: Array; enemies: Array; - handleInteraction(attackerType: string, weapon: Weapon) { + handleInteraction(attackerType: string, weapon: Weapon, user?: GameNode) { //may be unneeded since we are controlling the player - //we determine enemy collision there @@ -26,7 +27,7 @@ export default class BattleManager { // Check for collision with player for (let player of this.players) { if (weapon.hits(player.owner)) { - player.damage(weapon.type.damage); + (player).damage(weapon.type.damage, user); } } } diff --git a/src/shattered_sword/GameSystems/items/Weapon.ts b/src/shattered_sword/GameSystems/items/Weapon.ts index b62c9e1..a89d172 100644 --- a/src/shattered_sword/GameSystems/items/Weapon.ts +++ b/src/shattered_sword/GameSystems/items/Weapon.ts @@ -67,7 +67,7 @@ export default class Weapon extends Item { this.type.doAnimation(user, direction, this.EXTRA_RANGE, ...this.assets); // Apply damage - this.battleManager.handleInteraction(userType, this); + this.battleManager.handleInteraction(userType, this, user); // Reset the cooldown timer this.cooldownTimer.start(); diff --git a/src/shattered_sword/Player/PlayerController.ts b/src/shattered_sword/Player/PlayerController.ts index 9496de9..76a9374 100644 --- a/src/shattered_sword/Player/PlayerController.ts +++ b/src/shattered_sword/Player/PlayerController.ts @@ -17,6 +17,7 @@ import MathUtils from "../../Wolfie2D/Utils/MathUtils"; import Weapon from "../GameSystems/items/Weapon"; import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import InputWrapper from "../Tools/InputWrapper"; +import EnemyAI from "../AI/EnemyAI"; export enum PlayerType { @@ -70,6 +71,9 @@ export default class PlayerController extends StateMachineAI implements BattlerA CURRENT_DEF: number = 100; CURRENT_EXP : number = 0; MAX_EXP : number = 100; + //shield buff + CURRENT_SHIELD : number =0; + MAX_SHIELD : number = 20; invincible : boolean = false; @@ -96,14 +100,43 @@ export default class PlayerController extends StateMachineAI implements BattlerA } - // TODO - - damage(damage: number): void { + // TODO - figure out attacker + damage(damage: number, attacker?: GameNode): void { if( !this.invincible){ - (this.owner).animation.play("HURT", false); - this.CURRENT_HP -= damage; + //shield absorbs the damage and sends dmg back to attacker + if(this.CURRENT_SHIELD > 0){ + let newshield = Math.max(0, this.CURRENT_SHIELD - damage ); //calculate the new shield value + (attacker._ai).damage(this.CURRENT_SHIELD - newshield); //damage the attacker the dmg taken to shield + this.CURRENT_SHIELD = newshield; //update shield value + } + else{ + (this.owner).animation.play("HURT", false); + this.CURRENT_HP -= damage; + } + } } + /** + * gives the player a certain amount of shield + * @param shield amount of shield to add to player + */ + addShield(shield : number){ + this.CURRENT_SHIELD = (this.CURRENT_SHIELD + shield) % this.MAX_SHIELD; + } + + /** + * gives the player exp + * @param exp amount of exp to give the player + */ + giveExp(exp: number){ + this.CURRENT_EXP += exp; + //if > than max exp level up (give buff) + if(this.CURRENT_EXP >= this.MAX_EXP){ + this.CURRENT_EXP -= this.MAX_EXP; + this.emitter.fireEvent(Player_Events.GIVE_BUFF); + } + } //TODO - balance buff value generation /** * returns an array of three randomly generated buffs diff --git a/src/shattered_sword/Player/PlayerStates/Attack.ts b/src/shattered_sword/Player/PlayerStates/Attack.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 53a1d3f..d6e1188 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -66,8 +66,11 @@ export default class GameLevel extends Scene { // Health UI protected healthLabel: Label; - //may need exp label - //may need mp label + //exp label + protected expLabel : Label; + + //shield label + protected shieldLabel : Label; //seed UI protected seedLabel: Label; @@ -205,9 +208,11 @@ export default class GameLevel extends Scene { //remove enemy from enemies this.enemies = this.enemies.filter(item => item !== event.data.get("ai")); this.battleManager.removeEnemy(event.data.get("ai")); - node.destroy(); + //give the player the exp value of the enemy killed + (this.player._ai).giveExp(event.data.get("ai").exp_val); + node.destroy(); //destroy enemy node //TODO - this is for testing, add some chance here later - this.emitter.fireEvent(Player_Events.GIVE_BUFF); + //this.emitter.fireEvent(Player_Events.GIVE_BUFF); break; case Player_Events.GIVE_BUFF: @@ -251,8 +256,20 @@ export default class GameLevel extends Scene { //update health UI let playerAI = (this.player.ai); - this.healthLabel.text = "Player Health: "+ playerAI.CURRENT_HP +'/' + (playerAI.MAX_HP +playerAI.CURRENT_BUFFS.hp ); + this.healthLabel.text = "Health: "+ playerAI.CURRENT_HP +'/' + (playerAI.MAX_HP +playerAI.CURRENT_BUFFS.hp ); + this.healthLabel.sizeToText(); + //update shield ui + this.shieldLabel.text = "Shield: "+ playerAI.CURRENT_SHIELD +'/' + (playerAI.MAX_SHIELD); + this.shieldLabel.sizeToText(); + + //update exp ui + this.expLabel.text = "EXP: "+ playerAI.CURRENT_EXP +'/' + (playerAI.MAX_EXP); + this.expLabel.sizeToText(); + + + + //handle collisions - may be in battle manager instead //move background @@ -354,6 +371,16 @@ export default class GameLevel extends Scene { this.healthLabel.textColor = Color.WHITE; this.healthLabel.font = "PixelSimple"; + this.shieldLabel =