示例#1
0
 public void OnActorAppears(Actor aActor)
 {
     if (Client == null) return;
     switch (aActor.type)
     {
         case ActorType.PC:
             Packets.Server.SSMG_ACTOR_PC_APPEAR p = new SagaMap.Packets.Server.SSMG_ACTOR_PC_APPEAR();
             ActorPC pc = (ActorPC)aActor;
             p.ActorID = pc.ActorID;
             p.Dir = (byte)(pc.Dir / 45);
             p.HP = pc.HP;
             p.MaxHP = pc.MaxHP;
             p.PossessionActorID = 0xFFFFFFFF;
             p.PossessionPosition = PossessionPosition.NONE;
             p.Speed = pc.Speed;
             p.X = Global.PosX16to8(pc.X);
             p.Y = Global.PosY16to8(pc.Y);
             this.Client.netIO.SendPacket(p);
             break;
         case ActorType.ITEM:
             Packets.Server.SSMG_ITEM_ACTOR_APPEAR p1 = new SagaMap.Packets.Server.SSMG_ITEM_ACTOR_APPEAR();
             p1.Item = (ActorItem)aActor;
             this.Client.netIO.SendPacket(p1);
             break;
         default:
             break;
     }
 }
示例#2
0
 public void OnActorChangeEmotion(Actor aActor, MapEventArgs args)
 {
     ChatArg arg = (ChatArg)args;
     Packets.Server.SSMG_CHAT_EMOTION p = new SagaMap.Packets.Server.SSMG_CHAT_EMOTION();
     p.ActorID = aActor.ActorID;
     p.Emotion = arg.emotion;
     this.Client.netIO.SendPacket(p);
 }
示例#3
0
 public void OnActorChat(Actor cActor, MapEventArgs args)
 {
 }
示例#4
0
文件: Map.cs 项目: yasuhiro91/SagaECO
 private void SendActorToActor(Actor mActor, Actor tActor)
 {
     if (mActor.MapID == tActor.MapID)
         this.TeleportActor(mActor, tActor.X, tActor.Y);
     else
         this.SendActorToMap(mActor, tActor.MapID, tActor.X, tActor.Y);
 }
示例#5
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void SendVisibleActorsToActor(Actor jActor)
        {
            //search all actors which can be seen by jActor and tell jActor about them
            for (short deltaY = -1; deltaY <= 1; deltaY++)
            {
                for (short deltaX = -1; deltaX <= 1; deltaX++)
                {
                    uint region = (uint)(jActor.region + (deltaX * 1000000) + deltaY);
                    if (!this.actorsByRegion.ContainsKey(region)) continue;

                    foreach (Actor actor in this.actorsByRegion[region])
                    {
                        if (actor.ActorID == jActor.ActorID) continue;

                        //check wheter jActor can see actor, if yes: inform jActor
                        if (this.ACanSeeB(jActor, actor))
                        {
                            jActor.e.OnActorAppears(actor);
                        }

                    }
                }
            }
        }
示例#6
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void SendEventToAllActors(TOALL_EVENT_TYPE etype, MapEventArgs args, Actor sActor, bool sendToSourceActor)
        {
            foreach (Actor actor in this.actorsByID.Values)
            {
                if(sActor != null) if (!sendToSourceActor && (actor.ActorID == sActor.ActorID)) continue;

                switch (etype)
                {
                    case TOALL_EVENT_TYPE.CHAT:
                        actor.e.OnActorChat(sActor, args);
                        break;
                    default:
                        break;
                }
            }
        }
示例#7
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void SendActorToMap(Actor mActor, Map newMap, short x, short y)
        {
            // todo: add support for multiple map servers

            // obtain the new map
            byte mapid = (byte)newMap.id;
            if (mapid == mActor.MapID)
            {
                TeleportActor(mActor, x, y);
                return;
            }

            // delete the actor from this map
            this.DeleteActor(mActor);

            // update the actor
            mActor.MapID = mapid;
            mActor.X = x;
            mActor.Y = y;

            // register the actor in the new map
            if (mActor.type != ActorType.PC)
            {
                newMap.RegisterActor(mActor);
            }
            else
            {
                newMap.RegisterActor(mActor, mActor.ActorID);
            }
        }
