コード例 #1
0
 private IBehaviorNode CreateNode(object entity, BlackBoard blackBoard, Dictionary <int, IBehaviorNode> branches)
 {
     return(When <object> .Start(entity, (expected, real) => expected.Equals(real.GetType()))
            .CaseThenAs <ActionEntity>(typeof(ActionEntity), et => new ActionNode(
                                           name: et.name,
                                           eventId: et.eventId
                                           ))
            .CaseThenAs <FocusEntity>(typeof(FocusEntity), et => new FocusNode(
                                          name: et.name,
                                          onFocus: blackBoard.GetOnFocus(et.filterId, et.priorityId),
                                          count: et.count
                                          ))
            .CaseThenAs <TriggerEntity>(typeof(TriggerEntity), et => new TriggerNode(
                                            name: et.name,
                                            agentId: et.agentId,
                                            eventId: et.eventId
                                            ))
            .CaseThenAs <RandomSelectEntity>(typeof(RandomSelectEntity), et => new RandomSelectNode(
                                                 name: et.name,
                                                 children: (from child in et.children select branches[child.GetHashCode()]).ToList()
                                                 ))
            .CaseThenAs <SelectEntity>(typeof(SelectEntity), et => new SelectNode(
                                           name: et.name,
                                           children: (from child in et.children select branches[child.GetHashCode()]).ToList()
                                           ))
            .CaseThenAs <SequenceEntity>(typeof(SequenceEntity), et => new SequenceNode(
                                             name: et.name,
                                             children: (from child in et.children select branches[child.GetHashCode()]).ToList()
                                             ))
            .CaseThenAs <IfEntity>(typeof(IfEntity), et => new IfNode(
                                       name: et.name,
                                       onCheckCondition: blackBoard.GetOnCheckCondition(et.conditionFuncName),
                                       thenChild: branches[et.thenChild.GetHashCode()]
                                       ))
            .CaseThenAs <IfElseEntity>(typeof(IfElseEntity), et => new IfElseNode(
                                           name: et.name,
                                           onCheckCondition: blackBoard.GetOnCheckCondition(et.conditionFuncName),
                                           thenChild: branches[et.thenChild.GetHashCode()],
                                           elseChild: branches[et.elseChild.GetHashCode()]
                                           ))
            .CaseThenAs <UntilEntity>(typeof(UntilEntity), et => new UntilNode(
                                          name: et.name,
                                          onCheckCondition: blackBoard.GetOnCheckCondition(et.conditionFuncName),
                                          thenChild: branches[et.thenChild.GetHashCode()]
                                          ))
            /*TODO: Decorate node*/
            .End() as IBehaviorNode);
 }