本文整理汇总了Python中wouso.core.god.God类的典型用法代码示例。如果您正苦于以下问题:Python God类的具体用法?Python God怎么用?Python God使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了God类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: basic_cast
def basic_cast(self, player_dest, spell, due):
# Pre-cast God actions: immunity and curse ar done by this
# check
can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
if not can_cast:
return error
try:
psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
except IntegrityError:
if not spell.mass:
return 'Cannot cast the same spell more than once'
# extend the affected time by spell
psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
if psdue.due < due:
psdue.delete()
psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
else:
return None
if psdue.source == psdue.player:
signal_msg = _("cast a spell on himself/herself")
else:
signal_msg = _("cast a spell on {to} ")
signals.addActivity.send(sender=None, user_from=psdue.source,
user_to=psdue.player,
message=signal_msg,
arguments=dict(to=psdue.player),
action='cast',
game=None)
# Post-cast God action (there are specific modifiers, such as clean-spells
# that are implemented in God
God.post_cast(psdue)
return None
开发者ID:cvicentiu,项目名称:wouso,代码行数:35,代码来源:manager.py
示例2: player_race
def player_race(request, race_id):
race = get_object_or_404(Race, pk=race_id)
top_users = race.player_set.order_by('-points')
activity_qs = Activity.get_race_activity(race)
paginator = Paginator(activity_qs, 20)
activity = paginator.page(1)
# get top position
races = list(Race.objects.filter(can_play=True))
races.sort(key=lambda a: a.points, reverse=True)
if race in races:
top_rank = races.index(race) + 1
else:
top_rank = '-'
groups = NewHistory.get_children_top(race, PlayerGroup)
# Get levels
levels = []
for i, limit in enumerate(God.get_level_limits()):
l = God.get_race_level(level_no=i + 1, race=race)
l.limit = limit
levels.append(l)
return render_to_response('profile/race.html',
{'race': race,
'children': groups,
'top_users': top_users,
'top_rank': top_rank,
'top': ObjectHistory(),
'activity': activity,
'levels': levels},
context_instance=RequestContext(request)
)
开发者ID:gabrielivascu,项目名称:wouso,代码行数:35,代码来源:views.py
示例3: cast_spell
def cast_spell(self, spell, source, due):
""" Curse self with given spell from source, for due time. """
try:
psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
assert psamount.amount > 0
except (PlayerSpellAmount.DoesNotExist, AssertionError):
return False
# Pre-cat God actions: immunity and curse ar done by this
# check
if not God.can_cast(spell, source, self):
return False
try:
psdue = PlayerSpellDue.objects.create(player=self, source=source, spell=spell, due=due)
except Exception as e:
logging.exception(e)
return False
# Post-cast God action (there are specific modifiers, such as clean-spells
# that are implemented in God
God.post_cast(psdue)
psamount.amount -= 1
if psamount.amount == 0:
psamount.delete()
else:
psamount.save()
return True
开发者ID:MathPlayer,项目名称:wouso--older-,代码行数:27,代码来源:models.py
示例4: cast_spell
def cast_spell(self, spell, source, due):
""" Cast a spell on this player.
Returns: error message if the spell was not cast, or None
"""
try:
psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
assert psamount.amount > 0
except (PlayerSpellAmount.DoesNotExist, AssertionError):
return 'Spell unavailable'
# Pre-cast God actions: immunity and curse ar done by this
# check
can_cast, error = God.can_cast(spell, source, self.player)
if not can_cast:
return error
try:
psdue = PlayerSpellDue.objects.create(player=self.player, source=source, spell=spell, due=due)
except IntegrityError:
return 'Cannot cast the same spell more than once'
# Post-cast God action (there are specific modifiers, such as clean-spells
# that are implemented in God
God.post_cast(psdue)
psamount.amount -= 1
if not psamount.amount:
psamount.delete()
else:
psamount.save()
return None
开发者ID:ciprianf,项目名称:wouso,代码行数:31,代码来源:manager.py
示例5: management_task
def management_task(cls, datetime=lambda: datetime.now(), stdout=sys.stdout):
spells = PlayerSpellDue.get_expired(datetime)
stdout.write(" %d expired spells\n" % spells.count())
for s in spells:
SpellHistory.expired(s.player, s.spell)
from wouso.core.god import God
God.post_expire(psdue=s)
s.delete()
开发者ID:cvicentiu,项目名称:wouso,代码行数:10,代码来源:models.py
示例6: get_context_data
def get_context_data(self, **kwargs):
context = super(ArtifactHomeView, self).get_context_data(**kwargs)
modifiers = God.get_all_modifiers()
groups = ArtifactGroup.objects.all()
context.update(
{'groups': groups, 'group': self.group, 'modifiers': modifiers})
return context
开发者ID:TobyWanKenobi,项目名称:wouso,代码行数:7,代码来源:views.py
示例7: update_points
def update_points(player, game):
level = God.get_level_for_points(player.points)
if level != player.level_no:
if level < player.level_no:
amount = calculate('level-gold', level=player.level_no).get('gold', 0)
action_msg = 'gold-lost'
signal_msg = ugettext_noop("downgraded to level {level} and lost {amount} gold")
rollback(player, None, 'level-gold', external_id=player.level_no)
signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level, amount=amount),
game=game, action=action_msg)
else:
amount = calculate('level-gold', level=level)
# Check if the user has previously reached this level
if level > player.max_level:
# Update the maximum reached level
player.max_level = level
# Offer the corresponding amount of gold
score(player, None, 'level-gold', external_id=level, level=level)
else:
# The user should not receive additional gold
amount['gold'] = 0
signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
action_msg = 'gold-won'
signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level, amount=amount['gold']),
game=None, action=action_msg)
player.level_no = level
player.save()
开发者ID:Ciocirlan,项目名称:wouso,代码行数:32,代码来源:sm.py
示例8: update_points
def update_points(player, game):
level = God.get_level_for_points(player.points)
if level != player.level_no:
if level < player.level_no:
signal_msg = ugettext_noop("downgraded to level {level}")
signals.addActivity.send(
sender=None,
user_from=player,
user_to=player,
message=signal_msg,
arguments=dict(level=level),
game=game,
)
else:
amount = calculate("level-gold", level=level)
signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
score(player, None, "level-gold", level=level)
signals.addActivity.send(
sender=None,
user_from=player,
user_to=player,
message=signal_msg,
arguments=dict(level=level, amount=amount["gold"]),
game=None,
)
player.level_no = level
player.save()
开发者ID:andreip,项目名称:wouso,代码行数:27,代码来源:sm.py
示例9: update_points
def update_points(player, game):
level = God.get_level_for_points(player.points)
if level == player.level_no:
return
arguments = dict(level=level)
if level < player.level_no:
action_msg = 'level-downgrade'
signal_msg = ugettext_noop("downgraded to level {level}")
this_game = game
else:
action_msg = 'level-upgrade'
# Check if the user has previously reached this level
if level > player.max_level:
# Update the maximum reached level
player.max_level = level
# Offer the corresponding amount of gold
score(player, None, 'level-gold', external_id=level, level=level)
signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
amount = calculate('level-gold', level=level).get('gold', 0)
arguments['amount'] = amount
else:
# The user should not receive additional gold
signal_msg = ugettext_noop("upgraded back to level {level}")
this_game = None
signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level),
game=game, action=action_msg)
开发者ID:damianr13,项目名称:wouso,代码行数:32,代码来源:sm.py
示例10: give_modifier
def give_modifier(self, modifier, amount=1):
""" Add given amount to existing, or create new artifact amount
for the current user.
Return the PlayerArtifactAmount object after applying changes.
"""
if amount <= 0:
return
# Check for existing artifact
try:
paamount = PlayerArtifactAmount.objects.get(player=self.player, artifact__name=modifier)
except PlayerArtifactAmount.DoesNotExist:
paamount = 0
if not paamount:
artifact = God.get_artifact_for_modifier(modifier, self.player)
if not artifact:
logging.debug('No such artifact: %s' % modifier)
return None
paamount = PlayerArtifactAmount.objects.create(player=self.player, artifact=artifact, amount=amount)
else:
paamount.amount += amount
paamount.save()
return paamount
开发者ID:AndreiRO,项目名称:wouso,代码行数:25,代码来源:manager.py
示例11: sync_user
def sync_user(player):
""" Synchronise user points with database
"""
coin = Coin.get('points')
points = real_points(player)
if player.points != points and not player.magic.has_modifier('top-disguise'):
logging.debug('%s had %d instead of %d points' % (player, player.points, points))
player.points = points
player.level_no = God.get_level_for_points(player.points)
player.save()
开发者ID:damianr13,项目名称:wouso,代码行数:10,代码来源:sm.py
示例12: can_challenge
def can_challenge(self, user):
""" Check if the target user is available.
"""
user = user.get_extension(ChallengeUser)
if self.user == user.user:
# Cannot challenge myself
return False
if user.has_modifier('challenge-cannot-be-challenged'):
return False
return God.user_can_interact_with(self, user, game=ChallengeGame)
开发者ID:alexef,项目名称:wouso-1,代码行数:10,代码来源:models.py
示例13: sync_user
def sync_user(player):
""" Synchronise user points with database
"""
coin = Coin.get("points")
result = History.objects.filter(user=player.user, coin=coin).aggregate(total=models.Sum("amount"))
points = result["total"] if result["total"] is not None else 0
if player.points != points and not player.magic.has_modifier("top-disguise"):
logging.debug("%s had %d instead of %d points" % (player, player.points, points))
player.points = points
player.level_no = God.get_level_for_points(player.points)
player.save()
开发者ID:andreip,项目名称:wouso,代码行数:11,代码来源:sm.py
示例14: sync_user
def sync_user(player):
""" Synchronise user points with database
"""
coin = Coin.get('points')
result = History.objects.filter(user=player.user,coin=coin).aggregate(total=models.Sum('amount'))
points = result['total'] if result['total'] is not None else 0
if player.points != points:
logging.debug('%s had %d instead of %d points' % (player, player.points, points))
player.points = points
player.level_no = God.get_level_for_points(player.points)
player.save()
开发者ID:LucianU,项目名称:wouso,代码行数:11,代码来源:sm.py
示例15: can_challenge
def can_challenge(self, user):
""" Check if the target user is available.
"""
user = user.get_extension(ChallengeUser)
if self.user == user.user:
# Cannot challenge myself
logging.info("User cannot challenge because it is the same user.")
return False
if user.magic.has_modifier('challenge-cannot-be-challenged'):
logging.info("User cannot challenge due to magic modifier.")
return False
return God.user_can_interact_with(self, user, game=ChallengeGame)
开发者ID:MathPlayer,项目名称:wouso,代码行数:12,代码来源:models.py
示例16: update_points
def update_points(player, game):
level = God.get_level_for_points(player.points)
if level != player.level_no:
if level < player.level_no:
signal_msg = ugettext_noop("downgraded to level {level}")
else:
signal_msg = ugettext_noop("upgraded to level {level}")
signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level),
game=game)
player.level_no = level
player.save()
开发者ID:LucianU,项目名称:wouso,代码行数:14,代码来源:sm.py
示例17: basic_cast
def basic_cast(self, player_dest, spell, due):
# Pre-cast God actions: immunity and curse ar done by this
# check
can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
if not can_cast:
return error
try:
psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
except IntegrityError:
if not spell.mass:
return 'Cannot cast the same spell more than once'
#extend the affected time by spell
psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
if psdue.due < due:
psdue.delete()
psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
else:
return None
# Post-cast God action (there are specific modifiers, such as clean-spells
# that are implemented in God
God.post_cast(psdue)
return None
开发者ID:TomyRO,项目名称:wouso,代码行数:24,代码来源:manager.py
示例18: give_modifier
def give_modifier(self, modifier, amount):
""" Add given amount to existing, or creat new artifact amount
for the current user.
"""
if amount <= 0:
return
paamount = self.has_modifier(modifier)
if not paamount:
artifact = God.get_artifact_for_modifier(modifier, self)
paamount = PlayerArtifactAmount.objects.create(player=self, artifact=artifact, amount=amount)
else:
paamount.amount += amount
paamount.save()
return paamount
开发者ID:MathPlayer,项目名称:wouso--older-,代码行数:15,代码来源:models.py
示例19: artifact_home
def artifact_home(request, group=None):
if group is None:
group = 'Default'
group = get_object_or_404(ArtifactGroup, name=group)
artifacts = group.artifact_set.all()
modifiers = God.get_all_modifiers()
return render_to_response('cpanel/artifact_home.html',
{'groups': ArtifactGroup.objects.all(),
'artifacts': artifacts,
'module': 'artifacts',
'group': group,
'modifiers': modifiers,
},
context_instance=RequestContext(request))
开发者ID:dragoscalinescu,项目名称:wouso,代码行数:16,代码来源:views.py
示例20: setup
def setup():
""" Prepare database for Scoring """
for cc in CORE_POINTS:
if not Coin.get(cc):
Coin.add(cc, name=cc)
# special case, gold is integer
gold = Coin.get('gold')
gold.integer = True
gold.save()
# iterate through games and register formulas
for game in get_games():
for formula in game.get_formulas():
if not Formula.get(formula.id):
Formula.add(formula)
# add wouso formulas
for formula in God.get_system_formulas():
if not Formula.get(formula.id):
Formula.add(formula)
开发者ID:LucianU,项目名称:wouso,代码行数:19,代码来源:sm.py
注:本文中的wouso.core.god.God类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论