source: tags/start/modules/friendship.tcl @ 1143

Revision 2, 3.8 KB checked in by jamesoff, 9 years ago (diff)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1# bMotion - friendship handler
2#
3# $Id$
4#
5
6###############################################################################
7# bMotion - an 'AI' TCL script for eggdrops
8# Copyright (C) James Michael Seward 2000-2002
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful, but
16# WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18# General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23###############################################################################
24
25proc getFriendship { nick } {
26  if {![validuser $nick]} {
27    set handle [nick2hand $nick]
28    if {($handle == "*") || ($handle == "")} {
29      bMotion_putloglev 1 * "bMotion: couldn't find a handle for $nick to get friendship."
30      return 50
31    }
32  } else {
33    set handle $nick
34  }
35
36  set friendship 50
37
38  if {$handle != "*"} {
39    set friendship [getuser $handle XTRA friend]
40    if {$friendship == ""} {
41      setFriendship $nick 50 
42      set friendship 50
43    }
44  }
45  return $friendship
46}
47
48proc getFriendshipHandle { handle } {
49  set friendship 50
50
51  set friendship [getuser $handle XTRA friend]
52  if {$friendship == ""} {
53    setFriendship $nick 50 
54    set friendship 50
55  }
56  return $friendship
57}
58
59proc setFriendshipHandle { handle friendship } {
60  if {$friendship > 100} {
61    bMotion_putloglev 2 * "bMotion: friendship for $nick went over 100, capping back to 90"
62    set friendship 90
63  }
64
65  if {$friendship < 1} {
66    bMotion_putloglev 2 * "bMotion: friendship for $nick went under 1, capping back to 10"
67    set friendship 10
68  }
69
70  setuser $handle XTRA friend $friendship
71}
72
73
74proc setFriendship { nick friendship } {
75  set handle [nick2hand $nick]
76  if {$friendship > 100} {
77    bMotion_putloglev 2 * "bMotion: friendship for $nick went over 100, capping back to 90"
78    set friendship 90
79  }
80
81  if {$friendship < 0} {
82    bMotion_putloglev 2 * "bMotion: friendship for $nick went under 0, capping back to 10"
83    set friendship 10
84  }
85
86  setuser $handle XTRA friend $friendship
87}
88
89proc driftFriendship { nick drift } {
90  if {![validuser $nick]} {
91    set handle [nick2hand $nick]
92    if {($handle == "*") || ($handle == "")} {
93      bMotion_putloglev 1 * "bMotion: couldn't find a handle for $nick to drift friendship."
94      return 50
95    }
96    bMotion_putloglev 1 * "bMotion: mmm dynamic update of nick $nick to handle $handle :P"
97    set nick $handle
98  }
99
100  set friendship [getFriendship $nick]
101  incr friendship $drift
102  setFriendship $nick $friendship
103  bMotion_putloglev 2 * "bMotion: drifting friendship for $nick by $drift, now $friendship"
104  return $friendship
105}
106
107proc getFriendsList { } {
108  set users [userlist]
109  set r ""
110  set best(name) ""
111  set best(val) 0
112  set worst(name) ""
113  set worst(val) 100
114  foreach user $users {
115    set f [getuser $user XTRA friend]
116    if {$f != ""} {
117      append r "$user:$f "
118    }
119    if {$f > $best(val)} {
120      set best(val) $f
121      set best(name) $user
122    }
123    if {($f < $worst(val)) && ($f > 0)} {
124      set worst(val) $f
125      set worst(name) $user
126    }
127  }
128  set r "Best friend: $best(name), worst friend: $worst(name). $r"
129  return $r
130}
131
132proc bMotionIsFriend { nick } {
133  set friendship [getFriendship $nick]
134  bMotion_putloglev 2 * "bMotion: friendship for $nick is $friendship"
135  if {$friendship < 35} {
136    return 0
137  }
138  return 1
139}   
140
141bMotion_putloglev d * "bMotion: friendship module loaded"
Note: See TracBrowser for help on using the repository browser.