/
catan.js
157 lines (117 loc) · 3.37 KB
/
catan.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
CATAN.Notifications = [];
CATAN.Notify = function(data) {
if(window.webkitNotifications) {
if(window.webkitNotifications.checkPermission() == 0) {
var timeout = data.timeout ? data.timeout : 10000,
note;
if(!data.type || data.type == "default") {
var icon = data.icon ? data.icon : '',
title = data.title ? data.title : T('Title'),
subtitle = data.subtitle ? data.subtitle : "";
note = window.webkitNotifications.createNotification(icon,title,subtitle);
} else if(data.type == "html") {
var url = data.url ? data.url : "http://google.com/" // replace with 404 page later
note = window.webkitNotifications.createHTMLNotification(data.url);
}
note.show();
setTimeout(function(){
if(note != undefined) {
note.cancel();
}
}, timeout);
CATAN.Notifications.push(note);
} else {
window.webkitNotifications.requestPermission(this.Notify);
this.chat.AddLine(data.subtitle, "forcechat");
}
} else {
this.chat.AddLine(data.subtitle);
}
}
CATAN.ClearNotifications = function() {
var notifications = CATAN.Notifications;
for(var i in notifications) {
notifications[i].cancel();
}
CATAN.Notifications.length = 0;
}
CATAN.getName = function() {
return (localStorage && localStorage.Name) ? localStorage.Name : T('DefaultName');
}
CATAN.getSchema = function() {
return this.Schemas.get("Classic"); // static for now
}
CATAN.mouseRayTrace = function( event ) {
//if(onTurn != true) return; // TODO: prevent tracing while not client's turn
var camera = CATAN.Game.camera;
var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
CATAN.Game.controls.projector.unprojectVector( vector, CATAN.Game.camera );
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
var intersects = ray.intersectObjects( CATAN.Game.collisionObjects );
var hitObject = intersects[0];
if(hitObject) {
var ent = hitObject.object.Parent;
if (ent.isVisible()) {
return ent;
};
//CATAN.Game.lastSelection = hitObject.object;
};
};
CATAN.endBuildMode = function() {
var entities = CATAN.ents.getByName(["HexCorner","HexEdge"]);
for(var i in entities) {
var ent2 = entities[i];
if(!ent2.hasOwner()) {
ent2.hide();
}
}
}
CATAN.onSelectEntity = function(ent) {
if(!CATAN.LocalPlayer.isTurn()) return;
if(ent.isTile()) {
CATAN.server.emit('movedRobber', {
id: ent.getEntId()
});
} else {
CATAN.server.emit('playerBuild', {
id: ent.getEntId()
});
}
}
CATAN.getAvailableBuildings = function() {
var ply = CATAN.LocalPlayer;
var list = [];
var corners = this.board.getCorners();
for(var i in corners) {
var corner = corners[i];
if(corner.canBuild()) {
list.push(corner);
}
};
var edges = this.board.getEdges();
for(var i in edges) {
var edge = edges[i];
if(edge.canBuild(ply)) {
list.push(edge);
}
};
/*var corners = ply.getCorners();
for(var i in corners) {
var corner = corners[i];
var adjCorners = corner.getAdjacentCorners();
for(var j in adjCorners) {
if(adjCorners[j].canBuild()) {
list.push(adjCorners[j].getEntId());
}
}
var adjEdges = corner.getAdjacentEdges();
for(var j in adjEdges) {
var adjEdge = adjEdges[j];
if(adjEdge.canBuild(ply)) {
list.push(adjEdge.getEntId());
}
// TODO: Add adjacent roads
}
}*/
return list;
}