Advertisement
Guest User

Uno.tcl

a guest
Jul 2nd, 2011
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.40 KB | None | 0 0
  1. set UnoChan "#uno"
  2. set UnoRobot "Games"
  3. set UnoPointsName "Points"
  4. set UnoStopAfter 5
  5. set UnoBonus 1000
  6. set UnoWildDrawTwos 1
  7. set UnoCFGFile "scripts/jeux/uno.cfg"
  8. set UnoScoreFile "scripts/jeux/UnoScores"
  9. set UnoMaxNickLen 9
  10. set UnoMaxPlayers 10
  11. set UnoOpFlags "o|o"
  12. set UnoNTC "NOTICE"
  13.  
  14. # Command Binds
  15. bind pub - !unocmds UnoCmds
  16. bind pub - !remove UnoRemove
  17. bind pub - !pause UnoPause
  18. bind pub - !unowon UnoWon
  19. bind pub - !top10 UnoTopTen
  20. bind pub - !top10won UnoTopTenWon
  21. bind pub - !top3last UnoTopThreeLast
  22. bind pub - !fast UnoTopFast
  23. bind pub - !high UnoHighScore
  24. bind pub - !played UnoPlayed
  25. bind pub - !records UnoRecords
  26. bind pub - !version UnoVersion
  27. bind pub - !uno UnoInit
  28. bind pub - !stop UnoStop
  29.  
  30. # DCC Binds
  31. bind dcc - unohands dccUnoHands
  32. bind dcc - unorehash dcc_unorehash
  33.  
  34. # Cron Bind For Score Reset
  35. bind time - "00 00 01 * *" UnoNewMonth
  36.  
  37. # Global Variables
  38. set UnoOn 0
  39. set UnoMode 0
  40. set UnoPaused 0
  41. set UnoPlayers 0
  42. set MasterDeck ""
  43. set UnoDeck ""
  44. set DiscardPile ""
  45. set PlayCard ""
  46. set RoundRobin ""
  47. set ThisPlayer ""
  48. set ThisPlayerIDX 0
  49. set UnoStartTime [unixtime]
  50. set IsColorChange 0
  51. set ColorPicker ""
  52. set IsDraw 0
  53. set UnoIDX ""
  54. set UnPlayedRounds 0
  55.  
  56. # Scores Records And Ads
  57. set UnoLastMonthCards(0) "Nobody 0"
  58. set UnoLastMonthCards(1) "Nobody 0"
  59. set UnoLastMonthCards(2) "Nobody 0"
  60. set UnoLastMonthGames(0) "Nobody 0"
  61. set UnoLastMonthGames(1) "Nobody 0"
  62. set UnoLastMonthGames(2) "Nobody 0"
  63. set UnoFast "Nobody 600"
  64. set UnoHigh "Nobody 0"
  65. set UnoPlayed "Nobody 0"
  66. set UnoRecordHigh "Nobody 0"
  67. set UnoRecordFast "Nobody 600"
  68. set UnoRecordCard "Nobody 0"
  69. set UnoRecordWins "Nobody 0"
  70. set UnoRecordPlayed "Nobody 0"
  71. set UnoAdNumber 0
  72.  
  73. # Card Stats
  74. set CardStats(played) 0
  75. set CardStats(passed) 0
  76. set CardStats(drawn) 0
  77. set CardStats(wilds) 0
  78. set CardStats(draws) 0
  79. set CardStats(skips) 0
  80. set CardStats(revs) 0
  81.  
  82. # Timers
  83. set UnoStartTimer ""
  84. set UnoSkipTimer ""
  85. set UnoCycleTimer ""
  86. set UnoBotTimer ""
  87.  
  88. # Grace periods and timeouts
  89. # AutoSkip period can be raised but not lower than 2
  90. set AutoSkipPeriod 2
  91. set StartGracePeriod 30
  92. set RobotRestartPeriod 1
  93. set UnoCycleTime 30
  94.  
  95. # Nick colours
  96. set UnoNickColour "06 13 03 07 12 10 04 11 09 08"
  97.  
  98. # Debugging info
  99. set Debug 0
  100. set UnoVersion "0.96.74.3"
  101.  
  102. #
  103. # Bind Channel Commands
  104. #
  105. proc UnoBindCmds {} {
  106. bind pub - !go JoinUno
  107. bind pub - !zou JoinUno
  108. bind pub - !ordre UnoOrder
  109. bind pub - !od UnoOrder
  110. bind pub - !time UnoTime
  111. bind pub - !tps UnoTime
  112. bind pub - !cartes UnoShowCards
  113. bind pub - !ca UnoShowCards
  114. bind pub - !carte UnoPlayCard
  115. bind pub - !j UnoPlayCard
  116. bind pub - !card UnoTopCard
  117. bind pub - !cd UnoTopCard
  118. bind pub - !turn UnoTurn
  119. bind pub - !tu UnoTurn
  120. bind pub - !p UnoDraw
  121. bind pub - !dr UnoDraw
  122. bind pub - !color UnoColorChange
  123. bind pub - !c UnoColorChange
  124. bind pub - !passe UnoPass
  125. bind pub - !pa UnoPass
  126. bind pub - !count UnoCount
  127. bind pub - !ct UnoCount
  128. bind pub - !stats UnoCardStats
  129. bind pub - !st UnoCardStats
  130. }
  131.  
  132. #
  133. # Unbind Channel Commands
  134. #
  135. proc UnoUnbindCmds {} {
  136. catch {unbind pub - !go JoinUno}
  137. catch {unbind pub - !zou JoinUno}
  138. catch {unbind pub - !order UnoOrder}
  139. catch {unbind pub - !od UnoOrder}
  140. catch {unbind pub - !time UnoTime}
  141. catch {unbind pub - !tps UnoTime}
  142. catch {unbind pub - !cartes UnoShowCards}
  143. catch {unbind pub - !ca UnoShowCards}
  144. catch {unbind pub - !carte UnoPlayCard}
  145. catch {unbind pub - !j UnoPlayCard}
  146. catch {unbind pub - !card UnoTopCard}
  147. catch {unbind pub - !cd UnoTopCard}
  148. catch {unbind pub - !turn UnoTurn}
  149. catch {unbind pub - !tu UnoTurn}
  150. catch {unbind pub - !p UnoDraw}
  151. catch {unbind pub - !dr UnoDraw}
  152. catch {unbind pub - !color UnoColorChange}
  153. catch {unbind pub - !c UnoColorChange}
  154. catch {unbind pub - !passe UnoPass}
  155. catch {unbind pub - !pa UnoPass}
  156. catch {unbind pub - !count UnoCount}
  157. catch {unbind pub - !ct UnoCount}
  158. catch {unbind pub - !stats UnoCardStats}
  159. catch {unbind pub - !st UnoCardStats}
  160. }
  161.  
  162. #
  163. # Reset Game Variables
  164. #
  165. proc UnoReset {} {
  166. global UnoOn UnoMode UnoPaused UnoPlayers RoundRobin UnoDeck ThisPlayer ThisPlayerIDX PlayCard
  167. global DiscardPile IsColorChange ColorPicker IsDraw UnoIDX MasterDeck CardStats
  168. global UnoStartTimer UnoSkipTimer UnoCycleTimer
  169.  
  170. set UnoMode 0
  171. set UnoPaused 0
  172. set UnoPlayers 0
  173. set MasterDeck ""
  174. set UnoDeck ""
  175. set DiscardPile ""
  176. set RoundRobin ""
  177. set ThisPlayer ""
  178. set ThisPlayerIDX 0
  179. set PlayCard ""
  180. set IsColorChange 0
  181. set ColorPicker ""
  182. set IsDraw 0
  183. set UnoIDX ""
  184. set UnoAdNumber 0
  185.  
  186. set CardStats(played) 0
  187. set CardStats(passed) 0
  188. set CardStats(drawn) 0
  189. set CardStats(wilds) 0
  190. set CardStats(draws) 0
  191. set CardStats(skips) 0
  192. set CardStats(revs) 0
  193.  
  194. set UnoStartTimer ""
  195. set UnoSkipTimer ""
  196. set UnoCycleTimer ""
  197.  
  198. return
  199. }
  200.  
  201. #
  202. # Stop a game
  203. #
  204. proc UnoStop {nick uhost hand chan arg} {
  205. global Debug UnoChan UnoOn UnoPaused UnPlayedRounds UnoStartTimer UnoSkipTimer UnoCycleTimer
  206.  
  207. if {$chan != $UnoChan} {return}
  208.  
  209. catch {killutimer $UnoStartTimer}
  210. catch {killtimer $UnoSkipTimer}
  211. catch {killutimer $UnoCycleTimer}
  212.  
  213. unomsg "[unoad]\00306 arrêté par \00304\[\00312$nick!$uhost\00304\]\003"
  214.  
  215. set UnoOn 0
  216. set UnoPaused 0
  217. set UnPlayedRounds 0
  218.  
  219. UnoUnbindCmds
  220. UnoReset
  221.  
  222. return
  223. }
  224.  
  225. #
  226. # First Entry
  227. #
  228. proc UnoInit {nick uhost hand chan arg} {
  229. global UnoChan UnoOn
  230. if {($chan != $UnoChan)||($UnoOn > 0)} {return}
  231. unomsg "[unoad] \00304\[\00310$nick\!$uhost\00304\]\003"
  232. set UnoOn 1
  233. UnoBindCmds
  234. UnoNext
  235. return
  236. }
  237.  
  238. #
  239. # Initialize a new game
  240. #
  241. proc UnoNext {} {
  242. global UnoOn MasterDeck UnoDeck UnoMode StartGracePeriod UnoHand NickColor UnoVersion UnoStartTimer UnoSkipTimer
  243.  
  244. if {$UnoOn == 0} {return}
  245.  
  246. UnoReset
  247.  
  248. set UnoMode 1
  249.  
  250. set MasterDeck [list B0 B1 B1 B2 B2 B3 B3 B4 B4 B5 B5 B6 B6 B7 B7 B8 B8 B9 B9 BR BR BP BP BTD BTD R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7 R8 R8 R9 R9 RR RR RP RP RTD RTD J0 J1 J1 J2 J2 J3 J3 J4 J4 J5 J5 J6 J6 J7 J7 J8 J8 J9 J9 JR JR JP JP JTD JTD V0 V1 V1 V2 V2 V3 V3 V4 V4 V5 V5 V6 V6 V7 V7 V8 V8 V9 V9 VR VR VP VP VTD VTD C C C C CTQ CTQ CTQ CTQ]
  251. set UnoDeck ""
  252.  
  253. binary scan [unixtime] S1 rseed
  254. set newrand [expr srand($rseed)]
  255.  
  256. while {[llength $UnoDeck] != 108} {
  257. set pcardnum [rand [llength $MasterDeck]]
  258. set pcard [lindex $MasterDeck $pcardnum]
  259. lappend UnoDeck $pcard
  260. set MasterDeck [lreplace $MasterDeck $pcardnum $pcardnum]
  261. }
  262.  
  263. if [info exist UnoHand] {unset UnoHand}
  264. if [info exist NickColor] {unset NickColor}
  265.  
  266. unomsg " "
  267. unomsg "[unoad]\003 \0030,7 Taper !unocmds pour une aide sur les commandes \003"
  268. unomsg "[unoad]\003 \0030,12 Inscrivez-vous - Vous avez $StartGracePeriod Seconds ,tappez !go ou !zou \003"
  269.  
  270. set UnoStartTimer [utimer $StartGracePeriod UnoStart]
  271.  
  272. return
  273. }
  274.  
  275. #
  276. # Start a new game
  277. #
  278. proc UnoStart {} {
  279. global UnoChan UnoOn UnoCycleTime UnoRobot Debug UnoIDX UnoStartTime UnoPlayers RoundRobin ThisPlayer ThisPlayerIDX UnoDeck DiscardPile UnoMode UnoHand PlayCard AutoSkipPeriod
  280. global UnoSkipTimer UnPlayedRounds UnoStopAfter NickColor
  281.  
  282. if {$UnoOn == 0} {return}
  283.  
  284. if {[llength $RoundRobin] == 0} {
  285. unomsg "[unoad] \0030,3 Pas de joueurs - Prochaine partie dans $UnoCycleTime secondes \003"
  286. incr UnPlayedRounds
  287. if {($UnoStopAfter > 0)&&($UnPlayedRounds >= $UnoStopAfter)} {
  288. unomsg "[unoad] \0030,6 Stopper apres $UnoStopAfter relance - Tapez !uno pour relancé un partie \003"
  289. utimer 1 "UnoStop $UnoRobot $UnoRobot none $UnoChan none"
  290. return
  291. }
  292. UnoCycle
  293. return
  294. }
  295.  
  296. # Bot Joins If One Player
  297.  
  298. if {[llength $RoundRobin] == 1} {
  299. incr UnoPlayers
  300.  
  301. lappend RoundRobin "$UnoRobot"
  302. lappend UnoIDX "$UnoRobot"
  303.  
  304. if [info exist UnoHand($UnoRobot)] {unset UnoHand($UnoRobot)}
  305. if [info exist NickColor($UnoRobot)] {unset NickColor($UnoRobot)}
  306.  
  307. set UnoHand($UnoRobot) ""
  308. set NickColor($UnoRobot) [colornick $UnoPlayers]
  309.  
  310. unomsg "[nikclr $UnoRobot]\003 joins [unoad]\003"
  311.  
  312. UnoShuffle 7
  313.  
  314. while {[llength $UnoHand($UnoRobot)] != 7} {
  315. set pcardnum [rand [llength $UnoDeck]]
  316. set pcard [lindex $UnoDeck $pcardnum]
  317. set UnoDeck [lreplace ${UnoDeck} $pcardnum $pcardnum]
  318. lappend UnoHand($UnoRobot) "$pcard"
  319. }
  320. if {$Debug > 1} { unolog $UnoRobot $UnoHand($UnoRobot) }
  321. }
  322.  
  323. unomsg "\0030,6 Bienvenue à \003 [unoad]\003"
  324. unomsg "\0030,10 \002$UnoPlayers\002 joueurs pour cette partie \0030,6 $RoundRobin \003"
  325.  
  326. set UnoMode 2
  327. set ThisPlayer [lindex $RoundRobin 0]
  328.  
  329. # Draw Card From Deck - First Top Card
  330.  
  331. set DiscardPile ""
  332. set pcardnum [rand [llength $UnoDeck]]
  333. set pcard [lindex $UnoDeck $pcardnum]
  334.  
  335. # Play Doesnt Start With A Wild Card
  336.  
  337. while {[string range $pcard 0 0] == "C"} {
  338. set pcardnum [rand [llength $UnoDeck]]
  339. set pcard [lindex $UnoDeck $pcardnum]
  340. }
  341.  
  342. set PlayCard $pcard
  343.  
  344. set UnoDeck [lreplace ${UnoDeck} $pcardnum $pcardnum]
  345.  
  346. set Card [CardColor $pcard]
  347.  
  348. unomsg "[nikclr $ThisPlayer]\003 joue en premier - la première carte est $Card \003"
  349.  
  350. set Card [CardColorAll $ThisPlayer]
  351.  
  352. showcards $ThisPlayerIDX $Card
  353.  
  354. set UnoStartTime [unixtime]
  355.  
  356. # Start Auto-Skip Timer
  357.  
  358. set UnoSkipTimer [timer $AutoSkipPeriod UnoAutoSkip]
  359.  
  360. set UnPlayedRounds 0
  361. return
  362. }
  363.  
  364. #
  365. # Cycle a new game
  366. #
  367. proc UnoCycle {} {
  368. global UnoOn UnoMode UnoCycleTime UnoCycleTimer UnoSkipTimer
  369. if {$UnoOn == 0} {return}
  370. set UnoMode 4
  371. catch {killtimer $UnoSkipTimer}
  372. set AdTime [expr $UnoCycleTime /2]
  373. set UnoAdTimer [utimer $AdTime UnoScoreAdvertise]
  374. set UnoCycleTimer [utimer $UnoCycleTime UnoNext]
  375. return
  376. }
  377.  
  378. #
  379. # Add a player
  380. #
  381. proc JoinUno {nick uhost hand chan arg} {
  382. global Debug UnoIDX UnoMode UnoPlayers RoundRobin UnoDeck UnoHand UnoChan NickColor UnoMaxPlayers
  383.  
  384. if {($chan != $UnoChan)||($UnoMode < 1)||($UnoMode > 2)} {return}
  385.  
  386. if {[llength $RoundRobin] == $UnoMaxPlayers} {
  387. unontc $nick "Désolé $nick - cette partie de Uno a déjà $UnoMaxPlayers joueurs, essayez au prochain jeu"
  388. return
  389. }
  390.  
  391. set pcount 0
  392. while {[lindex $RoundRobin $pcount] != ""} {
  393. if {[lindex $RoundRobin $pcount] == $nick} {
  394. return
  395. }
  396. incr pcount
  397. }
  398.  
  399. incr UnoPlayers
  400.  
  401. lappend RoundRobin $nick
  402. lappend UnoIDX $nick
  403.  
  404. if [info exist UnoHand($nick)] {unset UnoHand($nick)}
  405. if [info exist NickColor($nick)] {unset NickColor($nick)}
  406.  
  407. set UnoHand($nick) ""
  408. set NickColor($nick) [colornick $UnoPlayers]
  409.  
  410. # Re-Shuffle Deck
  411.  
  412. UnoShuffle 7
  413.  
  414. # Deal Cards To Player
  415.  
  416. set Card ""
  417. while {[llength $UnoHand($nick)] != 7} {
  418. set pcardnum [rand [llength $UnoDeck]]
  419. set pcard [lindex $UnoDeck $pcardnum]
  420. set UnoDeck [lreplace ${UnoDeck} $pcardnum $pcardnum]
  421. lappend UnoHand($nick) $pcard
  422. append Card [CardColor $pcard]
  423. }
  424.  
  425. if {$Debug > 1} { unolog $nick $UnoHand($nick) }
  426.  
  427. unomsg "[nikclr $nick]\003 join cette parti de [unoad]\003"
  428. unontc $nick "main: $Card"
  429. return
  430. }
  431.  
  432. #
  433. # Add card(s) to players hand
  434. #
  435. proc UnoAddDrawToHand {cplayer idx num} {
  436. global UnoHand UnoDeck RoundRobin CardStats
  437.  
  438. # Check if deck needs reshuffling
  439. UnoShuffle $num
  440.  
  441. set Card ""
  442.  
  443. set newhand [expr [llength $UnoHand($cplayer)] + $num]
  444.  
  445. while {[llength $UnoHand($cplayer)] != $newhand} {
  446. set pcardnum [rand [llength $UnoDeck]]
  447. set pcard [lindex $UnoDeck $pcardnum]
  448. set UnoDeck [lreplace ${UnoDeck} $pcardnum $pcardnum]
  449. lappend UnoHand($cplayer) $pcard
  450. append Card [CardColor $pcard]
  451. }
  452.  
  453. showdraw $idx $Card
  454.  
  455. incr CardStats(drawn) $num
  456. }
  457.  
  458. #
  459. # Remove played card from player's hand
  460. #
  461. proc UnoRemoveCardFromHand {cplayer pcard} {
  462. global UnoHand
  463. set UnoHand($cplayer) [lreplace $UnoHand($cplayer) $pcard $pcard]
  464. }
  465.  
  466. #
  467. # Add card to discard pile
  468. #
  469. proc AddToDiscardPile {playcard} {
  470. global DiscardPile
  471. if {[string range $playcard 1 1] != ""} {
  472. lappend DiscardPile $playcard
  473. }
  474. }
  475.  
  476. #
  477. # Draw a card
  478. #
  479. proc UnoDraw {nick uhost hand chan arg} {
  480. global UnoChan UnoMode UnoDeck ThisPlayer ThisPlayerIDX UnoHand RoundRobin IsDraw CardStats
  481.  
  482. if {($chan != $UnoChan)||($UnoMode != 2)||($nick != $ThisPlayer)} {return}
  483.  
  484. if {$IsDraw == 0} {
  485. set IsDraw 1
  486. UnoShuffle 1
  487.  
  488. set dcardnum [rand [llength $UnoDeck]]
  489. set dcard [lindex $UnoDeck $dcardnum]
  490. lappend UnoHand($nick) $dcard
  491. set UnoDeck [lreplace ${UnoDeck} $dcardnum $dcardnum]
  492.  
  493. append Card [CardColor $dcard]
  494.  
  495. showdraw $ThisPlayerIDX $Card
  496.  
  497. showwhodrew $nick
  498. incr CardStats(drawn)
  499. UnoAutoSkipReset
  500.  
  501. return
  502. }
  503.  
  504. unontc $nick "Vous avez déjà tiré une carte $nick, joue une carte ou passe ton tour"
  505.  
  506. UnoAutoSkipReset
  507.  
  508. return
  509. }
  510.  
  511. #
  512. # Pass a turn
  513. #
  514. proc UnoPass {nick uhost hand chan arg} {
  515. global UnoChan UnoMode ThisPlayer IsDraw ThisPlayerIDX RoundRobin IsColorChange CardStats
  516.  
  517. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  518. if {($nick != $ThisPlayer)||($IsColorChange == 1)} {return}
  519.  
  520. UnoAutoSkipReset
  521.  
  522. if {$IsDraw == 1} {
  523. incr CardStats(passed)
  524. set IsDraw 0
  525. UnoNextPlayer
  526. playpass $nick $ThisPlayer
  527. set Card [CardColorAll $ThisPlayer]
  528. showcards $ThisPlayerIDX $Card
  529. UnoRobotRestart
  530. } {
  531. unontc $nick "désolé $nick - tu a passer sans tirer une carte"
  532. }
  533. return
  534. }
  535.  
  536. #
  537. # Color change
  538. #
  539. proc UnoColorChange {nick uhost hand chan arg} {
  540. global UnoChan UnoMode IsDraw PlayCard ColorPicker IsColorChange ThisPlayer ThisPlayerIDX RoundRobin
  541.  
  542. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  543. if {($nick != $ColorPicker)||($IsColorChange == 0)} {return}
  544.  
  545. UnoAutoSkipReset
  546.  
  547. regsub -all \[`.,!{}] $arg "" arg
  548.  
  549. set NewColor [string toupper [string range $arg 0 0]]
  550.  
  551. switch $NewColor {
  552. "B" { set PlayCard "B"; set Card " \0030,12 Bleu \003 "}
  553. "V" { set PlayCard "V"; set Card " \0030,3 Vert \003 "}
  554. "J" { set PlayCard "J"; set Card " \0031,8 Jaune \003 "}
  555. "R" { set PlayCard "R"; set Card " \0030,4 Rouge \003 "}
  556. default { unontc $nick "Choisir une couleur - (R ou r )=rouge, ( V ou v )=vert, ( B ou b )=bleu, ( J ou j )=jaune"; return }
  557. }
  558.  
  559. UnoNextPlayer
  560.  
  561. unomsg "[nikclr $ColorPicker]\003 choisi $Card le jeu se poursuit avec [nikclr $ThisPlayer]\003"
  562.  
  563. set Card [CardColorAll $ThisPlayer]
  564. showcards $ThisPlayerIDX $Card
  565.  
  566. set ColorPicker ""
  567. set IsColorChange 0
  568. set IsDraw 0
  569.  
  570. UnoRobotRestart
  571.  
  572. return
  573. }
  574.  
  575. #
  576. # Skip card
  577. #
  578. proc PlayUnoSkipCard {nick pickednum crd} {
  579. global IsDraw ThisPlayer ThisPlayerIDX PlayCard RoundRobin CardStats
  580.  
  581. set c0 [string range $crd 0 0]
  582. set c1 [string range $crd 1 1]
  583. set cip0 [string range $PlayCard 0 0]
  584. set cip1 [string range $PlayCard 1 1]
  585.  
  586. if {$c1 != "P"} {return 0}
  587.  
  588. if {($c0 != $cip0)&&($c1 != $cip1)} {return 0}
  589.  
  590. incr CardStats(played)
  591. incr CardStats(skips)
  592.  
  593. AddToDiscardPile $PlayCard
  594.  
  595. UnoRemoveCardFromHand $nick $pickednum
  596.  
  597. set PlayCard $crd
  598. set Card [CardColor $crd]
  599.  
  600. set SkipPlayer $ThisPlayer
  601.  
  602. UnoNextPlayer
  603.  
  604. set SkippedPlayer [lindex $RoundRobin $ThisPlayerIDX]
  605.  
  606. UnoNextPlayer
  607.  
  608. # No Cards Left = Winner
  609. if {[check_unowin $SkipPlayer $Card] > 0} {
  610. showwin $SkipPlayer $Card
  611. UnoWin $SkipPlayer
  612. UnoCycle
  613. return 1
  614. }
  615.  
  616. playskip $nick $Card $SkippedPlayer $ThisPlayer
  617.  
  618. check_hasuno $SkipPlayer
  619.  
  620. set Card [CardColorAll $ThisPlayer]
  621. showcards $ThisPlayerIDX $Card
  622.  
  623. set IsDraw 0
  624. return 1
  625. }
  626.  
  627. #
  628. # Reverse card
  629. #
  630. proc PlayUnoReverseCard {nick pickednum crd} {
  631. global IsDraw UnoIDX ThisPlayer ThisPlayerIDX PlayCard RoundRobin CardStats
  632.  
  633. set c0 [string range $crd 0 0]
  634. set c1 [string range $crd 1 1]
  635. set cip0 [string range $PlayCard 0 0]
  636. set cip1 [string range $PlayCard 1 1]
  637.  
  638. if {$c1 != "R"} {return 0}
  639.  
  640. if {($c0 != $cip0)&&($c1 != $cip1)} {return 0}
  641.  
  642. incr CardStats(played)
  643. incr CardStats(revs)
  644.  
  645. AddToDiscardPile $PlayCard
  646.  
  647. UnoRemoveCardFromHand $nick $pickednum
  648.  
  649. set PlayCard $crd
  650. set Card [CardColor $crd]
  651.  
  652. # Reverse RoundRobin and Move To Next Player
  653. set NewRoundRobin ""
  654. set OrigOrderLength [llength $RoundRobin]
  655. set IDX $OrigOrderLength
  656.  
  657. while {$OrigOrderLength != [llength $NewRoundRobin]} {
  658. set IDX [expr ($IDX - 1)]
  659. lappend NewRoundRobin [lindex $RoundRobin $IDX]
  660. }
  661.  
  662. set Newindexorder ""
  663. set OrigindexLength [llength $UnoIDX]
  664. set IDX $OrigindexLength
  665.  
  666. while {$OrigindexLength != [llength $Newindexorder]} {
  667. set IDX [expr ($IDX - 1)]
  668. lappend Newindexorder [lindex $UnoIDX $IDX]
  669. }
  670.  
  671. set UnoIDX $Newindexorder
  672. set RoundRobin $NewRoundRobin
  673.  
  674. set ReversePlayer $ThisPlayer
  675.  
  676. # Next Player After Reversing RoundRobin
  677.  
  678. set pcount 0
  679. while {$pcount != [llength $RoundRobin]} {
  680. if {[lindex $RoundRobin $pcount] == $ThisPlayer} {
  681. set ThisPlayerIDX $pcount
  682. break
  683. }
  684. incr pcount
  685. }
  686.  
  687. # <3 Players Act Like A Skip Card
  688.  
  689. if {[llength $RoundRobin] > 2} {
  690. incr ThisPlayerIDX
  691. if {$ThisPlayerIDX >= [llength $RoundRobin]} {set ThisPlayerIDX 0}
  692. }
  693.  
  694. set ThisPlayer [lindex $RoundRobin $ThisPlayerIDX]
  695.  
  696. # No Cards Left = Winner
  697. if {[check_unowin $ReversePlayer $Card] > 0} {
  698. showwin $ReversePlayer $Card
  699. UnoWin $ReversePlayer
  700. UnoCycle
  701. return 1
  702. }
  703.  
  704. playcard $nick $Card $ThisPlayer
  705.  
  706. check_hasuno $ReversePlayer
  707.  
  708. set Card [CardColorAll $ThisPlayer]
  709. showcards $ThisPlayerIDX $Card
  710.  
  711. set IsDraw 0
  712. return 1
  713. }
  714.  
  715. #
  716. # Draw Two card
  717. #
  718. proc PlayUnoDrawTwoCard {nick pickednum crd} {
  719. global IsDraw ThisPlayer ThisPlayerIDX PlayCard RoundRobin CardStats UnoWildDrawTwos
  720.  
  721. set CardOk 0
  722. set c0 [string range $crd 0 0]
  723. set c2 [string range $crd 2 2]
  724. set cip0 [string range $PlayCard 0 0]
  725. set cip1 [string range $PlayCard 1 1]
  726. set cip2 [string range $PlayCard 2 2]
  727.  
  728. if {$c2 != "D"} {return 0}
  729.  
  730. if {$c0 == $cip0} {set CardOk 1}
  731. if {$cip2 == "D"} {set CardOk 1}
  732. if {$UnoWildDrawTwos != 0} {
  733. if {($cip1 != "")&&($cip2 != "Q")} {set CardOk 1}
  734. }
  735.  
  736. if {$CardOk == 1} {
  737. incr CardStats(draws)
  738. incr CardStats(played)
  739.  
  740. AddToDiscardPile $PlayCard
  741.  
  742. UnoRemoveCardFromHand $nick $pickednum
  743.  
  744. set PlayCard $crd
  745. set Card [CardColor $crd]
  746.  
  747. set DrawPlayer $ThisPlayer
  748. set DrawPlayerIDX $ThisPlayerIDX
  749.  
  750. # Move to the player that draws
  751.  
  752. UnoNextPlayer
  753.  
  754. set PlayerThatDrew $ThisPlayer
  755. set PlayerThatDrewIDX $ThisPlayerIDX
  756.  
  757. # Move To The Next Player
  758.  
  759. UnoNextPlayer
  760.  
  761. if {[check_unowin $nick $Card] > 0} {
  762. UnoAddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 2
  763. showwin $nick $Card
  764. UnoWin $nick
  765. UnoCycle
  766. return 1
  767. }
  768.  
  769. playdraw $nick $Card $PlayerThatDrew $ThisPlayer
  770.  
  771. UnoAddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 2
  772.  
  773. check_hasuno $nick
  774.  
  775. set Card [CardColorAll $ThisPlayer]
  776. showcards $ThisPlayerIDX $Card
  777.  
  778. set IsDraw 0
  779. return 1
  780. }
  781. return 0
  782. }
  783.  
  784. #
  785. # Wild Draw Four card
  786. #
  787. proc PlayUnoWildDrawFourCard {nick pickednum crd isrobot} {
  788. global ThisPlayer ThisPlayerIDX PlayCard RoundRobin IsColorChange ColorPicker CardStats
  789.  
  790. if {[string range $crd 2 2] != "Q"} {return 0}
  791.  
  792. incr CardStats(wilds)
  793. incr CardStats(played)
  794.  
  795. set ColorPicker $ThisPlayer
  796.  
  797. AddToDiscardPile $PlayCard
  798.  
  799. UnoRemoveCardFromHand $nick $pickednum
  800.  
  801. set PlayCard $crd
  802. set Card [CardColor $crd]
  803.  
  804. # move to the player that draws
  805. UnoNextPlayer
  806.  
  807. set PlayerThatDrew $ThisPlayer
  808. set PlayerThatDrewIDX $ThisPlayerIDX
  809.  
  810. if {$isrobot > 0} {
  811. # choose color and move to next player
  812. set cip [UnoBotPickAColor]
  813. UnoNextPlayer
  814. }
  815.  
  816. if {[check_unowin $nick $Card] > 0} {
  817. UnoAddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 4
  818. showwin $nick $Card
  819. UnoWin $nick
  820. UnoCycle
  821. return 1
  822. }
  823.  
  824. if {$isrobot > 0} {
  825. botplaywildfour $ColorPicker $PlayerThatDrew $ColorPicker $cip $ThisPlayer
  826. set ColorPicker ""
  827. set IsColorChange 0
  828. } {
  829. playwildfour $nick $PlayerThatDrew $ColorPicker
  830. set IsColorChange 1
  831. }
  832.  
  833. UnoAddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 4
  834.  
  835. check_hasuno $nick
  836.  
  837. if {$isrobot > 0} {
  838. set Card [CardColorAll $ThisPlayer]
  839. showcards $ThisPlayerIDX $Card
  840. }
  841.  
  842. set IsDraw 0
  843. return 1
  844. }
  845.  
  846. #
  847. # Wild card
  848. #
  849. proc PlayUnoWildCard {nick pickednum crd isrobot} {
  850. global IsDraw ThisPlayer ThisPlayerIDX PlayCard RoundRobin IsColorChange ColorPicker CardStats
  851.  
  852. if {[string range $crd 0 0] != "C"} {return 0}
  853.  
  854. incr CardStats(wilds)
  855. incr CardStats(played)
  856.  
  857. set ColorPicker $ThisPlayer
  858.  
  859. AddToDiscardPile $PlayCard
  860.  
  861. UnoRemoveCardFromHand $nick $pickednum
  862.  
  863. set PlayCard $crd
  864. set Card [CardColor $crd]
  865.  
  866. # Ok to remove this?
  867. #set ThisPlayer [lindex $RoundRobin $ThisPlayerIDX]
  868. #set DrawnPlayer $ThisPlayer
  869.  
  870. if {$isrobot > 0} {
  871. # Make A Color Choice
  872. set cip [UnoBotPickAColor]
  873. UnoNextPlayer
  874. }
  875.  
  876. # No Cards Left = Winner
  877. if {[check_unowin $nick $Card] > 0} {
  878. showwin $nick $Card
  879. UnoWin $nick
  880. UnoCycle
  881. return 1
  882. }
  883.  
  884. if {$isrobot > 0} {
  885. botplaywild $nick $ColorPicker $cip $ThisPlayer
  886. set ColorPicker ""
  887. set Card [CardColorAll $ThisPlayer]
  888. showcards $ThisPlayerIDX $Card
  889. set IsColorChange 0
  890. } {
  891. playwild $nick $ColorPicker
  892. set IsColorChange 1
  893. }
  894.  
  895. check_hasuno $nick
  896.  
  897. set IsDraw 0
  898. return 1
  899. }
  900.  
  901. #
  902. # Number card
  903. #
  904. proc PlayUnoNumberCard {nick pickednum crd} {
  905. global IsDraw ThisPlayer ThisPlayerIDX PlayCard RoundRobin CardStats
  906.  
  907. set CardOk 0
  908. set c1 [string range $crd 0 0]
  909. set c2 [string range $crd 1 1]
  910. set cip1 [string range $PlayCard 0 0]
  911. set cip2 [string range $PlayCard 1 1]
  912.  
  913. if {$c2 == -1} {return 0}
  914.  
  915. if {$c1 == $cip1} {set CardOk 1}
  916.  
  917. if {($cip2 != "")} {
  918. if {$c2 == $cip2} {set CardOk 1}
  919. }
  920.  
  921. if {$CardOk == 1} {
  922. incr CardStats(played)
  923. AddToDiscardPile $PlayCard
  924.  
  925. UnoRemoveCardFromHand $nick $pickednum
  926.  
  927. set PlayCard $crd
  928. set Card [CardColor $crd]
  929.  
  930. set NumberCardPlayer $ThisPlayer
  931.  
  932. UnoNextPlayer
  933.  
  934. if {[check_unowin $NumberCardPlayer $Card] > 0} {
  935. showwin $NumberCardPlayer $Card
  936. UnoWin $NumberCardPlayer
  937. UnoCycle
  938. return 1
  939. }
  940.  
  941. playcard $nick $Card $ThisPlayer
  942.  
  943. check_hasuno $NumberCardPlayer
  944.  
  945. set Card [CardColorAll $ThisPlayer]
  946. showcards $ThisPlayerIDX $Card
  947.  
  948. set IsDraw 0
  949. return 1
  950. }
  951. unontc $nick "Oops! Pas une carte en cours de validité - tirer ou de jouer une autre"
  952. return 0
  953. }
  954.  
  955. #
  956. # Attempt to find card in hand
  957. #
  958. proc UnoFindCard {nick pickednum crd IsRobot} {
  959. global UnoRobot ThisPlayer ThisPlayerIDX
  960.  
  961. #if {$Debug > 1} {unolog $UnoRobot "UnoFindCard: [lindex $UnoHand($ThisPlayer) $pickednum"}
  962.  
  963. # Wild Draw Four
  964. set FoundCard [PlayUnoWildDrawFourCard $nick $pickednum $crd $IsRobot]
  965. if {$FoundCard == 1} {return 4}
  966.  
  967. # Wild
  968. set FoundCard [PlayUnoWildCard $nick $pickednum $crd $IsRobot]
  969. if {$FoundCard == 1} {return 5}
  970.  
  971. # Draw Two
  972. set FoundCard [PlayUnoDrawTwoCard $nick $pickednum $crd]
  973. if {$FoundCard == 1} {return 3}
  974.  
  975. # Skip
  976. set FoundCard [PlayUnoSkipCard $nick $pickednum $crd]
  977. if {$FoundCard == 1} {return 1}
  978.  
  979. # Reverse
  980. set FoundCard [PlayUnoReverseCard $nick $pickednum $crd]
  981. if {$FoundCard == 1} {return 2}
  982.  
  983. # Number card
  984. set FoundCard [PlayUnoNumberCard $nick $pickednum $crd]
  985. if {$FoundCard == 1} {return 6}
  986.  
  987. return 0
  988. }
  989.  
  990. #
  991. # Play a card
  992. #
  993. proc UnoPlayCard {nick uhost hand chan arg} {
  994. global UnoChan UnoMode IsDraw IsColorChange ColorPicker UnoPlayers RoundRobin UnoHand ThisPlayer
  995.  
  996. if {($chan != $UnoChan)||($UnoMode != 2)||($nick != $ThisPlayer)} {return}
  997.  
  998. UnoAutoSkipReset
  999.  
  1000. if {$IsColorChange == 1} {return}
  1001.  
  1002. regsub -all \[`,.!{}\ ] $arg "" arg
  1003.  
  1004. if {$arg == ""} {return}
  1005.  
  1006. set pcard [string toupper [string range $arg 0 3]]
  1007.  
  1008. set CardInPlayerHand 0
  1009.  
  1010. set pcount 0
  1011. while {[lindex $UnoHand($nick) $pcount] != ""} {
  1012. if {$pcard == [lindex $UnoHand($nick) $pcount]} {
  1013. set pcardnum $pcount
  1014. set CardInPlayerHand 1
  1015. break
  1016. }
  1017. incr pcount
  1018. }
  1019.  
  1020. if {$CardInPlayerHand == 0} {
  1021. unontc $nick "Désolé $nick - Vous ne disposez pas de cette carte - tiré ou jouer une autre"
  1022. return
  1023. }
  1024.  
  1025. set CardFound [UnoFindCard $nick $pcardnum $pcard 0]
  1026.  
  1027. switch $CardFound {
  1028. 0 {return}
  1029. 4 {return}
  1030. 5 {return}
  1031. default {UnoRobotRestart; return}
  1032. }
  1033. }
  1034.  
  1035. #
  1036. # Robot Player
  1037. #
  1038.  
  1039. proc UnoRobotPlayer {} {
  1040. global Debug UnoIDX IsDraw IsColorChange ColorPicker UnoMode UnoPlayers RoundRobin UnoDeck UnoHand ThisPlayer ThisPlayerIDX PlayCard CardStats UnoRobot
  1041.  
  1042. # Check for a valid card in hand
  1043. set CardOk 0
  1044. set IsDraw 0
  1045. set CardCount 0
  1046.  
  1047. set cip1 [string range $PlayCard 0 0]
  1048. set cip2 [string range $PlayCard 1 1]
  1049.  
  1050. while {$CardCount < [llength $UnoHand($ThisPlayer)]} {
  1051. set playcard [lindex $UnoHand($ThisPlayer) $CardCount]
  1052. set c1 [string range $playcard 0 0]
  1053. set c2 [string range $playcard 1 1]
  1054.  
  1055. #if {$Debug > 1} {unolog $UnoRobot "Trying: $playcard"}
  1056.  
  1057. if {($c1 == $cip1)||($c2 == $cip2)||($c1 == "C")} {
  1058. set CardOk 1
  1059. set pcard $playcard
  1060. set pcardnum $CardCount
  1061. break
  1062. }
  1063. incr CardCount
  1064. }
  1065.  
  1066. # Play the card if found
  1067. if {$CardOk == 1} {
  1068. set CardFound [UnoFindCard $UnoRobot $pcardnum $pcard 1]
  1069. switch $CardFound {
  1070. 0 {}
  1071. 5 {return}
  1072. 6 {return}
  1073. default {UnoRobotRestart; return}
  1074. }
  1075. }
  1076.  
  1077. # Bot draws a card
  1078.  
  1079. UnoShuffle 1
  1080.  
  1081. set dcardnum [rand [llength $UnoDeck]]
  1082. set dcard [lindex $UnoDeck $dcardnum]
  1083. lappend UnoHand($UnoRobot) "$dcard"
  1084. set UnoDeck [lreplace ${UnoDeck} $dcardnum $dcardnum]
  1085.  
  1086. showwhodrew $UnoRobot
  1087.  
  1088. set CardOk 0
  1089. set CardCount 0
  1090.  
  1091. incr CardStats(drawn)
  1092.  
  1093. while {$CardCount < [llength $UnoHand($ThisPlayer)]} {
  1094. set playcard [lindex $UnoHand($ThisPlayer) $CardCount]
  1095. set c1 [string range $playcard 0 0]
  1096. set c2 [string range $playcard 1 1]
  1097.  
  1098. # if {$Debug > 1} {unolog $UnoRobot "DrawTry: $playcard"}
  1099.  
  1100. if {($c1 == $cip1)||($c2 == $cip2)||($c1 == "C")} {
  1101. set CardOk 1
  1102. set pcard $playcard
  1103. set pcardnum $CardCount
  1104. break
  1105. }
  1106. incr CardCount
  1107. }
  1108.  
  1109. # Bot plays drawn card or passes turn
  1110.  
  1111. if {$CardOk == 1} {
  1112. set CardFound [UnoFindCard $UnoRobot $pcardnum $pcard 1]
  1113. if {$CardFound == 1} {UnoRobotRestart; return}
  1114. switch $CardFound {
  1115. 0 {}
  1116. 5 {return}
  1117. 6 {return}
  1118. default {UnoRobotRestart; return}
  1119. }
  1120. } {
  1121. incr CardStats(passed)
  1122.  
  1123. set IsDraw 0
  1124.  
  1125. UnoNextPlayer
  1126.  
  1127. playpass $UnoRobot $ThisPlayer
  1128.  
  1129. set Card [CardColorAll $ThisPlayer]
  1130. showcards $ThisPlayerIDX $Card
  1131. }
  1132. return
  1133. }
  1134.  
  1135. #
  1136. # Autoskip inactive players
  1137. #
  1138. proc UnoAutoSkip {} {
  1139. global UnoMode ThisPlayer ThisPlayerIDX RoundRobin AutoSkipPeriod IsColorChange ColorPicker
  1140. global UnoIDX UnoPlayers UnoDeck UnoHand UnoChan UnoSkipTimer Debug NickColor UnoPaused
  1141.  
  1142. if {$UnoMode != 2} {return}
  1143. if {$UnoPaused != 0} {return}
  1144.  
  1145. if {[uno_isrobot $ThisPlayerIDX]} {return}
  1146.  
  1147. set Idler $ThisPlayer
  1148. set IdlerIDX $ThisPlayerIDX
  1149.  
  1150. if {[unotimerexists UnoAutoSkip] != ""} {
  1151. unolog "uno" "AutoSkip Timer Already Exists"
  1152. return
  1153. }
  1154.  
  1155. set InChannel 0
  1156. set uclist [chanlist $UnoChan]
  1157.  
  1158. set pcount 0
  1159. while {[lindex $uclist $pcount] != ""} {
  1160. if {[lindex $uclist $pcount] == $Idler} {
  1161. set InChannel 1
  1162. break
  1163. }
  1164. incr pcount
  1165. }
  1166.  
  1167. if {$InChannel == 0} {
  1168. unomsg "[nikclr $Idler]\003 a quitté le chan et est retiré du Uno\003"
  1169.  
  1170. if {$IsColorChange == 1} {
  1171. if {$Idler == $ColorPicker} {
  1172. # Make A Color Choice
  1173. set cip [UnoPickAColor]
  1174. unomsg "\0030,13 $Idler \003a pas sélectionner une couleur: choix au hasard $cip \003"
  1175. set IsColorChange 0
  1176. } {
  1177. unolog "uno" "UnoAutoRemove: IsColorChange definis mais $Idler pas ColorPicker"
  1178. }
  1179. }
  1180.  
  1181. UnoNextPlayer
  1182. unomsg "le joueur actuel est [nikclr $Idler]\003 ,on continus avec [nikclr $ThisPlayer]\003"
  1183. if {![uno_isrobot $ThisPlayerIDX]} {
  1184. set Card [CardColorAll $ThisPlayer]
  1185. showcards $ThisPlayerIDX $Card
  1186. }
  1187.  
  1188. set UnoPlayers [expr ($UnoPlayers -1)]
  1189.  
  1190. # Remove Player From Game And Put Cards Back In Deck
  1191. if {$UnoPlayers > 1} {
  1192. set RoundRobin [lreplace ${RoundRobin} $IdlerIDX $IdlerIDX]
  1193. set UnoIDX [lreplace ${UnoIDX} $IdlerIDX $IdlerIDX]
  1194. lappend UnoDeck "$UnoHand($Idler)"
  1195. unset UnoHand($Idler)
  1196. unset NickColor($Idler)
  1197. }
  1198.  
  1199. switch $UnoPlayers {
  1200. 1 {
  1201. showwindefault $ThisPlayer
  1202. UnoWin $ThisPlayer
  1203. UnoCycle
  1204. }
  1205. 0 {
  1206. unomsg "[unoad] \0030,10 Pas de joueur - Pas de gagnant - Recycling \003"
  1207. UnoCycle
  1208. }
  1209. default {
  1210. if {![uno_isrobot $ThisPlayerIDX]} {
  1211. UnoAutoSkipReset
  1212. UnoRobotRestart
  1213. }
  1214. }
  1215. }
  1216. return
  1217. }
  1218.  
  1219. if {$Debug > 0} {unolog "uno" "AutoSkip Player: $Idler"}
  1220.  
  1221. unomsg "[nikclr $Idler]\003 inactif pendant \00313$AutoSkipPeriod \003minutes il passe son tour"
  1222.  
  1223. # Player Was ColorPicker
  1224.  
  1225. if {$IsColorChange == 1} {
  1226. if {$Idler == $ColorPicker} {
  1227. # Make A Color Choice
  1228. set cip [UnoPickAColor]
  1229. unomsg "[nikclr $Idler]\003 a pas choisi de couleur : choix au hazard $cip"
  1230. set IsColorChange 0
  1231. } {
  1232. unolog "uno" "UnoRemove: IsColorChange definis mais $Idler pas ColorPicker"
  1233. }
  1234. }
  1235.  
  1236. UnoNextPlayer
  1237.  
  1238. unomsg "[nikclr $Idler]\003est le joueur actuel. On continu avec [nikclr $ThisPlayer]\003"
  1239.  
  1240. if {![uno_isrobot $ThisPlayerIDX]} {
  1241. set Card [CardColorAll $ThisPlayer]
  1242. showcards $ThisPlayerIDX $Card
  1243. } {
  1244. UnoRobotRestart
  1245. }
  1246. UnoAutoSkipReset
  1247. return
  1248. }
  1249.  
  1250. #
  1251. # Pause play
  1252. #
  1253. proc UnoPause {nick uhost hand chan arg} {
  1254. global UnoChan UnoOn UnoMode UnoOpFlags UnoPaused
  1255.  
  1256. if {$chan != $UnoChan} {return}
  1257. if {$UnoOn != 1} {return}
  1258. if {$UnoMode != 2} {return}
  1259.  
  1260. if {([validuser $nick])&&([matchattr $nick $UnoOpFlags $UnoChan])} {
  1261. if {$UnoPaused == 0} {
  1262. set UnoPaused 1
  1263. UnoUnbindCmds
  1264. unomsg "[unoad] \0030,4 Mise en pause par $nick \003"
  1265. } {
  1266. set UnoPaused 0
  1267. UnoBindCmds
  1268. UnoAutoSkipReset
  1269. unomsg "[unoad] \0030,4 reprise de la partie par $nick \003"
  1270. }
  1271. }
  1272. }
  1273.  
  1274. #
  1275. # Remove user from play
  1276. #
  1277. proc UnoRemove {nick uhost hand chan arg} {
  1278. global UnoChan UnoOn UnoCycleTime UnoIDX UnoPlayers ThisPlayer ThisPlayerIDX RoundRobin UnoDeck DiscardPile UnoHand IsColorChange ColorPicker NickColor UnoOpFlags
  1279.  
  1280. if {$chan != $UnoChan} {return}
  1281. if {$UnoOn == 0} {return}
  1282.  
  1283. regsub -all \[`,.!{}] $arg "" arg
  1284.  
  1285. # Allow Ops To Remove Another Player
  1286. set UnoOpRemove 0
  1287.  
  1288. if {[string length $arg] > 0} {
  1289. if {([validuser $nick])&&([matchattr $nick $UnoOpFlags $UnoChan])} {
  1290. set UnoOpRemove 1
  1291. set UnoOpNick $nick
  1292. set nick $arg
  1293. } {
  1294. return
  1295. }
  1296. }
  1297.  
  1298. set PlayerFound 0
  1299.  
  1300. # Remove Player If Found - Put Cards Back To Bottom Of Deck
  1301.  
  1302. set pcount 0
  1303. while {[lindex $RoundRobin $pcount] != ""} {
  1304. if {[string tolower [lindex $RoundRobin $pcount]] == [string tolower $nick]} {
  1305. set PlayerFound 1
  1306. set FoundIDX $pcount
  1307. set nick [lindex $RoundRobin $pcount]
  1308. break
  1309. }
  1310. incr pcount
  1311. }
  1312.  
  1313. if {$PlayerFound == 1} {
  1314. if {$UnoOpRemove > 0} {
  1315. unomsg "[nikclr $nick]\003 a été retiré de cette partie de Uno par $UnoOpNick"
  1316. } {
  1317. unontc $nick "Vous êtes maintenant retirée de l'actuel partie de Uno."
  1318. unomsg "[nikclr $nick]\003 left Uno"
  1319. }
  1320.  
  1321. # Player Was ColorPicker
  1322.  
  1323. if {$IsColorChange == 1} {
  1324. if {$nick == $ColorPicker} {
  1325. # Make A Color Choice
  1326. set cip [UnoPickAColor]
  1327. unomsg "[nikclr $nick]\003 tu n as pas choisi de couleur... donc choix au hazard $cip"
  1328. set IsColorChange 0
  1329. } {
  1330. unolog "uno" "UnoRemove: IsColorChange definis mais $nick pas ColorPicker"
  1331. }
  1332. }
  1333.  
  1334. if {$nick == $ThisPlayer} {
  1335. UnoNextPlayer
  1336. if {$UnoPlayers > 2} {
  1337. unomsg "[nikclr $nick]\003 vien de joué, on continnus avec [nikclr $ThisPlayer]\003"
  1338. }
  1339. UnoAutoSkipReset
  1340. }
  1341.  
  1342. set UnoPlayers [expr ($UnoPlayers -1)]
  1343.  
  1344. # Remove Player From Game And Put Cards Back In Deck
  1345.  
  1346. if {$UnoPlayers > 1} {
  1347. set RoundRobin [lreplace ${RoundRobin} $FoundIDX $FoundIDX]
  1348. set UnoIDX [lreplace ${UnoIDX} $FoundIDX $FoundIDX]
  1349. lappend DiscardPile "$UnoHand($nick)"
  1350. unset UnoHand($nick)
  1351. unset NickColor($nick)
  1352. }
  1353.  
  1354. set pcount 0
  1355. while {[lindex $RoundRobin $pcount] != ""} {
  1356. if {[lindex $RoundRobin $pcount] == $ThisPlayer} {
  1357. set ThisPlayerIDX $pcount
  1358. break
  1359. }
  1360. incr pcount
  1361. }
  1362.  
  1363. if {$UnoPlayers == 1} {
  1364. showwindefault $ThisPlayer
  1365. UnoWin $ThisPlayer
  1366. UnoCycle
  1367. return
  1368. }
  1369. UnoRobotRestart
  1370. } {
  1371. # Player not in current game
  1372. return
  1373. }
  1374.  
  1375. if {$UnoPlayers == 0} {
  1376. unomsg "[unoad] \0030,10 Pas de jouer - pas de gagnant - Recycling \003"
  1377. UnoCycle
  1378. }
  1379. return
  1380. }
  1381.  
  1382. #
  1383. # Move to next player
  1384. #
  1385. proc UnoNextPlayer {} {
  1386. global ThisPlayer ThisPlayerIDX RoundRobin
  1387. incr ThisPlayerIDX
  1388. if {$ThisPlayerIDX >= [llength $RoundRobin]} {set ThisPlayerIDX 0}
  1389. set ThisPlayer [lindex $RoundRobin $ThisPlayerIDX]
  1390. }
  1391.  
  1392. #
  1393. # Pick a random color for skipped/removed players
  1394. #
  1395. proc UnoPickAColor {} {
  1396. global PlayCard
  1397. set ucolors "r v b j"
  1398. set pcol [string tolower [lindex $ucolors [rand [llength $ucolors]]]]
  1399. switch $pcol {
  1400. "r" {set PlayCard "R"; return "\0030,4 Rouge \003"}
  1401. "v" {set PlayCard "V"; return "\0030,3 Vert \003"}
  1402. "b" {set PlayCard "B"; return "\0030,12 Bleu \003"}
  1403. "j" {set PlayCard "J"; return "\0031,8 Jaune \003"}
  1404. }
  1405. }
  1406.  
  1407. #
  1408. # Robot picks a color by checking hand for 1st color card
  1409. # found with matching color, else picks color at random
  1410. #
  1411. proc UnoBotPickAColor {} {
  1412. global PlayCard UnoHand ThisPlayer
  1413. set CardCount 0
  1414. while {$CardCount < [llength $UnoHand($ThisPlayer)]} {
  1415. set thiscolor [string range [lindex $UnoHand($ThisPlayer) $CardCount] 0 0]
  1416. switch $thiscolor {
  1417. "R" {set PlayCard "R"; return "\0030,4 Rouge \003"}
  1418. "V" {set PlayCard "V"; return "\0030,3 Vert \003"}
  1419. "B" {set PlayCard "B"; return "\0030,12 Bleu \003"}
  1420. "J" {set PlayCard "J"; return "\0031,8 Jaune \003"}
  1421. }
  1422. incr CardCount
  1423. }
  1424. set ucolors "r v b j"
  1425. set pcol [string tolower [lindex $ucolors [rand [llength $ucolors]]]]
  1426. switch $pcol {
  1427. "r" {set PlayCard "R"; return "\0030,4 Rouge \003"}
  1428. "v" {set PlayCard "V"; return "\0030,3 Vert \003"}
  1429. "b" {set PlayCard "B"; return "\0030,12 Bleu \003"}
  1430. "j" {set PlayCard "J"; return "\0031,8 Jaune \003"}
  1431. }
  1432. }
  1433.  
  1434. #
  1435. # Set robot for next turn
  1436. #
  1437. proc UnoRobotRestart {} {
  1438. global UnoMode ThisPlayerIDX RobotRestartPeriod UnoBotTimer
  1439. if {$UnoMode != 2} {return}
  1440. if {![uno_isrobot $ThisPlayerIDX]} {return}
  1441. set UnoBotTimer [utimer $RobotRestartPeriod UnoRobotPlayer]
  1442. }
  1443.  
  1444. #
  1445. # Reset autoskip timer
  1446. #
  1447. proc UnoAutoSkipReset {} {
  1448. global AutoSkipPeriod UnoMode UnoSkipTimer
  1449. catch {killtimer $UnoSkipTimer}
  1450. if {$UnoMode == 2} {
  1451. set UnoSkipTimer [timer $AutoSkipPeriod UnoAutoSkip]
  1452. }
  1453. }
  1454.  
  1455. #
  1456. # Channel triggers
  1457. #
  1458.  
  1459. #
  1460. # Show current player order
  1461. #
  1462. proc UnoOrder {nick uhost hand chan arg} {
  1463. global UnoChan UnoMode UnoPlayers RoundRobin
  1464. if {($chan != $UnoChan)||($UnoMode < 2)} {return}
  1465. unomsg "\0030,10 ordre des joueurs \[$UnoPlayers\]: \0030,6 $RoundRobin "
  1466. return
  1467. }
  1468.  
  1469. #
  1470. # Show game running time
  1471. #
  1472. proc UnoTime {nick uhost hand chan arg} {
  1473. global UnoChan UnoMode
  1474. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1475. set unotime "\0030,10 temp de jeux: \0030,6 [duration [game_time]] \003"
  1476. unomsg "$unotime"
  1477. return
  1478. }
  1479.  
  1480. #
  1481. # Show player what cards they hold
  1482. #
  1483. proc UnoShowCards {nick uhost hand chan arg} {
  1484. global UnoChan UnoMode UnoHand ThisPlayerIDX
  1485. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1486. if [info exist UnoHand($nick)] {
  1487. set Card ""
  1488. set ccnt 0
  1489. while {[llength $UnoHand($nick)] != $ccnt} {
  1490. set pcard [lindex $UnoHand($nick) $ccnt]
  1491. append Card [CardColor $pcard]
  1492. incr ccnt
  1493. }
  1494. if {![uno_isrobot $ThisPlayerIDX]} {
  1495. unontc $nick "votre main: $Card\003"
  1496. }
  1497. }
  1498. return
  1499. }
  1500.  
  1501. #
  1502. # Show current player
  1503. #
  1504. proc UnoTurn {nick uhost hand chan arg} {
  1505. global UnoChan UnoMode ThisPlayer RoundRobin UnoMode
  1506. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1507. if {[llength $RoundRobin] < 1 } {return}
  1508. set info "\0030,10 Joueur actuel: \0030,6 $ThisPlayer \003"
  1509. unomsg "$info"
  1510. return
  1511. }
  1512.  
  1513. #
  1514. # Show current top card
  1515. #
  1516. proc UnoTopCard {nick uhost hand chan arg} {
  1517. global PlayCard UnoChan UnoMode
  1518. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1519. set pcard $PlayCard
  1520. set Card [CardColor $pcard]
  1521. unomsg "\0030,10 Carte jouer: \003 $Card \003"
  1522. return
  1523. }
  1524.  
  1525. #
  1526. # Show card stats
  1527. #
  1528. proc UnoCardStats {nick uhost hand chan arg} {
  1529. global UnoChan UnoMode CardStats
  1530. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1531. set passdraw [format "%3.1f" [get_ratio $CardStats(passed) $CardStats(drawn)]]
  1532. set skiprev [expr $CardStats(skips) +$CardStats(revs)]
  1533. unomsg "\0030,10 Stats des Cartes : \0030,6 jouer:$CardStats(played) Pass\/Draw Ratio:$passdraw\% Skip\/Rev:$skiprev DrawCards:$CardStats(draws) WildCards:$CardStats(wilds) \003"
  1534. return
  1535. }
  1536.  
  1537. #
  1538. # Card count
  1539. #
  1540. proc UnoCount {nick uhost hand chan arg} {
  1541. global RoundRobin UnoHand UnoMode UnoChan
  1542. if {($chan != $UnoChan)||($UnoMode != 2)} {return}
  1543. set ordcnt 0
  1544. set crdcnt ""
  1545. while {[lindex $RoundRobin $ordcnt] != ""} {
  1546. append crdcnt "\0030,10 [lindex $RoundRobin $ordcnt] \0030,6 [llength $UnoHand([lindex $RoundRobin $ordcnt])] Carte "
  1547. incr ordcnt
  1548. }
  1549. unomsg "$crdcnt\003"
  1550. return
  1551. }
  1552.  
  1553. #
  1554. # Show player's score
  1555. #
  1556. proc UnoWon {nick uhost hand chan arg} {
  1557. global UnoScoreFile UnoPointsName
  1558.  
  1559. regsub -all \[`,.!] $arg "" arg
  1560.  
  1561. if {[string length $arg] == 0} {set arg $nick}
  1562.  
  1563. set scorer [string tolower $arg]
  1564.  
  1565. set pflag 0
  1566.  
  1567. set f [open $UnoScoreFile r]
  1568. while {[gets $f sc] != -1} {
  1569. set cnick [string tolower [lindex [split $sc] 0]]
  1570. if {$cnick == $scorer} {
  1571. set pmsg "\0030,10 [lindex [split $sc] 0] \0030,6 [lindex $sc 2] $UnoPointsName in [lindex $sc 1] Games \003"
  1572. set pflag 1
  1573. }
  1574. }
  1575. close $f
  1576.  
  1577. if {$pflag == 0} {
  1578. set pmsg "\0030,10 $arg \0030,6 Pas de score \003"
  1579. }
  1580. unomsg "$pmsg"
  1581. return
  1582. }
  1583.  
  1584. #
  1585. # Display current top10
  1586. #
  1587. proc UnoTopTen {nick uhost hand chan arg} {
  1588. global UnoChan
  1589. if {$chan != $UnoChan} {return}
  1590. UnoTop10 1
  1591. return
  1592. }
  1593. proc UnoTopTenWon {nick uhost hand chan arg} {
  1594. global UnoChan
  1595. if {$chan != $UnoChan} {return}
  1596. UnoTop10 0
  1597. return
  1598. }
  1599.  
  1600. #
  1601. # Display last month's top3
  1602. #
  1603. proc UnoTopThreeLast {nick uhost hand chan arg} {
  1604. global UnoChan
  1605. if {$chan != $UnoChan} {return}
  1606. UnoLastMonthTop3 $nick $uhost $hand $chan 0
  1607. unomsg " "
  1608. UnoLastMonthTop3 $nick $uhost $hand $chan 1
  1609. return
  1610. }
  1611.  
  1612. #
  1613. # Display month fastest game
  1614. #
  1615. proc UnoTopFast {nick uhost hand chan arg} {
  1616. global UnoChan UnoFast
  1617. if {$chan != $UnoChan} {return}
  1618. unomsg "\0030,6 le plus rapide du jeu de ce mois-ci \0030,10 [lindex [split $UnoFast] 0] [duration [lindex $UnoFast 1]] \003"
  1619. return
  1620. }
  1621.  
  1622. #
  1623. # Display month high score
  1624. #
  1625. proc UnoHighScore {nick uhost hand chan arg} {
  1626. global UnoChan UnoHigh UnoPointsName
  1627. if {$chan != $UnoChan} {return}
  1628. unomsg "\0030,6 Le plus grand Score de Ce mois-ci \0030,10 [lindex [split $UnoHigh] 0] [lindex $UnoHigh 1] $UnoPointsName \003"
  1629. return
  1630. }
  1631.  
  1632. #
  1633. # Display month most cards played
  1634. #
  1635. proc UnoPlayed {nick uhost hand chan arg} {
  1636. global UnoChan UnoPlayed
  1637. if {$chan != $UnoChan} {return}
  1638. unomsg "\0030,6 Le plus grand nombres de cartes joué Ce mois-ci \0030,10 [lindex [split $UnoPlayed] 0] [lindex $UnoPlayed 1] Cards \003"
  1639. return
  1640. }
  1641.  
  1642. #
  1643. # Show all-time records
  1644. #
  1645. proc UnoRecords {nick uhost hand chan arg} {
  1646. global UnoChan UnoRecordFast UnoRecordHigh UnoRecordCard UnoRecordWins UnoRecordPlayed
  1647. if {$chan != $UnoChan} {return}
  1648. unomsg "\0030,6 Tout-les Records: Points \0030,10 $UnoRecordCard \0030,6 Jeux \0030,10 $UnoRecordWins \0030,6 rapidité \0030,10 [lindex $UnoRecordFast 0] [duration [lindex $UnoRecordFast 1]] \0030,6 High Score \0030,10 $UnoRecordHigh \0030,6 Cartes jouer \0030,10 $UnoRecordPlayed \003"
  1649. return
  1650. }
  1651.  
  1652. #
  1653. # Display month top10
  1654. #
  1655. proc UnoTop10 {mode} {
  1656. global UnoScoreFile unsortedscores UnoPointsName UnoRobot
  1657.  
  1658. if {($mode < 0)||($mode > 1)} {set mode 0}
  1659.  
  1660. switch $mode {
  1661. 0 {set winners "\0030,6 Top10 des jeux gagner "}
  1662. 1 {set winners "\0030,6 Top10 $UnoPointsName "}
  1663. }
  1664.  
  1665.  
  1666. if ![file exists $UnoScoreFile] {
  1667. set f [open $UnoScoreFile w]
  1668. puts $f "$UnoRobot 0 0"
  1669. unomsg "\0030,10 Le dossier de Score est vide - Création d'un nouveau One\003"
  1670. close $f
  1671. return
  1672. }
  1673.  
  1674. if [info exists unsortedscores] {unset unsortedscores}
  1675. if [info exists top10] {unset top10}
  1676.  
  1677. set f [open $UnoScoreFile r]
  1678. while {[gets $f s] != -1} {
  1679. switch $mode {
  1680. 0 {set unsortedscores([lindex [split $s] 0]) [lindex $s 1]}
  1681. 1 {set unsortedscores([lindex [split $s] 0]) [lindex $s 2]}
  1682. }
  1683. }
  1684. close $f
  1685.  
  1686. for {set s 0} {$s < 10} {incr s} {
  1687. set top10($s) "Nobody 0"
  1688. }
  1689.  
  1690. set s 0
  1691. foreach n [lsort -decreasing -command UnoSortScores [array names unsortedscores]] {
  1692. set top10($s) "$n $unsortedscores($n)"
  1693. incr s
  1694. }
  1695.  
  1696. for {set s 0} {$s < 10} {incr s} {
  1697. if {[lindex $top10($s) 1] > 0} {
  1698. append winners "\0030,6 #[expr $s +1] \0030,10 [lindex [split $top10($s)] 0] [lindex $top10($s) 1] "
  1699. } {
  1700. append winners "\0030,6 #[expr $s +1] \0030,10 Nobody 0 "
  1701. }
  1702. }
  1703. unomsg "$winners\003"
  1704. return
  1705. }
  1706.  
  1707. #
  1708. # Last month's top3
  1709. #
  1710. proc UnoLastMonthTop3 {nick uhost hand chan arg} {
  1711. global UnoChan UnoLastMonthCards UnoLastMonthGames UnoPointsName
  1712. if {$chan != $UnoChan} {return}
  1713. if {$arg == 0} {
  1714. if [info exists UnoLastMonthCards] {
  1715. set UnoTop3 "\0030,6 Le Top 3 du mois $UnoPointsName jeux "
  1716. for { set s 0} { $s < 3 } { incr s} {
  1717. append UnoTop3 "\0030,6 #[expr $s +1] \0030,10 $UnoLastMonthCards($s) "
  1718. }
  1719. unomsg "$UnoTop3"
  1720. }
  1721. } {
  1722. if [info exists UnoLastMonthGames] {
  1723. set UnoTop3 "\0030,6 Le Top 3 des Jeux Gagné ce mois ci "
  1724. for { set s 0} { $s < 3 } { incr s} {
  1725. append UnoTop3 "\0030,6 #[expr $s +1] \0030,10 $UnoLastMonthGames($s) "
  1726. }
  1727. unomsg "$UnoTop3"
  1728. }
  1729. }
  1730. }
  1731.  
  1732. #
  1733. # Show game help
  1734. #
  1735. proc UnoCmds {nick uhost hand chan arg} {
  1736. global UnoChan
  1737. if {$chan != $UnoChan} {return}
  1738. unontc $nick "Uno Commandes: !uno !stop !remove \[nick\] !unowon \[nick\] !unocmds"
  1739. unontc $nick "Uno Stats: !top10 !top3last !fast !high !records"
  1740. unontc $nick "Uno Chan Commandes: ca=cartes, cd=card, tu=tourner, od=ordre, ct=compteur, st=stats, tps=time"
  1741. unontc $nick "Uno Card Commands: !go ou !zou=joindre la partie, !j=jouer une carte, !pioche=tirer une carte, !passe=pass, !c=couleur"
  1742. unontc $nick "Uno \00301--------------------\003LES CARTES"
  1743. unontc $nick "Uno couleur des cartes \00301,12b=bleu\003 \00301---\00301,4r=rouge\003 \00301---\00301,3v=vert\003 \00301---\00301,8j=jaune.."
  1744. unontc $nick "Uno exemples \00301------------\00304pl j1 = jouer la carte \00301,8jaune N°1\003 \00304 .. pl r8 = jouer la carte \00301,4rouge N°8"
  1745. unontc $nick "Uno jouer \00301------------------\00304C = \0031,8 \002C\0031,3o\0031,4u\0031,12l\0031,7e\0031,8u\0031,9r\002 \003 changer de couleur co = choix de la couleur"
  1746. unontc $nick "Uno jouer \00301------------------\00304CTQ = \0031,8 \002T\0031,3I \0031,4R\0030,12E \0031,8Q\0031,3U\0031,4A\0031,12T\0031,8R\0031,3E \0031,8C\0031,3a\0031,4r\0031,12t\0031,12e\002 \003 faire tirer quatre cartes .. "
  1747. unontc $nick "Uno jouer \00301------------------\00304B,R,J ou VP ou b,r,j ou vP \00301,3 Pass\003=passer le tour du joueur"
  1748. unontc $nick "Uno jouer \00301------------------\00304B,R,J ou VR ou b,r,j ou vR \00301,3 Sens inverse\003 =changer de sens"
  1749. unontc $nick "Uno jouer \00301------------------\00304B,R,J ou VTD ou b,r,j ou VTD \00301,3 Tire deux\003 = faire tirer deux cartes"
  1750.  
  1751. return
  1752. }
  1753.  
  1754. #
  1755. # Uno version
  1756. #
  1757. proc UnoVersion {nick uhost hand chan arg} {
  1758. global UnoVersion
  1759. unomsg "[unoad]\003 \0030,6 v$UnoVersion \003"
  1760. return
  1761. }
  1762.  
  1763. #
  1764. # Read score file
  1765. #
  1766. proc UnoReadScores {} {
  1767. global unogameswon unoptswon UnoScoreFile UnoRobot
  1768.  
  1769. if [info exists unogameswon] { unset unogameswon }
  1770. if [info exists unoptswon] { unset unoptswon }
  1771.  
  1772. if ![file exists $UnoScoreFile] {
  1773. set f [open $UnoScoreFile w]
  1774. puts $f "$UnoRobot 0 0"
  1775. close $f
  1776. }
  1777.  
  1778. set f [open $UnoScoreFile r]
  1779. while {[gets $f s] != -1} {
  1780. set unogameswon([lindex [split $s] 0]) [lindex $s 1]
  1781. set unoptswon([lindex [split $s] 0]) [lindex $s 2]
  1782. }
  1783. close $f
  1784.  
  1785. return
  1786. }
  1787.  
  1788. #
  1789. # Clear top10 and write monthly scores
  1790. #
  1791. proc UnoNewMonth {min hour day month year} {
  1792. global unsortedscores unogameswon unoptswon UnoLastMonthCards UnoLastMonthGames UnoScoreFile UnoRobot
  1793. global UnoFast UnoHigh UnoPlayed UnoRecordFast UnoRecordHigh UnoRecordPlayed UnoRecordCard UnoRecordWins
  1794.  
  1795. set lmonth [UnoLastMonthName $month]
  1796.  
  1797. unomsg "[unoad] \0030,4 mise a jour des scores mensuel \003"
  1798.  
  1799. set UnoMonthFileName "$UnoScoreFile.$lmonth"
  1800.  
  1801. # Read Current Scores
  1802.  
  1803. UnoReadScores
  1804.  
  1805. # Write To Old Month File
  1806.  
  1807. if ![file exists $UnoMonthFileName] {
  1808. set f [open $UnoMonthFileName w]
  1809. foreach n [array names unogameswon] {
  1810. puts $f "$n $unogameswon($n) $unoptswon($n)"
  1811. }
  1812. close $f
  1813. }
  1814.  
  1815. # Find Top 3 Card Holders and Game Winners
  1816.  
  1817. set mode 0
  1818.  
  1819. while {$mode < 2} {
  1820. if [info exists unsortedscores] {unset unsortedscores}
  1821. if [info exists top10] {unset top10}
  1822.  
  1823. set f [open $UnoScoreFile r]
  1824. while {[gets $f s] != -1} {
  1825. switch $mode {
  1826. 0 {set unsortedscores([lindex [split $s] 0]) [lindex $s 1]}
  1827. 1 {set unsortedscores([lindex [split $s] 0]) [lindex $s 2]}
  1828. }
  1829. }
  1830. close $f
  1831.  
  1832. set s 0
  1833. foreach n [lsort -decreasing -command UnoSortScores [array names unsortedscores]] {
  1834. set top10($s) "$n $unsortedscores($n)"
  1835. incr s
  1836. }
  1837.  
  1838. for {set s 0} {$s < 3} {incr s} {
  1839. if {[lindex $top10($s) 1] > 0} {
  1840. switch $mode {
  1841. 0 {set UnoLastMonthGames($s) "[lindex [split $top10($s)] 0] [lindex $top10($s) 1]"}
  1842. 1 {set UnoLastMonthCards($s) "[lindex [split $top10($s)] 0] [lindex $top10($s) 1]"}
  1843. }
  1844. } {
  1845. switch $mode {
  1846. 0 {set UnoLastMonthGames($s) "Nobody 0"}
  1847. 1 {set UnoLastMonthCards($s) "Nobody 0"}
  1848. }
  1849. }
  1850. }
  1851. incr mode
  1852. }
  1853.  
  1854. # Update records
  1855. if {[lindex $UnoFast 1] < [lindex $UnoRecordFast 1]} {set UnoRecordFast $UnoFast}
  1856. if {[lindex $UnoHigh 1] > [lindex $UnoRecordHigh 1]} {set UnoRecordHigh $UnoHigh}
  1857. if {[lindex $UnoPlayed 1] > [lindex $UnoRecordPlayed 1]} {set UnoRecordPlayed $UnoPlayed}
  1858. if {[lindex $UnoLastMonthCards(0) 1] > [lindex $UnoRecordCard 1]} {set UnoRecordCard $UnoLastMonthCards(0)}
  1859. if {[lindex $UnoLastMonthGames(0) 1] > [lindex $UnoRecordWins 1]} {set UnoRecordWins $UnoLastMonthGames(0)}
  1860.  
  1861. # Wipe last months records
  1862. set UnoFast "$UnoRobot 60"
  1863. set UnoHigh "$UnoRobot 100"
  1864. set UnoPlayed "$UnoRobot 100"
  1865.  
  1866. # Save Top3 And Records To Config File
  1867. Uno_WriteCFG
  1868.  
  1869. # Wipe This Months Score File
  1870.  
  1871. set f [open $UnoScoreFile w]
  1872. puts $f "$UnoRobot 0 0"
  1873. close $f
  1874.  
  1875. unolog "uno" "mise a jour des scores mensuel"
  1876. return
  1877. }
  1878.  
  1879. #
  1880. # Update score of winning player
  1881. #
  1882. proc UnoUpdateScore {winner cardtotals} {
  1883. global unogameswon unoptswon UnoScoreFile
  1884.  
  1885. UnoReadScores
  1886.  
  1887. if {[info exists unogameswon($winner)]} {
  1888. incr unogameswon($winner)
  1889. } {
  1890. set unogameswon($winner) 1
  1891. }
  1892.  
  1893. if {[info exists unoptswon($winner)]} {
  1894. incr unoptswon($winner) $cardtotals
  1895. } {
  1896. set unoptswon($winner) $cardtotals
  1897. }
  1898.  
  1899. set f [open $UnoScoreFile w]
  1900. foreach n [array names unogameswon] {
  1901. puts $f "$n $unogameswon($n) $unoptswon($n)"
  1902. }
  1903. close $f
  1904.  
  1905. return
  1906. }
  1907.  
  1908. #
  1909. # Display winner and game statistics
  1910. #
  1911. proc UnoWin {winner} {
  1912. global UnoHand ThisPlayer RoundRobin UnoPointsName CardStats UnoMode UnoCycleTime UnoFast UnoHigh UnoPlayed UnoBonus
  1913.  
  1914. set cardtotals 0
  1915. set UnoMode 3
  1916. set ThisPlayerIDX 0
  1917. set needCFGWrite 0
  1918.  
  1919. set UnoTime [game_time]
  1920.  
  1921. unomsg "\0030,6 Total des cartes \003"
  1922.  
  1923. # Total up all player's cards
  1924.  
  1925. while {$ThisPlayerIDX != [llength $RoundRobin]} {
  1926. set Card ""
  1927. set ThisPlayer [lindex $RoundRobin $ThisPlayerIDX]
  1928.  
  1929. if {$ThisPlayer != $winner} {
  1930. set ccount 0
  1931. while {[lindex $UnoHand($ThisPlayer) $ccount] != ""} {
  1932. set cardtotal [lindex $UnoHand($ThisPlayer) $ccount]
  1933. set c1 [string range $cardtotal 0 0]
  1934. set c2 [string range $cardtotal 1 1]
  1935. set cardtotal 0
  1936.  
  1937. if {$c1 == "C"} {
  1938. set cardtotal 50
  1939. } {
  1940. switch $c2 {
  1941. "P" {set cardtotal 20}
  1942. "R" {set cardtotal 20}
  1943. "T" {set cardtotal 20}
  1944. default {set cardtotal $c2}
  1945. }
  1946. }
  1947. set cardtotals [expr $cardtotals + $cardtotal]
  1948. incr ccount
  1949. }
  1950. set Card [CardColorAll $ThisPlayer]
  1951. unomsg "[strpad [nikclr $ThisPlayer] 12] $Card"
  1952. }
  1953. incr ThisPlayerIDX
  1954. }
  1955.  
  1956. # Check high score record
  1957. set HighScore [lindex $UnoHigh 1]
  1958. if {$cardtotals > $HighScore} {
  1959. unomsg "\0030,4 $winner Vien de battre le record $UnoBonus Bonus $UnoPointsName \003"
  1960. set UnoHigh "$winner $cardtotals"
  1961. incr cardtotals $UnoBonus
  1962. set needCFGWrite 1
  1963. }
  1964. # Check played cards record
  1965. set HighPlayed [lindex $UnoPlayed 1]
  1966. if {$CardStats(played) > $HighPlayed} {
  1967. unomsg "\0030,4 $winner Vien de battre le record du nombres de cartes jouer $UnoBonus Bonus $UnoPointsName \003"
  1968. set UnoPlayed "$winner $CardStats(played)"
  1969. incr cardtotals $UnoBonus
  1970. set needCFGWrite 1
  1971. }
  1972. # Check fast game record
  1973. set FastRecord [lindex $UnoFast 1]
  1974. if {$UnoTime < $FastRecord} {
  1975. unomsg "\0030,4 $winner Vien de battre le record de rapidité $UnoBonus Bonus $UnoPointsName \003"
  1976. incr cardtotals $UnoBonus
  1977. set UnoFast "$winner $UnoTime"
  1978. set needCFGWrite 1
  1979. }
  1980.  
  1981. # Winner
  1982. unomsg "\0030,10 $winner \0030,6 $cardtotals $UnoPointsName en [duration $UnoTime] \003"
  1983.  
  1984. # Card stats
  1985. set passdraw [format "%3.1f" [get_ratio $CardStats(passed) $CardStats(drawn)]]
  1986. set skiprev [expr $CardStats(skips) +$CardStats(revs)]
  1987. unomsg "\0030,10 Cardstats \0030,6 jouer:$CardStats(played) Pass\/Draw Ratio:$passdraw\% Skip\/Rev:$skiprev DrawCards:$CardStats(draws) WildCards:$CardStats(wilds) \003"
  1988. unomsg "[unoad] \0030,3 Jeux suivant dans $UnoCycleTime Secondes \003"
  1989.  
  1990. # Write scores
  1991. UnoUpdateScore $winner $cardtotals
  1992.  
  1993. # Write records
  1994. if {$needCFGWrite > 0} {Uno_WriteCFG}
  1995.  
  1996. return
  1997. }
  1998.  
  1999. #
  2000. # Re-Shuffle deck
  2001. #
  2002. proc UnoShuffle {len} {
  2003. global UnoDeck DiscardPile
  2004. if {[llength $UnoDeck] >= $len} { return }
  2005. unomsg "[unoad] \0030,4 Re-Shuffling Uno Deck \003"
  2006. lappend DiscardPile "$UnoDeck"
  2007. set UnoDeck ""
  2008. set NewDeckSize [llength $DiscardPile]
  2009. while {[llength $UnoDeck] != $NewDeckSize} {
  2010. set pcardnum [rand [llength $DiscardPile]]
  2011. set pcard [lindex $DiscardPile $pcardnum]
  2012. lappend UnoDeck "$pcard"
  2013. set DiscardPile [lreplace ${DiscardPile} $pcardnum $pcardnum]
  2014. }
  2015. return
  2016. }
  2017.  
  2018. #
  2019. # Read config file
  2020. #
  2021. proc Uno_ReadCFG {} {
  2022. global UnoCFGFile UnoLastMonthCards UnoLastMonthGames UnoPointsName UnoScoreFile UnoRobot UnoChan UnoFast UnoHigh UnoPlayed UnoStopAfter UnoBonus
  2023. global UnoRecordHigh UnoRecordFast UnoRecordCard UnoRecordWins UnoRecordPlayed UnoWildDrawTwos
  2024. if {[file exist $UnoCFGFile]} {
  2025. set f [open $UnoCFGFile r]
  2026. while {[gets $f s] != -1} {
  2027. set kkey [string tolower [lindex [split $s "="] 0]]
  2028. set kval [lindex [split $s "="] 1]
  2029. switch $kkey {
  2030. botname {set UnoRobot $kval}
  2031. channel {set UnoChan $kval}
  2032. points {set UnoPointsName $kval}
  2033. scorefile {set UnoScoreFile $kval}
  2034. stopafter {set UnoStopAfter $kval}
  2035. wilddrawtwos {set UnoWildDrawTwos $kval}
  2036. lastmonthcard1 {set UnoLastMonthCards(0) $kval}
  2037. lastmonthcard2 {set UnoLastMonthCards(1) $kval}
  2038. lastmonthcard3 {set UnoLastMonthCards(2) $kval}
  2039. lastmonthwins1 {set UnoLastMonthGames(0) $kval}
  2040. lastmonthwins2 {set UnoLastMonthGames(1) $kval}
  2041. lastmonthwins3 {set UnoLastMonthGames(2) $kval}
  2042. fast {set UnoFast $kval}
  2043. high {set UnoHigh $kval}
  2044. played {set UnoPlayed $kval}
  2045. bonus {set UnoBonus $kval}
  2046. recordhigh {set UnoRecordHigh $kval}
  2047. recordfast {set UnoRecordFast $kval}
  2048. recordcard {set UnoRecordCard $kval}
  2049. recordwins {set UnoRecordWins $kval}
  2050. recordplayed {set UnoRecordPlayed $kval}
  2051. }
  2052. }
  2053. close $f
  2054. if {$UnoStopAfter < 0} {set UnoStopAfter 0}
  2055. if {$UnoBonus < 0} {set UnoBonus 1000}
  2056. if {($UnoWildDrawTwos < 0)||($UnoWildDrawTwos > 1)} {set UnoWildDrawTwos 0}
  2057. return
  2058. }
  2059. putcmdlog "\[Uno\] Config file $UnoCFGFile pas trouvé ... sauver par défaut"
  2060. Uno_WriteCFG
  2061. return
  2062. }
  2063.  
  2064. #
  2065. # Write config file
  2066. #
  2067. proc Uno_WriteCFG {} {
  2068. global UnoCFGFile UnoLastMonthCards UnoLastMonthGames UnoPointsName UnoScoreFile UnoRobot UnoChan UnoFast UnoHigh UnoPlayed UnoStopAfter UnoBonus
  2069. global UnoRecordHigh UnoRecordFast UnoRecordCard UnoRecordWins UnoRecordPlayed UnoWildDrawTwos
  2070. set f [open $UnoCFGFile w]
  2071. puts $f "# Ce fichier est automatiquement écrasé"
  2072. puts $f "BotName=$UnoRobot"
  2073. puts $f "Channel=$UnoChan"
  2074. puts $f "Points=$UnoPointsName"
  2075. puts $f "ScoreFile=$UnoScoreFile"
  2076. puts $f "StopAfter=$UnoStopAfter"
  2077. puts $f "WildDrawTwos=$UnoWildDrawTwos"
  2078. puts $f "LastMonthCard1=$UnoLastMonthCards(0)"
  2079. puts $f "LastMonthCard2=$UnoLastMonthCards(1)"
  2080. puts $f "LastMonthCard3=$UnoLastMonthCards(2)"
  2081. puts $f "LastMonthWins1=$UnoLastMonthGames(0)"
  2082. puts $f "LastMonthWins2=$UnoLastMonthGames(1)"
  2083. puts $f "LastMonthWins3=$UnoLastMonthGames(2)"
  2084. puts $f "Fast=$UnoFast"
  2085. puts $f "High=$UnoHigh"
  2086. puts $f "Played=$UnoPlayed"
  2087. puts $f "Bonus=$UnoBonus"
  2088. puts $f "RecordHigh=$UnoRecordHigh"
  2089. puts $f "RecordFast=$UnoRecordFast"
  2090. puts $f "RecordCard=$UnoRecordCard"
  2091. puts $f "RecordWins=$UnoRecordWins"
  2092. puts $f "RecordPlayed=$UnoRecordPlayed"
  2093. close $f
  2094. return
  2095. }
  2096.  
  2097. #
  2098. # Score advertiser
  2099. #
  2100. proc UnoScoreAdvertise {} {
  2101. global UnoChan UnoAdNumber UnoRobot
  2102. unomsg " "
  2103. switch $UnoAdNumber {
  2104. 0 {UnoTop10 0}
  2105. 1 {UnoLastMonthTop3 $UnoRobot none none $UnoChan 0}
  2106. 2 {UnoTop10 1}
  2107. 3 {UnoRecords $UnoRobot none none $UnoChan ""}
  2108. 4 {UnoPlayed $UnoRobot none none $UnoChan ""}
  2109. 5 {UnoHighScore $UnoRobot none none $UnoChan ""}
  2110. 6 {UnoTopFast $UnoRobot none none $UnoChan ""}
  2111. }
  2112. incr UnoAdNumber
  2113. if {$UnoAdNumber > 6} {set UnoAdNumber 0}
  2114. return
  2115. }
  2116.  
  2117. #
  2118. # Color all cards in hand
  2119. #
  2120. proc CardColorAll {cplayer} {
  2121. global UnoHand
  2122. set pCard ""
  2123. set ccount 0
  2124. while {[llength $UnoHand($cplayer)] != $ccount} {
  2125. append pCard [CardColor [lindex $UnoHand($cplayer) $ccount]]
  2126. incr ccount
  2127. }
  2128. return $pCard
  2129. }
  2130.  
  2131. #
  2132. # Color a single card
  2133. #
  2134. proc CardColor {pcard} {
  2135. set cCard ""
  2136. set c2 [string range $pcard 1 1]
  2137. switch [string range $pcard 0 0] {
  2138. "C" {
  2139. if {$c2 == "T"} {
  2140. append cCard "[wildf]"
  2141. } {
  2142. append cCard "[wild]"
  2143. }
  2144. return $cCard
  2145. }
  2146. "J" {append cCard " \0031,8 Jaune "}
  2147. "R" {append cCard " \0030,4 Rouge "}
  2148. "V" {append cCard " \0030,3 Vert "}
  2149. "B" {append cCard " \0030,12 Bleu "}
  2150. }
  2151. switch $c2 {
  2152. "P" {append cCard "\002Pass\002 \003 "}
  2153. "R" {append cCard "\002Sens inverse\002 \003 "}
  2154. "T" {append cCard "\002Tire deux\002 \003 "}
  2155. default {append cCard "$c2 \003 "}
  2156. }
  2157. return $cCard
  2158. }
  2159.  
  2160. #
  2161. # Check if player has Uno
  2162. #
  2163. proc check_hasuno {cplayer} {
  2164. global UnoHand
  2165. if {[llength $UnoHand($cplayer)] > 1} {return}
  2166. hasuno $cplayer
  2167. return
  2168. }
  2169.  
  2170. #
  2171. # Check for winner
  2172. #
  2173. proc check_unowin {cplayer ccard} {
  2174. global UnoHand
  2175. if {[llength $UnoHand($cplayer)] > 0} {return 0}
  2176. return 1
  2177. }
  2178.  
  2179. #
  2180. # Show player what cards they have
  2181. #
  2182. proc showcards {idx pcards} {
  2183. global UnoIDX
  2184. if {[uno_isrobot $idx]} {return}
  2185. unontc [lindex $UnoIDX $idx] "main: $pcards"
  2186. }
  2187.  
  2188. #
  2189. # Check if this is the robot player
  2190. #
  2191. proc uno_isrobot {cplayerIDX} {
  2192. global RoundRobin UnoRobot UnoMaxNickLen
  2193. if {[string range [lindex $RoundRobin $cplayerIDX] 0 $UnoMaxNickLen] != $UnoRobot} {return 0}
  2194. return 1
  2195. }
  2196.  
  2197. # Show played card
  2198. proc playcard {who crd nplayer} {
  2199. unomsg "[nikclr $who]\003 joue $crd \003a [nikclr $nplayer]\003"
  2200. }
  2201.  
  2202. # Show played draw card
  2203. proc playdraw {who crd dplayer nplayer} {
  2204. unomsg "[nikclr $who]\003 joue $crd [nikclr $dplayer]\003 tire \002deux cartes\002 et passe son tour - le joueur suivant est: [nikclr $nplayer]\003"
  2205. }
  2206.  
  2207. # Show played wildcard
  2208. proc playwild {who chooser} {
  2209. unomsg "[nikclr $who]\003 joue [wild] et choisi une couleur [nikclr $chooser]\003"
  2210. }
  2211.  
  2212. # Show played wild draw four
  2213. proc playwildfour {who skipper chooser} {
  2214. unomsg "[nikclr $who]\003 joue [wildf] [nikclr $skipper]\003 tire \002quatres cartes\002 et passe son tour - Choisissez une couleur [nikclr $chooser]\003"
  2215. }
  2216.  
  2217. # Show played skip card
  2218. proc playskip {who crd skipper nplayer} {
  2219. unomsg "[nikclr $who]\003 joue $crd\003 et fait passé le tour de [nikclr $skipper]\003 a [nikclr $nplayer]\003"
  2220. }
  2221.  
  2222. proc showwhodrew {who} {
  2223. unomsg "[nikclr $who]\003 \002tire\002 une cartes"
  2224. }
  2225.  
  2226. proc playpass {who nplayer} {
  2227. unomsg "[nikclr $who]\003 \002passes\002 a [nikclr $nplayer]\003"
  2228. }
  2229.  
  2230. proc botplaywild {who chooser ncolr nplayer} {
  2231. unomsg "[nikclr $who]\003 joue [wild] et choisi $ncolr \003 encore a: [nikclr $nplayer] de joué\003"
  2232. }
  2233.  
  2234. # Show played wild draw four
  2235. proc botplaywildfour {who skipper chooser choice nplayer} {
  2236. unomsg "[nikclr $who]\003 joue [wildf] [nikclr $skipper]\003 tire \002quatres cartes\002 et passe son tour. [nikclr $chooser]\003 choisit $choice\003 encore a: [nikclr $nplayer] de joué\003"
  2237. }
  2238.  
  2239. # Show a player what they drew
  2240. proc showdraw {idx crd} {
  2241. global UnoIDX
  2242. if {[uno_isrobot $idx]} {return}
  2243. unontc [lindex $UnoIDX $idx] "Tire: $crd"
  2244. }
  2245.  
  2246. # Show Win
  2247. proc showwin {who crd} {
  2248. unomsg "[nikclr $who]\003 joue $crd \003et \002\00309G\00312a\00313g\00308n\00307e\002 \00304cette parti de [unoad]\003"
  2249. }
  2250.  
  2251. # Show Win by default
  2252. proc showwindefault {who} {
  2253. unomsg "[nikclr $who] \002\00309G\00312a\00313g\00308n\00307e [unoad]\002\003 par Default \003"
  2254. }
  2255.  
  2256. # Player Has Uno
  2257. proc hasuno {who} {
  2258. global UnoChan
  2259. putquick "PRIVMSG $UnoChan :\001ACTION dit [nikclr $who] \002\00309A\00312n\00313n\00308o\00307n\00304c\00309e \00309U\00312n\00313o\00308! \002\003\001"
  2260. }
  2261.  
  2262. #
  2263. # Utility Functions
  2264. #
  2265.  
  2266. # Check if a timer exists
  2267. proc unotimerexists {cmd} {
  2268. foreach i [timers] {
  2269. if {![string compare $cmd [lindex $i 1]]} then {
  2270. return [lindex $i 2]
  2271. }
  2272. }
  2273. return
  2274. }
  2275.  
  2276. # Sort Scores
  2277. proc UnoSortScores {s1 s2} {
  2278. global unsortedscores
  2279. if {$unsortedscores($s1) > $unsortedscores($s2)} {return 1}
  2280. if {$unsortedscores($s1) < $unsortedscores($s2)} {return -1}
  2281. if {$unsortedscores($s1) == $unsortedscores($s2)} {return 0}
  2282. }
  2283.  
  2284. # Calculate Game Running Time
  2285. proc game_time {} {
  2286. global UnoStartTime
  2287. set UnoCurrentTime [unixtime]
  2288. set gt [expr ($UnoCurrentTime - $UnoStartTime)]
  2289. return $gt
  2290. }
  2291.  
  2292. # Colorize Nickname
  2293. proc nikclr {nick} {
  2294. global NickColor
  2295. return "\003$NickColor($nick)$nick"
  2296. }
  2297. proc colornick {pnum} {
  2298. global UnoNickColour
  2299. set c [lindex $UnoNickColour [expr $pnum-1]]
  2300. set nik [format "%02d" $c]
  2301. return $nik
  2302. }
  2303.  
  2304. # Ratio Of Two Numbers
  2305. proc get_ratio {num den} {
  2306. set n 0.0
  2307. set d 0.0
  2308. set n [expr $n +$num]
  2309. set d [expr $d +$den]
  2310. if {$d == 0} {return 0}
  2311. set ratio [expr (($n /$d) *100.0)]
  2312. return $ratio
  2313. }
  2314.  
  2315. # Name Of Last Month
  2316. proc UnoLastMonthName {month} {
  2317. switch $month {
  2318. 00 {return "Dec"}
  2319. 01 {return "Jan"}
  2320. 02 {return "Feb"}
  2321. 03 {return "Mar"}
  2322. 04 {return "Apr"}
  2323. 05 {return "May"}
  2324. 06 {return "Jun"}
  2325. 07 {return "Jul"}
  2326. 08 {return "Aug"}
  2327. 09 {return "Sep"}
  2328. 10 {return "Oct"}
  2329. 11 {return "Nov"}
  2330. default {return "???"}
  2331. }
  2332. }
  2333.  
  2334. # String Pad
  2335. proc strpad {str len} {
  2336. set slen [string length $str]
  2337. if {$slen > $len} {return $str}
  2338. while {$slen < $len} {
  2339. append str " "
  2340. incr slen
  2341. }
  2342. return $str
  2343. }
  2344.  
  2345. # Uno!
  2346. proc unoad {} {
  2347. return "\002\0033U\00312N\00313O\00308!\002"
  2348. }
  2349.  
  2350. # Wild Card
  2351. proc wild {} {
  2352. return " \0031,8 \002C\0031,3o\0031,4u\0031,12l\0031,7e\0031,8u\0031,9r\002 \003 "
  2353. }
  2354.  
  2355. # Wild Draw Four Card
  2356. proc wildf {} {
  2357. return " \0031,8 \002T\0031,3I \0031,4R\0030,12E \0031,8Q\0031,3U\0031,4A\0031,12T\0031,8R\0031,3E \0031,8C\0031,3a\0031,4r\0031,12t\0031,12e\002 \003 "
  2358. }
  2359.  
  2360. #
  2361. # Channel And DCC Messages
  2362. #
  2363.  
  2364. proc unomsg {what} {
  2365. global UnoChan
  2366. putquick "PRIVMSG $UnoChan :$what"
  2367. }
  2368.  
  2369. proc unontc {who what} {
  2370. global UnoNTC
  2371. putquick "$UnoNTC $who :$what"
  2372. }
  2373.  
  2374. proc unolog {who what} {
  2375. putcmdlog "\[$who\] $what"
  2376. }
  2377.  
  2378. #
  2379. # DCC Routines
  2380. #
  2381.  
  2382. # Show All Players Cards
  2383. proc dccUnoHands {hand idx arg} {
  2384. global UnoHand RoundRobin
  2385. set n 0
  2386. while {$n != [llength $RoundRobin]} {
  2387. set un [lindex $RoundRobin $n]
  2388. unolog $un $UnoHand($un)
  2389. incr n
  2390. }
  2391. }
  2392.  
  2393. # Rehash Configuration
  2394. proc dcc_unorehash {hand idx arg} {
  2395. unolog "$hand" "Rehashing UNO Configuration"
  2396. Uno_ReadCFG
  2397. return
  2398. }
  2399.  
  2400. Uno_ReadCFG
  2401.  
  2402. UnoReadScores
  2403.  
  2404. putlog "Loaded Color Uno $UnoVersion (C) 2004 by Marky traduit en FR par Agathion
  2405. "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement