public PathFollowing(AgentMeta character, List <Vector2> nodes, float pathOffset)
     : base("Path Following")
 {
     Character    = character;
     path         = new Path(nodes);
     PathOffset   = pathOffset;
     currentParam = 0.0f;
 }
 public CollisionAvoid(AgentMeta character, AgentMeta[] Targets, float Radius = 0.1f, float MaxAcc = 0.5f)
     : base("Collision Avoidance")
 {
     Character = character;
     targets   = Targets;
     radius    = Radius;
     maxAcc    = MaxAcc;
 }
示例#3
0
 public Behaviour(string behaviourName, AgentMeta target, AgentMeta character, float SlowRadius, float TargetRadius, float TimeToTarget)
 {
     Name         = behaviourName;
     Target       = target;
     Character    = character;
     slowRadius   = SlowRadius;
     targetRadius = TargetRadius;
     timeToTarget = TimeToTarget;
 }
 public PredictivePathFollowing(AgentMeta character, List <Vector2> nodes, float pathOffset, float PredictTime)
     : base("Predictive Path Following")
 {
     Character    = character;
     path         = new Path(nodes);
     PathOffset   = pathOffset;
     currentParam = 0.0f;
     predictTime  = PredictTime;
 }
    public BlendedSteering(AgentMeta character, List <BehaviourAndWeight.BehaviourAndWeight> behaviourWeighted) : base("Blended Steering")
    {
        if (behaviourWeighted.Count == 0)
        {
            return;
        }

        weightedBehaviours = behaviourWeighted;
    }
示例#6
0
 public Wander(AgentMeta character, float offset, float radius, float rate, float orientation)
     : base("Wander")
 {
     Character         = character;
     wanderOffset      = offset;
     wanderRadius      = radius;
     wanderRate        = rate;
     wanderOrientation = orientation;
 }
示例#7
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f);
        float     shortestTime = float.MaxValue;                // Tiempo faltante para la colision.
        AgentMeta firstTarget  = null;                          // Agente mas cercano a ocasionar una colision.

        // Distancias y posiciones relativas entre agentes.
        float   firstMinSeparation = -1, firstDistance = float.MaxValue;
        Vector2 firstRelativePos = new Vector2(), firstRelativeVel = new Vector2(), relativePos;

        foreach (AgentMeta target in targets)                                // Para cada objeto que puede causar una colision.
        {
            relativePos = target.position - Character.position;              // Posicion de Agente -> Target
            Vector2 relativeVel   = target.velocity - Character.velocity;    // Velocidad Agente -> Target.
            float   relativeSpeed = relativeVel.magnitude;                   // Rapidez relativa.
            float   distance      = relativePos.magnitude;                   // Distancia relativa entre agentes.
            float   minSeparation = distance - relativeSpeed * shortestTime; // Separacion minima (COLISION).

            /* Proyeccion del vector posicion sobre el vector velocidad para estimar el tiempo de colision. */
            float timeToCollision = Mathf.Abs(Vector2.Dot(relativePos, relativeVel) / (relativeSpeed * relativeSpeed));
            if (minSeparation > 2 * radius)
            {
                continue;
            }
            if (timeToCollision > 0 && timeToCollision < shortestTime)
            {
                /* Actualizacion del objetivo mas proximo a ocasionar colision */
                shortestTime = timeToCollision;
                Debug.Log("ShortT: " + shortestTime);
                firstTarget        = target;
                firstMinSeparation = minSeparation;
                firstDistance      = distance;
                firstRelativePos   = relativePos;
                firstRelativeVel   = relativeVel;
            }
        }
        /* Realizar evasion */
        if (firstTarget != null)
        {
            if (firstMinSeparation <= 0 || firstDistance < 2 * radius)
            {
                /* Caso 1: Ya choque, que chimbo */
                relativePos = firstTarget.position - Character.position;
            }
            else
            {
                /* Caso 2: Si sigo asi voy a chocar, y eso no es bueno :( */
                relativePos = firstRelativePos + firstRelativeVel * shortestTime;
            }
            relativePos.Normalize();
            steering.linear = -relativePos * maxAcc;
        }
        return(steering);
    }
