コード例 #1
0
ファイル: TCPServer.cs プロジェクト: ddabrahim/MagicalLife
 public void Send <T>(T data, Guid player)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.PlayerToSocket[player].Send(buffer);
 }
コード例 #2
0
ファイル: TCPServer.cs プロジェクト: ddabrahim/MagicalLife
 /// <summary>
 /// Broadcasts the message to a specific client.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void Send <T>(T data, Socket client)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     client.Send(buffer);
 }
コード例 #3
0
ファイル: HarvestTask.cs プロジェクト: philipbawn/MagicalLife
 public HarvestTask(Point2D target, Guid boundID)
     : base(GetDependencies(boundID, target), boundID, GetQualifications(), PriorityLayers.Default)
 {
     this.Target = target;
     MasterLog.DebugWriteLine("Target: " + this.Target.ToString());
     this.HitTimer = new TickTimer(30);
 }
コード例 #4
0
        /// <summary>
        /// Handles who gets the single click event from the options provided.
        /// For use if a container is being used.
        /// </summary>
        /// <param name="clickData"></param>
        private static void Click(MouseEventArgs clickData, List <GUIElement> Options, GUIContainer container)
        {
            int        focus  = -1;
            int        length = Options.Count;
            GUIElement item   = null;

            for (int i = 0; i < length; i++)
            {
                item = Options[i];
                if (focus == -1 && item.MouseBounds.Bounds.Contains(clickData.Position.X + container.DrawingBounds.X, clickData.Position.Y - container.DrawingBounds.Y))
                {
                    item.HasFocus = true;
                    focus         = i;
                }
                else
                {
                    item.HasFocus = false;
                }
            }

            if (focus != -1)
            {
                MasterLog.DebugWriteLine("Clicking on item: " + Options[focus].GetType().FullName);
                Options[focus].Click(clickData, container);
            }
        }
コード例 #5
0
 /// <summary>
 /// Assigns a task to the creature.
 /// </summary>
 /// <param name="l"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 private void AssignJob(Living l, MagicalTask task)
 {
     MasterLog.DebugWriteLine("Assigning job: " + task.ID.ToString() + " " + task.GetType().FullName);
     task.MakePreparations(l);
     l.AssignTask(task);
     task.ToilingWorker = l.ID;
 }
コード例 #6
0
ファイル: TCPClient.cs プロジェクト: ddabrahim/MagicalLife
 public void Send <T>(T message)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(message);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.Client.Write(buffer);
 }
コード例 #7
0
        /// <summary>
        /// Gets a task for the creature.
        /// This also reserves the task for the creature.
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public void AssignTask(Living l)
        {
            List <MagicalTask> allCompatibleTasks = new List <MagicalTask>();

            //Get all compatible jobs
            foreach (TaskDriver item in this.TaskDrivers)
            {
                allCompatibleTasks.AddRange(item.GetCompatibleJobs(l));
            }

            foreach (MagicalTask item in allCompatibleTasks)
            {
                //Has the job been reserved for the unemployed creature
                if (item.ReservedFor == l.ID)
                {
                    MasterLog.DebugWriteLine("Its been reserved for me: " + item.ID);
                    this.AssignJob(l, item);
                    return;
                }
            }

            if (allCompatibleTasks.Count > 0)
            {
                MagicalTask task = allCompatibleTasks[0];
                this.AssignJob(l, task);

                foreach (TaskDriver item in this.TaskDrivers)
                {
                    this.ReserveBoundTree(l, task.BoundID, item.Task);
                }
            }
        }
コード例 #8
0
        private void Server_ClientConnected(object sender, System.Net.Sockets.TcpClient e)
        {
            MasterLog.DebugWriteLine("Client connection received");

            //this.Send<ConcreteTest>(new ConcreteTest(), e.Client);
            this.Send <WorldTransferMessage>(new WorldTransferMessage(World.MainWorld), e.Client);
        }
