public void AddMiner(string s)
    {
        if (_minersAdded.Count >= maxMiners)
        {
            return;
        }

        AIPersonality pers   = AIPersonality.Basic;
        var           values = Enum.GetValues(typeof(AIPersonality));

        foreach (AIPersonality v in values)
        {
            if (s == v.ToString())
            {
                pers = v;
            }
        }

        GameObject go = Instantiate(_minerDataPrefab, Vector3.zero, Quaternion.identity);

        go.transform.parent     = _minerDataParent;
        go.transform.localScale = new Vector3(1, 1, 1);
        MinerAddedData d = go.GetComponent <MinerAddedData>();

        d.Personality = pers;
        d.selection   = this;
        _minersAdded.Add(d);
        UpdateMinerDataIDs();
    }
        static AIPersonality Parse(StreamReader sr)
        {
            AIPersonality result = new AIPersonality();
            string        line;

            while ((line = sr.ReadLine()) != null)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                line = line.Trim(); // get rid of whitespaces
                if (line.StartsWith(preamble))
                {
                    ReadIndex(line, result);
                }
                else if (line.StartsWith(preambleZero))
                {
                    ReadIndexZero(line, result);
                }
                else
                {
                    continue;
                }
            }

            return(result);
        }
        static void ReadIndexZero(string line, AIPersonality result)
        {
            // find field value
            int startIndex = line.IndexOf('=', preambleZero.Length);

            if (startIndex < 0)
            {
                Console.WriteLine("Err0r (field value search '='): " + line);
                return;
            }
            startIndex++;

            int endIndex = line.IndexOf(';', startIndex);

            if (endIndex < 0)
            {
                Console.WriteLine("Err0r (field value search ';'): " + line);
                return;
            }

            string str = line.Substring(startIndex, endIndex - startIndex).Trim();

            if (!int.TryParse(str, out int value))
            {
                Console.WriteLine("Err0r (field value parsing): " + line);
                return;
            }

            result.SetByIndex(0, value);
        }
Beispiel #4
0
    public static Transform ChooseElevator(int playerIndex, List <Collider2D> objs)
    {
        if (objs.Count == 0)
        {
            return(null);
        }

        AIPersonality pers = GameData.Instance.AIs[playerIndex];

        if (pers == AIPersonality.Basic || pers == AIPersonality.Explorer) //go to deepest mine :)
        {
            int       maxFloor = 0;
            Transform t        = null;
            for (int i = 0; i < objs.Count; i++)
            {
                if (objs[i].GetComponent <ElevatorObj>().floor > maxFloor)
                {
                    maxFloor = objs[i].GetComponent <ElevatorObj>().floor;
                    t        = objs[i].transform;
                }
            }
            return(t);
        }

        return(null);
    }
Beispiel #5
0
    public static bool BuildElevator(int playerIndex)
    {
        AIPersonality pers         = GameData.Instance.AIs[playerIndex];
        int           currentFloor = GameData.Instance.playerFloors[playerIndex][GameData.Instance.playerMineLocations[playerIndex]];

        int currentElevator = 0;

        for (int i = 0; i < GameData.Instance.playerElevators[playerIndex].Count; i++)
        {
            if (GameData.Instance.playerElevators[playerIndex][i].mineType == GameData.Instance.playerMineLocations[playerIndex])
            {
                currentElevator = GameData.Instance.playerElevators[playerIndex][i].floor;
            }
        }

        if (currentFloor <= currentElevator)
        {
            return(false);
        }
        if (GameData.Instance.playerOreSupplies[playerIndex][TileType.Coal] < 20)
        {
            return(false);
        }

        if (pers == AIPersonality.Basic || pers == AIPersonality.Explorer)
        {
            if (currentFloor - currentElevator >= 10 && Random.Range(0, 3) > 1)
            {
                return(true);
            }
        }

        return(false);
    }