示例#8
0
        private void ImportAgentVoice(Database dc, AgentMeta meta)
        {
            if (meta.VoiceId == null)
            {
                meta.VoiceId = VoiceId.Joanna;
            }

            var voice = new AgentVoice
            {
                VoiceId     = meta.VoiceId,
                VoiceEngine = "Amazon Polly",
                AgentId     = meta.Id
            };

            dc.Table <AgentVoice>().Add(voice);
        }
    public BlendedSteering(AgentMeta character, List <Behaviour> behaviours, List <float> Weights) : base("Blended Steering")
    {
        if (behaviours.Count != Weights.Count || behaviours.Count == 0 || Weights.Count == 0)
        {
            return;
        }

        weightedBehaviours = new List <BehaviourAndWeight.BehaviourAndWeight> ();

        for (int i = 0; i < behaviours.Count; i++)
        {
            weightedBehaviours.Add(new BehaviourAndWeight.BehaviourAndWeight(behaviours [i], Weights [i]));
        }

        Character = character;
    }
    public void ExportToMeta(ref AgentMeta agentMeta)
    {
        AgentMeta meta = agentMeta;

        meta.tag        = tag;
        meta.name       = name;
        meta.damage     = damage;
        meta.damageTime = damageTime;
        meta.num        = num;
        meta.speed      = speed;
        meta.health     = health;
        meta.defense    = defense;
        meta.level      = level;
        meta.cost       = cost;
        meta.gameObject = gameObject;
    }
示例#11
0
        private void ImportChatbot(Database dc, AgentMeta meta)
        {
            var rasa     = new RasaAi(dc);
            var importer = new AgentImporterInDialogflow();

            string dataDir = $"{Database.ContentRootPath}{Path.DirectorySeparatorChar}App_Data{Path.DirectorySeparatorChar}Agents";
            var    agent   = rasa.RestoreAgent(importer, meta.Name, dataDir);

            agent.Id                   = meta.Id;
            agent.UserId               = meta.UserId ?? AiBot.BUILTIN_USER_ID;
            agent.ClientAccessToken    = meta.ClientAccessToken;
            agent.DeveloperAccessToken = meta.DeveloperAccessToken;
            rasa.agent                 = agent;

            rasa.agent.SaveAgent(dc);
        }
示例#12
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        wanderOrientation += base.randomBinomial() * wanderRate;
        //Debug.Log (wanderOrientation);

        float targetOrientation = wanderOrientation + Character.getOrientation();

        float targetOrientationRadian = targetOrientation * Mathf.Deg2Rad;
        float orientationRadian       = Character.getOrientation() * Mathf.Deg2Rad;
        //Debug.Log (targetOrientationRadian);
        //Debug.Log (targetOrientation);

        Vector2 target = Character.getPosition()
                         + wanderOffset * new Vector2(Mathf.Cos(orientationRadian), Mathf.Sin(orientationRadian)).normalized
                         + wanderRadius * new Vector2(Mathf.Cos(targetOrientationRadian), Mathf.Sin(targetOrientationRadian)).normalized;
        //Debug.Log (Mathf.Cos (180f * Mathf.Deg2Rad));
        //Debug.Log(new Vector2 (Mathf.Cos (targetOrientationRadian), Mathf.Sin (targetOrientationRadian)));

        //Debug.Log (target);

        GameObject dummy      = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  dummyAgent = dummy.GetComponent <AgentMeta> ();

        dummyAgent.setPosition(target);
        dummyAgent.setOrientation(wanderOrientation + Character.getOrientation());
        //dummyAgent.setOrientation (

        //Debug.Log (dummyAgent.getPosition ()- Character.getPosition());

        //Behaviour face = new Face (dummyAgent, Character);
        //Debug.Log (dummyAgent.getPosition () - Character.getPosition());
        //Debug.Log (dummyAgent.getOrientation ());
        //Debug.Log (Character.getOrientation ());

        Behaviour seek = new SeekWhileLooking(dummyAgent, Character);

        //Behaviour lwyg = new LWYG (Character);

        //SteeringOutput.SteeringOutput steering = seek.getSteering () + lwyg.getSteering();
        SteeringOutput.SteeringOutput steering = seek.getSteering();
        Debug.Log(steering.angular);

        //steering.linear = Character.maxAcceleration * new Vector2 (Mathf.Cos (orientationRadian), Mathf.Sin (orientationRadian));

        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
