게임버전 (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로 반복되어있는데 도저히 어떤방식으로 간추릴수있는지 엄청 머리가 아프네요 방법이 있나요?
qsef1256
2022.06.08스크립트의 리팩토링도 어느정도 프로그래밍의 리팩토링 원칙을 따릅니다. 다만 절차적 언어인 이상 적용 하기 힘든 원칙도 있구요
지금 적용 해야하는 원칙은 대략 다음과 같습니다:
• 중복 코드를 없애라 (함수로 분리할 것)
• 재사용이 가능하도록 할 것
if 단일 항은 if 랑 들여쓰기를 없애고 is 만 남기시면 좀 더 보기 편합니다