개인 자료란 (JE)

  서버 커뮤니티

Profile 뚜찌k 대표칭호 없음
Profile

질문하기 스크립트

마크 스크립트 명령어 간추리기

2022.06.08 조회 수 104 추천 수 0
게임버전 (JE) 1.18.2 
게임버전 (BE) 관련없음 

command /철검일반강화 [<integer>]:

    trigger:

        if player is in the region "smithy":

            if arg 1 = 1:

                if {돈.%uuid of player%} >= 50000:

                    chance of 70%:

                        give paper named "&l&a철검 일반강화 1강" with lore "&c강화된 철검 1강으로 교환할수 있습니다" to player

                        add 50000 to {국가}

                        send action bar "&6&l강화에 성공했습니다!" to player

                        play sound "entity_player_levelup" with volume 0.5 and pitch 1 at player

                    else:

                        send action bar "&4&l강화에 실패하였습니다" to player

                        add 50000 to {국가}

                        play sound "ENTITY_DRAGON_FIREBALL_EXPLODE" with volume 0.2 and pitch 1 at player

                else:

                    send action bar "&4강화를 위해서 돈 &l50000&4원이 필요합니다 &f현재 돈 : &l%{돈.%uuid of player%}%&f원" to player

                    play sound "block_anvil_land" with volume 0.1 and pitch 1 at player

            if arg 1 = 2:

                if {돈.%uuid of player%} >= 60000:

                    chance of 60%:

                        give paper named "&l&a철검 일반강화 2강" with lore "&c강화된 철검 2강으로 교환할수 있습니다" to player

                        add 60000 to {국가}

                        send action bar "&6&l강화에 성공했습니다!" to player

                        play sound "entity_player_levelup" with volume 0.5 and pitch 1 at player

                    else:

                        send action bar "&4&l강화에 실패하였습니다" to player

                        add 60000 to {국가}

                        play sound "ENTITY_DRAGON_FIREBALL_EXPLODE" with volume 0.2 and pitch 1 at player

                else:

                    send action bar "&4강화를 위해서 돈 &l60000&4원이 필요합니다 &f현재 돈 : &l%{돈.%uuid of player%}%&f원" to player

                    play sound "block_anvil_land" with volume 0.1 and pitch 1 at player

            if arg 1 = 3:

                if {돈.%uuid of player%} >= 70000:

                    chance of 50%:

                        give paper named "&l&a철검 일반강화 3강" with lore "&c강화된 철검 3강으로 교환할수 있습니다" to player

                        add 70000 to {국가}

                        send action bar "&6&l강화에 성공했습니다!" to player

                        play sound "entity_player_levelup" with volume 0.5 and pitch 1 at player

                    else:

                        send action bar "&4&l강화에 실패하였습니다" to player

                        add 70000 to {국가}

                        play sound "ENTITY_DRAGON_FIREBALL_EXPLODE" with volume 0.2 and pitch 1 at player

                else:

                    send action bar "&4강화를 위해서 돈 &l70000&4원이 필요합니다 &f현재 돈 : &l%{돈.%uuid of player%}%&f원" to player

                    play sound "block_anvil_land" with volume 0.1 and pitch 1 at player

            if arg 1 = 4:

                if {돈.%uuid of player%} >= 80000:

                    chance of 35%:

                        add 80000 to {국가}

                        give paper named "&l&a철검 일반강화 4강" with lore "&c강화된 철검 4강으로 교환할수 있습니다" to player

                        send action bar "&6&l강화에 성공했습니다!" to player

                        play sound "entity_player_levelup" with volume 0.5 and pitch 1 at player

                    else:

                        send action bar "&4&l강화에 실패하였습니다" to player

                        play sound "ENTITY_DRAGON_FIREBALL_EXPLODE" with volume 0.2 and pitch 1 at player

                        add 80000 to {국가}

                else:

                    send action bar "&4강화를 위해서 돈 &l80000&4원이 필요합니다 &f현재 돈 : &l%{돈.%uuid of player%}%&f원" to player

                    play sound "block_anvil_land" with volume 0.1 and pitch 1 at player

            if arg 1 = 5:

                if {돈.%uuid of player%} >= 100000:

                    chance of 15%:

                        give paper named "&l&a철검 일반강화 5강" with lore "&c강화된 철검 5강으로 교환할수 있습니다" to player

                        add 100000 to {국가}

                        send action bar "&6&l강화에 성공했습니다!" to player

                        play sound "ui_toast_challenge_complete" with volume 0.5 and pitch 1 at player

                    else:

                        send action bar "&4&l강화에 실패하였습니다" to player

                        add 100000 to {국가}

                        play sound "ENTITY_DRAGON_FIREBALL_EXPLODE" with volume 0.2 and pitch 1 at player

                else:

                    send action bar "&4강화를 위해서 돈 &l100000&4원이 필요합니다 &f현재 돈 : &l%{돈.%uuid of player%}%&f원" to player

                    play sound "block_anvil_land" with volume 0.1 and pitch 1 at player

        else:

            send action bar "&4&l이 장비의 강화는 마을 대장간안에서만 가능합니다" to player

이런식으로 강화를 하는 명령어가 if else로 반복되어있는데 도저히 어떤방식으로 간추릴수있는지 엄청 머리가 아프네요 방법이 있나요?

1개의 댓글

qsef1256
2022.06.08

스크립트의 리팩토링도 어느정도 프로그래밍의 리팩토링 원칙을 따릅니다. 다만 절차적 언어인 이상 적용 하기 힘든 원칙도 있구요

 

지금 적용 해야하는 원칙은 대략 다음과 같습니다:

 

• 중복 코드를 없애라 (함수로 분리할 것)

• 재사용이 가능하도록 할 것

 

if 단일 항은 if 랑 들여쓰기를 없애고 is 만 남기시면 좀 더 보기 편합니다

뉴스 및 창작물
/files/thumbnails/576/775/003/262x150.crop.jpg?20240426232553

아티클

이달의 블록: 단단한 진흙

학교가기싫다

2024-04-26

0

/files/thumbnails/115/774/003/262x150.crop.jpg?20240426223813

업데이트

마인크래프트 1.20.5 정식 업데이트

학교가기싫다

2024-04-24

0

/files/thumbnails/762/770/003/262x150.crop.jpg?20240418073724

레드스톤

T.B.H (고민중독) | 노트블럭 버전 | NoteBlock Cover [한국어 영어 중국어 가사 추가]

노트블럭전문가

2024-04-18

0

/files/thumbnails/218/767/003/262x150.crop.jpg?20240412130213

레드스톤

우리의 꿈 - 원피스 오프닝

노트블럭전문가

2024-04-12

0

/files/thumbnails/505/766/003/262x150.crop.jpg?20240411122306

레드스톤

기동전사 건담 수성의 마녀 | 노트블럭 커버 1

노트블럭전문가

2024-04-11

1