Add Support for Breakout

parent 358509cf
Pipeline #581 passed with stage
......@@ -30,6 +30,14 @@ class Game {
const WEAPON_ENERGY_SWORD = '2650887244';
/**
* If you are viewing this. This code is horrible.
* Literally 3 functions in this file all do the SAME thing.
* They iterate through match events and pull whats needed.
*
* This could be simplified and sexified so much, but during
* dev you don't know what you are making until its done.
*
* I'll rewrite this when not under pressure of API competition.
* @param Match $match
* @return array
*/
......@@ -53,6 +61,11 @@ class Game {
'id' => $team->key,
'team' => $team,
];
foreach ($match->playersOnTeam($team->key) as $player)
{
$team_label[$team->key]['players'][$player->account_id] = $player->account;
}
}
}
else
......@@ -70,20 +83,42 @@ class Game {
}
$data = [];
$roundWinners = [];
for ($i = 0; $i < $match->hasRounds(); $i++)
{
foreach ($team_label as $team)
{
$stats = $team['team']->getRoundStats($i);
if ($stats['Rank'] == 1)
{
$roundWinners[$i] = $team['id'];
}
$data[$i][$team['id']] = [
'kills' => 0,
'deaths' => 0,
'assists' => 0,
'score' => $stats === false ? 0 : $stats['Score'],
'dnf' => $team['dnf'],
'extras' => [],
];
if ($match->isTeamGame)
{
foreach ($match->playersOnTeam($team['team']->key) as $player)
{
$data[$i][$team['id']][$player->account_id] = [
'kills' => 0,
'deaths' => 0,
'assists' => 0,
'score' => 0,
'dnf' => $player->dnf,
'extras' => [],
];
}
}
else
{
$data[$i][$team['id']] = [
'kills' => 0,
'deaths' => 0,
'assists' => 0,
'score' => $stats === false ? 0 : $stats['Score'],
'dnf' => $team['dnf'],
'extras' => [],
];
}
}
}
......@@ -92,6 +127,7 @@ class Game {
$infectedCount = 1;
$zombies = [];
$rounds = [];
$deathCount = 1;
foreach ($match->events as $event)
{
......@@ -121,10 +157,11 @@ class Game {
$killsObtained = false;
$infectedCount = 1;
$zombies = [];
$deathCount = 1;
}
else if ($event->event_name == EventName::WeaponPickup)
{
if (! $killsObtained)
if (! $killsObtained && ! $match->isTeamGame)
{
if ($event->killer_weapon_id == self::WEAPON_ENERGY_SWORD)
{
......@@ -145,6 +182,12 @@ class Game {
}
else if ($event->killer_id == $event->victim_id)
{
if ($match->isTeamGame)
{
$data[$currentRound][$team_map[$event->victim_id]]['extras']['deathCount'] = $deathCount++;
$data[$currentRound][$team_map[$event->victim_id]][$event->victim_id]['deaths'] += 1;
continue;
}
if (in_array($event->killer_id, $zombies))
{
continue;
......@@ -157,6 +200,9 @@ class Game {
continue;
}
$team_killer_id = $team_map[$event->killer_id];
$team_victim_id = $team_map[$event->victim_id];
if (! $match->isTeamGame)
{
if (in_array($event->killer_id, $zombies) && ! in_array($event->victim_id, $zombies))
......@@ -164,16 +210,30 @@ class Game {
$zombies[] = $event->victim_id;
$data[$currentRound][$event->victim_id]['extras']['infected'] = $infectedCount++;
}
$data[$currentRound][$event->killer_id]['kills'] += 1;
$data[$currentRound][$event->victim_id]['deaths'] += 1;
}
else
{
$data[$currentRound][$team_killer_id][$event->killer_id]['kills'] += 1;
$data[$currentRound][$team_victim_id][$event->victim_id]['deaths'] += 1;
$data[$currentRound][$team_victim_id][$event->victim_id]['extras']['deathCount'] = $deathCount++;
}
$data[$currentRound][$event->killer_id]['kills'] += 1;
$data[$currentRound][$event->victim_id]['deaths'] += 1;
if (count($event->assists) > 0)
{
foreach ($event->assists as $assist)
{
$data[$currentRound][$assist->account_id]['assists'] += 1;
if ($match->isTeamGame)
{
$data[$currentRound][$team_killer_id][$event->killer_id]['assists'] += 1;
}
else
{
$data[$currentRound][$assist->account_id]['assists'] += 1;
}
}
}
}
......@@ -187,19 +247,46 @@ class Game {
{
foreach ($players as &$player)
{
$player['kd'] = $player['deaths'] == 0 ? $player['kills'] : ($player['kills'] / $player['deaths']);
$player['kda'] = $player['deaths'] == 0 ? ($player['kills'] + $player['assists']) : ($player['kills'] + $player['assists']) / $player['deaths'];
if ($match->isTeamGame)
{
foreach ($player as &$_player)
{
$_player['kd'] = $_player['deaths'] == 0 ? $_player['kills'] : ($_player['kills'] / $_player['deaths']);
$_player['kda'] = $_player['deaths'] == 0 ? ($_player['kills'] + $_player['assists']) : ($_player['kills'] + $_player['assists']) / $_player['deaths'];
}
uasort($player, function($a, $b) use ($match)
{
return $b['kd'] - $a['kd'];
});
}
else
{
$player['kd'] = $player['deaths'] == 0 ? $player['kills'] : ($player['kills'] / $player['deaths']);
$player['kda'] = $player['deaths'] == 0 ? ($player['kills'] + $player['assists']) : ($player['kills'] + $player['assists']) / $player['deaths'];
}
}
uasort($players, function($a, $b)
if (! $match->isTeamGame)
{
return $b['score'] - $a['score'];
});
uasort($players, function($a, $b) use ($match)
{
if ($match->isTeamGame)
{
return $b['kd'] - $a['kd'];
}
else
{
return $b['score'] - $a['score'];
}
});
}
}
return [
'data' => $data,
'team' => $team_label,
'roundWinners' => $roundWinners,
'roundCount' => $match->hasRounds(),
'rounds' => $rounds,
];
......
......@@ -57,6 +57,11 @@ class Gametype extends Model {
// Public Methods
//---------------------------------------------------------------------------------
public function isBreakout()
{
return $this->contentId == '1e473914-46e4-408d-af26-178fb115de76';
}
public function getImage()
{
$path = public_path('images/gametypes/');
......
......@@ -109,6 +109,11 @@ class MatchTeam extends Model {
return false;
}
public function getSemanticColor()
{
return $this->team->getSemanticColor();
}
public function label()
{
if ($this->isWinner())
......
......@@ -39,7 +39,7 @@
</div>
@if ($match->hasRounds())
<div class="ui bottom attached tab" data-tab="rounds">
@include('includes.halo5.game.events.rounds-tab', ['data' => $round_data])
@include('includes.halo5.game.events.round-select-tab', ['data' => $round_data])
</div>
@endif
<div class="ui bottom attached tab" data-tab="gameviewer">
......
<table class="ui sortable table">
<thead class="desktop only">
<tr>
<th>Spartan</th>
<th>Kills</th>
<th>Deaths</th>
<th>Assists</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($round as $key => $item)
@if (! $item['dnf'])
<tr class="{{ $item['deaths'] == 0 && $item['kills'] != 0 ? 'positive' : null }}">
<td>
<a href="{{ URL::action('Halo5\ProfileController@index', [$data['team'][$team_id]['players'][$key]->seo]) }}">
{{ $data['team'][$team_id]['players'][$key]->gamertag }}
</a>
</td>
<td class="kills-table">{{ $item['kills'] }}</td>
<td class="deaths-table {{ $item['deaths'] == 0 ? 'no-deaths' : null }}">
{!! $item['deaths'] == 0 ? '<i class="smile icon"></i> no deaths' : $item['deaths'] !!}
</td>
<td class="assists-table">{{ $item['assists'] }}</td>
<td>
@if ($item['deaths'] == 0)
<span class="ui blue label">Survived</span>
@endif
@if (isset($item['extras']['deathCount']))
<span class="ui black label">{{ \Onyx\Laravel\Helpers\Text::ordinal($item['extras']['deathCount']) }} death</span>
@endif
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
\ No newline at end of file
@for ($i = 0; $i < $data['roundCount']; $i++)
<h3 class="ui top attached header">
Round {{ $i + 1 }}
<span class="ui {{ $data['team'][$data['roundWinners'][$i]]['team']->getSemanticColor() }} label">
{{ $data['team'][$data['roundWinners'][$i]]['team']->team->name }} Win
</span>
</h3>
<div class="ui attached segment">
<div class="ui equal width stackable grid">
@foreach ($data['data'][$i] as $team_id => $team)
<div class="{{ $data['team'][$team_id]['team']->getSemanticColor() }} column">
@include('includes.halo5.game.events.gametypes.breakout.round-table', ['round' => $data['data'][$i][$team_id], 'i' => $i, 'team_id' => $team_id])
</div>
@endforeach
</div>
</div>
@endfor
@section('inline-js')
<script type="text/javascript">
$(function() {
$(".ui.sortable.table").tablesort();
});
</script>
@append
\ No newline at end of file
......@@ -8,7 +8,7 @@
@endif
</h3>
<div class="ui attached segment">
@include('includes.halo5.game.events.round-table', ['round' => $data['data'][$i], 'i' => $i])
@include('includes.halo5.game.events.gametypes.infection.round-table', ['round' => $data['data'][$i], 'i' => $i])
</div>
@endfor
......
@if ($match->gametype->isBreakout())
@include('includes.halo5.game.events.gametypes.breakout.rounds-tab')
@else
@include('includes.halo5.game.events.gametypes.infection.rounds-tab')
@endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment