本文整理汇总了Python中core.resource.Resource.check方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.check方法的具体用法?Python Resource.check怎么用?Python Resource.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.resource.Resource
的用法示例。
在下文中一共展示了Resource.check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: levy
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def levy(self):
char = Char(self.char_id).mc
if self.counter.remained_value <= 0:
if char.vip < VIP_MAX_LEVEL:
raise SanguoException(
errormsg.LEVY_NO_TIMES,
self.char_id,
"Levy",
"no times. but can get additional times by increase vip level. current: {0}, max: {1}".format(char.vip, VIP_MAX_LEVEL)
)
raise SanguoException(
errormsg.LEVY_NO_TIMES_FINAL,
self.char_id,
"Levy",
"no times. vip reach the max level {0}".format(VIP_MAX_LEVEL)
)
resource = Resource(self.char_id, "Levy")
cost_cyess = self.get_cost_sycee()
with resource.check(sycee=-cost_cyess):
drop = self.get_levy_drop()
self.counter.incr()
standard_drop = resource.add(**drop)
t = Task(self.char_id)
t.trig(4)
self.send_notify()
return standard_drop
示例2: reset_one
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def reset_one(self, _id):
str_id = str(_id)
if str_id not in self.stage.elites:
raise SanguoException(
errormsg.STAGE_ELITE_NOT_OPEN,
self.char_id,
"Elite Reset One",
"reset a not opened stage {0}".format(_id)
)
reset_times = self.stage.elites_buy.get(str(_id), 0)
char = Char(self.char_id).mc
can_reset_times = VIP_FUNCTION[char.vip].stage_elite_buy
if reset_times >= can_reset_times:
raise SanguoException(
errormsg.STAGE_ELITE_RESET_FULL,
self.char_id,
"Elite Reset One",
"reset {0}".format(_id)
)
cost = self.get_reset_cost(_id)
resource = Resource(self.char_id, "Elite Reset One", "reset {0}".format(_id))
with resource.check(sycee=-cost):
self.stage.elites[str(_id)] = 0
self.stage.elites_buy[str(_id)] = reset_times + 1
self.stage.save()
self.send_update_notify(_id)
示例3: step_up
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def step_up(self):
to = self.equip.upgrade_to
if not to:
raise SanguoException(
errormsg.EQUIPMENT_REACH_MAX_STEP,
self.char_id,
"Equipment Step Up",
"Equipment {0} Can not step up".format(self.equip_id)
)
step_up_need_gold = self.step_up_need_gold()
stuff_needs = []
for x in self.equip.stuff_needs.split(','):
_id, _amount = x.split(':')
stuff_needs.append((int(_id), int(_amount)))
resouce = Resource(self.char_id, "Equipment Step Up", "equipment {0}".format(self.equip_id))
with resouce.check(gold=-step_up_need_gold, stuffs=stuff_needs):
self.oid = to
self.equip = EQUIPMENTS[self.oid]
self.mongo_item.equipments[str(self.equip_id)].oid = to
add_gem_slots = self.equip.slots - len(self.mongo_item.equipments[str(self.equip_id)].gems)
for i in range(add_gem_slots):
self.mongo_item.equipments[str(self.equip_id)].gems.append(0)
self.mongo_item.save()
achievement = Achievement(self.char_id)
achievement.trig(22, 1)
if not self.equip.upgrade_to:
achievement.trig(23, 1)
return stuff_needs
示例4: checkin
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
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)
示例5: create
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def create(self,name):
if len(name) > UNION_NAME_MAX_LENGTH:
raise SanguoException(
errormsg.UNION_NAME_TOO_LONG,
self.char_id,
"Union Create",
"name too long: {0}".format(name.encode('utf-8'))
)
if MongoUnion.objects.filter(name=name).count() > 0:
raise SanguoException(
errormsg.UNION_NAME_ALREADY_EXIST,
self.char_id,
"Union Create",
"name already exist: {0}".format(name.encode('utf-8'))
)
resource = Resource(self.char_id, "Union Create")
with resource.check(sycee=-UNION_CREATE_NEEDS_SYCEE):
new_id = id_generator('union')[0]
mu = MongoUnion(id=new_id)
mu.owner = self.char_id
mu.name = name
mu.bulletin = UNION_DEFAULT_DES
mu.level = 1
mu.contribute_points = 0
mu.save()
UnionMember(self.char_id).join_union(new_id)
Union(self.char_id, new_id).send_notify()
UnionBattle(self.char_id).send_notify()
示例6: refresh
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def refresh(self):
if self.all_opended():
# 所有卡都翻完了。直接刷新
self.panel = self.make_new_panel()
self.send_notify()
return
resouce = Resource(self.char_id, "HeroPanel Refresh")
with resouce.check(sycee=-GET_HERO_FORCE_REFRESH_COST):
self.panel = self.make_new_panel()
self.send_notify()
示例7: strength
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def strength(self, _id, method):
# method: 1 - free ,2 - gold, 3 - sycee
try:
h = self.mongo_horse.horses[str(_id)]
except KeyError:
raise SanguoException(
errormsg.HORSE_NOT_EXIST,
self.char_id,
"Horse Strength",
"horse {0} not exist".format(_id)
)
hobj = OneHorse(_id, h.oid, h.attack, h.defense, h.hp)
try:
HorseFreeTimesManager(self.char_id).incr()
except CounterOverFlow:
# 已经没有免费次数了
if method == 1:
# 但还要免费强化,引发异常
raise SanguoException(
errormsg.HORSE_STRENGTH_NO_FREE_TIMES,
self.char_id,
"Horse Strength",
"strength {0} using free times. but no free times".format(_id)
)
# 这个时候就要根据method来确定是否using_sycee和 resource_needs了
if method == 2:
using_sycee = False
resource_needs = {'gold': -hobj.strength_cost_gold}
else:
using_sycee = True
resource_needs = {'sycee': -hobj.strength_cost_sycee}
else:
# 还有免费次数,直接按照免费来搞
using_sycee = False
resource_needs = {}
if resource_needs:
resource = Resource(self.char_id, "Horse Strength", "strength {0} with method {1}".format(_id, method))
with resource.check(**resource_needs):
new_hobj = hobj.strength(using_sycee)
else:
new_hobj = hobj.strength(using_sycee)
self.mongo_horse.strengthed_horse = {str(_id): new_hobj.to_mongo_record()}
self.mongo_horse.save()
return new_hobj
示例8: refresh
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def refresh(self):
if self.all_opended():
# 所有卡都翻完了。直接刷新
self.panel = self.make_new_panel()
self.send_notify()
return
if self.refresh_seconds > 0:
# 免费刷新还在冷却,只能用元宝刷新,不重置免费刷新时间
resouce = Resource(self.char_id, "HeroPanel Refresh")
with resouce.check(sycee=-GET_HERO_FORCE_REFRESH_COST):
self.panel = self.make_new_panel(reset_time=False)
self.send_notify()
return
# 可以用免费刷新
self.panel = self.make_new_panel()
self.send_notify()
示例9: reset_total
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def reset_total(self):
counter = Counter(self.char_id, 'stage_elite_buy_total')
if counter.remained_value <= 0:
raise SanguoException(
errormsg.STAGE_ELITE_RESET_TOTAL_FULL,
self.char_id,
"Elite Reset Total",
"reset total"
)
cost = self.get_total_reset_cost()
resource = Resource(self.char_id, "Elite Reset Total", "")
with resource.check(sycee=-cost):
counter = Counter(self.char_id, 'stage_elite')
counter.reset()
self.send_remained_times_notify()
示例10: checkin
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def checkin(self):
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, self.mongo_union_member.joined).add_contribute_points(c.got_contributes)
示例11: levy
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def levy(self):
char = Char(self.char_id).mc
if self.counter.remained_value <= 0:
if char.vip < VIP_MAX_LEVEL:
raise SanguoException(
errormsg.LEVY_NO_TIMES,
self.char_id,
"Levy",
"no times. but can get additional times by increase vip level. current: {0}, max: {1}".format(char.vip, VIP_MAX_LEVEL)
)
raise SanguoException(
errormsg.LEVY_NO_TIMES_FINAL,
self.char_id,
"Levy",
"no times. vip reach the max level {0}".format(VIP_MAX_LEVEL)
)
resource = Resource(self.char_id, "Levy")
cost_cyess = self.get_cost_sycee()
with resource.check(sycee=-cost_cyess):
got_gold = LEVY_GOT_GOLD_FUNCTION(char.level)
prob = random.randint(1, 100)
for k, v in LEVY_CRIT_PROB_TABLE:
if prob <= k:
break
got_gold *= v
self.counter.incr()
resource.add(gold=got_gold)
t = Task(self.char_id)
t.trig(4)
self.send_notify()
return got_gold
示例12: level_up
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def level_up(self, quick=False):
def _up():
if self.level >= EQUIP_MAX_LEVEL:
raise SanguoException(
errormsg.EQUIPMENT_REACH_MAX_LEVEL,
self.char_id,
"Equipment Level Up",
"Equipment {0} has already touch max level {1}".format(self.equip.id, EQUIP_MAX_LEVEL))
if self.level >= char_level:
raise SanguoException(
errormsg.EQUIPMENT_REACH_CHAR_LEVEL,
self.char_id,
"Equipment Level Up",
"Equipment {0} level {1} >= char level {2}".format(self.equip.id, self.level, char_level)
)
gold_needs = self.level_up_need_gold()
if cache_char.gold < gold_needs:
raise SanguoException(
errormsg.GOLD_NOT_ENOUGH,
self.char_id,
"Equipment Level Up",
"Gold Not Enough"
)
cache_char.gold -= gold_needs
prob = random.randint(1, 100)
for p, l in LEVEL_UP_PROBS:
if prob <= p:
actual_level_up = l
break
self.mongo_item.equipments[str(self.equip_id)].level += actual_level_up
self.level += actual_level_up
return gold_needs
char = Char(self.char_id)
cache_char = char.mc
char_level = cache_char.level
LEVEL_UP_PROBS = (
(30, 1), (80, 2), (100, 3)
)
all_gold_needs = 0
equip_msgs = []
if quick:
quick_times = 0
while True:
try:
all_gold_needs += _up()
except SanguoException:
if quick_times == 0:
raise
else:
break
else:
quick_times += 1
msg = protomsg.Equip()
self._msg_equip(msg, self.equip_id, self.mongo_item.equipments[str(self.equip_id)], self)
equip_msgs.append(msg)
else:
all_gold_needs += _up()
msg = protomsg.Equip()
self._msg_equip(msg, self.equip_id, self.mongo_item.equipments[str(self.equip_id)], self)
equip_msgs.append(msg)
resource = Resource(self.char_id, "Equipment Level Up", "equipment {0}".format(self.equip_id))
with resource.check(gold=-all_gold_needs):
self.mongo_item.save()
Task(self.char_id).trig(8)
return equip_msgs
示例13: open
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def open(self, _id):
if str(_id) not in self.panel.panel:
raise SanguoException(
errormsg.HEROPANEL_SOCKET_NOT_EXIST,
self.char_id,
"HeroPanel Open",
"HeroPanel Socket {0} not exist".format(_id)
)
if self.panel.panel[str(_id)].opened:
# raise SanguoException(
# errormsg.HEROPANEL_SOCKET_ALREADY_OPENED,
# self.char_id,
# "HeroPanel Open",
# "HeroPanel Socket {0} already opended".format(_id)
# )
return None
if self.all_opended():
raise SanguoException(
errormsg.HEROPANEL_ALL_OPENED,
self.char_id,
"HeroPanel Open",
"all opened."
)
none_opened_heros = self.none_opened_heros()
none_opened_other_heros = [(socket_id, h) for socket_id, h in none_opened_heros if not h.good]
def _random_get():
if none_opened_other_heros:
return random.choice(none_opened_other_heros)
return random.choice(none_opened_heros)
using_sycee = self.get_hero_cost(incr=True)
resource = Resource(self.char_id, "HeroPanel Open")
with resource.check(sycee=-using_sycee):
if not self.has_got_good_hero():
# 还没有取到甲卡
if self.panel.refresh_times == 0:
# 新角色第一次抽卡,给好卡
prob = 100
else:
prob = GET_HERO_QUALITY_ONE_PROB[self.open_times + 1]
if random.randint(1, 100) <= prob:
# 取得甲卡
for k, v in none_opened_heros:
if v.good:
socket_id, hero = k, v
break
else:
socket_id, hero = _random_get()
else:
socket_id, hero = _random_get()
else:
socket_id, hero = _random_get()
self.panel.panel[str(_id)], self.panel.panel[socket_id] = self.panel.panel[socket_id], self.panel.panel[str(_id)]
self.panel.panel[str(_id)].opened = True
self.panel.save()
save_hero(self.char_id, hero.oid)
self.send_notify()
Task(self.char_id).trig(7)
return hero.oid
示例14: open
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def open(self, _id):
if str(_id) not in self.panel.panel:
raise SanguoException(
errormsg.HEROPANEL_SOCKET_NOT_EXIST,
self.char_id,
"HeroPanel Open",
"HeroPanel Socket {0} not exist".format(_id)
)
if self.panel.panel[str(_id)].opened:
raise SanguoException(
errormsg.HEROPANEL_SOCKET_ALREADY_OPENED,
self.char_id,
"HeroPanel Open",
"HeroPanel Socket {0} already opended".format(_id)
)
none_opended_heros = self.none_opened_heros()
if not none_opended_heros:
raise SanguoException(
errormsg.HEROPANEL_ALL_OPENED,
self.char_id,
"HeroPanel Open",
"all opened."
)
none_opened_good_hero = None
none_opened_other_heros = []
for k, v in none_opended_heros:
if v.good:
none_opened_good_hero = (k, v)
continue
none_opened_other_heros.append((k, v))
counter = Counter(self.char_id, 'gethero')
try:
counter.incr()
using_sycee = 0
except CounterOverFlow:
# 没有免费次数了,需要用元宝
using_sycee = GET_HERO_COST
resource = Resource(self.char_id, "HeroPanel Open")
with resource.check(sycee=-using_sycee):
if none_opened_good_hero:
# 还没有取到甲卡
prob = GET_HERO_QUALITY_ONE_PROB[self.open_times + 1]
if random.randint(1, 100) <= prob:
# 取得甲卡
socket_id, hero = none_opened_good_hero
else:
socket_id, hero = random.choice(none_opened_other_heros)
else:
socket_id, hero = random.choice(none_opened_other_heros)
self.panel.panel[str(_id)], self.panel.panel[socket_id] = self.panel.panel[socket_id], self.panel.panel[str(_id)]
self.panel.panel[str(_id)].opened = True
self.panel.save()
save_hero(self.char_id, hero.oid)
self.send_notify()
return hero.oid
示例15: prisoner_get
# 需要导入模块: from core.resource import Resource [as 别名]
# 或者: from core.resource.Resource import check [as 别名]
def prisoner_get(self, _id, treasures):
str_id = str(_id)
if str_id not in self.p.prisoners:
raise SanguoException(
errormsg.PRISONER_NOT_EXIST,
self.char_id,
"Prisoner Get",
"{0} not exist".format(_id)
)
if not self.p.prisoners[str_id].active:
raise SanguoException(
errormsg.PRISONER_NOT_ACTIVE,
self.char_id,
"Prisoner Get",
"{0} not active".format(_id)
)
treasures_prob = 0
for tid in treasures:
try:
treasures_prob += TREASURES[tid].value
except KeyError:
raise SanguoException(
errormsg.STUFF_NOT_EXIST,
self.char_id,
"Prisoner Get",
"treasure {0} not exist".format(tid)
)
def _get():
got = False
prob = self.p.prisoners[str_id].prob + treasures_prob
ae = ActivityEntry(self.char_id, 40008)
if ae and ae.is_ok():
prob += 80
ae = ActivityEntry(self.char_id, 50005)
if ae and ae.is_valid():
_vip = ae.get_current_value(self.char_id)
if _vip == 4:
prob += 30
elif _vip == 5:
prob += 50
elif _vip == 6:
prob += 60
elif _vip >= 7:
prob += 100
if prob >= random.randint(1, 100):
# got it
save_hero(self.char_id, self.p.prisoners[str_id].oid)
got = True
self.p.prisoners.pop(str_id)
msg = protomsg.RemovePrisonerNotify()
msg.ids.append(_id)
publish_to_char(self.char_id, pack_msg(msg))
else:
self.p.prisoners[str_id].active = False
msg = protomsg.UpdatePrisonerNotify()
p = msg.prisoner.add()
p_obj = self.p.prisoners[str_id]
self._fill_up_prisoner_msg(p, _id, p_obj.oid, p_obj.prob, p_obj.active)
publish_to_char(self.char_id, pack_msg(msg))
self.p.save()
return got
using_stuffs = [(tid, 1) for tid in treasures]
if using_stuffs:
resource = Resource(self.char_id, "Prisoner Get")
with resource.check(stuffs=using_stuffs):
got = _get()
else:
got = _get()
t = Task(self.char_id)
t.trig(5)
if got:
achievement = Achievement(self.char_id)
achievement.trig(14, 1)
TimesLogPrisonGetSuccess(self.char_id).inc()
return got