示例#13
0
    public DayMeta NextDay(ref Dictionary <string, GameObject> treeBook)
    {
        DayMeta nextDayMeta = new DayMeta();

        nextDayMeta.day = day + 1;
        // tree
        nextDayMeta.treeMeta = treeMeta;
        bool levelUpTree = false;

        for (int i = 0; i < nextDayMeta.treeMeta.Count; i++)
        {
            if (nextDayMeta.treeMeta [i].level < 6)
            {
                nextDayMeta.treeMeta [i] = nextDayMeta.treeMeta [i].NextDay(ref treeBook);
                levelUpTree = true;
                break;
            }
        }
        if (!levelUpTree)
        {
            // add new tree
            AgentMeta meta = new AgentMeta();
            if (treeBook.ContainsKey("Tree Spirit 1"))
            {
                treeBook ["Tree Spirit 1"].GetComponent <Agent> ().ExportToMeta(ref meta);
                nextDayMeta.treeMeta.Add(meta);
            }
        }
        // spirit
        nextDayMeta.spiritMeta = spiritMeta;
        for (int i = 0; i < nextDayMeta.spiritMeta.Count; i++)
        {
            nextDayMeta.spiritMeta [i] = nextDayMeta.spiritMeta [i].NextDay();
        }
        // ghost
        nextDayMeta.ghostMeta = ghostMeta;
        for (int i = 0; i < nextDayMeta.ghostMeta.Count; i++)
        {
            nextDayMeta.ghostMeta [i] = nextDayMeta.ghostMeta [i].NextDay();
        }
        nextDayMeta.numOfSpirits = numOfSpirits + 6;
        nextDayMeta.numOfGhosts  = numOfGhosts + 8;
        return(nextDayMeta);
    }
	public override SteeringOutput.SteeringOutput getSteering() {

		Vector2 futurePos = Character.getPosition () + Character.getVelocity () * predictTime;

		currentParam = path.getParam (futurePos, currentParam);

		float targetParam = currentParam + PathOffset;

		GameObject dummy = (GameObject) MonoBehaviour.Instantiate (Resources.Load ("Prefab/Dummy"));
		AgentMeta dummyAgent = dummy.GetComponent<AgentMeta> ();
		dummyAgent.setPosition (path.getPosition (targetParam));

		Behaviour seek = new Seek (dummyAgent, Character);
		SteeringOutput.SteeringOutput steering = seek.getSteering ();

		MonoBehaviour.Destroy (dummy);
		return steering; 

	}
示例#15
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput();
        Vector2 dir = Target.position - Character.position;

        if (dir.magnitude == 0)
        {
            return(steering);
        }

        GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  aux   = dummy.GetComponent <AgentMeta> ();

        aux.position    = Target.position;
        aux.orientation = Mathf.Atan2(-dir.x, dir.y) * Mathf.Rad2Deg;
        Behaviour alinear = new Align(aux, Character, Mathf.PI / 4, Mathf.PI / 10, .1f);

        //steering.linear = steering.linear.normalized * Character.maxAcceleration;
        steering = alinear.getSteering();
        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
示例#16
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput();
        Vector2 velocity = Character.velocity;

        if (velocity.magnitude == 0)
        {
            return(steering);
        }

        GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  aux   = dummy.GetComponent <AgentMeta> ();

        aux.position    = new Vector2(0.0f, 0.0f);
        aux.orientation = (Mathf.Atan2(-velocity.x, velocity.y) * Mathf.Rad2Deg) % 360.0f;
        Behaviour alinear = new Align(aux, Character, Mathf.PI / 100, Mathf.PI / 10, .1f);

        //steering.linear = steering.linear.normalized * Character.maxAcceleration;
        steering = alinear.getSteering();
        MonoBehaviour.Destroy(dummy);

        return(steering);
    }
