def update(self, gold=0, sycee=0, exp=0, official_exp=0, purchase_got=0, purchase_actual_got=0): opended_funcs = [] char = MongoCharacter.objects.get(id=self.id) if gold: char.gold += gold char_gold_changed_signal.send(sender=None, char_id=self.id, now_value=char.gold, change_value=gold) sycee += purchase_actual_got if sycee: char.sycee += sycee char_sycee_changed_signal.send(sender=None, char_id=self.id, now_value=char.sycee, change_value=sycee) if exp: old_level = char.level char.exp, char.level = char_level_up(char.exp, char.level, exp) if char.level != old_level: char_level_up_signal.send( sender=None, char_id=self.id, new_level=char.level, ) opended_funcs = FunctionOpen(self.id).trig_by_char_level( char.level) if official_exp: old_official_level = char.official char.official_exp, char.official = char_official_up( char.official_exp, char.official, official_exp) if char.official != old_official_level: char_official_up_signal.send(sender=None, char_id=self.id, new_official=char.official) # VIP total_purchase_got = char.purchase_got + purchase_got vip = get_vip_level(total_purchase_got) char.purchase_got = total_purchase_got char.vip = vip char.save() self.send_notify(char=char, opended_funcs=opended_funcs)
def login_notify(char_id): hero_objs = char_heros_obj(char_id) Char(char_id).send_notify() hero_notify(char_id, hero_objs) Item(char_id).send_notify() f = Formation(char_id) f.send_socket_notify() f.send_formation_notify() hang = Hang(char_id) hang.send_notify() Plunder(char_id).send_notify() p = Prison(char_id) p.send_prisoners_notify() Arena(char_id).send_notify() f = Friend(char_id) f.send_friends_notify() f.send_friends_amount_notify() m = Mail(char_id) m.send_mail_notify() CheckIn(char_id).send_notify() stage = Stage(char_id) stage.send_already_stage_notify() stage.send_new_stage_notify() stage_elite = EliteStage(char_id) stage_elite.send_notify() stage_elite.send_remained_times_notify() stage_activity = ActivityStage(char_id) stage_activity.send_notify() stage_activity.send_remained_times_notify() HeroPanel(char_id).send_notify() Task(char_id).send_notify() Achievement(char_id).send_notify() HeroSoul(char_id).send_notify() FunctionOpen(char_id).send_notify() Levy(char_id).send_notify() Attachment(char_id).send_notify()
def cmd(request): req = request._proto char_id = request._char_id if req.action == 2: print "Unsupported" return HttpResponse('', content_type='text/plain') drop = make_standard_drop_from_template() if req.tp == 1: drop['exp'] = req.param elif req.tp == 2: drop['official_exp'] = req.param elif req.tp == 3: drop['gold'] = req.param elif req.tp == 4: drop['sycee'] = req.param elif req.tp == 5: if req.param not in EQUIPMENTS: return HttpResponse('', content_type='text/plain') drop['equipments'].append((req.param, 1, 1)) elif req.tp == 6: if req.param not in GEMS: return HttpResponse('', content_type='text/plain') drop['gems'].append((req.param, 1)) elif req.tp == 7: if req.param not in HEROS: return HttpResponse('', content_type='text/plain') drop['heros'].append((req.param, 1)) elif req.tp == 8: if req.param not in STUFFS: return HttpResponse('', content_type='text/plain') drop['stuffs'].append((req.param, 1)) elif req.tp == 9: if req.param not in HEROS: return HttpResponse('', content_type='text/plain') drop['souls'].append((req.param, 1)) elif req.tp == 10: drop['purchase_got'] = req.param drop['purchase_actual_got'] = req.param resource = Resource(char_id, "CMD", "tp: {0}, param: {1}".format(req.tp, req.param)) standard_drop = resource.add(**drop) print standard_drop if req.tp == 11: fo = FunctionOpen(char_id) fo._open_all() fo.send_notify() return HttpResponse('', content_type='text/plain')
def battle(self, stage_id): try: this_stage = STAGES[stage_id] except KeyError: raise SanguoException( errormsg.STAGE_NOT_EXIST, self.char_id, "Stage Battle", "Stage {0} not exist".format(stage_id) ) char = Char(self.char_id) char_level = char.mc.level if char_level < this_stage.level_limit: raise SanguoException( errormsg.STAGE_LEVEL_GREATER_THAN_CHAR_LEVEL, self.char_id, "Stage Battle", "Stage {0} level limit {1} > char level {2}".format(stage_id, this_stage.level_limit, char_level) ) open_condition = this_stage.open_condition if open_condition and str(open_condition) not in self.stage.stages: raise SanguoException( errormsg.STAGE_NOT_OPEN, self.char_id, "Stage Battle", "Stage {0} not open. condition is {1}".format(stage_id, open_condition) ) if str(stage_id) not in self.stage.stages: self.first = True battle_msg = protomsg.Battle() b = PVE(self.char_id, stage_id, battle_msg) b.start() star = False if battle_msg.first_ground.self_win and battle_msg.second_ground.self_win and battle_msg.third_ground.self_win: star = True if not self.stage.stages.get(str(stage_id), False): self.first_star = True if stage_id > self.stage.max_star_stage: self.stage.max_star_stage = stage_id self.star = star if battle_msg.self_win: # 当前关卡星设置 old_star = self.stage.stages.get(str(stage_id), False) if not old_star: self.stage.stages[str(stage_id)] = star # 设置新关卡 stage_new = getattr(this_stage, 'next', None) if stage_new: if str(stage_new) not in self.stage.stages: if self.stage.stage_new != stage_new: self.stage.stage_new = stage_new self.send_new_stage_notify() # 发送通知 msg = protomsg.CurrentStageNotify() opened_func = FunctionOpen(self.char_id).trig_by_stage_id(stage_id) self._msg_stage(msg.stage, stage_id, old_star or star) msg.funcs.extend(opened_func) publish_to_char(self.char_id, pack_msg(msg)) self.stage.save() if battle_msg.self_win: # 开启精英关卡 elite = EliteStage(self.char_id) elite.enable_by_condition_id(stage_id) pve_finished_signal.send( sender=None, char_id=self.char_id, stage_id=stage_id, win=battle_msg.self_win, star=star, ) return battle_msg
def login_notify(char_id): message_clean(char_id) function_open = FunctionOpen(char_id) function_open.send_notify() hero_objs = char_heros_obj(char_id) Char(char_id).send_notify() hero_notify(char_id, hero_objs) Item(char_id).send_notify() f = Formation(char_id) f.send_socket_notify() f.send_formation_notify() Plunder(char_id).send_notify() p = Prison(char_id) p.send_prisoners_notify() if Arena.FUNC_ID not in function_open.mf.freeze: arena = Arena(char_id) arena.send_notify() arena.login_process() f = Friend(char_id) f.send_friends_notify() f.send_friends_amount_notify() CheckIn(char_id).send_notify() stage = Stage(char_id) stage.send_already_stage_notify() stage.send_new_stage_notify() stage_elite = EliteStage(char_id) stage_elite.send_notify() stage_elite.send_remained_times_notify() stage_activity = ActivityStage(char_id) stage_activity.send_notify() stage_activity.send_remained_times_notify() HeroPanel(char_id).send_notify() Task(char_id).send_notify() Achievement(char_id).send_notify() HeroSoul(char_id).send_notify() Levy(char_id).send_notify() Attachment(char_id).send_notify() PurchaseAction(char_id).send_notify() SystemBroadcast(char_id).send_global_broadcast() affairs = Affairs(char_id) affairs.send_city_notify() affairs.send_hang_notify() # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件 Mail(char_id).send_notify()
def login_notify(char_id): message_clean(char_id) function_open = FunctionOpen(char_id) function_open.send_notify() hero_objs = char_heros_obj(char_id) Char(char_id).send_notify() VIP(char_id).send_notify() hero_notify(char_id, hero_objs) Item(char_id).send_notify() f = Formation(char_id) f.send_socket_notify() f.send_formation_notify() Plunder(char_id).send_notify() p = Prison(char_id) p.send_prisoners_notify() a = Arena(char_id) a.send_notify() a.login_process() f = Friend(char_id) f.send_friends_notify() f.send_friends_amount_notify() CheckIn(char_id).send_notify() stage = Stage(char_id) stage.send_already_stage_notify() stage.send_new_stage_notify() stage_elite = EliteStage(char_id) stage_elite.send_notify() stage_elite.send_times_notify() stage_activity = ActivityStage(char_id) stage_activity.check(send_notify=False) stage_activity.send_notify() stage_activity.send_remained_times_notify() HeroPanel(char_id).send_notify() Task(char_id).send_notify() Achievement(char_id).send_notify() HeroSoul(char_id).send_notify() Levy(char_id).send_notify() Attachment(char_id).send_notify() BasePurchaseAction(char_id).send_notify() SystemBroadcast(char_id).send_global_broadcast() ChatMessagePublish(char_id).send_notify() affairs = Affairs(char_id) affairs.send_city_notify() affairs.send_hang_notify() HorseFreeTimesManager(char_id).send_notify() Horse(char_id).send_notify() union.send_notify(char_id) ae = ActivityEntry(char_id, 50006) if ae and ae.is_valid(): ae.enable(ae.get_current_value(char_id)) ActivityStatic(char_id).send_notify() # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件 Mail(char_id).send_notify()
def update(self, gold=0, sycee=0, exp=0, official_exp=0, purchase_got=0, purchase_actual_got=0): # purchase_got 充值获得元宝 # purchase_actual_got 充值实际获得元宝 # 比如 有个 商品 是 充1元,得1元宝,但现在做活动,买一送一,也就是充1元,得2元宝 # 这里的 purchase_got = 1, purchase_actual_got = 2 # 用户的 元宝 多2, 但是记录 purchase_got 还是加1 # VIP 也是用 累加的 purchase_got来计算的 opended_funcs = [] char = MongoCharacter.objects.get(id=self.id) if gold: char.gold += gold char_gold_changed_signal.send(sender=None, char_id=self.id, now_value=char.gold, change_value=gold) sycee += purchase_actual_got if sycee: char.sycee += sycee char_sycee_changed_signal.send(sender=None, char_id=self.id, now_value=char.sycee, change_value=sycee) if not CHARACTER_MAX_LEVEL or char.level < CHARACTER_MAX_LEVEL: if exp: old_level = char.level char.exp, char.level = char_level_up(char.exp, char.level, exp) if char.level != old_level: char_level_up_signal.send( sender=None, char_id=self.id, new_level=char.level, ) opended_funcs = FunctionOpen(self.id).trig_by_char_level( char.level) if official_exp: old_official_level = char.official char.official_exp, char.official = char_official_up( char.official_exp, char.official, official_exp) if char.official != old_official_level: char_official_up_signal.send(sender=None, char_id=self.id, new_official=char.official) # VIP total_purchase_got = char.purchase_got + purchase_got char.purchase_got = total_purchase_got old_vip = char.vip new_vip = get_vip_level(total_purchase_got) if new_vip > old_vip: char.vip = new_vip vip_changed_signal.send(sender=None, char_id=self.id, old_vip=old_vip, new_vip=new_vip) char.save() self.send_notify(char=char, opended_funcs=opended_funcs)
def update(self, gold=0, sycee=0, exp=0, official_exp=0, purchase_got=0, purchase_actual_got=0, update_settings=None): # purchase_got 充值获得元宝 # purchase_actual_got 充值实际获得元宝 # 比如 有个 商品 是 充1元,得1元宝,但现在做活动,买一送一,也就是充1元,得2元宝 # 这里的 purchase_got = 1, purchase_actual_got = 2 # 用户的 元宝 多2, 但是记录 purchase_got 还是加1 # VIP 也是用 累加的 purchase_got来计算的 def get_settings(key): if not update_settings: return True return update_settings.get(key, True) opended_funcs = [] char = MongoCharacter.objects.get(id=self.id) signal_go = SignalHeroWeGo() if gold: char.gold += gold signal_go.add(char_gold_changed_signal, sender=None, char_id=self.id, now_value=char.gold, change_value=gold) # 这里加上_cost_sycee是因为防止同时出现purchase_actual_got和消费的update # 虽然逻辑上不可能,但是代码是可以这样调用的 # 所以为了清晰,这里加上_cost_sycee表示消费了多少元宝 _cost_sycee = 0 _add_sycee = 0 if sycee < 0: _cost_sycee = abs(sycee) else: _add_sycee = sycee if sycee or purchase_actual_got: char.sycee += sycee + purchase_actual_got signal_go.add( char_sycee_changed_signal, sender=None, char_id=self.id, now_value=char.sycee, cost_value=_cost_sycee, add_value=_add_sycee + purchase_actual_got, ) if not CHARACTER_MAX_LEVEL or char.level < CHARACTER_MAX_LEVEL: if exp: old_level = char.level char.level, char.exp = char_level_up(char.level, char.exp, exp) if char.level != old_level: signal_go.add( char_level_up_signal, sender=None, char_id=self.id, new_level=char.level, ) opended_funcs = FunctionOpen(self.id).trig_by_char_level( char.level) if official_exp: old_official_level = char.official char.official_exp, char.official = char_official_up( char.official_exp, char.official, official_exp) if char.official != old_official_level: signal_go.add(char_official_up_signal, sender=None, char_id=self.id, new_official=char.official) total_purchase_got = char.purchase_got + purchase_got char.purchase_got = total_purchase_got # VIP if get_settings('as_vip_exp'): char.vip_exp += purchase_got old_vip = char.vip new_vip = get_vip_level(char.vip_exp) if new_vip > old_vip: char.vip = new_vip signal_go.add(vip_changed_signal, sender=None, char_id=self.id, old_vip=old_vip, new_vip=new_vip) char.save() self.send_notify(char=char, opended_funcs=opended_funcs) if purchase_got > 0 and get_settings('purchase_notify'): signal_go.add(new_purchase_signal, sender=None, char_id=self.id, new_got=purchase_got, total_got=total_purchase_got) signal_go.emit()