public List<uint> GetJobSpeciaficSkills(MySqlConnection connection, Character target, byte job)
        {
            List<uint> MyList = new List<uint>();
            MySqlDataReader reader = null;
            try
            {
                //LOAD ALL SKILL INFORMATION
                MySqlCommand command = new MySqlCommand(_query_65, connection);
                command.Parameters.AddWithValue("CharId", target.ModelId);

                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                while (reader.Read())
                {
                    Skill skill = new Skill();
                    skill.Id = reader.GetUInt32(0);
                    if (Singleton.SpellManager.TryGetSpell(skill.Id, out skill.info) &&
                        skill.info.requiredJobs[job - 1] == 1)
                        MyList.Add(skill.Id);
                }

                return MyList;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return new List<uint>();
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
            }
        }
        public IEnumerable<uint> GetAllLearnedSkills(MySqlConnection connection, Character target)
        {
            MySqlCommand command = new MySqlCommand(_query_61, connection);
            command.Parameters.AddWithValue("CharId", target.ModelId);
            MySqlDataReader reader = null;
            List<uint> Skills = new List<uint>();

            try
            {
                //LOAD ALL SKILL INFORMATION

                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                while (reader.Read())
                {
                    Skills.Add(reader.GetUInt32(0));
                }

                return Skills;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return Skills;
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
            }
        }
Exemple #3
0
        public static void ClearNpc(Character character, Match match)
        {
            ThreadStart AsyncOperation = delegate()
            {
                //Clear all mobs
                foreach (Zone zone in Singleton.Zones.HostedZones())
                {
                    zone.Clear();
                }

                //Respawns world objects (npc & quests)
                Singleton.QuestBoardSpawnManager.Reload();

                //Respawn npc
                Singleton.NpcSpawnManager.Reload();

                //Resend npc to actor
                foreach (Character mcharacter in Tasks.LifeCycle.Characters)
                {
                    Regiontree tree = mcharacter.currentzone.Regiontree;
                    foreach (MapObject regionObject in tree.SearchActors(mcharacter, Saga.Enumarations.SearchFlags.Npcs | Saga.Enumarations.SearchFlags.MapItems | Saga.Enumarations.SearchFlags.StaticObjects))
                    {
                        if (Point.IsInSightRangeByRadius(mcharacter.Position, regionObject.Position))
                        {
                            regionObject.ShowObject(character);
                            regionObject.Appears(character);
                        }
                    }
                }
            };

            Thread thread = new Thread(AsyncOperation);
            thread.Start();
        }
