Paste #4825: Untitled Paste

Date: 2014/05/26 17:39:55 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


'AIFightingEvents':
  type: world
  events:

    on npc damaged by entity:
      - if <context.damage.is[==].to[0]> queue stop
      - define status <npc.flag[Pathfind.Status]>
      - define attackerType <context.damager.prefix>
      - define attacker <context.damager>
      - inject s@AIAttackedEvent p:<def[attackerType]>_<def[status]>



'AIAttackedEvent':
  type: task
  debug: off

  script:
    - narrate "Herp is a Derp"

  player_Wandering:
    - flag npc Pathfind.Status:Fighting
    - flag npc WorkingSet:!
    - flag npc WorkingSet:|:<def[attacker]>|Fighting|<def[status]>
    - flag <def[attacker]> Fighting.NPC:<npc>
    - flag npc Fighting.PlayerList:<def[attacker]>
    - run s@AIAttackResponses as:<npc> id:<npc.id>_AttackResponseQueue





'AIAttackResponses':
  type: task
  script:
    - ^define workingSet <npc.flag[WorkingSet].as_list>
    - ^define player <def[workingSet].get[1]>
    - ^define task <def[workingSet].get[2]>
    - ^define previousStatus <def[workingSet].get[3]>
    - ^flag npc WorkingSet:!
    - ^flag npc WeightedRandomChoice:35/FightBackWeak|25/CryChat|20/RunAway|10/FightBackStrong|10/Lightning
    - ^inject s@WeightedRandomChoice instantly
    - ^flag npc WeightedRandomChoice:!
    - ^flag npc WorkingSet:|:<def[player]>|<def[result]>|<def[previousStatus]>
    - ^run s@PathfindPauseActivity as:<npc> def:<def[previousStatus]> instantly
    - ^inject s@AIAttackResponses p:<def[result]>
    - ^run s@AIAttackResponses p:StopFighting as:<npc> def:<npc>|<player>


  FightBackWeak:
    - ^define equipment "hand:<i@wood_sword>"
    - ^run s@EquipEscapingArgs "def:<escape:%equipment%>"
    - ^execute as_server "npc sel <npc.id>"
    - ^execute as_server "npc speed 0.8"
    - ^trigger name:proximity state:true cooldown:3 radius:8
    - ^follow <def[player]>
    - ^wait <util.random.int[10].to[40]>t
    - ^look <npc> <player.eye_location> duration:20t
    - ^animate <npc> animation:ARM_SWING
    - ^hurt <util.random.int[1].to[5]> <def[player]>
    - ^execute as_server "npc sel <npc.id>"
    - ^execute as_server "npc speed 1.0"
    - ^equip <npc> hand:<i@air>
    - ^if !<npc.is_spawned> || !<player.is_online> {
      - run s@AIAttackResponses p:StopFighting as:<npc> def:<npc>|<player>
      - queue clear
      }
    - ^inject s@AIAttackResponses p:FightBackWeak



'WeightedRandomChoice':
#
# Choose a random number from 1 to 100 and return which category the number is
# within.
#
  type: task
  script:
    - define list <npc.flag[WeightedRandomChoice].as_list>
    - define listSize <def[list].size>
    - define number <util.random.int[1].to[100]>
    - define counter 0
    - foreach <def[list].as_list> {
      - if <def[counter].is[OR_LESS].than[%listSize%]> {
        - define counter <def[counter].add[1]>
        - define entry_<def[counter].as_int> <def[list].get[<def[counter].as_int>]>
        - define percentChance <def[entry_<def[counter].as_int>].split[/].get[1]>
        - define returnValue <def[entry_<def[counter].as_int>].split[/].get[2]>
        - define oldValue '<def[oldValue] || 0>'
        - define lowValue '<def[oldValue].add[1]>'
        - define highValue '<def[oldValue].add[%percentChance%]>'
        - define oldValue '<def[highValue]>'

        - if <proc[isbetween].context[%number%|%lowValue%|%highValue%]> {
          - ^flag npc WeightedRandomChoice:<def[returnValue]>
          - ^foreach stop
          }
        }
      }
    - define result <npc.flag[WeightedRandomChoice]>