root/trunk/AE-go_GameServer/src/com/aionemu/gameserver/world/WorldMap.java
| 966 | 1006 | ||
|---|---|---|---|
19 | import java.util.HashMap; | 19 | import java.util.HashMap; |
20 | import java.util.Map; | 20 | import java.util.Map; |
21 | 21 | ||
22 | import org.apache.log4j.Logger; | ||
23 | |||
22 | import com.aionemu.gameserver.model.templates.WorldMapTemplate; | 24 | import com.aionemu.gameserver.model.templates.WorldMapTemplate; |
23 | 25 | ||
24 | /** | 26 | /** |
... | ... | ||
29 | */ | 31 | */ |
30 | public class WorldMap | 32 | public class WorldMap |
31 | { | 33 | { |
34 | private static Logger log = Logger.getLogger(WorldMap.class); | ||
35 | |||
32 | private WorldMapTemplate worldMapTemplate; | 36 | private WorldMapTemplate worldMapTemplate; |
33 | 37 | ||
34 | /** | 38 | /** |
... | ... | ||
79 | int twinCount = worldMapTemplate.getTwinCount(); | 83 | int twinCount = worldMapTemplate.getTwinCount(); |
80 | return twinCount > 0 ? twinCount : 1; | 84 | return twinCount > 0 ? twinCount : 1; |
81 | } | 85 | } |
86 | |||
87 | /** | ||
88 | * Will create new instance if there are not free yet and spawn according to xml data | ||
89 | * //TODO limit | ||
90 | * //TODO dispose unused instances (lifecycle) | ||
91 | * @return | ||
92 | */ | ||
93 | public synchronized int getNextFreeInstanceIndex() | ||
94 | { | ||
95 | for(WorldMapInstance instance : instances.values()) | ||
96 | { | ||
97 | if(!instance.isInUse()) | ||
98 | return instance.getInstanceId(); | ||
99 | } | ||
100 | //create new instance | ||
101 | int nextInstanceId = instances.size() + 1; | ||
102 | log.info("Creating new instance: " + worldMapTemplate.getMapId() + " " + nextInstanceId ); | ||
103 | instances.put(nextInstanceId, new WorldMapInstance(this, nextInstanceId)); | ||
104 | world.getSpawnEngine().spawnInstance(worldMapTemplate.getMapId(), nextInstanceId); | ||
105 | |||
106 | return nextInstanceId; | ||
107 | } | ||
82 | 108 | ||
83 | /** | 109 | /** |
84 | * Return a WorldMapInstance - depends on map configuration one map may have twins instances to balance player. This | 110 | * Return a WorldMapInstance - depends on map configuration one map may have twins instances to balance player. This |
... | ... | ||
126 | } | 152 | } |
127 | return getWorldMapInstance(instanceId); | 153 | return getWorldMapInstance(instanceId); |
128 | } | 154 | } |
129 | | ||
130 | /** | ||
131 | * | ||
132 | * @return | ||
133 | */ | ||
134 | public WorldMapInstance getNextFreeInstance() | ||
135 | { | ||
136 | //TODO | ||
137 | if(worldMapTemplate.getTwinCount() !=0) | ||
138 | { | ||
139 | for(WorldMapInstance instance : instances.values()) | ||
140 | { | ||
141 | if(instance.getCurrentPlayerCount() == 0) | ||
142 | return instance; | ||
143 | } | ||
144 | } | ||
145 | return null; | ||
146 | } | ||
147 | 155 | ||
148 | /** | 156 | /** |
149 | * Returns WorldMapInstance by instanceId. | 157 | * Returns WorldMapInstance by instanceId. |
Download diff