本文整理汇总了Python中core.resource.ResourceClassification类的典型用法代码示例。如果您正苦于以下问题:Python ResourceClassification类的具体用法?Python ResourceClassification怎么用?Python ResourceClassification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceClassification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buy
def buy(self, item_id):
config = ConfigTerritoryStore.get(item_id)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_STORE_ITEM_NOT_EXIST"))
remained_times = self.get_remained_times(item_id)
if not remained_times:
raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_STORE_ITEM_NO_TIMES"))
resource_classified = ResourceClassification.classify(config.needs)
resource_classified.check_exist(self.server_id, self.char_id)
resource_classified.remove(self.server_id, self.char_id, message="TerritoryStore.buy:{0}".format(item_id))
got = [(config.item_id, config.item_amount), ]
resource_classified = ResourceClassification.classify(got)
resource_classified.add(self.server_id, self.char_id, message="TerritoryStore.buy:{0}".format(item_id))
if str(item_id) in self.times:
self.times[str(item_id)] += 1
else:
self.times[str(item_id)] = 1
ValueLogTerritoryStoreBuyTimes(self.server_id, self.char_id).record(sub_id=item_id)
self.send_notify(item_id=item_id)
return resource_classified
示例2: sign_in
def sign_in(self, _id):
"""
:rtype: ResourceClassification
"""
if self.get_signed_id():
raise GameException(ConfigErrorMessage.get_error_id("UNION_ALREADY_SIGNED"))
config = ConfigUnionSignin.get(_id)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))
if config.vip:
VIP(self.server_id, self.char_id).check(config.vip)
rc = ResourceClassification.classify(config.cost)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="Union.sign_in")
self.add_contribution(config.contribution, send_notify=False)
rc = ResourceClassification.classify(config.rewards)
rc.add(self.server_id, self.char_id, message="Union.sign_in")
ValueLogUnionSignInTimes(self.server_id, self.char_id).record(sub_id=_id)
self.send_notify()
return rc
示例3: daily_buy
def daily_buy(self):
config = ConfigActivityDailyBuy.get(self.create_day)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))
if self.create_day in self.doc['daily_buy']:
raise GameException(ConfigErrorMessage.get_error_id("ACTIVITY_DAILY_BUY_HAS_BOUGHT"))
cost = [(money_text_to_item_id('diamond'), config.diamond_now), ]
rc = ResourceClassification.classify(cost)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="ActivityNewPlayer.daily_buy")
rc = ResourceClassification.classify(config.items)
rc.add(self.server_id, self.char_id, message="ActivityNewPlayer.daily_buy")
self.doc['daily_buy'].append(self.create_day)
MongoActivityNewPlayer.db(self.server_id).update_one(
{'_id': self.char_id},
{'$push': {
'daily_buy': self.create_day
}}
)
self.send_daily_buy_notify()
return rc
示例4: make_inspire
def make_inspire(self):
"""
:rtype: ResourceClassification | None
"""
if not self.remained_inspire_times():
raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_NO_INSPIRE_TIMES"))
cost = [(money_text_to_item_id('diamond'), self.inspire_cost()), ]
rc = ResourceClassification.classify(cost)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="Building.make_inspire")
ValueLogTerritoryBuildingInspireTimes(self.server_id, self.char_id).record(sub_id=self.id)
config = ConfigTerritoryBuilding.get(self.id).levels[self.level].inspire
level_up = self.add_exp(config.exp)
reward = config.get_reward()
if reward:
rc = ResourceClassification.classify(reward)
rc.add(self.server_id, self.char_id, message="Building.make_inspire")
return rc, level_up
return None, level_up
示例5: buy_reward
def buy_reward(self, vip_level):
self.check(vip_level)
config = ConfigVIP.get(vip_level)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))
if vip_level in self.doc['rewards']:
raise GameException(ConfigErrorMessage.get_error_id("VIP_ALREADY_BUY_REWARD"))
needs = [(money_text_to_item_id('diamond'), config.diamond_now)]
rc = ResourceClassification.classify(needs)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="VIP.buy_reward:{0}".format(vip_level))
got = [(config.item_id, 1)]
rc = ResourceClassification.classify(got)
rc.add(self.server_id, self.char_id, message="VIP.buy_reward:{0}".format(vip_level))
self.doc['rewards'].append(vip_level)
MongoVIP.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'rewards': self.doc['rewards']
}}
)
self.send_notify()
return rc
示例6: send_reward
def send_reward(self, goods_id):
if goods_id == YUEKA_ID:
# 月卡买了就立即发送
# 后面的再定时发送
config = ConfigPurchaseYueka.get(YUEKA_ID)
got = 0
actual_got = 0
MongoPurchase.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'yueka_remained_days': 29,
'yueka_new': True
}}
)
self.doc['yueka_remained_days'] = 29
self.doc['yueka_new'] = True
rc = ResourceClassification.classify(config.rewards)
attachment = rc.to_json()
m = MailManager(self.server_id, self.char_id)
m.add(config.mail_title, config.mail_content, attachment=attachment)
else:
config = ConfigPurchaseGoods.get(goods_id)
got = config.diamond
actual_got = config.diamond + config.diamond_extra
if self.get_purchase_times() == 0:
# 首充
actual_got = config.diamond * 2 + config.diamond_extra
doc = MongoPurchaseLog.document()
doc['_id'] = make_string_id()
doc['char_id'] = self.char_id
doc['goods_id'] = goods_id
doc['got'] = got
doc['actual_got'] = actual_got
doc['timestamp'] = arrow.utcnow().timestamp
MongoPurchaseLog.db(self.server_id).insert_one(doc)
reward = [
(VIP_EXP_ITEM_ID, config.vip_exp),
(money_text_to_item_id('diamond'), actual_got)
]
rc = ResourceClassification.classify(reward)
rc.add(self.server_id, self.char_id, message="Purchase.send_reward:{0}".format(goods_id))
purchase_done_signal.send(
sender=None,
server_id=self.server_id,
char_id=self.char_id,
goods_id=goods_id,
got=got,
actual_got=actual_got,
)
self.send_notify()
示例7: buy_item
def buy_item(self, party_level, buy_id, member_ids):
ret = api_handle.API.Party.BuyDone()
ret.ret = 0
config = ConfigPartyLevel.get(party_level)
if buy_id not in [config.buy_one, config.buy_two]:
ret.ret = ConfigErrorMessage.get_error_id("PARTY_BUY_ITEM_NOT_EXIST")
return ret
config_buy = ConfigPartyBuyItem.get(buy_id)
try:
rc = ResourceClassification.classify(config_buy.cost)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="Party.buy_item:{0},{1}".format(party_level, buy_id))
except GameException as e:
ret.ret = e.error_id
return ret
# 把购买的物品加给所有人
item_id, item_amount = config_buy.buy_result()
reward = [(item_id, item_amount), ]
rc = ResourceClassification.classify(reward)
rc.add(self.server_id, self.char_id)
for mid in member_ids:
rc.add(self.server_id, mid, message="Party.buy_item:{0},{1}".format(party_level, buy_id))
ret.buy_name = config_buy.name
ret.item_name = ConfigItemNew.get(item_id).name
ret.item_amount = item_amount
return ret
示例8: destroy
def destroy(self, using_sycee):
if self.level == UNIT_INIT_LEVEL and self.step == UNIT_INIT_STEP:
raise GameException(ConfigErrorMessage.get_error_id("UNIT_IS_INIT_CANNOT_DESTROY"))
if using_sycee:
need_diamond = GlobalConfig.value("UNIT_DESTROY_SYCEE")
cost = [(money_text_to_item_id('diamond'), need_diamond), ]
rc = ResourceClassification.classify(cost)
rc.check_exist(self.server_id, self.char_id)
rc.remove(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id))
percent = 1
else:
percent = 0.7
items = self.get_strengthen_cost()
items = [(_id, int(_amount * percent)) for _id, _amount in items]
rc = ResourceClassification.classify(items)
rc.add(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id))
self.level = UNIT_INIT_LEVEL
self.step = UNIT_INIT_STEP
MongoUnit.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'units.{0}.level'.format(self.id): self.level,
'units.{0}.step'.format(self.id): self.step,
}}
)
return rc
示例9: equipment_destroy
def equipment_destroy(self, slot_id, use_sycee):
# 装备销毁
"""
:rtype: ResourceClassification
"""
self._equipment_destroy_check(slot_id)
this_slot = self.doc['slots'][slot_id]
item_id = this_slot['item_id']
config = ConfigEquipmentNew.get(item_id)
level = this_slot['level']
equip = Equipment.load_from_slot_data(this_slot)
if use_sycee:
if equip.is_special:
min_level = 0
else:
min_level = min(config.levels.keys())
if level == min_level:
raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_CANNOT_DESTROY_NO_LEVEL_UP"))
diamond = GlobalConfig.value("EQUIPMENT_DESTROY_SYCEE")
rf = ResourceClassification.classify([(money_text_to_item_id('diamond'), diamond)])
rf.check_exist(self.server_id, self.char_id)
rf.remove(self.server_id, self.char_id)
MongoBag.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'slots.{0}.level'.format(slot_id): 0
}}
)
self.doc['slots'][slot_id]['level'] = 0
self.send_notify(slot_ids=[slot_id])
results = equip.get_destroy_back_items(is_normal_destroy=False)
else:
self.remove_by_slot_id(slot_id, 1)
results = equip.get_destroy_back_items(is_normal_destroy=True)
if config.renown:
results.append((money_text_to_item_id('renown'), config.renown))
resource_classified = ResourceClassification.classify(results)
resource_classified.add(self.server_id, self.char_id, message="Bag.equipment_destroy:{0}".format(item_id))
return resource_classified
示例10: buy
def buy(self, tp, goods_id):
if tp not in ALL_TYPES:
raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))
config = ConfigStore.get(goods_id)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST"))
try:
data = self.doc['tp'][str(tp)]['goods'][str(goods_id)]
except KeyError:
raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))
if data['times'] >= config.times_limit:
raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES"))
if config.condition_id == 1:
# VIP 等级
VIP(self.server_id, self.char_id).check(config.condition_value)
elif config.condition_id == 2:
# 爬塔历史最高星
Tower(self.server_id, self.char_id).check_history_max_star(config.condition_value)
elif config.condition_id == 3:
# 竞技场当前排名
Arena(self.server_id, self.char_id).check_current_rank(config.condition_value)
elif config.condition_id == 4:
# 当前公会等级
Union(self.server_id, self.char_id).check_level(config.condition_value)
item_id, item_amount, need_id, need_amount = config.content[data['index']]
resource_classify = ResourceClassification.classify([(need_id, need_amount)])
resource_classify.check_exist(self.server_id, self.char_id)
resource_classify.remove(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id))
resource_classify = ResourceClassification.classify([(item_id, item_amount)])
resource_classify.add(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id))
data['times'] += 1
MongoStore.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times']
}}
)
self.send_notify(tp=tp)
return resource_classify
示例11: trig
def trig(self, challenge_id):
if not self.doing:
# 任务都做完了
return
config = ConfigTaskMain.get(self.doing)
if not Challenge(self.server_id, self.char_id).is_challenge_id_passed(config.challenge_id):
return
if self.doing >= ConfigTaskMain.MAX_ID:
self.doing = 0
else:
self.doing += 1
MongoTaskMain.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'doing': self.doing
}}
)
resource_classified = ResourceClassification.classify(config.items)
resource_classified.add(self.server_id, self.char_id, message="TaskMain.trig:{0}".format(challenge_id))
self.send_notify(update=True)
示例12: step_up
def step_up(self):
if self.step >= self.config.max_step:
raise GameException(ConfigErrorMessage.get_error_id("STAFF_ALREADY_MAX_STEP"))
if self.level < self.config.steps[self.step].level_limit:
raise GameException(ConfigErrorMessage.get_error_id("STAFF_LEVEL_NOT_ENOUGH"))
using_items = self.config.steps[self.step].update_item_need
resource_classified = ResourceClassification.classify(using_items)
resource_classified.check_exist(self.server_id, self.char_id)
resource_classified.remove(self.server_id, self.char_id, message="Staff.step_up:{0}".format(self.oid))
self.step += 1
MongoStaff.db(self.server_id).update_one(
{'_id': self.char_id},
{'$set': {
'staffs.{0}.step'.format(self.id): self.step
}}
)
# NOTE 升阶可能会导致 天赋技能 改变
# 不仅会影响自己,可能(如果在阵型中)也会影响到其他选手
# 所以这里不自己 calculate, 而是先让 club 重新 load staffs
staff_step_up_signal.send(
sender=None,
server_id=self.server_id,
char_id=self.char_id,
staff_id=self.id,
staff_oid=self.oid,
new_step=self.step
)
示例13: send_rank_reward_and_reset_star
def send_rank_reward_and_reset_star(cls, server_id):
char_ids = Club.get_recent_login_char_ids(server_id)
char_ids = [i for i in char_ids]
condition = {'$and': [
{'_id': {'$in': char_ids}},
{'today_max_star': {'$ne': 0}}
]}
docs = MongoTower.db(server_id).find(condition, {'_id': 1}).sort('today_max_star', -1)
rank = 1
for doc in docs:
cid = doc['_id']
config = ConfigTowerRankReward.get(rank)
rc = ResourceClassification.classify(config.reward)
m = MailManager(server_id, cid)
m.add(
config.mail_title,
config.mail_content,
attachment=rc.to_json(),
)
rank += 1
# reset today max star
MongoTower.db(server_id).update_many(
{},
{'$set': {
'today_max_star': 0,
}}
)
示例14: _send_one_mail
def _send_one_mail(self, m):
if m.items:
rc = ResourceClassification.classify(m.get_parsed_items())
attachment = rc.to_json()
else:
attachment = ""
if m.condition_type == 1:
# 全部服务器
for s in ModelServer.objects.all():
self._send_to_one_server(s.id, m, attachment)
elif m.condition_type == 2:
# 指定服务器
for sid in m.get_parsed_condition_value():
self._send_to_one_server(sid, m, attachment)
elif m.condition_type == 3:
# 指定排除服务器
values = m.get_parsed_condition_value()
for s in ModelServer.objects.exclude(id__in=values):
self._send_to_one_server(s.id, m, attachment)
elif m.condition_type == 11:
# 指定角色ID
values = m.get_parsed_condition_value()
chars = ModelCharacter.objects.filter(id__in=values)
for c in chars:
self._send_to_one_char(c.server_id, c.id, m, attachment)
示例15: new_player_get
def new_player_get(self, _id):
config = ConfigWelfareNewPlayer.get(_id)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))
status = self.get_new_player_item_status(_id)
if status == WELFARE_CAN_NOT:
raise GameException(ConfigErrorMessage.get_error_id("WELFARE_NEW_PLAYER_CAN_NOT"))
if status == WELFARE_HAS_GOT:
raise GameException(ConfigErrorMessage.get_error_id("WELFARE_NEW_PLAYER_HAS_GOT"))
self.doc['new_player'].append(_id)
rc = ResourceClassification.classify(config.reward)
rc.add(self.server_id, self.char_id, message="Welfare.new_player_get:{0}".format(_id))
MongoWelfare.db(self.server_id).update_one(
{'_id': self.char_id},
{'$push': {
'new_player': _id
}}
)
self.send_new_player_notify(_id)
return rc