/// <summary> /// Create a collection of item drops /// </summary> /// <param name="mapobject"></param> /// <param name="character"></param> /// <returns></returns> public static LootCollection Create(MapObject mapobject, Character character) { if (MapObject.IsPlayer(mapobject)) throw new SystemException("Cannot create loot for mapobjects"); LootCollection collection = new LootCollection(); PartySession party = character.sessionParty; if (party == null) { collection.LootLeader = character.id; } else if (party.LootSettings == 3 && party.ItemLeader.currentzone == mapobject.currentzone && mapobject.currentzone.IsInSightRangeBySquare(mapobject.Position, party.ItemLeader.Position)) { collection.LootLeader = party.ItemLeader.id; } else { collection.LootLeader = character.id; } // Generate loot from base mobs foreach (Rag2Item c in Singleton.Itemdrops.FindItemDropsById(mapobject.ModelId, character._DropRate)) { collection.Lootlist.Add(c); } //Item drops from quest content foreach (Rag2Item item in QuestBase.UserQuestLoot(mapobject.ModelId, character)) { collection.Lootlist.Add(item); } return collection; }
public static void OpenMenu(Character target, MapObject source, uint dialogScript, DialogType type, params DialogType[] icons) { byte[] dialogs = new byte[icons.Length]; for (int i = 0; i < icons.Length; i++) dialogs[i] = (byte)icons[i]; OpenMenu(target, source, dialogScript, type, dialogs); }
public static void OpenSubmenu(Character target, MapObject source, uint dialogScript, DialogType type, params byte[] icon) { target._target = source; target.ActiveDialog = dialogScript; SMSG_NPCCHAT spkt = new SMSG_NPCCHAT(); spkt.Icons = icon; spkt.Unknown = (byte)type; spkt.Script = dialogScript; spkt.ActorID = source.id; spkt.SessionId = target.id; spkt.Unknown2 = 2; target.client.Send((byte[])spkt); }
public static void Subscribe(MapObject c) { //IF THE SELECTED OBJECT IS A PLAYER if (MapObject.IsPlayer(c)) { respawns_players.Add(new Respawn(c, c.currentzone)); } else if (c.CanRespawn == true) { c.currentzone.Regiontree.Unsubscribe(c); respawns.Enqueue(new Respawn(c, c.currentzone)); } else { c.currentzone.Regiontree.Unsubscribe(c); } }
/// <summary> /// Sends a corpse delete message to every visible /// player. /// </summary> /// <param name="c"></param> private static void SendCorpseClear(MapObject c) { Regiontree tree = c.currentzone.Regiontree; foreach (Character character in tree.SearchActors(c, SearchFlags.Characters)) { try { SMSG_ACTORDELETE spkt = new SMSG_ACTORDELETE(); spkt.ActorID = c.id; spkt.SessionId = character.id; character.client.Send((byte[])spkt); } catch (ObjectDisposedException) { //Do nothing if the object is disposed } } }
/// <summary> /// Selects a given actor /// </summary> /// <param name="target"></param> /// <param name="item"></param> public static void SelectActor(Character target, MapObject item) { ISelectAble current = item as ISelectAble; if (current != null) { target._targetid = item.id; SMSG_ACTORSELECTION spkt = new SMSG_ACTORSELECTION(); spkt.SessionId = target.id; spkt.MaxHP = current.HPMAX; spkt.HP = current.HP; spkt.MaxSP = current.SPMAX; spkt.SP = current.SP; spkt.SourceActorID = target.id; spkt.TargetActorID = target._targetid; target.client.Send((byte[])spkt); target._target = target; } }
public static void Unsubscribe(MapObject c) { if (MapObject.IsPlayer(c)) { lock (respawns_players) { for (int i = 0; i < respawns_players.Count; i++) { if (respawns_players[i].Object == c) { respawns_players.RemoveAt(i); i--; break; } } } } }
/// <summary> /// Occurs when reducing the LP for reduction /// </summary> /// <returns>True if LP is reduced</returns> //public bool OnLPReduction() //{ // if(LASTLP_TICK<_status.LASTLP_ADD) // LASTLP_TICK=_status.LASTLP_ADD; // int delta_t = Environment.TickCount - LASTLP_TICK; // if (delta_t > 60000) // { // LASTLP_TICK = Environment.TickCount; // if (_status.CurrentLp > 0) // { // _status.CurrentLp--; // this._status.Updates |= 1; // return true; // } // } // return false; //} public override void OnSkillUsedByTarget(MapObject source, SkillBaseEventArgs e) { //If durabillity could be checked if (e.CanCheckEquipmentDurabillity) Common.Durabillity.DoEquipment(this.Target as Character, e.Damage); //Set sword drawn if (e.SpellInfo.hate > 0) this.ISONBATTLE = true; //Use base skill base.OnSkillUsedByTarget(source, e); }
public override void OnEnemyDie(MapObject enemy) { if (MapObject.IsNpc(enemy)) { Quests.QuestBase.UserEliminateTarget(enemy.ModelId, this); } }
public static ItemSkillUsageEventArgs Create(Rag2Item item, MapObject sender, MapObject target) { ItemSkillUsageEventArgs skillusage = new ItemSkillUsageEventArgs(sender, target); skillusage.iteminfo = item.info; if (item == null) return null; else if (!Singleton.SpellManager.TryGetSpell(item.info.skill, out skillusage.info)) return null; else return skillusage; }
/// <summary> /// Clears all hate for the specified object /// </summary> /// <param name="objects"></param> public void Clear(MapObject objects) { lock (HateTable) { HateTable.Remove(objects.id); } }
/// <summary> /// Event called when casting a spell /// </summary> /// <param name="source">Source actor using the skill</param> /// <param name="e">Spell argument</param> public virtual void OnSkillUsedByTarget(MapObject source, SkillBaseEventArgs e) { }
/// <summary> /// Checks if the supplied mapobject is a character instance /// </summary> /// <param name="instance">Instance to check</param> /// <returns>True if the object is a player</returns> public static bool IsPlayer(MapObject instance) { return(instance.id < Regiontree.PlayerBorder); }
/// <summary> /// Returns all chacters in the regional sightrange. /// </summary> /// <param name="a">Object which to check if he can see</param> /// <returns>a list of objects which can be seen</returns> /// <remarks> /// Usefull for updates that should be spread about amongst /// multiple regions. For example update player information /// </remarks> public IEnumerable<Character> GetCharactersInSightRange(MapObject a) { foreach (MapObject c in this.regiontree.SearchActors(a, SearchFlags.Characters)) { if (MapObject.IsPlayer(c)) if (IsInSightRangeByRadius(c.Position, a.Position)) yield return (Character)c; } }
/// <summary> /// Returns all objects in the regional sightrange. /// </summary> /// <param name="a">Object which to check if he can see</param> /// <returns>a list of objects which can be seen</returns> /// <remarks> /// Usefull for updates that should be spread about amongst /// multiple regions. For example update player information /// </remarks> public IEnumerable<MapObject> GetObjectsInSightRange(MapObject a) { foreach (MapObject c in this.regiontree.SearchActors(a, SearchFlags.DynamicObjects)) { if (IsInSightRangeByRadius(c.Position, a.Position)) yield return c; } }
/// <summary> /// Creates a new corpse object /// </summary> /// <param name="corpse">Target who to corpse</param> public Corpse(MapObject corpse) { this.Tick = Environment.TickCount; this.Object = corpse; }
/// <summary> /// Subscribes an MapObject as an Corpse /// </summary> /// <param name="c"></param> public static void Subscribe(MapObject c) { corpses.Enqueue(new Corpse(c)); }
/// <summary> /// Occurs when seeing a enemy die /// </summary> /// <param name="enemy"></param> public virtual void OnEnemyDie(MapObject enemy) { }
/// <summary> /// Event called when actor dies /// </summary> /// <param name="d">Actor who's responsible for the death</param> public virtual void OnDie(MapObject d) { }
/// <summary>IActorid /// Checks if the supplied mapobject is a regulair npc instance /// </summary> /// <param name="instance">Instance to check</param> /// <returns>True if the object is a regulair npc</returns> public static bool IsNotMonster(MapObject instance) { return(IsNpc(instance) && (instance.ModelId < Regiontree.NpcIndexBorder)); }
/// <summary> /// Checks if the supplied mapobject is a npc instance /// </summary> /// <param name="instance">Instance to check</param> /// <returns>True if the object is a npc (this includes monsters)</returns> public static bool IsNpc(MapObject instance) { return(instance.id >= Regiontree.MapItemBorder); }
public IEnumerable<MapObject> GetObjectsInRegionalRange(MapObject a) { /* * Returns all objects in the regional sightrange. * * Usefull for updates that should be spread about amongst * multiple regions. For example update player information * */ foreach (MapObject c in this.regiontree.SearchActors(a, SearchFlags.DynamicObjects)) { yield return c; } }
public bool IsTarget(MapObject source, MapObject target) { bool result = false; if ((this.target & 1) == 1) result |= target.id == source.id; if ((this.target & 2) == 2) result |= MapObject.IsMonster(target) || MapObject.IsMapItem(target); if ((this.target & 4) == 4) result |= MapObject.IsNotMonster(target) || MapObject.IsMonster(target) || MapObject.IsPlayer(target); return result; }
/// <summary> /// Occurs when the speciafiec character killed /// our monsters /// </summary> /// <param name="target"></param> /// <returns></returns> public override void OnDie(MapObject target) { //Stop movement lock (this) { LifespanAI.Unsubscribe(this); this.stance = 7; } base.OnDie(target); }
/// <summary> /// Get's or the amount of hate for the specified object /// </summary> /// <param name="objects"></param> /// <returns></returns> public short this[MapObject objects] { get { short previoushate = 0; HateTable.TryGetValue(objects.id, out previoushate); return previoushate; } }
public static bool Create(Rag2Item item, MapObject sender, MapObject target, out ItemSkillUsageEventArgs argument) { argument = Create(item, sender, target); return argument != null; }
/// <summary> /// Use a offensive skills /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <param name="skillid"></param> /// <param name="skilltype"></param> /// <remarks> /// This functions is invoked by mob ai. The character has it's own skill handler /// inside the network client. /// </remarks> public static void OffensiveSkillUse(MapObject target, MapObject source, uint skillid, byte skilltype) { try { SkillUsageEventArgs argument = null; if (SkillUsageEventArgs.Create(skillid, source, target, out argument) && argument.Use()) { Predicate<Character> SendToCharacter = delegate(Character forwardTarget) { //Skill sucess SMSG_OFFENSIVESKILL spkt = new SMSG_OFFENSIVESKILL(); spkt.SkillID = skillid; spkt.SkillType = 1; spkt.TargetActor = target.id; spkt.SourceActor = source.id; spkt.IsCritical = (forwardTarget.id == source.id || forwardTarget.id == target.id) ? (byte)argument.Result : (byte)7; spkt.Damage = argument.Damage; spkt.SessionId = forwardTarget.id; forwardTarget.client.Send((byte[])spkt); //Process some general updates if (forwardTarget._targetid == target.id) Common.Actions.SelectActor(forwardTarget, target as Actor); if (argument.TargetHasDied) Common.Actions.UpdateStance(forwardTarget, target as Actor); if (argument.TargetHasDied && MapObject.IsNpc(target)) Common.Actions.UpdateIcon(forwardTarget, target as BaseMob); if (forwardTarget.id == target.id) LifeCycle.Update(forwardTarget); return true; }; Regiontree tree = source.currentzone.Regiontree; foreach (Character forwardTarget in tree.SearchActors(source, SearchFlags.Characters)) { SendToCharacter(forwardTarget); } } } catch (Exception e) { Console.WriteLine(e); } }
protected SkillBaseEventArgs(SkillContext context, MapObject sender, MapObject target) { this.context = context; this.sender = sender; this.target = target; if (!(this is SkillUsageEventArgs || this is ItemSkillUsageEventArgs || this is SkillToggleEventArgs)) { throw new SystemException("Class inheritance by other classes than the default are not allowed"); } }
/// <summary> /// Adds or substracts an amount of hate for the specified object /// </summary> /// <param name="objects"></param> /// <param name="hate"></param> public void Add(MapObject objects, uint damage) { if (damage > 0) { uint previousdamage = 0; DamageTable.TryGetValue(objects.id, out previousdamage); previousdamage = previousdamage + damage > uint.MaxValue ? (uint)uint.MaxValue : (uint)(previousdamage + damage); lock (DamageTable) { if (previousdamage == 0) { DamageTable.Remove(objects.id); } else { DamageTable[objects.id] = previousdamage; } } } }
private SkillUsageEventArgs(MapObject sender, MapObject target) : base(SkillContext.SkillUse, sender, target) { }
/// <summary> /// Adds or substracts an amount of hate for the specified object /// </summary> /// <param name="objects"></param> /// <param name="hate"></param> public void Add(MapObject objects, short hate) { short previoushate = 0; HateTable.TryGetValue(objects.id, out previoushate); previoushate = previoushate + hate > short.MaxValue ? (short)short.MaxValue : (short)(previoushate + hate); lock (HateTable) { if (previoushate == 0) { HateTable.Remove(objects.id); } else { HateTable[objects.id] = previoushate; } } }
public static SkillUsageEventArgs Create(uint skill, MapObject sender, MapObject target) { //SkillUsageEventArgs skill = new SkillUsageEventArgs(); SkillUsageEventArgs skillusage = new SkillUsageEventArgs(sender, target); if (Singleton.SpellManager.TryGetSpell(skill, out skillusage.info)) return skillusage; else return null; }
/// <summary> /// Get's or the amount of hate for the specified object /// </summary> /// <param name="objects"></param> /// <returns></returns> public uint this[MapObject objects] { get { uint previousdamage = 0; DamageTable.TryGetValue(objects.id, out previousdamage); return previousdamage; } }
public static bool Create(uint skill, MapObject sender, MapObject target, out SkillUsageEventArgs argument) { argument = Create(skill, sender, target); return argument != null; }