Beispiel #1
0
        // Set up.
        public void Init(Character cas, Prop targ, AIAction ac, int ind)
        {
            caster = cas;
            target = targ;
            action = ac;
            index  = ind;
            Power power = action as Power;

            if (power)
            {
                button.image.sprite = power.icon;

                ToolTipIcon toolTip = GetComponent <ToolTipIcon>();
                if (toolTip)
                {
                    toolTip.OnPointerExit();
                    Text text = toolTip.toolTip.GetComponentInChildren <Text>();
                    if (text)
                    {
                        text.text = power.GetDescription();
                    }
                }
            }

            // could be AIBrain (squad based setup) or PlayerPower (third person setup)
            responder = caster.GetComponent <IMenuItemResponder>();
        }
Beispiel #2
0
        public virtual AIAction MakeInstance()
        {
            AIAction action = Instantiate(this);

            action.name = name;
            return(action);
        }
Beispiel #3
0
        public override float Evaluate(AIBrain brain)
        {
            decided = true;
            isTrue  = IsCondition(condition, brain.character);

            AIAction node = isTrue ? nodeTrue : nodeFalse;

            brain.AddDebugMsg("-BR(" + isTrue + ")" + node.name);

            return(node.Evaluate(brain));
        }
Beispiel #4
0
        // Use this for initialization
        void Start()
        {
            character = GetComponent <Character>();
            ai        = GetComponent <AICharacterControl>();

            List <AIAction> extras = new List <AIAction>();
            Patrolling      patrol = GetComponent <Patrolling>();

            if (patrol)
            {
                extras.Add(ScriptableObject.CreateInstance <AIPatrol>());
            }

            int numActions = behaviours.Length + extras.Count;

            // set up a suitable rootnode, either a single power, or a group of them which compete!
            if (numActions == 0)
            {
                rootNode = null;
            }
            else if (numActions == 1)
            {
                if (behaviours.Length > 0)
                {
                    rootNode = behaviours[0].MakeInstance();
                }
                else
                {
                    rootNode = extras[0].MakeInstance();
                }
            }
            else
            {
                AIAction[] actions = new AIAction[numActions];
                for (int i = 0; i < behaviours.Length; i++)
                {
                    actions[i] = behaviours[i].MakeInstance();
                }
                for (int i = 0; i < extras.Count; i++)
                {
                    actions[i + behaviours.Length] = extras[i].MakeInstance();
                }

                AINodeEvaluate evalNode = ScriptableObject.CreateInstance <AINodeEvaluate>();
                evalNode.behaviours = actions;
                rootNode            = evalNode;
            }
            patrolling = GetComponent <Patrolling>();
        }
Beispiel #5
0
        public override AIAction Execute(AIBrain brain)
        {
            if (!decided)
            {
                isTrue = IsCondition(condition, brain.character);
            }

            AIAction node = isTrue ? nodeTrue : nodeFalse;

            brain.AddDebugMsg("+BR:" + isTrue + " " + node.name);

            decided = false;

            return(node.Execute(brain));
        }
Beispiel #6
0
        public override float Evaluate(AIBrain brain)
        {
            // if the caster condition fails, don't do it!
            if (!IsCondition(condition, brain.character))
            {
                return(0);
            }

            bestBehaviour  = null;
            bestEvaluation = 0;
            evals          = new float[behaviours.Length];
            targets        = new Prop[behaviours.Length];
            for (int i = 0; i < behaviours.Length; i++)
            {
                float evaluation = behaviours[i].Evaluate(brain);
                evals[i] = evaluation;
                Power p = behaviours[i] as Power;
                if (p == null)
                {
                    AINodePower pn = behaviours[i] as AINodePower;
                    if (pn)
                    {
                        p = pn.power;
                    }
                }
                if (p)
                {
                    targets[i] = p.npcTarget;
                }
                if (evaluation > bestEvaluation)
                {
                    bestBehaviour  = behaviours[i];
                    bestEvaluation = evaluation;
                }
            }

            return(bestEvaluation);
        }
Beispiel #7
0
 public void SetPower(Power p)
 {
     action = p;
     button.image.sprite = p.icon;
 }
Beispiel #8
0
        // Update is called once per frame
        void Update()
        {
            if (character.dead)
            {
                ai.SetTarget(null);
                return;
            }

            if (character.isHeld())
            {
                ai.SetTarget(null);
            }

            if (countDown > 0)
            {
                countDown -= Time.deltaTime;
                if (character.isHeld() == false && character.target)
                {
                    character.FaceTarget();
                }
                if (debugCountdown)
                {
                    debugCountdown.text = "" + countDown;
                }
            }
            else
            {
                if (character.isHeld())
                {
                    countDown = 1;
                }
                else
                {
                    UpdateEnemies();

                    if (showDebug)
                    {
                        //Debug.Log(RPGSettings.instance.GetHUD(character).debugText.text);
                        RPGSettings.instance.GetHUD(character).ClearDebugText();
                        foreach (Character enemy in enemies)
                        {
                            RPGSettings.instance.GetHUD(enemy).ClearDebugText();
                        }
                        foreach (Character ally in allies)
                        {
                            RPGSettings.instance.GetHUD(ally).ClearDebugText();
                        }
                    }
                    closingRange = 0;

                    //Debug.Log("THINKING...");
                    Power p = rootNode as Power;
                    if (p)
                    {
                        p.npcTarget = null;
                    }

                    AIAction node = rootNode ? rootNode.Execute(this): null;
                    //Debug.Log("...THINKING");
                    countDown = node == null ? 3 : node.GetDuration();
                }
            }

            if (character.activePower)
            {
                character.activePower.OnUpdate(character);
            }

            if (closingRange > 0 && Power.WithinRange(character, closingRange, true))
            {
                countDown = 0;
            }
        }
Beispiel #9
0
 public void SetRootNode(AIAction action)
 {
     rootNode  = action;
     countDown = 0;
 }