Next thing to concider.
What states do we want and what do they do.
basic easy states, do a job and once done pop themselves:
npc interaction (once at the npc location)
travel, moving from 1 place to another (waypoint usage)
Reactive states, pushed from an update loop:
combat
healing, or part of combat?
object interaction "F", includes looting
More complex controller states, that push other states as needed:
kill: looks for mobs and pushes combat state targeting mob, only pops itself after specific time or lvl has been reached. Also monitors repair and vendor and pushes them as required.
repair, pushes travel and NPC interaction
vendor, pushes travel and NPC interaction(sell junk in bags)
questing, pushes travel and kill states when required
events (To Be Determined)
Any thoughts ?
After creating all the state files I decided it was a pain to add all the names to main.lua so I did this.
Code: Select all
local subdir = getDirectory(getExecutionPath() .. "/classes/states/");
for i,v in pairs(subdir) do
include("classes/states/"..v);
end
just adds any files in there, I could probably do a string.find for .lua to make sure no dummy.txt files are added, prob not needed though.
Ok next bit, the calling of pushing a state, not overly happy with it atm.
Code: Select all
if( event == "repair" ) then
printf("Switching to repair.\n");
stateman:pushState(RepairState());
return true;
end
So for every event we need to add in code like this, I am trying to work out a way to do it so the event does it without having to repeat the code for each state.
A table comes to mind as the easiest way I can think of, obviously the event data is still added but when it comes to actually doing the code it will be much simpler.
Code: Select all
function StateManager:handleEvent(event)
for k,events in pairs(events) do
if( event == events.name and self.stateQueue[#self.stateQueue].name ~= event ) then
print("Switching to "..event);
stateman:pushState(events.function);
return true;
end
end
end
I am sure there is probably a better way though.
Have this atm,
Code: Select all
function StateManager:handleEvent(event)
if( event == "Quit" ) then
self.running = false;
return true;
end
for k,events in pairs(events) do
if( event == events.name ) then
print("Switching to "..event);
stateman:pushState(events.func);
return true;
end
end
end
each state has this at the bottom, name differs for each state of course.
Code: Select all
table.insert(events,{name = "Vendor", func = VendorState()})
trouble is that it does the constructor code when MM starts the script, so onload as such. probably not ideal.
events table looks like this when main.lua starts.
Code: Select all
table: 006E5970
1: table: 00714CC8
name: Combat
func: table: 00714D18
lasttime: 1343698066
name: Combat state
prevtime: 0
count2: 0
count: 0
newbattle: false
2: table: 006E43F8
name: Events
func: table: 006E4448
prevtime: 0
lasttime: 1343698066
name: Event state
3: table: 006E3AA0
name: Heal
func: table: 006E3AF0
prevtime: 0
lasttime: 1343698066
name: Heal state
4: table: 007194C8
name: Kill
func: table: 00719518
prevtime: 0
lasttime: 1343698066
name: Kill state
5: table: 006E32C8
name: Loot
func: table: 006E3318
prevtime: 0
lasttime: 1343698066
name: Loot state
6: table: 006E4380
name: Npc
func: table: 006E43D0
prevtime: 0
lasttime: 1343698066
name: Npc state
7: table: 007197C0
name: Object
func: table: 007198D8
prevtime: 0
lasttime: 1343698066
name: Object state
8: table: 006E3A28
name: Quest
func: table: 006E3A78
prevtime: 0
lasttime: 1343698066
name: Quest state
9: table: 006E4718
name: Repair
func: table: 006E4858
prevtime: 0
lasttime: 1343698066
name: Repair state
10: table: 006A37B8
name: Travel
func: table: 006A3B28
prevtime: 0
lasttime: 1343698066
name: Travel state
11: table: 00719AB8
name: Vendor
func: table: 00719B08
prevtime: 0
lasttime: 1343698066
name: Vendor state
12: table: 006E31B0
name: Waypoint
func: table: 006E3200
name: Waypoint state
lasttime: 1343698066
index: 1
waypoints: table: 006E54C0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
It still does the code fine but the constructors are all done at startup, maybe not so bad after all after more thought.
Code: Select all
Current state: Waypoint state
Waypoints advanced to #2
Waypoints advanced to #3
Waypoints advanced to #4
Keypressed N
Switching to Npc
Npc timer: 6
Waypoints advanced to #5
Waypoints advanced to #6
Keypressed N
Switching to Npc
back at Npcing
Npc timer: 1
Npc timer: 2
Npc timer: 3
Npc timer: 4
Waypoints advanced to #7
Waypoints advanced to #8
Waypoints advanced to #1
Keypressed N
Switching to Npc
back at Npcing
Npc timer: 1
Npc timer: 2
Npc timer: 3
Npc timer: 4
Waypoints advanced to #2
Waypoints advanced to #3
Waypoints advanced to #4
Waypoints advanced to #5
Waypoints advanced to #6
V 8
keypresses
C,T,N,V
(Combat,Travel,Npc,Vendor)
combat will randomly push heal and combat does max 10 seconds of actual combat not including healing time.
Also in main.lua if you uncomment --update() it has real usage for RoM, just make sure 1 RoM client is running. It will monitor HP and in combat flag.
If hp drops below 70% it will push heal state, if in combat it will push combat state, combat state will still randomly push heal state aswell.
could do this I guess which will refresh the constructor when the state is pushed
Code: Select all
stateman:pushState(events.func);
self.stateQueue[#self.stateQueue]:constructor();