public bool AdjacentToItem(Player player, Item item) { if (DistanceToDiagonal(Players[0].Position, item.Position) < 46) { return true; } else { return false; } }
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; }
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; }
public int PlayerAttack(Player player) { if (player.TargetID != -1) { Creature target = GetCreatureByID(player.TargetID); if (target.Name != "null") { if (CanAttack(player, target) && DistanceToDiagonal(player.Position, target.Position) < 46) // < 46 because when standing diagonal, the distance is 45, when standing directly in front, it is 32 { int dmgDealt = target.ReceiveDamage(player.TotalStrength(), target.Defense); if (target.Health < 1) { player.ReceiveExperience(target.Experience); player.TargetID = -1; } return dmgDealt; } } } return -1; }
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; }
internal List<DamageObject> PlayerAttack(Player player, GameTime gameTime) { List<DamageObject> DamagedMonsters = new List<DamageObject>(); int currentTime = (int)gameTime.TotalGameTime.TotalMilliseconds; if (player.TargetID != -1) { Creature target = GetCreatureByID(player.TargetID); if (target.Name != "null") { // TODO: Fix below so it works with the new coordinate system (which is screen coordinates / 32) if (CanAttack(player, target) && DistanceToDiagonal(player.Position, target.Position) < 2) // < 46 because when standing diagonal, the distance is 45, when standing directly in front, it is 32 { int dmgDealt = target.ReceiveDamage(player.TotalStrength(), target.Defense); DamagedMonsters.Add(new DamageObject(target, dmgDealt, DamageObject.Text_Damage, 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; }
internal bool AdjacentToItem(Player player, Item item) { if (DistanceToDiagonal(Players[0].Position, item.Position) < 2) { if (item.Position.Z == Players[0].Position.Z) { return true; } return false; } else { return false; } }
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; }
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; } }