Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #142 from mys/master
Browse files Browse the repository at this point in the history
Expedition mission enhancements
  • Loading branch information
mys authored Apr 29, 2018
2 parents cb181fc + 98ce413 commit 35b5509
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 135 deletions.
245 changes: 120 additions & 125 deletions includes/classes/missions/MissionCaseExpedition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function EndStayEvent()

$config = Config::get($this->_fleet['fleet_universe']);

$expeditionPoints = array();
$expeditionPoints = array();

foreach($reslist['fleet'] as $shipId)
{
Expand All @@ -55,9 +55,44 @@ function EndStayEvent()
$fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal']
+ $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];

// Get Expeditions count in this system
$sql = "SELECT COUNT(*) AS total FROM %%LOG_FLEETS%% where `fleet_end_galaxy` = :fleet_end_galaxy and `fleet_end_system` = :fleet_end_system and `fleet_end_planet` = :fleet_end_planet and `fleet_end_stay` > UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)";

$expeditionsCount = Database::get()->selectSingle($sql, array(
'fleet_end_galaxy' => $this->_fleet['fleet_end_galaxy'],
'fleet_end_system' => $this->_fleet['fleet_end_system'],
'fleet_end_planet' => $this->_fleet['fleet_end_planet']
), 'total');

// Hold time bonus
$holdTime = ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) / 3600;

$GetEvent = mt_rand(0, 1000);
$GetEvent -= $holdTime * 10;

$Message = $LNG['sys_expe_nothing_'.mt_rand(1,8)];

// Depletion check
if ($expeditionsCount <= 10) {
$chanceDepleted = 0;
$logbook = $LNG['sys_expe_depleted_not_'.mt_rand(1,2)];
}
else if ($expeditionsCount <= 25) {
$chanceDepleted = 25;
$logbook = $LNG['sys_expe_depleted_min_'.mt_rand(1,3)];
}
else if ($expeditionsCount <= 50) {
$chanceDepleted = 50;
$logbook = $LNG['sys_expe_depleted_med_'.mt_rand(1,3)];
}
else {
$chanceDepleted = 75;
$logbook = $LNG['sys_expe_depleted_max_'.mt_rand(1,3)];
}

$Message = $LNG['sys_expe_nothing_'.mt_rand(1,8)];
$depleted = mt_rand(0, 100);
if ($depleted < $chanceDepleted)
$GetEvent = 1000; // nothing happens

// Find resources: 32,5%. Values from http://owiki.de/Expedition
if ($GetEvent < 325)
Expand Down Expand Up @@ -141,9 +176,11 @@ function EndStayEvent()
$maxFactor = 2400;
}

//$founded = round(min($fleetCapacity,min($maxFactor, max(200, $factor)) * $fleetPoints));
$founded = min($factor * max(min($fleetPoints, $maxFactor), 200), $fleetCapacity);

if ($fleetPoints < $maxFactor)
$logbook = $LNG['sys_expe_found_ress_logbook_'.mt_rand(1,4)].'<br>'.$logbook;

$fleetColName = 'fleet_resource_'.$resource[$resourceId];
$this->UpdateFleet($fleetColName, $this->_fleet[$fleetColName] + $founded);
}
Expand Down Expand Up @@ -173,7 +210,7 @@ function EndStayEvent()
$this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
}

// Find abandoned ships: 22%. Valuels from http://owiki.de/Expedition , took 80% data.
// Find abandoned ships: 22%. Values from http://owiki.de/Expedition
elseif ($GetEvent < 635)
{
$eventSize = mt_rand(0, 100);
Expand Down Expand Up @@ -204,7 +241,6 @@ function EndStayEvent()
':universe' => $this->_fleet['fleet_universe']
), 'total');

//$MaxPoints = ($topPoints < 5000000) ? 4500 : 6000;
if($topPoints > 100000000)
{
$MaxPoints = 12500;
Expand Down Expand Up @@ -239,113 +275,70 @@ function EndStayEvent()
}

$FoundShips = max(round($Size * min($fleetPoints, $MaxPoints)), 10000);

if ($fleetPoints < $MaxPoints)
$logbook = $LNG['sys_expe_found_ships_logbook_'.mt_rand(1,3)].'<br>'.$logbook;

$FoundShipMess = "";
$NewFleetArray = "";