Beispiel #6
0
    private void instantiateIA(AIPersonality.Personalities type, Vector3 pos, int number, Color color)
    {
        currentIA = Instantiate(mockIA);
        currentIA.GetComponent <SpriteRenderer>().sprite = SpriteBase;
        currentIA.name  = "IA";
        currentIA.name += number;
        currentIA.GetComponent <SpriteRenderer>().color = color;
        currentIA.transform.position = pos;
        AIPersonality Aipers = currentIA.GetComponent <AIPersonality>();

        Aipers.SetMyOwnIndex(number);
        Aipers.health = 100;
        Aipers.attack = 10;
        Aipers.configurePersonality(type);
        GameObject image = Instantiate(LifeImage);

        Aipers.HealthImage = image;
        image.transform.SetParent(Aipers.panel.transform);
        image.transform.position   = currentIA.transform.position;
        image.transform.localScale = Vector3.one;

        var collider = currentIA.GetComponent <BoxCollider2D>();

        //esto tiene que ser asi

        collider.size = new Vector2(9.7f, 12f);
        VisibleElements.visibleGameObjects.Add(currentIA);
        currentIA.transform.Rotate(Vector3.up * Random.Range(0f, 1f) * 360);
    }
Beispiel #7
0
 public BehaviorVariableScope GetScopeForAIPersonality(AIPersonality aiPersonality)
 {
     if (scopesByAIPersonality.ContainsKey(aiPersonality))
     {
         return(scopesByAIPersonality[aiPersonality]);
     }
     return(null);
 }
Beispiel #8
0
    private void instantiateIA(AIPersonality.Personalities type)
    {
        currentIA       = Instantiate(mockIA);
        currentIA.name  = "IA";
        currentIA.name += Time.time * 100;
        AIPersonality Aipers = currentIA.GetComponent <AIPersonality>();

        Aipers.configurePersonality(type);
        VisibleElements.visibleGameObjects.Add(currentIA);
        fixIt = true;
    }
Beispiel #9
0
            public ScopeDesc(string name, AIMood mood)
            {
                this.Name          = name;
                this.ScopeKind     = ScopeKind.Global;
                this.UnitRole      = UnitRole.Undefined;
                this.AIPersonality = AIPersonality.Undefined;
                this.AISkillID     = AISkillID.Undefined;
                this.Mood          = mood;

                privateFactionValue = FactionEnumeration.GetInvalidUnsetFactionValue();
                FactionID           = privateFactionValue.Name;
            }
Beispiel #10
0
    public static Transform GetTargetedTileTransformFromMap(Collider2D[] interactableObjects, TileType toSeek, int playerIndex, Transform playerPos)
    {
        AIPersonality    pers           = GameData.Instance.AIs[playerIndex];
        List <Transform> tileTransforms = new List <Transform>();

        for (int i = 0; i < interactableObjects.Length; i++)
        {
            if (toSeek == TileType.Stair && interactableObjects[i].gameObject.tag == "Staircase")
            {
                tileTransforms.Add(interactableObjects[i].transform);
            }
            if (toSeek == TileType.Hole && interactableObjects[i].gameObject.tag == "Hole")
            {
                tileTransforms.Add(interactableObjects[i].transform);
            }
            if (interactableObjects[i].GetComponent <BreakableRock>() != null)
            {
                if (interactableObjects[i].GetComponent <BreakableRock>().tileType == toSeek)
                {
                    tileTransforms.Add(interactableObjects[i].transform);
                }
            }
        }

        //find random tile rn
        if (pers == AIPersonality.Basic)
        {
            int rand = Random.Range(0, tileTransforms.Count);
            if (rand < tileTransforms.Count)
            {
                return(tileTransforms[rand]);
            }
        }
        //get closest
        if (pers == AIPersonality.Explorer)
        {
            float     minDist      = 100;
            Transform minTransform = null;
            for (int i = 0; i < tileTransforms.Count; i++)
            {
                if (Vector3.Distance(playerPos.position, tileTransforms[i].position) < minDist)
                {
                    minDist      = Vector3.Distance(playerPos.position, tileTransforms[i].position);
                    minTransform = tileTransforms[i];
                }
            }
            return(minTransform);
        }
        return(null);
    }
 void Start()
 {
     if (this.tag == "IA")
     {
         cycleIA       = this.GetComponent <VisibilityConeCycleIA>();
         personality   = this.GetComponent <AIPersonality> ();
         objSeenBefore = personality.myMemory.objectsSeenBefore;
     }
     else if (this.tag == "Player")
     {
         cyclePlayer       = this.GetComponent <VisibilityConeCycle>();
         playerPersonality = this.GetComponent <PlayerPersonality>();
     }
     agentPositionControllerScript = this.GetComponent <AgentPositionController>();
 }
    // Use this for initialization
    void Start()
    {
        AngleRads = Mathf.Deg2Rad * Angle;

        Radius = 200;

        VisibleConePoints           = new LinkedList <Vector2>();
        visibleGameobjects          = new List <GameObject>();
        targetsAux                  = new List <GameObject>();
        visibleGameobjects.Capacity = 50;
        Objects               = new List <GameObject>();
        whatToDoScript        = this.GetComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
        decisionTargetScript  = this.GetComponent <DecisionTarget>();
        movementController    = GameObject.FindGameObjectWithTag("GameController").GetComponent <BehaviourAdder>();
        whatToDoScript        = this.GetComponent <DecisionTreeISeeSomeoneWhatShouldIDo>();
        Objects               = VisibleElements.visibleGameObjects;
        objecthand            = this.GetComponent <ObjectHandler>();
        personality           = this.GetComponent <AIPersonality>();
        rememberedObject      = new GameObject();
        rememberedObject.name = "rememberedObjectPosition";
    }