コード例 #9
0
        /// <summary>
        /// Determines how much of the "text" can be rendered before it goes out of "bounds".
        /// </summary>
        /// <param name="font">The font the text will be rendered with.</param>
        /// <param name="text">The full text that is attempting to be rendered.</param>
        /// <param name="bounds">The bounds that the text may be drawed in.</param>
        /// <returns></returns>
        public static string GetDrawableText(SpriteFont font, string text, Rectangle bounds)
        {
            int lastPassing = -1;
            int length      = text.Length;

            for (int i = 0; i < length; i++)
            {
                Vector2 result = font.MeasureString(text.Substring(0, i + 1));

                if (result.X > 0 && result.X < bounds.Width)
                {
                    lastPassing = i;
                }
            }

            if (lastPassing == -1 && text != string.Empty)
            {
                if (lastPassing == -1)
                {
                    MasterLog.DebugWriteLine("lastPassing = -1");
                }
                throw new Exception("Cannot possibly draw string in allotted space.");
            }
            else
            {
                return(text.Substring(0, lastPassing + 1));
            }
        }
コード例 #10
0
        /// <summary>
        /// Returns the next message. Returns null if no message is ready.
        /// </summary>
        /// <returns></returns>
        public BaseMessage GetMessageData()
        {
            BaseMessage data = null;

            if (this.NextMessageLength != -1 && this.NextMessageLength <= this.Buffer.Count)
            {
                using (MemoryStream ms = new MemoryStream(this.Buffer.ToArray()))
                {
                    data = (BaseMessage)ProtoUtil.TypeModel.DeserializeWithLengthPrefix(ms, null, typeof(BaseMessage), PrefixStyle.Base128, 0);
                    this.Buffer.RemoveRange(0, Convert.ToInt32(ms.Position));

                    //Remove the trailing 0s from the last message

                    //The starting index of the next message
                    int start = this.Buffer.FindIndex(x => x != 0);

                    if (start == -1)
                    {
                        this.Buffer.Clear();
                    }
                    else
                    {
                        this.Buffer.RemoveRange(0, start);
                    }
                }

                MasterLog.DebugWriteLine("Message Buffer: " + this.Buffer.Count);
                this.CalculateNextMessageLength();
            }

            return(data);
        }
コード例 #11
0
ファイル: AStar.cs プロジェクト: Batarian711/MagicalLife
        public List <PathLink> GetRoute(int dimension, Point origin, Point destination)
        {
            MasterLog.DebugWriteLine("Finding route from: " + origin.ToString());
            MasterLog.DebugWriteLine("Finding route to: " + destination.ToString());
            Position[]      path = this.Grid.GetPath(new Position(origin.X, origin.Y), new Position(destination.X, destination.Y));
            List <PathLink> ret  = new List <PathLink>();

            if (!World.Data.World.Dimensions[dimension][destination.X, destination.Y].IsWalkable)
            {
                throw new Exception("Destination not possible!");
            }

            if (path.Length < 1)
            {
                throw new Exception("Path not possible!");
            }

            int i      = 0;
            int length = path.Length - 1;

            while (i != length)
            {
                if (!World.Data.World.Dimensions[dimension][path[i].X, path[i].Y].IsWalkable)
                {
                    MasterLog.DebugWriteLine("Walking on unwalkable tile!");
                }

                ret.Add(new PathLink(new Point(path[i].X, path[i].Y), new Point(path[i + 1].X, path[i + 1].Y)));
                i++;
            }

            return(ret);
        }
