From 5fe0f53f89c4c560d95b1b66e2346689fb15c3a1 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Fri, 9 Jul 2021 21:27:09 -0400 Subject: [PATCH 01/14] add pet_service library --- libraries/pet_service/manifest.xml | 10 ++ libraries/pet_service/pet_service.lua | 151 ++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 libraries/pet_service/manifest.xml create mode 100644 libraries/pet_service/pet_service.lua diff --git a/libraries/pet_service/manifest.xml b/libraries/pet_service/manifest.xml new file mode 100644 index 00000000..80135a47 --- /dev/null +++ b/libraries/pet_service/manifest.xml @@ -0,0 +1,10 @@ + + pet_service + 1.0 + service + + packet + shared + struct + + diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua new file mode 100644 index 00000000..e112afc0 --- /dev/null +++ b/libraries/pet_service/pet_service.lua @@ -0,0 +1,151 @@ +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}, + 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)}, + 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 + 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 +}) \ No newline at end of file From 54976f3edde35436b6406edb957a5f28b48c2851 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Fri, 9 Jul 2021 21:36:27 -0400 Subject: [PATCH 02/14] add trailing newline --- libraries/pet_service/pet_service.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index e112afc0..45c4c038 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -148,4 +148,4 @@ packet.incoming:register_init({ data.mp_percent = math.floor(100 * p.mp / p.mp_max) end end -}) \ No newline at end of file +}) From 9617737539d04c53a72379787bc1b656a1659595 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Fri, 9 Jul 2021 21:43:35 -0400 Subject: [PATCH 03/14] add license to pet_service.lua --- libraries/pet_service/pet_service.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 45c4c038..b851974b 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -149,3 +149,28 @@ packet.incoming:register_init({ 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 + 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. +]] \ No newline at end of file From 8b31bbea15d0c501b31a4874d3f2a9bcca4d31b8 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sat, 10 Jul 2021 04:04:23 -0400 Subject: [PATCH 04/14] adding pet library to same branch --- libraries/pet/README.md | 67 ++++++++++++++++++++++++++++++++++++++ libraries/pet/manifest.xml | 11 +++++++ libraries/pet/pet.lua | 52 +++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 libraries/pet/README.md create mode 100644 libraries/pet/manifest.xml create mode 100644 libraries/pet/pet.lua diff --git a/libraries/pet/README.md b/libraries/pet/README.md new file mode 100644 index 00000000..75efef2e --- /dev/null +++ b/libraries/pet/README.md @@ -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** diff --git a/libraries/pet/manifest.xml b/libraries/pet/manifest.xml new file mode 100644 index 00000000..44c7fc48 --- /dev/null +++ b/libraries/pet/manifest.xml @@ -0,0 +1,11 @@ + + pet + 1.0 + library + + client_data + entities + pet_service + shared + + diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua new file mode 100644 index 00000000..cce72bbb --- /dev/null +++ b/libraries/pet/pet.lua @@ -0,0 +1,52 @@ +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, +} + + +ftype.fields.automaton.type.fields.attachments.type.base.fields.item = { + get = function(data) + return items[data.item_id] + end, +} + +ftype.fields.automaton.type.fields.heads_available = { + get = function(data) + return setmetatable({}, { + __index = function(t, k) + return data.available_heads[k - 0x2000] + end, + }) + end, +} + +ftype.fields.automaton.type.fields.frames_available = { + get = function(data) + return setmetatable({}, { + __index = function(t, k) + return data.available_frames[k - 0x2020] + end, + }) + end, +} + +ftype.fields.automaton.type.fields.attach_available = { + get = function(data) + return setmetatable({}, { + __index = function(t, k) + return data.available_attach[k - 0x2100] + end, + }) + end, +} + +return data From 34c946202e3c5ec8638796b4cf56f26d889aff30 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sat, 10 Jul 2021 04:13:00 -0400 Subject: [PATCH 05/14] re-added license --- libraries/pet/pet.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua index cce72bbb..603d70d7 100644 --- a/libraries/pet/pet.lua +++ b/libraries/pet/pet.lua @@ -50,3 +50,28 @@ ftype.fields.automaton.type.fields.attach_available = { } return data + +--[[ +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 + 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. +]] \ No newline at end of file From 115502250998b1795f5e21e01644401a88d8e64f Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sat, 10 Jul 2021 04:46:09 -0400 Subject: [PATCH 06/14] fix xml indentation --- libraries/pet/manifest.xml | 18 +++++++++--------- libraries/pet_service/manifest.xml | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/pet/manifest.xml b/libraries/pet/manifest.xml index 44c7fc48..60a7f7e9 100644 --- a/libraries/pet/manifest.xml +++ b/libraries/pet/manifest.xml @@ -1,11 +1,11 @@ - pet - 1.0 - library - - client_data - entities - pet_service - shared - + pet + 1.0 + library + + client_data + entities + pet_service + shared + diff --git a/libraries/pet_service/manifest.xml b/libraries/pet_service/manifest.xml index 80135a47..f5412cb5 100644 --- a/libraries/pet_service/manifest.xml +++ b/libraries/pet_service/manifest.xml @@ -1,10 +1,10 @@ - pet_service - 1.0 - service - - packet - shared - struct - + pet_service + 1.0 + service + + packet + shared + struct + From 277d5381e0e6f81bf71d6332eea48d68c61a7575 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sat, 10 Jul 2021 19:57:58 -0400 Subject: [PATCH 07/14] fix license --- libraries/pet/pet.lua | 7 +++++-- libraries/pet_service/pet_service.lua | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua index 603d70d7..f741e86d 100644 --- a/libraries/pet/pet.lua +++ b/libraries/pet/pet.lua @@ -52,10 +52,12 @@ ftype.fields.automaton.type.fields.attach_available = { return data --[[ -Copyright © 2020, John S Hobart +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 @@ -64,6 +66,7 @@ modification, are permitted provided that the following conditions are met: * 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 @@ -74,4 +77,4 @@ 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. -]] \ No newline at end of file +]] diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index b851974b..613ccf76 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -151,10 +151,12 @@ packet.incoming:register_init({ }) --[[ -Copyright © 2020, John S Hobart +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 @@ -163,6 +165,7 @@ modification, are permitted provided that the following conditions are met: * 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 @@ -173,4 +176,4 @@ 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. -]] \ No newline at end of file +]] From cf816e2c48cb9d3d903a796eaf8a636bc1a652d6 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sat, 10 Jul 2021 20:03:12 -0400 Subject: [PATCH 08/14] change all ints to int32 --- libraries/pet_service/pet_service.lua | 68 +++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 613ccf76..2cb0a867 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -6,20 +6,20 @@ local server = require('shared.server') local struct = require('struct') local item_type = struct.struct({ - item_id = {struct.uint16}, - raw = {struct.uint8}, + item_id = {struct.int32}, + raw = {struct.int32}, }) local data = server.new(struct.struct({ - index = {struct.uint16}, - id = {struct.uint32}, + index = {struct.int32}, + id = {struct.int32}, 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}, + 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}, automaton = {struct.struct({ active = {struct.bool}, @@ -30,30 +30,30 @@ local data = server.new(struct.struct({ available_frames = {struct.bitfield(4)}, available_attach = {struct.bitfield(32)}, name = {struct.string(0x10)}, - 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}, + hp = {struct.int32}, + hp_max = {struct.int32}, + mp = {struct.int32}, + mp_max = {struct.int32}, + melee = {struct.int32}, + melee_max = {struct.int32}, + ranged = {struct.int32}, + ranged_max = {struct.int32}, + magic = {struct.int32}, + magic_max = {struct.int32}, + str = {struct.int32}, + str_modifier = {struct.int32}, + dex = {struct.int32}, + dex_modifier = {struct.int32}, + vit = {struct.int32}, + vit_modifier = {struct.int32}, + agi = {struct.int32}, + agi_modifier = {struct.int32}, + int = {struct.int32}, + int_modifier = {struct.int32}, + mnd = {struct.int32}, + mnd_modifier = {struct.int32}, + chr = {struct.int32}, + chr_modifier = {struct.int32}, })} })) From c59ddfcc8dbbee164571aa2a4ddfe82e8df8a562 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sun, 11 Jul 2021 15:28:08 -0400 Subject: [PATCH 09/14] change stats to str->str-base and str_modifier->str_bonus --- libraries/pet_service/pet_service.lua | 100 +++++++++++++------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 2cb0a867..d3063caa 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -29,31 +29,31 @@ local data = server.new(struct.struct({ available_heads = {struct.bitfield(4)}, available_frames = {struct.bitfield(4)}, available_attach = {struct.bitfield(32)}, - name = {struct.string(0x10)}, - hp = {struct.int32}, - hp_max = {struct.int32}, - mp = {struct.int32}, - mp_max = {struct.int32}, - melee = {struct.int32}, - melee_max = {struct.int32}, - ranged = {struct.int32}, - ranged_max = {struct.int32}, - magic = {struct.int32}, - magic_max = {struct.int32}, - str = {struct.int32}, - str_modifier = {struct.int32}, - dex = {struct.int32}, - dex_modifier = {struct.int32}, - vit = {struct.int32}, - vit_modifier = {struct.int32}, - agi = {struct.int32}, - agi_modifier = {struct.int32}, - int = {struct.int32}, - int_modifier = {struct.int32}, - mnd = {struct.int32}, - mnd_modifier = {struct.int32}, - chr = {struct.int32}, - chr_modifier = {struct.int32}, + name = {struct.string(0x10)}, + hp = {struct.int32}, + hp_max = {struct.int32}, + mp = {struct.int32}, + mp_max = {struct.int32}, + melee = {struct.int32}, + melee_max = {struct.int32}, + ranged = {struct.int32}, + ranged_max = {struct.int32}, + magic = {struct.int32}, + magic_max = {struct.int32}, + str_base = {struct.int32}, + str_bonus = {struct.int32}, + dex_base = {struct.int32}, + dex_bonus = {struct.int32}, + vit_base = {struct.int32}, + vit_bonus = {struct.int32}, + agi_base = {struct.int32}, + agi_bonus = {struct.int32}, + int_base = {struct.int32}, + int_bonus = {struct.int32}, + mnd_base = {struct.int32}, + mnd_bonus = {struct.int32}, + chr_base = {struct.int32}, + chr_bonus = {struct.int32}, })} })) @@ -111,31 +111,31 @@ packet.incoming:register_init({ 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 + 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_base = p.str + data.automaton.str_bonus = p.str_bonus + data.automaton.dex_base = p.dex + data.automaton.dex_bonus = p.dex_bonus + data.automaton.vit_base = p.vit + data.automaton.vit_bonus = p.vit_bonus + data.automaton.agi_base = p.agi + data.automaton.agi_bonus = p.agi_bonus + data.automaton.int_base = p.int + data.automaton.int_bonus = p.int_bonus + data.automaton.mnd_base = p.mnd + data.automaton.mnd_bonus = p.mnd_bonus + data.automaton.chr_base = p.chr + data.automaton.chr_bonus = p.chr_bonus local active = data.active and (data.name == data.automaton.name) From 5b392df5cee2212179eb0d7fbdafd48f0e1a9581 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sun, 11 Jul 2021 17:23:22 -0400 Subject: [PATCH 10/14] update interface for auto parts --- libraries/pet/pet.lua | 124 +++++++++++++++++++++++++- libraries/pet_service/pet_service.lua | 58 ++++++------ 2 files changed, 149 insertions(+), 33 deletions(-) diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua index f741e86d..f1d43d29 100644 --- a/libraries/pet/pet.lua +++ b/libraries/pet/pet.lua @@ -1,10 +1,11 @@ +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') - +local data, ftype = client.new('pet_service') ftype.fields.target_entity = { get = function(data) @@ -12,13 +13,127 @@ ftype.fields.target_entity = { end, } +ftype.fields.automaton.type.fields.equipment.type.fields.head = { + get = function(data) + return items[data.head_id] + end, +} -ftype.fields.automaton.type.fields.attachments.type.base.fields.item = { +ftype.fields.automaton.type.fields.equipment.type.fields.frame = { get = function(data) - return items[data.item_id] + return items[data.frame_id] end, } +ftype.fields.automaton.type.fields.equipment.type.fields.attachments = { + get = function(data) + return setmetatable({}, { + __index = function(t, k) + local item_id = data.attachment_ids[k] + if item_id == 0 then + return nil + else + return items[data.attachment_ids[k]] + end + end, + }) + end, +} + +ftype.fields.automaton.type.fields.inventory.type.fields.heads = { + get = function(data) + local t = {} + local i + for i = 0, 8 do + if data.automaton.inventory._heads[i] then + table:append(t,items[i+0x2000]) + end + end + end +} + +ftype.fields.automaton.type.fields.inventory.type.fields.heads = { + get = function(data) + local t = {} + local i + for i = 0, 21 do + if data.automaton.inventory._heads[i] then + table:append(t,items[i+0x2020]) + end + end + end +} + +ftype.fields.automaton.type.fields.inventory.type.fields.heads = { + get = function(data) + local t = {} + local i + for i = 0, 31 do + if data.automaton.inventory._heads[i] then + table:append(t,items[i+0x2020]) + end + end + end +} + +ftype.fields.automaton.type.fields.inventory.type.fields.attachments = { + get = function(data) + local t = {} + local i + for i = 0, 255 do + if data.automaton.inventory._attachments[i] then + table:append(t,items[i+0x2100]) + end + end + end +} + +ftype.fields.automaton.type.fields.inventory.type.fields.has_head = { + data = function(_, item) + local id = nil + if type(item) == 'number' then + id = item + elseif type(item) == 'table' and item.id then + id = item.id + end + if id and id >= 0x2000 and id < 0x2020 then + return data.automaton.inventory._heads[id-0x2000] + end + return nil + end, +} + +ftype.fields.automaton.type.fields.inventory.type.fields.has_frame = { + data = function(_, item) + local id = nil + if type(item) == 'number' then + id = item + elseif type(item) == 'table' and item.id then + id = item.id + end + if id and id >= 0x2020 and id < 0x2040 then + return data.automaton.inventory._frames[id-0x2020] + end + return nil + end, +} + +ftype.fields.automaton.type.fields.inventory.type.fields.has_attachment = { + data = function(_, item) + local id = nil + if type(item) == 'number' then + id = item + elseif type(item) == 'table' and item.id then + id = item.id + end + if id and id >= 0x2100 and id < 0x2200 then + return data.automaton.inventory._attachments[id-0x2100] + end + return false + end, +} + +--[[ ftype.fields.automaton.type.fields.heads_available = { get = function(data) return setmetatable({}, { @@ -48,6 +163,7 @@ ftype.fields.automaton.type.fields.attach_available = { }) end, } +--]] return data diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index d3063caa..4b44ed7d 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -5,11 +5,6 @@ local packet = require('packet') local server = require('shared.server') local struct = require('struct') -local item_type = struct.struct({ - item_id = {struct.int32}, - raw = {struct.int32}, -}) - local data = server.new(struct.struct({ index = {struct.int32}, id = {struct.int32}, @@ -22,13 +17,17 @@ local data = server.new(struct.struct({ tp = {struct.int32}, 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)}, + active = {struct.bool}, + equipment = {struct.struct({ + head_id = {struct.int32}, + frame_id = {struct.int32}, + attachment_ids = {struct.int32[12]}, + })}, + inventory = {struct.struct({ + _heads = {struct.bool[32]}, + _frames = {struct.bool[32]}, + _attachments = {struct.bool[256]}, + })}, name = {struct.string(0x10)}, hp = {struct.int32}, hp_max = {struct.int32}, @@ -99,18 +98,19 @@ packet.incoming:register_init({ 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 + data.automaton.equipment.head_id = p.automaton_head + 0x2000 + data.automaton.equipment.frame_id = p.automaton_frame + 0x2000 + local i for i=0, 11 do - data.automaton.attachments[i].raw = p.attachments[i] - data.automaton.attachments[i].item_id = p.attachments[i] + 0x2100 + data.automaton.equipment.attachment_ids[i] = p.attachments[i] + 0x2100 + end + for i = 0, 31 do + data.automaton.inventory._heads[i] = p.available_heads[i] + data.automaton.inventory._frames[i] = p.available_frames[i] + end + for i = 0, 255 do + data.automaton.inventory._attachments[i] = p.available_attach[i] 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 @@ -123,19 +123,19 @@ packet.incoming:register_init({ data.automaton.magic = p.magic data.automaton.magic_max = p.magic_max data.automaton.str_base = p.str - data.automaton.str_bonus = p.str_bonus + data.automaton.str_bonus = p.str_modifier data.automaton.dex_base = p.dex - data.automaton.dex_bonus = p.dex_bonus + data.automaton.dex_bonus = p.dex_modifier data.automaton.vit_base = p.vit - data.automaton.vit_bonus = p.vit_bonus + data.automaton.vit_bonus = p.vit_modifier data.automaton.agi_base = p.agi - data.automaton.agi_bonus = p.agi_bonus + data.automaton.agi_bonus = p.agi_modifier data.automaton.int_base = p.int - data.automaton.int_bonus = p.int_bonus + data.automaton.int_bonus = p.int_modifier data.automaton.mnd_base = p.mnd - data.automaton.mnd_bonus = p.mnd_bonus + data.automaton.mnd_bonus = p.mnd_modifier data.automaton.chr_base = p.chr - data.automaton.chr_bonus = p.chr_bonus + data.automaton.chr_bonus = p.chr_modifier local active = data.active and (data.name == data.automaton.name) From 6790941ee2b02284e05aab8945f305d4ee15bd33 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sun, 11 Jul 2021 17:36:58 -0400 Subject: [PATCH 11/14] remove old commented code --- libraries/pet/pet.lua | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua index f1d43d29..10e270d7 100644 --- a/libraries/pet/pet.lua +++ b/libraries/pet/pet.lua @@ -133,38 +133,6 @@ ftype.fields.automaton.type.fields.inventory.type.fields.has_attachment = { end, } ---[[ -ftype.fields.automaton.type.fields.heads_available = { - get = function(data) - return setmetatable({}, { - __index = function(t, k) - return data.available_heads[k - 0x2000] - end, - }) - end, -} - -ftype.fields.automaton.type.fields.frames_available = { - get = function(data) - return setmetatable({}, { - __index = function(t, k) - return data.available_frames[k - 0x2020] - end, - }) - end, -} - -ftype.fields.automaton.type.fields.attach_available = { - get = function(data) - return setmetatable({}, { - __index = function(t, k) - return data.available_attach[k - 0x2100] - end, - }) - end, -} ---]] - return data --[[ From b0a3112e69a69f03add5f8e5dce2deb1d117b7d5 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sun, 18 Jul 2021 09:39:41 -0400 Subject: [PATCH 12/14] remove unnessary estimation of auto HP/MP --- libraries/pet_service/pet_service.lua | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 4b44ed7d..11823fee 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -137,17 +137,7 @@ packet.incoming:register_init({ data.automaton.chr_base = p.chr data.automaton.chr_bonus = 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 + data.automaton.active = data.active and (data.name == data.automaton.name) }) --[[ From 615b5fa3edd292e81515ca76e2f8b8a63e69df5c Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Sun, 18 Jul 2021 09:56:17 -0400 Subject: [PATCH 13/14] restore missing 'end' --- libraries/pet_service/pet_service.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 11823fee..247ab8ba 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -138,6 +138,7 @@ packet.incoming:register_init({ data.automaton.chr_bonus = p.chr_modifier data.automaton.active = data.active and (data.name == data.automaton.name) + end, }) --[[ From 44ec8ef3b70b4d9979682e8fd61377ffe07cabc5 Mon Sep 17 00:00:00 2001 From: John S Hobart Date: Thu, 30 Dec 2021 19:45:31 -0500 Subject: [PATCH 14/14] remote automaton related fields --- libraries/pet/pet.lua | 120 -------------------------- libraries/pet_service/pet_service.lua | 80 ----------------- 2 files changed, 200 deletions(-) diff --git a/libraries/pet/pet.lua b/libraries/pet/pet.lua index 10e270d7..ffb8a8ab 100644 --- a/libraries/pet/pet.lua +++ b/libraries/pet/pet.lua @@ -13,126 +13,6 @@ ftype.fields.target_entity = { end, } -ftype.fields.automaton.type.fields.equipment.type.fields.head = { - get = function(data) - return items[data.head_id] - end, -} - -ftype.fields.automaton.type.fields.equipment.type.fields.frame = { - get = function(data) - return items[data.frame_id] - end, -} - -ftype.fields.automaton.type.fields.equipment.type.fields.attachments = { - get = function(data) - return setmetatable({}, { - __index = function(t, k) - local item_id = data.attachment_ids[k] - if item_id == 0 then - return nil - else - return items[data.attachment_ids[k]] - end - end, - }) - end, -} - -ftype.fields.automaton.type.fields.inventory.type.fields.heads = { - get = function(data) - local t = {} - local i - for i = 0, 8 do - if data.automaton.inventory._heads[i] then - table:append(t,items[i+0x2000]) - end - end - end -} - -ftype.fields.automaton.type.fields.inventory.type.fields.heads = { - get = function(data) - local t = {} - local i - for i = 0, 21 do - if data.automaton.inventory._heads[i] then - table:append(t,items[i+0x2020]) - end - end - end -} - -ftype.fields.automaton.type.fields.inventory.type.fields.heads = { - get = function(data) - local t = {} - local i - for i = 0, 31 do - if data.automaton.inventory._heads[i] then - table:append(t,items[i+0x2020]) - end - end - end -} - -ftype.fields.automaton.type.fields.inventory.type.fields.attachments = { - get = function(data) - local t = {} - local i - for i = 0, 255 do - if data.automaton.inventory._attachments[i] then - table:append(t,items[i+0x2100]) - end - end - end -} - -ftype.fields.automaton.type.fields.inventory.type.fields.has_head = { - data = function(_, item) - local id = nil - if type(item) == 'number' then - id = item - elseif type(item) == 'table' and item.id then - id = item.id - end - if id and id >= 0x2000 and id < 0x2020 then - return data.automaton.inventory._heads[id-0x2000] - end - return nil - end, -} - -ftype.fields.automaton.type.fields.inventory.type.fields.has_frame = { - data = function(_, item) - local id = nil - if type(item) == 'number' then - id = item - elseif type(item) == 'table' and item.id then - id = item.id - end - if id and id >= 0x2020 and id < 0x2040 then - return data.automaton.inventory._frames[id-0x2020] - end - return nil - end, -} - -ftype.fields.automaton.type.fields.inventory.type.fields.has_attachment = { - data = function(_, item) - local id = nil - if type(item) == 'number' then - id = item - elseif type(item) == 'table' and item.id then - id = item.id - end - if id and id >= 0x2100 and id < 0x2200 then - return data.automaton.inventory._attachments[id-0x2100] - end - return false - end, -} - return data --[[ diff --git a/libraries/pet_service/pet_service.lua b/libraries/pet_service/pet_service.lua index 247ab8ba..3dc4e9e3 100644 --- a/libraries/pet_service/pet_service.lua +++ b/libraries/pet_service/pet_service.lua @@ -16,44 +16,6 @@ local data = server.new(struct.struct({ mp_percent = {struct.int32}, tp = {struct.int32}, active = {struct.bool}, - automaton = {struct.struct({ - active = {struct.bool}, - equipment = {struct.struct({ - head_id = {struct.int32}, - frame_id = {struct.int32}, - attachment_ids = {struct.int32[12]}, - })}, - inventory = {struct.struct({ - _heads = {struct.bool[32]}, - _frames = {struct.bool[32]}, - _attachments = {struct.bool[256]}, - })}, - name = {struct.string(0x10)}, - hp = {struct.int32}, - hp_max = {struct.int32}, - mp = {struct.int32}, - mp_max = {struct.int32}, - melee = {struct.int32}, - melee_max = {struct.int32}, - ranged = {struct.int32}, - ranged_max = {struct.int32}, - magic = {struct.int32}, - magic_max = {struct.int32}, - str_base = {struct.int32}, - str_bonus = {struct.int32}, - dex_base = {struct.int32}, - dex_bonus = {struct.int32}, - vit_base = {struct.int32}, - vit_bonus = {struct.int32}, - agi_base = {struct.int32}, - agi_bonus = {struct.int32}, - int_base = {struct.int32}, - int_bonus = {struct.int32}, - mnd_base = {struct.int32}, - mnd_bonus = {struct.int32}, - chr_base = {struct.int32}, - chr_bonus = {struct.int32}, - })} })) packet.incoming:register_init({ @@ -97,48 +59,6 @@ packet.incoming:register_init({ end end end, - [{0x044,0x12}] = function(p) - data.automaton.equipment.head_id = p.automaton_head + 0x2000 - data.automaton.equipment.frame_id = p.automaton_frame + 0x2000 - local i - for i=0, 11 do - data.automaton.equipment.attachment_ids[i] = p.attachments[i] + 0x2100 - end - for i = 0, 31 do - data.automaton.inventory._heads[i] = p.available_heads[i] - data.automaton.inventory._frames[i] = p.available_frames[i] - end - for i = 0, 255 do - data.automaton.inventory._attachments[i] = p.available_attach[i] - end - 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_base = p.str - data.automaton.str_bonus = p.str_modifier - data.automaton.dex_base = p.dex - data.automaton.dex_bonus = p.dex_modifier - data.automaton.vit_base = p.vit - data.automaton.vit_bonus = p.vit_modifier - data.automaton.agi_base = p.agi - data.automaton.agi_bonus = p.agi_modifier - data.automaton.int_base = p.int - data.automaton.int_bonus = p.int_modifier - data.automaton.mnd_base = p.mnd - data.automaton.mnd_bonus = p.mnd_modifier - data.automaton.chr_base = p.chr - data.automaton.chr_bonus = p.chr_modifier - - data.automaton.active = data.active and (data.name == data.automaton.name) - end, }) --[[