def stuff_sell(self, _id, amount): # TODO get gold gold = 10 * amount resource = Resource(self.char_id, "Stuff Sell", "sell {0}, amount: {1}".format(_id, amount)) resource.check_and_remove(stuffs=[(_id, amount)]) resource.add(gold=gold)
def step_up(self): # 升阶 if self.step >= HERO_MAX_STEP: raise SanguoException( errormsg.HERO_REACH_MAX_STEP, self.char_id, "Hero Step Up", "Hero {0} reach max step {1}".format(self.id, HERO_MAX_STEP) ) resource_needs = {} cost_gold = external_calculate.Hero.step_up_using_gold(self.model_hero.quality) resource_needs['gold'] = -cost_gold soul_needs_amount = external_calculate.Hero.step_up_using_soul_amount(self.model_hero.quality) hs = HeroSoul(self.char_id) self_soul_amount = hs.soul_amount(self.oid) common_soul_needs = soul_needs_amount - self_soul_amount if common_soul_needs <= 0: # don't need common soul resource_needs['souls'] = [(self.oid, soul_needs_amount)] else: # need common soul resource_needs['stuffs'] = [(22, common_soul_needs)] resource = Resource(self.char_id, "Hero Step Up", 'step up {0}'.format(self.id)) try: resource.check_and_remove(**resource_needs) except SanguoException as e: if e.error_id == errormsg.SOUL_NOT_ENOUGH or e.error_id == errormsg.STUFF_NOT_ENOUGH: raise SanguoException( errormsg.HERO_STEP_UP_ALL_NOT_ENOUGH, self.char_id, "Hero Step Up", "soul not enough" ) raise e # 扣完东西了,开始搞一次 self.hero.progress += 1 if self.hero.progress >= self.max_socket_amount: # 真正的升阶 # 否则仅仅是记录当前状态 self.hero.step += 1 self.hero.progress = 0 hero_step_up_signal.send( sender=None, char_id=self.char_id, hero_id=self.id, new_step=self.hero.step ) self.hero.save() hero_changed_signal.send( sender=None, hero_id=self.id )
def equip_sell(self, ids): if not isinstance(ids, (set, list, tuple)): ids = [ids] f = Formation(self.char_id) ids = set(ids) for _id in ids: if not self.has_equip(_id): raise SanguoException( errormsg.EQUIPMENT_NOT_EXIST, self.char_id, "Equipment Sell", "Equipment {0} NOT exist".format(_id) ) if f.find_socket_by_equip(_id): raise SanguoException( errormsg.EQUIPMENT_CANNOT_SELL_FORMATION, self.char_id, "Equipment Sell", "Equipment {0} in Formation, Can not sell".format(_id) ) gold = 0 for _id in ids: e = Equipment(self.char_id, _id, self.item) gold += e.sell_gold() resource = Resource(self.char_id, "Equipment Sell", "equipments {0}".format(ids)) resource.check_and_remove(equipments=list(ids)) resource.add(gold=gold)
def battle(self): need_sycee = 0 counter = Counter(self.char_id, 'arena') if counter.remained_value <= 0: counter = Counter(self.char_id, 'arena_buy') if counter.remained_value <= 0: char = Char(self.char_id).mc if char.vip < VIP_MAX_LEVEL: raise SanguoException( errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle", "arena no times. vip current: {0}, max {1}".format( char.vip, VIP_MAX_LEVEL)) raise SanguoException( errormsg.ARENA_NO_TIMES_FINAL, self.char_id, "Arena Battle", "arena no times. vip reach max level {0}".format( VIP_MAX_LEVEL)) else: need_sycee = ARENA_COST_SYCEE rival_id = self.choose_rival() if not rival_id: raise SanguoException(errormsg.ARENA_NO_RIVAL, self.char_id, "Arena Battle", "no rival.") if need_sycee: resource = Resource(self.char_id, "Arena Battle", "battle for no free times") resource.check_and_remove(sycee=-need_sycee) counter.incr() # set battle cd redis_client.setex(REDIS_ARENA_BATTLE_CD_KEY(rival_id), 1, ARENA_CD) msg = protomsg.Battle() b = PVP(self.char_id, rival_id, msg) b.start() if msg.self_win: achievement = Achievement(self.char_id) achievement.trig(11, 1) self_score = self.score rival_arena = Arena(rival_id) rival_score = rival_arena.score new_score = calculate_score(self_score, rival_score, msg.self_win) self.set_score(new_score) t = Task(self.char_id) t.trig(2) self.send_notify(score=new_score) rival_arena.be_beaten(rival_score, self_score, not msg.self_win, self.char_id) return msg
def get_plunder_target(self, city_id): """ @:rtype: PlunderRival """ target = PlunderRival.search_all_servers(city_id, exclude_char_id=self.char_id) self.mongo_plunder.char_id = target.char_id self.mongo_plunder.char_name = target.name self.mongo_plunder.char_gold = target.get_plunder_gold( Char(self.char_id).mc.level) self.mongo_plunder.char_power = target.power self.mongo_plunder.char_leader = target.leader self.mongo_plunder.char_formation = target.formation self.mongo_plunder.char_hero_original_ids = target.hero_original_ids self.mongo_plunder.char_city_id = target.city_id self.mongo_plunder.battle_heros = target.battle_heros self.mongo_plunder.server_url = target.server_url self.mongo_plunder.save() if target: gold_needs = BATTLES[city_id].refresh_cost_gold resource = Resource(self.char_id, "Plunder Refresh") resource.check_and_remove(gold=-gold_needs) return target
def battle(self): counter = Counter(self.char_id, 'arena') try: # 免费次数 counter.incr() except CounterOverFlow: counter = Counter(self.char_id, 'arena_buy') try: # 花费元宝次数 counter.incr() except CounterOverFlow: char = Char(self.char_id).mc if char.vip < VIP_MAX_LEVEL: raise SanguoException( errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle", "arena no times. vip current: {0}, max {1}".format(char.vip, VIP_MAX_LEVEL) ) raise SanguoException( errormsg.ARENA_NO_TIMES_FINAL, self.char_id, "Arena Battle", "arena no times. vip reach max level {0}".format(VIP_MAX_LEVEL) ) else: resource = Resource(self.char_id, "Arena Battle", "battle for no free times") resource.check_and_remove(sycee=-ARENA_COST_SYCEE) rival_id = self.choose_rival() msg = protomsg.Battle() b = PVP(self.char_id, rival_id, msg) b.start() achievement = Achievement(self.char_id) if msg.self_win: score = ARENA_GET_SCORE_WHEN_WIN achievement.trig(11, 1) self.mongo_arena.continues_win += 1 else: score = ARENA_GET_SCORE_WHEN_LOST self.mongo_arena.continues_win = 0 self.mongo_arena.save() if score: self.mongo_day.score += score self.mongo_day.save() t = Task(self.char_id) t.trig(2) self.send_notify() return msg
def step_up(self): # 升阶 if self.step >= HERO_MAX_STEP: raise SanguoException( errormsg.HERO_REACH_MAX_STEP, self.char_id, "Hero Step Up", "Hero {0} reach max step {1}".format(self.id, HERO_MAX_STEP)) resource_needs = {} cost_gold = self.get_step_up_gold_needs() resource_needs['gold'] = -cost_gold soul_needs_amount = self.get_step_up_soul_needs() resource_needs['souls'] = [(self.oid, soul_needs_amount)] hs = HeroSoul(self.char_id) self_soul_amount = hs.soul_amount(self.oid) common_soul_needs = soul_needs_amount - self_soul_amount if common_soul_needs > 0: # need common soul resource_needs['stuffs'] = [(22, common_soul_needs)] resource = Resource(self.char_id, "Hero Step Up", 'step up {0}'.format(self.id)) try: resource.check_and_remove(**resource_needs) except SanguoException as e: if e.error_id == errormsg.SOUL_NOT_ENOUGH or e.error_id == errormsg.STUFF_NOT_ENOUGH: raise SanguoException(errormsg.HERO_STEP_UP_ALL_NOT_ENOUGH, self.char_id, "Hero Step Up", "soul not enough") raise e # 扣完东西了,开始搞一次 self.hero.progress += 1 if self.hero.progress >= self.max_socket_amount: # 真正的升阶 # 否则仅仅是记录当前状态 self.hero.step += 1 self.hero.progress = 0 hero_step_up_signal.send(sender=None, char_id=self.char_id, hero_id=self.id, new_step=self.hero.step) self.step = self.hero.step self.hero.save() hero_changed_signal.send(sender=None, hero_id=self.id) TimesLogHeroStepUp(self.char_id).inc() if self.step >= 5: ae = ActivityEntry(self.char_id, 40004) if ae: ae.enable(self.step) ActivityStatic( self.char_id).send_update_notify(activity_ids=[40004])
def battle(self): counter = Counter(self.char_id, 'arena') try: # 免费次数 counter.incr() except CounterOverFlow: counter = Counter(self.char_id, 'arena_buy') try: # 花费元宝次数 counter.incr() except CounterOverFlow: char = Char(self.char_id).mc if char.vip < VIP_MAX_LEVEL: raise SanguoException( errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle", "arena no times. vip current: {0}, max {1}".format( char.vip, VIP_MAX_LEVEL)) raise SanguoException( errormsg.ARENA_NO_TIMES_FINAL, self.char_id, "Arena Battle", "arena no times. vip reach max level {0}".format( VIP_MAX_LEVEL)) else: resource = Resource(self.char_id, "Arena Battle", "battle for no free times") resource.check_and_remove(sycee=-ARENA_COST_SYCEE) rival_id = self.choose_rival() msg = protomsg.Battle() b = PVP(self.char_id, rival_id, msg) b.start() achievement = Achievement(self.char_id) if msg.self_win: score = ARENA_GET_SCORE_WHEN_WIN achievement.trig(11, 1) self.mongo_arena.continues_win += 1 else: score = ARENA_GET_SCORE_WHEN_LOST self.mongo_arena.continues_win = 0 self.mongo_arena.save() if score: self.mongo_day.score += score self.mongo_day.save() t = Task(self.char_id) t.trig(2) self.send_notify() return msg
def step_up(self): # 升阶 if self.step >= HERO_MAX_STEP: raise SanguoException( errormsg.HERO_REACH_MAX_STEP, self.char_id, "Hero Step Up", "Hero {0} reach max step {1}".format(self.id, HERO_MAX_STEP)) resource_needs = {} cost_gold = external_calculate.Hero.step_up_using_gold( self.model_hero.quality) resource_needs['gold'] = -cost_gold soul_needs_amount = external_calculate.Hero.step_up_using_soul_amount( self.model_hero.quality) hs = HeroSoul(self.char_id) self_soul_amount = hs.soul_amount(self.oid) common_soul_needs = soul_needs_amount - self_soul_amount if common_soul_needs <= 0: # don't need common soul resource_needs['souls'] = [(self.oid, soul_needs_amount)] else: # need common soul resource_needs['stuffs'] = [(22, common_soul_needs)] resource = Resource(self.char_id, "Hero Step Up", 'step up {0}'.format(self.id)) try: resource.check_and_remove(**resource_needs) except SanguoException as e: if e.error_id == errormsg.SOUL_NOT_ENOUGH or e.error_id == errormsg.STUFF_NOT_ENOUGH: raise SanguoException(errormsg.HERO_STEP_UP_ALL_NOT_ENOUGH, self.char_id, "Hero Step Up", "soul not enough") raise e # 扣完东西了,开始搞一次 self.hero.progress += 1 if self.hero.progress >= self.max_socket_amount: # 真正的升阶 # 否则仅仅是记录当前状态 self.hero.step += 1 self.hero.progress = 0 hero_step_up_signal.send(sender=None, char_id=self.char_id, hero_id=self.id, new_step=self.hero.step) self.step = self.hero.step self.hero.save() hero_changed_signal.send(sender=None, hero_id=self.id)
def gem_sell(self, _id, amount): try: this_gem = GEMS[_id] except KeyError: raise SanguoException(errormsg.GEM_NOT_EXIST, self.char_id, "Gem Sell", "Gem {0} not exist".format(_id)) gold = this_gem.sell_gold * amount resource = Resource(self.char_id, "Gem Sell", "sell: {0}, amount {1}".format(_id, amount)) resource.check_and_remove(gems=[(_id, amount)]) resource.add(gold=gold)
def stuff_sell(self, _id, amount): try: this_stuff = STUFFS[_id] except KeyError: raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id, "Stuff Sell", "Stuff {0} not exist".format(_id)) gold = this_stuff.sell_gold * amount resource = Resource(self.char_id, "Stuff Sell", "sell {0}, amount: {1}".format(_id, amount)) resource.check_and_remove(stuffs=[(_id, amount)]) resource.add(gold=gold)
def stuff_sell(self, _id, amount): try: this_stuff = STUFFS[_id] except KeyError: raise SanguoException( errormsg.STUFF_NOT_EXIST, self.char_id, "Stuff Sell", "Stuff {0} not exist".format(_id) ) gold = this_stuff.sell_gold * amount resource = Resource(self.char_id, "Stuff Sell", "sell {0}, amount: {1}".format(_id, amount)) resource.check_and_remove(stuffs=[(_id, amount)]) resource.add(gold=gold)
def gem_sell(self, _id, amount): try: this_gem = GEMS[_id] except KeyError: raise SanguoException( errormsg.GEM_NOT_EXIST, self.char_id, "Gem Sell", "Gem {0} not exist".format(_id) ) gold = this_gem.sell_gold * amount resource = Resource(self.char_id, "Gem Sell", "sell: {0}, amount {1}".format(_id, amount)) resource.check_and_remove(gems=[(_id, amount)]) resource.add(gold=gold)
def equip_sell(self, ids): if not isinstance(ids, (set, list, tuple)): ids = [ids] self.equip_check_sell(ids) off_gems = {} gold = 0 for _id in ids: e = Equipment(self.char_id, _id, self.item) gold += e.sell_gold() for gid in e.get_embedded_gems(): if gid: off_gems[gid] = off_gems.get(gid, 0) + 1 resource = Resource(self.char_id, "Equipment Sell", "equipments {0}".format(ids)) resource.check_and_remove(equipments=list(ids)) resource.add(gold=gold) self.gem_add(off_gems.items())
def get_plunder_target(self, city_id): """ @:rtype: PlunderRival """ target = PlunderRival.search(city_id, exclude_char_id=self.char_id) self.mongo_plunder.char_id = target.char_id self.mongo_plunder.char_name = target.name self.mongo_plunder.char_gold = target.get_plunder_gold(Char(self.char_id).mc.level) self.mongo_plunder.char_power = target.power self.mongo_plunder.char_leader = target.leader self.mongo_plunder.char_formation = target.formation self.mongo_plunder.char_hero_original_ids = target.hero_original_ids self.mongo_plunder.char_city_id = target.city_id self.mongo_plunder.save() if target: gold_needs = BATTLES[city_id].refresh_cost_gold resource = Resource(self.char_id, "Plunder Refresh") resource.check_and_remove(gold=-gold_needs) return target
def get_reward_check(self, char_id, condition_id): value = ACTIVITY_STATIC_CONDITIONS[condition_id].condition_value resource = Resource(char_id, "Activity Get Reward 18009") resource.check_and_remove(stuffs=[(self.STUFF_ID, value)])
def step_up(self): # 升阶 if self.step >= HERO_MAX_STEP: raise SanguoException( errormsg.HERO_REACH_MAX_STEP, self.char_id, "Hero Step Up", "Hero {0} reach max step {1}".format(self.id, HERO_MAX_STEP) ) resource_needs = {} cost_gold = self.get_step_up_gold_needs() resource_needs['gold'] = -cost_gold soul_needs_amount = self.get_step_up_soul_needs() resource_needs['souls'] = [(self.oid, soul_needs_amount)] hs = HeroSoul(self.char_id) self_soul_amount = hs.soul_amount(self.oid) common_soul_needs = soul_needs_amount - self_soul_amount if common_soul_needs > 0: # need common soul resource_needs['stuffs'] = [(22, common_soul_needs)] resource = Resource(self.char_id, "Hero Step Up", 'step up {0}'.format(self.id)) try: resource.check_and_remove(**resource_needs) except SanguoException as e: if e.error_id == errormsg.SOUL_NOT_ENOUGH or e.error_id == errormsg.STUFF_NOT_ENOUGH: raise SanguoException( errormsg.HERO_STEP_UP_ALL_NOT_ENOUGH, self.char_id, "Hero Step Up", "soul not enough" ) raise e # 扣完东西了,开始搞一次 self.hero.progress += 1 if self.hero.progress >= self.max_socket_amount: # 真正的升阶 # 否则仅仅是记录当前状态 self.hero.step += 1 self.hero.progress = 0 hero_step_up_signal.send( sender=None, char_id=self.char_id, hero_id=self.id, new_step=self.hero.step ) self.step = self.hero.step self.hero.save() hero_changed_signal.send( sender=None, hero_id=self.id ) TimesLogHeroStepUp(self.char_id).inc() if self.step >= 5: ae =ActivityEntry(self.char_id, 40004) if ae: ae.enable(self.step) ActivityStatic(self.char_id).send_update_notify(activity_ids=[40004])
def gem_sell(self, _id, amount): gold = 10 * amount resource = Resource(self.char_id, "Gem Sell", "sell: {0}, amount {1}".format(_id, amount)) resource.check_and_remove(gems=[(_id, amount)]) resource.add(gold=gold)
def battle(self): need_sycee = 0 counter = Counter(self.char_id, 'arena') if counter.remained_value <= 0: counter = Counter(self.char_id, 'arena_buy') if counter.remained_value <= 0: char = Char(self.char_id).mc if char.vip < VIP_MAX_LEVEL: raise SanguoException( errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle", "arena no times. vip current: {0}, max {1}".format(char.vip, VIP_MAX_LEVEL) ) raise SanguoException( errormsg.ARENA_NO_TIMES_FINAL, self.char_id, "Arena Battle", "arena no times. vip reach max level {0}".format(VIP_MAX_LEVEL) ) else: need_sycee = ARENA_COST_SYCEE rival_id = self.choose_rival() if not rival_id: raise SanguoException( errormsg.ARENA_NO_RIVAL, self.char_id, "Arena Battle", "no rival." ) if need_sycee: resource = Resource(self.char_id, "Arena Battle", "battle for no free times") resource.check_and_remove(sycee=-need_sycee) counter.incr() # set battle cd redis_client.setex(REDIS_ARENA_BATTLE_CD_KEY(rival_id), 1, ARENA_CD) msg = protomsg.Battle() b = PVP(self.char_id, rival_id, msg) b.start() t = Task(self.char_id) t.trig(2) drop = make_standard_drop_from_template() adding_score = 0 if msg.self_win: achievement = Achievement(self.char_id) achievement.trig(11, 1) # 只有打赢才设置积分 self_score = self.score rival_arena = Arena(rival_id) rival_score = rival_arena.score new_score = calculate_score(self_score, rival_score, msg.self_win) self.set_score(new_score) adding_score = new_score - self_score rival_arena.be_beaten(rival_score, self_score, not msg.self_win, self.char_id) TimesLogArenaWin(self.char_id).inc() ae = ActivityEntry(self.char_id, 50004) if ae and ae.is_valid(): drop = ae.get_additional_drop() Resource(self.char_id, "Arena Win").add(**drop) TimesLogArena(self.char_id).inc() ae = ActivityEntry(self.char_id, 40006) if ae: ae.trig() self.send_notify() drop['stuffs'].append((1001, adding_score)) return msg, drop
def battle(self): need_sycee = 0 counter = Counter(self.char_id, 'arena') if counter.remained_value <= 0: counter = Counter(self.char_id, 'arena_buy') if counter.remained_value <= 0: char = Char(self.char_id).mc if char.vip < VIP_MAX_LEVEL: raise SanguoException( errormsg.ARENA_NO_TIMES, self.char_id, "Arena Battle", "arena no times. vip current: {0}, max {1}".format(char.vip, VIP_MAX_LEVEL) ) raise SanguoException( errormsg.ARENA_NO_TIMES_FINAL, self.char_id, "Arena Battle", "arena no times. vip reach max level {0}".format(VIP_MAX_LEVEL) ) else: need_sycee = ARENA_COST_SYCEE rival_id = self.choose_rival() if not rival_id: raise SanguoException( errormsg.ARENA_NO_RIVAL, self.char_id, "Arena Battle", "no rival." ) if need_sycee: resource = Resource(self.char_id, "Arena Battle", "battle for no free times") resource.check_and_remove(sycee=-need_sycee) counter.incr() # set battle cd redis_client.setex(REDIS_ARENA_BATTLE_CD_KEY(rival_id), 1, ARENA_CD) msg = protomsg.Battle() b = PVP(self.char_id, rival_id, msg) b.start() if msg.self_win: achievement = Achievement(self.char_id) achievement.trig(11, 1) self_score = self.score rival_arena = Arena(rival_id) rival_score = rival_arena.score new_score = calculate_score(self_score, rival_score, msg.self_win) self.set_score(new_score) t = Task(self.char_id) t.trig(2) self.send_notify(score=new_score) rival_arena.be_beaten(rival_score, self_score, not msg.self_win, self.char_id) return msg