Move deposit box code to separate file

Give deposit boxes their own script and update all the banks.

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@20450 282e977c-c81d-0410-88c4-b93c2d0d6712
master
partmedia 2017-07-27 06:35:26 +00:00
parent 739ca3508b
commit b6f456c365
8 changed files with 53 additions and 87 deletions

View File

@ -9,7 +9,7 @@ enter_y 16
msg msg
Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu) Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu)
Idea credited to Eric Mehlhaff. Idea credited to Eric Mehlhaff.
Modified: 2012-09-03 Rick Tanner Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
end end
arch cobblestones2 arch cobblestones2
@ -3091,18 +3091,11 @@ x 17
y 3 y 3
end end
arch depositbox arch depositbox
name Deposit Box
x 17 x 17
y 3 y 3
arch event_apply
name Apply
title Python
slaying /python/IPO/banksay.py
end
arch event_close arch event_close
name Close
title Python title Python
slaying /python/IPO/banksay.py slaying /python/items/deposit_box.py
end end
end end
arch dungeon_magic arch dungeon_magic
@ -3449,10 +3442,7 @@ x 19
y 3 y 3
end end
arch sign_w arch sign_w
name ATM name deposit box
msg
Note. There is a service charge of 1% placed on deposits and withdrawls.
endmsg
x 19 x 19
y 3 y 3
end end

View File

@ -8,7 +8,7 @@ enter_x 10
enter_y 11 enter_y 11
msg msg
Created: 2012-09-03 Rick Tanner Created: 2012-09-03 Rick Tanner
Modified: 2014-10-04 Kevin Zheng Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
end end
arch grass_only arch grass_only
@ -1387,7 +1387,7 @@ x 10
y 9 y 9
end end
arch sign_e arch sign_e
name ATM name deposit box
x 10 x 10
y 9 y 9
end end
@ -1544,18 +1544,11 @@ x 11
y 9 y 9
end end
arch depositbox arch depositbox
name Deposit Box
x 11 x 11
y 9 y 9
arch event_apply
name Apply
title Python
slaying /python/IPO/banksay.py
end
arch event_close arch event_close
name Close
title Python title Python
slaying /python/IPO/banksay.py slaying /python/items/deposit_box.py
end end
end end
arch dungeon_magic arch dungeon_magic

View File

@ -5,7 +5,7 @@ width 7
height 20 height 20
msg msg
Created: 2002-08-28 Created: 2002-08-28
Modified: 2009-07-12 Andreas Kirschbaum Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
end end
arch pentagram arch pentagram
@ -135,6 +135,10 @@ end
arch depositbox arch depositbox
x 2 x 2
y 9 y 9
arch event_close
title Python
slaying /python/items/deposit_box.py
end
end end
arch dresser arch dresser
x 2 x 2

View File

@ -8,7 +8,7 @@ enter_x 9
enter_y 18 enter_y 18
msg msg
Created: 1996-01-29 Created: 1996-01-29
Modified: 2011-12-05 Rick Tanner Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
end end
arch afloor_right arch afloor_right
@ -299,18 +299,11 @@ x 1
y 18 y 18
end end
arch depositbox arch depositbox
name Deposit Box
x 1 x 1
y 18 y 18
arch event_apply
name Apply
title Python
slaying /python/IPO/banksay.py
end
arch event_close arch event_close
name Close
title Python title Python
slaying /python/IPO/banksay.py slaying /python/items/deposit_box.py
end end
end end
arch afloor_right arch afloor_right
@ -471,10 +464,7 @@ x 2
y 18 y 18
end end
arch sign_w arch sign_w
name ATM name deposit box
msg
Note. A service charge of 1% is placed on deposits and withdrawals.
endmsg
x 2 x 2
y 18 y 18
end end

View File

