// Get mean if characters wanna be bad
IfAttacked
  CallForHelp
  tmpargument = 5       //Team EVIL
  TargetJoinTeam
IfKilled
  tmpargument = 5       //Team EVIL
  TargetJoinTeam
IfSomeoneIsStealing     //Someone is stealing from our shop! ><
  CallForHelp           //Call the guards!
  tmpargument = 5       //Team EVIL
  TargetJoinTeam

//------------------------------------------------------------------------------
// ZZ> Setup shop...
IfSpawned
  tmpargument = passage
  AddShopPassage

  // Make the border
  tmpargument = 2
  tmpdistance = 0

  // Top
  tmpx = selfx - 192
  tmpy = selfy - 384
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle
  tmpx = tmpx + 128
  SpawnExactParticle

  // Bottom
  tmpy = selfy + 384
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle
  tmpx = tmpx - 128
  SpawnExactParticle

  // Left
  tmpx = selfx - 384
  tmpy = selfy - 192
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle
  tmpy = tmpy + 128
  SpawnExactParticle

  // Right
  tmpx = selfx + 384
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle
  tmpy = tmpy - 128
  SpawnExactParticle

  // Show the area
  //tmpdistance = 255
  //FlashPassage

  // Add some random goodies
  tmpdistance = 0
  tmpx = selfx - 128
  tmpy = selfy - 128
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx + 128
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpy = selfy
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx - 128
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpy = selfy + 128
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  tmpx = selfx + 128
  tmpturn = rand
  tmpargument = rand % 18 + 60
  SpawnExactCharacterXYZ

  // Add some random chests ( West side )
  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy - 128
  SpawnExactCharacterXYZ

  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy
  SpawnExactCharacterXYZ

  tmpturn = rand & 8191 + 28768
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx - 256
  tmpy = selfy + 128
  SpawnExactCharacterXYZ

  // Add some random chests ( East side )
  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy - 128
  SpawnExactCharacterXYZ

  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy
  SpawnExactCharacterXYZ

  tmpturn = rand & 8191 + 61535
  tmpargument = 40
  tmpx = tmpturn & 7
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 41  // Mimic
  tmpx = selfx + 256
  tmpy = selfy + 128
  SpawnExactCharacterXYZ

//------------------------------------------------------------------------------
// ZZ> Handle orders ( purchases )
IfOrdered
  // Counter specifies transaction ( 0, 1, or 2 )
  // Order specifies price
  tmpx = selforder
  tmpy = 0
  IfXIsEqualToY
    tmpx = selfcounter
    tmpy = 0
    IfXIsEqualToY
      // I'm not payin' for that!
      tmpargument = 8
      SendMessageNear
  Else
    // Buy/Sell
    tmpx = selfcounter
    tmpy = 3
    IfXIsLessThanY
      tmpy = 0 - 1
      IfXIsMoreThanY
        tmpargument = tmpx + 5
        tmpx = selforder
        SendMessageNear

//------------------------------------------------------------------------------
// ZZ> Move around...  Start at state 0
IfTimeOut
  IfStateIs0
    tmpx = rand & 255 - 128 + selfspawnx
    tmpy = rand & 255 - 128 + selfspawny
    ClearWaypoints
    AddWaypoint
  tmpargument = rand & 31 + 15
  SetTime

//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 3
  PlaySound
  tmpargument = MESSAGEDEATH
  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = MESSAGEACCIDENT
  SendMessage

  // Drop goodies
  tmpargument = selfmoney
  DropMoney

  // Make the character body
  tmpargument = 45
  SetBumpHeight

  // Tell the chests that they've been looted ( need differing IDSZ for
  // multiple shops on the same level... )
  tmpdistance = [SHOP]
  tmpargument = 983  // The unique code for a looted shop
  OrderSpecialID

//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    tmpargument = 2
    PlaySound
    tmpargument = MESSAGEOUCH
    SendMessageNear
  Else
    tmpargument = rand & 1 + 4
    PlaySound

//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
