def apply_union(self, union_id): # 申请加入工会 from core.union.union import Union, UnionList doc = MongoUnion._get_collection().find_one({'_id': union_id}, {'owner': 1}) if not doc: raise SanguoException(errormsg.UNION_NOT_EXIST, self.char_id, "Member Apply Union", "union {0} not exist".format(union_id)) if self.mongo_union_member.joined: raise SanguoException( errormsg.UNION_CANNOT_APPLY_ALREADY_IN, self.char_id, "Member Apply Union", "already in {0}".format(self.mongo_union_member.joined)) if len(self.mongo_union_member.applied) >= 10: raise SanguoException(errormsg.UNION_CANNOT_APPLY_FULL, self.char_id, "Member Apply Union", "apply list too long") if union_id not in self.mongo_union_member.applied: self.mongo_union_member.applied.append(union_id) self.mongo_union_member.save() Union(doc['owner']).send_apply_list_notify() UnionList.send_list_notify(self.char_id)
def get_joined_union(request): char_id = int(request.POST['char_id']) union = Union(char_id) if isinstance(union, UnionDummy): data = None else: m = Member(char_id) data = { 'char_id': char_id, 'union': union.union_id, 'union_owner': union.mongo_union.owner, 'union_name': union.mongo_union.name, 'union_bulletin': union.mongo_union.bulletin, 'union_level': union.mongo_union.level, 'union_contribute_points': union.mongo_union.contribute_points, 'union_score': union.mongo_union.score, 'member_coin': m.mongo_union_member.coin, 'member_contribute_points': m.mongo_union_member.contribute_points, 'member_position': m.mongo_union_member.position, 'member_checkin_times': m.mongo_union_member.checkin_times, 'member_buy_buff_times': m.mongo_union_member.buy_buff_times, 'member_boss_times': m.mongo_union_member.boss_times } return {'ret': 0, 'data': data}
def purge_char(char_id): from core.union.union import Union, UnionOwner char_id = int(char_id) # 工会特殊处理 u = Union(char_id) if isinstance(u, UnionOwner): # 要删除的人是会长 print "process union" u.quit() char_field_records = {'MongoHero'} from mongoengine.base.metaclasses import TopLevelDocumentMetaclass records = globals() final_records = {} for name, obj in records.iteritems(): if name.startswith('Mongo') and isinstance(obj, TopLevelDocumentMetaclass): final_records[name] = obj for name, obj in final_records.iteritems(): if name in char_field_records: obj.objects.filter(char=char_id).delete() else: try: x = obj.objects.get(id=char_id) x.delete() except: pass # special case for m in MongoFriend.objects.all(): _changed = False if char_id in m.friends: m.friends.remove(char_id) _changed = True if char_id in m.pending: m.pending.remove(char_id) _changed = True if char_id in m.accepting: m.accepting.remove(char_id) _changed = True if char_id in m.plunder_gives: m.plunder_gives.remove(char_id) _changed = True if char_id in m.plunder_gots: m.plunder_gots.remove(char_id) _changed = True if char_id in m.plunder_senders: m.plunder_senders.remove(char_id) _changed = True if _changed: m.save()
def __init__(self, my_char_id, rival_char_id): self.my_char_id = my_char_id self.rival_char_id = rival_char_id self.my_union = Union(my_char_id) self.rival_union = Union(rival_char_id) self.my_union_name = self.my_union.mongo_union.name self.rival_union_name = self.rival_union.mongo_union.name self.my_team = self.Team(self.my_union.get_battle_members()) self.rival_team = self.Team(self.rival_union.get_battle_members()) self.start_at = arrow.utcnow().timestamp self.initiative = True self.logs = []
def manage(request): req = request._proto char_id = request._char_id u = Union(char_id) if req.action == 1: u.kick_member(req.member_id) else: u.transfer(req.member_id) return None
def clean(signum): logger = Logger("union_transfer_owner.log") logger.write("Start") try: result = Union.cronjob_auto_transfer_union() except: logger.error(traceback.format_exc()) else: logger.write("Transfer: {0}".format(json.dumps(result))) finally: logger.close()
def checkin(self): # 签到 from core.union.union import Union from core.union.battle import UnionBattle if not self.mongo_union_member.joined: raise SanguoException(errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union") if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException(errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times") try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times + 1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format( self.mongo_union_member.checkin_times + 1)) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow( ).timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id).add_contribute_points(c.got_contributes) UnionBattle(self.char_id).send_notify() doc = MongoUnion._get_collection().find_one( {'_id': self.mongo_union_member.joined}, {'owner': 1}) owner = doc['owner'] UnionBattle(owner).send_notify() drop = make_standard_drop_from_template() drop['union_coin'] = c.got_coin drop['union_contribute_points'] = c.got_contributes return standard_drop_to_attachment_protomsg(drop)
def _send_reward(rank, mongo_union): data = _get_reward_by_rank(rank) contribute_points = data.pop('union_contribute_points') u = Union(mongo_union.owner) u.add_contribute_points(contribute_points) members = u.member_list attachment = json.dumps(data) for mid in members: m = Mail(mid) m.add(MAIL_UNION_BATTLE_REWARD_TITLE, MAIL_UNION_BATTLE_REWARD_CONTENT, attachment=attachment)
def send_notify(char_id): from core.union.battle import UnionBattle from core.union.boss import UnionBoss from core.union.store import UnionStore from core.union.union import Union, UnionList, UnionOwner from core.union.member import Member # 工会列表 UnionList.send_list_notify(char_id) # 个人信息 Member(char_id).send_personal_notify() u = Union(char_id) # UnionNotify u.send_notify() if isinstance(u, UnionOwner): # 会长才能看见的申请者列表 u.send_apply_list_notify() # 商店 UnionStore(char_id).send_notify() # 工会战 UnionBattle(char_id).send_notify()
def quit(request): char_id = request._char_id Union(char_id).quit() return None
def refuse_join(request): req = request._proto char_id = request._char_id Union(char_id).refuse_join(req.char_id) return None
def agree_join(request): req = request._proto char_id = request._char_id Union(char_id).agree_join(req.char_id) return None
def modify(request): req = request._proto char_id = request._char_id Union(char_id).modify(req.bulletin) return None
def __init__(self, char_id, union_id=None): self.char_id = char_id self.union = Union(char_id, union_id=union_id)