-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
182 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { i18n, i18nFormat } from '../foundryvtt-arms-reach'; | ||
import { | ||
computeDistanceBetweenCoordinates, | ||
computeDistanceBetweenCoordinatesOLD, | ||
getCharacterName, | ||
getFirstPlayerToken, | ||
getFirstPlayerTokenSelected, | ||
getTokenByTokenID, | ||
iteractionFailNotification, | ||
} from './ArmsReachHelper'; | ||
import { getCanvas, ARMS_REACH_MODULE_NAME, getGame } from './settings'; | ||
|
||
export const LightsReach = { | ||
globalInteractionDistance: function (character: Token, light: AmbientLight): boolean { | ||
let isOwned = false; | ||
if (!character) { | ||
character = <Token>getFirstPlayerToken(); | ||
if (character) { | ||
isOwned = true; | ||
} | ||
} | ||
if (!character) { | ||
if (getGame().user?.isGM) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
// Sets the global maximum interaction distance | ||
// OLD SETTING | ||
let globalInteraction = <number>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionDistance'); | ||
if (globalInteraction <= 0) { | ||
globalInteraction = <number>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionMeasurement'); | ||
} | ||
// Global interaction distance control. Replaces prototype function of Stairways. Danger... | ||
if (globalInteraction > 0) { | ||
// Check distance | ||
//let character:Token = getFirstPlayerToken(); | ||
if ( | ||
!getGame().user?.isGM || | ||
(getGame().user?.isGM && | ||
<boolean>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionDistanceForGM')) | ||
) { | ||
if (!character) { | ||
iteractionFailNotification(i18n(`${ARMS_REACH_MODULE_NAME}.noCharacterSelectedForLight`)); | ||
return false; | ||
} else { | ||
let isNotNearEnough = false; | ||
// OLD SETTING | ||
if (<number>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionDistance') > 0) { | ||
const dist = computeDistanceBetweenCoordinatesOLD(LightsReach.getLightsCenter(light), character); | ||
isNotNearEnough = | ||
dist > <number>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionDistance'); | ||
} else { | ||
const dist = computeDistanceBetweenCoordinates(LightsReach.getLightsCenter(light), character); | ||
isNotNearEnough = | ||
dist > <number>getGame().settings.get(ARMS_REACH_MODULE_NAME, 'globalInteractionMeasurement'); | ||
} | ||
if (isNotNearEnough) { | ||
const tokenName = getCharacterName(character); | ||
if (tokenName) { | ||
iteractionFailNotification( | ||
i18nFormat(`${ARMS_REACH_MODULE_NAME}.lightsNotInReachFor`, { tokenName: tokenName }), | ||
); | ||
} else { | ||
iteractionFailNotification(i18n(`${ARMS_REACH_MODULE_NAME}.lightsNotInReach`)); | ||
} | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
} else if (getGame().user?.isGM) { | ||
// DO NOTHING | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
getLightsCenter: function (light: AmbientLight) { | ||
const lightCenter = { x: light.x, y: light.y }; | ||
return lightCenter; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters