Example #1
0
    public static void Died(short Map_Num, byte Index)
    {
        Lists.Structures.NPCs NPC = Lists.NPC[Lists.Map[Map_Num].Temp_NPC[Index].Index];

        // Solta os itens
        for (byte i = 0; i <= Game.Max_NPC_Queda - 1; i++)
        {
            if (NPC.Queda[i].Item_Num > 0)
            {
                if (Game.Aleatório.Next(NPC.Queda[i].Chance, 101) == 100)
                {
                    // Data do item
                    Lists.Structures.Map_Items Item = new Lists.Structures.Map_Items();
                    Item.Index  = NPC.Queda[i].Item_Num;
                    Item.Amount = NPC.Queda[i].Amount;
                    Item.X      = Lists.Map[Map_Num].Temp_NPC[Index].X;
                    Item.Y      = Lists.Map[Map_Num].Temp_NPC[Index].Y;

                    // Solta
                    Lists.Map[Map_Num].Temp_Item.Add(Item);
                }
            }
        }

        // Envia os Data dos itens no chão para o mapa
        Sending.Map_Items(Map_Num);

        // Reseta os Data do NPC
        Lists.Map[Map_Num].Temp_NPC[Index].Vital[(byte)Game.Vital.Life] = 0;
        Lists.Map[Map_Num].Temp_NPC[Index].Appearance_Time = Environment.TickCount;
        Lists.Map[Map_Num].Temp_NPC[Index].Index           = 0;
        Lists.Map[Map_Num].Temp_NPC[Index].Target_Type     = 0;
        Lists.Map[Map_Num].Temp_NPC[Index].Target_Index    = 0;
        Sending.Map_NPC_Died(Map_Num, Index);
    }
Example #2
0
    public static short Renegation(short Map_Num, byte Index, byte Vital)
    {
        Lists.Structures.NPCs Data = Lists.NPC[Lists.Map[Map_Num].Temp_NPC[Index].Index];

        // Calculates the most vital that the NPC has
        switch ((Game.Vital)Vital)
        {
        case Game.Vital.Life: return((short)(Data.Vital[Vital] * 0.05 + Data.Attribute[(byte)Game.Attributes.Vitality] * 0.3));

        case Game.Vital.Mana: return((short)(Data.Vital[Vital] * 0.05 + Data.Attribute[(byte)Game.Attributes.Intelligence] * 0.1));
        }

        return(0);
    }
Example #3
0
    public static void Appearance(byte Index, short Map, byte x, byte y, Game.Location Direction = 0)
    {
        Lists.Structures.NPCs Data = Lists.NPC[Lists.Map[Map].NPC[Index].Index];
        short[] s = Data.Vital;

        // Define os Data
        Lists.Map[Map].Temp_NPC[Index].Index     = Lists.Map[Map].NPC[Index].Index;
        Lists.Map[Map].Temp_NPC[Index].X         = x;
        Lists.Map[Map].Temp_NPC[Index].Y         = y;
        Lists.Map[Map].Temp_NPC[Index].Direction = Direction;
        Lists.Map[Map].Temp_NPC[Index].Vital     = new short[(byte)Game.Vital.Amount];
        for (byte i = 0; i <= (byte)Game.Vital.Amount - 1; i++)
        {
            Lists.Map[Map].Temp_NPC[Index].Vital[i] = Data.Vital[i];
        }

        // Envia os Data aos jogadores
        if (Network.Device != null)
        {
            Sending.Map_NPC(Map, Index);
        }
    }
