WIP
This commit is contained in:
parent
288a946ced
commit
b1e757d02c
@ -33,6 +33,10 @@
|
|||||||
var newLng = coords.lng + (x * M) / Math.cos(coords.lat * (Math.PI / 180));
|
var newLng = coords.lng + (x * M) / Math.cos(coords.lat * (Math.PI / 180));
|
||||||
return { lat: newLat, lng: newLng };
|
return { lat: newLat, lng: newLng };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toPos(coords) {
|
||||||
|
return { lat: parseFloat(msg.split(",")[0]), lng: parseFloat(msg.split(",")[1]) };
|
||||||
|
}
|
||||||
function getSurroundings (location) {
|
function getSurroundings (location) {
|
||||||
const meters = 100;
|
const meters = 100;
|
||||||
const R_EARTH = 6378.137;
|
const R_EARTH = 6378.137;
|
||||||
@ -59,9 +63,7 @@
|
|||||||
const rlat2 = mk2.lat * (Math.PI / 180);
|
const rlat2 = mk2.lat * (Math.PI / 180);
|
||||||
const difflat = rlat2 - rlat1;
|
const difflat = rlat2 - rlat1;
|
||||||
const difflon = (mk2.lng - mk1.lng) * (Math.PI / 180);
|
const difflon = (mk2.lng - mk1.lng) * (Math.PI / 180);
|
||||||
const km =
|
const km = 2 * R *
|
||||||
2 *
|
|
||||||
R *
|
|
||||||
Math.asin(Math.sqrt(Math.sin(difflat / 2) * Math.sin(difflat / 2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon / 2) * Math.sin(difflon / 2)));
|
Math.asin(Math.sqrt(Math.sin(difflat / 2) * Math.sin(difflat / 2) + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon / 2) * Math.sin(difflon / 2)));
|
||||||
return km;
|
return km;
|
||||||
};
|
};
|
||||||
@ -85,41 +87,28 @@
|
|||||||
|
|
||||||
var isOpen = $.getSetIniDbBoolean('chatguessr', 'isOpen', false),
|
var isOpen = $.getSetIniDbBoolean('chatguessr', 'isOpen', false),
|
||||||
seed = {},
|
seed = {},
|
||||||
guesses = {
|
scale,
|
||||||
'1':[
|
|
||||||
{user:'Alpha',location:'0,0',distance:5,score:2,streak:0},
|
|
||||||
{user:'Beta',location:'5,0',distance:100,score:3,streak:0},
|
|
||||||
{user:'Charlie',location:'6,6',distance:1000,score:0,streak:0},
|
|
||||||
{user:'Delta',location:'42,6',distance:1,score:5,streak:1}
|
|
||||||
],
|
|
||||||
'2':[
|
|
||||||
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
function dbSetSeed(id) {
|
|
||||||
$.inidb.SetBoolean("chatguessr", "isOpen", "", open);
|
|
||||||
isOpen = open;
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbSetOpen(open) {
|
|
||||||
$.inidb.SetBoolean("chatguessr", "isOpen", "", open);
|
|
||||||
isOpen = open;
|
|
||||||
sendData('status',open);
|
|
||||||
}
|
|
||||||
function dbClearGuesses() {
|
|
||||||
guesses = {};
|
guesses = {};
|
||||||
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
|
||||||
sendData('guesses',guesses);
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbAddGuess(user,position) {
|
function addGuess(user,position) {
|
||||||
if(guesses[user] && guesses[user].length > 0){
|
if(seed.round == undefined) return;
|
||||||
}else if(isCoordinates(position)){
|
let current_round = ""+seed.round;
|
||||||
guesses[user] = position;
|
if(guesses[current_round]==undefined) guesses[current_round] = []
|
||||||
$.inidb.SetString("chatguessr", "guesses", JSON.stringify(guesses));
|
if(guesses[current_round].some((v)=>v.user==user)) return;
|
||||||
sendData('guesses',JSON.stringify(guesses));
|
if(!isCoordinates(position)) return;
|
||||||
}
|
let pos = toPos(position)
|
||||||
|
let distance = haversineDistance(pos, {lat:seed.rounds[current_round].lat,lon:seed.rounds[current_round].lon})
|
||||||
|
|
||||||
|
let score = calculateScore(distance, scale)
|
||||||
|
guesses[current_round].push({
|
||||||
|
user:user,
|
||||||
|
location:location,
|
||||||
|
distance:distance,
|
||||||
|
score:score,
|
||||||
|
streak: 0,
|
||||||
|
});
|
||||||
|
sendData('guesses',JSON.stringify(guesses));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendData(tpe, data) {
|
function sendData(tpe, data) {
|
||||||
@ -130,11 +119,6 @@
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCoordinates(coordinates) {
|
|
||||||
const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g;
|
|
||||||
return regex.test(coordinates);
|
|
||||||
};
|
|
||||||
|
|
||||||
$.bind('command', function(event) {
|
$.bind('command', function(event) {
|
||||||
const sender = event.getSender().toLowerCase(),
|
const sender = event.getSender().toLowerCase(),
|
||||||
command = event.getCommand(),
|
command = event.getCommand(),
|
||||||
@ -154,13 +138,28 @@
|
|||||||
$.setIniDbBoolean('cgstatus', 'isOpen', false)
|
$.setIniDbBoolean('cgstatus', 'isOpen', false)
|
||||||
}else if(action.equalsIgnoreCase('start')){
|
}else if(action.equalsIgnoreCase('start')){
|
||||||
seed = fetchSeed(args[1]);
|
seed = fetchSeed(args[1]);
|
||||||
|
scale = calculateScale(seed.bouds)
|
||||||
}else if(action.equalsIgnoreCase('end')){
|
}else if(action.equalsIgnoreCase('end')){
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
$.setIniDbBoolean('cgstatus', 'isOpen', false)
|
$.setIniDbBoolean('cgstatus', 'isOpen', false)
|
||||||
|
guesses = {};
|
||||||
|
seed = {};
|
||||||
|
sendData('guesses',JSON.stringify(guesses));
|
||||||
}else if(action.equalsIgnoreCase('refresh')){
|
}else if(action.equalsIgnoreCase('refresh')){
|
||||||
var newseed = fetchSeed(args[1]);
|
var newseed = fetchSeed(args[1]);
|
||||||
|
if(newseed.state=="finished"){
|
||||||
|
//FINISHED
|
||||||
|
}else if(newseed.player.guesses.length() > seed.player.guesses.length()){
|
||||||
|
//NEW ROUND !
|
||||||
|
}
|
||||||
}else if(action.equalsIgnoreCase('gg')){
|
}else if(action.equalsIgnoreCase('gg')){
|
||||||
sendData('guesses',JSON.stringify(guesses));
|
sendData('guesses',JSON.stringify(guesses));
|
||||||
|
}else if(action.equalsIgnoreCase('fg')){
|
||||||
|
DBAddG("Alpha","0,0");
|
||||||
|
DBAddG("Beta","40,0");
|
||||||
|
DBAddG("Charlie","0,60");
|
||||||
|
DBAddG("Delta","80,80");
|
||||||
|
sendData('guesses',JSON.stringify(guesses));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -175,6 +174,7 @@
|
|||||||
$.registerChatSubcommand('cga', 'end', 2);
|
$.registerChatSubcommand('cga', 'end', 2);
|
||||||
$.registerChatSubcommand('cga', 'refresh', 2);
|
$.registerChatSubcommand('cga', 'refresh', 2);
|
||||||
$.registerChatSubcommand('cga', 'gg', 2);
|
$.registerChatSubcommand('cga', 'gg', 2);
|
||||||
|
$.registerChatSubcommand('cga', 'fg', 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user