ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/rent.ext
Revision: 1.1
Committed: Mon Sep 18 00:40:30 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
Log Message:
renting system basis

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     use List::Util;
4    
5     my %apartment = (
6     "/scorn/apartment/apartments" => [ 1, "scorn", "skorn"],
7     "/santo/dominion/sdomino/appartment" => [ 10, "santo dominion", "domino"],
8     "/darcap/darcap/apartment" => [ 30, "darcap", "thecap"],
9     "/navar_city/apartments/apartment" => [ 250, "navar", "navar"],
10     "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"],
11     "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"],
12     "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"],
13     "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"],
14     "/brest/apartments/brest/town/house" => [30000, "brest", "brecht"],
15     );
16    
17     sub teleport {
18     my ($pl, $map, $x, $y) = @_;
19    
20     my $portal = cf::object::new "exit";
21    
22     $portal->slaying ($map);
23     $portal->stats->hp ($x);
24     $portal->stats->sp ($y);
25     $portal->apply ($pl->ob);
26     $portal->free;
27     }
28    
29     sub update_balance {
30     my ($pl) = @_;
31    
32     my $NOW = time;
33    
34     # 1 silver per day per level per apartment of kingdom tax
35     my $offline = (List::Util::min 30, ($NOW - $pl->{rent}{last_offline_check}) / 86400)
36     * (cf::exp_to_level $pl->ob->stats->exp)
37     * scalar keys %{ $pl->{rent}{apartment} };
38    
39     # once per hour per map rented
40     my $online = ($NOW - $pl->{rent}{last_offline_check}) / 3600
41     * List::Util::sum map $apartment{$_}[0], keys %{ $pl->{rent}{apartment} };
42    
43     #TODO: add to {balance}
44     warn "off $offline on $online\n";#d#
45     }
46    
47     sub pay_balance {
48     my ($pl) = @_;
49    
50     #TODO: rob the bank if balance > 0
51     }
52    
53     sub find_apartment {
54     my ($pl, $name) = @_;
55    
56     #TODO: find apartment or reply with error
57     }
58    
59     cf::register_script_function "rent::overview" => sub {
60     my ($pl, $types) = @_;
61    
62     while (my ($k, $v) = each %apartment) {
63     my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2;
64    
65     $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] ("
66     . (cf::cost_string_from_value $v->[0]) . "/hr)")
67     if $type & $types;
68     }
69     };
70    
71     cf::register_script_function "rent::status" => sub {
72     my ($pl, $types) = @_;
73    
74     if ($pl->{rent}{balance} <= 0) {
75     $pl->ob->reply (undef, "You have no debts to pay.");
76     } else {
77     $pl->ob->reply (undef, "You owe us " . (cf::cost_string_from_value $pl->{rent}{balance}) . ".");
78     }
79     };
80    
81     cf::register_script_function "rent::rent" => sub {
82     my ($pl, $apartment) = @_;
83    
84     $apartment = find_apartment $apartment
85     or return;
86    
87     update_balance $pl;
88    
89     $pl->{rent}{apartment}{$apartment} = undef;
90     };
91    
92     cf::register_script_function "rent::stop" => sub {
93     my ($pl, $apartment) = @_;
94    
95     $apartment = find_apartment $apartment
96     or return;
97    
98     update_balance $pl;
99    
100     delete $pl->{rent}{apartment}{$apartment};
101     };
102    
103     cf::attach_to_players prio => 100,
104     on_login => sub {
105     return;
106     my ($pl) = @_;
107    
108     use Data::Dumper;
109     warn Dumper $pl;
110    
111     $pl->{rent}{last_offline_check} ||= time;
112    
113     if ($pl->{rent}{last_online_check}) {
114     $pl->{rent}{last_online_check} = time
115     - List::Util::min 3600,
116     $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check};
117     } else {
118     $pl->{rent}{last_online_check} = time;
119     }
120    
121     update_balance $pl;
122     };
123    
124     cf::register_map_attachment rent =>
125     on_enter => sub {
126     return;
127     my ($map, $pl, $x, $y) = @_;
128    
129     # teleport $pl, "/world/world_105_115", 2, 34;
130     # cf::override;
131     };
132