コード例 #1
0
ファイル: Odin.cs プロジェクト: adrientoub/CrystalGate
        protected override void IA(List <Unite> unitsOnMap)
        {
            if (!isAtRange)
            {
                if (Outil.DistanceUnites(Outil.GetJoueur(Client.id).champion, this) <= 600)
                {
                    isAtRange = true;
                }
            }
            if (isAtRange)
            {
                if (!timer.IsRunning)
                {
                    timer.Start();
                }

                if (timer.Elapsed.Seconds < 1)
                {
                    color = Color.Red;
                }

                if (timer.Elapsed.Seconds > 1 && timer.Elapsed.Seconds < 8)
                {
                    if (IsCastable(0))
                    {
                        for (int i = 0; i < spellsUpdate.Count; i++)
                        {
                            if (spellsUpdate[i].idSort == 45)
                            {
                                spellsUpdate.RemoveAt(i);
                            }
                        }
                        ((NovaDeFeu)spells[0]).Positions.Clear();
                        Cast(spells[0], Vector2.Zero, null);
                        ObjectifListe.Clear();
                        color = Color.White;
                    }
                    uniteAttacked = null;
                }
                else
                {
                    spellsUpdate.Clear();
                    uniteAttacked = Outil.GetJoueur(Client.id).champion;
                    if (timer.Elapsed.Seconds > 11)
                    {
                        timer.Reset();
                    }
                }
            }
        }
コード例 #2
0
        public byte[] Serialize()
        {
            ASCIIEncoding   ascii     = new ASCIIEncoding();
            MemoryStream    stream    = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            // Definition du contenu
            Player p     = new Player();
            Joueur Local = Outil.GetJoueur(Client.id);

            // Pathfinding
            if (Mooved)
            {
                p.Mooved = true;
                List <Noeud> chemin = PathFinding.TrouverChemin(champion.PositionTile, ObjectifPoint, Map.Taille, new List <Unite> {
                }, Map.unitesStatic, false);
                p.objectifPointX = chemin[chemin.Count - 1].Position.X;
                p.objectifPointY = chemin[chemin.Count - 1].Position.Y;
                Mooved           = false;
            }

            // Unité visé
            p.idUniteAttacked = Local.champion.idUniteAttacked;

            p.LastDeath = Serveur.LastDead;
            // Unit dernierement morte selon le serveur
            SendSpell(p);

            // meme map?
            p.level = SceneHandler.level;

            if (lastItemUsed != -1)
            {
                p.LastItemUsed = lastItemUsed;
                lastItemUsed   = -1;
            }
            if (lastStuffUsed != -1)
            {
                p.LastStuffUsed = lastStuffUsed;
                lastStuffUsed   = -1;
            }

            formatter.Serialize(stream, p);
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);

            return(buffer);
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: adrientoub/CrystalGate
        public static void Unserialize(int IdDuJoueur, byte[] buffer)
        {
            // Traitement
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream    = new MemoryStream(buffer);

            stream.Position = 0;
            // mettre un try catch
            Player player = (Player)formatter.Deserialize(stream);

            if (Outil.GetJoueur(IdDuJoueur) != null && player.level == SceneHandler.level)
            {
                Joueur joueur = Outil.GetJoueur(IdDuJoueur);
                // Pathfinding
                if (player.Mooved)
                {
                    List <Noeud> path = PathFinding.TrouverChemin(joueur.champion.PositionTile, new Vector2(player.objectifPointX, player.objectifPointY), Map.Taille, Map.unites, Map.unitesStatic, true);
                    if (path != null)
                    {
                        joueur.champion.ObjectifListe = path;
                    }
                    else
                    {
                        joueur.champion.ObjectifListe.Clear();
                    }
                }
                // Unité ciblé
                if (player.idUniteAttacked != 0)
                {
                    foreach (Unite u in Map.unites)
                    {
                        if (u.id == player.idUniteAttacked)
                        {
                            joueur.champion.uniteAttacked = u;
                        }
                    }
                }
                else
                {
                    joueur.champion.uniteAttacked = null;
                }
                // Sorts
                if (player.idSortCast != 0)
                {
                    Unite        u = joueur.champion;
                    List <Spell> toutLesSpellsPossibles = new List <Spell> {
                        new Explosion(u), new Soin(u), new Invisibilite(u), new FurieSanguinaire(u), new Polymorphe(u), new Tempete(u)
                    };

                    foreach (Spell s in toutLesSpellsPossibles)
                    {
                        if (s.idSort == player.idSortCast)
                        {
                            s.Point = new Vector2(player.pointSortX, player.pointSortY);
                            if (player.idUniteCibleCast != 0)
                            {
                                foreach (Unite un in Map.unites)
                                {
                                    if (un.id == player.idUniteCibleCast)
                                    {
                                        s.UniteCible = un;
                                    }
                                }
                            }
                            joueur.champion.Cast(s, new Vector2(player.pointSortX, player.pointSortY), s.UniteCible, true);
                            break;
                        }
                    }
                }
                // Clear morts
                foreach (Unite u in Map.unites)
                {
                    foreach (byte b in player.LastDeath)
                    {
                        if (u.id == b)
                        {
                            u.Vie = 0;
                            break;
                        }
                    }
                }
                try
                {
                    Unite   u = joueur.champion;
                    Vector2 v = Vector2.Zero;

                    List <Item> items = new List <Item> {
                        new PotionDeVie(u, v), new PotionDeMana(u, v)
                    };
                    List <Stuff> stuffs = new List <Stuff> {
                        new BottesDacier(u, v), new Epaulieres(u, v), new EpeeSolari(u, v), new GantsDeDevotion(u, v), new HelmetPurple(u, v), new RingLionHead(u, v)
                    };
                    // Utilisation inventaire
                    // Objets
                    if (player.LastItemUsed != -1)
                    {
                        bool found = false;
                        // On regarde si il est dans l'inventaire
                        for (int i = 0; i < joueur.champion.Inventory.Count; i++)
                        {
                            if (joueur.champion.Inventory[i].id == player.LastItemUsed)
                            {
                                joueur.champion.Inventory[i].Utiliser();
                                found = true;
                                break;
                            }
                        }
                        // Sinon on l'ajoute
                        if (!found)
                        {
                            foreach (Item i in items)
                            {
                                if (i.id == player.LastItemUsed)
                                {
                                    joueur.champion.Inventory.Add(i);
                                    joueur.champion.Inventory[joueur.champion.Inventory.Count - 1].Utiliser();
                                }
                            }
                        }
                    }

                    // Stuff
                    if (player.LastStuffUsed != -1)
                    {
                        bool found = false;
                        // On regarde si il est dans l'inventaire
                        for (int i = 0; i < joueur.champion.Inventory.Count; i++)
                        {
                            if (joueur.champion.Inventory[i].id == player.LastStuffUsed)
                            {
                                ((Stuff)joueur.champion.Inventory[i]).Equiper();
                                found = true;
                                break;
                            }
                        }
                        // Sinon on l'ajoute
                        if (!found)
                        {
                            foreach (Stuff s in stuffs)
                            {
                                if (s.id == player.LastStuffUsed)
                                {
                                    joueur.champion.Inventory.Add(s);
                                    ((Stuff)joueur.champion.Inventory[joueur.champion.Inventory.Count - 1]).Equiper();
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // On sait jamais
                }
            }
        }