@@ -1788,7 +1798,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
} else if (presetId === 'spiritual_weapon') {
await combatAddEffect(encounter, {
presetId: 'spiritual_weapon', name: 'Spiritual Weapon', scope: 'encounter',
- ownerParticipantId: participant.id,
+ ownerParticipantId: encounter.currentTurnParticipantId || participant.id,
remainingRounds: 10, expiresOnDamage: false,
playerDisplay: 'prominent', createdRound: encounter.round || 0,
}, buildCtx(encounterPath));
@@ -1817,6 +1827,15 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
}
};
+ const handleSetEffectOwner = async (effect, ownerParticipantId) => {
+ if (!db) return;
+ try {
+ await combatUpdateEffect(encounter, effect.id, { ownerParticipantId }, buildCtx(encounterPath));
+ } catch (err) {
+ showToast(err.message || 'Failed to update effect owner.');
+ }
+ };
+
const handleRemoveEffect = async (effect) => {
if (!db) return;
try {
@@ -2114,7 +2133,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
Encounter Effects
{(encounter.effects || []).filter(effect => effect.scope === 'encounter' && (!effect.ownerParticipantId || !participants.some(p => p.id === effect.ownerParticipantId))).map(effect => (
-
+
))}
)}
@@ -2352,7 +2371,7 @@ function ParticipantManager({ encounter, encounterPath, campaignCharacters, camp
(effect.scope === 'participant' && effect.targetParticipantId === p.id) ||
(effect.scope === 'encounter' && effect.ownerParticipantId === p.id)
).map(effect => (
-
+
))}
{/* Expandable conditions picker */}
diff --git a/src/tests/TrackedEffects.test.js b/src/tests/TrackedEffects.test.js
index c6fd5d2..5605cf5 100644
--- a/src/tests/TrackedEffects.test.js
+++ b/src/tests/TrackedEffects.test.js
@@ -2,7 +2,7 @@ import { screen, fireEvent, waitFor, within } from '@testing-library/react';
import '@testing-library/jest-dom';
import {
setupReady, addMonsterViaUI, renderApp, createCampaignViaUI,
- selectCampaignByName, selectEncounterByName, MOCK_DB,
+ selectCampaignByName, selectEncounterByName, startCombatViaUI, MOCK_DB,
} from './testHelpers';
function latestEncounter() {
@@ -57,16 +57,27 @@ describe('tracked effects DM UI', () => {
test('Spiritual Weapon preset creates 10-round encounter effect', async () => {
await setupReady('Weapon Camp', 'Weapon Encounter');
await addMonsterViaUI('Cleric', 30, 2);
+ await addMonsterViaUI('Wizard', 24, 3);
- fireEvent.click(screen.getByRole('button', { name: 'Open conditions' }));
+ await startCombatViaUI();
+ const activeId = latestEncounter().currentTurnParticipantId;
+ const otherId = latestEncounter().participants.find(p => p.id !== activeId).id;
+ fireEvent.click(within(screen.getByTestId(`admin-participant-card-${otherId}`)).getByRole('button', { name: 'Open conditions' }));
fireEvent.click(screen.getByRole('button', { name: 'Spiritual Weapon' }));
await waitFor(() => expect(latestEncounter().effects[0]).toMatchObject({
presetId: 'spiritual_weapon', name: 'Spiritual Weapon', scope: 'encounter',
- remainingRounds: 10, expiresOnDamage: false, playerDisplay: 'prominent',
+ ownerParticipantId: activeId, remainingRounds: 10,
+ expiresOnDamage: false, playerDisplay: 'prominent',
}));
- const clericId = latestEncounter().participants.find(p => p.name === 'Cleric').id;
- expect(within(screen.getByTestId(`admin-participant-card-${clericId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument();
+ expect(within(screen.getByTestId(`admin-participant-card-${activeId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument();
+
+ const ownerSelect = screen.getByLabelText('Owner for Spiritual Weapon');
+ expect(ownerSelect).toHaveValue(activeId);
+ fireEvent.change(ownerSelect, { target: { value: otherId } });
+ await waitFor(() => expect(latestEncounter().effects[0].ownerParticipantId).toBe(otherId));
+ expect(within(screen.getByTestId(`admin-participant-card-${otherId}`)).getByText('SPIRITUAL WEAPON')).toBeInTheDocument();
+ expect(within(screen.getByTestId(`admin-participant-card-${activeId}`)).queryByText('SPIRITUAL WEAPON')).not.toBeInTheDocument();
});
test('generic ruleset offers custom effects only and rounds only', async () => {