def start(self): self.title = u'Рынок' sp = spell.get(self.spell_id) self.text = u'Торговец предлагает вам купить заклинание %s за %s золотых.' % (sp.name, self.price) self.options = _(u''' agree: Согласиться exit: Отказаться ''')
def agree(self): if self.user['gold'] >= self.price: s = spell.get(self.spell_id) self.user.private_message(u'Вы купили {:s} за %s золотых.' % self.price, s.js_link()) self.user['gold'] -= self.price self.user['reserve'].add(s.id) return False else: self.text = u'У вас не хватает золота!'
def shop_sell(self): self._checkloc("shop") spell_id = self.q["spell_id"] if not self.user['reserve'].has(spell_id): self._error('User doesn\'t have this card') s = spell.get(spell_id) sell_price = int(round(s.price * 0.25)) self.user["reserve"].remove(s.id) self.user["gold"] += sell_price self.user.save() return None
def shop_buy(self): self._checkloc("shop") s = spell.get(self.q["spell_id"]) if not s.shop: self._error("Not for sell") if self.user["gold"] < s.price: self._reject("Not enough gold") self.user["gold"] -= s.price self.user["reserve"].add(s.id) self.user.save() return None
def process_casts(self): ''' Обработка кастов заклинаний ''' to_cast = [(f.card_in_hand_by_id(f.move["card"]).spell, f, self.fighter_by_id(f.move["cast_target"]), f.card_in_hand_by_id(f.move["card"])) for f in self.fighters() if f.move and f.move.get("card")] to_cast += [(spell.get(f.move["spell"]), f, self.fighter_by_id(f.move["cast_target"]), None) for f in self.fighters() if f.move and f.move.get("spell")] to_cast.sort(key=lambda item: item[0].priority) for (sp, caster, target, card) in to_cast: if not caster.can_move(): continue caster.mana += sp.mana sp._cast(caster, target) if card: caster.hand.remove(card)
def deck_edit(self): user = self.user if user["loc"] == "fight" and user.fight().status != "over": self._error("Cannot edit deck while fighting") qdeck = self.q["deck"] qres = self.q["reserve"] if sum(qdeck.itervalues()) < constants.min_deck: self._error("Invalid deck") qq = combine_counter_dicts(qdeck, qres) old = combine_counter_dicts(user["deck"].dict, user["reserve"].dict) if qq != old: self._error("Invalid card set") uniques = 0 for id, count in qdeck.iteritems(): s = spell.get(id) if count > constants.max_cards[s.rarity]: self._error("Too many cards: " + id) if s.rarity >= 3: uniques += count if uniques > 1: self._error("Too many uniques!") user.update({"deck": deck.Deck(qdeck), "reserve": deck.Deck(qres)}) return None
def select_target(self): try: return random.choice(spell.get(self.spell).targets(self.fighter)).id except IndexError: return None
def js(self): return {"dict": self.dict, "spells": dict((id, spell.get(id).js()) for id in self.dict.iterkeys())}
def js_load(obj): global spell_module if spell_module == None: import spell as spell_module return spell_module.get(obj)
def open(self): ensure_imports() return OpenLoot(self._type, spell.get(self.spell_id))
def spell(self): if self._spell == None: self._spell = spell.get(self.spell_id) return self._spell