Esempio n. 1
0
        /// <summary>
        /// Occurs when leaving a zone
        /// </summary>
        /// <param name="character"></param>
        public virtual void OnLeave(Character character)
        {
            if (character.currentzone == this)
            {
                if (!this.Regiontree.Unsubscribe(character))
                {
                    Trace.TraceError("Unsubscribe failed");
                }

                Regiontree tree = character.currentzone.Regiontree;
                foreach (MapObject target in tree.SearchActors(character, Saga.Enumarations.SearchFlags.DynamicObjects))
                {
                    if (MapObject.IsPlayer(target))
                    {
                        Character cTarget = (Character)target;
                        if (cTarget != character && cTarget.client.isloaded == true)
                        {
                            character.HideObject(cTarget);
                        }
                        target.Disappear(character);
                    }
                    else
                    {
                        target.Disappear(character);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Occurs when you click on a object.
        /// Mapobject, Character doesn't matter.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_GETATTRIBUTE(CMSG_ATTRIBUTE cpkt)
        {
            MapObject Target;

            if (Regiontree.TryFind(cpkt.ActorID, this.character, out Target))
            {
                Target.OnClick(this.character);
            }


            //Reset the stance if we're not moving
            if (this.character.stance != 4 && this.character.stance != 5)
            {
                Regiontree tree = this.character.currentzone.Regiontree;
                foreach (Character current in tree.SearchActors(this.character, SearchFlags.Characters))
                {
                    if (current.id == this.character.id || current.client.isloaded == false || !Point.IsInSightRangeByRadius(current.Position, this.character.Position))
                    {
                        continue;
                    }
                    SMSG_ACTORCHANGESTATE spkt2 = new SMSG_ACTORCHANGESTATE();
                    spkt2.ActorID     = character.id;
                    spkt2.State       = (byte)((character.ISONBATTLE) ? 1 : 0);
                    spkt2.Stance      = character.stance;
                    spkt2.TargetActor = character._targetid;
                    spkt2.SessionId   = current.id;
                    current.client.Send((byte[])spkt2);
                }
            }
        }
Esempio n. 3
0
        public Character GetLowestEnemy()
        {
            Character selection   = null;
            int       lowestLevel = -1;

            Regiontree tree = this.currentzone.Regiontree;

            foreach (Character chacter in tree.SearchActors(this, SearchFlags.Characters))
            {
                int    level    = chacter.Level - this.Level;
                double distance = Point.GetDistance3D(chacter.Position, this.Position);
                if (level < 30 && distance < this._SIGHTRANGE)
                {
                    if (lowestLevel == -1)
                    {
                        selection   = chacter;
                        lowestLevel = level;
                        continue;
                    }

                    if (level > lowestLevel)
                    {
                        continue;
                    }

                    selection   = chacter;
                    lowestLevel = level;
                }
            }

            return(selection);
        }
Esempio n. 4
0
        /// <summary>
        /// Occurs when a character selects a supply menu
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_SELECTSUPPPLYMENU(CMSG_SUPPLYSELECT cpkt)
        {
            try
            {
                //Try get dependecies
                MapObject  regionoject = null;
                Regiontree tree        = this.character.currentzone.Regiontree;
                Regiontree.TryFind(cpkt.ActorId, this.character, out regionoject);

                //Implicit casts
                BaseNPC            npc       = this.character.Target as BaseNPC;
                TradelistContainer container = this.character.Tag as TradelistContainer;

                if (npc != null && container != null)
                {
                    //Regossip the npc
                    npc.OnGossip(this.character);

                    //Find the tradelist
                    BaseTradelist utradelist;
                    if (container.dict.TryGetValue(cpkt.ButtonId, out utradelist))
                    {
                        utradelist.Open(this.character, npc, cpkt.ButtonId);
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
        }
Esempio n. 5
0
        public void StartRunning(Point a)
        {
            //Set is moving to true
            this.stance = 5;

            //Set my destination position
            this.DestPosition = a;

            //Generate packet
            SMSG_ACTORMOVEMENTSTART spkt = new SMSG_ACTORMOVEMENTSTART();

            spkt.SourceActorID = this.id;
            //spkt.Stance = this.stance;
            spkt.Speed = (ushort)this._RUNSPEED;
            spkt.Source(this.Position);
            spkt.Destination(this.DestPosition);
            //this.Position = NextPosition;

            //Send over movement start to all characters in neighbourhood
            Regiontree tree = this.currentzone.Regiontree;

            foreach (Character character in tree.SearchActors(this, SearchFlags.Characters))
            {
                if (Point.IsInSightRangeByRadius(this.Position, character.Position))
                {
                    spkt.SessionId = character.id;
                    character.client.Send((byte[])spkt);
                }
            }
        }
Esempio n. 6
0
        public void StopMovement()
        {
            //Set my destination position
            this.DestPosition = this.Position;

            //Generate packet
            SMSG_MOVEMENTSTOPPED spkt = new SMSG_MOVEMENTSTOPPED();

            spkt.ActorID   = this.id;
            spkt.speed     = (ushort)this.Status.WalkingSpeed;
            spkt.DelayTime = 0;
            spkt.X         = this.Position.x;
            spkt.Y         = this.Position.y;
            spkt.Z         = this.Position.z;
            spkt.yaw       = this.Yaw;

            //Send over movement start to all characters in neighbourhood
            Regiontree tree = this.currentzone.Regiontree;

            foreach (Character character in tree.SearchActors(this, SearchFlags.Characters))
            {
                if (Point.IsInSightRangeByRadius(this.Position, character.Position))
                {
                    spkt.SessionId = character.id;
                    character.client.Send((byte[])spkt);
                }
            }

            //Set is moving to false
            this.stance = 3;
        }
Esempio n. 7
0
        /// <summary>
        /// Get's the currentscenariostep
        /// </summary>
        public static uint StartEvent(uint cid, uint EventId)
        {
            Console.WriteLine("Start event: {0}", EventId);

            Character value;

            if (LifeCycle.TryGetById(cid, out value))
            {
                SMSG_SCENARIOEVENTBEGIN spkt = new SMSG_SCENARIOEVENTBEGIN();
                spkt.ActorId = value.id;
                spkt.Event   = EventId;
                value._Event = EventId;

                Regiontree tree = value.currentzone.Regiontree;
                foreach (Character regionObject in tree.SearchActors(value, SearchFlags.Characters))
                {
                    if (value.currentzone.IsInSightRangeByRadius(value.Position, regionObject.Position))
                    {
                        spkt.SessionId = regionObject.id;
                        regionObject.client.Send((byte[])spkt);
                    }
                }

                while (value._Event > 0)
                {
                    Thread.Sleep(0);
                }
            }
            return(0);
        }
Esempio n. 8
0
 public override void Start(Ship ship)
 {
     ship.Position = point;
     ship.Yaw      = yaw;
     Regiontree.UpdateRegion(ship, false);
     Owner.NextPoint(ship);
 }
Esempio n. 9
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();
        }
Esempio n. 10
0
            public override void Check(Ship ship)
            {
                int t_diff = Environment.TickCount - Owner.LastTick;

                if (t_diff > 60000)
                {
                    //Check for players to warp
                    List <Character> characters = new List <Character>();
                    Regiontree       tree       = ship.currentzone.Regiontree;
                    foreach (Character regionObject in tree.SearchActors(ship, SearchFlags.Characters))
                    {
                        if (box.IsInBox(regionObject.Position))
                        {
                            characters.Add(regionObject);
                        }
                    }

                    if (characters.Count > 0)
                    {
                        Saga.Tasks.Shipservice.Enqeuee
                        (
                            characters,
                            ship.currentzone.Map,
                            DepartureWarpPosition,
                            DestinationMapId,
                            TravelTime
                        );
                    }

                    Thread.Sleep(5);

                    Owner.NextPoint(ship);
                    Owner.LastTick = Environment.TickCount;
                }
            }
Esempio n. 11
0
        /// <summary>
        /// Unspawns a item
        /// </summary>
        /// <param name="regionObject"></param>
        public void UnspawnInstance(MapObject regionObject)
        {
            regionObject.OnDeregister();
            Regiontree tree = regionObject.currentzone.Regiontree;

            foreach (Character character in tree.SearchActors(regionObject, Saga.Enumarations.SearchFlags.Characters))
            {
                try
                {
                    if (character.client.isloaded == false)
                    {
                        continue;
                    }
                    if (character.Target == regionObject)
                    {
                        character.Target = null;
                    }
                    regionObject.HideObject(character);
                }
                catch (SocketException)
                {
                    //Do nothing
                }
            }
        }
Esempio n. 12
0
        /// <title>Saga.AddWaypoint</title>
        /// <code>
        /// Saga.AddWaypoint(cid, QuestID, StepId, State);
        /// </code>
        /// <description>
        /// Adds a waypoint to the quest list.
        /// (Note it will also activate the npc if it's not yet activated)
        /// </description>
        /// <example>
        /// function QUEST_STEP_2(cid)
        ///	    -- Talk to mischa
        ///     local NPCIndex = 1000;
        ///     local ret = Saga.GetNPCIndex(cid);
        ///
        ///     Saga.AddWaypoint(cid, QuestID, NPCIndex, -12092, -6490, -8284, 1);
        ///     if ret == NPCIndex then
        ///         Saga.StepComplete(cid, QuestID, 102);
        ///     else
        ///         return  -1;
        ///     end
        ///
        ///     Saga.ClearWaypoints(cid, QuestID);
        ///     return 0;
        /// end
        /// </example>
        public static void AddWayPoint(uint cid, uint QID, uint stepid, byte substepid, uint npcType)
        {
            Character Character;

            if (LifeCycle.TryGetById(cid, out Character))
            {
                //Substep - 1;
                substepid--;

                //Find the substep
                Predicate <Saga.Quests.Objectives.ObjectiveList.SubStep> FindSubstep =
                    delegate(Saga.Quests.Objectives.ObjectiveList.SubStep objective)
                {
                    return(objective.Quest == QID &&
                           objective.StepId == stepid &&
                           objective.SubStepId == substepid);
                };

                Predicate <Saga.Quests.Objectives.ObjectiveList.Waypoint> FindWaypoint =
                    delegate(Saga.Quests.Objectives.ObjectiveList.Waypoint objective)
                {
                    return(objective.Quest == QID &&
                           objective.StepId == stepid &&
                           objective.NpcId == npcType);
                };

                //Get substep list
                List <Saga.Quests.Objectives.ObjectiveList.SubStep> Substeps =
                    Character.QuestObjectives.Substeps;

                //Add waypoint
                List <Saga.Quests.Objectives.ObjectiveList.Waypoint> Waypoints =
                    Character.QuestObjectives.GuidancePoints;

                //Add substeps
                int index = Substeps.FindIndex(FindSubstep);
                if (index == -1)
                {
                    int index2 = Waypoints.FindIndex(FindWaypoint);
                    if (index2 == -1)
                    {
                        Substeps.Add(new Saga.Quests.Objectives.ObjectiveList.SubStep(substepid, false, 0, 1, QID, stepid));
                        Waypoints.Add(new Saga.Quests.Objectives.ObjectiveList.Waypoint(npcType, QID, stepid, substepid));
                        Regiontree tree = Character.currentzone.Regiontree;
                        foreach (MapObject a in tree.SearchActors(Character, SearchFlags.Npcs))
                        {
                            BaseMob mob = a as BaseMob;
                            if (a.ModelId == npcType)
                            {
                                if (mob != null)
                                {
                                    Common.Actions.UpdateIcon(Character, mob);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
    public static void UpdateState(Character target)
    {
        Regiontree tree = target.currentzone.Regiontree;

        foreach (Character regionObject in tree.SearchActors(target, SearchFlags.Characters))
        {
            Common.Actions.UpdateStance(regionObject, target);
        }
    }
Esempio n. 14
0
        /// <summary>
        /// Does a lp effect.
        /// </summary>
        public void LpEffect(int value, Actor source)
        {
            Regiontree tree = source.currentzone.Regiontree;

            foreach (Character current in tree.SearchActors(source, Saga.Enumarations.SearchFlags.Characters))
            {
                Common.Skills.SendSkillEffect(current as Character, source, this.info.addition, 3, (uint)value);
            }
        }
Esempio n. 15
0
            public override void Check(Ship ship)
            {
                int tdiff = Environment.TickCount - Owner.LastTick;

                if (Owner.state == 0)
                {
                    if (tdiff > 1000)
                    {
                        UpdateMovment(tdiff, ship);
                        int    speed    = (int)ship.Status.WalkingSpeed;
                        double distance = ComputeDistance(ship);
                        if (distance < speed)
                        {
                            int t_add = (int)((distance / (double)speed) * 1000);
                            ship.Yaw       = this.structure.rotation;
                            ship.Position  = this.structure.point;
                            Owner.LastTick = Environment.TickCount + t_add;
                            Owner.NextPoint(ship);
                            Owner.state = 1;
                        }
                        else
                        {
                            Owner.LastTick = Environment.TickCount;
                        }
                    }
                }
                else
                {
                    if (tdiff > 0)
                    {
                        UpdateMovment(tdiff, ship);
                        Regiontree.UpdateRegion(ship, false);
                        int numberofpoints = 0;
                        for (int i = Owner.point; i < Owner.Elements.Count; i++)
                        {
                            if (Owner.Elements[i] is PointElement)
                            {
                                numberofpoints++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        Owner.state = 0;
                        if (numberofpoints > 1)
                        {
                            WaypointStructure current = new WaypointStructure(ship.Position, ship.Yaw);
                            PointElement      A       = Owner.Elements[Owner.point + 0] as PointElement;
                            PointElement      B       = Owner.Elements[Owner.point + 1] as PointElement;
                            ship.WideMovement(current, A.structure, B.structure);
                        }
                    }
                }
            }
        public static void UserUpdateActionObjectType(uint cid, uint QID, uint SID, uint AID, byte State)
        {
            //HELPER VARIABLES
            Character value;

            //GET THE ACTIVE QUEST
            if (LifeCycle.TryGetById(cid, out value))
            {
                Predicate <Saga.Quests.Objectives.ObjectiveList.Activation> FindActivatedObject = delegate(Saga.Quests.Objectives.ObjectiveList.Activation objective)
                {
                    return(objective.NpcId == AID &&
                           objective.StepId == SID);
                };

                bool process = false;
                if (State == 0)
                {
                    if (value.QuestObjectives.ActivatedNpc.FindIndex(FindActivatedObject) == -1)
                    {
                        value.QuestObjectives.ActivatedNpc.Add(
                            new Saga.Quests.Objectives.ObjectiveList.Activation(
                                AID,
                                QID,
                                SID
                                )
                            );
                        process = true;
                    }
                }
                else
                {
                    value.QuestObjectives.ActivatedNpc.RemoveAll(FindActivatedObject);
                    process = true;
                }


                if (process == true) //For optimilisation
                {
                    Regiontree tree = value.currentzone.Regiontree;
                    foreach (MapItem item in tree.SearchActors(value, Saga.Enumarations.SearchFlags.MapItems))
                    {
                        if (item.ModelId == AID)
                        {
                            SMSG_ITEMUPDATE spkt = new SMSG_ITEMUPDATE();
                            spkt.ActorID   = item.id;
                            spkt.Active1   = 0;
                            spkt.Active    = item.IsHighlighted(value);
                            spkt.Active2   = item.IsInteractable(value);
                            spkt.SessionId = value.id;
                            value.client.Send((byte[])spkt);
                        }
                    }
                }
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Is invoked when you greet the npc.
 /// </summary>
 /// <param name="cpkt"></param>
 private void CM_NPCCHAT(CMSG_NPCCHAT cpkt)
 {
     if (Regiontree.TryFind(cpkt.ActorID, this.character, out this.character._target))
     {
         if (character.Target is BaseNPC)
         {
             BaseNPC current = character.Target as BaseNPC;
             current.OnGossip(this.character);
         }
     }
 }
Esempio n. 18
0
        /// <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);
        }
Esempio n. 19
0
        /// <summary>
        /// Subscribes the monsters ai if an the monster is summoned in a crowded
        /// area.
        /// </summary>
        public override void OnRegister()
        {
            //First register the mob
            base.OnRegister();

            //Check if start moving the mob
            if (Regiontree.GetCharacterCount(this) > 0)
            {
                LifespanAI.Subscribe(this);
            }
        }
Esempio n. 20
0
        /// <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);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Deletes a given addition icon to a player
        /// </summary>
        /// <param name="source"></param>
        /// <param name="addition"></param>
        internal static void SendDeleteStatus(Actor source, uint addition)
        {
            Regiontree tree = source.currentzone.Regiontree;

            foreach (Character current in tree.SearchActors(SearchFlags.Characters))
            {
                SMSG_ADDITIONEND spkt = new SMSG_ADDITIONEND();
                spkt.SourceActor = source.id;
                spkt.StatusID    = addition;
                spkt.SessionId   = current.id;
                current.client.Send((byte[])spkt);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Respawns a monster or mapobject
        /// </summary>
        /// <param name="c"></param>
        private static void SendRespawn(MapObject c)
        {
            bool isnpc     = MapObject.IsNpc(c);
            bool ismapitem = MapObject.IsMapItem(c);

            c.OnDeregister();
            c.OnSpawn();
            c.OnRegister();

            Regiontree tree = c._currentzone.Regiontree;

            if (isnpc)
            {
                foreach (Character regionObject in tree.SearchActors(SearchFlags.Characters))
                {
                    Actor actor = c as Actor;
                    actor.stance = (byte)StancePosition.Reborn;
                    SMSG_NPCINFO spkt2 = new SMSG_NPCINFO(0);
                    spkt2.ActorID   = actor.id;
                    spkt2.HP        = actor.HPMAX;
                    spkt2.SP        = actor.SPMAX;
                    spkt2.MaxHP     = actor.HPMAX;
                    spkt2.MaxSP     = actor.SPMAX;
                    spkt2.NPCID     = actor.ModelId;
                    spkt2.X         = actor.Position.x;
                    spkt2.Y         = actor.Position.y;
                    spkt2.Z         = actor.Position.z;
                    spkt2.SessionId = regionObject.id;
                    regionObject.client.Send((byte[])spkt2);
                    c.Appears(regionObject);
                }
            }
            else if (ismapitem)
            {
                foreach (Character regionObject in tree.SearchActors(SearchFlags.Characters))
                {
                    MapItem       item  = c as MapItem;
                    SMSG_ITEMINFO spkt2 = new SMSG_ITEMINFO();
                    spkt2.ActorID     = item.id;
                    spkt2.CanInteract = item.IsInteractable(regionObject);
                    spkt2.IsActive    = item.IsHighlighted(regionObject);
                    spkt2.NPCID       = item.ModelId;
                    spkt2.X           = item.Position.x;
                    spkt2.Y           = item.Position.y;
                    spkt2.Z           = item.Position.z;
                    spkt2.SessionId   = regionObject.id;
                    regionObject.client.Send((byte[])spkt2);
                    c.Appears(regionObject);
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Adds a additions icon the the player.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="addition"></param>
        /// <param name="time"></param>
        internal static void SendExchangeStatus(Actor source, uint addition, uint time)
        {
            Regiontree tree = source.currentzone.Regiontree;

            foreach (Character current in tree.SearchActors(SearchFlags.Characters))
            {
                SMSG_ADDITIONBEGIN spkt = new SMSG_ADDITIONBEGIN();
                spkt.Duration    = time;
                spkt.SourceActor = source.id;
                spkt.StatusID    = addition;
                spkt.SessionId   = current.id;
                current.client.Send((byte[])spkt);
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Tries to get the hate of the mob.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_REQUESTSHOWNPCLOCATION(CMSG_NPCLOCATIONSELECT cpkt)
        {
            List <GuidePoint> guidepoints = this.character.Tag as List <GuidePoint>;

            if (guidepoints != null && cpkt.LocationId < guidepoints.Count)
            {
                GuidePoint    point  = guidepoints[cpkt.LocationId];
                GuideNpc      npoint = point as GuideNpc;
                GuidePosition ppoint = point as GuidePosition;

                if (npoint != null)
                {
                    //Predicated used searching
                    Predicate <MapObject> FindActor = delegate(MapObject actor)
                    {
                        return(actor.ModelId == npoint.Map);
                    };

                    List <MapObject> matchingactors = new List <MapObject>();
                    Regiontree       tree           = this.character.currentzone.Regiontree;
                    matchingactors.AddRange(tree.SearchActors(FindActor, SearchFlags.Npcs));
                    if (matchingactors.Count > 0)
                    {
                        MapObject matchingactor     = matchingactors[0];
                        SMSG_NPCASKLOCATIONSRC spkt = new SMSG_NPCASKLOCATIONSRC();
                        spkt.SessionId    = this.character.id;
                        spkt.Result       = 0;
                        spkt.DialogScript = 0;
                        spkt.NpcId        = npoint.Map;
                        spkt.X            = matchingactor.Position.x;
                        spkt.Y            = matchingactor.Position.y;
                        spkt.Z            = matchingactor.Position.z;
                        this.Send((byte[])spkt);
                    }
                }
                else if (ppoint != null)
                {
                    SMSG_NPCASKLOCATIONSRC spkt = new SMSG_NPCASKLOCATIONSRC();
                    spkt.SessionId    = this.character.id;
                    spkt.Result       = 2;
                    spkt.DialogScript = 0;
                    spkt.NpcId        = ppoint.Npc;
                    spkt.X            = ppoint.x;
                    spkt.Y            = ppoint.y;
                    spkt.Z            = ppoint.z;
                    spkt.Result2      = 6;
                    this.Send((byte[])spkt);
                }
            }
        }
Esempio n. 25
0
        public static bool UserTalktoTarget(uint NpcId, Character Target, QuestBase Quest)
        {
            try
            {
                Quest.CheckQuest(Target);
                if (true)
                {
                    /*
                     * //Predicate to remove the activated npc
                     * Predicate<ObjectiveList.Activation> FindActivatedNpc =
                     *  delegate(ObjectiveList.Activation objective)
                     * {
                     *  return objective.NpcId == NpcId && objective.Quest == Quest.QuestId;
                     * };
                     */


                    //Target.QuestObjectives.ActivatedNpc.RemoveAll(FindActivatedNpc);

                    /*
                     * MapObject myObject = Target.currentzone.Regiontree.SearchActor(IsNpc, Target, SearchFlags.Npcs);
                     * if (myObject != null)
                     * {
                     *  BaseMob temp = myObject as BaseMob;
                     * }*/

                    /**/

                    Regiontree tree = Target.currentzone.Regiontree;
                    foreach (MapObject a in tree.SearchActors(Target, SearchFlags.Npcs))
                    {
                        if (a.ModelId == NpcId)
                        {
                            BaseMob mob = a as BaseMob;
                            if (mob != null)
                            {
                                Common.Actions.UpdateIcon(Target, mob);
                            }
                        }
                    }

                    return(true);
                }
            }
            catch (QuestFailedException)
            {
                //Do nothing here
                return(false);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Spawns an instance of an item
        /// </summary>
        /// <param name="id">Id of the npc id</param>
        /// <param name="position">Position of the npc</param>
        /// <param name="yaw">Yaw of the npc</param>
        /// <param name="zone">Zone where to register the npc</param>
        /// <param name="regionObject">returned object</param>
        /// <returns>Returns true if the object doesn't fail</returns>
        public bool SpawnItemInstance(uint id, Point position, Rotator yaw, Zone zone, out MapObject regionObject)
        {
            if (CreateInstance(id, 1, out regionObject))
            {
                regionObject.Position    = position;
                regionObject.Yaw         = yaw;
                regionObject.currentzone = zone;
                regionObject.OnInitialize(position);
                regionObject.OnLoad();
                regionObject.OnSpawn();
                regionObject.OnRegister();


                if (regionObject.id > 0)
                {
                    Regiontree tree = regionObject.currentzone.Regiontree;
                    foreach (Character regionCharacter in tree.SearchActors(regionObject, Saga.Enumarations.SearchFlags.Characters))
                    {
                        try
                        {
                            if (regionCharacter.client.isloaded == false)
                            {
                                continue;
                            }
                            if (Point.IsInSightRangeByRadius(regionCharacter.Position, regionObject.Position))
                            {
                                regionObject.ShowObject(regionCharacter);
                            }
                        }
                        catch (SocketException)
                        {
                            //Do nothing
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            return(false);
        }
Esempio n. 27
0
        /// <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
                }
            }
        }
Esempio n. 28
0
        public void Clear()
        {
            lock (this.regiontree)
            {
                List <MapObject> list = new List <MapObject>();
                list.AddRange(regiontree.Clear());

                foreach (Character character in Regiontree.SearchActors(SearchFlags.Characters))
                {
                    foreach (MapObject regionObject in list)
                    {
                        try
                        {
                            SMSG_ACTORDELETE spkt = new SMSG_ACTORDELETE();
                            spkt.ActorID   = regionObject.id;
                            spkt.SessionId = character.id;
                            character.client.Send((byte[])spkt);
                        }
                        catch (SocketException)
                        {
                            break;
                        }
                        catch (Exception e)
                        {
                            Trace.TraceWarning(e.ToString());
                        }
                    }
                }

                foreach (MapObject regionObject in list)
                {
                    try
                    {
                        regionObject.OnDeregister();
                    }
                    catch (Exception)
                    {
                        //Do nothing
                    }
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Removes all actors from a region tree
        /// </summary>
        public void RefreshActors()
        {
            WaitCallback callback = delegate(object state)
            {
                foreach (KeyValuePair <uint, Zone> pair in this.maps)
                {
                    Regiontree tree = pair.Value.Regiontree;
                    foreach (MapObject regionObject in tree.SearchActors(SearchFlags.Npcs))
                    {
                        BaseNPC npc = regionObject as BaseNPC;
                        if (npc != null)
                        {
                            npc.OnRefresh();
                        }
                    }
                }
            };

            ThreadPool.QueueUserWorkItem(callback);
        }
Esempio n. 30
0
        /// <summary>
        /// This function will initialize the trading.
        /// First it will check if the desired target is a existing target and fill it
        /// to your characer.target, by using is Character we check if the target is a valid
        /// Character or a other type of actor.
        ///
        /// If the selected character is a non-character or the target is yourself
        /// we'll send a reason of NO_TARGET. If the selected target already has a tradesession
        /// active we send a TRADE_ACTIVE. IF everything goes according to plans we'll not set
        /// a reason which equals sucess.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_TRADEINVITATION(CMSG_REQUESTTRADE cpkt)
        {
            if (Regiontree.TryFind(cpkt.TargetActor, this.character, out this.character._target))
            {
                if (character.Target is Character)
                {
                    Character Target = this.character.Target as Character;
                    if (Target.TradeSession != null)
                    {
                        //CHARACTER CAN'T TRADE, HE IS ALREADY IN A TRADE
                        SMSG_TRADERESULT spkt = new SMSG_TRADERESULT();
                        spkt.ActorId   = cpkt.TargetActor;
                        spkt.SessionId = this.character.id;
                        spkt.Reason    = (byte)TradeResult.TargetAlreadyInTrade;
                        this.Send((byte[])spkt);
                    }
                    else
                    {
                        //TRADE SESSION ESTABLISHED
                        TradeSession tradesession = new TradeSession(this.character, Target);
                        Target.TradeSession         = tradesession;
                        this.character.TradeSession = tradesession;

                        //TRADE INVITATION WAIT FOR CONFIRMATION
                        SMSG_TRADEINVITATION spkt = new SMSG_TRADEINVITATION();
                        spkt.SessionId = Target.id;
                        spkt.ActorId   = this.character.id;
                        Target.client.Send((byte[])spkt);
                    }
                }
                else
                {
                    //SELECTED TARGET WAS NOT FOUND
                    SMSG_TRADERESULT spkt = new SMSG_TRADERESULT();
                    spkt.ActorId   = cpkt.TargetActor;
                    spkt.SessionId = this.character.id;
                    spkt.Reason    = (byte)TradeResult.TargetNotFound;
                    this.Send((byte[])spkt);
                }
            }
        }