Skip to content

Commit

Permalink
Character support for team maneuvers, fix for chatmessage handling of…
Browse files Browse the repository at this point in the history
… edge and trouble reroll

Closes issue #46 #46
closes issue #50  #50
  • Loading branch information
mjording committed Sep 29, 2024
1 parent 8245a71 commit 3b2bfe8
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ If either of these conditions are not met on the commit that tag points at, the
- The `system.json` file's `download` url must match the expected outcome of the release CI artifact. This should simply be changing version numbers in the url to match the release version.

```text
https://github.com/mjording/marvel-multiverse/releases/download/release-1.7.3/marvel-multiverse-1.7.3.zip
https://github.com/mjording/marvel-multiverse/releases/download/release-1.7.4/marvel-multiverse-1.7.4.zip
└─ Tag Name ──┘ └─ V ─┘ (version)
```

Expand Down
14 changes: 14 additions & 0 deletions module/data/character.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import MarvelMultiverseActorBase from "./actor-base.mjs";

export default class MarvelMultiverseCharacter extends MarvelMultiverseActorBase {

static defineSchema() {
const fields = foundry.data.fields;
const schema = super.defineSchema();

schema.teamManeuver = new fields.SchemaField({
maneuverType: new fields.StringField({ required: true, blank: true}),
level: new fields.NumberField({ min: 1, max: 3, integer: true })
})

return schema;
}


prepareDerivedData() {
// Loop through ability scores, and add their modifiers to our sheet output.
for (const key in this.abilities) {
Expand Down
60 changes: 34 additions & 26 deletions module/documents/chat-message.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ export class ChatMessageMarvel extends ChatMessage {

let rollTerm;


if(firstRollTerm instanceof foundry.dice.terms.ParentheticalTerm && firstRollTerm.roll.terms[0] instanceof foundry.dice.terms.PoolTerm){
rollTerm = firstRollTerm.roll.terms[0];
} else if (firstRollTerm instanceof foundry.dice.terms.PoolTerm) {
Expand All @@ -358,48 +357,55 @@ export class ChatMessageMarvel extends ChatMessage {

const targetRoll = rollTerm.rolls[dieIndex];
const targetDie = targetRoll.terms[0];
const targetIsMarvel = targetDie instanceof game.MarvelMultiverse.dice.MarvelDie
const formulaReg = /(?<number>\d)d(?<dieType>\d|m).*/;
const formulaGroups = formulaReg.exec(targetRoll._formula)?.groups;

const formulaNumber = formulaGroups.number;
const formulaDie = formulaGroups.dieType;

targetDie.number += 1;

const targetFormula = `${targetDie.number}d${formulaDie}`;

targetRoll._formula = `${targetFormula}${modifier}`;

rollTerm.terms[dieIndex] = targetRoll._formula

if (!targetDie.modifiers.includes(modifier)) {
targetDie.modifiers?.push(modifier)
}
targetDie.modifiers = [modifier];

const oldRollResult = targetDie.results.find((r) => r.active);
const oldFantastic = targetIsMarvel && oldRollResult.result === 1;
const oldResult = oldRollResult.result === 1 ? 6 : oldRollResult.result;

const newRoll = new MarvelMultiverseRoll(targetRoll._formula, {...targetRoll.data});
await newRoll.roll();

const old_result = targetDie.results.find((r) => r.active).result

targetDie.results.push(newRoll.terms[0].results[0]);

const resultResults = targetDie.results.map((result) => result.result);

let activeResult;

if ( targetDie instanceof game.MarvelMultiverse.dice.MarvelDie && resultResults.indexOf(1) > -1 ){
activeResult = targetDie.results[resultResults.indexOf(modifier === 'kh' ? 1 : Math.max.apply(Math, resultResults))];
const newRollResult = newRoll.terms[0].results[0];
const newResult = newRollResult.result === 1 ? 6 : newRollResult.result

if (modifier === 'kh') {
if ( oldFantastic || oldResult >= newResult ){
newRollResult.active = false;
newRollResult.discarded = true;
} else if( newResult > oldResult) {
oldRollResult.active = false;
oldRollResult.discarded = true;
newRollResult.active = true;
delete newRollResult.discarded;
}
} else {
activeResult = targetDie.results[resultResults.indexOf(modifier === 'kh' ? Math.max.apply(Math, resultResults) : Math.min.apply(Math, resultResults))];
if ( oldResult <= newResult ){
newRollResult.active = false;
newRollResult.discarded = true;
} else {
oldRollResult.active = false;
oldRollResult.discarded = true;
newRollResult.active = true;
delete newRollResult.discarded;
}
}
activeResult.active = true;
delete activeResult.discarded;

targetDie.results.filter((r) => r !== activeResult).forEach((result, i) => {
result.active = false;
result.discarded = true;
});

targetDie.results.push(newRollResult);

const re = /(\(?{)(\dd\d),(\ddm),(\dd\d)(}.*)/;

Expand All @@ -417,8 +423,10 @@ export class ChatMessageMarvel extends ChatMessage {
}

roll._formula = replacedFormula;
const resultAct = targetDie instanceof game.MarvelMultiverse.dice.MarvelDie && resultResults.indexOf(1) > -1 ? 6 : activeResult.result;
roll._total = roll.total - old_result + resultAct;

if ( newRollResult.active ){
roll._total = roll.total - oldResult + newResult;
}

let update = await roll.toMessage({flavor: flavor}, {create: false});
update = foundry.utils.mergeObject(chatMessage.toJSON(), update);
Expand Down
73 changes: 73 additions & 0 deletions module/helpers/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,79 @@ MARVEL_MULTIVERSE.elements = {
chemical: { label: "Chemical", fantasticEffect: "The target is corroding."},
}

MARVEL_MULTIVERSE.teamManeuvers = [
{
maneuverType: "Offensive",
levels: [
{
level: 1,
cost: "5 focus, each",
rankAvg: [1,2],
description: "The team members all get an edge on any attack they make this round."
},
{
level: 2,
cost: "10 focus, each",
rankAvg: [3,4],
description: "The team members can each reroll all their dice on any attack they make this round. They get to use the better result."
},
{
level: 3,
cost: "15 focus, each",
rankAvg: [5,6],
description: "The team members can each turn their Marvel die to a Fantastic success on any attack roll they make this round against targets of equal or highter rank."
}
]
},
{
maneuverType: "Defensive",
levels: [
{
level: 1,
cost: "5 focus, each",
rankAvg: [1,2],
description: "The team members all have Damage Reduction 2 for this round"
},
{
level: 2,
cost: "10 focus, each",
rankAvg: [3,4],
description: "The team members all have Damage Reduction 4 for this round"
},
{
level: 3,
cost: "15 focus, each",
rankAvg: [5,6],
description: "The team members all have Damage Reduction 8 for this round"
}
]
},
{
maneuverType: "Rally",
levels: [
{
level: 1,
cost: "5 focus, each",
rankAvg: [1,2],
description: "All actions taken against team members have trouble this round."
},
{
level: 2,
cost: "10 focus, each",
rankAvg: [3,4],
description: "Each member of the team can make a speedy recovery roll for either Health or Focus, as if they had spent a point of Karma"
},
{
level: 3,
cost: "15 focus, each",
rankAvg: [5,6],
description: "A single member of the team who has been killed or shattered in battle is healed to at least Health: 0 and Focus: 0"
}
]
}
]


MARVEL_MULTIVERSE.sizeEffects = {
microscopic: {
"name": "Microscopic Effects",
Expand Down
7 changes: 2 additions & 5 deletions module/sheets/actor-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class MarvelMultiverseActorSheet extends ActorSheet {
Object.keys(CONFIG.MARVEL_MULTIVERSE.sizes).map((key) => [key, game.i18n.localize(CONFIG.MARVEL_MULTIVERSE.sizes[key].label)])
);

context.teamManeuverTypes = Object.fromEntries(CONFIG.MARVEL_MULTIVERSE.teamManeuvers.map((teamMan) => [teamMan.maneuverType.toLowerCase(), teamMan.maneuverType] ))
context.teamManeuverLevels = Object.fromEntries([1,2,3].map((tml) => [tml, tml.toString() ]));

context.elements = Object.fromEntries(Object.keys(CONFIG.MARVEL_MULTIVERSE.elements).map((k) => [k,CONFIG.MARVEL_MULTIVERSE.elements[k].label]));

Expand Down Expand Up @@ -320,26 +322,21 @@ export class MarvelMultiverseActorSheet extends ActorSheet {

if ( itemData.type === "occupation" ) {
itemData.system.tags.forEach(async (tag) => {
console.log(`occupation: ${itemData.name} has tag ${tag.name}`);
this._createTag(tag);
});
itemData.system.traits.forEach(async (trait) => {
console.log(`occupation: ${itemData.trait} has trait ${trait.trait}`);
this._createTrait(trait);
});
// create the occupation
return super._onDropItemCreate(itemData);
} else if ( itemData.type === "origin" ) {
itemData.system.tags.forEach(async (tag) => {
console.log(`origin: ${itemData.name} has tag ${tag.name}`);
this._createTag(tag);
});
itemData.system.traits.forEach(async (trait) => {
console.log(`origin: ${itemData.name} has trait ${trait.name}`);
this._createTrait(trait);
});
itemData.system.powers.forEach(async (power) => {
console.log(`origin: ${itemData.name} has power ${power.name}`);
let newItemData = {
name: power.name,
type: "power",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvel-multiverse",
"version": "1.7.3",
"version": "1.7.4",
"description": "CSS compiler for the MarvelMultiverse system",
"scripts": {
"build:css": "sass src/scss/marvel-multiverse.scss css/marvel-multiverse.css --style=expanded --no-source-map",
Expand Down Expand Up @@ -31,4 +31,4 @@
"sass": "^1.53.0",
"yargs": "^17.7.2"
}
}
}
4 changes: 2 additions & 2 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"thumbnail": "systems/marvel-multiverse/ui/official/mmrpg-setup-thumbnail.png"
}
],
"version": "1.7.3",
"version": "1.7.4",
"compatibility": {
"minimum": 12,
"verified": "12.328"
Expand Down Expand Up @@ -116,7 +116,7 @@
],
"socket": true,
"manifest": "https://raw.githubusercontent.com/mjording/marvel-multiverse/main/system.json",
"download": "https://github.com/mjording/marvel-multiverse/releases/download/release-1.7.3/marvel-multiverse-release-1.7.3.zip",
"download": "https://github.com/mjording/marvel-multiverse/releases/download/release-1.7.4/marvel-multiverse-release-1.7.4.zip",
"background": "systems/marvel-multiverse/ui/official/mmrpg-background.webp",
"grid": {
"distance": 5,
Expand Down
10 changes: 7 additions & 3 deletions templates/actor/actor-character-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<span>+</span>
<div class="mm-damage-addition">
{{system.abilities.ego.value}}
</div>
</div>
</li>
<li>
<h6>Logic</h6>
Expand Down Expand Up @@ -90,8 +90,12 @@
<div class="mm-styled-field -flex-relative">
<label class="mm-styled-label -align-right"><span>Team Maneuver</span></label>
<div class="mm-styled-input">
<!-- Should probably be a dropdown with the ones selectable -->
<input type="text" value="Offense" data-dtype="String"/>
<select name="system.teamManeuver.maneuverType">
{{selectOptions teamManeuverTypes selected=system.teamManeuver.maneuverType labelAttr="label" blank=""}}
</select>
<select name="system.teamManeuver.level">
{{selectOptions teamManeuverLevels selected=system.teamManeuver.level}}
</select>
</div>
</div>
</div>
Expand Down

0 comments on commit 3b2bfe8

Please sign in to comment.