Last change
on this file since 52f778b was 52f778b, checked in by dportnoy <dmp1488@…>, 15 years ago |
Added necessary text files, better error logging, and allowed the struct file to specify where players spawn upon login.
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[057edef] | 1 | import java.util.*;
|
---|
| 2 |
|
---|
[4fbc6ff] | 3 | /*
|
---|
| 4 | * This thread handles events in the world such as monster movement and player movement and other things that do not require player input. It
|
---|
| 5 | * also sends information to all players to notify them of changes in the world.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[057edef] | 8 | public class ProcessingThread extends Thread {
|
---|
| 9 | LostHavenServer server;
|
---|
| 10 |
|
---|
| 11 | public ProcessingThread(LostHavenServer main) {
|
---|
| 12 | super("ProcessingThread");
|
---|
| 13 | server = main;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public void run() {
|
---|
| 17 | while(server.running) {
|
---|
| 18 | updateWorld();
|
---|
| 19 | //sendInfo();
|
---|
| 20 | try {
|
---|
| 21 | Thread.sleep(1);
|
---|
| 22 | }catch(InterruptedException ie) {
|
---|
| 23 | ie.printStackTrace();
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | private void updateWorld() {
|
---|
| 29 | Iterator<String> iter = server.orderedOnline.iterator();
|
---|
| 30 | Player p;
|
---|
| 31 | Point loc, target;
|
---|
| 32 |
|
---|
| 33 | while(iter.hasNext()) {
|
---|
| 34 | p = server.registered.get(iter.next());
|
---|
| 35 | loc = p.getLoc();
|
---|
| 36 | target = p.getTarget();
|
---|
| 37 |
|
---|
[52f778b] | 38 | if((System.currentTimeMillis()-p.getLastMoved())>=10) {
|
---|
[057edef] | 39 | if(Point.dist(loc, target) <= p.getSpeed())
|
---|
| 40 | p.setLoc(target);
|
---|
| 41 | else {
|
---|
| 42 | int xChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getX()-loc.getX())/Point.dist(loc, target)/20).intValue();
|
---|
| 43 | int yChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getY()-loc.getY())/Point.dist(loc, target)/20).intValue();
|
---|
| 44 |
|
---|
| 45 | p.setLoc(new Point(p.getLoc().getX()+xChange, p.getLoc().getY()+yChange));
|
---|
| 46 | }
|
---|
| 47 | p.setLastMoved(System.currentTimeMillis());
|
---|
| 48 | server.sendAll(MessageType.Movement, p.getName()+" "+p.getLoc().toString());
|
---|
[52f778b] | 49 | }
|
---|
[057edef] | 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.