Esempio n. 1
0
 public bool CanAttack(Creature creature, Creature target)
 {
     if (target.Health > 0 && creature.Health > 0)
     {
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public DamageObject(Creature monster, int Damage, int _text_type, int _StartTime, int _EndTime, int id = 0, Coordinates pos = null)
 {
     creature = monster;
     damageDealt = Damage;
     ID = id;
     EndTime = _EndTime;
     StartTime = _StartTime;
     Position = pos;
     Text_Type = _text_type;
 }
 public DamageObject(Creature monster, int Damage, bool healing, int _StartTime, int _EndTime, int id = 0, Coordinates pos = null)
 {
     creature = monster;
     damageDealt = Damage;
     ID = id;
     EndTime = _EndTime;
     StartTime = _StartTime;
     Position = pos;
     Healing = healing;
 }
Esempio n. 4
0
 public int CreatureAttack(Creature creature, Player target)
 {
     if (CanAttack(creature, target))
     {
         int dmgDealt = target.ReceiveDamage(creature.Strength, target.TotalDefense());
         if (target.Health < 1)
         {
             //creature.Experience += 1 + target.Experience;
             target.Die();
         }
         return dmgDealt;
     }
     return -1;
 }
Esempio n. 5
0
        public List<DamageObject> PlayerCastSpell(Player player, Spell spell, Creature target, GameTime gameTime)
        {
            List<DamageObject> DamagedMonsters = new List<DamageObject>();
            int currentTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
            if (!spell.TargetSpell)
            {
                for (int i = 0; i < spell.Area.Length / 3; i++)
                {
                    for (int j = 0; j < spell.Area.Length / 3; j++)
                    {
                        if (spell.Area[i + j])
                        {
                            /* TODO: Make area spell healing possible! */
                            int creatureID = GetCreatureIDFromTile(new Coordinates(player.Position.X - Coordinates.Step + (i * Coordinates.Step), player.Position.Y - Coordinates.Step + (j * Coordinates.Step)));
                            if (creatureID != -1)
                            {
                                Creature creature = GetCreatureByID(creatureID);
                                if (creature.Health > 0)
                                {
                                    int DamageDealt = creature.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                                    DamagedMonsters.Add(new DamageObject(creature, DamageDealt, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                                    if (creature.Health < 1)
                                    {
                                        player.ReceiveExperience(creature.Experience);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if(spell.HealSpell)
                {
                    int damage = spell.Damage + (player.MagicStrength * 2);
                    if (player.Health + damage > player.MaxHealth)
                    {
                        damage = player.MaxHealth - player.Health;
                        player.Health = player.MaxHealth;
                    }
                    else
                    {
                        player.Health += damage;
                    }
                    DamagedMonsters.Add(new DamageObject(player, damage, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                }
                else
                {
                    int DamageDealt = target.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                    DamagedMonsters.Add(new DamageObject(target, DamageDealt, spell.HealSpell, currentTime, currentTime + DamageObject.DamageDuration));
                    if (target.Health < 1)
                    {
                        player.ReceiveExperience(target.Experience);
                    }
                }
            }

            return DamagedMonsters;
        }
Esempio n. 6
0
 public void GeneratePathFromCreature(Creature FromCreature, Coordinates Target)
 {
     FromCreature.Destination = Target;
     FromCreature.ResetPath();
     AI ai = new AI(this);
     FromCreature.Path = ai.PathTo(Target, FromCreature.Position);
 }
Esempio n. 7
0
        internal List<DamageObject> PlayerCastSpell(Player player, Spell spell, Creature target, GameTime gameTime)
        {
            List<DamageObject> DamagedMonsters = new List<DamageObject>();
            int currentTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
            if (spell.AreaSpell)
            {
                Coordinates TopLeftOfScreen = new Coordinates(player.Position.X - 7, player.Position.Y - 5);
                /* TODO: Make area spell healing possible! */
                int n = 1;
                int y = 0;
                int x = 0;
                int experience = 0;
                for (int i = 0; i < spell.Area.Length; i++)
                {
                    if (n % 15 == 0)
                    {
                        y++;
                        x = -1;
                    }
                    if (spell.Area[i] == 1)
                    {
                        //spriteBatch.Draw(spell.Sprite, new Vector2((float)(SpellDamage[index].Position.X - map.Players[0].Position.X + (Utility.ScreenX) - 7 + x) * Coordinates.Step, (float)(SpellDamage[index].Position.Y - map.Players[0].Position.Y + (Utility.ScreenY) - 5 + y) * Coordinates.Step), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                        List<Creature> CastOnCreatures = GetCreaturesFromTile(new Coordinates(TopLeftOfScreen.X + x, TopLeftOfScreen.Y + y, player.Position.Z));
                        for (int c = 0; c < CastOnCreatures.Count; c++)
                        {

                            Creature creature = CastOnCreatures[c];
                            if (creature.Health > 0)
                            {
                                int DamageDealt = creature.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                                int text_type = 0;
                                if (spell.HealSpell)
                                {
                                    text_type = DamageObject.Text_Healing;
                                }
                                else
                                {
                                    text_type = DamageObject.Text_Damage;
                                }
                                DamagedMonsters.Add(new DamageObject(creature, DamageDealt, text_type, currentTime, currentTime + DamageObject.DamageDuration));
                                if (creature.Health < 1)
                                {
                                    experience += CreatureDie(creature, player);
                                }
                            }
                        }
                    }
                    n++;
                    x++;
                }
                if (experience > 0)
                {
                    DamagedMonsters.Add(new DamageObject(player, experience, DamageObject.Text_Experience, currentTime, currentTime + DamageObject.DamageDuration));
                }
            }
            else
            {
                if (spell.HealSpell)
                {
                    int damage = spell.Damage + (player.MagicStrength * 2);
                    if (player.Health + damage > player.MaxHealth)
                    {
                        damage = player.MaxHealth - player.Health;
                        player.Health = player.MaxHealth;
                    }
                    else
                    {
                        player.Health += damage;
                    }
                    int text_type = 0;
                    if (spell.HealSpell)
                    {
                        text_type = DamageObject.Text_Healing;
                    }
                    else
                    {
                        text_type = DamageObject.Text_Damage;
                    }
                    DamagedMonsters.Add(new DamageObject(player, damage, text_type, currentTime, currentTime + DamageObject.DamageDuration));
                }
                else
                {
                    int DamageDealt = target.ReceiveDamage(spell.Damage + (player.MagicStrength * 2), 0);
                    int text_type = 0;
                    if (spell.HealSpell)
                    {
                        text_type = DamageObject.Text_Healing;
                    }
                    else
                    {
                        text_type = DamageObject.Text_Damage;
                    }
                    DamagedMonsters.Add(new DamageObject(target, DamageDealt, text_type, currentTime, currentTime + DamageObject.DamageDuration));
                    if (target.Health < 1)
                    {
                        int experience = CreatureDie(target, player);
                        DamagedMonsters.Add(new DamageObject(player, experience, DamageObject.Text_Experience, currentTime, currentTime + DamageObject.DamageDuration));
                    }
                }
            }

            return DamagedMonsters;
        }
Esempio n. 8
0
        internal int Monster_FindTarget(Creature monster)
        {
            int targetID = -1;
            //StreamWriter debug = new StreamWriter("debug.txt", true);
            //rectangle.x = monsterx-13
            //rectangle.width = rectangle.x + 25
            //rectangle.y = monstery - 9
            //rectangle.height = rectangle.y + 17
            Rectangle TargetArea;
            TargetArea.X = monster.Position.X - 7;
            TargetArea.Y = monster.Position.Y - 5;
            TargetArea.Width = TargetArea.X + 15;
            TargetArea.Height = TargetArea.Y + 11;
            if (TargetArea.X < 0) { TargetArea.X = 0; TargetArea.Width += 1; }
            if (TargetArea.Y < 0) { TargetArea.Y = 0; TargetArea.Height += 1; }

            for (int i = 0; i < Players.Count; i++)
            {
                //debug.WriteLine("TargetAreaX = " + TargetArea.X + " TargetAreaY = " + TargetArea.Y + "TargetAreaWidth = " + TargetArea.Width + " TargetAreaHeight = " + TargetArea.Height + " | PlayerX = " + Players[i].Position.X + " PlayerY = " + Players[i].Position.Y + " PlayerZ = " + Players[i].Position.Z + " | MonsterZ = " + monster.Position.Z);
                if (DistanceToDiagonal(monster.Position, Players[i].Position) <= 8)
                {
                    if (TargetArea.Contains(Players[i].Position.X, Players[i].Position.Y) && monster.Position.Z == Players[i].Position.Z)
                    {
                        targetID = Players[i].ID;
                    }
                }
            }

            //debug.Close();

            return targetID;
        }
Esempio n. 9
0
        internal void GeneratePathFromPlayer(Creature FromCreature, Coordinates Target, int DistanceTo = 20)
        {
            FromCreature.Destination = Target;
            FromCreature.ResetPath();
            AI ai = new AI();
            PathfindingTask = Task.Factory.StartNew(() =>
            {
                FromCreature.Path = ai.PathTo(Target, FromCreature.Position, DistanceTo);
            }
            );

            //FromCreature.Path = ai.PathTo(Target, FromCreature.Position, DistanceTo);
        }
Esempio n. 10
0
        // Map(Coordinates WindowSize) { windowSize = WindowSize; }
        internal void GeneratePathFromCreature(Creature FromCreature, Coordinates Target, int DistanceTo = 20)
        {
            FromCreature.ResetPath();
            PathfindingTask = Task.Factory.StartNew(() =>
            {
                AI ai = new AI();
                FromCreature.Path = ai.Monster_PathTo(Target, FromCreature.Position, DistanceTo);
                if (FromCreature.Path.Count > 0)
                {
                    FromCreature.Destination = Coordinates.Parse(FromCreature.Path[0]);
                }
            }
            );

            //FromCreature.Path = ai.PathTo(Target, FromCreature.Position, DistanceTo);
        }
Esempio n. 11
0
 internal int CreatureDie(Creature creature, Player killer)
 {
     killer.ReceiveExperience(creature.Experience);
     if (creature.LootList.Count > 0)
     {
         for (int i = 0; i < creature.LootList.Count; i++)
         {
             if (Roll(creature.LootList[i].LootChance))
             {
                 CreateWorldItemFromListItem(creature.LootList[i].RealID, creature.Position);
             }
         }
     }
     if (creature.ID == killer.TargetID)
     {
         killer.TargetID = -1;
     }
     return creature.Experience;
 }
Esempio n. 12
0
 internal void CreateCreatureFromCreatureList(int ID, Coordinates pos = null)
 {
     Creature newCreature;
     if (pos == null) { pos = new Coordinates(0, 0, 0); }
     for (int i = 0; i < CreatureList.Count; i++)
     {
         if (CreatureList[i].ID == ID)
         {
             newCreature = new Creature(CreatureList[i].Name, pos, Players[0].ID, CreatureList[i].MagicStrength, CreatureList[i].Strength, CreatureList[i].Health, Creatures.Count, CreatureList[i].Defense, CreatureList[i].Experience, CreatureList[i].SpriteID, CreatureList[i].LootList, CreatureList[i].Spells);
             Creatures.Add(newCreature);
         }
     }
 }
Esempio n. 13
0
 internal void PlayerDie(Creature killer, Player creature)
 {
     //killer.ReceiveExperience(creature.Experience);
     //if (creature.LootList.Count > 0)
     //{
     //Random generator = new Random();
     //generator.
     /*for (int i = 0; i < 1; i++)
     {
         //Decimal chance = (generator.Next(creature.LootList[i].LootChance * 100, 1 * 100));
         //chance = (Math.Round(chance / 10.0)) * 10;
         //if (chance >= 90)
         CreateWorldItemFromListItem(creature.LootList[i].SpriteID, creature.Position);
         //else
         //killer.Name = chance.ToString();
     }
     }*/
     if (creature.ID == killer.TargetID)
     {
         killer.TargetID = -1;
     }
 }