示例#8
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public bool RegisterActor(Actor nActor)
        {
            // default: no success
            bool succes = false;

            // set the actorID and the actor's region on this map
            uint newID = this.GetNewActorID(nActor.type);

            if (nActor.type == ActorType.ITEM)
            {
                ActorItem item = (ActorItem)nActor;
                if (item.PossessionItem)
                    newID += ID_BORDER2;
            }

            if (newID != 0)
            {
                nActor.ActorID = newID;
                nActor.region = this.GetRegion(nActor.X, nActor.Y);

                // make the actor invisible (when the actor is ready: set it to false & call OnActorVisibilityChange)
                nActor.invisble = true;

                // add the new actor to the tables
                this.actorsByID.Add(nActor.ActorID, nActor);

                if (nActor.type == ActorType.PC && !this.pcByName.ContainsKey(nActor.Name))
                    this.pcByName.Add(nActor.Name, (ActorPC)nActor);

                if (!this.actorsByRegion.ContainsKey(nActor.region))
                    this.actorsByRegion.Add(nActor.region, new List<Actor>());

                this.actorsByRegion[nActor.region].Add(nActor);

                succes = true;
            }

            nActor.e.OnCreate(succes);
            return succes;
        }
示例#9
0
文件: Map.cs 项目: yasuhiro91/SagaECO
 public bool MoveStepIsInRange(Actor mActor, short[] to)
 {
     /* Disabled, until we have something better
     if (System.Math.Abs(mActor.x - to[0]) > mActor.maxMoveRange) return false;
     if (System.Math.Abs(mActor.y - to[1]) > mActor.maxMoveRange) return false;
     //we don't check for z , yet, to allow falling from great hight
     //if (System.Math.Abs(mActor.z - to[2]) > mActor.maxMoveRange) return false;
     */
      return true;
 }
示例#10
0
 public void OnActorStartsMoving(Actor mActor, short[] pos, ushort dir, ushort speed)
 {
     Packets.Server.SSMG_ACTOR_MOVE p = new SagaMap.Packets.Server.SSMG_ACTOR_MOVE();
     p.ActorID = mActor.ActorID;
     p.X = pos[0];
     p.Y = pos[1];
     p.Dir = dir;
     p.MoveType = MoveType.RUN;
     this.Client.netIO.SendPacket(p);
 }
示例#11
0
 public void OnActorStopsMoving(Actor mActor, short[] pos, ushort dir, ushort speed)
 {
     throw new NotImplementedException();
 }
示例#12
0
 public void OnActorSkillUse(Actor sActor, MapEventArgs args)
 {
     throw new NotImplementedException();
 }
示例#13
0
 public void OnActorStartsMoving(Actor mActor, short[] pos, ushort dir, ushort speed)
 {
 }
示例#14
0
 public void OnActorDisappears(Actor dActor)
 {
 }
示例#15
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public short[] GetRandomPosAroundActor(Actor actor)
        {
            short[] ret = new short[2];

            ret[0] = (short)Global.Random.Next(actor.X - 100, actor.X + 100);
            ret[1] = (short)Global.Random.Next(actor.Y - 100, actor.Y + 100);

            return ret;
        }
示例#16
0
 public void OnActorChangeEquip(Actor sActor, MapEventArgs args)
 {
     throw new NotImplementedException();
 }