Example #4
0
    public static void Logic(short Map_Num)
    {
        // Lógica dos NPCs
        for (byte i = 1; i <= Lists.Map[Map_Num].Temp_NPC.GetUpperBound(0); i++)
        {
            Lists.Structures.Map_NPCs Data     = Lists.Map[Map_Num].Temp_NPC[i];
            Lists.Structures.NPCs     NPC_Data = Lists.NPC[Lists.Map[Map_Num].NPC[i].Index];

            //////////////////
            // Aparecimento //
            //////////////////
            if (Data.Index == 0)
            {
                if (Environment.TickCount > Data.Appearance_Time + (NPC_Data.Appearance * 1000))
                {
                    Appearance(i, Map_Num);
                }
            }
            else
            {
                byte   TargetX = 0, TargetY = 0;
                bool[] PodeMover = new bool[(byte)Game.Location.Amount];
                short  DistânciaX, DistânciaY;
                bool   SeMoveu    = false;
                bool   Movimentar = false;

                /////////////////
                // Regeneração //
                /////////////////
                if (Environment.TickCount > Tie.Score_NPC_Reneration + 5000)
                {
                    for (byte v = 0; v <= (byte)Game.Vital.Amount - 1; v++)
                    {
                        if (Data.Vital[v] < NPC_Data.Vital[v])
                        {
                            // Renera os Vital
                            Lists.Map[Map_Num].Temp_NPC[i].Vital[v] += Renegation(Map_Num, i, v);

                            // Impede que o valor passe do limite
                            if (Lists.Map[Map_Num].Temp_NPC[i].Vital[v] > NPC_Data.Vital[v])
                            {
                                Lists.Map[Map_Num].Temp_NPC[i].Vital[v] = NPC_Data.Vital[v];
                            }

                            // Envia os Data aos jogadores do mapa
                            Sending.Map_NPC_Vital(Map_Num, i);
                        }
                    }
                }

                ///////////////
                // Movement //
                ///////////////
                // Atacar ao ver
                if (Lists.Map[Map_Num].Temp_NPC[i].Target_Index == 0 && NPC_Data.Aggressiveness == (byte)Aggressiveness.AtacarAoVer)
                {
                    for (byte p = 1; p <= Game.BiggerIndex; p++)
                    {
                        // Verifica se o jogador está jogando e no mesmo mapa que o NPC
                        if (!Player.IsPlaying(p))
                        {
                            continue;
                        }
                        if (Player.Character(p).Map != Map_Num)
                        {
                            continue;
                        }

                        // Distância entre o NPC e o jogador
                        DistânciaX = (short)(Data.X - Player.Character(p).X);
                        DistânciaY = (short)(Data.Y - Player.Character(p).Y);
                        if (DistânciaX < 0)
                        {
                            DistânciaX *= -1;
                        }
                        if (DistânciaY < 0)
                        {
                            DistânciaY *= -1;
                        }

                        // Se estiver no alcance, ir atrás do jogador
                        if (DistânciaX <= NPC_Data.View && DistânciaY <= NPC_Data.View)
                        {
                            Lists.Map[Map_Num].Temp_NPC[i].Target_Type  = (byte)Game.Target.Player;
                            Lists.Map[Map_Num].Temp_NPC[i].Target_Index = p;
                            Data = Lists.Map[Map_Num].Temp_NPC[i];
                        }
                    }
                }

                if (Data.Target_Type == (byte)Game.Target.Player)
                {
                    // Posição do Target
                    TargetX = Player.Character(Lists.Map[Map_Num].Temp_NPC[i].Target_Index).X;
                    TargetY = Player.Character(Lists.Map[Map_Num].Temp_NPC[i].Target_Index).Y;

                    // Verifica se o jogador ainda está disponível
                    if (!Player.IsPlaying(Data.Target_Index) || Player.Character(Data.Target_Index).Map != Map_Num)
                    {
                        Lists.Map[Map_Num].Temp_NPC[i].Target_Type  = 0;
                        Lists.Map[Map_Num].Temp_NPC[i].Target_Index = 0;
                        Data = Lists.Map[Map_Num].Temp_NPC[i];
                    }
                }

                // Distância entre o NPC e o Target
                DistânciaX = (short)(Data.X - TargetX);
                DistânciaY = (short)(Data.Y - TargetY);
                if (DistânciaX < 0)
                {
                    DistânciaX *= -1;
                }
                if (DistânciaY < 0)
                {
                    DistânciaY *= -1;
                }

                // Verifica se o Target saiu do alcance
                if (DistânciaX > NPC_Data.View || DistânciaY > NPC_Data.View)
                {
                    Lists.Map[Map_Num].Temp_NPC[i].Target_Type  = 0;
                    Lists.Map[Map_Num].Temp_NPC[i].Target_Index = 0;
                    Data = Lists.Map[Map_Num].Temp_NPC[i];
                }

                // Evita que ele se movimente sem sentido
                if (Data.Target_Index > 0)
                {
                    Movimentar = true;
                }
                else
                {
                    // Define o Target até a zona do NPC
                    if (Lists.Map[Map_Num].NPC[i].Zone > 0)
                    {
                        if (Lists.Map[Map_Num].Tile[Data.X, Data.Y].Zone != Lists.Map[Map_Num].NPC[i].Zone)
                        {
                            for (byte x2 = 0; x2 <= Lists.Map[Map_Num].Width; x2++)
                            {
                                for (byte y2 = 0; y2 <= Lists.Map[Map_Num].Height; y2++)
                                {
                                    if (Lists.Map[Map_Num].Tile[x2, y2].Zone == Lists.Map[Map_Num].NPC[i].Zone)
                                    {
                                        if (!Map.Tile_Blocked(Map_Num, x2, y2))
                                        {
                                            TargetX    = x2;
                                            TargetY    = y2;
                                            Movimentar = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Movimenta o NPC até mais perto do Target
                if (Movimentar)
                {
                    // Verifica como pode se mover até o Target
                    if (Data.Y > TargetY)
                    {
                        PodeMover[(byte)Game.Location.Above] = true;
                    }
                    if (Data.Y < TargetY)
                    {
                        PodeMover[(byte)Game.Location.Below] = true;
                    }
                    if (Data.X > TargetX)
                    {
                        PodeMover[(byte)Game.Location.Left] = true;
                    }
                    if (Data.X < TargetX)
                    {
                        PodeMover[(byte)Game.Location.Right] = true;
                    }

                    // Aleatoriza a forma que ele vai se movimentar até o Target
                    if (Game.Aleatório.Next(0, 2) == 0)
                    {
                        for (byte d = 0; d <= (byte)Game.Location.Amount - 1; d++)
                        {
                            if (!SeMoveu && PodeMover[d] && Move(Map_Num, i, (Game.Location)d))
                            {
                                SeMoveu = true;
                            }
                        }
                    }
                    else
                    {
                        for (short d = (byte)Game.Location.Amount - 1; d >= 0; d--)
                        {
                            if (!SeMoveu && PodeMover[d] && Move(Map_Num, i, (Game.Location)d))
                            {
                                SeMoveu = true;
                            }
                        }
                    }
                }

                // Move-se aleatoriamente
                if (NPC_Data.Aggressiveness == (byte)Aggressiveness.Passive || Data.Target_Index == 0)
                {
                    if (Game.Aleatório.Next(0, 3) == 0 && !SeMoveu)
                    {
                        Move(Map_Num, i, (Game.Location)Game.Aleatório.Next(0, 4), 1, true);
                    }
                }
            }

            ////////////
            // Attack //
            ////////////
            short Next_X = Data.X, Next_Y = Data.Y;
            Map.NextTile(Data.Direction, ref Next_X, ref Next_Y);
            if (Data.Target_Type == (byte)Game.Target.Player)
            {
                // Checks if player is in front of NPC
                if (Map.ThereIsPlayer(Map_Num, Next_X, Next_Y) == Data.Target_Index)
                {
                    Attack_Player(Map_Num, i, Data.Target_Index);
                }
            }
        }
    }