ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.106 by root, Mon Jul 24 04:24:42 2006 UTC vs.
Revision 1.114 by elmex, Mon Aug 14 04:34:40 2006 UTC

1=head1 NAME 1=head1 NAME
2 2
3CFClient - undocumented utility garbage for our crossfire client 3CFPlus - undocumented utility garbage for our crossfire client
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use CFClient; 7 use CFPlus;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package CFClient; 15package CFPlus;
16 16
17BEGIN { 17BEGIN {
18 $VERSION = '0.1'; 18 $VERSION = '0.2';
19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFPlus", $VERSION;
22} 22}
23 23
24use utf8; 24use utf8;
25 25
26use Carp (); 26use Carp ();
28use BerkeleyDB; 28use BerkeleyDB;
29use Pod::POM (); 29use Pod::POM ();
30use Scalar::Util (); 30use Scalar::Util ();
31use Storable (); # finally 31use Storable (); # finally
32 32
33our %STAT_TOOLTIP = (
34 Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack",
35 Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed",
36 Con => "<b>Constitution</b>, physical health and toughness. Determines how many healthpoints you can have",
37 Int => "<b>Intelligence</b>, your ability to learn and use skills and incantations (both prayers and magic) and determines how much spell points you can have",
38 Wis => "<b>Wisdom</b>, the ability to learn and use divine magic (prayers). Determines how many grace points you can have",
39 Pow => "<b>Power</b>, your magical potential. Influences the strength of spell effects, and also how much your spell and grace points increase when leveling up",
40 Cha => "<b>Charisma</b>, how well you are received by NPCs. Affects buying and selling prices in shops.",
41
42 Wc => "<b>Weapon Class</b>, effectiveness of melee/missile attacks. Lower is more potent. Current weapon, level and Str are some things which effect the value of Wc. The value of Wc may range between 25 and -72.",
43 Ac => "<b>Armour Class</b>, how protected you are from being hit by any attack. Lower values are better. Ac is based on your race and is modified by the Dex and current armour worn. For characters that cannot wear armour, Ac improves as their level increases.",
44 Dam => "<b>Damage</b>, how much damage your melee/missile attack inflicts. Higher values indicate a greater amount of damage will be inflicted with each attack.",
45 Arm => "<b>Armour</b>, how much damage (from physical attacks) will be subtracted from successful hits made upon you. This value ranges between 0 to 99%. Current armour worn primarily determines Arm value. This is the same as the physical resistance.",
46 Spd => "<b>Speed</b>, how fast you can move. The value of speed may range between nearly 0 (\"very slow\") to higher than 5 (\"lightning fast\"). Base speed is determined from the Dex and modified downward proportionally by the amount of weight carried which exceeds the Max Carry limit. The armour worn also sets the upper limit on speed.",
47 WSp => "<b>Weapon Speed</b>, how many attacks you may make per unit of time (0.120s). Higher values indicate faster attack speed. Current weapon and Dex effect the value of weapon speed.",
48);
49
50=item guard { BLOCK } 33=item guard { BLOCK }
51 34
52Returns an object that executes the given block as soon as it is destroyed. 35Returns an object that executes the given block as soon as it is destroyed.
53 36
54=cut 37=cut
55 38
56sub guard(&) { 39sub guard(&) {
57 bless \(my $cb = $_[0]), "CFClient::Guard" 40 bless \(my $cb = $_[0]), "CFPlus::Guard"
58} 41}
59 42
60sub CFClient::Guard::DESTROY { 43sub CFPlus::Guard::DESTROY {
61 ${$_[0]}->() 44 ${$_[0]}->()
62} 45}
63 46
64sub asxml($) { 47sub asxml($) {
65 local $_ = $_[0]; 48 local $_ = $_[0];
69 s/</&lt;/g; 52 s/</&lt;/g;
70 53
71 $_ 54 $_
72} 55}
73 56
74package CFClient::Database; 57package CFPlus::Database;
75 58
76our @ISA = BerkeleyDB::Btree::; 59our @ISA = BerkeleyDB::Btree::;
77 60
78sub get($$) { 61sub get($$) {
79 my $data; 62 my $data;
91 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); 74 $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync });
92 75
93 $db->db_put ($key => $data) 76 $db->db_put ($key => $data)
94} 77}
95 78
96package CFClient; 79package CFPlus;
97 80
98sub find_rcfile($) { 81sub find_rcfile($) {
99 my $path; 82 my $path;
100 83
101 for (grep !ref, @INC) { 84 for (grep !ref, @INC) {
102 $path = "$_/CFClient/resources/$_[0]"; 85 $path = "$_/CFPlus/resources/$_[0]";
103 return $path if -r $path; 86 return $path if -r $path;
104 } 87 }
105 88
106 die "FATAL: can't find required file $_[0]\n"; 89 die "FATAL: can't find required file $_[0]\n";
107} 90}
108 91
92BEGIN {
93 use Crossfire::Protocol::Base ();
94 *to_json = \&Crossfire::Protocol::Base::to_json;
95 *from_json = \&Crossfire::Protocol::Base::from_json;
96}
97
109sub read_cfg { 98sub read_cfg {
110 my ($file) = @_; 99 my ($file) = @_;
111 100
112 open CFG, $file 101 open my $fh, $file
113 or return; 102 or return;
114 103
115 my $CFG;
116
117 local $/; 104 local $/;
118 $CFG = eval <CFG>; 105 my $CFG = <$fh>;
119 106
120 $::CFG = $CFG; 107 if ($CFG =~ /^---/) { ## TODO compatibility cruft, remove
121 108 require YAML;
122 close CFG; 109 utf8::decode $CFG;
110 $::CFG = YAML::Load ($CFG);
111 } elsif ($CFG =~ /^\{/) {
112 $::CFG = from_json $CFG;
113 } else {
114 $::CFG = eval $CFG; ## todo comaptibility cruft
115 }
123} 116}
124 117
125sub write_cfg { 118sub write_cfg {
126 my ($file) = @_; 119 my ($file) = @_;
127 120
128 open CFG, ">$file" 121 $::CFG->{VERSION} = $::VERSION;
122
123 open my $fh, ">:utf8", $file
129 or return; 124 or return;
130 125 print $fh to_json $::CFG;
131 {
132 require Data::Dumper;
133 local $Data::Dumper::Purity = 1;
134 $::CFG->{VERSION} = $::VERSION;
135 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]);
136 }
137
138 close CFG;
139} 126}
140 127
141our $DB_ENV; 128our $DB_ENV;
142 129
143{ 130{
162sub db_table($) { 149sub db_table($) {
163 my ($table) = @_; 150 my ($table) = @_;
164 151
165 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 152 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
166 153
167 new CFClient::Database 154 new CFPlus::Database
168 -Env => $DB_ENV, 155 -Env => $DB_ENV,
169 -Filename => $table, 156 -Filename => $table,
170# -Filename => "database", 157# -Filename => "database",
171# -Subname => $table, 158# -Subname => $table,
172 -Property => DB_CHKSUM, 159 -Property => DB_CHKSUM,
173 -Flags => DB_CREATE | DB_UPGRADE, 160 -Flags => DB_CREATE | DB_UPGRADE,
174 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 161 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
175} 162}
176 163
177package CFClient::Layout; 164package CFPlus::Layout;
178 165
179$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Layout"} = sub { 166$CFPlus::OpenGL::SHUTDOWN_HOOK{"CFPlus::Layout"} = sub {
180 reset_glyph_cache; 167 reset_glyph_cache;
181}; 168};
182 169
183package CFClient::Item; 170package CFPlus::Item;
184 171
185use strict; 172use strict;
186use Crossfire::Protocol::Constants; 173use Crossfire::Protocol::Constants;
187 174
188my $last_enter_count = 1; 175my $last_enter_count = 1;
222} 209}
223 210
224sub do_n_dialog { 211sub do_n_dialog {
225 my ($cb) = @_; 212 my ($cb) = @_;
226 213
227 my $w = new CFClient::UI::FancyFrame 214 my $w = new CFPlus::UI::Toplevel
228 on_delete => sub { $_[0]->destroy; 1 }, 215 on_delete => sub { $_[0]->destroy; 1 },
229 has_close_button => 1, 216 has_close_button => 1,
230 ; 217 ;
231 218
232 $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); 219 $w->add (my $vb = new CFPlus::UI::VBox x => "center", y => "center");
233 $vb->add (new CFClient::UI::Label text => "Enter item count:"); 220 $vb->add (new CFPlus::UI::Label text => "Enter item count:");
234 $vb->add (my $entry = new CFClient::UI::Entry 221 $vb->add (my $entry = new CFPlus::UI::Entry
235 text => $last_enter_count, 222 text => $last_enter_count,
236 on_activate => sub { 223 on_activate => sub {
237 my ($entry) = @_; 224 my ($entry) = @_;
238 $last_enter_count = $entry->get_text; 225 $last_enter_count = $entry->get_text;
239 $cb->($last_enter_count); 226 $cb->($last_enter_count);
261 248
262 if ($self->{container} == $::CONN->{player}{tag}) { 249 if ($self->{container} == $::CONN->{player}{tag}) {
263 $targ = $::CONN->{open_container}; 250 $targ = $::CONN->{open_container};
264 } 251 }
265 252
266 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { 253 if (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 1) {
267 $::CONN->send ("move $targ $self->{tag} 0") 254 $::CONN->send ("move $targ $self->{tag} 0")
268 if $targ || !($self->{flags} & F_LOCKED); 255 if $targ || !($self->{flags} & F_LOCKED);
269 } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) { 256 } elsif (($ev->{mod} & CFPlus::KMOD_SHIFT) && $ev->{button} == 2) {
270 $self->{flags} & F_LOCKED 257 $self->{flags} & F_LOCKED
271 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) 258 ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag})
272 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) 259 : $::CONN->send ("lock " . pack "CN", 1, $self->{tag})
273 } elsif ($ev->{button} == 1) { 260 } elsif ($ev->{button} == 1) {
274 $::CONN->send ("examine $self->{tag}"); 261 $::CONN->send ("examine $self->{tag}");
285 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], 272 ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }],
286 ["ignite/thaw", # first try of an easier use of flint&steel 273 ["ignite/thaw", # first try of an easier use of flint&steel
287 sub { 274 sub {
288 $::CONN->send ("mark ". pack "N", $self->{tag}); 275 $::CONN->send ("mark ". pack "N", $self->{tag});
289 $::CONN->send ("command apply flint and steel"); 276 $::CONN->send ("command apply flint and steel");
277 }
278 ],
279 ["inscribe", # first try of an easier use of flint&steel
280 sub {
281 &::open_string_query ("Text to inscribe", sub {
282 my ($entry, $txt) = @_;
283 $::CONN->send ("mark ". pack "N", $self->{tag});
284 $::CONN->send ("command use_skill inscription $txt");
285 });
286 }
287 ],
288 ["rename", # first try of an easier use of flint&steel
289 sub {
290 &::open_string_query ("Rename item to:", sub {
291 my ($entry, $txt) = @_;
292 $::CONN->send ("mark ". pack "N", $self->{tag});
293 $::CONN->send ("command rename to <$txt>");
294 });
290 } 295 }
291 ], 296 ],
292 ["apply", sub { $::CONN->send ("apply $self->{tag}") }], 297 ["apply", sub { $::CONN->send ("apply $self->{tag}") }],
293 ( 298 (
294 $self->{flags} & F_LOCKED 299 $self->{flags} & F_LOCKED
305 ] 310 ]
306 ) 311 )
307 ), 312 ),
308 ); 313 );
309 314
310 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 315 CFPlus::UI::Menu->new (items => \@menu_items)->popup ($ev);
311 } 316 }
312 317
313 1 318 1
314 }; 319 };
315 320
323 328
324 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5] 329 my $bg = $self->{flags} & F_CURSED ? [1 , 0 , 0, 0.5]
325 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5] 330 : $self->{flags} & F_MAGIC ? [0.2, 0.2, 1, 0.5]
326 : undef; 331 : undef;
327 332
328 $self->{face_widget} ||= new CFClient::UI::Face 333 $self->{face_widget} ||= new CFPlus::UI::Face
329 can_events => 1, 334 can_events => 1,
330 can_hover => 1, 335 can_hover => 1,
331 anim => $self->{anim}, 336 anim => $self->{anim},
332 animspeed => $self->{animspeed}, # TODO# must be set at creation time 337 animspeed => $self->{animspeed}, # TODO# must be set at creation time
333 on_button_down => $button_cb, 338 on_button_down => $button_cb,
341 . "Item uses face #$self->{face}. " 346 . "Item uses face #$self->{face}. "
342 . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ") 347 . ($self->{animspeed} ? "Item uses animation #$self->{anim} at " . (1 / $self->{animspeed}) . "fps. " : "Item is not animated. ")
343 . "\n\n$tooltip_std" 348 . "\n\n$tooltip_std"
344 ); 349 );
345 350
346 $self->{desc_widget} ||= new CFClient::UI::Label 351 $self->{desc_widget} ||= new CFPlus::UI::Label
347 can_events => 1, 352 can_events => 1,
348 can_hover => 1, 353 can_hover => 1,
349 ellipsise => 2, 354 ellipsise => 2,
350 align => -1, 355 align => -1,
351 on_button_down => $button_cb, 356 on_button_down => $button_cb,
352 ; 357 ;
353 my $desc = CFClient::Item::desc_string $self; 358 my $desc = CFPlus::Item::desc_string $self;
354 $self->{desc_widget}{bg} = $bg; 359 $self->{desc_widget}{bg} = $bg;
355 $self->{desc_widget}->set_text ($desc); 360 $self->{desc_widget}->set_text ($desc);
356 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std"); 361 $self->{desc_widget}->set_tooltip ("<b>$desc</b>.\n$tooltip_std");
357 362
358 $self->{weight_widget} ||= new CFClient::UI::Label 363 $self->{weight_widget} ||= new CFPlus::UI::Label
359 can_events => 1, 364 can_events => 1,
360 can_hover => 1, 365 can_hover => 1,
361 ellipsise => 0, 366 ellipsise => 0,
362 align => 0, 367 align => 0,
363 on_button_down => $button_cb, 368 on_button_down => $button_cb,
364 ; 369 ;
365 $self->{weight_widget}{bg} = $bg; 370 $self->{weight_widget}{bg} = $bg;
366 $self->{weight_widget}->set_text (CFClient::Item::weight_string $self); 371 $self->{weight_widget}->set_text (CFPlus::Item::weight_string $self);
367 $self->{weight_widget}->set_tooltip ( 372 $self->{weight_widget}->set_tooltip (
368 "<b>Weight</b>.\n" 373 "<b>Weight</b>.\n"
369 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ") 374 . ($self->{weight} >= 0 ? "One item weighs $self->{weight}g. " : "You have no idea how much this weighs. ")
370 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") 375 . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ")
371 . "\n\n$tooltip_std" 376 . "\n\n$tooltip_std"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines