Crossfire Server, Trunk
CFGuilds.py
Go to the documentation of this file.
1 # CFGuilds.py - classes for crossfire guilds
2 #
3 # Copyright (C) 2004 Todd Mitchell
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # The author can be reached via e-mail at temitchell@sourceforge.net
20 
21 import Crossfire
22 
23 from time import localtime, strftime, time
24 import os
25 import sys
26 from CFDataFile import CFDataFile, CFData
27 
29  sys.path.append(os.path.join(Crossfire.DataDirectory(), Crossfire.MapDirectory(), 'templates', 'guild'))
30  from guilds import guilds
31  guildlisting = list(map(lambda x: x.id, guilds))
32  Crossfire.Log(Crossfire.LogDebug, 'Found guilds: %s' % guildlisting)
33  for guild in guildlisting:
34  if not CFGuildHouses().info(guild):
35  if CFGuildHouses().add_guild(guild):
36  Crossfire.Log(Crossfire.LogInfo,'New Guild: %s' %guild)
37 
38 def SearchGuilds(player):
39  guildlist = CFGuildHouses().list_guilds()
40  for guild in guildlist:
41  memberlist = CFGuild(guild).list_members()
42  for member in memberlist:
43  if member == player:
44  return guild
45  return 0
46 
48  '''Inter-Guild management class'''
49 
50  def __init__(self):
51  guildhousesheader= ['Founded_Date', 'Points', 'Status', 'Quest_points']
52  self.status=['active', 'suspended', 'probation', 'inactive']
53  self.guildhouselist = CFData('GuildHouses_log', guildhousesheader)
54  self.pointscap = 2000000000
55  self.qpcap = 2000000000
56 
57  def info(self, name):
58  record = self.guildhouselist.get_record(name)
59  if record:
60  return record
61  else:
62  return 0
63 
64  def list_guilds(self):
65  return self.guildhouselist.get_keys()
66 
67  def add_guild(self, name):
68  record={'#' : name
69  ,'Founded_Date' : 'never'
70  ,'Points' : 0
71  ,'Status' : 'inactive'
72  ,'Quest_points': 0
73  }
74  try:
75  self.guildhouselist.put_record(record)
76  return 1
77  except:
78  return 0
79 
80  def establish(self, name):
81  record = self.info(name)
82  date = strftime("%a, %d %b %Y", localtime(time()))
83  if record:
84  record['Founded_Date'] = date
85  record['Status'] = 'active'
86  self.guildhouselist.put_record(record)
87  return 1
88  else:
89  return 0
90 
91  def change_status(self, name, status):
92  record = self.info(name)
93  if record:
94  if self.status.count(status) != 0:
95  record['Status'] = status
96  self.guildhouselist.put_record(record)
97  return 1
98  else:
99  return 0
100  else:
101  return 0
102 
103  def add_questpoints(self, name, number):
104  record = self.info(name)
105  if record:
106  temp = int(record['Quest_points'])
107  if temp + number >= self.qpcap:
108  temp = self.qpcap
109  else:
110  temp = temp + number
111  record['Quest_points'] = temp
112  self.guildhouselist.put_record(record)
113  return 1
114  else:
115  return 0
116 
117  def update_points(self, name, number):
118  record = self.info(name)
119  if record:
120  temp = int(record['Points'])
121  if temp + number >= self.pointscap:
122  temp = self.pointscap
123  else:
124  temp = temp + number
125  record['Points'] = temp
126  self.guildhouselist.put_record(record)
127  return 1
128  else:
129  return 0
130 
131 class CFGuild:
132 
133  def __init__(self, guildname):
134  self.guildname = guildname
135  guildheader = ['Join_date', 'Rank', 'Status', 'Dues', 'Demerits', 'Quest_points']
136  self.ranks=['Initiate', 'Novice', 'Guildman', 'Journeyman', 'Master', 'GuildMaster']
137  self.status=['suspended', 'probation', 'good']
138  self.duescap = 1000000 #arbitrary limit on dues (if you change it remember it currently is an int)
139  self.demeritcap = 100 #arbitrary limit on demerits
140  self.qpcap = 100
141  guild_name = '%s_log' %self.guildname
142  self.guildlist = CFData(guild_name, guildheader)
143 
144  def add_member(self, name, rank):
145  date = strftime("%a, %d %b %Y", localtime(time()))
146  record={'#' : name
147  ,'Join_date' : date
148  ,'Rank' : rank
149  ,'Status' : 'good'
150  ,'Dues' : 0
151  ,'Demerits' : 0
152  ,'Quest_points': 0
153  }
154  try:
155  self.guildlist.put_record(record)
156  return 1
157  except:
158  return 0
159 
160  def remove_member(self, name):
161  try:
162  self.guildlist.remove_record(name)
163  return 1
164  except:
165  return 0
166 
167  def info(self, name):
168  record = self.guildlist.get_record(name)
169  if record:
170  return record
171  else:
172  return 0
173 
174  def list_members(self):
175  return self.guildlist.get_keys()
176 
177  def count_members(self):
178  number = len(self.guildlist.get_keys())
179  return number
180 
181  def add_demerits(self, name, number):
182  record = self.info(name)
183  if record:
184  temp = int(record['Demerits'])
185  if temp + number >= self.demeritcap:
186  temp = self.demeritcap
187  else:
188  temp = temp + number
189  record['Demerits'] = temp
190  self.guildlist.put_record(record)
191  return 1
192  else:
193  return 0
194 
195  def remove_demerits(self, name, number):
196  record = self.info(name)
197  if record:
198  temp = int(record['Demerits'])
199  if temp - number <=0:
200  temp = 0
201  else:
202  temp = temp - number
203  record['Demerits'] = temp
204  self.guildlist.put_record(record)
205  return 1
206  else:
207  return 0
208 
209  def add_questpoints(self, name, number):
210  record = self.info(name)
211  if record:
212  temp = int(record['Quest_points'])
213  if temp + number >= self.qpcap:
214  temp = self.qpcap
215  else:
216  temp = temp + number
217  record['Quest_points'] = temp
218  self.guildlist.put_record(record)
219  return 1
220  else:
221  return 0
222 
223  def pay_dues(self, name, number):
224  record = self.info(name)
225  if record:
226  temp = int(record['Dues'])
227  if temp + number >= self.duescap:
228  temp = self.duescap
229  else:
230  temp = temp + number
231  record['Dues'] = temp
232  self.guildlist.put_record(record)
233  # add points to the guild record
234  CFGuildHouses().update_points(self.guildname,number)
235  return 1
236  else:
237  return 0
238 
239  def clear_dues(self, name, number):
240  record = self.info(name)
241  if record:
242  record['Dues'] = 0
243  self.guildlist.put_record(record)
244  return 1
245  else:
246  return 0
247 
248  def change_status(self, name, status):
249  record = self.info(name)
250  if record:
251  if self.status.count(status) != 0:
252  record['Status'] = status
253  self.guildlist.put_record(record)
254  return 1
255  else:
256  return 0
257  else:
258  return 0
259 
260  def promote_member(self, name):
261  record = self.info(name)
262  if record:
263  currentrank = record['Rank']
264  if currentrank != 'GuildMaster':
265  ranknum = self.ranks.index(currentrank)
266  newrank = ranknum+1
267  record['Rank'] = self.ranks[newrank]
268  self.guildlist.put_record(record)
269  return 1
270  else:
271  return 0
272  else:
273  return 0
274 
275  def demote_member(self, name):
276  record = self.info(name)
277  if record:
278  currentrank = record['Rank']
279  if currentrank != 'Initiate':
280  ranknum = self.ranks.index(currentrank)
281  Crossfire.Log(Crossfire.LogDebug, "ranknum = %d"%ranknum)
282  newrank = ranknum-1
283  record['Rank'] = self.ranks[newrank]
284  self.guildlist.put_record(record)
285  return 1
286  else:
287  return 0
288  else:
289  return 0
CFGuilds.CFGuildHouses.qpcap
qpcap
Definition: CFGuilds.py:55
CFGuilds.CFGuild.list_members
def list_members(self)
Definition: CFGuilds.py:174
CFDataFile.CFData
Definition: CFDataFile.py:94
CFGuilds.SearchGuilds
def SearchGuilds(player)
Definition: CFGuilds.py:38
CFGuilds.CFGuild.clear_dues
def clear_dues(self, name, number)
Definition: CFGuilds.py:239
CFGuilds.CFGuild.status
status
Definition: CFGuilds.py:137
CFGuilds.CFGuild.ranks
ranks
Definition: CFGuilds.py:136
guildoracle.list
list
Definition: guildoracle.py:87
CFGuilds.CFGuild.promote_member
def promote_member(self, name)
Definition: CFGuilds.py:260
CFGuilds.CFGuild.add_member
def add_member(self, name, rank)
Definition: CFGuilds.py:144
CFGuilds.CFGuild.count_members
def count_members(self)
Definition: CFGuilds.py:177
CFGuilds.CFGuild.remove_demerits
def remove_demerits(self, name, number)
Definition: CFGuilds.py:195
CFGuilds.CFGuildHouses.guildhouselist
guildhouselist
Definition: CFGuilds.py:53
CFGuilds.CFGuild.change_status
def change_status(self, name, status)
Definition: CFGuilds.py:248
CFGuilds.CFGuildHouses.change_status
def change_status(self, name, status)
Definition: CFGuilds.py:91
CFGuilds.CFGuildHouses.__init__
def __init__(self)
Definition: CFGuilds.py:50
CFGuilds.CFGuildHouses.info
def info(self, name)
Definition: CFGuilds.py:57
disinfect.map
map
Definition: disinfect.py:4
CFGuilds.CFGuildHouses.add_guild
def add_guild(self, name)
Definition: CFGuilds.py:67
CFGuilds.CFGuildHouses.pointscap
pointscap
Definition: CFGuilds.py:54
CFGuilds.CFGuild.guildname
guildname
Definition: CFGuilds.py:134
CFGuilds.CFGuildHouses.update_points
def update_points(self, name, number)
Definition: CFGuilds.py:117
CFGuilds.CFGuild.remove_member
def remove_member(self, name)
Definition: CFGuilds.py:160
CFGuilds.CFGuild.demeritcap
demeritcap
Definition: CFGuilds.py:139
disinfect.count
int count
Definition: disinfect.py:7
CFGuilds.CFGuildHouses.establish
def establish(self, name)
Definition: CFGuilds.py:80
CFGuilds.CFGuild.pay_dues
def pay_dues(self, name, number)
Definition: CFGuilds.py:223
CFGuilds.CFGuild
Definition: CFGuilds.py:131
CFGuilds.CFGuild.add_questpoints
def add_questpoints(self, name, number)
Definition: CFGuilds.py:209
CFGuilds.CFGuildHouses
Definition: CFGuilds.py:47
CFGuilds.GuildUpdate
def GuildUpdate()
Definition: CFGuilds.py:28
CFGuilds.CFGuild.demote_member
def demote_member(self, name)
Definition: CFGuilds.py:275
CFGuilds.CFGuild.info
def info(self, name)
Definition: CFGuilds.py:167
npc_dialog.index
int index
Definition: npc_dialog.py:102
CFGuilds.CFGuild.qpcap
qpcap
Definition: CFGuilds.py:140
CFGuilds.CFGuild.duescap
duescap
Definition: CFGuilds.py:138
CFGuilds.CFGuildHouses.list_guilds
def list_guilds(self)
Definition: CFGuilds.py:64
make_face_from_files.int
int
Definition: make_face_from_files.py:32
CFGuilds.CFGuild.__init__
def __init__(self, guildname)
Definition: CFGuilds.py:133
CFGuilds.CFGuildHouses.status
status
Definition: CFGuilds.py:52
CFGuilds.CFGuild.add_demerits
def add_demerits(self, name, number)
Definition: CFGuilds.py:181
CFGuilds.CFGuild.guildlist
guildlist
Definition: CFGuilds.py:142
CFGuilds.CFGuildHouses.add_questpoints
def add_questpoints(self, name, number)
Definition: CFGuilds.py:103