Rooms and matchmaking debugging

* Dorm is not properly cloned (fix this)
* Basic matchmaking implementation
* Goto route
* Goto DormRoom
This commit is contained in:
2025-04-02 14:10:01 -04:00
parent 27b3754330
commit bcee414004
6 changed files with 237 additions and 86 deletions

View File

@@ -15,6 +15,8 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
import Rooms from "../content/rooms.ts";
import { RoomAccessibility, RoomState } from "../content/roomtypes.ts";
import { Profile } from "../profiles.ts";
import Instances from "./instances.ts";
import { MatchmakingErrorCode, RoomInstance } from "./types.ts";
@@ -25,7 +27,7 @@ interface MatchmakingOptions {
roomName: string,
subRoomName?: string,
private?: boolean,
instanceId?: string,
instanceId?: number,
profile: Profile
}
@@ -51,30 +53,55 @@ class MatchmakingBase {
loginLocks.delete(prof.getId());
}
matchmake(options: MatchmakingOptions) {
async matchmake(options: MatchmakingOptions) {
if (options.instanceId) {
// get instance
// if instance exists, check private
}
/*
if roomname is dormroom, create the profile's dormroom if it does not exist
set the target room to the profile's dormroom id
const instance = Instances.getInstance(options.instanceId);
if (instance) {
get all public instances for roomname
filter out private and full instances
if a subroomname was specified, filter out subrooms that are not that subroom
if (Instances.playerIsInInstance(options.profile, instance)) return { errorCode: MatchmakingErrorCode.AlreadyInTargetInstance };
else {
if (instance.isFull) return { errorCode: MatchmakingErrorCode.InsufficientSpace }
else if (instance.isPrivate) return { errorCode: MatchmakingErrorCode.RoomInstanceIsPrivate };
Instances.setPlayerInstance(options.profile, instance);
return { errorCode: MatchmakingErrorCode.Success, roomInstance: instance };
}
} else return { errorCode: MatchmakingErrorCode.NoSuchGame }
} else {
const targetRoom = options.roomName !== 'DormRoom' ? await Rooms.getByName(options.roomName) : await Rooms.getProfileDormDefault(options.profile);
if (!targetRoom) return { errorCode: MatchmakingErrorCode.NoSuchRoom };
if (targetRoom.Room.Accessibility == RoomAccessibility.Private) return { errorCode: MatchmakingErrorCode.RoomIsPrivate };
if (targetRoom.Room.State !== RoomState.Active) return { errorCode: MatchmakingErrorCode.RoomIsNotActive };
const roomId = targetRoom.Room.RoomId;
let allInstances = Instances.getAllRoomInstances(roomId).values().toArray().filter(instance => !instance.isPrivate && !instance.isFull);
const subroomId = targetRoom.Scenes.find(scene => scene.Name == options.subRoomName)?.RoomSceneId;
if (subroomId) allInstances = allInstances.filter(instance => instance.subRoomId == subroomId);
const foundInstance = allInstances[Math.floor(Math.random() * allInstances.length)];
if (!foundInstance) {
const matchmakeableSubrooms = targetRoom.Scenes.filter(scene => scene.CanMatchmakeInto);
const newInstance = Instances.createInstance({
Room: targetRoom,
SceneIndex: Math.floor(Math.random() * matchmakeableSubrooms.length),
FirstPlayer: options.profile
});
return { errorCode: MatchmakingErrorCode.Success, roomInstance: newInstance };
} else {
Instances.setPlayerInstance(options.profile, foundInstance);
return { errorCode: MatchmakingErrorCode.Success, roomInstance: foundInstance };
}
pick an instance of the given instances at random
if none exist, create one
use only matchmakeable subrooms
if none are matchmakeable, go to "Home"
if "Home" does not exist, go to the first index
go to that instance
*/
}
}