mirror of
https://github.com/gooba42/adventureland.git
synced 2026-10-14 10:33:47 -05:00
Open source
This commit is contained in:
Executable
+1
@@ -0,0 +1 @@
|
||||
#!/usr/bin/env python
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
from config import *
|
||||
from facebook import *
|
||||
from functions import *
|
||||
from models import *
|
||||
from modelclasses import *
|
||||
from rpgapp.functionz import *
|
||||
|
||||
class Handler(webapp.RequestHandler):
|
||||
def get(self,appid):
|
||||
permissions="email"
|
||||
app=RApp(appid)
|
||||
info=login(self,app,permissions)
|
||||
if not info.logged:
|
||||
return
|
||||
facebook=GraphAPI(info.access_token)
|
||||
appuser=RUser(app.db,info.id,facebook,permissions,app,the_webapp=self)
|
||||
if getattr(appuser,"login",0): self.response.out.write(appuser.login); return
|
||||
if not appuser.admin:
|
||||
return
|
||||
adminuser=get_cached(User,appuser.appuser.id)
|
||||
usage=len(app.db.info)
|
||||
usage=usage/10000.0
|
||||
usage="%.2f%%"%usage
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/admin.html")
|
||||
self.response.out.write(template.render(path,dict(usage=usage,adminuser=adminuser,app=app,user=appuser,inside="/admin")))
|
||||
appuser.ssave()
|
||||
app.ssave()
|
||||
def post(self,appid):
|
||||
self.get(appid)
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
from config import *
|
||||
from facebook import *
|
||||
from functions import *
|
||||
from appcomponents.library import *
|
||||
from models import *
|
||||
from modelclasses import *
|
||||
from rpgapp.functionz import *
|
||||
|
||||
|
||||
class Handler(webapp.RequestHandler):
|
||||
def get(self,adv=None):
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/dyn.html")
|
||||
self.response.out.write(template.render(path,dict()))
|
||||
def post(self,adv=None):
|
||||
self.get(adv)
|
||||
|
||||
|
||||
class SaverHandler(webapp.RequestHandler):
|
||||
def get(self,adv):
|
||||
pass
|
||||
def post(self,adv):
|
||||
self.get(adv)
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
import random
|
||||
from functions import *
|
||||
from modelclasses import *
|
||||
import json as simplejson
|
||||
|
||||
class RApp(XApp):
|
||||
def __init__(self,appid):
|
||||
XApp.__init__(self,appid)
|
||||
self.appid=appid
|
||||
self.adventure=getattr(self,"adventure","adventure1")
|
||||
|
||||
class RUser(SUser):
|
||||
def __init__(self, application, id, facebook, permissions,app=None,additional_info="",the_webapp=None):
|
||||
SUser.__init__(self, application, id, facebook, permissions,app,additional_info,the_webapp)
|
||||
if getattr(self,"login",0): return
|
||||
self.credits=getattr(self,"credits",0)
|
||||
self.rpguser.third_party_id=getattr(self.me,"third_party_id",0)
|
||||
self.rpguser.name=getattr(self.me,"name","Secret")
|
||||
if getattr(self.rpguser,"password","GG")=="GG":
|
||||
setattr(self.rpguser,"password",randomStr(10))
|
||||
|
||||
def nick_good(nick):
|
||||
if nick.isalnum():
|
||||
return True
|
||||
|
||||
def nick_available(nick,adv):
|
||||
nn=nick.lower()
|
||||
q=RPGChar.all()
|
||||
q.filter("adventure =",adv)
|
||||
q.filter("nrep =",nn)
|
||||
qq=q.get()
|
||||
if qq:
|
||||
return False
|
||||
return True
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
{% if error %}
|
||||
{"error":"1"}
|
||||
{% else %}
|
||||
{
|
||||
"id":"{{rpgchar.id}}",
|
||||
"nick":"{{rpgchar.nick}}"
|
||||
}
|
||||
{% endif %}
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% block "content" %}
|
||||
|
||||
{% endblock %}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>FUCK YEAH ITS A MORPG!</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<style>{% include "style.css" %}</style>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content" align="center">
|
||||
{% block "content" %}{%endblock%}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
function getOffset( el ) {
|
||||
var _x = 0;
|
||||
var _y = 0;
|
||||
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
|
||||
_x += el.offsetLeft - el.scrollLeft;
|
||||
_y += el.offsetTop - el.scrollTop;
|
||||
el = el.parentNode;
|
||||
}
|
||||
return {top: _y, left: _x};
|
||||
}
|
||||
function dge(x)
|
||||
{
|
||||
return document.getElementById(x);
|
||||
}
|
||||
function pa(x)
|
||||
{
|
||||
return parseInt(x);
|
||||
}
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"version":1,
|
||||
"maps":["start"],
|
||||
"characters":{
|
||||
"defmale":"r|c3e|2|1",
|
||||
"deffemale":"r|c3e|2|2"
|
||||
}
|
||||
}
|
||||
Executable
+310
@@ -0,0 +1,310 @@
|
||||
{% extends "base.html" %}
|
||||
{% block "content" %}
|
||||
<style>
|
||||
body{
|
||||
background-image: url("/rpgapp/images/128-25.jpg");
|
||||
background-repeat: repeat;
|
||||
}
|
||||
body{cursor: url('/rpgapp/images/blank.gif'), default !important;}
|
||||
</style>
|
||||
<script src="//lordkaan.com:1080/socket.io/socket.io.js"></script>
|
||||
<script>{% include "common.js" %}</script>
|
||||
<script>
|
||||
var HEIGHT=600,WIDTH=800,inited=0;
|
||||
var c_x=200,c_y=200,dx=2,dy=2,to_x=-1,to_y=-1,s_x,s_y,moving=0;
|
||||
var mouse_x=0,mouse_y=0;
|
||||
var direction=0;
|
||||
var gameCanvas,context;
|
||||
var loaded=0;
|
||||
var players=Array(),npeople;
|
||||
var maps=new Object();
|
||||
var curmap=0;
|
||||
var steps=0;
|
||||
var cworld=0;
|
||||
var on_chat=0;
|
||||
var cursor_type=1,c_cursor=0;
|
||||
var gofleft=0,goftop=0;
|
||||
</script>
|
||||
<div id="loading" style="color: #E9F607; font-size: 1.8em; font-weight: bold; padding-top: 200px;"><img src="/rpgapp/images/ajax-loader.gif" /> Loading ...</div>
|
||||
<canvas id="gameCanvas" width="800" height="600">
|
||||
This text is displayed if your browser does not support HTML5 Canvas.
|
||||
</canvas>
|
||||
<div id="game-infos" unselectable="on" class="unselectable">
|
||||
<div id="game-info" align="left" unselectable="on" class="unselectable">
|
||||
</div>
|
||||
<input type="text" id="field" onkeydown=" if (event.keyCode==13) {
|
||||
socket.emit('msg',my_nick+': '+$('#field').val());
|
||||
$('#field').val('');
|
||||
}" />
|
||||
</div>
|
||||
<div id="cursor" onclick="return false;" unselectable="on" class="unselectable"></div>
|
||||
|
||||
<script>
|
||||
var socket,my_id="{{user.appuser.id}}",my_nick="{{char.nick}}";
|
||||
window.onload=function()
|
||||
{
|
||||
document.getElementById('saudio').volume=0.1;
|
||||
document.getElementById('saudio').addEventListener('ended', function(){
|
||||
this.currentTime = 0;
|
||||
}, false);
|
||||
gameCanvas = document.getElementById('gameCanvas');
|
||||
context = gameCanvas.getContext('2d');
|
||||
inited=1;
|
||||
|
||||
socket= io.connect('http://lordkaan.com:1080');
|
||||
|
||||
socket.emit('setuser',{"id":"{{user.appuser.id}}","pass":"{{user.rpguser.password}}","appid":"{{app.db.appid}}","char":"{{char.id}}"});
|
||||
|
||||
socket.on('msg', function (data) {
|
||||
console.log(data);
|
||||
html=$("#game-info").html();
|
||||
$("#game-info").html(html+"<div class='message' unselectable='on' class='unselectable'>"+data["msg"]+"</div>");
|
||||
});
|
||||
|
||||
socket.on('world', function (data) {
|
||||
if(loaded && inited)
|
||||
{
|
||||
for(var i=0;i<data.players.length;i++)
|
||||
{
|
||||
var c=data.players[i];
|
||||
if(c.id==my_id)
|
||||
c_x=c.x,c_y=c.y;
|
||||
}
|
||||
cworld=data;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', function (data) {
|
||||
window.top.location="//apps.facebook.com/{{app.db.slug}}/";
|
||||
});
|
||||
|
||||
socket.on('ready', function (data) {
|
||||
if(!data.map)
|
||||
data.map="start";
|
||||
loadMap(data.map);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
window.addEventListener('keydown',doKeyDown,true);
|
||||
window.addEventListener('click',doClick,true);
|
||||
window.addEventListener('mousemove',doMove,true);
|
||||
|
||||
function walk()
|
||||
{
|
||||
var s=0;
|
||||
if(to_x!=-1)
|
||||
{
|
||||
if(to_x>c_x)
|
||||
{
|
||||
c_x+=10;
|
||||
if(to_x<=c_x)
|
||||
to_x=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
c_x-=10;
|
||||
if(to_x>=c_x)
|
||||
to_x=-1;
|
||||
}
|
||||
s=1;
|
||||
}
|
||||
if(to_y!=-1)
|
||||
{
|
||||
if(to_y>c_y)
|
||||
{
|
||||
c_y+=10;
|
||||
if(to_y<=c_y)
|
||||
to_y=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
c_y-=10;
|
||||
if(to_y>=c_y)
|
||||
to_y=-1;
|
||||
}
|
||||
s=1;
|
||||
}
|
||||
if(s) { moving=1; send_coord(); }
|
||||
else if(moving){
|
||||
moving=0;
|
||||
send_coord();
|
||||
}
|
||||
}
|
||||
|
||||
function stepper(){
|
||||
steps=steps+1;
|
||||
}
|
||||
function setCursor()
|
||||
{
|
||||
if(c_cursor!=cursor_type)
|
||||
{
|
||||
if(cursor_type==1)
|
||||
$("#cursor").css("background","url('/rpgapp/images/gam1229.gif')");
|
||||
else if(cursor_type==2)
|
||||
$("#cursor").css("background","url('/rpgapp/images/cur886.gif')");
|
||||
}
|
||||
$("#cursor").css("top",mouse_y-30);
|
||||
$("#cursor").css("left",mouse_x-30);
|
||||
}
|
||||
setInterval(stepper,200);
|
||||
setInterval(walk,200);
|
||||
function doMove(e){
|
||||
if(inited && loaded)
|
||||
{
|
||||
var x;
|
||||
var y;
|
||||
if (e.pageX || e.pageY) {
|
||||
x = e.pageX;
|
||||
y = e.pageY;
|
||||
}
|
||||
else {
|
||||
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
||||
}
|
||||
mouse_x=x;
|
||||
mouse_y=y;
|
||||
x-=gofleft;
|
||||
y-=goftop;
|
||||
if(x>=0 && x<=200 && y>=0 && y<=200)
|
||||
{
|
||||
if(!on_chat) $("#game-infos").addClass("onit");
|
||||
on_chat=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(on_chat) $("#game-infos").removeClass("onit");
|
||||
on_chat=0;
|
||||
}
|
||||
}
|
||||
setCursor();
|
||||
}
|
||||
|
||||
function doClick(e){
|
||||
if(inited && loaded)
|
||||
{
|
||||
var x;
|
||||
var y;
|
||||
if (e.pageX || e.pageY) {
|
||||
x = e.pageX;
|
||||
y = e.pageY;
|
||||
}
|
||||
else {
|
||||
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
||||
}
|
||||
x -= gameCanvas.offsetLeft;
|
||||
y -= gameCanvas.offsetTop;
|
||||
var dispx=WIDTH/2-c_x,dispy=HEIGHT/2-c_y;
|
||||
if(!on_chat)
|
||||
{
|
||||
to_x=x-dispx;
|
||||
to_y=y-dispy;
|
||||
}
|
||||
}
|
||||
if(on_chat)
|
||||
$("#field").select();
|
||||
}
|
||||
|
||||
function doKeyDown(evt){
|
||||
switch (evt.keyCode) {
|
||||
case 38:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(draw_world,250);
|
||||
|
||||
function draw_world(data)
|
||||
{
|
||||
if(!cworld) return;
|
||||
data=cworld;
|
||||
if(!curmap) return;
|
||||
WIDTH=context.canvas.width = window.innerWidth;
|
||||
HEIGHT=context.canvas.height = window.innerHeight;
|
||||
var dispx=WIDTH/2-pa(c_x),dispy=HEIGHT/2-pa(c_y);
|
||||
var pnx,pny;
|
||||
for(var i=0;i<WIDTH/32;i++)
|
||||
for(var j=0;j<HEIGHT/32;j++)
|
||||
{
|
||||
context.drawImage(dge(curmap.def.tile),curmap.def.x,curmap.def.y,32,32,i*32,j*32,32,32);
|
||||
}
|
||||
for(var i=0;i<curmap.items.length;i++)
|
||||
{
|
||||
var c=curmap.items[i];
|
||||
c=c.split("|");
|
||||
if(c[0][0]=="r")
|
||||
{
|
||||
var t,y;
|
||||
pnx=parseInt(c[3])+dispx;
|
||||
pny=parseInt(c[4])+dispy;
|
||||
if(-40<=pnx && pnx<=WIDTH+40 && -40<=pny && pny<=HEIGHT+40)
|
||||
context.drawImage(dge(c[1]),pa(c[5]),pa(c[6]),pa(c[2]),pa(c[2]),pnx,pny,pa(c[2]),pa(c[2]));
|
||||
}
|
||||
else if(c[0][0]=='m')
|
||||
{
|
||||
for(var j=0;j<pa(c[7]);j++)
|
||||
for(var k=0;k<pa(c[8]);k++)
|
||||
{
|
||||
pnx=pa(c[3])+j*pa(c[2])+dispx;
|
||||
pny=pa(c[4])+k*pa(c[2])+dispy;
|
||||
if(-40<=pnx && pnx<=WIDTH+40 && -40<=pny && pny<=HEIGHT+40)
|
||||
context.drawImage(dge(c[1]),pa(c[5]),pa(c[6]),pa(c[2]),pa(c[2]),pnx,pny,pa(c[2]),pa(c[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
for(var i=0;i<data.players.length;i++)
|
||||
{
|
||||
var cur=data.players[i];
|
||||
var c=cur.character;
|
||||
c=c.split("|");
|
||||
if(c[0]=="r")
|
||||
{
|
||||
context.fillStyle="green";
|
||||
context.fillText(cur.nick,cur.x-20+dispx,cur.y-48+dispy,50);
|
||||
pnx=cur.x-16+dispx;
|
||||
pny=cur.y-48+dispy;
|
||||
if(-40<=pnx && pnx<=WIDTH+40 && -40<=pny && pny<=HEIGHT+40)
|
||||
context.drawImage(dge(c[1]),pa(c[2])*96+(steps%3)*32*pa(cur.m),pa(c[3])*192+cur.d*48,32,48,pnx,pny,32,48);
|
||||
}
|
||||
}
|
||||
$("#game-infos").css("left",$("#gameCanvas").offset().left);
|
||||
$("#game-infos").css("top",$("#gameCanvas").offset().top+HEIGHT-220);
|
||||
gofleft=$("#game-infos").offset().left;
|
||||
goftop=$("#game-infos").offset().top;
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
|
||||
function loadMap(name)
|
||||
{
|
||||
if(maps[name])
|
||||
{
|
||||
curmap=maps[name];
|
||||
}
|
||||
else
|
||||
{
|
||||
$.get("/rpgapp/getmap/{{app.adventure}}-"+name,function(data){
|
||||
$("body").css("background","none");
|
||||
$("#loading").hide();
|
||||
curmap=maps[name]=eval("("+data+")");
|
||||
c_x=curmap.spawn.x;
|
||||
c_y=curmap.spawn.y;
|
||||
loaded=1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function send_coord()
|
||||
{
|
||||
socket.emit('coord',{x:c_x,y:c_y,d:direction,m:moving});
|
||||
}
|
||||
</script>
|
||||
<audio id="saudio" loop="loop" volume="0.2">
|
||||
<source src="/rpgapp/images/CloudTopLoops.ogg" type="audio/ogg" />
|
||||
No Audio Support, Upgrade your Browser
|
||||
</audio>
|
||||
{% include "resources.html" %}
|
||||
|
||||
{% endblock %}
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
{% extends "base.html" %}
|
||||
{% block "content" %}
|
||||
<style>
|
||||
body{
|
||||
background-image: url("/rpgapp/images/128-25.jpg");
|
||||
background-repeat: repeat;
|
||||
}
|
||||
</style>
|
||||
<div style="padding-top: 150px;">
|
||||
<div style="font-size: 1.8em; font-weight: bold; color: white; padding-bottom: 30px;">
|
||||
{{app.db.name}}
|
||||
</div>
|
||||
{% if chars %}
|
||||
|
||||
|
||||
<input type="reset" class="huge green button" onclick="window.top.location='//apps.facebook.com/{{app.db.slug}}/game/'+$('#server').val()" value=" Play " />
|
||||
<br />
|
||||
<br />
|
||||
<select name="schar" class="fsel">
|
||||
{% for ch in chars %}
|
||||
<option value="{{ch.id}}">{{ch.nick}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="server" class="fsel">
|
||||
<option value="s1">Server 1</option>
|
||||
</select>
|
||||
<div style="font-style: italic; color: white">(Your character is the same on all servers.)</div>
|
||||
{% else %}
|
||||
<form method="get" target="_top" action="//apps.facebook.com/{{app.db.slug}}/game/">
|
||||
<span style="font-size: 1.8em; font-weight: bold; color: white; padding-bottom: 30px;">
|
||||
Nickname:
|
||||
</span>
|
||||
<input name="char" type="text" id="char" style="width: 150px; height: 30px; font-size: 1.4em; font-weight: bold" /><br />
|
||||
<input type="submit" class="large green button" value=" Create Character " />
|
||||
</form>
|
||||
<br />
|
||||
{% endif %}
|
||||
{% if error %}
|
||||
<div style="font-size: 1.8em; font-weight: bold; color: red; padding-bottom: 30px;" >
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<audio id="saudio" autoplay="autoplay" loop="loop" volume="0.2">
|
||||
<source src="/rpgapp/images/CloudTopLoops.ogg" type="audio/ogg" />
|
||||
No Audio Support, Upgrade your Browser
|
||||
</audio>
|
||||
<script>
|
||||
window.onload=function(){
|
||||
|
||||
document.getElementById('saudio').volume=0.2;
|
||||
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Executable
+262
@@ -0,0 +1,262 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>RPG MAP Editor</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
|
||||
<style>{% include "style.css" %}</style>
|
||||
<script>{% include "common.js" %}</script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="map" width="2000" height="2000">
|
||||
Change your browser.
|
||||
</canvas>
|
||||
<div id="editor" class="editor" title="Map Editor">
|
||||
Tileset:
|
||||
<select id="tileset" onchange="load_palet(); s_x=0; s_y=0;">
|
||||
<option value="t1">Tile A1</option>
|
||||
<option value="t2">Tile A2</option>
|
||||
<option value="t3">Tile A3</option>
|
||||
<option value="t4">Tile A4</option>
|
||||
<option value="tb">Tile B</option>
|
||||
<option value="tc">Tile C</option>
|
||||
<option value="td">Tile D</option>
|
||||
<option value="te">Tile E</option>
|
||||
<option value="c1">Chars 1A</option>
|
||||
<option value="i4">Icon Set BC4</option>
|
||||
</select>
|
||||
Current:
|
||||
<canvas id="current-el" width="32" height="32"></canvas>
|
||||
Default:
|
||||
<canvas id="default-el" width="32" height="32"></canvas>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td width="140" valign="top">
|
||||
Lines: <input type="checkbox" onchange=" if (this.checked) lines=1; else lines=0" checked/> <br />
|
||||
Coords: <input type="checkbox" onchange=" if (this.checked) coordinates=1; else coordinates=0" checked/> <br />
|
||||
PLines: <input type="checkbox" onchange=" if (this.checked) plines=1; else plines=0; load_palet()" checked/> <br />
|
||||
X_f: <input type="checkbox" onchange=" if (this.checked) x_f=16; else x_f=0; load_palet()"/> <br />
|
||||
Y_f: <input type="checkbox" onchange=" if (this.checked) y_f=16; else y_f=0; load_palet()"/> <br />
|
||||
16x16: <input type="checkbox" onchange=" if (this.checked) b_size=16; else b_size=32; load_palet()"/> <br />
|
||||
24x24: <input type="checkbox" onchange=" if (this.checked) b_size=24; else b_size=32; load_palet()"/> <br />
|
||||
Forbidden: <input type="checkbox" onchange=" if (this.checked) forbidden=1; else forbidden=0;"/> <br />
|
||||
Delete: <input type="checkbox" onchange=" if (this.checked) delete_mode=1; else delete_mode=0;"/> <br />
|
||||
Don't Delete: <input type="checkbox" onchange=" if (this.checked) dont_delete=1; else dont_delete=0;"/> <br />
|
||||
Multiplier X: <input type="text" onchange="multip_x=pa(this.value); if (multip_x<1) multip_x=1;" value="1"/> <br />
|
||||
Multiplier Y: <input type="text" onchange="multip_y=pa(this.value); if (multip_y<1) multip_y=1;" value="1"/> <br />
|
||||
<input type="reset" value="Save" class="green button" onclick="save_map()"/> <br />
|
||||
<input type="reset" value="Set Spawn Point" class="small orange button" onclick="spawn_mode=1;"/> <br />
|
||||
<input type="reset" value="Make Default" class="small blue button" onclick="make_default()"/> <br />
|
||||
</td>
|
||||
<td>
|
||||
<div align="center"><canvas id="palet"></canvas></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
var multip_x=1,multip_y=1,forbidden=0,dont_delete=0;
|
||||
var lines=1,plines=1,coordinates=1,delete_mode=0,spawn_mode=0;
|
||||
var x_f=0,y_f=0,b_size=32;
|
||||
var rep=eval("({{info.rep|escapejs}})");
|
||||
if (typeof rep.items !="object")
|
||||
rep.items=new Array();
|
||||
if (typeof rep.spawn !="object")
|
||||
rep.spawn=new Object();
|
||||
var map_x,map_y,palet_x,palet_y,s_x=0,s_y=0;
|
||||
var WIDTH=2000,HEIGHT=2000,PWIDTH,PHEIGHT;
|
||||
</script>
|
||||
<script>
|
||||
function reflect_default()
|
||||
{
|
||||
if (rep.def)
|
||||
{
|
||||
default_el.canvas.width=32;
|
||||
default_el.canvas.height=32;
|
||||
default_el.drawImage(document.getElementById(rep.def.tile),rep.def.x,rep.def.y,32,32,0,0,32,32);
|
||||
}
|
||||
}
|
||||
function make_default()
|
||||
{
|
||||
rep.def=new Object();
|
||||
rep.def.tile=$("#tileset").val();
|
||||
rep.def.x=s_x;
|
||||
rep.def.y=s_y;
|
||||
alert("Made Default")
|
||||
}
|
||||
$('#map').dblclick(function() {
|
||||
var d_x,d_y,t_d=-1,undeleted=Array();
|
||||
d_x=(parseInt(map_x/b_size))*b_size;
|
||||
d_y=(parseInt(map_y/b_size))*b_size;
|
||||
if(spawn_mode)
|
||||
{
|
||||
rep.spawn.x=d_x;
|
||||
rep.spawn.y=d_y;
|
||||
alert("Spawn point set: "+d_x+","+d_y);
|
||||
spawn_mode=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete existing items
|
||||
if(!dont_delete)
|
||||
{
|
||||
for(var i=0;i<rep.items.length;i++)
|
||||
{
|
||||
var c=rep.items[i],xx=1,xy=1;
|
||||
c=c.split("|");
|
||||
if(c[0][0]=="m")
|
||||
xx=pa(c[7]),xy=pa(c[8]);
|
||||
if(d_x<= pa(c[3]) && pa(c[3])+pa(c[2])*xx<=d_x+b_size*multip_x && d_y<=pa(c[4]) && pa(c[4])+pa(c[2])*xy<=d_y+b_size*multip_y){}
|
||||
else
|
||||
undeleted.push(rep.items[i]);
|
||||
}
|
||||
rep.items=undeleted;
|
||||
}
|
||||
// end delete
|
||||
if (!delete_mode )
|
||||
{
|
||||
s_x=parseInt(s_x);s_y=parseInt(s_y);map_x=parseInt(map_x);map_y=parseInt(map_y);
|
||||
var cur=new Object();
|
||||
cur.t="r";
|
||||
if(multip_x>1 || multip_y>1)
|
||||
cur.t="m";
|
||||
if (forbidden)
|
||||
cur.t+="f";
|
||||
cur.x=d_x;
|
||||
cur.y=d_y;
|
||||
cur.s=b_size;
|
||||
cur.f=$("#tileset").val();
|
||||
cur.fx=s_x;
|
||||
cur.fy=s_y;
|
||||
var gg=cur.t+"|"+cur.f+"|"+cur.s+"|"+cur.x+"|"+cur.y+"|"+cur.fx+"|"+cur.fy;
|
||||
if(multip_x>1 || multip_y>1)
|
||||
gg=gg+"|"+multip_x+"|"+multip_y;
|
||||
rep.items.push(gg);
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#palet').dblclick(function() {
|
||||
if(b_size==32)
|
||||
{
|
||||
s_x=parseInt((palet_x-x_f)/32)*32+x_f;
|
||||
if (x_f && palet_x<16) s_x=0;
|
||||
s_y=parseInt((palet_y-y_f)/32)*32+y_f;
|
||||
if (y_f && palet_y<16) s_y=0;
|
||||
}
|
||||
else if(b_size==16)
|
||||
{
|
||||
s_x=parseInt((palet_x)/b_size)*b_size;
|
||||
s_y=parseInt((palet_y)/b_size)*b_size;
|
||||
}
|
||||
current_el.canvas.width=b_size;
|
||||
current_el.canvas.height=b_size;
|
||||
current_el.drawImage(document.getElementById($("#tileset").val()),s_x,s_y,b_size,b_size,0,0,b_size,b_size);
|
||||
});
|
||||
window.onload=function(){
|
||||
setInterval(draw_world,1000);
|
||||
mapCanvas = document.getElementById('map');
|
||||
context = mapCanvas.getContext('2d');
|
||||
editorCanvas = document.getElementById('palet');
|
||||
palet = editorCanvas.getContext('2d');
|
||||
current_el=document.getElementById('current-el').getContext('2d');
|
||||
default_el=document.getElementById('default-el').getContext('2d');
|
||||
reflect_default();
|
||||
$( "#editor" ).dialog({
|
||||
name: "Editor",
|
||||
width: 700,
|
||||
height: 500,
|
||||
closeOnEscape: false,
|
||||
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }});
|
||||
setInterval(load_palet,1000);
|
||||
|
||||
}
|
||||
function load_palet()
|
||||
{
|
||||
palet.canvas.width=palet.canvas.width;
|
||||
PWIDTH=palet.canvas.width;
|
||||
PHEIGHT=palet.canvas.height;
|
||||
img=document.getElementById($("#tileset").val());
|
||||
palet.canvas.width=img.width;
|
||||
palet.canvas.height=img.height;
|
||||
palet.drawImage(img,0,0);
|
||||
if (plines)
|
||||
{
|
||||
palet.fillStyle="white";
|
||||
for(var i=0;i<PHEIGHT;i++)
|
||||
if(!((i+y_f)%b_size) || ((i+y_f)%b_size)==b_size-1)
|
||||
palet.fillRect(0,i,WIDTH,1);
|
||||
for(var i=0;i<PWIDTH;i++)
|
||||
if(!((i+x_f)%b_size) || ((i+x_f)%b_size)==b_size-1)
|
||||
palet.fillRect(i,0,1,HEIGHT);
|
||||
}
|
||||
|
||||
}
|
||||
function draw_world()
|
||||
{
|
||||
context.canvas.width=context.canvas.width;
|
||||
WIDTH=context.canvas.width;
|
||||
HEIGHT=context.canvas.height;
|
||||
for(var i=0;i<rep.items.length;i++)
|
||||
{
|
||||
var c=rep.items[i];
|
||||
c=c.split("|");
|
||||
if(c[0][0]=='r')
|
||||
{
|
||||
context.drawImage(document.getElementById(c[1]),c[5],c[6],c[2],c[2],c[3],c[4],c[2],c[2]);
|
||||
}
|
||||
else if(c[0][0]=='m')
|
||||
{
|
||||
for(var j=0;j<pa(c[7]);j++)
|
||||
for(var k=0;k<pa(c[8]);k++)
|
||||
context.drawImage(document.getElementById(c[1]),c[5],c[6],c[2],c[2],pa(c[3])+j*pa(c[2]),pa(c[4])+k*pa(c[2]),c[2],c[2]);
|
||||
}
|
||||
}
|
||||
if (lines)
|
||||
{
|
||||
context.fillStyle="purple";
|
||||
for(var i=0;i<HEIGHT;i++)
|
||||
if(!(i%b_size) || (i%b_size)==b_size-1)
|
||||
{
|
||||
context.fillRect(0,i,WIDTH,1);
|
||||
context.fillRect(i,0,1,HEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener('click',doClick,true);
|
||||
|
||||
function doClick(e){
|
||||
var x;
|
||||
var y;
|
||||
if (e.pageX || e.pageY) {
|
||||
x = e.pageX;
|
||||
y = e.pageY;
|
||||
}
|
||||
else {
|
||||
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
||||
}
|
||||
map_x=palet_x=x;
|
||||
map_y=palet_y=y;
|
||||
map_x -= $("#map").offset().left;
|
||||
map_y -= $("#map").offset().top;
|
||||
palet_x -= $("#palet").offset().left;
|
||||
palet_y -= $("#palet").offset().top;
|
||||
//palet_x+=17;
|
||||
//palet_y+=40;
|
||||
// JQUERY DIALOG ADJUSTMENTS - DIRTY
|
||||
console.log(map_x +" "+map_y);
|
||||
console.log(palet_x +" "+palet_y);
|
||||
}
|
||||
function save_map()
|
||||
{
|
||||
$.post("/rpgapp/map/{{mapkey}}", { map_rep:JSON.stringify(rep) },
|
||||
function(data) {
|
||||
alert("Saved "+data);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% include "resources.html" %}
|
||||
</body>
|
||||
</html>
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<img id="t1" src="/rpgapp/images/tileA1.png" style="display: none"/>
|
||||
<img id="t2" src="/rpgapp/images/tileA2.png" style="display: none"/>
|
||||
<img id="t3" src="/rpgapp/images/tileA3.png" style="display: none"/>
|
||||
<img id="t4" src="/rpgapp/images/tileA4.png" style="display: none"/>
|
||||
<img id="tb" src="/rpgapp/images/tileB.png" style="display: none"/>
|
||||
<img id="tc" src="/rpgapp/images/tileC.png" style="display: none"/>
|
||||
<img id="td" src="/rpgapp/images/tileD.png" style="display: none"/>
|
||||
<img id="te" src="/rpgapp/images/tileE.png" style="display: none"/>
|
||||
<img id="c1" src="/rpgapp/images/vx_chara01_a.png" style="display: none"/>
|
||||
<img id="c3e" src="/rpgapp/images/vx_chara03_e.png" style="display: none"/>
|
||||
<img id="i4" src="/rpgapp/images/iconsetbc4.png" style="display: none"/>
|
||||
<img id="cr" src="/rpgapp/images/cursor2.gif" style="display: none"/>
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#content{
|
||||
width: 100%;
|
||||
}
|
||||
#cursor{
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
#game-infos:hover{
|
||||
opacity: 0.8;
|
||||
}
|
||||
.onit{
|
||||
opacity: 0.8 !important;
|
||||
}
|
||||
#game-infos{
|
||||
background-color: darkgrey;
|
||||
opacity: 0.4;
|
||||
padding: 1px;
|
||||
margin: 1px;
|
||||
position: absolute;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
#game-info{
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
overflow: hidden;
|
||||
width: 200px;
|
||||
height: 180px;
|
||||
}
|
||||
#field{
|
||||
width: 196px;
|
||||
}
|
||||
.button {
|
||||
padding: 5px 10px;
|
||||
display: inline;
|
||||
background: #777 url(/fortuneapp/images/button.png) repeat-x bottom;
|
||||
border: none;
|
||||
color: #fff !important;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
text-shadow: 1px 1px #666;
|
||||
}
|
||||
.button:hover {
|
||||
background-position: 0 -48px;
|
||||
}
|
||||
.button:active {
|
||||
background-position: 0 top;
|
||||
position: relative;
|
||||
top: 1px;
|
||||
padding: 6px 10px 4px;
|
||||
}
|
||||
.button.red { background-color: #e50000; }
|
||||
.button.purple { background-color: #9400bf; }
|
||||
.button.green { background-color: #58aa00; }
|
||||
.button.orange { background-color: #ff9c00; }
|
||||
.button.blue { background-color: #2c6da0; }
|
||||
.button.black { background-color: #333; }
|
||||
.button.white { background-color: #fff; color: #000; text-shadow: 1px 1px #fff; }
|
||||
.button.small { font-size: 75%; padding: 3px 7px; }
|
||||
.button.small:hover { background-position: 0 -50px; }
|
||||
.button.small:active { padding: 4px 7px 2px; background-position: 0 top; }
|
||||
.button.large { font-size: 125%; padding: 7px 12px; }
|
||||
.button.large:hover { background-position: 0 -35px; }
|
||||
.button.large:active { padding: 8px 12px 6px; background-position: 0 top; }
|
||||
.button.huge { font-size: 175%; padding: 11px 17px; }
|
||||
.button.huge:hover { background-position: 0 -20px; }
|
||||
.button.huge:active { padding: 12px 17px 10px; background-position: 0 top; }
|
||||
|
||||
.fsel{
|
||||
font-size: 8pt; border: 1px solid #fff; background-color: #000; padding: 10px; color: #ccc
|
||||
}
|
||||
*.unselectable {
|
||||
-moz-user-select: -moz-none;
|
||||
-khtml-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#map-footer{
|
||||
position:fixed; bottom:0;
|
||||
}
|
||||
|
||||
#editor{
|
||||
}
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
from config import *
|
||||
from facebook import *
|
||||
from functions import *
|
||||
from appcomponents.library import *
|
||||
from models import *
|
||||
from modelclasses import *
|
||||
from rpgapp.functionz import *
|
||||
import rpgapp.admin as admin
|
||||
import rpgapp.map as map
|
||||
import rpgapp.dyn as dyn
|
||||
|
||||
class MainHandler(webapp.RequestHandler):
|
||||
def get(self,appid):
|
||||
permissions="email"
|
||||
app=RApp(appid)
|
||||
info=login(self,app,permissions)
|
||||
if not info.logged:
|
||||
return
|
||||
facebook=GraphAPI(info.access_token)
|
||||
appuser=RUser(app.db,info.id,facebook,permissions,app,the_webapp=self)
|
||||
if getattr(appuser,"login",0): self.response.out.write(appuser.login); return
|
||||
rpginfo=cPickle.loads(appuser.rpguser.info)
|
||||
chars=getattr(rpginfo,"%s_chars"%app.adventure,[])
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/index.html")
|
||||
self.response.out.write(template.render(path,dict(app=app,user=appuser,chars=chars)))
|
||||
appuser.ssave()
|
||||
def post(self,appid):
|
||||
self.get(appid)
|
||||
|
||||
class GameHandler(webapp.RequestHandler):
|
||||
def get(self,appid,server_id=0):
|
||||
permissions="email"
|
||||
app=RApp(appid)
|
||||
info=login(self,app,permissions)
|
||||
if not info.logged:
|
||||
return
|
||||
facebook=GraphAPI(info.access_token)
|
||||
appuser=RUser(app.db,info.id,facebook,permissions,app,the_webapp=self)
|
||||
if getattr(appuser,"login",0): self.response.out.write(appuser.login); return
|
||||
rpginfo=cPickle.loads(appuser.rpguser.info)
|
||||
chars=getattr(rpginfo,"%s_chars"%app.adventure,[])
|
||||
current=0
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/index.html")
|
||||
try:
|
||||
if self.request.get("char"):
|
||||
logging.info("Creating a new character")
|
||||
nick=self.request.get("char")
|
||||
if not nick_good(nick):
|
||||
self.response.out.write(template.render(path,dict(app=app,user=appuser,error="Nickname should only consist of characters and numbers")))
|
||||
return
|
||||
if not nick_available(nick,app.adventure):
|
||||
self.response.out.write(template.render(path,dict(app=app,user=appuser,error="Nickname is not available")))
|
||||
return
|
||||
ch=GG()
|
||||
ch.id=randomStr(30)
|
||||
ch.nick=nick
|
||||
ch.adventure=app.adventure
|
||||
chh=RPGChar(key_name=dgt(appuser.appuser.id,ch.id),id=appuser.appuser.id,nrep=nick.lower(),nick=nick,adventure=app.adventure)
|
||||
if isAppengine(): db.put_async(chh)
|
||||
else: chh.put()
|
||||
chars.append(ch)
|
||||
setattr(rpginfo,"%s_chars"%app.adventure,chars)
|
||||
appuser.rpguser.info=cPickle.dumps(rpginfo)
|
||||
appuser.tosave=1
|
||||
current=ch
|
||||
elif self.request.get("schar"):
|
||||
current=chars[0]
|
||||
for ch in chars:
|
||||
if ch.id==self.request.get("schar"):
|
||||
tch=ch
|
||||
else:
|
||||
current=chars[0]
|
||||
except:
|
||||
logTrace()
|
||||
self.response.out.write(template.render(path,dict(app=app,user=appuser,error="A problem occured")))
|
||||
return
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/game.html")
|
||||
self.response.out.write(template.render(path,dict(app=app,user=appuser,char=current)))
|
||||
appuser.ssave()
|
||||
def post(self,appid,server_id=0):
|
||||
self.get(appid,server_id)
|
||||
|
||||
class AckHandler(webapp.RequestHandler):
|
||||
def get(self,appid,user=0,char=0,passw=0):
|
||||
app=RApp(appid)
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/ack.html")
|
||||
rpgchar=RPGChar.get_by_key_name(dgt(user,char))
|
||||
if not rpgchar:
|
||||
self.response.out.write(template.render(path,dict(app=app,error=1)))
|
||||
return
|
||||
self.response.out.write(template.render(path,dict(app=app,rpgchar=rpgchar)))
|
||||
def post(self,appid,user=0,char=0,passw=0):
|
||||
self.get(appid,server_id)
|
||||
|
||||
application = webapp.WSGIApplication([
|
||||
('/rpgapp/getdyn/(.*)/', dyn.Handler),
|
||||
('/rpgapp/getdyn/(.*)', dyn.Handler),
|
||||
('/rpgapp/getmap/(.*)/', map.MapGetter),
|
||||
('/rpgapp/getmap/(.*)', map.MapGetter),
|
||||
('/rpgapp/map/(.*)/', map.Handler),
|
||||
('/rpgapp/map/(.*)', map.Handler),
|
||||
('/rpgapp/(\d*)/game/(.*)/', GameHandler),
|
||||
('/rpgapp/(\d*)/game/.*', GameHandler),
|
||||
('/rpgapp/(\d*)/ackuser/(.*)/(.*)/(.*)/', AckHandler),
|
||||
('/rpgapp/(\d*)/ackuser/(.*)/(.*)/(.*)', AckHandler),
|
||||
('/rpgapp/(\d*)/admin/?.*', admin.Handler),
|
||||
('/rpgapp/(\d*)/?.*', MainHandler),
|
||||
],debug=not isAppengine())
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
from config import *
|
||||
from facebook import *
|
||||
from functions import *
|
||||
from appcomponents.library import *
|
||||
from models import *
|
||||
from modelclasses import *
|
||||
from rpgapp.functionz import *
|
||||
|
||||
class Handler(webapp.RequestHandler):
|
||||
def get(self,mapkey=None):
|
||||
if not mapkey:
|
||||
return
|
||||
map=RPGMap.get_by_key_name(mapkey)
|
||||
if not map:
|
||||
map=RPGMap(key_name=mapkey,adventure=mapkey.split("-")[0])
|
||||
mapinfo=cPickle.loads(map.info)
|
||||
mapinfo.rep=getattr(mapinfo,"rep","{}")
|
||||
if self.request.get("map_rep"):
|
||||
logging.info("Saving Map ...")
|
||||
mapinfo.rep=self.request.get("map_rep")
|
||||
map.info=cPickle.dumps(mapinfo)
|
||||
map.put()
|
||||
ln=len(map.info);ln=ln/10000.0;ln="%.3lf%%"%ln
|
||||
self.response.out.write(ln)
|
||||
return
|
||||
path = os.path.join(os.path.dirname(__file__), "htmls/mapeditor.html")
|
||||
self.response.out.write(template.render(path,dict(info=mapinfo,mapkey=mapkey)))
|
||||
def post(self,adv=None):
|
||||
self.get(adv)
|
||||
|
||||
class MapGetter(webapp.RequestHandler):
|
||||
def get(self,mapkey=None):
|
||||
if not mapkey:
|
||||
return
|
||||
map=RPGMap.get_by_key_name(mapkey)
|
||||
if not map:
|
||||
map=RPGMap(key_name=mapkey,adventure=mapkey.split("-")[0])
|
||||
mapinfo=cPickle.loads(map.info)
|
||||
mapinfo.rep=getattr(mapinfo,"rep","{}")
|
||||
self.response.out.write(mapinfo.rep)
|
||||
def post(self,adv=None):
|
||||
self.get(adv)
|
||||
Executable
+239
@@ -0,0 +1,239 @@
|
||||
var DEBUG=1;
|
||||
var http = require('http');
|
||||
|
||||
function getClient(){
|
||||
try{
|
||||
if(!DEBUG) return http.createClient(80, "createnspread.appspot.com");
|
||||
return http.createClient(80, "lordkaan.com");
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
console.log(err);
|
||||
return getClient();
|
||||
}
|
||||
}
|
||||
|
||||
var host = "0.0.0.0";
|
||||
var port = 1080;
|
||||
var http_server = http.createServer(httpHandler);
|
||||
var io = require("socket.io").listen(http_server);
|
||||
http_server.listen(port, host);
|
||||
|
||||
io.configure(function () {
|
||||
io.set('transports', ['websocket', 'flashsocket', 'xhr-polling']);
|
||||
});
|
||||
|
||||
|
||||
var adventure="adventure1";
|
||||
var game_version=-1;
|
||||
var waiting=new Object();
|
||||
var players=new Array();
|
||||
var maps=new Object();
|
||||
var gameDyn=0;
|
||||
var gdata="";
|
||||
|
||||
|
||||
downloadGame();
|
||||
function initMap(name)
|
||||
{
|
||||
console.log("GOT MAP "+name);
|
||||
maps[name]=eval("("+maps[name].tdata+")");
|
||||
}
|
||||
|
||||
function downloadMap(name)
|
||||
{
|
||||
var GAE=getClient();
|
||||
GAE.on("error",function(err){
|
||||
console.log(err);
|
||||
setTimeout(function(){downloadMap(name);},500);
|
||||
});
|
||||
var request = GAE.request('GET', "/rpgapp/getmap/"+adventure+"-"+name);
|
||||
maps[name]=new Object();
|
||||
maps[name].tdata="";
|
||||
request.end();
|
||||
request.on('response', function (response) {
|
||||
response.setEncoding('utf8');
|
||||
response.on('data', function (chunk) {
|
||||
maps[name].tdata+=chunk;
|
||||
});
|
||||
response.on('close',function(){
|
||||
console.log("CLOSED AMK: "+name);
|
||||
setTimeout(function(){downloadMap(name);},500);
|
||||
});
|
||||
response.on('end',function(){initMap(name);});
|
||||
});
|
||||
}
|
||||
|
||||
function downloadMaps()
|
||||
{
|
||||
var dene=123;
|
||||
gameDyn=eval("("+gdata+")");
|
||||
for(var i=0;i<gameDyn.maps.length;i++)
|
||||
{
|
||||
downloadMap(gameDyn.maps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadGame()
|
||||
{
|
||||
var GAE=getClient();
|
||||
GAE.on("error",function(err){
|
||||
console.log(err);
|
||||
setTimeout(function(){downloadGame();},500);
|
||||
});
|
||||
var request = GAE.request('GET', "/rpgapp/getdyn/"+adventure);
|
||||
request.end();
|
||||
request.on('response', function (response) {
|
||||
response.setEncoding('utf8');
|
||||
response.on('data', function (chunk) {
|
||||
gdata+=chunk;
|
||||
});
|
||||
response.on('close',function(){
|
||||
console.log("CLOSED AMK - GAME ");
|
||||
setTimeout(function(){downloadGame();},500);
|
||||
});
|
||||
response.on('end',function(){downloadMaps();});
|
||||
});
|
||||
}
|
||||
|
||||
function savePlayers(plrs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function saveGame()
|
||||
{
|
||||
var slen=50;
|
||||
for(i=0;i<players.length;i+=slen)
|
||||
{
|
||||
savePlayers(players.slice(i,i+50));
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
setInterval(sendWorld,100);
|
||||
setInterval(gameLogic,10);
|
||||
setInterval(saveGame,60000);
|
||||
},30000);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
|
||||
socket.on('setuser', function (data) {
|
||||
socket.set('user', data, function () {
|
||||
|
||||
handle_player(data["id"],data["char"],data["pass"],data["appid"],socket);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
socket.on('msg', function (msg) {
|
||||
console.log('Chat message !!!!!!!!!!!!!');
|
||||
io.sockets.emit('msg', { msg: msg});
|
||||
});
|
||||
|
||||
socket.on('coord', function (c) {
|
||||
socket.get("user",function(err,user){
|
||||
for(var i=0;i<players.length;i++)
|
||||
if(players[i].id==user.id)
|
||||
{
|
||||
players[i].x=c.x;
|
||||
players[i].y=c.y;
|
||||
players[i].d=c.d;
|
||||
players[i].m=c.m;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
socket.get("user",function(err,user){
|
||||
for(var i=0;i<players.length;i++)
|
||||
if(players[i].id==user.id)
|
||||
players.splice(i,1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
function gameLogic()
|
||||
{
|
||||
for(var i=0;i<players.length;i++)
|
||||
{
|
||||
var cur=players[i];
|
||||
if(!cur.x)
|
||||
{
|
||||
cur.x=maps[cur.map].spawn.x;
|
||||
cur.y=maps[cur.map].spawn.y;
|
||||
cur.d=0;
|
||||
cur.m=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendWorld()
|
||||
{
|
||||
var world=new Object();
|
||||
world.players=players;
|
||||
io.sockets.volatile.emit("world",world);
|
||||
}
|
||||
|
||||
function check_user(user,chr,pass,appid,socket)
|
||||
{
|
||||
data=eval('('+waiting[user].data+')');
|
||||
if(data.error)
|
||||
{
|
||||
socket.emit("disconnect");
|
||||
return;
|
||||
}
|
||||
if(!data.map)
|
||||
data.map="start";
|
||||
if(!data.character)
|
||||
{
|
||||
if(data.gender=="female")
|
||||
data.chtype="deffemale";
|
||||
else
|
||||
data.chtype="defmale";
|
||||
}
|
||||
data.character=gameDyn.characters[data.chtype];
|
||||
players.push(data);
|
||||
socket.emit('ready',data);
|
||||
}
|
||||
|
||||
function handle_player(user,chr,pass,appid,socket)
|
||||
{
|
||||
var GAE=getClient();
|
||||
GAE.on("error",function(err){
|
||||
console.log(err);
|
||||
setTimeout(function(){handle_player(user,chr,pass,appid,socket);},500);
|
||||
});
|
||||
var request = GAE.request('GET', "/rpgapp/"+appid+"/ackuser/"+user+"/"+chr+"/"+pass+"/");
|
||||
request.end();
|
||||
request.on('response', function (response) {
|
||||
response.setEncoding('utf8');
|
||||
waiting[user]=new Object();
|
||||
waiting[user].data="";
|
||||
response.on('data', function (chunk) {
|
||||
waiting[user].data+=chunk;
|
||||
});
|
||||
response.on('close',function(){
|
||||
console.log("CLOSED USER: "+user);
|
||||
setTimeout(function(){handle_player(user,chr,pass,appid,socket);},500);
|
||||
});
|
||||
response.on('end',function(){check_user(user,chr,pass,appid,socket);});
|
||||
});
|
||||
}
|
||||
|
||||
function httpHandler(request, response)
|
||||
{
|
||||
console.log("WHY THE FUCK?");
|
||||
|
||||
}
|
||||
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
for(var i=0;i<10;i++)
|
||||
{
|
||||
function callLater(i)
|
||||
{
|
||||
return (function(){console.log(i);});
|
||||
}
|
||||
var gg=callLater(i);
|
||||
setTimeout(gg,1000);
|
||||
}
|
||||
Reference in New Issue
Block a user