def __init__(self, server_id, char_id): from core.formation import Formation from core.plunder import Plunder from core.inspire import Inspire from core.championship import Championship self.server_id = server_id self.char_id = char_id self.formation = Formation(server_id, char_id) p = Plunder(server_id, char_id) self.plunder_formation_1 = p.get_way_object(1) self.plunder_formation_2 = p.get_way_object(2) self.plunder_formation_3 = p.get_way_object(3) c = Championship(server_id, char_id) self.championship_formation_1 = c.get_way_object(1) self.championship_formation_2 = c.get_way_object(2) self.championship_formation_3 = c.get_way_object(3) self.inspire = Inspire(server_id, char_id)
def try_initialize(self, send_notify=True): if self.doc['active']: return # 从 掠夺阵型 拷贝 p = Plunder(self.server_id, self.char_id) for i in [1, 2, 3]: way = p.get_way_object(i) doc = way.get_or_create_doc() WAY_MAP[i].MONGO_COLLECTION.db(self.server_id).delete_one( {'_id': self.char_id}) WAY_MAP[i].MONGO_COLLECTION.db(self.server_id).insert_one(doc) self.doc['active'] = True MongoChampionship.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'active': True }}) if send_notify: self.send_notify()
def cronjob(cls, sid): from core.club import Club from core.plunder import Plunder notify = cls.NOTIFY() notify.session = "" docs = cls.MONGO_DOCUMENT.db(sid).find({ 'winning': { '$gt': 0 } }).sort('winning', -1).limit(3) if docs.count() == 0: data = notify.SerializeToString() value = None else: for doc in docs: msg_club = Club(sid, doc['_id']).make_protomsg() _plunder = Plunder(sid, doc['_id']) notify_club = notify.clubs.add() notify_club.club.MergeFrom(msg_club) notify_club.point = doc['winning'] for _way_id in [1, 2, 3]: notify_club_formation = notify_club.formation.add() notify_club_formation.MergeFrom( _plunder.get_way_object(_way_id).make_protobuf()) data = notify.SerializeToString() value = base64.b64encode(data) cls.COMMON(sid).set(value) cls.MONGO_DOCUMENT.db(sid).drop() for _cid in OperationLog.get_recent_action_char_ids(sid, recent_minutes=5): MessagePipe(_cid).put(data=data)