# PwAPI Quick Reference

## Item Structure

```php
$item = [
    'id'          => 11208,   // Item ID dari elements.data
    'pos'         => 0,       // Posisi slot (auto-assigned saat addItem)
    'count'       => 10,      // Jumlah item
    'max_count'   => 10,      // Stack max (biasanya sama dengan count)
    'data'        => '0',     // Octet data (hex string, '0' = kosong)
    'proctype'    => 0,       // Process type (0 = normal)
    'expire_date' => 0,       // Expire timestamp (0 = tidak expire)
    'guid1'       => 0,       // Unique GUID 1
    'guid2'       => 0,       // Unique GUID 2
    'mask'        => 0,       // Mask flags
];
```

## Common Operations

### Get Character Data
```php
$role = $api->getRole(1024);
$name     = $role['base']['name'];
$level    = $role['status']['level'];
$class    = $role['base']['cls'];
$hp       = $role['status']['hp'];
$mp       = $role['status']['mp'];
$posx     = $role['status']['posx'];
$posy     = $role['status']['posy'];
$posz     = $role['status']['posz'];
$worldtag = $role['status']['worldtag'];
```

### Send Mail with Item
```php
$api->sendMail($roleId, 'Title', 'Message body', 0, [
    'id' => 11208, 'pos' => 0, 'count' => 10,
    'max_count' => 10, 'data' => '0', 'proctype' => 0,
    'expire_date' => 0, 'guid1' => 0, 'guid2' => 0, 'mask' => 0,
]);
```

### Send Mail with Gold Only
```php
$api->sendMail($roleId, 'Gold Gift', 'Here is your gold!', 1000000, []);
```

### World Chat
```php
$api->worldChat(0, 'Server will restart in 5 minutes!', 9);
// Channel 9 = world chat, roleid 0 = system sender
```

### Ban Character
```php
$api->forbidRole($roleId, 86400, 'Cheating'); // 24 hours
```

### Teleport Character
```php
$api->teleportRole($roleId, 448.0, 900.0, 210.0, 1);
// posx, posy, posz, worldtag
```

### Reset Skills
```php
$api->resetSkills($roleId);
// atau dengan custom hex
$api->resetSkills($roleId, '060000009f00000000000000...');
```

### Clear Storehouse Password
```php
$api->clearStorehousePassword($roleId);
```

### Get Online Players
```php
$onlineList = $api->getOnlineList();
foreach ($onlineList as $player) {
    echo "{$player['roleid']} - {$player['name']}\n";
}
```

### Get User's Characters
```php
$roles = $api->getRoles($userId);
foreach ($roles['roles'] as $role) {
    echo "ID: {$role['id']}, Name: {$role['name']}\n";
}
```

### Get Cash/Gold
```php
$cash = $api->getUserCash($userId);
echo "Total cash: {$cash['cash_total']}\n";
```

### Get Faction Info
```php
$faction = $api->getFactionDetail($factionId);
echo "Name: {$faction['name']}\n";
echo "Level: {$faction['level']}\n";
echo "Members: " . count($faction['member']) . "\n";
```

### Get Territories
```php
$territories = $api->getTerritories();
foreach ($territories['territory'] as $t) {
    echo "ID: {$t['id']}, Owner: {$t['owner']}\n";
}
```

### Class ID Reference
```
0 = Warrior (Male)
1 = Warrior (Female)
2 = Wizard (Male)
3 = Wizard (Female)
4 = Psychic (Male)
5 = Psychic (Female)
6 = Werefox (Male)
7 = Werefox (Female)
8 = Mystic (Male)
9 = Mystic (Female)
10 = Seeker (Male)
11 = Seeker (Female)
```
