Steemnova: Marketplace history and bugfixes
Market history
Marketplace is a very useful feature in the game. Every user can create offers and wait for the customer. But it is always difficult to find the real value of the resources. Some offers are on the market many days and fleet goes back with nothing. Ratio of the resources changes in the game all the time, but what is actual value?
The solution is simple. History of the transactions. If offer has bought it is possible that similar one also.
Implementation
It is one of the smallest features which I made for steemnova so I will try to describe it accurately.
The first step was to create a new function in the ShowMarketPlacePage.class.php which will return the data from the database.
+ private function getTradeHistory() {
+ $db = Database::get();
Database::get returns object of the database to run query.
+ $sql = 'SELECT
+ seller_u.username as seller,
+ buyer_u.username as buyer,
+ buy_time as time,
+ ex_resource_type as type,
+ ex_resource_amount as amount,
+ seller.fleet_resource_metal as metal,
+ seller.fleet_resource_crystal as crystal,
+ seller.fleet_resource_deuterium as deuterium
+ FROM %%TRADES%%
+ JOIN %%LOG_FLEETS%% seller ON seller.fleet_id = seller_fleet_id
+ JOIN %%LOG_FLEETS%% buyer ON buyer.fleet_id = buyer_fleet_id
+ JOIN %%USERS%% buyer_u ON buyer_u.id = buyer.fleet_owner
+ JOIN %%USERS%% seller_u ON seller_u.id = seller.fleet_owner
+ WHERE transaction_type = 0 ORDER BY time DESC LIMIT 40;';
This query return the last 40 transactions. JOIN is used to get the buyer and seller name. Change has been merged without the names because players wanted this solution first. But I plan to create a special setting in the administration panel to give possibility of changing it. That's why still old query is used.
+ $trades = $db->select($sql, array(
+ ));
+ return $trades;
+ }
$db->sekect runs query and returns the results. Result goes to the template:
$this->assign(array(
'message' => $message,
'FlyingFleetList' => $FlyingFleetList,
+ 'history' => $this->getTradeHistory(),
));
$this->tplObj->loadscript('marketplace.js');
$this->display('page.marketPlace.default.tpl');
And in template new table has been created.
+<table id="historyList" style="width:50%;white-space: nowrap;" class="tablesorter">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>{$LNG.tkb_datum}</th>
+ <th>{$LNG['tech'][901]}</th>
+ <th>{$LNG['tech'][902]}</th>
+ <th>{$LNG['tech'][903]}</th>
+ <th class="no-background no-border center">-></th>
+ <th>{$LNG.market_p_cost_amount}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach name=History item=row from=$history}
+ <tr>
+ <td>{$smarty.foreach.History.iteration}</td>
+ <td>{$row.time}</td>
+ <td>{$row.metal}</td>
+ <td>{$row.crystal}</td>
+ <td>{$row.deuterium}</td>
+ <td class="no-background no-border center">
+ {if $row.type == 1}<img src="./styles/theme/nova/images/metal.gif"/>
+ {elseif $row.type == 2}<img src="./styles/theme/nova/images/crystal.gif"/>
+ {elseif $row.type == 3}<img src="./styles/theme/nova/images/deuterium.gif"/>{/if}</td>
+ <td>{$row.amount}</td>
+ </tr>
+ {/foreach}
+ </tbody>
+</table>
Bugfix: No diplo
This bug happens if someone is in alliance but without packts:
Solution
Fix is simple. If no diplomatic level found, use the null value.
includes/pages/game/ShowMarketPlacePage.class.php
@@ -100,7 +100,11 @@ private function doBuy() {
':ow' => $USER['ally_id'],
':ow2' => $fleetResult[0]['ally_id'],
));
- $buy = $this->checkBuyable($fleetResult[0]['filter_visibility'], $res[0]['level'], $fleetResult[0]['ally_id'], $USER['ally_id']);
+ $level = null;
+ if ($db->rowCount() != 0) {
+ $level = $res[0]['level'];
+ }
+ $buy = $this->checkBuyable($fleetResult[0]['filter_visibility'], $level, $fleetResult[0]['ally_id'], $USER['ally_id']);
if(!$buy['buyable']) {
return $buy['reason'];
}
Bugfix: Research
It was possible to do research and build laboratory at the same time if good order has been used.
Full description of the bug here
Solution
In file includes/pages/game/ShowResearchPage.class.php which is responsible for research was simple checking but only the planet with the research.
The easiest solution was to check all planets. I did the SQL query and function is checking all planets know.
private function CheckLabSettingsInQueue()
{
- global $PLANET;
- if ($PLANET['b_building'] == 0)
- return true;
-
- $CurrentQueue = unserialize($PLANET['b_building_id']);
- foreach($CurrentQueue as $ListIDArray) {
- if($ListIDArray[0] == 6 || $ListIDArray[0] == 31)
- return false;
+ global $USER;
+ $db = Database::get();
+ $sql = "SELECT * FROM %%PLANETS%% WHERE id_owner = :owner;";
+ $planets = $db->select($sql, array(
+ ':owner' => $USER['id'],
+ ));
+
+ foreach ($planets as $planet)
+ {
+ if ($planet['b_building'] == 0)
+ continue;
+
+ $CurrentQueue = unserialize($planet['b_building_id']);
+ foreach($CurrentQueue as $ListIDArray) {
+ if($ListIDArray[0] == 6 || $ListIDArray[0] == 31)
+ return false;
+ }
}
return true;
}
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
I like how you improved the way you expose your work here and that you crammed enough contributions in to be worthy of a reward.
You can contact us on Discord.
[utopian-moderator]
Thank you very much!
Hey @dotevo I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x