Beispiel #1
0
        public DungeonDomainBuilder TrySpawnNpc(string race, string name)
        {
            Optionally();
            {
                Action($"Try spawn npc");
                {
                    Do((context) =>
                    {
                        var parentRoom = context.RoomStack.Peek();
                        if (parentRoom != null)
                        {
                            Debug.Log($"Spawn npc {race}/{name} in room {parentRoom.Id}\n");
                            var npcSpawn = new DungeonSpawnNpcMeta()
                            {
                                SpawnRoom = parentRoom,
                                Race      = race,
                                Name      = name,
                            };
                            context.NpcSpawnMeta.Add(npcSpawn);
                            return(TaskStatus.Success);
                        }

                        Debug.Log($"Error! Can't spawn npc in the void!\n");
                        return(TaskStatus.Failure);
                    });
                }
                End();
            }
            End();
            return(this);
        }
Beispiel #2
0
        public AIController SpawnAi(DungeonSpawnNpcMeta meta)
        {
            var room = GetRoom(meta.SpawnRoom);

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

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

            var character = Spawn(meta.Race, meta.Name, position, out var brain);

            if (character != null)
            {
                var controller = new AIController(brain);
                controller.Set(character);

                return(controller);
            }

            return(null);
        }