public static void CalculateRegenTick(LivingObject lobj) { if (lobj.ObjectType == OBJECTTYPE.PLAYER) { PlayerObject pobj = (PlayerObject)lobj; float ticktime = 3.0f; float baseregenpower = 0.1f; float baseregenhealth = 0.1f; float powerregen = pobj.BaseSpirit * baseregenpower * ticktime; float healthregen = pobj.BaseSpirit * baseregenhealth * ticktime; if (pobj.StandState != UNITSTANDSTATE.SITTING) { healthregen = healthregen / 3; powerregen = powerregen / 3; } pobj.Health += (int)healthregen; if (pobj.Health > pobj.MaxHealth) { pobj.Health = pobj.MaxHealth; } pobj.Power += (int)powerregen; if (pobj.Power > pobj.MaxPower) { pobj.Power = pobj.MaxPower; } } else { UnitBase uobj = (UnitBase)lobj; float ticktime = 3.0f; float baseregenhealth = 0.1f; float healthregen = (20.0f + ((float)uobj.Level / 3.0f)) * baseregenhealth * ticktime; if (uobj.Attacking) { healthregen = healthregen / 3; } uobj.Health += (int)healthregen; if (uobj.Health > uobj.MaxHealth) { uobj.Health = uobj.MaxHealth; } } }
public void DealDamage(LivingObject lobj, int damage) { this.Health -= damage; if (this.Health < 1) { this.Health = 0; this.StandState = UNITSTANDSTATE.DEAD; this.Dead = true; this.UpdateData(); } else { this.UpdateData(); } }
private void Kill() { try { if (aclient.Player != null) { aclient.Player.StopCombat(); aclient.Player.PlayerCombatEvent = null; attacker = null; target = null; } } catch (Exception) {} EventManager.RemoveEvent(this); return; }
public static void CalculateSpellDamage(LivingObject attacker, LivingObject target, DBSpell spell, out int damage) { damage = 0; if (attacker.ObjectType == OBJECTTYPE.PLAYER) { float basedps = 0.10f; float baseintellect = (float)attacker.BaseIntellect; float baseattacktime = (float)spell.CastTime / 1000.0f; int dps = Convert.ToInt32(basedps * baseintellect * baseattacktime); int minDmg = (int)spell.Damage; int maxDmg = (int)minDmg + (int)spell.RandomPercentageDamage; damage = m_damagerandom.Next(minDmg, (maxDmg + 1)); //damage += dps; if (target != null) { } } }
public override void FireEvent() { try { if (aclient.Player == null) { this.Kill(); return; } attacker = aclient.Player; attacker.InRound = false; target = (LivingObject)ObjectManager.GetWorldObjectByGUID(aclient.Player.Target); if (attacker.Dead) { this.Kill(); return; } if ((!attacker.Attacking) || target.Dead) { this.Kill(); return; } //Console.WriteLine("Fire combat event attacker: " + attacker.Name + " -> " + target.Name); float angle = (float)(aclient.Player.Position.Angle(target.Position) * 180 / Math.PI); float facing = (float)(aclient.Player.Facing * 180 / Math.PI) % 360; if (angle < 0) { angle += 360; } // Try to normalize so that foc (field of combat) // is between 30 and -30 deg float dif = (angle - facing) % 360; if (dif > 180) { dif = 360 - dif; } if (Math.Abs(dif) > 35) { //Console.WriteLine("Look where you are fighting: " + attacker.Name + " -> " + target.Name); } else { uint hitflag; uint victimstate; int damage; int blocked; StatManager.CalculateMeleeDamage(attacker, target, out hitflag, out victimstate, out damage, out blocked); if (aclient.Player.Position.Distance(target.Position) + aclient.Player.Position.Distance(aclient.Player.LastPosition) <= 2.5) //So they dont get free hits from 20 feet away { attacker.InRound = true; ServerPacket pkg2 = new ServerPacket(SMSG.ATTACKERSTATEUPDATE); pkg2.Write((uint)hitflag); pkg2.Write(attacker.GUID); pkg2.Write(target.GUID); pkg2.Write((int)damage); pkg2.Write((byte)1); pkg2.Write((uint)0); pkg2.Write((float)damage); pkg2.Write((int)damage); pkg2.Write((int)0); pkg2.Write((uint)victimstate); pkg2.Write((uint)0); pkg2.Write((uint)0); pkg2.Write((uint)0); pkg2.Write((int)blocked); pkg2.Finish(); attacker.MapTile.Map.Send(pkg2, attacker.Position, 25.0f); if (target.ObjectType == OBJECTTYPE.UNIT) { UnitBase uobj = (UnitBase)target; uobj.DealDamage(attacker, damage); if (uobj.Dead) { attacker.StopCombat(); } } } else { //Console.WriteLine("Your are to far away to hit mob: " + attacker.Name + " -> " + target.Name); } } aclient.Player.LastPosition = aclient.Player.Position; int nextEvent = (attacker.InRound?attacker.BaseAttackTime:1000); eventTime = DateTime.Now.Add(TimeSpan.FromMilliseconds(nextEvent)); EventManager.AddEvent(this); return; } catch (Exception e) { this.Kill(); Console.WriteLine("This exception happened in Combat Event. Probably, someone just disconnected while in combat. It won't crash server though!"); Console.WriteLine(e); return; } }
public static void CalculateMeleeDamage(LivingObject attacker, LivingObject target, out uint hitflag, out uint victimstate, out int damage, out int blocked) { blocked = 0; if (attacker.ObjectType == OBJECTTYPE.PLAYER) { float basedps = 0.15f; float basestrength = (float)attacker.BaseStrength; float baseattacktime = (float)attacker.BaseAttackTime / 1000.0f; int dps = Convert.ToInt32(basedps * basestrength * baseattacktime); hitflag = 2; victimstate = (uint)VICTIMSTATE.WOUND; damage = m_damagerandom.Next((int)attacker.MinDamage, (int)(attacker.MaxDamage + 1)); damage += dps; // Targets Dodge % float basedodge = (20.0f + ((float)target.Level / 3.0f)) * 0.25f; // Soft cap on 25% if (basedodge > 25.0f) { basedodge = 25.0f; } int hit = m_damagerandom.Next(100); if (hit <= (int)basedodge) { hitflag = 1; victimstate = (uint)VICTIMSTATE.DODGE; damage = 0; } else { // Critical hit % float basecritical = (float)attacker.BaseAgility * 0.25f; // Soft cap on 25% if (basecritical > 25.0f) { basecritical = 25.0f; } hit = m_damagerandom.Next(100); if (hit <= (int)basecritical) { hitflag = 10; damage += (int)attacker.MaxDamage; } } } else { float basedps = 0.1f; float basestrength = 20.0f + ((float)attacker.Level * (float)1.1); float baseattacktime = (float)attacker.BaseAttackTime / 1000.0f; int dps = Convert.ToInt32(basedps * basestrength * baseattacktime); hitflag = 2; victimstate = (uint)VICTIMSTATE.WOUND; damage = m_damagerandom.Next((int)attacker.MinDamage, (int)(attacker.MaxDamage + 1)); damage += dps; // Target AC float damagereduction = (0.3f * (float)(target.Resist_Physical - 1) / (10.0f * (float)target.Level + 89.0f)); damage -= Convert.ToInt32((float)damage * damagereduction); // Targets Dodge % float basedodge = (float)target.BaseAgility * 0.25f; // Soft cap on 25% if (basedodge > 25.0f) { basedodge = 25.0f; } int hit = m_damagerandom.Next(100); if (hit <= (int)basedodge) { hitflag = 1; victimstate = (uint)VICTIMSTATE.DODGE; damage = 0; } else { PlayerObject pobj = (PlayerObject)target; if (pobj.HasShield) { int baseblock = 25; hit = m_damagerandom.Next(100); if (hit < baseblock) { blocked = Convert.ToInt32((float)damage * 0.2f); damage -= blocked; } } } } }
public static void CalculateNewStats(LivingObject lobj) { if (lobj.ObjectType == OBJECTTYPE.PLAYER) { PlayerObject pobj = (PlayerObject)lobj; BaseStats stats = BaseStats.GetBaseStats(pobj); pobj.MaxHealth = stats.Health; pobj.MaxPower = stats.Power; pobj.BaseStrength = stats.Strength; pobj.BaseStamina = stats.Stamina; pobj.BaseAgility = stats.Agility; pobj.BaseIntellect = stats.Intellect; pobj.BaseSpirit = stats.Spirit; CalculateInvStats(pobj); } else if (lobj.ObjectType == OBJECTTYPE.UNIT) { UnitBase uobj = (UnitBase)lobj; int basehealth = 60; int basestamina = Convert.ToInt32(((float)lobj.Level * ((float)lobj.Level * 0.2f)) - 1); if (basestamina < (uobj.Level - 1)) { basestamina = uobj.Level - 1; } int health = basehealth + (basestamina * 10); if (uobj.Level < 10) { switch (uobj.Level) { case 1: uobj.BaseAttackTime = 2000; uobj.MinDamage = (float)2.0; uobj.MaxDamage = (float)4.0; break; case 2: uobj.BaseAttackTime = 2600; uobj.MinDamage = (float)3.0; uobj.MaxDamage = (float)6.0; break; case 3: uobj.BaseAttackTime = 2200; uobj.MinDamage = (float)3.0; uobj.MaxDamage = (float)6.0; break; case 4: uobj.BaseAttackTime = 2000; uobj.MinDamage = (float)3.0; uobj.MaxDamage = (float)6.0; break; case 5: uobj.BaseAttackTime = 1800; uobj.MinDamage = (float)3.0; uobj.MaxDamage = (float)6.0; break; case 6: uobj.BaseAttackTime = 2100; uobj.MinDamage = (float)4.0; uobj.MaxDamage = (float)8.0; break; case 7: uobj.BaseAttackTime = 1950; uobj.MinDamage = (float)4.0; uobj.MaxDamage = (float)8.0; break; case 8: uobj.BaseAttackTime = 1800; uobj.MinDamage = (float)4.0; uobj.MaxDamage = (float)8.0; break; case 9: uobj.BaseAttackTime = 2200; uobj.MinDamage = (float)5.0; uobj.MaxDamage = (float)10.0; break; } } else { uobj.BaseAttackTime = 2000; uobj.MinDamage = (float)uobj.Level / (float)2.0; uobj.MaxDamage = (float)uobj.Level; } uobj.MaxHealth = health; uobj.MaxPower = 0; } }