Example #1
0
 /**
  * PhysicShot::__construct()
  * 
  * @param ShipType $shipType
  * @param int $damage
  * @param int $count
  * @return
  */
 public function __construct(ShipType $shipType, $damage, $count)
 {
     log_var('damage', $damage);
     log_var('count', $count);
     if ($damage < 0) {
         throw new Exception('Negative damage');
     }
     if ($count < 0) {
         throw new Exception('Negative amount of shots');
     }
     $this->fighters = $shipType->cloneMe();
     $this->damage = $damage;
     $this->count = $count;
 }
Example #2
0
 /**
  * Battle::startBattle()
  * 
  * @return null
  */
 public function startBattle($debug = false)
 {
     if (!$debug) {
         ob_start();
     }
     $this->battleStarted = true;
     //only for initial fleets presentation
     log_var('attackers', $this->attackers);
     log_var('defenders', $this->defenders);
     $round = new Round($this->attackers, $this->defenders, 0);
     $this->report->addRound($round);
     for ($i = 1; $i <= ROUNDS; $i++) {
         $att_lose = $this->attackers->isEmpty();
         $deff_lose = $this->defenders->isEmpty();
         //if one of they are empty then battle is ended, so update the status
         if ($att_lose || $deff_lose) {
             $this->checkWhoWon($att_lose, $deff_lose);
             $this->report->setBattleResult($this->attackers->battleResult, $this->defenders->battleResult);
             if (!$debug) {
                 ob_get_clean();
             }
             return;
         }
         //initialize the round
         $round = new Round($this->attackers, $this->defenders, $i);
         $round->startRound();
         //add the round to the combatReport
         $this->report->addRound($round);
         //if($i==2) die('Round: '.$this->report->getRound(0)->getNumber()); // ERRORE
         //update the attackers and defenders after round
         $this->attackers = $round->getAfterBattleAttackers();
         $this->defenders = $round->getAfterBattleDefenders();
     }
     //check status after all rounds
     $this->checkWhoWon($this->attackers->isEmpty(), $this->defenders->isEmpty());
     if (!$debug) {
         ob_get_clean();
     }
     return true;
 }
Example #3
0
 /**
  * ShipsCleaner::start()
  * Start the system
  * @return null
  */
 public function start()
 {
     /*** calculating probability to explode ***/
     //the mean probably to explode based on damage
     $prob = 1 - $this->fighters->getCurrentLife() / ($this->fighters->getHull() * $this->fighters->getCount());
     if ($prob < 0 && $prob > -EPSILON) {
         $prob = 0;
     }
     if ($prob < 0) {
         throw new Exception("Negative prob");
     }
     //if most of ships are hitten,then we can apply the more realistic way
     if (USE_BIEXPLOSION_SYSTEM && $this->lastShipHit >= $this->fighters->getCount() / PROB_TO_REAL_MAGIC) {
         log_comment('lastShipHit bigger than getCount()/magic');
         if ($prob < MIN_PROB_TO_EXPLODE) {
             $probToExplode = 0;
         } else {
             $probToExplode = $prob;
         }
     } else {
         log_comment('lastShipHit smaller than getCount()/magic');
         $probToExplode = $prob * (1 - MIN_PROB_TO_EXPLODE);
     }
     /*** calculating the amount of exploded ships ***/
     $teoricExploded = round($this->fighters->getCount() * $probToExplode);
     if (USE_EXPLODED_LIMITATION) {
         $teoricExploded = min($teoricExploded, $this->lastShots);
     }
     $this->exploded = $teoricExploded;
     //bounded by the total shots fired to simulate a real combat :)
     /*** calculating the life of destroyed ships ***/
     //$this->remainLife = $this->exploded * (1 - $prob) * ($this->fighters->getCurrentLife() / $this->fighters->getCount());
     $this->remainLife = $this->fighters->getCurrentLife() / $this->fighters->getCount();
     log_var('prob', $prob);
     log_var('probToExplode', $probToExplode);
     log_var('teoricExploded', $teoricExploded);
     log_var('exploded', $this->exploded);
     log_var('remainLife', $this->remainLife);
 }
