L
R
HOME
FORUM
DOWNLOADS
Content
Links
Browse SVN
SVN Commit log
Documentation (Wiki)
Developers
Taskmanager
User
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
December 02, 2008, 03:20:19 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search
Advanced search
BeBot - An Anarchy Online/Age Of Conan chat automaton
>
Forum
>
Modules
>
Official modules
> Topic:
Tokens Calulator
Pages: [
1
]
2
Go Down
« previous
next »
Print
Author
Topic: Tokens Calulator (Read 2465 times)
0 Members and 1 Guest are viewing this topic.
nebhyper
Rookie
Offline
Gender:
Posts: 62
Tokens Calulator
«
on:
December 06, 2006, 12:04:14 AM »
Tokens Calculator Module
Basically you tell it your level, goal tokens, current tokens and it tells you the number of bags and token (discs) you need to reach that goal.
!tokens 205 2500 1319
CHANGE
4 Feb 2007
- Fixed so you can not enter 0 for goal.
- Fixed tell responses to not send blobs.
3 Feb 2007
- !tokens no longer needs your level. The code finds your level. You can still eneter your level just in case your character info has not been added to the members table or the whois cache table.
- Changed the output to be a link displaying your stats on the top and the bottom has what you need to achieve your goal.
- Included upcoming Tokens for VP.
EDIT: Added Change log and files to first post
«
Last Edit: February 04, 2007, 03:11:59 PM by nebhyper
»
Logged
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.
jjones666
BeBot Contributor
Champion
Offline
Posts: 353
Re: !Tokens
«
Reply #1 on:
January 23, 2007, 08:01:47 AM »
Excellent plugin, moved to the official custom modules section.
-jj-
Logged
Malosar
Expert
Offline
Posts: 259
Re: !Tokens
«
Reply #2 on:
January 23, 2007, 10:10:23 AM »
Code:
function tell($name, $msg)
{
if (preg_match("/^".$this -> bot -> commpre."tokens ([0-9]+) ([0-9]+) ([0-9]+)$/i", $msg, $info)) {
$this -> bot -> send_tell($this -> ShowTokens($info[1], $info[2], $info[3]));
}
}
send_tell needs a $name, change to:
Code:
$this -> bot -> send_tell($name,$this -> ShowTokens($info[1], $info[2], $info[3]));
Logged
Eternalist
General of The Syndicate
nebhyper
Rookie
Offline
Gender:
Posts: 62
Re: !Tokens
«
Reply #3 on:
January 23, 2007, 10:55:36 AM »
Actually I forgot to update this post.
I've attached my current module.
EDIT: Changed first post to have changes and files
«
Last Edit: February 03, 2007, 01:35:06 PM by nebhyper
»
Logged
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.
nebhyper
Rookie
Offline
Gender:
Posts: 62
Re: Tokens Calulator
«
Reply #4 on:
February 03, 2007, 01:42:24 PM »
Changed the posts around to be more clear.
Changes and files added to first post.
Help file and php file have been changed and added to first post.
Logged
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.
jjones666
BeBot Contributor
Champion
Offline
Posts: 353
Re: Tokens Calulator
«
Reply #5 on:
February 04, 2007, 06:09:10 AM »
You might want to add the following sanity check:
Code:
if ($need < 1)
{
return "Current tokens must be less than token goal!";
}
Otherwise ppl can enter a negative value.
Also, you can't make a blob link in a tell, so this help link won't work.
Cheers for the VP addition :-)
-jj-
Logged
nebhyper
Rookie
Offline
Gender:
Posts: 62
Re: Tokens Calulator
«
Reply #6 on:
February 04, 2007, 02:23:39 PM »
Good points.
Currently as it is if Goal is > 0 and Current > Goal it switches the values.
But if Goal is 0, yes you can get a negative $need.
I can either enter your sanity check for $need or remove Goal > 0.
Either one should fix it, I think.
As for blob in tells are you talking about
Code:
$this -> bot -> send_tell($name, "Unknown command. <a href='chatcmd:///tell <botname> <pre>help tokens'>[Help on Tokens commands]</a>");
Because I just tried it and it worked for me.
Logged
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.
jjones666
BeBot Contributor
Champion
Offline
Posts: 353
Re: Tokens Calulator
«
Reply #7 on:
February 04, 2007, 02:56:02 PM »
Aye the blob works fine, AFAIK u can't click it tho...
-jj-
Logged
nebhyper
Rookie
Offline
Gender:
Posts: 62
Re: Tokens Calulator
«
Reply #8 on:
February 04, 2007, 03:09:42 PM »
Ok, I'll fix it and update the first post.
Logged
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.
Khalem
BeBot Founder
Administrator
Grandmaster
Offline
Gender:
Posts: 670
Re: Tokens Calulator
«
Reply #9 on:
July 21, 2007, 08:28:41 PM »
Moved to official modules.
Will be included in 0.4 branch and trunk soon.
Updated and adapted module for BeBot 0.4, added security, help and new command handler. Cleaned up the main function some and altered the old style font tags. Also added veteran tokens calculation and added detection for the rounding issue at level 50/51 for clan.
Code:
<?php
/*
* Tokens.php - Determines how many tokens and token bags you need based on your level, current tokens, and goal tokens.
* Developed by Siocuffin (RK1), adapted for BeBot 0.4 by Khalem (RK1)
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stensås, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; Version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* File last changed at $LastChangedDate$
* Revision: $Id$
*
*/
$tokens
= new
tokens
(
$bot
);
$commands
[
"pgmsg"
][
"tokens"
] = &
$tokens
;
$commands
[
"tell"
][
"tokens"
] = &
$tokens
;
$commands
[
"gc"
][
"tokens"
] = &
$tokens
;
/*
The Class itself...
*/
class
tokens
{
var
$bot
;
function
tokens
(&
$bot
)
{
$this
->
bot
= &
$bot
;
$this
->
bot
->
accesscontrol
->
create
(
"all"
,
"tokens"
,
"GUEST"
);
$this
->
help
[
'description'
] =
"Token calculator"
;
$this
->
help
[
'command'
][
'tokens <target> <current>'
]=
"Calculates the amount of tokens, token bags or VP tokens (and price) based on your current level, <target> and <current> tokens"
;
$this
->
help
[
'command'
][
'tokens <level > <target> <current>'
] =
"Calculates the amount of tokens, token bags or VP tokens (and price) based on your <level>, <target> and <current> tokens"
;
}
/*
Unified message handler
*/
function
handler
(
$source
,
$msg
,
$type
)
{
$return
=
false
;
$clan
=
false
;
/*
This should really be moved to the bot core.. but until i get the time to modify every single module... :\
*/
$vars
=
explode
(
' '
,
strtolower
(
$msg
));
if (!empty(
$this
->
bot
->
commpre
))
{
$vars
[
0
] =
substr
(
$vars
[
0
],
1
);
}
$command
=
$vars
[
0
];
switch(
$command
)
{
case
'tokens'
:
$count
=
count
(
$vars
);
if (
$count
==
3
)
{
if (!
ctype_digit
(
$vars
[
1
]) || !
ctype_digit
(
$vars
[
2
]))
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"Values given are not numerical"
;
}
else
{
$who
=
$this
->
bot
->
whois
->
lookup
(
$source
);
$level
=
$who
[
"level"
];
if (
$who
[
"faction"
] ==
'Clan'
)
{
$clan
=
true
;
}
$return
=
$this
->
ShowTokens
(
$level
,
$vars
[
1
],
$vars
[
2
],
$clan
);
}
}
else if (
$count
==
4
)
{
if (!
ctype_digit
(
$vars
[
1
]) || !
ctype_digit
(
$vars
[
2
]) || !
ctype_digit
(
$vars
[
3
]))
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"Values given are not numerical"
;
}
else
{
$who
=
$this
->
bot
->
whois
->
lookup
(
$source
);
if (
$who
[
"faction"
] ==
'Clan'
)
{
$clan
=
true
;
}
$return
=
$this
->
ShowTokens
(
$vars
[
1
],
$vars
[
2
],
$vars
[
3
],
$clan
);
}
}
else
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"##highlight##$msg##end## is not valid input. Please see <pre>help tokens "
;
}
if (
$return
[
"error"
] ==
true
)
{
$this
->
bot
->
send_output
(
$source
,
$return
[
"errordesc"
],
$type
);
}
else
{
$this
->
bot
->
send_output
(
$source
,
$return
[
"content"
],
$type
);
}
break;
default:
$this
->
bot
->
send_tell
(
$source
,
"Broken plugin, recieved unhandled command: $command"
);
}
}
/*
Just pass off to the unified handler
*/
function
tell
(
$source
,
$msg
)
{
$this
->
handler
(
$source
,
$msg
,
1
);
}
function
pgmsg
(
$source
,
$msg
)
{
$this
->
handler
(
$source
,
$msg
,
2
);
}
function
gc
(
$source
,
$msg
)
{
$this
->
handler
(
$source
,
$msg
,
3
);
}
function
ShowTokens
(
$level
,
$goal
,
$current
,
$clan
)
{
$return
=
false
;
// Make sure our goal is larger than our current tokens
if (
$goal
<=
$current
)
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"Your goal tokens can not be the same or less than your current tokens!"
;
return
$return
;
}
// Make sure we have a legal level range
if ((
$level
<
1
) || (
$level
>
220
))
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"Enter a level between ##highlight##1##end## and ##highlight##220##end##!"
;
return
$return
;
}
// Make sure we have a sane token count for both goal and current
if (!
is_finite
(
$goal
) || !
is_finite
(
$current
))
{
$return
[
"error"
] =
true
;
$return
[
"errordesc"
] =
"Please enter sane values for both goal and current tokens!"
;
return
$return
;
}
if (
$level
>
189
)
{
$tpl
=
9
;
}
else if (
$level
>
174
)
{
$tpl
=
8
;
}
else if (
$level
>
149
)
{
$tpl
=
7
;
}
else if (
$level
>
124
)
{
$tpl
=
6
;
}
else if (
$level
>
99
)
{
$tpl
=
5
;
}
else if (
$level
>
74
)
{
$tpl
=
4
;
}
// Heres the odd one out. According to amongst others http://wiki.aodevs.com/wiki/Token_and_Tokenboards, Omni will get 3 TPL from level 50, but clan will only get from level 51. Rounding error anyone?
else if (
$level
>
49
)
{
if (!
$clan
)
{
$tpl
=
3
;
}
else
{
if (
$level
>
50
)
{
$tpl
=
3
;
}
else
{
$tpl
=
2
;
}
}
}
else if (
$level
>
14
)
{
$tpl
=
2
;
}
else
{
$tpl
=
1
;
}
$need
=
$goal
-
$current
;
$Step1
=
$need
/
$tpl
;
$Step2
=
$Step1
/
7
;
$bags
=
ceil
(
4
*
$Step2
);
$Step1
=
ceil
(
$Step1
);
$VPtoke
=
ceil
(
$need
/
10
);
$VP
=
$VPtoke
*
1000
;
$VP2
=
$VPtoke
*
10
;
$VetToke
=
ceil
(
$need
/
50
);
$Vet
=
$VetToke
*
7
;
$Vet2
=
$VetToke
*
50
;
$inside
=
"##normal##::: ##highlight##Token calculator results##end## :::\n\n"
;
$inside
.=
"::: ##highlight##Your status##end## :::\n"
;
$inside
.=
"Your level: ##highlight##"
.
$level
.
"##end##\n"
;
$inside
.=
"Current # of tokens: ##highlight##"
.
number_format
(
$current
) .
"##end##\n"
;
$inside
.=
"Goal # of Tokens: ##highlight##"
.
number_format
(
$goal
) .
"##end##\n"
;
$inside
.=
"Tokens needed: ##highlight##"
.