public override bool Check(ChangeCondition changeCondition, OutputChange outputChange, Agent agent, Entity target, Mapping mapping, float actualAmount) { int index = -1; if (changeCondition.valueType == ChangeCondition.ValueType.Selector) { index = (int)changeCondition.selector.GetFloatValue(agent, mapping); } else if (changeCondition.valueType == ChangeCondition.ValueType.IntValue) { index = changeCondition.intValue; } OutputChange targetOutputChange; if (index == -1) { targetOutputChange = outputChange.Previous(mapping.mappingType); } else { targetOutputChange = mapping.mappingType.outputChanges[index]; } // Find this one in history to see it has run and if so what result was // TODO: Reliance on History is bad - Add a structure in Decider? Or DeciderType? // Dictionary<(Mapping, OutputChange), Status> - reset it when new plan starts HistoryType.OutputChangeLog outputChangeLog = agent.historyType.GetOutputChangeLog(agent, mapping, targetOutputChange); if (outputChangeLog == null) { Debug.LogError(agent.name + ": PreviousOCStatusCCT - unable to find OC status in HistoryType OutputChangeLog."); return(false); } if (outputChangeLog.succeeded == changeCondition.boolValue) { return(true); } return(false); }
public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop) { forceStop = false; OutputChange previousOutputChange = outputChange.Previous(mapping.mappingType); HistoryType.OutputChangeLog outputChangeLog = agent.historyType.GetOutputChangeLog(agent, mapping, previousOutputChange); if (outputChangeLog == null) { Debug.LogError(agent.name + ": PlaySoundFromATMOCT - unable to find OC status in HistoryType OutputChangeLog."); return(false); } int tagEnumIndex; if (outputChangeLog.succeeded) { tagEnumIndex = 1; } else { tagEnumIndex = 2; } // This uses mapping.target since target will be the agent if TargetType is ToSelf ActionType otherActionType = null; if (mapping.target is Agent targetAgent && targetAgent.decider.CurrentMapping != null) { otherActionType = targetAgent.decider.CurrentMapping.mappingType.actionType; } Entity inventoryTarget = mapping.inventoryTargets[outputChange.inventoryTypeGroupMatchIndex]; List <AudioClip> audioClips = agent.inventoryType.GetItemSoundEffects(agent, mapping.mappingType.actionType, otherActionType, ItemCondition.ModifierType.Used, false, tagEnumIndex); if (audioClips == null || audioClips.Count == 0) { Debug.Log(agent.name + ": MappingType: " + mapping.mappingType.name + " - PlaySoundFromATMOCT: No Audio Clips found."); return(false); } AudioClip audioClip = audioClips[Random.Range(0, audioClips.Count)]; if (audioClip == null) { Debug.LogError(agent.name + ": MappingType: " + mapping.mappingType.name + " - PlaySoundFromATMOCT: Audio Clip is null."); return(false); } AudioSource audioSource = target.GetSFXGameObject((int)outputChange.floatValue).GetComponent <AudioSource>(); if (audioSource == null) { if (mapping != null) { Debug.LogError(agent.name + ": MappingType: " + mapping.mappingType.name + " - PlaySoundFromATMOCT: target " + target.name + " has no AudioSource Component."); } else { Debug.LogError(agent.name + ": PlaySoundFromATMOCT: target " + target.name + " has no AudioSource Component."); } return(false); } if (!audioSource.isPlaying || !outputChange.boolValue) { audioSource.clip = audioClip; audioSource.loop = false; audioSource.Play(); } return(true); }