;@@@
;@@@ DreamBot IRC Bot 5.4
;@@@ File description: various games
;@@@ Design & coding: DreamBot development team & Brax
;@@@ (C) Copyright 2004-2006 DreamBot development team. All rights reserved. 
;@@@


;@@@ db misc games setup dialog @@@
dialog games {
  title "DreamBot misc games"
  icon "img/set.ico", 0
  size -1 -1 400 230
  text "      Using this dialog you can enable or disable certain commands, such as !time, !date, !roll, etc. Note that if enabled, these commands can be used by any user, so that's why I created this dialog. Enjoy!", 1, 5 5 390 80
  box "", 100, 5 60 390 165
  check "!date", 2, 10 75 75 15
  check "!time", 3, 10 95 75 15
  check "!roll game", 4, 10 115 75 15
  check "!hl (Higher/Lower) game", 5, 10 135 135 15
  check "!random (randomize tool)", 6, 10 155 140 15
  check "!char (ASCII character)", 7, 10 175 135 15
  check "!timebomb", 11, 10 195 135 15
  button "Save", 8, 300 75 90 30
  button "Cancel", 9, 300 110 90 30, cancel
  button "Apply", 10, 300 145 90 30 
}
on *:dialog:games:init:0: {
  if (%!date == on) { did -c games 2 }
  if (%!time == on) { did -c games 3 }
  if (%!roll == on) { did -c games 4 }
  if (%!hl == on) { did -c games 5 }
  if (%!random == on) { did -c games 6 }
  if (%!char == on) { did -c games 7 }
  if (%!timebomb == on) { did -c games 11 }
}
on *:dialog:games:sclick:8:{
  if ($did(games,2).state == 1) { set %!date on }
  if ($did(games,2).state == 0) { set %!date off }
  if ($did(games,3).state == 1) { set %!time on }
  if ($did(games,3).state == 0) { set %!time off }
  if ($did(games,4).state == 1) { set %!roll on }
  if ($did(games,4).state == 0) { set %!roll off }
  if ($did(games,5).state == 1) { set %!hl on }
  if ($did(games,5).state == 0) { set %!hl off }
  if ($did(games,6).state == 1) { set %!random on }
  if ($did(games,6).state == 0) { set %!random off }
  if ($did(games,7).state == 1) { set %!char on }
  if ($did(games,7).state == 0) { set %!char off }
  if ($did(games,11).state == 1) { set %!timebomb on }
  if ($did(games,11).state == 0) { set %!timebomb off }
  dialog -c games
  _info DreamBot Misc Games features were saved. 
}
on *:dialog:games:sclick:10:{
  if ($did(games,2).state == 1) { set %!date on }
  if ($did(games,2).state == 0) { set %!date off }
  if ($did(games,3).state == 1) { set %!time on }
  if ($did(games,3).state == 0) { set %!time off }
  if ($did(games,4).state == 1) { set %!roll on }
  if ($did(games,4).state == 0) { set %!roll off }
  if ($did(games,5).state == 1) { set %!hl on }
  if ($did(games,5).state == 0) { set %!hl off }
  if ($did(games,6).state == 1) { set %!random on }
  if ($did(games,6).state == 0) { set %!random off }
  if ($did(games,7).state == 1) { set %!char on }
  if ($did(games,7).state == 0) { set %!char off }
  if ($did(games,11).state == 1) { set %!timebomb on }
  if ($did(games,11).state == 0) { set %!timebomb off }
  _info DreamBot Misc Games features were saved. 
}

;@@@ !time & !date functions @@@
on 1:text:*date:#: { 
  if (%!date == on) {
    if ($1 == %c $+ date) { 
      var %date = $time(d)
      if $right(%date,1) = 1 { %date = %date $+ st | goto display }
      if $right(%date,1) = 2 { %date = %date $+ nd | goto display }
      if $right(%date,1) = 3 { %date = %date $+ rd | goto display }
      else { %date = %date $+ th }
      :display
      msg $chan Today is $time(dddd) $+ , %date of $time(mmmm) $time(yyyy) $+ . 
    }
  }
}
/*
on 1:text:*time:#: { 
  if (%!time == on) {
    if ($1 == %c $+ time) { 

      ;Define a new timezone, as mIRC's is messed up
      var %tz.tmp = $timezone
      if $left(%tz.tmp,1) == $chr(45) { var %timezone = $remove($timezone,$chr(45)) }
      if $left(%tz.tmp,1) !== $chr(45) { var %timezone = $chr(45) $+ $timezone }

      ;Attempt to display timezone
      var %time-zone = $iif($left(%timezone,1) == $chr(45),$mid(%timezone,2,$len(%timezone)),%timezone)
      ;GMT segments
      var %segments = $calc(%time-zone / 3600)
      msg $chan Now it's $time (GMT $+ $iif($left(%timezone,1) == $chr(45),$left(%timezone,1),$chr(43)) $+ %segments $+ ). 
    }
  }
}
*/
; ========================================
; DreamBot IRC Bot
; Time + timezones
; $Id: datime.mrc,v 1.0 2005/11/26 4:20 Brax $
; Brax braxter@gmail.com
; ========================================

