matthiggins/bluezone

一个用于与PUBG API和PUBG比赛遥测文件交互的现代PHP SDK。


README

bluezone-banner

BLUEZONE:PUBG API的PHP SDK

Version PHP Version Require License

BLUEZONE是一个PHP SDK,它使得使用PUBG API变得非常简单。它提供了一套简单直观的方法,允许您无需担心认证和请求处理等底层细节即可与PUBG API交互。使用BLUEZONE,您可以轻松检索玩家、比赛、赛季、武器精通和生存精通的数据。它还包括一组数据传输对象(DTOs),帮助您以结构化和组织化的方式处理API返回的数据。

除了访问API数据外,BLUEZONE还允许您访问比赛遥测文件并解析它们以获取玩家数据。这使得分析游戏数据和深入了解玩家行为变得容易。无论您是构建帮助玩家提高技能的工具,还是对玩家行为进行研究,BLUEZONE都提供了一个强大而灵活的方式来处理PUBG数据。

相关链接

目录

安装

要安装,请使用composer要求包matthiggins/bluezone

composer require matthiggins/bluezone

用法

使用您的PUBG API密钥实例化一个新的Bluezone实例。您可以通过访问PUBG开发者门户来获取自己的API密钥。

BLUEZONE使用Saloon创建用于PUBG API的连接器、请求和DTO。您可以在请求和响应中使用Saloon的所有功能。

use Bluezone\Bluezone;

$bluezone = new Bluezone($apiKey);

发起请求

请求将返回PUBG DTO实例或实例集合。

// Search for a player
$player = $bluezone->player()->search($shard, $playerName);

// Find a player by account ID
$player = $bluezone->player()->find($shard, $accountId);

如果请求导致错误,将抛出异常。

use Saloon\Exceptions\SaloonException;

try {
    $seasons = $bluezone->season()->all('fail');
}catch(SaloonException $e) {
    $status = $e->getStatus();
}

默认情况下,Saloon提供用于特定请求错误的类。

Saloon - 处理失败

SaloonException
├── FatalRequestException (Connection Errors)
└── RequestException (Request Errors)
    ├── ServerException (5xx)
    │   ├── InternalServerErrorException (500)
    │   ├── ServiceUnavailableException (503)
    │   └── GatewayTimeoutException (504)
    └── ClientException (4xx)
        ├── UnauthorizedException (401)
        ├── ForbiddenException (403)
        ├── NotFoundException (404)
        ├── MethodNotAllowedException (405)
        ├── RequestTimeOutException (408)
        ├── UnprocessableEntityException (422)
        └── TooManyRequestsException (429)

可用方法

