Ejemplo n.º 1
0
        public IActor Create(IWorld world, IRoom room, IFaction faction, ActorBlueprint blueprint, RoomBlueprint roomBlueprintIfAny)
        {
            HandleInheritance(blueprint);

            var npc = new Npc(blueprint.Name, room);

            AddBasicProperties(world, npc, blueprint, "talk");
            world.AdjectiveFactory.AddAdjectives(world, npc, blueprint);

            if (faction != null && !blueprint.Unaligned)
            {
                npc.FactionMembership.Add(faction);
            }

            if (string.IsNullOrWhiteSpace(npc.Name))
            {
                npc.Name = faction?.GenerateName(world.R) ?? "Unnamed Npc";
            }

            foreach (var blue in blueprint.MandatoryItems)
            {
                npc.Equip(npc.SpawnItem(blue));
            }

            //plus give them one more random thing that fits the factions / actor
            var pickFrom = world.ItemFactory.Blueprints.Union(blueprint.OptionalItems).ToArray();

            if (roomBlueprintIfAny != null)
            {
                pickFrom = pickFrom.Union(roomBlueprintIfAny.OptionalItems).ToArray();
            }

            if (pickFrom.Any())
            {
                npc.Equip(npc.SpawnItem(pickFrom.GetRandom(world.R)));
            }

            npc.AvailableSlots = (blueprint.Slots ?? faction?.DefaultSlots ?? DefaultSlots)?.Clone() ?? new SlotCollection();

            return(npc);
        }