Skip to content

Commit

Permalink
propagate action thru performAdjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
aeauseth committed Dec 20, 2024
1 parent 91d5fc9 commit 0c1c803
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 16 deletions.
11 changes: 6 additions & 5 deletions module/item/item-attack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2756,7 +2756,7 @@ async function _onApplyAdjustmentToSpecificToken(adjustmentItem, token, damageDe

// DRAIN
const reductionChatMessages = [];
const reductionTargetActor = token.actor;
//const reductionTargetActor = token.actor;
for (const reduce of reducesArray) {
reductionChatMessages.push(
await performAdjustment(
Expand All @@ -2766,7 +2766,7 @@ async function _onApplyAdjustmentToSpecificToken(adjustmentItem, token, damageDe
defense,
damageDetail.effects,
false,
reductionTargetActor,
token,
action,
),
);
Expand All @@ -2791,7 +2791,7 @@ async function _onApplyAdjustmentToSpecificToken(adjustmentItem, token, damageDe
"None - Beneficial",
"",
false,
enhancementTargetActor,
token,
),
);
// BODY
Expand All @@ -2803,7 +2803,7 @@ async function _onApplyAdjustmentToSpecificToken(adjustmentItem, token, damageDe
"None - Beneficial",
"",
false,
enhancementTargetActor,
token,
),
);
adjustmentItemTags.push({
Expand All @@ -2823,7 +2823,8 @@ async function _onApplyAdjustmentToSpecificToken(adjustmentItem, token, damageDe
"None - Beneficial",
"",
false,
enhancementTargetActor,
token,
action,
),
);
adjustmentItemTags.push({ name: enhance });
Expand Down
151 changes: 148 additions & 3 deletions module/utility/adjustment.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HEROSYS } from "../herosystem6e.mjs";
import { getPowerInfo, hdcTimeOptionIdToSeconds } from "./util.mjs";
import { getPowerInfo, hdcTimeOptionIdToSeconds, getCharacteristicInfoArrayForActor } from "./util.mjs";
import { RoundFavorPlayerUp } from "./round.mjs";

/**
Expand Down Expand Up @@ -338,7 +338,6 @@ function _createNewAdjustmentEffect(
// those. We only need to worry about 2 (DEX -> OCV & DCV and EGO -> OMCV & DMCV)
// as figured characteristics aren't adjusted.
if (targetActor.system.is5e) {
debugger;
if (potentialCharacteristic === "dex") {
activeEffect.changes.push(_createAEChangeBlock("ocv", targetSystem));
activeEffect.flags.target.push("ocv");
Expand All @@ -364,9 +363,25 @@ export async function performAdjustment(
defenseDescription,
effectsDescription,
isFade,
targetActor,
token,
action,
) {
const targetActor = token.actor || token;

// Aaron's attempt to refactor
// if (item.system.XMLID === "AID") {
// return performAdjustmentAaron(
// item,
// nameOfCharOrPower,
// thisAttackRawActivePointsDamage, // Amount of AP to change (fade or initial value)
// defenseDescription,
// effectsDescription,
// isFade,
// token,
// action,
// );
// }

const isHealing = item.system.XMLID === "HEALING";
const isOnlyToStartingValues = item.findModsByXmlid("ONLYTOSTARTING") || isHealing;

Expand Down Expand Up @@ -694,6 +709,136 @@ export async function performAdjustment(
);
}

// async function performAdjustmentAaron(
// item,
// targetXMLID,
// adjustmentEffectActivePoints, // Amount of AP to change (fade or initial value)
// _defenseDescription,
// _effectsDescription,
// _isFade,
// token,
// action,
// ) {
// const isHealing = item.system.XMLID === "HEALING";
// const isOnlyToStartingValues = item.findModsByXmlid("ONLYTOSTARTING") || isHealing;

// // TODO: pass in the correct adjustmentEffectActivePoints
// switch (item.system.XMLID) {
// case "AID":
// if (adjustmentEffectActivePoints < 0) {
// adjustmentEffectActivePoints = Math.abs(adjustmentEffectActivePoints);
// console.warn(`Fixed NEGATIVE adjustmentEffectActivePoints for ${item.system.XMLID}`);
// }
// break;
// case "DRAIN":
// if (adjustmentEffectActivePoints > 0) {
// adjustmentEffectActivePoints = -Math.abs(adjustmentEffectActivePoints);
// console.warn(`Fixed POSITIVE adjustmentEffectActivePoints for ${item.system.XMLID}`);
// }
// break;
// default:
// console.warn(`Unhandled ${targetXMLID}`);
// }

// // 5e conversions for Calculated Characteristics
// // Adjustment Powers
// // that affect Primary Characteristics have no effect
// // on Figured Characteristics, but do affect abilities
// // calculated from Primary Characteristics (such as
// // the lifting capacity of and damage caused by STR,
// // a character’s Combat Value derived from DEX, and
// // so forth).
// if (token.actor.is5e) {
// switch (targetXMLID) {
// case "OCV":
// case "DCV":
// console.warn(`${targetXMLID} is invalid for a 5e actor, using DEX instead.`);
// targetXMLID = "DEX";

// break;
// case "OMCV":
// case "DMCV":
// console.warn(`${targetXMLID} is invalid for a 5e actor, using EGO instead.`);
// targetXMLID = "EGO";
// break;
// }
// }

// // Find a matching characteristic.
// // Note that movement powers are sometimes treated as characteristics.
// const targetCharacteristic = getCharacteristicInfoArrayForActor(token.actor).find((o) => o.key === targetXMLID)
// ? token.actor.system.characteristics[targetXMLID.toLowerCase()]
// : null;

// // Search the target for this power.
// // TODO: will return first matching power. How can we distinguish without making users
// // setup the item for a specific? Will likely need to provide a dialog. That gets
// // us into the thorny question of what powers have been discovered.
// const targetPowers = token.actor.items.filter((item) => item.system.XMLID === targetXMLID);
// if (!targetCharacteristic && targetPowers.length > 1) {
// console.warn(`Multiple ${targetXMLID} powers`);
// }
// // Notice we favor targetCharacteristic over a power
// const targetPower = targetCharacteristic ? null : targetPowers?.[0];

// // Do we have a target?
// if (!targetCharacteristic && !targetPower) {
// await ui.notifications.warn(
// `${targetXMLID} is an invalid target for the adjustment power ${item.name}. Perhaps ${token.name} does not have that characteristic or power.`,
// );
// return;
// }

// // Characteristics target an actor, and powers target an item
// const targetActorOrItem = targetCharacteristic ? token.actor : targetPower;

// const targetStartingValue = targetCharacteristic?.value || parseInt(targetPower.adjustedLevels);
// const targetStartingMax = targetCharacteristic?.max || parseInt(targetPower.system.LEVELS);
// const targetStartingCore = targetCharacteristic?.core || parseInt(targetPower.system.LEVELS);

// // Check for previous adjustment (i.e ActiveEffect) from same power against this target
// const existingEffect = _findExistingMatchingEffect(item, targetXMLID, targetPower, targetActorOrItem);

// const activeEffect =
// existingEffect ||
// {
// name: `Adjustment ${taragetXMLID}`,
// img: item.img,
// flags: {
// type: "adjustment",
// version: 3,
// adjustmentActivePoints: 0,
// affectedPoints: 0,
// XMLID: item.system.XMLID,
// source: targetActor.name,
// target: [targetPower?.uuid || potentialCharacteristic],
// key: targetPower?.system?.XMLID || potentialCharacteristic,
// itemTokenName,
// attackerTokenId: action?.current?.attackerTokenId,
// },
// origin: item.uuid, // Not always true with multiple sources for same XMLID
// description: item.system.description, // Not always true with multiple sources for same XMLID
// transfer: true,
// disabled: false,
// };

// debugger;
// // return _generateAdjustmentChatCard(
// // item,
// // thisAttackRawActivePointsDamage,
// // totalActivePointAffectedDifference,
// // totalAdjustmentNewActivePoints,
// // thisAttackActivePointAdjustmentNotAppliedDueToMax,
// // thisAttackActivePointEffectNotAppliedDueToNotExceeding,
// // defenseDescription,
// // effectsDescription,
// // targetUpperCaseName, //potentialCharacteristic,
// // isFade,
// // isEffectFinished,
// // targetActor,
// // );
// }

function _generateAdjustmentChatCard(
item,
activePointDamage,
Expand Down
28 changes: 20 additions & 8 deletions templates/chat/item-damage-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
</div>

<div data-visibility="gm">
<button class="apply-damage" title="Apply damage to selected tokens." data-itemId="{{item.uuid}}" data-action-data="{{actionData}}"
data-body-damage="{{bodyDamage}}" data-body-damage-effective="{{bodyDamageEffective}}"
data-stun-damage="{{stunDamage}}" data-stun-damage-effective="{{stunDamageEffective}}"
data-roller="{{roller}}" data-stun-multiplier="{{stunMultiplier}}" data-hit-location="{{hitLocation}}" data-target-Entangle="{{targetEntangle}}">
<button class="apply-damage" title="Apply damage to selected tokens." data-itemId="{{item.uuid}}"
data-action-data="{{actionData}}"
data-body-damage="{{bodyDamage}}"
data-body-damage-effective="{{bodyDamageEffective}}"
data-stun-damage="{{stunDamage}}"
data-stun-damage-effective="{{stunDamageEffective}}"
data-roller="{{roller}}"
data-stun-multiplier="{{stunMultiplier}}"
data-hit-location="{{hitLocation}}"
data-target-Entangle="{{targetEntangle}}">
{{#if (or nonDmgEffect senseAffecting)}}
Apply {{item.system.XMLID}}
{{else}}
Expand All @@ -52,11 +58,17 @@
</button>

{{#each targetTokens as |target id|}}
<button class="apply-damage" title="Apply damage to {{target.token.name}}." data-itemId="{{../item.uuid}}" data-action-data="{{actionData}}"
<button class="apply-damage" title="Apply damage to {{target.token.name}}." data-itemId="{{../item.uuid}}"
data-action-data="{{@root/actionData}}"
data-target-token-id="{{target.token.id}}"
data-body-damage="{{../bodyDamage}}" data-body-damage-effective="{{../bodyDamageEffective}}"
data-stun-damage="{{../stunDamage}}" data-stun-damage-effective="{{../stunDamageEffective}}"
data-roller="{{target.roller}}" data-stun-multiplier="{{../stunMultiplier}}" data-hit-location="{{../hitLocation}}" data-target-Entangle="{{../targetEntangle}}">
data-body-damage="{{../bodyDamage}}"
data-body-damage-effective="{{../bodyDamageEffective}}"
data-stun-damage="{{../stunDamage}}"
data-stun-damage-effective="{{../stunDamageEffective}}"
data-roller="{{target.roller}}"
data-stun-multiplier="{{../stunMultiplier}}"
data-hit-location="{{../hitLocation}}"
data-target-Entangle="{{../targetEntangle}}">
{{#if ../nonDmgEffect}}
Apply {{../item.system.XMLID}} to <b>{{target.token.name}}</b>
{{else}}
Expand Down

0 comments on commit 0c1c803

Please sign in to comment.