示例#1
0
 private function manageArmy(Army $army, Country $country)
 {
     if ($country->isFree()) {
         return;
     }
     $army->increaseSize();
 }
示例#2
0
 /** @test */
 function it_is_dead_if_no_units_are_alive()
 {
     $unit1 = $this->getMock(Army\Unit\Unit::class);
     $unit2 = $this->getMock(Army\Unit\Unit::class);
     $unit1->method('isDead')->willReturn(true);
     $unit2->method('isDead')->willReturn(true);
     $this->army->add($unit1);
     $this->army->add($unit2);
     $this->assertTrue($this->army->isDead());
 }
 /** @test */
 function it_returns_false_when_trying_to_get_a_winner_while_more_than_one_army_alive()
 {
     $armyOne = new Army('Foo');
     $armyTwo = new Army('Bar');
     $armyOne->add(new Barbarian());
     $armyOne->add(new Archer());
     $armyTwo->add(new Giant());
     $this->simulator->addArmy($armyOne);
     $this->simulator->addArmy($armyTwo);
     $this->assertFalse($this->simulator->getWinner());
 }
示例#4
0
 /**
  * @param Unit $newUnit
  * @param Unit $occupyingUnit
  * @return Unit
  */
 public static function joinExisting(Unit $newUnit, Unit $occupyingUnit)
 {
     $comp = null;
     if (!is_null($comp = $occupyingUnit->getComposite())) {
         $comp->addUnit($newUnit);
     } else {
         $comp = new Army();
         $comp->addUnit($occupyingUnit)->addUnit($newUnit);
     }
     return $comp;
 }
示例#5
0
 /** Cette fonction transfert les unités en attaque au stock et efface le combat
  * elle retourne la nouvelle armée pour l'affichage en ajax
  * @return array new updated Army_owned list
  */
 public function reset_army()
 {
     $army_mobile = new Army($this->attacker_id, $this->id);
     $army_owned = new Army($this->attacker_id);
     if (count($army_mobile->troops) > 0 && $army_mobile->total_units > 0) {
         foreach ($army_mobile->troops as $unit_id => $troop) {
             if ($troop->quantity > 0) {
                 $army_owned->add_troop($unit_id, $troop->quantity);
             }
             $troop = new Troop($troop->id);
             $troop->delete();
         }
     }
     $this->delete();
     return $army_owned->get_troops();
 }
示例#6
0
<?php

include_once '../../class/pattern/iterator.php';
$archer = new Archer();
$main_army = new Army();
$main_army->addUnit($archer);
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Cavalry());
$sub_army->addUnit(new Cavalry());
$main_army->addUnit($sub_army);
$compositeIterator = $main_army->createIterator();
//$unit = $compositeIterator->current();
//echo $unit->getName();
$unit = $compositeIterator->next();
echo $unit->getName();
$unit = $compositeIterator->next();
echo $unit->getName();
$unit = $compositeIterator->next();
echo $unit->getName();
$unit = $compositeIterator->next();
echo $unit->getName();
$compositeIterator->next();
$compositeIterator->next();
echo "<br>";
$subCompositeIterator = $unit->createIterator();
$unit = $subCompositeIterator->next();
echo $unit->getName();
$unit = $subCompositeIterator->next();
示例#7
0
 /**
  * Give up the war
  *
  * @param   Army    $enemy  The army to surrender to
  *
  * Note: Regardless of the $enemy, a surrender applies to all wars we are engaged in.
  */
 private function demandSurrender($enemy)
 {
     if ($this->troops > $enemy->troops * $enemy->troops) {
         $enemy->parley();
         $enemy->surrendered = true;
     }
 }
    {
        if (in_array($unit, $this->units, true)) {
            return;
        }
        $this->units[] = $unit;
    }
    function removeUnit(Unit $unit)
    {
        $this->units = array_udiff($this->units, [$unit], function ($a, $b) {
            return $a === $b ? 0 : 1;
        });
    }
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
// создадим армию
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$main_army->addUnit($sub_army);
print "Атакующая сила: {$main_army->bombardStrength()}\n";
<?php

class Army
{
    public static $strength = 20;
    public static function getStrength()
    {
        //late static binding... if the child that called the method has a the property, use that one
        //else, go up the class hierarchy and find the static property
        return static::$strength;
    }
}
echo 'Army strength: ' . Army::getStrength() . '<br/>';
class Batallion extends Army
{
    public static $strength = 10;
}
echo 'Batallion strength: ' . Batallion::getStrength() . "<br/>";
<?php

