Esempio n. 1
0
 public static function GetShipsOfColony(Colony $colony)
 {
     global $GR_missionDatabaseIDs;
     $id = $colony->ID();
     $query = "SELECT * FROM fleet WHERE colonyID = {$id} AND mission_type = 0 LIMIT 1;";
     $row = Database::Instance()->ExecuteQuery($query, "SELECT");
     return ShipFleet::FromDatabase($row, $colony);
 }
Esempio n. 2
0
 public function BuildCost(Colony $c, $buildLevel = NULL)
 {
     if ($buildLevel == NULL) {
         $buildLevel = $this->GetScheduledLevelsInDatabase() + $c->Buildings()->GetMemberByName($this->Name())->Amount();
     }
     $metalCost = floor($this->Cost()->Metal() * pow($this->NextcostModifier(), $buildLevel));
     $crystalCost = floor($this->Cost()->Crystal() * pow($this->NextcostModifier(), $buildLevel));
     $deuteriumCost = floor($this->Cost()->Deuterium() * pow($this->NextcostModifier(), $buildLevel));
     $energyCost = floor($this->Cost()->Energy() * pow($this->NextcostModifier(), $buildLevel));
     return new Cost($metalCost, $crystalCost, $deuteriumCost, $energyCost);
 }
Esempio n. 3
0
 public static function GetDefensesOfColony(Colony $colony)
 {
     $id = $colony->ID();
     $query = "SELECT * FROM colony_defences WHERE colonyID = {$id};";
     $row = Database::Instance()->ExecuteQuery($query, "SELECT");
     $row = array_slice($row, 1);
     // Get rid of colonyID
     // TODO: put these numbers in the config files or game resources,
     // otherwise when you add a new weapon you need to change all these.
     $row = array_slice($row, 0, 8);
     // Get rid of missiles
     return CombatGroup::FromList($row, $colony);
 }
Esempio n. 4
0
 public function BuildTime(Colony $colony)
 {
     // Calculate time required
     global $NN_config;
     $metalCost = $this->Cost()->Metal();
     $crystalCost = $this->Cost()->Crystal();
     $gameSpeed =& $NN_config["game_speed"];
     $shipyards = $colony->Buildings()->GetMemberByName("shipyard")->Amount();
     $nanoFactories = $colony->Buildings()->GetMemberByName("nano_factory")->Amount();
     $defenders = $colony->Owner()->Officers()->GetMemberByName("defender")->Amount();
     $timeRequired = ($metalCost + $crystalCost) / $gameSpeed * (1 / ($shipyards + 1)) * pow(0.5, $nanoFactories);
     $timeRequired = floor($timeRequired * 3600 * (1 - $defenders * 0.375));
     return $timeRequired;
 }
Esempio n. 5
0
 public function BuildTime(Colony $colony, Cost $buildCosts)
 {
     // Calculate time required
     global $NN_config;
     $metalCost =& $buildCosts->Metal();
     $crystalCost =& $buildCosts->Crystal();
     $gameSpeed =& $NN_config["game_speed"];
     $robotFactories = $colony->Buildings()->GetMemberByName("robotics_factory")->Amount();
     $nanoFactories = $colony->Buildings()->GetMemberByName("nano_factory")->Amount();
     $manufacturers = $colony->Owner()->Officers()->GetMemberByName("manufacturer")->Amount();
     $timeRequired = ($metalCost + $crystalCost) / $gameSpeed * (1 / ($robotFactories + 1)) * pow(0.5, $nanoFactories);
     $timeRequired = floor($timeRequired * 3600 * (1 - $manufacturers * 0.1));
     return $timeRequired;
 }
Esempio n. 6
0
 public static function FromDatabaseByColony(Colony $colony)
 {
     $id = $colony->ID();
     $query = "SELECT * FROM colony_structures WHERE colonyID = {$id};";
     $row = Database::Instance()->ExecuteQuery($query, "SELECT");
     $row = array_slice($row, 1);
     // Dump the colonyID
     $productionUnitsRow = array_slice($row, 0, 5);
     // TODO: put solar sats here?
     $buildingsRow = array_slice($row, 5);
     $productionUnits = BuildingGroup::FromDatabase($productionUnitsRow, $colony);
     $buildings = BuildingGroup::FromDatabase($buildingsRow, $colony);
     return array($productionUnits, $buildings);
 }
