示例#1
0
        public static void Start(List <RoomEntity> users)
        {
            users.ForEach(usr =>
            {
                if (!usr.Disposing)
                {
                    if (usr.TargetPosition != null && usr.Path != null && usr.Path.Count > 0)
                    {
                        if (usr.Actions.Has("mv"))
                        {
                            usr.Actions.Remove("mv");
                        }
                        if (usr.Actions.Has("sit"))
                        {
                            usr.Actions.Remove("sit");
                        }
                        if (usr.Actions.Has("lay"))
                        {
                            usr.Actions.Remove("lay");
                        }

                        RoomTile oldTile = usr.Room.Mapping.Tiles[usr.Position.X, usr.Position.Y];
                        oldTile.RemoveEntity(usr);

                        Point p       = usr.Path.First();
                        RoomTile tile = usr.Room.Mapping.Tiles[p.X, p.Y];
                        tile.AddEntity(usr);

                        double height = 0.0;

                        if (oldTile.TopItem != null)
                        {
                            // walk off
                            if (tile.TopItem == null || tile.TopItem != oldTile.TopItem)
                            {
                                oldTile.TopItem.GetInteractor().OnUserWalkOff(usr, usr.Room, oldTile.TopItem);
                            }
                        }

                        if (tile.TopItem != null)
                        {
                            // walk on
                            if (oldTile.TopItem == null || oldTile.TopItem != tile.TopItem)
                            {
                                tile.TopItem.GetInteractor().OnUserWalkOn(usr, usr.Room, tile.TopItem);
                            }

                            height += tile.TopItem.Position.Z;
                            if (!tile.TopItem.ItemData.CanSit && !tile.TopItem.ItemData.CanLay)
                            {
                                // todo: multiheight furni
                                height += tile.TopItem.ItemData.Height;
                            }
                        }
                        else
                        {
                            height += tile.Position.Z;
                        }

                        usr.Actions.Add("mv", p.X + "," + p.Y + "," + height);
                        usr.Position.Rotation     = usr.Room.PathFinder.Rotation(usr.Position.X, usr.Position.Y, p.X, p.Y);
                        usr.Position.HeadRotation = usr.Position.Rotation;
                        usr.Path.RemoveFirst();
                        usr.Room.EntityManager.Send(new RoomUserStatusComposer(usr));
                        usr.Position.X = p.X;
                        usr.Position.Y = p.Y;
                        usr.Position.Z = height;

                        if (usr.Path.Count() != 0)
                        {
                            usr.Path = usr.Room.PathFinder.Path(usr);
                        }
                    }
                    else
                    {
                        if (usr.TargetPosition.X == usr.Position.X && usr.TargetPosition.Y == usr.Position.Y)
                        {
                            bool update = false;
                            if (usr.Actions.Has("mv"))
                            {
                                usr.Actions.Remove("mv");
                                update = true;
                            }

                            RoomTile tile = usr.Room.Mapping.Tiles[usr.TargetPosition.X, usr.TargetPosition.Y];

                            if (tile.TopItem != null && tile.TopItem.ItemData.CanSit)
                            {
                                usr.Actions.Add("sit", tile.TopItem.ItemData.Height.ToString());
                                usr.Position.Rotation     = tile.TopItem.Position.Rotation;
                                usr.Position.HeadRotation = usr.Position.Rotation;
                                usr.Position.Z            = tile.TopItem.ItemData.Height + tile.TopItem.Position.Z;
                                usr.isSitting             = false;
                                update = true;
                            }
                            else if (tile.TopItem != null && tile.TopItem.ItemData.CanLay)
                            {
                                usr.Actions.Add("lay", tile.TopItem.ItemData.Height.ToString());
                                usr.Position.Rotation     = tile.TopItem.Position.Rotation;
                                usr.Position.HeadRotation = usr.Position.Rotation;
                                usr.Position.Z            = tile.TopItem.ItemData.Height + tile.TopItem.Position.Z;
                                usr.isSitting             = false;
                                update = true;
                            }
                            else
                            {
                                if (!usr.isSitting && usr.Actions.Has("sit"))
                                {
                                    usr.Actions.Remove("sit");
                                    usr.Position.Z = tile.Position.Z;
                                    update         = true;
                                }

                                if (usr.Actions.Has("lay"))
                                {
                                    usr.Actions.Remove("lay");
                                    usr.Position.Z = tile.Position.Z;
                                    update         = true;
                                }
                            }

                            if (update)
                            {
                                usr.Room.EntityManager.Send(new RoomUserStatusComposer(usr));
                            }

                            if (usr.Room.Model.Door.X == usr.Position.X && usr.Room.Model.Door.Y == usr.Position.Y)
                            {
                                usr.Room.EntityManager.OnUserLeave(usr);
                                usr.Player.Session.Send(new HotelViewComposer());
                            }
                        }
                    }
                }
            });
        }