コード例 #12
0
        public static void DrawEntities(int dimension)
        {
            int chunkHeight = Chunk.Height;
            int chunkWidth  = Chunk.Width;
            int xSize       = World.Dimensions[dimension].Width;
            int ySize       = World.Dimensions[dimension].Height;

            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    Chunk chunk = World.Dimensions[dimension].GetChunk(x, y);

                    int length = chunk.Creatures.Count;
                    for (int i = 0; i < length; i++)
                    {
                        KeyValuePair <System.Guid, Living> item = chunk.Creatures.ElementAt(i);

                        if (item.Value != null)
                        {
                            Point2D livingScreenLocation = new Point2D((int)(item.Value.TileLocation.X * Tile.GetTileSize().X), (int)(item.Value.TileLocation.Y * Tile.GetTileSize().Y));
                            MasterLog.DebugWriteLine("Entity: " + item.Value.ID.ToString() + "Screen position: " + item.Value.TileLocation.ToString());
                            item.Value.Visual.Render(MapDrawer, livingScreenLocation);
                        }
                    }
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Used to validate that a mod contains correct information.
        /// </summary>
        /// <param name="mod"></param>
        /// <returns></returns>
        private bool IsValid(ModInformation info)
        {
            if (info == null)
            {
                MasterLog.DebugWriteLine("Mod rejected due to ModInformation being invalid.");
                return(false);
            }
            if (info.AuthorName == null || info.AuthorName.Equals(string.Empty))
            {
                MasterLog.DebugWriteLine("Mod rejected due to AuthorName in ModInformation being invalid.");
                return(false);
            }
            if (info.Description == null)
            {
                MasterLog.DebugWriteLine("Mod rejected due to Description in ModInformation being invalid.");
                return(false);
            }
            if (info.DisplayName == null || info.DisplayName.Equals(string.Empty))
            {
                MasterLog.DebugWriteLine("Mod rejected due to DisplayName in ModInformation being invalid.");
                return(false);
            }
            if (info.Version == null)
            {
                MasterLog.DebugWriteLine("Mod rejected due to Version in ModInformation being invalid.");
                return(false);
            }

            return(true);
        }
コード例 #14
0
ファイル: TCPServer.cs プロジェクト: ddabrahim/MagicalLife
 /// <summary>
 /// Broadcasts the message to all connected clients.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void Broadcast <T>(T data)
     where T : BaseMessage
 {
     byte[] buffer = ProtoUtil.Serialize <T>(data);
     MasterLog.DebugWriteLine("Sending " + buffer.Length + " bytes");
     this.Server.Broadcast(buffer);
 }
コード例 #15
0
        private static void OutputDebugInfo()
        {
            MasterLog.DebugWriteLine("Screens:");

            foreach (Screen screen in Screen.AllScreens)
            {
                MasterLog.DebugWriteLine("Device Name: " + screen.DeviceName);
                MasterLog.DebugWriteLine("Bounds: " + screen.Bounds.ToString());
                MasterLog.DebugWriteLine("Type: " + screen.GetType().ToString());
                MasterLog.DebugWriteLine("Working Area: " + screen.WorkingArea.ToString());
                MasterLog.DebugWriteLine("Bounds: " + screen.Bounds.ToString());
                MasterLog.DebugWriteLine("Primary Screen: " + screen.Primary.ToString());
            }

            MasterLog.DebugWriteLine("Screens end");

            System.Collections.ObjectModel.ReadOnlyCollection <GraphicsAdapter> gpus = GraphicsAdapter.Adapters;

            foreach (GraphicsAdapter item in gpus)
            {
                MasterLog.DebugWriteLine("Description: " + item.Description);
                MasterLog.DebugWriteLine("Device ID" + item.DeviceId.ToString());
                MasterLog.DebugWriteLine("Device Name: " + item.DeviceName);
                MasterLog.DebugWriteLine("Is Default: " + item.IsDefaultAdapter.ToString());
                MasterLog.DebugWriteLine("Revision: " + item.Revision.ToString());
                MasterLog.DebugWriteLine("Sub System ID: " + item.SubSystemId.ToString());
                MasterLog.DebugWriteLine("Vendor ID: " + item.VendorId.ToString());
            }
        }
コード例 #16
0
        public static void DumpEventInformation()
        {
            MasterLog.DebugWriteLine("Dumping Sound Events");
            foreach (EventDescription item in MainEvents)
            {
                item.getPath(out string path);
                MasterLog.DebugWriteLine(path);
                item.is3D(out bool is3D);
                MasterLog.DebugWriteLine("Is 3D: " + is3D.ToString());

                item.getParameterCount(out int length);

                for (int i = 0; i < length; i++)
                {
                    item.getParameterByIndex(i, out PARAMETER_DESCRIPTION parameter);
                    MasterLog.DebugWriteLine("Parameter name: " + parameter.name);
                    MasterLog.DebugWriteLine("Parameter type: " + parameter.type);
                    MasterLog.DebugWriteLine("Parameter index: " + parameter.index);
                    MasterLog.DebugWriteLine("Parameter default value: " + parameter.defaultvalue);
                    MasterLog.DebugWriteLine("Parameter minimum: " + parameter.minimum);
                    MasterLog.DebugWriteLine("Parameter maximum: " + parameter.maximum);
                }
            }
            MasterLog.DebugWriteLine("End of Sound Events");
        }
コード例 #17
0
 public MineTask(Point2D target, Guid boundID)
     : base(GetDependencies(boundID, target), boundID, new List <Qualification>())
 {
     this.Target = target;
     MasterLog.DebugWriteLine("Target: " + this.Target.ToString());
     this.HitTimer = new TickTimer(30);
 }
コード例 #18
0
        /// <summary>
        /// This function determines for each chunk what terrain generator should generate it.
        /// What terrain generator neighboring chunks use has an impact upon surrounding chunks.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        private int[,] AssignGenerators(int width, int height, Random seededRandom)
        {
            MasterLog.DebugWriteLine("Assigning generators");
            List <int> terrainWeights = new List <int>();

            foreach (TerrainGenerator item in WorldGeneratorRegistry.TerrainGenerators)
            {
                terrainWeights.Add(item.Weight);
            }

            WeightedRandom randomTerrainGenerators = new WeightedRandom(terrainWeights, seededRandom);

            int[,] terrainMap = new int[width, height];
            ArrayUtil.FillAll <int>(terrainMap, -1);

            int done = 0;
            int toDo = width * height;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    terrainMap[x, y] = this.ChooseTerrainGenerator(terrainMap, randomTerrainGenerators, x, y, seededRandom);
                    done++;
                    MasterLog.DebugWriteLine(done.ToString() + "/" + toDo.ToString());
                }
            }

            MasterLog.DebugWriteLine("Done assigning generators");
            return(terrainMap);
        }
コード例 #19
0
 /// <summary>
 /// Receives a message.
 /// </summary>
 /// <param name="message"></param>
 public static void Recieve(BaseMessage message)
 {
     TotalReceived++;
     MasterLog.DebugWriteLine("Total received: " + TotalReceived.ToString());
     RecievedMessages.Enqueue(message);
     RaiseMessageRecieved(null, message);
 }
コード例 #20
0
 private void HandleEscapeKey()
 {
     //Show main menu.
     MasterLog.DebugWriteLine("Escape key pressed");
     //MainMenu.ToggleMainMenu();
     MenuHandler.Back();
 }
コード例 #21
0
        /// <summary>
        /// Handles who gets the double click event.
        /// </summary>
        /// <param name="clickData"></param>
        private static void DoubleClick(MouseEventArgs clickData, List <GUIElement> Options, GuiContainer container)
        {
            int        focus  = -1;
            int        length = Options.Count;
            GUIElement item   = null;

            MasterLog.DebugWriteLine("Double click position: " + clickData.Position.ToString());

            for (int i = 0; i < length; i++)
            {
                item = Options[i];

                MasterLog.DebugWriteLine(item.GetType().ToString() + " gui bounds: " + item.MouseBounds.Bounds.ToString());

                if (focus == -1 && item.MouseBounds.Bounds.Contains(clickData.Position.X, clickData.Position.Y))
                {
                    item.HasFocus = true;
                    focus         = i;
                    MasterLog.DebugWriteLine(item.GetType().ToString() + " with a bounds of " + item.MouseBounds.Bounds.ToString() + "was double clicked on");
                }
                else
                {
                    item.HasFocus = false;
                    MasterLog.DebugWriteLine(item.GetType().ToString() + " with a bounds of " + item.MouseBounds.Bounds.ToString() + "was not double clicked on");
                }
            }

            if (focus != -1)
            {
                Options[focus].DoubleClick(clickData, container);
            }
        }
