-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
158 lines (144 loc) · 4.26 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function getmousesquare(mousex,mousey,tilesize){
squarex=(mousex-(mousex%tilesize))/tilesize;
squarey=(mousey-(mousey%tilesize))/tilesize;
}
function getsquarecontents(terrain,decals,items,creatures,square,radius){
var playerx=creatures[0].position.x;
var playery=creatures[0].position.y;
var localterrain;
localterrain = terrain[square.x][square.y];
switch (localterrain){
case "u":
localterrain="none";
break;
case "0":
localterrain="floor";
break;
case "1":
localterrain="wall";
break;
case "2":
localterrain="stairup";
break;
case "3":
localterrain="stairdown";
break;
}
var localdecal;
localdecal = parseInt(decals[square.x][square.y]);
if (localdecal!=0){
localdecal ="decal"+localdecal;
}
var localitem = false;
for (item in items){
if (items[item].position.x-playerx+radius==square.x&&items[item].position.y-playery+radius==square.y) {
localitem=items[item].type;
}
}
var localcreature = false;
for (creature in creatures){
if (creatures[creature].position.x-playerx+radius==square.x&&creatures[creature].position.y-playery+radius==square.y) {
localcreature=creatures[creature];
}
}
var contentstack = [];
contentstack.push(localterrain);
contentstack.push(localdecal);
contentstack.push(localitem);
contentstack.push(localcreature);
return contentstack;
}
function getcreatureatsquare(creatures,square,radius){
var playerx=false;
var playery=false;
for (creature in creatures){
if (creatures[creature].type=="player"){
playerx=creatures[creature].position.x;
playery=creatures[creature].position.y;
}
}
var localcreature = false;
for (creature in creatures){
if (creatures[creature].position.x-playerx+radius==square.x&&creatures[creature].position.y-playery+radius==square.y) {
localcreature=creatures[creature];
}
}
return localcreature;
}
function getlocalimagestack(terrain,decals,items,creatures,square,radius){
var squarecontents=getsquarecontents(terrain,decals,items,creatures,square,radius);
var imgstack = [];
for (i=0;i<3;i++){
imgstack.push(squarecontents[i]);
}
if (squarecontents[3]!=false){
imgstack.push(squarecontents[3].type);
for (piece in squarecontents[3].equipment){
imgstack.push(squarecontents[3].equipment[piece]);
}
} else {
imgstack.push(squarecontents[3]);
}
return imgstack;
}
function getnexttarget(creatures,radius) {
var target=false;
var dist=2*radius;
for (creature in creatures){
var dist2=Math.abs(creatures[creature].position.x-creatures[0].position.x)
+Math.abs(creatures[creature].position.y-creatures[0].position.y);
if (dist2<=dist&&dist2>0){
dist=dist2;
target=creatures[creature].position;
}
}
return target;
}
function parsedata(thisdata){
//$("#outtakes").html(thisdata);
var outputs=JSON.parse(thisdata);
//parse terrain/decals output
outputs.terrain=outputs.terrain.split("L");
for (i in outputs.terrain){
outputs.terrain[i]=outputs.terrain[i].split("");
}
outputs.explored=outputs.explored.split("L");
for (i in outputs.explored){
outputs.explored[i]=outputs.explored[i].split("");
}
outputs.decals=outputs.decals.split("L");
for (i in outputs.decals){
outputs.decals[i]=outputs.decals[i].split("");
}
return outputs;
}
function playmove(com,mod){
}
function drawUIskin(opentab){
var ctx = document.getElementById("controls").getContext("2d");
var img;
img = document.getElementById("uibars");
ctx.drawImage(img,180,0,208,64);
img = document.getElementById("uicast");
ctx.drawImage(img,336,148,52,32);
img = document.getElementById("uiexplore");
ctx.drawImage(img,180,148,52,32);
img = document.getElementById("uifight");
ctx.drawImage(img,232,148,52,32);
img = document.getElementById("uiinfobox");
ctx.drawImage(img,0,180,388,144);
img = document.getElementById("ui"+opentab);
ctx.drawImage(img,62,324,326,196);
img = document.getElementById("uiitembutton");
ctx.drawImage(img,0,324,62,38);
img = document.getElementById("uimagicbutton");
ctx.drawImage(img,0,362,62,38);
img = document.getElementById("uioptionsbuttons");
ctx.drawImage(img,0,438,62,38);
img = document.getElementById("uirest");
ctx.drawImage(img,284,148,52,32);
img = document.getElementById("uiskillbutton");
ctx.drawImage(img,0,400,62,38);
img = document.getElementById("uistats");
ctx.drawImage(img,180,64,208,84);
}