Пример #1
0
        /// <summary>
        /// Occurs when the party invitation gets accepted
        /// </summary>
        private void CM_PARTYINVITATIONACCEPT(CMSG_PARTYINVITATIONACCEPT cpkt)
        {
            //FORWARD A OKAY MESSAGE TO THE SENDER AND RECIEVER OF THE INIVATION
            PartySession party = this.character.sessionParty;

            if (party != null)
            {
                if (cpkt.Status == 1)
                {
                    //Has accepted the party invitation
                    {
                        SMSG_PARTYINVITATIONRESULT spkt = new SMSG_PARTYINVITATIONRESULT();
                        spkt.Result    = 0;
                        spkt.SessionId = party.PartyLeader.id;
                        party.PartyLeader.client.Send((byte[])spkt);
                    }
                    //Send over a new party
                    if (this.character.sessionParty.Count == 1)
                    {
                        SMSG_PARTYMEMBERINFO spkt = new SMSG_PARTYMEMBERINFO();
                        spkt.Leader      = party.PartyLeader.id;
                        spkt.LeaderIndex = 1;
                        spkt.Setting1    = this.character.sessionParty.LootSettings;
                        spkt.Setting2    = this.character.sessionParty.ExpSettings;
                        spkt.Setting3    = 0;
                        if (this.character.sessionParty.ItemLeader != null)
                        {
                            spkt.Setting4 = this.character.sessionParty.ItemLeader.id;
                        }
                        spkt.AddMemberInfo(party.GetCharacters());
                        spkt.SessionId = party.PartyLeader.id;
                        spkt.Result    = 1;
                        party.PartyLeader.client.Send((byte[])spkt);
                    }

                    //Forwards new party member information to all existing players
                    this.character.sessionParty.Add(this.character);
                    int index = party.IndexOf(this.character) + 1;


                    //Process character adding
                    foreach (Character target in party.GetCharacters())
                    {
                        //Send a new character to other party members
                        if (target.id != character.id)
                        {
                            SMSG_PARTYNEWMEMBER spkt2 = new SMSG_PARTYNEWMEMBER();
                            spkt2.Index     = 1;
                            spkt2.ActorId   = this.character.id;
                            spkt2.Unknown   = 1;
                            spkt2.Name      = this.character.Name;
                            spkt2.SessionId = target.id;
                            target.client.Send((byte[])spkt2);
                        }
                        //Send a complete list to yourself
                        else
                        {
                            SMSG_PARTYMEMBERINFO spkt7 = new SMSG_PARTYMEMBERINFO();
                            spkt7.Leader      = party.PartyLeader.id;
                            spkt7.LeaderIndex = 1;
                            spkt7.Setting1    = this.character.sessionParty.LootSettings;
                            spkt7.Setting2    = this.character.sessionParty.ExpSettings;
                            spkt7.Setting3    = 0;
                            if (this.character.sessionParty.ItemLeader != null)
                            {
                                spkt7.Setting4 = this.character.sessionParty.ItemLeader.id;
                            }
                            spkt7.Result    = 1;
                            spkt7.SessionId = this.character.id;
                            spkt7.AddMemberInfo(party.GetCharacters());
                            this.Send((byte[])spkt7);
                        }
                    }



                    //Forwards new party member location and HP/SP
                    //informations
                    foreach (Character target in party.GetCharacters())
                    {
                        if (target.id == character.id)
                        {
                            continue;
                        }

                        //Send over target to myself
                        SMSG_PARTYUNKNOWN spkt4 = new SMSG_PARTYUNKNOWN();
                        spkt4.ActorID   = target.id;
                        spkt4.Unsure    = 1;
                        spkt4.Unknown   = (byte)(this.character.map + 0x65);
                        spkt4.Race      = 0;
                        spkt4.Map       = target.map;
                        spkt4.HP        = target.HP;
                        spkt4.HPmax     = target.HPMAX;
                        spkt4.SP        = target.SP;
                        spkt4.SPmax     = target.SPMAX;
                        spkt4.LP        = target._status.CurrentLp;
                        spkt4.CharLvl   = target._level;
                        spkt4.Job       = target.job;
                        spkt4.JobLvl    = target.jlvl;
                        spkt4.SessionId = this.character.id;
                        this.Send((byte[])spkt4);

                        //Send my self to target
                        SMSG_PARTYUNKNOWN spkt3 = new SMSG_PARTYUNKNOWN();
                        spkt3.ActorID   = this.character.id;
                        spkt3.Unsure    = 1;
                        spkt3.Unknown   = (byte)(this.character.map + 0x65);
                        spkt3.Race      = 0;
                        spkt3.Map       = this.character.map;
                        spkt3.HP        = this.character.HP;
                        spkt3.HPmax     = this.character.HPMAX;
                        spkt3.SP        = this.character.SP;
                        spkt3.SPmax     = this.character.SPMAX;
                        spkt3.LP        = this.character._status.CurrentLp;
                        spkt3.CharLvl   = this.character._level;
                        spkt3.Job       = this.character.job;
                        spkt3.JobLvl    = this.character.jlvl;
                        spkt3.SessionId = target.id;
                        target.client.Send((byte[])spkt3);


                        //Process positon update
                        if (target.map == this.character.map)
                        {
                            SMSG_PARTYMEMBERLOCATION spkt6 = new SMSG_PARTYMEMBERLOCATION();
                            spkt6.Index     = 1;
                            spkt6.ActorId   = target.id;
                            spkt6.X         = target.Position.x;
                            spkt6.Y         = target.Position.y;
                            spkt6.SessionId = this.character.id;
                            this.Send((byte[])spkt6);


                            SMSG_PARTYMEMBERLOCATION spkt5 = new SMSG_PARTYMEMBERLOCATION();
                            spkt5.Index     = 1;
                            spkt5.ActorId   = this.character.id;
                            spkt5.X         = this.character.Position.x;
                            spkt5.Y         = this.character.Position.y;
                            spkt5.SessionId = target.id;
                            target.client.Send((byte[])spkt5);
                        }
                    }
                }
                else
                {
                    Character PartyLeader           = this.character.sessionParty.PartyLeader;
                    SMSG_PARTYINVITATIONRESULT spkt = new SMSG_PARTYINVITATIONRESULT();
                    spkt.Result    = (byte)PartyErrors.DENIED;
                    spkt.SessionId = PartyLeader.id;
                    PartyLeader.client.Send((byte[])spkt);

                    try
                    {
                        uint      TargetActorId = (uint)this.character.Tag;
                        Character TargetActor   = null;
                        if (LifeCycle.TryGetById(TargetActorId, out TargetActor))
                        {
                            TargetActor.Tag = null;
                            if (TargetActor.sessionParty._Characters.Count <= 1)
                            {
                                TargetActor.sessionParty = null;
                            }
                        }
                    }
                    catch (InvalidCastException)
                    {
                        Trace.TraceWarning("Cannot retrieve actor information");
                    }

                    if (this.character.sessionParty.Count <= 1)
                    {
                        this.character.sessionParty = null;
                    }
                    this.character.Tag = null;
                }
            }
            //FORWARD A DENIAL MESSAGE TO THE RECIEVER OF THE INVITATION
            else
            {
                SMSG_PARTYINVITATIONRESULT spkt = new SMSG_PARTYINVITATIONRESULT();
                spkt.Result    = (byte)PartyErrors.DENIED;
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);
                this.character.sessionParty = null;
            }
        }