コード例 #22
0
ファイル: JobSystem.cs プロジェクト: ddabrahim/MagicalLife
        /// <summary>
        /// Every tick this method assigns jobs to workers who do not have jobs, if possible.
        /// </summary>
        public void ManageJobs()
        {
            int i = 0;

            lock (this.SyncObject)
            {
                while (i != this.Idle.Count)
                {
                    Living worker = this.Idle.ElementAt(i).Value;

                    bool result = AssignJob(worker);

                    if (result)
                    {
                        Job  job  = worker.Task;
                        Type type = job.GetType();
                        MasterLog.DebugWriteLine("Worker received job: " + type.FullName);
                        this.Idle.Remove(worker.ID);
                        this.Busy.Add(worker.ID, worker);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// Handles who gets the scroll event from the options provided.
        /// For use if a container is being used.
        /// </summary>
        private static void Scroll(MouseEventArgs scrollData, List <GUIElement> options, GuiContainer container)
        {
            int        focus  = -1;
            int        length = options.Count;
            GUIElement item   = null;

            MasterLog.DebugWriteLine("Scroll position: " + scrollData.Position.ToString());

            for (int i = 0; i < length; i++)
            {
                item = options[i];

                MasterLog.DebugWriteLine(item.GetType().ToString() + " gui bounds: " + item.MouseBounds.Bounds.ToString());

                if (focus == -1 && item.MouseBounds.Bounds.Contains(scrollData.Position.X - container.DrawingBounds.X, scrollData.Position.Y - container.DrawingBounds.Y))
                {
                    item.HasFocus = true;
                    focus         = i;
                    MasterLog.DebugWriteLine(item.GetType().ToString() + " with a bounds of " + item.MouseBounds.Bounds.ToString() + "was scrolled on");
                }
                else
                {
                    item.HasFocus = false;
                    MasterLog.DebugWriteLine(item.GetType().ToString() + " with a bounds of " + item.MouseBounds.Bounds.ToString() + "was not scrolled on");
                }
            }

            if (focus != -1)
            {
                MasterLog.DebugWriteLine("Scrolling on item: " + options[focus].GetType().FullName);
                options[focus].Scroll(scrollData, container);
            }
        }
コード例 #24
0
        /// <summary>
        /// Removes all mods that have invalid/duplicate mod ids from the passed in list.
        /// </summary>
        /// <param name="mods"></param>
        /// <returns></returns>
        private void RemoveInvalidMods(List <IMod> mods)
        {
            Dictionary <string, IMod> idToMods = new Dictionary <string, IMod>();

            foreach (IMod item in mods)
            {
                ModInformation info = item.GetInfo();
                if (idToMods.ContainsKey(info.ModID))
                {
                    idToMods.TryGetValue(info.ModID, out IMod value);
                    MasterLog.DebugWriteLine("Mod conflict: " + info.DisplayName + "(" + info.ModID +
                                             ") has an identical ModID to " + value.GetInfo().DisplayName + "(" + value.GetInfo().ModID + ")");
                    mods.Remove(item);
                    mods.Remove(value);
                    MasterLog.DebugWriteLine("Refusing to load either mod due to the ModID conflict");
                }
                else
                {
                    if (!this.IsValid(info))
                    {
                        mods.Remove(item);
                    }
                }
            }
        }
コード例 #25
0
 private void AssignJob(Living l, MagicalTask task)
 {
     MasterLog.DebugWriteLine("Assigning job: " + task.ID);
     MasterLog.DebugWriteLine("Assigning job to: " + l.ID);
     l.AssignTask(task);
     task.MakePreparations(l);
     task.ToilingWorker = l.ID;
 }
コード例 #26
0
ファイル: TillTask.cs プロジェクト: philipbawn/MagicalLife
 public TillTask(Point2D target, Guid boundID, int dimension)
     : base(GetDependencies(boundID, target), boundID, new List <Qualification>(), PriorityLayers.Default)
 {
     this.Dimension = dimension;
     this.Target    = target;
     MasterLog.DebugWriteLine("Target: " + this.Target.ToString());
     this.HitTimer = new TickTimer(30);
 }
コード例 #27
0
        /// <summary>
        /// Returns the center of the player's screen view.
        /// </summary>
        /// <returns></returns>
        public static Point2D GetCameraCenter()
        {
            int x = (FullScreenWindow.Width / 2) + XViewOffset;
            int y = (FullScreenWindow.Height / 2) + YViewOffset;

            MasterLog.DebugWriteLine("Center Camera/Listener: " + x.ToString() + ", " + y.ToString());
            return(new Point2D(x, y));
        }
コード例 #28
0
 public override void Tick(Living l)
 {
     if (l.MapLocation.Equals(this.AdjacentLocation))
     {
         MasterLog.DebugWriteLine(this.ID.ToString());
         this.CompleteTask();
     }
 }
コード例 #29
0
 protected override void JobTick(Living living)
 {
     if (living.MapLocation.Equals(this.AdjacentLocation))
     {
         MasterLog.DebugWriteLine(this.ID.ToString());
         this.CompleteJob(living);
     }
 }
コード例 #30
0
        private void Server_ClientDisconnected(object sender, System.Net.Sockets.TcpClient e)
        {
            KeyValuePair <Guid, Socket> result = this.PlayerToSocket.First(x => x.Value == e.Client);

            this.PlayerToSocket.Remove(result.Key);
            ServerSendRecieve.Recieve(new DisconnectMessage(result.Key));

            MasterLog.DebugWriteLine("Client disconnected: " + e.Client.RemoteEndPoint.ToString());
        }