@ -2,7 +2,7 @@
Created by: Joris Bontje <jbontje@suespammers.org> Created by: Joris Bontje <jbontje@suespammers.org>
This module implements banking in Crossfire. It provides the 'say' event for This module implements banking in Crossfire. It provides the 'say' event for
bank tellers, as well as a deposit box for quickly depositing money. bank tellers.
""" """
import random import random
@ -70,14 +70,6 @@ def getExchangeRate(coinName):
else: else:
return None return None
def get_inventory(obj):
"""An iterator for a given object's inventory."""
current_item = obj.Inventory
while current_item != None:
next_item = current_item.Below
yield current_item
current_item = next_item
def do_deposit(player, amount): def do_deposit(player, amount):
"""Deposit the given amount for the player.""" """Deposit the given amount for the player."""
with CFBank.open() as bank: with CFBank.open() as bank:
@ -85,15 +77,6 @@ def do_deposit(player, amount):
whoami.Say("%s credited to your account." \ whoami.Say("%s credited to your account." \
% Crossfire.CostStringFromValue(amount)) % Crossfire.CostStringFromValue(amount))
def deposit_box_close():
"""Find the total value of items in the deposit box and deposit."""
total_value = 0
for obj in get_inventory(whoami):
if obj.Name != 'Apply' and obj.Name != 'Close':
total_value += obj.Value * obj.Quantity
obj.Teleport(activator.Map, 15, 3)
do_deposit(activator, total_value)
def cmd_help(): def cmd_help():
"""Print a help message for the player.""" """Print a help message for the player."""
whoami.Say("The Bank of Skud can help you keep your money safe. In addition, you will be able to access your money from any bank in the world! What would you like to do?") whoami.Say("The Bank of Skud can help you keep your money safe. In addition, you will be able to access your money from any bank in the world! What would you like to do?")
@ -192,14 +175,8 @@ def main_employee():
whoami.Say("Hello, what can I help you with today?") whoami.Say("Hello, what can I help you with today?")
Crossfire.AddReply("learn", "I want to learn how to use the bank.") Crossfire.AddReply("learn", "I want to learn how to use the bank.")
# Find out if the script is being run by a deposit box or an employee. Crossfire.SetReturnValue(1)
if whoami.Name.find('Deposit Box') > -1: try:
ScriptParm = Crossfire.ScriptParameters() main_employee()
if ScriptParm == 'Close': except ValueError:
deposit_box_close() whoami.Say("I don't know how much money that is.")
else:
Crossfire.SetReturnValue(1)
try:
main_employee()
except ValueError:
whoami.Say("I don't know how much money that is.")

View File

@ -0,0 +1,27 @@
import CFBank
import Crossfire
activator = Crossfire.WhoIsActivator()
whoami = Crossfire.WhoAmI()
def get_inventory(obj):
"""An iterator for a given object's inventory."""
current_item = obj.Inventory
while current_item != None:
next_item = current_item.Below
yield current_item
current_item = next_item
def deposit_box_close():
"""Find the total value of items in the deposit box and deposit."""
total_value = 0
for obj in get_inventory(whoami):
if obj.Name != 'event_close':
total_value += obj.Value * obj.Quantity
obj.Remove()
with CFBank.open() as bank:
bank.deposit(activator.Name, total_value)
whoami.Say("%s credited to your account." \
% Crossfire.CostStringFromValue(total_value))
deposit_box_close()

View File

@ -9,7 +9,7 @@ enter_y 16
msg msg
Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu) Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu)
Idea credited to Eric Mehlhaff. Idea credited to Eric Mehlhaff.
Modified: 2012-08-30 Rick Tanner Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
end end
arch grass_only arch grass_only
@ -3227,18 +3227,11 @@ x 18
y 9 y 9
end end
arch depositbox arch depositbox
name Deposit Box
x 18 x 18
y 9 y 9
arch event_apply
name Apply
title Python
slaying /python/IPO/banksay.py
end
arch event_close arch event_close
name Close
title Python title Python
slaying /python/IPO/banksay.py slaying /python/items/deposit_box.py
end end
end end
arch dungeon_magic arch dungeon_magic
@ -3429,10 +3422,7 @@ x 19
y 9 y 9
end end
arch sign_w arch sign_w
name ATM name deposit box
msg
Note. There is a service charge of 1% placed on deposits and withdrawls.
endmsg
x 19 x 19
y 9 y 9
end end

View File

@ -9,7 +9,7 @@ enter_y 16
msg msg
Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu) Created: 1993-10-10 skud the great (tvangod@ecst.csuchico.edu)
Idea credited to Eric Mehlhaff. Idea credited to Eric Mehlhaff.
Modified: 2015-02-22 Kevin Zheng Modified: 2017-07-26 Kevin Zheng
endmsg endmsg
outdoor 1 outdoor 1
end end
@ -1717,13 +1717,11 @@ x 12
y 12 y 12
end end
arch depositbox arch depositbox
name Deposit Box
x 12 x 12
y 12 y 12
arch event_close arch event_close
name Close
title Python title Python
slaying /python/IPO/banksay.py slaying /python/items/deposit_box.py
end end
end end
arch dungeon_magic arch dungeon_magic
@ -1910,10 +1908,7 @@ x 13
y 12 y 12
end end
arch sign_w arch sign_w
name Deposit Box name deposit box
msg
Note: There is a 1% service charge on all deposits.
endmsg
x 13 x 13
y 12 y 12
end end