Beispiel #1
0
        //Carrega a lista de mob e npcs
        public static void LoadNPC()
        {
            DateTime start = Time;

            StreamReader    stream          = new StreamReader($"{Dir}NPCGenerator.xml");
            XmlSerializer   desserializador = new XmlSerializer(typeof(List <SMobList>));
            List <SMobList> mobGenerator    = (List <SMobList>)desserializador.Deserialize(stream);

            MobList = new List <SMobList>();

            for (int i = 0; i < mobGenerator.Count(); i++)
            {
                string path = @"mobs\" + mobGenerator[i].MobName.Trim() + ".xml";

                SMob     mob       = ReadMob(path);
                SMobList vaMobList = mobGenerator[i];
                mob.LastPosition = vaMobList.PositionInicial;
                vaMobList.Mob    = mob;

                vaMobList.Mob.ClientId = (short)(1000 + i);
                MobList.Add(vaMobList);
            }
            Log.Information($"Mob, foram gerados {MobList.Where(a => a.Mob.Merchant == 0).Count():N0} mobs, carregada em [{Time - start}]");
            Log.Information($"Npc, foram gerados {MobList.Where(a => a.Mob.Merchant > 0).Count():N0} npcs, carregada em [{Time - start}]");
        }
        // Construtores
        public static SMobList New()
        {
            SMobList tmp = new SMobList()
            {
                Mob             = SMob.New(),
                Number          = 0,
                Speed           = 1,
                PositionInicial = SPosition.New(),
                PositionFinal   = SPosition.New(),
                FreqStep        = 1,
                IdGroup         = 0,
                Tab             = ""
            };

            return(tmp);
        }
Beispiel #3
0
        public void ExecutaAndarMob()
        {
            while (this.Active)
            {
                for (int i = 0; i < Client.Count(); i++)
                {
                    for (int a = 0; a < Client[i].MobView.Where(b => b.Mob.Merchant == 0).Count(); a++)
                    {
                        //if que decide se o mob anda ou não (50% de chance de andar)
                        if (_rand.Next(0, 100) > 50)
                        {
                            SMobList mob = Client[i].MobView[a];
                            int      x, y;

                            //if para evitar erro do random
                            if (mob.PositionInicial.X < mob.PositionFinal.X)
                            {
                                x = _rand.Next(mob.PositionInicial.X, mob.PositionFinal.X);
                            }
                            else
                            {
                                x = _rand.Next(mob.PositionFinal.X, mob.PositionInicial.X);
                            }

                            if (mob.PositionInicial.Y < mob.PositionFinal.Y)
                            {
                                y = _rand.Next(mob.PositionInicial.Y, mob.PositionFinal.Y);
                            }
                            else
                            {
                                y = _rand.Next(mob.PositionFinal.Y, mob.PositionInicial.Y);
                            }


                            // Prepara o pacote de andar dos mobs / npc
                            P_36C p36c = P_36C.New(mob.Mob.ClientId, mob.PositionInicial, SPosition.New(x, y), 0, mob.Speed, new byte[12]);

                            // Envia o pacote de andar
                            Client[i].Send(p36c);
                        }
                    }
                }
                // Mob / Npc anda a cada 5s
                Thread.Sleep(5000);
            }
        }
Beispiel #4
0
        public static void controller(Client client, short mobId, ulong xpAdd)
        {
            //mata o mob
            client.Send(P_338.New(client, mobId, xpAdd));

            //obtem os itens do mob
            SMobList mob = client.MobView.Where(a => a.Mob.ClientId == mobId).FirstOrDefault();

            //regra de drop:
            //0  a 14 slot sao drop normal      Tx 90%
            //15 a 29 slot drop dificil         Tx 65%
            //30 a 44 slot drop raro            TX 40%
            //45 a 60 slot drop super raro      Tx 15%


            int   TaxaDrop    = new Random().Next(0, 100);
            SItem itemDropado = SItem.New();

            //inicia o slot com 60 pois para dar a probalidade de nao receber nenhum item
            int slot = 60;

            if (TaxaDrop >= 0 && TaxaDrop <= 15)
            {
                slot = new Random().Next(45, GetSlotAvailable(mob.Mob.Inventory, 45, 59));
            }

            if (TaxaDrop >= 16 && TaxaDrop <= 40)
            {
                slot = new Random().Next(30, GetSlotAvailable(mob.Mob.Inventory, 30, 44));
            }

            if (TaxaDrop >= 41 && TaxaDrop <= 65)
            {
                slot = new Random().Next(15, GetSlotAvailable(mob.Mob.Inventory, 15, 29));
            }

            if (TaxaDrop >= 66 && TaxaDrop <= 100)
            {
                slot = new Random().Next(0, GetSlotAvailable(mob.Mob.Inventory, 0, 14));
            }

            itemDropado = mob.Mob.Inventory[slot];

            if (itemDropado.Id != 0)
            {
                int tamanho = 30;
                if (client.Character.Mob.Andarilho[0].Id != 0)
                {
                    tamanho += 15;
                }
                if (client.Character.Mob.Andarilho[1].Id != 0)
                {
                    tamanho += 15;
                }

                //checa se o inventario esta cheio
                if (mob.Mob.Inventory.Where(a => a.Id != 0).Count() == tamanho)
                {
                    client.Send(P_101.New("O inventario esta cheio."));
                }
                else
                {
                    client.Character.Mob.Gold += mob.Mob.Gold < 0 ? mob.Mob.Gold * -1 : mob.Mob.Gold;
                    client.Character.Mob.Inventory.ToList().ForEach(a => { slot = 0; if (a.Id == 0)
                                                                           {
                                                                               return;
                                                                           }
                                                                           else
                                                                           {
                                                                               slot += 1;
                                                                           } });
                    client.Character.Mob.AddItemToCharacter(client, itemDropado, TypeSlot.Inventory, slot);
                }
            }
            Log.Normal($"Teve: {TaxaDrop}% de conseguir algum item");
        }
