cast spell


/**
* This page is used to calculate the effect of the spell casted by the player.
*/

function calc_effect($base)
{
global $uservals;

$maxeffect=$base+ceil(($uservals["INTELLIGENCE"]/3+$uservals["INTMOD"]/4+$uservals["TEMP_INT"]/4));
return mt_rand(ceil($maxeffect*.8),$maxeffect);
}

$r=$db->Execute("SELECT COUNT(SPELLID) FROM SPELLBOOK WHERE SPELLID = $id AND USERID = $userid");
if($r->fields[0] == "1")
$ok=true;
else
$ok=false;
$r->Close();

$failed=false;
$otherschool=false;
if($ok)
{
$spell=read_db_entry($db,"SELECT * FROM SPELLS WHERE ID = $id");
if($spell["SCHOOL"] != "M" && $uservals["SCHOOL"] != $spell["SCHOOL"])
{
$spell["MININT"]*=10;
$spell["MINLEVEL"]*=3;
$otherschool=true;
}

$int=($uservals["INTMOD"]+$uservals["TEMP_INT"]+$uservals["INTELLIGENCE"])*4;
$pts=$spell["HEAL"]+$spell["ATTACK"]+$spell["FREEZE"]*20+$spell["PROTECTION"]+$spell["TAKEHP"]*2+$spell["TAKEMP"]*2;
$prob=mt_rand(0,$pts+$int);

if(($int/4) < ($spell["MININT"]+0))
{
if(isset($text))
$text.="As you try to cast the spell, your hands spark....but nothing happens!
\nIt seems your int is too low to cast this spell.
\n";
else
echo "As you try to cast the spell, your hands spark....but nothing happens!
\nIt seems your int is too low to cast this spell.
\n";
$failed=true;
}
else if(($uservals["LEVEL"]+0) < ($spell["MINLEVEL"]+0))
{
if(isset($text))
$text.="As you try to cast the spell, your hands spark....but nothing happens!
\nIt seems your level is too low to cast this spell.
\n";
else
echo "As you try to cast the spell, your hands spark....but nothing happens!
\nIt seems your level is too low to cast this spell.
\n";
$failed=true;
}
else if($prob > $int && ($uservals["MP"]+0) >= ($spell["MPCOST"]+0) && ($uservals["MONSTERCOMBAT"]+0) != 0 && $otherschool)
{
if(isset($text))
$text.="As you try to cast the spell, your hands spark....but nothing happens!
\n";
else
echo "As you try to cast the spell, your hands spark....but nothing happens!
\n";
$uservals["MP"]-=$spell["MPCOST"];
$db->Execute("UPDATE PLAYER SET MP={$uservals['MP']} WHERE ID=$userid");
$failed=true;
}
else if(($uservals["MP"]+0) >= ($spell["MPCOST"]+0))
{
if($spell["TYPE"] == 'G')
{
if(($spell["HEAL"]+0) > 0)
{
$hp=calc_effect($spell["HEAL"]);
$uservals["HP"]+=$hp;
if($uservals["HP"] > ($uservals["HPMOD"]+$uservals['MAXHP']+$uservals["TEMP_HP"]))
$uservals["HP"]=($uservals["HPMOD"]+$uservals['MAXHP']+$uservals["TEMP_HP"]);
$uservals["MP"]-=$spell["MPCOST"];
$db->Execute("UPDATE PLAYER SET HP={$uservals['HP']}, MP={$uservals['MP']} WHERE ID=$userid");
$msg=str_replace("\$HEAL",$hp,$spell["DISPLAY"]);
if(isset($text))
$text.="$msg
\n";
else
echo "$msg
\n";
}
}
else if($spell["TYPE"] == 'A')
{
$uservals["MP"]-=$spell["MPCOST"];
$db->Execute("UPDATE PLAYER SET MP={$uservals['MP']} WHERE ID=$userid");
$attack=calc_effect($spell["ATTACK"]);
$fattack=$attack;
$prot=calc_effect($spell["PROTECTION"]);
if($attack > 0)
{
$mpro=round(($monster["LEVEL"])*pow($monster["LEVEL"],0.25)*$monster["PRO"]/50);
$attack=ceil($attack-$mpro*.5);
if($attack <= 0)
$attack=0;
}
$msg=str_replace(array("\$DMG","\$PRO"),array($attack,$prot),$spell["DISPLAY"]);
if(isset($text))
$text.="$msg
\n";
else
echo "$msg
\n";
if(($spell["SELF"]+0) > 0)
{
$selfdmg=ceil($fattack*($spell["SELF"]/$spell["ATTACK"]));
if($selfdmg > 0)
{
$uservals["HP"]-=$selfdmg;
$db->Execute("UPDATE PLAYER SET HP = ".$uservals["HP"]." WHERE ID = $userid");
if(isset($text))
$text.="Your spell also produced $selfdmg to yourself.
\n";
else
echo "Your spell also produced $selfdmg to yourself.
\n";
}
}
if(($spell["FREEZE"]+0) > 0)
{
$dif=$monster["LEVEL"]-$uservals["LEVEL"];
$i=($uservals["INTELLIGENCE"]+$uservals["INTMOD"]+$uservals["TEMP_INT"]);
if($dif < 3 || mt_rand(0,ceil($dif+$i/4)) <= ceil($i/4))
{
$db->Execute("UPDATE PLAYER SET FREEZE=-".$spell["FREEZE"]." WHERE ID=$userid");
$uservals["FREEZE"]=-$spell["FREEZE"];
if(isset($text))
$text.="You froze your opponent for ".$spell["FREEZE"]." round.
\n";
else
echo "You froze your opponent for ".$spell["FREEZE"]." round.
\n";
}
else
{
if(isset($text))
$text.="Your opponent resisted your freeze spell.
\n";
else
echo "Your opponent resisted your freeze spell.
\n";
}
}
if(($spell["PROTECTION"]+0) > 0 && ($uservals["COMBATPROT"]+0) == 0)
{
$db->Execute("UPDATE PLAYER SET COMBATPROT=".$prot." WHERE ID=$userid");
$uservals["COMBATPROT"]=$prot;
if(isset($text))
$text.="You upgraded your protection by ".$prot." points, you now have ".($uservals["PROTECTION"]+$uservals["COMBATPROT"]).".
\n";
else
echo "You upgraded your protection by ".$prot." points, you now have ".($uservals["PROTECTION"]+$uservals["COMBATPROT"]).".
\n";
}
if(($spell["TAKEHP"]+0) > 0)
{
$heal=calc_effect($spell["TAKEHP"]);
if($heal > $attack)
$heal=$attack;
$uservals["HP"]+=$heal;
if($uservals["HP"] > ($uservals["HPMOD"]+$uservals['MAXHP']+$uservals["TEMP_HP"]))
$uservals["HP"]=($uservals["HPMOD"]+$uservals['MAXHP']+$uservals["TEMP_HP"]);
$db->Execute("UPDATE PLAYER SET HP=".$uservals["HP"]." WHERE ID=$userid");
if(isset($text))
$text.="You recovered $heal HP.
\n";
else
echo "You recovered $heal HP.
\n";
}
if(($spell["TAKEMP"]+0) > 0)
{
$heal=calc_effect($spell["TAKEMP"]);
if($heal > $attack)
$heal=$attack;
$uservals["MP"]+=$heal;
if($uservals["MP"] > ($uservals["MPMOD"]+$uservals['MAXMP']+$uservals["TEMP_MP"]))
$uservals["MP"]=($uservals["MPMOD"]+$uservals['MAXMP']+$uservals["TEMP_MP"]);
$db->Execute("UPDATE PLAYER SET MP=".$uservals["MP"]." WHERE ID=$userid");
if(isset($text))
$text.="You recovered $heal MP.
\n";
else
echo "You recovered $heal MP.
\n";
}
}
}
else
{
if(isset($text))
$text.="You do not have enough MP to cast this spell.
\n";
else
echo "You do not have enough MP to cast this spell.
\n";
}
}
?>

Wyszukiwarka

Podobne podstrony:
cast spell
cast spell
remove spell
P C and Kristin Cast Dom Nocy Ujawniona (Revealed) rozdział 18
Dragon Age Spell Grimoire
divine spell
P C Cast, Kristin Cast (Dom Nocy 01) Naznaczona [rozd 3,4,5]
Spell Sheet Exalted Deeds v3 5
Spell Bound Rozdział 31
Spell Sheet Wizard v3 5
Arcana Evolved Spell Treasury The Lost
spell checker
Spell Sheet Assassin v3 5
spell

więcej podobnych podstron