def post_cast(sender, **kwargs): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ try: psdue = kwargs['psdue'] except: return # Log usage to SpellHistory SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Special actions if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: signals.postExpire.send(sender=None, psdue=psd) psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): signals.postExpire.send(sender=None, psdue=psd) psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'top-disguise': psdue.player.points = 1.0 * psdue.player.points * psdue.player.magic.modifier_percents('top-disguise') / 100 psdue.player.save() return False
def bazaar_buy(request, spell): spell = get_object_or_404(Spell, pk=spell) player = request.user.get_profile() error, message = '','' if Bazaar.disabled(): error = _("Magic is disabled") elif spell.price > player.coins.get('gold', 0): error = _("Insufficient gold amount") elif spell.available == False: error = _("Spell is not available") elif spell.level_required > player.level_no: error = _("Level {level} is required to buy this spell").format(level=spell.level_required) else: player.magic.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) signal_msg = ugettext_noop('bought a spell') action_msg = 'spell-buy' signals.addActivity.send(sender=None, user_from=player, user_to=player, message=signal_msg, game=None, action=action_msg, public=False) SpellHistory.bought(player, spell) message = _("Successfully aquired") return bazaar(request, message=message, error=error)
def post_cast(self, psdue): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ # Log usage to SpellHistory SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Special actions if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: self.post_expire(psd) psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): self.post_expire(psd) psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'steal': psdue.player.steal_points(psdue.source, psdue.spell.percents) psdue.delete() return True if psdue.spell.name == 'top-disguise': psdue.player.points = 1.0 * psdue.player.points * psdue.player.magic.modifier_percents( 'top-disguise') / 100 psdue.player.save() return False
def post_cast(sender, **kwargs): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ try: psdue = kwargs['psdue'] except: return # Log usage to SpellHistory SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Special actions if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: signals.postExpire.send(sender=None, psdue=psd) psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): signals.postExpire.send(sender=None, psdue=psd) psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'top-disguise': psdue.player.points = 1.0 * psdue.player.points * psdue.player.magic.modifier_percents( 'top-disguise') / 100 psdue.player.save() return False
def bazaar_buy(request, spell): spell = get_object_or_404(Spell, pk=spell) player = request.user.get_profile() error, message = '', '' if Bazaar.disabled(): error = _("Magic is disabled") elif spell.price > player.coins.get('gold', 0): error = _("Insufficient gold amount") elif spell.available == False: error = _("Spell is not available") elif spell.level_required > player.level_no: error = _("Level {level} is required to buy this spell").format( level=spell.level_required) else: player.magic.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) signal_msg = ugettext_noop('bought a spell') action_msg = 'spell-buy' signals.addActivity.send(sender=None, user_from=player, user_to=player, message=signal_msg, game=None, action=action_msg, public=False) SpellHistory.bought(player, spell) message = _("Successfully aquired") return bazaar(request, message=message, error=error)
def post_cast(self, psdue): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ # Always executed, so log SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Also trigger anonymous activiy from wouso.interface.activity import signals if psdue.source == psdue.player: signal_msg = 'a facut o vraja asupra sa.' else: signal_msg = 'a facut o vraja asupra {to}.' signals.addActivity.send(sender=None, user_from=psdue.source, user_to=psdue.player, message=signal_msg, arguments=dict(to=psdue.player), game=None) if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'steal': psdue.player.steal_points(psdue.source, psdue.spell.percents) psdue.delete() return True return False
def create(self, request): attrs = self.flatten_dict(request.POST) if 'spell' not in attrs.keys(): return {'success': False, 'error': 'Spell not provided'} try: spell = int(attrs['spell']) spell = Spell.objects.get(pk=spell) except (ValueError, Spell.DoesNotExist): return {'success': False, 'error': 'No such spell'} # TODO refactor player = request.user.get_profile() if spell.price > player.coins.get('gold', 0): return {'success': False, 'error': 'Insufficient gold'} else: player.magic.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) SpellHistory.bought(player, spell) return {'success': True}
def post_cast(self, psdue): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ # Log usage to SpellHistory SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Special actions if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: self.post_expire(psd) psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): self.post_expire(psd) psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'steal': psdue.player.steal_points(psdue.source, psdue.spell.percents) psdue.delete() return True if psdue.spell.name == 'top-disguise': psdue.player.points = 1.0 * psdue.player.points * psdue.player.magic.modifier_percents('top-disguise') / 100 psdue.player.save() return False
def bazaar_buy(request, spell): spell = get_object_or_404(Spell, pk=spell) player = request.user.get_profile() error, message = '','' if spell.price > player.coins.get('gold', 0): error = _("Insufficient gold amount") else: player.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) SpellHistory.bought(player, spell) message = _("Successfully aquired") return bazaar(request, message=message, error=error) # TODO: use django-flash """
def post_cast(self, psdue): """ Execute action after a spell is cast. This is used to implement specific spells such as 'clean any existing spell' cast. Returns True if action has been taken, False if not. """ # Always executed, so log SpellHistory.used(psdue.source, psdue.spell, psdue.player) # Also trigger anonymous activiy from wouso.interface.activity import signals if psdue.source == psdue.player: signal_msg = 'a facut o vraja asupra sa.' else: signal_msg = 'a facut o vraja asupra {to}.' action_msg = 'cast' signals.addActivity.send(sender=None, user_from=psdue.source, user_to=psdue.player, message=signal_msg, arguments=dict(to=psdue.player), action=action_msg, game=None) if psdue.spell.name == 'dispell': for psd in psdue.player.magic.spells: self.post_expire(psd) psd.delete() return True if psdue.spell.name == 'cure': for psd in psdue.player.magic.spells.filter(spell__type='n'): self.post_expire(psd) psd.delete() # also delete itself psdue.delete() return True if psdue.spell.name == 'steal': psdue.player.steal_points(psdue.source, psdue.spell.percents) psdue.delete() return True if psdue.spell.name == 'top-disguise': psdue.player.points = 1.0 * psdue.player.points * psdue.player.magic.modifier_percents( 'top-disguise') / 100 psdue.player.save() return False
def bazaar_buy(request, spell): spell = get_object_or_404(Spell, pk=spell) player = request.user.get_profile() error, message = '','' if spell.price > player.coins.get('gold', 0): error = _("Insufficient gold amount") elif spell.available == False: error = _("Spell is not available") elif spell.level_required > player.level_no: error = _("Level {level} is required to buy this spell").format(level=spell.level_required) else: player.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) SpellHistory.bought(player, spell) message = _("Successfully aquired") return bazaar(request, message=message, error=error)
def create(self, request): attrs = self.flatten_dict(request.POST) if 'spell' not in attrs.keys(): return {'success': False, 'error': 'Spell not provided'} try: spell = int(attrs['spell']) spell = Spell.objects.get(pk=spell) except (ValueError, Spell.DoesNotExist): return {'success': False, 'error': 'No such spell'} # TODO refactor player = request.user.get_profile() if spell.price > player.coins.get('gold', 0): return {'success': False, 'error': 'Insufficient gold'} else: player.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) SpellHistory.bought(player, spell) return {'success': True}
def bazaar_buy(request, spell): spell = get_object_or_404(Spell, pk=spell) player = request.user.get_profile() error, message = '', '' if spell.price > player.coins.get('gold', 0): error = _("Insufficient gold amount") elif spell.available == False: error = _("Spell is not available") elif spell.level_required > player.level_no: error = _("Level {level} is required to buy this spell").format( level=spell.level_required) else: player.add_spell(spell) scoring.score(player, None, 'buy-spell', external_id=spell.id, price=spell.price) SpellHistory.bought(player, spell) message = _("Successfully aquired") return bazaar(request, message=message, error=error)
def main(args): print "THIS IS DEPRECATED. Use `./manage.py wousocron' instead" try: init() except: print "No wouso/settings.py file. Maybe you can symlink the example file?" sys.exit(1) from wouso.core.user.models import Player, PlayerGroup from wouso.interface.top.models import TopUser, History today = date.today() print 'Updating users with date: ', today for i,u in enumerate(Player.objects.all().order_by('-points')): topuser = u.get_extension(TopUser) position = i + 1 hs, new = History.objects.get_or_create(user=topuser, date=today, relative_to=None) hs.position, hs.points = position, u.points hs.save() print 'Updating group history: ' for p in PlayerGroup.objects.all(): p.points = p.live_points p.save() # get position on distinct classes #TODO fixme for cls in PlayerGroup.objects.values_list('gclass').distinct(): cls = cls[0] for i,p in enumerate(PlayerGroup.objects.filter(gclass=cls).order_by('-points')): position = i + 1 hs, new = History.objects.get_or_create(group=p, date=today, relative_to=None) hs.position, hs.points = position, p.points hs.save() print 'Updating user relative to group position: ' for g in PlayerGroup.objects.all(): for i,u in enumerate(g.players.order_by('-points')): topuser = u.get_extension(TopUser) position = i + 1 hs, new = History.objects.get_or_create(user=topuser, date=today, relative_to=g) hs.position, hs.points = position, p.points hs.save() print 'Updating group relative to parent group position: ' for g in PlayerGroup.objects.all(): if g.children: for i,c in enumerate(g.children.order_by('-points')): position = i + 1 hs, new = History.objects.get_or_create(group=c, date=today, relative_to=g) hs.position, hs.points = position, p.points hs.save() from wouso.games.challenge.models import Challenge challenges = Challenge.get_expired(today) print 'Updating expired challenges ', len(challenges) for c in challenges: if c.is_launched(): # launched before yesterday, automatically refuse c.refuse(auto=True) else: # launched and accepted before yesterday, but not played by both c.set_expired() spells = PlayerSpellDue.get_expired(today) print 'Updating expired spells (%d)' % spells.count() for s in spells: SpellHistory.expired(s.player, s.spell) s.delete() print 'Done.'