Esempio n. 7
0
 private function RenderRowOfColony(Colony $c)
 {
     $positionData = array("tabindex" => $c->Coordinates()->Planet() + 1, "planet_position" => $c->Coordinates()->Planet());
     $planetImage['planet_image'] = $c->PlanetData()->Image();
     $nameData = $this->GetPlanetNameDataOfColony($c);
     $moonImage['moon_image'] = $c->PlanetData()->Image();
     // TODO: PLACEHOLDER, put actual moon image here
     $debrisData['debris'] = "Debris";
     // TODO: PLACEHOLDER
     $ownerData['owner'] = $c->Owner()->Username();
     // TODO: PLACEHOLDER
     $allianceData['alliance'] = "Alliance";
     // TODO: PLACEHOLDER
     $actionData['actions'] = "Actions";
     // TODO: PLACEHOLDER, implement PMs and alliances and buddies before doing this
     $vars = array_merge($positionData, $planetImage, $nameData, $moonImage, $debrisData, $ownerData, $allianceData, $actionData);
     return Page::StaticRender("galaxy/galaxy_row", $vars, $this->_user->AuthorisationLevelName());
 }
 public static function FromDatabase(array $row, Colony $colony = NULL)
 {
     $transport = new Transportation();
     $fleet = ShipFleet::FromDatabaseByID($row['fleetID']);
     $transport->Fleet($fleet);
     $transport->ID($row['transportID']);
     if ($colony === NULL) {
         $colony = Colony::FromDatabaseByID($row['colonyID'], User::GetCurrentUser());
     }
     $transport->ReceivingColony($colony);
     $transport->ScheduledTime($row['scheduled_time']);
     $transport->IsValid(true);
     // Anything that gets into the database is valid.
     return $transport;
 }
 public function send_cupon($id)
 {
     $promo = Promo::where('id', '=', $id)->first();
     $user_id = AssigmentRoleHab::where('role_id', '=', 2)->where('colony_id', '=', $promo->colony_id)->pluck('user_id');
     $admin_user = DB::connection('habitaria_dev')->select('select email from users where id = ? ', [$user_id]);
     foreach ($admin_user as $user) {
         $admin_email = $user->email;
     }
     $admin_neighbor = Neighbors::where('user_id', '=', $user_id)->first();
     $colony_data = Colony::where('id', '=', $promo->colony_id)->first();
     $colony_name = $colony_data->name;
     $data = array('email' => $admin_email, 'days' => $promo->days, 'code' => Crypt::decrypt($promo->code), 'colony' => $colony_name, 'admin' => $admin_neighbor->name . ' ' . $admin_neighbor->last_name);
     Mail::send('emails.cupon_promo', $data, function ($message) use($admin_email) {
         $message->subject('Promo de HABITARIA');
         $message->to($admin_email);
     });
     $notice_msg = 'Promo enviada al administrador de la Colonia: ' . $colony_name;
     return Redirect::back()->with('error', false)->with('msg', $notice_msg)->with('class', 'info');
 }
 public function cambiarPermisos()
 {
     /*$id = Input::get("id");
     		$state = Input::get("state");*/
     $colonia = Session::get("colonia");
     $coloniaName = Colony::find($colonia);
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $datos = (string) Input::get("datos");
     $rol = Input::get('rol');
     $array = explode(",", $datos);
     $num = count($array);
     for ($i = 0; $i < $num; $i++) {
         $permisos = explode(".", $array[$i]);
         $id = (int) $permisos[0];
         $estado = (int) $permisos[1];
         $permiso = PermissionRole::find($id);
         $permiso->state = $estado;
         $permiso->save();
     }
     // $permiso = PermissionRole::find($id);
     // $permiso->state = $state;
     // $permiso->save();
     return Response::json(array("estado" => 1));
 }
 public static function GetListCount(Colony $c)
 {
     $id = $c->ID();
     $query = "SELECT COUNT(colonyID) as count FROM production_building WHERE colonyID = {$id};";
     $result = Database::Instance()->ExecuteQuery($query, "SELECT");
     if ($result == NULL) {
         $count = 0;
     } else {
         $count = $result['count'];
     }
 }
Esempio n. 12
0
 public function FullfillsPrerequisites(Colony $c)
 {
     if ($this->Prerequisite() == NULL) {
         return true;
     }
     foreach ($this->Prerequisite() as $prerequisite) {
         $prereqName = $prerequisite->Item()->Name();
         $prereqAmount = $prerequisite->Amount();
         $colonyAmount = $c->SearchForPrerequisite($prereqName)->Amount();
         if ($prereqAmount > $colonyAmount) {
             return false;
         }
     }
     return true;
 }