ON 1:text:*time*:#: { 
  IF (%!time == on) {
    IF ($1 == %c $+ time) && ($2 == $null) {
      .msg $chan Now is $time $+ .
    }
    IF ($1 == %c $+ time) && ($2 >= -12) && ($2 <= 12) {
      msg $chan $gmttime($2)
    }
  }
}

ALIAS gmttime {
  var %gmt0 = $asctime($gmt,HH:nn:ss)
  var %gmtzone = $1-
  var %gmttocalc = $gettok(%gmt0,1,58)
  IF ($left(%gmtzone,1) isnum 0-9) {
    var %gmtzone = + $+ %gmtzone
  }
  var %gmtcalcD = $calc(%gmttocalc %gmtzone)
  IF (%gmtcalcD > 23) {
    var %gmtcalcD = $calc(%gmtcalcD -24)
  }
  IF (%gmtcalcD < 0) {
    var %gmtcalcD = $calc(24 %gmtcalcD)
  }
  return Time in GMT $+ %gmtzone is: %gmtcalcD $+ : $+ $gettok(%gmt0,2,58) $+ : $+ $gettok(%gmt0,3,58)
}
;@@@ Misc characters function (!random,!char,!asc) @@@
on 1:text:*random*:#: {
  if ($1 == %c $+ random) {
    if (%!random == on) {
      if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ random <char1> <char2>. This service is avalable only to voiced or oped users. | halt }
      if (($nick isvoice $chan) || ($nick isop $chan)) { //.msg $chan $rand($2,$3) }
    }
  }
}
on @100:text:*random*:#: {
  if ($1 == %c $+ random) {
    if (%!random == on) {
      if (($2 == $null) || ($3 == $null)) { .msg $nick Command incomplete. Syntax: %c $+ random <char1> <char2>. | halt } 
      { //.msg $chan $rand($2,$3) }
    }
  }
}
on @1:text:*char*:#: {
  if ($1 == %c $+ char) {
    if (%!char == on) {
      if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ char <ASCII symbol number>. | halt }
      else { .msg $chan ASCII number $2 is equal to $chr($2) }
    }
  }
}
;@@@ Roll the dices @@@
on 1:text:*roll:#: {
  if ($1 == %c $+ roll) {
    if (%!roll == on) {
      set %roll1 $rand(1,6)
      set %roll2 $rand(1,6)
      describe $chan rolls the dices for $nick $+ : %roll1 and %roll2 = $calc(%roll1 + %roll2)
      unset %roll1 %roll2
    }
  }
}

;@@@ Higher/lower game @@@
alias _check.hl {
  if (%hl [ $+ [ $1 ] ] == $null) { .timerhl $+ $1 off | halt }
  msg $1 5Time's up! I can't figure it out how you didn't guess this number. It was $+ 4 %hl.num [ $+ [ $1 ] ] $+ 5 $+  . Game is now over. Type %c $+ hl on <number> to play again!
  unset %hl [ $+ [ $1 ] ]
  unset %hl.num [ $+ [ $1 ] ]
}
on 1:text:*hl*:#: {
  if ($1 == %c $+ hl) {
    if (%!hl == on) {
      if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ hl <on|off> <number>. | halt }
      if ($2 == on) { 
        if ($3 == $null) { msg $chan Please specify a number. | halt }
        if ($3 !isnum 0-9999) { msg $chan Enter a number between 0 and 9999. | halt }
        if ($3 == 0) { msg $chan $nick $+ , do you really want to guess a number between 0 and 0? | halt }
        if %hl [ $+ [ $chan ] ] !== $null { msg $chan Another game is already running, type  $+ %c $+ hl off to disable it. | halt }
        set %hl [ $+ [ $chan ] ] on
        set %hl.num [ $+ [ $chan ] ] $rand(0,$3)
        msg $chan 4Higher/3Lower 5game enabled! 7I picked up a number between 0 and $3 $+ . Type 10 $+ %c $+ hl <number> 6to try to guess it and you have 1 minute to do so!
        .timerhl $+ $chan 1 60 _check.hl $chan 
        halt
      }
      if ($2 == off) { 
        unset %hl [ $+ [ $chan ] ]
        unset %hl.num [ $+ [ $chan ] ]
        msg $chan 4Higher/3Lower game disabled.
        halt
      }
      else {
        if (%hl [ $+ [ $chan ] ] == $null) { msg $chan No game is enabled. | halt }
        if ($2 !isnum 0-9999) { msg $chan Enter a number between 0 and 9999. $2 is outranged. | halt }
        if ($2 > %hl.num [ $+ [ $chan ] ]) { msg $chan 3Lower, $nick $+ . }
        if ($2 < %hl.num [ $+ [ $chan ] ]) { msg $chan 4Higher, $nick $+ . }
        if ($2 == %hl.num [ $+ [ $chan ] ]) { 
          msg $chan Yes, $nick $+ , $2 was the correct number! Game is now over. 6Type %c $+ hl on <number> to play again! 
          unset %hl [ $+ [ $chan ] ]
          unset %hl.num [ $+ [ $chan ] ]
          .timerhl $+ $chan off
        }
      }
    }
  }
}
