本文整理汇总了Python中core.resource.Resource.check_and_remove方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.check_and_remove方法的具体用法?Python Resource.check_and_remove怎么用?Python Resource.check_and_remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.resource.Resource
的用法示例。
在下文中一共展示了Resource.check_and_remove方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: step_up
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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
)
示例2: stuff_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)
示例3: equip_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)
示例4: battle
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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
示例5: stuff_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)
示例6: gem_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)
示例7: equip_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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())
示例8: get_plunder_target
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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
示例9: battle
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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
示例10: get_reward_check
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)])
示例11: step_up
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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])
示例12: battle
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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
示例13: gem_sell
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check_and_remove [as 别名]
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)