Ejemplo n.º 1
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;

            if (mapping.target is Agent)
            {
                // TODO: This is really confusing - fix it and make sure it works
                Agent otherAgent = target as Agent;
                if (target == agent)
                {
                    otherAgent = (Agent)mapping.target;
                }
                ((Agent)target).memoryType.ChangeRLevel(((Agent)target), otherAgent, actualAmount);
            }
            else if (mapping.target is AgentEvent)
            {
                // TODO: Move this into AgentEvent so that it can decide how to handle RLevel changes
                // Change this agent's R Level for all other attendees in this event
                AgentEvent agentEvent = (AgentEvent)mapping.target;

                foreach (AgentEvent.Attendee attendee in agentEvent.attendees)
                {
                    if (agent != attendee.agent)
                    {
                        agent.memoryType.ChangeRLevel(agent, attendee.agent, actualAmount);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        // Adds a GoTo Mapping to an EntityType Mapping if its needed
        public virtual Mapping MaybeAddGoToMapping(Agent agent, Mapping mapping)
        {
            if (RequiresGoToMapping(agent, mapping))
            {
                AgentEvent agentEvent = mapping.target as AgentEvent;
                if (agentEvent != null)
                {
                    agentEvent.NotifyTravellingTo(agent);
                }

                Mapping goToMapping = CreateGoToMapping(mapping);

                if (mapping.children == null)
                {
                    mapping.children = new List <Mapping>()
                    {
                        goToMapping
                    };
                    mapping.reasonForChildren = new List <InputCondition>()
                    {
                        mapping.mappingType.inputConditions.Last()
                    };
                    goToMapping.childIndex = 0;
                }
                else
                {
                    mapping.children.Add(goToMapping);
                    mapping.reasonForChildren.Add(mapping.mappingType.inputConditions.Last());
                    goToMapping.childIndex = mapping.children.Count - 1;
                }
                return(goToMapping);
            }
            return(mapping);
        }
Ejemplo n.º 3
0
        void Start()
        {
            inAgentEvent = null;
            isAutonomous = true;
            isAlive      = true;

            pastLocations.Add(transform.position);

            mainCoroutine = StartCoroutine(MainAgentLoop());
        }
Ejemplo n.º 4
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            AgentEvent agentEvent = target as AgentEvent;

            if (agentEvent.state == (AgentEvent.State)inputCondition.enumValueIndex)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        // Agent is an attendee in an AgentEvent that has just started - change roles if needed
        public void EventStarting(AgentEvent agentEvent)
        {
            Debug.Log(name + ": Starting Event");
            inAgentEvent = agentEvent;

            // Figure out what roles need to be applied
            // TODO: Only CreatorAttendee Type is implemented
            List <RoleType> roleTypes = agentEvent.GetRoleTypes(this);

            // Handle applying roles
            foreach (RoleType roleType in roleTypes)
            {
                roleType.AddToAgent(this);
            }
        }
Ejemplo n.º 6
0
        public override GameObject CreateEntity(int prefabVariantIndex, Vector3 position, Quaternion rotation, Vector3 scale, Entity creator)
        {
            // This appears to work - During runtime the prefab must be saved somewhere - does not change assets
            GameObject prefab = prefabVariants[prefabVariantIndex];

            prefab.SetActive(false);
            GameObject agentEventGameObject = Instantiate(prefab, position, rotation);
            AgentEvent agentEvent           = agentEventGameObject.GetComponent <AgentEvent>();

            agentEvent.state = AgentEvent.State.Waiting;

            // Set entityType - this allows one prefab to be used for multiple AgentEventTypes
            agentEvent.entityType     = this;
            agentEvent.agentEventType = this;

            if (creator != null)
            {
                agentEvent.creator = (Agent)creator;
            }
            agentEvent.attendees = new List <AgentEvent.Attendee>();

            // Create the trigger collider
            //SphereCollider sc = agentEventGameObject.AddComponent(typeof(SphereCollider)) as SphereCollider;
            //sc.isTrigger = true;
            //sc.radius = detectionRadius;

            // Set Waiting Sound
            AudioSource audioSource = agentEvent.GetComponent <AudioSource>();

            if (audioSource != null && soundForWaiting != null)
            {
                audioSource.clip        = soundForWaiting;
                audioSource.loop        = loop;
                audioSource.playOnAwake = true;
            }
            else if (audioSource == null && soundForWaiting != null)
            {
                Debug.LogError(name + " has waiting sound set but the AgentEvent " + agentEvent.name + " is missing an Audio Sorce.");
            }
            agentEventGameObject.SetActive(true);
            prefab.SetActive(true);

            return(agentEventGameObject);
        }
Ejemplo n.º 7
0
        public void QuitEvent()
        {
            Debug.Log(name + ": Quitting Event");

            // Run On Quit AgentEvent OutputChangesWaitEndOCT
            decider.RunOutputChangesFromAgent(this, null, OutputChange.Timing.OnQuitAgentEvent);

            // Disable any AgentEvent roles and figure out changes to Drives and Actions
            List <RoleType> roleTypes = inAgentEvent.GetRoleTypes(this);

            // Handle applying roles
            foreach (RoleType roleType in roleTypes)
            {
                roleType.RemoveFromAgent(this);
            }

            inAgentEvent.RemoveAttendee(this);

            inAgentEvent = null;
        }
Ejemplo n.º 8
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            if (agent.inAgentEvent != null)
            {
                return(false);
            }

            // Event can get destroyed right before this check
            if (target == null)
            {
                return(false);
            }

            AgentEvent targetAgentEvent = (AgentEvent)target;

            // See if the creator's rLevel for this agent meets the min r requirement for this agent event
            if (targetAgentEvent != null && targetAgentEvent.CanJoin(agent))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;

            AgentEventType agentEventType = outputChange.entityType as AgentEventType;

            Vector3 position = target.transform.position;

            if (agentEventType.prefabVariants == null || agentEventType.prefabVariants.Count == 0)
            {
                Debug.LogError(agent.name + ": CreateAgentEventOCT: " + agentEventType.name + " has no Prefab Variants.  Please Fix.");
                return(false);
            }
            GameObject newGameObject = agentEventType.CreateEntity(0, position, agentEventType.prefabVariants[0].transform.rotation,
                                                                   agentEventType.prefabVariants[0].transform.localScale, agent);

            AgentEvent agentEvent = newGameObject.GetComponent <AgentEvent>();

            mapping.target = agentEvent;
            agentEvent.AddAttendee(agent);
            return(true);
        }