public override void FireEvent() { if (!m_mobs.Dead && m_mobs.Health < m_mobs.MaxHealth) { //Console.WriteLine("MobsRegenEvent.FireEvent: " + m_mobs.Name); StatManager.CalculateRegenTick(m_mobs); m_mobs.UpdateData(); eventTime = DateTime.Now.Add(TimeSpan.FromSeconds(3)); EventManager.AddEvent(this); } else { m_mobs.MobsRegenEvent = null; } }
// [UpdateValueAttribute(PLAYERFIELDS.SKILL_INFO, ArraySize=384)] // protected uint [] m_skill_info; public PlayerObject(DBCharacter c) : base() { m_character = c; m_character.Health = c.Health; m_character.MaxHealth = c.MaxHealth; m_character.Power = c.Power; m_character.MaxPower = c.MaxPower; m_character.Strength = c.Strength; m_character.BaseStrength = c.BaseStrength; m_character.Stamina = c.Stamina; m_character.BaseStamina = c.BaseStamina; m_character.Agility = c.Agility; m_character.BaseAgility = c.BaseAgility; m_character.Intellect = c.Intellect; m_character.BaseIntellect = c.BaseIntellect; m_character.Spirit = c.Spirit; m_character.BaseSpirit = c.BaseSpirit; m_character.AttackPower = c.AttackPower; m_character.AttackPowerModifier = c.AttackPowerModifier; m_character.GuildID = c.GuildID; m_character.GuildRank = c.GuildRank; m_character.GuildTimeStamp = WorldClock.GetTimeStamp(); m_scale = c.Scale; m_displayID = c.DisplayID; m_nativedisplayID = c.DisplayID; m_playerFlags = 0; m_accessLevel = ACCESSLEVEL.NORMAL; m_baseattacktime = 2000; // m_skill_info = new uint[384]; // m_skill_info[0] = 133; //Just for a test, Mage spell fireball Inventory = new PlayerInventory(this); if (c.Items != null) { foreach (DBItem item in c.Items) { Inventory.CreateItem(item); } } StatManager.CalculateNextLevelExp(this); StatManager.CalculateNewStats(this); ObjectManager.AddWorldObject(this); EventManager.AddEvent(new AggrMonsterEvent(this)); EventManager.AddEvent(new RoamingEvent(this)); }
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 override void FireEvent() { try { attacker.InRound = false; attacker.DidAttack = false; if (aclient.Player == null) { this.Kill(); return; } //Console.WriteLine("CombatEvent.FireEvent (" + aclient.Player.Name + "): " + attacker.Name); aclient = WorldServer.GetClientByCharacterID((uint)attacker.Target); if (attacker.Dead) { this.Kill(); return; } target = aclient.Player; } catch (Exception) { this.Kill(); return; } if (aclient.Player.Position.Distance(attacker.Position) > 50) { Console.WriteLine("Ennemy out of range! Stopping attack"); this.Kill(); return; } if (aclient.Player.Dead || aclient.Player.RezSickness) { this.Kill(); return; } uint hitflag; uint victimstate; int damage; int blocked; attacker.InRound = true; StatManager.CalculateMeleeDamage(attacker, target, out hitflag, out victimstate, out damage, out blocked); if (aclient.Player.Position.Distance(attacker.Position) < 2.75f) //So they dont get free hits from 20 feet away { attacker.DidAttack = 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)0); pkg2.Finish(); attacker.MapTile.Map.Send(pkg2, attacker.Position, 25.0f); target.DealDamage(attacker, damage); if (target.Dead) { attacker.StopCombat(); } } else { ChasingEvent chase = new ChasingEvent(attacker); chase.FireEvent(); } int nextEvent = (attacker.DidAttack?attacker.BaseAttackTime:1000); eventTime = DateTime.Now.Add(TimeSpan.FromMilliseconds(nextEvent)); EventManager.AddEvent(this); return; }
public void DealDamage(PlayerObject pobj, int damage) { if (!this.Dead) { if (m_agrotable[pobj.CharacterID] == null) { m_agrotable.Add(pobj.CharacterID, damage); } else { int damagedealt = (int)m_agrotable[pobj.CharacterID]; damagedealt += damage; m_agrotable[pobj.CharacterID] = damagedealt; } this.Health -= damage; if (this.Health < 1) { this.Roaming = false; EventManager.AddEvent(new CorpseDespawnEvent((UnitBase)this)); this.Health = 0; this.StandState = UNITSTANDSTATE.DEAD; this.Dead = true; this.DynamicFlags = 1; // If set to 1 there will be loot. this.LootOwner = pobj.GUID; this.UpdateData(); try { // Give xp to the right people. int exp = StatManager.CalculateExp(this, pobj); int maxdamage = 0; Hashtable expdividergroup = new Hashtable(); Hashtable expdividersolo = new Hashtable(); foreach (DictionaryEntry de in m_agrotable) { maxdamage += (int)de.Value; WorldClient aclient = WorldServer.GetClientByCharacterID((uint)de.Key); if (aclient.Player.Group == null) { expdividersolo.Add(aclient.Player.CharacterID, (int)de.Value); } else { if (expdividergroup[aclient.Player.Group.LeaderGUID] == null) { expdividergroup.Add(aclient.Player.Group.LeaderGUID, (int)de.Value); } else { int damagedealt = (int)expdividergroup[aclient.Player.Group.LeaderGUID]; damagedealt += (int)de.Value; expdividergroup[aclient.Player.Group.LeaderGUID] = damagedealt; } } } // Solo players foreach (DictionaryEntry de in expdividersolo) { float expbit = ((int)de.Value / (float)maxdamage); WorldClient aclient = WorldServer.GetClientByCharacterID((uint)de.Key); if (aclient != null) { aclient.Player.GainXp(Convert.ToInt32(exp * expbit), this.GUID); } } // Group players foreach (DictionaryEntry de in expdividergroup) { WorldClient aclient = WorldServer.GetClientByCharacterID(Convert.ToUInt32((ulong)de.Key)); if (aclient != null) { GroupObject gobj = aclient.Player.Group; float expbit = (((int)de.Value / (float)maxdamage) / (float)gobj.Size); for (int i = 0; i < gobj.Size; i++) { gobj.Members[i].GainXp(Convert.ToInt32(exp * expbit), this.GUID); } } } } catch (Exception exp) { DebugLogger.Logger.Log("", exp); } } else { this.UpdateData(); if (this.MobsRegenEvent == null) { this.MobsRegenEvent = new MobsRegenEvent(this); EventManager.AddEvent(this.MobsRegenEvent); } } } }