Beispiel #1
0
 public override void OnEnter(BlackBoard blackboard)
 {
     LogEnter();
     _targetPos  = blackboard.GetValue <BbV3>(_bbTarget).Value;
     _entity     = blackboard.GetValue <BaseEntity>(SequenceSelfConst.TARGET_SELF_ENTITY);
     _sourcePos  = _entity.EntityController.WroldPosition;
     _curr_frame = 0;
 }
Beispiel #2
0
 public override void OnEnter(BlackBoard blackboard)
 {
     LogEnter();
     _targetPos = blackboard.GetValue <BbV3>(SequenceSelfConst.TARGET_POSITION1).Value;
     _entity    = blackboard.GetValue <BaseEntity>(SequenceSelfConst.TARGET_SELF_ENTITY);
     _sourcePos = _entity.EntityController.WroldPosition;
     //SkillLog.Log("位置偏移-->OnEnter");
 }
Beispiel #3
0
    public override NodeState Tick()
    {
        Vector3 pos;

        if (board.GetValue(key, out pos))
        {
            soldier.Fire(pos + shootPos);
        }

        return(NodeState.Running);
    }
    public override NodeState Tick()
    {
        GameObject weapon;

        if (board.GetValue(key, out weapon))
        {
            soldier.PickUpWeapon(weapon);
            soldier.SetEquipment(true);
            state = NodeState.Completed;
        }

        return(state);
    }
Beispiel #5
0
    public override NodeState Tick()
    {
        Vector3 pos;

        if (board.GetValue(key, out pos))
        {
            if (Vector3.Distance(soldier.transform.position, pos) > 0.1f)
            {
                soldier.Move(pos);
                state = NodeState.Running;
            }
            else
            {
                soldier.Stop();
                state = NodeState.Completed;
            }
        }

        return(state);
    }
    public void Tick(BlackBoard board, object target)
    {
        Tick tick = new Tick(this, board, target);

        _root.Execute(tick);
        List <Node> lastOpenNodes    = board.GetValue(MemoryKeys.OPEN_NODES.ToString(), _id) as List <Node>;
        List <Node> currentOpenNodes = new List <Node>(tick.OpenNodes);

        if (lastOpenNodes != null)
        {
            int activeNodesCount = GetOpenNodesCount(lastOpenNodes, currentOpenNodes);
            for (int i = lastOpenNodes.Count - 1; i >= activeNodesCount; i--)
            {
                lastOpenNodes[i].Close(tick);
            }
        }
        board.SetValue(MemoryKeys.OPEN_NODES.ToString(), _id, currentOpenNodes);
        board.SetValue(MemoryKeys.NODES_COUNT.ToString(), _id, tick.NodesCount);

        return;
    }
Beispiel #7
0
    public override NodeState Tick()
    {
        Vector3 pos;

        if (board.GetValue(key, out pos))
        {
            var dir          = pos - soldier.transform.position;
            var desiredAngle = Vector3.Angle(soldier.transform.forward, dir);
            if (Mathf.Abs(desiredAngle) > 10)
            {
                var normal = Vector3.Cross(soldier.transform.forward, dir);
                var angle  = Mathf.Lerp(0, desiredAngle, 1f);
                angle *= Mathf.Sign(Vector3.Dot(Vector3.up, normal));
                soldier.Turn(angle);
                state = NodeState.Running;
            }
            else
            {
                state = NodeState.Completed;
            }
        }
        return(state);
    }
 public T GetBBValue <T>(string key, T defaultValue)
 {
     return(_blackboard.GetValue <T>(key, defaultValue));
 }
Beispiel #9
0
 // Get Value
 static public T GetValue <T>(string key)
 {
     return(blackboard.GetValue <T>(key));
 }
Beispiel #10
0
 public bool GetValue <T>(string key, out T outData)
 {
     return(m_BLackBoard.GetValue <T>(key, out outData));
 }
Beispiel #11
0
    /* Chooses a course of action based on how many rules are satisfied
     */
    public void Deliberate(BlackBoard bb)
    {
        // Get the maximal match and save its index
        foreach (Dictionary <string, Dictionary <string, string> > rule in rules)
        {
            int numRulesMet = 0;

            foreach (KeyValuePair <string, string> r in rule[Constants.p1Key])
            {
                if (r.Key == Constants.indexLifePoints)
                {
                    if (Hp_level(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexFavor)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexRally)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexBalance)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastHitDamage)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastAttackByPlayer)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.landedLastAttack)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastEvade)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastEvadeSuccessful)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastAttackByOpponent)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.opponentLandedLastAttack)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.distToOpponent)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.winner)
                {
                    if (Favor(bb.GetValue(Constants.p1Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }

                else
                {
                    string value = bb.GetValue(Constants.p1Key, r.Key);
                    if (value == r.Value || (value == "" && r.Value == "None"))
                    {
                        numRulesMet += 1;
                    }

                    break;
                }
            }

            foreach (KeyValuePair <string, string> r in rule[Constants.p2Key])
            {
                if (r.Key == Constants.indexLifePoints)
                {
                    if (Hp_level(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexFavor)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexRally)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.indexBalance)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastHitDamage)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastAttackByPlayer)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.landedLastAttack)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastEvade)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastEvadeSuccessful)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.lastAttackByOpponent)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.opponentLandedLastAttack)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.distToOpponent)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }
                else if (r.Key == Constants.winner)
                {
                    if (Favor(bb.GetValue(Constants.p2Key, r.Key)) == r.Value)
                    {
                        numRulesMet += 1;
                    }
                }

                else
                {
                    string value = bb.GetValue(Constants.p2Key, r.Key);
                    if (value == r.Value || (value == "" && r.Value == "None"))
                    {
                        numRulesMet += 1;
                    }

                    break;
                }
            }

            //Debug.Log("Rules met: " + numRulesMet);
            //Debug.Log("at " + this.rules.IndexOf(rule));
            //Debug.Log("Current Goodness: " + this.goodness);
            //Debug.Log(numRulesMet >= this.goodness);
            if (numRulesMet >= this.goodness)
            {
                this.goodness = numRulesMet;
                this.ruleMet  = this.rules.IndexOf(rule);
                //Debug.Log(this.ToString());
            }
        }
    }