示例#17
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        // make sure only 1 thread at a time is executing this method
        public void MoveActor(MOVE_TYPE mType, Actor mActor, short[] pos, ushort dir, ushort speed)
        {
            try
            {
                // check wheter the destination is in range, if not kick the client
                if (!this.MoveStepIsInRange(mActor, pos))
                {
                    Logger.ShowError("MoveStep is not in range", null);
                    mActor.e.OnKick();
                    return;
                }

                //scroll through all actors that "could" see the mActor at "from"
                //or are going "to see" mActor, or are still seeing mActor
                for (short deltaY = -1; deltaY <= 1; deltaY++)
                {
                    for (short deltaX = -1; deltaX <= 1; deltaX++)
                    {
                        uint region = (uint)(mActor.region + (deltaX * 1000000) + deltaY);
                        if (!this.actorsByRegion.ContainsKey(region)) continue;

                        foreach (Actor actor in this.actorsByRegion[region])
                        {
                            if (actor.ActorID == mActor.ActorID) continue;

                            // A) INFORM OTHER ACTORS

                            //actor "could" see mActor at its "from" position
                            if (this.ACanSeeB(actor, mActor))
                            {
                                //actor will still be able to see mActor
                                if (this.ACanSeeB(actor, mActor, pos[0], pos[1]))
                                {
                                    if (mType == MOVE_TYPE.START)
                                        actor.e.OnActorStartsMoving(mActor, pos, dir, speed);
                                    else
                                        actor.e.OnActorStopsMoving(mActor, pos, dir, speed);
                                }
                                //actor won't be able to see mActor anymore
                                else actor.e.OnActorDisappears(mActor);
                            }
                            //actor "could not" see mActor, but will be able to see him now
                            else if (this.ACanSeeB(actor, mActor, pos[0], pos[1]))
                            {
                                actor.e.OnActorAppears(mActor);

                                //send move / move stop
                                if (mType == MOVE_TYPE.START)
                                    actor.e.OnActorStartsMoving(mActor, pos, dir, speed);
                                else
                                    actor.e.OnActorStopsMoving(mActor, pos, dir, speed);
                            }

                            // B) INFORM mActor
                            //mActor "could" see actor on its "from" position
                            if (this.ACanSeeB(mActor, actor))
                            {
                                //mActor won't be able to see actor anymore
                                if (!this.ACanSeeB(mActor, pos[0], pos[1], actor))
                                    mActor.e.OnActorDisappears(actor);
                                //mAactor will still be able to see actor
                                else { }
                            }

                            else if (this.ACanSeeB(mActor, pos[0], pos[1], actor))
                            {
                                //mActor "could not" see actor, but will be able to see him now
                                //send pcinfo
                                mActor.e.OnActorAppears(actor);
                            }
                        }
                    }
                }

                //update x/y/z/yaw of the actor
                mActor.X = pos[0];
                mActor.Y = pos[1];
                mActor.Dir = dir;

                //update the region of the actor
                uint newRegion = this.GetRegion(pos[0], pos[1]);
                if (mActor.region != newRegion)
                {
                    this.actorsByRegion[mActor.region].Remove(mActor);
                    //turn off all the ai if the old region has no player on it
                    if (GetRegionPlayerCount(mActor.region) == 0 && mActor.type == ActorType.PC)
                    {
                        MobAIToggle(mActor.region, false);
                    }
                    mActor.region = newRegion;
                    if (GetRegionPlayerCount(mActor.region) == 0 && mActor.type == ActorType.PC)
                    {
                        MobAIToggle(mActor.region, true);
                    }

                    if (!this.actorsByRegion.ContainsKey(newRegion))
                        this.actorsByRegion.Add(newRegion, new List<Actor>());

                    this.actorsByRegion[newRegion].Add(mActor);
                }
            }
            catch(Exception)
            { }
        }
示例#18
0
 public void OnActorChat(Actor cActor, MapEventArgs args)
 {
     if (Client == null) return;
     Packets.Server.SSMG_CHAT_PUBLIC p = new SagaMap.Packets.Server.SSMG_CHAT_PUBLIC();
     p.ActorID = cActor.ActorID;
     p.Message = ((ChatArg)args).content;
     this.Client.netIO.SendPacket(p);
 }
示例#19
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void OnActorVisibilityChange(Actor dActor)
        {
            if (dActor.invisble)
                this.SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE.DISAPPEAR, null, dActor, false);

            else
                this.SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE.APPEAR, null, dActor, false);
        }
