-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameclient_zone_example.lua
More file actions
199 lines (162 loc) · 8.07 KB
/
Copy pathgameclient_zone_example.lua
File metadata and controls
199 lines (162 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
-- GameClient Zone Utils Example for EQMap Lua Scripts
-- This script demonstrates the new GameClient-based zone and position functionality
-- All zone/position data now comes from EQProtocol GameClient for better architecture
-- Drop this file onto the EQMap window to execute
function Main()
log:Info("=== GameClient Zone Utils Test Started ===")
log:Info("NOTE: Zone and position data now comes from EQProtocol GameClient")
-- Test the zone utility functions (now from GameClient ZoneUtils)
log:Info("=== Zone Utility Function Tests ===")
-- Test zone name to number conversion
local arenaId = ZoneNameToNumber("arena")
log:Info("Zone 'arena' has ID: " .. arenaId)
local qeynosId = ZoneNameToNumber("qeynos")
log:Info("Zone 'qeynos' has ID: " .. qeynosId)
-- Test zone number to name conversion
local zone77Name = ZoneNumberToName(77)
log:Info("Zone ID 77 is: " .. zone77Name)
local zone1Name = ZoneNumberToName(1)
log:Info("Zone ID 1 is: " .. zone1Name)
-- Test invalid zone
local invalidZone = ZoneNumberToName(99999)
log:Info("Invalid zone ID 99999 returns: " .. invalidZone)
-- Test validation functions
log:Info("=== Zone Validation Tests ===")
log:Info("Is zone ID 77 valid? " .. tostring(IsValidZoneId(77)))
log:Info("Is zone ID 99999 valid? " .. tostring(IsValidZoneId(99999)))
log:Info("Is zone name 'arena' valid? " .. tostring(IsValidZoneName("arena")))
log:Info("Is zone name 'invalidzone' valid? " .. tostring(IsValidZoneName("invalidzone")))
-- Test current zone information if zone object is available
if zone then
log:Info("=== Current Zone Information (via GameClient) ===")
log:Info("Current Zone Name: " .. (zone.Name or "Unknown"))
log:Info("Current Zone ID: " .. tostring(zone.Id or 0))
log:Info("Raw Zone Name from Client: " .. (zone.CurrentZoneName or "Unknown"))
log:Info("Zone ID from Client: " .. tostring(zone.CurrentZoneId or 0))
-- Verify the zone name/ID consistency
local expectedName = ZoneNumberToName(zone.Id)
if zone.Name == expectedName then
log:Info("✓ Zone name/ID mapping is consistent")
else
log:Info("✗ Zone name/ID mapping mismatch!")
log:Info(" Expected: " .. expectedName .. ", Got: " .. zone.Name)
end
log:Info("=== Player Location (GameClient Data) ===")
log:Info("Player Name: " .. (zone.PlayerName or "Unknown"))
log:Info("Position: " .. zone.Position)
log:Info("Full Location: " .. zone.Location)
log:Info("Player Heading: " .. string.format("%.1f", zone.Heading or 0))
log:Info("Is Moving: " .. tostring(zone.IsMoving))
-- Test some zone lookup examples
log:Info("=== Zone Lookup Examples ===")
local commonZones = {"qeynos", "freeporte", "arena", "gfaydark", "crushbone", "blackburrow"}
for i, zoneName in ipairs(commonZones) do
local zoneId = ZoneNameToNumber(zoneName)
if zoneId > 0 then
log:Info(string.format("Zone '%s' = ID %d", zoneName, zoneId))
else
log:Info(string.format("Zone '%s' not found", zoneName))
end
end
-- Distance examples with proper zone names
if zone.X and zone.Y and zone.Z then
log:Info("=== Distance Calculation Examples (GameClient) ===")
-- Example: distance to zone center (0, 0)
local distanceToCenter = zone:DistanceTo(0, 0)
log:Info(string.format("Distance to %s center (0, 0): %.2f units", zone.Name, distanceToCenter))
-- Example: check if within certain distance of spawn point
local withinSpawnRange = zone:IsWithinDistance(0, 0, 1000)
log:Info(string.format("Within 1000 units of %s center: %s", zone.Name, tostring(withinSpawnRange)))
-- 3D distance example
local distance3D = zone:DistanceTo(100, 200, zone.Z + 50)
log:Info(string.format("3D Distance to (100, 200, %.1f): %.2f units", zone.Z + 50, distance3D))
end
-- Test movement capabilities
log:Info("=== Movement System Tests ===")
log:Info("Movement system available via zone:MoveTo() and zone:StopMovement()")
log:Info("Current movement state: " .. (zone.IsMoving and "Moving" or "Stationary"))
-- Note: Uncomment the following lines to test actual movement
-- log:Info("Testing movement - moving 10 units forward...")
-- zone:MoveTo(zone.X, zone.Y + 10, zone.Z)
-- sleepSeconds(2)
-- log:Info("Stopping movement...")
-- zone:StopMovement()
-- Test sleep functions (delegated to GameClient)
log:Info("=== Sleep Function Tests (GameClient) ===")
log:Info("Testing 0.5 second sleep via zone:Sleep()...")
zone:Sleep(500) -- 500ms sleep via GameClient
log:Info("Sleep completed")
else
log:Info("Zone object not available - you need to be connected to EverQuest")
log:Info("Connect to EQ first to see current zone information")
log:Info("The zone object is now a lightweight wrapper around EQGameClient")
end
log:Info("=== Architecture Notes ===")
log:Info("* Zone class now delegates to EQGameClient in EQProtocol")
log:Info("* All position/movement data comes from GameClient")
log:Info("* ZoneUtils moved to OpenEQ.Netcode.GameClient namespace")
log:Info("* EQMap is now just UI/graphics and Lua integration")
log:Info("* GameClient handles all game logic and state")
log:Info("=== GameClient Zone Utils Test Completed ===")
return "GameClient zone utils test completed successfully"
end
-- Example function for zone-specific scripting using GameClient data
function ZoneSpecificAction()
if not zone then
log:Info("Zone not available for zone-specific actions")
return false
end
local currentZone = zone.Name
log:Info("Executing zone-specific action for: " .. currentZone)
-- Example zone-specific logic using proper zone names from GameClient
if currentZone == "arena" then
log:Info("Arena detected - could implement PvP bot behavior here")
log:Info("Current position: " .. zone.Position)
log:Info("Player heading: " .. string.format("%.1f", zone.Heading))
elseif currentZone == "qeynos" then
log:Info("Qeynos detected - could implement city/trading behavior here")
elseif currentZone == "crushbone" then
log:Info("Crushbone detected - could implement dungeon crawling here")
elseif currentZone == "gfaydark" then
log:Info("Greater Faydark detected - could implement outdoor hunting here")
else
log:Info("Zone '" .. currentZone .. "' - using default behavior")
end
return true
end
-- Example function to validate zone before performing actions
function ValidateZoneAndExecute(requiredZone, actionFunction)
if not zone then
log:Info("Zone not available - cannot validate zone")
return false
end
local currentZone = zone.Name
if currentZone ~= requiredZone then
log:Info(string.format("Zone mismatch: Expected '%s', currently in '%s'", requiredZone, currentZone))
return false
end
log:Info(string.format("Zone validated: Currently in '%s' as expected", currentZone))
if actionFunction then
return actionFunction()
end
return true
end
-- Example usage of GameClient-based zone validation
function ExampleZoneValidation()
log:Info("=== Zone Validation Example (GameClient) ===")
-- This would only execute if we're in the arena
ValidateZoneAndExecute("arena", function()
log:Info("Arena-specific action executed!")
log:Info("Arena position: " .. zone.Position)
return true
end)
-- This would only execute if we're in qeynos
ValidateZoneAndExecute("qeynos", function()
log:Info("Qeynos-specific action executed!")
log:Info("Qeynos position: " .. zone.Position)
return true
end)
end
-- Uncomment the next line to run zone-specific examples
-- ZoneSpecificAction()
-- ExampleZoneValidation()