$findableShips[210] = [210, 202]; # SS
$findableShips[202] = [210, 202, 204]; # light cargo
$findableShips[204] = [210, 202, 204, 203]; # light fighter
$findableShips[203] = [210, 202, 204, 203, 205]; # heavy cargo
$findableShips[205] = [210, 202, 204, 203, 205, 206]; # heavy fighter
$findableShips[206] = [210, 202, 204, 203, 205, 206, 207]; # cruiser
$findableShips[207] = [210, 202, 204, 203, 205, 206, 207, 215]; # battleship
$findableShips[215] = [210, 202, 204, 203, 205, 206, 207, 215, 211]; # battle cruiser
$findableShips[211] = [210, 202, 204, 203, 205, 206, 207, 215, 211, 213]; # planet bomber
$findableShips[213] = [210, 202, 204, 203, 205, 206, 207, 215, 211, 213]; # destroyer

$highestShipId = 0;
if (array_key_exists(210, $fleetArray))
$highestShipId = 210;
if (array_key_exists(202, $fleetArray))
$highestShipId = 202;
if (array_key_exists(204, $fleetArray))
$highestShipId = 204;
if (array_key_exists(203, $fleetArray))
$highestShipId = 203;
if (array_key_exists(205, $fleetArray))
$highestShipId = 205;
if (array_key_exists(206, $fleetArray))
$highestShipId = 206;
if (array_key_exists(207, $fleetArray))
$highestShipId = 207;
if (array_key_exists(215, $fleetArray))
$highestShipId = 215;
if (array_key_exists(211, $fleetArray))
$highestShipId = 211;
if (array_key_exists(213, $fleetArray))
$highestShipId = 213;

$Found = array();
foreach($reslist['fleet'] as $ID)
$upperValue = 3;
while($highestShipId > 0 && $upperValue > 0)
{
// not a colony ship/recycler/death star
if($ID == 208 || $ID == 209 || $ID == 214)
continue;

$Findable = False;
foreach($fleetArray as $fleetID => $Count)
$ID = $findableShips[$highestShipId][rand(0, count($findableShips[$highestShipId])-1)];
$MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]));
if($MaxFound <= 0)
{
if ($fleetID == 210) # spy probe in a fleet
{
if ($ID == 210 || $ID == 202) # <- foundable
{
$Findable = True;
break;
}
}
elseif ($fleetID == 202) # light cargo
{
if ($ID == 210 || $ID == 202 || $ID == 204)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 204) # light fighter
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 203) # heavy cargo
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 205) # heavy fighter
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205 || $ID == 206)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 206) # cruiser
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205 || $ID == 206 || $ID == 207)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 207) # battleship
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205 || $ID == 206 || $ID == 207 || $ID == 215)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 215) # battle cruiser
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205 || $ID == 206 || $ID == 207 || $ID == 215 || $ID == 211)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 211) # planet bomber
{
if ($ID == 210 || $ID == 202 || $ID == 204 || $ID == 203 || $ID == 205 || $ID == 206 || $ID == 207 || $ID == 215 || $ID == 211 || $ID == 213)
{
$Findable = True;
break;
}
}
elseif ($fleetID == 213) # destroyer
{
$Findable = True;
break;
}
}

if (!$Findable)
continue;

$MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]));
if($MaxFound <= 0)
$upperValue -= 1;
continue;

$Count = mt_rand(0, $MaxFound);
if($Count <= 0)
}

$Count = mt_rand(0, $MaxFound);
if($Count <= 0)
{
$upperValue -= 1;
continue;

$Found[$ID] = $Count;
$FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]);
$FoundShipMess .= '<br>'.$LNG['tech'][$ID].': '.pretty_number($Count);
}

if(array_key_exists($ID, $Found))
$Found[$ID] += $Count;
else
$Found[$ID] = $Count;
$FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]);
if($FoundShips <= 0)
break;
}
Expand All @@ -360,6 +353,7 @@ function EndStayEvent()
if(!empty($Found[$ID]))
{
$Count += $Found[$ID];
$FoundShipMess .= '<br>'.$LNG['tech'][$ID].': '.pretty_number($Count);
}
if(!empty($fleetArray[$ID]))
{
Expand All @@ -372,7 +366,7 @@ function EndStayEvent()
}
}

$Message .= $FoundShipMess;
$Message .= $FoundShipMess;