BLUEZONE提供了访问[PUBG API端点](https://documentation.pubg.com/en/introduction.ht)的简单方法

赛季列表

// Get all PUBG seasons
$seasons = $bluezone->season()->all($shard);

玩家搜索、玩家资料和统计数据

您可以通过游戏名称和分区或使用账户ID检索玩家。

// Find a specific player using the account id
$player = $bluezone->player()->find($shard, $accountId);

// Search for a player by name 
// NOTE : player search requires the name to be entered exactly as it is displayed in-game
$player = $bluezone->player()->search($shard, $playerName);

// Search for up to 10 players
$results = $bluezone->player()->searchMany($shard, [$playerName01, $playerName02]);

// Season stats for a single player
$seasonStats = $bluezone->player()->seasonStats($shard, $season, $accountId);

// Season stats for up to 10 players
$seasonStats = $bluezone->player()->seasonStatsMany($shard, $season, $gameMode, [$accountId,$accountId]);

// Ranked season stats for a single player
$rankedSeasonStats = $bluezone->player()->rankedSeasonStats($shard, $season, $accountId);

// Lifetime season stats for a single player
$lifetimeStats = $bluezone->player()->lifetimeStats($shard, $accountId);

// Lifetime stats for up to 10 players
$lifetimeStats = $bluezone->player()->lifetimeStatsMany($shard, $gameMode, [$accountId,$accountId]);

// Get weapon mastery for a single player
$weaponMastery = $bluezone->player()->weaponMastery($shard, $accountId);

// Get survival mastery for a single player
$survivalMastery = $bluezone->player()->survivalMastery($shard, $accountId);

比赛

// Get a match
$match = $bluezone->match()->find($shard, $matchId);

访问比赛遥测数据

PUBG API提供通过比赛遥测文件访问非常详细的比赛数据。此文件包含游戏细节、玩家移动、玩家操作、区域信息等。遥测文件是大型JSON文件,可以解析和分析以进行更深入的分析。

要获取遥测文件,您必须首先请求PUBG比赛详情。

// Get a single match DTO instance
$match = $bluezone->match()->find($shard, $matchId);

// Get the telemetry DTO instance
$telemetry = $match->getTelemetry();

// Get the raw telemetry events in a Collection
$rawEvents = $telemetry->raw();

// Alternatively you can map all telemetry 
// events to their DTO instances
$events = $telemetry->events();   

处理遥测事件

遥测文件基本上是比赛中发生的大量事件的列表。这些事件包括个别玩家的以及游戏事件,如补给包、圈移动等。您可以使用辅助方法轻松过滤这些事件,使提取玩家和游戏数据变得更加容易。

// Get all telemetry events for a specific player
$telemetry->player($accountId)->all();

// Get all attack events for a specific player
$telemetry->player($accountId)->attackEvents();

// Get all heal events for a specific player
$telemetry->player($accountId)->healEvents();

// Get all item attachment events for a specific player
$telemetry->player($accountId)->itemAttachEvents();

// Get all item detachment events for a specific player
$telemetry->player($accountId)->itemDetachEvents();

// Get all item drop events for a specific player
$telemetry->player($accountId)->itemDropEvents();

// Get all item equip events for a specific player
$telemetry->player($accountId)->itemEquipEvents();

// Get all item pickup events for a specific player
$telemetry->player($accountId)->itemPickupEvents();

// Get all item unequip events for a specific player
$telemetry->player($accountId)->itemUnequipEvents();

// Get all item use events for a specific player
$telemetry->player($accountId)->itemUseEvents();

// Get all kill events for a specific player
$telemetry->player($accountId)->killEvents();

// Get all object destroy events for a specific player
$telemetry->player($accountId)->objectDestroyEvents();

// Get all object interaction events for a specific player
$telemetry->player($accountId)->objectInteractionEvents();

// Get all parachute landing events for a specific player
$telemetry->player($accountId)->parachuteLandingEvents();

// Get all position events for a specific player
$telemetry->player($accountId)->positionEvents();

// Get all take damage events for a specific player
$telemetry->player($accountId)->takeDamageEvents();

// Get all throwable use events for a specific player
$telemetry->player($accountId)->useThrowableEvents();

// Get all swim events for a specific player
$telemetry->player($accountId)->swimEvents();

// Get all swim start events for a specific player
$telemetry->player($accountId)->swimStartEvents();

// Get all swim end events for a specific player
$telemetry->player($accountId)->swimEndEvents();

// Get all vault events for a specific player
$telemetry->player($accountId)->vaultEvents();

// Get all vehicle events for a specific player
$telemetry->player($accountId)->vehicleEvents();

// Get all weapon fire count events for a specific player
$telemetry->player($accountId)->weaponFireCountEvents();

// Get all wheel destroy events for a specific player
$telemetry->player($accountId)->wheelDestroyEvents();

遥测中的游戏事件和比赛事件

除了玩家事件外,您还可以轻松访问游戏事件和比赛详情。

// Get all care package events from the telemetry
$telemetry->match()->carePackageEvents();

// Get the definition of the match
$telemetry->match()->definition();

// Get the end state of the match
$telemetry->match()->end();

// Get all phase change events for the match
$telemetry->match()->phaseChanges();

// Get the start state of the match
$telemetry->match()->start();

// Get all state events from the match
$telemetry->match()->stateEvents();

从遥测数据中过滤事件

您可以使用Laravel Collection方法轻松筛选数据中的事件。

例如

use Bluezone\Telemetry\Events\PlayerAttack;

$playerAttackEvents = $telemetry->events()->filter(function ($event) use ($accountId) {
    return ($event instanceof PlayerAttack) && $event->attacker->accountId == $accountId;
});