Implement bounties
This commit is contained in:
@@ -14,6 +14,7 @@ import json
|
||||
from datetime import datetime
|
||||
from models import cachePlayerList
|
||||
from events import server_queue, web_queue, chat, server_broadcast, send_web_event, QuitEvent, JoinEvent, PlayerDeathEvent
|
||||
from bounty.models import Bounty
|
||||
|
||||
class MOTDHandler(AnonymousBaseHandler):
|
||||
allowed_methods = ('GET',)
|
||||
@@ -110,6 +111,13 @@ class ServerEventHandler(BaseHandler):
|
||||
if evt['type'] == 'player-death':
|
||||
send_web_event(PlayerDeathEvent(evt['payload']['player'],
|
||||
evt['payload']['message']))
|
||||
if evt['type'] == 'player-murder':
|
||||
bounties = Bounty.objects.filter(target__mc_username=evt['payload']['player'])
|
||||
killer = MinecraftProfile.objects.get(mc_username=evt['payload']['killer'])
|
||||
for bounty in bounties:
|
||||
bounty.close(killer)
|
||||
if len(bounties) > 0:
|
||||
server_broadcast("The bounty on %s has been collected."%(evt['payload']['player']))
|
||||
return {'result': 'success'}
|
||||
|
||||
class ChatHandler(BaseHandler):
|
||||
|
0
bounty/__init__.py
Normal file
0
bounty/__init__.py
Normal file
4
bounty/admin.py
Normal file
4
bounty/admin.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import models
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.register(models.Bounty)
|
20
bounty/models.py
Normal file
20
bounty/models.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
from django.db.models import F
|
||||
import datetime
|
||||
from minecraft.models import MinecraftProfile
|
||||
from api import events
|
||||
|
||||
class Bounty(models.Model):
|
||||
creator = models.ForeignKey(MinecraftProfile, related_name='created_bounties')
|
||||
killer = models.ForeignKey(MinecraftProfile, related_name='closed_bounties', null=True, blank=True)
|
||||
target = models.ForeignKey(MinecraftProfile, related_name='bounties')
|
||||
price = models.IntegerField()
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
closed = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
def close(self, killer):
|
||||
self.closed = datetime.datetime.now()
|
||||
self.killer = killer
|
||||
self.save()
|
||||
killer.currencyaccount.balance = F('balance') + self.price
|
||||
killer.currencyaccount.save()
|
16
bounty/tests.py
Normal file
16
bounty/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
7
bounty/urls.py
Normal file
7
bounty/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
|
||||
urlpatterns = patterns('bounty',
|
||||
url(r'^$', 'views.index'),
|
||||
url(r'^create$', 'views.create'),
|
||||
)
|
||||
|
9
bounty/views.py
Normal file
9
bounty/views.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import models
|
||||
from django.shortcuts import render_to_response
|
||||
|
||||
def index(request):
|
||||
bounties = models.Bounty.objects.filter(closed__isnull=True)
|
||||
return render_to_response('bounty/index.html', {'bounties': bounties})
|
||||
|
||||
def create(request):
|
||||
return render_to_response('bounty/create.html')
|
18
templates/bounty/index.html
Normal file
18
templates/bounty/index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends "base_simple.html" %}
|
||||
{% load minecraft %}
|
||||
|
||||
{% block title %}Bounties{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<table>
|
||||
<tr class="header"><th>Who</th><th>Price</th></tr>
|
||||
{% if not bounties %}
|
||||
<tr class="infoBar"><td colspan="2">No bounties found.</td></tr>
|
||||
{% endif %}
|
||||
{% for bounty in bounties%}
|
||||
<tr><td><div class="avatar">{% avatar bounty.target.user %}</div> {{bounty.target}}</td><td>{{bounty.price}}</td></tr>
|
||||
{% endfor %}
|
||||
<tr class="actionBar"><td colspan="2"><a href="{% url bounty.views.create %}">Create a bounty</a></td></tr>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user