Skip to content
Open
67 changes: 67 additions & 0 deletions libraries/pet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Pet

Provides information about the player's pet.

## `pet`
This table mostly contains simple/self explanatory information about the player's currently active pet, if any.
- **index**
- **id**
- **name**
- **owner_index**
- **owner_id**
- **target_id**
- **hp_percent** (current/max values not available, except for the player's automaton in `pet.automaton`)
- **mp_percent** (current/max values not available, except for the player's automaton in `pet.automaton`)
- **tp**
- **active** true if the player has a pet out

## `pet.automaton`
This table holds more complex data describing the player's puppetmaster automaton.
- **name**
- **hp**
- **hp_max**
- **mp**
- **mp_max**
- **active** true if the player's currently active pet appears to be their automaton
- **head**
- **raw**: unmodified value
- **item_id**: `raw` + 0x2000
- **item**: Item information from `client_data.items`
- **frame**
- **raw**: unmodified value
- **item_id**: `raw` + 0x2000
- **item**: Item information from `client_data.items`
- **attachments**: Arrays from 0 to 11 of the following type:
- **raw**: unmodified value
- **item_id**: `raw` + 0x2100
- **item**: Item information from `client_data``
- **available_heads[i]**: Original index. Offset from `item_id` by 0x2000, starting at `harlequin_head == 1` (no `0`).
- **available_frames[i]**: Original index. Offset from `item_id` by 0x2020, starting at `harlequin_frame == 0`.
- **available_attach[i]**: Original index. Offset from `item_id` by 0x2100, starting at `strobe == 1` (no `0`).
- **heads_available[item_id]** Modified index to accept `item_id`.
- **frames_available[item_id]** Modified index to accept `item_id`.
- **attach_available[item_id]** Modified index to accept `item_id`.
Automaton's current skill values
- **melee**
- **ranged**
- **magic**
Automaton's skill caps
- **melee_max**
- **magic_max**
- **ranged_max**
Automaton's base stats
- **str**
- **dex**
- **vit**
- **agi**
- **int**
- **mnd**
- **chr**
Automaton's current stat modifiers
- **str_modifier**
- **dex_modifier**
- **vit_modifier**
- **agi_modifier**
- **int_modifier**
- **mnd_modifier**
- **chr_modifier**
11 changes: 11 additions & 0 deletions libraries/pet/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<package>
<name>pet</name>
<version>1.0</version>
<type>library</type>
<dependencies>
<dependency>client_data</dependency>
<dependency>entities</dependency>
<dependency>pet_service</dependency>
<dependency>shared</dependency>
</dependencies>
</package>
44 changes: 44 additions & 0 deletions libraries/pet/pet.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local table = require('table')

local client = require('shared.client')
local entities = require('entities')
local items = require('client_data.items')


local data, ftype = client.new('pet_service')

ftype.fields.target_entity = {
get = function(data)
return entities:by_id(data.target_id)
end,
}

return data

--[[
Copyright © 2020, Windower Dev Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Windower Dev Team nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE WINDOWER DEV TEAM BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
10 changes: 10 additions & 0 deletions libraries/pet_service/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<package>
<name>pet_service</name>
<version>1.0</version>
<type>service</type>
<dependencies>
<dependency>packet</dependency>
<dependency>shared</dependency>
<dependency>struct</dependency>
</dependencies>
</package>
90 changes: 90 additions & 0 deletions libraries/pet_service/pet_service.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
local math = require('math')
local ffi = require('ffi')

local packet = require('packet')
local server = require('shared.server')
local struct = require('struct')

local data = server.new(struct.struct({
index = {struct.int32},
id = {struct.int32},
name = {struct.string(0x10)},
owner_index = {struct.int32},
owner_id = {struct.int32},
target_id = {struct.int32},
hp_percent = {struct.int32},
mp_percent = {struct.int32},
tp = {struct.int32},
active = {struct.bool},
}))

packet.incoming:register_init({
[{0x037}] = function(p) -- While this packet is mostly player data, it does occassionally update the pet index when no other pet related packet is sent. For example, when moving into zones where the pet is supressed, such as cities and towns, this packet will set the pet index to 0.
data.index = p.pet_index
if p.pet_index and p.pet_index ~= 0 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.pet_index should never be nil, so the first check could be removed (elsewhere as well).

data.active = true
else
data.active = false
end
end,
[{0x067}] = function(p)
if p.type == 4 then
data.index = p.pet_index
data.id = p.pet_id
data.owner_index = p.owner_index
data.hp_percent = p.hp_percent
data.mp_percent = p.mp_percent
data.tp = p.pet_tp
if p.pet_index and p.pet_index ~= 0 then
data.active = true
else
data.active = false
end
end
end,
[{0x068}] = function(p)
if p.type == 4 then
data.owner_index = p.owner_index
data.owner_id = p.owner_id
data.index = p.pet_index
data.hp_percent = p.hp_percent
data.mp_percent = p.mp_percent
data.tp = p.pet_tp
data.target_id = p.target_id
data.name = p.pet_name
if p.pet_index and p.pet_index ~= 0 then
data.active = true
else
data.active = false
end
end
end,
})

--[[
Copyright © 2020, Windower Dev Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Windower Dev Team nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE WINDOWER DEV TEAM BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]