コード例 #1
0
    public void AddSkill(Skills id, int level)
    {
        GOAP_Skill skill = new GOAP_Skill(id, level);

        if (characterData.skills.Contains(skill))
        {
            return;
        }
        characterData.skills.Add(skill);
    }
コード例 #2
0
    private void AddSkill(GOAP_Skill skill)
    {
        SkillsContentPanel p = Instantiate(skillsPrefab, skillsParent).GetComponent <SkillsContentPanel>();

        p.SetContent(characterData, skillOptions, (int)skill.id, skill.level.ToString());
    }
コード例 #3
0
ファイル: GOAP_Planner.cs プロジェクト: Sushiy/Master_Thesis
    private static Node GetValidNeighborNode(Node activeNode, GOAP_Action action, List_GOAP_Worldstate planningWorldState, GOAP_Agent agent)
    {
        bool isUsefulAction = false;

        List_GOAP_Worldstate newRequired = new List_GOAP_Worldstate(activeNode.required);

        //Actions need to fulfill at least one required Worldstate to result in a valid neighbor
        foreach (GOAP_Worldstate state in activeNode.required)
        {
            if (action.SatisfyWorldstates.ContainsExactly(state))
            {
                if (state.key == WorldStateKey.bWasFieldTended && state.value == 0)
                {
                    Debug.LogError(action.SatisfyWorldstates.ToString());
                }
                newRequired.Remove(state);
                isUsefulAction = true;
            }
        }

        //if this action does not help the plan, return null
        if (!isUsefulAction)
        {
            return(null);
        }

        //If the actions proceduralConditions are not met, we can't perform it anyways
        //if (!action.CheckProceduralConditions(agent)) return null;

        //add the actions own required worldstates to the Node
        foreach (GOAP_Worldstate state in action.RequiredWorldstates)
        {
            if (!planningWorldState.ContainsExactly(state))
            {
                //If the state is an observable one and the agent does not have any memory of it, they just assume that it is in their favor
                if (state.IsObservableState && !agent.currentWorldstates.ContainsKey(state))
                {
                    Debug.Log("<color=#cc00cc>" + agent.Character.characterData.characterName + "</color> assumes state:" + state.ToString());
                    agent.ChangeCurrentWorldState(state);
                }
                else
                {
                    newRequired.Add(state);
                }
            }
        }

        //Apply skillmodification onto the neighbor if it is valid
        float skillModifier = 1f;

        if (action.BenefitingSkill != Skills.None)
        {
            GOAP_Skill skill = agent.Character.characterData.skills.Find(x => x.id == action.BenefitingSkill);
            if (skill != null)
            {
                //If the character is actually skilled in this action, adjust the skillmodifier
                skillModifier /= skill.level;
            }
            else
            {
                //If the character is not skilled in this action, the skillmodifier is set to 5. This only comes into play, when global knowledge planning is used.
                skillModifier = 1f;
            }
        }

        //Change the skillmodifier on the action
        action.ApplySkillModifier(skillModifier);

        return(new Node(activeNode, newRequired, action, newRequired.Count * heuristicFactor + action.ActionCost + activeNode.estimatedPathCost));
    }