Exemple #4
0
 protected void OnCheckQuest(Character target)
 {
     foreach (QuestBase c in target.QuestObjectives)
     {
         c.CheckQuest(target);
     }
 }
        /// <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 void OnOpenBook(Character sender)
 {
     Rag2Collection items = new Rag2Collection();
     foreach (Rag2Item c in Singleton.Itemdrops.FindItemDropsById(this.ModelId, sender._DropRate))
         items.Add(c);
     this.loottable.Add(sender.id, items);
 }
 public static bool SaveCredits(Character character, int CreditValue)
 {
     IQueryProvider provider = Singleton.Database.GetQueryProvider();
     provider.CmdText = "UPDATE list_credits SET Credits=@Credits CharId=@CharId";
     provider.Parameters.AddWithValue("CharId", character.ModelId);
     provider.Parameters.AddWithValue("Credits", CreditValue);
     return Singleton.Database.ExecuteNonQuery(provider) > 0;
 }
 public void Open(Character character, BaseNPC basenpc)
 {
     character.Tag = this;
     SMSG_SUPPLYMENU spkt = new SMSG_SUPPLYMENU();
     spkt.MenuId = this.TradeMenu;
     spkt.SessionId = character.id;
     character.client.Send((byte[])spkt);
 }
 /// <summary>
 /// Occurs when the auction button is pressed.
 /// </summary>
 /// <param name="npc">Npc who calls the function</param>
 /// <param name="target">Character who requires interaction</param>
 protected virtual void OnAuction(BaseNPC npc, Character target)
 {
     Common.Actions.OpenSubmenu(target, npc,
         _Auction,               //Dialog script to show
         DialogType.Market,      //Button function
         21                      //Open market
     );
 }
        public DialogType[] GetDialogButtons(Character target)
        {
            List<DialogType> types = new List<DialogType>();
            types.AddRange(this.state.GetDialogButtons(this, target));

            DialogType[] typesa = types.ToArray();
            return typesa;
        }
 /// <summary>
 /// Subscribes the monsters moving ai if an
 /// character appears.
 /// </summary>
 /// <param name="character"></param>
 public override void Appears(Character character)
 {
     //ENABLE THE AI
     if (!LifespanAI.IsSubscribed(this))
     {
         Lifespan.lasttick = Environment.TickCount;
         LifespanAI.Subscribe(this);
     }
 }
 public override int ComputeIcon(Character target)
 {
     int dialog = 0;
     if (target.client.AvailablePersonalRequests.ContainsKey(this.ModelId))
         dialog |= 1;
     if (QuestBase.IsTalkToObjective(this.ModelId, target))
         dialog |= 2;
     return (int)(base.ComputeIcon(target) | dialog);
 }
 /// <summary>
 /// Occurs after the Kaftra button is pressed.
 /// </summary>
 /// <param name="npc">Npc who called the event</param>
 /// <param name="target">Character who requirs interaction</param>
 protected virtual void OnKaftraService(BaseNPC npc, Character target)
 {
     Common.Actions.OpenSubmenu(
         target, npc,
         _KaftraService,
         DialogType.Kaftra,
         10,
         11
     );
 }
Exemple #14
0
 public void WideMovement(Character character, params WaypointStructure[] waypoints)
 {
     SMSG_WIDEMOVEMENTSTART spkt = new SMSG_WIDEMOVEMENTSTART();
     spkt.SourceActorID = this.id;
     spkt.Speed = (ushort)this.Status.WalkingSpeed;
     for (int i = 0; i < waypoints.Length; i++)
         spkt.AddWaypoint(waypoints[i].point, waypoints[i].rotation);
     spkt.SessionId = character.id;
     character.client.Send((byte[])spkt);
 }
        public Rag2Collection GetLootList(Character target)
        {
            Rag2Collection items;
            if (!loottable.TryGetValue(target.id, out items))
            {
                items = new Rag2Collection();
            }

            return items;
        }
        /// <summary>
        /// Unsubscribes the monsters moving ai if the region's player
        /// count is 0.
        /// </summary>
        /// <param name="character"></param>
        public override void Disappear(Character character)
        {
            //DISABLE THE AI
            if (Regiontree.GetCharacterCount(this) == 0)
            {
                LifespanAI.Unsubscribe(this);
                this.Position = this.DestPosition;
            }

            base.Disappear(character);
        }
 public void Show(Character target)
 {
     SMSG_JOBCHANGE spkt = new SMSG_JOBCHANGE();
     spkt.SessionId = target.id;
     for (int i = 0; i < availablejobs.Count; i++)
     {
         spkt.Add(availablejobs[i]);
     }
     target.Tag = this;
     target.client.Send((byte[])spkt);
 }
        /// <summary>
        /// Occurs when subemnu item 'Open market' is pressed.
        /// </summary>
        /// <param name="npc">Npc who calls the function</param>
        /// <param name="target">Character who requires interaction</param>
        protected virtual void OnAuctionOpen(BaseNPC npc, Character target)
        {
            CommonFunctions.ShowAuction(target, npc);

            Common.Actions.OpenMenu(
                target, npc,
                _AuctionOpen,
                DialogType.Market,
                new byte[] { }
            );
        }
