- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register


Click here to create your own public paste ~ ~ click to duplicate and edit this paste


TitleUntitled Paste
TypeDenizen Script
Date2017/02/23 22:18:41 UTC-08:00
ByGuest
Other
Paste
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
17000
## 수매 퀘스트 셋업
PurchaseQuestDefaultSetup:
    type: yaml data
    configpath: ../JemrQuest/purchase.yml
#    sellerpath: ../JemrQuest/sellerlist.yml
    logpath: ./plugins/JemrQuest/trade.log



## 수매 시작
warehouse_Purchase_start:
    type: task
    script:
    - yaml load:<s@purchasequestdefaultsetup.yaml_key[configpath]> id:purchase
    - wait 1s
    - define npc <yaml[purchase].read[default.setting.npc]>
    ### 수매중이라면 실행 중지
    - if <def[npc].has_flag[quantity]> == true {
        - narrate "지금은 수매중입니다."
        - queue clear
    }

    - if <yaml[purchase].list_keys[purchase_list].random[1].get[1]||null> == null {
        - narrate "최소한 하나 이상의 아이템이 등록되어 있어야 합니다."
        - log "하나 이상의 아이템 등록 필요" type:warning file:<s@purchasequestdefaultsetup.yaml_key[logpath]>
        - queue clear
    }
    - define npc <yaml[purchase].read[default.setting.npc]>
    - define item <yaml[purchase].list_keys[purchase_list].random[1].get[1]>
    - define item_name <yaml[purchase].read[purchase_list.<def[item]>.name]>
    - define price <yaml[purchase].read[purchase_list.<def[item]>.current.price]>
    - define quantity <yaml[purchase].read[purchase_list.<def[item]>.current.quantity]>
    - flag <def[npc]> item:<def[item]>
    - flag <def[npc]> item_name:<def[item_name]>
    - flag <def[npc]> price:<def[price]>
    - flag <def[npc]> quantity:<def[quantity]>
    - flag <def[npc]> timeout:<util.date.time>:<util.date.time.second> duration:<yaml[purchase].read[default.setting.time_limit]>

    - log "Purchaing statred!" type:fine file:<s@purchasequestdefaultsetup.yaml_key[logpath]>

    ## 안내시작
    - title "title: " "subtitle:<&c>창고에서 수매를 시작합니다" targets:<server.list_online_players> stay:5s
    - narrate target:<server.list_online_players> "지금부터 수매를 시작합니다!     <server.current_time_millis>"

    - bossbar create purchasing players:<server.list_online_players> "title:창고에서 <def[item_name]> 수매중... " color:red progress:0