Beispiel #5
0
        public static void controller(Client client, P_39D p39d)
        {
            int tamanho = 0;

            p39d.Damage.ToList().ForEach(a =>
            {
                tamanho += client.MobView.Where(b => a.MobId == b.Mob.ClientId).Count();
            });

            SMobList[] mobList = new SMobList[tamanho];
            for (int i = 0; i < p39d.Damage.Length - 1; i++)
            {
                SMobList dmg = client.MobView.Where(a => a.Mob.ClientId == p39d.Damage[i].MobId).FirstOrDefault();
                if (dmg.Mob.ClientId != 0)
                {
                    mobList[i] = dmg;
                    //remove os mob para que possa ser atualizado com o novo hp ja com o dano recebido depois
                    client.MobView.Remove(dmg);
                }
            }

            //check o modo que esta sendo atacado
            switch (p39d.SkillIndex)
            {
            case 151:   //Arco
            case -1:    //espada ou sem arma
            {
                for (int i = 0; i < mobList.Count(); i++)
                {
                    mobList[i].Mob.GameStatus.CurHP -= client.Character.Mob.GameStatus.Attack;
                    mobList[i].Mob.GameStatus.CurHP += mobList[i].Mob.GameStatus.Defense;

                    for (int a = 0; a < p39d.Damage.Length; a++)
                    {
                        if (p39d.Damage[a].MobId == mobList[i].Mob.ClientId)
                        {
                            p39d.Damage[a].Damage = client.Character.Mob.GameStatus.Attack - mobList[i].Mob.GameStatus.Defense;
                        }
                    }
                }
                break;
            }

            case 27:     // FM: skill Cura
            case 29:     // FM: skill Recuperar
            {
                SSkillList skill   = Config.SkilList[p39d.SkillIndex];
                int        kind    = p39d.SkillIndex % 24 / 8 + 1;
                int        special = client.Character.Mob.GameStatus.Master[kind];
                int        dam     = 0;

                if (p39d.SkillIndex == 27)
                {
                    dam = (special * 2) + skill.InstanceValue;
                }
                else
                {
                    dam = ((special * 3) / 2) + skill.InstanceValue;
                }

                client.Character.Mob.GameStatus.CurHP += dam;


                if (client.Character.Mob.GameStatus.CurHP > client.Character.Mob.GameStatus.MaxHP)
                {
                    client.Character.Mob.GameStatus.CurHP = client.Character.Mob.GameStatus.MaxHP;
                }

                p39d.Damage[0].Damage -= dam;
                break;
            }

            case 32:     // FM: skill Atake de fogo
            case 33:     // FM: skill Ralampago
            case 34:     // FM: skill Lanca de gelo
            case 35:     // FM: skill Meteoro
            case 36:     // FM: skill Nevasca
            case 38:     // FM: skill Fenix
            case 39:     // FM: skill 8
            {
                SSkillList skill = Config.SkilList[p39d.SkillIndex];
                client.Character.Mob.GameStatus.CurMP -= skill.ManaInicial;

                SStatus status = client.Character.Mob.GameStatus;

                int kind    = p39d.SkillIndex % 24 / 8 + 1;
                int special = status.Master[kind];

                switch (client.Character.Mob.ClassInfo)
                {
                case ClassInfo.TK:             // TK Magico
                {
                    client.Character.Mob.MagicIncrement = (short)(special + skill.InstanceValue + status.Master[0] + status.Level + (status.Int / 4) + (status.Int / 40));
                    break;
                }

                case ClassInfo.FM:             // testado
                {
                    client.Character.Mob.MagicIncrement = (short)((status.Int * 0.368) + (skill.InstanceValue / 4.2) + (status.Level / 2) + (1.15 * special));
                    break;
                }

                case ClassInfo.BM:
                {
                    client.Character.Mob.MagicIncrement = (short)((status.Int / 30) + (status.Int / 3) + skill.InstanceValue + 2 * special);
                    break;
                }

                case ClassInfo.HT:
                {
                    client.Character.Mob.MagicIncrement = (short)((3 * status.Master[0]) + (3 * status.Str) + special + skill.InstanceValue);
                    break;
                }
                }
                ;

                for (int i = 0; i < mobList.Count(); i++)
                {
                    mobList[i].Mob.GameStatus.CurHP -= client.Character.Mob.MagicIncrement;
                    mobList[i].Mob.GameStatus.CurHP += mobList[i].Mob.GameStatus.Defense;

                    for (int a = 0; a < p39d.Damage.Length; a++)
                    {
                        if (p39d.Damage[a].MobId == mobList[i].Mob.ClientId)
                        {
                            p39d.Damage[a].Damage = client.Character.Mob.MagicIncrement - mobList[i].Mob.GameStatus.Defense;
                        }
                    }
                }
                break;
            }

            case 37:     // FM: skill Trovao
            case 41:     // FM: skill Velocidade
            case 43:     // FM: skill Escudo Magico
            case 44:     // FM: skill Dano
            case 45:     // FM: skill Toque de Athena
            case 53:     // BM: skill Protecao Elemental
            {
                SSkillList skill = Config.SkilList[p39d.SkillIndex];
                client.Character.Mob.GameStatus.CurMP -= skill.ManaInicial;

                int index = Functions.GetSlotAffect(client, skill.IdSkill);

                client.Character.Mob.Affects[index].Index = (byte)skill.TipoDeEfeito;
                client.Character.Mob.Affects[index].Value = (short)skill.ValorDoEfeito;
                client.Character.Mob.Affects[index].Time  = skill.TempoDoEfeito;
                Functions.GetCurrentScore(client, false);
                break;
            }

            case 56:     // BM: skill Sumona Condor
            case 57:     // BM: skill Sumona javali Selvagem
            case 58:     // BM: skill Sumona Lobo Selvagem
            case 59:     // BM: skill Sumona Urso Selvagem
            case 60:     // BM: skill Sumona Grande Tigre
            case 61:     // BM  skill Sumona Gorila Gigante
            case 62:     // BM  skill Sumona Dragao
            case 63:     // BM  skill Sumona Succubus
            {
                SSkillList skill = Config.SkilList.ToArray()[p39d.SkillIndex - 1];;

                if (skill.InstanceValue >= 1 && skill.InstanceValue <= 50)
                {
                    int summons = 0;

                    if (skill.InstanceValue == 1 || skill.InstanceValue == 2)
                    {
                        summons = client.Character.Mob.GameStatus.Master[2] / 30;
                    }

                    else if (skill.InstanceValue == 3 || skill.InstanceValue == 4 || skill.InstanceValue == 5)
                    {
                        summons = client.Character.Mob.GameStatus.Master[2] / 40;
                    }

                    else if (skill.InstanceValue == 6 || skill.InstanceValue == 7)
                    {
                        summons = client.Character.Mob.GameStatus.Master[2] / 80;
                    }

                    else if (skill.InstanceValue == 8)
                    {
                        summons = 1;
                    }

                    //TODO: Falta fazer meio complexo isso
                    //client.Character.Mob.GenerateSummon(client, skill.InstanceValue - 1, summons);
                }
                break;
            }

            case 64:     // BM: skill Transformacao Lobisomem
            case 66:     // BM: skill Transformacao Urso
            case 68:     // BM: skill Transformacao Astaroth
            case 70:     // BM: skill Transformacao Titan
            case 71:     // BM: skill Transformacao Eden
            {
                SSkillList skill = Config.SkilList[p39d.SkillIndex];
                for (int i = 0; i < client.Character.Mob.Affects.Length; i++)
                {
                    if (client.Character.Mob.Affects[i].Index == 0 || client.Character.Mob.Affects[i].Index == (byte)Affect.Transformacao)
                    {
                        client.Character.Mob.Affects[i].Index = (byte)skill.TipoDeEfeito;
                        client.Character.Mob.Affects[i].Value = (short)skill.ValorDoEfeito;
                        client.Character.Mob.Affects[i].Time  = skill.TempoDoEfeito;
                        Functions.GetCurrentScore(client, false);
                        break;
                    }
                }

                short id = 0;
                switch (p39d.SkillIndex)
                {
                case 64:
                { id = 22; break; }

                case 66:
                { id = 23; break; }

                case 68:
                { id = 24; break; }

                case 70:
                { id = 25; break; }

                case 71:
                { id = 32; break; }
                }

                //troca a face do client para a skill sumonada
                client.Character.Mob.Equip[0].Id = id;

                short[] sanc = new short[16];
                byte[]  anc  = new byte[16];

                for (int i = 0; i < client.Character.Mob.Equip.Length; i++)
                {
                    //obtem os codigos de todos itens
                    sanc[i] = Functions.GetVisualItemCode(client.Character.Mob.Equip[i], i == 14 ? true : false);

                    //obtem os codigos Anct de todos os itens
                    anc[i] = Functions.GetVisualAnctCode(client.Character.Mob.Equip[i]);
                }

                //envia os efeitos
                client.Send(P_36B.New(client, sanc, anc));

                //atualiza o score do client
                Functions.GetCurrentScore(client, false);
                break;
            }
            }

            //Adiciona os mob a list de view com dano Hp reduzido
            client.MobView.AddRange(mobList);

            //envia o dano recebido para o mob
            client.Send(P_39D.New(client, p39d));

            //Varre a lista de mob para ver se alguem morreu
            for (int i = 0; i < mobList.Count(); i++)
            {
                if (mobList[i].Mob.GameStatus.CurHP < 0)
                {
                    //mata o mob e envia o drop se houver
                    P_338.controller(client, mobList[i].Mob.ClientId, mobList[i].Mob.Exp);

                    //trata o recebimento do xp
                    AddXpMob(client, mobList[i].Mob.Exp);
                }
            }

            //Cada atake checa se a experiencia estorou o limite e avanca o lvl a cada atake
            if (client.Character.Mob.Exp >= Rate.Exp_Mortal_Arch[client.Character.Mob.BaseStatus.Level])
            {
                client.Character.Mob.BaseStatus.Level += 1;
                Functions.GetCurrentScore(client, false);
                client.Send(P_36A.New(client, Emotion.LevelUP, 3));
            }
        }
        private static List <SMobList> convertNpcGeneratorToXml(string path)
        {
            StreamReader    stream  = new StreamReader(path);
            string          linha   = null;
            int             i       = 0;
            List <SMobList> mobList = new List <SMobList>();
            SMobList        mob     = SMobList.New();

            try
            {
                while ((linha = stream.ReadLine()) != null)
                {
                    if (linha == "")
                    {
                        continue;
                    }
                    if (i == 5)
                    {
                    }

                    if (linha.Substring(0, 1).Equals("#") || linha.Substring(0, 1).Equals("/") || linha.Substring(0, 1) == null)
                    {
                        continue;
                    }

                    if (linha.Contains("MaxNumMob"))
                    {
                        i          = i + 1;
                        mob.Number = (short)Convert.ToInt16(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1));
                    }


                    if (linha.Contains("Leader"))
                    {
                        i           = i + 1;
                        mob.MobName = linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1).Trim();
                        mob.MobName = mob.MobName.EndsWith(".") == true?mob.MobName.Substring(0, mob.MobName.Length - 1) : mob.MobName;
                    }

                    if (linha.Contains("StartX"))
                    {
                        i = i + 1;
                        mob.PositionInicial.X = (short)Convert.ToInt16(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1));
                    }

                    if (linha.Contains("StartY"))
                    {
                        i = i + 1;
                        mob.PositionInicial.Y = (short)Convert.ToInt16(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1));
                    }

                    if (linha.Contains("DestX"))
                    {
                        i = i + 1;
                        mob.PositionFinal.X = (short)Convert.ToInt16(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1));
                    }

                    if (linha.Contains("DestY"))
                    {
                        i = i + 1;
                        var    apenasDigitos = new Regex(@"[^\d]");
                        string var           = apenasDigitos.Replace(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1), "");
                        mob.PositionFinal.Y = (short)Convert.ToInt16(var);
                    }

                    if (linha.Contains("RouteType"))
                    {
                        i            = i + 1;
                        mob.FreqStep = (short)Convert.ToInt16(linha.Split(':')[1].Substring(1, linha.Split(':')[1].Length - 1));
                    }

                    if (i == 9)
                    {
                        i = 1;
                        mobList.Add(mob);
                        mob = SMobList.New();
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(mobList);
        }