示例#20
0
 public void OnActorDisappears(Actor dActor)
 {
     switch (dActor.type)
     {
         case ActorType.PC:
             Packets.Server.SSMG_ACTOR_DELETE p = new SagaMap.Packets.Server.SSMG_ACTOR_DELETE();
             p.ActorID = dActor.ActorID;
             this.Client.netIO.SendPacket(p);
             break;
         case ActorType.ITEM:
             Packets.Server.SSMG_ITEM_ACTOR_DISAPPEAR p1 = new SagaMap.Packets.Server.SSMG_ITEM_ACTOR_DISAPPEAR();
             ActorItem item = (ActorItem)dActor;
             p1.ActorID = item.ActorID;
             p1.Count = item.Item.stack;
             p1.Looter = item.LootedBy;
             this.Client.netIO.SendPacket(p1);
             break;
     }
 }
示例#21
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public bool RegisterActor(Actor nActor,uint SessionID)
        {
            // default: no success
            bool succes = false;

            // set the actorID and the actor's region on this map
            uint newID = SessionID;

            if (newID != 0)
            {
                nActor.ActorID = newID;
                nActor.region = this.GetRegion(nActor.X, nActor.Y);
                if (GetRegionPlayerCount(nActor.region) == 0 && nActor.type == ActorType.PC)
                {
                    MobAIToggle(nActor.region, true);
                }

                // make the actor invisible (when the actor is ready: set it to false & call OnActorVisibilityChange)
                nActor.invisble = true;

                // add the new actor to the tables
                if (!this.actorsByID.ContainsKey(nActor.ActorID)) this.actorsByID.Add(nActor.ActorID, nActor);

                if (nActor.type == ActorType.PC && !this.pcByName.ContainsKey(nActor.Name))
                    this.pcByName.Add(nActor.Name, (ActorPC)nActor);

                if (!this.actorsByRegion.ContainsKey(nActor.region))
                    this.actorsByRegion.Add(nActor.region, new List<Actor>());

                this.actorsByRegion[nActor.region].Add(nActor);

                succes = true;
            }

            nActor.e.OnCreate(succes);
            return succes;
        }
示例#22
0
文件: Map.cs 项目: yasuhiro91/SagaECO
 public bool ACanSeeB(Actor A, Actor B, float bx, float by)
 {
     if (B.invisble) return false;
     if (System.Math.Abs(A.X - bx) > A.sightRange) return false;
     if (System.Math.Abs(A.Y - by) > A.sightRange) return false;
     return true;
 }
示例#23
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void SendActorToMap(Actor mActor, uint mapid, short x, short y)
        {
            // todo: add support for multiple map servers

            // obtain the new map
            Map newMap;
            if (mapid == mActor.MapID)
            {
                TeleportActor(mActor, x, y);
                return;
            }
            newMap = MapManager.Instance.GetMap(mapid);
            if (newMap == null)
                return;
            // delete the actor from this map
            this.DeleteActor(mActor);
            if (x == 0f && y == 0f)
            {
                short[] pos = newMap.GetRandomPos();
                x = pos[0];
                y = pos[1];
            }
            // update the actor
            mActor.MapID = mapid;
            mActor.X = x;
            mActor.Y = y;

            // register the actor in the new map
            if (mActor.type != ActorType.PC)
            {
                newMap.RegisterActor(mActor);
            }
            else
            {
                newMap.RegisterActor(mActor,mActor.ActorID);
            }
        }
示例#24
0
文件: Map.cs 项目: yasuhiro91/SagaECO
 public bool ACanSeeB(Actor A, float ax, float ay, Actor B)
 {
     if (B.invisble) return false;
     if (System.Math.Abs(ax - B.X) > A.sightRange) return false;
     if (System.Math.Abs(ay - B.Y) > A.sightRange) return false;
     return true;
 }