$this->UpdateFleet('fleet_array', $NewFleetArray);
$this->UpdateFleet('fleet_amount', array_sum($fleetArray));
Expand Down Expand Up @@ -409,6 +403,7 @@ function EndStayEvent()

$targetFleetData = array();

// pirates
if($attackType == 1)
{
$techBonus = -3;
Expand All @@ -434,7 +429,7 @@ function EndStayEvent()
$targetFleetData[207] = 2;
}
}
else
else // aliens
{
$techBonus = 3;
$targetName = $LNG['sys_expe_attackname_2'];
Expand All @@ -444,7 +439,7 @@ function EndStayEvent()
{
$Message = $LNG['sys_expe_attack_1_1_5'];
$attackFactor = (40 + mt_rand(-4, 4)) / 100;
$targetFleetData[204] = 5;
$targetFleetData[205] = 5;
}
elseif(0 < $eventSize && 10 >= $eventSize)
{
Expand All @@ -459,15 +454,15 @@ function EndStayEvent()
$targetFleetData[213] = 2;
}
}

foreach($fleetArray as $shipId => $shipAmount)
{
if(isset($targetFleetData[$shipId]))
if(!isset($targetFleetData[$shipId]))
{
$targetFleetData[$shipId] = 0;
$targetFleetData[$shipId] = 0;
}

$targetFleetData[$shipId] = $roundFunction($shipAmount * $attackFactor);
$targetFleetData[$shipId] += $roundFunction($shipAmount * $attackFactor);
}

$targetFleetData = array_filter($targetFleetData);
Expand All @@ -481,9 +476,9 @@ function EndStayEvent()
$targetData = array(
'id' => 0,
'username' => $targetName,
'military_tech' => min($senderData['military_tech'] + $techBonus, 0),
'defence_tech' => min($senderData['defence_tech'] + $techBonus, 0),
'shield_tech' => min($senderData['shield_tech'] + $techBonus, 0),
'military_tech' => max($senderData['military_tech'] + $techBonus, 0),
'defence_tech' => max($senderData['defence_tech'] + $techBonus, 0),
'shield_tech' => max($senderData['shield_tech'] + $techBonus, 0),
'rpg_amiral' => 0,
'dm_defensive' => 0,
'dm_attack' => 0
Expand Down Expand Up @@ -539,6 +534,7 @@ function EndStayEvent()
{
$this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1));
$this->UpdateFleet('fleet_amount', $totalCount);
$fleetArray = FleetFunctions::unserialize($fleetArray);
}

require_once('includes/classes/missions/functions/GenerateReport.php');
Expand Down Expand Up @@ -653,33 +649,32 @@ function EndStayEvent()
$Wrapper[] = 3;
$Wrapper[] = 3;
$Wrapper[] = 5;


$normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'];
$stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time'];
$factor = $Wrapper[mt_rand(0, 9)];

if($chance < 75)
{
// More return time

$normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'];
$stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time'];
$factor = $Wrapper[mt_rand(0, 9)];

$endTime = $this->_fleet['fleet_end_stay'] + $normalBackTime + $stayTime + $factor;
$endTime = $this->_fleet['fleet_end_stay'] + $normalBackTime + $stayTime * $factor;
$this->UpdateFleet('fleet_end_time', $endTime);
$Message = $LNG['sys_expe_time_slow_'.mt_rand(1,6)];
}
else
{
$normalBackTime = $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'];
$stayTime = $this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time'];
$factor = $Wrapper[mt_rand(0, 9)];

$endTime = max(1, $normalBackTime - $stayTime / 3 * $factor);
// Less return time
$endTime = $this->_fleet['fleet_end_stay'] + max(1, $normalBackTime - $stayTime / 3 * $factor);
$this->UpdateFleet('fleet_end_time', $endTime);
$Message = $LNG['sys_expe_time_fast_'.mt_rand(1,3)];
}
}

// else
// Find nothing: 18,8%...

if(isset($fleetArray[210]))
$Message .= '<br><br>'.$logbook;

PlayerUtil::sendMessage($this->_fleet['fleet_owner'], 0, $LNG['sys_mess_tower'], 15,
$LNG['sys_expe_report'], $Message, $this->_fleet['fleet_end_stay'], NULL, 1, $this->_fleet['fleet_universe']);
Expand Down
Loading

0 comments on commit 35b5509

Please sign in to comment.