示例#17
0
    public AgentMeta NextDay()
    {
        AgentMeta nextAgentMeta = new AgentMeta();

        nextAgentMeta.tag        = tag;
        nextAgentMeta.name       = name;
        nextAgentMeta.damage     = damage;
        nextAgentMeta.damageTime = damageTime;
        nextAgentMeta.num        = num;
        nextAgentMeta.speed      = speed;
        nextAgentMeta.health     = health;
        nextAgentMeta.defense    = defense;
        nextAgentMeta.level      = level;
        nextAgentMeta.rate       = rate;
        nextAgentMeta.gameObject = gameObject;

        if (nextAgentMeta.tag == "Ghost")
        {
            nextAgentMeta.LevelUp(ref nextAgentMeta);
            nextAgentMeta.rate++;
        }

        return(nextAgentMeta);
    }
示例#18
0
    public void LevelUp(ref AgentMeta meta)
    {
        if (meta.tag == "Ghost")
        {
            if (meta.defense != -1)
            {
                meta.damage *= 1.1f;
            }

            if (meta.health != -1)
            {
                meta.health *= 1.1f;
            }

            if (meta.defense != -1)
            {
                meta.defense *= 1.05f;
            }

            if (meta.defense > 0.7f)
            {
                meta.defense = 0.7f;
            }
        }

        if (meta.tag == "Spirit")
        {
            if (meta.defense != -1)
            {
                meta.damage *= 1.1f;
            }

            if (meta.health != -1)
            {
                meta.health *= 1.1f;
            }

            if (meta.defense != -1)
            {
                meta.defense *= 1.05f;
            }

            if (meta.defense > 0.7f)
            {
                meta.defense = 0.7f;
            }

            if (meta.cost != -1)
            {
                meta.cost *= 2;
            }
        }

        if (meta.tag == "Tree")
        {
            if (meta.health != -1)
            {
                meta.health += 80;
            }
        }

        meta.level += 1;

        ExportToPrefab();
    }
 public EvadeWhileLooking(AgentMeta target, AgentMeta character, float MaxPrediction)
     : base("Evade", target, character, MaxPrediction)
 {
 }
示例#20
0
 // Set de las variables
 public void setTarget(AgentMeta target)
 {
     Target = target;
 }
示例#21
0
 public void setCharacter(AgentMeta character)
 {
     Character = character;
 }
示例#22
0
 public Behaviour(string behaviourName, AgentMeta target, AgentMeta character)
 {
     Name      = behaviourName;
     Target    = target;
     Character = character;
 }
示例#23
0
 public Poke(AgentMeta target, AgentMeta character, float pokeRadius)
     : base("Poke", target, character)
 {
     pokeDistance = pokeRadius;
 }
示例#24
0
 public Face(AgentMeta target, AgentMeta character) : base("Face", target, character)
 {
 }
示例#25
0
 public Seek(AgentMeta target, AgentMeta character) : base("Seek", target, character)
 {
 }
示例#26
0
 public Stalking(AgentMeta target, AgentMeta character, float SlowRadius, float TargetRadius, float TimeToTarget, float StalkRadius)
     : base("Stalk", target, character, SlowRadius, TargetRadius, TimeToTarget)
 {
     stalkRadius = StalkRadius;
 }
示例#27
0
 public Arrive(AgentMeta target, AgentMeta character, float SlowRadius, float TargetRadius, float TimeToTarget)
     : base("Arrive", target, character, SlowRadius, TargetRadius, TimeToTarget)
 {
 }
示例#28
0
 public LWYG(AgentMeta character) : base("Look where you're going")
 {
     Character = character;
 }