class Army
{
    public static $strength = 20;
    public static function getStrength()
    {
        return static::$strength;
        // will check child class first then parent class
        //This is called late static binding
        //return self::$strength; will renter 20 for battalion
    }
}
class Battalion extends Army
{
    public static $strength = 10;
}
echo 'Army strength: ' . Army::getStrength() . "<br/>";
echo 'Battalion strength: ' . Battalion::getStrength() . "<br/>";
//Batallion str is 10 but it will render 20 because it will render the parent static as the default
//
class Unit extends Battalion
{
    public static $strength = 5;
}
echo 'Unit strength: ' . Unit::getStrength() . "<br/>";
示例#11
0
     $target = new User($_POST['target_id']);
     if (!Combat::is_available_target($user->score, $target->score)) {
         $errors[] = "{$target->pseudo} n'est pas a votre portée";
         return;
     }
     /* TODO : décommenter pour interdire l'attaque sur soi
            if ($user->id == $defender->id) {
                $errors[] = "C'est une mutinerie ? Non sérieusement vous ne pouvez pas vous attaquer.";
                return;
            }
        */
     $target = new User($_POST['target_id']);
     $combat = new Combat();
     $combat->hydrate(['attacker_id' => $user->id, 'target_id' => $target->id, 'arrival_time' => date("Y-m-d H:i:s", time('now') + abs($user->score - $target->score))]);
     $combat_id = intval($combat->add());
     $army_moving = new Army($user->id, $combat_id);
     $army_owned = new Army($user->id);
     foreach ($_POST as $post_key => $quantity) {
         $post_arr = explode('_', $post_key);
         if ($post_arr[0] == 'unitID' && $quantity > 0) {
             $army_moving->add_troop(intval($post_arr[1]), intval($quantity), $combat_id);
             $army_owned->add_troop(intval($post_arr[1]), intval(-$quantity));
         }
     }
     // redirection pour éviter le renvoi d'une nouvelle flotte en actualisant la page
     /* TODO décommenter en prod
        $url = 'Location:' . _ROOT_ . 'war';
        header("$url");
        */
     // fleet selection
 } elseif (isset($_GET['action']) && $_GET['action'] == 'attack' && isset($_GET['param'])) {
示例#12
0
        $this->units = array_udiff($this->units, array($unit), function ($a, $b) {
            return $a === $b ? 0 : 1;
        });
        // < php 5.3
        // $this->units = array_udiff( $this->units, array( $unit ),
        //                 create_function( '$a,$b', 'return ($a === $b)?0:1;' ) );
    }
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
// create an army
$main_army = new Army();
// add some units
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
// create a new army
$sub_army = new Army();
// add some units
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
// add the second army to the first
$main_army->addUnit($sub_army);
// all the calculations handled behind the scenes
print "attacking with strength: {$main_army->bombardStrength()}\n";
示例#13
0
    {
        return $this->units;
    }
    function removeUnit(Unit $unit)
    {
        $units = array();
        foreach ($this->units as $thisunit) {
            if ($unit !== $thisunit) {
                $units[] = $thisunit;
            }
        }
        $this->units = $units;
    }
    function addUnit(Unit $unit)
    {
        if (in_array($unit, $this->units, true)) {
            return;
        }
        $this->units[] = $unit;
    }
}
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$main_army->addUnit($sub_army);
var_dump($sub_army);
var_dump($main_army);
示例#14
0
 public function get_player_certs($name = NULL)
 {
     //searching by name, null name = no buenos
     if ($name == NULL) {
         return Response::error('404');
     } else {
         $input_name = urldecode($name);
     }
     //Look up the player, latest to account for deletes with the same name
     $player = Player::where('name', '=', $input_name)->order_by('created_at', 'DESC')->first();
     //no player found, why not search?
     if (!$player) {
         return Response::error('404');
     }
     //Does the player have an army?
     $army = Army::where('armyId', '=', $player->armyid)->order_by('created_at', 'DESC')->first();
     //escape for output in title
     $playerName = htmlentities($player->name);
     //Player website preferences
     $web_prefs = WebsitePref::where('db_id', '=', $player->db_id)->first();
     if (isset($web_prefs->attributes)) {
         $web_prefs = $web_prefs->attributes;
     }
     //website prefs we care about - show_workbench, show_craftables, show_market_listings
     if (!isset($web_prefs['show_workbench'])) {
         $web_prefs['show_workbench'] = 1;
     }
     if (!isset($web_prefs['show_craftables'])) {
         $web_prefs['show_craftables'] = 0;
     }
     if (!isset($web_prefs['show_market_listings'])) {
         $web_prefs['show_market_listings'] = 0;
     }
     if ($web_prefs['show_market_listings']) {
         //find out what this player has currently listed on the market
         $cache_key_player_market = $player->db_id . "_market_listings";
         if (Cache::has($cache_key_player_market)) {
             //pull from cache
             $cached_market_listings = Cache::get($cache_key_player_market);
             $item_stats_lookup = $cached_market_listings['stats'];
             $market_listings = $cached_market_listings['data'];
         } else {
             $market_listings = MarketListing::where('active', '=', '1')->where('character_guid', '=', $player->db_id)->get(array('item_sdb_id', 'expires_at', 'price_cy', 'price_per_unit', 'rarity', 'quantity', 'title', 'icon', 'ff_id', 'category'));
             if (!empty($market_listings)) {
                 $market_stat_ids = array();
                 $market_stat_cats = array();
                 foreach ($market_listings as $listing) {
                     $market_stat_ids[] = $listing->attributes['ff_id'];
                     $market_stat_cats[] = $listing->attributes['category'];
                 }
                 if (count($market_stat_cats) < 1) {
                     $stats = false;
                 }
                 $market_stat_cats_unique = array_unique($market_stat_cats);
                 $item_stats_lookup = false;
                 foreach ($market_stat_cats_unique as $statcat) {
                     switch ($statcat) {
                         case 'AbilityModule':
                             $stats = MarketStatAbilityModule::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $ustats = (array) unserialize($stat->stats);
                                 ksort($ustats);
                                 foreach ($ustats as $key => $value) {
                                     $key = str_replace('_', ' ', $key);
                                     $key = ucwords($key);
                                     $value = number_format($value, 2);
                                     $temp .= '<tr><td>' . htmlentities($key) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                 }
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'CraftingComponent':
                             $stats = MarketStatCraftingComponent::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '';
                                 $key_lookup = array('mass' => 'MASS', 'power' => 'PWR', 'cpu' => 'CPU');
                                 ksort($stat->attributes);
                                 foreach ($stat->attributes as $key => $value) {
                                     if ($value > 0 && array_key_exists($key, $key_lookup)) {
                                         $temp .= htmlentities($key_lookup[$key]) . ': ' . htmlentities($value) . '<br>';
                                     }
                                 }
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'Jumpjet':
                             $stats = MarketStatJumpjet::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $key_lookup = array('id', 'updated_at', 'created_at', 'marketlisting_id');
                                 ksort($stat->attributes);
                                 foreach ($stat->attributes as $key => $value) {
                                     if (!in_array($key, $key_lookup)) {
                                         $key = str_replace('_', ' ', $key);
                                         $key = ucwords($key);
                                         $value = number_format($value, 2);
                                         $temp .= '<tr><td>' . htmlentities($key) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                     }
                                 }
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'Plating':
                             $stats = MarketStatPlating::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $key_lookup = array('id', 'updated_at', 'created_at', 'marketlisting_id');
                                 ksort($stat->attributes);
                                 foreach ($stat->attributes as $key => $value) {
                                     if (!in_array($key, $key_lookup)) {
                                         $key = str_replace('_', ' ', $key);
                                         $key = ucwords($key);
                                         $value = number_format($value, 2);
                                         $temp .= '<tr><td>' . htmlentities($key) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                     }
                                 }
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'Resource':
                             $stats = MarketStatResource::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $key_lookup = array(1 => 'Thermal Resistance', 2 => 'Conductivity', 3 => 'Malleability', 4 => 'Density', 5 => 'Toughness', 'quality' => 'Quality');
                                 $temp_ar = array();
                                 foreach ($stat->attributes as $key => $value) {
                                     if (array_key_exists($key, $key_lookup)) {
                                         $temp_ar[$key] = '<tr><td>' . htmlentities($key_lookup[$key]) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                     }
                                 }
                                 //because resources are special, we alpha order them numerically
                                 $temp .= $temp_ar[2];
                                 $temp .= $temp_ar[4];
                                 $temp .= $temp_ar[3];
                                 $temp .= $temp_ar[1];
                                 $temp .= $temp_ar[5];
                                 $temp .= $temp_ar['quality'];
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'Servo':
                             $stats = MarketStatServo::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $key_lookup = array('id', 'updated_at', 'created_at', 'marketlisting_id');
                                 ksort($stat->attributes);
                                 foreach ($stat->attributes as $key => $value) {
                                     if (!in_array($key, $key_lookup)) {
                                         $key = str_replace('_', ' ', $key);
                                         $key = ucwords($key);
                                         $value = number_format($value, 2);
                                         $temp .= '<tr><td>' . htmlentities($key) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                     }
                                 }
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         case 'Weapon':
                             $stats = MarketStatWeapon::where_in('marketlisting_id', $market_stat_ids)->get();
                             foreach ($stats as $stat) {
                                 $temp = '<table>';
                                 $key_lookup = array('id', 'updated_at', 'created_at', 'marketlisting_id');
                                 ksort($stat->attributes);
                                 foreach ($stat->attributes as $key => $value) {
                                     if (!in_array($key, $key_lookup)) {
                                         $key = str_replace('_', ' ', $key);
                                         $key = ucwords($key);
                                         $value = number_format($value, 2);
                                         $temp .= '<tr><td>' . htmlentities($key) . ': </td><td>' . htmlentities($value) . '</td></tr>';
                                     }
                                 }
                                 $temp .= '</table>';
                                 $item_stats_lookup[(string) $stat->marketlisting_id] = $temp;
                             }
                             break;
                         default:
                             break;
                     }
                 }
                 //Cache
                 $cached_market_listings = array();
                 $cached_market_listings['data'] = $market_listings;
                 $cached_market_listings['stats'] = $item_stats_lookup;
                 Cache::put($cache_key_player_market, $cached_market_listings, 30);
             }
         }
     }
     if ($web_prefs['show_craftables']) {
         if (isset($web_prefs['show_progress'])) {
             if ($web_prefs['show_progress']) {
                 $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
             } else {
                 $progress = null;
             }
         } else {
             $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
         }
         if (!empty($progress)) {
             $cache_key_progress = $player->db_id . "_progress";
             $progress = $progress->entry;
             $progress_md5 = md5($progress);
             if (Cache::Get($cache_key_progress . "_md5_cc") != $progress_md5) {
                 $progress = unserialize($progress);
                 if (isset($progress->unlocks)) {
                     $master_cert_list = array();
                     //all odd number certs from 799 to 1245
                     //category names from 766 to 783
                     //arsenal = 1398
                     /*
                     	766 = base assault
                     	767 = base biotech
                     	768 = base dreadnaught
                     	769 = base engineer
                     	770 = base recon
                     	
                     	774 = firecat
                     	775 = tigerclaw
                     	776 = dragonfly
                     	777 = recluse
                     	778 = rhino
                     	779 = mammoth
                     	1398 = arsenal
                     	780 = electron
                     	781 = bastion
                     	782 = nighthawk
                     	783 = raptor
                     */
                     //certs we don't care about
                     $useless_certs = array(784, 785, 786, 788, 789, 790, 791, 792, 794, 1154, 1359, 1366, 1367, 1371, 1372, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392);
                     $unlocked_base_assault = 0;
                     $unlocked_base_biotech = 0;
                     $unlocked_base_dreadnaught = 0;
                     $unlocked_base_engineer = 0;
                     $unlocked_base_recon = 0;
                     $unlocked_firecat = 0;
                     $unlocked_tigerclaw = 0;
                     $unlocked_dragonfly = 0;
                     $unlocked_recluse = 0;
                     $unlocked_rhino = 0;
                     $unlocked_arsenal = 0;
                     $unlocked_mammoth = 0;
                     $unlocked_electron = 0;
                     $unlocked_bastion = 0;
                     $unlocked_nighthawk = 0;
                     $unlocked_raptor = 0;
                     foreach ($progress->unlocks as $progress_certs) {
                         //Make a master list of certs, note that certs are in numerical sorted order so we are able to do a fast merge
                         for ($i = 0; $i < count($progress_certs); $i++) {
                             if (!in_array($progress_certs[$i], $master_cert_list)) {
                                 if (!in_array($progress_certs[$i], $useless_certs)) {
                                     //unlock flags
                                     if ($progress_certs[$i] == 766) {
                                         $unlocked_base_assault = 1;
                                     }
                                     if ($progress_certs[$i] == 767) {
                                         $unlocked_base_biotech = 1;
                                     }
                                     if ($progress_certs[$i] == 768) {
                                         $unlocked_base_dreadnaught = 1;
                                     }
                                     if ($progress_certs[$i] == 769) {
                                         $unlocked_base_engineer = 1;
                                     }
                                     if ($progress_certs[$i] == 770) {
                                         $unlocked_base_recon = 1;
                                     }
                                     if ($progress_certs[$i] == 774) {
                                         $unlocked_firecat = 1;
                                     }
                                     if ($progress_certs[$i] == 775) {
                                         $unlocked_tigerclaw = 1;
                                     }
                                     if ($progress_certs[$i] == 776) {
                                         $unlocked_dragonfly = 1;
                                     }
                                     if ($progress_certs[$i] == 777) {
                                         $unlocked_recluse = 1;
                                     }
                                     if ($progress_certs[$i] == 778) {
                                         $unlocked_rhino = 1;
                                     }
                                     if ($progress_certs[$i] == 779) {
                                         $unlocked_mammoth = 1;
                                     }
                                     if ($progress_certs[$i] == 1398) {
                                         $unlocked_arsenal = 1;
                                     }
                                     if ($progress_certs[$i] == 780) {
                                         $unlocked_electron = 1;
                                     }
                                     if ($progress_certs[$i] == 781) {
                                         $unlocked_bastion = 1;
                                     }
                                     if ($progress_certs[$i] == 782) {
                                         $unlocked_nighthawk = 1;
                                     }
                                     if ($progress_certs[$i] == 783) {
                                         $unlocked_raptor = 1;
                                     }
                                     if ($progress_certs[$i] > 764 && $progress_certs[$i] < 798 || $progress_certs[$i] > 1246) {
                                         //add to the master list
                                         $master_cert_list[] = $progress_certs[$i];
                                     } else {
                                         if ($progress_certs[$i] > 797 && $progress_certs[$i] < 1246 && $progress_certs[$i] % 2 == 0) {
                                             //add to the master list
                                             $master_cert_list[] = $progress_certs[$i];
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     //free up some memory
                     $progress = null;
                     sort($master_cert_list);
                     $cert_info = Certification::where(function ($query) use($master_cert_list) {
                         $query->where_in('id', $master_cert_list);
                     })->get(array('id', 'name'));
                     //look at all these arrays
                     //jumpjets, secondary weapons {Assault rifle, burst rifle, grenade launcher, SMG, shotgun}, servos
                     $base_shared_certs = array(910, 982, 984, 986, 988, 990, 992, 1222, 1224, 1226, 1228, 1230, 1242, 1244, 1345, 1346, 1347, 1348, 1349, 1355, 1356);
                     //accord absorbtion plating, afterburners, bombs away, burn jets, crater, overcharge, plasma cannon, shockwave, assault plating
                     $base_assault_certs = array(787, 793, 795, 798, 800, 802, 806, 828, 996, 1016, 1018, 1020, 1022, 1024, 1026, 1028, 1202, 1204, 1232, 1246, 1247, 1248, 1249, 1250, 1335, 1336, 1350);
                     //accord chemical sprayer, accord siphoning plating, healing generator, healing wave, needler, poison ball, poison trail, triage, biotech plating
                     $base_biotech_certs = array(804, 808, 812, 814, 824, 830, 832, 1008, 1010, 1054, 1056, 1058, 1060, 1062, 1064, 1210, 1212, 1236, 1256, 1264, 1265, 1266, 1267, 1268, 1339, 1340, 1352);
                     //Absorption Bomb, Accord Explosive Rounds, Accord Mortar Arcfold, Accord Repulsor Blast, Heavy Armor, Turret Mode, Heavy Machine Gun, Resilient Plating
                     $base_dreadnaught_certs = array(862, 866, 872, 880, 940, 998, 1012, 1014, 1090, 1092, 1094, 1096, 1098, 1100, 1206, 1208, 1234, 1281, 1282, 1283, 1284, 1285, 1286, 1337, 1338, 1351);
                     //Anti-Personnel Turret, Charged Pulse Generator, Claymore, Deployable Shield, Heavy Turret, Supply Station, Accord Nanite Deployment, engineer plating, Sticky Grenade Launcher
                     $base_engineer_certs = array(942, 944, 946, 948, 950, 994, 1004, 1006, 1126, 1128, 1130, 1132, 1134, 1136, 1214, 1216, 1238, 1299, 1300, 1301, 1302, 1303, 1304, 1341, 1342, 1353);
                     //Accord Artillery Strike, Cryo Grenade, Decoy, Proximity Reponse, Resonating Bolts, SIN Beacon, Accord Regenerative Plating, R36 Assault Rifle
                     $base_recon_certs = array(904, 918, 922, 928, 932, 934, 936, 1000, 1002, 1166, 1168, 1170, 1172, 1174, 1176, 1218, 1220, 1240, 1317, 1318, 1319, 1320, 1321, 1322, 1343, 1344, 1354);
                     //ADV frames
                     //fuel air bomb, immolate, incinerator, inferno dash, thermal cannon, thermal wave
                     $base_firecat_certs = array(810, 816, 818, 820, 822, 826, 1030, 1032, 1034, 1036, 1038, 1040, 1251, 1252, 1253, 1254, 1255, 1257);
                     //fusion cannon, Disruption, Missile Shot, Tether Field, Trailblaze, Auxiliary Tanks
                     $base_tigerclaw_certs = array(834, 838, 842, 844, 848, 852, 1042, 1044, 1046, 1048, 1050, 1052, 1258, 1259, 1260, 1261, 1262, 1263);
                     //bio rifle, Emergency Response, Healing Ball, Healing Dome, Healing Pillar, Rally
                     $base_dragonfly_certs = array(836, 846, 850, 856, 860, 864, 1066, 1068, 1070, 1072, 1074, 1076, 1269, 1270, 1271, 1272, 1273, 1274);
                     //bio crossbow, creeping death, evacuate, kinetic shot, necrosis, necrotic poison
                     $base_recluse_certs = array(874, 878, 884, 888, 890, 898, 1078, 1080, 1082, 1084, 1086, 1088, 1275, 1276, 1277, 1278, 1279, 1280);
                     //Charge!, Dreadfield, Gravity Field Grenade, Sundering Wave, Heavy Laser MG, Personal Shield
                     $base_rhino_certs = array(912, 916, 920, 924, 926, 930, 1114, 1116, 1118, 1120, 1122, 1124, 1293, 1294, 1295, 1296, 1297, 1298, 1393, 1394, 1395);
                     //Shield Wall, Teleport Shot, Thunderdome, Tremors, Imminent Threat, Heavy Plasma MG
                     $base_mammoth_certs = array(892, 896, 900, 902, 906, 908, 938, 1102, 1104, 1106, 1108, 1110, 1112, 1287, 1288, 1289, 1290, 1291, 1292, 1357, 1358);
                     //Boomerang Shot, Bulwark, Electrical Storm, Overclocking Station, Shock Rail, Fail-Safe
                     $base_arsenal_certs = array(1399, 1400, 1403, 1406, 1407, 1408, 1409, 1410, 1411, 1416, 1417, 1418, 1421, 1422, 1423, 1426, 1427, 1428, 1436, 1437, 1438);
                     //EMP, Particle Beam, Rocket Jump, Shoulder Rockets, Combat shotgun, light machine gun
                     $base_electron_certs = array(964, 966, 968, 970, 972, 974, 1150, 1152, 1156, 1158, 1162, 1164, 1311, 1312, 1313, 1314, 1315, 1316);
                     //Energy Wall, Fortify, Multi Turret, Sentinel Pod, Tesla Rifle, Overseer
                     $base_bastion_certs = array(952, 954, 956, 958, 960, 962, 1138, 1140, 1142, 1144, 1146, 1148, 1305, 1306, 1307, 1308, 1309, 1310);
                     //Eruption Rounds, Execute Shot, Remote Explosive, Smoke Screen, Sniper Rifle, Ambush
                     $base_nighthawk_certs = array(870, 876, 882, 886, 894, 914, 980, 1178, 1180, 1182, 1184, 1186, 1188, 1323, 1324, 1325, 1326, 1327, 1328);
                     //Overload, Power Field, SIN Scrambler, Teleport Beacon, Conduit, Charge Rifle
                     $base_raptor_certs = array(840, 854, 858, 868, 976, 978, 1190, 1192, 1194, 1196, 1198, 1200, 1329, 1330, 1331, 1332, 1333, 1334);
                     $base_shared_items = array();
                     $base_assault_items = array();
                     $base_biotech_items = array();
                     $base_dreadnaught_items = array();
                     $base_engineer_items = array();
                     $base_recon_items = array();
                     $base_firecat_items = array();
                     $base_tigerclaw_items = array();
                     $base_dragonfly_items = array();
                     $base_recluse_items = array();
                     $base_rhino_items = array();
                     $base_mammoth_items = array();
                     $base_arsenal_items = array();
                     $base_electron_items = array();
                     $base_bastion_items = array();
                     $base_nighthawk_items = array();
                     $base_raptor_items = array();
                     for ($i = 0; $i < count($cert_info); $i++) {
                         //base items
                         if (in_array($cert_info[$i]->id, $base_shared_certs)) {
                             $base_shared_items[] = $cert_info[$i]->name;
                         }
                         if ($unlocked_base_assault) {
                             if (in_array($cert_info[$i]->id, $base_assault_certs)) {
                                 $base_assault_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_base_biotech) {
                             if (in_array($cert_info[$i]->id, $base_biotech_certs)) {
                                 $base_biotech_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_base_dreadnaught) {
                             if (in_array($cert_info[$i]->id, $base_dreadnaught_certs)) {
                                 $base_dreadnaught_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_base_engineer) {
                             if (in_array($cert_info[$i]->id, $base_engineer_certs)) {
                                 $base_engineer_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_base_recon) {
                             if (in_array($cert_info[$i]->id, $base_recon_certs)) {
                                 $base_recon_items[] = $cert_info[$i]->name;
                             }
                         }
                         //ASSAULT ADV
                         if ($unlocked_firecat) {
                             if (in_array($cert_info[$i]->id, $base_firecat_certs)) {
                                 $base_firecat_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_tigerclaw) {
                             if (in_array($cert_info[$i]->id, $base_tigerclaw_certs)) {
                                 $base_tigerclaw_items[] = $cert_info[$i]->name;
                             }
                         }
                         //BIOTECH ADV
                         if ($unlocked_dragonfly) {
                             if (in_array($cert_info[$i]->id, $base_dragonfly_certs)) {
                                 $base_dragonfly_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_recluse) {
                             if (in_array($cert_info[$i]->id, $base_recluse_certs)) {
                                 $base_recluse_items[] = $cert_info[$i]->name;
                             }
                         }
                         //DREADNAUGHT ADV
                         if ($unlocked_rhino) {
                             if (in_array($cert_info[$i]->id, $base_rhino_certs)) {
                                 $base_rhino_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_mammoth) {
                             if (in_array($cert_info[$i]->id, $base_mammoth_certs)) {
                                 $base_mammoth_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_arsenal) {
                             if (in_array($cert_info[$i]->id, $base_arsenal_certs)) {
                                 $base_arsenal_items[] = $cert_info[$i]->name;
                             }
                         }
                         //ENGINEER ADV
                         if ($unlocked_electron) {
                             if (in_array($cert_info[$i]->id, $base_electron_certs)) {
                                 $base_electron_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_bastion) {
                             if (in_array($cert_info[$i]->id, $base_bastion_certs)) {
                                 $base_bastion_items[] = $cert_info[$i]->name;
                             }
                         }
                         //RECON ADV
                         if ($unlocked_nighthawk) {
                             if (in_array($cert_info[$i]->id, $base_nighthawk_certs)) {
                                 $base_nighthawk_items[] = $cert_info[$i]->name;
                             }
                         }
                         if ($unlocked_raptor) {
                             if (in_array($cert_info[$i]->id, $base_raptor_certs)) {
                                 $base_raptor_items[] = $cert_info[$i]->name;
                             }
                         }
                     }
                     asort($base_shared_items);
                     asort($base_assault_items);
                     asort($base_biotech_items);
                     asort($base_dreadnaught_items);
                     asort($base_engineer_items);
                     asort($base_recon_items);
                     asort($base_firecat_items);
                     asort($base_tigerclaw_items);
                     asort($base_dragonfly_items);
                     asort($base_recluse_items);
                     asort($base_rhino_items);
                     asort($base_mammoth_items);
                     asort($base_arsenal_items);
                     asort($base_electron_items);
                     asort($base_bastion_items);
                     asort($base_nighthawk_items);
                     asort($base_raptor_items);
                     //cache it, cache it good
                     $cached_can_craft = array();
                     $cached_can_craft['base_shared_items'] = $base_shared_items;
                     $cached_can_craft['base_assault_items'] = $base_assault_items;
                     $cached_can_craft['base_biotech_items'] = $base_biotech_items;
                     $cached_can_craft['base_dreadnaught_items'] = $base_dreadnaught_items;
                     $cached_can_craft['base_engineer_items'] = $base_engineer_items;
                     $cached_can_craft['base_recon_items'] = $base_recon_items;
                     $cached_can_craft['base_firecat_items'] = $base_firecat_items;
                     $cached_can_craft['base_tigerclaw_items'] = $base_tigerclaw_items;
                     $cached_can_craft['base_dragonfly_items'] = $base_dragonfly_items;
                     $cached_can_craft['base_recluse_items'] = $base_recluse_items;
                     $cached_can_craft['base_rhino_items'] = $base_rhino_items;
                     $cached_can_craft['base_mammoth_items'] = $base_mammoth_items;
                     $cached_can_craft['base_electron_items'] = $base_electron_items;
                     $cached_can_craft['base_bastion_items'] = $base_bastion_items;
                     $cached_can_craft['base_nighthawk_items'] = $base_nighthawk_items;
                     $cached_can_craft['base_raptor_items'] = $base_raptor_items;
                     $cached_can_craft['base_arsenal_items'] = $base_arsenal_items;
                     Cache::forever($cache_key_progress . "_can_craft", $cached_can_craft);
                     Cache::forever($cache_key_progress . "_md5_cc", $progress_md5);
                     //set progress to 1 for the view control params.
                     $progress = 1;
                 } else {
                     //this player does not have progress->unlocks so we can't even check for craftables; assume null.
                     $progress = null;
                 }
             } else {
                 //load it all from cache
                 $cached_can_craft = Cache::Get($cache_key_progress . "_can_craft");
                 //set all those variables
                 $base_shared_items = $cached_can_craft['base_shared_items'];
                 $base_assault_items = $cached_can_craft['base_assault_items'];
                 $base_biotech_items = $cached_can_craft['base_biotech_items'];
                 $base_dreadnaught_items = $cached_can_craft['base_dreadnaught_items'];
                 $base_engineer_items = $cached_can_craft['base_engineer_items'];
                 $base_recon_items = $cached_can_craft['base_recon_items'];
                 $base_firecat_items = $cached_can_craft['base_firecat_items'];
                 $base_tigerclaw_items = $cached_can_craft['base_tigerclaw_items'];
                 $base_dragonfly_items = $cached_can_craft['base_dragonfly_items'];
                 $base_recluse_items = $cached_can_craft['base_recluse_items'];
                 $base_rhino_items = $cached_can_craft['base_rhino_items'];
                 $base_mammoth_items = $cached_can_craft['base_mammoth_items'];
                 $base_arsenal_items = $cached_can_craft['base_arsenal_items'];
                 $base_electron_items = $cached_can_craft['base_electron_items'];
                 $base_bastion_items = $cached_can_craft['base_bastion_items'];
                 $base_nighthawk_items = $cached_can_craft['base_nighthawk_items'];
                 $base_raptor_items = $cached_can_craft['base_raptor_items'];
             }
         }
     }
     if ($web_prefs['show_workbench']) {
         //Workbench Stuff
         $workbench_info = array();
         if (Cache::has($player->db_id . '_printer')) {
             $workbench_info = Cache::get($player->db_id . '_printer');
         } else {
             $wbinfo = Printer::where('db_id', '=', $player->db_id)->get();
             foreach ($wbinfo as $wb) {
                 $workbench_info[] = $wb->original;
             }
             Cache::forever($player->db_id . '_printer', $workbench_info);
         }
         if (!empty($workbench_info)) {
             $workbench_info_blueprints = array();
             for ($i = 0; $i < count($workbench_info); $i++) {
                 $workbench_info_blueprints[] = $workbench_info[$i]['blueprint_id'];
             }
             $workbench_results = Recipe::with(array('outputs'))->where_in('itemtypeid', $workbench_info_blueprints)->get(array('itemtypeid', 'description', 'name'));
             $workbench_output_ids = array();
             $workbench_output_names = array();
             //at this point we will always have something in the workbench so don't worry about null
             foreach ($workbench_results as $workbench_result) {
                 if ($workbench_result->relationships['outputs'] != null) {
                     //add the output itemtypeid to the list
                     print_r($workbench_result->relationships['outputs']);
                 } else {
                     //add the blueprint_id as an itemtypeid because its a cert
                     $workbench_output_ids[] = $workbench_result->attributes['itemtypeid'];
                     if (strstr($workbench_result->attributes['description'], "Research")) {
                         $workbench_output_names[$workbench_result->attributes['itemtypeid']] = $workbench_result->attributes['description'];
                     } else {
                         $workbench_output_names[$workbench_result->attributes['itemtypeid']] = $workbench_result->attributes['name'];
                     }
                 }
             }
             unset($workbench_results);
             //get the icons
             $wb_icons = hWebIcon::where(function ($query) use($workbench_output_ids) {
                 $query->where('version', '=', Base_Controller::getVersionDate());
                 $query->where_in('itemTypeId', $workbench_output_ids);
             })->get(array('itemtypeid', 'asset_path'));
             foreach ($wb_icons as $wb) {
                 $workbench_output_icons[$wb->itemtypeid] = $wb->asset_path;
             }
             unset($wb_icons);
         }
     }
     //ShipIt(TM)
     $response = View::make('player.player_profile_store')->with('title', 'Player Store for ' . $playerName)->with(compact('web_prefs'))->with(compact('player'))->with(compact('army'));
     if (!empty($progress)) {
         $response->progress = $progress;
         $response->base_shared_items = $base_shared_items;
         $response->base_assault_items = $base_assault_items;
         $response->base_biotech_items = $base_biotech_items;
         $response->base_dreadnaught_items = $base_dreadnaught_items;
         $response->base_engineer_items = $base_engineer_items;
         $response->base_recon_items = $base_recon_items;
         $response->base_firecat_items = $base_firecat_items;
         $response->base_tigerclaw_items = $base_tigerclaw_items;
         $response->base_dragonfly_items = $base_dragonfly_items;
         $response->base_recluse_items = $base_recluse_items;
         $response->base_rhino_items = $base_rhino_items;
         $response->base_mammoth_items = $base_mammoth_items;
         $response->base_arsenal_items = $base_arsenal_items;
         $response->base_electron_items = $base_electron_items;
         $response->base_bastion_items = $base_bastion_items;
         $response->base_nighthawk_items = $base_nighthawk_items;
         $response->base_raptor_items = $base_raptor_items;
     }
     if (!empty($market_listings)) {
         $response->market_listings = $market_listings;
         if (!empty($item_stats_lookup)) {
             $response->stats = $item_stats_lookup;
         }
     }
     if (!empty($workbench_info)) {
         $response->workbench_info = $workbench_info;
         $response->workbench_output_icons = $workbench_output_icons;
         $response->workbench_output_names = $workbench_output_names;
     }
     return $response;
 }
示例#15
0
<?php

use chapter10\DiamondDecorator;
use chapter10\Plains;
use chapter10\PollutionDecorator;
$factory = new TerrainFactory(new EarthSea(-2), new EarthForest(), new EarthPlains());
print_r($factory->getSea());
print_r($factory->getForest());
print_r($factory->getPlains());
echo "<hr/>";
//TODO 216-217 page
//main army
$army = new Army();
$army->addUnit(new Archer())->addUnit(new LaserCannonUnit());
//sub army
$sub_army = new Army();
$sub_army->addUnit(new TroopCarrier())->addUnit(new LaserCannonUnit())->addUnit(new LaserCannonUnit());
//merging two armies
$army->addUnit($sub_army);
echo "Attack power is equal to: " . $army->bombardStrength();
echo "<hr/>";
$tile = new DiamondDecorator(new PollutionDecorator(new Plains()));
echo $tile->getWealthFactor();
echo "<hr/>";
$carrier = new TroopCarrier();
$carrier->addUnit(new Cavalry());
print_r(UnitScript::joinExisting($carrier, $army));
示例#16
0
{
    public function bombardStrength()
    {
        return 44;
    }
}
class Cavalry extends Unit
{
    public function bombardStrength()
    {
        return 15;
    }
}
$archer = new Archer();
echo "archer attacking with strength: " . $archer->bombardStrength() . "\n";
$main_army = new Army();
$main_army->addUnit($archer);
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$main_army->addUnit(new Cavalry());
echo "main_army attacking with strength: " . $main_army->bombardStrength() . "\n";
$sub_army = new Army();
$sub_army->addUnit(new Cavalry());
$sub_army->addUnit(new Cavalry());
$main_army->addUnit($sub_army);
echo "main_army attacking with strength: " . $main_army->bombardStrength() . "\n";
$troop = new TroopCarrier();
$troop->addUnit(new Archer());
$troop->addUnit(new LaserCannonUnit());
$main_army->addUnit($troop);
echo "main_army attacking with strength: " . $main_army->bombardStrength() . "\n";
示例#17
0
 public function get_player_profile($name = NULL)
 {
     //searching by name, null name = no buenos
     if ($name == NULL) {
         return Response::error('404');
     } else {
         $input_name = urldecode($name);
     }
     //Look up the player, latest to account for deletes with the same name
     $player = Player::where('name', '=', $input_name)->order_by('created_at', 'DESC')->first();
     //no player found, why not search?
     if (!$player) {
         return Response::error('404');
     }
     /*
     if( $player->name == 'Thehink' ) {
         return View::make('player.player_profile_banned')
         ->with('title', 'Player Profile for ' . $player->name)
         ->with(compact('player'));
     }
     */
     //But wait there's more, let's see if we know where that player has been
     $locations = false;
     /*Location::where('db_id','=',$player->db_id)
       ->order_by('created_at','DESC')
       ->first();*/
     //provide the spotters name if a location has been sighted
     if ($locations) {
         $spotter = Player::where('db_id', '=', $locations->spotter_db_id)->only('name');
     } else {
         $spotter = NULL;
     }
     //calculate the players closest POI
     if ($locations) {
         if (!Cache::has('poi_lookup')) {
             Cache::forever('poi_lookup', PointOfInterest::get(array('name', 'coord_x', 'coord_y')));
         }
         $pois = Cache::get('poi_lookup');
         $poi_locs = $pois;
         $poi_lastx = round($locations->coord_x);
         $poi_lasty = round($locations->coord_y);
         $poi_nearest = [999999, 'n/a'];
         foreach ($poi_locs as $pois) {
             $xs = 0;
             $ys = 0;
             $xs = $poi_lastx - intval($pois->coord_x);
             $xs = $xs * $xs;
             $ys = $poi_lasty - intval($pois->coord_y);
             $ys = $ys * $ys;
             $distance = round(sqrt($xs + $ys));
             if ($distance < $poi_nearest[0]) {
                 $poi_nearest = [$distance, $pois->name];
             }
         }
         $nearestloc = $poi_nearest[1];
     } else {
         $nearestloc = NULL;
     }
     //Does the player have an army?
     $army = Army::where('armyId', '=', $player->armyid)->order_by('created_at', 'DESC')->first();
     //escape for output in title
     $playerName = htmlentities($player->name);
     //Player website preferences
     $web_prefs = WebsitePref::where('db_id', '=', $player->db_id)->first();
     if (isset($web_prefs->attributes)) {
         $web_prefs = $web_prefs->attributes;
     }
     if (isset($web_prefs['show_inventory'])) {
         if ($web_prefs['show_inventory'] == 1) {
             $inventory = Inventory::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
         } else {
             $inventory = null;
         }
     } else {
         $inventory = Inventory::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
     }
     /*
     			Mappings:
     				local c_RawToRefinedConversion = {
     					["78014"] = "77703", --Copper
     					["78015"] = "77704", --Iron
     					["78016"] = "77705", --Aluminum
     					["78017"] = "77706", --Carbon
     					["78018"] = "77707", --Silicate
     					["78019"] = "77708", --Ceramics
     					["78020"] = "77709", --Methine
     					["78021"] = "77710", --Octine
     					["78022"] = "77711", --Nitrine
     					["82420"] = "82419", --Radine
     					["78023"] = "77713", --Petrochemical
     					["78024"] = "77714", --Biopolymer
     					["78025"] = "77715", --Xenografts
     					["78026"] = "77716", --Toxins
     					["78027"] = "77736", --Regenics
     					["78028"] = "77737", --Anabolics
     				}
     				local c_RefinedToRawConversion = {
     					["77703"] = "78014", --Copper
     					["77704"] = "78015", --Iron
     					["77705"] = "78016", --Aluminum
     					["77706"] = "78017", --Carbon
     					["77707"] = "78018", --Silicate
     					["77708"] = "78019", --Ceramics
     					["77709"] = "78020", --Methine
     					["77710"] = "78021", --Octine
     					["77711"] = "78022", --Nitrine
     					["82419"] = "82420", --Radine
     					["77713"] = "78023", --Petrochemical
     					["77714"] = "78024", --Biopolymer
     					["77715"] = "78025", --Xenografts
     					["77716"] = "78026", --Toxins
     					["77736"] = "78027", --Regenics
     					["77737"] = "78028", --Anabolics
     				}
     				local c_ResourceIds = {
     					["10"] = "Crystite",
     					["80404"] = "AMPS",
     					["30412"] = "CHITS",
     					["30404"] = "SiftedEarth",
     					["77703"] = "Metal",
     					["77704"] = "Metal",
     					["77705"] = "Metal",
     					["77706"] = "Carbon",
     					["77707"] = "Carbon",
     					["77708"] = "Carbon",
     					["77709"] = "Ceramic",
     					["77710"] = "Ceramic",
     					["77711"] = "Ceramic",
     					["77713"] = "Biomaterial",
     					["77714"] = "Biomaterial",
     					["77715"] = "Biomaterial",
     					["77716"] = "Polymer",
     					["77736"] = "Polymer",
     					["77737"] = "Polymer",
     					["82419"] = "Ceramic",
     				}
     */
     if ($inventory) {
         $inventory = unserialize($inventory->inventory);
         if (isset($inventory->{10})) {
             $player_crystite_amount = $inventory->{10};
         } else {
             $player_crystite_amount = 0;
         }
         $cache_key_inventory = $player->db_id . "_inventory";
         if (Cache::Get($cache_key_inventory) != $inventory) {
             $raw_resource_names = array('Copper', 'Iron', 'Aluminum', 'Carbon', 'Silicate', 'Ceramics', 'Methine', 'Octine', 'Nitrine', 'Radine', 'Petrochemical', 'Biopolymer', 'Xenografts', 'Toxins', 'Regenics', 'Anabolics');
             $raw_resource_ids = array(78014, 78015, 78016, 78017, 78018, 78019, 78020, 78021, 78022, 82420, 78023, 78024, 78025, 78026, 78027, 78028);
             $refined_resource_ids = array(77703, 77704, 77705, 77706, 77707, 77708, 77709, 77710, 77711, 82419, 77713, 77714, 77715, 77716, 77736, 77737);
             //Convert inventory to an array
             $inventory = (array) $inventory;
             //Get a cache (or make one) of all the resource item image paths
             if (!Cache::has('resource_asset_paths_dump')) {
                 $resource_ids = array_merge($raw_resource_ids, $refined_resource_ids);
                 $resource_icons = hWebIcon::where(function ($query) use($resource_ids) {
                     $query->where('version', '=', Base_Controller::getVersionDate());
                     $query->where_in('itemTypeId', $resource_ids);
                 })->get(array('itemtypeid', 'asset_path'));
                 Cache::forever('resource_asset_paths_dump', $resource_icons);
             } else {
                 $resource_icons = Cache::Get('resource_asset_paths_dump');
             }
             $player_raw_resources = array();
             $player_refined_resources = array();
             $counter_raw = 0;
             $counter_refined = 0;
             foreach ($inventory as $key => $value) {
                 if (in_array($key, $raw_resource_ids)) {
                     $player_raw_resources[$counter_raw]['name'] = $raw_resource_names[array_search($key, $raw_resource_ids)];
                     $player_raw_resources[$counter_raw]['id'] = $key;
                     $player_raw_resources[$counter_raw]['amt'] = $value;
                     for ($i = 0; $i < count($resource_icons); $i++) {
                         if ($resource_icons[$i]->attributes['itemtypeid'] == $key) {
                             $player_raw_resources[$counter_raw]['asset_path'] = $resource_icons[$i]->attributes['asset_path'];
                         }
                     }
                     $counter_raw++;
                 }
                 if (in_array($key, $refined_resource_ids)) {
                     $player_refined_resources[$counter_refined]['name'] = $raw_resource_names[array_search($key, $refined_resource_ids)];
                     $player_refined_resources[$counter_refined]['id'] = $key;
                     $player_refined_resources[$counter_refined]['amt'] = $value;
                     for ($i = 0; $i < count($resource_icons); $i++) {
                         if ($resource_icons[$i]->attributes['itemtypeid'] == $key) {
                             $player_refined_resources[$counter_refined]['asset_path'] = $resource_icons[$i]->attributes['asset_path'];
                         }
                     }
                     $counter_refined++;
                 }
             }
             //set some cache
             Cache::forever($cache_key_inventory . "_refined_resources", $player_refined_resources);
             Cache::forever($cache_key_inventory . "_raw_resources", $player_raw_resources);
         } else {
             $player_refined_resources = Cache::Get($cache_key_inventory . "_refined_resources");
             $player_raw_resources = Cache::Get($cache_key_inventory . "_raw_resources");
         }
         //set inventory to 1, we don't need everything else exposed on the players page
         $inventory = 1;
     }
     //loadouts
     /*
         Mappings:
             $loadout->Gear[$i] = Currently equipped items array
             $loadout->Gear[$i]->slot_index
             $loadout->Gear[$i]->info->durability->pool
             $loadout->Gear[$i]->info->durability->current
             $loadout->Gear[$i]->info->attribute_modifiers[$k] = array of custom attributes for this item
             $loadout->Gear[$i]->info->quality = The quality of the crafted item
             $loadout->Gear[$i]->info->creator_guid = the creators unique player ID
             $loadout->Gear[$i]->info->item_sdb_id = The root item this was crafted from
     
             $loadout->Weapons[$i] = Currently equiped weapons array
             $loadout->Weapons[$i]->info->durability->pool
             $loadout->Weapons[$i]->info->durability->current
             $loadout->Weapons[$i]->info->attribute_modifiers[$k]
             $loadout->Weapons[$i]->info->quality
             $loadout->Weapons[$i]->info->creator_guid
             $loadout->Weapons[$i]->info->item_sdb_id
             $loadout->Weapons[$i]->allocated_power
             $loadout->Weapons[$i]->slot_index = Weapon slot, 0 is main hand, 1 is alt weapon
     */
     /*
         Attribute modifiers mapping:
             5   = Jet Energy Recharge
             6   = health
             7   = health regen
             12  = Run Speed
             29  = weapon splash radius
             35  = Energy (for jetting)
             37  = Jump Height
             950 = Max durability pool
             951 = Mass (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             952 = Power (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             953 = CPU (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             956 = clip size
             954 = damage per round
             977 = Damage
             978 = Debuff Duration
             1121= Air Sprint
     
             Defaults for weapons are set in the "hstats" table.
     */
     if (isset($web_prefs['show_loadout'])) {
         if ($web_prefs['show_loadout'] == 1) {
             $loadout = Loadout::where('db_id', '=', $player->db_id)->first();
         } else {
             $loadout = null;
         }
     } else {
         $loadout = Loadout::where('db_id', '=', $player->db_id)->first();
     }
     if ($loadout) {
         //Lets play the cache game, where all the stuff is stored locally and the points don't matter!
         $loadout = unserialize($loadout->entry);
         //VERSION 0.6 CHECKING (Array = Good, Object = BAD!)
         if (gettype($loadout) == "object") {
             //This is from version 0.6, we can no longer use this data.
             $loadout = null;
         }
         $cache_key_loadouts = $player->db_id . "_loadouts";
         $loadout_md5 = md5(serialize($loadout));
         if (Cache::Get($cache_key_loadouts . '_md5') != $loadout_md5 && $loadout != null) {
             //Oh I am playing the game, the one that will take me to my end.
             //Make sure this isnt a terrible send
             if (isset($loadout[0]->Gear)) {
                 for ($k = 0; $k < count($loadout); $k++) {
                     if ($loadout[$k]->Chassis_ID == 77733 || $loadout[$k]->Chassis_ID == 82394 || $loadout[$k]->Chassis_ID == 31334) {
                         //ignore the training frame
                     } else {
                         //Break each loadout into its own cache
                         Cache::forever($cache_key_loadouts . '_' . $loadout[$k]->Chassis_ID, $loadout[$k]);
                     }
                 }
                 //Cache the loadout md5 so we can call it again later
                 Cache::forever($cache_key_loadouts . '_md5', $loadout_md5);
                 //and finally set loadout=1 so we know to display equipped gear data
                 $loadout = 1;
             }
         }
     }
     //progress (feat. obama)
     if (isset($web_prefs['show_progress'])) {
         if ($web_prefs['show_progress'] == 1) {
             $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
         } else {
             $progress = null;
         }
     } else {
         $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
     }
     /*
         Mappings:
             $progress->xp[$i].sdb_id = ItemTypeId for chassis
             $progress->xp[$i].name = battle frame name
             $progress->xp[$i].lifetime_xp = amount of xp gained overall
             $progress->xp[$i].current_xp = currently allocated XP (WARNING: key may not exist!)
             $progress->chassis_id = current chassis ID, use this to identify what battleframe the player was last using
             $progress->unlocks.array() = certificate array for currently equipped chassis
     */
     if ($progress) {
         //Progression graph builder
         $player_progresses_cache_key = $player->db_id . "_graph";
         $player_id = $player->db_id;
         $frame_progress_javascript = array();
         if (Cache::has($player_progresses_cache_key)) {
             //pull from cache
             $frame_progress_javascript = Cache::get($player_progresses_cache_key);
         } else {
             //don't cache the query, that wont help us; cache the javascript output for highcharts instead.
             $player_progresses = DB::query('SELECT DISTINCT(`db_id`),`entry`,unix_timestamp(`updated_at`) AS `updated_at` FROM `progresses` WHERE db_id= ' . $player_id . '  AND `created_at` > DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY `created_at` ORDER BY `updated_at` ASC LIMIT 7');
             //check chassis_id exists
             if (!empty($player_progresses)) {
                 $check_chassis = unserialize($player_progresses[0]->entry);
             } else {
                 $check_chassis = "";
                 $check_chassis_id = false;
             }
             if (!isset($check_chassis->chassis_id)) {
                 $check_chassis_id = false;
             } else {
                 $check_chassis_id = true;
             }
             if ($player_progresses && $check_chassis_id) {
                 $frame_progress = array();
                 for ($i = 0; $i < count($player_progresses); $i++) {
                     $day_progress = unserialize($player_progresses[$i]->entry);
                     unset($day_progress->unlocks);
                     foreach ($day_progress->xp as $key => $value) {
                         if ($value->sdb_id == 77733 || $value->sdb_id == 82394 || $value->sdb_id == 31334) {
                             //ignore training frame
                         } else {
                             $frame_progress[$value->name][$player_progresses[$i]->updated_at] = $value->lifetime_xp;
                         }
                     }
                 }
                 //Make it json datas
                 $frame_progress_javascript = array();
                 foreach ($frame_progress as $battle_frame_name => $value) {
                     $xp_data_string = "[";
                     foreach ($value as $day => $xp_amt) {
                         $xp_data_string .= "[" . $day * 1000 . "," . $xp_amt . "],";
                         $frame_progress_javascript[$battle_frame_name] = rtrim($xp_data_string, ",") . "]";
                     }
                 }
             } else {
                 $frame_progress_javascript = null;
                 $progress = false;
             }
             //build cache
             Cache::put($player_progresses_cache_key, $frame_progress_javascript, 30);
         }
     } else {
         $frame_progress_javascript = null;
         $progress = false;
     }
     //Frames & Unlocks
     if ($progress) {
         $cache_key_progress = $player->db_id . "_progress";
         $progress = $progress->entry;
         $progress_md5 = md5($progress);
         if (Cache::Get($cache_key_progress . "_md5") != $progress_md5) {
             $progress = unserialize($progress);
             if (isset($progress->xp)) {
                 $battle_frame_id_list = array();
                 for ($i = 0; $i < count($progress->xp); $i++) {
                     $battle_frame_id_list[$i] = $progress->xp[$i]->sdb_id;
                 }
                 $battle_frame_images = hWebIcon::where(function ($query) use($battle_frame_id_list) {
                     $query->where('version', '=', Base_Controller::getVersionDate());
                     $query->where_in('itemTypeId', $battle_frame_id_list);
                 })->get();
                 //set some cache
                 Cache::forever($cache_key_progress . "_battleframe_images", $battle_frame_images);
             } else {
                 $battle_frame_images = null;
             }
             if (isset($web_prefs['show_unlocks'])) {
                 $show_unlocks = $web_prefs['show_unlocks'];
             } else {
                 //Assume show unlocks is 1
                 $show_unlocks = 1;
             }
             if (isset($progress->unlocks) && $show_unlocks == 1) {
                 //VERSION 0.6 CHECK (Array = BAD, Object = Good!)
                 if (gettype($progress->unlocks) == "array") {
                     //NOPE.
                     $battle_frame_unlocks = null;
                 } else {
                     if (gettype($progress->unlocks) == "object") {
                         //Looks like 0.7+ to me!
                         //Create a cache for each frame unlock set
                         foreach ($progress->unlocks as $chassis_id => $cert_array) {
                             if ($chassis_id == 77733 || $chassis_id == 82394 || $chassis_id == 31334) {
                                 //ignore training frame
                             } else {
                                 Cache::forever($cache_key_progress . "_" . $chassis_id, $cert_array);
                             }
                         }
                     }
                 }
             }
             //Cache the progress variable so we can do a quick compare on a later load
             Cache::forever($cache_key_progress, $progress);
             Cache::forever($cache_key_progress . "_md5", $progress_md5);
         } else {
             //Assign cache values to local variable names.
             $battle_frame_images = Cache::Get($cache_key_progress . "_battleframe_images");
             $progress = Cache::Get($cache_key_progress);
         }
     } else {
         $battle_frame_unlocks = null;
     }
     return View::make('player.player_profile')->with('title', 'Player Profile for ' . $playerName)->with(compact('player'))->with(compact('locations'))->with(compact('nearestloc'))->with(compact('army'))->with(compact('inventory'))->with(compact('player_raw_resources'))->with(compact('player_refined_resources'))->with(compact('player_crystite_amount'))->with(compact('loadout'))->with(compact('battle_frame_unlocks'))->with(compact('progress'))->with(compact('frame_progress_javascript'))->with(compact('battle_frame_images'))->with(compact('web_prefs'))->with(compact('spotter'));
 }
示例#18
0
<?php

require_once "Visitor.php";
require_once "Army.php";
require_once "CompositeUnit.php";
require_once "Unit.php";
class UnitException extends Exception
{
}
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$main_army->addUnit(new Cavalry());
$textdump = new TextDumpArmyVisitor();
$main_army->accept($textdump);
print $textdump->getText();
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$main_army->addUnit(new Cavalry());
$taxcollector = new TaxCollectionVisitor();
$main_army->accept($taxcollector);
print $taxcollector->getReport();
print "TOTAL: ";
print $taxcollector->getTax() . "\n";
// mz: end add client code
示例#19
0
{
    public $value = 0;
    function add(unit $unit)
    {
        $this->value += 1;
    }
    function getValue()
    {
        return $this->vlaue;
    }
    function remove(unit $unit)
    {
        $this->value = 0;
    }
}
class Archer extends unit
{
    function add(unit $unit)
    {
        print_r($unit);
    }
    function remove(unit $unit)
    {
        print_r("Archer::remove()");
    }
}
$main = new Army();
$main->add(new Archer());
$main->add(new Archer());
$sub = new Archer();
$sub->add(new Archer());
示例#20
0
    }
}
class LaserCannonUnit extends Unit
{
    function bombardStrength()
    {
        return 44;
    }
}
class Army
{
    private $units = array();
    function addUnit(Unit $unit)
    {
        array_push($this->units, $unit);
    }
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
$unit1 = new Archer();
$unit2 = new LaserCannonUnit();
$army = new Army();
$army->addUnit($unit1);
$army->addUnit($unit2);
print $army->bombardStrength();
示例#21
0
 /**
  * déduit le temps écoulé des éléments en construction
  * @param $time_diff int
  */
 public function update_queue($time_diff)
 {
     $item = $this->get_first_item_from_queue();
     if (!empty($item)) {
         $time_left = $item['time_left'] - $time_diff;
         if ($time_left > 0) {
             $sql = "UPDATE queue SET time_left = time_left - :time_diff WHERE id = {$item['id']}";
             $req = Db::prepare($sql);
             $req->bindParam(':time_diff', $time_diff, PDO::PARAM_INT);
             $req->execute();
         } else {
             // ajout de la flotte au stock et mise à jour du score
             $fleet = new Army($this->user_id);
             $fleet->add_troop($item['unit_id'], $item['quantity'], -1, true);
             // effacement de l'élement de la file d'attente
             $this->remove_item_from_queue($item['id']);
             // on met à jour l'élément suivant de la file d'attente
             $this->update_queue(abs($time_left));
         }
     }
 }
示例#22
0
        if (in_array($unit, $this->units, true)) {
            return;
        }
        $this->units[] = $unit;
    }
    function removeUnit(Unit $unit)
    {
        $this->units = array_udiff($this->units, [$unit], function ($a, $b) {
            return $a === $b ? 0 : 1;
        });
    }
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Archer());
$main_army->addUnit($sub_army);
echo $main_army->bombardStrength();
var_dump($main_army);
var_dump($sub_army);
示例#23
0
    {
        if ($unit instanceof Cavalry) {
            throw new UnitException("Can't get a horse on the vehicle");
        }
        parent::addUnit($unit);
    }
    function bombardStrength()
    {
        return 0;
    }
}
// end previous code
class Army extends CompositeUnit
{
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units() as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
$main_army = new Army();
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCanonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Cavalry());
$main_army->addUnit($sub_army);
$main_army->addUnit(new Cavalry());
print $main_army->textDump();
 public function get_siggen($name = NULL, $frame_request = NULL)
 {
     //searching by name, null name = no buenos
     if ($name == NULL || $frame_request == NULL) {
         return Response::error('404');
     } else {
         $input_name = urldecode($name);
     }
     //check to make sure in valid frame names
     //don't forget "barsig" for current
     $valid_frame_requests = array('sig', 'arsenal', 'assault', 'firecat', 'tigerclaw', 'biotech', 'recluse', 'dragonfly', 'dreadnaught', 'rhino', 'mammoth', 'engineer', 'electron', 'bastion', 'recon', 'raptor', 'nighthawk');
     if (!in_array($frame_request, $valid_frame_requests)) {
         return Response::error('404');
     }
     //Look up the player, latest to account for deletes with the same name
     $player = Player::where('name', '=', $input_name)->order_by('created_at', 'DESC')->first();
     //no player found, why not search?
     if (!$player) {
         return Response::error('404');
     }
     //Does the player have an army?
     $army = Army::where('armyId', '=', $player->armyid)->order_by('created_at', 'DESC')->first();
     if (isset($player->armytag)) {
         $army = $player->armytag;
     } else {
         $army = null;
     }
     //escape for output in title
     $playerName = htmlentities($player->name);
     //Get the most recent progress and find out the current frame being played and its total XP
     $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
     if ($progress) {
         $progress = unserialize($progress->entry);
         $cache_key_progress = $player->db_id . "_progress";
         if (isset($progress->xp) && isset($progress->chassis_id)) {
             //if we're barsig only, current frame, if not check entry for other frame exists
             if ($frame_request == 'sig') {
                 $current_frame = $progress->chassis_id;
             } else {
                 $frame_request_exists = self::simpleNameToChassisId($frame_request);
                 if (!$frame_request_exists) {
                     return Response::error('404');
                 } else {
                     $current_frame = $frame_request_exists;
                 }
             }
             $frame_exists_in_progress = false;
             for ($i = 0; $i < count($progress->xp); $i++) {
                 if ($progress->xp[$i]->sdb_id == $current_frame) {
                     $lifetime_xp = number_format($progress->xp[$i]->lifetime_xp);
                     $frame_exists_in_progress = true;
                 }
             }
             if (!$frame_exists_in_progress) {
                 return Response::error('404');
             }
         } else {
             //we need this data, abort!
             return Response::error('404');
         }
     } else {
         //We kind of need progress in order to display anything so if the user doesn't have a progress than abort everything.
         return Response::error('404');
     }
     //Cache checking ain't easy
     $cache_key = $playerName . "_sig_" . $frame_request;
     if (!Cache::has($player->db_id . '_sig_' . $frame_request)) {
         //THEME DEFAULT SETTING
         $theme = "Default";
         $background = self::chassisIdToSimpleName($current_frame);
         if (!$background) {
             return Response::error('404');
         }
         $background = imagecreatefrompng('public/img/sig_set/' . $theme . '/' . $background . '.png');
         //START DEFAULT THEME
         if ($theme == "Default") {
             //Hey man, lets make this shit look good.
             imageantialias($background, true);
             //Save its alpha channel
             imagesavealpha($background, true);
             $overlay = imagecreatefrompng('public/img/sig_set/Default/Overlay.png');
             //Before we set the overlay, lets write some things on our image
             $text_color = imagecolorallocate($background, 255, 255, 255);
             $stroke_color = imagecolorallocate($background, 0, 0, 0);
             //EuroStyle Condensed H16 / W10
             $font = imageloadfont('public/img/sig_set/Default/tddb_sig_font.gdf');
             //EuroStyle Condensed H14 / W10
             $small_font = imageloadfont('public/img/sig_set/Default/tddb_sig_font_14px.gdf');
             //background_image,font,x-space,y-space,string,color
             if ($army != "") {
                 //18 character limit for trying to position this beast using $font
                 if (strlen($army) + strlen($playerName) + 3 > 18) {
                     //Use a smaller font.
                     $input_string = $army . $playerName;
                     //Draw the shadow
                     self::Image_Center_String($background, $small_font, -11, 34, 10, $input_string, $stroke_color);
                     self::Image_Center_String($background, $small_font, -9, 36, 10, $input_string, $stroke_color);
                     self::Image_Center_String($background, $small_font, -10, 35, 9, $input_string, $stroke_color);
                     self::Image_Center_String($background, $small_font, -10, 35, 11, $input_string, $stroke_color);
                     //Draw the string
                     self::Image_Center_String($background, $small_font, -10, 35, 10, $input_string, $text_color);
                 } else {
                     $input_string = $army . $playerName;
                     //Draw the shadow
                     self::Image_Center_String($background, $font, -11, 34, 10, $input_string, $stroke_color);
                     self::Image_Center_String($background, $font, -9, 36, 10, $input_string, $stroke_color);
                     self::Image_Center_String($background, $font, -10, 35, 9, $input_string, $stroke_color);
                     self::Image_Center_String($background, $font, -10, 35, 11, $input_string, $stroke_color);
                     //Draw the string
                     self::Image_Center_String($background, $font, -10, 35, 10, $input_string, $text_color);
                 }
             } else {
                 //No army name found
                 $input_string = $playerName;
                 //Draw the shadow
                 self::Image_Center_String($background, $font, -11, 34, 10, $input_string, $stroke_color);
                 self::Image_Center_String($background, $font, -9, 36, 10, $input_string, $stroke_color);
                 self::Image_Center_String($background, $font, -10, 35, 9, $input_string, $stroke_color);
                 self::Image_Center_String($background, $font, -10, 35, 11, $input_string, $stroke_color);
                 //Draw the string
                 self::Image_Center_String($background, $font, -10, 35, 10, $input_string, $text_color);
             }
             $input_string = $lifetime_xp . " XP";
             //Draw the shadow
             self::Image_Center_String($background, $font, 191, 201, 10, $input_string, $stroke_color);
             self::Image_Center_String($background, $font, 189, 198, 10, $input_string, $stroke_color);
             self::Image_Center_String($background, $font, 190, 200, 9, $input_string, $stroke_color);
             self::Image_Center_String($background, $font, 190, 200, 11, $input_string, $stroke_color);
             //Draw the string
             self::Image_Center_String($background, $font, 190, 200, 10, $input_string, $text_color);
             //Merge that overlay!
             self::imagecopymerge_alpha($background, $overlay, 0, 0, 0, 0, imagesx($background), imagesy($overlay), 65);
         }
         //END DEFAULT THEME
         imagesavealpha($background, true);
         //So we cant actually cache an image, but we can create a cache and use it as a timer to recreate the stored image
         Cache::put($player->db_id . '_sig_' . $frame_request, '1', 5);
         imagepng($background, 'storage/cache/sigs/' . $playerName . '_sig_' . $frame_request . '.png', 9);
         imagedestroy($background);
     }
     $image_path = 'storage/cache/sigs/' . $cache_key . '.png';
     $name = $cache_key . '.png';
     //Generate the response
     Response::make('', 200, array('Content-Type' => 'image/png', 'Content-Transfer-Encoding' => 'binary', 'Content-Disposition' => 'inline', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => filesize($image_path)))->send_headers();
     readfile($image_path);
     exit;
 }
示例#25
0
<?php

include_once '../../class/pattern/composite.php';
$archer = new Archer();
echo "archer attacking with strength: {$archer->bombardStrength()}" . "<br/>";
$main_army = new Army();
$main_army->addUnit($archer);
$main_army->addUnit(new Archer());
$main_army->addUnit(new LaserCannonUnit());
echo "main_army attacking with strength: {$main_army->bombardStrength()}" . "<br/>";
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new Cavalry());
$sub_army->addUnit(new Cavalry());
echo "sub_army attacking with strength: {$sub_army->bombardStrength()}" . "<br/>";
$main_army->addUnit($sub_army);
echo "main_army attacking with strength: {$main_army->bombardStrength()}" . "<br/>";
$troop = new TroopCarrier();
//$troop->addUnit(new Cavalry);
$troop->addUnit(new Archer());
$troop->addUnit(new Archer());
//$troop->addUnit(new Cavalry());
echo "troop attacking with strength: {$troop->bombardStrength()}" . "<br/>";
$main_army->addUnit($troop);
echo "attacking with strength: {$main_army->bombardStrength()}" . "<br/>";
?>


示例#26
0
    function removeUnit(Unit $unit)
    {
    }
    function bombardStrength()
    {
        return 4;
    }
}
class Soldier extends Unit
{
    function addUnit(Unit $unit)
    {
    }
    function removeUnit(Unit $unit)
    {
    }
    function bombardStrength()
    {
        return 8;
    }
}
$tank = new Tank();
$tank2 = new Tank();
$soldier = new Soldier();
$army = new Army();
$army->addUnit($soldier);
$army->addUnit($tank);
$army->addUnit($tank2);
print_r($army);
$army->removeUnit($tank2);
print_r($army);
示例#27
0
    protected $tile;
    function __construct(Tile $tile)
    {
        $this->tile = $tile;
    }
}
class DiamontDecorator extends TileDecorator
{
    function getWealthFactor()
    {
        return $this->tile->getWealthFactor() + 5;
    }
}
class PollutionDecorator extends TileDecorator
{
    function getWealthFactor()
    {
        return $this->tile->getWealthFactor() - 5;
    }
}
$tile = new Plains();
$pollution = new PollutionDecorator($tile);
print $pollution->getWealthFactor() . "\n";
$army = new Army();
$army->addUnit(new Archer());
$army->addUnit(new LaserCanonUnit());
$sub_army = new Army();
$sub_army->addUnit(new Archer());
$sub_army->addUnit(new LaserCanonUnit());
$army->addUnit($sub_army);
print "Атака всей армии составляет {$army->bombardStrength()}";
示例#28
0
    // Chargement du controller
    $controller = 'controllers/' . strtolower($page) . '.controller.php';
    $template = 'views/' . strtolower($page) . '.view.phtml';
    if (!file_exists($controller) || !file_exists($template)) {
        header("HTTP/1.1 404 Not Found");
        include 'views/404.phtml';
        die;
    }
} else {
    $template = 'views/maintenance.view.phtml';
}
// Mise à jour des données
if (User::isLogged()) {
    $user = new User($_SESSION['user']['id']);
    $queue = new Queue($user->id);
    $army = new Army($user->id);
    // mise à jour des ressources
    $user->update_ressources();
    // mise à jour des construction
    $queue->update_queue(get_time_diff($user->last_refresh));
    // résolution des combats
    foreach (Combat::get_arrived_troops() as $combat) {
        $combat = new Combat($combat['id']);
        $combat->solve_combats();
    }
    // mise à jour de l'armée (après les constructions et combats)
    $troops = $army->get_troops();
    // mise à jour de l'heure
    $user->update_value('last_refresh', date("Y-m-d H:i:s"));
}
if (!_MAINTENANCE_) {