Roll : Added target info in ChatMessage

This commit is contained in:
Vlyan
2022-02-16 17:20:56 +01:00
parent bc103c2988
commit 448fadeca7
22 changed files with 295 additions and 101 deletions

View File

@@ -2,82 +2,6 @@
* L5R Character generator base object
*/
export class CharacterGenerator {
//<editor-fold desc="Config Datas">
static demeanorList = [
{ id: "adaptable", mod: { fire: 2, earth: -2 } },
{ id: "adaptable", mod: { water: 2, earth: -2 } },
{ id: "aggressive", mod: { fire: 2, air: -2 } },
{ id: "aggressive", mod: { fire: 2, water: -2 } },
{ id: "ambitious", mod: { fire: 2, water: -2 } },
{ id: "amiable", mod: { air: 2, earth: -2 } },
{ id: "analytical", mod: { fire: 2, air: -2 } },
{ id: "angry", mod: { fire: 2, air: -2 } },
{ id: "arrogant", mod: { fire: 2, water: -2 } },
{ id: "assertive", mod: { earth: 2, air: -2 } },
{ id: "assertive", mod: { earth: 2, air: 2 } },
{ id: "beguiling", mod: { air: 2, earth: -2 } },
{ id: "beguiling", mod: { fire: 2, earth: -2 } },
{ id: "bitter", mod: { fire: 2, air: -2 } },
{ id: "bold", mod: { fire: 1, earth: -1 } },
{ id: "calculating", mod: { air: 2, fire: -2 } },
{ id: "calm", mod: { fire: 2, air: -2 } },
{ id: "capricious", mod: { air: 2, earth: -2 } },
{ id: "cautious", mod: { air: 2, earth: -2 } },
{ id: "clever", mod: { air: 2, earth: -2 } },
{ id: "confused", mod: { fire: 1, void: 1, air: -2 } },
{ id: "courageous", mod: { air: 2, earth: -2 } },
{ id: "cowardly", mod: { earth: 2, fire: -2 } },
{ id: "curious", mod: { earth: 1, void: -2 } },
{ id: "curious", mod: { fire: 1, void: 1, air: -2 } },
{ id: "dependable", mod: { fire: 1, water: 1, earth: -2 } },
{ id: "detached", mod: { earth: 1, fire: 1, void: -2 } },
{ id: "disheartened", mod: { fire: 1, earth: -1 } },
{ id: "enraged", mod: { air: 1, fire: -2 } },
{ id: "feral", mod: { air: 2, fire: -2 } },
{ id: "fickle", mod: { fire: 2, air: -2 } },
{ id: "fierce", mod: { fire: 2, earth: -2 } },
{ id: "flighty", mod: { air: 2, fire: -2 } },
{ id: "flighty", mod: { water: 2, fire: -2 } },
{ id: "flippant", mod: { fire: 2, air: -2 } },
{ id: "friendly", mod: { fire: 1, earth: -2, water: -2 } },
{ id: "gruff", mod: { water: 2, earth: -2 } },
{ id: "hungry", mod: { fire: 2, air: -2 } },
{ id: "intense", mod: { air: 2, water: -2 } },
{ id: "intense", mod: { fire: 2, water: -2 } },
{ id: "intimidating", mod: { fire: 2, air: -2 } },
{ id: "irritable", mod: { fire: 2, air: -1, water: -1 } },
{ id: "loyal", mod: { air: 1, earth: -2, fire: -2 } },
{ id: "loyal", mod: { water: 2, fire: -2 } },
{ id: "mischievous", mod: { fire: 2, air: -2 } },
{ id: "mischievous", mod: { air: 2, earth: -2 } },
{ id: "mischievous", mod: { earth: 2, fire: -2 } },
{ id: "morose", mod: { water: 2, fire: -2 } },
{ id: "nurturing", mod: { earth: 2, fire: -2 } },
{ id: "obstinate", mod: { earth: 2, air: -2 } },
{ id: "obstinate", mod: { water: 2, air: -2 } },
{ id: "opportunistic", mod: { water: 2, fire: -2 } },
{ id: "passionate", mod: { earth: 2, air: -2 } },
{ id: "playful", mod: { earth: 2, water: -2 } },
{ id: "playful", mod: { fire: 1, air: 1, void: -2 } },
{ id: "power_hungry", mod: { fire: 2, earth: -2 } },
{ id: "proud", mod: { fire: 2, earth: -2 } },
{ id: "restrained", mod: { earth: 2, air: -2 } },
{ id: "scheming", mod: { air: 2, void: -2 } },
{ id: "serene", mod: { fire: 2, void: -2 } },
{ id: "serene", mod: { void: 2, fire: -2 } },
{ id: "serious", mod: { fire: 2, earth: -2 } },
{ id: "shrewd", mod: { air: 2, fire: -2 } },
{ id: "stubborn", mod: { earth: 2, water: -2 } },
{ id: "suspicious", mod: { air: 2, earth: -2 } },
{ id: "teasing", mod: { air: 2, earth: -2 } },
{ id: "territorial", mod: { fire: 2, air: -2 } },
{ id: "uncertain", mod: { air: 2, fire: -2 } },
{ id: "unenthused", mod: { earth: 2, fire: -2 } },
{ id: "vain", mod: { earth: 2, air: -2 } },
{ id: "wary", mod: { earth: 2, fire: -2 } },
];
//</editor-fold>
/**
* Payload Object
*/
@@ -464,7 +388,7 @@ export class CharacterGenerator {
*/
_generateDemeanor(actorDatas) {
// demeanor { id: "adaptable", mod: { fire: 2, earth: -2 } },
const demeanor = CharacterGenerator._getRandomArrayValue(CharacterGenerator.demeanorList);
const demeanor = CharacterGenerator._getRandomArrayValue(CONFIG.l5r5e.demeanorList);
actorDatas.attitude = game.i18n.localize("l5r5e.demeanor." + demeanor.id);
actorDatas.rings_affinities = foundry.utils.mergeObject(
{

View File

@@ -80,9 +80,7 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"data.identity.clan",
Object.entries(game.i18n.translations.l5r5e.clans)
.filter(([k, v]) => k !== "title")
.map(([k, v]) => v)
game.l5r5e.HelpersL5r5e.getLocalizedClansList()
);
game.l5r5e.HelpersL5r5e.autocomplete(
html,
@@ -93,6 +91,12 @@ export class CharacterSheetL5r5e extends BaseCharacterSheetL5r5e {
)?.[0]
)
);
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"data.identity.roles",
game.l5r5e.HelpersL5r5e.getLocalizedRolesList(),
","
);
// Open linked school curriculum journal
html.find(".school-journal-link").on("click", this._openLinkedJournal.bind(this));

View File

@@ -52,4 +52,30 @@ export class NpcSheetL5r5e extends BaseCharacterSheetL5r5e {
return sheetData;
}
/**
* Subscribe to events from the sheet.
* @param {jQuery} html HTML content of the sheet.
*/
activateListeners(html) {
super.activateListeners(html);
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable) {
return;
}
// Autocomplete
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"data.attitude",
CONFIG.l5r5e.demeanorList.map((e) => {
let modifiers = [];
Object.entries(e.mod).forEach(([k, v]) => {
modifiers.push(`${game.i18n.localize(`l5r5e.rings.${k}`)} ${v}`);
});
return game.i18n.localize(`l5r5e.demeanor.${e.id}`) + ` (${modifiers.join(", ")})`;
})
);
}
}