Beispiel #13
0
    public static List <TileType> GetTilePreferences(AIPersonality personality)
    {
        List <TileType> types = new List <TileType>();

        if (personality == AIPersonality.Basic)
        {
            types.Add(TileType.Iron);
            types.Add(TileType.Food);
            types.Add(TileType.Coal);
            types.Add(TileType.Diamond);
        }

        if (personality == AIPersonality.Explorer)
        {
            types.Add(TileType.Hole);
            types.Add(TileType.Rock);
            types.Add(TileType.Diamond);
            types.Add(TileType.Stair);
        }

        return(types);
    }
Beispiel #14
0
    public static Mine GetMineChoice(int playerIndex)
    {
        AIPersonality pers = GameData.Instance.AIs[playerIndex];

        if (pers == AIPersonality.Basic)
        {
            int rand = Random.Range(0, 3);
            if (rand == 0)
            {
                return(Mine.IronMine);
            }
            else if (rand == 1)
            {
                return(Mine.JellyMine);
            }
            return(Mine.CoalMine);
        }
        if (pers == AIPersonality.Explorer)
        {
            return(Mine.JellyMine);
        }

        return(Mine.IronMine);
    }
Beispiel #15
0
    public static TileType GetTileTypeToSeek(int playerIndex, bool random)
    {
        if (GameData.Instance.durabilityLevels[playerIndex] <= 0) //if can't use axe anymore, just try traversing as much as possible
        {
            return(TileType.Stair);
        }

        AIPersonality pers  = GameData.Instance.AIs[playerIndex];
        Mine          mine  = GameData.Instance.playerMineLocations[playerIndex];
        int           floor = 0;

        Tile[] currentMineLayout = new Tile[0];
        if (!GameData.Instance.playerFloors[playerIndex].ContainsKey(mine))
        {
            return(TileType.Stair);
        }
        floor = GameData.Instance.playerFloors[playerIndex][mine];

        currentMineLayout = MineRecorder.GetMineFloor(mine, floor);
        Dictionary <TileType, int> tileKinds   = new Dictionary <TileType, int>();
        List <TileType>            preferences = GetTilePreferences(pers);

        for (int i = 0; i < currentMineLayout.Length; i++)
        {
            TileType t = currentMineLayout[i].tileType;

            if (preferences.Contains(t) || random)
            {
                if (tileKinds.ContainsKey(t))
                {
                    tileKinds[t]++;
                }
                else
                {
                    tileKinds.Add(t, 1);
                }
            }
        }

        if (pers == AIPersonality.Basic)
        {
            int rand  = Random.Range(0, tileKinds.Count - 1);
            int index = 0;
            foreach (KeyValuePair <TileType, int> entry in tileKinds)
            {
                if (index == rand)
                {
                    return(entry.Key);
                }
                index++;
            }
        }
        if (pers == AIPersonality.Explorer)
        {
            if (tileKinds.ContainsKey(TileType.Hole))
            {
                return(TileType.Hole);
            }
            int rand = Random.Range(0, 10);
            if (rand < 5)
            {
                return(TileType.Stair);
            }
            return(TileType.Rock);
        }


        return(TileType.Stair);
    }
