本文整理汇总了Python中core.formation.Formation类的典型用法代码示例。如果您正苦于以下问题:Python Formation类的具体用法?Python Formation怎么用?Python Formation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Formation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
def start(self, dungeon_id, formation_slots=None):
grade_conf = ConfigDungeonGrade.get(dungeon_id)
if not grade_conf:
raise GameException(ConfigErrorMessage.get_error_id("DUNGEON_NOT_EXIST"))
map_name = ConfigDungeon.get(grade_conf.belong).map_name
club_level = get_club_property(self.server_id, self.char_id, 'level')
if grade_conf.need_level > club_level:
raise GameException(ConfigErrorMessage.get_error_id("DUNGEON_CLUB_LEVEL_NOT_ENOUGH"))
f = Formation(self.server_id, self.char_id)
if formation_slots:
f.sync_slots(formation_slots)
Energy(self.server_id, self.char_id).check(ConfigDungeon.get(grade_conf.belong).cost)
ri = TimesInfo(self.server_id, self.char_id, grade_conf.belong)
if not ri.remained_match_times:
# 购买
self.buy_times(grade_conf.belong)
club_one = Club(self.server_id, self.char_id)
club_two = ConfigNPCFormation.get(grade_conf.npc)
msg = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(), {}).start()
msg.key = str(dungeon_id)
msg.map_name = map_name
return msg
示例2: equip_sell
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)
示例3: match
def match(self, friend_id):
friend_id = int(friend_id)
if not self.check_friend_exist(friend_id):
raise GameException(ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))
club_one = Club(self.server_id, self.char_id)
club_two = Club(self.server_id, friend_id)
f_one = Formation(self.server_id, self.char_id)
f_two = Formation(self.server_id, self.char_id)
match = ClubMatch(club_one, club_two, 6, f_one.get_skill_sequence(), f_two.get_skill_sequence())
msg = match.start()
msg.key = ""
msg.map_name = GlobalConfig.value_string("MATCH_MAP_FRIEND")
friend_match_signal.send(
sender=None,
server_id=self.server_id,
char_id=self.char_id,
target_id=friend_id,
win=msg.club_one_win
)
return msg
示例4: create_character_infomation_message
def create_character_infomation_message(char_id):
from core.character import Char
from core.formation import Formation
from core.hero import char_heros_dict
msg = CharacterInfomation()
char = Char(char_id)
heros = char_heros_dict(char_id)
f = Formation(char_id)
msg.id = char.mc.id
msg.name = char.mc.name
msg.level = char.mc.level
msg.vip = char.mc.vip
msg.power = char.power
msg.leader = f.get_leader_oid()
for hid in f.in_formation_hero_ids():
msg_hero = msg.formation.add()
if hid == 0:
msg_hero.id = 0
msg_hero.oid = 0
msg_hero.step = 0
else:
h = heros[hid]
msg_hero.id = h.id
msg_hero.oid = h.oid
msg_hero.step = h.step
return msg
示例5: trig
def trig(self, char_level, stage_id=None):
try:
s = MongoStage.objects.get(id=self.char_id)
passed_stages = s.stages.keys()
except DoesNotExist:
passed_stages = []
passed_stages.append('0')
if stage_id:
passed_stages.append(str(stage_id))
opened_funcs = []
for func_id in self.mf.freeze[:]:
try:
this_func = FUNCTION_DEFINE[func_id]
except KeyError:
self.mf.freeze.remove(func_id)
continue
if char_level >= this_func.char_level and str(this_func.stage_id) in passed_stages:
# OPEN
self.mf.freeze.remove(func_id)
opened_funcs.append(func_id)
self.mf.save()
f = Formation(self.char_id)
for of in opened_funcs[:]:
if of in FUNC_SOCKET_AMOUNT_TABLE:
opened = f.open_socket(FUNC_SOCKET_AMOUNT_TABLE[of])
if not opened:
opened_funcs.remove(of)
return opened_funcs
示例6: break_hero
def break_hero(char_id, _id):
# 主动将武将转为卡魂
try:
h = char_heros_dict(char_id)[_id]
except KeyError:
raise SanguoException(
errormsg.HERO_NOT_EXSIT,
char_id,
"Hero Break",
"hero {0} not exist".format(_id)
)
formation = Formation(char_id)
if _id in formation.in_formation_hero_ids():
raise SanguoException(
errormsg.HERO_CANNOT_BREAK_IN_FORMATION,
char_id,
"Hero Break",
"hero {0} in formation, cannot break".format(_id)
)
oid = h.oid
quality = HEROS[oid].quality
souls_amount = SAVE_HERO_TO_SOUL_TABLE[quality]
MongoHero.objects.get(id=_id).delete()
hero_del_signal.send(
sender=None,
char_id=char_id,
hero_id=_id,
hero_oid=oid
)
HeroSoul(char_id).add_soul([(oid, souls_amount)])
示例7: start
def start(self, challenge_id, formation_slots=None):
config = ConfigChallengeMatch.get(challenge_id)
if not config:
raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_EXIST"))
if config.condition_challenge:
doc = MongoChallenge.db(self.server_id).find_one(
{'_id': self.char_id},
{'challenge_star.{0}'.format(config.condition_challenge): 1}
)
if str(config.condition_challenge) not in doc['challenge_star']:
raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_OPEN"))
rt = RemainedTimes(self.server_id, self.char_id, challenge_id)
if not rt.remained_match_times:
raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_WITHOUT_TIMES"))
f = Formation(self.server_id, self.char_id)
if formation_slots:
f.sync_slots(formation_slots)
Energy(self.server_id, self.char_id).check(config.energy)
club_one = Club(self.server_id, self.char_id)
club_two = ChallengeNPCClub(challenge_id)
match = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(), {})
msg = match.start()
msg.key = str(challenge_id)
msg.map_name = config.map_name
return msg
示例8: set_formation
def set_formation(request):
req = request._proto
char_id = request._char_id
f = Formation(char_id)
socket_ids = [int(s) for s in req.socket_ids]
f.save_formation(socket_ids)
示例9: _equip_changed
def _equip_changed(char_id, equip_obj, **kwargs):
equip_id = equip_obj.equip_id
f = Formation(char_id)
socket = f.find_socket_by_equip(equip_id)
if socket:
socket_changed_signal.send(sender=None, socket_obj=socket)
示例10: create
def create(cls, server_id, char_id, club_name, club_flag):
from core.staff import StaffManger
from core.formation import Formation
from core.mail import MailManager
from apps.config.models import Mail as ModelMail
doc = MongoCharacter.document()
doc['_id'] = char_id
doc['create_at'] = arrow.utcnow().timestamp
doc['name'] = club_name
doc['flag'] = club_flag
doc['gold'] = CHAR_INIT_GOLD
doc['diamond'] = CHAR_INIT_DIAMOND
doc['crystal'] = CHAR_INIT_CRYSTAL
doc['gas'] = CHAR_INIT_GAS
sm = StaffManger(server_id, char_id)
formation_init_data = []
for staff_id, unit_id in CHAR_INIT_STAFFS:
uid = sm.add(staff_id, send_notify=False, trig_signal=False)
formation_init_data.append((uid, unit_id))
fm = Formation(server_id, char_id)
fm.initialize(formation_init_data)
MongoCharacter.db(server_id).insert_one(doc)
# add welfare mail
start_time = get_start_time_of_today()
condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\
Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))
mails = ModelMail.objects.filter(condition)
m = MailManager(server_id, char_id)
for m_obj in mails:
if not m_obj.welfare:
continue
ok = False
if m_obj.condition_type == 1:
ok = True
elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value():
ok = True
elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value():
ok = True
if not ok:
continue
if m_obj.items:
rc = ResourceClassification.classify(m_obj.get_parsed_items())
attachment = rc.to_json()
else:
attachment = ""
m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
示例11: _add_equip_attrs
def _add_equip_attrs(self):
from core.item import Equipment
f = Formation(self.char_id)
socket = f.find_socket_by_hero(self.id)
if not socket:
return
# 先把装备数值加到人物上
equipments = []
for x in ['weapon', 'armor', 'jewelry']:
equip_id = getattr(socket, x)
if equip_id:
equip = Equipment(self.char_id, equip_id)
self.attack += equip.attack
self.defense += equip.defense
self.hp += equip.hp
equipments.append(equip)
# 然后加成人物的专属装备
additions = {}
special_equipments = self.model_hero.special_equipments
if special_equipments:
for equip in equipments:
_cls = equip.equip.cls
if _cls not in special_equipments:
continue
_tp = equip.equip.tp
additions[_tp] = additions.get(_tp, 0) + special_equipments[_cls]
for _tp, _add_percent in additions.items():
if _tp == 1:
# attack
self.attack *= (1 + _add_percent / 100.0)
elif _tp == 2:
# defense
self.defense *= (1 + _add_percent / 100.0)
else:
# hp
self.hp *= (1 + _add_percent / 100.0)
self.hp = int(self.hp)
# 最后再把宝石加上
for equip in equipments:
for k, v in equip.gem_attributes.iteritems():
value = getattr(self, k)
setattr(self, k, value + v)
# 马
if socket.horse:
horse = Horse(self.char_id).mongo_horse.horses[str(socket.horse)]
self.attack += horse.attack
self.defense += horse.defense
self.hp += horse.hp
self.crit += int(HORSE[horse.oid].crit / 10)
示例12: power
def power(self):
f = Formation(self.id)
hero_ids = f.in_formation_hero_ids()
p = 0
for hid in hero_ids:
if hid == 0:
continue
h = Hero.cache_obj(hid)
p += h.power
return p
示例13: load_units
def load_units(self):
from core.formation import Formation
units = {}
""":type: dict[int, Unit]"""
doc = MongoUnit.db(self.server_id).find_one({'_id': self.char_id})
for _id, _data in doc['units'].iteritems():
u = Unit(self.server_id, self.char_id, int(_id), _data)
u.calculate()
u.make_cache()
units[int(_id)] = u
race = {
1: {'level': 0, 'step': 0},
2: {'level': 0, 'step': 0},
3: {'level': 0, 'step': 0},
}
for _, u in units.iteritems():
race[u.config.race]['level'] += u.level
race[u.config.race]['step'] += u.step
additions = {
1: UnitAddition(),
2: UnitAddition(),
3: UnitAddition(),
}
for k, v in additions.iteritems():
_level_addition = ConfigUnitAddition.get_level_addition(k, race[k]['level'])
_step_addition = ConfigUnitAddition.get_step_addition(k, race[k]['step'])
if _level_addition:
for attr in UnitAddition.__slots__:
v.add_property(attr, getattr(_level_addition, attr))
if _step_addition:
for attr in UnitAddition.__slots__:
v.add_property(attr, getattr(_step_addition, attr))
# 只作用于上阵兵种
in_format_staffs = Formation(self.server_id, self.char_id).in_formation_staffs()
for k, v in in_format_staffs.iteritems():
if not v['unit_id']:
continue
u = units[v['unit_id']]
_add = additions[u.config.race]
for attr in UnitAddition.__slots__:
_old_value = getattr(u, attr)
_new_value = _old_value + getattr(_add, attr)
setattr(u, attr, _new_value)
u.make_cache()
示例14: load_formation_staffs
def load_formation_staffs(self):
# NOTE: 这段代码其实是从 Club.force_load_staffs 抄来的
from core.formation import Formation
from core.unit import UnitManager
from core.talent import TalentManager
from core.collection import Collection
from core.party import Party
from core.inspire import Inspire
self.formation_staffs = []
""":type: list[core.staff.Staff]"""
sm = StaffManger(self.server_id, self.char_id)
fm = Formation(self.server_id, self.char_id)
um = UnitManager(self.server_id, self.char_id)
ins = Inspire(self.server_id, self.char_id)
staffs = sm.get_staffs_data()
in_formation_staffs = self.in_formation_staffs()
for k, v in in_formation_staffs.iteritems():
obj = Staff(self.server_id, self.char_id, k, staffs[k])
self.formation_staffs.append(obj)
obj.policy = in_formation_staffs[k]['policy']
obj.formation_position = in_formation_staffs[k]['position']
unit_id = in_formation_staffs[k]['unit_id']
if unit_id:
obj.set_unit(um.get_unit_object(unit_id))
club = Club(self.server_id, self.char_id, load_staffs=False)
club.formation_staffs = self.formation_staffs
working_staff_oids = self.working_staff_oids()
for obj in self.formation_staffs:
obj.check_qianban(working_staff_oids)
obj.add_self_talent_effect(club)
talent_effects_1 = TalentManager(self.server_id, self.char_id).get_talent_effects()
talent_effects_2 = Collection(self.server_id, self.char_id).get_talent_effects()
talent_effects_3 = fm.get_talent_effects()
talent_effects_4 = Party(self.server_id, self.char_id).get_talent_effects()
club.add_talent_effects(talent_effects_1)
club.add_talent_effects(talent_effects_2)
club.add_talent_effects(talent_effects_3)
club.add_talent_effects(talent_effects_4)
config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config()
for obj in self.formation_staffs:
obj.config_inspire_level_addition = config_inspire_level_addition
obj.config_inspire_step_addition = config_inspire_step_addition
obj.calculate()
示例15: load_staffs
def load_staffs(self):
from core.staff import StaffManger
from core.formation import Formation
self.formation_staffs = []
sm = StaffManger(self.server_id, self.char_id)
fm = Formation(self.server_id, self.char_id)
for k in fm.in_formation_staffs():
self.formation_staffs.append(sm.get_staff_object(k))