Exemple #19
0
        protected void OnCheckMail(Character target)
        {
            SMSG_MAILLIST spkt = new SMSG_MAILLIST();
            spkt.SessionId = target.id;
            spkt.SourceActor = target.id;

            foreach (Mail c in Singleton.Database.GetInboxMail(target))
                spkt.AddMail(c);

            target.client.Send((byte[])spkt);
        }
 /// <summary>
 /// Occurs when opening the blacksmith menu
 /// </summary>
 /// <param name="npc">Npc who requires shows the menu</param>
 /// <param name="target">Character who requires interaction</param>
 protected virtual void OnBlackSmithMenu(BaseNPC npc, Character target)
 {
     Common.Actions.OpenSubmenu(target, npc,
         _BlackSmithMenu,        //Dialog script to show
         DialogType.Smith,       //Button function
         50,                     //Repair
         52,                     //Change Type
         53,                     //Upgrade
         55                      //Change Suffix
     );
 }
        /// <summary>
        /// Occurs after showing the trader dialog.
        /// </summary>
        /// <param name="npc"></param>
        /// <param name="target"></param>
        protected virtual void OnTradeDialog(BaseNPC npc, Character target)
        {
            Common.Actions.OpenMenu(
                target, npc,
                _TradeDialog,
                DialogType.TradeItems,
                npc.GetDialogButtons(target)
            );

            _container.Open(target, npc);
        }
        /// <summary>
        /// Occurs when pressing the shop buttong
        /// </summary>
        /// <param name="npc">Npc who calls the event</param>
        /// <param name="target">Character who requires interaction</param>
        protected virtual void OnShop(BaseNPC npc, Character target)
        {
            //Open menu
            Common.Actions.OpenMenu(
                target, npc,
                _Shop,
                DialogType.Shop,
                npc.GetDialogButtons(target)
            );

            //Open shoplist
            _shoplist.Open(target, npc);
        }
        protected uint ComputeTransferFee(Character character, byte job)
        {
            int Price = 0;
            Price += (character.CharacterJobLevel[job] * 300);
            List<uint> Skills = Singleton.Database.GetJobSpeciaficSkills(character, job);
            for (int i = 0; i < Skills.Count; i++)
            {
                int Lvl = (int)(Skills[i] % 100);
                Price += ((Lvl - 1) * 100);
            }

            return (uint)Price;
        }
Exemple #24
0
 public override void ShowObject(Character character)
 {
     SMSG_ITEMINFO spkt = new SMSG_ITEMINFO();
     spkt.ActorID = this.id;
     spkt.NPCID = this.ModelId;
     spkt.X = this.Position.x;
     spkt.Y = this.Position.y;
     spkt.Z = this.Position.z;
     spkt.Yaw = this.Yaw;
     spkt.SessionId = character.id;
     spkt.IsActive = this.IsHighlighted(character);
     spkt.CanInteract = this.IsInteractable(character);
     character.client.Send((byte[])spkt);
 }
        /// <summary>
        /// Checks if a skill can be used.
        /// </summary>
        /// <param name="character">Character to check on</param>
        /// <param name="info">Information to check</param>
        /// <returns>True if skill can be used</returns>
        public bool CanUse(Character character, Info info)
        {
            int WeaponType = 0;
            int Job = character.job - 1;

            int WeaponIndex = (character.weapons.ActiveWeaponIndex == 1) ? character.weapons.SeconairyWeaponIndex : character.weapons.PrimaryWeaponIndex;
            if (WeaponIndex < character.weapons.UnlockedWeaponSlots)
            {
                WeaponType = character.weapons[WeaponIndex]._weapontype;
            }

            bool jobAble = info.requiredJobs[Job] == 1;
            bool weaponAble = info.requiredWeapons[WeaponType] == 1;
            return jobAble && weaponAble;
        }
        /// <summary>
        /// This functions subscribes a character to a list of users
        /// indexed by their sessions id. (Is the same as the character
        /// id.
        /// </summary>
        /// <param name="character"></param>
        public static void Subscribe(Character character)
        {
            if (character == null) return;
            lock (ListOfUsers)
            {
                if (ListOfUsers.ContainsKey(character.id) == false)
                {
                    lock (ListOfUsersByName)
                    {
                        ListOfUsersByName.Add(character.Name.ToUpperInvariant(), character);
                    }

                    ListOfUsers.Add(character.id, character);
                }
            }
        }
 internal static void ForcePlayerFromShipZone(Character character)
 {
     lock (states)
     {
         for (int i = 0; i < states.Count; i++)
         {
             DepartureState state = states[i];
             if (state.zone == character.currentzone)
             {
                 character.map = state.zone.CathelayaLocation.map;
                 character.Position = state.zone.CathelayaLocation.coords;
                 break;
             }
         }
     }
 }
