Вход Регистрация
Файл: include/chain.php
Строк: 193
<?php

include_once("table_name.php");
include_once(
"base.php");
include_once(
"thing.php");

/**
    class for work with chain
*/

class CChain extends CBase 
{
    
/**
        Constructor
    */
    
function CChain($database,$vnum 0)
    {
        global 
$table_chain;
    
        
$this->db $database;
        
$this->table_name=$table_chain;
        
$this->vnum=$vnum;    
    }
    
    function 
getComponents()
    {
        
$sql "select vnum_1,vnum_2,count_1,count_2 from $this->table_name where vnum='$this->vnum'";
        
        
$result $this->execSQL($sql);
        
        if(
$result->numRows()==0) return false;

        
$row $result->fetchRow();
        
        
$components = array("vnum_1" => $row[0], "vnum_2" => $row[1], "count_1" => $row[2], "count_2" => $row[3]);
        
        return 
$components;
    }
    
    
/**
        make one things and remove components from bag player
    */
    
function checkComponents($player_things)
    {

        
$components $this->getComponents();
        
        
//no chain
        
if($components == false) return false;
        
        
//check count first components
        
$vnum_1 $player_things->getThingVnum($components["vnum_1"]);
        if(
$vnum_1==-1) return false;
        
$comp_1_count $player_things->getCountThing($vnum_1);
        if(
$comp_1_count $components["count_1"]) return false;
    
           if(
$components["vnum_2"]!=0){
               
//check second components
               
$vnum_2 $player_things->getThingVnum($components["vnum_2"]);
               if(
$vnum_2==-1) return false;
               
$comp_2_count$player_things->getCountThing($vnum_2);
            if(
$comp_2_count $components["count_2"]) return false;
           }
           
           return 
true;
    }
    
    function 
makeThings($player_things)
    {
        
//make one things and remove components from bag player
        
if($this->checkComponents($player_things)==false) return false;
        
        
$components $this->getComponents();
           
           
//all ok, make things
           //first remove player components
           
$vnum_1 $player_things->getThingVnum($components["vnum_1"]);    
           
$player_things->removeThing($vnum_1,$components["count_1"]);
           if(
$components["vnum_2"]!=0){
               
$vnum_2 $player_things->getThingVnum($components["vnum_2"]);
               
$player_things->removeThing($vnum_2,$components["count_2"]);
           }
           
           
//add player things
           
$player_things->addThing($this->vnum);
           
           return 
true;
    }
    
    function 
calculateExp()
    {
        
$components $this->getComponents();
        
        
$thing = new CThing($this->db);
        
        
$thing->setVnum($components["vnum_1"]);
        
$exp_1 $thing->getV0()*$components["count_1"];
        
        
$thing->setVnum($components["vnum_2"]);
        
$exp_2 $thing->getV0()*$components["count_2"];
        
        
$exp floor(($exp_1+$exp_2)*COMPONENT_COMMISSION);
        
        return 
$exp;    
    }
  


?>
Онлайн: 1
Реклама