本文整理汇总了Python中core.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Python Resource类的具体用法?Python Resource怎么用?Python Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_drop
def save_drop(self, _id=None):
if _id:
this_stage = STAGE_ELITE[_id]
else:
this_stage = self.this_stage
exp = this_stage.normal_exp
gold = this_stage.normal_gold
drop_ids = [int(i) for i in this_stage.normal_drop.split(',') if i.isdigit()]
prepare_drop = get_drop(drop_ids)
prepare_drop['gold'] += gold
prepare_drop['exp'] += exp
if self.is_circle_reward:
drop_hero_ids = this_stage.drop_hero_ids
if drop_hero_ids:
_drop_id = random.choice([int(i) for i in drop_hero_ids.split(',')])
prepare_drop['heros'].append((_drop_id, 1))
additional_drop = ActivityEntry(self.char_id, 11001).get_additional_drop()
drop = merge_drop([prepare_drop, additional_drop])
resource = Resource(self.char_id, "EliteStage Drop", "stage {0}".format(this_stage.id))
standard_drop = resource.add(**drop)
return standard_drop
示例2: reset_one
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: get_reward
def get_reward(self, char_id, condition_id):
key = self.make_key(condition_id)
try:
doc = MongoActivityEnabledCondition.objects.get(id=key)
except DoesNotExist:
raise SanguoException(
errormsg.ACTIVITY_CAN_NOT_GET_REWARD,
char_id,
"Activity Get Reward",
"condition {0} can not get".format(condition_id)
)
if doc.value == 1:
raise SanguoException(
errormsg.ACTIVITY_ALREADY_GOT_REWARD,
char_id,
"Activity Get Reward",
"condition {0} already got".format(condition_id)
)
doc.value = 1
doc.save()
standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package])
resource = Resource(char_id, "Activity Get Reward", "get condition id {0}".format(condition_id))
standard_drop = resource.add(**standard_drop)
return standard_drop_to_attachment_protomsg(standard_drop)
示例4: levy
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
示例5: step_up
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
示例6: get_reward
def get_reward(self, vip):
if vip > self.mc.vip:
raise SanguoException(
errormsg.VIP_LEVEL_NOT_ENOUGH,
self.char_id,
"VIP GET REWARD",
"vip not enough. {0} < {1}".format(self.mc.vip, vip)
)
vips = self.can_reward_vips()
if vip not in vips:
raise SanguoException(
errormsg.VIP_HAS_GOT_REWARD,
self.char_id,
"VIP GET REWARD",
"vip {0} has got reward".format(vip)
)
# send reward
prepare_drop = get_drop([VIP_REWARD[vip].package])
resource = Resource(self.char_id, "VIP GET REWARD", "vip {0}".format(vip))
standard_drop = resource.add(**prepare_drop)
self.mc.vip_has_reward.append(vip)
self.mc.save()
self.send_notify()
return standard_drop_to_attachment_protomsg(standard_drop)
示例7: create
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()
示例8: get_attachment
def get_attachment(self, mail_id):
if str(mail_id) not in self.mail.mails:
raise SanguoException(
errormsg.MAIL_NOT_EXIST,
self.char_id,
"Mail Get Attachment",
"mail {0} not exist".format(mail_id)
)
if not self.mail.mails[str(mail_id)].attachment:
raise SanguoException(
errormsg.MAIL_HAS_NO_ATTACHMENT,
self.char_id,
"Mail Get Attachment",
"mail {0} has no attachment".format(mail_id)
)
resource = Resource(self.char_id, "Mail Attachment")
attachment = json.loads(self.mail.mails[str(mail_id)].attachment)
resource.add(**attachment)
self.mail.mails[str(mail_id)].attachment = ''
self.mail.mails[str(mail_id)].has_read = True
self.mail.save()
self.send_notify()
return attachment
示例9: send_reward_with_custom_price
def send_reward_with_custom_price(self, goods_id, price):
# 这里 price 是新台币,而且不一定是这个goods_id所对应的价格
# 所以这里按照比例给东西
p = PURCHASE[goods_id]
xintaibi = p.rmb * 5
buy_div, buy_mod = divmod(price, xintaibi)
for i in xrange(buy_div):
self.send_reward(goods_id)
if buy_mod:
# 换算成对应的元宝
sycee = buy_mod * 2
# 任意金额也要双倍!!!
buy_times = self.buy_times_of_this_goods(goods_id)
if buy_times == 0:
actual_sycee = sycee * 2
else:
actual_sycee = sycee
resource = Resource(self.char_id, "Purchase With Custom Price")
resource.add(purchase_got=sycee, purchase_actual_got=actual_sycee)
self.mongo_record.times[str(goods_id)] = buy_times + 1
self.mongo_record.save()
self.send_notify()
title = u'充值成功'
content = u'获得了 {0} 元宝'.format(actual_sycee)
mail = Mail(self.char_id)
mail.add(title, content)
示例10: checkin
def checkin(self):
if self.c.has_checked:
raise SanguoException(
errormsg.CHECKIN_ALREADY_CHECKIN,
self.char_id,
"CheckIn checkin",
"already checkin",
)
self.c.has_checked = True
day = self.c.day
self.c.save()
resource = Resource(self.char_id, "Daily Checkin", 'checkin reward. day {0}'.format(day))
resource_add = self.checkin_data[str(day)]['package']
resource_add = get_drop_from_raw_package(resource_add)
standard_drop = resource.add(**resource_add)
msg = CheckInResponse()
msg.ret = 0
msg.reward.MergeFrom(standard_drop_to_attachment_protomsg(standard_drop))
self.send_update_notify(day)
return msg
示例11: get_reward
def get_reward(self):
counter = Counter(self.char_id, 'official_reward')
if counter.remained_value <= 0:
raise SanguoException(
errormsg.OFFICAL_ALREADY_GET_REWARD,
self.char_id,
"OfficialDailyReward Get Reward",
"already got"
)
char = Char(self.char_id)
official_level = char.mc.official
if official_level == 0:
raise SanguoException(
errormsg.OFFICAL_ZERO_GET_REWARD,
self.char_id,
"OfficialDailyReward Get Reward",
"char official level = 0"
)
counter = Counter(self.char_id, 'official_reward')
counter.incr()
gold = OFFICIAL[official_level].gold
resource = Resource(self.char_id, "Daily Official", 'official reward')
standard_drop = resource.add(gold=gold)
return standard_drop_to_attachment_protomsg(standard_drop)
示例12: save_drop
def save_drop(self):
stage_id = self.hang_doing.stage_id
actual_seconds = self.hang_doing.actual_seconds
times = actual_seconds / 15
stage = STAGES[stage_id]
drop_exp = stage.normal_exp * times
drop_gold = stage.normal_gold * times
drop_gold = self._actual_gold(drop_gold)
drop_ids = [int(i) for i in stage.normal_drop.split(',')]
prepare_drop = get_drop(drop_ids, multi=times, gaussian=True)
prepare_drop['exp'] += drop_exp
prepare_drop['gold'] += drop_gold
self.hang_doing.delete()
self.hang_doing = None
self.send_notify()
prepare_drop = drop_after_stage_type(stage_id, prepare_drop)
resource = Resource(self.char_id, "Hang Reward", "actual seconds = {0}, times = {1}".format(actual_seconds, times))
standard_drop = resource.add(**prepare_drop)
achievement = Achievement(self.char_id)
achievement.trig(29, drop_exp)
return standard_drop_to_attachment_protomsg(standard_drop)
示例13: stuff_sell
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)
示例14: checkin
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)
示例15: step_up
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
)