i feel like i should commit my changes so far
This commit is contained in:
parent
db289b3e49
commit
1f01a94368
109
src/battle.ts
Normal file
109
src/battle.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import { Message, TextChannel } from "discord.js";
|
||||||
|
import { Character, CHARACTERS, PotencyStatus } from "./characters";
|
||||||
|
import { Player } from "./models/player";
|
||||||
|
import { Unit } from "./models/unit";
|
||||||
|
|
||||||
|
interface StatusEffects {
|
||||||
|
poison: number
|
||||||
|
regeneration: number
|
||||||
|
burn: number
|
||||||
|
confusion: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PotencyEffects {
|
||||||
|
resistanceChange: PotencyStatus[]
|
||||||
|
accuracyChange: PotencyStatus[]
|
||||||
|
speedChange: PotencyStatus[]
|
||||||
|
}
|
||||||
|
|
||||||
|
class BattleUnit {
|
||||||
|
constructor (unit: Unit) {
|
||||||
|
this.unit = unit;
|
||||||
|
this.defaultHealth = unit.health;
|
||||||
|
this.health = unit.health;
|
||||||
|
this.speed = unit.speed;
|
||||||
|
this.character = CHARACTERS.get(unit.character_id)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
unit: Unit
|
||||||
|
defaultHealth: number
|
||||||
|
health: number
|
||||||
|
speed: number
|
||||||
|
character: Character
|
||||||
|
statusEffects: StatusEffects = {
|
||||||
|
poison: 0,
|
||||||
|
regeneration: 0,
|
||||||
|
burn: 0,
|
||||||
|
confusion: 0
|
||||||
|
}
|
||||||
|
potencyEffects: PotencyEffects = {
|
||||||
|
resistanceChange: [],
|
||||||
|
accuracyChange: [],
|
||||||
|
speedChange: []
|
||||||
|
}
|
||||||
|
active = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Battle {
|
||||||
|
constructor (channel: TextChannel, player1: Player, player2: Player, team1: [Unit, Unit, Unit], team2: [Unit, Unit, Unit]) {
|
||||||
|
this.channel = channel;
|
||||||
|
this.player1 = player1;
|
||||||
|
this.player2 = player2;
|
||||||
|
this.team1 = team1.map(unit => {return new BattleUnit(unit)}) as [BattleUnit, BattleUnit, BattleUnit];
|
||||||
|
this.team2 = team2.map(unit => {return new BattleUnit(unit)}) as [BattleUnit, BattleUnit, BattleUnit];
|
||||||
|
this.units = this.team1.concat(this.team2) as [BattleUnit, BattleUnit, BattleUnit, BattleUnit, BattleUnit, BattleUnit];
|
||||||
|
}
|
||||||
|
|
||||||
|
simulateRound () {
|
||||||
|
this.tickStatuses(this.units);
|
||||||
|
this.checkAlive(this.units);
|
||||||
|
}
|
||||||
|
|
||||||
|
tickStatuses (units: BattleUnit[]) {
|
||||||
|
for (const unit of units) {
|
||||||
|
if (!unit.active) continue;
|
||||||
|
|
||||||
|
if (unit.statusEffects.poison > 0) {
|
||||||
|
unit.statusEffects.poison--
|
||||||
|
const change = Math.floor(unit.defaultHealth/12);
|
||||||
|
unit.health -= change;
|
||||||
|
this.appendLog(`${unit.character.nameShort} took ${change} poison damage!`);
|
||||||
|
}
|
||||||
|
this.log += '\n';
|
||||||
|
if (unit.statusEffects.regeneration > 0) {
|
||||||
|
unit.statusEffects.regeneration--
|
||||||
|
const change = Math.floor(unit.defaultHealth/10)
|
||||||
|
unit.health += change;
|
||||||
|
this.appendLog(`${unit.character.nameShort} regenerated ${change} health!`);
|
||||||
|
}
|
||||||
|
this.log += '\n';
|
||||||
|
if (unit.statusEffects.burn > 0) {
|
||||||
|
unit.statusEffects.burn--
|
||||||
|
unit.health -= 5;
|
||||||
|
this.appendLog(`${unit.character.nameShort} took 5 burn damage!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAlive (units: BattleUnit[]) {
|
||||||
|
for (const unit of units) {
|
||||||
|
if (unit.health <= 0) unit.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appendLog (str: string) {
|
||||||
|
if (this.log) this.log += '\n';
|
||||||
|
this.log += str;
|
||||||
|
return this.log;
|
||||||
|
}
|
||||||
|
|
||||||
|
message?: Message
|
||||||
|
log = ""
|
||||||
|
|
||||||
|
channel: TextChannel
|
||||||
|
player1: Player
|
||||||
|
player2: Player
|
||||||
|
team1: [BattleUnit, BattleUnit, BattleUnit]
|
||||||
|
team2: [BattleUnit, BattleUnit, BattleUnit]
|
||||||
|
units: [BattleUnit, BattleUnit, BattleUnit, BattleUnit, BattleUnit, BattleUnit]
|
||||||
|
}
|
@ -1,21 +1,48 @@
|
|||||||
import charactersJSON from './characters.json'
|
import charactersJSON from './characters.json'
|
||||||
import { Collection } from 'discord.js'
|
import { Collection } from 'discord.js'
|
||||||
|
|
||||||
export enum Type {
|
enum Target {
|
||||||
Something
|
Self = "self",
|
||||||
|
Team = "team",
|
||||||
|
OneOpponent = "oneOpponent",
|
||||||
|
AllOpponents = "allOpponents",
|
||||||
|
TrueRandomOpponent = "trueRandomOpponent"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Character {
|
export interface PotencyStatus {
|
||||||
id: number;
|
duration: number
|
||||||
name: string;
|
potency: number
|
||||||
nameShort: string;
|
}
|
||||||
type: Type;
|
|
||||||
img: string;
|
interface Effect {
|
||||||
stat1: number;
|
target: Target
|
||||||
stat2: number;
|
accuracy?: number
|
||||||
stat3: number;
|
damage?: number
|
||||||
stat4: number;
|
heal?: number
|
||||||
stat5: number;
|
poison?: number
|
||||||
|
regeneration?: number
|
||||||
|
burn?: number
|
||||||
|
confusion?: number
|
||||||
|
resistanceChange?: PotencyStatus
|
||||||
|
accuracyChange?: PotencyStatus
|
||||||
|
speedChange?: PotencyStatus
|
||||||
|
function?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Skill {
|
||||||
|
name: string
|
||||||
|
accuracy?: number
|
||||||
|
effects: Effect[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Character {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
nameShort: string
|
||||||
|
img: string
|
||||||
|
health: number
|
||||||
|
speed: number
|
||||||
|
skills: [Skill, Skill, Skill]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CHARACTERS: Collection<number, Character> = new Collection(charactersJSON.map((element, index) => {return [index, element]}));
|
export const CHARACTERS: Collection<number, Character> = new Collection(charactersJSON.map((element, index) => {return [index, element]}));
|
@ -59,19 +59,10 @@ Unit.init({
|
|||||||
character_id: {
|
character_id: {
|
||||||
type: DataTypes.INTEGER
|
type: DataTypes.INTEGER
|
||||||
},
|
},
|
||||||
stat1: {
|
health: {
|
||||||
type: DataTypes.INTEGER
|
type: DataTypes.INTEGER
|
||||||
},
|
},
|
||||||
stat2: {
|
speed: {
|
||||||
type: DataTypes.INTEGER
|
|
||||||
},
|
|
||||||
stat3: {
|
|
||||||
type: DataTypes.INTEGER
|
|
||||||
},
|
|
||||||
stat4: {
|
|
||||||
type: DataTypes.INTEGER
|
|
||||||
},
|
|
||||||
stat5: {
|
|
||||||
type: DataTypes.INTEGER
|
type: DataTypes.INTEGER
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3,9 +3,6 @@ import { CreationOptional, InferAttributes, InferCreationAttributes, Model } fro
|
|||||||
export class Unit extends Model<InferAttributes<Unit>, InferCreationAttributes<Unit>> {
|
export class Unit extends Model<InferAttributes<Unit>, InferCreationAttributes<Unit>> {
|
||||||
declare user_id: string
|
declare user_id: string
|
||||||
declare character_id: number
|
declare character_id: number
|
||||||
declare stat1: number
|
declare health: number
|
||||||
declare stat2: number
|
declare speed: number
|
||||||
declare stat3: number
|
|
||||||
declare stat4: number
|
|
||||||
declare stat5: number
|
|
||||||
}
|
}
|
@ -26,11 +26,8 @@ export class RollCommand implements SlashCommand {
|
|||||||
await Unit.create({
|
await Unit.create({
|
||||||
user_id: int.user.id,
|
user_id: int.user.id,
|
||||||
character_id: character.id,
|
character_id: character.id,
|
||||||
stat1: character.stat1,
|
health: character.health,
|
||||||
stat2: character.stat2,
|
speed: character.speed
|
||||||
stat3: character.stat3,
|
|
||||||
stat4: character.stat4,
|
|
||||||
stat5: character.stat5
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return int.reply({
|
return int.reply({
|
||||||
|
Loading…
Reference in New Issue
Block a user