示例#25
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE etype, MapEventArgs args, Actor sActor, bool sendToSourceActor)
        {
            try
            {
                for (short deltaY = -1; deltaY <= 1; deltaY++)
                {
                    for (short deltaX = -1; deltaX <= 1; deltaX++)
                    {
                        uint region = (uint)(sActor.region + (deltaX * 1000000) + deltaY);
                        if (!this.actorsByRegion.ContainsKey(region)) continue;

                        foreach (Actor actor in this.actorsByRegion[region])
                        {
                            try
                            {
                                if (!sendToSourceActor && (actor.ActorID == sActor.ActorID)) continue;

                                if (this.ACanSeeB(actor, sActor))
                                {
                                    switch (etype)
                                    {
                                        case EVENT_TYPE.APPEAR:
                                            actor.e.OnActorAppears(sActor);
                                            break;

                                        case EVENT_TYPE.DISAPPEAR:
                                            actor.e.OnActorDisappears(sActor);
                                            break;

                                        case EVENT_TYPE.EMOTION:
                                            actor.e.OnActorChangeEmotion(sActor, args);
                                            break;

                                        case EVENT_TYPE.MOTION:
                                            actor.e.OnActorChangeMotion(sActor, args);
                                            break;

                                        case EVENT_TYPE.CHAT:
                                            actor.e.OnActorChat(sActor, args);
                                            break;

                                        case EVENT_TYPE.SKILL:
                                            actor.e.OnActorSkillUse(sActor, args);
                                            break;

                                        case EVENT_TYPE.CHANGE_EQUIP:
                                            actor.e.OnActorChangeEquip(sActor, args);
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.ShowError(ex);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex);
            }
        }
示例#26
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void DeleteActor(Actor dActor)
        {
            this.SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE.DISAPPEAR, null, dActor, false);

            if (dActor.type == ActorType.PC && this.pcByName.ContainsKey(dActor.Name))
                this.pcByName.Remove(dActor.Name);

            this.actorsByID.Remove(dActor.ActorID);

            if (this.actorsByRegion.ContainsKey(dActor.region))
            {
                this.actorsByRegion[dActor.region].Remove(dActor);
                if (GetRegionPlayerCount(dActor.region) == 0 && dActor.type == ActorType.PC)
                {
                    MobAIToggle(dActor.region, false);
                }
            }

            dActor.e.OnDelete();
        }
示例#27
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public void TeleportActor(Actor sActor, short x, short y)
        {
            this.SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE.DISAPPEAR, null, sActor, false);

            this.actorsByRegion[sActor.region].Remove(sActor);
            if (GetRegionPlayerCount(sActor.region) == 0 && sActor.type == ActorType.PC)
            {
                MobAIToggle(sActor.region, false);
            }

            sActor.X = x;
            sActor.Y = y;
            sActor.region = this.GetRegion(x, y);
            if (GetRegionPlayerCount(sActor.region) == 0 && sActor.type == ActorType.PC)
            {
                MobAIToggle(sActor.region, true);
            }

            if (!this.actorsByRegion.ContainsKey(sActor.region)) this.actorsByRegion.Add(sActor.region, new List<Actor>());
            this.actorsByRegion[sActor.region].Add(sActor);

            sActor.e.OnTeleport(x, y);

            this.SendEventToAllActorsWhoCanSeeActor(EVENT_TYPE.APPEAR, null, sActor, false);
            this.SendVisibleActorsToActor(sActor);
        }
示例#28
0
文件: Map.cs 项目: yasuhiro91/SagaECO
        public List<Actor> GetActorsArea(Actor sActor, float range, bool includeSourceActor)
        {
            List<Actor> actors = new List<Actor>();
            for (short deltaY = -1; deltaY <= 1; deltaY++)
            {
                for (short deltaX = -1; deltaX <= 1; deltaX++)
                {
                    uint region = (uint)(this.GetRegion(sActor.X, sActor.Y) + (deltaX * 1000000) + deltaY);
                    if (!this.actorsByRegion.ContainsKey(region)) continue;

                    foreach (Actor actor in this.actorsByRegion[region])
                    {
                        if (!includeSourceActor && (actor.ActorID == sActor.ActorID)) continue;

                        if (this.ACanSeeB(actor, sActor, range))
                        {
                            actors.Add(actor);
                        }
                    }
                }
            }
            return actors;
        }
示例#29
0
文件: Map.cs 项目: yasuhiro91/SagaECO
 public bool ACanSeeB(Actor A, Actor B)
 {
     if (B.invisble) return false;
     if (System.Math.Abs(A.X - B.X) > A.sightRange) return false;
     if (System.Math.Abs(A.Y - B.Y) > A.sightRange) return false;
     return true;
 }
示例#30
0
 public void OnActorChangeMotion(Actor aActor, MapEventArgs args)
 {
 }