@@ -14,11 +14,20 @@ import {
1414 setLanguage ,
1515 t ,
1616} from '../i18n' ;
17- import { getAdjectiveStar , getBoShi12 , getchangsheng12 , getMajorStar , getMinorStar , getYearly12 } from '../star' ;
17+ import {
18+ getAdjectiveStar ,
19+ getBoShi12 ,
20+ getchangsheng12 ,
21+ getMajorStar ,
22+ getMinorStar ,
23+ getTianshiTianshangIndex ,
24+ getYearly12 ,
25+ } from '../star' ;
1826import { fixIndex , translateChineseDate } from '../utils' ;
1927import FunctionalAstrolabe from './FunctionalAstrolabe' ;
2028import FunctionalPalace , { IFunctionalPalace } from './FunctionalPalace' ;
2129import { getPalaceNames , getSoulAndBody , getHoroscope , getFiveElementsClass } from './palace' ;
30+ import FunctionalStar from '../star/FunctionalStar' ;
2231
2332const _plugins = [ ] as Plugin [ ] ;
2433const _mutagens : Partial < Record < HeavenlyStemKey , StarKey [ ] > > = { } ;
@@ -356,7 +365,60 @@ export function rearrangeAstrolable<T extends FunctionalAstrolabe>({
356365 } ) ;
357366
358367 astrolable . fiveElementsClass = fiveElementsClass ;
368+
369+ // 重新获取天使、天伤的索引
370+ const { tianshiIndex, tianshangIndex } = getTianshiTianshangIndex (
371+ astrolable . gender as GenderName ,
372+ kot ( astrolable . rawDates . chineseDate . yearly [ 1 ] ) as EarthlyBranchKey ,
373+ soulIndex ,
374+ ) ;
375+ // 重新获取天才星的位置
376+ const tiancaiIndex = fixIndex (
377+ soulIndex + EARTHLY_BRANCHES . indexOf ( kot ( astrolable . rawDates . chineseDate . yearly [ 1 ] ) as EarthlyBranchKey ) ,
378+ ) ;
379+
359380 astrolable . palaces . forEach ( ( palace , i ) => {
381+ const _tianshangIdx = palace . adjectiveStars . findIndex ( ( item ) => kot ( item . name ) === 'tianshang' ) ;
382+
383+ if ( _tianshangIdx !== - 1 && tianshangIndex !== i ) {
384+ // 当天伤不应该在该宫位时,删之
385+ palace . adjectiveStars . splice ( _tianshangIdx , 1 ) ;
386+ }
387+
388+ if ( _tianshangIdx === - 1 && tianshangIndex === i ) {
389+ // 当天伤应该在该宫位却不在,加之
390+ palace . adjectiveStars . push ( new FunctionalStar ( { name : t ( 'tianshang' ) , type : 'adjective' , scope : 'origin' } ) ) ;
391+ }
392+
393+ const _tianshiIdx = palace . adjectiveStars . findIndex ( ( item ) => kot ( item . name ) === 'tianshi' ) ;
394+
395+ if ( _tianshiIdx !== - 1 && tianshiIndex !== i ) {
396+ // 当天使不应该在该宫位时,删之
397+ palace . adjectiveStars . splice ( _tianshiIdx , 1 ) ;
398+ }
399+
400+ if ( _tianshiIdx === - 1 && tianshiIndex === i ) {
401+ // 当天使应该在该宫位却不在,加之
402+ palace . adjectiveStars . push ( new FunctionalStar ( { name : t ( 'tianshi' ) , type : 'adjective' , scope : 'origin' } ) ) ;
403+ }
404+
405+ const _tiancaiIndex = palace . adjectiveStars . findIndex ( ( item ) => kot ( item . name ) === 'tiancai' ) ;
406+
407+ if ( _tiancaiIndex !== - 1 && tiancaiIndex !== i ) {
408+ // 当天才不应该在该宫位时,删之
409+ palace . adjectiveStars . splice ( _tiancaiIndex , 1 ) ;
410+ }
411+
412+ if ( _tiancaiIndex === - 1 && tiancaiIndex === i ) {
413+ // 当天才应该在该宫位却不在,加之
414+ palace . adjectiveStars . push ( new FunctionalStar ( { name : t ( 'tiancai' ) , type : 'adjective' , scope : 'origin' } ) ) ;
415+ }
416+
417+ if ( _tianshiIdx === - 1 && tianshiIndex === i ) {
418+ // 当天使应该在该宫位却不在,加之
419+ palace . adjectiveStars . push ( new FunctionalStar ( { name : t ( 'tianshi' ) , type : 'adjective' , scope : 'origin' } ) ) ;
420+ }
421+
360422 palace . name = palaceNames [ i ] ;
361423 palace . majorStars = majorStars [ i ] ;
362424 palace . changsheng12 = changsheng12 [ i ] ;
@@ -484,16 +546,16 @@ export const getMajorStarBySolarDate = (
484546) => {
485547 language && setLanguage ( language ) ;
486548
487- const { bodyIndex } = getSoulAndBody ( { solarDate : solarDateStr , timeIndex, fixLeap } ) ;
549+ const { soulIndex } = getSoulAndBody ( { solarDate : solarDateStr , timeIndex, fixLeap } ) ;
488550 const majorStars = getMajorStar ( { solarDate : solarDateStr , timeIndex, fixLeap } ) ;
489- const stars = majorStars [ bodyIndex ] . filter ( ( star ) => star . type === 'major' ) ;
551+ const stars = majorStars [ soulIndex ] . filter ( ( star ) => star . type === 'major' ) ;
490552
491553 if ( stars . length ) {
492554 return stars . map ( ( star ) => t ( star . name ) ) . join ( ',' ) ;
493555 }
494556
495557 // 如果命宫为空宫,则借对宫主星
496- return majorStars [ fixIndex ( bodyIndex + 6 ) ]
558+ return majorStars [ fixIndex ( soulIndex + 6 ) ]
497559 . filter ( ( star ) => star . type === 'major' )
498560 . map ( ( star ) => t ( star . name ) )
499561 . join ( ',' ) ;
0 commit comments