示例#2
0
        public void WalkCycle()
        {
            try
            {
                if (this.TargetPosition != null && this.Path != null && this.Path.Count > 0)
                {
                    if (this.Actions.Has("mv"))
                    {
                        this.Actions.Remove("mv");
                    }
                    if (this.Actions.Has("sit"))
                    {
                        this.Actions.Remove("sit");
                    }
                    if (this.Actions.Has("lay"))
                    {
                        this.Actions.Remove("lay");
                    }

                    RoomTile oldTile = this.Room.Mapping.Tiles[this.Position.X, this.Position.Y];
                    oldTile.RemoveEntity(this);

                    Point    p    = this.Path.First();
                    RoomTile tile = this.Room.Mapping.Tiles[p.X, p.Y];
                    tile.AddEntity(this);

                    double height = 0.0;

                    if (oldTile.TopItem != null)
                    {
                        // walk off
                        if (tile.TopItem == null || tile.TopItem != oldTile.TopItem)
                        {
                            oldTile.TopItem.GetInteractor().OnUserWalkOff(this, this.Room, oldTile.TopItem);
                        }
                    }

                    if (tile.TopItem != null)
                    {
                        // walk on
                        if (oldTile.TopItem == null || oldTile.TopItem != tile.TopItem)
                        {
                            tile.TopItem.GetInteractor().OnUserWalkOn(this, this.Room, tile.TopItem);
                        }

                        height += tile.TopItem.Position.Z;
                        if (!tile.TopItem.ItemData.CanSit && !tile.TopItem.ItemData.CanLay)
                        {
                            // todo: multiheight furni
                            height += tile.TopItem.ItemData.Height;
                        }
                    }
                    else
                    {
                        height += tile.Position.Z;
                    }

                    this.Actions.Add("mv", p.X + "," + p.Y + "," + height);
                    this.Position.Rotation     = this.Room.PathFinder.Rotation(this.Position.X, this.Position.Y, p.X, p.Y);
                    this.Position.HeadRotation = this.Position.Rotation;
                    this.Path.RemoveFirst();
                    this.Room.EntityManager.Send(new RoomUserStatusComposer(this));
                    this.Position.X = p.X;
                    this.Position.Y = p.Y;
                    this.Position.Z = height;

                    if (this.Path.Count() != 0)
                    {
                        this.Path = this.Room.PathFinder.Path(this);
                    }
                }
                else
                {
                    bool update = false;
                    if (this.Actions.Has("mv"))
                    {
                        this.Actions.Remove("mv");
                        update = true;
                    }
                    RoomTile tile = this.Room.Mapping.Tiles[this.TargetPosition.X, this.TargetPosition.Y];

                    if (tile.TopItem != null && tile.TopItem.ItemData.CanSit)
                    {
                        this.Actions.Add("sit", tile.TopItem.ItemData.Height + 0.1 + "");
                        this.Position.Rotation     = tile.TopItem.Position.Rotation;
                        this.Position.HeadRotation = this.Position.Rotation;
                        this.Position.Z            = tile.TopItem.Position.Z;
                        this.isSitting             = false;
                        update = true;
                    }
                    else if (tile.TopItem != null && tile.TopItem.ItemData.CanLay)
                    {
                        this.Actions.Add("lay", tile.TopItem.ItemData.Height + 0.1 + "");
                        this.Position.Rotation     = tile.TopItem.Position.Rotation;
                        this.Position.HeadRotation = this.Position.Rotation;
                        this.Position.Z            = tile.TopItem.Position.Z;
                        this.isSitting             = false;
                        update = true;
                    }
                    else
                    {
                        if (!this.isSitting && this.Actions.Has("sit"))
                        {
                            this.Actions.Remove("sit");
                            this.Position.Z = tile.Position.Z;
                            update          = true;
                        }

                        if (this.Actions.Has("lay"))
                        {
                            this.Actions.Remove("lay");
                            this.Position.Z = tile.Position.Z;
                            update          = true;
                        }
                    }

                    if (update)
                    {
                        this.Room.EntityManager.Send(new RoomUserStatusComposer(this));
                    }

                    if ((this.Room.Model.Door.X == this.Position.X && this.Room.Model.Door.Y == this.Position.Y) &&
                        this.Type == RoomEntityType.Player)
                    {
                        //this.Player.Session.Send(new HotelViewComposer());
                        //this.Room.EntityManager.OnUserLeave(this);
                    }
                }
            }
            catch { }
        }