def item_buy(activator, obj, nrof, seller): # Get the object's name with the correct nrof. old_nrof = obj.nrof obj.nrof = nrof obj_name = obj.GetName() obj.nrof = old_nrof ## Inserts the bought item inside the player, splitting it if necessary. def item_insert(): # Different nrof, so split the object. if obj.nrof > 1 and obj.nrof != nrof: new = obj.Clone() new.nrof = nrof obj.nrof -= nrof clear_custom_values(new) new.InsertInto(activator) else: clear_custom_values(obj) obj.InsertInto(activator) # Seller is the same as the buyer, withdraw the item. if seller == activator.name: item_insert() return "You have withdrawn the {}.".format(obj_name) # Calculate the cost. cost = int(obj.ReadKey("auction_house_value")) * max(1, nrof) try: if not activator.PayAmount(cost): return "You lack {} to buy {}.".format( CostString(cost - activator.GetMoney()), obj_name) except OverflowError: return "Overflow error encountered; could not buy {}.\n\nTry buying a smaller quantity.".format( obj_name) import PostOffice # Create the container with the money. cont = create_money_container( cost, "What: {}\nPrice: {}.".format(obj_name, CostString(cost))) # Send the container. post = PostOffice.PostOffice(activator.name) try: post.send_item(cont, seller) finally: post.db.close() cont.Destroy() item_insert() return "You paid {} for {}.".format(CostString(cost), obj_name)
from connections.postoffice import MasterConnection, ConnectionPostOfficeEnd import Recording import BCI import PostOffice if __name__ == "__main__": main_connection = ConnectionPostOfficeEnd.MainConnection() connections = MasterConnection.MasterConnection() recording = Recording.Recording() bci_controller = BCI.BCI(connections, main_connection, recording) PostOffice.PostOffice(main_connection, connections, bci_controller)
def __init__(self): ip = "0.0.0.0" port = 8005 self._topcommunicator = TcpCommunicator(ip, port, bind=True) self._botcommunicator = I2cCommunicator() self._myhardware = Hardware(self._botcommunicator) #===============AVR self._Avr1address = 6 self._Avr2address = 7 self._myhardware.addAVR(self._Avr1address) self._myhardware.addAVR(self._Avr2address) #===============Devices motorsbasepwm = 1440 zero = 0 cameraservobase = 1500 RGBwhite = 7 self._myhardware._avrList[0].addDevice("Front_Right_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Front_Left_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Back_Right_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Back_Left_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Up_Front_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Up_Back_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("DC", zero, 1) self._myhardware._avrList[1].addDevice("Camera_Servo", cameraservobase, 2) self._myhardware._avrList[1].addDevice("LED", RGBwhite, 1) self._myhardware._avrList[1].addDevice("Cycle_Flag", zero, 1) #=============Components #identifiers must be in the form of a list self._rovmanipulator = Manipulator(self._myhardware, {"grip": 0}) self._rovLights = Lights(self._myhardware, {"led": 7}) self._rovCamera = Camera(self._myhardware, {"cam": 0}) self._rovmotion = Motion(self._myhardware, { "x": 0, "y": 0, "z": 0, "r": 0, "currentmode": "normal" }) modules = [ self._rovmanipulator, self._rovLights, self._rovCamera, self._rovmotion ] #=============PostOffcie self.mypostoffice = PostOffice() for module in modules: self.mypostoffice.registerEventListner("TCP", module.mail) self.mypostoffice.registerEventListner("TCP ERROR", module.mail) self.mypostoffice.registerEventListner("I2C", self._rovmanipulator.mail) self.mypostoffice.registerEventListner( "I2C", self._myhardware._avrList[1].mail) self.mypostoffice.registerEventListner( "I2C", self._myhardware._avrList[0].mail) self.mypostoffice.registerEventListner("Sensors", self._topcommunicator._send) self._topcommunicator.registerCallBack(self.mypostoffice.triggerEvent) #=============Sensors # self._mysensors=SensorRegistry() # self._mysensors.registerSensor(sensor) # self._mysensors.registerCallBack(self.mypostoffice.triggerEvent) #=====intterupts self._interruptor = Interrupt() self._interruptor.register(23, False, self.mypostoffice.triggerEvent, "I2C") self._topcommunicator._mainLoop()
__author__ = 'Anti' if __name__ == "__main__": import PostOffice PostOffice.PostOffice()