Beispiel #16
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            Dictionary <string, string> header       = new Dictionary <string, string>();
            List <AICharacter>          AICharacters = new List <AICharacter>();
            AICollection collection = new AICollection();

            Type AICharacterType   = typeof(AICharacter);
            Type AIPersonalityType = typeof(AIPersonality);

            foreach (KeyValuePair <string, object> entry in dictionary)
            {
                AICharacterSerializationException SerializationErrors = new AICharacterSerializationException();
                SerializationErrors.Errors = new List <string>();

                if (entry.Key == "AICShortDescription")
                {
                    foreach (KeyValuePair <string, object> field in (Dictionary <string, object>)entry.Value)
                    {
                        try
                        {
                            header[field.Key] = field.Value.ToString().Substring(0, Math.Min(field.Value.ToString().Length, 1000)).ToString();
                        }
                        catch (ArgumentException)
                        {
                            SerializationErrors.Errors.Add(GetErrorMessage(field.Key, null));
                        }
                    }
                }
                else if (entry.Key == "AICharacters")
                {
                    AICharacter   currentCharacter;
                    AIPersonality currentPersonality;
                    foreach (var character in (System.Collections.ArrayList)entry.Value)
                    {
                        currentCharacter    = new AICharacter();
                        SerializationErrors = new AICharacterSerializationException();

                        foreach (KeyValuePair <string, object> definition in (Dictionary <string, object>)character)
                        {
                            if (definition.Key != "Personality")
                            {
                                try
                                {
                                    SetProperty(AICharacterType, currentCharacter, definition.Key, definition.Value);
                                }
                                catch (Exception e)
                                {
                                    if (e is TargetInvocationException || e is ArgumentException)
                                    {
                                        String customName = currentCharacter.CustomName;
                                        String name       = (currentCharacter._Name != 0) ? null : Enum.GetName(typeof(AICharacterName), currentCharacter._Name);
                                        String errorName  = ((name == null || name.Equals(String.Empty) || customName.Equals(name)) ? String.Empty : " (" + customName + ")");
                                        SerializationErrors.Errors.Add(GetErrorMessage(definition.Key, errorName));
                                    }
                                }
                            }
                            else if (definition.Key == "Personality")
                            {
                                currentPersonality = new AIPersonality();
                                foreach (KeyValuePair <string, object> personalityValue in (Dictionary <string, object>)definition.Value)
                                {
                                    if (personalityValue.Key.ToLowerInvariant().Contains("description") ||
                                        personalityValue.Key.ToLowerInvariant().Contains("comment"))
                                    {
                                        continue;
                                    }
                                    try
                                    {
                                        SetProperty(AIPersonalityType, currentPersonality, personalityValue.Key, personalityValue.Value);
                                    }
                                    catch (ArgumentException)
                                    {
                                        String customName = currentCharacter.CustomName;
                                        String name       = (currentCharacter._Name != 0) ? null : Enum.GetName(typeof(AICharacterName), currentCharacter._Name);
                                        String errorName  = ((name == null || name.Equals(String.Empty) || customName.Equals(name)) ? String.Empty : " (" + customName + ")");
                                        SerializationErrors.Errors.Add(GetErrorMessage(personalityValue.Key, errorName));
                                    }
                                    catch (NullReferenceException)
                                    {
                                        String customName = currentCharacter.CustomName;
                                        String name       = (currentCharacter._Name != 0) ? null : Enum.GetName(typeof(AICharacterName), currentCharacter._Name);
                                        String errorName  = ((name == null || name.Equals(String.Empty) || customName.Equals(name)) ? String.Empty : " (" + customName + ")");
                                        SerializationErrors.Errors.Add(GetErrorMessage(personalityValue.Key, errorName));
                                    }
                                    catch (Exception)
                                    {
                                        String customName = currentCharacter.CustomName;
                                        String name       = (currentCharacter._Name != 0) ? null : Enum.GetName(typeof(AICharacterName), currentCharacter._Name);
                                        String errorName  = ((name == null || name.Equals(String.Empty) || customName.Equals(name)) ? String.Empty : " (" + customName + ")");
                                        SerializationErrors.Errors.Add(GetErrorMessage(personalityValue.Key, errorName));
                                    }
                                }
                                currentCharacter.Personality = currentPersonality;
                            }
                        }
                        AICharacters.Add(currentCharacter);
                        if (SerializationErrors.Errors.Count > 0 || currentCharacter._Name == 0)
                        {
                            String customName = currentCharacter.CustomName;
                            String name       = (currentCharacter._Name != 0) ? null : Enum.GetName(typeof(AICharacterName), currentCharacter._Name);
                            String errorName  = ((name == null || customName.Equals(String.Empty) || customName.Equals(name)) ? String.Empty : " (" + customName + ")");
                            SerializationErrors.AssociatedAICharacter = errorName;

                            if (currentCharacter._Name == 0)
                            {
                                SerializationErrors.Errors.Add(GetErrorMessage("Index", errorName));
                            }

                            AICSerializationExceptionList.ErrorList.Add(SerializationErrors);
                        }
                    }
                }
            }
            if (AICSerializationExceptionList.ErrorList.Count > 0)
            {
                throw AICSerializationExceptionList;
            }
            collection.AICShortDescription = header;
            collection.AICharacters        = AICharacters;
            return(collection);
        }
