Paste #2807: Untitled Paste

Date: 2014/03/23 11:50:01 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


"Lumberjack":
    type: assignment

    default constants:
        logs: oak_log|birch_log|spruce_log
        leaves: leaves|birch_leaves|spruce_leaves
        initialRange: 5

    interact scripts:
    - 10 Lumberjack life

    actions:
        on assignment:
            - trigger name:proximity toggle:true
            - flag npc actualRange:<cons:initialRange>
            - flag npc gatheredLogs:0
            - anchor add l@-3510,67,13,Azeroth id:home
            - anchor add l@-3521,67,13,Azeroth id:startPosition
            - anchor add l@-3518,67,16,Azeroth id:restPosition 
            - anchor add l@-3508,68,12,Azeroth id:sleepPosition
            - note cu@-3523,65,3,Azeroth|-3500,77,24,Azeroth as:ForesterLodge
            - equip <npc> hand:i@258 chest:i@299 legs:i@300 boots:i@301
            - if <server.has_flag[defaultSleepNpcList]> {
                - if <global.flag[defaultSleepNpcList].as_list> !contains <npc> {
                    - flag global defaultSleepNpcList:->:<npc>
                    }
                } else {
                - flag global defaultSleepNpcList:!
                - flag global defaultSleepNpcList:->:<npc>
                }
            - if <server.has_flag[employedNpcs]> {
                - if <global.flag[employedNpcs].as_list> !contains <npc> {
                    - flag global employedNpcs:->:<npc>
                    }
                } else {
                - flag global employedNpcs:!
                - flag global employedNpcs:->:<npc>
                }

        on remove assignment:
            - trigger name:proximity toggle:false
            - anchor remove id:startPosition
            - anchor remove id:restPosition
            - anchor id:sleepPosition remove 
            - if <global.flag[defaultSleepNpcList].as_list> contains <npc> {
                - flag global defaultSleepNpcList:<-:<npc>
                }
            - if <global.flag[employedNpcs].as_list> contains <npc> {
                - flag global employedNpcs:<-:<npc>
                }
            - flag npc found_tree:!
            - flag npc current_tree:!
            - flag npc tree_elems:!
            - flag npc current_elem:!

        on complete navigation:
            - if <npc.location.simple> == <npc.anchor[startPosition].simple> {
                - if <global.flag[fajrant]> {
                    - if <npc.flag[gatheredLogs] > 0 {
                        - run "fillChestLog"
                        } else {
                        - run "goRest"
                        }
                    } else {
                    - if <npc.flag[ready_to_work]> {
                        - run "lookForTrees"
                        } else {
                        - run "goRest"                        
                        }
                    }
                } else if <npc.location.simple> == <npc.anchor[home].simple> {
                - if <global.flag[noc]> {
                    - run "goToBed"
                    } else {
                    - if <global.flag[fajrant]> {
                        - run "goRest"
                        } else {
                        - if <npc.flag[ready_to_work]> {
                            - run "goToStart"
                            }
                        }
                    }
                } else if <npc.location.simple> == <npc.anchor[restPosition].simple> {
                    - queue clear
                } else {
                - if <global.flag[fajrant]> {
                    - queue clear
                    - run "goToStart"
                    } else {
                    - run "DefineTree"
                    }
                }

"Lumberjack Life":
    type: interact
    Requirements:
        Mode: ALL    
    steps:
        1:
            proximity trigger:
                entry:
                    script:
                        - run "Greetings"

"Greetings":
    type: task
    script:
        - chat targets:p@<player.name> "Hello there traveler!"

"lookForTrees":
    type: task
    script:
        - flag npc found_tree:!
        - if <npc.has_flag[gatheredLogs]> {
            - foreach <npc.location.find.blocks[<npc.constant[logs]>].within[<npc.flag[actualRange]>].as_list> {
                - if <proc[isTreeHump].context[%value%]> {
                    - if !<proc[isHome].context[%value%]> {
                        - flag npc found_tree:|:%value%
                        }                
                    }
                }
            - if <npc.flag[found_tree].size.as_int> == 0 {
                - flag npc actualRange:++:5
                - run "lookForTrees"
                } else {
                - flag npc current_tree:1
                - lookclose <npc> state:false
                - ~walk <npc> <npc.flag[found_tree].get[<npc.flag[current_tree].as_int>]> auto_range
                - queue clear
                }
            } else {
            - flag npc gatheredLogs:0
            - run "lookForTrees"
            }

"defineTree":
    type: task
    script:
        - look <npc> <npc.flag[found_tree].get[<npc.flag[current_tree].as_int>]>
        - flag npc tree_elems:!
        - flag npc tree_elems:|:<npc.flag[found_tree].get[<npc.flag[current_tree].as_int>]>
        - flag npc current_elem:1
        - run "checkBlockAbove"

"checkBlockAbove":
    type: task
    script:
        - define currentBlock <npc.flag[tree_elems].get[<npc.flag[current_elem].as_int>]>
        - if <proc[isLogAbove].context[%currentBlock%]> {
            - animate <npc> animation:arm_swing
            - flag npc tree_elems:|:<%currentBlock%.above>
            - flag npc current_elem:++
            - run "checkBlockAbove"            
            } else {
                - run "lookForLeaves"
            }

"lookForLeaves":
    type: task
    script:
        - flag npc gatheredLogs:++:<npc.flag[tree_elems].size.as_int>
        - define topBlock <npc.flag[tree_elems].get[<npc.flag[tree_elems].size.as_int>]>
        - foreach <%topBlock%.find.blocks[<npc.constant[leaves]>].within[3].as_list> {
            - flag npc tree_elems:|:%value%
            }
        - run "cutTree"

"cutTree":
    type: task
    script:
        - foreach <npc.flag[tree_elems].as_list> {
            - modifyblock %value% 0
            }
        - narrate targets:p@NLS667 "Tree was cut."
        - if <npc.flag[found_tree].get[<npc.flag[current_tree].as_int>].below.material.id> != 1 {
            - modifyblock <npc.flag[found_tree].get[<npc.flag[current_tree].as_int>]> 6
            - narrate targets:p@NLS667 "Tree was planted."
            }
        - run "lookForTrees"

"isHome":
    type: procedure
    definitions: block
    script:
        - if <cu@ForesterLodge.is_within[%block%]> {
            - ^determine true
            } else {
            - ^determine false
            }


"isLogAbove":
    type: procedure
    debug: false
    definitions: block
    script:
        - if <%block%.above.material.id> == <%block%.material.id> {
            - ^determine true            
            } else {
            - ^determine false            
            }

"isTreeHump":
    type: procedure
    debug: false
    definitions: block
    script:
        - ^if <%block%.below.material.id> == 3 || <%block%.below.material.id> == 1 {
            - if <%block%.above.material.id> == <%block%.material.id> {
                - ^determine true
                } else {
                - ^determine false
                }
            } else {
            - ^determine false
            }

"fillChestLog":
    type: task
    script:
        - narrate targets:p@NLS667 "I added <npc.flag[gatheredLogs].as_int> logs to chest."

#-------------- NPC's everyday tasks ------------------------

"goRest":
    type: task
    script:
        - ~walk <npc> <npc.anchor[restPosition]> speed:0.8 auto_range

"goToStart":
    type: task
    script:
        - flag npc actualRange:<npc.constant[initialRange]>
        - ~walk <npc> <npc.anchor[startPosition]> auto_range