Beispiel #1
0
        public void Initialize()
        {
            Log.Info($"Map is a {info.boundsShape} shape");
            foreach (EntityInstanceInfo spawnInfo in info.entities)
            {
                EntityInfo entityInfo = entityService.GetEntityInfo(spawnInfo.type);
                if (entityInfo == null)
                {
                    Log.Warning($"Map.Initialize: Initializing map {identity}, no entity of type {{{spawnInfo.type}}} found!");
                    continue;
                }

                Log.Verbose($"Map.Initialize: {identity} creating entity for {spawnInfo.type} at T{ spawnInfo.position } R{spawnInfo.rotation} S {spawnInfo.scale}");
                Entity entity = entityService.CreateEntity();
                Guid   id     = entity.guid;

                TRS trs = entity.AddComponent <TRS>();
                trs.position = spawnInfo.position;
                trs.rotation = spawnInfo.rotation;
                trs.scale    = spawnInfo.scale;

                OnMap onMap = entity.AddComponent <OnMap>();
                onMap.mapId            = name;
                onMap.mapInstanceIndex = instanceIndex;

                foreach (var comp in entityInfo.components)
                {
                    var type = entityService.GetCompType(comp.type);

                    if (type != null)
                    {
                        Comp c = entityService.AddComponent(id, type);
                        Json.ReflectInto(comp.data, c);
                        Log.Info($"Initialized Component: {c}");
                    }
                }

                if (entityInfo.global)
                {
                    globalIds.Add(id);
                    globalEntities.Add(entity);
                }
                else
                {
                    RequireCell(CellPositionFor(spawnInfo.position)).AddEntity(id);
                }
            }
        }
Beispiel #2
0
        /// <summary> RPC, Client -> Server. Requests the client's entity get moved </summary>
        /// <param name="msg"> RPC Message info </param>
        public void RequestMove(RPCMessage msg)
        {
#if !UNITY
            if (isMaster)
            {
                // Id, position, rotation
                if (msg.numArgs != 3)
                {
                    return;
                }
                Guid    id  = Unpack.Base64 <Guid>(msg[0]);
                Vector3 pos = Unpack.Base64 <Vector3>(msg[1]);
                Vector3 rot = Unpack.Base64 <Vector3>(msg[2]);
                Log.Debug($"Getting move request for {id} / {pos} / {rot}");

                // Check that requester owns the entity they are requesting to move
                // right now, just a direct id check
                if (id != msg.sender.id)
                {
                    return;
                }

                Entity entity = entityService[id];
                if (entity != null)
                {
                    OnMap onMap = entity.GetComponent <OnMap>();
                    if (onMap != null)
                    {
                        Map map = GetMap(onMap.mapId, onMap.mapInstanceIndex);

                        Log.Debug($"Forwarding move request to map {onMap.mapId} for {id} / {pos} / {rot}");
                        map?.Move(id, pos, rot, false);
                    }
                }
            }
#endif
        }