logic monster
This commit is contained in:
parent
08a249feb3
commit
b54edaf8d4
@ -1,5 +1,5 @@
|
||||
import { Message, TextChannel } from "discord.js";
|
||||
import { Character, CHARACTERS, PotencyStatus } from "./characters";
|
||||
import { Character, CHARACTERS, PotencyStatus, Target } from "./characters";
|
||||
import { Player } from "./models/player";
|
||||
import { Unit } from "./models/unit";
|
||||
|
||||
@ -88,6 +88,65 @@ export class Battle {
|
||||
}
|
||||
}
|
||||
|
||||
useSkills (units: BattleUnit[]) {
|
||||
const order = [];
|
||||
|
||||
for (let i = 0; i < units.length; i++) {
|
||||
const rolls = []
|
||||
let modifiedSpeed = units[i].speed
|
||||
for (const change of units[i].potencyEffects.accuracyChange) {
|
||||
modifiedSpeed -= change.potency;
|
||||
}
|
||||
for (let o = 0; o < modifiedSpeed; o++) {
|
||||
rolls.push(Math.random());
|
||||
}
|
||||
const initiative = Math.max(...rolls);
|
||||
order.push([i, initiative]);
|
||||
}
|
||||
|
||||
order.sort((a, b) => {return b[1] - a[1]});
|
||||
|
||||
for (const initiative of order) {
|
||||
const unit = units[initiative[1]];
|
||||
const skill = unit.character.skills[Math.floor(Math.random()*unit.character.skills.length)];
|
||||
const team = initiative[0] < 3 ? 1 : 2
|
||||
const target = team === 1 ? this.team2[Math.floor(Math.random()*this.team2.length)] : this.team1[Math.floor(Math.random()*this.team1.length)];
|
||||
const allyTarget = team === 1 ? this.team1[Math.floor(Math.random()*this.team1.length)] : this.team2[Math.floor(Math.random()*this.team2.length)];
|
||||
|
||||
if (skill.accuracy && Math.random()*100 > skill.accuracy) {
|
||||
this.appendLog(`${unit.character.nameShort} used ${skill.name}, but missed!`);
|
||||
}
|
||||
|
||||
this.appendLog(`${unit.character.nameShort} used ${skill.name}!`);
|
||||
for (const effect of skill.effects) {
|
||||
switch (effect.target){
|
||||
case Target.Self:
|
||||
this.runEffect([unit]);
|
||||
break;
|
||||
case Target.Team:
|
||||
this.runEffect(team === 1 ? this.team1 : this.team2);
|
||||
break;
|
||||
case Target.OneTeammate:
|
||||
this.runEffect([allyTarget]);
|
||||
break;
|
||||
case Target.OneOpponent:
|
||||
this.runEffect([target]);
|
||||
break;
|
||||
case Target.AllOpponents:
|
||||
this.runEffect(team === 1 ? this.team2 : this.team1);
|
||||
break;
|
||||
case Target.TrueRandomOpponent:
|
||||
this.runEffect([team === 1 ? this.team2[Math.floor(Math.random()*this.team2.length)] : this.team1[Math.floor(Math.random()*this.team1.length)]]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runEffect (targets: BattleUnit[]) {
|
||||
|
||||
}
|
||||
|
||||
checkAlive (units: BattleUnit[]) {
|
||||
for (const unit of units) {
|
||||
if (unit.health <= 0) unit.active = false;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import charactersJSON from './characters.json'
|
||||
import { Collection } from 'discord.js'
|
||||
|
||||
enum Target {
|
||||
export enum Target {
|
||||
Self = "self",
|
||||
Team = "team",
|
||||
OneTeammate = "oneTeammate",
|
||||
|
Loading…
Reference in New Issue
Block a user