Char - WIP

This commit is contained in:
2022-01-06 18:22:05 +01:00
parent 7a06989d87
commit a8a27d1924
34 changed files with 693 additions and 144 deletions

View File

@@ -48,6 +48,7 @@ export class PegasusActorSheet extends ActorSheet {
shields: duplicate(this.actor.getShields()),
equipments: duplicate(this.actor.getEquipments()),
perks: duplicate(this.actor.getPerks()),
abilities: duplicate(this.actor.getAbilities()),
activePerks: duplicate(this.actor.getActivePerks()),
powers: duplicate(this.actor.getPowers()),
subActors: duplicate(this.actor.getSubActors()),

View File

@@ -90,6 +90,11 @@ export class PegasusActor extends Actor {
return perks;
}
/* -------------------------------------------- */
getAbilities() {
let ab = this.data.items.filter( item => item.type == 'ability');
return ab;
}
/* -------------------------------------------- */
getPerks() {
let comp = this.data.items.filter( item => item.type == 'perk');
return comp;
@@ -472,6 +477,34 @@ export class PegasusActor extends Actor {
}
}
/* -------------------------------------------- */
async applyRace( race ) {
let updates = { 'data.racename':race.name }
let newItems = []
newItems.push(race);
for (let ability of race.data.abilities) {
console.log("Ability", ability)
if ( ability.data.affectedstat == "notapplicable") {
newItems.push(ability);
} else {
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
stat.value += parseInt(ability.data.statlevelincrease)
stat.mod += parseInt(ability.data.statmodifier)
updates[`data.statistics.${ability.data.affectedstat}`] = stat
}
}
await this.update( updates )
await this.createEmbeddedDocuments('Item', newItems)
console.log("Updates", updates, newItems)
console.log("Updated actor", this)
}
/* -------------------------------------------- */
applyRole( role ) {
console.log("ROLE", role)
}
/* -------------------------------------------- */
async rollPower( powId ) {
let power = this.data.items.find( item => item.type == 'power' && item.id == powId);

108
modules/pegasus-commands.js Normal file
View File

@@ -0,0 +1,108 @@
/* -------------------------------------------- */
import { PegasusActorCreate } from "./pegasus-create-char.js";
import { PegasusUtility } from "./pegasus-utility.js";
/* -------------------------------------------- */
export class PegasusCommands {
static init() {
if (!game.system.pegasus.commands) {
const pegasusCommands = new PegasusCommands();
pegasusCommands.registerCommand({ path: ["/char"], func: (content, msg, params) => pegasusCommands.createChar(msg), descr: "Create a new character" });
game.system.pegasus.commands = pegasusCommands;
}
}
constructor() {
this.commandsTable = {};
}
/* -------------------------------------------- */
registerCommand(command) {
this._addCommand(this.commandsTable, command.path, '', command);
}
/* -------------------------------------------- */
_addCommand(targetTable, path, fullPath, command) {
if (!this._validateCommand(targetTable, path, command)) {
return;
}
const term = path[0];
fullPath = fullPath + term + ' '
if (path.length == 1) {
command.descr = `<strong>${fullPath}</strong>: ${command.descr}`;
targetTable[term] = command;
}
else {
if (!targetTable[term]) {
targetTable[term] = { subTable: {} };
}
this._addCommand(targetTable[term].subTable, path.slice(1), fullPath, command)
}
}
/* -------------------------------------------- */
_validateCommand(targetTable, path, command) {
if (path.length > 0 && path[0] && command.descr && (path.length != 1 || targetTable[path[0]] == undefined)) {
return true;
}
console.warn("pegasusCommands._validateCommand failed ", targetTable, path, command);
return false;
}
/* -------------------------------------------- */
/* Manage chat commands */
processChatCommand(commandLine, content = '', msg = {}) {
// Setup new message's visibility
let rollMode = game.settings.get("core", "rollMode");
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperRecipients("GM");
if (rollMode === "blindroll") msg["blind"] = true;
msg["type"] = 0;
let command = commandLine[0].toLowerCase();
let params = commandLine.slice(1);
return this.process(command, params, content, msg);
}
process(command, params, content, msg) {
return this._processCommand(this.commandsTable, command, params, content, msg);
}
_processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
let command = commandsTable[name];
path = path + name + " ";
if (command && command.subTable) {
if (params[0]) {
return this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path)
}
else {
this.help(msg, command.subTable);
return true;
}
}
if (command && command.func) {
const result = command.func(content, msg, params);
if (result == false) {
RdDCommands._chatAnswer(msg, command.descr);
}
return true;
}
return false;
}
/* -------------------------------------------- */
async createChar(msg) {
game.system.pegasus.creator = new PegasusActorCreate();
game.system.pegasus.creator.start();
}
/* -------------------------------------------- */
static _chatAnswer(msg, content) {
msg.whisper = [game.user.id];
msg.content = content;
ChatMessage.create(msg);
}
}