Exemple #28
0
        public static int LoadCredits(Character character)
        {
            IQueryProvider provider = Singleton.Database.GetQueryProvider();
            provider.CmdText = "SELECT Credits FROM list_credits WHERE CharId=@CharId";
            provider.Parameters.AddWithValue("CharId", character.ModelId);

            int credits = 0;
            using (IDataReader reader = Singleton.Database.ExecuteDataReader(provider, CommandBehavior.SingleResult))
            {
                while (reader.Read())
                {
                    credits = reader.GetInt32(0);
                }
            }

            return credits;
        }
        public static JobChangeCollection Create(Character target)
        {
            JobChangeCollection collection = new JobChangeCollection();
            collection.availablejobs = new List<byte>();
            collection.transferfee = new List<uint>();
            for (byte i = 1; i < 7; i++)
            {
                if (i == target.job) continue;
                if (target.jlvl >= 5)
                {
                    collection.availablejobs.Add(i);
                    collection.transferfee.Add(collection.ComputeTransferFee(target, i));
                }
            }

            return collection;
        }
        public static void ParseGMCommand(string command, Character character)
        {
            try
            {
                string[] commands = command.Split(new char[] { ' ' }, 2);
                string commandname = commands[0].Length > 1 ? command.Substring(1, commands[0].Length - 1) : string.Empty;
                string body = commands.Length > 1 ? commands[1] : string.Empty;
                if (commandname == string.Empty) return;

                GmCommand commanda;
                if (CommandList.TryGetValue(commandname.ToUpperInvariant(), out commanda))
                {
                    Regex matchingrex = commanda.attribute.Regex;
                    Match match = matchingrex.Match(body);

                    if (match.Success == false)
                    {
                        string warning = string.Format(CultureInfo.InvariantCulture, "Command: {0} was not successfull.", commandname);
                        SendCommandReply(character.client, warning);
                    }
                    //else if (commanda.attribute.Gmlevel >= character.GmLevel)
                    else if (commanda.attribute.Gmlevel > character.GmLevel)
                    {
                        string warning = string.Format(CultureInfo.InvariantCulture, "You are not authorised to use this command.");
                        SendCommandReply(character.client, warning);
                    }
                    else
                    {
                        commanda.handler.Invoke(character, match);
                    }
                }
                else
                {
                    string warning = string.Format(CultureInfo.InvariantCulture, "Command: {0} was not found.", commandname);
                    SendCommandReply(character.client, warning);
                }
            }
            catch (Exception)
            {
                Trace.TraceWarning("Error parsing commands: {0}", command);
            }
        }
Exemple #31
0
 /// <summary>
 /// Evemt called when clicking on the item
 /// </summary>
 /// <param name="target">Target who clicks on the object</param>
 public virtual void OnClicked(Character target)
 {
     Console.WriteLine(this.ModelId);
 }
Exemple #32
0
 /// <summary>
 /// Get's if the item is interactable for the given actor
 /// </summary>
 /// <param name="target">Target to check against</param>
 /// <returns>1 If the item is interactable</returns>
 public virtual byte IsInteractable(Character target)
 {
     return(0);
 }
Exemple #33
0
 /// <summary>
 /// Get's if the item can be highlighted to show a tooltip
 /// </summary>
 /// <param name="target">Target to check against</param>
 /// <returns>1 If the item can be highlighted</returns>
 public virtual byte IsHighlighted(Character target)
 {
     return(0);
 }