Example #4
0
 public function inflictDamage(FireManager $fires)
 {
     $physicShots = array();
     //doesn't matter who shot first, but who receive first the damage
     foreach ($fires->getIterator() as $fire) {
         $tmp = array();
         foreach ($this->getOrderedIterator() as $idShipTypeDefender => $shipTypeDefender) {
             $idShipTypeAttacker = $fire->getId();
             log_comment("---- firing from {$idShipTypeAttacker} to {$idShipTypeDefender} ----");
             $xs = $fire->getShotsFiredByAllToDefenderType($shipTypeDefender, true);
             $ps = $shipTypeDefender->inflictDamage($fire->getPower(), $xs->result);
             log_var('$xs', $xs);
             $tmp[$idShipTypeDefender] = $xs->rest;
             if ($ps != null) {
                 $physicShots[$idShipTypeDefender][] = $ps;
             }
         }
         log_var('$tmp', $tmp);
         // assign the last shot to the more likely shitType
         $m = 0;
         $f = 0;
         foreach ($tmp as $k => $v) {
             if ($v > $m) {
                 $m = $v;
                 $f = $k;
             }
         }
         if ($f != 0) {
             log_comment('adding 1 shot');
             $ps = $this->getShipType($f)->inflictDamage($fire->getPower(), 1);
             $physicShots[$f][] = $ps;
         }
     }
     return $physicShots;
 }
