-
Notifications
You must be signed in to change notification settings - Fork 21
Add pet_service library #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
5fe0f53
54976f3
9617737
8b31bbe
34c9462
1155022
277d538
cf816e2
c59ddfc
5b392df
6790941
b0a3112
615b5fa
44ec8ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| local math = require('math') | ||
| local ffi = require('ffi') | ||
|
|
||
| local packet = require('packet') | ||
| local server = require('shared.server') | ||
| local struct = require('struct') | ||
|
|
||
| local item_type = struct.struct({ | ||
| item_id = {struct.uint16}, | ||
sigilbaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raw = {struct.uint8}, | ||
| }) | ||
|
|
||
| local data = server.new(struct.struct({ | ||
| index = {struct.uint16}, | ||
| id = {struct.uint32}, | ||
| name = {struct.string(0x10)}, | ||
| owner_index = {struct.uint16}, | ||
| owner_id = {struct.uint32}, | ||
| target_id = {struct.uint32}, | ||
| hp_percent = {struct.uint8}, | ||
| mp_percent = {struct.uint8}, | ||
| tp = {struct.uint32}, | ||
| active = {struct.bool}, | ||
| automaton = {struct.struct({ | ||
|
||
| active = {struct.bool}, | ||
| head = {item_type}, | ||
| frame = {item_type}, | ||
| attachments = {item_type[12]}, | ||
| available_heads = {struct.bitfield(4)}, | ||
|
||
| available_frames = {struct.bitfield(4)}, | ||
| available_attach = {struct.bitfield(32)}, | ||
| name = {struct.string(0x10)}, | ||
sigilbaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hp = {struct.uint16}, | ||
| hp_max = {struct.uint16}, | ||
| mp = {struct.uint16}, | ||
| mp_max = {struct.uint16}, | ||
| melee = {struct.uint16}, | ||
| melee_max = {struct.uint16}, | ||
| ranged = {struct.uint16}, | ||
| ranged_max = {struct.uint16}, | ||
| magic = {struct.uint16}, | ||
| magic_max = {struct.uint16}, | ||
| str = {struct.uint16}, | ||
| str_modifier = {struct.uint16}, | ||
|
||
| dex = {struct.uint16}, | ||
| dex_modifier = {struct.uint16}, | ||
| vit = {struct.uint16}, | ||
| vit_modifier = {struct.uint16}, | ||
| agi = {struct.uint16}, | ||
| agi_modifier = {struct.uint16}, | ||
| int = {struct.uint16}, | ||
| int_modifier = {struct.uint16}, | ||
| mnd = {struct.uint16}, | ||
| mnd_modifier = {struct.uint16}, | ||
| chr = {struct.uint16}, | ||
| chr_modifier = {struct.uint16}, | ||
| })} | ||
| })) | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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, | ||
| [{0x044,0x12}] = function(p) | ||
|
|
||
| data.automaton.head.raw = p.automaton_head | ||
|
||
| data.automaton.head.item_id = p.automaton_head + 0x2000 | ||
| data.automaton.frame.raw = p.automaton_frame | ||
| data.automaton.frame.item_id = p.automaton_frame + 0x2000 | ||
| for i=0, 11 do | ||
|
||
| data.automaton.attachments[i].raw = p.attachments[i] | ||
| data.automaton.attachments[i].item_id = p.attachments[i] + 0x2100 | ||
| end | ||
| ffi.copy(data.automaton._available_heads, p._available_heads, 4) | ||
| ffi.copy(data.automaton._available_frames, p._available_frames, 4) | ||
| ffi.copy(data.automaton._available_attach, p._available_attach, 32) | ||
| data.automaton.name = p.pet_name | ||
| data.automaton.hp = p.hp | ||
| data.automaton.hp_max = p.hp_max | ||
| data.automaton.mp = p.mp | ||
| data.automaton.mp_max = p.mp_max | ||
| data.automaton.melee = p.melee | ||
| data.automaton.melee_max = p.melee_max | ||
| data.automaton.ranged = p.ranged | ||
| data.automaton.ranged_max = p.ranged_max | ||
| data.automaton.magic = p.magic | ||
| data.automaton.magic_max = p.magic_max | ||
| data.automaton.str = p.str | ||
| data.automaton.str_modifier = p.str_modifier | ||
| data.automaton.dex = p.dex | ||
| data.automaton.dex_modifier = p.dex_modifier | ||
| data.automaton.vit = p.vit | ||
| data.automaton.vit_modifier = p.vit_modifier | ||
| data.automaton.agi = p.agi | ||
| data.automaton.agi_modifier = p.agi_modifier | ||
| data.automaton.int = p.int | ||
| data.automaton.int_modifier = p.int_modifier | ||
| data.automaton.mnd = p.mnd | ||
| data.automaton.mnd_modifier = p.mnd_modifier | ||
| data.automaton.chr = p.chr | ||
| data.automaton.chr_modifier = p.chr_modifier | ||
|
|
||
| local active = data.active and (data.name == data.automaton.name) | ||
|
||
|
|
||
| data.automaton.active = active | ||
|
|
||
| if p.hp_max ~= 0 and active then | ||
|
||
| data.hp_percent = math.floor(100 * p.hp / p.hp_max) | ||
| end | ||
| if p.mp_max ~= 0 and active then | ||
| data.mp_percent = math.floor(100 * p.mp / p.mp_max) | ||
| end | ||
| end | ||
| }) | ||
|
|
||
| --[[ | ||
| Copyright © 2020, John S Hobart | ||
| 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 | ||
sigilbaram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
sigilbaram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
| ]] | ||
sigilbaram marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use two spaces for XML indentation.