Exemple #1
0
        //public Action<World> onNewWorldHook = (a) => { };
        //public Action<World> onDeleteWorldHook = (a) => { };

        //public Action<PlayerInfo> onNewMyPlayerHook = (a) => { };

        //public Action<World, PlayerInfo, Point, ActionValidity> onMoveHook = (a, b, c, d) => { };
        //public Action<World, PlayerInfo, bool> onPlayerLeaveHook = (a, b, c) => { };

        //Func<WorldInitializer, World> generateWorld;

        public Client(GlobalHost globalHost, Aggregator all, Func <WorldInitializer, World> generateWorld)
        {
            this.all = all;
            //this.generateWorld = generateWorld;

            Host = globalHost.NewHost(Client.hostName, Game.Convert(AssignProcessor),
                                      BasicInfo.GenerateHandshake(NodeRole.CLIENT), Aggregator.longInactivityWait);

            SetConnectionHook(ProcessNewConnection);

            Action <WorldInfo> subscribe = wi => MessageWorld(wi, MessageType.SUBSCRIBE);

            Action <WorldInfo> unsubscribe = wi => MessageWorld(wi, MessageType.UNSUBSCRIBE);

            TrackedWorldData data = new TrackedWorldData()
            {
                generateWorld = generateWorld, recordWorldInfo = null, subscribe = subscribe, unsubscribe = unsubscribe
            };

            worlds = new WorldDatabase(data);

            connectedPlayers = new PlayerDatabase(p => worlds.At(p).Track(), p => worlds.At(p).Untrack(),
                                                  inf => worlds.At(inf.position).SetWorldInfo(inf));
        }