예제 #1
0
 public static function pegarDoPost()
 {
     //var_dump($_POST);
     $item = null;
     $tipo_item = intval($_POST['item_tipo']);
     $slug = '';
     $nome = '';
     $peso = 0.0;
     $preco = 0.0;
     $pericia_slug = '';
     if (array_key_exists('slug', $_POST)) {
         $slug = $_POST['slug'];
     }
     if (array_key_exists('nome', $_POST)) {
         $nome = $_POST['nome'];
     }
     if (array_key_exists('peso', $_POST)) {
         $peso = floatval($_POST['peso']);
     }
     if (array_key_exists('preco', $_POST)) {
         $preco = floatval($_POST['preco']);
     }
     if (array_key_exists('pericia_slug', $_POST)) {
         $pericia_slug = $_POST['pericia_slug'];
     }
     switch ($tipo_item) {
         case 1:
             $item = new Item($slug, $nome, $peso, $preco);
             break;
         case 2:
         case 3:
             $item = new Arma($slug, $nome, $peso, $preco, $pericia_slug);
             if (array_key_exists('arma_mao', $_POST)) {
                 $item->setMao($_POST['arma_mao']);
             }
             break;
         case 4:
             $item = new ArmaMuscular($slug, $nome, $peso, $preco, $pericia_slug);
             break;
         default:
             throw new Exception("Tipo de Item '{$_POST['item_tipo']}' não existe.");
             break;
     }
     if (in_array($tipo_item, array(2, 3))) {
         if (count($_POST['dano']) > 0) {
             foreach ($_POST['dano'] as $dado) {
                 $item->addDano(new ArmaDano($dado['tipo'], $dado['dano'], intval($dado['bonus']), floatval($dado['alcance_de']), floatval($dado['alcance_ate']), 0, intval($dado['preparacao'])));
             }
         }
         /*
                     <input type="hidden" class="tipo" name="dano[<?php echo $i; ?>][tipo]" value="<?php echo $dano->getTipo(); ?>">
                     <input type="hidden" class="dano" name="dano[<?php echo $i; ?>][dano]" value="<?php echo $dano->getDano(); ?>">
                     <input type="hidden" class="bonus" name="dano[<?php echo $i; ?>][bonus]" value="<?php echo $dano->getBonus(); ?>">
                     <input type="hidden" class="preparacao" name="dano[<?php echo $i; ?>][preparacao]" value="<?php //echo $dano->getPreparacao(); ?>">
                     <input type="hidden" class="alcance_de" name="dano[<?php echo $i; ?>][alcance_de]" value="<?php echo $dano->getAlcanceDe(); ?>">
                     <input type="hidden" class="alcance_ate" name="dano[<?php echo $i; ?>][alcance_ate]" value="<?php echo $dano->getAlcanceAte(); ?>">
         */
     }
     if ($tipo_item == 3) {
         $longe = new ArmaMuscular($slug, $nome, $peso, $preco, $pericia_slug);
         static::carregarLongeDoPost($longe);
         $item->setArremesso($longe);
     } elseif ($tipo_item == 4) {
         static::carregarLongeDoPost($item);
     }
     /*
             echo '<pre>';
             var_dump($_POST, $item);
             echo '</pre>';
             exit();
     * 
     */
     return $item;
 }
예제 #2
0
        $item->alterar();
    } else {
        $item->inserir();
    }
    header('Location: item-editor.php?slug=' . $item->getSlug());
    exit;
} elseif (array_key_exists('slug', $_GET)) {
    $item = Item::pegarItem($_GET['slug']);
} else {
    $item = new Item('', '', 0.0, 0.0);
}
//var_dump($item);
if ($item instanceof ArmaMuscular) {
    $arma = new Arma('', '', 0, 0, '');
    $longe = $item;
    $arma->setMao($longe->getMao());
} elseif ($item instanceof Arma) {
    $arma = $item;
    if (!is_null($arma->getArremesso())) {
        $longe = $arma->getArremesso();
    } else {
        $longe = new ArmaMuscular('', '', 0.0, 0.0, '');
    }
} else {
    $arma = new Arma('', '', 0, 0, '');
    $longe = new ArmaMuscular('', '', 0.0, 0.0, '');
}
/*
if ($item instanceof ArmaMuscular)
   $longe = $item;
else