def log_aid(nation, target, resource, amount): value = get_value(resource, amount) query = nation.outgoing_aid.filter(resource=resource, reciever=target, timestamp__gte=v.now() - timezone.timedelta(minutes=10)) if query.exists(): query.update(amount=F('amount') + amount, value=F('value') + value) else: nation.outgoing_aid.create(reciever=target, resource=resource, amount=amount, value=value) #now for action logging query = nation.actionlogs.filter(action='Sent aid', extra=resource, timestamp__gte=v.now() - timezone.timedelta(minutes=10)) if query.exists(): query.update(amount=F('amount') + 1) else: nation.actionlogs.create(action='Sent aid', extra=resource)
def delete_war(request, target): if request.POST['deletewar'] == 'offensive': war = target.offensives.filter( over=False)[0] #there's only 1 because 1 war limit otherguy = war.defender.name adj = 'offensive' else: war = target.defensives.filter(over=False)[0] otherguy = war.attacker.name adj = 'defensive' log = war.warlog log.timeend = v.now() log.save() war.delete() return "%s war against %s has been deleted" % (adj, otherguy), otherguy
def test_vacation_actions(self): expected = v.vacationtimer() enter_vacation(self.mod, self.pleb, 'placing in vacation') self.pleb.settings.refresh_from_db() self.pleb.refresh_from_db() self.assertEqual(self.pleb.vacation, True) self.assertEqual(self.pleb.settings.vacation_timer > expected, True) self.assertEqual( self.mod.mod_actions.filter(action__icontains='vacation', reason='placing in vacation').exists(), True) exit_vacation(self.mod, self.pleb, 'removing from vacation') self.pleb.refresh_from_db() expected = v.now() self.pleb.settings.refresh_from_db() self.assertEqual(self.pleb.vacation, False) self.assertEqual(self.pleb.settings.vacation_timer < expected, True) self.assertEqual( self.mod.mod_actions.filter( action__icontains='vacation', reason='removing from vacation').exists(), True)
def _log(self): #policy logging #logs policies so mods can see who did what, and when #oh and how many times lol log, created = self.nation.actionlogs.get_or_create( timestamp__gte=v.now() - v.timezone.timedelta(minutes=15), action=self.name) new_cost = self.cost if not created: #updates the json encoded cost so it's a total cost = json.loads(log.cost) for field in new_cost: if field in cost: cost[field] += new_cost[field] else: cost[field] = new_cost[field] new_cost = cost log.amount += 1 log.cost = json.dumps(new_cost) log.action = self.name log.policy = True log.save()
def send_aid(*args, **kwargs): nation = kwargs.pop('nation') target = kwargs.pop('target') POST = kwargs.pop('POST') form = ajaxaidform(nation, POST) if form.is_valid(): resource = form.cleaned_data['resource'] if resource in v.resources: aid_amount = form.cleaned_data['amount'] if nation.outgoing_aidspam.filter( reciever=target, resource=resource, amount=aid_amount, timestamp__gte=v.now() - timezone.timedelta(minutes=10)).count() > 5: return {'result': 'no'} market = Market.objects.latest('pk') tariff = 0 if (nation.economy < 33 and target.economy > 66) or (target.economy < 33 and nation.economy > 66): tariff += 10 if (nation.alignment == 3 and target.alignment == 1) or (target.alignment == 3 and nation.alignment == 1): tariff += 10 if resource != 'budget': tariff = aid_amount * tariff tb = market.__dict__['%sprice' % resource] * aid_amount else: tariff = (int(aid_amount * 0.1) if tariff > 0 else 0) tb = aid_amount nation.__dict__[resource] -= aid_amount target.__dict__[resource] += aid_amount nation.trade_balance -= tb target.trade_balance += tb news.aidnews(nation, target, resource, aid_amount) #to decrease clutter, merge aidlogs < 10 minutes old #so instead of 2x $9999k aid logs, it's 1x $19998k log nation.outgoing_aidspam.create(resource=resource, reciever=target, amount=aid_amount) result = "%s has recieved %s!" % (target.name, v.pretty(aid_amount, resource)) #feeeeees :D uf = [resource, 'trade_balance'] if tariff > 0: result += " But the differences between our systems resulted in $%sk in tariffs!" % tariff nation.budget -= tariff if resource != 'budget': uf.append('budget') nation.save(update_fields=uf) target.save(update_fields=uf) log_aid(nation, target, resource, aid_amount) result = {'result': result, 'update': True} else: result = {'result': 'invalid resource'} else: try: result = {'result': form.errors.as_data()['amount'][0][0]} except: result = {'result': 'invalid resource'} return result
def exit_vacation(mod, player, reason): Nation.objects.filter(pk=player.pk).update(vacation=False) Settings.objects.filter(nation=player).update(vacation_timer=v.now()) result = "%s has been removed from vacation mode!" % player.name set_modaction(mod, "Removed %s from vacation mode" % player.name, reason) return result
def lastonline(seen): delta = v.now() - seen toreturn = longtimeformat(delta) return mark_safe(toreturn)