Ejemplo n.º 1
0
        internal void Load(IEnumerable <Card> cards, string gameNamespace)
        {
            // Set cards (without behaviours)
            Cards = (from c in cards select new { Key = c.Id, Value = c }).ToDictionary(x => x.Key, x => x.Value);

            // Add in placeholder cards
            Cards.Add("Game", new Card
            {
                AssetId = -1,
                Guid    = new Guid("00000000-0000-0000-0000-000000000001"),
                Id      = "Game",
                Name    = "Game",
                Tags    = new Dictionary <GameTag, int> {
                    { GameTag.CARDTYPE, (int)CardType.GAME }
                },
                Requirements = new Dictionary <PlayRequirements, int>(),
                Behaviour    = null
            });
            Cards.Add("Player", new Card
            {
                AssetId = -2,
                Guid    = new Guid("00000000-0000-0000-0000-000000000002"),
                Id      = "Player",
                Name    = "Player",
                Tags    = new Dictionary <GameTag, int> {
                    { GameTag.CARDTYPE, (int)CardType.PLAYER }
                },
                Requirements = new Dictionary <PlayRequirements, int>(),
                Behaviour    = null
            });

            // Compile card behaviours
            var behavioursType = Type.GetType(gameNamespace + ".Cards");

            foreach (var c in Cards.Values)
            {
                // Get behaviour script and compile ActionGraph for cards with behaviours
                // TODO: Allow fetch from card name as well as ID
                var b = behavioursType.GetField(c.Id, BindingFlags.Static | BindingFlags.NonPublic);
                if (b != null)
                {
                    var script = b.GetValue(null) as CardBehaviourGraph;
                    c.Behaviour = CardBehaviour.FromGraph(script);
                }
                else
                {
                    c.Behaviour = new CardBehaviour();
                }
            }
        }
Ejemplo n.º 2
0
        // Compile all the ActionGraph fields in a Behaviour into lists of QueueActions
        internal static CardBehaviour FromGraph(CardBehaviourGraph b)
        {
            var compiled      = new CardBehaviour();
            var behaviourList = new List <string>();

            // Find all the fields we can compile
            var behaviourClass = typeof(CardBehaviourGraph).GetFields();

            foreach (var field in behaviourClass)
            {
                if (field.FieldType == typeof(ActionGraph))
                {
                    behaviourList.Add(field.Name);
                }
            }

            // Compile each field that exists
            foreach (var fieldName in behaviourList)
            {
                var         field      = b.GetType().GetField(fieldName);
                ActionGraph fieldValue = field.GetValue(b) as ActionGraph;
                if (fieldValue != null)
                {
                    compiled.GetType().GetField(fieldName).SetValue(compiled, fieldValue.Unravel());
                }
                else
                {
                    compiled.GetType().GetField(fieldName).SetValue(compiled, new List <QueueAction>());
                }
            }

            // Copy event triggers
            compiled.TriggersByZone = b.TriggersByZone;

            return(compiled);
        }