View File

@@ -0,0 +1,66 @@
import { PegasusUtility } from "./pegasus-utility.js";
import { PegasusActor } from "./pegasus-actor.js";
import { PegasusActorSheet } from "./pegasus-actor-sheet.js";
export class PegasusActorCreate {
/* -------------------------------------------- */
async start() {
this.actor = await Actor.create({
name: "New Actor",
type: "character"
});
this.actor.sheet.render(true);
const racesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.race");
this.races = racesPack.map(i => i.toObject());
const rolesPack = await PegasusUtility.loadCompendium("fvtt-pegasus-rpg.role");
this.roles = rolesPack.map(i => i.toObject());
this.showRaces()
}
/* -------------------------------------------- */
createFormData(step) {
let formData = {
name: this.actor.name,
img: this.actor.img,
step: step,
races: this.races,
roles: this.roles
}
return formData;
}
/* -------------------------------------------- */
processChatEvent( event ) {
const step = $(event.currentTarget).data("step-name");
const itemId = $(event.currentTarget).data("item-id");
console.log("Create chat evet", event, itemId, step)
if ( step == "select-race") {
let race = this.races.find( item => item._id == itemId);
this.actor.applyRace( race)
}
}
/* -------------------------------------------- */
async showRaces() {
let formData = this.createFormData("select-race")
let chatData = {
user: game.user.id,
alias : this.actor.name,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
content: await renderTemplate('systems/fvtt-pegasus-rpg/templates/chat-create-actor.html', formData)
};
//console.log("Apply damage chat", chatData );
await ChatMessage.create( chatData );
}
/* -------------------------------------------- */
async showRoles() {
console.log("Available roles", roles);
// TODO : display buttons
}
}

View File

@@ -55,8 +55,7 @@ Hooks.once("init", async function () {
CONFIG.Combat.documentClass = PegasusCombat;
CONFIG.Actor.documentClass = PegasusActor;
CONFIG.Item.documentClass = PegasusItem;
CONFIG.WOTG = {
}
game.system.pegasus = { };
/* -------------------------------------------- */
// Register sheet application classes
@@ -110,8 +109,11 @@ Hooks.once("ready", function () {
Hooks.on("chatMessage", (html, content, msg) => {
if (content[0] == '/') {
let regExp = /(\S+)/g;
let commands = content.toLowerCase().match(regExp);
console.log(commands);
let commands = content.match(regExp);
if (game.system.pegasus.commands.processChatCommand(commands, content, msg)) {
return false;
}
}
return true;
});

View File

@@ -1,3 +1,7 @@
/* -------------------------------------------- */
import { PegasusCommands } from "./pegasus-commands.js";
import { PegasusActorCreate } from "./pegasus-create-char.js";
/* -------------------------------------------- */
const __level2Dice = [ "d0", "d4", "d6", "d8", "d10", "d12" ];
@@ -14,7 +18,9 @@ export class PegasusUtility {
this.diceFoundryList = [];
this.optionsDiceList = "";
this.buildDiceLists();
PegasusCommands.init();
}
/* -------------------------------------------- */
static getSpecs( ) {
return this.specs;
@@ -26,6 +32,18 @@ export class PegasusUtility {
this.specs = specs.map(i => i.toObject());
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium);
return await pack?.getDocuments() ?? [];
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await PegasusUtility.loadCompendiumData(compendium);
return compendiumData.filter(filter);
}
/* -------------------------------------------- */
static buildDiceLists() {
let maxLevel = game.settings.get("fvtt-pegasus-rpg", "dice-max-level");
@@ -98,29 +116,11 @@ export class PegasusUtility {
/* -------------------------------------------- */
static async chatListeners(html) {
html.on("click", '.apply-technique-cost', event => {
const rollId = $(event.currentTarget).data("roll-id");
const actorId = $(event.currentTarget).data("actor-id");
const techId = $(event.currentTarget).data("technique-id");
let actor = game.actors.get( actorId);
actor.applyTechniqueCost(techId);
});
html.on("click", '.chat-create-actor', event => {
console.log("Event !")
game.system.pegasus.creator.processChatEvent(event);
} );
html.on("click", '.apply-defense-roll', event => {
const defenseRollId = $(event.currentTarget).data("roll-id");
this.computeAttackDefense(defenseRollId);
});
html.on("click", '.apply-nodefense', event => {
const actorId = $(event.currentTarget).data("actor-id");
const rollId = $(event.currentTarget).data("roll-id");
this.applyNoDefense(actorId, rollId);
});
html.on("click", '.apply-damage', event => {
const rollId = $(event.currentTarget).data("roll-id");
this.applyDamage(rollId);
});
}
/* -------------------------------------------- */