Example #5
0
                        $msg = "Pagamento em anαlise: via " . $tp_pagamento . " em " . $parcelas . " parcelas αs " . $hora . " hs Fatura: ";
                        addtransaction($userid, $faturaid, $msg, "000", "0.00", "0000", "moipapi", $transid, $faturaid);
                        logTransaction($gatewayname, $_POST, "Successful");
                        log_var("Status [" . $_POST['status_pagamento'] . "]\nTransaηγo \"Em anαlise\", valor repassado para sua conta MoIP. ", "Retorno de dados MoIP, Fatura: " . $faturaid . "\nData: " . $data_hora, true);
                        echo "Sucesso6";
                        exit;
                    } else {
                        if ($status_pagamento == "7") {
                            $amount = "zero";
                            $msg = "Pagamento extornado: via " . $tp_pagamento . " em " . $parcelas . " parcelas αs " . $hora . " hs Fatura:";
                            addtransaction($userid, $faturaid, $msg, "000", "0.00", "0000", "moipapi", $transid, $faturaid);
                            logTransaction($gatewayname, $_POST, "Successful");
                            log_var("Status [" . $_POST['status_pagamento'] . "]\nPagamento Extornado. ", "Retorno de dados MoIP, Fatura: " . $faturaid . "\nData: " . $data_hora, true);
                            echo "Sucesso7";
                            exit;
                        } else {
                            $msg = "Retorno desconhecido: via " . $tp_pagamento . " αs " . $hora . " hs Fatura:";
                            $amount = "zero";
                            addtransaction($userid, $faturaid, $msg, "00", "0.00", "0", "moipapi", $transid, $faturaid);
                            logTransaction($gatewayname, $_POST, "Successful");
                            log_var("Status [" . $_POST['status_pagamento'] . "]\nPagamento Iniciado. ", "Retorno de dados MoIP, Fatura: " . $faturaid . "\nData: " . $data_hora, true);
                            echo "SucessoN";
                            exit;
                        }
                    }
                }
            }
        }
    }
}
exit;
            $errors = $MoIP->getL('cart') . ' <br />';
        } elseif (Order::getOrderByCartId(intval($id_transacao_moip))) {
            $errors = $MoIP->getL('order') . ' <br />';
        } else {
            $currency = new Currency(intval(isset($_POST['currency_payement']) ? $_POST['currency_payement'] : $cookie->id_currency));
            //Cria order, transacao.
            $MoIP->validateOrder($id_transacao_moip, $status, $valor_compra, $MoIP->displayName, $MoIP->getL('transaction'), $mailVars, $id_moeda);
            if ($MoIP->currentOrder != "") {
                log_var("Compra gravado no BD corretamente\nId proprio: " . $_POST['id_transacao'] . "\nCodigo MoIP: " . $_POST['cod_moip'] . "\nID transacao: " . $id_transacao_moip . "\nID Order PrestaShop: " . $MoIP->currentOrder, "Validacao de dados", true);
                $MoIP->addOrder($id_transacao_moip);
            } else {
                log_var("Erro ao gravar compra no BD\nId transacao: " . $id_transacao_moip, "Validacao de dados", true);
            }
        }
    }
    log_var("Resultado: " . $result . "\nErro: " . $errors . "\nTotal: " . $valor_compra . "\nStatus MoIP: " . $_POST['status_pagamento'] . "\nNovo Status: " . $status . "\nCart: " . $cart->id . "\nOrder: " . $MoIP->currentOrder . "\nMoeda: " . $id_moeda, "MoIP Labs Debug, Data: " . date("Y-m-d G:i:s"), true);
} else {
    $errors .= $MoIP->getL('VERIFICADO');
    log_var("NAO VERIFICADO", "MoIP Labs Debug, Data: " . date("Y-m-d G:i:s"), true);
}
if (!empty($errors) and isset($_POST['id_transacao'])) {
    $id_order_db = $MoIP->getOrder($id_transacao_moip);
    $id_transacao = $id_order_db['id_order'];
    $id_transacao_proprio = $id_order_db['id_transaction'];
    log_var("ID transacao: " . $id_transacao_moip . "\nID Compra(order) PrestaShop: " . $id_transacao, "Recuperando order do BD, Data: " . date("Y-m-d G:i:s"), true);
    $extraVars = array();
    $history = new OrderHistory();
    $history->id_order = intval($id_transacao);
    $history->changeIdOrderState(intval($status), intval($id_transacao));
    $history->addWithemail(true, $extraVars);
}
    foreach ($threads as $t) {
        $url = $t['url'];
        $exist = $ds->getThreadByUrl($url);
        if (!$exist) {
            $current_createdat = $t['createdat'];
            if ($current_createdat > $createdat) {
                $createdat = $current_createdat;
            }
            libxml_use_internal_errors(true);
            $start = time();
            $logService->log('D4CRAWLER', 'd4crawler new thread forumid=' . $forumid, var_log($url, '$url'), 'd4crawler');
            try {
                @crawl($url, '', '', '', '', '', false);
            } catch (Exception $x) {
                echo $x;
                $logService->log('ERROR', 'd4 crawler exception', log_var($x, '$x'), 'd4crawler');
            }
        } else {
            //$logService->log('D4CRAWLER','Thread exists already ',var_log($url,'$url'),'d4crawler');
        }
    }
    $logService->log('D4CRAWLER', 'Forum finished forumid=' . $forumid, var_log($url, '$url'), 'd4crawler');
    if ($createdat) {
        $ds->updateForumLastCrawled($forumid, $createdat);
    }
}
function crawl($url, $default_date, $default_description, $default_language, $default_title, $default_site_name, $nocrawl)
{
    global $dom;
    global $input;
    global $root;
Example #8
0
$transacao = explode(':', $_POST['id_transacao']);
$transacao_novo = $transacao[1];
$tmp = explode('-', $transacao_novo);
$invoiceid = str_replace(" ", "", $tmp[0]);
function define_var($params)
{
    $url_retorno = $params['url_retorno'];
    return $url_retorno;
}
if ($status_pagamento == "1") {
    addinvoicepayment($invoiceid, $transid, $amount, "", 'moip');
    log_var("Status [" . $_POST['status_pagamento'] . "] \nTransação \"Autorizada\", valor pago pelo cliente e identificado pelo MoIP. ", "Retorno de dados MoIP, Pedido: " . $invoiceid . "\nData: " . $data_hora, true);
    echo 'Sucesso';
    exit;
} elseif ($status_pagamento == "4") {
    log_var("Status [" . $_POST['status_pagamento'] . "] \nTransação \"Comcluida\", valor repassado par sua conta MoIP. ", "Retorno de dados MoIP, Pedido: " . $invoiceid . "\nData: " . $data_hora, true);
    echo 'Sucesso';
    exit;
} elseif ($status_pagamento == "5") {
    log_var("Status [" . $_POST['status_pagamento'] . "] \nPagamento Cancelado. ", "Retorno de dados MoIP, Pedido: " . $invoiceid . "\nData: " . $data_hora, true);
    echo 'Sucesso';
    exit;
} else {
    log_var("Status [" . $_POST['status_pagamento'] . "] \nPagamento não identificado. ", "Retorno de dados MoIP, Pedido: " . $invoiceid . "\nData: " . $data_hora, true);
    echo 'Sucesso';
    exit;
}
exit;
/*
    [Isaías 33:6 = E haverá estabilidade nos teus tempos, abundância de salvação, sabedoria e ciência; e o temor do SENHOR será o seu tesouro. ]
*/
Example #9
0
 /**
  * Fire::getShotsFromOneAttackerShipOfType()
  * This function return the number of shots caused by RF from one ShipType to all defenders
  * @param ShipType $shipType_A
  * @return int
  */
 private function getShotsFromOneAttackerShipOfType(ShipType $shipType_A)
 {
     $p = $this->getProbabilityToShotAgainForAttackerShipOfType($shipType_A);
     $meanShots = GeometricDistribution::getMeanFromProbability(1 - $p) - 1;
     if (USE_RANDOMIC_RF) {
         $max = $meanShots * (1 + MAX_RF_BUFF);
         $min = $meanShots * (1 - MAX_RF_NERF);
         log_var('$max', $max);
         log_var('$min', $min);
         log_var('$mean', $meanShots);
         return Gauss::getNextMsBetween($meanShots, GeometricDistribution::getStandardDeviationFromProbability(1 - $p), $min, $max);
     }
     return $meanShots;
 }
Example #10
0
<?php

if (!function_exists('log_var')) {
    function log_var($var, $name = '', $to_file = false)
    {
        if ($to_file == true) {
            $txt = @fopen('debug.txt', 'a');
            if ($txt) {
                fwrite($txt, "-----------------------------------\n");
                fwrite($txt, $name . "\n");
                fwrite($txt, print_r($var, true) . "\n");
                fclose($txt);
                //
            }
        } else {
            echo '<pre><b>' . $name . '</b><br>' . print_r($var, true) . '</pre>';
        }
    }
}
/* SSL Management */
$useSSL = true;
include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../header.php';
include dirname(__FILE__) . '/MoIP.php';
if (!$cookie->isLogged()) {
    Tools::redirect('authentication.php?back=order.php');
}
$MoIP = new MoIP();
echo $MoIP->execPayment($cart);
log_var("cookie: " . $cookie->isLogged() . "\ncart: " . $MoIP->execPayment($cart), "payment.php", true);
include_once dirname(__FILE__) . '/../../footer.php';
Example #11
0
 /**
  * ShipType::cleanShips()
  * Start the task of explosion system.
  * @return ShipsCleaner
  */
 public function cleanShips()
 {
     log_var('lastShipHit after', $this->lastShipHit);
     log_var('lastShots after', $this->lastShots);
     log_var('currentLife before', $this->currentLife);
     $sc = new ShipsCleaner($this, $this->lastShipHit, $this->lastShots);
     $sc->start();
     $this->decrement($sc->getExplodedShips(), $sc->getRemainLife(), 0);
     $this->lastShipHit = 0;
     $this->lastShots = 0;
     log_var('currentLife after', $this->currentLife);
     return $sc;
 }