Пример #2
0
    public static bool Warp(Character target, Point destination, Zone NewZoneInstance)
    {
        if (target.client.isloaded == true)
        {
            if (target.map > 0 && NewZoneInstance.Map > 0)
            {
                if (target.map != NewZoneInstance.Map)
                {
                    #region Not the same Zone

                    if (target.currentzone.Type != ZoneType.Dungeon)
                    {
                        WorldCoordinate worldcoord;
                        worldcoord.coords   = target.Position;
                        worldcoord.map      = target.currentzone.Map;
                        target.lastlocation = worldcoord;
                    }

                    //Start loading
                    target.client.isloaded = false;
                    Zone currentZone = target.currentzone;
                    target.currentzone.OnLeave(target);

                    lock (target)
                    {
                        //Unregister
                        currentZone.Regiontree.Unsubscribe(target);

                        //Set position to the new location
                        target.map = NewZoneInstance.Map;

                        //Set new position
                        target.Position = new Point(
                            destination.x,
                            destination.y,
                            destination.z
                            );
                    }

                    //Update party members
                    if (target.sessionParty != null)
                    {
                        foreach (Character partyTarget in target.sessionParty)
                        {
                            //switch the map
                            SMSG_PARTYMEMBERMAPCHANGE spkt4 = new SMSG_PARTYMEMBERMAPCHANGE();
                            spkt4.Index     = 1;
                            spkt4.ActorId   = target.id;
                            spkt4.Unknown   = (byte)(target.map + 0x065);
                            spkt4.Zone      = target.map;
                            spkt4.SessionId = partyTarget.id;
                            partyTarget.client.Send((byte[])spkt4);
                        }
                    }

                    //Set zone instance
                    target.currentzone = NewZoneInstance;

                    //Send over load packet
                    SMSG_SENDSTART spkt = new SMSG_SENDSTART();
                    spkt.SessionId = target.id;
                    spkt.X         = destination.x;
                    spkt.Y         = destination.y;
                    spkt.Z         = destination.z;
                    spkt.MapId     = NewZoneInstance.Map;
                    spkt.Unknown   = (byte)(target.map + 0x65);
                    spkt.Channel   = 1;
                    target.client.Send((byte[])spkt);
                    return(true);

                    #endregion Not the same Zone
                }
                else
                {
                    #region Notify People That Actor Disapears

                    Point origin = target.Position;

                    Regiontree tree;
                    tree = target.currentzone.Regiontree;
                    foreach (MapObject c in tree.SearchActors(target, SearchFlags.DynamicObjects))
                    {
                        bool insightrangeold = Point.IsInSightRangeByRadius(origin, c.Position);
                        bool insightrangenew = Point.IsInSightRangeByRadius(destination, c.Position);
                        if (c.id == target.id)
                        {
                            continue;
                        }

                        //If vible from old postion but not from new position hide
                        if (insightrangeold && !insightrangenew)
                        {
                            double distance = Point.GetDistance3D(destination, c.Position);
                            //CROSS NOTIFY PLAYERS ACTORS DISAPPPEARS
                            if (MapObject.IsPlayer(c))
                            {
                                Character targetChar = c as Character;
                                targetChar.HideObject(target);
                            }

                            c.HideObject(target);
                            c.Disappear(target);
                        }
                    }

                    #endregion Notify People That Actor Disapears

                    #region Update Region

                    target.Position = new Point(destination.x, destination.y, destination.z);
                    Regiontree.UpdateRegion(target);

                    #endregion Update Region

                    #region Teleport

                    SMSG_ACTORTELEPORT spkt = new SMSG_ACTORTELEPORT();
                    spkt.SessionId = target.id;
                    spkt.x         = destination.x;
                    spkt.y         = destination.y;
                    spkt.Z         = destination.z;
                    target.client.Send((byte[])spkt);

                    #endregion Teleport

                    #region Reset State

                    target.ISONBATTLE = false;
                    target.stance     = (byte)StancePosition.Reborn;
                    target._targetid  = 0;

                    SMSG_ACTORCHANGESTATE spkt4 = new SMSG_ACTORCHANGESTATE();
                    spkt4.SessionId   = target.id;
                    spkt4.Stance      = target.stance;
                    spkt4.TargetActor = target._targetid;
                    spkt4.State       = (target.ISONBATTLE == true) ? (byte)1 : (byte)0;
                    spkt4.ActorID     = target.id;
                    target.client.Send((byte[])spkt4);

                    #endregion Reset State

                    #region Notify People That the Actor Appears

                    tree = target.currentzone.Regiontree;
                    foreach (MapObject myObject in tree.SearchActors(target, SearchFlags.DynamicObjects))
                    {
                        bool insightrangeold = Point.IsInSightRangeByRadius(origin, myObject.Position);
                        bool insightrangenew = Point.IsInSightRangeByRadius(destination, myObject.Position);

                        double distance = Point.GetDistance3D(destination, myObject.Position);

                        //If visible from new postion but not from old postion
                        if (insightrangenew && !insightrangeold)
                        {
                            myObject.ShowObject(target);
                            myObject.Appears(target);

                            if (MapObject.IsPlayer(myObject))
                            {
                                Character current = (Character)myObject;
                                if (current.client.isloaded == false)
                                {
                                    continue;
                                }
                                target.ShowObject(current);
                            }
                        }
                    }

                    #endregion Notify People That the Actor Appears

                    #region Notify Party Members

                    if (target.sessionParty != null)
                    {
                        foreach (Character partyTarget in target.sessionParty)
                        {
                            if (partyTarget.id == target.id)
                            {
                                continue;
                            }
                            SMSG_PARTYMEMBERLOCATION spkt3 = new SMSG_PARTYMEMBERLOCATION();
                            spkt3.Index     = 1;
                            spkt3.ActorId   = target.id;
                            spkt3.SessionId = partyTarget.id;
                            spkt3.X         = (destination.x / 1000);
                            spkt3.Y         = (destination.y / 1000);
                            partyTarget.client.Send((byte[])spkt3);
                        }
                    }

                    #endregion Notify Party Members

                    return(true);
                }
            }
            else
            {
                Trace.TraceError("Warping player {0} to unsupported map {1}", target.Name, 0);
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }