def score_simple(player, coin, amount, game=None, formula=None, external_id=None, percents=100): """ Give amount of coin to the player. """ if not isinstance(game, Game) and game is not None: game = game.get_instance() if not isinstance(player, Player): raise InvalidScoreCall() user = player.user player = user.get_profile() user = player.user coin = Coin.get(coin) formula = Formula.get(formula) computed_amount = 1.0 * amount * percents / 100 hs = History.add(user=user, coin=coin, amount=computed_amount, game=game, formula=formula, external_id=external_id, percents=percents) # update user.points asap if coin.name == 'points': if player.magic.has_modifier('top-disguise'): computed_amount = 1.0 * computed_amount * player.magic.modifier_percents( 'top-disguise') / 100 player.points += computed_amount player.save() update_points(player, game) logging.debug("Scored %s with %f %s" % (user, computed_amount, coin)) return hs
def user_profile(request, id, page=u'1'): profile = get_object_or_404(Player, id=id) activity_list = Activity.get_player_activity(profile) top_user = profile.get_extension(TopUser) history = History.user_points(profile.user) paginator = Paginator(activity_list, 10) try: activity = paginator.page(page) except (EmptyPage, InvalidPage): activity = paginator.page(paginator.num_pages) # some hackish introspection if hasattr(g, 'user_model'): model = getattr(g, 'user_model') setattr(profile, model.__name__.lower(), profile.get_extension(model)) #Fix to show succes message from report user form if 'report_msg' in request.session: message = request.session['report_msg'] del request.session['report_msg'] else: message = '' challenge_launched_recently = Challenge.exist_last_day( date.today(), request.user.get_profile(), profile) specialquest_button = SpecialQuestGame.get_specialquest_user_button( request, profile) return render_to_response('profile/profile.html', { 'profile': profile, 'activity': activity, 'top': top_user, 'scoring': history, 'challenge_launched_recently': challenge_launched_recently, 'specialquest_button': specialquest_button, 'message': message }, context_instance=RequestContext(request))
def user_coins(user): """ Returns a dictionary with user coins """ if not isinstance(user, User): user = user.user return History.user_coins(user)
def inf(self): return History.user_coins(user=self)['penalty']
def test_user_coins(self): Coin.add('points') Coin.add('gold') player = self._get_player() self.assertIn('points', History.user_coins(player.user))
def coins(self): # TODO check usage and deprecate this function from wouso.core.scoring.models import History return History.user_coins(self.user)
def gold_amount(player): """ Return player's amount of gold """ coins = History.user_coins(player) return coins['gold']