Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public bool ProcessMessage(NetMessage message)
 {
     return(message.Match()
            .With <PhysicsWorldDataMessage>((physics) =>
     {
         MapInstance.Instance.Initialize(
             physics.PtmRatio,
             physics.GravityX,
             physics.GravityY,
             physics.VelocityIte,
             physics.PositionIte);
         Logger.Debug("Physics data received");
     })
            .With <ClientControlledObjectMessage>((m) =>
     {
         WorldManager.Instance.ControlledObjectId = m.ObjectId;
     })
            .With <EntitySpawMessage>((entitySpawn) =>
     {
         var entity = EntityFactory.Instance.CreateFromNetwork(entitySpawn.Type, entitySpawn.SubType, entitySpawn.EntityData);
         if (entity != null)
         {
             AddGameObject(entity);
             Logger.Debug("[entity]");
             Logger.Debug("id=" + entity.Id);
             Logger.Debug("position=" + entity.InitialPosition);
             var animated = entity as AnimatedEntity;
             if (animated != null)
             {
                 Logger.Debug("Animation stand for entity : " + entity.Id);
                 animated.StartAnimation(Animation.STAND);
             }
         }
     })
            .With <EntityDestroyMessage>(entityDestroyed =>
     {
         MapInstance.Instance.RemoveGameObject(entityDestroyed.ObjectId);
     })
            .With <WorldStateSnapshotMessage>((m) =>
     {
         var snapshot = new WorldStateSnapshot();
         using (var stream = new MemoryStream(m.WorldStateData))
         {
             using (var reader = new BinaryReader(stream))
             {
                 snapshot.FromNetwork(reader);
             }
         }
         WorldManager.Instance.AddWorldStateSnapshot(snapshot);
     })
            .Matched);
 }