Пример #1
0
        public DungeonDomainBuilder TrySpawnPlayer()
        {
            Optionally();
            {
                Action($"Try spawn player");
                {
                    Condition("Player needs spawn point",
                              context => context.HasState(DungeonWorldState.PlayerNeedsSpawnPoint));
                    Do((context) =>
                    {
                        var parentRoom = context.RoomStack.Peek();
                        if (parentRoom != null)
                        {
                            Debug.Log($"Spawn player in room {parentRoom.Id}\n");
                            var playerSpawn = new DungeonSpawnMeta
                            {
                                SpawnRoom = parentRoom,
                            };
                            context.PlayerSpawnMeta = playerSpawn;
                            return(TaskStatus.Success);
                        }

                        Debug.Log($"Error! Can't spawn player in the void!\n");
                        return(TaskStatus.Failure);
                    });
                    Effect("Player spawned", EffectType.PlanAndExecute,
                           (context, type) => context.SetState(DungeonWorldState.PlayerNeedsSpawnPoint, false, type));
                }
                End();
            }
            End();
            return(this);
        }
Пример #2
0
        public PlayerController SpawnPlayer(string race, string name, DungeonSpawnMeta meta)
        {
            var room = GetRoom(meta.SpawnRoom);

            if (room == null)
            {
                return(null);
            }

            if (room.GetValidSpawnPosition(this, out var position) == false)
            {
                return(null);
            }

            // TODO: Need to look up spawn position in room, that we ensure valid positions
            var character = Spawn(race, name, position, out var brain);

            if (character != null)
            {
                var controller = new PlayerController();
                controller.Set(_uiManager, _targetGameObjectPrefab);
                controller.Set(character);

                return(controller);
            }

            return(null);
        }