Esempio n. 13
0
 public function Trader(Colony $c)
 {
     $this->_colony = $c;
     // Include language files for trader page, useful to put error messages there.
     $this->_text =& $c->Owner()->Language()->GetFilesByPage("trader");
 }
Esempio n. 14
0
 public function ThinkForColony($colonyID)
 {
     $colony = Colony::FromDatabaseByID($colonyID);
     $this->ConstructUnitsOf($colony);
 }
 public function store_register_neighbors()
 {
     $post = Input::All();
     $urbanismNeigh = Input::get('urbanism');
     $neighbor = new Neighbors();
     $neighbor->user_id = Input::get('user_id');
     //$neighbor->urbanism_id =  Input::get('urbanism');
     $neighbor->name = Input::get('firstname');
     $neighbor->last_name = Input::get('lastname');
     $neighbor->phone = Input::get('phone');
     $neighbor->save();
     $last_neighbor_add = $neighbor->id;
     $urbanism_type = Input::get('urbanism_type');
     $neighbor_properties = new NeighborProperty();
     $neighbor_properties->neighbors_id = $last_neighbor_add;
     $neighbor_properties->urbanism_id = Input::get('urbanism');
     if ($urbanism_type == 3) {
         $neighbor_properties->num_floor_id = Input::get('name_floor');
     } else {
         $neighbor_properties->num_street_id = Input::get('name_street');
     }
     $neighbor_properties->num_house_or_apartment = Input::get('num_house_or_apartment');
     if ($neighbor_properties->save()) {
         $role = Role::where('name', '=', 'vecino')->first();
         $colony = Urbanism::where('id', '=', Input::get('urbanism'))->pluck('colony_id');
         $rol = new AssigmentRole();
         $rol->user_id = Input::get('user_id');
         $rol->role_id = $role->id;
         $rol->colony_id = $colony;
         $rol->save();
     }
     $colonies = Colony::select('colonies.id')->join('urbanisms', 'urbanisms.colony_id', '=', 'colonies.id')->join('neighbors_properties', 'urbanisms.id', '=', 'neighbors_properties.urbanism_id')->where('neighbors_properties.urbanism_id', '=', $urbanismNeigh)->first();
     $user = Neighbors::where('id', '=', $last_neighbor_add)->pluck('user_id');
     $user_auth = User::where('id', '=', $user)->first();
     Auth::login($user_auth);
     if (Auth::check()) {
         Session::put('colonia', $colonies->id);
         return Redirect::action('HomeController@index');
     } else {
         return Redirect::action('UsersController@login');
     }
 }