View File

@@ -221,6 +221,19 @@ export class TwentyQuestionsDialog extends FormApplication {
await this.object.toActor(this.actor, flattenObject(this.cache));
await this.close({ submit: true, force: true });
});
// Autocomplete
game.l5r5e.HelpersL5r5e.autocomplete(html, "step1.clan", game.l5r5e.HelpersL5r5e.getLocalizedClansList());
game.l5r5e.HelpersL5r5e.autocomplete(
html,
"step2.family",
CONFIG.l5r5e.families.get(
Object.entries(game.i18n.translations.l5r5e.clans).find(
([k, v]) => v === this.object.data.step1.clan
)?.[0]
)
);
game.l5r5e.HelpersL5r5e.autocomplete(html, "step3.roles", game.l5r5e.HelpersL5r5e.getLocalizedRolesList(), ",");
}
/**

View File

@@ -7,6 +7,7 @@ L5R5E.paths = {
L5R5E.money = [50, 10];
L5R5E.stances = ["earth", "air", "water", "fire", "void"];
L5R5E.roles = ["artisan", "bushi", "courtier", "monk", "sage", "shinobi", "shugenja"];
L5R5E.xp = {
costPerRank: [0, 20, 24, 32, 44, 60],
@@ -148,3 +149,78 @@ L5R5E.families.set("tortoise", ["Kasuga"]);
L5R5E.families.set("ivory_kingdoms", []);
L5R5E.families.set("qamarist", []);
L5R5E.families.set("ujik", []);
// *** demeanor ***
L5R5E.demeanorList = [
{ id: "adaptable", mod: { fire: 2, earth: -2 } },
{ id: "adaptable", mod: { water: 2, earth: -2 } },
{ id: "aggressive", mod: { fire: 2, air: -2 } },
{ id: "aggressive", mod: { fire: 2, water: -2 } },
{ id: "ambitious", mod: { fire: 2, water: -2 } },
{ id: "amiable", mod: { air: 2, earth: -2 } },
{ id: "analytical", mod: { fire: 2, air: -2 } },
{ id: "angry", mod: { fire: 2, air: -2 } },
{ id: "arrogant", mod: { fire: 2, water: -2 } },
{ id: "assertive", mod: { earth: 2, air: -2 } },
{ id: "assertive", mod: { earth: 2, air: 2 } },
{ id: "beguiling", mod: { air: 2, earth: -2 } },
{ id: "beguiling", mod: { fire: 2, earth: -2 } },
{ id: "bitter", mod: { fire: 2, air: -2 } },
{ id: "bold", mod: { fire: 1, earth: -1 } },
{ id: "calculating", mod: { air: 2, fire: -2 } },
{ id: "calm", mod: { fire: 2, air: -2 } },
{ id: "capricious", mod: { air: 2, earth: -2 } },
{ id: "cautious", mod: { air: 2, earth: -2 } },
{ id: "clever", mod: { air: 2, earth: -2 } },
{ id: "confused", mod: { fire: 1, void: 1, air: -2 } },
{ id: "courageous", mod: { air: 2, earth: -2 } },
{ id: "cowardly", mod: { earth: 2, fire: -2 } },
{ id: "curious", mod: { earth: 1, void: -2 } },
{ id: "curious", mod: { fire: 1, void: 1, air: -2 } },
{ id: "dependable", mod: { fire: 1, water: 1, earth: -2 } },
{ id: "detached", mod: { earth: 1, fire: 1, void: -2 } },
{ id: "disheartened", mod: { fire: 1, earth: -1 } },
{ id: "enraged", mod: { air: 1, fire: -2 } },
{ id: "feral", mod: { air: 2, fire: -2 } },
{ id: "fickle", mod: { fire: 2, air: -2 } },
{ id: "fierce", mod: { fire: 2, earth: -2 } },
{ id: "flighty", mod: { air: 2, fire: -2 } },
{ id: "flighty", mod: { water: 2, fire: -2 } },
{ id: "flippant", mod: { fire: 2, air: -2 } },
{ id: "friendly", mod: { fire: 1, earth: -2, water: -2 } },
{ id: "gruff", mod: { water: 2, earth: -2 } },
{ id: "hungry", mod: { fire: 2, air: -2 } },
{ id: "intense", mod: { air: 2, water: -2 } },
{ id: "intense", mod: { fire: 2, water: -2 } },
{ id: "intimidating", mod: { fire: 2, air: -2 } },
{ id: "irritable", mod: { fire: 2, air: -1, water: -1 } },
{ id: "loyal", mod: { air: 1, earth: -2, fire: -2 } },
{ id: "loyal", mod: { water: 2, fire: -2 } },
{ id: "mischievous", mod: { fire: 2, air: -2 } },
{ id: "mischievous", mod: { air: 2, earth: -2 } },
{ id: "mischievous", mod: { earth: 2, fire: -2 } },
{ id: "morose", mod: { water: 2, fire: -2 } },
{ id: "nurturing", mod: { earth: 2, fire: -2 } },
{ id: "obstinate", mod: { earth: 2, air: -2 } },
{ id: "obstinate", mod: { water: 2, air: -2 } },
{ id: "opportunistic", mod: { water: 2, fire: -2 } },
{ id: "passionate", mod: { earth: 2, air: -2 } },
{ id: "playful", mod: { earth: 2, water: -2 } },
{ id: "playful", mod: { fire: 1, air: 1, void: -2 } },
{ id: "power_hungry", mod: { fire: 2, earth: -2 } },
{ id: "proud", mod: { fire: 2, earth: -2 } },
{ id: "restrained", mod: { earth: 2, air: -2 } },
{ id: "scheming", mod: { air: 2, void: -2 } },
{ id: "serene", mod: { fire: 2, void: -2 } },
{ id: "serene", mod: { void: 2, fire: -2 } },
{ id: "serious", mod: { fire: 2, earth: -2 } },
{ id: "shrewd", mod: { air: 2, fire: -2 } },
{ id: "stubborn", mod: { earth: 2, water: -2 } },
{ id: "suspicious", mod: { air: 2, earth: -2 } },
{ id: "teasing", mod: { air: 2, earth: -2 } },
{ id: "territorial", mod: { fire: 2, air: -2 } },
{ id: "uncertain", mod: { air: 2, fire: -2 } },
{ id: "unenthused", mod: { earth: 2, fire: -2 } },
{ id: "vain", mod: { earth: 2, air: -2 } },
{ id: "wary", mod: { earth: 2, fire: -2 } },
];

View File

@@ -41,8 +41,8 @@ export class DicePickerDialog extends FormApplication {
value: 2,
hidden: false,
addVoidPoint: false,
targetTokenId: null,
},
targetInfos: null,
useVoidPoint: false,
isInitiativeRoll: false,
};
@@ -534,7 +534,7 @@ export class DicePickerDialog extends FormApplication {
roll.l5r5e.difficultyHidden = this.object.difficulty.hidden;
roll.l5r5e.voidPointUsed = this.object.useVoidPoint;
roll.l5r5e.skillAssistance = this.object.skill.assistance;
roll.l5r5e.targetTokenId = this.object.difficulty.targetTokenId;
roll.l5r5e.targetInfos = this.object.targetInfos;
await roll.roll();
message = await roll.toMessage();
@@ -694,18 +694,17 @@ export class DicePickerDialog extends FormApplication {
// Define which actor is needed for the difficulty
let targetActor = null;
let targetTokenId = null;
let targetToken = null;
if (infos[1] === "S") {
targetActor = this._actor;
} else if (game.user.targets.size > 0) {
// Between the targets
const targetToken = DicePickerDialog._getTargetTokenFromSelection(
targetToken = DicePickerDialog._getTargetTokenFromSelection(
infos[4] || infos[2],
!infos[3] ? null : infos[3] === "min"
);
if (targetToken) {
targetActor = targetToken.actor;
targetTokenId = targetToken.data._id;
}
}
// Wrong syntax or no target set, do manual TN
@@ -728,7 +727,10 @@ export class DicePickerDialog extends FormApplication {
if (infos[1] === "T") {
this.difficultyHidden = true;
this._difficultyHiddenIsLock.option = true;
this.object.difficulty.targetTokenId = targetTokenId;
this.object.targetInfos = {
img: targetToken.data.img,
name: targetToken.data.name,
};
}
return true;
}

View File

@@ -34,7 +34,7 @@ export class RollL5r5e extends Roll {
opportunity: 0,
strife: 0,
},
targetTokenId: null,
targetInfos: null,
voidPointUsed: false,
};

View File

@@ -79,6 +79,24 @@ export class HelpersL5r5e {
}));
}
/**
* Return the list of Clans
* @return {string[]}
*/
static getLocalizedClansList() {
return Object.entries(game.i18n.translations.l5r5e.clans)
.filter(([k, v]) => k !== "title")
.map(([k, v]) => v);
}
/**
* Return the list of Roles
* @return {string[]}
*/
static getLocalizedRolesList() {
return CONFIG.l5r5e.roles.map((e) => game.i18n.localize(`l5r5e.roles.${e}`));
}
/**
* Return the target object on a drag n drop event, or null if not found
* @param {DragEvent} event
@@ -720,8 +738,11 @@ export class HelpersL5r5e {
* @param {jQuery} html HTML content of the sheet.
* @param {string} name Html name of the input
* @param {string[]} list Array of string to display
* @param {string} sep (optional) Separator
*/
static autocomplete(html, name, list = []) {
static autocomplete(html, name, list = [], sep = "") {
return; // TODO tmp disabled
/*
const inp = document.getElementsByName(name)?.[0];
if (list.length < 1) {
return;
@@ -741,11 +762,20 @@ export class HelpersL5r5e {
inp.addEventListener("input", (inputEvent) => {
closeAllLists();
const val = inputEvent.target.value;
let val = inputEvent.target.value.trim();
if (!val) {
return false;
}
// separator
let previous = [val];
let currentIdx = 0;
if (sep) {
currentIdx = (val.substring(0, inputEvent.target.selectionStart).match(new RegExp(`[${sep}]`, "g")) || []).length;
previous = val.split(sep);
val = previous[currentIdx].trim();
}
currentFocus = -1;
// create a DIV element that will contain the items (values)
@@ -772,7 +802,8 @@ export class HelpersL5r5e {
if (!list[selectedIndex]) {
return;
}
inp.value = list[selectedIndex];
previous[currentIdx] = list[selectedIndex];
inp.value = previous.map(e => e.trim()).join(sep + " ");
closeAllLists();
});
listDiv.appendChild(choiceDiv);
@@ -822,5 +853,6 @@ export class HelpersL5r5e {
html.on("focusout", (e) => {
closeAllLists(e.target);
});
*/
}
}