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 |
root |
1.18 |
"/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"], |
10 |
|
|
"/celvear_port/tower2/tower2" => [ 150, "celvear port", "kevlar"], |
11 |
root |
1.1 |
"/navar_city/apartments/apartment" => [ 250, "navar", "navar"], |
12 |
|
|
"/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], |
13 |
|
|
"/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], |
14 |
root |
1.15 |
"/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"], |
15 |
root |
1.1 |
"/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], |
16 |
root |
1.16 |
"/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"], |
17 |
root |
1.18 |
"/towerapartment/tower1" => [10000, "gotisch", "risen"], |
18 |
|
|
"/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], |
19 |
root |
1.1 |
"/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], |
20 |
|
|
); |
21 |
|
|
|
22 |
|
|
# we have to special case some special cases :) |
23 |
|
|
sub reject_entry { |
24 |
|
|
my ($pl) = @_; |
25 |
|
|
|
26 |
root |
1.7 |
my $prev_pos = $pl->ob->{_prev_pos}; |
27 |
root |
1.8 |
$pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); |
28 |
root |
1.7 |
|
29 |
root |
1.1 |
cf::override; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
sub update_balance { |
33 |
|
|
my ($pl) = @_; |
34 |
|
|
|
35 |
|
|
my $NOW = time; |
36 |
|
|
|
37 |
|
|
# 1 silver per day per level per apartment of kingdom tax |
38 |
|
|
my $offline = (List::Util::min 30, ($NOW - $pl->{rent}{last_offline_check}) / 86400) |
39 |
|
|
* (cf::exp_to_level $pl->ob->stats->exp) |
40 |
|
|
* scalar keys %{ $pl->{rent}{apartment} }; |
41 |
|
|
|
42 |
|
|
# once per hour per map rented |
43 |
|
|
my $online = ($NOW - $pl->{rent}{last_online_check}) / 3600 |
44 |
|
|
* List::Util::sum map $apartment{$_}[0], keys %{ $pl->{rent}{apartment} }; |
45 |
|
|
|
46 |
|
|
$pl->{rent}{last_offline_check} = $NOW; |
47 |
|
|
$pl->{rent}{last_online_check} = $NOW; |
48 |
|
|
|
49 |
|
|
$pl->{rent}{balance} += $offline + $online; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
sub pay_balance { |
53 |
|
|
my ($pl) = @_; |
54 |
|
|
|
55 |
root |
1.11 |
cf::cede_to_tick; |
56 |
|
|
|
57 |
root |
1.1 |
update_balance $pl; |
58 |
|
|
|
59 |
|
|
return unless $pl->{rent}{balance} > 0; |
60 |
|
|
|
61 |
|
|
my $deduct = cf::ceil $pl->{rent}{balance}; |
62 |
|
|
|
63 |
|
|
my $deduct_string = cf::cost_string_from_value $deduct; |
64 |
|
|
|
65 |
|
|
if ($deduct <= $pl->ob->{bank_balance}) { |
66 |
|
|
cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; |
67 |
|
|
$pl->ob->{bank_balance} -= $deduct; |
68 |
|
|
$pl->{rent}{balance} -= $deduct; |
69 |
root |
1.10 |
$pl->ob->reply (undef, "Something whispers into your ear: " |
70 |
root |
1.9 |
. "Your highness, we deducted your apartment rent ($deduct_string) from your bank account."); |
71 |
root |
1.1 |
} else { |
72 |
root |
1.10 |
$pl->ob->reply (undef, "Something whispers into your ear: " |
73 |
root |
1.9 |
. "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " |
74 |
root |
1.1 |
. "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
sub check_balance { |
79 |
|
|
my ($pl) = @_; |
80 |
|
|
|
81 |
|
|
pay_balance $pl if $pl->{rent}{balance} > 0; |
82 |
|
|
|
83 |
|
|
$pl->{rent}{balance} <= 0 |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
sub find_apartment { |
87 |
|
|
my ($pl, $name) = @_; |
88 |
|
|
|
89 |
|
|
my $apartment = (grep $apartment{$_}[2] eq $name, keys %apartment)[0] |
90 |
|
|
or $pl->ob->reply (undef, "Sorry, but we do not offer model '$name' for rent."); |
91 |
|
|
|
92 |
|
|
$apartment |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
cf::register_script_function "rent::overview" => sub { |
96 |
|
|
my ($pl, $types) = @_; |
97 |
|
|
|
98 |
|
|
while (my ($k, $v) = each %apartment) { |
99 |
|
|
my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; |
100 |
|
|
|
101 |
root |
1.17 |
$pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] (" |
102 |
root |
1.10 |
. (cf::cost_string_from_value $v->[0]) . "/hr)\n") |
103 |
root |
1.1 |
if $type & $types; |
104 |
|
|
} |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
cf::register_script_function "rent::status" => sub { |
108 |
|
|
my ($pl, $types) = @_; |
109 |
|
|
|
110 |
|
|
if ($pl->{rent}{balance} <= 0) { |
111 |
|
|
$pl->ob->reply (undef, "You have no debts to pay."); |
112 |
|
|
} else { |
113 |
|
|
$pl->ob->reply (undef, "You owe us " . (cf::cost_string_from_value $pl->{rent}{balance}) . "."); |
114 |
|
|
} |
115 |
|
|
}; |
116 |
|
|
|
117 |
|
|
cf::register_script_function "rent::rent" => sub { |
118 |
|
|
my ($pl, $apartment) = @_; |
119 |
|
|
|
120 |
|
|
$apartment = find_apartment $pl, $apartment |
121 |
|
|
or return; |
122 |
|
|
|
123 |
|
|
update_balance $pl; |
124 |
|
|
|
125 |
|
|
$pl->{rent}{apartment}{$apartment} = undef; |
126 |
|
|
|
127 |
root |
1.9 |
$pl->ob->reply (undef, "Wonderful decision, your highness! " |
128 |
root |
1.1 |
. "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " |
129 |
|
|
. "We are sure you will be satisfied!"); |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
cf::register_script_function "rent::stop" => sub { |
133 |
|
|
my ($pl, $apartment) = @_; |
134 |
|
|
|
135 |
|
|
$apartment = find_apartment $pl, $apartment |
136 |
|
|
or return; |
137 |
|
|
|
138 |
|
|
update_balance $pl; |
139 |
|
|
|
140 |
|
|
delete $pl->{rent}{apartment}{$apartment}; |
141 |
|
|
|
142 |
|
|
$pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); |
143 |
|
|
}; |
144 |
|
|
|
145 |
root |
1.2 |
cf::player->attach ( |
146 |
|
|
prio => 100, |
147 |
root |
1.1 |
on_login => sub { |
148 |
|
|
my ($pl) = @_; |
149 |
|
|
|
150 |
|
|
$pl->{rent}{last_offline_check} ||= time; |
151 |
|
|
|
152 |
|
|
if ($pl->{rent}{last_online_check}) { |
153 |
|
|
$pl->{rent}{last_online_check} = time |
154 |
|
|
- List::Util::min 3600, |
155 |
root |
1.13 |
$pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check}; |
156 |
root |
1.1 |
} else { |
157 |
|
|
$pl->{rent}{last_online_check} = time; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
update_balance $pl; |
161 |
root |
1.2 |
}, |
162 |
|
|
); |
163 |
root |
1.1 |
|
164 |
root |
1.2 |
cf::map::attachment rent => |
165 |
root |
1.1 |
on_enter => sub { |
166 |
|
|
my ($map, $pl, $x, $y) = @_; |
167 |
|
|
|
168 |
root |
1.7 |
my $pfx = sprintf "~%s/", $pl->ob->name; |
169 |
root |
1.1 |
|
170 |
root |
1.7 |
# only do something if entering ones own apartment |
171 |
|
|
if ($pfx eq substr $map->path, 0, length $pfx) { |
172 |
|
|
for my $path (keys %{ $pl->{rent}{apartment} }) { |
173 |
|
|
$path = sprintf "~%s%s", $pl->ob->name, $path; |
174 |
|
|
|
175 |
|
|
if ($map->path eq $path) { |
176 |
|
|
if (check_balance $pl) { |
177 |
root |
1.9 |
$pl->ob->reply (undef, "Welcome to your apartment, your highness!"); |
178 |
root |
1.7 |
} else { |
179 |
root |
1.9 |
$pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); |
180 |
root |
1.7 |
reject_entry $pl; |
181 |
|
|
} |
182 |
root |
1.1 |
|
183 |
root |
1.7 |
return; |
184 |
root |
1.1 |
} |
185 |
root |
1.7 |
} |
186 |
root |
1.1 |
|
187 |
elmex |
1.14 |
$pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!"); |
188 |
root |
1.7 |
reject_entry $pl; |
189 |
root |
1.1 |
} |
190 |
|
|
}, |
191 |
|
|
; |
192 |
|
|
|
193 |
root |
1.12 |
our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub { |
194 |
|
|
pay_balance $_ for cf::player::list; |
195 |
|
|
}; |
196 |
root |
1.1 |
|