## 수매 종/료
warehouse_Purchase_end:
    type: task
    speed: 1t
    script:
    - yaml load:<s@purchasequestdefaultsetup.yaml_key[configpath]> id:purchase
    - wait 1s
    - define npc <yaml[purchase].read[default.setting.npc]>
    ### 수매중이지 않다면 실행 중지
    - if <def[npc].has_flag[quantity]||false> == false {
        - narrate "수매중이 아닙니다."
        - queue clear
    }
        ### 플래그에서 그간 저장된 변수 가져오기 시작
    - define item <def[npc].flag[item]>
    - define price <def[npc].flag[price]>
    - define quantity <yaml[purchase].read[purchase_list.<def[item]>.current.quantity].sub[<def[npc].flag[quantity]>]>
    - define expenditure <yaml[purchase].read[purchase_list.<def[item]>.current.price].mul[<def[quantity]>]>

    ### 하나도 안팔린 경우 이벤트 그냥 종료하기
    - if <def[npc].flag[quantity]||0> >= <yaml[purchase].read[purchase_list.<def[item]>.current.quantity]> {
        - narrate "아무도 구매하지 않았습니다."
    }
    else {
        ## 수매정보를 업데이트
        - yaml id:purchase set purchase_list.<def[item]>.history.total.procurement:+:1
        - yaml id:purchase set purchase_list.<def[item]>.history.total.purchased_expenditure:+:<def[expenditure]>
        - yaml id:purchase set purchase_list.<def[item]>.history.total.purchased_quantity:+:<def[quantity]>

        #평균 수매량과, 평균가 계산
        - define total_expenditure <yaml[purchase].read[purchase_list.<def[item]>.history.total.purchased_expenditure]>
        - define total_quantity <yaml[purchase].read[purchase_list.<def[item]>.history.total.purchased_quantity]>
        - define procurement <yaml[purchase].read[purchase_list.<def[item]>.history.total.procurement]>
        - yaml id:purchase set purchase_list.<def[item]>.history.average.quantity:<def[total_expenditure].div[<def[procurement]>]>
        - yaml id:purchase set purchase_list.<def[item]>.history.average.price:<def[total_expenditure].div[<def[total_quantity]>]>

        ## 수매 목표량 계산
        - define target_quantity <yaml[purchase].read[purchase_list.<def[item]>.current.quantity]||1>
        - define achievement <def[quantity].div[<def[target_quantity]>]>
        - narrate "<def[achievement].mul[100].round_to[2]>%입니다. <def[achievement]>"

        ##수매 결과에 따라 가격 갱신  # 계산식, y=2mx+(1-m)

        ### q갱신 q_delta, achievement
        - define q_delta <yaml[purchase].read[default.quantity.delta]>
        - define p_delta <yaml[purchase].read[default.price.delta]>

        ## 최소 최대값 불러오기
        - define p_min <yaml[purchase].read[default.price.min]>
        - define p_max <yaml[purchase].read[default.price.max]>
        - define q_min <yaml[purchase].read[default.quantity.min]>
        - define q_max <yaml[purchase].read[default.quantity.max]>

        # 랜덤 변화를 위한... # gauss 70%가 -2에서 +2사이에 존재함.
        - define ran <util.random.gauss.div[80]>
        - yaml id:purchase set purchase_list.<def[item]>.current.quantity:*:<def[q_delta].mul[2].mul[<def[achievement]>].add[1].sub[<def[q_delta]>].add[<def[ran]>]>
        - yaml id:purchase set purchase_list.<def[item]>.current.quantity:<yaml[purchase].read[purchase_list.<def[item]>.current.quantity].round.max[<def[q_min]>].min[<def[q_max]>]>

        - define ran <util.random.gauss.div[80]>
        - yaml id:purchase set purchase_list.<def[item]>.current.price:*:<def[p_delta].mul[-2].mul[<def[achievement]>].add[1].add[<def[p_delta]>].add[<def[ran]>]>
        - yaml id:purchase set purchase_list.<def[item]>.current.price:<yaml[purchase].read[purchase_list.<def[item]>.current.price].round_to[2].max[<def[p_min]>].min[<def[p_max]>]>
        ### 수매 결과를 로그에 기록하기
            ## 수매결과
        - narrate "수매를 종료합니다."
        - log "Result:<def[item]>TQ:<yaml[purchase].read[purchase_list.<def[item]>.current.quantity]> purchased:<def[quantity]><def[achievement].mul[100].round_to[2]>%, expenditure:<def[expenditure]>percost:<def[price]>" type:info file:<s@purchasequestdefaultsetup.yaml_key[logpath]>
        ## 개인별 참여여부 기록
        - foreach <def[npc].list_flags> {
            - if <def[value].is_player||null> {
                - log "<def[value].name> <def[npc].flag[<def[value]>]>" type:none file:<s@purchasequestdefaultsetup.yaml_key[logpath]>
                - flag <def[npc]> <def[value]>:!
            }
        }
    }
 
    - yaml savefile:<s@purchasequestdefaultsetup.yaml_key[configpath]> id:purchase

    ## 이벤트 마감 공지
    - title "title: " "subtitle:<&c>수매를 종료합니다" targets:<server.list_online_players> stay:5s
    - narrate target:<server.list_online_players> "수매가 종료되었습니다!"
    - bossbar remove purchasing

    ### npc 플래그 삭제하기
    - flag <def[npc]> item:!
    - flag <def[npc]> item_name:!
    - flag <def[npc]> price:!
    - flag <def[npc]> timeout:!
    - flag <def[npc]> purchasing:!
    - flag <def[npc]> quantity:!



### 수매시간 마감 시 종료하기
"purchase_timer":
    type: world
    events:
        on system time hourly:
        # 세명 이상이라면 매시간 수매 이벤트 시작하기
        - if <server.list_online_players.size> >= 3 run warehouse_Purchase_start instantly

        # 보스바 업데이트로 공지하기
        on system time minutely:

        # 진행중이지 않다면, 공지x
        - ~define npc <yaml[purchase].read[default.setting.npc]>
            # q가 0이거나 플래그가 없다면 => 수매가 끝났다면
        - if <def[npc].flag[quantity]||0> <= 0 {
            - run warehouse_Purchase_end instantly
            - queue clear
        }

        #수매가 진행중이라면 보스바로 공지

        - define item_name <yaml[purchase].read[default.setting.npc].flag[item_name]>
            #progress calc
        - define item <def[npc].flag[item]>
        - define target_q <yaml[purchase].read[purchase_list.<def[item]>.current.quantity]>
        - define remain_q <def[npc].flag[quantity]>
        - define current_q <def[target_q].sub[<def[remain_q]>]>
        - define progress <def[current_q].div[<def[target_q]>]>
        - narrate target:<server.list_online_players> "<def[npc]><n><def[item]><n><def[remain_q]><n><def[current_q]><n><def[target_q]>"
        - bossbar update purchasing players:<server.list_online_players> progress:<def[progress]>



RawRaw



Pastes made: 66918