Exemplo n.º 1
0
    public void ChooseBuilding()
    {
        StopSound();
        _buildingDecision.Reset();
        foreach (System.Reflection.MethodInfo method in this.GetType().GetMethods())
        {
            if (((BuildingChoiceMethod[])method.GetCustomAttributes(typeof(BuildingChoiceMethod), true)).Length > 0)
            {
                DecisionTree <GameObject> .Percept p = _buildingDecision.GetPercept(method.Name);
                if (p != null && ((Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), this, method))())
                {
                    p.Activate();
                }
            }
        }
        GameObject nextBuild = _buildingDecision.Decide();
        bool       water     = (nextBuild.name == "FishermanHut");

        _target          = _village.AddBuilding(_construction, ChooseEmplacement(water)).GetComponent <ConstructionSite>();
        _target.Building = nextBuild;
        string[] props = Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name).GetElements();
        for (int i = 1; i < props.Length; i++)
        {
            props[i] = props[i].Remove(0, _target.Building.name.Length + 1);
        }
        for (int i = 1; i < props.Length - 1; i++)
        {
            _target.Needed[props[i]] = (int)(float)Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name + "." + props[i]).Value;
        }
        _target.Duration = (float)Manager.Instance.Properties.GetElement("BuildingCost." + _target.Building.name + ".Duration").Value;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    protected virtual void Update()
    {
        _decision.Reset();
        foreach (System.Reflection.MethodInfo method in this.GetType().GetMethods())
        {
            if (((PerceptMethod[])method.GetCustomAttributes(typeof(PerceptMethod), true)).Length > 0)
            {
                DecisionTree <Action> .Percept p = _decision.GetPercept(method.Name);
                if (p != null && ((Func <bool>)Delegate.CreateDelegate(typeof(Func <bool>), this, method))())
                {
                    p.Activate();
                }
            }
        }
        Action action = _decision.Decide();

        if (action != null)
        {
            action();
        }
    }