-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.pl
56 lines (45 loc) · 1.41 KB
/
token.pl
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
## internal, puts player's token in maps directory
##
## $token="[name] [level] [object]-[tick obj] [z] [expires]";
##
$a1=substr($player{'map'},0,1);
$b1=substr($player{'map'},1,1);
#print "pop=$player{'map'} - $a1.$b1 - $a2.$b2\n";
if($b1 gt $MapEdgeX){#city
$map="$a1$b1";
#this checks $y, no need to check $x
$z=$player{'z'}<$MapHigh*$MapWide?$player{'z'}:$MapHigh*$MapWide;
}else{
$a2=$a1; $a2++; if ($a2>$MapEdgeY) { $a2="A"; }
$b2=$b1; $b2++; if ($b2>$MapEdgeX) { $b2="0"; }
$map="";
$y=int($player{'z'}/$MapWide);
$x=$player{'z'}-($y*$MapWide);
if ($y>$MapSizeY) {
#print "pop=y > MapSizeY\n";
$y=$y-($MapSizeY+1);
$map.="$a2";
} else {
#print "pop=$y y > $MapSizeY MapSizeY else \n";
$map.="$a1";
}
if ($x>=$MapSizeX+1) {
#print "pop=x > MapSizeX\n";
$x=$x-($MapSizeX+1);
$map.="$b2";
} else {
#print "pop=x > MapSizeX else \n";
$map.="$b1";
}
$z=($y*($MapSizeX+1))+$x;
}
#print "pop=tmap.$map tz.$z\n";
$player{'tmap'}=$map;
$player{'tz'}=$z;
#print "pop=$player{'map'} - $a1.$b1 - $a2.$b2\n";
if (!-d "$datadir/tokens/$map/") { mkdir "$datadir/tokens/$map"; }
if (!-w "$datadir/tokens/$map/") { chmod 0766, "$datadir/tokens/$map"; }
if ($player{'token'}) { unlink "$datadir/tokens/$player{'token'}.txt"; }
$player{'token'}="$map/$player{'name'} $player{'level'} $player{'object'}-$TickObj $z $estamp ";
open (FILE, ">$datadir/tokens/$player{'token'}.txt"); print FILE "player"; close FILE;
1;