Beispiel #17
0
 public ScopeDesc(string name, AIMood mood, AIPersonality aiPersonality) : this(name, mood)
 {
     this.AIPersonality = aiPersonality;
     this.ScopeKind     = ScopeKind.Personality;
 }
    /// <summary>
    /// Devuelve el GAmeObject, que la IA NO TIENE, más prioritario
    /// </summary>
    /// <param name="viewedTargets"></param>
    /// <param name="Ai"></param>
    /// <returns></returns>

    public GameObject ChooseTarget(List <GameObject> viewedTargets, GameObject Ai)
    {
        int           priority;
        int           currentTargetpriority;
        string        nameCurrentTarget;
        GameObject    chosenTarget  = null;
        GameObject    currentTarget = null;
        AIPersonality personality   = Ai.GetComponent <AIPersonality>();
        ObjectHandler objectHand    = Ai.GetComponent <ObjectHandler> ();

        memory = Ai.GetComponent <Memory>();

        string priorities = "veo un : ";

        foreach (GameObject target in viewedTargets)
        {
            priority    = priorityTree.GetPriority(target, personality); // Llama al árbol de prioridad que devuelve la prioridad de ese GameObject
            priorities += target.name + " (priority)";
            //Debug.Log("La prioridad de " + target + " es " + priority);

            if (!analyzedTargets.ContainsKey(target) && priority != -1)
            {
                analyzedTargets.Add(target, priority);
            }
        }

        chosenTarget = GivePriorityTarget(analyzedTargets, memory); // Recoge el GameObject más prioritario
        //Debug.Log("elegido es " + chosenTarget.name);
        nameCurrentTarget = objectTraduction(personality);          // Mira qué objeto lleva en ese momento la IA
        if (chosenTarget == null)
        {
            return(chosenTarget);
        }
        if (chosenTarget.tag == "IA")
        {
            analyzedTargets.Clear();

            //active tree
            if (this.GetComponent <GroupScript>().checkIAInGroup(chosenTarget))
            {
                return(null);
            }
            return(chosenTarget);
        }
        else if (chosenTarget.tag == "Player")
        {
            analyzedTargets.Clear();

            //active tree

            return(chosenTarget);
        }
        else if (chosenTarget.name == "Medicalaid" && analyzedTargets[chosenTarget] != 4) //Si el objeto más prioritario que ha visto es un botiquín pero no lo necesita, no lo coge
        {
            return(null);
        }
        else if (nameCurrentTarget != "NONE")
        {
            string aux = "Prefabs/Objects/";
            aux          += nameCurrentTarget;
            currentTarget = Resources.Load(aux) as GameObject;

            currentTargetpriority = priorityTree.GetPriority(currentTarget, personality);
            //Debug.Log ("currentTarget: " + currentTarget);
            //Debug.Log ("prioridad del target actual: " + currentTargetpriority + " prioridad del que estoy viendo: " + analyzedTargets [chosenTarget]);

            if (currentTargetpriority > analyzedTargets[chosenTarget])
            {
                analyzedTargets.Clear();
                chosenTarget = null;
            }
            else
            {
                if (chosenTarget.name == nameCurrentTarget) // Si lleva un objeto y es el que ha visto más prioritario: ese objeto se elimina del diccionario y se recoge el siguiente con más prioridad
                {
                    //Debug.Log ("El que veo es más prioritario");
                    analyzedTargets.Remove(chosenTarget);
                    chosenTarget = GivePriorityTarget(analyzedTargets, memory);
                    analyzedTargets.Clear();
                }
            }
            return(chosenTarget);
        }
        else
        {
            analyzedTargets.Clear();
            return(chosenTarget);
        }
    }
 private void Start()
 {
     personality = GetComponent <AIPersonality> ();
     mesh        = GetComponent <ActorMesh> ();
 }