private IEnumerator Move() { ele = GO.GetComponent<Unite>(); deplacement = ele.deplacement; mouvement = ele.mouvement; if (deplacement != null) { if (deplacement.Count == 0) { ele.deplacement = null; mouvement = 0; } else { StartCoroutine("MoveTowards"); } } else { int rand = UnityEngine.Random.Range(7, 19); if (ele.camp.Equals("Ours")) { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 50, rand); } else { ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, 2, rand); } } yield break; }
public override bool Execute() { uni = GO.GetComponent<Unite>(); dist = new List<float>(); foreach (KeyValuePair<float, Vector3> entry in uni.enn_pos) { dist.Add(entry.Key); } dist.Sort(); StartCoroutine("Projectile"); return true; }
public void Produire(string nomUnite, bool[][] recherche) { Vector2 depart = new Vector2(transform.position.x - largeur / 2 - 0.5f, transform.position.y - hauteur / 2 - 1.5f); if (Niveau.grille[(int)depart.x, (int)depart.y].GetComponent <Case>().occupe == false) { //SCUnite = new Unite(); //0=ours, 1=poulpe; 0=bon arme; 1 bon armure, 2 bon pv double[][] bonus = new double[2][]; for (int i = 0; i < 2; i++) { bonus[i] = new double[3]; for (int j = 0; j < 3; j++) { bonus[i][j] = 1; } } if (recherche[0][0]) { bonus[0][0] = 1.3; } if (recherche[0][1]) { bonus[0][1] = 1.2; } if (recherche[1][0]) { bonus[1][0] = 1.3; } if (recherche[1][1]) { bonus[1][1] = 1.2; } switch (nomUnite) { case "Collecteur_ours": unite = Instantiate(Resources.Load("Prefab/Ours/Collecteur")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Collecteur_ours#" + num, "Ours", "", 1, 5 * bonus[0][1], 1, 1, 1, 5, false, 5); SCUnite.mouvement = 1; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "Collecteur"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Collecteur_Poulpe": unite = Instantiate(Resources.Load("Prefab/Poulpe/Collecteur")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Collecteur_Poulpe#" + num, "Poulpe", "", 1, 5 * bonus[0][1], 1, 1, 1, 5, false, 5); SCUnite.mouvement = 1; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "Collecteur"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ourson": unite = Instantiate(Resources.Load("Prefab/Ours/Ourson")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Ourson #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 50); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ours Blanc": unite = Instantiate(Resources.Load("Prefab/Ours/Ours Blanc")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Ours Blanc #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 150); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ours de guerre": unite = Instantiate(Resources.Load("Prefab/Ours/Ours de guerre")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Ours de guerre #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 300); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Poulpy": unite = Instantiate(Resources.Load("Prefab/Poulpe/Poulpy")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Poulpy #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 50); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Octopus": unite = Instantiate(Resources.Load("Prefab/Poulpe/Octopus")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Octopus #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 150); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Cyber-poulpe": unite = Instantiate(Resources.Load("Prefab/Poulpe/Cyber-poulpe")) as GameObject; SCUnite = unite.AddComponent <Unite>(); SCUnite.Initialize("Cyber-poulpe #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 300); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent <RuleBase>(); unite.AddComponent <State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent <InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; default: Debug.Log("Nom d'unité inconnu, production annulée"); break; } for (int i = 0; i < SCUnite.hauteur; i++) { for (int j = 0; j < SCUnite.largeur; j++) { SCUnite.list_case[i, j] = Niveau.grille[(int)(i + unite.transform.position.x - 0.5), (int)(j + unite.transform.position.y - 0.5)]; SCUnite.list_case[i, j].GetComponent <Case>().occupe = true; SCUnite.list_case[i, j].GetComponent <Case>().element = unite; } } if (SCUnite.camp == "Ours") { Niveau.list_element[0].Add(unite); } else { Niveau.list_element[1].Add(unite); } } }
private Vector2 PlacerUnite(GameObject uniteAPlacer) { Unite SCUnite = uniteAPlacer.GetComponent <Unite>(); int numTour = 1; bool place = false; Vector2 position = new Vector2(); Vector2 depart = new Vector2(transform.position.x - SCUnite.largeur / 2 - 0.5f, transform.position.y - SCUnite.hauteur / 2 - 1.5f); if (Niveau.grille[(int)depart.x, (int)depart.y].GetComponent <Case>().occupe == false) { Niveau.grille[(int)depart.x, (int)depart.y].GetComponent <Case>().occupe = true; Niveau.grille[(int)depart.x, (int)depart.y].GetComponent <Case>().element = uniteAPlacer; position = depart; } else { while (place == false && numTour < 1000) { for (int i = 0; i < hauteur; i++) { for (int j = 0; j < largeur; j++) { if (Niveau.grille[((int)(list_case[j, i].transform.position.x + 1)), ((int)(list_case[j, i].transform.position.y))] .GetComponent <Case>().occupe == false) { position = new Vector2((int)list_case[j, i].transform.position.x + 1.5f, (int)list_case[j, i].transform.position.y + 0.5f); place = true; } else if (Niveau.grille[(int)(list_case[j, i].transform.position.x - 1), (int)(list_case[j, i].transform.position.y)] .GetComponent <Case>().occupe == false) { position = new Vector2((int)list_case[j, i].transform.position.x - 0.5f, (int)list_case[j, i].transform.position.y + 0.5f); place = true; } else if (Niveau.grille[(int)(list_case[j, i].transform.position.x), (int)(list_case[j, i].transform.position.y + 1)] .GetComponent <Case>().occupe == false) { position = new Vector2((int)list_case[j, i].transform.position.x + 0.5f, (int)list_case[j, i].transform.position.y + 1.5f); place = true; } else if (Niveau.grille[(int)(list_case[j, i].transform.position.x), (int)(list_case[j, i].transform.position.y - 1)] .GetComponent <Case>().occupe == false) { position = new Vector2((int)list_case[j, i].transform.position.x + 0.5f, (int)list_case[j, i].transform.position.y - 0.5f); place = true; } } } numTour++; } } return(position); }
public void Produire(string nomUnite, bool[][] recherche) { Vector2 depart = new Vector2(transform.position.x - largeur / 2 - 0.5f, transform.position.y - hauteur / 2 - 1.5f); if (Niveau.grille[(int)depart.x, (int)depart.y].GetComponent<Case>().occupe == false) { //SCUnite = new Unite(); //0=ours, 1=poulpe; 0=bon arme; 1 bon armure, 2 bon pv double[][] bonus = new double[2][]; for (int i = 0; i < 2; i++) { bonus[i] = new double[3]; for (int j = 0; j < 3; j++) { bonus[i][j] = 1; } } if (recherche[0][0]) { bonus[0][0] = 1.3; } if (recherche[0][1]) { bonus[0][1] = 1.2; } if (recherche[1][0]) { bonus[1][0] = 1.3; } if (recherche[1][1]) { bonus[1][1] = 1.2; } switch (nomUnite) { case "Collecteur_ours": unite = Instantiate(Resources.Load("Prefab/Ours/Collecteur")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Collecteur_ours#" + num, "Ours", "", 1, 5 * bonus[0][1], 1, 1, 1, 5, false, 5); SCUnite.mouvement = 1; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "Collecteur"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Collecteur_Poulpe": unite = Instantiate(Resources.Load("Prefab/Poulpe/Collecteur")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Collecteur_Poulpe#" + num, "Poulpe", "", 1, 5 * bonus[0][1], 1, 1, 1, 5, false, 5); SCUnite.mouvement = 1; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "Collecteur"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ourson": unite = Instantiate(Resources.Load("Prefab/Ours/Ourson")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Ourson #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 50); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ours Blanc": unite = Instantiate(Resources.Load("Prefab/Ours/Ours Blanc")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Ours Blanc #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 150); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Ours de guerre": unite = Instantiate(Resources.Load("Prefab/Ours/Ours de guerre")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Ours de guerre #" + num, "Ours", "", 1, 10 * bonus[0][1], 0, 1, 0, 10, false, 300); SCUnite.attaque = new Attaque(1 * bonus[0][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Poulpy": unite = Instantiate(Resources.Load("Prefab/Poulpe/Poulpy")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Poulpy #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 50); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Octopus": unite = Instantiate(Resources.Load("Prefab/Poulpe/Octopus")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Octopus #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 150); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 2; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; case "Cyber-poulpe": unite = Instantiate(Resources.Load("Prefab/Poulpe/Cyber-poulpe")) as GameObject; SCUnite = unite.AddComponent<Unite>(); SCUnite.Initialize("Cyber-poulpe #" + num, "Poulpe", "", 1, 8 * bonus[1][1], 10, 1, 0, 10, false, 300); SCUnite.attaque = new Attaque(1 * bonus[1][0], 0, 5, 0, "normal", 2); SCUnite.mouvement = 1; num++; unite.AddComponent<RuleBase>(); unite.AddComponent<State>(); unite.transform.position = PlacerUnite(unite); engine = unite.AddComponent<InferenceEngine>(); engine.m_RuleBaseFilePath = "unite"; engine.m_RuleBaseTick = (int)(Chargement_jeu.turnTimeStatic * 2000f); break; default: Debug.Log("Nom d'unité inconnu, production annulée"); break; } for (int i = 0; i < SCUnite.hauteur; i++) { for (int j = 0; j < SCUnite.largeur; j++) { SCUnite.list_case[i, j] = Niveau.grille[(int)(i + unite.transform.position.x - 0.5), (int)(j + unite.transform.position.y - 0.5)]; SCUnite.list_case[i, j].GetComponent<Case>().occupe = true; SCUnite.list_case[i, j].GetComponent<Case>().element = unite; } } if (SCUnite.camp == "Ours") { Niveau.list_element[0].Add(unite); } else { Niveau.list_element[1].Add(unite); } } }
public override bool Execute() { ele = Go.GetComponent<Unite>(); deplacement = ele.deplacement; mouvement = ele.mouvement; State etat = Go.GetComponent<State>(); Variable var = new Variable(); etat.GetVariable("prox", out var); if ((int)var.GetValue() == 1) { if (!calcule) { direction = 1; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); deplacement = ele.deplacement; calcule = true; init=1; } } else if ((int)var.GetValue() == 2) { if (!calcule) { direction = 2; Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); calcule = true; if (Go.GetComponent<Element>().camp == "Ours") { Score.ressource_IA[0] += Unite.stockage*init; Score.ressourcediv_IA[0][0] += Unite.stockage*init * Batiment.aggressivite / 100; Score.ressourcediv_IA[0][1] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[0][2] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } else if (Go.GetComponent<Element>().camp == "Poulpe") { Score.ressource_IA[1] += Unite.stockage*init; Score.ressourcediv_IA[1][0] += Unite.stockage *init* Batiment.aggressivite / 100; Score.ressourcediv_IA[1][1] += Unite.stockage*init * (1 - Batiment.aggressivite / 100) * Batiment.defense / 100; Score.ressourcediv_IA[1][2] += Unite.stockage *init* (1 - Batiment.aggressivite / 100) * Batiment.technologie / 100; } } } else if ((int)var.GetValue() == 0) { calcule = false; } if (deplacement != null) { if (deplacement.Count != 0) { for (int i = 0; i < ele.hauteur; i++) { for (int j = 0; j < ele.largeur; j++) { ele.list_case[i, j] = Niveau.grille[(int)(i + Go.transform.position.x - 0.5), (int)(j + Go.transform.position.y - 0.5)]; ele.list_case[i, j].GetComponent<Case>().occupe = false; ele.list_case[i, j].GetComponent<Case>().element = null; } } StartCoroutine("MoveTowards"); } else { Vector2 res = FindRessource(); ele.deplacement = Niveau.boucle_path((int)this.gameObject.transform.position.x, (int)this.gameObject.transform.position.y, (int)res.x, (int)res.y); mouvement = 0; } } return true; }