Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="IAction"/> based on the <paramref name="blueprint"/> and adds it as a <see cref="IHasStats.BaseActions"/>
        /// </summary>
        /// <param name="world"></param>
        /// <param name="onto"></param>
        /// <param name="blueprint"></param>
        /// <returns></returns>
        public IAction Create(IWorld world, IHasStats onto, ActionBlueprint blueprint)
        {
            HandleInheritance(blueprint);
            IAction action;

            if (string.IsNullOrWhiteSpace(blueprint.Type))
            {
                action = new Action(onto);
            }
            else
            {
                try
                {
                    var type = _types.GetTypeNamed(blueprint.Type);
                    action = (IAction)Activator.CreateInstance(type, onto);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Error creating base Type for ActionBlueprint {blueprint}", ex);
                }
            }

            AddBasicProperties(world, action, blueprint, "use");

            if (!string.IsNullOrWhiteSpace(blueprint.Name))
            {
                action.Name = blueprint.Name;
            }

            action.Owner = onto;

            if (blueprint.HotKey.HasValue)
            {
                action.HotKey = blueprint.HotKey.Value;
            }

            action.Effect.AddRange(blueprint.Effect.SelectMany(e => e.Create()));

            if (blueprint.Targets != null)
            {
                action.Targets = blueprint.Targets;
            }

            action.TargetPrompt = blueprint.TargetPrompt;

            if (action is FightAction fight && blueprint.InjurySystem.HasValue)
            {
                fight.InjurySystem = (IInjurySystem)world.GetSystem(blueprint.InjurySystem.Value);
            }

            onto.BaseActions.Add(action);
            return(action);
        }
Esempio n. 2
0
        public void ValidateBehaviour(IWorld world, IHasStats owner, IBehaviour behaviour, IRoom room)
        {
            var actor = owner as IActor ?? GetTestActor(room);

            var testAction = new Action(actor)
            {
                Name = "Test Action"
            };
            var stack = new ActionStack();

            try
            {
                behaviour.OnPush(world, _ui, stack, new Frame(actor, testAction, 0));
            }
            catch (Exception e)
            {
                AddWarning($"Error testing OnPush of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e);
            }

            try
            {
                behaviour.OnPop(world, _ui, stack, new Frame(actor, testAction, 0));
            }
            catch (Exception e)
            {
                AddWarning($"Error testing OnPop of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e);
            }

            try
            {
                behaviour.OnRoundEnding(world, _ui, Guid.NewGuid());
            }
            catch (Exception e)
            {
                AddWarning($"Error testing OnRoundEnding of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e);
            }

            try
            {
                behaviour.OnEnter(world, _ui, Guid.NewGuid(), actor, room);
            }
            catch (Exception e)
            {
                AddWarning($"Error testing OnEnter of Behaviour {behaviour} of on '{owner}' in room '{room.Name}' with test actor '{actor}'", e);
            }
        }