示例#1
0
        private void InjectDependencies(IQuest quest)
        {
            var questFields = quest.GetType()
                              .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                              .Where(t => t.GetCustomAttribute <InjectAttribute>() != null);

            var questMethods = quest.GetType()
                               .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
                               .Where(m => m.GetCustomAttribute <InvokeAttribute>() != null);

            var factoryFields = typeof(QuestFactory)
                                .GetFields(BindingFlags.Instance | BindingFlags.NonPublic);

            foreach (var field in questFields)
            {
                if (factoryFields.Any(f => f.FieldType == field.FieldType))
                {
                    field.SetValue(quest, factoryFields
                                   .First(f => f.FieldType == field.FieldType)
                                   .GetValue(this));
                }
            }

            foreach (var method in questMethods)
            {
                method.Invoke(quest, new object[] { });
            }
        }
示例#2
0
    public void Update()
    {
        if (_currentQuest == null)
        {
            PickAQuest();
        }

        if (_currentCommand == null)
        {
            _currentCommand = _currentQuest.GetCommand(this);
        }

        _currentCommand.invokeOn(this);

        if (_currentCommand.IsCompleted())
        {
            _currentCommand = null;

            if (_currentQuest.IsCompleted())
            {
                _currentQuest.Finalize(this);
                GameLogger.Log(name + " finished quest for " + _currentQuest.GetType().Name);
                _currentQuest = null;
            }
        }

        OnMouseDown();
    }
示例#3
0
 public static void SaveSelected()
 {
     if (selectedQuest == null || pars.Length == 0)
     {
         return;
     }
     if (selectedQuest.GetType() == typeof(TaskBase))
     {
         TaskBase tmp = (TaskBase)selectedQuest;
         tmp.taskName = pars[0].Text;
         tmp.taskItems.Clear();
         for (int i = 0; i < itemPars.Count; i += 2)
         {
             if (itemPars[i].Text.Length > 0)
             {
                 tmp.taskItems.Add(new ItemPickup {
                     itemName = itemPars[i].Text, itemQuantity = int.Parse(itemPars[i + 1].Text)
                 });
             }
         }
         UpdateSelected();
     }
 }
示例#4
0
            public static void UpdateSelected()
            {
                grp.Visible       = false;
                active.Visible    = false;
                completed.Visible = false;
                items.Visible     = false;
                addButt.Visible   = false;
                if (list.SelectedItem == null || !QuestData.QuestDatabase.ContainsKey(((string)list.SelectedItem).Replace("*", "")))
                {
                    return;
                }
                selectedQuest     = QuestData.QuestDatabase[((string)list.SelectedItem).Replace("*", "")];
                grp.Visible       = true;
                active.Visible    = true;
                completed.Visible = true;
                completed.Checked = selectedQuest.Completed;
                if (QuestData.ActiveQuests.Contains(selectedQuest.ToString()))
                {
                    active.Checked = true;
                }
                if (selectedQuest.GetType() == typeof(TaskBase))
                {
                    TaskBase bas = (TaskBase)selectedQuest;
                    grp.Controls.Clear();
                    items.Visible   = true;
                    addButt.Visible = true;
                    pars            = new TextBox[1];
                    TextBox val = new TextBox()
                    {
                        Location = new Point(0, 35),
                        Size     = new Size(200, 20)
                    };
                    val.Text = bas.taskName;
                    grp.Controls.Add(new Label()
                    {
                        Text = "Task Name (Requires Restart): ", Location = new Point(0, 15), Size = new Size(200, 20)
                    });
                    grp.Controls.Add(val);
                    pars[0] = val;

                    itemPars = new List <TextBox>();
                    items.Controls.Clear();
                    int counter = 0;
                    foreach (ItemPickup p in bas.taskItems)
                    {
                        TextBox vab = new TextBox()
                        {
                            Location = new Point(0, 35 + 10 * counter),
                            Size     = new Size(100, 20)
                        };
                        vab.Text = p.itemName;
                        TextBox vad = new TextBox()
                        {
                            Location = new Point(100, 35 + 10 * counter),
                            Size     = new Size(100, 20)
                        };
                        vad.Text = p.itemQuantity.ToString();
                        items.Controls.Add(vab);
                        items.Controls.Add(vad);
                        counter += 2;
                        itemPars.Add(vab);
                        itemPars.Add(vad);
                    }
                    items.Controls.Add(new Label()
                    {
                        Text = "Item Name: ", Location = new Point(10, 15), Size = new Size(90, 20)
                    });
                    items.Controls.Add(new Label()
                    {
                        Text = "Item Quantity: ", Location = new Point(110, 15), Size = new Size(90, 20)
                    });
                }
            }
示例#5
0
 private void PickAQuest()
 {
     _currentQuest = _decisionMaker.PickAQuest(_decisionMaker.GetBiggestNeed());
     GameLogger.Log(name + " picked a quest for " + _currentQuest.GetType().Name
                    + " with need of " + _currentQuest.GetBenefitForNeedAbs(_decisionMaker.GetBiggestNeed()));
 }