Archive > AO official modules

Tokens Calulator

<< < (2/4) > >>

jjones666:
You might want to add the following sanity check:


--- Code: --- if ($need < 1)
{
return "Current tokens must be less than token goal!";
}
--- End code ---

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-

nebhyper:
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>");
--- End code ---

Because I just tried it and it worked for me.

jjones666:
Aye the blob works fine, AFAIK u can't click it tho...

-jj-

nebhyper:
Ok, I'll fix it and update the first post.

Khalem:
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##". number_format($need) ."##end##\n";
$inside .= "Tokens per token disk: ##highlight##". number_format($tpl) ."##end##\n\n";

$inside .= "::: ##highlight## Your Calculated Token Options##end## :::\n";
$inside .= "Token bags needed: ##highlight##". number_format($bags) ."##end##\n";
$inside .= "Token discs needed: ##highlight##". number_format($Step1) ."##end##\n";
$inside .= "Veteran tokens(##highlight##*##end##): ##highlight##" . number_format($VetToke) . "##end## for ##highlight##" . number_format($Vet) . "##end## veteran points.\n";
$inside .= "OFAB tokens(##highlight##**##end##): ##highlight##". number_format($VPtoke) ."##end## for ##highlight##" . number_format($VP) . "##end## victory points.\n\n";

$inside .= "##highlight##*##end## One veteran token is a set of 50 tokens, thus ##highlight##". number_format($VetToke) ."##end## will equal ##highlight##". number_format($Vet2) ." tokens.##end##\n"; 
$inside .= "##highlight##**##end## OFAB tokens listed are the set of 10, thus ##highlight##". number_format($VPtoke) ."##end## will equal ##highlight##". number_format($VP2) ." tokens.##end###end##"; 

$info = "Token calculator ::: " . $this -> bot -> make_blob('Click for results', $inside);
$return["content"] = $info;
return $return;
}

?>

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version