示例#29
0
    public void Init()
    {
        trees.Clear();
        treeBook.Clear();
        spirits.Clear();
        spiritBook.Clear();
        ghosts.Clear();
        ghostBook.Clear();

        int index;

        // trees
        index = 1;
        foreach (GameObject tree in allTrees)
        {
            Agent agent = tree.GetComponent <Agent>();
            if (!treeBook.ContainsKey(agent.name))
            {
                treeBook.Add(agent.name, agent.gameObject);
                agent.id = index;
                // agent.level = 1;
                agent.agentManager = this;
                trees.Add(agent);
                index++;
            }
        }

        // spirits
        index = 1;
        foreach (GameObject spirit in allSpirits)
        {
            Agent agent = spirit.GetComponent <Agent>();
            if (!spiritBook.ContainsKey(agent.name))
            {
                spiritBook.Add(agent.name, agent.gameObject);
                agent.id = index;
                // agent.level = 1;
                agent.agentManager = this;
                spirits.Add(agent);
                index++;
            }
        }

        // ghosts
        index = 1;
        foreach (GameObject ghost in allGhosts)
        {
            Agent agent = ghost.GetComponent <Agent>();
            if (!ghostBook.ContainsKey(agent.name))
            {
                ghostBook.Add(agent.name, agent.gameObject);
                agent.id = index;
                // agent.level = 1;
                agent.agentManager = this;
                ghosts.Add(agent);
                index++;
            }
        }

        // dictionary
        dayMeta.Clear();

        // AgentMeta todaysTree = null;
        List <AgentMeta> todaysTrees   = new List <AgentMeta> ();
        List <AgentMeta> todaysSpirits = new List <AgentMeta> ();
        List <AgentMeta> todaysGhosts  = new List <AgentMeta> ();
        DayMeta          todaysMeta;
        AgentMeta        agentMeta;
        int day       = 0;
        int spiritNum = 0;
        int ghostNum  = 0;
        int lineNum   = 0;
        int lineIndex = 0;
        // string line;

        //-------start loading data
        TextAsset txt     = (TextAsset)Resources.Load("DayMeta", typeof(TextAsset));
        string    content = txt.text;

        string[] lines = Regex.Split(content, "\n|\r|\r\n");
        // StreamReader theReader = new StreamReader ("Assets/Data/DayMeta.txt", Encoding.Default);
        // using (theReader)
        // {
        // do
        // {
        // line = theReader.ReadLine();
        // if (line != null)
        // {
        foreach (string line in lines)
        {
            string[] entries = line.Split(',');
            if (entries.Length == 4)
            {
                day       = int.Parse(entries [0]);
                spiritNum = int.Parse(entries [1]);
                ghostNum  = int.Parse(entries [2]);
                lineNum   = int.Parse(entries [3]);
                lineIndex = 0;
                // todaysTree = null;
                todaysTrees   = new List <AgentMeta> ();
                todaysSpirits = new List <AgentMeta> ();
                todaysGhosts  = new List <AgentMeta> ();
            }

            if (lineIndex < lineNum)
            {
                if (entries.Length == 12)
                {
                    lineIndex++;
                    if (day != int.Parse(entries [0]))
                    {
                        continue;
                    }
                    if (treeBook.ContainsKey(entries [2]))
                    {
                        agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], treeBook [entries [2]]);
                        agentMeta.ExportToPrefab();
                        agentMeta.ExportFromPrefab();
                        todaysTrees.Add(agentMeta);
                    }
                    if (spiritBook.ContainsKey(entries [2]))
                    {
                        agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], spiritBook [entries [2]]);
                        agentMeta.ExportToPrefab();
                        agentMeta.ExportFromPrefab();
                        todaysSpirits.Add(agentMeta);
                    }
                }
                if (entries.Length == 13)
                {
                    lineIndex++;
                    if (day != int.Parse(entries [0]))
                    {
                        continue;
                    }
                    if (ghostBook.ContainsKey(entries [2]))
                    {
                        agentMeta = new AgentMeta(entries [1], entries [2], entries [3], entries [4], entries [5], entries [6], entries [7], entries [8], entries [9], entries [10], entries [11], ghostBook [entries [2]]);
                        agentMeta.ExportToPrefab();
                        agentMeta.ExportFromPrefab();
                        agentMeta.LevelUp(int.Parse(entries [12]));
                        todaysGhosts.Add(agentMeta);
                    }
                }
            }

            if (lineIndex == lineNum)
            {
                lineIndex++;
                todaysMeta = new DayMeta(day, todaysTrees, todaysSpirits, todaysGhosts, spiritNum, ghostNum);
                dayMeta.Add(todaysMeta);
            }
        }
        // }
        // }
        // while (line != null);
        // theReader.Close();
        //  }
        //-------finish loading data
    }
示例#30
0
 public VelocityMatching(AgentMeta target, AgentMeta character) : base("Velocity Matching", target, character)
 {
 }