<commit_before><?php
require_once(LIB . 'Default/shop_goods.inc');

// creates needed objects
$amount = get_amount();
$bargain_price = get_bargain_price();

if (!is_numeric($amount) || !is_numeric($bargain_price))
	create_error('Numbers only please!');
// get good name, id, ...
$good_id = $var['good_id'];
$good_name = Globals::getGoodName($good_id);

// do we have enough turns?
if ($player->getTurns() == 0)
	create_error('You don\'t have enough turns to trade.');

$sector =& $player->getSector();
// get rid of those bugs when we die...there is no port at the home sector
if (!$sector->hasPort())
	create_error('I can\'t see a port in this sector. Can you?');
$port =& $sector->getPort();

// check if the player has the right relations to trade at the current port
if ($player->getRelation($port->getRaceID()) < RELATIONS_WAR)
	create_error('This port refuses to trade with you because you are at <big><span class="bold red">WAR!</span></big>');

// does the port actually buy or sell this good?
$transaction = $port->getGoodTransaction($good_id);
if (empty($transaction))
	create_error('I don\'t trade in that good.');

$portGood = $port->getGood($good_id);
// check if there are enough left at port
if ($port->getGoodAmount($good_id) < $amount)
	create_error('I\'m short of '.$good_name.'. So I\'m not going to sell you '.$amount.' pcs.');

// does we have what we are going to sell?
if ($transaction == 'Sell' && $amount > $ship->getCargo($good_id))
	create_error('Scanning your ships indicates you don\'t have '.$amount.' pcs. of '.$good_name.'!');

// check if we have enough room for the thing we are going to buy
if ($transaction == 'Buy' && $amount > $ship->getEmptyHolds())
	create_error('Scanning your ships indicates you don\'t have enough free cargo bays!');

// check if the guy has enough money
if ($transaction == 'Buy' && $player->getCredits() < $bargain_price)
	create_error('You don\'t have enough credits!');

// get relations for us (global + personal)
$relations = $player->getRelation($port->getRaceID());

if (!isset($var['ideal_price'])) SmrSession::updateVar('ideal_price',$port->getIdealPrice($good_id, $transaction, $amount, $relations));
$ideal_price = $var['ideal_price'];

if (!isset($var['offered_price'])) SmrSession::updateVar('offered_price',$port->getOfferPrice($ideal_price, $relations, $transaction));
$offered_price = $var['offered_price'];

// nothing should happen here but just to avoid / by 0
if ($ideal_price == 0 || $offered_price == 0)
	create_error('Port calculation error...buy more goods.');

if ($_REQUEST['action'] == 'Steal') {
	if (!$ship->isUnderground()) {
		create_error('You are not allowed to steal goods!');
	}
	$transaction = $_REQUEST['action'];
}
<commit_msg>Add small chance to get caught stealing goods<commit_after><?php
require_once(LIB . 'Default/shop_goods.inc');

// creates needed objects
$amount = get_amount();
$bargain_price = get_bargain_price();

if (!is_numeric($amount) || !is_numeric($bargain_price))
	create_error('Numbers only please!');
// get good name, id, ...
$good_id = $var['good_id'];
$good_name = Globals::getGoodName($good_id);

// do we have enough turns?
if ($player->getTurns() == 0)
	create_error('You don\'t have enough turns to trade.');

$sector =& $player->getSector();
// get rid of those bugs when we die...there is no port at the home sector
if (!$sector->hasPort())
	create_error('I can\'t see a port in this sector. Can you?');
$port =& $sector->getPort();

// check if the player has the right relations to trade at the current port
if ($player->getRelation($port->getRaceID()) < RELATIONS_WAR)
	create_error('This port refuses to trade with you because you are at <big><span class="bold red">WAR!</span></big>');

// does the port actually buy or sell this good?
$transaction = $port->getGoodTransaction($good_id);
if (empty($transaction))
	create_error('I don\'t trade in that good.');

$portGood = $port->getGood($good_id);
// check if there are enough left at port
if ($port->getGoodAmount($good_id) < $amount)
	create_error('I\'m short of '.$good_name.'. So I\'m not going to sell you '.$amount.' pcs.');

// does we have what we are going to sell?
if ($transaction == 'Sell' && $amount > $ship->getCargo($good_id))
	create_error('Scanning your ships indicates you don\'t have '.$amount.' pcs. of '.$good_name.'!');

// check if we have enough room for the thing we are going to buy
if ($transaction == 'Buy' && $amount > $ship->getEmptyHolds())
	create_error('Scanning your ships indicates you don\'t have enough free cargo bays!');

// check if the guy has enough money
if ($transaction == 'Buy' && $player->getCredits() < $bargain_price)
	create_error('You don\'t have enough credits!');

// get relations for us (global + personal)
$relations = $player->getRelation($port->getRaceID());

if (!isset($var['ideal_price'])) SmrSession::updateVar('ideal_price',$port->getIdealPrice($good_id, $transaction, $amount, $relations));
$ideal_price = $var['ideal_price'];

if (!isset($var['offered_price'])) SmrSession::updateVar('offered_price',$port->getOfferPrice($ideal_price, $relations, $transaction));
$offered_price = $var['offered_price'];

// nothing should happen here but just to avoid / by 0
if ($ideal_price == 0 || $offered_price == 0)
	create_error('Port calculation error...buy more goods.');

if ($_REQUEST['action'] == 'Steal') {
	if (!$ship->isUnderground()) {
		create_error('You are not allowed to steal goods!');
	}
	$transaction = $_REQUEST['action'];

	// Small chance to get caught stealing
	$catchChancePercent = $port->getMaxLevel() - $port->getLevel() + 1;
	if (rand(1, 100) <= $catchChancePercent) {
		$fine = $ideal_price * ($port->getLevel() + 1);
		// Don't take the trader all the way to 0 credits
		$newCredits = max(5000, $player->getCredits() - $fine);
		$player->setCredits($newCredits);
		$player->decreaseAlignment(5);

		$fineMessage = '<span class="red">A Federation patrol caught you loading stolen goods onto your ship!<br />The stolen goods have been confiscated and you have been fined '.number_format($fine).' credits.</span><br /><br />';
		$container = create_container('skeleton.php', 'shop_goods.php');
		$container['trade_msg'] = $fineMessage;
		forward($container);
	}
}

{'fraction_non_alphanumeric': 0.17046548956661317, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 5.212362911266202, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7473813', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1979, 'n_words': 624}