Paste #7740: Lumberjack

Date: 2014/07/31 12:32:23 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


"Lumberjack Life":
    type: world
    events:
        on time 0 in BaseWorld:
        - foreach <server.get_npcs_assigned[Lumberjack]> {- run "lookfortrees" }
        on time 12 in BaseWorld:
        - foreach <server.get_npcs_assigned[Lumberjack]> {- walkto <npc.anchor[startPosition]> }
        - queue clear

"Lumberjack":
    type: assignment

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

    interact scripts:
    - 10 Lumberjack

    actions:
        on assignment:
            - trigger name:click toggle:true
            - trigger name:proximity toggle:true range:5
            - flag npc ready_to_cut:!
            - flag npc actualRange:<cons:initialRange>
            - anchor add <npc.location> "id:startPosition"

        on complete navigation:
             - if <npc.flag[ready_to_cut]> {
                    - run "defineTree"
                    }
                }

        on cancel navigation:
            - queue clear

"lookForTrees":
    type: task
    script:
        - flag npc found_trees:!
        - foreach <npc.location.find.blocks[<cons:logs>].within[<npc.flag[actualRange]>].as_list> {
            - if <proc[isTreeHump].context[%value%]> {
                - flag npc found_trees:|:%value%
                }
            }
        - if <npc.flag[found_trees].size.as_int> == 0 {
            - flag npc actualRange:++:10
            - run "lookForTrees"
            } else {
            - flag npc current_tree:1
            - lookclose <npc> state:false
            - walkto <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
            - flag npc ready_to_cut:true
            - queue clear
            }        

"defineTree":
    type: task
    script:
        - look <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
        - flag npc tree_elems:!
        - flag npc tree_elems:|:<npc.flag[found_trees].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:
        - define topBlock <npc.flag[tree_elems].get[<npc.flag[tree_elems].size.as_int>]>
        - foreach <%topBlock%.find.blocks[<cons: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
            }
        - modifyblock <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]> 6
        - flag npc current_tree:++
        - if <proc[wasLast].context[<npc.flag[current_tree].as_int>|<npc.flag[found_trees].size.as_int>]> {
            - run "goToStart"
            } else {
            - walkto <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
            }

"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
            }

"wasLast":
    type: procedure
    debug: false
    definitions: index|total
    script:
        - if %index% > %total% {
            - ^determine true
            } else {
            - ^determine false
            }

"goToStart":
    type: task
    script:
        - flag npc ready_to_cut:!
        - flag npc actualRange:<cons:initialRange>
        - walkto <npc> <npc.anchor[startPosition]>