• R/O
  • SSH
  • HTTPS

mmosf: 提交


Commit MetaInfo

修訂104 (tree)
時間2010-02-28 23:18:12
作者msz006

Log Message

クライアント側移動プロトコル修正

Change Summary

差異

--- server/trunk/src/jp/sourceforge/mmosf/server/ProcessMove.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/ProcessMove.java (nonexistent)
@@ -1,164 +0,0 @@
1-/*
2- * Copyright (c) 2007, MMO Server Framework Project
3- *
4- * All rights reserved.
5- *
6- * Redistribution and use in source and binary forms, with or without modification,
7- * are permitted provided that the following conditions are met:
8- *
9- * Redistributions of source code must retain the above copyright notice,
10- * this list of conditions and the following disclaimer.
11- *
12- * Redistributions in binary form must reproduce the above copyright notice,
13- * this list of conditions and the following disclaimer in the documentation
14- * and/or other materials provided with the distribution.
15- *
16- * Neither the name of the MMO Server Framework Project nor the names of its
17- * contributors may be used to endorse or promote products derived from this
18- * software without specific prior written permission.
19- *
20- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31- */
32-
33-package jp.sourceforge.mmosf.server;
34-
35-import java.io.IOException;
36-
37-import jp.sourceforge.mmosf.server.object.Mob;
38-import jp.sourceforge.mmosf.server.object.MoveObject;
39-import jp.sourceforge.mmosf.server.object.Moving;
40-import jp.sourceforge.mmosf.server.object.MovingVector;
41-import jp.sourceforge.mmosf.server.object.PlayerCharactor;
42-import jp.sourceforge.mmosf.server.object.Position;
43-import jp.sourceforge.mmosf.server.object.Vector;
44-import jp.sourceforge.mmosf.server.packet.MovePacket;
45-import jp.sourceforge.mmosf.server.packet.Packet;
46-import jp.sourceforge.mmosf.server.packet.PacketFactory;
47-import jp.sourceforge.mmosf.server.packet.PacketFormatException;
48-
49-public class ProcessMove {
50- /**
51- *
52- */
53- private final MatchingServer matchingServer;
54- private Perception perception;
55-
56- public ProcessMove(MatchingServer matchingServer, Perception perception) {
57- super();
58- this.matchingServer = matchingServer;
59- this.perception = perception;
60- }
61-
62- public void process(Packet packet,PlayerCharactor pc) throws PacketFormatException, IOException{
63-// pc.moving.move(pc, this);
64-// Position oldPos = pc.moving.getPosition();
65- move(pc,pc.moving, true);
66-// pc.setVector(Vector.ZERO);
67-
68- Vector v = ((MovePacket)packet).getVector();
69-// System.out.println("input vector = "+v.toString());
70-// if(v.isZero()){
71-// log.trace("zero");
72-// }
73- pc.moving.setDirection(v.getDirection());
74- MoveObject mo = null;
75- if(v.isZero() && !isZero(((MovePacket)packet))){
76- mo = new MoveObject(pc.moving.getPosition(),((MovePacket)packet).getPosition(),pc.getId());
77- }else{
78- mo = new MoveObject(pc.moving.getPosition(),Vector.toBaseVector(v),pc.getId());
79- }
80- if(!perception.isEnableMove(mo)){
81- pc.setVector(Vector.ZERO);
82-// assert(v.equals(Vector.ZERO));
83-// Packet sendPacket = PacketFactory.createMoveResponsePacket(pc.moving.getPosition(),Vector.ZERO,pc.moving.getDirection(),0);
84-// System.out.println("move:"+pc.moving.toString());
85- MovingVector mv = new MovingVector(pc.moving.getPosition());
86- mv.setVector(Vector.ZERO);
87- mv.setDirection(pc.moving.getDirection());
88- mv.setSpeed(pc.moving.getSpeed());
89-// Packet sendPacket = PacketFactory.createMoveResponsePacket(pc.moving);
90- Packet sendPacket = PacketFactory.createMoveResponsePacket(mv);
91- pc.conn.send(sendPacket);
92-// System.out.println("can't move.");
93- return;
94- }
95-// Position next = new Position(pc.getPos());
96-// next.move(v);
97-// next.move(v);
98-// next.move(v);
99-// Position next = pc.getPos().getMoved(new Vector(v,3));
100-
101-// Packet response = PacketFactory.createMoveResponsePacket(pc.moving.getPosition(), v,pc.moving.getDirection(), pc.moving.getSpeed());
102- //進行方向以外の向きで移動するにはdirectionを指定する
103- if(pc.getCombatSate().isAgressive()){
104- Mob target = pc.getCombatSate().getTarget();
105- Vector direction = pc.moving.getPosition().getVector(target.moving.getPosition());
106- pc.moving.setDirection(direction.getDirection());
107- System.out.println("vec1:"+direction);
108- System.out.println("dir1:"+direction.getDirection());
109- pc.moving.setType(Moving.TYPE_ORIENTED);
110- }
111- pc.setVector(v);
112-// Packet response = PacketFactory.createMoveResponsePacket(pc.moving.getPosition(), v,pc.moving.getDirection(), pc.moving.getSpeed());
113-// System.out.println("move:"+pc.moving.toString());
114-// MovingVector mv = (MovingVector)pc.moving.duplicate();
115-// mv.setVector(v);
116- Packet response = PacketFactory.createMoveResponsePacket(pc.moving);
117-// Packet response = PacketFactory.createMoveResponsePacket(mv);
118- pc.conn.send(response);
119-
120-// System.out.println("move.");
121-
122-// if(!pc.getVector().equals(v)){
123-// pc.setMoveQueue(v);
124-// pc.setVector(v);
125-// move(pc);
126-// }else{
127-// }
128-
129- }
130-
131- private boolean isZero(MovePacket movePacket) throws PacketFormatException {
132- return movePacket.getPosition().getX() == 0 && movePacket.getPosition().getY() == 0 && movePacket.getPosition().getZ() == 0;
133- }
134-
135- public void move(Mob mob,Moving moving, boolean isReceive){
136- Position oldPos = moving.getPosition();
137- updateTime(moving, isReceive);
138- //*
139- if(mob.getCombatSate().isAgressive()){
140- Mob target = mob.getCombatSate().getTarget();
141- Vector direction = moving.getPosition().getVector(target.getPosition());
142- moving.setDirection(direction.getDirection());
143- moving.setType(Moving.TYPE_ORIENTED);
144-// System.out.println("vec1:"+direction);
145-// System.out.println("dir1:"+direction.getDirection());
146- }
147- //*/
148- moving.move(perception);
149- if (moving.getPosition().equals(oldPos)){
150- return;
151- }
152-
153- this.matchingServer.shard.getSyncZone(mob.getPosition()).move(mob,oldPos, mob.getPosition());
154- }
155-
156- protected void updateTime(Moving moving, boolean isReceive) {
157- if(isReceive){
158- moving.updateTime(System.currentTimeMillis()-200);
159- }else{
160- moving.updateTime(System.currentTimeMillis());
161- }
162- }
163-
164- }
\ No newline at end of file
--- server/trunk/src/jp/sourceforge/mmosf/server/test/TestSmoothMove.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/test/TestSmoothMove.java (revision 104)
@@ -599,4 +599,64 @@
599599 //*/
600600 }
601601
602+ /**
603+ * 移動、停止、そのまま
604+ */
605+ @Test
606+ public void testMove9(){
607+ ProcessMove2 processMove = new ProcessMove2(getMatchingServer(),getMatchingServer());
608+
609+ Position firstPosition = new Position(1,0,1);
610+
611+ DebugConnection debugConnection = new DebugConnection();
612+ final int id = processMove.hashCode();
613+ PlayerCharactor pc = new PlayerCharactor(firstPosition.getX(),
614+ firstPosition.getY(),firstPosition.getZ(),'A',id,debugConnection);
615+ getMatchingServer().register(pc);
616+
617+ long time = System.currentTimeMillis();
618+
619+ Vector vec = Direction.EAST.getVector();
620+ Vector vec2 = Direction.SOUTH.getVector();
621+ Direction dir = Direction.EAST;
622+ Direction dir2 = Direction.SOUTH;
623+
624+ try{
625+ Packet pac = createMoveStart(vec, dir);
626+ processMove.process(pac, pc, time);
627+ processMove.move(pc, pc.moving, time);
628+
629+ Packet ret2 = debugConnection.receiveSreverResponse();
630+ assertTrue("1",ret2 instanceof MovePacket);
631+
632+ Packet pac2 = createMoveEnd();
633+
634+ processMove.process(pac2, pc, time + 10000);
635+ processMove.move(pc, pc.moving, time + 10000);
636+
637+ Packet ret3 = debugConnection.receiveSreverResponse();
638+ assertTrue("2",ret3 instanceof MovePacket);
639+ MovePacket retMove2 = (MovePacket)ret3;
640+ assertTrue(retMove2.getPosition().equals(firstPosition));
641+ assertTrue(retMove2.getVector().equals(Vector.ZERO));
642+ assertTrue(retMove2.getDirection().equals(dir));
643+ assertTrue(retMove2.getNext().equals(pc.getPosition()));
644+
645+ for(int i=0;i<100;i++){
646+ processMove.move(pc, pc.moving, time + 10000 + i* 200);
647+ Thread.sleep(200);
648+// Packet ret4 = debugConnection.receiveSreverResponse();
649+// assertTrue(ret2 instanceof MovePacket);
650+ assertTrue("past "+i*200,retMove2.getNext().equals(pc.getPosition()));
651+
652+ }
653+
654+ }catch(Exception e){
655+ e.printStackTrace();
656+ fail(e.toString());
657+ }finally{
658+ getMatchingServer().unregister(pc);
659+ }
660+ }
661+
602662 }
--- server/trunk/src/jp/sourceforge/mmosf/server/loginserver/SingleProcessThread2.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/loginserver/SingleProcessThread2.java (revision 104)
@@ -1,3 +1,35 @@
1+/*
2+ * Copyright (c) 2007-2010, MMO Server Framework Project
3+ *
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without modification,
7+ * are permitted provided that the following conditions are met:
8+ *
9+ * Redistributions of source code must retain the above copyright notice,
10+ * this list of conditions and the following disclaimer.
11+ *
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * Neither the name of the MMO Server Framework Project nor the names of its
17+ * contributors may be used to endorse or promote products derived from this
18+ * software without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
133 package jp.sourceforge.mmosf.server.loginserver;
234
335 import java.util.concurrent.BlockingQueue;
--- server/trunk/src/jp/sourceforge/mmosf/server/MatchingServer.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/MatchingServer.java (revision 104)
@@ -598,6 +598,8 @@
598598 processMove.move(pc, pc.moving, false);
599599 log.trace("move pc:"+pc.c);
600600
601+ System.out.println("pc:"+pc.getPosition());
602+
601603 if(pc.getCombatSate().isAgressive()){
602604 attack(pc);
603605 }
--- server/trunk/src/jp/sourceforge/mmosf/server/mobmove/MoveData.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/mobmove/MoveData.java (revision 104)
@@ -107,6 +107,14 @@
107107 return data;
108108 }
109109
110+ public static MoveData createStart(int commandId, Vector vec, Direction drc, double speed, long startTime) {
111+ MoveData data;
112+
113+ data = new MoveData(commandId, startTime, vec, drc, speed);
114+
115+ return data;
116+ }
117+
110118 public static MoveData createEnd(Mob mob, MovePacket movePacket,long endTime) throws PacketFormatException {
111119 MoveData data;
112120 // data = new MoveData(movePacket.getCommandId(), movePacket.getNext(),endTime);
@@ -118,6 +126,18 @@
118126 return data;
119127 }
120128 //*
129+ public static MoveData createEnd(int commandId, long endTime) {
130+ MoveData data;
131+// data = new MoveData(movePacket.getCommandId(), movePacket.getNext(),endTime);
132+ data = new MoveData(commandId, INVALID_TIME, Vector.ZERO, null,0);
133+
134+// data.setEnd(movePacket.getNext());
135+ data.setEndTime(endTime);
136+
137+ return data;
138+ }
139+
140+
121141 private MoveData(int moveid, long startTme, Vector vector, Direction direction, double speed) {
122142 super();
123143 this.moveid = moveid;
--- server/trunk/src/jp/sourceforge/mmosf/server/mobmove/MoveDataQueue.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/mobmove/MoveDataQueue.java (revision 104)
@@ -103,5 +103,9 @@
103103 }
104104 return null;
105105 }
106+
107+ public MoveData find(int id) {
108+ return get(id);
109+ }
106110
107111 }
--- server/trunk/src/jp/sourceforge/mmosf/server/mobmove/ProcessMove2.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/mobmove/ProcessMove2.java (revision 104)
@@ -134,7 +134,7 @@
134134 long span = nowTime - moveData.getStartTme();
135135
136136 Position newPos = moveData.getMovedPosition(span);
137- newPos = new Position(newPos.getX()+0.5,newPos.getY()+0.5,newPos.getZ()+0.5);
137+ // newPos = new Position(newPos.getX()+0.5,newPos.getY()+0.5,newPos.getZ()+0.5);
138138
139139 MoveObject mo = new MoveObject(oldPos,newPos,mob.getId());
140140 if(!perception.isEnableMove(mo)){
--- server/trunk/src/jp/sourceforge/mmosf/server/object/test/TestBoundBox.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/object/test/TestBoundBox.java (revision 104)
@@ -1,11 +1,10 @@
11 package jp.sourceforge.mmosf.server.object.test;
22
3+import static org.junit.Assert.assertEquals;
34 import jp.sourceforge.mmosf.server.object.Direction;
45 import jp.sourceforge.mmosf.server.object.Position;
5-import jp.sourceforge.mmosf.server.object.Vector;
66
77 import org.junit.Test;
8-import static org.junit.Assert.*;
98
109 public class TestBoundBox {
1110
--- server/trunk/src/jp/sourceforge/mmosf/server/object/Position.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/object/Position.java (revision 104)
@@ -171,7 +171,7 @@
171171 // if(!isValid){
172172 // return "not initialize.";
173173 // }
174- return "x="+getX()+",y="+getY()+",z="+getZ()+",zone="+zoneID+",shard="+shardID;
174+ return "x="+x+",y="+y+",z="+z+",zone="+zoneID+",shard="+shardID;
175175 }
176176
177177 public String toString2() {
@@ -267,6 +267,11 @@
267267 // checkValid();
268268 return (int)x;
269269 }
270+
271+ public double getdX() {
272+// checkValid();
273+ return x;
274+ }
270275 // public void setY(int y) {
271276 // this.y = y;
272277 // }
@@ -274,6 +279,11 @@
274279 // checkValid();
275280 return (int)y;
276281 }
282+
283+ public double getdY() {
284+// checkValid();
285+ return y;
286+ }
277287 // public void setZ(int z) {
278288 // this.z = z;
279289 // }
@@ -281,6 +291,11 @@
281291 // checkValid();
282292 return (int)z;
283293 }
294+
295+ public double getdZ() {
296+// checkValid();
297+ return z;
298+ }
284299 /*
285300 public void set(int x, int y , int z){
286301 this.x = x;
--- server/trunk/src/jp/sourceforge/mmosf/server/object/Mob.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/object/Mob.java (revision 104)
@@ -37,8 +37,6 @@
3737
3838
3939 import java.util.HashMap;
40-import java.util.LinkedList;
41-import java.util.List;
4240 import java.util.Map;
4341
4442 import jp.sourceforge.mmosf.server.object.action.Action;
--- server/trunk/src/jp/sourceforge/mmosf/server/object/MovingVector.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/object/MovingVector.java (revision 104)
@@ -381,7 +381,7 @@
381381
382382 protected void normalize(){
383383 Position pos = getPosition();
384- setPosition(new Position(pos.getX()+0.5,pos.getY()+0.5,pos.getZ()+0.5));
384+// setPosition(new Position(pos.getX()+0.5,pos.getY()+0.5,pos.getZ()+0.5));
385385 // setPosition(new Position(pos.getX(),pos.getY(),pos.getZ()));
386386 }
387387
--- server/trunk/src/jp/sourceforge/mmosf/server/packet/PacketFactory.java (revision 103)
+++ server/trunk/src/jp/sourceforge/mmosf/server/packet/PacketFactory.java (revision 104)
@@ -313,18 +313,6 @@
313313 return packet;
314314 }
315315
316- public static Packet createMovePacket(Position pos){
317- MovePacket packet = (MovePacket)createPacket(Type.MOVE);
318- if(packet == null){
319- return null;
320- }
321-
322- packet.setVector(Vector.ZERO);
323- packet.setPosition(pos);
324- packet.setTime(System.currentTimeMillis());
325-
326- return packet;
327- }
328316
329317 public static Packet createMovePacket(Position startPosition, Position endPosition, Vector vec, Direction dir, int move_id){
330318 MovePacket packet = (MovePacket)createPacket(Type.MOVE);
@@ -383,6 +371,18 @@
383371
384372 return packet;
385373 }
374+
375+ public static Packet createMenuRequestPaket(Integer mobId){
376+ MenuPacket packet = (MenuPacket)createPacket(Type.MENU);
377+ if(packet == null){
378+ return null;
379+ }
380+
381+ packet.setInt(MenuPacket.TYPE, MenuPacket.TYPE_MOB);
382+ packet.setInt(MenuPacket.MOB_ID, mobId.intValue());
383+
384+ return packet;
385+ }
386386 //*/
387387 public static Packet createMenuRequestPaket(int slot/*,Item item*/){
388388 MenuPacket packet = (MenuPacket)createPacket(Type.MENU);
@@ -591,7 +591,7 @@
591591 return packet;
592592 }
593593
594- public static Packet createMovePacket(MoveData moveData) {
594+ public static Packet createMoveResponse(MoveData moveData) {
595595 MovePacket packet = (MovePacket)createPacket(Type.MOVE);
596596 if(packet == null){
597597 return null;
Show on old repository browser