Esempio n. 16
0
require_once "common.php";
Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_defences", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_properties", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_resources", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE colony_structures", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE fleet", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE user", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE production", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE user_officers", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE user_technology", NULL);
Database::Instance()->ExecuteQuery("TRUNCATE TABLE scheduled_transports", NULL);
Database::Instance()->SetDebugging(true);
$user = User::NewUser("Beerdude26", "aSimplePassword", 100, "Beerdude26@gmail.com", "alternate_email");
$colony = Colony::NewColony("Nigron", new Coordinates(100, 50, 7), $user, FALSE);
Colony::AddToDatabase($colony);
echo "<br/>";
echo "<br/>";
echo "Current colony:";
Helper::var_dump_pre($user->CurrentColony()->ID());
$units = array("light_fighter" => 10, "small_cargo_ship" => 20, "cruiser" => 10);
$extrafleet = ShipFleet::FromList($units, $user->CurrentColony(), 0);
//Helper::var_dump_pre( $user->CurrentColony()->Fleet() );
echo "Adding some extra units to original fleet: ";
$user->CurrentColony()->Fleet()->AddToFleet($extrafleet);
$user->CurrentColony()->Fleet()->UpdateDatabase();
$t_units = array("light_fighter" => 5, "small_cargo_ship" => 5, "cruiser" => 3);
$t_fleet = ShipFleet::FromList($t_units, $user->CurrentColony(), 0);
echo "Splitting up some units from the original fleet: ";
$fleets = $user->CurrentColony()->Fleet()->SplitFleet($t_fleet);
// Let's send a part of the fleet on a transport mission
 public function sendEmails()
 {
     $colonia = Session::get("colonia");
     $coloniaName = Colony::find($colonia);
     $urbanism = Urbanism::where('colony_id', '=', $colonia)->first();
     $state = State::where('id', $coloniaName->City->state_id)->first()->name;
     $ciudad = $coloniaName->City->name;
     $contenido = Input::get('contenido');
     $user_id = Input::get('email');
     $asunto = Input::get('asunto');
     $admin_colonia = Neighbors::where('user_id', '=', Auth::user()->id)->first();
     $optGroup = Input::get('optGroup');
     if ($user_id == 'Todos' && $optGroup == NULL) {
         $neighbors = NeighborProperty::with('Neighbors')->where('urbanism_id', '=', $urbanism->id)->where('neighbors_id', '!=', $admin_colonia->id)->get();
         foreach ($neighbors as $neighbor) {
             $email = $neighbor->Neighbors->User->email;
             $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad);
             Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) {
                 $message->subject($asunto);
                 $message->to($email);
             });
         }
     }
     if ($optGroup == 'Vecinos') {
         $email = User::findOrFail($user_id)->email;
         $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad);
         Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) {
             $message->subject($asunto);
             $message->to($email);
         });
     }
     if ($optGroup == 'Roles') {
         $neighbors = NeighborProperty::join('neighbors', 'neighbors.id', '=', 'neighbors_properties.neighbors_id')->join('assigned_roles', 'neighbors.user_id', '=', 'assigned_roles.user_id')->where('assigned_roles.colony_id', '=', $colonia)->where('urbanism_id', '=', $urbanism->id)->where('assigned_roles.role_id', '=', $user_id)->get();
         foreach ($neighbors as $neighbor) {
             $email = $neighbor->Neighbors->User->email;
             $data = array('email' => $email, 'link' => 'ConfirmationController@confirm', 'code' => "jhhjdhsdhhdsjhdsh", 'name_inv' => $admin_colonia->name, 'lname_inv' => $admin_colonia->last_name, 'urbanism' => $urbanism->name, 'contenido' => $contenido, 'asunto' => $asunto, 'coloniaName' => $coloniaName, 'estado' => $state, 'ciudad' => $ciudad);
             Mail::send('emails.email_masivos', $data, function ($message) use($email, $asunto) {
                 $message->subject($asunto);
                 $message->to($email);
             });
         }
     }
 }
Esempio n. 18
0
 public function Equals(self $other)
 {
     if ($this->ID() == $other->ID()) {
         return true;
     }
     return false;
 }
Esempio n. 19
0
 public static function FromDatabase($row, Colony $c = NULL)
 {
     $user = new User();
     $user->ID($row['ID']);
     $user->Username($row['username']);
     $user->AuthorisationLevel(Database::Instance()->ExecuteQuery("SELECT * FROM authorisation WHERE ID = " . (int) $row['authorisationID'] . ";", "SELECT"));
     $user->PrimaryEmail($row['primary_email']);
     $user->SecondaryEmail($row['secondary_email']);
     $user->RegistrationTime($row['registration_time']);
     $user->LastOnline($row['last_online']);
     $user->IsBanned($row['is_banned']);
     $user->BannedUntil($row['banned_until']);
     // Load authorisation level name
     $levelNameRow = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = " . $user->AuthorisationLevel() . ";", "SELECT");
     $user->AuthorisationLevelName($levelNameRow['name']);
     // Load home colony
     if ($c == NULL) {
         $colonyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM colony WHERE userID = " . $user->ID() . " AND is_home_colony = 1", "SELECT");
         $user->CurrentColony(Colony::FromDatabase($colonyDatabaseRow, $user));
     } else {
         $user->CurrentColony($c);
     }
     // Load user's technologies
     $technologyDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_technology WHERE userID = " . $user->ID(), "SELECT");
     $user->Technologies(TechnologyGroup::FromDatabase($technologyDatabaseRow, $user));
     // Load user's officers
     $officerDatabaseRow = Database::Instance()->ExecuteQuery("SELECT * FROM user_officers WHERE userID = " . $user->ID(), "SELECT");
     $user->Officers(OfficerGroup::FromDatabase($officerDatabaseRow, $user));
     // Return user
     return $user;
 }
Esempio n. 20
0
 public function GetBuildLevelOnColony(Colony $c)
 {
     return $c->Ships()->GetMemberByName($this->Name())->Amount();
 }