diff --git a/LICENSE b/LICENSE index 5ef931675..ecd241d0e 100644 --- a/LICENSE +++ b/LICENSE @@ -11,30 +11,30 @@ software and other kinds of works. The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, +to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the +software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to +any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you +price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have +these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: @@ -42,19 +42,19 @@ know their rights. giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and +that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we +use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we +products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. @@ -62,7 +62,7 @@ of the GPL, as needed to protect the freedom of users. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that +make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and @@ -78,12 +78,12 @@ modification follow. works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and +License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the +exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based @@ -92,12 +92,12 @@ on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, +computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through +parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" @@ -105,14 +105,14 @@ to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If +work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source +for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official @@ -125,7 +125,7 @@ than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A +implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to @@ -134,10 +134,10 @@ produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's +control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source +which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, @@ -155,25 +155,25 @@ same work. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your +content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose +in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works +not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 +the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. @@ -216,14 +216,14 @@ terms of section 4, provided that you also meet all of these conditions: b) The work must carry prominent notices stating that it is released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to + 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This + License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no + regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. @@ -238,7 +238,7 @@ and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work +beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. @@ -267,7 +267,7 @@ in one of these ways: Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This + written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. @@ -275,13 +275,13 @@ in one of these ways: d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the + Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. @@ -297,12 +297,12 @@ included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product +actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. @@ -310,7 +310,7 @@ the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must +a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. @@ -321,7 +321,7 @@ part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply +by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). @@ -329,7 +329,7 @@ been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a +the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. @@ -346,14 +346,14 @@ unpacking, reading or copying. License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions +that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own +it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. @@ -386,10 +386,10 @@ that material) supplement the terms of this License with terms: those licensors and authors. All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you +restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains +restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does @@ -407,7 +407,7 @@ the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or +provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). @@ -428,31 +428,31 @@ your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently +this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work +run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, +to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible +propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered +organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could @@ -461,7 +461,7 @@ Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may +rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that @@ -471,7 +471,7 @@ sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The +License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims @@ -479,7 +479,7 @@ owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For +consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. @@ -492,7 +492,7 @@ propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a +sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. @@ -504,7 +504,7 @@ then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have +license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that @@ -521,7 +521,7 @@ work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered +specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying @@ -541,10 +541,10 @@ otherwise be available to you under applicable patent law. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a +excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you +not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. @@ -554,7 +554,7 @@ License would be to refrain entirely from conveying the Program. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this +combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the @@ -563,16 +563,16 @@ combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will +the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - Each version is given a distinguishing version number. If the + Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the +Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. @@ -582,19 +582,19 @@ public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any +permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. @@ -626,40 +626,36 @@ copy of the Program in return for a fee. possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - To do so, attach the following notices to the program. It is safest + To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. ModernUO - Copyright (C) 2019 ModernUO Dev Team - hi@modernuo.com + Copyright 2019-2020 ModernUO Development Team + Email: hi@modernuo.com + File: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Copyright (C) + Copyright This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands +parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, @@ -668,8 +664,8 @@ For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you +into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read . diff --git a/Projects/Server/AssemblyHandler.cs b/Projects/Server/AssemblyHandler.cs index daf4e8b89..90d4bf9c0 100644 --- a/Projects/Server/AssemblyHandler.cs +++ b/Projects/Server/AssemblyHandler.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AssemblyHandler.cs * * * @@ -33,7 +33,9 @@ namespace Server var assemblies = new Assembly[files.Length]; for (var i = 0; i < files.Length; i++) + { assemblies[i] = AssemblyLoadContext.Default.LoadFromAssemblyPath(files[i]); + } Assemblies = assemblies; } @@ -43,42 +45,61 @@ namespace Server var invoke = new List(); for (var a = 0; a < Assemblies.Length; ++a) + { invoke.AddRange( Assemblies[a] .GetTypes() .Select(t => t.GetMethod(method, BindingFlags.Static | BindingFlags.Public)) .Where(m => m != null) ); + } invoke.Sort(new CallPriorityComparer()); for (var i = 0; i < invoke.Count; ++i) + { invoke[i].Invoke(null, null); + } } public static TypeCache GetTypeCache(Assembly asm) { if (asm == null) + { return m_NullCache ??= new TypeCache(null); + } if (m_TypeCaches.TryGetValue(asm, out var c)) + { return c; + } return m_TypeCaches[asm] = new TypeCache(asm); } public static Type FindFirstTypeForName(string name, bool ignoreCase = false, Func predicate = null) { - if (string.IsNullOrWhiteSpace(name)) return null; + if (string.IsNullOrWhiteSpace(name)) + { + return null; + } var types = FindTypesByName(name, ignoreCase).ToList(); if (types.Count == 0) + { return null; + } if (predicate != null) + { return types.FirstOrDefault(predicate); + } + if (types.Count == 1) + { return types[0]; + } + // Try to find the closest match if there is no predicate. // Check for exact match of the FullName or Name // Then check for case-insensitive match of FullName or Name @@ -97,13 +118,19 @@ namespace Server var types = new List(); if (ignoreCase) + { name = name.ToLower(); + } for (var i = 0; i < Assemblies.Length; i++) + { types.AddRange(GetTypeCache(Assemblies[i])[name]); + } if (types.Count == 0) + { types.AddRange(GetTypeCache(Core.Assembly)[name]); + } return types; } @@ -150,15 +177,19 @@ namespace Server addToRefs(i, current.FullName); addToRefs(i, current.FullName?.ToLower()); if (current.GetCustomAttribute(aliasType, false) is TypeAliasAttribute alias) + { for (var j = 0; j < alias.Aliases.Length; j++) { addToRefs(i, alias.Aliases[j]); addToRefs(i, alias.Aliases[j].ToLower()); } + } } foreach (var (key, value) in nameMap) + { m_NameMap[key] = value.ToArray(); + } } public IEnumerable Types => m_Types; diff --git a/Projects/Server/Attributes.cs b/Projects/Server/Attributes.cs index a5967466a..fe626f0cf 100644 --- a/Projects/Server/Attributes.cs +++ b/Projects/Server/Attributes.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Attributes.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Reflection; @@ -57,22 +37,32 @@ namespace Server public int Compare(MethodInfo x, MethodInfo y) { if (x == null && y == null) + { return 0; + } if (x == null) + { return 1; + } if (y == null) + { return -1; + } var xPriority = GetPriority(x); var yPriority = GetPriority(y); if (xPriority > yPriority) + { return 1; + } if (xPriority < yPriority) + { return -1; + } return 0; } @@ -82,10 +72,14 @@ namespace Server var objs = mi.GetCustomAttributes(typeof(CallPriorityAttribute), true); if (objs.Length == 0) + { return 0; + } if (!(objs[0] is CallPriorityAttribute attr)) + { return 0; + } return attr.Priority; } diff --git a/Projects/Server/Buffers/BufferReader.cs b/Projects/Server/Buffers/BufferReader.cs index c654c6d29..c9a924132 100644 --- a/Projects/Server/Buffers/BufferReader.cs +++ b/Projects/Server/Buffers/BufferReader.cs @@ -74,7 +74,9 @@ namespace System.Buffers { if (length < 0) // Cast-away readonly to initialize lazy field + { Volatile.Write(ref Unsafe.AsRef(length), sequence.Length); + } return length; } @@ -109,9 +111,13 @@ namespace System.Buffers if (CurrentSpanIndex >= CurrentSpan.Length) { if (usingSequence) + { GetNextSpan(); + } else + { moreData = false; + } } return true; @@ -120,7 +126,10 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Rewind(long count) { - if ((ulong)count > (ulong)Consumed) throw new ArgumentOutOfRangeException(nameof(count)); + if ((ulong)count > (ulong)Consumed) + { + throw new ArgumentOutOfRangeException(nameof(count)); + } Consumed -= count; @@ -232,7 +241,10 @@ namespace System.Buffers private void AdvanceToNextSpan(long count) { - if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); + if (count < 0) + { + throw new ArgumentOutOfRangeException(nameof(count)); + } Consumed += count; while (moreData) @@ -253,7 +265,10 @@ namespace System.Buffers GetNextSpan(); - if (count == 0) break; + if (count == 0) + { + break; + } } if (count != 0) @@ -286,7 +301,9 @@ namespace System.Buffers { // If we don't have enough to fill the requested buffer, return false if (Remaining < destination.Length) + { return false; + } var firstSpan = UnreadSpan; firstSpan.CopyTo(destination); @@ -294,14 +311,19 @@ namespace System.Buffers var next = nextPosition; while (sequence.TryGet(ref next, out var nextSegment)) + { if (nextSegment.Length > 0) { var nextSpan = nextSegment.Span; var toCopy = Math.Min(nextSpan.Length, destination.Length - copied); nextSpan.Slice(0, toCopy).CopyTo(destination.Slice(copied)); copied += toCopy; - if (copied >= destination.Length) break; + if (copied >= destination.Length) + { + break; + } } + } return true; } diff --git a/Projects/Server/Buffers/BufferReaderExtensions.cs b/Projects/Server/Buffers/BufferReaderExtensions.cs index fd42765a4..f19242b35 100644 --- a/Projects/Server/Buffers/BufferReaderExtensions.cs +++ b/Projects/Server/Buffers/BufferReaderExtensions.cs @@ -14,7 +14,10 @@ namespace System.Buffers where T : unmanaged { var span = reader.UnreadSpan; - if (span.Length < sizeof(T)) return TryReadMultisegment(ref reader, out value); + if (span.Length < sizeof(T)) + { + return TryReadMultisegment(ref reader, out value); + } value = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(span)); reader.Advance(sizeof(T)); diff --git a/Projects/Server/Buffers/BufferWriter.cs b/Projects/Server/Buffers/BufferWriter.cs index f4fbd01c8..1999b1612 100644 --- a/Projects/Server/Buffers/BufferWriter.cs +++ b/Projects/Server/Buffers/BufferWriter.cs @@ -110,7 +110,10 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Ensure(int count = 1) { - if (_span.Length < count) EnsureMore(count); + if (_span.Length < count) + { + EnsureMore(count); + } } /// @@ -120,7 +123,10 @@ namespace System.Buffers [MethodImpl(MethodImplOptions.NoInlining)] private void EnsureMore(int count = 0) { - if (_buffered > 0) Commit(); + if (_buffered > 0) + { + Commit(); + } _span = _output.GetSpan(count); } @@ -133,7 +139,10 @@ namespace System.Buffers { while (source.Length > 0) { - if (_span.Length == 0) EnsureMore(); + if (_span.Length == 0) + { + EnsureMore(); + } var writable = Math.Min(source.Length, _span.Length); source.Slice(0, writable).CopyTo(_span); diff --git a/Projects/Server/Buffers/MemoryPoolSlab.cs b/Projects/Server/Buffers/MemoryPoolSlab.cs index 82168ee91..520ac3e74 100644 --- a/Projects/Server/Buffers/MemoryPoolSlab.cs +++ b/Projects/Server/Buffers/MemoryPoolSlab.cs @@ -58,14 +58,20 @@ namespace System.Buffers protected void Dispose(bool disposing) { - if (_isDisposed) return; + if (_isDisposed) + { + return; + } _isDisposed = true; Array = null; NativePointer = IntPtr.Zero; - if (_gcHandle.IsAllocated) _gcHandle.Free(); + if (_gcHandle.IsAllocated) + { + _gcHandle.Free(); + } } ~MemoryPoolSlab() diff --git a/Projects/Server/Buffers/SlabMemoryPool.cs b/Projects/Server/Buffers/SlabMemoryPool.cs index e0e91a131..d58f655f5 100644 --- a/Projects/Server/Buffers/SlabMemoryPool.cs +++ b/Projects/Server/Buffers/SlabMemoryPool.cs @@ -72,7 +72,10 @@ namespace System.Buffers public override IMemoryOwner Rent(int size = AnySize) { - if (size > _blockSize) MemoryPoolThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockSize); + if (size > _blockSize) + { + MemoryPoolThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockSize); + } var block = Lease(); return block; @@ -85,7 +88,9 @@ namespace System.Buffers private MemoryPoolBlock Lease() { if (_isDisposed) + { MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPool); + } if (_blocks.TryDequeue(out var block)) { @@ -127,7 +132,9 @@ namespace System.Buffers block = new MemoryPoolBlock(this, slab, offset, _blockSize); if (i != blockCount - 1) // last block + { Return(block); + } offset += _blockSize; } @@ -148,9 +155,13 @@ namespace System.Buffers internal void Return(MemoryPoolBlock block) { if (!_isDisposed) + { _blocks.Enqueue(block); + } else + { GC.SuppressFinalize(block); + } } // This method can ONLY be called from the finalizer of MemoryPoolBlock @@ -162,25 +173,37 @@ namespace System.Buffers // Need to make a new object because this one is being finalized // Note, this must be called within the _disposeSync lock because the block // could be disposed at the same time as the finalizer. + { Return(new MemoryPoolBlock(this, slab, offset, length)); + } } } protected override void Dispose(bool disposing) { - if (_isDisposed) return; + if (_isDisposed) + { + return; + } lock (_disposeSync) { _isDisposed = true; if (disposing) + { while (_slabs.TryPop(out var slab)) // dispose managed state (managed objects). + { slab.Dispose(); + } + } // Discard blocks in pool - while (_blocks.TryDequeue(out var block)) GC.SuppressFinalize(block); + while (_blocks.TryDequeue(out var block)) + { + GC.SuppressFinalize(block); + } } } } diff --git a/Projects/Server/CityInfo.cs b/Projects/Server/CityInfo.cs index c686b4971..9cd28d918 100644 --- a/Projects/Server/CityInfo.cs +++ b/Projects/Server/CityInfo.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CityInfo.cs * * * diff --git a/Projects/Server/ClientVersion.cs b/Projects/Server/ClientVersion.cs index 551904cad..284c4afb6 100644 --- a/Projects/Server/ClientVersion.cs +++ b/Projects/Server/ClientVersion.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ClientVersion.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Text; @@ -58,7 +38,9 @@ namespace Server var br3 = br2 + 1; while (br3 < fmt.Length && char.IsDigit(fmt, br3)) + { br3++; + } Major = Utility.ToInt32(fmt.Substring(0, br1)); Minor = Utility.ToInt32(fmt.Substring(br1 + 1, br2 - br1 - 1)); @@ -69,7 +51,9 @@ namespace Server if (Major <= 5 && Minor <= 0 && Revision <= 6) // Anything before 5.0.7 { if (!char.IsWhiteSpace(fmt, br3)) + { Patch = fmt[br3] - 'a' + 1; + } } else { @@ -78,12 +62,18 @@ namespace Server } if (fmt.IndexOf("god") >= 0 || fmt.IndexOf("gq") >= 0) + { Type = ClientType.God; + } else if (fmt.IndexOf("third dawn") >= 0 || fmt.IndexOf("uo:td") >= 0 || fmt.IndexOf("uotd") >= 0 || fmt.IndexOf("uo3d") >= 0 || fmt.IndexOf("uo:3d") >= 0) + { Type = ClientType.UOTD; + } else + { Type = ClientType.Regular; + } } catch { @@ -110,24 +100,50 @@ namespace Server public int CompareTo(ClientVersion o) { if (o == null) + { return 1; + } if (Major > o.Major) + { return 1; + } + if (Major < o.Major) + { return -1; + } + if (Minor > o.Minor) + { return 1; + } + if (Minor < o.Minor) + { return -1; + } + if (Revision > o.Revision) + { return 1; + } + if (Revision < o.Revision) + { return -1; + } + if (Patch > o.Patch) + { return 1; + } + if (Patch < o.Patch) + { return -1; + } + return 0; } @@ -171,7 +187,9 @@ namespace Server if (Major <= 5 && Minor <= 0 && Revision <= 6) // Anything before 5.0.7 { if (Patch > 0) + { builder.Append((char)('a' + (Patch - 1))); + } } else { @@ -195,11 +213,19 @@ namespace Server public static int Compare(ClientVersion a, ClientVersion b) { if (IsNull(a) && IsNull(b)) + { return 0; + } + if (IsNull(a)) + { return -1; + } + if (IsNull(b)) + { return 1; + } return a.CompareTo(b); } diff --git a/Projects/Server/Collections/ArraySet.cs b/Projects/Server/Collections/ArraySet.cs index c2ce57669..bf547781d 100644 --- a/Projects/Server/Collections/ArraySet.cs +++ b/Projects/Server/Collections/ArraySet.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ArraySet.cs * * * @@ -57,7 +57,10 @@ namespace Server.Collections { var indexOf = m_List.IndexOf(item); - if (indexOf >= 0) return indexOf; + if (indexOf >= 0) + { + return indexOf; + } m_List.Add(item); return m_List.Count - 1; diff --git a/Projects/Server/Commands.cs b/Projects/Server/Commands.cs index 190b4b296..6df63e5b2 100644 --- a/Projects/Server/Commands.cs +++ b/Projects/Server/Commands.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Commands.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using Server.Network; @@ -49,7 +29,9 @@ namespace Server public string GetString(int index) { if (index < 0 || index >= Arguments.Length) + { return ""; + } return Arguments[index]; } @@ -57,7 +39,9 @@ namespace Server public int GetInt32(int index) { if (index < 0 || index >= Arguments.Length) + { return 0; + } return Utility.ToInt32(Arguments[index]); } @@ -65,7 +49,9 @@ namespace Server public uint GetUInt32(int index) { if (index < 0 || index >= Arguments.Length) + { return 0; + } return Utility.ToUInt32(Arguments[index]); } @@ -73,7 +59,9 @@ namespace Server public bool GetBoolean(int index) { if (index < 0 || index >= Arguments.Length) + { return false; + } return Utility.ToBoolean(Arguments[index]); } @@ -81,7 +69,9 @@ namespace Server public double GetDouble(int index) { if (index < 0 || index >= Arguments.Length) + { return 0.0; + } return Utility.ToDouble(Arguments[index]); } @@ -89,7 +79,9 @@ namespace Server public TimeSpan GetTimeSpan(int index) { if (index < 0 || index >= Arguments.Length) + { return TimeSpan.Zero; + } return Utility.ToTimeSpan(Arguments[index]); } @@ -145,10 +137,16 @@ namespace Server var end = start; while (end < array.Length) + { if (array[end] != '"' || array[end - 1] == '\\') + { ++end; + } else + { break; + } + } list.Add(value.Substring(start, end - start)); @@ -159,10 +157,16 @@ namespace Server var end = start; while (end < array.Length) + { if (array[end] != ' ') + { ++end; + } else + { break; + } + } list.Add(value.Substring(start, end - start)); @@ -185,10 +189,14 @@ namespace Server public static bool Handle(Mobile from, string text, MessageType type = MessageType.Regular) { if (!text.StartsWith(Prefix) && type != MessageType.Command) + { return false; + } if (type != MessageType.Command) + { text = text.Substring(Prefix.Length); + } var indexOf = text.IndexOf(' '); @@ -226,7 +234,9 @@ namespace Server else { if (from.AccessLevel <= BadCommandIgnoreLevel) + { return false; + } from.SendMessage("You do not have access to that command."); } @@ -234,7 +244,9 @@ namespace Server else { if (from.AccessLevel <= BadCommandIgnoreLevel) + { return false; + } from.SendMessage("That is not a valid command."); } diff --git a/Projects/Server/Configuration/ServerConfiguration.cs b/Projects/Server/Configuration/ServerConfiguration.cs index ed8e2ddc1..5b78cecc3 100644 --- a/Projects/Server/Configuration/ServerConfiguration.cs +++ b/Projects/Server/Configuration/ServerConfiguration.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerConfiguration.cs * * * diff --git a/Projects/Server/ContextMenus/ContextMenu.cs b/Projects/Server/ContextMenus/ContextMenu.cs index b4ab93f7e..d3cb9207c 100644 --- a/Projects/Server/ContextMenus/ContextMenu.cs +++ b/Projects/Server/ContextMenus/ContextMenu.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ContextMenu.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Collections.Generic; using System.Linq; @@ -50,14 +30,20 @@ namespace Server.ContextMenus var list = new List(); if (target is Mobile mobile) - mobile.GetContextMenuEntries(from, list); + { + mobile.GetContextMenuEntries(@from, list); + } else if (target is Item item) - item.GetContextMenuEntries(from, list); + { + item.GetContextMenuEntries(@from, list); + } Entries = list.ToArray(); for (var i = 0; i < Entries.Length; ++i) + { Entries[i].Owner = this; + } } /// diff --git a/Projects/Server/ContextMenus/ContextMenuEntry.cs b/Projects/Server/ContextMenus/ContextMenuEntry.cs index da9bfdd43..dfc54958a 100644 --- a/Projects/Server/ContextMenus/ContextMenuEntry.cs +++ b/Projects/Server/ContextMenus/ContextMenuEntry.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ContextMenuEntry.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.ContextMenus @@ -44,9 +24,13 @@ namespace Server.ContextMenus public ContextMenuEntry(int number, int range = -1) { if (number <= 0x7FFF) // Legacy code support + { Number = 3000000 + number; + } else + { Number = number; + } Range = range; Enabled = true; diff --git a/Projects/Server/ContextMenus/OpenBackpackEntry.cs b/Projects/Server/ContextMenus/OpenBackpackEntry.cs index 58ca41d71..f32c518f2 100644 --- a/Projects/Server/ContextMenus/OpenBackpackEntry.cs +++ b/Projects/Server/ContextMenus/OpenBackpackEntry.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * OpenBackpackEntry.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.ContextMenus { public class OpenBackpackEntry : ContextMenuEntry diff --git a/Projects/Server/ContextMenus/PaperdollEntry.cs b/Projects/Server/ContextMenus/PaperdollEntry.cs index e1bffde8a..4ef4fea6f 100644 --- a/Projects/Server/ContextMenus/PaperdollEntry.cs +++ b/Projects/Server/ContextMenus/PaperdollEntry.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PaperdollEntry.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.ContextMenus { public class PaperdollEntry : ContextMenuEntry @@ -29,7 +9,9 @@ namespace Server.ContextMenus public override void OnClick() { if (m_Mobile.CanPaperdollBeOpenedBy(Owner.From)) + { m_Mobile.DisplayPaperdollTo(Owner.From); + } } } } diff --git a/Projects/Server/Diagnostics/BaseProfile.cs b/Projects/Server/Diagnostics/BaseProfile.cs index 28b680a5e..e28116e69 100644 --- a/Projects/Server/Diagnostics/BaseProfile.cs +++ b/Projects/Server/Diagnostics/BaseProfile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketProfile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Diagnostics; @@ -61,7 +41,10 @@ namespace Server.Diagnostics public virtual void Start() { - if (_stopwatch.IsRunning) _stopwatch.Reset(); + if (_stopwatch.IsRunning) + { + _stopwatch.Reset(); + } _stopwatch.Start(); } @@ -72,7 +55,10 @@ namespace Server.Diagnostics TotalTime += elapsed; - if (elapsed > PeakTime) PeakTime = elapsed; + if (elapsed > PeakTime) + { + PeakTime = elapsed; + } Count++; diff --git a/Projects/Server/Diagnostics/GumpProfile.cs b/Projects/Server/Diagnostics/GumpProfile.cs index deaedef86..7380e336f 100644 --- a/Projects/Server/Diagnostics/GumpProfile.cs +++ b/Projects/Server/Diagnostics/GumpProfile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketProfile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; @@ -36,10 +16,14 @@ namespace Server.Diagnostics public static GumpProfile Acquire(Type type) { if (!Core.Profiling) + { return null; + } if (!_profiles.TryGetValue(type, out var prof)) + { _profiles.Add(type, prof = new GumpProfile(type)); + } return prof; } diff --git a/Projects/Server/Diagnostics/PacketProfile.cs b/Projects/Server/Diagnostics/PacketProfile.cs index 0b122ad83..3aa880b90 100644 --- a/Projects/Server/Diagnostics/PacketProfile.cs +++ b/Projects/Server/Diagnostics/PacketProfile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketProfile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.IO; @@ -67,7 +47,9 @@ namespace Server.Diagnostics public static PacketSendProfile Acquire(Type type) { if (!_profiles.TryGetValue(type, out var prof)) + { _profiles.Add(type, prof = new PacketSendProfile(type)); + } return prof; } @@ -101,7 +83,9 @@ namespace Server.Diagnostics public static PacketReceiveProfile Acquire(int packetId) { if (!_profiles.TryGetValue(packetId, out var prof)) + { _profiles.Add(packetId, prof = new PacketReceiveProfile(packetId)); + } return prof; } diff --git a/Projects/Server/Diagnostics/TargetProfile.cs b/Projects/Server/Diagnostics/TargetProfile.cs index e7f1e93b5..0ac4b215a 100644 --- a/Projects/Server/Diagnostics/TargetProfile.cs +++ b/Projects/Server/Diagnostics/TargetProfile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketProfile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; @@ -37,10 +17,14 @@ namespace Server.Diagnostics public static TargetProfile Acquire(Type type) { if (!Core.Profiling) + { return null; + } if (!_profiles.TryGetValue(type, out var prof)) + { _profiles.Add(type, prof = new TargetProfile(type)); + } return prof; } diff --git a/Projects/Server/Diagnostics/TimerProfile.cs b/Projects/Server/Diagnostics/TimerProfile.cs index f2e4d05be..a482cdbdc 100644 --- a/Projects/Server/Diagnostics/TimerProfile.cs +++ b/Projects/Server/Diagnostics/TimerProfile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketProfile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Collections.Generic; using System.IO; @@ -43,10 +23,14 @@ namespace Server.Diagnostics public static TimerProfile Acquire(string name) { if (!Core.Profiling) + { return null; + } if (!_profiles.TryGetValue(name, out var prof)) + { _profiles.Add(name, prof = new TimerProfile(name)); + } return prof; } diff --git a/Projects/Server/Effects.cs b/Projects/Server/Effects.cs index dcc9046af..871b36712 100644 --- a/Projects/Server/Effects.cs +++ b/Projects/Server/Effects.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Effects.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server @@ -51,7 +31,9 @@ namespace Server public static void PlaySound(IPoint3D p, Map map, int soundID) { if (soundID <= -1) + { return; + } if (map != null) { @@ -89,7 +71,9 @@ namespace Server var map = e.Map; if (map == null) + { return; + } e.ProcessDelta(); @@ -98,6 +82,7 @@ namespace Server var eable = map.GetClientsInRange(e.Location); foreach (var state in eable) + { if (state.Mobile.CanSee(e)) { if (SendParticlesTo(state)) @@ -118,6 +103,7 @@ namespace Server state.Send(playSound); } } + } Packet.Release(preEffect); Packet.Release(boltEffect); @@ -220,7 +206,9 @@ namespace Server public static void SendTargetEffect(IEntity target, int itemID, int speed, int duration, int hue, int renderMode) { if (target is Mobile mobile) + { mobile.ProcessDelta(); + } SendPacket(target.Location, target.Map, new TargetEffect(target, itemID, speed, duration, hue, renderMode)); } @@ -247,7 +235,9 @@ namespace Server ) { if (target is Mobile mobile) + { mobile.ProcessDelta(); + } var map = target.Map; @@ -302,10 +292,14 @@ namespace Server ) { if (from is Mobile mobile) + { mobile.ProcessDelta(); + } if (to is Mobile mobile1) + { mobile1.ProcessDelta(); + } SendPacket( from.Location, @@ -389,10 +383,14 @@ namespace Server ) { if (from is Mobile fromMob) + { fromMob.ProcessDelta(); + } if (to is Mobile toMob) + { toMob.ProcessDelta(); + } var map = from.Map; @@ -461,7 +459,9 @@ namespace Server public static void SendPacket(Point3D origin, Map map, Packet p) { if (map == null) + { return; + } var eable = map.GetClientsInRange(origin); @@ -481,7 +481,9 @@ namespace Server public static void SendPacket(IPoint3D origin, Map map, Packet p) { if (map == null) + { return; + } var eable = map.GetClientsInRange(new Point3D(origin)); diff --git a/Projects/Server/Events/AccountLoginEvent.cs b/Projects/Server/Events/AccountLoginEvent.cs index c8c17dce8..2fbcd3da1 100644 --- a/Projects/Server/Events/AccountLoginEvent.cs +++ b/Projects/Server/Events/AccountLoginEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AccountLoginEvent.cs * * * diff --git a/Projects/Server/Events/AggressiveActionEvent.cs b/Projects/Server/Events/AggressiveActionEvent.cs index 3ef396cda..b0f10beb3 100644 --- a/Projects/Server/Events/AggressiveActionEvent.cs +++ b/Projects/Server/Events/AggressiveActionEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AggressiveActionEvent.cs * * * diff --git a/Projects/Server/Events/CharacterCreatedEvent.cs b/Projects/Server/Events/CharacterCreatedEvent.cs index 03379cffb..e6e299a41 100644 --- a/Projects/Server/Events/CharacterCreatedEvent.cs +++ b/Projects/Server/Events/CharacterCreatedEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CharacterCreatedEvent.cs * * * diff --git a/Projects/Server/Events/CreateGuildEvent.cs b/Projects/Server/Events/CreateGuildEvent.cs index 44b6974e7..8acabea78 100644 --- a/Projects/Server/Events/CreateGuildEvent.cs +++ b/Projects/Server/Events/CreateGuildEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CreateGuildEvent.cs * * * diff --git a/Projects/Server/Events/EventSink.cs b/Projects/Server/Events/EventSink.cs index 0b99c2b66..388a6486a 100644 --- a/Projects/Server/Events/EventSink.cs +++ b/Projects/Server/Events/EventSink.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: EventSink.cs * * * @@ -137,7 +137,9 @@ namespace Server public static void InvokeEquipMacro(Mobile m, List list) { if (list?.Count > 0) + { EquipMacro?.Invoke(m, list); + } } public static event Action> UnequipMacro; @@ -145,7 +147,9 @@ namespace Server public static void InvokeUnequipMacro(Mobile m, List layers) { if (layers?.Count > 0) + { UnequipMacro?.Invoke(m, layers); + } } public static event Action TargetedSpell; diff --git a/Projects/Server/Events/FastwalkEvent.cs b/Projects/Server/Events/FastwalkEvent.cs index 39b78ceb8..b659ef154 100644 --- a/Projects/Server/Events/FastwalkEvent.cs +++ b/Projects/Server/Events/FastwalkEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: FastwalkEvent.cs * * * diff --git a/Projects/Server/Events/GameLoginEvent.cs b/Projects/Server/Events/GameLoginEvent.cs index dc933bb44..eb11f2c47 100644 --- a/Projects/Server/Events/GameLoginEvent.cs +++ b/Projects/Server/Events/GameLoginEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GameLoginEvent.cs * * * diff --git a/Projects/Server/Events/MovementEvent.cs b/Projects/Server/Events/MovementEvent.cs index c9ecd9f21..9a7e0a92d 100644 --- a/Projects/Server/Events/MovementEvent.cs +++ b/Projects/Server/Events/MovementEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MovementEvent.cs * * * diff --git a/Projects/Server/Events/ServerCrashedEvent.cs b/Projects/Server/Events/ServerCrashedEvent.cs index c6240f7b5..08895df24 100644 --- a/Projects/Server/Events/ServerCrashedEvent.cs +++ b/Projects/Server/Events/ServerCrashedEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerCrashedEvent.cs * * * diff --git a/Projects/Server/Events/ServerListEvent.cs b/Projects/Server/Events/ServerListEvent.cs index a2a118c92..923adce2d 100644 --- a/Projects/Server/Events/ServerListEvent.cs +++ b/Projects/Server/Events/ServerListEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerListEvent.cs * * * diff --git a/Projects/Server/Events/SocketConnectionEvent.cs b/Projects/Server/Events/SocketConnectionEvent.cs index ecc79de8e..fa1f21a60 100644 --- a/Projects/Server/Events/SocketConnectionEvent.cs +++ b/Projects/Server/Events/SocketConnectionEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SocketConnectionEvent.cs * * * diff --git a/Projects/Server/Events/SpeechEvent.cs b/Projects/Server/Events/SpeechEvent.cs index de054ac78..d1e737d35 100644 --- a/Projects/Server/Events/SpeechEvent.cs +++ b/Projects/Server/Events/SpeechEvent.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SpeechEvent.cs * * * @@ -46,8 +46,12 @@ namespace Server public bool HasKeyword(int keyword) { for (var i = 0; i < Keywords.Length; ++i) + { if (Keywords[i] == keyword) + { return true; + } + } return false; } diff --git a/Projects/Server/ExpansionInfo.cs b/Projects/Server/ExpansionInfo.cs index 1265bed47..cf4711529 100644 --- a/Projects/Server/ExpansionInfo.cs +++ b/Projects/Server/ExpansionInfo.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ExpansionInfo.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server @@ -317,7 +297,10 @@ namespace Server { var info = GetInfo(ex); - if (info != null) return info.SupportedFeatures; + if (info != null) + { + return info.SupportedFeatures; + } return ex switch { @@ -343,7 +326,10 @@ namespace Server { var v = ex; - if (v < 0 || v >= Table.Length) v = 0; + if (v < 0 || v >= Table.Length) + { + v = 0; + } return Table[v]; } diff --git a/Projects/Server/Geometry/Point2D.cs b/Projects/Server/Geometry/Point2D.cs index 6a623a510..bac42a7a3 100644 --- a/Projects/Server/Geometry/Point2D.cs +++ b/Projects/Server/Geometry/Point2D.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point2D.cs * * * @@ -104,14 +104,22 @@ namespace Server public int CompareTo(Point2D other) { var xComparison = m_X.CompareTo(other.m_X); - if (xComparison != 0) return xComparison; + if (xComparison != 0) + { + return xComparison; + } + return m_Y.CompareTo(other.m_Y); } public int CompareTo(IPoint2D other) { var xComparison = m_X.CompareTo(other.X); - if (xComparison != 0) return xComparison; + if (xComparison != 0) + { + return xComparison; + } + return m_Y.CompareTo(other.Y); } } diff --git a/Projects/Server/Geometry/Point3D.cs b/Projects/Server/Geometry/Point3D.cs index 25f23e2ab..d3fe000f3 100644 --- a/Projects/Server/Geometry/Point3D.cs +++ b/Projects/Server/Geometry/Point3D.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point3D.cs * * * @@ -128,18 +128,34 @@ namespace Server public int CompareTo(Point3D other) { var xComparison = m_X.CompareTo(other.m_X); - if (xComparison != 0) return xComparison; + if (xComparison != 0) + { + return xComparison; + } + var yComparison = m_Y.CompareTo(other.m_Y); - if (yComparison != 0) return yComparison; + if (yComparison != 0) + { + return yComparison; + } + return m_Z.CompareTo(other.m_Z); } public int CompareTo(IPoint3D other) { var xComparison = m_X.CompareTo(other.X); - if (xComparison != 0) return xComparison; + if (xComparison != 0) + { + return xComparison; + } + var yComparison = m_Y.CompareTo(other.Y); - if (yComparison != 0) return yComparison; + if (yComparison != 0) + { + return yComparison; + } + return m_Z.CompareTo(other.Z); } } diff --git a/Projects/Server/Geometry/Point3DList.cs b/Projects/Server/Geometry/Point3DList.cs index 784290ec0..6db81bcc8 100644 --- a/Projects/Server/Geometry/Point3DList.cs +++ b/Projects/Server/Geometry/Point3DList.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Point3DList.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server @@ -52,7 +32,9 @@ namespace Server m_List = new Point3D[old.Length * 2]; for (var i = 0; i < old.Length; ++i) + { m_List[i] = old[i]; + } } m_List[Count].m_X = x; @@ -69,7 +51,9 @@ namespace Server m_List = new Point3D[old.Length * 2]; for (var i = 0; i < old.Length; ++i) + { m_List[i] = old[i]; + } } m_List[Count].m_X = p.m_X; @@ -81,12 +65,16 @@ namespace Server public Point3D[] ToArray() { if (Count == 0) + { return m_EmptyList; + } var list = new Point3D[Count]; for (var i = 0; i < Count; ++i) + { list[i] = m_List[i]; + } Count = 0; diff --git a/Projects/Server/Geometry/Rectangle2D.cs b/Projects/Server/Geometry/Rectangle2D.cs index 8dfa58fba..52ced65bb 100644 --- a/Projects/Server/Geometry/Rectangle2D.cs +++ b/Projects/Server/Geometry/Rectangle2D.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Rectangle2D.cs * * * @@ -111,16 +111,24 @@ namespace Server public void MakeHold(Rectangle2D r) { if (r.m_Start.m_X < m_Start.m_X) + { m_Start.m_X = r.m_Start.m_X; + } if (r.m_Start.m_Y < m_Start.m_Y) + { m_Start.m_Y = r.m_Start.m_Y; + } if (r.m_End.m_X > m_End.m_X) + { m_End.m_X = r.m_End.m_X; + } if (r.m_End.m_Y > m_End.m_Y) + { m_End.m_Y = r.m_End.m_Y; + } } public bool Contains(Point3D p) => diff --git a/Projects/Server/Geometry/Rectangle3D.cs b/Projects/Server/Geometry/Rectangle3D.cs index 3ff8869a6..a98869c31 100644 --- a/Projects/Server/Geometry/Rectangle3D.cs +++ b/Projects/Server/Geometry/Rectangle3D.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Rectangle3D.cs * * * @@ -81,22 +81,34 @@ namespace Server public void MakeHold(Rectangle3D r) { if (r.m_Start.m_X < m_Start.m_X) + { m_Start.m_X = r.m_Start.m_X; + } if (r.m_Start.m_Y < m_Start.m_Y) + { m_Start.m_Y = r.m_Start.m_Y; + } if (r.m_Start.m_Z < m_Start.m_Z) + { m_Start.m_Z = r.m_Start.m_Z; + } if (r.m_End.m_X > m_End.m_X) + { m_End.m_X = r.m_End.m_X; + } if (r.m_End.m_Y > m_End.m_Y) + { m_End.m_Y = r.m_End.m_Y; + } if (r.m_End.m_Z < m_End.m_Z) + { m_End.m_Z = r.m_End.m_Z; + } } public bool Contains(Point3D p) => diff --git a/Projects/Server/Geometry/WorldLocation.cs b/Projects/Server/Geometry/WorldLocation.cs index 97a8c1d42..2a7fa4597 100644 --- a/Projects/Server/Geometry/WorldLocation.cs +++ b/Projects/Server/Geometry/WorldLocation.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: WorldLocation.cs * * * @@ -104,7 +104,11 @@ namespace Server public int CompareTo(WorldLocation other) { var locComparison = m_Loc.CompareTo(other.m_Loc); - if (locComparison != 0) return locComparison; + if (locComparison != 0) + { + return locComparison; + } + return Comparer.Default.Compare(m_Map, other.m_Map); } diff --git a/Projects/Server/Guild.cs b/Projects/Server/Guild.cs index ce378865a..aa9585c46 100644 --- a/Projects/Server/Guild.cs +++ b/Projects/Server/Guild.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Guild.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Collections.Generic; using System.Linq; @@ -39,7 +19,10 @@ namespace Server.Guilds Serial = id; List.Add(Serial, this); if (Serial + 1 > m_NextID) + { m_NextID = Serial + 1; + } + SaveBuffer = new BufferedFileWriter(true); } @@ -95,7 +78,9 @@ namespace Server.Guilds var name = g.Name.ToLower(); if (words.All(t => name.IndexOf(t) != -1)) + { results.Add(g); + } } return results; diff --git a/Projects/Server/Gumps/Gump.cs b/Projects/Server/Gumps/Gump.cs index 9916492fa..bfd2abdbb 100644 --- a/Projects/Server/Gumps/Gump.cs +++ b/Projects/Server/Gumps/Gump.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Gump.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Text; @@ -232,15 +212,21 @@ namespace Server.Gumps public void Add(GumpEntry g) { if (g.Parent != this) + { g.Parent = this; + } else if (!Entries.Contains(g)) + { Entries.Add(g); + } } public void Remove(GumpEntry g) { if (g == null || !Entries.Contains(g)) + { return; + } Entries.Remove(g); g.Parent = null; @@ -250,7 +236,10 @@ namespace Server.Gumps { var indexOf = Strings.IndexOf(value); - if (indexOf >= 0) return indexOf; + if (indexOf >= 0) + { + return indexOf; + } Strings.Add(value); return Strings.Count - 1; @@ -269,21 +258,33 @@ namespace Server.Gumps IGumpWriter disp; if (ns?.Unpack == true) + { disp = new DisplayGumpPacked(this); + } else + { disp = new DisplayGumpFast(this); + } if (!Draggable) + { disp.AppendLayout(m_NoMove); + } if (!Closable) + { disp.AppendLayout(m_NoClose); + } if (!Disposable) + { disp.AppendLayout(m_NoDispose); + } if (!Resizable) + { disp.AppendLayout(m_NoResize); + } var count = Entries.Count; diff --git a/Projects/Server/Gumps/GumpAlphaRegion.cs b/Projects/Server/Gumps/GumpAlphaRegion.cs index 6e30c9b6e..85fe42cf0 100644 --- a/Projects/Server/Gumps/GumpAlphaRegion.cs +++ b/Projects/Server/Gumps/GumpAlphaRegion.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpAlphaRegion.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpBackground.cs b/Projects/Server/Gumps/GumpBackground.cs index 0d180d301..ed801c820 100644 --- a/Projects/Server/Gumps/GumpBackground.cs +++ b/Projects/Server/Gumps/GumpBackground.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpBackground.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpButton.cs b/Projects/Server/Gumps/GumpButton.cs index 49f59a87b..52e989b39 100644 --- a/Projects/Server/Gumps/GumpButton.cs +++ b/Projects/Server/Gumps/GumpButton.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpButton.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpCheck.cs b/Projects/Server/Gumps/GumpCheck.cs index 91113b903..9c6e93c1d 100644 --- a/Projects/Server/Gumps/GumpCheck.cs +++ b/Projects/Server/Gumps/GumpCheck.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpCheck.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpECHandleInput.cs b/Projects/Server/Gumps/GumpECHandleInput.cs index 809fb0de1..21fa02df3 100644 --- a/Projects/Server/Gumps/GumpECHandleInput.cs +++ b/Projects/Server/Gumps/GumpECHandleInput.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpECHandleInput.cs * * * diff --git a/Projects/Server/Gumps/GumpEntry.cs b/Projects/Server/Gumps/GumpEntry.cs index a1c045ed5..15d3d940b 100644 --- a/Projects/Server/Gumps/GumpEntry.cs +++ b/Projects/Server/Gumps/GumpEntry.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpEntry.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpGroup.cs b/Projects/Server/Gumps/GumpGroup.cs index abbc64579..b3e37cc06 100644 --- a/Projects/Server/Gumps/GumpGroup.cs +++ b/Projects/Server/Gumps/GumpGroup.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpGroup.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpHtml.cs b/Projects/Server/Gumps/GumpHtml.cs index 943064ed6..e2c4e3b2b 100644 --- a/Projects/Server/Gumps/GumpHtml.cs +++ b/Projects/Server/Gumps/GumpHtml.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpHtml.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpHtmlLocalized.cs b/Projects/Server/Gumps/GumpHtmlLocalized.cs index 2a08719f2..ddfd52391 100644 --- a/Projects/Server/Gumps/GumpHtmlLocalized.cs +++ b/Projects/Server/Gumps/GumpHtmlLocalized.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpHtmlLocalized.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpImage.cs b/Projects/Server/Gumps/GumpImage.cs index 42d2f4c32..c2696664b 100644 --- a/Projects/Server/Gumps/GumpImage.cs +++ b/Projects/Server/Gumps/GumpImage.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpImage.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpImageTileButton.cs b/Projects/Server/Gumps/GumpImageTileButton.cs index 62b8cc7e9..411983c53 100644 --- a/Projects/Server/Gumps/GumpImageTileButton.cs +++ b/Projects/Server/Gumps/GumpImageTileButton.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpImageTileButton.cs - * ------------------- - * begin : April 26, 2005 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps @@ -91,8 +71,11 @@ namespace Server.Gumps public override string Compile(NetState ns) { if (LocalizedTooltip > 0) + { return $"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}"; + } + return $"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}"; } diff --git a/Projects/Server/Gumps/GumpImageTiled.cs b/Projects/Server/Gumps/GumpImageTiled.cs index 7955a3e43..bc4b072b1 100644 --- a/Projects/Server/Gumps/GumpImageTiled.cs +++ b/Projects/Server/Gumps/GumpImageTiled.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpImageTiled.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpItem.cs b/Projects/Server/Gumps/GumpItem.cs index a88d9ad01..996e930e3 100644 --- a/Projects/Server/Gumps/GumpItem.cs +++ b/Projects/Server/Gumps/GumpItem.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpItem.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps @@ -54,7 +34,9 @@ namespace Server.Gumps disp.AppendLayout(ItemID); if (Hue != 0) + { disp.AppendLayout(Hue); + } } } } diff --git a/Projects/Server/Gumps/GumpItemProperty.cs b/Projects/Server/Gumps/GumpItemProperty.cs index 5f004d85e..8adefb5c3 100644 --- a/Projects/Server/Gumps/GumpItemProperty.cs +++ b/Projects/Server/Gumps/GumpItemProperty.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpItemProperty.cs - * ------------------- - * begin : May 26, 2013 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpLabel.cs b/Projects/Server/Gumps/GumpLabel.cs index fe58a0b0d..702c6d84b 100644 --- a/Projects/Server/Gumps/GumpLabel.cs +++ b/Projects/Server/Gumps/GumpLabel.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpLabel.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpLabelCropped.cs b/Projects/Server/Gumps/GumpLabelCropped.cs index dae0129b2..58ac425b7 100644 --- a/Projects/Server/Gumps/GumpLabelCropped.cs +++ b/Projects/Server/Gumps/GumpLabelCropped.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpLabelCropped.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpMasterGump.cs b/Projects/Server/Gumps/GumpMasterGump.cs index 2f2c1b239..9847abf21 100644 --- a/Projects/Server/Gumps/GumpMasterGump.cs +++ b/Projects/Server/Gumps/GumpMasterGump.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpMasterGump.cs * * * diff --git a/Projects/Server/Gumps/GumpPage.cs b/Projects/Server/Gumps/GumpPage.cs index 81ad30cd4..e2d90b43e 100644 --- a/Projects/Server/Gumps/GumpPage.cs +++ b/Projects/Server/Gumps/GumpPage.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpPage.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpRadio.cs b/Projects/Server/Gumps/GumpRadio.cs index 69b93ddee..5c2d65a60 100644 --- a/Projects/Server/Gumps/GumpRadio.cs +++ b/Projects/Server/Gumps/GumpRadio.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpRadio.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpSpriteImage.cs b/Projects/Server/Gumps/GumpSpriteImage.cs index 7b3556cdd..f5a88f72f 100644 --- a/Projects/Server/Gumps/GumpSpriteImage.cs +++ b/Projects/Server/Gumps/GumpSpriteImage.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpSpriteImage.cs * * * diff --git a/Projects/Server/Gumps/GumpTextEntry.cs b/Projects/Server/Gumps/GumpTextEntry.cs index b4a0f0847..3b6fa49ce 100644 --- a/Projects/Server/Gumps/GumpTextEntry.cs +++ b/Projects/Server/Gumps/GumpTextEntry.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpTextEntry.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpTextEntryLimited.cs b/Projects/Server/Gumps/GumpTextEntryLimited.cs index c85d6a318..f34f8bf3d 100644 --- a/Projects/Server/Gumps/GumpTextEntryLimited.cs +++ b/Projects/Server/Gumps/GumpTextEntryLimited.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * GumpTextEntryLimited.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Gumps diff --git a/Projects/Server/Gumps/GumpTooltip.cs b/Projects/Server/Gumps/GumpTooltip.cs index 24a92c225..a91b73ea2 100644 --- a/Projects/Server/Gumps/GumpTooltip.cs +++ b/Projects/Server/Gumps/GumpTooltip.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpTooltip.cs * * * diff --git a/Projects/Server/Gumps/RelayInfo.cs b/Projects/Server/Gumps/RelayInfo.cs index 50bf37e3b..7831f2174 100644 --- a/Projects/Server/Gumps/RelayInfo.cs +++ b/Projects/Server/Gumps/RelayInfo.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * RelayInfo.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Gumps { public class TextRelay @@ -51,8 +31,12 @@ namespace Server.Gumps public bool IsSwitched(int switchID) { for (var i = 0; i < Switches.Length; ++i) + { if (Switches[i] == switchID) + { return true; + } + } return false; } @@ -60,8 +44,12 @@ namespace Server.Gumps public TextRelay GetTextEntry(int entryID) { for (var i = 0; i < TextEntries.Length; ++i) + { if (TextEntries[i].EntryID == entryID) + { return TextEntries[i]; + } + } return null; } diff --git a/Projects/Server/HuePicker.cs b/Projects/Server/HuePicker.cs index 658347a9e..1d549467d 100644 --- a/Projects/Server/HuePicker.cs +++ b/Projects/Server/HuePicker.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * HuePicker.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.HuePickers diff --git a/Projects/Server/IAccount.cs b/Projects/Server/IAccount.cs index 3dacc1076..5bf15b2c3 100644 --- a/Projects/Server/IAccount.cs +++ b/Projects/Server/IAccount.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * IAccount.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server.Accounting diff --git a/Projects/Server/IEntity.cs b/Projects/Server/IEntity.cs index c3795a8c8..9e01d5189 100644 --- a/Projects/Server/IEntity.cs +++ b/Projects/Server/IEntity.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * IEntity.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server diff --git a/Projects/Server/Insensitive.cs b/Projects/Server/Insensitive.cs index 1bb022df9..819d2f437 100644 --- a/Projects/Server/Insensitive.cs +++ b/Projects/Server/Insensitive.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Insensitive.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; diff --git a/Projects/Server/Interfaces.cs b/Projects/Server/Interfaces.cs index 1cb6ad885..82aaa451a 100644 --- a/Projects/Server/Interfaces.cs +++ b/Projects/Server/Interfaces.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Interfaces.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server diff --git a/Projects/Server/Items/BaseMulti.cs b/Projects/Server/Items/BaseMulti.cs index 148471c68..1927ffc28 100644 --- a/Projects/Server/Items/BaseMulti.cs +++ b/Projects/Server/Items/BaseMulti.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * BaseMulti.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server.Items @@ -60,7 +40,10 @@ namespace Server.Items int id = mcl.List[0].ItemId; if (id < 0x4000) + { return 1020000 + id; + } + return 1078872 + id; } @@ -129,8 +112,12 @@ namespace Server.Items var version = reader.ReadInt(); if (version == 0) + { if (ItemID >= 0x4000) + { ItemID -= 0x4000; + } + } } } } diff --git a/Projects/Server/Items/Container.cs b/Projects/Server/Items/Container.cs index c592d97bf..a079e36b3 100644 --- a/Projects/Server/Items/Container.cs +++ b/Projects/Server/Items/Container.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Container.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.IO; @@ -71,7 +51,9 @@ namespace Server.Items get { if (m_ContainerData == null) + { UpdateContainerData(); + } return m_ContainerData; } @@ -89,7 +71,9 @@ namespace Server.Items base.ItemID = value; if (ItemID != oldID) + { UpdateContainerData(); + } } } @@ -123,7 +107,10 @@ namespace Server.Items { get { - if (Parent is Container container && container.MaxWeight == 0) return 0; + if (Parent is Container container && container.MaxWeight == 0) + { + return 0; + } return DefaultMaxWeight; } @@ -206,7 +193,9 @@ namespace Server.Items if (IsDecoContainer) { if (message) + { SendCantStoreMessage(m, item); + } return false; } @@ -217,7 +206,9 @@ namespace Server.Items TotalItems + plusItems + item.TotalItems + (item.IsVirtualItem ? 0 : 1) > maxItems) { if (message) + { SendFullItemsMessage(m, item); + } return false; } @@ -225,7 +216,9 @@ namespace Server.Items if (MaxWeight != 0 && TotalWeight + plusWeight + item.TotalWeight + item.PileWeight > MaxWeight) { if (message) + { SendFullWeightMessage(m, item); + } return false; } @@ -236,10 +229,14 @@ namespace Server.Items while (parent != null) { if (parent is Container container) + { return container.CheckHold(m, item, message, checkItems, plusItems, plusWeight); + } if (!(parent is Item parentItem)) + { break; + } parent = parentItem.Parent; } @@ -265,7 +262,9 @@ namespace Server.Items public virtual bool OnDragDropInto(Mobile from, Item item, Point3D p) { if (!CheckHold(from, item, true, true)) + { return false; + } item.Location = new Point3D(p.m_X, p.m_Y, 0); AddItem(item); @@ -280,8 +279,12 @@ namespace Server.Items var t = item.GetType(); for (var i = 0; i < types.Length; ++i) + { if (types[i].IsAssignableFrom(t)) + { return true; + } + } return false; } @@ -289,7 +292,9 @@ namespace Server.Items private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf) { if (setIf) + { flags |= toSet; + } } private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet) => (flags & toGet) != 0; @@ -310,13 +315,19 @@ namespace Server.Items writer.Write((byte)flags); if (GetSaveFlag(flags, SaveFlag.MaxItems)) + { writer.WriteEncodedInt(m_MaxItems); + } if (GetSaveFlag(flags, SaveFlag.GumpID)) + { writer.WriteEncodedInt(m_GumpID); + } if (GetSaveFlag(flags, SaveFlag.DropSound)) + { writer.WriteEncodedInt(m_DropSound); + } } public override void Deserialize(IGenericReader reader) @@ -332,19 +343,31 @@ namespace Server.Items var flags = (SaveFlag)reader.ReadByte(); if (GetSaveFlag(flags, SaveFlag.MaxItems)) + { m_MaxItems = reader.ReadEncodedInt(); + } else + { m_MaxItems = -1; + } if (GetSaveFlag(flags, SaveFlag.GumpID)) + { m_GumpID = reader.ReadEncodedInt(); + } else + { m_GumpID = -1; + } if (GetSaveFlag(flags, SaveFlag.DropSound)) + { m_DropSound = reader.ReadEncodedInt(); + } else + { m_DropSound = -1; + } LiftOverride = GetSaveFlag(flags, SaveFlag.LiftOverride); @@ -358,19 +381,27 @@ namespace Server.Items case 0: { if (version < 1) + { m_MaxItems = GlobalMaxItems; + } m_GumpID = reader.ReadInt(); m_DropSound = reader.ReadInt(); if (m_GumpID == DefaultGumpID) + { m_GumpID = -1; + } if (m_DropSound == DefaultDropSound) + { m_DropSound = -1; + } if (m_MaxItems == DefaultMaxItems) + { m_MaxItems = -1; + } // m_Bounds = new Rectangle2D( reader.ReadPoint2D(), reader.ReadPoint2D() ); reader.ReadPoint2D(); @@ -397,6 +428,7 @@ namespace Server.Items public override void UpdateTotal(Item sender, TotalType type, int delta) { if (sender != this && delta != 0 && !sender.IsVirtualItem) + { switch (type) { case TotalType.Gold: @@ -413,6 +445,7 @@ namespace Server.Items InvalidateProperties(); break; } + } base.UpdateTotal(sender, type, delta); } @@ -426,7 +459,9 @@ namespace Server.Items var items = m_Items; if (items == null) + { return; + } for (var i = 0; i < items.Count; ++i) { @@ -435,7 +470,9 @@ namespace Server.Items item.UpdateTotals(); if (item.IsVirtualItem) + { continue; + } m_TotalGold += item.TotalGold; m_TotalItems += item.TotalItems + 1; @@ -471,7 +508,9 @@ namespace Server.Items if (!(item is Container) && CheckHold(from, dropped, false, false) && item.StackWith(from, dropped, playSound)) + { return true; + } } if (CheckHold(from, dropped, sendFullMessage, true)) @@ -525,10 +564,14 @@ namespace Server.Items if (dropItems.Count + stackItems.Count == droppedItems.Length) // All good { for (var i = 0; i < dropItems.Count; i++) + { DropItem(dropItems[i]); + } for (var i = 0; i < stackItems.Count; i++) - stackItems[i].m_StackItem.StackWith(from, stackItems[i].m_DropItem, false); + { + stackItems[i].m_StackItem.StackWith(@from, stackItems[i].m_DropItem, false); + } return true; } @@ -542,11 +585,13 @@ namespace Server.Items var map = Map; for (var i = Items.Count - 1; i >= 0; --i) + { if (i < Items.Count) { Items[i].SetLastMoved(); Items[i].MoveToWorld(loc, map); } + } Delete(); } @@ -554,7 +599,9 @@ namespace Server.Items public virtual void DropItem(Item dropped) { if (dropped == null) + { return; + } AddItem(dropped); @@ -564,14 +611,22 @@ namespace Server.Items int x, y; if (bounds.Width >= ourBounds.Width) + { x = (ourBounds.Width - bounds.Width) / 2; + } else + { x = Utility.Random(ourBounds.Width - bounds.Width); + } if (bounds.Height >= ourBounds.Height) + { y = (ourBounds.Height - bounds.Height) / 2; + } else + { y = Utility.Random(ourBounds.Height - bounds.Height); + } x += ourBounds.X; x -= bounds.X; @@ -593,9 +648,13 @@ namespace Server.Items if (trade != null) { if (trade.From.Mobile == from) + { DisplayTo(trade.To.Mobile); + } else if (trade.To.Mobile == from) + { DisplayTo(trade.From.Mobile); + } } } else @@ -614,7 +673,10 @@ namespace Server.Items base.OnSingleClick(from); if (CheckContentDisplay(from)) - LabelTo(from, "({0} item{2}, {1} stones)", TotalItems, TotalWeight, TotalItems != 1 ? "s" : string.Empty); + { + LabelTo(@from, "({0} item{2}, {1} stones)", TotalItems, TotalWeight, TotalItems != 1 ? "s" : string.Empty); + } + // LabelTo( from, 1050044, String.Format( "{0}\t{1}", TotalItems.ToString(), TotalWeight.ToString() ) ); } @@ -634,9 +696,13 @@ namespace Server.Items if (ns != null) { if (ns.HighSeas) + { to.Send(new ContainerDisplayHS(Serial, GumpID)); + } else + { to.Send(new ContainerDisplay(Serial, GumpID)); + } SendContentTo(ns); @@ -645,7 +711,9 @@ namespace Server.Items var items = Items; for (var i = 0; i < items.Count; ++i) + { to.Send(items[i].OPLPacket); + } } } } @@ -653,7 +721,9 @@ namespace Server.Items public void ProcessOpeners(Mobile opener) { if (IsPublicContainer) + { return; + } var contains = false; @@ -675,7 +745,9 @@ namespace Server.Items var range = GetUpdateRange(mob); if (mob.Map != map || !mob.InRange(worldLoc, range)) + { Openers.RemoveAt(i--); + } } } } @@ -695,12 +767,18 @@ namespace Server.Items public virtual void SendContentTo(NetState state) { if (state == null) + { return; + } if (state.ContainerGridLines) + { state.Send(new ContainerContent6017(state.Mobile, this)); + } else + { state.Send(new ContainerContent(state.Mobile, this)); + } } public override void GetProperties(ObjectPropertyList list) @@ -712,6 +790,7 @@ namespace Server.Items if (Core.ML) { if (ParentsContain()) // Root Parent is the Mobile. Parent could be another containter. + { list.Add( 1073841, "{0}\t{1}\t{2}", @@ -719,7 +798,9 @@ namespace Server.Items MaxItems, TotalWeight ); // Contents: ~1_COUNT~/~2_MAXCOUNT~ items, ~3_WEIGHT~ stones + } else + { list.Add( 1072241, "{0}\t{1}\t{2}\t{3}", @@ -728,6 +809,7 @@ namespace Server.Items TotalWeight, MaxWeight ); // Contents: ~1_COUNT~/~2_MAXCOUNT~ items, ~3_WEIGHT~/~4_MAXWEIGHT~ stones + } // TODO: Where do the other clilocs come into play? 1073839 & 1073840? } @@ -741,15 +823,21 @@ namespace Server.Items public override void OnDoubleClick(Mobile from) { if (from.AccessLevel > AccessLevel.Player || from.InRange(GetWorldLocation(), 2)) - DisplayTo(from); + { + DisplayTo(@from); + } else - from.SendLocalizedMessage(500446); // That is too far away. + { + @from.SendLocalizedMessage(500446); // That is too far away. + } } public bool ConsumeTotalGrouped(Type type, int amount, bool recurse, OnItemConsumed callback, CheckItemGroup grouper) { if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var typedItems = FindItemsByType(type, recurse); @@ -769,9 +857,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -789,16 +881,23 @@ namespace Server.Items items[i] = groups[i].ToArray(); for (var j = 0; j < items[i].Length; ++j) + { totals[i] += items[i][j].Amount; + } if (totals[i] >= amount) + { hasEnough = true; + } } if (!hasEnough) + { return false; + } for (var i = 0; i < items.Length; ++i) + { if (totals[i] >= amount) { var need = amount; @@ -827,6 +926,7 @@ namespace Server.Items break; } + } return true; } @@ -837,9 +937,14 @@ namespace Server.Items ) { if (types.Length != amounts.Length) + { throw new ArgumentException("length of types and amounts must match"); + } + if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var items = new Item[types.Length][][]; var totals = new int[types.Length][]; @@ -864,9 +969,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -884,18 +993,26 @@ namespace Server.Items items[i][j] = groups[j].ToArray(); for (var k = 0; k < items[i][j].Length; ++k) + { totals[i][j] += items[i][j][k].Amount; + } if (totals[i][j] >= amounts[i]) + { hasEnough = true; + } } if (!hasEnough) + { return i; + } } for (var i = 0; i < items.Length; ++i) + { for (var j = 0; j < items[i].Length; ++j) + { if (totals[i][j] >= amounts[i]) { var need = amounts[i]; @@ -924,6 +1041,8 @@ namespace Server.Items break; } + } + } return -1; } @@ -934,9 +1053,14 @@ namespace Server.Items ) { if (types.Length != amounts.Length) + { throw new ArgumentException("length of types and amounts must match"); + } + if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var items = new Item[types.Length][][]; var totals = new int[types.Length][]; @@ -961,9 +1085,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -981,18 +1109,26 @@ namespace Server.Items items[i][j] = groups[j].ToArray(); for (var k = 0; k < items[i][j].Length; ++k) + { totals[i][j] += items[i][j][k].Amount; + } if (totals[i][j] >= amounts[i]) + { hasEnough = true; + } } if (!hasEnough) + { return i; + } } for (var i = 0; i < items.Length; ++i) + { for (var j = 0; j < items[i].Length; ++j) + { if (totals[i][j] >= amounts[i]) { var need = amounts[i]; @@ -1021,6 +1157,8 @@ namespace Server.Items break; } + } + } return -1; } @@ -1028,7 +1166,9 @@ namespace Server.Items public int ConsumeTotal(Type[][] types, int[] amounts, bool recurse = true, OnItemConsumed callback = null) { if (types.Length != amounts.Length) + { throw new ArgumentException("length of types and amounts must match"); + } var items = new Item[types.Length][]; var totals = new int[types.Length]; @@ -1038,10 +1178,14 @@ namespace Server.Items items[i] = FindItemsByType(types[i], recurse); for (var j = 0; j < items[i].Length; ++j) + { totals[i] += items[i][j].Amount; + } if (totals[i] < amounts[i]) + { return i; + } } for (var i = 0; i < types.Length; ++i) @@ -1077,7 +1221,9 @@ namespace Server.Items public int ConsumeTotal(Type[] types, int[] amounts, bool recurse = true, OnItemConsumed callback = null) { if (types.Length != amounts.Length) + { throw new ArgumentException("length of types and amounts must match"); + } var items = new Item[types.Length][]; var totals = new int[types.Length]; @@ -1087,10 +1233,14 @@ namespace Server.Items items[i] = FindItemsByType(types[i], recurse); for (var j = 0; j < items[i].Length; ++j) + { totals[i] += items[i][j].Amount; + } if (totals[i] < amounts[i]) + { return i; + } } for (var i = 0; i < types.Length; ++i) @@ -1131,7 +1281,9 @@ namespace Server.Items var total = 0; for (var i = 0; i < items.Length; ++i) + { total += items[i].Amount; + } if (total >= amount) { @@ -1175,7 +1327,9 @@ namespace Server.Items RecurseConsumeUpTo(this, type, amount, recurse, ref consumed, toDelete); while (toDelete.Count > 0) + { toDelete.Dequeue().Delete(); + } return consumed; } @@ -1186,7 +1340,9 @@ namespace Server.Items ) { if (current == null || current.Items.Count == 0) + { return; + } var list = current.Items; @@ -1222,7 +1378,9 @@ namespace Server.Items public int GetBestGroupAmount(Type type, bool recurse, CheckItemGroup grouper) { if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var best = 0; @@ -1244,9 +1402,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -1261,10 +1423,14 @@ namespace Server.Items var total = 0; for (var j = 0; j < items.Length; ++j) + { total += items[j].Amount; + } if (total >= best) + { best = total; + } } return best; @@ -1273,7 +1439,9 @@ namespace Server.Items public int GetBestGroupAmount(Type[] types, bool recurse, CheckItemGroup grouper) { if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var best = 0; @@ -1295,9 +1463,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -1311,7 +1483,9 @@ namespace Server.Items var total = items.Sum(t => t.Amount); if (total >= best) + { best = total; + } } return best; @@ -1320,7 +1494,9 @@ namespace Server.Items public int GetBestGroupAmount(Type[][] types, bool recurse, CheckItemGroup grouper) { if (grouper == null) + { throw new ArgumentNullException(nameof(grouper)); + } var best = 0; @@ -1344,9 +1520,13 @@ namespace Server.Items var v = grouper(a, b); if (v == 0) - group.Add(b); + { + @group.Add(b); + } else + { break; + } ++idx; } @@ -1360,10 +1540,14 @@ namespace Server.Items var total = 0; for (var k = 0; k < items.Length; ++k) + { total += items[k].Amount; + } if (total >= best) + { best = total; + } } } @@ -1377,7 +1561,9 @@ namespace Server.Items public Item[] FindItemsByType(Type type, bool recurse = true) { if (m_FindItemsList.Count > 0) + { m_FindItemsList.Clear(); + } RecurseFindItemsByType(this, type, recurse, m_FindItemsList); @@ -1387,7 +1573,9 @@ namespace Server.Items private static void RecurseFindItemsByType(Item current, Type type, bool recurse, List list) { if (current == null || current.Items.Count == 0) + { return; + } var items = current.Items; @@ -1396,17 +1584,23 @@ namespace Server.Items var item = items[i]; if (type.IsInstanceOfType(item)) + { list.Add(item); + } if (recurse && item is Container) + { RecurseFindItemsByType(item, type, true, list); + } } } public Item[] FindItemsByType(Type[] types, bool recurse = true) { if (m_FindItemsList.Count > 0) + { m_FindItemsList.Clear(); + } RecurseFindItemsByType(this, types, recurse, m_FindItemsList); @@ -1416,7 +1610,9 @@ namespace Server.Items private static void RecurseFindItemsByType(Item current, Type[] types, bool recurse, List list) { if (current == null || current.Items.Count == 0) + { return; + } var items = current.Items; @@ -1425,10 +1621,14 @@ namespace Server.Items var item = items[i]; if (InTypeList(item, types)) + { list.Add(item); + } if (recurse && item is Container) + { RecurseFindItemsByType(item, types, true, list); + } } } @@ -1437,7 +1637,9 @@ namespace Server.Items private static Item RecurseFindItemByType(Item current, Type type, bool recurse) { if (current == null || current.Items.Count == 0) + { return null; + } var list = current.Items; @@ -1446,14 +1648,18 @@ namespace Server.Items var item = list[i]; if (type.IsInstanceOfType(item)) + { return item; + } if (recurse && item is Container) { var check = RecurseFindItemByType(item, type, true); if (check != null) + { return check; + } } } @@ -1465,7 +1671,9 @@ namespace Server.Items private static Item RecurseFindItemByType(Item current, Type[] types, bool recurse) { if (current == null || current.Items.Count == 0) + { return null; + } var list = current.Items; @@ -1473,14 +1681,19 @@ namespace Server.Items { var item = list[i]; - if (InTypeList(item, types)) return item; + if (InTypeList(item, types)) + { + return item; + } if (recurse && item is Container) { var check = RecurseFindItemByType(item, types, true); if (check != null) + { return check; + } } } @@ -1517,10 +1730,16 @@ namespace Server.Items { var container = queue.Dequeue(); foreach (var item in container.Items) + { if (item is T typedItem && predicate?.Invoke(typedItem) != false) + { items.Add(typedItem); + } else if (recurse && item is Container itemContainer) + { queue.Enqueue(itemContainer); + } + } } return items; @@ -1556,9 +1775,14 @@ namespace Server.Items foreach (var item in container.Items) { if (item is T typedItem && predicate?.Invoke(typedItem) != false) + { return typedItem; + } + if (recurse && item is Container itemContainer) + { queue.Enqueue(itemContainer); + } } } @@ -1623,7 +1847,9 @@ namespace Server.Items line = line.Trim(); if (line.Length == 0 || line.StartsWith("#")) + { continue; + } try { @@ -1635,7 +1861,9 @@ namespace Server.Items var aRect = split[1].Split(' '); if (aRect.Length < 4) + { continue; + } var x = Utility.ToInt32(aRect[0]); var y = Utility.ToInt32(aRect[1]); @@ -1659,9 +1887,13 @@ namespace Server.Items var id = Utility.ToInt32(aIDs[i]); if (m_Table.ContainsKey(id)) + { Console.WriteLine(@"Warning: double ItemID entry in Data\containers.cfg"); + } else + { m_Table[id] = data; + } } } } diff --git a/Projects/Server/Items/Containers.cs b/Projects/Server/Items/Containers.cs index 5c703642c..e327e3258 100644 --- a/Projects/Server/Items/Containers.cs +++ b/Projects/Server/Items/Containers.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Containers.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Accounting; using Server.Network; @@ -88,14 +68,18 @@ namespace Server.Items Opened = reader.ReadBool(); if (Owner == null) + { Delete(); + } break; } } if (ItemID == 0xE41) + { ItemID = 0xE7C; + } } public void Close() @@ -103,7 +87,9 @@ namespace Server.Items Opened = false; if (SendDeleteOnClose) + { Owner?.Send(RemovePacket); + } } public override void OnSingleClick(Mobile from) @@ -129,7 +115,9 @@ namespace Server.Items public override int GetTotal(TotalType type) { if (AccountGold.Enabled && Owner?.Account != null && type == TotalType.Gold) + { return Owner.Account.TotalGold; + } return base.GetTotal(type); } diff --git a/Projects/Server/Item.cs b/Projects/Server/Items/Item.cs similarity index 88% rename from Projects/Server/Item.cs rename to Projects/Server/Items/Item.cs index 27f1bcbb3..9cf08fc5e 100644 --- a/Projects/Server/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Item.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Diagnostics; @@ -141,11 +121,17 @@ namespace Server Serial serial = reader.ReadUInt(); if (serial.IsItem) + { parent = World.FindItem(serial); + } else if (serial.IsMobile) + { parent = World.FindMobile(serial); + } else + { parent = null; + } return new BounceInfo(map, loc, worldLoc, parent); } @@ -168,11 +154,17 @@ namespace Server writer.Write(info.WorldLoc); if (info.Parent is Mobile mobile) + { writer.Write(mobile); + } else if (info.Parent is Item item) + { writer.Write(item); + } else + { writer.Write((Serial)0); + } } } } @@ -282,7 +274,9 @@ namespace Server info.m_TempFlags = value; if (info.m_TempFlags == 0) + { VerifyCompactInfo(); + } } } @@ -296,7 +290,9 @@ namespace Server info.m_SavedFlags = value; if (info.m_SavedFlags == 0) + { VerifyCompactInfo(); + } } } @@ -313,7 +309,9 @@ namespace Server info.m_HeldBy = value; if (info.m_HeldBy == null) + { VerifyCompactInfo(); + } } } @@ -333,7 +331,9 @@ namespace Server m_LootType = value; if (DisplayLootType) + { InvalidateProperties(); + } } } } @@ -390,7 +390,9 @@ namespace Server var m = state.Mobile; if (!m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m))) + { state.Send(RemovePacket); + } } eable.Free(); @@ -451,7 +453,9 @@ namespace Server get { if (m_ItemID < 0x4000) + { return 1020000 + m_ItemID; + } return 1078872 + m_ItemID; } @@ -471,12 +475,16 @@ namespace Server get { if (m_ItemID < 0 || m_ItemID > TileData.MaxItemValue || this is BaseMulti) + { return 0; + } var weight = TileData.ItemTable[m_ItemID].Weight; if (weight == 255 || weight == 0) + { weight = 1; + } return weight; } @@ -502,7 +510,9 @@ namespace Server info.m_Weight = value; if (info.m_Weight == -1) + { VerifyCompactInfo(); + } var newPileWeight = PileWeight; @@ -561,7 +571,10 @@ namespace Server while (p is Item item) { - if (item.m_Parent == null) break; + if (item.m_Parent == null) + { + break; + } p = item.m_Parent; } @@ -616,7 +629,9 @@ namespace Server info.m_Name = value; if (info.m_Name == null) + { VerifyCompactInfo(); + } InvalidateProperties(); } @@ -630,7 +645,9 @@ namespace Server set { if (m_Parent == value) + { return; + } var oldParent = m_Parent; @@ -639,9 +656,13 @@ namespace Server if (m_Map != null) { if (oldParent != null && m_Parent == null) + { m_Map.OnEnter(this); + } else if (m_Parent != null) + { m_Map.OnLeave(this); + } } } } @@ -702,15 +723,19 @@ namespace Server Delta(ItemDelta.Update); if (oldValue > 1 || value > 1) + { InvalidateProperties(); + } if (!Stackable && m_Amount > 1) + { Console.WriteLine( "Warning: 0x{0:X}: Amount changed for non-stackable item '{2}'. ({1})", Serial.Value, m_Amount, GetType().Name ); + } } } } @@ -770,7 +795,9 @@ namespace Server info.m_BlessedFor = value; if (info.m_BlessedFor == null) + { VerifyCompactInfo(); + } InvalidateProperties(); } @@ -823,13 +850,19 @@ namespace Server if (x != 0 || y != 0) { if (x >= byte.MinValue && x <= byte.MaxValue && y >= byte.MinValue && y <= byte.MaxValue) + { flags |= SaveFlag.LocationByteXY; + } else + { flags |= SaveFlag.LocationShortXY; + } } if (z != 0) + { flags |= SaveFlag.LocationSByteZ; + } } else { @@ -841,38 +874,78 @@ namespace Server var items = LookupItems(); if (m_Direction != Direction.North) + { flags |= SaveFlag.Direction; + } + if (info?.m_Bounce != null) + { flags |= SaveFlag.Bounce; + } + if (m_LootType != LootType.Regular) + { flags |= SaveFlag.LootType; + } + if (m_ItemID != 0) + { flags |= SaveFlag.ItemID; + } + if (m_Hue != 0) + { flags |= SaveFlag.Hue; + } + if (m_Amount != 1) + { flags |= SaveFlag.Amount; + } + if (m_Layer != Layer.Invalid) + { flags |= SaveFlag.Layer; + } + if (info?.m_Name != null) + { flags |= SaveFlag.Name; + } + if (m_Parent != null) + { flags |= SaveFlag.Parent; + } + if (items != null && items.Count > 0) + { flags |= SaveFlag.Items; + } + if (m_Map != Map.Internal) + { flags |= SaveFlag.Map; + } // if (m_InsuredFor != null && !m_InsuredFor.Deleted) // flags |= SaveFlag.InsuredFor; if (info != null) { if (info.m_BlessedFor?.Deleted == false) + { flags |= SaveFlag.BlessedFor; + } + if (info.m_HeldBy?.Deleted == false) + { flags |= SaveFlag.HeldBy; + } + if (info.m_SavedFlags != 0) + { flags |= SaveFlag.SavedFlags; + } } if (info == null || info.m_Weight == -1.0) @@ -888,9 +961,13 @@ namespace Server else if (info.m_Weight != 1.0) { if (info.m_Weight == (int)info.m_Weight) + { flags |= SaveFlag.IntWeight; + } else + { flags |= SaveFlag.WeightNot1or0; + } } } @@ -898,7 +975,9 @@ namespace Server ImplFlag.PaidInsurance | ImplFlag.QuestItem); if (implFlags != (ImplFlag.Visible | ImplFlag.Movable)) + { flags |= SaveFlag.ImplFlags; + } writer.Write((int)flags); @@ -912,13 +991,19 @@ namespace Server /* end */ if (GetSaveFlag(flags, SaveFlag.Direction)) + { writer.Write((byte)m_Direction); + } if (GetSaveFlag(flags, SaveFlag.Bounce)) + { BounceInfo.Serialize(info?.m_Bounce, writer); + } if (GetSaveFlag(flags, SaveFlag.LootType)) + { writer.Write((byte)m_LootType); + } if (GetSaveFlag(flags, SaveFlag.LocationFull)) { @@ -940,57 +1025,91 @@ namespace Server } if (GetSaveFlag(flags, SaveFlag.LocationSByteZ)) + { writer.Write((sbyte)z); + } } if (GetSaveFlag(flags, SaveFlag.ItemID)) + { writer.WriteEncodedInt(m_ItemID); + } if (GetSaveFlag(flags, SaveFlag.Hue)) + { writer.WriteEncodedInt(m_Hue); + } if (GetSaveFlag(flags, SaveFlag.Amount)) + { writer.WriteEncodedInt(m_Amount); + } if (GetSaveFlag(flags, SaveFlag.Layer)) + { writer.Write((byte)m_Layer); + } if (GetSaveFlag(flags, SaveFlag.Name)) + { writer.Write(info.m_Name); + } if (GetSaveFlag(flags, SaveFlag.Parent)) { if (m_Parent?.Deleted == false) + { writer.Write(m_Parent.Serial); + } else + { writer.Write(Serial.MinusOne); + } } if (GetSaveFlag(flags, SaveFlag.Items)) + { writer.Write(items, false); + } if (GetSaveFlag(flags, SaveFlag.IntWeight)) + { writer.WriteEncodedInt((int)info.m_Weight); + } else if (GetSaveFlag(flags, SaveFlag.WeightNot1or0)) + { writer.Write(info.m_Weight); + } if (GetSaveFlag(flags, SaveFlag.Map)) + { writer.Write(m_Map); + } if (GetSaveFlag(flags, SaveFlag.ImplFlags)) + { writer.WriteEncodedInt((int)implFlags); + } if (GetSaveFlag(flags, SaveFlag.InsuredFor)) + { writer.Write((Mobile)null); + } if (GetSaveFlag(flags, SaveFlag.BlessedFor)) + { writer.Write(info.m_BlessedFor); + } if (GetSaveFlag(flags, SaveFlag.HeldBy)) + { writer.Write(info.m_HeldBy); + } if (GetSaveFlag(flags, SaveFlag.SavedFlags)) + { writer.WriteEncodedInt(info.m_SavedFlags); + } } int IComparable.CompareTo(IEntity other) => other == null ? -1 : Serial.CompareTo(other.Serial); @@ -1001,7 +1120,9 @@ namespace Server public void MoveToWorld(Point3D location, Map map) { if (Deleted) + { return; + } var oldLocation = GetWorldLocation(); var oldRealLocation = m_Location; @@ -1009,9 +1130,13 @@ namespace Server SetLastMoved(); if (Parent is Mobile mobile) + { mobile.RemoveItem(this); + } else if (Parent is Item item) + { item.RemoveItem(this); + } if (m_Map != map) { @@ -1030,7 +1155,9 @@ namespace Server var m = state.Mobile; if (m.InRange(oldLocation, GetUpdateRange(m))) + { state.Send(RemovePacket); + } } eable.Free(); @@ -1045,8 +1172,12 @@ namespace Server var items = LookupItems(); if (items != null) + { for (var i = 0; i < items.Count; ++i) + { items[i].Map = map; + } + } m_Map = map; m_Map?.OnEnter(this); @@ -1062,7 +1193,9 @@ namespace Server var m = state.Mobile; if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m))) + { SendInfoTo(state); + } } eable.Free(); @@ -1071,7 +1204,9 @@ namespace Server RemDelta(ItemDelta.Update); if (old == null || old == Map.Internal) + { InvalidateProperties(); + } } else if (m_Map != null) { @@ -1085,7 +1220,10 @@ namespace Server { var m = state.Mobile; - if (!m.InRange(location, GetUpdateRange(m))) state.Send(RemovePacket); + if (!m.InRange(location, GetUpdateRange(m))) + { + state.Send(RemovePacket); + } } eable.Free(); @@ -1105,7 +1243,9 @@ namespace Server var m = state.Mobile; if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m))) + { SendInfoTo(state); + } } eable.Free(); @@ -1145,20 +1285,28 @@ namespace Server var items = LookupItems(); if (items != null) + { for (var i = 0; i < items.Count; ++i) + { items[i].Map = value; + } + } m_Map = value; if (m_Parent == null) + { m_Map?.OnEnter(this); + } Delta(ItemDelta.Update); OnMapChange(); if (old == null || old == Map.Internal) + { InvalidateProperties(); + } } } } @@ -1173,7 +1321,9 @@ namespace Server var map = m_Map; if (map == null || Deleted) + { return; + } var worldLoc = GetWorldLocation(); var update = (flags & ItemDelta.Update) != 0; @@ -1190,12 +1340,18 @@ namespace Server if (ns != null && rootParent.CanSee(this) && rootParent.InRange(worldLoc, GetUpdateRange(rootParent))) { if (ns.ContainerGridLines) + { ns.Send(new ContainerContentUpdate6017(this)); + } else + { ns.Send(new ContainerContentUpdate(this)); + } if (ObjectPropertyList.Enabled) + { ns.Send(OPLPacket); + } } } @@ -1206,30 +1362,41 @@ namespace Server var test = st.From.Mobile; if (test != null && test != rootParent) + { tradeRecip = test; + } test = st.To.Mobile; if (test != null && test != rootParent) + { tradeRecip = test; + } var ns = tradeRecip?.NetState; if (ns != null && tradeRecip.CanSee(this) && tradeRecip.InRange(worldLoc, GetUpdateRange(tradeRecip))) { if (ns.ContainerGridLines) + { ns.Send(new ContainerContentUpdate6017(this)); + } else + { ns.Send(new ContainerContentUpdate(this)); + } if (ObjectPropertyList.Enabled) + { ns.Send(OPLPacket); + } } } var openers = contParent.Openers; if (openers != null) + { lock (openers) { for (var i = 0; i < openers.Count; ++i) @@ -1245,26 +1412,37 @@ namespace Server else { if (mob == rootParent || mob == tradeRecip) + { continue; + } var ns = mob.NetState; if (ns != null && mob.CanSee(this)) { if (ns.ContainerGridLines) + { ns.Send(new ContainerContentUpdate6017(this)); + } else + { ns.Send(new ContainerContentUpdate(this)); + } if (ObjectPropertyList.Enabled) + { ns.Send(OPLPacket); + } } } } if (openers.Count == 0) + { contParent.Openers = null; + } } + } return; } @@ -1277,7 +1455,10 @@ namespace Server { var m = state.Mobile; - if (!m.CanSee(this) || !m.InRange(worldLoc, GetUpdateRange(m))) continue; + if (!m.CanSee(this) || !m.InRange(worldLoc, GetUpdateRange(m))) + { + continue; + } if (update) { @@ -1294,9 +1475,13 @@ namespace Server else if (m_Parent is Item) { if (state.ContainerGridLines) + { state.Send(new ContainerContentUpdate6017(this)); + } else + { state.Send(new ContainerContentUpdate(this)); + } } else if (m_Parent is Mobile) { @@ -1307,7 +1492,9 @@ namespace Server } if (ObjectPropertyList.Enabled) + { state.Send(OPLPacket); + } } } else if ((flags & ItemDelta.EquipOnly) != 0 && m_Parent is Mobile) @@ -1315,7 +1502,9 @@ namespace Server state.Send(p ??= Packet.Acquire(new EquipUpdate(this))); if (ObjectPropertyList.Enabled) + { state.Send(OPLPacket); + } } else if (ObjectPropertyList.Enabled && (flags & ItemDelta.Properties) != 0) { @@ -1330,32 +1519,47 @@ namespace Server public virtual void Delete() { if (Deleted || !World.OnDelete(this)) + { return; + } OnDelete(); var items = LookupItems(); if (items != null) + { for (var i = items.Count - 1; i >= 0; --i) + { if (i < items.Count) + { items[i].OnParentDeleted(this); + } + } + } SendRemovePacket(); SetFlag(ImplFlag.Deleted, true); if (Parent is Mobile mobile) + { mobile.RemoveItem(this); + } else if (Parent is Item item) + { item.RemoveItem(this); + } ClearBounce(); if (m_Map != null) { if (m_Parent == null) + { m_Map.OnLeave(this); + } + m_Map = null; } @@ -1376,7 +1580,9 @@ namespace Server info.m_Spawner = value; if (info.m_Spawner == null) + { VerifyCompactInfo(); + } } } @@ -1397,7 +1603,10 @@ namespace Server var oldLocation = m_Location; if (oldLocation == value) + { return; + } + if (m_Map != null) { if (m_Parent == null) @@ -1412,7 +1621,10 @@ namespace Server { var m = state.Mobile; - if (!m.InRange(value, GetUpdateRange(m))) state.Send(RemovePacket); + if (!m.InRange(value, GetUpdateRange(m))) + { + state.Send(RemovePacket); + } } eable.Free(); @@ -1433,7 +1645,9 @@ namespace Server if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)) && (!state.HighSeas || !NoMoveHS || (m_DeltaFlags & ItemDelta.Update) != 0 || !m.InRange(oldLoc, GetUpdateRange(m)))) + { SendInfoTo(state); + } } eable.Free(); @@ -1454,7 +1668,9 @@ namespace Server } if (m_Parent == null) + { m_Map.OnMove(oldLocation, this); + } } else { @@ -1508,7 +1724,9 @@ namespace Server public void ReleaseOPLPacket() { if (m_PropertyList == null) + { return; + } Packet.Release(m_PropertyList); m_PropertyList = null; @@ -1523,31 +1741,49 @@ namespace Server if (info != null) { if (info.m_BlessedFor != null) + { flags |= ExpandFlag.Blessed; + } if (info.m_Bounce != null) + { flags |= ExpandFlag.Bounce; + } if (info.m_HeldBy != null) + { flags |= ExpandFlag.Holder; + } if (info.m_Items != null) + { flags |= ExpandFlag.Items; + } if (info.m_Name != null) + { flags |= ExpandFlag.Name; + } if (info.m_Spawner != null) + { flags |= ExpandFlag.Spawner; + } if (info.m_SavedFlags != 0) + { flags |= ExpandFlag.SaveFlag; + } if (info.m_TempFlags != 0) + { flags |= ExpandFlag.TempFlag; + } if (info.m_Weight != -1) + { flags |= ExpandFlag.Weight; + } } return flags; @@ -1567,7 +1803,9 @@ namespace Server var info = m_CompactInfo; if (info == null) + { return; + } var isValid = info.m_Name != null || info.m_Items != null @@ -1580,13 +1818,17 @@ namespace Server || info.m_Weight != -1; if (!isValid) + { ReleaseCompactInfo(); + } } public List LookupItems() { if (this is Container container) + { return container.m_Items; + } return LookupCompactInfo()?.m_Items; } @@ -1594,7 +1836,9 @@ namespace Server public List AcquireItems() { if (this is Container cont) + { return cont.m_Items ?? (cont.m_Items = new List()); + } var info = AcquireCompactInfo(); return info.m_Items ?? (info.m_Items = new List()); @@ -1603,9 +1847,13 @@ namespace Server private void SetFlag(ImplFlag flag, bool value) { if (value) + { m_Flags |= flag; + } else + { m_Flags &= ~flag; + } } private bool GetFlag(ImplFlag flag) => (m_Flags & flag) != 0; @@ -1624,19 +1872,25 @@ namespace Server var bounce = info?.m_Bounce; if (bounce == null) + { return; + } info.m_Bounce = null; if (bounce.Parent is Item parentItem) { if (!parentItem.Deleted) + { parentItem.OnItemBounceCleared(this); + } } else if (bounce.Parent is Mobile parentMobile) { if (!parentMobile.Deleted) + { parentMobile.OnItemBounceCleared(this); + } } VerifyCompactInfo(); @@ -1703,16 +1957,24 @@ namespace Server if (name == null) { if (m_Amount <= 1) + { list.Add(LabelNumber); + } else + { list.Add(1050039, "{0}\t#{1}", m_Amount, LabelNumber); // ~1_NUMBER~ ~2_ITEMNAME~ + } } else { if (m_Amount <= 1) + { list.Add(name); + } else + { list.Add(1050039, "{0}\t{1}", m_Amount, Name); // ~1_NUMBER~ ~2_ITEMNAME~ + } } } @@ -1723,11 +1985,17 @@ namespace Server public virtual void AddLootTypeProperty(ObjectPropertyList list) { if (m_LootType == LootType.Blessed) + { list.Add(1038021); // blessed + } else if (m_LootType == LootType.Cursed) + { list.Add(1049643); // cursed + } else if (Insured) + { list.Add(1061682); // insured + } } /// @@ -1738,27 +2006,37 @@ namespace Server var v = PhysicalResistance; if (v != 0) + { list.Add(1060448, v.ToString()); // physical resist ~1_val~% + } v = FireResistance; if (v != 0) + { list.Add(1060447, v.ToString()); // fire resist ~1_val~% + } v = ColdResistance; if (v != 0) + { list.Add(1060445, v.ToString()); // cold resist ~1_val~% + } v = PoisonResistance; if (v != 0) + { list.Add(1060449, v.ToString()); // poison resist ~1_val~% + } v = EnergyResistance; if (v != 0) + { list.Add(1060446, v.ToString()); // energy resist ~1_val~% + } } /// @@ -1769,9 +2047,13 @@ namespace Server var weight = PileWeight + TotalWeight; if (weight == 1) + { list.Add(1072788, weight.ToString()); // Weight: ~1_WEIGHT~ stone + } else + { list.Add(1072789, weight.ToString()); // Weight: ~1_WEIGHT~ stones + } } /// @@ -1784,23 +2066,35 @@ namespace Server AddNameProperty(list); if (IsSecure) + { AddSecureProperty(list); + } else if (IsLockedDown) + { AddLockedDownProperty(list); + } var blessedFor = BlessedFor; if (blessedFor?.Deleted == false) + { AddBlessedForProperty(list, blessedFor); + } if (DisplayLootType) + { AddLootTypeProperty(list); + } if (DisplayWeight) + { AddWeightProperty(list); + } if (QuestItem) + { AddQuestItemProperty(list); + } AppendChildNameProperties(list); } @@ -1845,9 +2139,13 @@ namespace Server public virtual void GetChildProperties(ObjectPropertyList list, Item item) { if (m_Parent is Item parentItem) + { parentItem.GetChildProperties(list, item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.GetChildProperties(list, item); + } } /// @@ -1859,9 +2157,13 @@ namespace Server public virtual void GetChildNameProperties(ObjectPropertyList list, Item item) { if (m_Parent is Item parentItem) + { parentItem.GetChildNameProperties(list, item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.GetChildNameProperties(list, item); + } } public virtual bool IsChildVisibleTo(Mobile m, Item child) => true; @@ -1869,9 +2171,13 @@ namespace Server public void Bounce(Mobile from) { if (m_Parent is Item item) + { item.RemoveItem(this); + } else if (m_Parent is Mobile mobile) + { mobile.RemoveItem(this); + } m_Parent = null; @@ -1903,7 +2209,9 @@ namespace Server else if (parent is Mobile parentMobile) { if (!parentMobile.EquipItem(this)) + { MoveToWorld(bounce.WorldLoc, bounce.Map); + } } else { @@ -1930,7 +2238,7 @@ namespace Server /// { /// if (from.Int >= 100) /// return true; - /// + /// /// return base.AllowEquippedCast( from ); /// } /// When placed in an Item script, the item may be cast when equipped if the has 100 or more @@ -1945,17 +2253,25 @@ namespace Server public virtual void GetChildContextMenuEntries(Mobile from, List list, Item item) { if (m_Parent is Item parentItem) - parentItem.GetChildContextMenuEntries(from, list, item); + { + parentItem.GetChildContextMenuEntries(@from, list, item); + } else if (m_Parent is Mobile parentMobile) - parentMobile.GetChildContextMenuEntries(from, list, item); + { + parentMobile.GetChildContextMenuEntries(@from, list, item); + } } public virtual void GetContextMenuEntries(Mobile from, List list) { if (m_Parent is Item item) - item.GetChildContextMenuEntries(from, list, this); + { + item.GetChildContextMenuEntries(@from, list, this); + } else if (m_Parent is Mobile mobile) - mobile.GetChildContextMenuEntries(from, list, this); + { + mobile.GetChildContextMenuEntries(@from, list, this); + } } public virtual bool VerifyMove(Mobile from) => Movable; @@ -1963,15 +2279,29 @@ namespace Server public virtual DeathMoveResult OnParentDeath(Mobile parent) { if (!Movable) + { return DeathMoveResult.RemainEquipped; + } + if (parent.KeepsItemsOnDeath) + { return DeathMoveResult.MoveToBackpack; + } + if (CheckBlessed(parent)) + { return DeathMoveResult.MoveToBackpack; + } + if (CheckNewbied() && parent.Kills < 5) + { return DeathMoveResult.MoveToBackpack; + } + if (parent.Player && Nontransferable) + { return DeathMoveResult.MoveToBackpack; + } return DeathMoveResult.MoveToCorpse; } @@ -1979,15 +2309,29 @@ namespace Server public virtual DeathMoveResult OnInventoryDeath(Mobile parent) { if (!Movable) + { return DeathMoveResult.MoveToBackpack; + } + if (parent.KeepsItemsOnDeath) + { return DeathMoveResult.MoveToBackpack; + } + if (CheckBlessed(parent)) + { return DeathMoveResult.MoveToBackpack; + } + if (CheckNewbied() && parent.Kills < 5) + { return DeathMoveResult.MoveToBackpack; + } + if (parent.Player && Nontransferable) + { return DeathMoveResult.MoveToBackpack; + } return DeathMoveResult.MoveToCorpse; } @@ -2033,9 +2377,13 @@ namespace Server public virtual void LabelLootTypeTo(Mobile to) { if (m_LootType == LootType.Blessed) + { LabelTo(to, 1041362); // (blessed) + } else if (m_LootType == LootType.Cursed) + { LabelTo(to, "(cursed)"); + } } public bool AtWorldPoint(int x, int y) => m_Parent == null && m_Location.m_X == x && m_Location.m_Y == y; @@ -2061,7 +2409,9 @@ namespace Server if (CanStackWith(dropped)) { if (m_LootType != dropped.m_LootType) + { m_LootType = LootType.Regular; + } Amount += dropped.Amount; dropped.Delete(); @@ -2071,7 +2421,9 @@ namespace Server var soundID = GetDropSound(); if (soundID == -1) + { soundID = 0x42; + } from.SendSound(soundID, GetWorldLocation()); } @@ -2110,16 +2462,25 @@ namespace Server doubled = false; if (m_Amount <= 1) + { itemID = coinBase; + } else if (m_Amount <= 5) + { itemID = coinBase + 1; + } else // m_Amount > 5 + { itemID = coinBase + 2; + } } var bounds = ItemBounds.Table[itemID & 0x3FFF]; - if (doubled) bounds.Set(bounds.X, bounds.Y, bounds.Width + 5, bounds.Height + 5); + if (doubled) + { + bounds.Set(bounds.X, bounds.Y, bounds.Width + 5, bounds.Height + 5); + } return bounds; } @@ -2127,17 +2488,25 @@ namespace Server public virtual void AppendChildProperties(ObjectPropertyList list) { if (m_Parent is Item item) + { item.GetChildProperties(list, this); + } else if (m_Parent is Mobile mobile) + { mobile.GetChildProperties(list, this); + } } public virtual void AppendChildNameProperties(ObjectPropertyList list) { if (m_Parent is Item item) + { item.GetChildNameProperties(list, this); + } else if (m_Parent is Mobile mobile) + { mobile.GetChildNameProperties(list, this); + } } public ObjectPropertyList NewObjectPropertyList() @@ -2161,7 +2530,9 @@ namespace Server public void InvalidateProperties() { if (!ObjectPropertyList.Enabled) + { return; + } if (m_Map != null && m_Map != Map.Internal && !World.Loading) { @@ -2190,10 +2561,14 @@ namespace Server var flags = 0; if (!Visible) + { flags |= 0x80; + } if (Movable || ForceShowProperties) + { flags |= 0x20; + } return flags; } @@ -2226,7 +2601,9 @@ namespace Server private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf) { if (setIf) + { flags |= toSet; + } } private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet) => (flags & toGet) != 0; @@ -2271,12 +2648,18 @@ namespace Server var info = AcquireCompactInfo(); if (value) + { info.m_TempFlags |= flag; + } else + { info.m_TempFlags &= ~flag; + } if (info.m_TempFlags == 0) + { VerifyCompactInfo(); + } } public bool GetSavedFlag(int flag) => ((LookupCompactInfo()?.m_SavedFlags ?? 0) & flag) != 0; @@ -2286,12 +2669,18 @@ namespace Server var info = AcquireCompactInfo(); if (value) + { info.m_SavedFlags |= flag; + } else + { info.m_SavedFlags &= ~flag; + } if (info.m_SavedFlags == 0) + { VerifyCompactInfo(); + } } public virtual void Deserialize(IGenericReader reader) @@ -2328,13 +2717,19 @@ namespace Server } if (GetSaveFlag(flags, SaveFlag.Direction)) + { m_Direction = (Direction)reader.ReadByte(); + } if (GetSaveFlag(flags, SaveFlag.Bounce)) + { AcquireCompactInfo().m_Bounce = BounceInfo.Deserialize(reader); + } if (GetSaveFlag(flags, SaveFlag.LootType)) + { m_LootType = (LootType)reader.ReadByte(); + } int x = 0, y = 0, z = 0; @@ -2358,28 +2753,38 @@ namespace Server } if (GetSaveFlag(flags, SaveFlag.LocationSByteZ)) + { z = reader.ReadSByte(); + } } m_Location = new Point3D(x, y, z); if (GetSaveFlag(flags, SaveFlag.ItemID)) + { m_ItemID = reader.ReadEncodedInt(); + } if (GetSaveFlag(flags, SaveFlag.Hue)) + { m_Hue = reader.ReadEncodedInt(); + } m_Amount = GetSaveFlag(flags, SaveFlag.Amount) ? reader.ReadEncodedInt() : 1; if (GetSaveFlag(flags, SaveFlag.Layer)) + { m_Layer = (Layer)reader.ReadByte(); + } if (GetSaveFlag(flags, SaveFlag.Name)) { var name = reader.ReadString(); if (name != DefaultName) + { AcquireCompactInfo().m_Name = name; + } } if (GetSaveFlag(flags, SaveFlag.Parent)) @@ -2387,14 +2792,22 @@ namespace Server Serial parent = reader.ReadUInt(); if (parent.IsMobile) + { m_Parent = World.FindMobile(parent); + } else if (parent.IsItem) + { m_Parent = World.FindItem(parent); + } else + { m_Parent = null; + } if (m_Parent == null && (parent.IsMobile || parent.IsItem)) + { Delete(); + } } if (GetSaveFlag(flags, SaveFlag.Items)) @@ -2402,9 +2815,13 @@ namespace Server var items = reader.ReadStrongItemList(); if (this is Container) + { (this as Container).m_Items = items; + } else + { AcquireCompactInfo().m_Items = items; + } } if (version < 8 || !GetSaveFlag(flags, SaveFlag.NullWeight)) @@ -2412,16 +2829,26 @@ namespace Server double weight; if (GetSaveFlag(flags, SaveFlag.IntWeight)) + { weight = reader.ReadEncodedInt(); + } else if (GetSaveFlag(flags, SaveFlag.WeightNot1or0)) + { weight = reader.ReadDouble(); + } else if (GetSaveFlag(flags, SaveFlag.WeightIs0)) + { weight = 0.0; + } else + { weight = 1.0; + } if (weight != DefaultWeight) + { AcquireCompactInfo().m_Weight = weight; + } } m_Map = GetSaveFlag(flags, SaveFlag.Map) ? reader.ReadMap() : Map.Internal; @@ -2431,26 +2858,40 @@ namespace Server SetFlag(ImplFlag.Movable, !GetSaveFlag(flags, SaveFlag.Movable) || reader.ReadBool()); if (GetSaveFlag(flags, SaveFlag.Stackable)) + { SetFlag(ImplFlag.Stackable, reader.ReadBool()); + } if (GetSaveFlag(flags, SaveFlag.ImplFlags)) + { m_Flags = (ImplFlag)reader.ReadEncodedInt(); + } if (GetSaveFlag(flags, SaveFlag.InsuredFor)) /*m_InsuredFor = */ + { reader.ReadMobile(); + } if (GetSaveFlag(flags, SaveFlag.BlessedFor)) + { AcquireCompactInfo().m_BlessedFor = reader.ReadMobile(); + } if (GetSaveFlag(flags, SaveFlag.HeldBy)) + { AcquireCompactInfo().m_HeldBy = reader.ReadMobile(); + } if (GetSaveFlag(flags, SaveFlag.SavedFlags)) + { AcquireCompactInfo().m_SavedFlags = reader.ReadEncodedInt(); + } if (m_Map != null && m_Parent == null) + { m_Map.OnEnter(this); + } break; } @@ -2461,34 +2902,50 @@ namespace Server LastMoved = reader.ReadDeltaTime(); if (GetSaveFlag(flags, SaveFlag.Direction)) + { m_Direction = (Direction)reader.ReadByte(); + } if (GetSaveFlag(flags, SaveFlag.Bounce)) + { AcquireCompactInfo().m_Bounce = BounceInfo.Deserialize(reader); + } if (GetSaveFlag(flags, SaveFlag.LootType)) + { m_LootType = (LootType)reader.ReadByte(); + } if (GetSaveFlag(flags, SaveFlag.LocationFull)) + { m_Location = reader.ReadPoint3D(); + } if (GetSaveFlag(flags, SaveFlag.ItemID)) + { m_ItemID = reader.ReadInt(); + } if (GetSaveFlag(flags, SaveFlag.Hue)) + { m_Hue = reader.ReadInt(); + } m_Amount = GetSaveFlag(flags, SaveFlag.Amount) ? reader.ReadInt() : 1; if (GetSaveFlag(flags, SaveFlag.Layer)) + { m_Layer = (Layer)reader.ReadByte(); + } if (GetSaveFlag(flags, SaveFlag.Name)) { var name = reader.ReadString(); if (name != DefaultName) + { AcquireCompactInfo().m_Name = name; + } } if (GetSaveFlag(flags, SaveFlag.Parent)) @@ -2496,14 +2953,22 @@ namespace Server Serial parent = reader.ReadUInt(); if (parent.IsMobile) + { m_Parent = World.FindMobile(parent); + } else if (parent.IsItem) + { m_Parent = World.FindItem(parent); + } else + { m_Parent = null; + } if (m_Parent == null && (parent.IsMobile || parent.IsItem)) + { Delete(); + } } if (GetSaveFlag(flags, SaveFlag.Items)) @@ -2511,38 +2976,60 @@ namespace Server var items = reader.ReadStrongItemList(); if (this is Container cont) + { cont.m_Items = items; + } else + { AcquireCompactInfo().m_Items = items; + } } double weight; if (GetSaveFlag(flags, SaveFlag.IntWeight)) + { weight = reader.ReadEncodedInt(); + } else if (GetSaveFlag(flags, SaveFlag.WeightNot1or0)) + { weight = reader.ReadDouble(); + } else if (GetSaveFlag(flags, SaveFlag.WeightIs0)) + { weight = 0.0; + } else + { weight = 1.0; + } if (weight != DefaultWeight) + { AcquireCompactInfo().m_Weight = weight; + } if (GetSaveFlag(flags, SaveFlag.Map)) + { m_Map = reader.ReadMap(); + } else + { m_Map = Map.Internal; + } SetFlag(ImplFlag.Visible, !GetSaveFlag(flags, SaveFlag.Visible) || reader.ReadBool()); SetFlag(ImplFlag.Movable, !GetSaveFlag(flags, SaveFlag.Movable) || reader.ReadBool()); if (GetSaveFlag(flags, SaveFlag.Stackable)) + { SetFlag(ImplFlag.Stackable, reader.ReadBool()); + } if (m_Map != null && m_Parent == null) + { m_Map.OnEnter(this); + } break; } @@ -2577,19 +3064,29 @@ namespace Server var name = reader.ReadString(); if (name != DefaultName) + { AcquireCompactInfo().m_Name = name; + } Serial parent = reader.ReadUInt(); if (parent.IsMobile) + { m_Parent = World.FindMobile(parent); + } else if (parent.IsItem) + { m_Parent = World.FindItem(parent); + } else + { m_Parent = null; + } if (m_Parent == null && (parent.IsMobile || parent.IsItem)) + { Delete(); + } var count = reader.ReadInt(); @@ -2602,19 +3099,27 @@ namespace Server var item = reader.ReadItem(); if (item != null) + { items.Add(item); + } } if (this is Container cont) + { cont.m_Items = items; + } else + { AcquireCompactInfo().m_Items = items; + } } var weight = reader.ReadDouble(); if (weight != DefaultWeight) + { AcquireCompactInfo().m_Weight = weight; + } if (version <= 3) { @@ -2629,19 +3134,25 @@ namespace Server if (version <= 3) /*m_Deleted =*/ + { reader.ReadBool(); + } Stackable = reader.ReadBool(); if (m_Map != null && m_Parent == null) + { m_Map.OnEnter(this); + } break; } } if (HeldBy != null) + { Timer.DelayCall(FixHolding_Sandbox); + } // if (version < 9) VerifyCompactInfo(); @@ -2679,15 +3190,24 @@ namespace Server { state.Send(GetWorldPacketFor(state)); - if (sendOplPacket) state.Send(OPLPacket); + if (sendOplPacket) + { + state.Send(OPLPacket); + } } protected virtual Packet GetWorldPacketFor(NetState state) { if (state.HighSeas) + { return WorldPacketHS; + } + if (state.StygianAbyss) + { return WorldPacketSA; + } + return WorldPacket; } @@ -2698,11 +3218,17 @@ namespace Server if (!IsVirtualItem) { if (m_Parent is Item item) + { item.UpdateTotal(sender, type, delta); + } else if (m_Parent is Mobile mobile) + { mobile.UpdateTotal(sender, type, delta); + } else + { HeldBy?.UpdateTotal(sender, type, delta); + } } } @@ -2714,9 +3240,11 @@ namespace Server { // OSI sends 1074769, bug! if (QuestItem) - from.SendLocalizedMessage( + { + @from.SendLocalizedMessage( 1049343 ); // You can only drop quest items into the top-most level of your backpack while you still need them for your quest. + } } public bool ParentsContain() where T : Item @@ -2726,9 +3254,14 @@ namespace Server while (p is Item item) { if (item is T) + { return true; + } - if (item.m_Parent == null) break; + if (item.m_Parent == null) + { + break; + } p = item.m_Parent; } @@ -2738,7 +3271,10 @@ namespace Server public virtual void AddItem(Item item) { - if (item?.Deleted != false || item.m_Parent == this) return; + if (item?.Deleted != false || item.m_Parent == this) + { + return; + } if (item == this) { @@ -2767,11 +3303,17 @@ namespace Server } if (item.m_Parent is Mobile parentMobile) + { parentMobile.RemoveItem(item); + } else if (item.m_Parent is Item parentItem) + { parentItem.RemoveItem(item); + } else + { item.SendRemovePacket(); + } item.Parent = this; item.Map = m_Map; @@ -2796,7 +3338,9 @@ namespace Server public void Delta(ItemDelta flags) { if (m_Map == null || m_Map == Map.Internal) + { return; + } m_DeltaFlags |= flags; @@ -2805,6 +3349,7 @@ namespace Server SetFlag(ImplFlag.InQueue, true); if (_processing) + { try { using var op = new StreamWriter("delta-recursion.log", true); @@ -2816,8 +3361,11 @@ namespace Server { // ignored } + } else + { m_DeltaQueue.Add(this); + } } Core.Set(); @@ -2832,6 +3380,7 @@ namespace Server SetFlag(ImplFlag.InQueue, false); if (_processing) + { try { using var op = new StreamWriter("delta-recursion.log", true); @@ -2843,8 +3392,11 @@ namespace Server { // ignored } + } else + { m_DeltaQueue.Remove(this); + } } } @@ -2853,10 +3405,16 @@ namespace Server _processing = true; if (m_DeltaQueue.Count >= 512) + { Parallel.ForEach(m_DeltaQueue, i => i.ProcessDelta()); + } else + { for (var i = 0; i < m_DeltaQueue.Count; i++) + { m_DeltaQueue[i].ProcessDelta(); + } + } m_DeltaQueue.Clear(); @@ -2888,7 +3446,9 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text) { if (m_Map == null) + { return; + } Packet p = null; var worldLoc = GetWorldLocation(); @@ -2904,9 +3464,13 @@ namespace Server if (p == null) { if (ascii) + { p = new AsciiMessage(Serial, m_ItemID, type, hue, 3, Name, text); + } else + { p = new UnicodeMessage(Serial, m_ItemID, type, hue, 3, "ENU", Name, text); + } p.Acquire(); } @@ -2928,7 +3492,9 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, int number, string args) { if (m_Map == null) + { return; + } Packet p = null; var worldLoc = GetWorldLocation(); @@ -3016,7 +3582,9 @@ namespace Server public virtual bool OnDroppedInto(Mobile from, Container target, Point3D p) { if (!from.OnDroppedItemInto(this, target, p)) + { return false; + } if (Nontransferable && from.Player && target != from.Backpack) { @@ -3031,15 +3599,30 @@ namespace Server { if (Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null) + { return false; + } + if (from.AccessLevel < AccessLevel.GameMaster && !from.InRange(target.GetWorldLocation(), 2)) + { return false; + } + if (!from.CanSee(target) || !from.InLOS(target)) + { return false; + } + if (!target.IsAccessibleTo(from)) + { return false; + } + if (!from.OnDroppedItemOnto(this, target)) + { return false; + } + if (Nontransferable && from.Player && target != from.Backpack) { HandleInvalidTransfer(from); @@ -3053,20 +3636,39 @@ namespace Server { if (Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null) + { return false; + } if (from.AccessLevel < AccessLevel.GameMaster && !from.InRange(target.GetWorldLocation(), 2)) + { return false; + } + if (!from.CanSee(target) || !from.InLOS(target)) + { return false; + } + if (!target.IsAccessibleTo(from)) + { return false; + } + if (target.RootParent is Mobile mobile && !mobile.CheckNonlocalDrop(from, this, target)) + { return false; + } + if (!from.OnDroppedItemToItem(this, target, p)) + { return false; + } + if (target is Container container && p.m_X != -1 && p.m_Y != -1) - return OnDroppedInto(from, container, p); + { + return OnDroppedInto(@from, container, p); + } return OnDroppedOnto(from, target); } @@ -3087,15 +3689,21 @@ namespace Server public virtual bool DropToWorld(Mobile from, Point3D p) { if (Deleted || from.Deleted || from.Map == null) + { return false; + } if (!from.InRange(p, 2)) + { return false; + } var map = from.Map; if (map == null) + { return false; + } int x = p.m_X, y = p.m_Y; var z = int.MinValue; @@ -3109,8 +3717,12 @@ namespace Server map.GetAverageZ(x, y, ref landZ, ref landAvg, ref landTop); if (!landTile.Ignored && (landFlags & TileFlag.Impassable) == 0) + { if (landAvg <= maxZ) + { z = landAvg; + } + } var tiles = map.Tiles.GetStaticTiles(x, y, true); @@ -3120,12 +3732,16 @@ namespace Server var id = TileData.ItemTable[tile.ID & TileData.MaxItemValue]; if (!id.Surface) + { continue; + } var top = tile.Z + id.CalcHeight; if (top > maxZ || top < z) + { continue; + } z = top; } @@ -3136,7 +3752,9 @@ namespace Server item => { if (item is BaseMulti || item.ItemID > TileData.MaxItemValue) + { return false; + } var id = item.ItemData; @@ -3144,7 +3762,9 @@ namespace Server { var top = item.Z + id.CalcHeight; if (top <= maxZ && top >= z) + { z = top; + } } return true; @@ -3155,10 +3775,14 @@ namespace Server eable.Free(); if (z == int.MinValue) + { return false; + } if (z > maxZ) + { return false; + } m_OpenSlots = (1 << 20) - 1; @@ -3173,13 +3797,17 @@ namespace Server var checkTop = checkZ + id.CalcHeight; if (checkTop == checkZ && !id.Surface) + { ++checkTop; + } var zStart = Math.Max(checkZ - z, 0); var zEnd = Math.Min(checkTop - z, 19); if (zStart >= 20 || zEnd < 0) + { continue; + } var bitCount = zEnd - zStart; @@ -3195,13 +3823,17 @@ namespace Server var checkTop = checkZ + id.CalcHeight; if (checkTop == checkZ && !id.Surface) + { ++checkTop; + } var zStart = Math.Max(checkZ - z, 0); var zEnd = Math.Min(checkTop - z, 19); if (zStart >= 20 || zEnd < 0) + { continue; + } var bitCount = zEnd - zStart; @@ -3211,10 +3843,14 @@ namespace Server var height = ItemData.Height; if (height == 0) + { ++height; + } if (height > 30) + { height = 30; + } var match = (1 << height) - 1; var okay = false; @@ -3222,7 +3858,9 @@ namespace Server for (var i = 0; i < 20; ++i) { if (i + height > 20) + { match >>= 1; + } okay = ((m_OpenSlots >> i) & match) == match; @@ -3234,18 +3872,26 @@ namespace Server } if (!okay) + { return false; + } height = ItemData.Height; if (height == 0) + { ++height; + } if (landAvg > z && z + height > landZ) + { return false; + } if ((landFlags & TileFlag.Impassable) != 0 && landAvg > surfaceZ && z + height > landZ) + { return false; + } for (var i = 0; i < tiles.Length; ++i) { @@ -3256,10 +3902,14 @@ namespace Server var checkTop = checkZ + id.CalcHeight; if (checkTop > z && z + height > checkZ) + { return false; + } if ((id.Surface || id.Impassable) && checkTop > surfaceZ && z + height > checkZ) + { return false; + } } for (var i = 0; i < items.Count; ++i) @@ -3271,17 +3921,27 @@ namespace Server // int checkTop = checkZ + id.CalcHeight; if (item.Z + id.CalcHeight > z && z + height > item.Z) + { return false; + } } p = new Point3D(x, y, z); if (!from.InLOS(new Point3D(x, y, z + 1))) + { return false; + } + if (!from.OnDroppedItemToWorld(this, p)) + { return false; + } + if (!OnDroppedToWorld(from, p)) + { return false; + } var soundID = GetDropSound(); @@ -3295,7 +3955,10 @@ namespace Server public void SendRemovePacket() { if (Deleted || m_Map == null) + { return; + } + var worldLoc = GetWorldLocation(); var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()); @@ -3304,7 +3967,10 @@ namespace Server { var m = state.Mobile; - if (m.InRange(worldLoc, GetUpdateRange(m))) state.Send(RemovePacket); + if (m.InRange(worldLoc, GetUpdateRange(m))) + { + state.Send(RemovePacket); + } } eable.Free(); @@ -3317,7 +3983,10 @@ namespace Server var root = RootParent; if (root == null) + { return m_Location; + } + return root.Location; // return root == null ? m_Location : new Point3D( (IPoint3D) root ); @@ -3328,11 +3997,13 @@ namespace Server var root = RootParent; if (root == null) + { return new Point3D( m_Location.m_X, m_Location.m_Y, m_Location.m_Z + (ItemData.Surface ? ItemData.CalcHeight : 0) ); + } return root.Location; } @@ -3343,7 +4014,9 @@ namespace Server public void SendLocalizedMessageTo(Mobile to, int number) { if (Deleted || !to.CanSee(this)) + { return; + } to.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", "")); } @@ -3351,7 +4024,9 @@ namespace Server public void SendLocalizedMessageTo(Mobile to, int number, string args) { if (Deleted || !to.CanSee(this)) + { return; + } to.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, number, "", args)); } @@ -3359,7 +4034,9 @@ namespace Server public void SendLocalizedMessageTo(Mobile to, int number, AffixType affixType, string affix, string args) { if (Deleted || !to.CanSee(this)) + { return; + } to.Send( new MessageLocalizedAffix( @@ -3388,7 +4065,9 @@ namespace Server while (p is Item item) { if (item is SecureTradeContainer container) + { return container; + } p = item.m_Parent; } @@ -3399,49 +4078,73 @@ namespace Server public virtual void OnItemAdded(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemAdded(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemAdded(item); + } } public virtual void OnItemRemoved(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemRemoved(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemRemoved(item); + } } public virtual void OnSubItemAdded(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemAdded(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemAdded(item); + } } public virtual void OnSubItemRemoved(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemRemoved(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemRemoved(item); + } } public virtual void OnItemBounceCleared(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemBounceCleared(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemBounceCleared(item); + } } public virtual void OnSubItemBounceCleared(Item item) { if (m_Parent is Item parentItem) + { parentItem.OnSubItemBounceCleared(item); + } else if (m_Parent is Mobile parentMobile) + { parentMobile.OnSubItemBounceCleared(item); + } } public virtual bool CheckTarget(Mobile from, Target targ, object targeted) => @@ -3455,17 +4158,19 @@ namespace Server public virtual bool IsAccessibleTo(Mobile check) { if (m_Parent is Item item) + { return item.IsAccessibleTo(check); + } var reg = Region.Find(GetWorldLocation(), m_Map); return reg.CheckAccessibility(this, check); /*SecureTradeContainer cont = GetSecureTradeCont(); - + if (cont != null && !cont.IsChildOf( check )) return false; - + return true;*/ } @@ -3476,20 +4181,28 @@ namespace Server var p = m_Parent; if ((p == null || o == null) && !allowNull) + { return false; + } if (p == o) + { return true; + } while (p is Item item) { if (item.m_Parent == null) + { break; + } p = item.m_Parent; if (p == o) + { return true; + } } return false; @@ -3498,9 +4211,13 @@ namespace Server public virtual void OnItemUsed(Mobile from, Item item) { if (m_Parent is Item parentItem) - parentItem.OnItemUsed(from, item); + { + parentItem.OnItemUsed(@from, item); + } else if (m_Parent is Mobile parentMobile) - parentMobile.OnItemUsed(from, item); + { + parentMobile.OnItemUsed(@from, item); + } } public bool CheckItemUse(Mobile from) => CheckItemUse(from, this); @@ -3516,9 +4233,13 @@ namespace Server public virtual void OnItemLifted(Mobile from, Item item) { if (m_Parent is Item parentItem) - parentItem.OnItemLifted(from, item); + { + parentItem.OnItemLifted(@from, item); + } else if (m_Parent is Mobile parentMobile) - parentMobile.OnItemLifted(from, item); + { + parentMobile.OnItemLifted(@from, item); + } } public bool CheckLift(Mobile from) @@ -3539,7 +4260,9 @@ namespace Server public virtual void OnSingleClickContained(Mobile from, Item item) { if (m_Parent is Item parentItem) - parentItem.OnSingleClickContained(from, item); + { + parentItem.OnSingleClickContained(@from, item); + } } public virtual void OnAosSingleClick(Mobile from) @@ -3547,7 +4270,8 @@ namespace Server var opl = PropertyList; if (opl.Header > 0) - from.Send( + { + @from.Send( new MessageLocalized( Serial, m_ItemID, @@ -3559,26 +4283,36 @@ namespace Server opl.HeaderArgs ) ); + } } public virtual void OnSingleClick(Mobile from) { if (Deleted || !from.CanSee(this)) + { return; + } if (DisplayLootType) - LabelLootTypeTo(from); + { + LabelLootTypeTo(@from); + } var ns = from.NetState; if (ns == null) + { return; + } if (Name == null) { if (m_Amount <= 1) + { ns.Send(new MessageLocalized(Serial, m_ItemID, MessageType.Label, 0x3B2, 3, LabelNumber, "", "")); + } else + { ns.Send( new MessageLocalizedAffix( Serial, @@ -3593,6 +4327,7 @@ namespace Server "" ) ); + } } else { @@ -3630,18 +4365,26 @@ namespace Server var type = LootType; if (Amount == 0) + { Delete(); + } newItem.Amount = amount * amountPerOldItem; if (carryHue) + { newItem.Hue = ourHue; + } if (ScissorCopyLootType) + { newItem.LootType = type; + } if ((thisParent as Container)?.TryDropItem(from, newItem, false) != true) + { newItem.MoveToWorld(worldLoc, thisMap); + } } public virtual void Consume() @@ -3654,7 +4397,9 @@ namespace Server Amount -= amount; if (Amount <= 0) + { Delete(); + } } public virtual void ReplaceWith(Item newItem) diff --git a/Projects/Server/ItemBounds.cs b/Projects/Server/Items/ItemBounds.cs similarity index 59% rename from Projects/Server/ItemBounds.cs rename to Projects/Server/Items/ItemBounds.cs index 77c0ecb4e..4fea6ae67 100644 --- a/Projects/Server/ItemBounds.cs +++ b/Projects/Server/Items/ItemBounds.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ItemBounds.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.IO; diff --git a/Projects/Server/Layer.cs b/Projects/Server/Items/Layer.cs similarity index 98% rename from Projects/Server/Layer.cs rename to Projects/Server/Items/Layer.cs index ee9e0adc0..4758422f7 100644 --- a/Projects/Server/Layer.cs +++ b/Projects/Server/Items/Layer.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Layer.cs * * * diff --git a/Projects/Server/LightType.cs b/Projects/Server/Items/LightType.cs similarity index 99% rename from Projects/Server/LightType.cs rename to Projects/Server/Items/LightType.cs index 735c0633e..6245926a8 100644 --- a/Projects/Server/LightType.cs +++ b/Projects/Server/Items/LightType.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: LightType.cs * * * diff --git a/Projects/Server/Items/SecureTradeContainer.cs b/Projects/Server/Items/SecureTradeContainer.cs index c5f8b676e..d4d5e64ba 100644 --- a/Projects/Server/Items/SecureTradeContainer.cs +++ b/Projects/Server/Items/SecureTradeContainer.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * SecureTradeContainer.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Accounting; using Server.Network; @@ -40,7 +20,10 @@ namespace Server.Items public override bool CheckHold(Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight) { - if (item == Trade.From.VirtualCheck || item == Trade.To.VirtualCheck) return true; + if (item == Trade.From.VirtualCheck || item == Trade.To.VirtualCheck) + { + return true; + } var to = Trade.From.Container != this ? Trade.From.Mobile : Trade.To.Mobile; @@ -59,37 +42,51 @@ namespace Server.Items public override void OnItemAdded(Item item) { if (!(item is VirtualCheck)) + { ClearChecks(); + } } public override void OnItemRemoved(Item item) { if (!(item is VirtualCheck)) + { ClearChecks(); + } } public override void OnSubItemAdded(Item item) { if (!(item is VirtualCheck)) + { ClearChecks(); + } } public override void OnSubItemRemoved(Item item) { if (!(item is VirtualCheck)) + { ClearChecks(); + } } public void ClearChecks() { if (Trade == null) + { return; + } if (Trade.From?.IsDisposed == false) + { Trade.From.Accepted = false; + } if (Trade.To?.IsDisposed == false) + { Trade.To.Accepted = false; + } Trade.Update(); } diff --git a/Projects/Server/Items/VirtualCheck.cs b/Projects/Server/Items/VirtualCheck.cs index 780ab7cc5..0710d8c02 100644 --- a/Projects/Server/Items/VirtualCheck.cs +++ b/Projects/Server/Items/VirtualCheck.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: VirtualCheck.cs * * * @@ -78,7 +78,10 @@ namespace Server.Items { var c = GetSecureTradeCont(); - if (check == null || c == null) return base.IsAccessibleTo(check); + if (check == null || c == null) + { + return base.IsAccessibleTo(check); + } return c.RootParent == check && IsChildOf(c); } @@ -125,11 +128,19 @@ namespace Server.Items { var c = GetSecureTradeCont(); - if (c?.Trade == null) return; + if (c?.Trade == null) + { + return; + } if (user == c.Trade.From.Mobile) + { c.Trade.UpdateFromCurrency(); - else if (user == c.Trade.To.Mobile) c.Trade.UpdateToCurrency(); + } + else if (user == c.Trade.To.Mobile) + { + c.Trade.UpdateToCurrency(); + } c.ClearChecks(); } @@ -194,7 +205,9 @@ namespace Server.Items base.OnServerClose(owner); if (Check?.Deleted == false) + { Check.UpdateTrade(User); + } } public void Close() @@ -202,17 +215,25 @@ namespace Server.Items User.CloseGump(); if (Check?.Deleted == false) + { Check.UpdateTrade(User); + } else + { Check = null; + } } public void Send() { if (Check?.Deleted == false) + { User.SendGump(this); + } else + { Close(); + } } public void Refresh(bool recompile) @@ -224,7 +245,9 @@ namespace Server.Items } if (recompile) + { CompileLayout(); + } Close(); Send(); @@ -233,7 +256,9 @@ namespace Server.Items private void CompileLayout() { if (Check?.Deleted != false) + { return; + } Entries.ForEach(e => e.Parent = null); Entries.Clear(); @@ -353,7 +378,9 @@ namespace Server.Items } if (updated) + { User.SendMessage("Your offer has been updated."); + } if (refresh && Check?.Deleted == false) { diff --git a/Projects/Server/Items/VirtualHair.cs b/Projects/Server/Items/VirtualHair.cs index 913e2a0de..66de253eb 100644 --- a/Projects/Server/Items/VirtualHair.cs +++ b/Projects/Server/Items/VirtualHair.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * VirtualHair.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server diff --git a/Projects/Server/JsonConfiguration/Converters/IPEndPointConverter.cs b/Projects/Server/JsonConfiguration/Converters/IPEndPointConverter.cs index 29e1a8cc3..586513786 100644 --- a/Projects/Server/JsonConfiguration/Converters/IPEndPointConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/IPEndPointConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IPEndPointConverter.cs * * * @@ -25,7 +25,9 @@ namespace Server.Json public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (IPEndPoint.TryParse(reader.GetString(), out var ipep)) + { return ipep; + } throw new JsonException("IPEndPoint must be in the correct format"); } diff --git a/Projects/Server/JsonConfiguration/Converters/IPEndPointConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/IPEndPointConverterFactory.cs index 9dd01410c..3a05cb364 100644 --- a/Projects/Server/JsonConfiguration/Converters/IPEndPointConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/IPEndPointConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IPEndPointConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/MapConverter.cs b/Projects/Server/JsonConfiguration/Converters/MapConverter.cs index 08eb50f3c..f93a412e3 100644 --- a/Projects/Server/JsonConfiguration/Converters/MapConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/MapConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MapConverter.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/MapConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/MapConverterFactory.cs index d23b36b5c..9e00e463e 100644 --- a/Projects/Server/JsonConfiguration/Converters/MapConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/MapConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MapConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/NullableStructSerializer.cs b/Projects/Server/JsonConfiguration/Converters/NullableStructSerializer.cs index 187fa4038..eae088e3c 100644 --- a/Projects/Server/JsonConfiguration/Converters/NullableStructSerializer.cs +++ b/Projects/Server/JsonConfiguration/Converters/NullableStructSerializer.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: NullableStructSerializer.cs * * * @@ -25,9 +25,13 @@ namespace System.Text.Json.Serialization public override void Write(Utf8JsonWriter writer, TStruct? value, JsonSerializerOptions options) { if (value == null) + { writer.WriteNullValue(); + } else + { JsonSerializer.Serialize(writer, value.Value, options); + } } } } diff --git a/Projects/Server/JsonConfiguration/Converters/NullableStructSerializerFactory.cs b/Projects/Server/JsonConfiguration/Converters/NullableStructSerializerFactory.cs index 2f76e0bc1..05a65844e 100644 --- a/Projects/Server/JsonConfiguration/Converters/NullableStructSerializerFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/NullableStructSerializerFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: NullableStructSerializerFactory.cs * * * @@ -20,7 +20,9 @@ namespace System.Text.Json.Serialization public override bool CanConvert(Type typeToConvert) { if (!typeToConvert.IsGenericType || typeToConvert.GetGenericTypeDefinition() != typeof(Nullable<>)) + { return false; + } var structType = typeToConvert.GenericTypeArguments[0]; return !structType.IsPrimitive && structType.Namespace?.StartsWith(nameof(System)) != true && !structType.IsEnum; diff --git a/Projects/Server/JsonConfiguration/Converters/Point2DConverter.cs b/Projects/Server/JsonConfiguration/Converters/Point2DConverter.cs index 971127b47..633aeb075 100644 --- a/Projects/Server/JsonConfiguration/Converters/Point2DConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/Point2DConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point2DConverter.cs * * * @@ -30,19 +30,25 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndArray) + { break; + } if (reader.TokenType == JsonTokenType.Number) { if (count < 2) + { data[count] = reader.GetInt32(); + } count++; } } if (count > 2) + { throw new JsonException("Point2D must be an array of x, y"); + } return new Point2D(data[0], data[1]); } @@ -55,10 +61,14 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndObject) + { break; + } if (reader.TokenType != JsonTokenType.PropertyName) + { throw new JsonException("Invalid json structure for Point2D object"); + } var key = reader.GetString(); @@ -72,7 +82,9 @@ namespace Server.Json reader.Read(); if (reader.TokenType != JsonTokenType.Number) + { throw new JsonException($"Value for {key} must be a number"); + } data[i] = reader.GetInt32(); } diff --git a/Projects/Server/JsonConfiguration/Converters/Point2DConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/Point2DConverterFactory.cs index 208550f9c..7243f3854 100644 --- a/Projects/Server/JsonConfiguration/Converters/Point2DConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/Point2DConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point2DConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/Point3DConverter.cs b/Projects/Server/JsonConfiguration/Converters/Point3DConverter.cs index 2fe85422a..3c9281065 100644 --- a/Projects/Server/JsonConfiguration/Converters/Point3DConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/Point3DConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point3DConverter.cs * * * @@ -30,19 +30,25 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndArray) + { break; + } if (reader.TokenType == JsonTokenType.Number) { if (count < 3) + { data[count] = reader.GetInt32(); + } count++; } } if (count > 3) + { throw new JsonException("Point3D must be an array of x, y, z"); + } return new Point3D(data[0], data[1], data[2]); } @@ -55,10 +61,14 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndObject) + { break; + } if (reader.TokenType != JsonTokenType.PropertyName) + { throw new JsonException("Invalid json structure for Point3D object"); + } var key = reader.GetString(); @@ -73,7 +83,9 @@ namespace Server.Json reader.Read(); if (reader.TokenType != JsonTokenType.Number) + { throw new JsonException($"Value for {key} must be a number"); + } data[i] = reader.GetInt32(); } diff --git a/Projects/Server/JsonConfiguration/Converters/Point3DConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/Point3DConverterFactory.cs index d026cd701..1b8097cfa 100644 --- a/Projects/Server/JsonConfiguration/Converters/Point3DConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/Point3DConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Point3DConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverter.cs b/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverter.cs index 72f142018..1401ad874 100644 --- a/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Rectangle3DConverter.cs * * * @@ -30,19 +30,25 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndArray) + { break; + } if (reader.TokenType == JsonTokenType.Number) { if (count < 6) + { data[count] = reader.GetInt32(); + } count++; } } if (count > 6) + { throw new JsonException("Rectangle3D must be an array of x, y, z, h, w, d"); + } return new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5]); } @@ -59,10 +65,14 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndObject) + { break; + } if (reader.TokenType != JsonTokenType.PropertyName) + { throw new JsonException("Invalid json structure for Rectangle3D object"); + } var key = reader.GetString(); @@ -71,7 +81,9 @@ namespace Server.Json if (key == "start" || key == "end") { if (objType > -1 && objType != 2) + { throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both."); + } objType = 2; @@ -107,20 +119,31 @@ namespace Server.Json if (i < 10) { if (objType > -1 && objType != 0) + { throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both."); + } objType = 0; data[i] = reader.GetInt32(); - if (i == 2) hasZ = true; + if (i == 2) + { + hasZ = true; + } + continue; } if (objType > -1 && objType != 1) + { throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both."); + } objType = 1; data[i - 10] = reader.GetInt32(); - if (i == 12 || i == 15) hasZ = true; + if (i == 12 || i == 15) + { + hasZ = true; + } } if (!hasZ) diff --git a/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverterFactory.cs index 431916b0d..9a2f6093f 100644 --- a/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/Rectangle3DConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Rectangle3DConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/TimeSpanConverter.cs b/Projects/Server/JsonConfiguration/Converters/TimeSpanConverter.cs index f3b53e463..a72a96e51 100644 --- a/Projects/Server/JsonConfiguration/Converters/TimeSpanConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/TimeSpanConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TimeSpanConverter.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/TimeSpanConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/TimeSpanConverterFactory.cs index 344f96225..f329b5708 100644 --- a/Projects/Server/JsonConfiguration/Converters/TimeSpanConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/TimeSpanConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TimeSpanConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/TypeConverter.cs b/Projects/Server/JsonConfiguration/Converters/TypeConverter.cs index d26a293c2..02f4fb397 100644 --- a/Projects/Server/JsonConfiguration/Converters/TypeConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/TypeConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TypeConverter.cs * * * @@ -24,7 +24,9 @@ namespace Server.Json public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.String) + { throw new JsonException("The JSON value could not be converted to System.Type"); + } return AssemblyHandler.FindFirstTypeForName(reader.GetString()); } diff --git a/Projects/Server/JsonConfiguration/Converters/TypeConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/TypeConverterFactory.cs index 308808a6d..ea4b41504 100644 --- a/Projects/Server/JsonConfiguration/Converters/TypeConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/TypeConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TypeConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/Converters/WorldLocationConverter.cs b/Projects/Server/JsonConfiguration/Converters/WorldLocationConverter.cs index 12f53ff89..8a9ec6885 100644 --- a/Projects/Server/JsonConfiguration/Converters/WorldLocationConverter.cs +++ b/Projects/Server/JsonConfiguration/Converters/WorldLocationConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: WorldLocationConverter.cs * * * @@ -32,14 +32,20 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndArray) + { break; + } if (reader.TokenType == JsonTokenType.Number) { if (count < 3) + { data[count] = reader.GetInt32(); + } else if (count == 3) + { map = Map.Maps[reader.GetInt32()]; + } count++; } @@ -52,7 +58,9 @@ namespace Server.Json } if (!hasMap || count < 3 || count > 4) + { throw new JsonException("WorldLocation must be an array of x, y, z, and map"); + } return new WorldLocation(data[0], data[1], data[2], map); } @@ -70,10 +78,14 @@ namespace Server.Json { reader.Read(); if (reader.TokenType == JsonTokenType.EndObject) + { break; + } if (reader.TokenType != JsonTokenType.PropertyName) + { throw new JsonException("Invalid Json structure for WorldLocation object"); + } var key = reader.GetString(); @@ -88,17 +100,23 @@ namespace Server.Json }; if (i == 5) + { continue; + } reader.Read(); if (i < 3) { if (hasLoc) + { throw new JsonException("WorldLocation must have loc or x, y, z, but not both"); + } if (reader.TokenType != JsonTokenType.Number) + { throw new JsonException($"Value for {key} must be a number"); + } hasXYZ = true; data[i] = reader.GetInt32(); @@ -108,7 +126,9 @@ namespace Server.Json if (i == 3) { if (hasXYZ) + { throw new JsonException("WorldLocation must have loc or x, y, z, but not both"); + } hasLoc = true; var loc = new Point3DConverter().Read(ref reader, typeof(Point3D), options); @@ -128,7 +148,9 @@ namespace Server.Json } if (!hasMap || count < 2) + { throw new JsonException("WorldLocation must have an x, y, z, and map properties"); + } return new WorldLocation(data[0], data[1], data[2], map); } diff --git a/Projects/Server/JsonConfiguration/Converters/WorldLocationConverterFactory.cs b/Projects/Server/JsonConfiguration/Converters/WorldLocationConverterFactory.cs index 54b401d47..a370e9b9b 100644 --- a/Projects/Server/JsonConfiguration/Converters/WorldLocationConverterFactory.cs +++ b/Projects/Server/JsonConfiguration/Converters/WorldLocationConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: WorldLocationConverterFactory.cs * * * diff --git a/Projects/Server/JsonConfiguration/DynamicJson.cs b/Projects/Server/JsonConfiguration/DynamicJson.cs index 8b5a8cef1..880d96427 100644 --- a/Projects/Server/JsonConfiguration/DynamicJson.cs +++ b/Projects/Server/JsonConfiguration/DynamicJson.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: DynamicJson.cs * * * @@ -41,7 +41,9 @@ namespace Server.Json public bool GetEnumProperty(string key, JsonSerializerOptions options, out T t) where T : struct, Enum { if (data.TryGetValue(key, out var el)) + { return Enum.TryParse(el.ToObject(options), out t); + } t = default; return false; diff --git a/Projects/Server/JsonConfiguration/JsonConfig.cs b/Projects/Server/JsonConfiguration/JsonConfig.cs index 3bc89af0b..fb25de5e1 100644 --- a/Projects/Server/JsonConfiguration/JsonConfig.cs +++ b/Projects/Server/JsonConfiguration/JsonConfig.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: JsonConfig.cs * * * diff --git a/Projects/Server/KeywordList.cs b/Projects/Server/KeywordList.cs index fd28d50d3..eb3662c7f 100644 --- a/Projects/Server/KeywordList.cs +++ b/Projects/Server/KeywordList.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * KeywordList.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server @@ -40,7 +20,9 @@ namespace Server var contains = false; for (var i = 0; !contains && i < Count; ++i) + { contains = keyword == m_Keywords[i]; + } return contains; } @@ -53,7 +35,9 @@ namespace Server m_Keywords = new int[old.Length * 2]; for (var i = 0; i < old.Length; ++i) + { m_Keywords[i] = old[i]; + } } m_Keywords[Count++] = keyword; @@ -62,12 +46,16 @@ namespace Server public int[] ToArray() { if (Count == 0) + { return m_EmptyInts; + } var keywords = new int[Count]; for (var i = 0; i < Count; ++i) + { keywords[i] = m_Keywords[i]; + } Count = 0; diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index 13a85631d..1f4a14c23 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Main.cs * * * @@ -104,8 +104,6 @@ namespace Server ? m_ProfileTime + (DateTime.UtcNow - m_ProfileStart) : m_ProfileTime; - internal static bool HaltOnWarning { get; private set; } - public static Assembly Assembly { get; set; } // Assembly file version @@ -172,11 +170,6 @@ namespace Server Utility.Separate(sb, "-profile", " "); } - if (HaltOnWarning) - { - Utility.Separate(sb, "-haltonwarning", " "); - } - return sb.ToString(); } } @@ -366,10 +359,6 @@ namespace Server { Profiling = true; } - else if (Insensitive.Equals(a, "-haltonwarning")) - { - HaltOnWarning = true; - } } Thread = Thread.CurrentThread; @@ -392,7 +381,6 @@ namespace Server } Utility.PushColor(ConsoleColor.Green); - // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not Console.WriteLine( "ModernUO - [https://github.com/modernuo/modernuo] Version {0}.{1}.{2}.{3}", Version.Major, @@ -400,9 +388,20 @@ namespace Server Version.Build, Version.Revision ); - Console.WriteLine("Core: Running on {0}\n", RuntimeInformation.FrameworkDescription); Utility.PopColor(); + Utility.PushColor(ConsoleColor.DarkGray); + Console.WriteLine(@"Copyright 2019-2020 ModernUO Development Team + This program comes with ABSOLUTELY NO WARRANTY; + This is free software, and you are welcome to redistribute it under certain conditions. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + ".TrimMultiline()); + Utility.PopColor(); + + Console.WriteLine("Core: Running on {0}", RuntimeInformation.FrameworkDescription); + var ttObj = new Timer.TimerThread(); timerThread = new Thread(ttObj.TimerMain) { diff --git a/Projects/Server/Map.cs b/Projects/Server/Map.cs index 98a70ef99..73f3a47b2 100644 --- a/Projects/Server/Map.cs +++ b/Projects/Server/Map.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Map.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections; using System.Collections.Generic; @@ -82,9 +62,14 @@ namespace Server { var eable = Enumerable.Empty(); if (mobiles) + { eable = eable.Union(s.Mobiles.Where(o => o?.Deleted == false)); + } + if (items) + { eable = eable.Union(s.Items.Where(o => o?.Deleted == false && o.Parent == null)); + } return eable.Where(bounds.Contains); } @@ -118,17 +103,26 @@ namespace Server { xo = x - (o.X + c.Min.X); - if (xo < 0 || xo >= c.Width) continue; + if (xo < 0 || xo >= c.Width) + { + continue; + } for (y = bounds.Start.Y; y < bounds.End.Y; y++) { yo = y - (o.Y + c.Min.Y); - if (yo < 0 || yo >= c.Height) continue; + if (yo < 0 || yo >= c.Height) + { + continue; + } t = c.Tiles[xo][yo]; - if (t.Length <= 0) continue; + if (t.Length <= 0) + { + continue; + } r = new StaticTile[t.Length]; @@ -170,7 +164,9 @@ namespace Server public static IEnumerable EnumerateSectors(Map map, Rectangle2D bounds) { if (map == null || map == Map.Internal) + { yield break; + } var x1 = bounds.Start.X; var y1 = bounds.Start.Y; @@ -178,12 +174,16 @@ namespace Server var y2 = bounds.End.Y; if (!Bound(map, ref x1, ref y1, ref x2, ref y2, out var xSector, out var ySector)) + { yield break; + } var index = 0; while (NextSector(map, x1, y1, x2, y2, ref index, ref xSector, ref ySector, out var s)) + { yield return s; + } } public static bool Bound( @@ -243,6 +243,7 @@ namespace Server } if (index++ > 0) + { if (++ySector > y2) { ySector = y1; @@ -255,6 +256,7 @@ namespace Server return false; } } + } s = map.GetRealSector(xSector, ySector); return true; @@ -321,10 +323,12 @@ namespace Server get { if (m_Tiles == null) + { lock (tileLock) { m_Tiles = new TileMatrix(this, m_FileIndex, MapID, Width, Height); } + } return m_Tiles; } @@ -389,13 +393,19 @@ namespace Server public static Map Parse(string value) { if (string.IsNullOrWhiteSpace(value)) + { return null; + } if (Insensitive.Equals(value, "Internal")) + { return Internal; + } if (!int.TryParse(value, out var index)) + { return Maps.FirstOrDefault(m => m != null && Insensitive.Equals(m.Name, value)); + } return index == 127 ? Internal : Maps.FirstOrDefault(m => m?.MapIndex == index); } @@ -420,19 +430,35 @@ namespace Server z = zTop; if (zLeft < z) + { z = zLeft; + } + if (zRight < z) + { z = zRight; + } + if (zBottom < z) + { z = zBottom; + } top = zTop; if (zLeft > top) + { top = zLeft; + } + if (zRight > top) + { top = zRight; + } + if (zBottom > top) + { top = zBottom; + } avg = Math.Abs(zTop - zBottom) > Math.Abs(zLeft - zRight) ? FloorAverage(zLeft, zRight) @@ -444,7 +470,9 @@ namespace Server var v = a + b; if (v < 0) + { --v; + } return v / 2; } @@ -455,14 +483,18 @@ namespace Server private static List AcquireFixItems(Map map, int x, int y) { if (map == null || map == Internal || x < 0 || x > map.Width || y < 0 || y > map.Height) + { return m_EmptyFixItems; + } List pool = null; lock (m_FixPool) { if (m_FixPool.Count > 0) + { pool = m_FixPool.Dequeue(); + } } pool ??= new List(128); // Arbitrary limit @@ -483,14 +515,18 @@ namespace Server private static void FreeFixItems(List pool) { if (pool == m_EmptyFixItems) + { return; + } pool.Clear(); lock (m_FixPool) { if (m_FixPool.Count < 128) + { m_FixPool.Enqueue(pool); + } } } @@ -509,13 +545,17 @@ namespace Server var toFix = items[i]; if (!toFix.Movable) + { continue; + } var z = int.MinValue; var currentZ = toFix.Z; if (!landTile.Ignored && landAvg <= currentZ) + { z = landAvg; + } foreach (var tile in tiles) { @@ -525,16 +565,22 @@ namespace Server var checkTop = checkZ + id.CalcHeight; if (checkTop == checkZ && !id.Surface) + { ++checkTop; + } if (checkTop > z && checkTop <= currentZ) + { z = checkTop; + } } for (var j = 0; j < items.Count; ++j) { if (j == i) + { continue; + } var item = items[j]; var id = item.ItemData; @@ -543,14 +589,20 @@ namespace Server var checkTop = checkZ + id.CalcHeight; if (checkTop == checkZ && !id.Surface) + { ++checkTop; + } if (checkTop > z && checkTop <= currentZ) + { z = checkTop; + } } if (z != int.MinValue) + { toFix.Location = new Point3D(toFix.X, toFix.Y, z); + } } FreeFixItems(items); @@ -560,25 +612,25 @@ namespace Server public List GetTilesAt( Point2D p, bool items, bool land, bool statics ) { List list = new List(); - + if (this == Internal) return list; - + if (land) list.Add( Tiles.GetLandTile( p.m_X, p.m_Y ) ); - + if (statics) list.AddRange( Tiles.GetStaticTiles( p.m_X, p.m_Y, true ) ); - + if (items) { Sector sector = GetSector( p ); - + foreach ( Item item in sector.Items ) if (item.AtWorldPoint( p.m_X, p.m_Y )) list.Add( new StaticTile( (ushort)item.ItemID, (sbyte) item.Z ) ); } - + return list; } */ @@ -591,7 +643,9 @@ namespace Server public object GetTopSurface(Point3D p) { if (this == Internal) + { return null; + } object surface = null; var surfaceZ = int.MinValue; @@ -608,7 +662,9 @@ namespace Server surfaceZ = avgZ; if (surfaceZ == p.Z) + { return surface; + } } } @@ -629,7 +685,9 @@ namespace Server surfaceZ = tileZ; if (surfaceZ == p.Z) + { return surface; + } } } } @@ -655,7 +713,9 @@ namespace Server surfaceZ = itemZ; if (surfaceZ == p.Z) + { return surface; + } } } } @@ -681,34 +741,46 @@ namespace Server public void ActivateSectors(int cx, int cy) { for (var x = cx - SectorActiveRange; x <= cx + SectorActiveRange; ++x) + { for (var y = cy - SectorActiveRange; y <= cy + SectorActiveRange; ++y) { var sect = GetRealSector(x, y); if (sect != InvalidSector) + { sect.Activate(); + } } + } } public void DeactivateSectors(int cx, int cy) { for (var x = cx - SectorActiveRange; x <= cx + SectorActiveRange; ++x) + { for (var y = cy - SectorActiveRange; y <= cy + SectorActiveRange; ++y) { var sect = GetRealSector(x, y); if (sect != InvalidSector && !PlayersInRange(sect, SectorActiveRange)) + { sect.Deactivate(); + } } + } } private bool PlayersInRange(Sector sect, int range) { for (var x = sect.X - range; x <= sect.X + range; ++x) + { for (var y = sect.Y - range; y <= sect.Y + range; ++y) { var check = GetRealSector(x, y); if (check != InvalidSector && check.Players.Count > 0) + { return true; + } } + } return false; } @@ -716,19 +788,25 @@ namespace Server public void OnClientChange(NetState oldState, NetState newState, Mobile m) { if (this != Internal) + { GetSector(m).OnClientChange(oldState, newState); + } } public void OnEnter(Mobile m) { if (this != Internal) + { GetSector(m).OnEnter(m); + } } public void OnEnter(Item item) { if (this == Internal) + { return; + } GetSector(item).OnEnter(item); @@ -746,13 +824,17 @@ namespace Server public void OnLeave(Mobile m) { if (this != Internal) + { GetSector(m).OnLeave(m); + } } public void OnLeave(Item item) { if (this == Internal) + { return; + } GetSector(item).OnLeave(item); @@ -770,21 +852,33 @@ namespace Server public void RemoveMulti(BaseMulti m, Sector start, Sector end) { if (this == Internal) + { return; + } for (var x = start.X; x <= end.X; ++x) + { for (var y = start.Y; y <= end.Y; ++y) + { InternalGetSector(x, y).OnMultiLeave(m); + } + } } public void AddMulti(BaseMulti m, Sector start, Sector end) { if (this == Internal) + { return; + } for (var x = start.X; x <= end.X; ++x) + { for (var y = start.Y; y <= end.Y; ++y) + { InternalGetSector(x, y).OnMultiEnter(m); + } + } } public Sector GetMultiMinSector(Point3D loc, MultiComponentList mcl) => @@ -796,7 +890,9 @@ namespace Server public void OnMove(Point3D oldLocation, Mobile m) { if (this == Internal) + { return; + } var oldSector = GetSector(oldLocation); var newSector = GetSector(m.Location); @@ -811,7 +907,9 @@ namespace Server public void OnMove(Point3D oldLocation, Item item) { if (this == Internal) + { return; + } var oldSector = GetSector(oldLocation); var newSector = GetSector(item.Location); @@ -845,12 +943,18 @@ namespace Server var regName = reg.Name; if (regName == null) + { return; + } if (Regions.ContainsKey(regName)) + { Console.WriteLine("Warning: Duplicate region name '{0}' for map '{1}'", regName, Name); + } else + { Regions[regName] = reg; + } } public void UnregisterRegion(Region reg) @@ -858,7 +962,9 @@ namespace Server var regName = reg.Name; if (regName != null) + { Regions.Remove(regName); + } } public Point3D GetPoint(object o, bool eye) @@ -969,10 +1075,14 @@ namespace Server ) { if (this == Internal) + { return false; + } if (x < 0 || y < 0 || x >= Width || y >= Height) + { return false; + } var hasSurface = false; @@ -983,10 +1093,14 @@ namespace Server var landFlags = TileData.LandTable[lt.ID & TileData.MaxLandValue].Flags; if ((landFlags & TileFlag.Impassable) != 0 && avgZ > z && z + height > lowZ) + { return false; + } if ((landFlags & TileFlag.Impassable) == 0 && z == avgZ && !lt.Ignored) + { hasSurface = true; + } var staticTiles = Tiles.GetStaticTiles(x, y, true); @@ -999,10 +1113,14 @@ namespace Server impassable = id.Impassable; if ((surface || impassable) && staticTiles[i].Z + id.CalcHeight > z && z + height > staticTiles[i].Z) + { return false; + } if (surface && !impassable && z == staticTiles[i].Z + id.CalcHeight) + { hasSurface = true; + } } var sector = GetSector(x, y); @@ -1021,22 +1139,30 @@ namespace Server if ((surface || impassable || checkBlocksFit && item.BlocksFit) && item.Z + id.CalcHeight > z && z + height > item.Z) + { return false; + } if (surface && !impassable && !item.Movable && z == item.Z + id.CalcHeight) + { hasSurface = true; + } } } if (checkMobiles) + { for (var i = 0; i < mobs.Count; ++i) { var m = mobs[i]; if (m.Location.m_X == x && m.Location.m_Y == y && (m.AccessLevel == AccessLevel.Player || !m.Hidden) && m.Z + 16 > z && z + height > m.Z) + { return false; + } } + } return !requireSurface || hasSurface; } @@ -1065,12 +1191,16 @@ namespace Server var xSectors = m_Sectors[x]; if (xSectors == null) + { m_Sectors[x] = xSectors = new Sector[m_SectorsHeight]; + } var sec = xSectors[y]; if (sec == null) + { xSectors[y] = sec = new Sector(x, y, this); + } return sec; } @@ -1081,10 +1211,14 @@ namespace Server public bool LineOfSight(Point3D org, Point3D dest) { if (this == Internal) + { return false; + } if (!Utility.InRange(org, dest, MaxLOSDistance)) + { return false; + } var end = dest; @@ -1101,10 +1235,14 @@ namespace Server TileFlag flags; if (org == dest) + { return true; + } if (path.Count > 0) + { path.Clear(); + } var xd = dest.m_X - org.m_X; var yd = dest.m_Y - org.m_Y; @@ -1130,7 +1268,9 @@ namespace Server p = path.Last; if (p.m_X != ix || p.m_Y != iy || p.m_Z != iz) + { path.Add(ix, iy, iz); + } } else { @@ -1143,12 +1283,16 @@ namespace Server } if (path.Count == 0) + { return true; // <--should never happen, but to be safe. + } p = path.Last; if (p != dest) + { path.Add(dest); + } Point3D pTop = org, pBottom = dest; Utility.FixPoints(ref pTop, ref pBottom); @@ -1168,7 +1312,9 @@ namespace Server if (landZ <= pointTop && landTop >= point.m_Z && (point.m_X != end.m_X || point.m_Y != end.m_Y || landZ > endTop || landTop < end.m_Z) && !landTile.Ignored) + { return false; + } /* --Do land tiles need to be checked? There is never land between two people, always statics.-- LandTile landTile = Tiles.GetLandTile( point.X, point.Y ); @@ -1182,7 +1328,9 @@ namespace Server var ltID = landTile.ID; for (var j = 0; !contains && j < InvalidLandTiles.Length; ++j) + { contains = ltID == InvalidLandTiles[j]; + } if (contains && statics.Length == 0) { @@ -1193,7 +1341,9 @@ namespace Server eable.Free(); if (contains) + { return false; + } } for (var j = 0; j < statics.Length; ++j) @@ -1208,7 +1358,9 @@ namespace Server if (t.Z <= pointTop && t.Z + height >= point.Z && (flags & (TileFlag.Window | TileFlag.NoShoot)) != 0) { if (point.m_X == end.m_X && point.m_Y == end.m_Y && t.Z <= endTop && t.Z + height >= end.m_Z) + { continue; + } return false; } @@ -1230,16 +1382,22 @@ namespace Server foreach (var i in area) { if (!i.Visible) + { continue; + } if (i is BaseMulti || i.ItemID > TileData.MaxItemValue) + { continue; + } var id = i.ItemData; flags = id.Flags; if ((flags & (TileFlag.Window | TileFlag.NoShoot)) == 0) + { continue; + } height = id.CalcHeight; @@ -1255,21 +1413,25 @@ namespace Server // if (t.Z <= point.Z && t.Z+height >= point.Z && ( height != 0 || ( t.Z == dest.Z && zd != 0 ) )) if (loc.m_X == point.m_X && loc.m_Y == point.m_Y && loc.m_Z <= pointTop && loc.m_Z + height >= point.m_Z) + { if (loc.m_X != end.m_X || loc.m_Y != end.m_Y || loc.m_Z > endTop || loc.m_Z + height < end.m_Z) { found = true; break; } + } } if (!found) + { continue; + } area.Free(); return false; /*if ((flags & (TileFlag.Impassable | TileFlag.Surface | TileFlag.Roof)) != 0) - + //flags = TileData.ItemTable[i.ItemID&TileData.MaxItemValue].Flags; //if ((flags&TileFlag.Window)==0 && (flags&TileFlag.NoShoot)!=0 && ( (flags&TileFlag.Wall)!=0 || (flags&TileFlag.Roof)!=0 || (((flags&TileFlag.Surface)!=0 && zd != 0)) )) { @@ -1291,7 +1453,9 @@ namespace Server public bool LineOfSight(Mobile from, Point3D target) { if (from.AccessLevel > AccessLevel.Player) + { return true; + } var eye = from.Location; @@ -1303,7 +1467,9 @@ namespace Server public bool LineOfSight(Mobile from, Mobile to) { if (from == to || from.AccessLevel > AccessLevel.Player) + { return true; + } var eye = from.Location; var target = to.Location; @@ -1349,7 +1515,9 @@ namespace Server } if (locs != null) + { locs[xRand, yRand] = true; + } } j++; @@ -1404,7 +1572,9 @@ namespace Server public void Free() { if (m_IsDisposed) + { return; + } m_Pool.Clear(); m_Pool.Capacity = Math.Max(m_Pool.Capacity, 0x100); @@ -1424,13 +1594,17 @@ namespace Server lock (((ICollection)_Buffer).SyncRoot) { if (_Buffer.Count > 0) + { e = _Buffer.Dequeue(); + } } var pool = PooledEnumeration.EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds)); if (e == null) + { return new PooledEnumerable(pool); + } e.m_Pool.AddRange(pool); return e; diff --git a/Projects/Server/Menus/IMenu.cs b/Projects/Server/Menus/IMenu.cs index d9892ab59..bb007d7f0 100644 --- a/Projects/Server/Menus/IMenu.cs +++ b/Projects/Server/Menus/IMenu.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * IMenu.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Menus diff --git a/Projects/Server/Menus/ItemListMenu.cs b/Projects/Server/Menus/ItemListMenu.cs index b83a167f7..ed111c304 100644 --- a/Projects/Server/Menus/ItemListMenu.cs +++ b/Projects/Server/Menus/ItemListMenu.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ItemListMenu.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Menus.ItemLists diff --git a/Projects/Server/Menus/QuestionMenu.cs b/Projects/Server/Menus/QuestionMenu.cs index 9b3475563..992ae2b4f 100644 --- a/Projects/Server/Menus/QuestionMenu.cs +++ b/Projects/Server/Menus/QuestionMenu.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * QuestionMenu.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Menus.Questions diff --git a/Projects/Server/AggressorInfo.cs b/Projects/Server/Mobiles/AggressorInfo.cs similarity index 83% rename from Projects/Server/AggressorInfo.cs rename to Projects/Server/Mobiles/AggressorInfo.cs index 7b89d3081..26afe9050 100644 --- a/Projects/Server/AggressorInfo.cs +++ b/Projects/Server/Mobiles/AggressorInfo.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * AggressorInfo.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Diagnostics; @@ -54,7 +34,9 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_Attacker.Deleted || m_Defender.Deleted || DateTime.UtcNow >= m_LastCombatTime + ExpireDelay; } @@ -65,14 +47,18 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_CriminalAggression; } set { if (m_Queued) + { DumpAccess(); + } m_CriminalAggression = value; } @@ -83,7 +69,9 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_Attacker; } @@ -94,7 +82,9 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_Defender; } @@ -105,7 +95,9 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_LastCombatTime; } @@ -116,14 +108,18 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_Reported; } set { if (m_Queued) + { DumpAccess(); + } m_Reported = value; } @@ -134,14 +130,18 @@ namespace Server get { if (m_Queued) + { DumpAccess(); + } return m_CanReportMurder; } set { if (m_Queued) + { DumpAccess(); + } m_CanReportMurder = value; } @@ -176,7 +176,9 @@ namespace Server public void Free() { if (m_Queued) + { return; + } m_Queued = true; m_Pool.Enqueue(this); @@ -194,7 +196,9 @@ namespace Server public void Refresh() { if (m_Queued) + { DumpAccess(); + } m_LastCombatTime = DateTime.UtcNow; m_Reported = false; diff --git a/Projects/Server/BaseVendor.cs b/Projects/Server/Mobiles/BaseVendor.cs similarity index 64% rename from Projects/Server/BaseVendor.cs rename to Projects/Server/Mobiles/BaseVendor.cs index c90698510..467708ee1 100644 --- a/Projects/Server/BaseVendor.cs +++ b/Projects/Server/Mobiles/BaseVendor.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * BaseVendor.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Collections.Generic; namespace Server @@ -26,9 +6,20 @@ namespace Server { public int Compare(BuyItemState l, BuyItemState r) { - if (l == null && r == null) return 0; - if (l == null) return -1; - if (r == null) return 1; + if (l == null && r == null) + { + return 0; + } + + if (l == null) + { + return -1; + } + + if (r == null) + { + return 1; + } return l.MySerial.CompareTo(r.MySerial); } diff --git a/Projects/Server/Body.cs b/Projects/Server/Mobiles/Body.cs similarity index 86% rename from Projects/Server/Body.cs rename to Projects/Server/Mobiles/Body.cs index fdf3ea297..595d1714e 100644 --- a/Projects/Server/Body.cs +++ b/Projects/Server/Mobiles/Body.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Body.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.IO; @@ -49,7 +29,9 @@ namespace Server while ((line = ip.ReadLine()) != null) { if (line.Length == 0 || line.StartsWith("#")) + { continue; + } var split = line.Split('\t'); diff --git a/Projects/Server/Mobiles/IMount.cs b/Projects/Server/Mobiles/IMount.cs index 19f6ac4d2..8590668a3 100644 --- a/Projects/Server/Mobiles/IMount.cs +++ b/Projects/Server/Mobiles/IMount.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IMount.cs * * * diff --git a/Projects/Server/Mobiles/IVendor.cs b/Projects/Server/Mobiles/IVendor.cs index 476d6f578..2eb842599 100644 --- a/Projects/Server/Mobiles/IVendor.cs +++ b/Projects/Server/Mobiles/IVendor.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IVendor.cs * * * diff --git a/Projects/Server/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs similarity index 92% rename from Projects/Server/Mobile.cs rename to Projects/Server/Mobiles/Mobile.cs index 1ebef0a57..5b1e30d17 100644 --- a/Projects/Server/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Mobile.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Diagnostics; @@ -129,7 +109,9 @@ namespace Server m_Owner = value; if (m_Owner != value) + { m_Owner.AddSkillMod(this); + } } } } @@ -270,7 +252,9 @@ namespace Server public bool HasElapsed() { if (m_Duration == TimeSpan.Zero) + { return false; + } return DateTime.UtcNow - m_Added >= m_Duration; } @@ -732,7 +716,9 @@ namespace Server set { if (Skills != null) + { Skills.Cap = value; + } } } @@ -785,11 +771,15 @@ namespace Server UpdateTotal(m_Holding, TotalType.Weight, -(m_Holding.TotalWeight + m_Holding.PileWeight)); if (m_Holding.HeldBy == this) + { m_Holding.HeldBy = null; + } } if (value != null && m_Holding != null) + { DropHolding(); + } m_Holding = value; @@ -940,7 +930,9 @@ namespace Server set { if (Deleted) + { return; + } if (m_Combatant != value && value != this) { @@ -1053,17 +1045,23 @@ namespace Server var newTarget = value; if (oldTarget == newTarget) + { return; + } m_Target = null; if (oldTarget != null && newTarget != null) + { oldTarget.Cancel(this, TargetCancelType.Overridden); + } m_Target = newTarget; if (newTarget != null && m_NetState != null && !TargetLocked) + { m_NetState.Send(newTarget.GetPacketFor(m_NetState)); + } OnTargetChange(); } @@ -1080,9 +1078,13 @@ namespace Server { // Old packet is preferred until assistants catch up if (m_NetState.NewHaven && m_ContextMenu.RequiresNewPacket) + { Send(new DisplayContextMenu(m_ContextMenu)); + } else + { Send(new DisplayContextMenuOld(m_ContextMenu)); + } } } } @@ -1113,7 +1115,9 @@ namespace Server set { if (m_Spell != null && value != null) + { Console.WriteLine("Warning: Spell has been overwritten"); + } m_Spell = value; } @@ -1223,9 +1227,13 @@ namespace Server InvalidateProperties(); if (!m_Player && m_Dex <= 100 && m_CombatTimer != null) + { m_CombatTimer.Priority = TimerPriority.FiftyMS; + } else if (m_CombatTimer != null) + { m_CombatTimer.Priority = TimerPriority.EveryTick; + } CheckStatTimers(); } @@ -1288,7 +1296,9 @@ namespace Server m_Fame = value; if (ShowFameTitle && (m_Player || m_Body.IsHuman) && oldValue >= 10000 != value >= 10000) + { InvalidateProperties(); + } OnFameChange(oldValue); } @@ -1350,7 +1360,9 @@ namespace Server get { if (m_HueMod != -1) + { return m_HueMod; + } return m_Hue; } @@ -1419,7 +1431,9 @@ namespace Server set { if (Deleted) + { return; + } if (m_Warmode != value) { @@ -1433,17 +1447,25 @@ namespace Server Delta(MobileDelta.Flags); if (m_NetState != null) + { Send(SetWarMode.Instantiate(value)); + } if (!m_Warmode) + { Combatant = null; + } if (!Alive) { if (value) + { Delta(MobileDelta.GhostUpdate); + } else + { SendRemovePacket(false); + } } OnWarmodeChanged(); @@ -1491,7 +1513,9 @@ namespace Server var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } // REMOVED: // m_Actions.Clear(); @@ -1506,9 +1530,13 @@ namespace Server // Disconnected, start the logout timer if (m_LogoutTimer == null) + { m_LogoutTimer = new LogoutTimer(this); + } else + { m_LogoutTimer.Stop(); + } m_LogoutTimer.Delay = GetLogoutDelay(); m_LogoutTimer.Start(); @@ -1534,18 +1562,22 @@ namespace Server for (var i = Items.Count - 1; i >= 0; --i) { if (i >= Items.Count) + { continue; + } var item = Items[i]; if (item is SecureTradeContainer) { for (var j = item.Items.Count - 1; j >= 0; --j) + { if (j < item.Items.Count) { item.Items[j].OnSecureTrade(this, this, this, false); AddToBackpack(item.Items[j]); } + } Timer.DelayCall(item.Delete); } @@ -1589,7 +1621,9 @@ namespace Server m_GuildTitle = value; if (m_Guild?.Disbanded == false && m_GuildTitle != null) + { SendLocalizedMessage(1018026, true, m_GuildTitle); // Your guild title has changed : + } InvalidateProperties(); @@ -1678,10 +1712,14 @@ namespace Server var d = LastStrGain; if (LastIntGain > d) + { d = LastIntGain; + } if (LastDexGain > d) + { d = LastDexGain; + } return d; } @@ -1703,7 +1741,9 @@ namespace Server if (old != value) { if (value == null) + { GuildTitle = null; + } m_Guild = value; @@ -1748,7 +1788,9 @@ namespace Server get { if (IsBodyMod) + { return m_BodyMod; + } return m_Body; } @@ -1790,7 +1832,11 @@ namespace Server get => m_SolidHueOverride; set { - if (m_SolidHueOverride == value) return; + if (m_SolidHueOverride == value) + { + return; + } + m_SolidHueOverride = value; Delta(MobileDelta.Hue | MobileDelta.Body); } @@ -1802,14 +1848,18 @@ namespace Server get { if (m_Weapon is Item item && !item.Deleted && item.Parent == this && CanSee(item)) + { return m_Weapon; + } m_Weapon = null; item = FindItemOnLayer(Layer.OneHanded) ?? FindItemOnLayer(Layer.TwoHanded); if (item is IWeapon weapon) + { return m_Weapon = weapon; + } return GetDefaultWeapon(); } @@ -1821,12 +1871,16 @@ namespace Server get { if (m_BankBox?.Deleted == false && m_BankBox.Parent == this) + { return m_BankBox; + } m_BankBox = FindItemOnLayer(Layer.Bank) as BankBox; if (m_BankBox == null) + { AddItem(m_BankBox = new BankBox(this)); + } return m_BankBox; } @@ -1838,7 +1892,9 @@ namespace Server get { if (m_Backpack?.Deleted != false || m_Backpack.Parent != this) + { m_Backpack = FindItemOnLayer(Layer.Backpack) as Container; + } return m_Backpack; } @@ -1880,7 +1936,9 @@ namespace Server set { if (m_ShortTermMurders != value) + { m_ShortTermMurders = Math.Max(value, 0); + } } } @@ -1900,9 +1958,13 @@ namespace Server if (m_Criminal) { if (m_ExpireCriminal == null) + { m_ExpireCriminal = new ExpireCriminalTimer(this); + } else + { m_ExpireCriminal.Stop(); + } m_ExpireCriminal.Start(); } @@ -1926,12 +1988,16 @@ namespace Server Item item = null; if (m_MountItem?.Deleted == false && m_MountItem.Parent == this) + { item = m_MountItem; + } item ??= FindItemOnLayer(Layer.Mount); if (!(item is IMountItem mountItem)) + { return null; + } m_MountItem = item; return mountItem.Mount; @@ -2047,17 +2113,23 @@ namespace Server var newPrompt = value; if (oldPrompt == newPrompt) + { return; + } m_Prompt = null; if (newPrompt != null) + { oldPrompt?.OnCancel(this); + } m_Prompt = newPrompt; if (newPrompt != null) + { Send(new UnicodePrompt(newPrompt)); + } } } @@ -2119,7 +2191,9 @@ namespace Server set { if (StatMods.Count == 0) + { RawStr = value; + } } } @@ -2176,7 +2250,9 @@ namespace Server set { if (StatMods.Count == 0) + { RawDex = value; + } } } @@ -2233,7 +2309,9 @@ namespace Server set { if (StatMods.Count == 0) + { RawInt = value; + } } } @@ -2250,7 +2328,9 @@ namespace Server set { if (Deleted) + { return; + } value = Math.Clamp(value, 0, HitsMax); @@ -2259,10 +2339,14 @@ namespace Server m_HitsTimer?.Stop(); for (var i = 0; i < Aggressors.Count; i++) // reset reports on full HP + { Aggressors[i].CanReportMurder = false; + } if (DamageEntries.Count > 0) + { DamageEntries.Clear(); // reset damage entries on full HP + } } else { @@ -2304,7 +2388,9 @@ namespace Server set { if (Deleted) + { return; + } value = Math.Clamp(value, 0, StamMax); @@ -2355,7 +2441,9 @@ namespace Server set { if (Deleted) + { return; + } value = Math.Clamp(value, 0, ManaMax); @@ -2440,11 +2528,17 @@ namespace Server set { if (m_Hair == null && value > 0) + { m_Hair = new HairInfo(value); + } else if (value <= 0) + { m_Hair = null; + } else if (m_Hair != null) + { m_Hair.ItemID = value; + } Delta(MobileDelta.Hair); } @@ -2460,11 +2554,17 @@ namespace Server set { if (m_FacialHair == null && value > 0) + { m_FacialHair = new FacialHairInfo(value); + } else if (value <= 0) + { m_FacialHair = null; + } else if (m_FacialHair != null) + { m_FacialHair.ItemID = value; + } Delta(MobileDelta.FacialHair); } @@ -2552,16 +2652,26 @@ namespace Server byte hairflag = 0x00; if (m_Hair != null) + { hairflag |= 0x01; + } + if (m_FacialHair != null) + { hairflag |= 0x02; + } writer.Write(hairflag); if ((hairflag & 0x01) != 0) + { m_Hair?.Serialize(writer); + } + if ((hairflag & 0x02) != 0) + { m_FacialHair?.Serialize(writer); + } writer.Write(Race); @@ -2668,10 +2778,14 @@ namespace Server public virtual void Delete() { if (Deleted) + { return; + } if (!World.OnDelete(this)) + { return; + } if (m_NetState != null) { @@ -2691,11 +2805,17 @@ namespace Server OnDelete(); for (var i = Items.Count - 1; i >= 0; --i) + { if (i < Items.Count) + { Items[i].OnParentDeleted(this); + } + } for (var i = 0; i < Stabled.Count; i++) + { Stabled[i].Delete(); + } SendRemovePacket(); @@ -2724,7 +2844,9 @@ namespace Server set { if (Deleted) + { return; + } if (m_Map != value) { @@ -2741,7 +2863,9 @@ namespace Server } for (var i = 0; i < Items.Count; ++i) + { Items[i].Map = value; + } m_Map = value; @@ -2755,17 +2879,25 @@ namespace Server { ns.Sequence = 0; if (Map != null) + { ns.Send(new MapChange(Map)); + } if (!Core.SE && ns.ProtocolChanges < ProtocolChanges.Version6000) + { ns.Send(new MapPatches()); + } ns.Send(SeasonChange.Instantiate(GetSeason(), true)); if (ns.StygianAbyss) + { ns.Send(new MobileUpdate(this)); + } else + { ns.Send(new MobileUpdateOld(this)); + } ClearFastwalkStack(); } @@ -2773,7 +2905,9 @@ namespace Server if (ns != null) { if (m_Map != null) + { ns.Send(new ServerChange(m_Location, m_Map)); + } ns.Sequence = 0; ClearFastwalkStack(); @@ -2833,7 +2967,9 @@ namespace Server public virtual void MoveToWorld(Point3D newLocation, Map map) { if (Deleted) + { return; + } if (m_Map == map) { @@ -2844,7 +2980,9 @@ namespace Server var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } var oldLocation = m_Location; var oldMap = m_Map; @@ -2860,7 +2998,9 @@ namespace Server } for (var i = 0; i < Items.Count; ++i) + { Items[i].Map = map; + } m_Map = map; @@ -2878,17 +3018,25 @@ namespace Server { ns.Sequence = 0; if (Map != null) + { ns.Send(new MapChange(Map)); + } if (!Core.SE && ns.ProtocolChanges < ProtocolChanges.Version6000) + { ns.Send(new MapPatches()); + } ns.Send(SeasonChange.Instantiate(GetSeason(), true)); if (ns.StygianAbyss) + { ns.Send(new MobileUpdate(this)); + } else + { ns.Send(new MobileUpdateOld(this)); + } ClearFastwalkStack(); } @@ -2901,7 +3049,9 @@ namespace Server if (ns != null) { if (m_Map != null) + { Send(new ServerChange(m_Location, m_Map)); + } ns.Sequence = 0; ClearFastwalkStack(); @@ -2979,7 +3129,9 @@ namespace Server var delta = m.m_DeltaFlags; if (delta == MobileDelta.None) + { return; + } var attrs = delta & MobileDelta.Attributes; @@ -3013,7 +3165,10 @@ namespace Server } } - if ((delta & MobileDelta.GhostUpdate) != 0) sendNonlocalIncoming = true; + if ((delta & MobileDelta.GhostUpdate) != 0) + { + sendNonlocalIncoming = true; + } if ((delta & MobileDelta.Hue) != 0) { @@ -3045,11 +3200,20 @@ namespace Server sendUpdate = true; } else*/ - if ((delta & (MobileDelta.Flags | MobileDelta.Noto)) != 0) sendMoving = true; + if ((delta & (MobileDelta.Flags | MobileDelta.Noto)) != 0) + { + sendMoving = true; + } - if ((delta & MobileDelta.HealthbarPoison) != 0) sendHealthbarPoison = true; + if ((delta & MobileDelta.HealthbarPoison) != 0) + { + sendHealthbarPoison = true; + } - if ((delta & MobileDelta.HealthbarYellow) != 0) sendHealthbarYellow = true; + if ((delta & MobileDelta.HealthbarYellow) != 0) + { + sendHealthbarYellow = true; + } if ((delta & MobileDelta.Name) != 0) { @@ -3062,12 +3226,16 @@ namespace Server if ((delta & (MobileDelta.WeaponDamage | MobileDelta.Resistances | MobileDelta.Stat | MobileDelta.Weight | MobileDelta.Gold | MobileDelta.Armor | MobileDelta.StatCap | MobileDelta.Followers | MobileDelta.TithingPoints | MobileDelta.Race)) != 0) + { sendPrivateStats = true; + } if ((delta & MobileDelta.Hair) != 0) { if (m.HairItemID <= 0) + { removeHair = true; + } sendHair = true; } @@ -3075,7 +3243,9 @@ namespace Server if ((delta & MobileDelta.FacialHair) != 0) { if (m.FacialHairItemID <= 0) + { removeFacialHair = true; + } sendFacialHair = true; } @@ -3091,15 +3261,21 @@ namespace Server ourState.Sequence = 0; if (ourState.StygianAbyss) + { ourState.Send(new MobileUpdate(m)); + } else + { ourState.Send(new MobileUpdateOld(m)); + } ClearFastwalkStack(); } if (sendIncoming) + { ourState.Send(MobileIncoming.Create(ourState, m, m)); + } if (ourState.StygianAbyss) { @@ -3110,10 +3286,14 @@ namespace Server } if (sendHealthbarPoison) + { ourState.Send(new HealthbarPoison(m)); + } if (sendHealthbarYellow) + { ourState.Send(new HealthbarYellow(m)); + } } else { @@ -3135,43 +3315,65 @@ namespace Server else if (sendAny) { if (sendHits) + { ourState.Send(new MobileHits(m)); + } if (sendStam) + { ourState.Send(new MobileStam(m)); + } if (sendMana) + { ourState.Send(new MobileMana(m)); + } } if (sendStam || sendMana) + { if (Party is IParty ip) { if (sendStam) + { ip.OnStamChanged(this); + } if (sendMana) + { ip.OnManaChanged(this); + } } + } if (sendHair) { if (removeHair) + { ourState.Send(new RemoveHair(m)); + } else + { ourState.Send(new HairEquipUpdate(m)); + } } if (sendFacialHair) { if (removeFacialHair) + { ourState.Send(new RemoveFacialHair(m)); + } else + { ourState.Send(new FacialHairEquipUpdate(m)); + } } if (sendOPLUpdate) + { ourState.Send(OPLPacket); + } } sendMoving = sendMoving || sendNonlocalMoving; @@ -3202,7 +3404,9 @@ namespace Server if (beholder != m && beholder.CanSee(m)) { if (sendRemove) + { state.Send(RemovePacket); + } if (sendIncoming) { @@ -3225,7 +3429,9 @@ namespace Server var p = cache[0][noto]; if (p == null) + { cache[0][noto] = p = Packet.Acquire(new MobileMoving(m, noto)); + } state.Send(p); } @@ -3253,7 +3459,9 @@ namespace Server var p = cache[1][noto]; if (p == null) + { cache[1][noto] = p = Packet.Acquire(new MobileMovingOld(m, noto)); + } state.Send(p); } @@ -3300,7 +3508,9 @@ namespace Server } if (sendOPLUpdate) + { state.Send(OPLPacket); + } } } @@ -3317,9 +3527,15 @@ namespace Server } if (sendMoving || sendNonlocalMoving || sendHealthbarPoison || sendHealthbarYellow) + { for (var i = 0; i < cache.Length; ++i) + { for (var j = 0; j < cache[i].Length; ++j) + { Packet.Release(ref cache[i][j]); + } + } + } } public ISpawner Spawner { get; set; } @@ -3355,7 +3571,9 @@ namespace Server public void ReleaseOPLPacket() { if (m_PropertyList == null) + { return; + } Packet.Release(m_PropertyList); m_PropertyList = null; @@ -3389,14 +3607,18 @@ namespace Server var delta = false; for (var i = 0; i < Resistances.Length; ++i) + { if (Resistances[i] != int.MinValue) { Resistances[i] = int.MinValue; delta = true; } + } if (delta) + { Delta(MobileDelta.Resistances); + } } public virtual int GetResistance(ResistanceType type) @@ -3406,7 +3628,9 @@ namespace Server var v = (int)type; if (v < 0 || v >= Resistances.Length) + { return 0; + } var res = Resistances[v]; @@ -3434,7 +3658,9 @@ namespace Server ResistanceMods.Remove(toRemove); if (ResistanceMods.Count == 0) + { ResistanceMods = null; + } } UpdateResistances(); @@ -3445,7 +3671,9 @@ namespace Server Resistances ??= new[] { int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue }; for (var i = 0; i < Resistances.Length; ++i) + { Resistances[i] = 0; + } Resistances[0] += BasePhysicalResistance; Resistances[1] += BaseFireResistance; @@ -3459,7 +3687,9 @@ namespace Server var v = (int)mod.Type; if (v >= 0 && v < Resistances.Length) + { Resistances[v] += mod.Offset; + } } for (var i = 0; i < Items.Count; ++i) @@ -3467,7 +3697,9 @@ namespace Server var item = Items[i]; if (item.CheckPropertyConflict(this)) + { continue; + } Resistances[0] += item.PhysicalResistance; Resistances[1] += item.FireResistance; @@ -3482,12 +3714,18 @@ namespace Server var max = GetMaxResistance((ResistanceType)i); if (max < min) + { max = min; + } if (Resistances[i] > max) + { Resistances[i] = max; + } else if (Resistances[i] < min) + { Resistances[i] = min; + } } } @@ -3511,11 +3749,17 @@ namespace Server int hue; if (NameHue != -1) + { hue = NameHue; + } else if (m_AccessLevel > AccessLevel.Player) + { hue = 11; + } else - hue = Notoriety.GetHue(Notoriety.Compute(from, this)); + { + hue = Notoriety.GetHue(Notoriety.Compute(@from, this)); + } from.Send(new MessageLocalized(Serial, Body, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs)); } @@ -3530,21 +3774,29 @@ namespace Server string prefix; if (ShowFameTitle && (m_Player || m_Body.IsHuman) && m_Fame >= 10000) + { prefix = m_Female ? "Lady" : "Lord"; + } else + { prefix = ""; + } var suffix = ""; if (PropertyTitle && !string.IsNullOrEmpty(Title)) + { suffix = Title; + } var guild = m_Guild; if (guild != null && (m_Player || m_DisplayGuildTitle)) + { suffix = suffix.Length > 0 ? $"{suffix} [{Utility.FixHtml(guild.Abbreviation)}]" : $"[{Utility.FixHtml(guild.Abbreviation)}]"; + } suffix = ApplyNameSuffix(suffix); @@ -3559,9 +3811,13 @@ namespace Server if (title.Length > 0) { if (NewGuildDisplay) + { list.Add("{0}, {1}", Utility.FixHtml(title), Utility.FixHtml(guild.Name)); + } else + { list.Add("{0}, {1} Guild{2}", Utility.FixHtml(title), Utility.FixHtml(guild.Name), type); + } } else { @@ -3603,7 +3859,9 @@ namespace Server for (var i = Aggressors.Count - 1; i >= 0; --i) { if (i >= Aggressors.Count) + { continue; + } var info = Aggressors[i]; @@ -3616,14 +3874,18 @@ namespace Server info.Free(); if (m_NetState != null && CanSee(attacker) && Utility.InUpdateRange(m_Location, attacker.m_Location)) + { m_NetState.Send(MobileIncoming.Create(m_NetState, this, attacker)); + } } } for (var i = Aggressed.Count - 1; i >= 0; --i) { if (i >= Aggressed.Count) + { continue; + } var info = Aggressed[i]; @@ -3636,7 +3898,9 @@ namespace Server info.Free(); if (m_NetState != null && CanSee(defender) && Utility.InUpdateRange(m_Location, defender.m_Location)) + { m_NetState.Send(MobileIncoming.Create(m_NetState, this, defender)); + } } } @@ -3669,16 +3933,22 @@ namespace Server var mod = SkillMods[i]; if (mod.CheckCondition()) + { ++i; + } else + { InternalRemoveSkillMod(mod); + } } } public virtual void AddSkillMod(SkillMod mod) { if (mod == null) + { return; + } ValidateSkillMods(); @@ -3695,7 +3965,9 @@ namespace Server public virtual void RemoveSkillMod(SkillMod mod) { if (mod == null) + { return; + } ValidateSkillMods(); @@ -3731,7 +4003,9 @@ namespace Server } if (m_Warmode == value) + { return; + } DateTime now = DateTime.UtcNow, next = m_NextWarmodeChange; @@ -3798,7 +4072,10 @@ namespace Server { _actions.Remove(toLock); - if (_actions.Count == 0) _actions = null; + if (_actions.Count == 0) + { + _actions = null; + } } } @@ -3831,7 +4108,9 @@ namespace Server public virtual void SendSkillMessage() { if (NextActionMessage - Core.TickCount >= 0) + { return; + } NextActionMessage = Core.TickCount + ActionMessageDelay; @@ -3841,7 +4120,9 @@ namespace Server public virtual void SendActionMessage() { if (NextActionMessage - Core.TickCount >= 0) + { return; + } NextActionMessage = Core.TickCount + ActionMessageDelay; @@ -3861,16 +4142,22 @@ namespace Server var pack = Backpack; if (pack == null) + { AddToBackpack(item); + } else + { pack.DropItem(item); + } } } public virtual void Attack(Mobile m) { if (CheckAttack(m)) + { Combatant = m; + } } public virtual bool CheckAttack(Mobile m) => Utility.InUpdateRange(this, m) && CanSee(m) && InLOS(m); @@ -3912,7 +4199,9 @@ namespace Server public virtual void AggressiveAction(Mobile aggressor, bool criminal) { if (aggressor == this) + { return; + } var args = AggressiveActionEventArgs.Create(this, aggressor, criminal); @@ -3923,9 +4212,13 @@ namespace Server if (Combatant == aggressor) { if (m_ExpireCombatant == null) + { m_ExpireCombatant = new ExpireCombatantTimer(this); + } else + { m_ExpireCombatant.Stop(); + } m_ExpireCombatant.Start(); } @@ -4006,10 +4299,15 @@ namespace Server ) ); // new AggressorInfo( aggressor, this, criminal, true ) ); - if (CanSee(aggressor)) m_NetState?.Send(MobileIncoming.Create(m_NetState, this, aggressor)); + if (CanSee(aggressor)) + { + m_NetState?.Send(MobileIncoming.Create(m_NetState, this, aggressor)); + } if (Combatant == null) + { setCombatant = true; + } UpdateAggrExpire(); } @@ -4024,16 +4322,23 @@ namespace Server ) ); // new AggressorInfo( aggressor, this, criminal, false ) ); - if (CanSee(aggressor)) m_NetState?.Send(MobileIncoming.Create(m_NetState, this, aggressor)); + if (CanSee(aggressor)) + { + m_NetState?.Send(MobileIncoming.Create(m_NetState, this, aggressor)); + } if (Combatant == null) + { setCombatant = true; + } UpdateAggrExpire(); } if (setCombatant) + { Combatant = aggressor; + } Region.OnAggressed(aggressor, this, criminal); } @@ -4041,7 +4346,9 @@ namespace Server public void RemoveAggressed(Mobile aggressed) { if (Deleted) + { return; + } var list = Aggressed; @@ -4055,7 +4362,9 @@ namespace Server info.Free(); if (m_NetState != null && CanSee(aggressed)) + { m_NetState.Send(MobileIncoming.Create(m_NetState, this, aggressed)); + } break; } @@ -4067,7 +4376,9 @@ namespace Server public void RemoveAggressor(Mobile aggressor) { if (Deleted) + { return; + } var list = Aggressors; @@ -4081,7 +4392,9 @@ namespace Server info.Free(); if (m_NetState != null && CanSee(aggressor)) + { m_NetState.Send(MobileIncoming.Create(m_NetState, this, aggressor)); + } break; } @@ -4102,7 +4415,9 @@ namespace Server public virtual void UpdateTotal(Item sender, TotalType type, int delta) { if (delta == 0 || sender.IsVirtualItem) + { return; + } switch (type) { @@ -4126,7 +4441,9 @@ namespace Server public virtual void UpdateTotals() { if (Items == null) + { return; + } var oldWeight = m_TotalWeight; @@ -4141,7 +4458,9 @@ namespace Server item.UpdateTotals(); if (item.IsVirtualItem) + { continue; + } m_TotalGold += item.TotalGold; m_TotalItems += item.TotalItems + 1; @@ -4149,10 +4468,14 @@ namespace Server } if (m_Holding != null) + { m_TotalWeight += m_Holding.TotalWeight + m_Holding.PileWeight; + } if (m_TotalWeight != oldWeight) + { OnWeightChange(oldWeight); + } } public void ClearQuestArrow() => m_QuestArrow = null; @@ -4180,7 +4503,9 @@ namespace Server private bool InternalOnMove(Direction d) { if (!OnMove(d)) + { return false; + } var e = MovementEventArgs.Create(this, d); @@ -4200,8 +4525,12 @@ namespace Server protected virtual bool OnMove(Direction d) { if (m_Hidden && m_AccessLevel == AccessLevel.Player) + { if (AllowedStealthSteps-- <= 0 || (d & Direction.Running) != 0 || Mounted) + { RevealingAction(); + } + } return true; } @@ -4209,7 +4538,9 @@ namespace Server public virtual void ClearFastwalkStack() { if (m_MoveRecords != null && m_MoveRecords.Count > 0) + { m_MoveRecords.Clear(); + } m_EndQueue = Core.TickCount; } @@ -4219,12 +4550,16 @@ namespace Server public virtual bool Move(Direction d) { if (Deleted) + { return false; + } var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } var newLocation = m_Location; var oldLocation = newLocation; @@ -4234,7 +4569,9 @@ namespace Server // We are actually moving (not just a direction change) if (m_Spell?.OnCasterMoving(d) == false) + { return false; + } if (m_Paralyzed || m_Frozen) { @@ -4302,7 +4639,9 @@ namespace Server if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z && !m.OnMoveOff(this)) + { return false; + } } for (var i = 0; i < oldSector.Items.Count; ++i) @@ -4312,7 +4651,9 @@ namespace Server if (item.AtWorldPoint(oldX, oldY) && (item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) && !item.OnMoveOff(this)) + { return false; + } } for (var i = 0; i < newSector.Mobiles.Count; ++i) @@ -4320,7 +4661,9 @@ namespace Server var m = newSector.Mobiles[i]; if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this)) + { return false; + } } for (var i = 0; i < newSector.Items.Count; ++i) @@ -4330,7 +4673,9 @@ namespace Server if (item.AtWorldPoint(x, y) && (item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) && !item.OnMoveOver(this)) + { return false; + } } } else @@ -4341,9 +4686,14 @@ namespace Server if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z && !m.OnMoveOff(this)) + { return false; + } + if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this)) + { return false; + } } for (var i = 0; i < oldSector.Items.Count; ++i) @@ -4353,16 +4703,23 @@ namespace Server if (item.AtWorldPoint(oldX, oldY) && (item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) && !item.OnMoveOff(this)) + { return false; + } + if (item.AtWorldPoint(x, y) && (item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) && !item.OnMoveOver(this)) + { return false; + } } } if (!Region.CanMove(this, d, newLocation, oldLocation, m_Map)) + { return false; + } } else { @@ -4370,7 +4727,9 @@ namespace Server } if (!InternalOnMove(d)) + { return false; + } if (FwdEnabled && m_NetState != null && m_AccessLevel < FwdAccessOverride && (!FwdUOTDOverride || !m_NetState.IsUOTDClient)) @@ -4382,9 +4741,13 @@ namespace Server var r = m_MoveRecords.Peek(); if (r.Expired()) + { m_MoveRecords.Dequeue(); + } else + { break; + } } if (m_MoveRecords.Count >= FwdMaxSteps) @@ -4393,7 +4756,9 @@ namespace Server EventSink.InvokeFastWalk(fw); if (fw.Blocked) + { return false; + } } var delay = ComputeMovementSpeed(d); @@ -4401,9 +4766,13 @@ namespace Server long end; if (m_MoveRecords.Count > 0) + { end = m_EndQueue + delay; + } else + { end = Core.TickCount + delay; + } m_MoveRecords.Enqueue(MovementRecord.NewInstance(end)); @@ -4437,12 +4806,17 @@ namespace Server foreach (var o in eable) { if (o == this) + { continue; + } if (o is Mobile mob) { if (mob.NetState != null) + { m_MoveClientList.Add(mob); + } + m_MoveList.Add(mob); } else if (o is Item item && item.HandlesOnMovement) @@ -4471,7 +4845,9 @@ namespace Server var p = cache[0][noto]; if (p == null) + { cache[0][noto] = p = Packet.Acquire(new MobileMoving(this, noto)); + } ns.Send(p); } @@ -4481,7 +4857,9 @@ namespace Server var p = cache[1][noto]; if (p == null) + { cache[1][noto] = p = Packet.Acquire(new MobileMovingOld(this, noto)); + } ns.Send(p); } @@ -4489,23 +4867,36 @@ namespace Server } for (var i = 0; i < cache.Length; ++i) + { for (var j = 0; j < cache[i].Length; ++j) + { Packet.Release(ref cache[i][j]); + } + } for (var i = 0; i < m_MoveList.Count; ++i) { var o = m_MoveList[i]; if (o is Mobile mobile) + { mobile.OnMovement(this, oldLocation); - else if (o is Item item) item.OnMovement(this, oldLocation); + } + else if (o is Item item) + { + item.OnMovement(this, oldLocation); + } } if (m_MoveList.Count > 0) + { m_MoveList.Clear(); + } if (m_MoveClientList.Count > 0) + { m_MoveClientList.Clear(); + } } OnAfterMove(oldLocation); @@ -4525,9 +4916,13 @@ namespace Server int delay; if (Mounted) + { delay = (dir & Direction.Running) != 0 ? RunMount : WalkMount; + } else + { delay = (dir & Direction.Running) != 0 ? RunFoot : WalkFoot; + } return delay; } @@ -4549,9 +4944,14 @@ namespace Server if ((m_Map.Rules & MapRules.FreeMovement) == 0) { if (!shoved.Alive || !Alive || shoved.IsDeadBondedPet || IsDeadBondedPet) + { return true; + } + if (shoved.m_Hidden && shoved.m_AccessLevel > AccessLevel.Player) + { return true; + } if (!Pushing) { @@ -4595,7 +4995,9 @@ namespace Server public virtual void CriminalAction(bool message) { if (Deleted) + { return; + } Criminal = true; @@ -4631,17 +5033,23 @@ namespace Server if (!Alive) { if (!Region.OnResurrect(this)) + { return; + } if (!CheckResurrect()) + { return; + } OnBeforeResurrect(); var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } Poison = null; @@ -4659,12 +5067,16 @@ namespace Server for (var i = Items.Count - 1; i >= 0; --i) { if (i >= Items.Count) + { continue; + } var item = Items[i]; if (item.ItemID == 0x204E) + { item.Delete(); + } } SendIncomingPacket(); @@ -4683,7 +5095,9 @@ namespace Server if (holding != null) { if (!holding.Deleted && holding.HeldBy == this && holding.Map == Map.Internal) + { AddToBackpack(holding); + } Holding = null; holding.ClearBounce(); @@ -4760,20 +5174,36 @@ namespace Server public virtual void Kill() { if (!CanBeDamaged()) + { return; + } + if (!Alive || IsDeadBondedPet) + { return; + } + if (Deleted) + { return; + } + if (!Region.OnBeforeDeath(this)) + { return; + } + if (!OnBeforeDeath()) + { return; + } var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } m_NetState?.CancelAllTrades(); @@ -4822,7 +5252,9 @@ namespace Server var item = itemsCopy[i]; if (item == pack) + { continue; + } var res = GetParentMoveResultFor(item); @@ -4853,9 +5285,13 @@ namespace Server var res = GetInventoryMoveResultFor(item); if (res == DeathMoveResult.MoveToCorpse) + { content.Add(item); + } else + { moveToPack.Add(item); + } } for (var i = 0; i < moveToPack.Count; ++i) @@ -4863,7 +5299,9 @@ namespace Server var item = moveToPack[i]; if (RetainPackLocsOnDeath && item.Parent == pack) + { continue; + } pack.DropItem(item); } @@ -4871,11 +5309,15 @@ namespace Server HairInfo hair = null; if (m_Hair != null) + { hair = new HairInfo(m_Hair.ItemID, m_Hair.Hue); + } FacialHairInfo facialhair = null; if (m_FacialHair != null) + { facialhair = new FacialHairInfo(m_FacialHair.ItemID, m_FacialHair.Hue); + } var c = CreateCorpseHandler?.Invoke(this, hair, facialhair, content, equip); @@ -4895,14 +5337,19 @@ namespace Server var corpseSerial = c?.Serial ?? Serial.Zero; foreach (var state in eable) + { if (state != m_NetState) { animPacket ??= Packet.Acquire(new DeathAnimation(Serial, corpseSerial)); state.Send(animPacket); - if (!state.Mobile.CanSee(this)) state.Send(RemovePacket); + if (!state.Mobile.CanSee(this)) + { + state.Send(RemovePacket); + } } + } Packet.Release(animPacket); @@ -4932,7 +5379,9 @@ namespace Server var sound = GetDeathSound(); if (sound >= 0) + { Effects.PlaySound(this, Map, sound); + } if (!m_Player) { @@ -4977,12 +5426,16 @@ namespace Server public virtual void Use(Item item) { if (item?.Deleted != false || item.QuestItem || Deleted) + { return; + } DisruptiveAction(); if (m_Spell?.OnCasterUsingObject(item) == false) + { return; + } var root = item.RootParent; var okay = false; @@ -5000,7 +5453,9 @@ namespace Server var reg = Region.Find(item.GetWorldLocation(), item.Map); if (reg?.SendInaccessibleMessage(item, this) != true) + { item.OnDoubleClickNotAccessible(this); + } } else if (!CheckAlive(false)) { @@ -5029,32 +5484,48 @@ namespace Server { // TODO: Is this correct? if (!item.Deleted) + { item.OnItemUsed(this, item); + } // TODO: Is this correct? if (!item.Deleted) + { item.OnDoubleClick(this); + } } } public virtual void Use(Mobile m) { if (m?.Deleted != false || Deleted) + { return; + } DisruptiveAction(); if (m_Spell?.OnCasterUsingObject(m) == false) + { return; + } if (!Utility.InUpdateRange(this, m)) + { m.OnDoubleClickOutOfRange(this); + } else if (!CanSee(m)) + { m.OnDoubleClickCantSee(this); + } else if (!CheckAlive(false)) + { m.OnDoubleClickDead(this); + } else if (Region.OnDoubleClick(this, m) && !m.Deleted) + { m.OnDoubleClick(this); + } } public virtual void Lift(Item item, int amount, out bool rejected, out LRReason reject) @@ -5063,7 +5534,9 @@ namespace Server reject = LRReason.Inspecific; if (item == null) + { return; + } var from = this; var state = m_NetState; @@ -5097,7 +5570,9 @@ namespace Server else if (item.Nontransferable && amount != item.Amount) { if (item.QuestItem) - from.SendLocalizedMessage(1074868); // Stacks of quest items cannot be unstacked. + { + @from.SendLocalizedMessage(1074868); // Stacks of quest items cannot be unstacked. + } reject = LRReason.CannotLift; } @@ -5131,16 +5606,22 @@ namespace Server } if (amount == 0) + { amount = 1; + } if (amount > item.Amount) + { amount = item.Amount; + } var oldAmount = item.Amount; // item.Amount = amount; //Set in LiftItemDupe if (amount < oldAmount) + { LiftItemDupe(item, amount); + } // item.Dupe( oldAmount - amount ); var map = from.Map; @@ -5152,7 +5633,8 @@ namespace Server var rootItem = root as Item; foreach (var ns in eable) - if (ns.Mobile != from && ns.Mobile.CanSee(from) && ns.Mobile.InLOS(from) && + { + if (ns.Mobile != @from && ns.Mobile.CanSee(@from) && ns.Mobile.InLOS(@from) && ns.Mobile.CanSee(root)) { if (p == null) @@ -5163,11 +5645,12 @@ namespace Server map ); - p = Packet.Acquire(new DragEffect(src, from, item.ItemID, item.Hue, amount)); + p = Packet.Acquire(new DragEffect(src, @from, item.ItemID, item.Hue, amount)); } ns.Send(p); } + } Packet.Release(p); @@ -5187,12 +5670,16 @@ namespace Server var liftSound = item.GetLiftSound(from); if (liftSound != -1) - from.Send(new PlaySound(liftSound, from)); + { + @from.Send(new PlaySound(liftSound, @from)); + } from.NextActionTime = Core.TickCount + ActionDelay; if (fixMap != null && shouldFix) + { fixMap.FixColumn(fixLoc.m_X, fixLoc.m_Y); + } reject = LRReason.Inspecific; rejected = false; @@ -5215,14 +5702,20 @@ namespace Server state.Send(new LiftRej(reject)); if (item.Deleted) + { return; + } if (item.Parent is Item) { if (state.ContainerGridLines) + { state.Send(new ContainerContentUpdate6017(item)); + } else + { state.Send(new ContainerContentUpdate(item)); + } } else if (item.Parent is Mobile) { @@ -5234,7 +5727,9 @@ namespace Server } if (ObjectPropertyList.Enabled && item.Parent != null) + { state.Send(item.OPLPacket); + } } } @@ -5273,8 +5768,13 @@ namespace Server oldItem.OnAfterDuped(item); if (oldItem.Parent is Mobile parentMobile) + { parentMobile.AddItem(item); - else if (oldItem.Parent is Item parentItem) parentItem.AddItem(item); + } + else if (oldItem.Parent is Item parentItem) + { + parentItem.AddItem(item); + } item.Delta(ItemDelta.Update); @@ -5297,7 +5797,9 @@ namespace Server foreach (var ns in eable) { if (ns.StygianAbyss) + { continue; + } if (ns.Mobile != this && ns.Mobile.CanSee(this) && ns.Mobile.InLOS(this) && ns.Mobile.CanSee(root)) { @@ -5332,21 +5834,30 @@ namespace Server from.Holding = null; - if (!valid) return false; + if (!valid) + { + return false; + } var bounced = true; item.SetLastMoved(); if (to == null || !item.DropToItem(from, to, loc)) - item.Bounce(from); + { + item.Bounce(@from); + } else + { bounced = false; + } item.ClearBounce(); if (!bounced) + { SendDropEffect(item); + } return !bounced; } @@ -5360,21 +5871,30 @@ namespace Server from.Holding = null; - if (!valid) return false; + if (!valid) + { + return false; + } var bounced = true; item.SetLastMoved(); if (!item.DropToWorld(from, loc)) - item.Bounce(from); + { + item.Bounce(@from); + } else + { bounced = false; + } item.ClearBounce(); if (!bounced) + { SendDropEffect(item); + } return !bounced; } @@ -5388,21 +5908,30 @@ namespace Server from.Holding = null; - if (!valid) return false; + if (!valid) + { + return false; + } var bounced = true; item.SetLastMoved(); if (to == null || !item.DropToMobile(from, to, loc)) - item.Bounce(from); + { + item.Bounce(@from); + } else + { bounced = false; + } item.ClearBounce(); if (!bounced) + { SendDropEffect(item); + } return !bounced; } @@ -5410,12 +5939,16 @@ namespace Server public virtual bool MutateSpeech(List hears, ref string text, ref object context) { if (Alive) + { return false; + } var sb = new StringBuilder(text.Length, text.Length); for (var i = 0; i < text.Length; ++i) + { sb.Append(text[i] != ' ' ? GhostChars.RandomElement() : ' '); + } text = sb.ToString(); context = m_GhostMutateContext; @@ -5427,9 +5960,13 @@ namespace Server Warmode = true; if (m_AutoManifestTimer == null) + { m_AutoManifestTimer = new AutoManifestTimer(this, delay); + } else + { m_AutoManifestTimer.Stop(); + } m_AutoManifestTimer.Start(); } @@ -5437,7 +5974,9 @@ namespace Server public virtual bool CheckSpeechManifest() { if (Alive) + { return false; + } var delay = AutoManifestTimeout; @@ -5460,17 +5999,23 @@ namespace Server var item = cont.Items[i]; if (item.HandlesOnSpeech) + { list.Add(item); + } if (item is Container container) + { AddSpeechItemsFrom(list, container); + } } } public virtual void DoSpeech(string text, int[] keywords, MessageType type, int hue) { if (Deleted || CommandSystem.Handle(this, text, type)) + { return; + } var range = 15; @@ -5518,12 +6063,16 @@ namespace Server OnSaid(regArgs); if (regArgs.Blocked) + { return; + } text = regArgs.Speech; if (string.IsNullOrEmpty(text)) + { return; + } var hears = m_Hears; var onSpeech = m_OnSpeech; @@ -5533,36 +6082,52 @@ namespace Server var eable = m_Map.GetObjectsInRange(m_Location, range); foreach (var o in eable) + { if (o is Mobile heard) { if (!heard.CanSee(this) || !NoSpeechLOS && heard.Player && !heard.InLOS(this)) + { continue; + } if (heard.m_NetState != null) + { hears.Add(heard); + } if (heard.HandlesOnSpeech(this)) + { onSpeech.Add(heard); + } for (var i = 0; i < heard.Items.Count; ++i) { var item = heard.Items[i]; if (item.HandlesOnSpeech) + { onSpeech.Add(item); + } if (item is Container container) + { AddSpeechItemsFrom(onSpeech, container); + } } } else if (o is Item item) { if (item.HandlesOnSpeech) + { onSpeech.Add(item); + } if (item is Container container) + { AddSpeechItemsFrom(onSpeech, container); + } } + } eable.Free(); @@ -5571,7 +6136,9 @@ namespace Server SpeechEventArgs mutatedArgs = null; if (MutateSpeech(hears, ref mutatedText, ref mutateContext)) + { mutatedArgs = new SpeechEventArgs(this, mutatedText, type, hue, Array.Empty()); + } CheckSpeechManifest(); @@ -5620,7 +6187,9 @@ namespace Server Packet.Release(mutp); if (onSpeech.Count > 1) + { onSpeech.Sort(LocationComparer.GetInstance(this)); + } for (var i = 0; i < onSpeech.Count; ++i) { @@ -5629,9 +6198,13 @@ namespace Server if (obj is Mobile heard) { if (mutatedArgs == null || !CheckHearsMutatedSpeech(heard, mutateContext)) + { heard.OnSpeech(regArgs); + } else + { heard.OnSpeech(mutatedArgs); + } } else { @@ -5640,10 +6213,14 @@ namespace Server } if (m_Hears.Count > 0) + { m_Hears.Clear(); + } if (m_OnSpeech.Count > 0) + { m_OnSpeech.Clear(); + } } } @@ -5656,14 +6233,20 @@ namespace Server for (var i = DamageEntries.Count - 1; i >= 0; --i) { if (i >= DamageEntries.Count) + { continue; + } var de = DamageEntries[i]; if (de.HasExpired) + { DamageEntries.RemoveAt(i); + } else if (allowSelf || de.Damager != this) + { return de; + } } return null; @@ -5676,7 +6259,9 @@ namespace Server for (var i = 0; i < DamageEntries.Count; ++i) { if (i < 0) + { continue; + } var de = DamageEntries[i]; @@ -5703,14 +6288,20 @@ namespace Server for (var i = DamageEntries.Count - 1; i >= 0; --i) { if (i >= DamageEntries.Count) + { continue; + } var de = DamageEntries[i]; if (de.HasExpired) + { DamageEntries.RemoveAt(i); + } else if ((allowSelf || de.Damager != this) && (mostTotal == null || de.DamageGiven > mostTotal.DamageGiven)) + { mostTotal = de; + } } return mostTotal; @@ -5725,14 +6316,20 @@ namespace Server for (var i = DamageEntries.Count - 1; i >= 0; --i) { if (i >= DamageEntries.Count) + { continue; + } var de = DamageEntries[i]; if (de.HasExpired) + { DamageEntries.RemoveAt(i); + } else if ((allowSelf || de.Damager != this) && (mostTotal == null || de.DamageGiven < mostTotal.DamageGiven)) + { mostTotal = de; + } } return mostTotal; @@ -5743,14 +6340,20 @@ namespace Server for (var i = DamageEntries.Count - 1; i >= 0; --i) { if (i >= DamageEntries.Count) + { continue; + } var de = DamageEntries[i]; if (de.HasExpired) + { DamageEntries.RemoveAt(i); + } else if (de.Damager == m) + { return de; + } } return null; @@ -5775,12 +6378,16 @@ namespace Server var list = de.Responsible; if (list == null) + { de.Responsible = list = new List(); + } var resp = list.FirstOrDefault(check => check.Damager == master); if (resp == null) + { list.Add(resp = new DamageEntry(master)); + } resp.DamageGiven += amount; resp.LastDamage = DateTime.UtcNow; @@ -5815,10 +6422,14 @@ namespace Server public virtual void Damage(int amount, Mobile from, bool informMount) { if (!CanBeDamaged() || Deleted) + { return; + } if (!Region.OnDamage(this, ref amount)) + { return; + } if (amount > 0) { @@ -5831,7 +6442,9 @@ namespace Server // m_Spell.Disturb( DisturbType.Hurt, false, true ); if (from != null) - RegisterDamage(amount, from); + { + RegisterDamage(amount, @from); + } DisruptiveAction(); @@ -5859,7 +6472,9 @@ namespace Server OnDamage(amount, from, newHits < 0); if (informMount) - Mount?.OnRiderDamaged(amount, from, newHits < 0); + { + Mount?.OnRiderDamaged(amount, @from, newHits < 0); + } if (newHits < 0) { @@ -5868,7 +6483,9 @@ namespace Server Hits = 0; if (oldHits >= 0) + { Kill(); + } } else { @@ -5886,7 +6503,9 @@ namespace Server var master = GetDamageMaster(from); if (master != null) + { ourState = master.m_NetState; + } } if (theirState == null && from != null) @@ -5894,7 +6513,9 @@ namespace Server var master = from.GetDamageMaster(this); if (master != null) + { theirState = master.m_NetState; + } } if (amount > 0 && (ourState != null || theirState != null)) @@ -5935,12 +6556,16 @@ namespace Server public void SendVisibleDamageEveryone(int amount) { if (amount < 0) + { return; + } var map = m_Map; if (map == null) + { return; + } var eable = map.GetClientsInRange(m_Location); @@ -5948,6 +6573,7 @@ namespace Server Packet pOld = null; foreach (var ns in eable) + { if (ns.Mobile.CanSee(this)) { if (ns.DamagePacket) @@ -5963,6 +6589,7 @@ namespace Server ns.Send(pOld); } } + } Packet.Release(pNew); Packet.Release(pOld); @@ -5989,7 +6616,9 @@ namespace Server } if (!damaged.ShowVisibleDamage) + { return; + } if (theirState == null && from != null) { @@ -6007,17 +6636,25 @@ namespace Server if (damaged.CanSeeVisibleDamage && ourState != null) { if (ourState.DamagePacket) + { ourState.Send(new DamagePacket(Serial, amount)); + } else + { ourState.Send(new DamagePacketOld(Serial, amount)); + } } if (theirState != null && theirState != ourState && damager.CanSeeVisibleDamage) { if (theirState.DamagePacket) + { theirState.Send(new DamagePacket(Serial, amount)); + } else + { theirState.Send(new DamagePacketOld(Serial, amount)); + } } } } @@ -6035,18 +6672,26 @@ namespace Server public void Heal(int amount, Mobile from, bool message) { if (!Alive || IsDeadBondedPet) + { return; + } if (!Region.OnHeal(this, ref amount)) + { return; + } OnHeal(ref amount, from); - if (Hits + amount > HitsMax) amount = HitsMax - Hits; + if (Hits + amount > HitsMax) + { + amount = HitsMax - Hits; + } Hits += amount; if (message && amount > 0) + { m_NetState?.Send( new MessageLocalizedAffix( Serial.MinusOne, @@ -6061,6 +6706,7 @@ namespace Server "" ) ); + } } public virtual void OnHeal(ref int amount, Mobile from) @@ -6091,9 +6737,14 @@ namespace Server var hairflag = reader.ReadByte(); if ((hairflag & 0x01) != 0) + { m_Hair = new HairInfo(reader); + } + if ((hairflag & 0x02) != 0) + { m_FacialHair = new FacialHairInfo(reader); + } goto case 29; } @@ -6105,7 +6756,9 @@ namespace Server case 28: { if (version <= 30) + { LastStatGain = reader.ReadDeltaTime(); + } goto case 27; } @@ -6171,7 +6824,9 @@ namespace Server case 15: { if (version < 22) + { reader.ReadInt(); // followers + } m_FollowersMax = reader.ReadInt(); @@ -6240,7 +6895,10 @@ namespace Server } case 4: { - if (version <= 25) Poison.Deserialize(reader); + if (version <= 25) + { + Poison.Deserialize(reader); + } goto case 3; } @@ -6265,16 +6923,24 @@ namespace Server case 0: { if (version < 21) + { Stabled = new List(); + } if (version < 18) + { Virtues = new VirtueInfo(); + } if (version < 11) + { m_DisplayGuildTitle = true; + } if (version < 3) + { m_StatCap = 225; + } if (version < 15) { @@ -6339,11 +7005,16 @@ namespace Server SkillMods = new List(); if (version < 32) + { if (reader.ReadBool()) { var count = reader.ReadInt(); - for (var i = 0; i < count; ++i) reader.ReadDateTime(); + for (var i = 0; i < count; ++i) + { + reader.ReadDateTime(); + } } + } if (m_Player && m_Map != Map.Internal) { @@ -6363,12 +7034,18 @@ namespace Server } if (ShouldCheckStatTimers) + { CheckStatTimers(); + } if (!m_Player && m_Dex <= 100 && m_CombatTimer != null) + { m_CombatTimer.Priority = TimerPriority.FiftyMS; + } else if (m_CombatTimer != null) + { m_CombatTimer.Priority = TimerPriority.EveryTick; + } UpdateRegion(); @@ -6379,7 +7056,9 @@ namespace Server } if (!m_Player) + { Utility.Intern(ref m_Name); + } Utility.Intern(ref m_Title); Utility.Intern(ref m_Language); @@ -6407,7 +7086,9 @@ namespace Server public virtual void CheckStatTimers() { if (Deleted) + { return; + } if (Hits < HitsMax) { @@ -6475,13 +7156,19 @@ namespace Server public virtual void GetContextMenuEntries(Mobile from, List list) { if (Deleted) + { return; + } if (CanPaperdollBeOpenedBy(from)) + { list.Add(new PaperdollEntry(this)); + } if (from == this && Backpack != null && CanSee(Backpack) && CheckAlive(false)) + { list.Add(new OpenBackpackEntry(this)); + } } public void Internalize() @@ -6542,16 +7229,27 @@ namespace Server public void AddItem(Item item) { if (item?.Deleted != false) + { return; + } if (item.Parent == this) + { return; + } + if (item.Parent is Mobile parentMobile) + { parentMobile.RemoveItem(item); + } else if (item.Parent is Item parentItem) + { parentItem.RemoveItem(item); + } else + { item.SendRemovePacket(); + } item.Parent = this; item.Map = m_Map; @@ -6572,13 +7270,17 @@ namespace Server if (item.PhysicalResistance != 0 || item.FireResistance != 0 || item.ColdResistance != 0 || item.PoisonResistance != 0 || item.EnergyResistance != 0) + { UpdateResistances(); + } } public void RemoveItem(Item item) { if (item == null || Items == null) + { return; + } if (Items.Contains(item)) { @@ -6602,7 +7304,9 @@ namespace Server if (item.PhysicalResistance != 0 || item.FireResistance != 0 || item.ColdResistance != 0 || item.PoisonResistance != 0 || item.EnergyResistance != 0) + { UpdateResistances(); + } } } @@ -6611,7 +7315,10 @@ namespace Server var map = m_Map; if (map == null) + { return; + } + ProcessDelta(); Packet p = null; @@ -6620,6 +7327,7 @@ namespace Server var eable = map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this)) { state.Mobile.ProcessDelta(); @@ -6639,24 +7347,44 @@ namespace Server if (Flying) { if (action >= 9 && action <= 11) + { action = 71; + } else if (action >= 12 && action <= 14) + { action = 72; + } else if (action == 20) + { action = 77; + } else if (action == 31) + { action = 71; + } else if (action == 34) + { action = 78; + } else if (action >= 200 && action <= 259) + { action = 75; - else if (action >= 260 && action <= 270) action = 75; + } + else if (action >= 260 && action <= 270) + { + action = 75; + } } else { if (action >= 200 && action <= 259) + { action = 17; - else if (action >= 260 && action <= 270) action = 16; + } + else if (action >= 260 && action <= 270) + { + action = 16; + } } } @@ -6676,6 +7404,7 @@ namespace Server state.Send(p); // } } + } Packet.Release(p); // Packet.Release( pNew ); @@ -6686,27 +7415,37 @@ namespace Server public void SendSound(int soundID) { if (soundID != -1 && m_NetState != null) + { Send(new PlaySound(soundID, this)); + } } public void SendSound(int soundID, IPoint3D p) { if (soundID != -1 && m_NetState != null) + { Send(new PlaySound(soundID, p)); + } } public void PlaySound(int soundID) { if (soundID == -1 || m_Map == null) + { return; + } var p = Packet.Acquire(new PlaySound(soundID, this)); var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this)) + { state.Send(p); + } + } Packet.Release(p); @@ -6729,7 +7468,9 @@ namespace Server public virtual void RevealingAction() { if (m_Hidden && m_AccessLevel == AccessLevel.Player) + { Hidden = false; + } DisruptiveAction(); // Anything that unhides you will also distrupt meditation } @@ -6742,13 +7483,19 @@ namespace Server public void SendRemovePacket(bool everyone) { if (m_Map == null) + { return; + } var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state != m_NetState && (everyone || !state.Mobile.CanSee(this))) + { state.Send(RemovePacket); + } + } eable.Free(); } @@ -6756,21 +7503,29 @@ namespace Server public void ClearScreen() { if (m_Map == null || m_NetState == null) + { return; + } var eable = m_Map.GetObjectsInRange(m_Location, Core.GlobalMaxUpdateRange); foreach (var o in eable) + { if (o is Mobile m) { if (m != this && Utility.InUpdateRange(m_Location, m.m_Location)) + { m_NetState.Send(m.RemovePacket); + } } else if (o is Item item) { if (InRange(item.Location, item.GetUpdateRange(this))) + { m_NetState.Send(item.RemovePacket); + } } + } eable.Free(); } @@ -6786,7 +7541,9 @@ namespace Server } if (throwOnOffline) + { throw new MobileNotConnectedException(this, "Packet could not be sent."); + } return false; } @@ -6800,15 +7557,21 @@ namespace Server if (Squelched) { if (Core.ML) + { SendLocalizedMessage(500168); // You can not say anything, you have been muted. + } else + { SendMessage("You can not say anything, you have been squelched."); // Cliloc ITSELF changed during ML. + } e.Blocked = true; } if (!e.Blocked) + { RevealingAction(); + } } public virtual bool HandlesOnSpeech(Mobile from) => false; @@ -6831,10 +7594,13 @@ namespace Server var eable = m_Map.GetObjectsInRange(m_Location, Core.GlobalMaxUpdateRange); foreach (var o in eable) + { if (o is Item item) { if (CanSee(item) && InRange(item.Location, item.GetUpdateRange(this))) + { item.SendInfoTo(ns); + } } else if (o is Mobile m) { @@ -6845,18 +7611,28 @@ namespace Server if (ns.StygianAbyss) { if (m.Poisoned) + { ns.Send(new HealthbarPoison(m)); + } if (m.Blessed || m.YellowHealthbar) + { ns.Send(new HealthbarYellow(m)); + } } if (m.IsDeadBondedPet) + { ns.Send(new BondedStatus(m.Serial, true)); + } - if (ObjectPropertyList.Enabled) ns.Send(m.OPLPacket); + if (ObjectPropertyList.Enabled) + { + ns.Send(m.OPLPacket); + } } } + } eable.Free(); } @@ -6865,7 +7641,9 @@ namespace Server public void UpdateRegion() { if (Deleted) + { return; + } var newRegion = Region.Find(m_Location, m_Map); @@ -6897,22 +7675,34 @@ namespace Server var flags = 0x0; if (m_Paralyzed || m_Frozen) + { flags |= 0x01; + } if (m_Female) + { flags |= 0x02; + } if (m_Flying) + { flags |= 0x04; + } if (m_Blessed || m_YellowHealthbar) + { flags |= 0x08; + } if (m_Warmode) + { flags |= 0x40; + } if (m_Hidden) + { flags |= 0x80; + } return flags; } @@ -6923,22 +7713,34 @@ namespace Server var flags = 0x0; if (m_Paralyzed || m_Frozen) + { flags |= 0x01; + } if (m_Female) + { flags |= 0x02; + } if (m_Poison != null) + { flags |= 0x04; + } if (m_Blessed || m_YellowHealthbar) + { flags |= 0x08; + } if (m_Warmode) + { flags |= 0x40; + } if (m_Hidden) + { flags |= 0x80; + } return flags; } @@ -6963,11 +7765,14 @@ namespace Server AllowedStealthSteps = 0; if (m_Map == null) + { return; + } var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (!state.Mobile.CanSee(this)) { state.Send(RemovePacket); @@ -6977,10 +7782,16 @@ namespace Server state.Send(MobileIncoming.Create(state, state.Mobile, this)); if (IsDeadBondedPet) + { state.Send(new BondedStatus(Serial, true)); + } - if (ObjectPropertyList.Enabled) state.Send(OPLPacket); + if (ObjectPropertyList.Enabled) + { + state.Send(OPLPacket); + } } + } eable.Free(); } @@ -7000,10 +7811,14 @@ namespace Server public virtual bool CanSee(object o) { if (o is Item item) + { return CanSee(item); + } if (o is Mobile mobile) + { return CanSee(mobile); + } return true; } @@ -7011,33 +7826,46 @@ namespace Server public virtual bool CanSee(Item item) { if (m_Map == Map.Internal) + { return false; + } + if (item.Map == Map.Internal) + { return false; + } if (item.Parent != null) { if (item.Parent is Item parent) { if (!(CanSee(parent) && parent.IsChildVisibleTo(this, item))) + { return false; + } } else if (item.Parent is Mobile mobile) { if (!CanSee(mobile)) + { return false; + } } } if (item is BankBox box && m_AccessLevel <= AccessLevel.Counselor && (box.Owner != this || !box.Opened)) + { return false; + } if (item is SecureTradeContainer container) { var trade = container.Trade; if (trade != null && trade.From.Mobile != this && trade.To.Mobile != this) + { return false; + } } return !item.Deleted && item.Map == m_Map && (item.Visible || m_AccessLevel > AccessLevel.Counselor); @@ -7046,7 +7874,9 @@ namespace Server public virtual bool CanSee(Mobile m) { if (Deleted || m.Deleted || m_Map == Map.Internal || m.m_Map == Map.Internal) + { return false; + } return this == m || m.m_Map == m_Map && (!m.Hidden || m_AccessLevel != AccessLevel.Player && @@ -7075,7 +7905,9 @@ namespace Server var delta = -1; for (var i = 0; delta < 0 && i < m_InvalidBodies.Length; ++i) + { delta = m_InvalidBodies[i] - body; + } return delta != 0 ? body : 0; } @@ -7107,7 +7939,9 @@ namespace Server public void InvalidateProperties() { if (!ObjectPropertyList.Enabled) + { return; + } if (m_Map != null && m_Map != Map.Internal && !World.Loading) { @@ -7129,12 +7963,16 @@ namespace Server public virtual void SetLocation(Point3D newLocation, bool isTeleport) { if (Deleted) + { return; + } var oldLocation = m_Location; if (oldLocation == newLocation) + { return; + } m_Location = newLocation; UpdateRegion(); @@ -7142,7 +7980,9 @@ namespace Server var box = FindBankNoCreate(); if (box?.Opened == true) + { box.Close(); + } m_NetState?.ValidateAllTrades(); @@ -7153,9 +7993,13 @@ namespace Server m_NetState.Sequence = 0; if (m_NetState.StygianAbyss) + { m_NetState.Send(new MobileUpdate(this)); + } else + { m_NetState.Send(new MobileUpdateOld(this)); + } ClearFastwalkStack(); } @@ -7169,8 +8013,12 @@ namespace Server var eable = map.GetClientsInRange(oldLocation); foreach (var ns in eable) + { if (ns != m_NetState && !Utility.InUpdateRange(newLocation, ns.Mobile.Location)) + { ns.Send(RemovePacket); + } + } eable.Free(); @@ -7184,6 +8032,7 @@ namespace Server // We are attached to a client, so it's a bit more complex. We need to send new items and people to ourself, and ourself to other clients foreach (var o in eeable) + { if (o is Item item) { var range = item.GetUpdateRange(this); @@ -7191,12 +8040,16 @@ namespace Server if (!Utility.InRange(oldLocation, loc, range) && Utility.InRange(newLocation, loc, range) && CanSee(item)) + { item.SendInfoTo(ourState); + } } else if (o != this && o is Mobile m) { if (!Utility.InUpdateRange(newLocation, m.m_Location)) + { continue; + } var inOldRange = Utility.InUpdateRange(oldLocation, m.m_Location); @@ -7215,13 +8068,20 @@ namespace Server } if (IsDeadBondedPet) + { m.m_NetState.Send(new BondedStatus(Serial, true)); + } - if (ObjectPropertyList.Enabled) m.m_NetState.Send(OPLPacket); + if (ObjectPropertyList.Enabled) + { + m.m_NetState.Send(OPLPacket); + } } if (inOldRange || !CanSee(m)) + { continue; + } ourState.Send(MobileIncoming.Create(ourState, this, m)); @@ -7235,10 +8095,16 @@ namespace Server } if (m.IsDeadBondedPet) + { ourState.Send(new BondedStatus(m.Serial, true)); + } - if (ObjectPropertyList.Enabled) ourState.Send(m.OPLPacket); + if (ObjectPropertyList.Enabled) + { + ourState.Send(m.OPLPacket); + } } + } eeable.Free(); } @@ -7248,6 +8114,7 @@ namespace Server // We're not attached to a client, so simply send an Incoming foreach (var ns in eable) + { if ((isTeleport && (!ns.HighSeas || !NoMoveHS) || !Utility.InUpdateRange(oldLocation, ns.Mobile.Location)) && ns.Mobile.CanSee(this)) { @@ -7263,10 +8130,16 @@ namespace Server } if (IsDeadBondedPet) + { ns.Send(new BondedStatus(Serial, true)); + } - if (ObjectPropertyList.Enabled) ns.Send(OPLPacket); + if (ObjectPropertyList.Enabled) + { + ns.Send(OPLPacket); + } } + } eable.Free(); } @@ -7291,7 +8164,9 @@ namespace Server public BankBox FindBankNoCreate() { if (m_BankBox?.Deleted != false || m_BankBox.Parent != this) + { m_BankBox = FindItemOnLayer(Layer.Bank) as BankBox; + } return m_BankBox; } @@ -7305,7 +8180,10 @@ namespace Server { var item = eq[i]; - if (!item.Deleted && item.Layer == layer) return item; + if (!item.Deleted && item.Layer == layer) + { + return item; + } } return null; @@ -7314,11 +8192,14 @@ namespace Server public void SendIncomingPacket() { if (m_Map == null) + { return; + } var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this)) { state.Send(MobileIncoming.Create(state, state.Mobile, this)); @@ -7326,17 +8207,27 @@ namespace Server if (state.StygianAbyss) { if (m_Poison != null) + { state.Send(new HealthbarPoison(this)); + } if (m_Blessed || m_YellowHealthbar) + { state.Send(new HealthbarYellow(this)); + } } if (IsDeadBondedPet) + { state.Send(new BondedStatus(Serial, true)); + } - if (ObjectPropertyList.Enabled) state.Send(OPLPacket); + if (ObjectPropertyList.Enabled) + { + state.Send(OPLPacket); + } } + } eable.Free(); } @@ -7344,7 +8235,9 @@ namespace Server public bool PlaceInBackpack(Item item) { if (item.Deleted) + { return false; + } return Backpack?.TryDropItem(this, item, false) == true; } @@ -7352,7 +8245,9 @@ namespace Server public bool AddToBackpack(Item item) { if (item.Deleted) + { return false; + } if (!PlaceInBackpack(item)) { @@ -7385,20 +8280,32 @@ namespace Server public virtual bool OpenTrade(Mobile from, Item offer = null) { - if (!from.Player || !Player || !from.Alive || !Alive) return false; + if (!from.Player || !Player || !from.Alive || !Alive) + { + return false; + } var ourState = m_NetState; var theirState = from.m_NetState; - if (ourState == null || theirState == null) return false; + if (ourState == null || theirState == null) + { + return false; + } var cont = theirState.FindTradeContainer(this); - if (!from.CheckTrade(this, offer, cont, true, true, 0, 0)) return false; + if (!from.CheckTrade(this, offer, cont, true, true, 0, 0)) + { + return false; + } cont ??= theirState.AddTrade(ourState); - if (offer != null) cont.DropItem(offer); + if (offer != null) + { + cont.DropItem(offer); + } return true; } @@ -7424,9 +8331,13 @@ namespace Server public virtual bool CheckEquip(Item item) { for (var i = 0; i < Items.Count; ++i) + { if (Items[i].CheckConflictingLayer(this, item, item.Layer) || item.CheckConflictingLayer(this, Items[i], Items[i].Layer)) + { return false; + } + } return true; } @@ -7543,12 +8454,16 @@ namespace Server public virtual bool EquipItem(Item item) { if (item?.Deleted != false || !item.CanEquip(this)) + { return false; + } if (CheckEquip(item) && OnEquip(item) && item.OnEquip(this)) { if (m_Spell?.OnCasterEquipping(item) == false) + { return false; + } // if (m_Spell != null && m_Spell.State == SpellState.Casting) // m_Spell.Disturb( DisturbType.EquipRequest ); @@ -7583,7 +8498,9 @@ namespace Server public virtual void Delta(MobileDelta flag) { if (m_Map == null || m_Map == Map.Internal || Deleted) + { return; + } m_DeltaFlags |= flag; @@ -7592,6 +8509,7 @@ namespace Server m_InDeltaQueue = true; if (_processing) + { lock (m_DeltaQueueR) { m_DeltaQueueR.Enqueue(this); @@ -7610,8 +8528,11 @@ namespace Server // ignored } } + } else + { m_DeltaQueue.Enqueue(this); + } } Core.Set(); @@ -7629,13 +8550,17 @@ namespace Server else { while (m_DeltaQueue.TryDequeue(out var m)) + { m.ProcessDelta(); + } } _processing = false; while (m_DeltaQueueR.TryDequeue(out var m)) + { m.ProcessDelta(); + } } public virtual void OnKillsChange(int oldValue) @@ -7645,10 +8570,14 @@ namespace Server public bool CheckAlive(bool message = true) { if (Alive) + { return true; + } if (message) + { LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019048); // I am dead and cannot do that. + } return false; } @@ -7682,7 +8611,9 @@ namespace Server public virtual void OnPaperdollRequest() { if (CanPaperdollBeOpenedBy(this)) + { DisplayPaperdollTo(this); + } } /// @@ -7692,13 +8623,19 @@ namespace Server public virtual void OnStatsQuery(Mobile from) { if (from.Map == Map && Utility.InUpdateRange(this, from) && from.CanSee(this)) - from.Send(new MobileStatus(from, this, m_NetState)); + { + @from.Send(new MobileStatus(@from, this, m_NetState)); + } if (from == this) + { Send(new StatLockInfo(this)); + } if (Party is IParty ip) - ip.OnStatsQuery(from, this); + { + ip.OnStatsQuery(@from, this); + } } /// @@ -7707,7 +8644,9 @@ namespace Server public virtual void OnSkillsQuery(Mobile from) { if (from == this) + { Send(new SkillUpdate(Skills)); + } } /// @@ -7724,7 +8663,9 @@ namespace Server { if (Deleted || AccessLevel == AccessLevel.Player && DisableHiddenSelfClick && Hidden && from == this) + { return; + } if (GuildClickMessage) { @@ -7736,9 +8677,13 @@ namespace Server string type; if (guild.Type >= 0 && (int)guild.Type < m_GuildTypes.Length) + { type = m_GuildTypes[(int)guild.Type]; + } else + { type = ""; + } var text = string.Format( title.Length <= 0 ? "[{1}]{2}" : "[{0}, {1}]{2}", @@ -7754,36 +8699,54 @@ namespace Server int hue; if (NameHue != -1) + { hue = NameHue; + } else if (AccessLevel > AccessLevel.Player) + { hue = 11; + } else - hue = Notoriety.GetHue(Notoriety.Compute(from, this)); + { + hue = Notoriety.GetHue(Notoriety.Compute(@from, this)); + } var name = Name ?? string.Empty; var prefix = ""; if (ShowFameTitle && (m_Player || m_Body.IsHuman) && m_Fame >= 10000) + { prefix = m_Female ? "Lady" : "Lord"; + } var suffix = ""; if (ClickTitle && !string.IsNullOrEmpty(Title)) + { suffix = Title; + } suffix = ApplyNameSuffix(suffix); string val; if (prefix.Length > 0 && suffix.Length > 0) + { val = $"{prefix} {name} {suffix}"; + } else if (prefix.Length > 0) + { val = $"{prefix} {name}"; + } else if (suffix.Length > 0) + { val = $"{name} {suffix}"; + } else + { val = name; + } PrivateOverheadMessage(MessageType.Label, hue, AsciiClickMessage, val, from.NetState); } @@ -7827,21 +8790,30 @@ namespace Server public static TimeSpan GetHitsRegenRate(Mobile m) { if (HitsRegenRateHandler == null) + { return DefaultHitsRate; + } + return HitsRegenRateHandler(m); } public static TimeSpan GetStamRegenRate(Mobile m) { if (StamRegenRateHandler == null) + { return DefaultStamRate; + } + return StamRegenRateHandler(m); } public static TimeSpan GetManaRegenRate(Mobile m) { if (ManaRegenRateHandler == null) + { return DefaultManaRate; + } + return ManaRegenRateHandler(m); } @@ -7867,7 +8839,9 @@ namespace Server public virtual int GetAngerSound() { if (BaseSoundID != 0) + { return BaseSoundID; + } return -1; } @@ -7875,7 +8849,9 @@ namespace Server public virtual int GetIdleSound() { if (BaseSoundID != 0) + { return BaseSoundID + 1; + } return -1; } @@ -7883,7 +8859,9 @@ namespace Server public virtual int GetAttackSound() { if (BaseSoundID != 0) + { return BaseSoundID + 2; + } return -1; } @@ -7891,16 +8869,25 @@ namespace Server public virtual int GetHurtSound() { if (BaseSoundID != 0) + { return BaseSoundID + 3; + } return -1; } public virtual int GetDeathSound() { - if (BaseSoundID != 0) return BaseSoundID + 4; + if (BaseSoundID != 0) + { + return BaseSoundID + 4; + } + + if (m_Body.IsHuman) + { + return Utility.Random(m_Female ? 0x314 : 0x423, m_Female ? 4 : 5); + } - if (m_Body.IsHuman) return Utility.Random(m_Female ? 0x314 : 0x423, m_Female ? 4 : 5); return -1; } @@ -7911,7 +8898,9 @@ namespace Server var map = m_Map; if (map == null) + { return Map.NullEnumerable.Instance; + } return map.GetItemsInRange(m_Location, range); } @@ -7921,7 +8910,9 @@ namespace Server var map = m_Map; if (map == null) + { return Map.NullEnumerable.Instance; + } return map.GetObjectsInRange(m_Location, range); } @@ -7933,7 +8924,9 @@ namespace Server var map = m_Map; if (map == null) + { return Map.NullEnumerable.Instance; + } return map.GetMobilesInRange(m_Location, range); } @@ -7943,7 +8936,9 @@ namespace Server var map = m_Map; if (map == null) + { return Map.NullEnumerable.Instance; + } return map.GetClientsInRange(m_Location, range); } @@ -8056,7 +9051,10 @@ namespace Server return true; } - if (throwOnOffline) throw new MobileNotConnectedException(this, "Hue picker could not be sent."); + if (throwOnOffline) + { + throw new MobileNotConnectedException(this, "Hue picker could not be sent."); + } return false; } @@ -8069,7 +9067,9 @@ namespace Server public bool CloseGump() where T : Gump { if (m_NetState == null) + { return false; + } var gump = FindGump(); @@ -8089,7 +9089,9 @@ namespace Server var ns = m_NetState; if (ns == null) + { return false; + } var gumps = new List(ns.Gumps); @@ -8110,7 +9112,9 @@ namespace Server public bool SendGump(Gump g) { if (m_NetState == null) + { return false; + } g.SendTo(m_NetState); return true; @@ -8119,7 +9123,9 @@ namespace Server public bool SendMenu(IMenu m) { if (m_NetState == null) + { return false; + } m.SendTo(m_NetState); return true; @@ -8132,19 +9138,25 @@ namespace Server public virtual bool CanBeBeneficial(Mobile target, bool message, bool allowDead) { if (target == null) + { return false; + } if (Deleted || target.Deleted || !Alive || IsDeadBondedPet || !allowDead && (!target.Alive || target.IsDeadBondedPet)) { if (message) + { SendLocalizedMessage(1001017); // You can not perform beneficial acts on your target. + } return false; } if (target == this) + { return true; + } if ( /*m_Player &&*/!Region.AllowBeneficial(this, target)) { @@ -8152,7 +9164,9 @@ namespace Server // if (!(target.m_Player || target.Body.IsHuman || target.Body.IsAnimal)) // { if (message) + { SendLocalizedMessage(1001017); // You can not perform beneficial acts on your target. + } return false; // } @@ -8164,7 +9178,9 @@ namespace Server public virtual bool IsBeneficialCriminal(Mobile target) { if (this == target) + { return false; + } var n = Notoriety.Compute(this, target); @@ -8177,13 +9193,17 @@ namespace Server public virtual void OnBeneficialAction(Mobile target, bool isCriminal) { if (isCriminal) + { CriminalAction(false); + } } public virtual void DoBeneficial(Mobile target) { if (target == null) + { return; + } OnBeneficialAction(target, IsBeneficialCriminal(target)); @@ -8209,19 +9229,25 @@ namespace Server public virtual bool CanBeHarmful(Mobile target, bool message, bool ignoreOurBlessedness) { if (target == null) + { return false; + } if (Deleted || !ignoreOurBlessedness && m_Blessed || target.Deleted || target.m_Blessed || !Alive || IsDeadBondedPet || !target.Alive || target.IsDeadBondedPet) { if (message) + { SendLocalizedMessage(1001018); // You can not perform negative acts on your target. + } return false; } if (target == this) + { return true; + } // TODO: Pets if ( /*m_Player &&*/ @@ -8229,7 +9255,9 @@ namespace Server ) // (target.m_Player || target.Body.IsHuman) && !Region.AllowHarmful( this, target ) ) { if (message) + { SendLocalizedMessage(1001018); // You can not perform negative acts on your target. + } return false; } @@ -8246,7 +9274,9 @@ namespace Server public virtual void OnHarmfulAction(Mobile target, bool isCriminal) { if (isCriminal) + { CriminalAction(false); + } } public virtual void DoHarmful(Mobile target) @@ -8257,7 +9287,9 @@ namespace Server public virtual void DoHarmful(Mobile target, bool indirect) { if (target == null || Deleted) + { return; + } var isCriminal = IsHarmfulCriminal(target); @@ -8268,12 +9300,18 @@ namespace Server target.Region.OnGotHarmful(this, target); if (!indirect) + { Combatant = target; + } if (m_ExpireCombatant == null) + { m_ExpireCombatant = new ExpireCombatantTimer(this); + } else + { m_ExpireCombatant.Stop(); + } m_ExpireCombatant.Start(); } @@ -8314,7 +9352,9 @@ namespace Server var check = StatMods[i]; if (check.Name == name) + { return check; + } } return null; @@ -8344,13 +9384,19 @@ namespace Server MobileDelta delta = 0; if ((type & StatType.Str) != 0) + { delta |= MobileDelta.Hits; + } if ((type & StatType.Dex) != 0) + { delta |= MobileDelta.Stam; + } if ((type & StatType.Int) != 0) + { delta |= MobileDelta.Mana; + } return delta; } @@ -8763,17 +9809,29 @@ namespace Server Direction ret; if ((ay >> 1) - ax >= 0) + { ret = ry > 0 ? Direction.Up : Direction.Down; + } else if ((ax >> 1) - ay >= 0) + { ret = rx > 0 ? Direction.Left : Direction.Right; + } else if (rx >= 0 && ry >= 0) + { ret = Direction.West; + } else if (rx >= 0 && ry < 0) + { ret = Direction.South; + } else if (rx < 0 && ry < 0) + { ret = Direction.East; + } else + { ret = Direction.North; + } return ret; } @@ -8785,7 +9843,9 @@ namespace Server public Direction GetDirectionTo(IPoint2D p) { if (p == null) + { return Direction.North; + } return GetDirectionTo(p.X, p.Y); } @@ -8793,7 +9853,9 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text, bool noLineOfSight = true) { if (m_Map == null) + { return; + } var p = ascii ? (Packet)new AsciiMessage(Serial, Body, type, hue, 3, Name, text) @@ -8804,8 +9866,12 @@ namespace Server var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this) && (noLineOfSight || state.Mobile.InLOS(this))) + { state.Send(p); + } + } Packet.Release(p); @@ -8815,15 +9881,21 @@ namespace Server public void PublicOverheadMessage(MessageType type, int hue, int number, string args = "", bool noLineOfSight = true) { if (m_Map == null) + { return; + } var p = Packet.Acquire(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this) && (noLineOfSight || state.Mobile.InLOS(this))) + { state.Send(p); + } + } Packet.Release(p); @@ -8836,7 +9908,9 @@ namespace Server ) { if (m_Map == null) + { return; + } var p = Packet.Acquire( new MessageLocalizedAffix( @@ -8856,8 +9930,12 @@ namespace Server var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state.Mobile.CanSee(this) && (noLineOfSight || state.Mobile.InLOS(this))) + { state.Send(p); + } + } Packet.Release(p); @@ -8867,12 +9945,18 @@ namespace Server public void PrivateOverheadMessage(MessageType type, int hue, bool ascii, string text, NetState state) { if (state == null) + { return; + } if (ascii) + { state.Send(new AsciiMessage(Serial, Body, type, hue, 3, Name, text)); + } else + { state.Send(new UnicodeMessage(Serial, Body, type, hue, 3, m_Language, Name, text)); + } } public void PrivateOverheadMessage(MessageType type, int hue, int number, NetState state) @@ -8890,12 +9974,18 @@ namespace Server var ns = m_NetState; if (ns == null) + { return; + } if (ascii) + { ns.Send(new AsciiMessage(Serial, Body, type, hue, 3, Name, text)); + } else + { ns.Send(new UnicodeMessage(Serial, Body, type, hue, 3, m_Language, Name, text)); + } } public void LocalOverheadMessage(MessageType type, int hue, int number, string args = "") @@ -8906,15 +9996,21 @@ namespace Server public void NonlocalOverheadMessage(MessageType type, int hue, int number, string args = "") { if (m_Map == null) + { return; + } var p = Packet.Acquire(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state != m_NetState && state.Mobile.CanSee(this)) + { state.Send(p); + } + } Packet.Release(p); @@ -8924,7 +10020,9 @@ namespace Server public void NonlocalOverheadMessage(MessageType type, int hue, bool ascii, string text) { if (m_Map == null) + { return; + } var p = ascii ? (Packet)new AsciiMessage(Serial, Body, type, hue, 3, Name, text) @@ -8935,8 +10033,12 @@ namespace Server var eable = m_Map.GetClientsInRange(m_Location); foreach (var state in eable) + { if (state != m_NetState && state.Mobile.CanSee(this)) + { state.Send(p); + } + } Packet.Release(p); @@ -8951,11 +10053,15 @@ namespace Server public void SendLocalizedMessage(int number, string args, int hue = 0x3B2) { if (hue == 0x3B2 && string.IsNullOrEmpty(args)) + { m_NetState?.Send(MessageLocalized.InstantiateGeneric(number)); + } else + { m_NetState?.Send( new MessageLocalized(Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", args) ); + } } public void SendLocalizedMessage(int number, bool append, string affix, string args = "", int hue = 0x3B2) @@ -9036,7 +10142,9 @@ namespace Server } if (CanPaperdollBeOpenedBy(from)) - DisplayPaperdollTo(from); + { + DisplayPaperdollTo(@from); + } } /// @@ -9066,7 +10174,9 @@ namespace Server public virtual void OnDoubleClickDead(Mobile from) { if (CanPaperdollBeOpenedBy(from)) - DisplayPaperdollTo(from); + { + DisplayPaperdollTo(@from); + } } private class MovementRecord @@ -9099,7 +10209,9 @@ namespace Server var v = Core.TickCount - m_End >= 0; if (v) + { m_InstancePool.Enqueue(this); + } return v; } @@ -9173,7 +10285,9 @@ namespace Server protected override void OnTick() { if (!m_Mobile.Alive) + { m_Mobile.Warmode = false; + } } } @@ -9190,9 +10304,13 @@ namespace Server public static LocationComparer GetInstance(IEntity relativeTo) { if (m_Instance == null) + { m_Instance = new LocationComparer(relativeTo); + } else + { m_Instance.RelativeTo = relativeTo; + } return m_Instance; } @@ -9224,7 +10342,9 @@ namespace Server protected override void OnTick() { if (m_Owner.CanRegenMana) + { m_Owner.Mana++; + } Delay = Interval = GetManaRegenRate(m_Owner); } @@ -9244,7 +10364,9 @@ namespace Server protected override void OnTick() { if (m_Owner.CanRegenHits) + { m_Owner.Hits++; + } Delay = Interval = GetHitsRegenRate(m_Owner); } @@ -9264,7 +10386,9 @@ namespace Server protected override void OnTick() { if (m_Owner.CanRegenStam) + { m_Owner.Stam++; + } Delay = Interval = GetStamRegenRate(m_Owner); } @@ -9338,13 +10462,17 @@ namespace Server m_Mobile = m; if (!m_Mobile.m_Player && m_Mobile.m_Dex <= 100) + { Priority = TimerPriority.FiftyMS; + } } protected override void OnTick() { if (Core.TickCount - m_Mobile.NextCombatTime < 0) + { return; + } var combatant = m_Mobile.Combatant; @@ -9360,7 +10488,9 @@ namespace Server var weapon = m_Mobile.Weapon; if (!m_Mobile.InRange(combatant, weapon.MaxRange)) + { return; + } if (m_Mobile.InLOS(combatant)) { @@ -9423,9 +10553,13 @@ namespace Server protected override void OnTick() { if (m_Mobile.Deleted || m_Mobile.Aggressors.Count == 0 && m_Mobile.Aggressed.Count == 0) + { m_Mobile.StopAggrExpire(); + } else + { m_Mobile.CheckAggrExpire(); + } } } @@ -9455,9 +10589,13 @@ namespace Server public override void OnCancel(Mobile from) { if (m_CallbackHandlesCancel && m_Callback != null) - m_Callback(from, ""); + { + m_Callback(@from, ""); + } else - m_CancelCallback?.Invoke(from, ""); + { + m_CancelCallback?.Invoke(@from, ""); + } } } diff --git a/Projects/Server/Movement.cs b/Projects/Server/Mobiles/Movement.cs similarity index 68% rename from Projects/Server/Movement.cs rename to Projects/Server/Mobiles/Movement.cs index ff6712caf..b61076f2e 100644 --- a/Projects/Server/Movement.cs +++ b/Projects/Server/Mobiles/Movement.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Movement.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Movement { public static class Movement @@ -27,7 +7,9 @@ namespace Server.Movement public static bool CheckMovement(Mobile m, Direction d, out int newZ) { if (Impl != null) + { return Impl.CheckMovement(m, d, out newZ); + } newZ = m.Z; return false; @@ -36,7 +18,9 @@ namespace Server.Movement public static bool CheckMovement(Mobile m, Map map, Point3D loc, Direction d, out int newZ) { if (Impl != null) + { return Impl.CheckMovement(m, map, loc, d, out newZ); + } newZ = m.Z; return false; diff --git a/Projects/Server/Notoriety.cs b/Projects/Server/Mobiles/Notoriety.cs similarity index 52% rename from Projects/Server/Notoriety.cs rename to Projects/Server/Mobiles/Notoriety.cs index 90b2a3b0f..c575a258d 100644 --- a/Projects/Server/Notoriety.cs +++ b/Projects/Server/Mobiles/Notoriety.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Notoriety.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server { public delegate int NotorietyHandler(Mobile source, Mobile target); diff --git a/Projects/Server/MultiData.cs b/Projects/Server/MultiData.cs index 57eb644f1..e6bd8edfb 100644 --- a/Projects/Server/MultiData.cs +++ b/Projects/Server/MultiData.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * MultiData.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Buffers; using System.Collections.Generic; @@ -55,7 +35,10 @@ namespace Server var vdPath = Core.FindDataFile("verdata.mul", false); - if (!File.Exists(vdPath)) return; + if (!File.Exists(vdPath)) + { + return; + } using var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read); var bin = new BinaryReader(fs); @@ -92,11 +75,17 @@ namespace Server multiID &= 0x3FFF; if (Components.ContainsKey(multiID)) + { mcl = Components[multiID]; + } else if (!UsingUOPFormat) + { Components[multiID] = mcl = Load(multiID); + } else + { mcl = MultiComponentList.Empty; + } return mcl; } @@ -108,10 +97,14 @@ namespace Server // Head Information Start if (streamReader.ReadInt32() != 0x0050594D) // Not a UOP Files + { return; + } if (streamReader.ReadInt32() > 5) // Bad Version + { return; + } // Multi ID List Array Start UOPHash.BuildChunkIDs(out var chunkIds); @@ -149,7 +142,9 @@ namespace Server index++; if (offset == 0 || decompressedSize == 0 || filehash == 0x126D1E99DDEDEE0A) // Exclude housing.bin + { continue; + } chunkIds.TryGetValue(filehash, out var chunkID); @@ -160,7 +155,9 @@ namespace Server Span sourceData = new byte[compressedSize]; if (stream.Read(sourceData) != compressedSize) + { continue; + } Span data; @@ -221,7 +218,9 @@ namespace Server var length = m_IndexReader.ReadInt32(); if (lookup < 0 || length <= 0) + { return MultiComponentList.Empty; + } m_StreamReader.BaseStream.Seek(lookup, SeekOrigin.Begin); @@ -279,14 +278,18 @@ namespace Server Tiles[x][y] = new StaticTile[toCopy.Tiles[x][y].Length]; for (var i = 0; i < Tiles[x][y].Length; ++i) + { Tiles[x][y][i] = toCopy.Tiles[x][y][i]; + } } } List = new MultiTileEntry[toCopy.List.Length]; for (var i = 0; i < List.Length; ++i) + { List[i] = toCopy.List[i]; + } } public MultiComponentList(IGenericReader reader) @@ -304,11 +307,14 @@ namespace Server var allTiles = List = new MultiTileEntry[length]; if (version == 0) + { for (var i = 0; i < length; ++i) { int id = reader.ReadShort(); if (id >= 0x4000) + { id -= 0x4000; + } allTiles[i].ItemId = (ushort)id; allTiles[i].OffsetX = reader.ReadShort(); @@ -316,7 +322,9 @@ namespace Server allTiles[i].OffsetZ = reader.ReadShort(); allTiles[i].Flags = (TileFlag)reader.ReadInt(); } + } else + { for (var i = 0; i < length; ++i) { allTiles[i].ItemId = reader.ReadUShort(); @@ -325,6 +333,7 @@ namespace Server allTiles[i].OffsetZ = reader.ReadShort(); allTiles[i].Flags = (TileFlag)reader.ReadInt(); } + } var tiles = new TileList[Width][]; Tiles = new StaticTile[Width][][]; @@ -335,10 +344,13 @@ namespace Server Tiles[x] = new StaticTile[Height][]; for (var y = 0; y < Height; ++y) + { tiles[x][y] = new TileList(); + } } for (var i = 0; i < allTiles.Length; ++i) + { if (i == 0 || allTiles[i].Flags != 0) { var xOffset = allTiles[i].OffsetX + Center.m_X; @@ -346,10 +358,15 @@ namespace Server tiles[xOffset][yOffset].Add(allTiles[i].ItemId, (sbyte)allTiles[i].OffsetZ); } + } for (var x = 0; x < Width; ++x) + { for (var y = 0; y < Height; ++y) + { Tiles[x][y] = tiles[x][y].ToArray(); + } + } } public MultiComponentList(BinaryReader reader, int count) @@ -364,25 +381,37 @@ namespace Server allTiles[i].OffsetZ = reader.ReadInt16(); if (PostHSFormat) + { allTiles[i].Flags = (TileFlag)reader.ReadUInt64(); + } else + { allTiles[i].Flags = (TileFlag)reader.ReadUInt32(); + } var e = allTiles[i]; if (i == 0 || e.Flags != 0) { if (e.OffsetX < m_Min.m_X) + { m_Min.m_X = e.OffsetX; + } if (e.OffsetY < m_Min.m_Y) + { m_Min.m_Y = e.OffsetY; + } if (e.OffsetX > m_Max.m_X) + { m_Max.m_X = e.OffsetX; + } if (e.OffsetY > m_Max.m_Y) + { m_Max.m_Y = e.OffsetY; + } } } @@ -399,10 +428,13 @@ namespace Server Tiles[x] = new StaticTile[Height][]; for (var y = 0; y < Height; ++y) + { tiles[x][y] = new TileList(); + } } for (var i = 0; i < allTiles.Length; ++i) + { if (i == 0 || allTiles[i].Flags != 0) { var xOffset = allTiles[i].OffsetX + Center.m_X; @@ -410,10 +442,15 @@ namespace Server tiles[xOffset][yOffset].Add(allTiles[i].ItemId, (sbyte)allTiles[i].OffsetZ); } + } for (var x = 0; x < Width; ++x) + { for (var y = 0; y < Height; ++y) + { Tiles[x][y] = tiles[x][y].ToArray(); + } + } } public MultiComponentList(List list) @@ -433,13 +470,25 @@ namespace Server if (i == 0 || e.Flags != 0) { - if (e.OffsetX < m_Min.m_X) m_Min.m_X = e.OffsetX; + if (e.OffsetX < m_Min.m_X) + { + m_Min.m_X = e.OffsetX; + } - if (e.OffsetY < m_Min.m_Y) m_Min.m_Y = e.OffsetY; + if (e.OffsetY < m_Min.m_Y) + { + m_Min.m_Y = e.OffsetY; + } - if (e.OffsetX > m_Max.m_X) m_Max.m_X = e.OffsetX; + if (e.OffsetX > m_Max.m_X) + { + m_Max.m_X = e.OffsetX; + } - if (e.OffsetY > m_Max.m_Y) m_Max.m_Y = e.OffsetY; + if (e.OffsetY > m_Max.m_Y) + { + m_Max.m_Y = e.OffsetY; + } } } @@ -455,10 +504,14 @@ namespace Server tiles[x] = new TileList[Height]; Tiles[x] = new StaticTile[Height][]; - for (var y = 0; y < Height; ++y) tiles[x][y] = new TileList(); + for (var y = 0; y < Height; ++y) + { + tiles[x][y] = new TileList(); + } } for (var i = 0; i < allTiles.Length; ++i) + { if (i == 0 || allTiles[i].Flags != 0) { var xOffset = allTiles[i].OffsetX + Center.m_X; @@ -467,10 +520,15 @@ namespace Server tiles[xOffset][yOffset].Add((ushort)itemID, (sbyte)allTiles[i].OffsetZ); } + } for (var x = 0; x < Width; ++x) + { for (var y = 0; y < Height; ++y) + { Tiles[x][y] = tiles[x][y].ToArray(); + } + } } private MultiComponentList() @@ -514,7 +572,9 @@ namespace Server (TileData.ItemTable[oldTiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Roof) != 0; if (newIsRoof == oldIsRoof) + { Remove(oldTiles[i].ID, x, y, z); + } } } @@ -523,7 +583,9 @@ namespace Server var newTiles = new StaticTile[oldTiles.Length + 1]; for (var i = 0; i < oldTiles.Length; ++i) + { newTiles[i] = oldTiles[i]; + } newTiles[oldTiles.Length] = new StaticTile((ushort)itemID, (sbyte)z); @@ -533,7 +595,9 @@ namespace Server var newList = new MultiTileEntry[oldList.Length + 1]; for (var i = 0; i < oldList.Length; ++i) + { newList[i] = oldList[i]; + } newList[oldList.Length] = new MultiTileEntry( (ushort)itemID, @@ -546,16 +610,24 @@ namespace Server List = newList; if (x < m_Min.m_X) + { m_Min.m_X = x; + } if (y < m_Min.m_Y) + { m_Min.m_Y = y; + } if (x > m_Max.m_X) + { m_Max.m_X = x; + } if (y > m_Max.m_Y) + { m_Max.m_Y = y; + } } } @@ -577,10 +649,14 @@ namespace Server var newTiles = new StaticTile[oldTiles.Length - 1]; for (var j = 0; j < i; ++j) + { newTiles[j] = oldTiles[j]; + } for (var j = i + 1; j < oldTiles.Length; ++j) + { newTiles[j - 1] = oldTiles[j]; + } Tiles[vx][vy] = newTiles; @@ -600,10 +676,14 @@ namespace Server var newList = new MultiTileEntry[oldList.Length - 1]; for (var j = 0; j < i; ++j) + { newList[j] = oldList[j]; + } for (var j = i + 1; j < oldList.Length; ++j) + { newList[j - 1] = oldList[j]; + } List = newList; @@ -631,10 +711,14 @@ namespace Server var newTiles = new StaticTile[oldTiles.Length - 1]; for (var j = 0; j < i; ++j) + { newTiles[j] = oldTiles[j]; + } for (var j = i + 1; j < oldTiles.Length; ++j) + { newTiles[j - 1] = oldTiles[j]; + } Tiles[vx][vy] = newTiles; @@ -654,10 +738,14 @@ namespace Server var newList = new MultiTileEntry[oldList.Length - 1]; for (var j = 0; j < i; ++j) + { newList[j] = oldList[j]; + } for (var j = i + 1; j < oldList.Length; ++j) + { newList[j - 1] = oldList[j]; + } List = newList; @@ -683,9 +771,13 @@ namespace Server for (var y = 0; y < newHeight; ++y) { if (x < oldWidth && y < oldHeight) + { newTiles[x][y] = oldTiles[x][y]; + } else + { newTiles[x][y] = Array.Empty(); + } totalLength += newTiles[x][y].Length; } @@ -702,6 +794,7 @@ namespace Server var index = 0; for (var x = 0; x < newWidth; ++x) + { for (var y = 0; y < newHeight; ++y) { var tiles = newTiles[x][y]; @@ -714,16 +807,24 @@ namespace Server var vy = y - Center.Y; if (vx < m_Min.m_X) + { m_Min.m_X = vx; + } if (vy < m_Min.m_Y) + { m_Min.m_Y = vy; + } if (vx > m_Max.m_X) + { m_Max.m_X = vx; + } if (vy > m_Max.m_Y) + { m_Max.m_Y = vy; + } List[index++] = new MultiTileEntry( (ushort)tile.ID, @@ -734,6 +835,7 @@ namespace Server ); } } + } } public void Serialize(IGenericWriter writer) @@ -771,7 +873,9 @@ namespace Server chunkIds = new Dictionary(); for (var i = 0; i < maxId; ++i) + { chunkIds[HashLittle2($"build/multicollection/{i:000000}.bin")] = i; + } } private static ulong HashLittle2(string s) diff --git a/Projects/Server/NativeReader.cs b/Projects/Server/NativeReader.cs index 6ff474e39..148068ac6 100644 --- a/Projects/Server/NativeReader.cs +++ b/Projects/Server/NativeReader.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * NativeReader.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Runtime.InteropServices; using System.Threading; @@ -31,9 +11,13 @@ namespace Server static NativeReader() { if (Core.Unix) + { m_NativeReader = new NativeReaderUnix(); + } else + { m_NativeReader = new NativeReaderWin32(); + } } public static unsafe void Read(IntPtr p, void* buffer, int length) diff --git a/Projects/Server/Network/EncodedPacketHandler.cs b/Projects/Server/Network/EncodedPacketHandler.cs index 58163f9c5..1de53876a 100644 --- a/Projects/Server/Network/EncodedPacketHandler.cs +++ b/Projects/Server/Network/EncodedPacketHandler.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * EncodedPacketHandler.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Network { public delegate void OnEncodedPacketReceive(NetState state, IEntity ent, EncodedReader pvSrc); diff --git a/Projects/Server/Network/EncodedReader.cs b/Projects/Server/Network/EncodedReader.cs index ad71681de..33a46e267 100644 --- a/Projects/Server/Network/EncodedReader.cs +++ b/Projects/Server/Network/EncodedReader.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * EncodedReader.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Network { public ref struct EncodedReader diff --git a/Projects/Server/Network/MessagePumpService.cs b/Projects/Server/Network/MessagePumpService.cs index 27f77ad76..25c8eb9d0 100644 --- a/Projects/Server/Network/MessagePumpService.cs +++ b/Projects/Server/Network/MessagePumpService.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MessagePumpService.cs * * * diff --git a/Projects/Server/Network/NetState.cs b/Projects/Server/Network/NetState.cs index ff4abed67..0ff7ec32b 100644 --- a/Projects/Server/Network/NetState.cs +++ b/Projects/Server/Network/NetState.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * NetState.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/Projects/Server/Network/NetworkCompression.cs b/Projects/Server/Network/NetworkCompression.cs index 631c4f6c3..4b2776765 100644 --- a/Projects/Server/Network/NetworkCompression.cs +++ b/Projects/Server/Network/NetworkCompression.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Compression.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server.Network @@ -84,15 +64,32 @@ namespace Server.Network ReadOnlySpan input, int offset, int count, Span output, out int length ) { - if (input == null) throw new ArgumentNullException(nameof(input)); + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } - if (offset < 0 || offset >= input.Length) throw new ArgumentOutOfRangeException(nameof(offset)); - if (count < 0 || count > input.Length) throw new ArgumentOutOfRangeException(nameof(count)); - if (input.Length - offset < count) throw new ArgumentOutOfRangeException(nameof(offset)); + if (offset < 0 || offset >= input.Length) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } + + if (count < 0 || count > input.Length) + { + throw new ArgumentOutOfRangeException(nameof(count)); + } + + if (input.Length - offset < count) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } length = 0; - if (count > DefiniteOverflow) return; + if (count > DefiniteOverflow) + { + return; + } var bitCount = 0; var bitValue = 0; diff --git a/Projects/Server/Network/Packet.cs b/Projects/Server/Network/Packet.cs index 3c9c4b767..43ac2c614 100644 --- a/Projects/Server/Network/Packet.cs +++ b/Projects/Server/Network/Packet.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Packet.cs - * ------------------- - * begin : August 2, 2019 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Buffers; using System.Diagnostics; @@ -112,16 +92,22 @@ namespace Server.Network Core.Set(); // Is this still needed if this is done async? if ((m_State & (State.Acquired | State.Static)) == 0) + { Free(); + } } private void Free() { if (m_CompiledBuffer == null) + { return; + } if ((m_State & State.Buffered) != 0) + { ArrayPool.Shared.Return(m_CompiledBuffer); + } m_State &= ~(State.Static | State.Acquired | State.Buffered); @@ -131,7 +117,9 @@ namespace Server.Network public void Release() { if ((m_State & State.Acquired) != 0) + { Free(); + } } public byte[] Compile(bool compress, out int length) diff --git a/Projects/Server/Network/PacketHandler.cs b/Projects/Server/Network/PacketHandler.cs index 7bee08af8..08ec40862 100644 --- a/Projects/Server/Network/PacketHandler.cs +++ b/Projects/Server/Network/PacketHandler.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketHandler.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server.Network diff --git a/Projects/Server/Network/PacketHandlers.cs b/Projects/Server/Network/PacketHandlers.cs index 7f5978223..de5cb0336 100644 --- a/Projects/Server/Network/PacketHandlers.cs +++ b/Projects/Server/Network/PacketHandlers.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketHandlers.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Buffers; using System.Collections.Generic; @@ -209,15 +189,21 @@ namespace Server.Network public static void RegisterExtended(int packetID, bool ingame, OnPacketReceive onReceive) { if (packetID >= 0 && packetID < 0x100) + { m_ExtendedHandlersLow[packetID] = new PacketHandler(packetID, 0, ingame, onReceive); + } else + { m_ExtendedHandlersHigh[packetID] = new PacketHandler(packetID, 0, ingame, onReceive); + } } public static PacketHandler GetExtendedHandler(int packetID) { if (packetID >= 0 && packetID < 0x100) + { return m_ExtendedHandlersLow[packetID]; + } m_ExtendedHandlersHigh.TryGetValue(packetID, out var handler); return handler; @@ -226,23 +212,33 @@ namespace Server.Network public static void RemoveExtendedHandler(int packetID) { if (packetID >= 0 && packetID < 0x100) + { m_ExtendedHandlersLow[packetID] = null; + } else + { m_ExtendedHandlersHigh.Remove(packetID); + } } public static void RegisterEncoded(int packetID, bool ingame, OnEncodedPacketReceive onReceive) { if (packetID >= 0 && packetID < 0x100) + { m_EncodedHandlersLow[packetID] = new EncodedPacketHandler(packetID, ingame, onReceive); + } else + { m_EncodedHandlersHigh[packetID] = new EncodedPacketHandler(packetID, ingame, onReceive); + } } public static EncodedPacketHandler GetEncodedHandler(int packetID) { if (packetID >= 0 && packetID < 0x100) + { return m_EncodedHandlersLow[packetID]; + } m_EncodedHandlersHigh.TryGetValue(packetID, out var handler); return handler; @@ -251,9 +247,13 @@ namespace Server.Network public static void RemoveEncodedHandler(int packetID) { if (packetID >= 0 && packetID < 0x100) + { m_EncodedHandlersLow[packetID] = null; + } else + { m_EncodedHandlersHigh.Remove(packetID); + } } public static void RegisterThrottler(int packetID, ThrottlePacketCallback t) @@ -261,12 +261,16 @@ namespace Server.Network var ph = GetHandler(packetID); if (ph != null) + { ph.ThrottleCallback = t; + } ph = Get6017Handler(packetID); if (ph != null) + { ph.ThrottleCallback = t; + } } public static int ProcessPacket(IMessagePumpService pump, NetState ns, in ReadOnlySequence seq) @@ -332,7 +336,9 @@ namespace Server.Network } if (r.Length < packetLength) + { return 0; + } if (handler.Ingame && ns.Mobile?.Deleted != false) { @@ -348,7 +354,9 @@ namespace Server.Network var throttled = handler.ThrottleCallback?.Invoke(ns) ?? TimeSpan.Zero; if (throttled > TimeSpan.Zero) + { ns.ThrottledUntil = DateTime.UtcNow + throttled; + } var packet = seq.Slice(r.Position); var length = (int)packet.Length; @@ -424,7 +432,9 @@ namespace Server.Network var targ = World.FindMobile(pvSrc.ReadUInt32()); if (targ != null) - EventSink.InvokeRenameRequest(from, targ, pvSrc.ReadStringSafe()); + { + EventSink.InvokeRenameRequest(@from, targ, pvSrc.ReadStringSafe()); + } } public static void ChatRequest(NetState state, PacketReader pvSrc) @@ -442,7 +452,9 @@ namespace Server.Network if (World.FindItem(serial) is SecureTradeContainer cont && cont.Trade != null && (cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile)) + { cont.Trade.Cancel(); + } break; } @@ -507,7 +519,10 @@ namespace Server.Network var vendor = World.FindMobile(pvSrc.ReadUInt32()); var flag = pvSrc.ReadByte(); - if (vendor == null) return; + if (vendor == null) + { + return; + } if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10)) { @@ -520,7 +535,9 @@ namespace Server.Network var msgSize = (int)pvSrc.Remaining; if (msgSize / 7 > 100) + { return; + } var buyList = new List(msgSize / 7); while (msgSize > 0) @@ -534,7 +551,9 @@ namespace Server.Network } if (buyList.Count > 0 && vendor is IVendor v && v.OnBuyItems(state.Mobile, buyList)) + { state.Send(new EndVendorBuy(vendor)); + } } else { @@ -547,7 +566,10 @@ namespace Server.Network Serial serial = pvSrc.ReadUInt32(); var vendor = World.FindMobile(serial); - if (vendor == null) return; + if (vendor == null) + { + return; + } if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10)) { @@ -558,7 +580,9 @@ namespace Server.Network int count = pvSrc.ReadUInt16(); if (count >= 100 || pvSrc.Remaining != count * 6) + { return; + } var sellList = new List(count); @@ -568,11 +592,15 @@ namespace Server.Network int amount = pvSrc.ReadInt16(); if (item != null && amount > 0) + { sellList.Add(new SellItemResponse(item, amount)); + } } if (sellList.Count > 0 && vendor is IVendor v && v.OnSellItems(state.Mobile, sellList)) + { state.Send(new EndVendorSell(vendor)); + } } public static void DeleteCharacter(NetState state, PacketReader pvSrc) @@ -602,14 +630,18 @@ namespace Server.Network if (item != null && from.Map == item.Map && Utility.InUpdateRange(item.GetWorldLocation(), from.Location) && from.CanSee(item)) - item.OnHelpRequest(from); + { + item.OnHelpRequest(@from); + } } else if (serial.IsMobile) { var m = World.FindMobile(serial); if (m != null && from.Map == m.Map && Utility.InUpdateRange(m.Location, from.Location) && from.CanSee(m)) + { m.OnHelpRequest(m); + } } } @@ -618,7 +650,9 @@ namespace Server.Network var m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null && Utility.InUpdateRange(state.Mobile, m) && state.Mobile.CanSee(m)) + { state.Send(new MobileName(m)); + } } public static void RequestScrollWindow(NetState state, PacketReader pvSrc) @@ -633,7 +667,9 @@ namespace Server.Network var m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null) - from.Attack(m); + { + @from.Attack(m); + } } public static void HuePickerResponse(NetState state, PacketReader pvSrc) @@ -645,6 +681,7 @@ namespace Server.Network hue = Utility.ClipDyedHue(hue); foreach (var huePicker in state.HuePickers) + { if (huePicker.Serial == serial) { state.RemoveHuePicker(huePicker); @@ -653,6 +690,7 @@ namespace Server.Network break; } + } } public static void SystemInfo(NetState state, PacketReader pvSrc) @@ -693,7 +731,9 @@ namespace Server.Network case 0x24: // Use skill { if (!int.TryParse(command.Split(' ')[0], out var skillIndex)) + { break; + } Skills.UseSkill(m, skillIndex); @@ -702,7 +742,9 @@ namespace Server.Network case 0x43: // Open spellbook { if (!int.TryParse(command, out var booktype)) + { booktype = 1; + } EventSink.InvokeOpenSpellbookRequest(m, booktype); @@ -772,7 +814,9 @@ namespace Server.Network var text = pvSrc.ReadStringSafe(); if (text.Length > 128) + { return; + } var from = state.Mobile; var p = from.Prompt; @@ -782,9 +826,13 @@ namespace Server.Network from.Prompt = null; if (type == 0) - p.OnCancel(from); + { + p.OnCancel(@from); + } else - p.OnResponse(from, text); + { + p.OnResponse(@from, text); + } } } @@ -797,7 +845,9 @@ namespace Server.Network var text = pvSrc.ReadUnicodeStringLESafe(); if (text.Length > 128) + { return; + } var from = state.Mobile; var p = from.Prompt; @@ -807,9 +857,13 @@ namespace Server.Network from.Prompt = null; if (type == 0) - p.OnCancel(from); + { + p.OnCancel(@from); + } else - p.OnResponse(from, text); + { + p.OnResponse(@from, text); + } } } @@ -824,17 +878,23 @@ namespace Server.Network index -= 1; // convert from 1-based to 0-based foreach (var menu in state.Menus) + { if (menu.Serial == serial) { state.RemoveMenu(menu); if (index >= 0 && index < menu.EntryLength) + { menu.OnResponse(state, index); + } else + { menu.OnCancel(state); + } break; } + } } public static void ProfileReq(NetState state, PacketReader pvSrc) @@ -845,7 +905,10 @@ namespace Server.Network var beholder = state.Mobile; var beheld = World.FindMobile(serial); - if (beheld == null) return; + if (beheld == null) + { + return; + } switch (type) { @@ -861,7 +924,9 @@ namespace Server.Network int length = pvSrc.ReadUInt16(); if (length > 511) + { return; + } var text = pvSrc.ReadUnicodeString(length); @@ -895,13 +960,18 @@ namespace Server.Network from.Holding = null; - if (!valid) return; + if (!valid) + { + return; + } pvSrc.Seek(5, SeekOrigin.Current); var to = World.FindMobile(pvSrc.ReadUInt32()) ?? from; if (!to.AllowEquipFrom(from) || !to.EquipItem(item)) - item.Bounce(from); + { + item.Bounce(@from); + } item.ClearBounce(); } @@ -1012,13 +1082,18 @@ namespace Server.Network int graphic = pvSrc.ReadUInt16(); if (targetID == unchecked((int)0xDEADBEEF)) + { return; + } var from = state.Mobile; var t = from.Target; - if (t == null) return; + if (t == null) + { + return; + } var prof = TargetProfile.Acquire(t.GetType()); prof?.Start(); @@ -1062,12 +1137,19 @@ namespace Server.Network if (state.HighSeas) { var id = TileData.ItemTable[graphic & TileData.MaxItemValue]; - if (id.Surface) z -= id.Height; + if (id.Surface) + { + z -= id.Height; + } } for (var i = 0; !valid && i < tiles.Length; ++i) + { if (tiles[i].Z == z && tiles[i].ID == graphic) + { valid = true; + } + } if (!valid) { @@ -1113,10 +1195,14 @@ namespace Server.Network foreach (var gump in state.Gumps) { if (gump.Serial != serial || gump.TypeID != typeID) + { continue; + } + var buttonExists = buttonID == 0; // 0 is always 'close' if (!buttonExists) + { foreach (var e in gump.Entries) { if (e is GumpButton button && button.ButtonID == buttonID) @@ -1131,6 +1217,7 @@ namespace Server.Network break; } } + } if (!buttonExists) { @@ -1151,7 +1238,9 @@ namespace Server.Network var switches = new int[switchCount]; for (var j = 0; j < switches.Length; ++j) + { switches[j] = pvSrc.ReadInt32(); + } var textCount = pvSrc.ReadInt32(); @@ -1203,14 +1292,18 @@ namespace Server.Network var beheld = World.FindMobile(pvSrc.ReadUInt32()); if (beheld != null) + { EventSink.InvokeVirtueGumpRequest(state.Mobile, beheld); + } } else { var beheld = World.FindMobile(serial); if (beheld != null) + { EventSink.InvokeVirtueItemRequest(state.Mobile, beheld, buttonID); + } } } } @@ -1225,9 +1318,13 @@ namespace Server.Network var m = state.Mobile; if (state.StygianAbyss) + { state.Send(new MobileUpdate(m)); + } else + { state.Send(new MobileUpdateOld(m)); + } state.Send(MobileIncoming.Create(state, m, m)); @@ -1248,10 +1345,14 @@ namespace Server.Network var text = pvSrc.ReadStringSafe().Trim(); if (text.Length <= 0 || text.Length > 128) + { return; + } if (!Enum.IsDefined(typeof(MessageType), type)) + { type = MessageType.Regular; + } from.DoSpeech(text, m_EmptyInts, type, Utility.ClipDyedHue(hue)); } @@ -1276,7 +1377,9 @@ namespace Server.Network var hold = value & 0xF; if (count < 0 || count > 50) + { return; + } var keyList = m_KeywordList; @@ -1299,7 +1402,9 @@ namespace Server.Network } if (!keyList.Contains(speechID)) + { keyList.Add(speechID); + } } text = pvSrc.ReadUTF8StringSafe(); @@ -1316,12 +1421,16 @@ namespace Server.Network text = text.Trim(); if (text.Length <= 0 || text.Length > 128) + { return; + } type &= ~MessageType.Encoded; if (!Enum.IsDefined(typeof(MessageType), type)) + { type = MessageType.Regular; + } from.Language = lang; from.DoSpeech(text, keywords, type, Utility.ClipDyedHue(hue)); @@ -1348,14 +1457,18 @@ namespace Server.Network var m = World.FindMobile(s); if (m?.Deleted == false) - from.Use(m); + { + @from.Use(m); + } } else if (s.IsItem) { var item = World.FindItem(s); if (item?.Deleted == false) - from.Use(item); + { + @from.Use(item); + } } } @@ -1386,7 +1499,9 @@ namespace Server.Network else { if (from.Region.OnSingleClick(from, m)) - m.OnSingleClick(from); + { + m.OnSingleClick(@from); + } } } } @@ -1404,7 +1519,9 @@ namespace Server.Network else if (from.Region.OnSingleClick(from, item)) { if (item.Parent is Item parentItem) - parentItem.OnSingleClickContained(from, item); + { + parentItem.OnSingleClickContained(@from, item); + } item.OnSingleClick(from); } @@ -1442,7 +1559,9 @@ namespace Server.Network ++seq; if (seq == 256) + { seq = 1; + } state.Sequence = seq; } @@ -1456,10 +1575,14 @@ namespace Server.Network var ok = false; for (var i = 0; !ok && i < ValidAnimations.Length; ++i) + { ok = action == ValidAnimations[i]; + } if (from != null && ok && from.Alive && from.Body.IsHuman && !from.Mounted) - from.Animate(action, 7, 1, true, false, 0); + { + @from.Animate(action, 7, 1, true, false, 0); + } } public static void QuestArrow(NetState state, PacketReader pvSrc) @@ -1485,11 +1608,14 @@ namespace Server.Network if (ph.Ingame && state.Mobile?.Deleted != false) { if (state.Mobile == null) + { Console.WriteLine( "Client: {0}: Sent in-game packet (0xBFx{1:X2}) before having been attached to a mobile", state, packetID ); + } + state.Dispose(); } else @@ -1503,12 +1629,16 @@ namespace Server.Network var from = state.Mobile; if (from == null) + { return; + } Item spellbook = null; if (pvSrc.ReadInt16() == 1) + { spellbook = World.FindItem(pvSrc.ReadUInt32()); + } var spellID = pvSrc.ReadInt16() - 1; @@ -1520,19 +1650,25 @@ namespace Server.Network var from = state.Mobile; if (from == null) + { return; + } if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0) { var bandage = World.FindItem(pvSrc.ReadUInt32()); if (bandage == null) + { return; + } var target = World.FindMobile(pvSrc.ReadUInt32()); if (target == null) + { return; + } EventSink.InvokeBandageTargetRequest(from, bandage, target); @@ -1552,14 +1688,18 @@ namespace Server.Network public static void BatchQueryProperties(NetState state, PacketReader pvSrc) { if (!ObjectPropertyList.Enabled) + { return; + } var from = state.Mobile; var length = pvSrc.Remaining; if (length % 4 != 0) + { return; + } while (pvSrc.Remaining > 0) { @@ -1570,7 +1710,9 @@ namespace Server.Network var m = World.FindMobile(s); if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m)) - m.SendPropertiesTo(from); + { + m.SendPropertiesTo(@from); + } } else if (s.IsItem) { @@ -1578,7 +1720,9 @@ namespace Server.Network if (item?.Deleted == false && from.CanSee(item) && Utility.InUpdateRange(from.Location, item.GetWorldLocation())) - item.SendPropertiesTo(from); + { + item.SendPropertiesTo(@from); + } } } } @@ -1586,7 +1730,9 @@ namespace Server.Network public static void QueryProperties(NetState state, PacketReader pvSrc) { if (!ObjectPropertyList.Enabled) + { return; + } var from = state.Mobile; @@ -1597,7 +1743,9 @@ namespace Server.Network var m = World.FindMobile(s); if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m)) - m.SendPropertiesTo(from); + { + m.SendPropertiesTo(@from); + } } else if (s.IsItem) { @@ -1605,14 +1753,18 @@ namespace Server.Network if (item?.Deleted == false && from.CanSee(item) && Utility.InUpdateRange(from.Location, item.GetWorldLocation())) - item.SendPropertiesTo(from); + { + item.SendPropertiesTo(@from); + } } } public static void PartyMessage(NetState state, PacketReader pvSrc) { if (state.Mobile == null) + { return; + } switch (pvSrc.ReadByte()) { @@ -1697,11 +1849,15 @@ namespace Server.Network int stat = pvSrc.ReadByte(); int lockValue = pvSrc.ReadByte(); - if (lockValue > 2) lockValue = 0; + if (lockValue > 2) + { + lockValue = 0; + } var m = state.Mobile; if (m != null) + { switch (stat) { case 0: @@ -1714,6 +1870,7 @@ namespace Server.Network m.IntLock = (StatLockType)lockValue; break; } + } } public static void ScreenSize(NetState state, PacketReader pvSrc) @@ -1726,7 +1883,10 @@ namespace Server.Network { var from = state.Mobile; - if (from == null) return; + if (from == null) + { + return; + } var menu = from.ContextMenu; @@ -1741,11 +1901,17 @@ namespace Server.Network Point3D p; if (entity is Mobile) + { p = entity.Location; + } else if (entity is Item item) + { p = item.GetWorldLocation(); + } else + { return; + } int index = pvSrc.ReadUInt16(); @@ -1756,10 +1922,14 @@ namespace Server.Network var range = e.Range; if (range == -1) + { range = 18; + } if (e.Enabled && from.InRange(p, range)) + { e.OnClick(); + } } } } @@ -1773,24 +1943,36 @@ namespace Server.Network if (from != null && target != null && from.Map == target.Map && from.CanSee(target)) { if (target is Mobile && !Utility.InUpdateRange(from.Location, target.Location)) + { return; + } var item = target as Item; if (item != null && !Utility.InUpdateRange(from.Location, item.GetWorldLocation())) + { return; + } if (!from.CheckContextMenuDisplay(target)) + { return; + } var c = new ContextMenu(from, target); if (c.Entries.Length > 0) { if (item?.RootParent is Mobile mobile && mobile != from && mobile.AccessLevel >= from.AccessLevel) + { for (var i = 0; i < c.Entries.Length; ++i) + { if (!c.Entries[i].NonLocalUse) + { c.Entries[i].Enabled = false; + } + } + } from.ContextMenu = c; } @@ -1807,7 +1989,9 @@ namespace Server.Network var lang = pvSrc.ReadString(4); if (state.Mobile != null) + { state.Mobile.Language = lang; + } } public static void AssistVersion(NetState state, PacketReader pvSrc) @@ -1842,16 +2026,17 @@ namespace Server.Network var m = World.FindMobile(pvSrc.ReadUInt32()); if (m != null) + { switch (type) { case 0x04: // Stats { - m.OnStatsQuery(from); + m.OnStatsQuery(@from); break; } case 0x05: { - m.OnSkillsQuery(from); + m.OnSkillsQuery(@from); break; } default: @@ -1860,6 +2045,7 @@ namespace Server.Network break; } } + } } public static void PlayCharacter(NetState state, PacketReader pvSrc) @@ -1934,10 +2120,14 @@ namespace Server.Network state.Send(new LoginConfirm(m)); if (m.Map != null) + { state.Send(new MapChange(m.Map)); + } if (!Core.SE && state.ProtocolChanges < ProtocolChanges.Version6000) + { state.Send(new MapPatches()); + } state.Send(SeasonChange.Instantiate(m.GetSeason(), true)); @@ -2019,7 +2209,9 @@ namespace Server.Network state.Send(new CurrentTime()); state.Send(SeasonChange.Instantiate(m.GetSeason(), true)); if (m.Map != null) + { state.Send(new MapChange(m.Map)); + } EventSink.InvokeLogin(m); @@ -2066,7 +2258,7 @@ namespace Server.Network Pre-7.0.0.0: 0x00, 0x01 -> Human Male, Human Female 0x02, 0x03 -> Elf Male, Elf Female - + Post-7.0.0.0: 0x00, 0x01 0x02, 0x03 -> Human Male, Human Female @@ -2296,11 +2488,13 @@ namespace Server.Network var oldest = DateTime.MaxValue; foreach (var kvp in m_AuthIDWindow) + { if (kvp.Value.Age < oldest) { oldestID = kvp.Key; oldest = kvp.Value.Age; } + } m_AuthIDWindow.Remove(oldestID); } @@ -2312,7 +2506,9 @@ namespace Server.Network authID = Utility.Random(1, int.MaxValue - 1); if (Utility.RandomBool()) + { authID |= 1 << 31; + } } while (m_AuthIDWindow.ContainsKey(authID)); m_AuthIDWindow[authID] = new AuthIDPersistence(state.Version); @@ -2374,9 +2570,13 @@ namespace Server.Network state.Send(SupportedFeatures.Instantiate(state)); if (state.NewCharacterList) + { state.Send(new CharacterList(state.Account, state.CityInfo)); + } else + { state.Send(new CharacterListOld(state.Account, state.CityInfo)); + } } else { @@ -2477,9 +2677,13 @@ namespace Server.Network EventSink.InvokeAccountLogin(e); if (e.Accepted) + { AccountLogin_ReplyAck(state); + } else + { AccountLogin_ReplyRej(state, e.RejectReason); + } } public static void AccountLogin_ReplyAck(NetState state) @@ -2514,7 +2718,9 @@ namespace Server.Network int count = pvSrc.ReadByte(); var serialList = new List(count); for (var i = 0; i < count; ++i) + { serialList.Add(pvSrc.ReadUInt32()); + } EventSink.InvokeEquipMacro(ns.Mobile, serialList); } @@ -2524,7 +2730,9 @@ namespace Server.Network int count = pvSrc.ReadByte(); var layers = new List(count); for (var i = 0; i < count; ++i) + { layers.Add((Layer)pvSrc.ReadUInt16()); + } EventSink.InvokeUnequipMacro(ns.Mobile, layers); } @@ -2547,7 +2755,10 @@ namespace Server.Network { Serial serial = pvSrc.ReadUInt32(); - if (serial.IsItem) EventSink.InvokeTargetByResourceMacro(ns.Mobile, World.FindItem(serial), pvSrc.ReadInt16()); + if (serial.IsItem) + { + EventSink.InvokeTargetByResourceMacro(ns.Mobile, World.FindItem(serial), pvSrc.ReadInt16()); + } } private class LoginTimer : Timer diff --git a/Projects/Server/Network/PacketReader.cs b/Projects/Server/Network/PacketReader.cs index 876225d01..26623fe25 100644 --- a/Projects/Server/Network/PacketReader.cs +++ b/Projects/Server/Network/PacketReader.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketReader.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Buffers; using System.IO; @@ -46,7 +26,9 @@ namespace Server.Network var buffer = m_Reader.Sequence.ToArray(); if (buffer.Length > 0) + { sw.WriteLine("Client: {0}: Unhandled packet 0x{1:X2}", state, buffer[0]); + } using (var ms = new MemoryStream(buffer)) { @@ -68,22 +50,37 @@ namespace Server.Network { case SeekOrigin.Begin: if (offset < m_Reader.Consumed) + { m_Reader.Rewind(m_Reader.Consumed - Math.Max(offset, 0L)); + } else + { m_Reader.Advance(offset - m_Reader.Consumed); + } + break; case SeekOrigin.Current: if (offset < 0) + { m_Reader.Rewind(Math.Min(m_Reader.Consumed, offset * -1)); + } else + { m_Reader.Advance(Math.Min(m_Reader.Remaining, offset)); + } + break; case SeekOrigin.End: var count = m_Reader.Remaining - offset; if (count < 0) + { m_Reader.Rewind(count * -1); + } else if (count > 0) + { m_Reader.Advance(count); + } + break; } @@ -111,7 +108,9 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryReadLittleEndian(out short c) && c != 0) + { sb.Append((char)c); + } return sb.ToString(); } @@ -121,10 +120,14 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryReadLittleEndian(out short c) && c != 0) + { sb.Append((char)c); + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength); + } return sb.ToString(); } @@ -134,11 +137,17 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryReadLittleEndian(out short c) && c != 0) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength * 2); + } return sb.ToString(); } @@ -148,8 +157,12 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryReadLittleEndian(out short c) && c != 0) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } return sb.ToString(); } @@ -159,8 +172,12 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryReadBigEndian(out short c) && c != 0) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } return sb.ToString(); } @@ -170,7 +187,9 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryReadBigEndian(out short c) && c != 0) + { sb.Append((char)c); + } return sb.ToString(); } @@ -195,8 +214,12 @@ namespace Server.Network var sb = new StringBuilder(s.Length); for (var i = 0; i < s.Length; ++i) + { if (IsSafeChar(s[i])) + { sb.Append(s[i]); + } + } return sb.ToString(); } @@ -218,8 +241,12 @@ namespace Server.Network var sb = new StringBuilder(s.Length); for (var i = 0; i < s.Length; ++i) + { if (IsSafeChar(s[i])) + { sb.Append(s[i]); + } + } return sb.ToString(); } @@ -236,7 +263,9 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryRead(out var c)) + { sb.Append((char)c); + } return sb.ToString(); } @@ -246,8 +275,12 @@ namespace Server.Network var sb = new StringBuilder(); while (m_Reader.TryRead(out var c)) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } return sb.ToString(); } @@ -257,11 +290,17 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryReadBigEndian(out short c) && c != 0) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength * 2); + } return sb.ToString(); } @@ -271,10 +310,14 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryReadBigEndian(out short c) && c != 0) + { sb.Append((char)c); + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength * 2); + } return sb.ToString(); } @@ -284,11 +327,17 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryRead(out var c) && c != 0) + { if (IsSafeChar(c)) + { sb.Append((char)c); + } + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength); + } return sb.ToString(); } @@ -298,10 +347,14 @@ namespace Server.Network var sb = new StringBuilder(); while (fixedLength-- > 0 && m_Reader.TryRead(out var c) && c != 0) + { sb.Append((char)c); + } if (fixedLength > 0) + { m_Reader.Advance(fixedLength); + } return sb.ToString(); } diff --git a/Projects/Server/Network/PacketWriter.cs b/Projects/Server/Network/PacketWriter.cs index ee991ed0e..307ed18f8 100644 --- a/Projects/Server/Network/PacketWriter.cs +++ b/Projects/Server/Network/PacketWriter.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * PacketWriter.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Concurrent; using System.IO; diff --git a/Projects/Server/Network/Packets/Old Packets/AccountPackets.cs b/Projects/Server/Network/Packets/Old Packets/AccountPackets.cs index bc9fe7876..959a39696 100644 --- a/Projects/Server/Network/Packets/Old Packets/AccountPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/AccountPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AccountPackets.cs * * * @@ -56,21 +56,30 @@ namespace Server.Network var count = 0; for (var i = 0; i < a.Length; ++i) + { if (a[i] != null) + { ++count; + } + } Stream.Write((byte)count); Stream.Write((byte)0); for (var i = 0; i < a.Length; ++i) + { if (a[i] != null) { var name = a[i].Name; if (name == null) + { name = "-null-"; + } else if ((name = name.Trim()).Length == 0) + { name = "-empty-"; + } Stream.WriteAsciiFixed(name, 30); Stream.Fill(30); // password @@ -79,6 +88,7 @@ namespace Server.Network { Stream.Fill(60); } + } } } @@ -123,15 +133,23 @@ namespace Server.Network flags &= ~FeatureFlags.UOTD; if (ns.Account.Limit > 6) + { flags |= FeatureFlags.SeventhCharacterSlot; + } else + { flags |= FeatureFlags.SixthCharacterSlot; + } } if (ns.ExtendedSupportedFeatures) + { Stream.Write((uint)flags); + } else + { Stream.Write((ushort)flags); + } } public static FeatureFlags Value { get; set; } @@ -156,7 +174,9 @@ namespace Server.Network var map = m.Map; if (map == null || map == Map.Internal) + { map = m.LogoutMap; + } Stream.Write((short)0); Stream.Write((short)0); @@ -185,8 +205,12 @@ namespace Server.Network var highSlot = -1; for (var i = 0; i < a.Length; ++i) + { if (a[i] != null) + { highSlot = i; + } + } var count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5); @@ -218,14 +242,19 @@ namespace Server.Network var highSlot = -1; for (var i = 0; i < a.Length; ++i) + { if (a[i] != null) + { highSlot = i; + } + } var count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5); Stream.Write((byte)count); for (var i = 0; i < count; ++i) + { if (a[i] != null) { Stream.WriteAsciiFixed(a[i].Name, 30); @@ -235,6 +264,7 @@ namespace Server.Network { Stream.Fill(60); } + } Stream.Write((byte)info.Length); @@ -256,13 +286,19 @@ namespace Server.Network var flags = ExpansionInfo.CoreExpansion.CharacterListFlags; if (count > 6) + { flags |= CharacterListFlags.SeventhCharacterSlot | CharacterListFlags.SixthCharacterSlot; // 7th Character Slot - TODO: Is SixthCharacterSlot Required? + } else if (count == 6) + { flags |= CharacterListFlags.SixthCharacterSlot; // 6th Character Slot + } else if (a.Limit == 1) + { flags |= CharacterListFlags.SlotLimit & CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character + } Stream.Write((int)(flags | AdditionalFlags)); // Additional Flags @@ -281,14 +317,19 @@ namespace Server.Network var highSlot = -1; for (var i = 0; i < a.Length; ++i) + { if (a[i] != null) + { highSlot = i; + } + } var count = Math.Max(Math.Max(highSlot + 1, a.Limit), 5); Stream.Write((byte)count); for (var i = 0; i < count; ++i) + { if (a[i] != null) { Stream.WriteAsciiFixed(a[i].Name, 30); @@ -298,6 +339,7 @@ namespace Server.Network { Stream.Fill(60); } + } Stream.Write((byte)info.Length); @@ -313,13 +355,19 @@ namespace Server.Network var flags = ExpansionInfo.CoreExpansion.CharacterListFlags; if (count > 6) + { flags |= CharacterListFlags.SeventhCharacterSlot | CharacterListFlags.SixthCharacterSlot; // 7th Character Slot - TODO: Is SixthCharacterSlot Required? + } else if (count == 6) + { flags |= CharacterListFlags.SixthCharacterSlot; // 6th Character Slot + } else if (a.Limit == 1) + { flags |= CharacterListFlags.SlotLimit & CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character + } Stream.Write((int)(flags | CharacterList.AdditionalFlags)); // Additional Flags } diff --git a/Projects/Server/Network/Packets/Old Packets/ArrowPackets.cs b/Projects/Server/Network/Packets/Old Packets/ArrowPackets.cs index e02795735..231307b24 100644 --- a/Projects/Server/Network/Packets/Old Packets/ArrowPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/ArrowPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ArrowPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/AttributeNormalizer.cs b/Projects/Server/Network/Packets/Old Packets/AttributeNormalizer.cs index 954ea4f4e..47cc6dea2 100644 --- a/Projects/Server/Network/Packets/Old Packets/AttributeNormalizer.cs +++ b/Projects/Server/Network/Packets/Old Packets/AttributeNormalizer.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AttributeNormalizer.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/CombatPackets.cs b/Projects/Server/Network/Packets/Old Packets/CombatPackets.cs index 0b649ccac..c42eab6bb 100644 --- a/Projects/Server/Network/Packets/Old Packets/CombatPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/CombatPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CombatPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs b/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs index 91f300926..0237ccd24 100644 --- a/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/DamagePackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: DamagePackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/DisplayHuePicker.cs b/Projects/Server/Network/Packets/Old Packets/DisplayHuePicker.cs index 469cc7ec3..bc829d2de 100644 --- a/Projects/Server/Network/Packets/Old Packets/DisplayHuePicker.cs +++ b/Projects/Server/Network/Packets/Old Packets/DisplayHuePicker.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: DisplayHuePicker.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/EffectPackets.cs b/Projects/Server/Network/Packets/Old Packets/EffectPackets.cs index ad094ca20..faad7c948 100644 --- a/Projects/Server/Network/Packets/Old Packets/EffectPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/EffectPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: EffectPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/EquipmentPackets.cs b/Projects/Server/Network/Packets/Old Packets/EquipmentPackets.cs index a683c0a25..cbd483260 100644 --- a/Projects/Server/Network/Packets/Old Packets/EquipmentPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/EquipmentPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: EquipmentPackets.cs * * * @@ -83,7 +83,10 @@ namespace Server.Network } } - if (info.Unidentified) Stream.Write(-4); + if (info.Unidentified) + { + Stream.Write(-4); + } for (var i = 0; i < attrs.Length; ++i) { @@ -109,7 +112,9 @@ namespace Server.Network parentSerial = parent.Serial; if (parent.SolidHueOverride >= 0) + { hue = parent.SolidHueOverride; + } } else { diff --git a/Projects/Server/Network/Packets/Old Packets/GumpPackets.cs b/Projects/Server/Network/Packets/Old Packets/GumpPackets.cs index 80238dc6a..92cb2fc8f 100644 --- a/Projects/Server/Network/Packets/Old Packets/GumpPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/GumpPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/ItemPackets.cs b/Projects/Server/Network/Packets/Old Packets/ItemPackets.cs index 01a12afcf..1ef140e91 100644 --- a/Projects/Server/Network/Packets/Old Packets/ItemPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/ItemPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ItemPackets.cs * * * @@ -41,43 +41,69 @@ namespace Server.Network var direction = (int)item.Direction; if (amount != 0) + { serial |= 0x80000000; + } else + { serial &= 0x7FFFFFFF; + } Stream.Write(serial); if (item is BaseMulti) + { Stream.Write((short)(itemID | 0x4000)); + } else + { Stream.Write((short)itemID); + } - if (amount != 0) Stream.Write((short)amount); + if (amount != 0) + { + Stream.Write((short)amount); + } x &= 0x7FFF; - if (direction != 0) x |= 0x8000; + if (direction != 0) + { + x |= 0x8000; + } Stream.Write((short)x); y &= 0x3FFF; - if (hue != 0) y |= 0x8000; + if (hue != 0) + { + y |= 0x8000; + } - if (flags != 0) y |= 0x4000; + if (flags != 0) + { + y |= 0x4000; + } Stream.Write((short)y); if (direction != 0) + { Stream.Write((byte)direction); + } Stream.Write((sbyte)loc.m_Z); if (hue != 0) + { Stream.Write((ushort)hue); + } if (flags != 0) + { Stream.Write((byte)flags); + } } } @@ -212,7 +238,9 @@ namespace Server.Network Stream.Write((short)offset); for (var i = 0; i < 8; ++i) + { Stream.Write((byte)(content >> (i * 8))); + } } } @@ -229,6 +257,7 @@ namespace Server.Network ulong mask = 1; for (var i = 0; i < 64; ++i, mask <<= 1) + { if ((content & mask) != 0) { Stream.Write(0x7FFFFFFF - i); @@ -242,6 +271,7 @@ namespace Server.Network ++written; } + } Stream.Seek(3, SeekOrigin.Begin); Stream.Write((ushort)written); @@ -261,6 +291,7 @@ namespace Server.Network ulong mask = 1; for (var i = 0; i < 64; ++i, mask <<= 1) + { if ((content & mask) != 0) { Stream.Write(0x7FFFFFFF - i); @@ -275,6 +306,7 @@ namespace Server.Network ++written; } + } Stream.Seek(3, SeekOrigin.Begin); Stream.Write((ushort)written); diff --git a/Projects/Server/Network/Packets/Old Packets/LightPackets.cs b/Projects/Server/Network/Packets/Old Packets/LightPackets.cs index 126f9a75a..6fd482b94 100644 --- a/Projects/Server/Network/Packets/Old Packets/LightPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/LightPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: LightPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/MapPackets.cs b/Projects/Server/Network/Packets/Old Packets/MapPackets.cs index 1266eb1f7..1880cbaea 100644 --- a/Projects/Server/Network/Packets/Old Packets/MapPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/MapPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MapPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/MenuPackets.cs b/Projects/Server/Network/Packets/Old Packets/MenuPackets.cs index f6a529f4e..1a602494a 100644 --- a/Projects/Server/Network/Packets/Old Packets/MenuPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/MenuPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MenuPackets.cs * * * @@ -166,11 +166,15 @@ namespace Server.Network var range = e.Range; if (range == -1) + { range = 18; + } var flags = e.Flags; if (!(e.Enabled && menu.From.InRange(p, range))) + { flags |= CMEFlags.Disabled; + } Stream.Write((short)flags); } @@ -213,21 +217,29 @@ namespace Server.Network var range = e.Range; if (range == -1) + { range = 18; + } var flags = e.Flags; if (!(e.Enabled && menu.From.InRange(p, range))) + { flags |= CMEFlags.Disabled; + } var color = e.Color & 0xFFFF; if (color != 0xFFFF) + { flags |= CMEFlags.Colored; + } Stream.Write((short)flags); if ((flags & CMEFlags.Colored) != 0) + { Stream.Write((short)color); + } } } } diff --git a/Projects/Server/Network/Packets/Old Packets/MessagePackets.cs b/Projects/Server/Network/Packets/Old Packets/MessagePackets.cs index 12514836d..9adae8fd4 100644 --- a/Projects/Server/Network/Packets/Old Packets/MessagePackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/MessagePackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MessagePackets.cs * * * @@ -40,7 +40,9 @@ namespace Server.Network args ??= ""; if (hue == 0) + { hue = 0x3B2; + } EnsureCapacity(50 + args.Length * 2); @@ -117,7 +119,9 @@ namespace Server.Network args ??= ""; if (hue == 0) + { hue = 0x3B2; + } EnsureCapacity(52 + affix.Length + args.Length * 2); @@ -144,7 +148,9 @@ namespace Server.Network text ??= ""; if (hue == 0) + { hue = 0x3B2; + } EnsureCapacity(45 + text.Length); @@ -165,12 +171,18 @@ namespace Server.Network string text ) : base(0xAE) { - if (string.IsNullOrEmpty(lang)) lang = "ENU"; + if (string.IsNullOrEmpty(lang)) + { + lang = "ENU"; + } + name ??= ""; text ??= ""; if (hue == 0) + { hue = 0x3B2; + } EnsureCapacity(50 + text.Length * 2); diff --git a/Projects/Server/Network/Packets/Old Packets/MobilePackets.cs b/Projects/Server/Network/Packets/Old Packets/MobilePackets.cs index 79c34b0a7..51beb7da8 100644 --- a/Projects/Server/Network/Packets/Old Packets/MobilePackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/MobilePackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MobilePackets.cs * * * @@ -49,7 +49,9 @@ namespace Server.Network var hue = m.Hue; if (m.SolidHueOverride >= 0) + { hue = m.SolidHueOverride; + } Stream.Write(m.Serial); Stream.Write((short)m.Body); @@ -72,7 +74,9 @@ namespace Server.Network var hue = m.Hue; if (m.SolidHueOverride >= 0) + { hue = m.SolidHueOverride; + } Stream.Write(m.Serial); Stream.Write((short)m.Body); @@ -319,8 +323,12 @@ namespace Server.Network } if (type >= 6) + { for (var i = 0; i < 15; ++i) + { Stream.Write((short)m.GetAOSStatus(i)); + } + } } } @@ -362,16 +370,22 @@ namespace Server.Network Stream.WriteAsciiFixed(name, 30); if (beholder == beheld) + { WriteAttr(beheld.Hits, beheld.HitsMax); + } else + { WriteAttrNorm(beheld.Hits, beheld.HitsMax); + } Stream.Write(beheld.CanBeRenamedBy(beholder)); Stream.Write((byte)type); if (type <= 0) + { return; + } Stream.Write(beheld.Female); @@ -423,8 +437,12 @@ namespace Server.Network } if (type >= 6) + { for (var i = 0; i < 15; ++i) + { Stream.Write((short)beheld.GetAOSStatus(i)); + } + } } private void WriteAttr(int current, int maximum) @@ -453,9 +471,13 @@ namespace Server.Network var p = m.Poison; if (p != null) + { Stream.Write((byte)(p.Level + 1)); + } else + { Stream.Write((byte)0); + } } } @@ -471,9 +493,13 @@ namespace Server.Network Stream.Write((short)2); if (m.Blessed || m.YellowHealthbar) + { Stream.Write((byte)1); + } else + { Stream.Write((byte)0); + } } } @@ -484,7 +510,9 @@ namespace Server.Network var hue = m.Hue; if (m.SolidHueOverride >= 0) + { hue = m.SolidHueOverride; + } Stream.Write(m.Serial); Stream.Write((short)m.Body); @@ -507,7 +535,9 @@ namespace Server.Network var hue = m.Hue; if (m.SolidHueOverride >= 0) + { hue = m.SolidHueOverride; + } Stream.Write(m.Serial); Stream.Write((short)m.Body); @@ -536,16 +566,23 @@ namespace Server.Network var count = eq.Count; if (beheld.HairItemID > 0) + { count++; + } + if (beheld.FacialHairItemID > 0) + { count++; + } EnsureCapacity(23 + count * 9); var hue = beheld.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } Stream.Write(beheld.Serial); Stream.Write((short)beheld.Body); @@ -570,7 +607,9 @@ namespace Server.Network hue = item.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = item.ItemID & 0xFFFF; @@ -583,13 +622,16 @@ namespace Server.Network } if (beheld.HairItemID > 0) + { if (m_DupedLayers[(int)Layer.Hair] != m_Version) { m_DupedLayers[(int)Layer.Hair] = m_Version; hue = beheld.HairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.HairItemID & 0xFFFF; @@ -599,15 +641,19 @@ namespace Server.Network Stream.Write((short)hue); } + } if (beheld.FacialHairItemID > 0) + { if (m_DupedLayers[(int)Layer.FacialHair] != m_Version) { m_DupedLayers[(int)Layer.FacialHair] = m_Version; hue = beheld.FacialHairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.FacialHairItemID & 0xFFFF; @@ -617,6 +663,7 @@ namespace Server.Network Stream.Write((short)hue); } + } Stream.Write(0); // terminate } @@ -624,9 +671,15 @@ namespace Server.Network public static Packet Create(NetState ns, Mobile beholder, Mobile beheld) { if (ns.NewMobileIncoming) + { return new MobileIncoming(beholder, beheld); + } + if (ns.StygianAbyss) + { return new MobileIncomingSA(beholder, beheld); + } + return new MobileIncomingOld(beholder, beheld); } } @@ -645,16 +698,23 @@ namespace Server.Network var count = eq.Count; if (beheld.HairItemID > 0) + { count++; + } + if (beheld.FacialHairItemID > 0) + { count++; + } EnsureCapacity(23 + count * 9); var hue = beheld.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } Stream.Write(beheld.Serial); Stream.Write((short)beheld.Body); @@ -679,70 +739,92 @@ namespace Server.Network hue = item.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = item.ItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(item.Serial); Stream.Write((ushort)itemID); Stream.Write(layer); if (writeHue) + { Stream.Write((short)hue); + } } } if (beheld.HairItemID > 0) + { if (m_DupedLayers[(int)Layer.Hair] != m_Version) { m_DupedLayers[(int)Layer.Hair] = m_Version; hue = beheld.HairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.HairItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(HairInfo.FakeSerial(beheld)); Stream.Write((ushort)itemID); Stream.Write((byte)Layer.Hair); if (writeHue) + { Stream.Write((short)hue); + } } + } if (beheld.FacialHairItemID > 0) + { if (m_DupedLayers[(int)Layer.FacialHair] != m_Version) { m_DupedLayers[(int)Layer.FacialHair] = m_Version; hue = beheld.FacialHairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.FacialHairItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(FacialHairInfo.FakeSerial(beheld)); Stream.Write((ushort)itemID); Stream.Write((byte)Layer.FacialHair); if (writeHue) + { Stream.Write((short)hue); + } } + } Stream.Write(0); // terminate } @@ -763,16 +845,23 @@ namespace Server.Network var count = eq.Count; if (beheld.HairItemID > 0) + { count++; + } + if (beheld.FacialHairItemID > 0) + { count++; + } EnsureCapacity(23 + count * 9); var hue = beheld.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } Stream.Write(beheld.Serial); Stream.Write((short)beheld.Body); @@ -797,70 +886,92 @@ namespace Server.Network hue = item.Hue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = item.ItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(item.Serial); Stream.Write((ushort)itemID); Stream.Write(layer); if (writeHue) + { Stream.Write((short)hue); + } } } if (beheld.HairItemID > 0) + { if (m_DupedLayers[(int)Layer.Hair] != m_Version) { m_DupedLayers[(int)Layer.Hair] = m_Version; hue = beheld.HairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.HairItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(HairInfo.FakeSerial(beheld)); Stream.Write((ushort)itemID); Stream.Write((byte)Layer.Hair); if (writeHue) + { Stream.Write((short)hue); + } } + } if (beheld.FacialHairItemID > 0) + { if (m_DupedLayers[(int)Layer.FacialHair] != m_Version) { m_DupedLayers[(int)Layer.FacialHair] = m_Version; hue = beheld.FacialHairHue; if (beheld.SolidHueOverride >= 0) + { hue = beheld.SolidHueOverride; + } var itemID = beheld.FacialHairItemID & 0x7FFF; var writeHue = hue != 0; if (writeHue) + { itemID |= 0x8000; + } Stream.Write(FacialHairInfo.FakeSerial(beheld)); Stream.Write((ushort)itemID); Stream.Write((byte)Layer.FacialHair); if (writeHue) + { Stream.Write((short)hue); + } } + } Stream.Write(0); // terminate } diff --git a/Projects/Server/Network/Packets/Old Packets/MovementPackets.cs b/Projects/Server/Network/Packets/Old Packets/MovementPackets.cs index d5dc3b8f1..fac5b0f46 100644 --- a/Projects/Server/Network/Packets/Old Packets/MovementPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/MovementPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MovementPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/ObjectHelpResponsePackets.cs b/Projects/Server/Network/Packets/Old Packets/ObjectHelpResponsePackets.cs index fb88b6639..492056675 100644 --- a/Projects/Server/Network/Packets/Old Packets/ObjectHelpResponsePackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/ObjectHelpResponsePackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ObjectHelpResponsePackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/PlayerPackets.cs b/Projects/Server/Network/Packets/Old Packets/PlayerPackets.cs index f66032c9b..e81a95b47 100644 --- a/Projects/Server/Network/Packets/Old Packets/PlayerPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/PlayerPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: PlayerPackets.cs * * * @@ -290,10 +290,14 @@ namespace Server.Network byte flags = 0x00; if (warmode) + { flags |= 0x01; + } if (canLift) + { flags |= 0x02; + } Stream.Write(m); Stream.WriteAsciiFixed(title, 60); @@ -328,7 +332,9 @@ namespace Server.Network public static Packet GetInstance(MusicName name) { if (name == MusicName.Invalid) + { return InvalidInstance; + } var v = (int)name; Packet p; @@ -338,7 +344,9 @@ namespace Server.Network p = m_Instances[v]; if (p == null) + { m_Instances[v] = p = SetStatic(new PlayMusic(name)); + } } else { diff --git a/Projects/Server/Network/Packets/Old Packets/SecureTradePackets.cs b/Projects/Server/Network/Packets/Old Packets/SecureTradePackets.cs index ec7687efa..e6525c7e8 100644 --- a/Projects/Server/Network/Packets/Old Packets/SecureTradePackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/SecureTradePackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SecureTradePackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/TargetPackets.cs b/Projects/Server/Network/Packets/Old Packets/TargetPackets.cs index 478baf790..05c14528b 100644 --- a/Projects/Server/Network/Packets/Old Packets/TargetPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/TargetPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TargetPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/UnicodePromptPackets.cs b/Projects/Server/Network/Packets/Old Packets/UnicodePromptPackets.cs index e2a4df741..30dc6f417 100644 --- a/Projects/Server/Network/Packets/Old Packets/UnicodePromptPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/UnicodePromptPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: UnicodePromptPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/VendorBuyPackets.cs b/Projects/Server/Network/Packets/Old Packets/VendorBuyPackets.cs index b2a5e70d3..204a8f6df 100644 --- a/Projects/Server/Network/Packets/Old Packets/VendorBuyPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/VendorBuyPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: VendorBuyPackets.cs * * * diff --git a/Projects/Server/Network/Packets/Old Packets/VendorSellPackets.cs b/Projects/Server/Network/Packets/Old Packets/VendorSellPackets.cs index 72baa464e..2f060bb99 100644 --- a/Projects/Server/Network/Packets/Old Packets/VendorSellPackets.cs +++ b/Projects/Server/Network/Packets/Old Packets/VendorSellPackets.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: VendorSellPackets.cs * * * diff --git a/Projects/Server/Network/ServerConnectionHandler.cs b/Projects/Server/Network/ServerConnectionHandler.cs index c7a6317f3..1610d4378 100644 --- a/Projects/Server/Network/ServerConnectionHandler.cs +++ b/Projects/Server/Network/ServerConnectionHandler.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerConnectionHandler.cs * * * diff --git a/Projects/Server/Network/ServerInfo.cs b/Projects/Server/Network/ServerInfo.cs index 6153fe581..939cdb841 100644 --- a/Projects/Server/Network/ServerInfo.cs +++ b/Projects/Server/Network/ServerInfo.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerInfo.cs * * * diff --git a/Projects/Server/Network/ServerStartup.cs b/Projects/Server/Network/ServerStartup.cs index 5fdc3b74b..20d2678cc 100644 --- a/Projects/Server/Network/ServerStartup.cs +++ b/Projects/Server/Network/ServerStartup.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ServerStartup.cs * * * diff --git a/Projects/Server/Network/StaticPacketHandlers.cs b/Projects/Server/Network/StaticPacketHandlers.cs index b00829879..73b5b147a 100644 --- a/Projects/Server/Network/StaticPacketHandlers.cs +++ b/Projects/Server/Network/StaticPacketHandlers.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: StaticPacketHandlers.cs * * * @@ -50,7 +50,9 @@ namespace Server.Network public static OPLInfo FreeOPLInfoPacket(IPropertyListObject obj) { if (OPLInfoPackets.TryRemove(obj, out var p)) + { Packet.Release(p); + } return p; } @@ -71,7 +73,9 @@ namespace Server.Network public static void FreeRemoveItemPacket(IEntity entity) { if (RemoveEntityPackets.TryRemove(entity, out var p)) + { Packet.Release(p); + } } public static WorldItem GetWorldItemPacket(Item item) @@ -116,13 +120,19 @@ namespace Server.Network public static void FreeWorldItemPackets(Item item) { if (WorldItemPackets.TryRemove(item, out var wi)) + { Packet.Release(wi); + } if (WorldItemSAPackets.TryRemove(item, out var wisa)) + { Packet.Release(wisa); + } if (WorldItemHSPackets.TryRemove(item, out var wihs)) + { Packet.Release(wihs); + } } } } diff --git a/Projects/Server/Network/TcpServer.cs b/Projects/Server/Network/TcpServer.cs index 59180560b..86dbc0f77 100644 --- a/Projects/Server/Network/TcpServer.cs +++ b/Projects/Server/Network/TcpServer.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TcpServer.cs * * * diff --git a/Projects/Server/ObjectPropertyList.cs b/Projects/Server/ObjectPropertyList.cs index 8565d290f..cca32808d 100644 --- a/Projects/Server/ObjectPropertyList.cs +++ b/Projects/Server/ObjectPropertyList.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ObjectPropertyList.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.IO; using System.Text; using Server.Network; @@ -73,7 +53,9 @@ namespace Server public void Add(int number) { if (number == 0) + { return; + } AddHash(number); @@ -104,7 +86,9 @@ namespace Server public void Add(int number, string arguments) { if (number == 0) + { return; + } arguments ??= ""; @@ -122,7 +106,9 @@ namespace Server var byteCount = m_Encoding.GetByteCount(arguments); if (byteCount > m_Buffer.Length) + { m_Buffer = new byte[byteCount]; + } byteCount = m_Encoding.GetBytes(arguments, 0, arguments.Length, m_Buffer, 0); @@ -183,7 +169,7 @@ namespace Server /*public OPLInfo( ObjectPropertyList list ) : base( 0xBF ) { EnsureCapacity( 13 ); - + m_Stream.Write( (short) 0x10 ); m_Stream.Write( (int) list.Entity.Serial ); m_Stream.Write( (int) list.Hash ); diff --git a/Projects/Server/Party.cs b/Projects/Server/Party.cs index d285b71fc..64b30e5c7 100644 --- a/Projects/Server/Party.cs +++ b/Projects/Server/Party.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Party.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server { public abstract class PartyCommands diff --git a/Projects/Server/Persistence/BinaryMemoryWriter.cs b/Projects/Server/Persistence/BinaryMemoryWriter.cs index 5c9e349f2..929afe426 100644 --- a/Projects/Server/Persistence/BinaryMemoryWriter.cs +++ b/Projects/Server/Persistence/BinaryMemoryWriter.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * BinaryMemoryWriter.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.IO; namespace Server diff --git a/Projects/Server/Persistence/DualSaveStrategy.cs b/Projects/Server/Persistence/DualSaveStrategy.cs index 4b26e52ac..bbb412c2a 100644 --- a/Projects/Server/Persistence/DualSaveStrategy.cs +++ b/Projects/Server/Persistence/DualSaveStrategy.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * DualSaveStrategy.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Threading; namespace Server @@ -42,7 +22,9 @@ namespace Server if (permitBackgroundWrite && UseSequentialWriters ) // If we're permitted to write in the background, but we don't anyways, then notify. + { World.NotifyDiskWriteComplete(); + } } } } diff --git a/Projects/Server/Persistence/DynamicSaveStrategy.cs b/Projects/Server/Persistence/DynamicSaveStrategy.cs index 127b6cf2f..89a971eb9 100644 --- a/Projects/Server/Persistence/DynamicSaveStrategy.cs +++ b/Projects/Server/Persistence/DynamicSaveStrategy.cs @@ -1,24 +1,4 @@ -/*************************************************************************** - * DynamicSaveStrategy.cs - * ------------------- - * begin : December 16, 2010 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; @@ -137,7 +117,10 @@ namespace Server writer.QueueForIndex(item, size); if (item.Decays && item.Parent == null && item.Map != Map.Internal && - DateTime.UtcNow > item.LastMoved + item.DecayTime) _decayBag.Add(item); + DateTime.UtcNow > item.LastMoved + item.DecayTime) + { + _decayBag.Add(item); + } return writer; }, @@ -230,8 +213,12 @@ namespace Server public override void ProcessDecay() { while (_decayBag.TryTake(out var item)) + { if (item.OnDecay()) + { item.Delete(); + } + } } private void OpenFiles() @@ -287,7 +274,10 @@ namespace Server bfw.Write(types.Count); - foreach (var type in types) bfw.Write(type.FullName); + foreach (var type in types) + { + bfw.Write(type.FullName); + } bfw.Flush(); diff --git a/Projects/Server/Persistence/FileOperations.cs b/Projects/Server/Persistence/FileOperations.cs index 2ed74fe99..b42fd2151 100644 --- a/Projects/Server/Persistence/FileOperations.cs +++ b/Projects/Server/Persistence/FileOperations.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * FileOperations.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.IO; #if WINDOWS @@ -48,7 +28,9 @@ namespace Server var options = FileOptions.SequentialScan; if (Concurrency > 0) + { options |= FileOptions.Asynchronous; + } #if !WINDOWS return new FileStream(path, mode, access, share, BufferSize, options); diff --git a/Projects/Server/Persistence/FileQueue.cs b/Projects/Server/Persistence/FileQueue.cs index 9eaf86ba2..04a2cb622 100644 --- a/Projects/Server/Persistence/FileQueue.cs +++ b/Projects/Server/Persistence/FileQueue.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * FileQueue.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Buffers; using System.Collections.Generic; @@ -47,11 +27,16 @@ namespace Server public FileQueue(int concurrentWrites, FileCommitCallback callback) { - if (concurrentWrites < 1) throw new ArgumentOutOfRangeException(nameof(concurrentWrites)); + if (concurrentWrites < 1) + { + throw new ArgumentOutOfRangeException(nameof(concurrentWrites)); + } if (bufferSize < 1) #pragma warning disable CA2208 // Instantiate argument exceptions correctly + { throw new ArgumentOutOfRangeException(nameof(FileOperations.BufferSize)); + } #pragma warning restore CA2208 // Instantiate argument exceptions correctly syncRoot = new object(); @@ -79,11 +64,15 @@ namespace Server { lock (syncRoot) { - if (activeCount == 0) idle.Reset(); + if (activeCount == 0) + { + idle.Reset(); + } ++activeCount; for (var slot = 0; slot < active.Length; ++slot) + { if (active[slot] == null) { active[slot] = new Chunk(this, slot, page.buffer, 0, page.length); @@ -92,6 +81,7 @@ namespace Server return; } + } pending.Enqueue(page); } @@ -111,15 +101,15 @@ namespace Server if (pending.Count > 0 ) { idle.Reset(); } - + for ( int slot = 0; slot < active.Length && pending.Count > 0; ++slot ) { if (active[slot] == null ) { Page page = pending.Dequeue(); - + active[slot] = new Chunk( this, slot, page.buffer, 0, page.length ); - + ++activeCount; - + callback( active[slot] ); } } @@ -130,11 +120,17 @@ namespace Server private void Commit(Chunk chunk, int slot) { - if (slot < 0 || slot >= active.Length) throw new ArgumentOutOfRangeException(nameof(slot)); + if (slot < 0 || slot >= active.Length) + { + throw new ArgumentOutOfRangeException(nameof(slot)); + } lock (syncRoot) { - if (active[slot] != chunk) throw new ArgumentException("active slot is not the current chunk"); + if (active[slot] != chunk) + { + throw new ArgumentException("active slot is not the current chunk"); + } ArrayPool.Shared.Return(chunk.Buffer); @@ -153,17 +149,34 @@ namespace Server --activeCount; - if (activeCount == 0) idle.Set(); + if (activeCount == 0) + { + idle.Set(); + } } } public void Enqueue(byte[] buffer, int offset, int size) { - if (buffer == null) throw new ArgumentNullException(nameof(buffer)); + if (buffer == null) + { + throw new ArgumentNullException(nameof(buffer)); + } - if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset)); - if (size < 0) throw new ArgumentOutOfRangeException(nameof(size)); - if (buffer.Length - offset < size) throw new ArgumentOutOfRangeException(nameof(offset)); + if (offset < 0) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } + + if (size < 0) + { + throw new ArgumentOutOfRangeException(nameof(size)); + } + + if (buffer.Length - offset < size) + { + throw new ArgumentOutOfRangeException(nameof(offset)); + } Position += size; diff --git a/Projects/Server/Persistence/ParallelSaveStrategy.cs b/Projects/Server/Persistence/ParallelSaveStrategy.cs index dc4ccafcd..14d076d47 100644 --- a/Projects/Server/Persistence/ParallelSaveStrategy.cs +++ b/Projects/Server/Persistence/ParallelSaveStrategy.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * ParallelSaveStrategy.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections; using System.Collections.Generic; @@ -77,14 +57,23 @@ namespace Server consumers = new Consumer[GetThreadCount()]; - for (var i = 0; i < consumers.Length; ++i) consumers[i] = new Consumer(this, 256); + for (var i = 0; i < consumers.Length; ++i) + { + consumers[i] = new Consumer(this, 256); + } IEnumerable collection = new Producer(); foreach (var value in collection) + { while (!Enqueue(value)) + { if (!Commit()) + { Thread.Sleep(0); + } + } + } finished = true; @@ -108,7 +97,10 @@ namespace Server { var item = _decayQueue.Dequeue(); - if (item.OnDecay()) item.Delete(); + if (item.OnDecay()) + { + item.Delete(); + } } } @@ -124,7 +116,10 @@ namespace Server bfw.Write(types.Count); - foreach (var type in types) bfw.Write(type.FullName); + foreach (var type in types) + { + bfw.Write(type.FullName); + } bfw.Flush(); @@ -179,11 +174,17 @@ namespace Server var writer = entry.writer; if (value is Item item) + { Save(item, writer); + } else if (value is Mobile mob) + { Save(mob, writer); + } else if (value is BaseGuild guild) + { Save(guild, writer); + } } private void Save(Item item, BinaryMemoryWriter writer) @@ -191,7 +192,10 @@ namespace Server writer.CommitTo(itemData, itemIndex, item.TypeRef, item.Serial); if (item.Decays && item.Parent == null && item.Map != Map.Internal && - DateTime.UtcNow > item.LastMoved + item.DecayTime) _decayQueue.Enqueue(item); + DateTime.UtcNow > item.LastMoved + item.DecayTime) + { + _decayQueue.Enqueue(item); + } } private void Save(Mobile mob, BinaryMemoryWriter writer) @@ -273,11 +277,20 @@ namespace Server public IEnumerator GetEnumerator() { - foreach (var item in items) yield return item; + foreach (var item in items) + { + yield return item; + } - foreach (var mob in mobiles) yield return mob; + foreach (var mob in mobiles) + { + yield return mob; + } - foreach (var guild in guilds) yield return guild; + foreach (var guild in guilds) + { + yield return guild; + } } IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); @@ -305,7 +318,10 @@ namespace Server buffer = new ConsumableEntry[bufferSize]; - for (var i = 0; i < buffer.Length; ++i) buffer[i].writer = new BinaryMemoryWriter(); + for (var i = 0; i < buffer.Length; ++i) + { + buffer[i].writer = new BinaryMemoryWriter(); + } completionEvent = new ManualResetEvent(false); diff --git a/Projects/Server/Persistence/Persistence.cs b/Projects/Server/Persistence/Persistence.cs index 01b965750..07da3f710 100644 --- a/Projects/Server/Persistence/Persistence.cs +++ b/Projects/Server/Persistence/Persistence.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Persistence.cs * * * @@ -30,9 +30,14 @@ namespace Server file.Refresh(); if (file.Directory?.Exists == false) + { file.Directory.Create(); + } - if (!file.Exists) file.Create().Close(); + if (!file.Exists) + { + file.Create().Close(); + } file.Refresh(); @@ -72,7 +77,9 @@ namespace Server if (file.Directory?.Exists == false) { if (!ensure) + { throw new DirectoryNotFoundException(); + } file.Directory.Create(); } @@ -80,10 +87,12 @@ namespace Server if (!file.Exists) { if (!ensure) + { throw new FileNotFoundException { Source = file.FullName }; + } file.Create().Close(); } @@ -99,7 +108,10 @@ namespace Server } catch (EndOfStreamException eos) { - if (file.Length > 0) Console.WriteLine("[Persistence]: {0}", eos); + if (file.Length > 0) + { + Console.WriteLine("[Persistence]: {0}", eos); + } } catch (Exception e) { diff --git a/Projects/Server/Persistence/QueuedMemoryWriter.cs b/Projects/Server/Persistence/QueuedMemoryWriter.cs index 4e5fc35e4..5f5a77ad6 100644 --- a/Projects/Server/Persistence/QueuedMemoryWriter.cs +++ b/Projects/Server/Persistence/QueuedMemoryWriter.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * QueuedMemoryWriter.cs - * ------------------- - * begin : December 16, 2010 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.Collections.Generic; using System.IO; diff --git a/Projects/Server/Persistence/SaveStrategy.cs b/Projects/Server/Persistence/SaveStrategy.cs index bd96a51af..287f017f3 100644 --- a/Projects/Server/Persistence/SaveStrategy.cs +++ b/Projects/Server/Persistence/SaveStrategy.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * SaveStrategy.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server { public abstract class SaveStrategy @@ -31,8 +11,10 @@ namespace Server var processorCount = Core.ProcessorCount; if (processorCount > 2) + { return new DualSaveStrategy(); // return new DynamicSaveStrategy(); (4.0 or return new ParallelSaveStrategy(processorCount); (2.0) + } return new DualSaveStrategy(); } diff --git a/Projects/Server/Persistence/SequentialFileWriterStream.cs b/Projects/Server/Persistence/SequentialFileWriterStream.cs index bf847f887..2cf84499d 100644 --- a/Projects/Server/Persistence/SequentialFileWriterStream.cs +++ b/Projects/Server/Persistence/SequentialFileWriterStream.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * SequentialFileWriter.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.IO; @@ -32,7 +12,10 @@ namespace Server public SequentialFileWriterStream(string path) { - if (path == null) throw new ArgumentNullException(nameof(path)); + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } fileStream = FileOperations.OpenSequentialStream(path, FileMode.Create, FileAccess.Write, FileShare.None); diff --git a/Projects/Server/Persistence/StandardSaveStrategy.cs b/Projects/Server/Persistence/StandardSaveStrategy.cs index 2cc070f9e..5e016edf1 100644 --- a/Projects/Server/Persistence/StandardSaveStrategy.cs +++ b/Projects/Server/Persistence/StandardSaveStrategy.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * StandardSaveStrategy.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -60,7 +40,9 @@ namespace Server if (permitBackgroundWrite && UseSequentialWriters ) // If we're permitted to write in the background, but we don't anyways, then notify. + { World.NotifyDiskWriteComplete(); + } } protected void SaveMobiles() @@ -90,7 +72,9 @@ namespace Server tdb.Write(World.m_MobileTypes.Count); for (var i = 0; i < World.m_MobileTypes.Count; ++i) + { tdb.Write(World.m_MobileTypes[i].FullName); + } tdb.Close(); } @@ -151,7 +135,9 @@ namespace Server tdb.Write(World.m_ItemTypes.Count); for (var i = 0; i < World.m_ItemTypes.Count; ++i) + { tdb.Write(World.m_ItemTypes[i].FullName); + } tdb.Close(); } @@ -243,7 +229,9 @@ namespace Server var item = _decayQueue.Dequeue(); if (item.OnDecay()) + { item.Delete(); + } } } } diff --git a/Projects/Server/Poison.cs b/Projects/Server/Poison.cs index 028742004..24ab4e6f2 100644 --- a/Projects/Server/Poison.cs +++ b/Projects/Server/Poison.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Poison.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; @@ -51,9 +31,14 @@ namespace Server for (var i = 0; i < Poisons.Count; i++) { if (reg.Level == Poisons[i].Level) + { throw new Exception("A poison with that level already exists."); + } + if (regName == Poisons[i].Name.ToLower()) + { throw new Exception("A poison with that name already exists."); + } } Poisons.Add(reg); @@ -69,7 +54,9 @@ namespace Server var p = Poisons[i]; if (p.Level == level) + { return p; + } } return null; @@ -82,7 +69,9 @@ namespace Server var p = Poisons[i]; if (Utility.InsensitiveCompare(p.Name, name) == 0) + { return p; + } } return null; diff --git a/Projects/Server/Prompt.cs b/Projects/Server/Prompt.cs index 5c26ca299..eb91edf31 100644 --- a/Projects/Server/Prompt.cs +++ b/Projects/Server/Prompt.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Prompt.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Prompts { public abstract class Prompt diff --git a/Projects/Server/QuestArrow.cs b/Projects/Server/QuestArrow.cs index 35967ca33..5dfee5fe7 100644 --- a/Projects/Server/QuestArrow.cs +++ b/Projects/Server/QuestArrow.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * QuestArrow.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server @@ -50,17 +30,25 @@ namespace Server public void Update(int x, int y) { if (!Running) + { return; + } var ns = Mobile.NetState; if (ns == null) + { return; + } if (ns.HighSeas) + { ns.Send(new SetArrowHS(x, y, Target.Serial)); + } else + { ns.Send(new SetArrow(x, y)); + } } public void Stop() @@ -71,7 +59,9 @@ namespace Server public void Stop(int x, int y) { if (!Running) + { return; + } Mobile.ClearQuestArrow(); @@ -80,9 +70,13 @@ namespace Server if (ns != null) { if (ns.HighSeas) + { ns.Send(new CancelArrowHS(x, y, Target.Serial)); + } else + { ns.Send(new CancelArrow()); + } } Running = false; diff --git a/Projects/Server/Race.cs b/Projects/Server/Race.cs index 9cd6c0015..5c60994b4 100644 --- a/Projects/Server/Race.cs +++ b/Projects/Server/Race.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Race.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; @@ -93,12 +73,18 @@ namespace Server CheckNamesAndValues(); for (var i = 0; i < m_RaceNames.Length; ++i) + { if (Insensitive.Equals(m_RaceNames[i], value)) + { return m_RaceValues[i]; + } + } if (int.TryParse(value, out var index) && index >= 0 && index < Races.Length && Races[index] != null) + { return Races[index]; + } throw new ArgumentException("Invalid race name"); } @@ -106,7 +92,9 @@ namespace Server private static void CheckNamesAndValues() { if (m_RaceNames?.Length == AllRaces.Count) + { return; + } m_RaceNames = new string[AllRaces.Count]; m_RaceValues = new Race[AllRaces.Count]; diff --git a/Projects/Server/Random/BaseRandomSource.cs b/Projects/Server/Random/BaseRandomSource.cs index 1d1adea02..1c1dbaa78 100644 --- a/Projects/Server/Random/BaseRandomSource.cs +++ b/Projects/Server/Random/BaseRandomSource.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: BaseRandomSource.cs * * * @@ -42,8 +42,15 @@ namespace Server.Random [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Next(int count) { - if (count == 0) throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); - if (count == 1 || count == -1) return 0; + if (count == 0) + { + throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); + } + + if (count == 1 || count == -1) + { + return 0; + } var negative = count < 0; @@ -66,8 +73,15 @@ namespace Server.Random [MethodImpl(MethodImplOptions.AggressiveInlining)] public uint Next(uint count) { - if (count == 0) throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); - if (count == 1) return 0; + if (count == 0) + { + throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); + } + + if (count == 1) + { + return 0; + } var bits = Log2(count); @@ -86,8 +100,15 @@ namespace Server.Random [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Next(long count) { - if (count == 0) throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); - if (count == 1 || count == -1) return 0; + if (count == 0) + { + throw new ArgumentOutOfRangeException(nameof(count), count, "count must not be 0"); + } + + if (count == 1 || count == -1) + { + return 0; + } var negative = count < 0; @@ -143,7 +164,9 @@ namespace Server.Random exponent -= 64; if (exponent < -1074) + { return 0; + } } shift = BitOperations.LeadingZeroCount(significand); diff --git a/Projects/Server/Random/IRandomSource.cs b/Projects/Server/Random/IRandomSource.cs index e73acee61..3d590b79e 100644 --- a/Projects/Server/Random/IRandomSource.cs +++ b/Projects/Server/Random/IRandomSource.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IRandomSource.cs * * * diff --git a/Projects/Server/Random/RandomSources.cs b/Projects/Server/Random/RandomSources.cs index 562f1fdff..d99add499 100644 --- a/Projects/Server/Random/RandomSources.cs +++ b/Projects/Server/Random/RandomSources.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: RandomSources.cs * * * diff --git a/Projects/Server/Random/SecureRandom.cs b/Projects/Server/Random/SecureRandom.cs index 2eb403305..284502d1b 100644 --- a/Projects/Server/Random/SecureRandom.cs +++ b/Projects/Server/Random/SecureRandom.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SecureRandom.cs * * * diff --git a/Projects/Server/Random/Xoshiro256PlusPlus.cs b/Projects/Server/Random/Xoshiro256PlusPlus.cs index 928126713..5f0f0eb9c 100644 --- a/Projects/Server/Random/Xoshiro256PlusPlus.cs +++ b/Projects/Server/Random/Xoshiro256PlusPlus.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Xoshiro256PlusPlus.cs * * * @@ -75,7 +75,10 @@ namespace Server.Random [MethodImpl(MethodImplOptions.AggressiveInlining)] public override unsafe void NextBytes(Span b) { - if (b.Length == 0) return; + if (b.Length == 0) + { + return; + } var s0 = _s0; var s1 = _s1; @@ -150,6 +153,7 @@ namespace Server.Random ulong s3 = 0; for (var i = 0; i < jumps.Length; i++) + { for (var b = 0; b < 64; b++) { if ((jumps[i] & (1ul << b)) != 0) @@ -162,6 +166,7 @@ namespace Server.Random NextULong(); } + } _s0 = s0; _s1 = s1; @@ -202,7 +207,10 @@ namespace Server.Random [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FillArray(ulong[] arr) { - for (var i = 0; i < arr.Length; i++) arr[i] = Next(); + for (var i = 0; i < arr.Length; i++) + { + arr[i] = Next(); + } } } } diff --git a/Projects/Server/Regions/Region.cs b/Projects/Server/Regions/Region.cs index 4b9ade479..163aba550 100644 --- a/Projects/Server/Regions/Region.cs +++ b/Projects/Server/Regions/Region.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Region.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Text.Json; @@ -174,7 +154,9 @@ namespace Server : Array.Empty(); if (Area.Length == 0) + { Console.WriteLine("Empty area for region '{0}'", this); + } if (json.GetProperty("go", options, out Point3D go)) { @@ -232,13 +214,17 @@ namespace Server public int CompareTo(Region reg) { if (reg == null) + { return 1; + } // Dynamic regions go first if (Dynamic) { if (!reg.Dynamic) + { return -1; + } } else if (reg.Dynamic) { @@ -249,7 +235,9 @@ namespace Server var regPriority = reg.Priority; if (thisPriority != regPriority) + { return regPriority - thisPriority; + } return reg.ChildLevel - ChildLevel; } @@ -258,20 +246,28 @@ namespace Server public static Region Find(string name, Map map, bool insensitive = false) { if (insensitive) + { name = name.ToLower(); + } for (var i = 0; i < Regions.Count; i++) { var region = Regions[i]; if (region.Map != map) + { continue; + } var rName = region.Name; if (insensitive) + { rName = rName.ToLower(); + } if (rName == name) + { return region; + } } return null; @@ -280,7 +276,9 @@ namespace Server public static Region Find(Point3D p, Map map) { if (map == null) + { return Map.Internal.DefaultRegion; + } var sector = map.GetSector(p); var list = sector.RegionRects; @@ -290,7 +288,9 @@ namespace Server var regRect = list[i]; if (regRect.Contains(p)) + { return regRect.Region; + } } return map.DefaultRegion; @@ -303,7 +303,10 @@ namespace Server { var ret = new Rectangle3D[rects.Length]; - for (var i = 0; i < ret.Length; i++) ret[i] = ConvertTo3D(rects[i]); + for (var i = 0; i < ret.Length; i++) + { + ret[i] = ConvertTo3D(rects[i]); + } return ret; } @@ -311,7 +314,9 @@ namespace Server public void Register() { if (Registered) + { return; + } OnRegister(); @@ -340,6 +345,7 @@ namespace Server var endSector = Map.GetSector(end); for (var x = startSector.X; x <= endSector.X; x++) + { for (var y = startSector.Y; y <= endSector.Y; y++) { var sector = Map.GetRealSector(x, y); @@ -347,8 +353,11 @@ namespace Server sector.OnEnter(this, rect); if (!sectors.Contains(sector)) + { sectors.Add(sector); + } } + } } Sectors = sectors.ToArray(); @@ -357,14 +366,18 @@ namespace Server public void Unregister() { if (!Registered) + { return; + } OnUnregister(); Registered = false; if (Children.Count > 0) + { Console.WriteLine("Warning: Unregistering region '{0}' with children", this); + } if (Parent != null) { @@ -377,8 +390,12 @@ namespace Server Map.UnregisterRegion(this); if (Sectors != null) + { for (var i = 0; i < Sectors.Length; i++) + { Sectors[i].OnLeave(this); + } + } Sectors = null; } @@ -390,7 +407,9 @@ namespace Server var rect = Area[i]; if (rect.Contains(p)) + { return true; + } } return false; @@ -400,14 +419,18 @@ namespace Server public bool IsChildOf(Region region) { if (region == null) + { return false; + } var p = Parent; while (p != null) { if (p == region) + { return true; + } p = p.Parent; } @@ -423,7 +446,9 @@ namespace Server do { if (r is T tr) + { return tr; + } r = r.Parent; } while (r != null); @@ -434,14 +459,18 @@ namespace Server public Region GetRegion(Type regionType) { if (regionType == null) + { return null; + } var r = this; do { if (regionType.IsInstanceOfType(r)) + { return r; + } r = r.Parent; } while (r != null); @@ -452,14 +481,18 @@ namespace Server public Region GetRegion(string regionName) { if (regionName == null) + { return null; + } var r = this; do { if (r.Name == regionName) + { return r; + } r = r.Parent; } while (r != null); @@ -485,8 +518,12 @@ namespace Server var sector = Sectors[i]; foreach (var player in sector.Players) + { if (player.Region.IsPartOf(this)) + { list.Add(player); + } + } } return list; @@ -501,8 +538,12 @@ namespace Server var sector = Sectors[i]; foreach (var player in sector.Players) + { if (player.Region.IsPartOf(this)) + { count++; + } + } } return count; @@ -517,8 +558,12 @@ namespace Server var sector = Sectors[i]; foreach (var mobile in sector.Mobiles) + { if (mobile.Region.IsPartOf(this)) + { list.Add(mobile); + } + } } return list; @@ -533,8 +578,12 @@ namespace Server var sector = Sectors[i]; foreach (var mobile in sector.Mobiles) + { if (mobile.Region.IsPartOf(this)) + { count++; + } + } } return count; @@ -618,9 +667,13 @@ namespace Server public virtual void OnCriminalAction(Mobile m, bool message) { if (Parent != null) + { Parent.OnCriminalAction(m, message); + } else if (message) + { m.SendLocalizedMessage(1005040); // You've committed a criminal act!! + } } public virtual bool AllowBeneficial(Mobile from, Mobile target) => @@ -683,7 +736,9 @@ namespace Server public virtual TimeSpan GetLogoutDelay(Mobile m) { if (Parent != null) + { return Parent.GetLogoutDelay(m); + } return m.AccessLevel > AccessLevel.Player ? StaffLogoutDelay : DefaultLogoutDelay; } @@ -696,10 +751,14 @@ namespace Server while (oldRegion != newRegion) { if (!newRegion.OnMoveInto(m, d, newLocation, oldLocation)) + { return false; + } if (newRegion.Parent == null) + { return true; + } newRegion = newRegion.Parent; } @@ -713,7 +772,10 @@ namespace Server { m.CheckLightLevels(false); - if (oldRegion == null || oldRegion.Music != newRegion.Music) m.Send(PlayMusic.GetInstance(newRegion.Music)); + if (oldRegion == null || oldRegion.Music != newRegion.Music) + { + m.Send(PlayMusic.GetInstance(newRegion.Music)); + } } var oldR = oldRegion; diff --git a/Projects/Server/Regions/RegionLoader.cs b/Projects/Server/Regions/RegionLoader.cs index c331ec96a..e6266f5c5 100644 --- a/Projects/Server/Regions/RegionLoader.cs +++ b/Projects/Server/Regions/RegionLoader.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: RegionLoader.cs * * * diff --git a/Projects/Server/Sector.cs b/Projects/Server/Sector.cs index bcd90f64a..63dee12b7 100644 --- a/Projects/Server/Sector.cs +++ b/Projects/Server/Sector.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Sector.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using Server.Items; @@ -101,7 +81,10 @@ namespace Server { list.Remove(value); - if (list.Count == 0) list = null; + if (list.Count == 0) + { + list = null; + } } } @@ -112,9 +95,13 @@ namespace Server var index = list?.IndexOf(oldValue) ?? -1; if (index >= 0) + { list[index] = newValue; + } else + { Add(ref list, newValue); + } } else if (oldValue != null) { @@ -145,11 +132,17 @@ namespace Server { Add(ref m_Mobiles, mob); - if (mob.NetState != null) Add(ref m_Clients, mob.NetState); + if (mob.NetState != null) + { + Add(ref m_Clients, mob.NetState); + } if (mob.Player) { - if (m_Players == null) Owner.ActivateSectors(X, Y); + if (m_Players == null) + { + Owner.ActivateSectors(X, Y); + } Add(ref m_Players, mob); } @@ -159,13 +152,19 @@ namespace Server { Remove(ref m_Mobiles, mob); - if (mob.NetState != null) Remove(ref m_Clients, mob.NetState); + if (mob.NetState != null) + { + Remove(ref m_Clients, mob.NetState); + } if (mob.Player && m_Players != null) { Remove(ref m_Players, mob); - if (m_Players == null) Owner.DeactivateSectors(X, Y); + if (m_Players == null) + { + Owner.DeactivateSectors(X, Y); + } } } @@ -186,10 +185,16 @@ namespace Server { var regRect = m_RegionRects[i]; - if (regRect.Region == region) m_RegionRects.RemoveAt(i); + if (regRect.Region == region) + { + m_RegionRects.RemoveAt(i); + } } - if (m_RegionRects.Count == 0) m_RegionRects = null; + if (m_RegionRects.Count == 0) + { + m_RegionRects = null; + } } UpdateMobileRegions(); @@ -201,7 +206,10 @@ namespace Server { var sandbox = new List(m_Mobiles); - foreach (var mob in sandbox) mob.UpdateRegion(); + foreach (var mob in sandbox) + { + mob.UpdateRegion(); + } } } @@ -220,12 +228,20 @@ namespace Server if (!Active && Owner != Map.Internal) { if (m_Items != null) + { foreach (var item in m_Items) + { item.OnSectorActivate(); + } + } if (m_Mobiles != null) + { foreach (var mob in m_Mobiles) + { mob.OnSectorActivate(); + } + } m_Active = true; } @@ -236,12 +252,20 @@ namespace Server if (Active) { if (m_Items != null) + { foreach (var item in m_Items) + { item.OnSectorDeactivate(); + } + } if (m_Mobiles != null) + { foreach (var mob in m_Mobiles) + { mob.OnSectorDeactivate(); + } + } m_Active = false; } diff --git a/Projects/Server/SecureTrade.cs b/Projects/Server/SecureTrade.cs index 5c754b45a..c82101e92 100644 --- a/Projects/Server/SecureTrade.cs +++ b/Projects/Server/SecureTrade.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * SecureTrade.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using Server.Accounting; using Server.Items; @@ -44,49 +24,68 @@ namespace Server from.Send(new UpdateSecureTrade(From.Container, false, false)); if (from6017) - from.Send(new SecureTradeEquip6017(To.Container, to)); + { + @from.Send(new SecureTradeEquip6017(To.Container, to)); + } else - from.Send(new SecureTradeEquip(To.Container, to)); + { + @from.Send(new SecureTradeEquip(To.Container, to)); + } from.Send(new UpdateSecureTrade(From.Container, false, false)); if (from6017) - from.Send(new SecureTradeEquip6017(From.Container, from)); + { + @from.Send(new SecureTradeEquip6017(From.Container, @from)); + } else - from.Send(new SecureTradeEquip(From.Container, from)); + { + @from.Send(new SecureTradeEquip(From.Container, @from)); + } from.Send(new DisplaySecureTrade(to, From.Container, To.Container, to.Name)); from.Send(new UpdateSecureTrade(From.Container, false, false)); if (from.Account != null && from704565) - from.Send( + { + @from.Send( new UpdateSecureTrade( From.Container, TradeFlag.UpdateLedger, - from.Account.TotalGold, - from.Account.TotalPlat + @from.Account.TotalGold, + @from.Account.TotalPlat ) ); + } to.Send(new MobileStatus(to, from)); to.Send(new UpdateSecureTrade(To.Container, false, false)); if (to6017) - to.Send(new SecureTradeEquip6017(From.Container, from)); + { + to.Send(new SecureTradeEquip6017(From.Container, @from)); + } else - to.Send(new SecureTradeEquip(From.Container, from)); + { + to.Send(new SecureTradeEquip(From.Container, @from)); + } to.Send(new UpdateSecureTrade(To.Container, false, false)); if (to6017) + { to.Send(new SecureTradeEquip6017(To.Container, to)); + } else + { to.Send(new SecureTradeEquip(To.Container, to)); + } to.Send(new DisplaySecureTrade(from, To.Container, From.Container, from.Name)); to.Send(new UpdateSecureTrade(To.Container, false, false)); if (to.Account != null && to704565) + { to.Send( new UpdateSecureTrade( To.Container, @@ -95,6 +94,7 @@ namespace Server to.Account.TotalPlat ) ); + } } public SecureTradeInfo From { get; } @@ -105,42 +105,64 @@ namespace Server public void Cancel() { - if (!Valid) return; + if (!Valid) + { + return; + } var list = From.Container.Items; for (var i = list.Count - 1; i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == From.VirtualCheck) continue; + if (item == From.VirtualCheck) + { + continue; + } item.OnSecureTrade(From.Mobile, To.Mobile, From.Mobile, false); - if (!item.Deleted) From.Mobile.AddToBackpack(item); + if (!item.Deleted) + { + From.Mobile.AddToBackpack(item); + } } + } list = To.Container.Items; for (var i = list.Count - 1; i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == To.VirtualCheck) continue; + if (item == To.VirtualCheck) + { + continue; + } item.OnSecureTrade(To.Mobile, From.Mobile, To.Mobile, false); - if (!item.Deleted) To.Mobile.AddToBackpack(item); + if (!item.Deleted) + { + To.Mobile.AddToBackpack(item); + } } + } Close(); } public void Close() { - if (!Valid) return; + if (!Valid) + { + return; + } From.Mobile.Send(new CloseSecureTrade(From.Container)); To.Mobile.Send(new CloseSecureTrade(To.Container)); @@ -180,12 +202,17 @@ namespace Server } if (right.Mobile.NetState?.NewSecureTrading == true) + { right.Mobile.Send(new UpdateSecureTrade(right.Container, TradeFlag.UpdateGold, left.Gold, left.Plat)); + } } public void Update() { - if (!Valid) return; + if (!Valid) + { + return; + } if (!From.IsDisposed && From.Accepted && !To.IsDisposed && To.Accepted) { @@ -194,26 +221,42 @@ namespace Server var allowed = true; for (var i = list.Count - 1; allowed && i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == From.VirtualCheck) continue; + if (item == From.VirtualCheck) + { + continue; + } - if (!item.AllowSecureTrade(From.Mobile, To.Mobile, To.Mobile, true)) allowed = false; + if (!item.AllowSecureTrade(From.Mobile, To.Mobile, To.Mobile, true)) + { + allowed = false; + } } + } list = To.Container.Items; for (var i = list.Count - 1; allowed && i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == To.VirtualCheck) continue; + if (item == To.VirtualCheck) + { + continue; + } - if (!item.AllowSecureTrade(To.Mobile, From.Mobile, From.Mobile, true)) allowed = false; + if (!item.AllowSecureTrade(To.Mobile, From.Mobile, From.Mobile, true)) + { + allowed = false; + } } + } if (AccountGold.Enabled) { @@ -254,35 +297,53 @@ namespace Server } if (AccountGold.Enabled && From.Mobile.Account != null && To.Mobile.Account != null) + { HandleAccountGoldTrade(); + } list = From.Container.Items; for (var i = list.Count - 1; i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == From.VirtualCheck) continue; + if (item == From.VirtualCheck) + { + continue; + } item.OnSecureTrade(From.Mobile, To.Mobile, To.Mobile, true); - if (!item.Deleted) To.Mobile.AddToBackpack(item); + if (!item.Deleted) + { + To.Mobile.AddToBackpack(item); + } } + } list = To.Container.Items; for (var i = list.Count - 1; i >= 0; --i) + { if (i < list.Count) { var item = list[i]; - if (item == To.VirtualCheck) continue; + if (item == To.VirtualCheck) + { + continue; + } item.OnSecureTrade(To.Mobile, From.Mobile, From.Mobile, true); - if (!item.Deleted) From.Mobile.AddToBackpack(item); + if (!item.Deleted) + { + From.Mobile.AddToBackpack(item); + } } + } Close(); } @@ -302,28 +363,40 @@ namespace Server { fromPlatSend = From.Plat; - if (To.Mobile.Account.DepositPlat(From.Plat)) toPlatRecv = fromPlatSend; + if (To.Mobile.Account.DepositPlat(From.Plat)) + { + toPlatRecv = fromPlatSend; + } } if ((From.Gold > 0) & From.Mobile.Account.WithdrawGold(From.Gold)) { fromGoldSend = From.Gold; - if (To.Mobile.Account.DepositGold(From.Gold)) toGoldRecv = fromGoldSend; + if (To.Mobile.Account.DepositGold(From.Gold)) + { + toGoldRecv = fromGoldSend; + } } if ((To.Plat > 0) & To.Mobile.Account.WithdrawPlat(To.Plat)) { toPlatSend = To.Plat; - if (From.Mobile.Account.DepositPlat(To.Plat)) fromPlatRecv = toPlatSend; + if (From.Mobile.Account.DepositPlat(To.Plat)) + { + fromPlatRecv = toPlatSend; + } } if ((To.Gold > 0) & To.Mobile.Account.WithdrawGold(To.Gold)) { toGoldSend = To.Gold; - if (From.Mobile.Account.DepositGold(To.Gold)) fromGoldRecv = toGoldSend; + if (From.Mobile.Account.DepositGold(To.Gold)) + { + fromGoldRecv = toGoldSend; + } } HandleAccountGoldTrade(From.Mobile, To.Mobile, fromPlatSend, fromGoldSend, fromPlatRecv, fromGoldRecv); @@ -342,29 +415,43 @@ namespace Server if (platSend > 0 || goldSend > 0) { if (platSend > 0 && goldSend > 0) + { left.SendMessage( "You traded {0:#,0} platinum and {1:#,0} gold to {2}.", platSend, goldSend, right.RawName ); + } else if (platSend > 0) + { left.SendMessage("You traded {0:#,0} platinum to {1}.", platSend, right.RawName); - else if (goldSend > 0) left.SendMessage("You traded {0:#,0} gold to {1}.", goldSend, right.RawName); + } + else if (goldSend > 0) + { + left.SendMessage("You traded {0:#,0} gold to {1}.", goldSend, right.RawName); + } } if (platRecv > 0 || goldRecv > 0) { if (platRecv > 0 && goldRecv > 0) + { left.SendMessage( "You received {0:#,0} platinum and {1:#,0} gold from {2}.", platRecv, goldRecv, right.RawName ); + } else if (platRecv > 0) + { left.SendMessage("You received {0:#,0} platinum from {1}.", platRecv, right.RawName); - else if (goldRecv > 0) left.SendMessage("You received {0:#,0} gold from {1}.", goldRecv, right.RawName); + } + else if (goldRecv > 0) + { + left.SendMessage("You received {0:#,0} gold from {1}.", goldRecv, right.RawName); + } } } } diff --git a/Projects/Server/Serial.cs b/Projects/Server/Serial.cs index 567020b07..fa93c2bc8 100644 --- a/Projects/Server/Serial.cs +++ b/Projects/Server/Serial.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Serial.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server @@ -73,9 +53,15 @@ namespace Server public override bool Equals(object obj) { - if (obj is Serial serial) return this == serial; + if (obj is Serial serial) + { + return this == serial; + } - if (obj is uint u) return Value == u; + if (obj is uint u) + { + return Value == u; + } return false; } diff --git a/Projects/Server/Serialization/AsyncWriter.cs b/Projects/Server/Serialization/AsyncWriter.cs index f82c1f3c2..b7550f845 100644 --- a/Projects/Server/Serialization/AsyncWriter.cs +++ b/Projects/Server/Serialization/AsyncWriter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AsyncWriter.cs * * * @@ -62,7 +62,9 @@ namespace Server set { if (m_Mem.Length > 0) + { Enqueue(m_Mem); + } m_Mem = value; m_Bin = new BinaryWriter(m_Mem, Utility.UTF8WithEncoding); @@ -277,49 +279,73 @@ namespace Server public void Write(Map value) { if (value != null) + { Write((byte)value.MapIndex); + } else + { Write((byte)0xFF); + } } public void Write(Race value) { if (value != null) + { Write((byte)value.RaceIndex); + } else + { Write((byte)0xFF); + } } public void WriteEntity(IEntity value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(Item value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(Mobile value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(BaseGuild value) { if (value == null) + { Write(0); + } else + { Write(value.Serial); + } } public void WriteItem(T value) where T : Item @@ -355,16 +381,26 @@ namespace Server public void WriteItemList(List list, bool tidy) where T : Item { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -374,11 +410,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void WriteItemSet(HashSet set) where T : Item @@ -388,11 +430,17 @@ namespace Server public void WriteItemSet(HashSet set, bool tidy) where T : Item { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void Write(List list) @@ -403,16 +451,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteMobileList(List list) where T : Mobile @@ -423,16 +481,26 @@ namespace Server public void WriteMobileList(List list, bool tidy) where T : Mobile { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -442,11 +510,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(mobile => mobile.Deleted); + if (tidy) + { + set.RemoveWhere(mobile => mobile.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void WriteMobileSet(HashSet set) where T : Mobile @@ -456,11 +530,17 @@ namespace Server public void WriteMobileSet(HashSet set, bool tidy) where T : Mobile { - if (tidy) set.RemoveWhere(mob => mob.Deleted); + if (tidy) + { + set.RemoveWhere(mob => mob.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void Write(List list) @@ -471,16 +551,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteGuildList(List list) where T : BaseGuild @@ -491,16 +581,26 @@ namespace Server public void WriteGuildList(List list, bool tidy) where T : BaseGuild { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -510,11 +610,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } public void WriteGuildSet(HashSet set) where T : BaseGuild @@ -524,11 +630,17 @@ namespace Server public void WriteGuildSet(HashSet set, bool tidy) where T : BaseGuild { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } private void Enqueue(MemoryStream mem) @@ -578,20 +690,28 @@ namespace Server lock (m_Owner.m_WriteQueue) { if ((lastCount = m_Owner.m_WriteQueue.Count) > 0) + { mem = m_Owner.m_WriteQueue.Dequeue(); + } } if (mem?.Length > 0) + { mem.WriteTo(m_Owner.m_File); + } } while (lastCount > 1); if (m_Owner.m_Closed) + { m_Owner.m_File.Close(); + } ThreadCount--; if (ThreadCount <= 0) + { World.NotifyDiskWriteComplete(); + } } } } diff --git a/Projects/Server/Serialization/BinaryFileReader.cs b/Projects/Server/Serialization/BinaryFileReader.cs index 3da6acdc8..7edd1b5f3 100644 --- a/Projects/Server/Serialization/BinaryFileReader.cs +++ b/Projects/Server/Serialization/BinaryFileReader.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: BinaryFileReader.cs * * * @@ -37,9 +37,14 @@ namespace Server var now = DateTime.UtcNow.Ticks; if (ticks > 0 && ticks + now < 0) + { return DateTime.MaxValue; + } + if (ticks < 0 && ticks + now < 0) + { return DateTime.MinValue; + } try { @@ -145,8 +150,12 @@ namespace Server var list = new List(count); for (var i = 0; i < count; ++i) + { if (ReadItem() is T item) + { list.Add(item); + } + } return list; } @@ -165,8 +174,12 @@ namespace Server var set = new HashSet(); for (var i = 0; i < count; ++i) + { if (ReadItem() is T item) + { set.Add(item); + } + } return set; } @@ -185,8 +198,12 @@ namespace Server var list = new List(count); for (var i = 0; i < count; ++i) + { if (ReadMobile() is T m) + { list.Add(m); + } + } return list; } @@ -205,8 +222,12 @@ namespace Server var set = new HashSet(); for (var i = 0; i < count; ++i) + { if (ReadMobile() is T item) + { set.Add(item); + } + } return set; } @@ -225,8 +246,12 @@ namespace Server var list = new List(count); for (var i = 0; i < count; ++i) + { if (ReadGuild() is T g) + { list.Add(g); + } + } return list; } @@ -245,8 +270,12 @@ namespace Server var set = new HashSet(); for (var i = 0; i < count; ++i) + { if (ReadGuild() is T item) + { set.Add(item); + } + } return set; } diff --git a/Projects/Server/Serialization/BinaryFileWriter.cs b/Projects/Server/Serialization/BinaryFileWriter.cs index 77121335d..c6ed00878 100644 --- a/Projects/Server/Serialization/BinaryFileWriter.cs +++ b/Projects/Server/Serialization/BinaryFileWriter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: BinaryFileWriter.cs * * * @@ -64,7 +64,9 @@ namespace Server get { if (m_Index > 0) + { Flush(); + } return m_File; } @@ -75,7 +77,9 @@ namespace Server public void Close() { if (m_Index > 0) + { Flush(); + } m_File.Close(); } @@ -87,14 +91,18 @@ namespace Server while (v >= 0x80) { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = (byte)(v | 0x80); v >>= 7; } if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = (byte)v; } @@ -106,14 +114,18 @@ namespace Server if (value == null) { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = 0; } else { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = 1; @@ -171,13 +183,17 @@ namespace Server var bits = decimal.GetBits(value); for (var i = 0; i < bits.Length; ++i) + { Write(bits[i]); + } } public void Write(long value) { if (m_Index + 8 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -193,7 +209,9 @@ namespace Server public void Write(ulong value) { if (m_Index + 8 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -209,7 +227,9 @@ namespace Server public void Write(int value) { if (m_Index + 4 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -221,7 +241,9 @@ namespace Server public void Write(uint value) { if (m_Index + 4 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -233,7 +255,9 @@ namespace Server public void Write(short value) { if (m_Index + 2 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -243,7 +267,9 @@ namespace Server public void Write(ushort value) { if (m_Index + 2 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index] = (byte)value; m_Buffer[m_Index + 1] = (byte)(value >> 8); @@ -253,7 +279,9 @@ namespace Server public unsafe void Write(double value) { if (m_Index + 8 > m_Buffer.Length) + { Flush(); + } fixed (byte* pBuffer = m_Buffer) { @@ -266,7 +294,9 @@ namespace Server public unsafe void Write(float value) { if (m_Index + 4 > m_Buffer.Length) + { Flush(); + } fixed (byte* pBuffer = m_Buffer) { @@ -279,7 +309,9 @@ namespace Server public void Write(char value) { if (m_Index + 8 > m_Buffer.Length) + { Flush(); + } m_SingleCharBuffer[0] = value; @@ -290,7 +322,9 @@ namespace Server public void Write(byte value) { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = value; } @@ -303,7 +337,9 @@ namespace Server public void Write(byte[] value, int length) { if (m_Index + length > m_Buffer.Length) + { Flush(); + } Buffer.BlockCopy(value, 0, m_Buffer, m_Index, length); m_Index += length; @@ -312,7 +348,9 @@ namespace Server public void Write(sbyte value) { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = (byte)value; } @@ -320,7 +358,9 @@ namespace Server public void Write(bool value) { if (m_Index + 1 > m_Buffer.Length) + { Flush(); + } m_Buffer[m_Index++] = (byte)(value ? 1 : 0); } @@ -353,49 +393,73 @@ namespace Server public void Write(Map value) { if (value != null) + { Write((byte)value.MapIndex); + } else + { Write((byte)0xFF); + } } public void Write(Race value) { if (value != null) + { Write((byte)value.RaceIndex); + } else + { Write((byte)0xFF); + } } public void WriteEntity(IEntity value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(Item value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(Mobile value) { if (value?.Deleted != false) + { Write(Serial.MinusOne); + } else + { Write(value.Serial); + } } public void Write(BaseGuild value) { if (value == null) + { Write(0); + } else + { Write(value.Serial); + } } public void WriteItem(T value) where T : Item @@ -431,16 +495,26 @@ namespace Server public void WriteItemList(List list, bool tidy) where T : Item { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i]?.Deleted != false) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -450,11 +524,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void WriteItemSet(HashSet set) where T : Item @@ -464,11 +544,17 @@ namespace Server public void WriteItemSet(HashSet set, bool tidy) where T : Item { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void Write(List list) @@ -479,16 +565,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteMobileList(List list) where T : Mobile @@ -499,16 +595,26 @@ namespace Server public void WriteMobileList(List list, bool tidy) where T : Mobile { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -518,11 +624,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(mobile => mobile.Deleted); + if (tidy) + { + set.RemoveWhere(mobile => mobile.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void WriteMobileSet(HashSet set) where T : Mobile @@ -532,11 +644,17 @@ namespace Server public void WriteMobileSet(HashSet set, bool tidy) where T : Mobile { - if (tidy) set.RemoveWhere(mob => mob.Deleted); + if (tidy) + { + set.RemoveWhere(mob => mob.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void Write(List list) @@ -547,16 +665,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteGuildList(List list) where T : BaseGuild @@ -567,16 +695,26 @@ namespace Server public void WriteGuildList(List list, bool tidy) where T : BaseGuild { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -586,11 +724,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } public void WriteGuildSet(HashSet set) where T : BaseGuild @@ -600,11 +744,17 @@ namespace Server public void WriteGuildSet(HashSet set, bool tidy) where T : BaseGuild { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } public void Flush() @@ -641,7 +791,9 @@ namespace Server var byteLength = m_Encoding.GetBytes(value, current, charCount, m_CharacterBuffer, 0); if (m_Index + byteLength > m_Buffer.Length) + { Flush(); + } Buffer.BlockCopy(m_CharacterBuffer, 0, m_Buffer, m_Index, byteLength); m_Index += byteLength; @@ -655,7 +807,9 @@ namespace Server var byteLength = m_Encoding.GetBytes(value, 0, value.Length, m_CharacterBuffer, 0); if (m_Index + byteLength > m_Buffer.Length) + { Flush(); + } Buffer.BlockCopy(m_CharacterBuffer, 0, m_Buffer, m_Index, byteLength); m_Index += byteLength; diff --git a/Projects/Server/Serialization/BufferedFileWriter.cs b/Projects/Server/Serialization/BufferedFileWriter.cs index 081da7a09..2f25bf386 100644 --- a/Projects/Server/Serialization/BufferedFileWriter.cs +++ b/Projects/Server/Serialization/BufferedFileWriter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: BufferedFileWriter.cs * * * @@ -59,14 +59,18 @@ namespace Server while (v >= 0x80) { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = (byte)(v | 0x80); v >>= 7; } if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = (byte)v; } @@ -78,14 +82,18 @@ namespace Server if (value == null) { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = 0; } else { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = 1; @@ -143,13 +151,17 @@ namespace Server var bits = decimal.GetBits(value); for (var i = 0; i < bits.Length; ++i) + { Write(bits[i]); + } } public void Write(long value) { if (m_Index + 8 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -165,7 +177,9 @@ namespace Server public void Write(ulong value) { if (m_Index + 8 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -181,7 +195,9 @@ namespace Server public void Write(int value) { if (m_Index + 4 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -193,7 +209,9 @@ namespace Server public void Write(uint value) { if (m_Index + 4 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -205,7 +223,9 @@ namespace Server public void Write(short value) { if (m_Index + 2 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -215,7 +235,9 @@ namespace Server public void Write(ushort value) { if (m_Index + 2 > Data.Length) + { Expand(); + } Data[m_Index] = (byte)value; Data[m_Index + 1] = (byte)(value >> 8); @@ -225,7 +247,9 @@ namespace Server public unsafe void Write(double value) { if (m_Index + 8 > Data.Length) + { Expand(); + } fixed (byte* pBuffer = Data) { @@ -238,7 +262,9 @@ namespace Server public unsafe void Write(float value) { if (m_Index + 4 > Data.Length) + { Expand(); + } fixed (byte* pBuffer = Data) { @@ -251,7 +277,9 @@ namespace Server public void Write(char value) { if (m_Index + 8 > Data.Length) + { Expand(); + } m_SingleCharBuffer[0] = value; @@ -262,7 +290,9 @@ namespace Server public void Write(byte value) { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = value; } @@ -275,7 +305,9 @@ namespace Server public void Write(byte[] value, int length) { while (m_Index + length > Data.Length) + { Expand(); + } Buffer.BlockCopy(value, 0, Data, m_Index, length); m_Index += length; @@ -284,7 +316,9 @@ namespace Server public void Write(sbyte value) { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = (byte)value; } @@ -292,7 +326,9 @@ namespace Server public void Write(bool value) { if (m_Index + 1 > Data.Length) + { Expand(); + } Data[m_Index++] = (byte)(value ? 1 : 0); } @@ -325,17 +361,25 @@ namespace Server public void Write(Map value) { if (value != null) + { Write((byte)value.MapIndex); + } else + { Write((byte)0xFF); + } } public void Write(Race value) { if (value != null) + { Write((byte)value.RaceIndex); + } else + { Write((byte)0xFF); + } } public void WriteEntity(IEntity value) @@ -356,9 +400,13 @@ namespace Server public void Write(BaseGuild value) { if (value == null) + { Write(0); + } else + { Write(value.Serial); + } } public void WriteItem(T value) where T : Item @@ -394,16 +442,26 @@ namespace Server public void WriteItemList(List list, bool tidy) where T : Item { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -413,11 +471,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void WriteItemSet(HashSet set) where T : Item @@ -427,11 +491,17 @@ namespace Server public void WriteItemSet(HashSet set, bool tidy) where T : Item { - if (tidy) set.RemoveWhere(item => item.Deleted); + if (tidy) + { + set.RemoveWhere(item => item.Deleted); + } Write(set.Count); - foreach (var item in set) Write(item); + foreach (var item in set) + { + Write(item); + } } public void Write(List list) @@ -442,16 +512,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteMobileList(List list) where T : Mobile @@ -462,16 +542,26 @@ namespace Server public void WriteMobileList(List list, bool tidy) where T : Mobile { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Deleted) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -481,11 +571,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(mobile => mobile.Deleted); + if (tidy) + { + set.RemoveWhere(mobile => mobile.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void WriteMobileSet(HashSet set) where T : Mobile @@ -495,11 +591,17 @@ namespace Server public void WriteMobileSet(HashSet set, bool tidy) where T : Mobile { - if (tidy) set.RemoveWhere(mob => mob.Deleted); + if (tidy) + { + set.RemoveWhere(mob => mob.Deleted); + } Write(set.Count); - foreach (var mob in set) Write(mob); + foreach (var mob in set) + { + Write(mob); + } } public void Write(List list) @@ -510,16 +612,26 @@ namespace Server public void Write(List list, bool tidy) { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void WriteGuildList(List list) where T : BaseGuild @@ -530,16 +642,26 @@ namespace Server public void WriteGuildList(List list, bool tidy) where T : BaseGuild { if (tidy) + { for (var i = 0; i < list.Count;) + { if (list[i].Disbanded) + { list.RemoveAt(i); + } else + { ++i; + } + } + } Write(list.Count); for (var i = 0; i < list.Count; ++i) + { Write(list[i]); + } } public void Write(HashSet set) @@ -549,11 +671,17 @@ namespace Server public void Write(HashSet set, bool tidy) { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } public void WriteGuildSet(HashSet set) where T : BaseGuild @@ -563,11 +691,17 @@ namespace Server public void WriteGuildSet(HashSet set, bool tidy) where T : BaseGuild { - if (tidy) set.RemoveWhere(guild => guild.Disbanded); + if (tidy) + { + set.RemoveWhere(guild => guild.Disbanded); + } Write(set.Count); - foreach (var guild in set) Write(guild); + foreach (var guild in set) + { + Write(guild); + } } public void Flush() @@ -605,7 +739,9 @@ namespace Server var byteLength = m_Encoding.GetBytes(value, current, charCount, m_CharacterBuffer, 0); if (m_Index + byteLength > Data.Length) + { Expand(); + } Buffer.BlockCopy(m_CharacterBuffer, 0, Data, m_Index, byteLength); m_Index += byteLength; @@ -619,7 +755,9 @@ namespace Server var byteLength = m_Encoding.GetBytes(value, 0, value.Length, m_CharacterBuffer, 0); if (m_Index + byteLength > Data.Length) + { Expand(); + } Buffer.BlockCopy(m_CharacterBuffer, 0, Data, m_Index, byteLength); m_Index += byteLength; diff --git a/Projects/Server/Serialization/IGenericReader.cs b/Projects/Server/Serialization/IGenericReader.cs index 370461c06..3ea2700fd 100644 --- a/Projects/Server/Serialization/IGenericReader.cs +++ b/Projects/Server/Serialization/IGenericReader.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IGenericReader.cs * * * diff --git a/Projects/Server/Serialization/IGenericWriter.cs b/Projects/Server/Serialization/IGenericWriter.cs index 7570ca701..91376fbd6 100644 --- a/Projects/Server/Serialization/IGenericWriter.cs +++ b/Projects/Server/Serialization/IGenericWriter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: IGenericWriter.cs * * * diff --git a/Projects/Server/Serialization/ISerializable.cs b/Projects/Server/Serialization/ISerializable.cs index 74b4bcb90..7fb2dfa6b 100644 --- a/Projects/Server/Serialization/ISerializable.cs +++ b/Projects/Server/Serialization/ISerializable.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ISerializable.cs * * * diff --git a/Projects/Server/Skills.cs b/Projects/Server/Skills.cs index e61095c19..fe6974d9f 100644 --- a/Projects/Server/Skills.cs +++ b/Projects/Server/Skills.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Skills.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections; using System.Collections.Generic; @@ -133,15 +113,23 @@ namespace Server if ((version & 0xC0) == 0x00) { if ((version & 0x1) != 0) + { m_Base = reader.ReadUShort(); + } if ((version & 0x2) != 0) + { m_Cap = reader.ReadUShort(); + } else + { m_Cap = 1000; + } if ((version & 0x4) != 0) + { Lock = (SkillLock)reader.ReadByte(); + } } break; @@ -247,7 +235,9 @@ namespace Server var raceBonus = Owner.Owner.RacialSkillBonus; if (raceBonus > value) + { value = raceBonus; + } return value; } @@ -261,7 +251,10 @@ namespace Server var baseValue = Base; var inv = 100.0 - baseValue; - if (inv < 0.0) inv = 0.0; + if (inv < 0.0) + { + inv = 0.0; + } inv /= 100.0; @@ -273,7 +266,9 @@ namespace Server statsOffset *= inv; if (statsOffset > statTotal) + { statsOffset = statTotal; + } var value = baseValue + statsOffset; @@ -292,9 +287,13 @@ namespace Server if (mod.Relative) { if (mod.ObeyCap) + { bonusObey += mod.Value; + } else + { bonusNotObey += mod.Value; + } } else { @@ -312,7 +311,9 @@ namespace Server value += bonusObey; if (value > Cap) + { value = Cap; + } } return value; @@ -324,7 +325,9 @@ namespace Server public void SetLockNoRelay(SkillLock skillLock) { if (skillLock < SkillLock.Up || skillLock > SkillLock.Locked) + { return; + } Lock = skillLock; } @@ -340,24 +343,36 @@ namespace Server var flags = 0x0; if (m_Base != 0) + { flags |= 0x1; + } if (m_Cap != 1000) + { flags |= 0x2; + } if (Lock != SkillLock.Up) + { flags |= 0x4; + } writer.Write((byte)flags); // version if (m_Base != 0) + { writer.Write((short)m_Base); + } if (m_Cap != 1000) + { writer.Write((short)m_Cap); + } if (Lock != SkillLock.Up) + { writer.Write((byte)Lock); + } } } @@ -513,11 +528,15 @@ namespace Server case 1: { if (version < 2) + { Cap = 7000; + } if (version < 3) /*m_Total =*/ + { reader.ReadInt(); + } var info = SkillInfo.Table; @@ -526,6 +545,7 @@ namespace Server var count = reader.ReadInt(); for (var i = 0; i < count; ++i) + { if (i < info.Length) { var sk = new Skill(this, info[i], reader); @@ -541,6 +561,7 @@ namespace Server // Will be discarded _ = new Skill(this, null, reader); } + } // for ( int i = count; i < info.Length; ++i ) // m_Skills[i] = new Skill( this, info[i], 0, 1000, SkillLock.Up ); @@ -572,12 +593,16 @@ namespace Server get { if (skillID < 0 || skillID >= m_Skills.Length) + { return null; + } var sk = m_Skills[skillID]; if (sk == null) + { m_Skills[skillID] = sk = new Skill(this, SkillInfo.Table[skillID], 0, 1000, SkillLock.Up); + } return sk; } @@ -801,11 +826,19 @@ namespace Server public static bool UseSkill(Mobile from, int skillID) { if (!from.CheckAlive()) + { return false; + } + if (!from.Region.OnSkillUse(from, skillID)) + { return false; + } + if (!from.AllowSkillUse((SkillName)skillID)) + { return false; + } if (skillID >= 0 && skillID < SkillInfo.Table.Length) { @@ -861,9 +894,13 @@ namespace Server public void OnSkillChange(Skill skill) { if (skill == m_Highest) // could be downgrading the skill, force a recalc + { m_Highest = null; + } else if (m_Highest != null && skill.BaseFixedPoint > m_Highest.BaseFixedPoint) + { m_Highest = skill; + } Owner.OnSkillInvalidated(skill); Owner.NetState?.Send(new SkillChange(skill)); diff --git a/Projects/Server/Targeting/LandTarget.cs b/Projects/Server/Targeting/LandTarget.cs index e6a6a23c4..32511045e 100644 --- a/Projects/Server/Targeting/LandTarget.cs +++ b/Projects/Server/Targeting/LandTarget.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * LandTarget.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Targeting { public class LandTarget : IPoint3D diff --git a/Projects/Server/Targeting/MultiTarget.cs b/Projects/Server/Targeting/MultiTarget.cs index f96dff4de..4e6867803 100644 --- a/Projects/Server/Targeting/MultiTarget.cs +++ b/Projects/Server/Targeting/MultiTarget.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * MultiTarget.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using Server.Network; namespace Server.Targeting @@ -41,7 +21,10 @@ namespace Server.Targeting public override Packet GetPacketFor(NetState ns) { if (ns.HighSeas) + { return new MultiTargetReqHS(this); + } + return new MultiTargetReq(this); } } diff --git a/Projects/Server/Targeting/StaticTarget.cs b/Projects/Server/Targeting/StaticTarget.cs index ae8d2c898..33cb9107c 100644 --- a/Projects/Server/Targeting/StaticTarget.cs +++ b/Projects/Server/Targeting/StaticTarget.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * StaticTarget.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Targeting { public class StaticTarget : IPoint3D diff --git a/Projects/Server/Targeting/Target.cs b/Projects/Server/Targeting/Target.cs index 6e5523d1b..4b3480cba 100644 --- a/Projects/Server/Targeting/Target.cs +++ b/Projects/Server/Targeting/Target.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Target.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using Server.Network; @@ -187,19 +167,33 @@ namespace Server.Targeting else { if (!from.CanSee(targeted)) - OnCantSeeTarget(from, targeted); + { + OnCantSeeTarget(@from, targeted); + } else if (CheckLOS && !from.InLOS(targeted)) - OnTargetOutOfLOS(from, targeted); + { + OnTargetOutOfLOS(@from, targeted); + } else if (item?.InSecureTrade == true) - OnTargetInSecureTrade(from, targeted); + { + OnTargetInSecureTrade(@from, targeted); + } else if (item?.IsAccessibleTo(from) == false) - OnTargetNotAccessible(from, targeted); + { + OnTargetNotAccessible(@from, targeted); + } else if (item?.CheckTarget(from, this, targeted) == false) - OnTargetUntargetable(from, targeted); + { + OnTargetUntargetable(@from, targeted); + } else if (mobile?.CheckTarget(from, this, mobile) == false) - OnTargetUntargetable(from, mobile); + { + OnTargetUntargetable(@from, mobile); + } else if (from.Region.OnTarget(from, this, targeted)) - OnTarget(from, targeted); + { + OnTarget(@from, targeted); + } } OnTargetFinish(from); @@ -270,19 +264,29 @@ namespace Server.Targeting m_Mobile = m; if (delay >= ThirtySeconds) + { Priority = TimerPriority.FiveSeconds; + } else if (delay >= TenSeconds) + { Priority = TimerPriority.OneSecond; + } else if (delay >= OneSecond) + { Priority = TimerPriority.TwoFiftyMS; + } else + { Priority = TimerPriority.TwentyFiveMS; + } } protected override void OnTick() { if (m_Mobile.Target == m_Target) + { m_Target.Timeout(m_Mobile); + } } } } diff --git a/Projects/Server/Targeting/TargetCancelType.cs b/Projects/Server/Targeting/TargetCancelType.cs index 65e99da20..1d6740d97 100644 --- a/Projects/Server/Targeting/TargetCancelType.cs +++ b/Projects/Server/Targeting/TargetCancelType.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TargetCancelType.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server.Targeting { public enum TargetCancelType diff --git a/Projects/Server/Targeting/TargetFlags.cs b/Projects/Server/Targeting/TargetFlags.cs index efa420b20..0d10bcad0 100644 --- a/Projects/Server/Targeting/TargetFlags.cs +++ b/Projects/Server/Targeting/TargetFlags.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TargetFlags.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server.Targeting diff --git a/Projects/Server/TileData.cs b/Projects/Server/TileData.cs index 2916e27db..e10cf880a 100644 --- a/Projects/Server/TileData.cs +++ b/Projects/Server/TileData.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TileData.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.IO; using System.Text; @@ -66,9 +46,13 @@ namespace Server set { if (value) + { Flags |= TileFlag.Bridge; + } else + { Flags &= ~TileFlag.Bridge; + } } } @@ -78,9 +62,13 @@ namespace Server set { if (value) + { Flags |= TileFlag.Impassable; + } else + { Flags &= ~TileFlag.Impassable; + } } } @@ -90,9 +78,13 @@ namespace Server set { if (value) + { Flags |= TileFlag.Surface; + } else + { Flags &= ~TileFlag.Surface; + } } } @@ -131,7 +123,10 @@ namespace Server get { if ((Flags & TileFlag.Bridge) != 0) + { return m_Height / 2; + } + return m_Height; } } @@ -184,7 +179,10 @@ namespace Server ItemTable = new ItemData[0x10000]; LandTable = new LandData[0x4000]; - if (Core.IsRunningFromXUnit) return; + if (Core.IsRunningFromXUnit) + { + return; + } var filePath = Core.FindDataFile("tiledata.mul"); @@ -200,7 +198,9 @@ namespace Server if (is7090) { if (i == 1 || i > 0 && (i & 0x1F) == 0) + { bin.ReadInt32(); + } } else if ((i & 0x1F) == 0) { @@ -218,7 +218,10 @@ namespace Server for (var i = 0; i < length; i++) { - if ((i & 0x1F) == 0) bin.ReadInt32(); // header + if ((i & 0x1F) == 0) + { + bin.ReadInt32(); // header + } var flags = (TileFlag)(is7090 ? bin.ReadInt64() : bin.ReadInt32()); int weight = bin.ReadByte(); @@ -263,7 +266,9 @@ namespace Server while (count < 20) { if (m_StringBuffer[count] == 0) + { break; + } count++; } diff --git a/Projects/Server/TileList.cs b/Projects/Server/TileList.cs index b4035c4b2..04f11c240 100644 --- a/Projects/Server/TileList.cs +++ b/Projects/Server/TileList.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TileList.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; namespace Server @@ -43,11 +23,15 @@ namespace Server m_Tiles = new StaticTile[(Count + tiles.Length) * 2]; for (var i = 0; i < old.Length; ++i) + { m_Tiles[i] = old[i]; + } } for (var i = 0; i < tiles.Length; ++i) + { m_Tiles[Count++] = tiles[i]; + } } public void Add(ushort id, sbyte z) @@ -58,7 +42,9 @@ namespace Server m_Tiles = new StaticTile[old.Length * 2]; for (var i = 0; i < old.Length; ++i) + { m_Tiles[i] = old[i]; + } } m_Tiles[Count].m_ID = id; @@ -69,12 +55,16 @@ namespace Server public StaticTile[] ToArray() { if (Count == 0) + { return m_EmptyTiles; + } var tiles = new StaticTile[Count]; for (var i = 0; i < Count; ++i) + { tiles[i] = m_Tiles[i]; + } Count = 0; diff --git a/Projects/Server/TileMatrix.cs b/Projects/Server/TileMatrix.cs index 6e2c0a674..db5ea3839 100644 --- a/Projects/Server/TileMatrix.cs +++ b/Projects/Server/TileMatrix.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TileMatrix.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.IO; @@ -67,6 +47,7 @@ namespace Server var tm = m_Instances[i]; if (tm.m_FileIndex == fileIndex) + { lock (m_FileShare) { lock (tm.m_FileShare) @@ -75,6 +56,7 @@ namespace Server m_FileShare.Add(tm); } } + } } m_Instances.Add(this); @@ -100,7 +82,9 @@ namespace Server mapPath = Core.FindDataFile($"map{fileIndex}.mul", false, true); if (mapPath != null) + { m_MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + } } var indexPath = Core.FindDataFile($"staidx{fileIndex}.mul", false, true); @@ -114,7 +98,9 @@ namespace Server var staticsPath = Core.FindDataFile($"statics{fileIndex}.mul", false, true); if (staticsPath != null) + { DataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + } } EmptyStaticBlock = new StaticTile[8][][]; @@ -124,7 +110,9 @@ namespace Server EmptyStaticBlock[i] = new StaticTile[8][]; for (var j = 0; j < 8; ++j) + { EmptyStaticBlock[i][j] = Array.Empty(); + } } m_InvalidLandBlock = new LandTile[196]; @@ -153,7 +141,9 @@ namespace Server public void SetStaticBlock(int x, int y, StaticTile[][][] value) { if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight) + { return; + } m_StaticTiles[x] ??= new StaticTile[BlockHeight][][][]; m_StaticTiles[x][y] = value; @@ -166,14 +156,18 @@ namespace Server public StaticTile[][][] GetStaticBlock(int x, int y) { if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight || DataStream == null || IndexStream == null) + { return EmptyStaticBlock; + } m_StaticTiles[x] ??= new StaticTile[BlockHeight][][][]; var tiles = m_StaticTiles[x][y]; if (tiles != null) + { return tiles; + } lock (m_FileShare) { @@ -188,14 +182,18 @@ namespace Server var theirTiles = shared.m_StaticTiles[x]; if (theirTiles != null) + { tiles = theirTiles[y]; + } if (tiles != null) { var theirBits = shared.m_StaticPatches[x]; if (theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0) + { tiles = null; + } } } } @@ -213,12 +211,16 @@ namespace Server var tiles = GetStaticBlock(x >> 3, y >> 3); if (!multis) + { return tiles[x & 0x7][y & 0x7]; + } var eable = m_Owner.GetMultiTilesAt(x, y); if (eable == Map.NullEnumerable.Instance) + { return tiles[x & 0x7][y & 0x7]; + } var any = false; @@ -236,7 +238,9 @@ namespace Server eable.Free(); if (!any) + { return tiles[x & 0x7][y & 0x7]; + } m_TilesList.AddRange(tiles[x & 0x7][y & 0x7]); @@ -247,7 +251,9 @@ namespace Server public void SetLandBlock(int x, int y, LandTile[] value) { if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight) + { return; + } m_LandTiles[x] ??= new LandTile[BlockHeight][]; m_LandTiles[x][y] = value; @@ -260,14 +266,18 @@ namespace Server public LandTile[] GetLandBlock(int x, int y) { if (x < 0 || y < 0 || x >= BlockWidth || y >= BlockHeight || m_MapStream == null) + { return m_InvalidLandBlock; + } m_LandTiles[x] ??= new LandTile[BlockHeight][]; var tiles = m_LandTiles[x][y]; if (tiles != null) + { return tiles; + } lock (m_FileShare) { @@ -282,14 +292,18 @@ namespace Server var theirTiles = shared.m_LandTiles[x]; if (theirTiles != null) + { tiles = theirTiles[y]; + } if (tiles != null) { var theirBits = shared.m_LandPatches[x]; if (theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0) + { tiles = null; + } } } } @@ -312,14 +326,18 @@ namespace Server var length = m_IndexReader.ReadInt32(); if (lookup < 0 || length <= 0) + { return EmptyStaticBlock; + } var count = length / 7; DataStream.Seek(lookup, SeekOrigin.Begin); if (m_TileBuffer.Length < count) + { m_TileBuffer = new StaticTile[count]; + } var staTiles = m_TileBuffer; // new StaticTile[tileCount]; @@ -335,7 +353,9 @@ namespace Server m_Lists[i] = new TileList[8]; for (var j = 0; j < 8; ++j) + { m_Lists[i][j] = new TileList(); + } } } @@ -356,7 +376,9 @@ namespace Server tiles[i] = new StaticTile[8][]; for (var j = 0; j < 8; ++j) + { tiles[i][j] = lists[i][j].ToArray(); + } } return tiles; @@ -377,7 +399,9 @@ namespace Server public void Force() { if ((AssemblyHandler.Assemblies?.Length ?? 0) == 0) + { throw new Exception(); + } } [MethodImpl(MethodImplOptions.Synchronized)] @@ -388,7 +412,9 @@ namespace Server var offset = (x * BlockHeight + y) * 196 + 4; if (m_MapIndex != null) + { offset = m_MapIndex.Lookup(offset); + } m_MapStream.Seek(offset, SeekOrigin.Begin); @@ -538,7 +564,9 @@ namespace Server m_Length = (int)stream.Length; if (m_Reader.ReadInt32() != 0x50594D) + { throw new ArgumentException("Invalid UOP file."); + } Version = m_Reader.ReadInt32(); m_Reader.ReadInt32(); @@ -600,7 +628,9 @@ namespace Server var newTotal = total + m_Entries[i].m_Length; if (offset < newTotal) + { return m_Entries[i].m_Offset + (offset - total); + } total = newTotal; } diff --git a/Projects/Server/TileMatrixPatch.cs b/Projects/Server/TileMatrixPatch.cs index 5f25c1e53..9842bbbb2 100644 --- a/Projects/Server/TileMatrixPatch.cs +++ b/Projects/Server/TileMatrixPatch.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * TileMatrixPatch.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System.IO; using System.Runtime.CompilerServices; @@ -33,20 +13,26 @@ namespace Server public TileMatrixPatch(TileMatrix matrix, int index) { if (!Enabled) + { return; + } var mapDataPath = Core.FindDataFile($"mapdif{index}.mul", false); var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false); if (File.Exists(mapDataPath) && File.Exists(mapIndexPath)) + { m_LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath); + } var staDataPath = Core.FindDataFile($"stadif{index}.mul", false); var staIndexPath = Core.FindDataFile($"stadifl{index}.mul", false); var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false); if (File.Exists(staDataPath) && File.Exists(staIndexPath) && File.Exists(staLookupPath)) + { m_StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath); + } } public static bool Enabled { get; set; } = true; @@ -123,7 +109,9 @@ namespace Server lists[x] = new TileList[8]; for (var y = 0; y < 8; ++y) + { lists[x][y] = new TileList(); + } } for (var i = 0; i < count; ++i) @@ -147,7 +135,9 @@ namespace Server var tileCount = length / 7; if (m_TileBuffer.Length < tileCount) + { m_TileBuffer = new StaticTile[tileCount]; + } var staTiles = m_TileBuffer; @@ -169,7 +159,9 @@ namespace Server tiles[x] = new StaticTile[8][]; for (var y = 0; y < 8; ++y) + { tiles[x][y] = lists[x][y].ToArray(); + } } matrix.SetStaticBlock(blockX, blockY, tiles); diff --git a/Projects/Server/Timer/Timer.cs b/Projects/Server/Timer/Timer.cs index ba98ee5d3..f0c5e49c1 100644 --- a/Projects/Server/Timer/Timer.cs +++ b/Projects/Server/Timer/Timer.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Timer.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.IO; @@ -73,7 +53,9 @@ namespace Server } if (DefRegCreation) + { RegCreation(); + } } public TimerPriority Priority @@ -82,14 +64,18 @@ namespace Server set { if (!m_PrioritySet) + { m_PrioritySet = true; + } if (m_Priority != value) { m_Priority = value; if (m_Running) + { TimerThread.PriorityChange(this, (int)m_Priority); + } } } } @@ -114,9 +100,13 @@ namespace Server set { if (value) + { Start(); + } else + { Stop(); + } } } @@ -134,7 +124,10 @@ namespace Server public TimerProfile GetProfile() { - if (!Core.Profiling) return null; + if (!Core.Profiling) + { + return null; + } var name = ToString(); @@ -169,7 +162,10 @@ namespace Server { var prof = GetProfile(); - if (prof != null) prof.Created++; + if (prof != null) + { + prof.Created++; + } } public override string ToString() => GetType().FullName ?? ""; @@ -177,22 +173,34 @@ namespace Server public static TimerPriority ComputePriority(TimeSpan ts) { if (ts >= TimeSpan.FromMinutes(1.0)) + { return TimerPriority.FiveSeconds; + } if (ts >= TimeSpan.FromSeconds(10.0)) + { return TimerPriority.OneSecond; + } if (ts >= TimeSpan.FromSeconds(5.0)) + { return TimerPriority.TwoFiftyMS; + } if (ts >= TimeSpan.FromSeconds(2.5)) + { return TimerPriority.FiftyMS; + } if (ts >= TimeSpan.FromSeconds(1.0)) + { return TimerPriority.TwentyFiveMS; + } if (ts >= TimeSpan.FromSeconds(0.5)) + { return TimerPriority.TenMS; + } return TimerPriority.EveryTick; } @@ -206,7 +214,10 @@ namespace Server var prof = GetProfile(); - if (prof != null) prof.Started++; + if (prof != null) + { + prof.Started++; + } } } @@ -219,7 +230,10 @@ namespace Server var prof = GetProfile(); - if (prof != null) prof.Stopped++; + if (prof != null) + { + prof.Stopped++; + } } } @@ -285,7 +299,9 @@ namespace Server var key = t.ToString(); if (!hash.TryGetValue(key, out var list)) + { hash[key] = list = new List(); + } list.Add(t); } @@ -392,7 +408,9 @@ namespace Server { var now = Core.TickCount; if (now < m_NextPriorities[i]) + { break; + } m_NextPriorities[i] = now + m_PriorityDelays[i]; @@ -412,15 +430,21 @@ namespace Server loaded = true; if (t.m_Count != 0 && ++t.m_Index >= t.m_Count) + { t.Stop(); + } else + { t.m_Next = now + t.m_Interval; + } } } } if (loaded) + { Core.Set(); + } m_Signal.WaitOne(1, false); } @@ -445,7 +469,9 @@ namespace Server lock (m_InstancePool) { if (m_InstancePool.Count < 200) // Arbitrary + { m_InstancePool.Enqueue(this); + } } } @@ -455,7 +481,10 @@ namespace Server lock (m_InstancePool) { - if (m_InstancePool.Count > 0) e = m_InstancePool.Dequeue(); + if (m_InstancePool.Count > 0) + { + e = m_InstancePool.Dequeue(); + } } if (e != null) diff --git a/Projects/Server/Timer/TimerDelayCalls.cs b/Projects/Server/Timer/TimerDelayCalls.cs index fbc6f6f3c..4fd2d791e 100644 --- a/Projects/Server/Timer/TimerDelayCalls.cs +++ b/Projects/Server/Timer/TimerDelayCalls.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TimerDelayCalls.cs * * * diff --git a/Projects/Server/Utilities/ActivatorUtil.cs b/Projects/Server/Utilities/ActivatorUtil.cs index 1aa71eef0..eace380b5 100644 --- a/Projects/Server/Utilities/ActivatorUtil.cs +++ b/Projects/Server/Utilities/ActivatorUtil.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: ActivatorUtil.cs * * * @@ -25,7 +25,10 @@ namespace Server.Utilities { var emptyCtor = type.GetConstructor(Type.EmptyTypes); - if (emptyCtor != null && predicate?.Invoke(emptyCtor) != false) return emptyCtor; + if (emptyCtor != null && predicate?.Invoke(emptyCtor) != false) + { + return emptyCtor; + } var optionalCtor = type.GetConstructors() .SingleOrDefault( @@ -33,7 +36,10 @@ namespace Server.Utilities predicate?.Invoke(info) != false && info.GetParameters().All(x => x.IsOptional) ); - if (optionalCtor != null) return optionalCtor; + if (optionalCtor != null) + { + return optionalCtor; + } throw new TypeInitializationException( type.ToString(), @@ -51,7 +57,10 @@ namespace Server.Utilities { ctor = type.GetConstructor(args); - if (ctor != null && predicate?.Invoke(ctor) != false) return ctor; + if (ctor != null && predicate?.Invoke(ctor) != false) + { + return ctor; + } } else { @@ -59,20 +68,30 @@ namespace Server.Utilities .SingleOrDefault( info => { - if (predicate?.Invoke(info) == false) return false; + if (predicate?.Invoke(info) == false) + { + return false; + } var paramList = info.GetParameters().ToList(); // If more args are given than parameters, skip. - if (args.Length > paramList.Count) return false; + if (args.Length > paramList.Count) + { + return false; + } // check all given args map to params. for (var i = 0; i < args.Length; i++) // if a null reference is passed, but the type is not nullable + { if (args[i] == null && paramList[i].ParameterType.IsValueType // or if an arg is not null and is not assignable to the parameter type, skip. || !(args[i] == null || paramList[i].ParameterType.IsAssignableFrom(args[i]))) + { return false; + } + } // If there are more parameters, check if they any are not optional, if any are not, skip. // Otherwise all checks have passed. We have found a match @@ -82,7 +101,10 @@ namespace Server.Utilities } ); - if (ctor != null) return ctor; + if (ctor != null) + { + return ctor; + } } throw new Exception($"There is no empty/default constructor for {type} that matches predicate."); @@ -99,7 +121,10 @@ namespace Server.Utilities var cctor = GetConstructor(type, constructorPredicate); var args = cctor.GetParameters(); - if (args.Length == 0) return cctor.Invoke(Type.EmptyTypes); + if (args.Length == 0) + { + return cctor.Invoke(Type.EmptyTypes); + } var argList = new object[args.Length]; Array.Fill(argList, Type.Missing); @@ -111,7 +136,10 @@ namespace Server.Utilities params object[] args ) { - if (args == null || args.Length == 0) return CreateInstance(type, constructorPredicate); + if (args == null || args.Length == 0) + { + return CreateInstance(type, constructorPredicate); + } var cctor = GetConstructor(type, constructorPredicate, args.Select(x => x?.GetType()).ToArray()); return cctor.Invoke(args); diff --git a/Projects/Server/Utilities/RefPool.cs b/Projects/Server/Utilities/RefPool.cs index 7caf442bc..8c7bbc58c 100644 --- a/Projects/Server/Utilities/RefPool.cs +++ b/Projects/Server/Utilities/RefPool.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: RefPool.cs * * * @@ -71,14 +71,23 @@ namespace Server.Utilities public RefPool(Generator generator, int preGenerateCount = 0, int maxRefrenceRetention = DEFAULT_RESOURCE_RETENTION) { if (generator == null) + { throw new ArgumentNullException(nameof(generator)); + } + if (preGenerateCount > maxRefrenceRetention) + { throw new IndexOutOfRangeException( $"{nameof(preGenerateCount)} greater than {nameof(maxRefrenceRetention)}" ); + } + m_Generator = generator; m_MaxRefrenceRetention = maxRefrenceRetention; - while (--preGenerateCount >= 0) m_Resources.Push(generator(this)); + while (--preGenerateCount >= 0) + { + m_Resources.Push(generator(this)); + } } /// @@ -90,7 +99,10 @@ namespace Server.Utilities set { m_MaxRefrenceRetention = value; - while (m_Resources.Count > value) m_Resources.Pop(); + while (m_Resources.Count > value) + { + m_Resources.Pop(); + } } } @@ -109,7 +121,9 @@ namespace Server.Utilities public void Return(TRef queueRef) { if (m_Resources.Count < MaxRefrenceRetention) + { m_Resources.Push(queueRef); + } } } diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 5f61af941..9f93a3bc4 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * Utility.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Globalization; @@ -127,7 +107,9 @@ namespace Server public static void Separate(StringBuilder sb, string value, string separator) { if (sb.Length > 0) + { sb.Append(separator); + } sb.Append(value); } @@ -172,25 +154,35 @@ namespace Server public static string FixHtml(string str) { if (str == null) + { return ""; + } var hasOpen = str.IndexOf('<') >= 0; var hasClose = str.IndexOf('>') >= 0; var hasPound = str.IndexOf('#') >= 0; if (!hasOpen && !hasClose && !hasPound) + { return str; + } var sb = new StringBuilder(str); if (hasOpen) + { sb.Replace('<', '('); + } if (hasClose) + { sb.Replace('>', ')'); + } if (hasPound) + { sb.Replace('#', '-'); + } return sb.ToString(); } @@ -198,7 +190,9 @@ namespace Server public static bool IPMatchCIDR(string cidr, IPAddress ip) { if (ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6) + { return false; // Just worry about IPv4 for now + } var bytes = new byte[4]; var split = cidr.Split('.'); @@ -269,7 +263,9 @@ namespace Server else if (c == '/') { if (cidrBits || i != 3) // If there's two '/' or the '/' isn't in the last byte + { return false; + } partBase = 10; cidrBits = true; @@ -290,7 +286,9 @@ namespace Server { // Ignore IPv6 for now if (cidrPrefix == null || ip == null || cidrPrefix.AddressFamily == AddressFamily.InterNetworkV6) + { return false; + } var cidrValue = SwapUnsignedInt((uint)GetLongAddressValue(cidrPrefix)); var ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip)); @@ -301,7 +299,9 @@ namespace Server public static bool IPMatchCIDR(uint cidrPrefixValue, IPAddress ip, int cidrLength) { if (ip == null || ip.AddressFamily == AddressFamily.InterNetworkV6) + { return false; + } var ipValue = SwapUnsignedInt((uint)GetLongAddressValue(ip)); @@ -311,7 +311,9 @@ namespace Server public static bool IPMatchCIDR(uint cidrPrefixValue, uint ipValue, int cidrLength) { if (cidrLength <= 0 || cidrLength >= 32) // if invalid cidr Length, just compare IPs + { return cidrPrefixValue == ipValue; + } var mask = uint.MaxValue << (32 - cidrLength); @@ -321,7 +323,9 @@ namespace Server private static uint OrderedAddressValue(byte[] bytes) { if (bytes.Length != 4) + { return 0; + } return (uint)((bytes[0] << 0x18) | (bytes[1] << 0x10) | (bytes[2] << 8) | bytes[3]) & 0xffffffff; } @@ -335,21 +339,32 @@ namespace Server public static bool TryConvertIPv6toIPv4(ref IPAddress address) { if (!Socket.OSSupportsIPv6 || address.AddressFamily == AddressFamily.InterNetwork) + { return true; + } var addr = address.GetAddressBytes(); if (addr.Length == 16) // sanity 0 - 15 //10 11 //12 13 14 15 { if (addr[10] != 0xFF || addr[11] != 0xFF) + { return false; + } for (var i = 0; i < 10; i++) + { if (addr[i] != 0) + { return false; + } + } var v4Addr = new byte[4]; - for (var i = 0; i < 4; i++) v4Addr[i] = addr[12 + i]; + for (var i = 0; i < 4; i++) + { + v4Addr[i] = addr[12 + i]; + } address = new IPAddress(v4Addr); return true; @@ -466,7 +481,9 @@ namespace Server int b = (byte)(GetAddressValue(ip) >> (i * 8)); if (b < lowPart || b > highPart) + { return false; + } } return true; @@ -487,11 +504,20 @@ namespace Server var adx = Math.Abs(dx); var ady = Math.Abs(dy); - if (adx >= ady * 3) return dx > 0 ? Direction.East : Direction.West; + if (adx >= ady * 3) + { + return dx > 0 ? Direction.East : Direction.West; + } - if (ady >= adx * 3) return dy > 0 ? Direction.South : Direction.North; + if (ady >= adx * 3) + { + return dy > 0 ? Direction.South : Direction.North; + } - if (dx > 0) return dy > 0 ? Direction.Down : Direction.Right; + if (dx > 0) + { + return dy > 0 ? Direction.Down : Direction.Right; + } return dy > 0 ? Direction.Left : Direction.Up; } @@ -562,14 +588,22 @@ namespace Server bytes.Append(c.ToString("X2")); if (j != 7) + { bytes.Append(' '); + } else + { bytes.Append(" "); + } if (c >= 0x20 && c < 0x7F) + { chars.Append((char)c); + } else + { chars.Append('.'); + } } output.Write(byteIndex.ToString("X4")); @@ -585,6 +619,7 @@ namespace Server var chars = new StringBuilder(rem); for (var j = 0; j < 16; ++j) + { if (j < rem) { var c = input.ReadByte(); @@ -592,19 +627,28 @@ namespace Server bytes.Append(c.ToString("X2")); if (j != 7) + { bytes.Append(' '); + } else + { bytes.Append(" "); + } if (c >= 0x20 && c < 0x7F) + { chars.Append((char)c); + } else + { chars.Append('.'); + } } else { bytes.Append(" "); } + } output.Write(byteIndex.ToString("X4")); output.Write(" "); @@ -662,7 +706,9 @@ namespace Server m.HairItemID = m.Race.RandomHair(m); if (randomHue) + { m.HairHue = m.Race.RandomHairHue(); + } } public static void AssignRandomFacialHair(Mobile m, int hue) @@ -676,7 +722,9 @@ namespace Server m.FacialHairItemID = m.Race.RandomFacialHair(m); if (randomHue) + { m.FacialHairHue = m.Race.RandomHairHue(); + } } public static List CastListContravariant(List list) where TInput : TOutput => @@ -688,7 +736,9 @@ namespace Server public static List SafeConvertList(List list) where TOutput : class { if ((list?.Capacity ?? 0) == 0) + { return new List(); + } var output = new List(list.Capacity); output.AddRange(list.OfType()); @@ -729,9 +779,13 @@ namespace Server #pragma warning disable CA1806 // Do not ignore method results if (value.StartsWith("0x")) + { int.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i); + } else + { int.TryParse(value, out i); + } #pragma warning restore CA1806 // Do not ignore method results return i; @@ -743,9 +797,13 @@ namespace Server #pragma warning disable CA1806 // Do not ignore method results if (value.StartsWith("0x")) + { uint.TryParse(value.Substring(2), NumberStyles.HexNumber, null, out i); + } else + { uint.TryParse(value, out i); + } #pragma warning restore CA1806 // Do not ignore method results return i; @@ -848,7 +906,9 @@ namespace Server var total = 0; for (var i = 0; i < amount; ++i) + { total += (int)RandomSources.Source.Next(1, sides); + } return total + bonus; } @@ -883,7 +943,10 @@ namespace Server */ public static T[] RandomSample(this T[] source, int count) { - if (count <= 0) return Array.Empty(); + if (count <= 0) + { + return Array.Empty(); + } var length = source.Length; Span list = stackalloc bool[length]; @@ -894,7 +957,9 @@ namespace Server { var rand = Random(length); if (!(list[rand] && (list[rand] = true))) + { sampleList[i++] = source[rand]; + } } while (i < count); return sampleList; @@ -902,7 +967,10 @@ namespace Server public static List RandomSample(this List source, int count) { - if (count <= 0) return new List(); + if (count <= 0) + { + return new List(); + } var length = source.Count; Span list = stackalloc bool[length]; @@ -913,7 +981,9 @@ namespace Server { var rand = Random(length); if (!(list[rand] && (list[rand] = true))) + { sampleList[i++] = source[rand]; + } } while (i < count); return sampleList; @@ -1064,5 +1134,27 @@ namespace Server [MethodImpl(MethodImplOptions.AggressiveInlining)] public static TimeSpan Max(this TimeSpan val, TimeSpan max) => val > max ? max : val; + + public static string TrimMultiline(this string str, string lineSeparator = "\n") + { + var parts = str.Split(lineSeparator); + for (var i = 0; i < parts.Length; i++) + { + parts[i] = parts[i].Trim(); + } + + return string.Join(lineSeparator, parts); + } + + public static string IndentMultiline(this string str, string indent = "\t", string lineSeparator = "\n") + { + var parts = str.Split(lineSeparator); + for (var i = 0; i < parts.Length; i++) + { + parts[i] = $"{indent}{parts[i]}"; + } + + return string.Join(lineSeparator, parts); + } } } diff --git a/Projects/Server/VirtueInfo.cs b/Projects/Server/VirtueInfo.cs index 7b23eefeb..336ccd656 100644 --- a/Projects/Server/VirtueInfo.cs +++ b/Projects/Server/VirtueInfo.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * VirtueInfo.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - namespace Server { [PropertyObject] @@ -43,8 +23,12 @@ namespace Server Values = new int[8]; for (var i = 0; i < 8; ++i) + { if ((mask & (1 << i)) != 0) + { Values[i] = reader.ReadInt(); + } + } } break; @@ -144,14 +128,22 @@ namespace Server var mask = 0; for (var i = 0; i < 8; ++i) + { if (info.Values[i] != 0) + { mask |= 1 << i; + } + } writer.Write((byte)mask); for (var i = 0; i < 8; ++i) + { if (info.Values[i] != 0) + { writer.Write(info.Values[i]); + } + } } } } diff --git a/Projects/Server/World.cs b/Projects/Server/World.cs index b75bcd540..adc6c5e6e 100644 --- a/Projects/Server/World.cs +++ b/Projects/Server/World.cs @@ -1,23 +1,3 @@ -/*************************************************************************** - * World.cs - * ------------------- - * begin : May 1, 2002 - * copyright : (C) The RunUO Software Team - * email : info@runuo.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - using System; using System.Collections.Generic; using System.Diagnostics; @@ -67,7 +47,10 @@ namespace Server public static void NotifyDiskWriteComplete() { - if (m_DiskWriteHandle.Set()) Console.WriteLine("Closing Save Files. "); + if (m_DiskWriteHandle.Set()) + { + Console.WriteLine("Closing Save Files. "); + } } public static void WaitForWriteCompletion() @@ -79,7 +62,10 @@ namespace Server { if (Saving || Loading) { - if (Saving) AppendSafetyLog("delete", entity); + if (Saving) + { + AppendSafetyLog("delete", entity); + } _deleteQueue.Enqueue(entity); @@ -94,17 +80,25 @@ namespace Server Packet p; if (ascii) + { p = new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text); + } else + { p = new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text); + } var list = TcpServer.Instances; p.Acquire(); for (var i = 0; i < list.Count; ++i) + { if (list[i].Mobile != null) + { list[i].Send(p); + } + } p.Release(); } @@ -147,9 +141,13 @@ namespace Server var ctor = t.GetConstructor(m_SerialTypeArray); if (ctor != null) + { types.Add(new Tuple(ctor, typeName)); + } else + { throw new Exception($"Type '{t}' does not have a serialization constructor"); + } } return types; @@ -158,7 +156,9 @@ namespace Server public static void Load() { if (Loaded) + { return; + } Loaded = true; LoadingType = null; @@ -202,7 +202,9 @@ namespace Server var objs = types[typeID]; if (objs == null) + { continue; + } Mobile m = null; var ctor = objs.Item1; @@ -257,7 +259,9 @@ namespace Server var objs = types[typeID]; if (objs == null) + { continue; + } Item item = null; var ctor = objs.Item1; @@ -307,7 +311,9 @@ namespace Server EventSink.InvokeCreateGuild(createEventArgs); var guild = createEventArgs.Guild; if (guild != null) + { guilds.Add(new GuildEntry(guild, pos, length)); + } } idxReader.Close(); @@ -339,7 +345,9 @@ namespace Server m.Deserialize(reader); if (reader.Position != entry.Position + entry.Length) + { throw new Exception($"***** Bad serialize on {m.GetType()} *****"); + } } catch (Exception e) { @@ -379,7 +387,9 @@ namespace Server item.Deserialize(reader); if (reader.Position != entry.Position + entry.Length) + { throw new Exception($"***** Bad serialize on {item.GetType()} *****"); + } } catch (Exception e) { @@ -420,7 +430,9 @@ namespace Server g.Deserialize(reader); if (reader.Position != entry.Position + entry.Length) + { throw new Exception($"***** Bad serialize on Guild {g.Serial} *****"); + } } catch (Exception e) { @@ -458,17 +470,33 @@ namespace Server if (Console.ReadKey(true).Key == ConsoleKey.Y) { if (failedMobiles) + { for (var i = 0; i < mobiles.Count;) + { if (mobiles[i].TypeID == failedTypeID) + { mobiles.RemoveAt(i); + } else + { ++i; + } + } + } else if (failedItems) + { for (var i = 0; i < items.Count;) + { if (items[i].TypeID == failedTypeID) + { items.RemoveAt(i); + } else + { ++i; + } + } + } } } @@ -495,7 +523,9 @@ namespace Server foreach (var item in Items.Values) { if (item.Parent == null) + { item.UpdateTotals(); + } item.ClearProperties(); } @@ -525,9 +555,13 @@ namespace Server var entity = _addQueue.Dequeue(); if (entity is Item item) + { AddItem(item); + } else if (entity is Mobile mob) + { AddMobile(mob); + } } while (_deleteQueue.Count > 0) @@ -535,9 +569,13 @@ namespace Server var entity = _deleteQueue.Dequeue(); if (entity is Item item) + { item.Delete(); + } else if (entity is Mobile mob) + { mob.Delete(); + } } } @@ -564,13 +602,19 @@ namespace Server private static void SaveIndex(List list, string path) where T : IEntityEntry { if (!Directory.Exists("Saves/Mobiles/")) + { Directory.CreateDirectory("Saves/Mobiles/"); + } if (!Directory.Exists("Saves/Items/")) + { Directory.CreateDirectory("Saves/Items/"); + } if (!Directory.Exists("Saves/Guilds/")) + { Directory.CreateDirectory("Saves/Guilds/"); + } using var idx = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); var idxWriter = new BinaryWriter(idx); @@ -598,7 +642,9 @@ namespace Server public static void Save(bool message, bool permitBackgroundWrite) { if (Saving) + { return; + } ++m_Saves; @@ -611,7 +657,9 @@ namespace Server m_DiskWriteHandle.Reset(); if (message) + { Broadcast(0x35, true, "The world is saving, please wait."); + } var strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLower()); @@ -621,11 +669,19 @@ namespace Server var watch = Stopwatch.StartNew(); if (!Directory.Exists("Saves/Mobiles/")) + { Directory.CreateDirectory("Saves/Mobiles/"); + } + if (!Directory.Exists("Saves/Items/")) + { Directory.CreateDirectory("Saves/Items/"); + } + if (!Directory.Exists("Saves/Guilds/")) + { Directory.CreateDirectory("Saves/Guilds/"); + } strategy.Save(permitBackgroundWrite); @@ -643,7 +699,9 @@ namespace Server Saving = false; if (!permitBackgroundWrite) + { NotifyDiskWriteComplete(); // Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies. + } ProcessSafetyQueues(); @@ -652,12 +710,14 @@ namespace Server Console.WriteLine("Save done in {0:F2} seconds.", watch.Elapsed.TotalSeconds); if (message) + { Broadcast( 0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds ); + } NetState.Resume(); } @@ -665,9 +725,14 @@ namespace Server public static IEntity FindEntity(Serial serial) { if (serial.IsItem) + { return FindItem(serial); + } + if (serial.IsMobile) + { return FindMobile(serial); + } return null; } diff --git a/Projects/UOContent/Accounting/Security/AccountSecurity.cs b/Projects/UOContent/Accounting/Security/AccountSecurity.cs index dbc890a6f..45bd06e34 100644 --- a/Projects/UOContent/Accounting/Security/AccountSecurity.cs +++ b/Projects/UOContent/Accounting/Security/AccountSecurity.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: AccountSecurity.cs * * * diff --git a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs index 793357974..39e836e8e 100644 --- a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: Argon2PasswordProtection.cs * * * diff --git a/Projects/UOContent/Accounting/Security/MD5PasswordProtection.cs b/Projects/UOContent/Accounting/Security/MD5PasswordProtection.cs index 423d3a170..33f220489 100644 --- a/Projects/UOContent/Accounting/Security/MD5PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/MD5PasswordProtection.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: MD5PasswordProtection.cs * * * diff --git a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs index b88aa25fb..d8b64a8f1 100644 --- a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: PBKDF2PasswordProtection.cs * * * diff --git a/Projects/UOContent/Accounting/Security/SHA1PasswordProtection.cs b/Projects/UOContent/Accounting/Security/SHA1PasswordProtection.cs index ae88dfa85..36c29aa64 100644 --- a/Projects/UOContent/Accounting/Security/SHA1PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/SHA1PasswordProtection.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SHA1PasswordProtection.cs * * * diff --git a/Projects/UOContent/Accounting/Security/SHA2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/SHA2PasswordProtection.cs index 6dc2fdf0e..8cbd9ea9e 100644 --- a/Projects/UOContent/Accounting/Security/SHA2PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/SHA2PasswordProtection.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: SHA2PasswordProtection.cs * * * diff --git a/Projects/UOContent/Commands/Object Creation/CAGCategory.cs b/Projects/UOContent/Commands/Object Creation/CAGCategory.cs index 93b39ef4f..79cc93f6b 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGCategory.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGCategory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CAGCategory.cs * * * diff --git a/Projects/UOContent/Commands/Object Creation/CAGLoader.cs b/Projects/UOContent/Commands/Object Creation/CAGLoader.cs index baee39455..584595ee1 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGLoader.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGLoader.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CAGLoader.cs * * * diff --git a/Projects/UOContent/Commands/Object Creation/CAGNode.cs b/Projects/UOContent/Commands/Object Creation/CAGNode.cs index a7d0cc5e8..db38c388c 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGNode.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGNode.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CAGNode.cs * * * diff --git a/Projects/UOContent/Commands/Object Creation/CAGObject.cs b/Projects/UOContent/Commands/Object Creation/CAGObject.cs index cee0cbdd7..f65f089b5 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGObject.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGObject.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CAGObject.cs * * * diff --git a/Projects/UOContent/Configuration/EmailConfiguration.cs b/Projects/UOContent/Configuration/EmailConfiguration.cs index 48200de4d..2a852c3d9 100644 --- a/Projects/UOContent/Configuration/EmailConfiguration.cs +++ b/Projects/UOContent/Configuration/EmailConfiguration.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: EmailConfiguration.cs * * * diff --git a/Projects/UOContent/Items/Construction/Doors/BaseDoor.cs b/Projects/UOContent/Items/Construction/Doors/BaseDoor.cs index 8ce8d5a7d..7e2461e2b 100644 --- a/Projects/UOContent/Items/Construction/Doors/BaseDoor.cs +++ b/Projects/UOContent/Items/Construction/Doors/BaseDoor.cs @@ -117,7 +117,6 @@ namespace Server.Items Use(from); } - // Called by RunUO public static void Initialize() { EventSink.OpenDoorMacroUsed += EventSink_OpenDoorMacroUsed; diff --git a/Projects/UOContent/Items/Special/Veteran Rewards/MiningCart.cs b/Projects/UOContent/Items/Special/Veteran Rewards/MiningCart.cs index b6d660b01..ffcf0a83d 100644 --- a/Projects/UOContent/Items/Special/Veteran Rewards/MiningCart.cs +++ b/Projects/UOContent/Items/Special/Veteran Rewards/MiningCart.cs @@ -185,9 +185,9 @@ namespace Server.Items case MiningCartType.GemEast: if (Gems > 0) { - var gems = Utility.Random(15) switch + Item gems = Utility.Random(15) switch { - 0 => (Item)new Amber(), + 0 => new Amber(), 1 => new Amethyst(), 2 => new Citrine(), 3 => new Diamond(), @@ -196,14 +196,14 @@ namespace Server.Items 6 => new Sapphire(), 7 => new StarSapphire(), 8 => new Tourmaline(), + // Mondain's Legacy gems 9 => new PerfectEmerald(), 10 => new DarkSapphire(), 11 => new Turquoise(), 12 => new EcruCitrine(), 13 => new FireRuby(), - 14 => new BlueDiamond(), - _ => null + _ => new BlueDiamond() // 14 }; var amount = Math.Min(5, Gems); diff --git a/Projects/UOContent/Json/Converters/TextDefinitionConverter.cs b/Projects/UOContent/Json/Converters/TextDefinitionConverter.cs index 875346da5..b675f24b0 100644 --- a/Projects/UOContent/Json/Converters/TextDefinitionConverter.cs +++ b/Projects/UOContent/Json/Converters/TextDefinitionConverter.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TextDefinitionConverter.cs * * * diff --git a/Projects/UOContent/Json/Converters/TextDefinitionConverterFactory.cs b/Projects/UOContent/Json/Converters/TextDefinitionConverterFactory.cs index f82430b34..01dc9a1b7 100644 --- a/Projects/UOContent/Json/Converters/TextDefinitionConverterFactory.cs +++ b/Projects/UOContent/Json/Converters/TextDefinitionConverterFactory.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright (C) 2019-2020 - ModernUO Development Team * + * Copyright 2019-2020 - ModernUO Development Team * * Email: hi@modernuo.com * * File: TextDefinitionConverterFactory.cs * * * diff --git a/Projects/UOContent/Misc/ResourceInfo.cs b/Projects/UOContent/Misc/ResourceInfo.cs index a6930ecbb..ef48edec3 100644 --- a/Projects/UOContent/Misc/ResourceInfo.cs +++ b/Projects/UOContent/Misc/ResourceInfo.cs @@ -395,7 +395,9 @@ namespace Server.Items ResourceTypes = resourceTypes; for (var i = 0; i < resourceTypes.Length; ++i) + { CraftResources.RegisterType(resourceTypes[i], resource); + } } public int Hue { get; } @@ -723,7 +725,9 @@ namespace Server.Items public static void RegisterType(Type resourceType, CraftResource resource) { if (m_TypeTable == null) + { m_TypeTable = new Dictionary(); + } m_TypeTable[resourceType] = resource; } @@ -735,7 +739,9 @@ namespace Server.Items public static CraftResource GetFromType(Type resourceType) { if (m_TypeTable == null) + { return CraftResource.None; + } return m_TypeTable.TryGetValue(resourceType, out var res) ? res : CraftResource.None; } @@ -760,7 +766,9 @@ namespace Server.Items var index = GetIndex(resource); if (index >= 0 && index < list.Length) + { return list[index]; + } } return null; @@ -772,16 +780,24 @@ namespace Server.Items public static CraftResourceType GetType(CraftResource resource) { if (resource >= CraftResource.Iron && resource <= CraftResource.Valorite) + { return CraftResourceType.Metal; + } if (resource >= CraftResource.RegularLeather && resource <= CraftResource.BarbedLeather) + { return CraftResourceType.Leather; + } if (resource >= CraftResource.RedScales && resource <= CraftResource.BlueScales) + { return CraftResourceType.Scales; + } if (resource >= CraftResource.RegularWood && resource <= CraftResource.Frostwood) + { return CraftResourceType.Wood; + } return CraftResourceType.None; } @@ -810,7 +826,9 @@ namespace Server.Items var start = GetStart(resource); if (start == CraftResource.None) + { return 0; + } return resource - start; } @@ -855,32 +873,69 @@ namespace Server.Items public static CraftResource GetFromOreInfo(OreInfo info) { if (info.Name.IndexOf("Spined") >= 0) + { return CraftResource.SpinedLeather; + } + if (info.Name.IndexOf("Horned") >= 0) + { return CraftResource.HornedLeather; + } + if (info.Name.IndexOf("Barbed") >= 0) + { return CraftResource.BarbedLeather; + } + if (info.Name.IndexOf("Leather") >= 0) + { return CraftResource.RegularLeather; + } if (info.Level == 0) + { return CraftResource.Iron; + } + if (info.Level == 1) + { return CraftResource.DullCopper; + } + if (info.Level == 2) + { return CraftResource.ShadowIron; + } + if (info.Level == 3) + { return CraftResource.Copper; + } + if (info.Level == 4) + { return CraftResource.Bronze; + } + if (info.Level == 5) + { return CraftResource.Gold; + } + if (info.Level == 6) + { return CraftResource.Agapite; + } + if (info.Level == 7) + { return CraftResource.Verite; + } + if (info.Level == 8) + { return CraftResource.Valorite; + } return CraftResource.None; } @@ -896,13 +951,24 @@ namespace Server.Items material == ArmorMaterialType.Horned || material == ArmorMaterialType.Barbed) { if (info.Level == 0) + { return CraftResource.RegularLeather; + } + if (info.Level == 1) + { return CraftResource.SpinedLeather; + } + if (info.Level == 2) + { return CraftResource.HornedLeather; + } + if (info.Level == 3) + { return CraftResource.BarbedLeather; + } return CraftResource.None; } @@ -911,7 +977,7 @@ namespace Server.Items } } - // NOTE: This class is only for compatability with very old RunUO versions. + // NOTE: This class is only for compatibility with very old RunUO versions. // No changes to it should be required for custom resources. public class OreInfo { diff --git a/Projects/UOContent/Misc/WebStatus.cs b/Projects/UOContent/Misc/WebStatus.cs index b7ea82ab1..96d0089ee 100644 --- a/Projects/UOContent/Misc/WebStatus.cs +++ b/Projects/UOContent/Misc/WebStatus.cs @@ -107,7 +107,7 @@ namespace Server.Misc op.WriteLine(" tr.even td { background: #DDD; color: #222; }"); op.WriteLine(" "); op.WriteLine(" "); - op.WriteLine("

RunUO Server Status

"); + op.WriteLine("

ModernUO Server Status

"); op.WriteLine("

Online clients

"); op.WriteLine(" "); op.WriteLine( diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index a1210c35a..70c69179a 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -278,7 +278,9 @@ namespace Server.Mobiles get { if (Core.ML && Race == Race.Human) + { return 20.0; + } return 0; } @@ -296,7 +298,9 @@ namespace Server.Mobiles var ts = m_SavagePaintExpiration - DateTime.UtcNow; if (ts < TimeSpan.Zero) + { ts = TimeSpan.Zero; + } return ts; } @@ -311,7 +315,9 @@ namespace Server.Mobiles var ts = m_NextSmithBulkOrder - DateTime.UtcNow; if (ts < TimeSpan.Zero) + { ts = TimeSpan.Zero; + } return ts; } @@ -336,7 +342,9 @@ namespace Server.Mobiles var ts = m_NextTailorBulkOrder - DateTime.UtcNow; if (ts < TimeSpan.Zero) + { ts = TimeSpan.Zero; + } return ts; } @@ -376,7 +384,10 @@ namespace Server.Mobiles get { if (NetState != null) + { return m_GameTime + (DateTime.UtcNow - SessionStart); + } + return m_GameTime; } } @@ -394,9 +405,13 @@ namespace Server.Mobiles base.Paralyzed = value; if (value) + { AddBuff(new BuffInfo(BuffIcon.Paralyze, 1075827)); // Paralyze/You are frozen and can not move + } else + { RemoveBuff(BuffIcon.Paralyze); + } } } @@ -599,11 +614,15 @@ namespace Server.Mobiles strOffs = AosAttributes.GetValue(this, AosAttribute.BonusHits); if (Core.ML && strOffs > 25 && AccessLevel <= AccessLevel.Player) + { strOffs = 25; + } if (AnimalForm.UnderTransformation(this, typeof(BakeKitsune)) || AnimalForm.UnderTransformation(this, typeof(GreyWolf))) + { strOffs += 20; + } } else { @@ -627,7 +646,9 @@ namespace Server.Mobiles get { if (Core.ML && AccessLevel == AccessLevel.Player) + { return Math.Min(base.Str, 150); + } return base.Str; } @@ -640,7 +661,9 @@ namespace Server.Mobiles get { if (Core.ML && AccessLevel == AccessLevel.Player) + { return Math.Min(base.Int, 150); + } return base.Int; } @@ -653,7 +676,9 @@ namespace Server.Mobiles get { if (Core.ML && AccessLevel == AccessLevel.Player) + { return Math.Min(base.Dex, 150); + } return base.Dex; } @@ -676,7 +701,9 @@ namespace Server.Mobiles var isInTourney = DuelContext?.Finished == false && DuelContext.m_Tournament != null; if (wasInTourney != isInTourney) + { SendEverything(); + } } } @@ -687,8 +714,6 @@ namespace Server.Mobiles [CommandProperty(AccessLevel.GameMaster)] public SolenFriendship SolenFriendship { get; set; } - public bool ChangedMyRunUO { get; set; } - public virtual bool UsesFastwalkPrevention => AccessLevel < AccessLevel.Counselor; public Type EnemyOfOneType @@ -700,7 +725,9 @@ namespace Server.Mobiles var newType = value; if (oldType == newType) + { return; + } m_EnemyOfOneType = value; @@ -769,7 +796,10 @@ namespace Server.Mobiles public override void ToggleFlying() { - if (Race != Race.Gargoyle) return; + if (Race != Race.Gargoyle) + { + return; + } if (Flying) { @@ -818,7 +848,9 @@ namespace Server.Mobiles { // No message? if (Spell is FlySpell spell) + { spell.Stop(); + } new FlySpell(this).Cast(); } @@ -841,13 +873,21 @@ namespace Server.Mobiles Direction ret; if (rx >= 0 && ry >= 0) + { ret = Direction.West; + } else if (rx >= 0 && ry < 0) + { ret = Direction.South; + } else if (rx < 0 && ry < 0) + { ret = Direction.East; + } else + { ret = Direction.North; + } return ret; } @@ -855,7 +895,9 @@ namespace Server.Mobiles public override bool OnDroppedItemToWorld(Item item, Point3D location) { if (!base.OnDroppedItemToWorld(item, location)) + { return false; + } if (Core.AOS) { @@ -869,7 +911,9 @@ namespace Server.Mobiles mobiles.Free(); if (found) + { return false; + } mobiles.Free(); } @@ -886,6 +930,7 @@ namespace Server.Mobiles var objs = type.GetCustomAttributes(typeof(FlippableAttribute), true); if (objs.Length > 0) + { if (objs[0] is FlippableAttribute fp) { var itemIDs = fp.ItemIDs; @@ -898,6 +943,7 @@ namespace Server.Mobiles var dir = GetDirection4(oldWorldLoc, newWorldLoc); if (itemIDs.Length == 2) + { item.ItemID = dir switch { Direction.North => itemIDs[0], @@ -906,7 +952,9 @@ namespace Server.Mobiles Direction.West => itemIDs[1], _ => item.ItemID }; + } else if (itemIDs.Length == 4) + { item.ItemID = dir switch { Direction.South => itemIDs[0], @@ -915,8 +963,10 @@ namespace Server.Mobiles Direction.West => itemIDs[3], _ => item.ItemID }; + } } } + } } } @@ -928,7 +978,9 @@ namespace Server.Mobiles var flags = base.GetPacketFlags(); if (m_IgnoreMobiles) + { flags |= 0x10; + } return flags; } @@ -938,7 +990,9 @@ namespace Server.Mobiles var flags = base.GetOldPacketFlags(); if (m_IgnoreMobiles) + { flags |= 0x10; + } return flags; } @@ -948,15 +1002,21 @@ namespace Server.Mobiles public void SetFlag(PlayerFlag flag, bool value) { if (value) + { Flags |= flag; + } else + { Flags &= ~flag; + } } public static void Initialize() { if (FastwalkPrevention) + { PacketHandlers.RegisterThrottler(0x02, MovementThrottle_Callback); + } EventSink.Login += OnLogin; EventSink.Logout += OnLogout; @@ -967,26 +1027,37 @@ namespace Server.Mobiles EventSink.EquipMacro += EquipMacro; EventSink.UnequipMacro += UnequipMacro; - if (Core.SE) Timer.DelayCall(CheckPets); + if (Core.SE) + { + Timer.DelayCall(CheckPets); + } } private static void TargetedSkillUse(Mobile from, IEntity target, int skillId) { if (from == null || target == null) + { return; + } from.TargetLocked = true; if (skillId == 35) + { AnimalTaming.DisableMessage = true; + } // AnimalTaming.DeferredTarget = false; if (from.UseSkill(skillId)) - from.Target?.Invoke(from, target); + { + @from.Target?.Invoke(@from, target); + } if (skillId == 35) // AnimalTaming.DeferredTarget = true; + { AnimalTaming.DisableMessage = false; + } from.TargetLocked = false; } @@ -1000,7 +1071,10 @@ namespace Server.Mobiles foreach (var serial in list) { var item = pack.Items.FirstOrDefault(i => i.Serial == serial); - if (item == null) continue; + if (item == null) + { + continue; + } var toMove = pm.FindItemOnLayer(item.Layer); @@ -1010,9 +1084,13 @@ namespace Server.Mobiles toMove.Internalize(); if (!pm.EquipItem(item)) + { pm.EquipItem(toMove); + } else + { pack.DropItem(toMove); + } } else { @@ -1033,7 +1111,9 @@ namespace Server.Mobiles { var item = eq[i]; if (layers.Contains(item.Layer)) + { pack.TryDropItem(pm, item, false); + } } } } @@ -1041,10 +1121,14 @@ namespace Server.Mobiles private static void CheckPets() { foreach (var m in World.Mobiles.Values) + { if (m is PlayerMobile pm && ((!pm.Mounted || pm.Mount is EtherealMount) && pm.AllFollowers.Count > pm.AutoStabled.Count || pm.Mounted && pm.AllFollowers.Count > pm.AutoStabled.Count + 1)) + { pm.AutoStablePets(); /* autostable checks summons, et al: no need here */ + } + } } private static bool CheckBlock(MountBlock block) => block?.m_Timer.Running == true; @@ -1054,33 +1138,47 @@ namespace Server.Mobiles if (dismount) { if (Mount != null) + { Mount.Rider = null; + } else if (AnimalForm.UnderTransformation(this)) + { AnimalForm.RemoveContext(this, true); + } } if (m_MountBlock?.m_Timer.Running != true || m_MountBlock.m_Timer.Next < DateTime.UtcNow + duration) + { m_MountBlock = new MountBlock(duration, type, this); + } } public override void OnSkillInvalidated(Skill skill) { if (Core.AOS && skill.SkillName == SkillName.MagicResist) + { UpdateResistances(); + } } public override int GetMaxResistance(ResistanceType type) { if (AccessLevel > AccessLevel.Player) + { return 100; + } var max = base.GetMaxResistance(type); if (type != ResistanceType.Physical && max > 60 && CurseSpell.UnderEffect(this)) + { max = 60; + } if (Core.ML && Race == Race.Elf && type == ResistanceType.Energy) + { max += 5; // Intended to go after the 60 max from curse + } return max; } @@ -1104,9 +1202,13 @@ namespace Server.Mobiles var racialNightSight = Core.ML && Race == Race.Elf; if (LightLevel < 21 && (AosAttributes.GetValue(this, AosAttribute.NightSight) > 0 || racialNightSight)) + { personal = 21; + } else + { personal = LightLevel; + } } public override void CheckLightLevels(bool forceResend) @@ -1114,15 +1216,21 @@ namespace Server.Mobiles var ns = NetState; if (ns == null) + { return; + } ComputeLightLevels(out var global, out var personal); if (!forceResend) + { forceResend = global != m_LastGlobalLight || personal != m_LastPersonalLight; + } if (!forceResend) + { return; + } m_LastGlobalLight = global; m_LastPersonalLight = personal; @@ -1137,11 +1245,17 @@ namespace Server.Mobiles int min; if (magicResist >= 1000) + { min = 40 + (magicResist - 1000) / 50; + } else if (magicResist >= 400) + { min = (magicResist - 400) / 15; + } else + { min = int.MinValue; + } return Math.Clamp(min, base.GetMinResistance(type), MaxPlayerResistance); } @@ -1150,8 +1264,12 @@ namespace Server.Mobiles { base.OnManaChange(oldValue); if (ExecutesLightningStrike > 0) + { if (Mana < ExecutesLightningStrike) + { SpecialMove.ClearCurrentMove(this); + } + } } private static void OnLogin(Mobile from) @@ -1165,13 +1283,19 @@ namespace Server.Mobiles if (!(from.Account is Account acct) || !acct.HasAccess(from.NetState)) { if (from.AccessLevel == AccessLevel.Player) + { notice = "The server is currently under lockdown. No players are allowed to log in at this time."; + } else + { notice = "The server is currently under lockdown. You do not have sufficient access level to connect."; + } if (from.NetState != null) - Timer.DelayCall(TimeSpan.FromSeconds(1.0), from.NetState.Dispose); + { + Timer.DelayCall(TimeSpan.FromSeconds(1.0), @from.NetState.Dispose); + } } else if (from.AccessLevel >= AccessLevel.Administrator) { @@ -1188,16 +1312,22 @@ namespace Server.Mobiles } if (from is PlayerMobile mobile) + { mobile.ClaimAutoStabledPets(); + } } public void ValidateEquipment() { if (m_NoDeltaRecursion || Map == null || Map == Map.Internal) + { return; + } if (Items == null) + { return; + } m_NoDeltaRecursion = true; Timer.DelayCall(ValidateEquipment_Sandbox); @@ -1208,12 +1338,16 @@ namespace Server.Mobiles try { if (Map == null || Map == Map.Internal) + { return; + } var items = Items; if (items == null) + { return; + } var moved = false; @@ -1230,7 +1364,9 @@ namespace Server.Mobiles for (var i = items.Count - 1; i >= 0; --i) { if (i >= items.Count) + { continue; + } var item = items[i]; @@ -1266,13 +1402,21 @@ namespace Server.Mobiles var drop = false; if (dex < weapon.DexRequirement) + { drop = true; + } else if (str < AOS.Scale(weapon.StrRequirement, 100 - weapon.GetLowerStatReq())) + { drop = true; + } else if (intel < weapon.IntRequirement) + { drop = true; + } else if (weapon.RequiredRace != null && weapon.RequiredRace != Race) + { drop = true; + } if (drop) { @@ -1307,11 +1451,17 @@ namespace Server.Mobiles int intBonus = armor.ComputeStatBonus(StatType.Int), intReq = armor.ComputeStatReq(StatType.Int); if (dex < dexReq || dex + dexBonus < 1) + { drop = true; + } else if (str < strReq || str + strBonus < 1) + { drop = true; + } else if (intel < intReq || intel + intBonus < 1) + { drop = true; + } } if (drop) @@ -1319,9 +1469,13 @@ namespace Server.Mobiles var name = armor.Name ?? $"#{armor.LabelNumber}"; if (armor is BaseShield) - from.SendLocalizedMessage(1062003, name); // You can no longer equip your ~1_SHIELD~ + { + @from.SendLocalizedMessage(1062003, name); // You can no longer equip your ~1_SHIELD~ + } else - from.SendLocalizedMessage(1062002, name); // You can no longer wear your ~1_ARMOR~ + { + @from.SendLocalizedMessage(1062002, name); // You can no longer wear your ~1_ARMOR~ + } from.AddToBackpack(armor); moved = true; @@ -1349,7 +1503,9 @@ namespace Server.Mobiles var strReq = clothing.ComputeStatReq(StatType.Str); if (str < strReq || str + strBonus < 1) + { drop = true; + } } if (drop) @@ -1373,9 +1529,13 @@ namespace Server.Mobiles var ourFaction = Faction.Find(this); if (ourFaction == null || ourFaction != factionItem.Faction) + { drop = true; + } else if (++factionItemCount > FactionItem.GetMaxWearables(this)) + { drop = true; + } if (drop) { @@ -1386,7 +1546,9 @@ namespace Server.Mobiles } if (moved) - from.SendLocalizedMessage(500647); // Some equipment has been moved to your backpack. + { + @from.SendLocalizedMessage(500647); // Some equipment has been moved to your backpack. + } } catch (Exception e) { @@ -1403,7 +1565,9 @@ namespace Server.Mobiles base.Delta(flag); if ((flag & MobileDelta.Stat) != 0) + { ValidateEquipment(); + } } private static void OnLogout(Mobile m) @@ -1447,10 +1611,14 @@ namespace Server.Mobiles from.RevealingAction(); foreach (var item in context.Foundation.GetItems()) + { item.Location = context.Foundation.BanLocation; + } foreach (var mobile in context.Foundation.GetMobiles()) + { mobile.Location = context.Foundation.BanLocation; + } // Restore relocated entities context.Foundation.RestoreRelocatedEntities(); @@ -1472,7 +1640,9 @@ namespace Server.Mobiles public override void RevealingAction() { if (DesignContext != null) + { return; + } InvisibilitySpell.RemoveTimer(this); @@ -1491,12 +1661,16 @@ namespace Server.Mobiles ); // Always remove, default to the hiding icon EXCEPT in the invis spell where it's explicitly set if (!Hidden) + { RemoveBuff(BuffIcon.HidingAndOrStealth); + } else // if (!InvisibilitySpell.HasTimer( this )) + { BuffInfo.AddBuff( this, new BuffInfo(BuffIcon.HidingAndOrStealth, 1075655) ); // Hidden/Stealthing & You Are Hidden + } } public override void OnSubItemAdded(Item item) @@ -1507,7 +1681,9 @@ namespace Server.Mobiles var curWeight = BodyWeight + TotalWeight; if (curWeight > maxWeight) + { SendLocalizedMessage(1019035, true, $" : {curWeight} / {maxWeight}"); + } } base.OnSubItemAdded(item); @@ -1516,16 +1692,22 @@ namespace Server.Mobiles public override bool CanBeHarmful(Mobile target, bool message, bool ignoreOurBlessedness) { if (DesignContext != null || target is PlayerMobile mobile && mobile.DesignContext != null) + { return false; + } if (target is BaseCreature creature && creature.IsInvulnerable || target is PlayerVendor || target is TownCrier) { if (message) { if (target.Title == null) + { SendMessage("{0} cannot be harmed.", target.Name); + } else + { SendMessage("{0} {1} cannot be harmed.", target.Name, target.Title); + } } return false; @@ -1537,7 +1719,9 @@ namespace Server.Mobiles public override bool CanBeBeneficial(Mobile target, bool message, bool allowDead) { if (DesignContext != null || target is PlayerMobile mobile && mobile.DesignContext != null) + { return false; + } return base.CanBeBeneficial(target, message, allowDead); } @@ -1556,7 +1740,9 @@ namespace Server.Mobiles } if (NetState != null) + { CheckLightLevels(false); + } } public override void OnItemRemoved(Item item) @@ -1571,13 +1757,17 @@ namespace Server.Mobiles } if (NetState != null) + { CheckLightLevels(false); + } } private void AddArmorRating(ref double rating, Item armor) { if (armor is BaseArmor ar && (!Core.AOS || ar.ArmorAttributes.MageArmor == 0)) + { rating += ar.ArmorRatingScaled; + } } public override bool Move(Direction d) @@ -1585,6 +1775,7 @@ namespace Server.Mobiles var ns = NetState; if (ns != null) + { if (HasGump()) { if (Alive) @@ -1597,20 +1788,25 @@ namespace Server.Mobiles return false; } } + } var speed = ComputeMovementSpeed(d); bool res; if (!Alive) + { MovementImpl.IgnoreMovableImpassables = true; + } res = base.Move(d); MovementImpl.IgnoreMovableImpassables = false; if (!res) + { return false; + } m_NextMovementTime += speed; @@ -1622,7 +1818,9 @@ namespace Server.Mobiles var context = DesignContext; if (context == null) + { return base.CheckMovement(d, out newZ); + } var foundation = context.Foundation; @@ -1642,7 +1840,9 @@ namespace Server.Mobiles public override bool AllowItemUse(Item item) { if (DuelContext?.AllowItemUse(this, item) == false) + { return false; + } return DesignContext.Check(this); } @@ -1650,15 +1850,21 @@ namespace Server.Mobiles public override bool AllowSkillUse(SkillName skill) { if (AnimalForm.UnderTransformation(this)) + { for (var i = 0; i < AnimalFormRestrictedSkills.Length; i++) + { if (AnimalFormRestrictedSkills[i] == skill) { SendLocalizedMessage(1070771); // You cannot use that skill in this form. return false; } + } + } if (DuelContext?.AllowSkillUse(this, skill) == false) + { return false; + } return DesignContext.Check(this); } @@ -1673,9 +1879,13 @@ namespace Server.Mobiles if (isProtected != m_LastProtectedMessage) { if (isProtected) + { SendLocalizedMessage(500112); // You are now under the protection of the town guards. + } else + { SendLocalizedMessage(500113); // You have left the protection of the town guards. + } m_LastProtectedMessage = isProtected; } @@ -1696,13 +1906,17 @@ namespace Server.Mobiles var zDrop = Location.Z - loc.Z; if (zDrop > 20) // we fell more than one story + { Hits -= zDrop / 20 * 10 - 5; // deal some damage; does not kill, disrupt, etc + } } base.SetLocation(loc, isTeleport); if (isTeleport || --m_NextProtectionCheck == 0) + { RecheckTownProtection(); + } } public override void GetContextMenuEntries(Mobile from, List list) @@ -1718,31 +1932,39 @@ namespace Server.Mobiles if (InsuranceEnabled) { if (Core.SA) + { list.Add(new CallbackEntry(1114299, OpenItemInsuranceMenu)); // Open Item Insurance Menu + } list.Add(new CallbackEntry(6201, ToggleItemInsurance)); // Toggle Item Insurance if (!Core.SA) { if (AutoRenewInsurance) + { list.Add( new CallbackEntry( 6202, CancelRenewInventoryInsurance ) ); // Cancel Renewing Inventory Insurance + } else + { list.Add( new CallbackEntry( 6200, AutoRenewInventoryInsurance ) ); // Auto Renew Inventory Insurance + } } } if (MLQuestSystem.Enabled) + { list.Add(new CallbackEntry(6169, ToggleQuestItem)); // Toggle Quest Item + } } var house = BaseHouse.FindHouseAt(this); @@ -1750,34 +1972,47 @@ namespace Server.Mobiles if (house != null) { if (Alive && house.InternalizedVendors.Count > 0 && house.IsOwner(this)) + { list.Add(new CallbackEntry(6204, GetVendor)); + } if (house.IsAosRules && !Region.IsPartOf()) // Dueling + { list.Add(new CallbackEntry(6207, LeaveHouse)); + } } if (JusticeProtectors.Count > 0) + { list.Add(new CallbackEntry(6157, CancelProtection)); + } if (Alive) + { list.Add(new CallbackEntry(6210, ToggleChampionTitleDisplay)); + } if (Core.HS) { var ns = from.NetState; if (ns?.ExtendedStatus == true) + { list.Add( new CallbackEntry( RefuseTrades ? 1154112 : 1154113, ToggleTrades ) ); // Allow Trades / Refuse Trades + } } } else { - if (Core.TOL && from.InRange(this, 2)) list.Add(new CallbackEntry(1077728, () => OpenTrade(from))); // Trade + if (Core.TOL && from.InRange(this, 2)) + { + list.Add(new CallbackEntry(1077728, () => OpenTrade(@from))); // Trade + } if (Alive && Core.Expansion >= Expansion.AOS) { @@ -1791,8 +2026,13 @@ namespace Server.Mobiles else if (theirParty != null && theirParty.Leader == from) { if (ourParty == null) - list.Add(new AddToPartyEntry(from, this)); - else if (ourParty == theirParty) list.Add(new RemoveFromPartyEntry(from, this)); + { + list.Add(new AddToPartyEntry(@from, this)); + } + else if (ourParty == theirParty) + { + list.Add(new RemoveFromPartyEntry(@from, this)); + } } } @@ -1800,7 +2040,9 @@ namespace Server.Mobiles if (curhouse != null && Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules && curhouse.IsFriend(from)) - list.Add(new EjectPlayerEntry(from, this)); + { + list.Add(new EjectPlayerEntry(@from, this)); + } } } @@ -1846,13 +2088,17 @@ namespace Server.Mobiles var house = BaseHouse.FindHouseAt(this); if (house != null) + { Location = house.BanLocation; + } } public override void DisruptiveAction() { if (Meditating) + { RemoveBuff(BuffIcon.ActiveMeditation); + } base.DisruptiveAction(); } @@ -1864,7 +2110,9 @@ namespace Server.Mobiles var mount = Mount; if (mount != null && !DesignContext.Check(this)) + { return; + } } base.OnDoubleClick(from); @@ -1873,16 +2121,22 @@ namespace Server.Mobiles public override void DisplayPaperdollTo(Mobile to) { if (DesignContext.Check(this)) + { base.DisplayPaperdollTo(to); + } } public override bool CheckEquip(Item item) { if (!base.CheckEquip(item)) + { return false; + } if (DuelContext?.AllowItemEquip(this, item) == false) + { return false; + } var factionItem = FactionItem.Find(item); @@ -1909,11 +2163,13 @@ namespace Server.Mobiles var equipped = Items[i]; if (item != equipped && FactionItem.Find(equipped) != null) + { if (--maxWearables == 0) { SendLocalizedMessage(1010373); // You do not have enough rank to equip more faction items! return false; } + } } } @@ -1926,7 +2182,9 @@ namespace Server.Mobiles if (bounce.Parent is Item parent) { if (parent == Backpack || parent.IsChildOf(Backpack)) + { return true; + } } else if (bounce.Parent == this) { @@ -1953,13 +2211,21 @@ namespace Server.Mobiles if (cont == null) { if (to.Holding != null) + { msgNum = 1062727; // You cannot trade with someone who is dragging something. + } else if (HasTrade) + { msgNum = 1062781; // You are already trading with someone else! + } else if (to.HasTrade) + { msgNum = 1062779; // That person is already involved in a trade + } else if (to is PlayerMobile mobile && mobile.RefuseTrades) + { msgNum = 1154111; // ~1_NAME~ is refusing all trades. + } } if (msgNum == 0 && item != null) @@ -1971,11 +2237,17 @@ namespace Server.Mobiles } if (Backpack?.CheckHold(this, item, false, checkItems, plusItems, plusWeight) != true) + { msgNum = 1004040; // You would not be able to hold this if the trade failed. + } else if (to.Backpack?.CheckHold(to, item, false, checkItems, plusItems, plusWeight) != true) + { msgNum = 1004039; // The recipient of this trade would not be able to carry this. + } else + { msgNum = CheckContentForTrade(item); + } } if (msgNum != 0) @@ -1983,9 +2255,13 @@ namespace Server.Mobiles if (message) { if (msgNum == 1154111) + { SendLocalizedMessage(msgNum, to.Name); + } else + { SendLocalizedMessage(msgNum); + } } return false; @@ -1997,19 +2273,27 @@ namespace Server.Mobiles private static int CheckContentForTrade(Item item) { if (item is TrappableContainer container && container.TrapType != TrapType.None) + { return 1004044; // You may not trade trapped items. + } if (StolenItem.IsStolen(item)) + { return 1004043; // You may not trade recently stolen items. + } if (item is Container) + { foreach (var subItem in item.Items) { var msg = CheckContentForTrade(subItem); if (msg != 0) + { return msg; + } } + } return 0; } @@ -2017,10 +2301,14 @@ namespace Server.Mobiles public override bool CheckNonlocalDrop(Mobile from, Item item, Item target) { if (!base.CheckNonlocalDrop(from, item, target)) + { return false; + } if (from.AccessLevel >= AccessLevel.GameMaster) + { return true; + } var pack = Backpack; if (from == this && HasTrade && (target == pack || target.IsChildOf(pack))) @@ -2028,7 +2316,9 @@ namespace Server.Mobiles var bounce = item.GetBounce(); if (bounce?.Parent is Item parent && (parent == pack || parent.IsChildOf(pack))) + { return true; + } SendLocalizedMessage(1004041); // You can't do that while you have a trade pending. return false; @@ -2046,7 +2336,9 @@ namespace Server.Mobiles var context = DesignContext; if (context == null || m_NoRecursion) + { return; + } m_NoRecursion = true; @@ -2063,7 +2355,9 @@ namespace Server.Mobiles if (newX >= startX && newY >= startY && newX < endX && newY < endY && Map == foundation.Map) { if (Z != newZ) + { Location = new Point3D(X, Y, newZ); + } m_NoRecursion = false; return; @@ -2090,21 +2384,27 @@ namespace Server.Mobiles protected override void OnMapChange(Map oldMap) { if (Map != Faction.Facet && oldMap == Faction.Facet || Map == Faction.Facet && oldMap != Faction.Facet) + { InvalidateProperties(); + } DuelContext?.OnMapChanged(this); var context = DesignContext; if (context == null || m_NoRecursion) + { return; + } m_NoRecursion = true; var foundation = context.Foundation; if (Map != foundation.Map) + { Map = foundation.Map; + } m_NoRecursion = false; } @@ -2121,11 +2421,17 @@ namespace Server.Mobiles int disruptThreshold; if (!Core.AOS) + { disruptThreshold = 0; + } else if (from?.Player == true) + { disruptThreshold = 18; + } else + { disruptThreshold = 25; + } if (amount > disruptThreshold) { @@ -2135,7 +2441,9 @@ namespace Server.Mobiles } if (Confidence.IsRegenerating(this)) + { Confidence.StopRegenerating(this); + } WeightOverloading.FatigueOnDamage(this, amount); @@ -2143,7 +2451,9 @@ namespace Server.Mobiles SentHonorContext?.OnSourceDamaged(from, amount); if (willKill && from is PlayerMobile mobile) + { Timer.DelayCall(TimeSpan.FromSeconds(10), mobile.RecoverAmmo); + } base.OnDamage(amount, from, willKill); } @@ -2159,14 +2469,18 @@ namespace Server.Mobiles Item deathRobe = new DeathRobe(); if (!EquipItem(deathRobe)) + { deathRobe.Delete(); + } } } public override void OnWarmodeChanged() { if (!Warmode) + { Timer.DelayCall(TimeSpan.FromSeconds(10), RecoverAmmo); + } } private bool FindItems_Callback(Item item) => @@ -2182,7 +2496,9 @@ namespace Server.Mobiles DropHolding(); if (Core.AOS && Backpack?.Deleted == false) + { Backpack.FindItemsByType(FindItems_Callback).ForEach(item => Backpack.AddItem(item)); + } EquipSnapshot = new List(Items); @@ -2194,14 +2510,20 @@ namespace Server.Mobiles var master = creature.GetMaster(); if (master != null) + { m_InsuranceAward = master; + } } if (m_InsuranceAward != null && (!m_InsuranceAward.Player || m_InsuranceAward == this)) + { m_InsuranceAward = null; + } if (m_InsuranceAward is PlayerMobile mobile) + { mobile.m_InsuranceBonus = 0; + } ReceivedHonorContext?.OnTargetKilled(); SentHonorContext?.OnSourceKilled(); @@ -2214,18 +2536,24 @@ namespace Server.Mobiles private bool CheckInsuranceOnDeath(Item item) { if (!InsuranceEnabled || !item.Insured) + { return false; + } if (DuelContext?.Registered == true && DuelContext.Started && m_DuelPlayer?.Eliminated != true) + { return true; + } if (AutoRenewInsurance) { var cost = GetInsuranceCost(item); if (m_InsuranceAward != null) + { cost /= 2; + } if (Banker.Withdraw(this, cost)) { @@ -2250,7 +2578,9 @@ namespace Server.Mobiles } if (m_InsuranceAward != null && Banker.Deposit(m_InsuranceAward, 300) && m_InsuranceAward is PlayerMobile pm) + { pm.m_InsuranceBonus += 300; + } return true; } @@ -2259,15 +2589,21 @@ namespace Server.Mobiles { // It seems all items are unmarked on death, even blessed/insured ones if (item.QuestItem) + { item.QuestItem = false; + } if (CheckInsuranceOnDeath(item)) + { return DeathMoveResult.MoveToBackpack; + } var res = base.GetParentMoveResultFor(item); if (res == DeathMoveResult.MoveToCorpse && item.Movable && Young) + { res = DeathMoveResult.MoveToBackpack; + } return res; } @@ -2276,22 +2612,31 @@ namespace Server.Mobiles { // It seems all items are unmarked on death, even blessed/insured ones if (item.QuestItem) + { item.QuestItem = false; + } if (CheckInsuranceOnDeath(item)) + { return DeathMoveResult.MoveToBackpack; + } var res = base.GetInventoryMoveResultFor(item); if (res == DeathMoveResult.MoveToCorpse && item.Movable && Young) + { res = DeathMoveResult.MoveToBackpack; + } return res; } public override void OnDeath(Container c) { - if (m_NonAutoreinsuredItems > 0) SendLocalizedMessage(1061115); + if (m_NonAutoreinsuredItems > 0) + { + SendLocalizedMessage(1061115); + } base.OnDeath(c); @@ -2325,10 +2670,14 @@ namespace Server.Mobiles PermaFlags.Clear(); if (c is Corpse corpse) + { corpse.Criminal = true; + } if (Stealing.ClassicMode) + { Criminal = true; + } } if (Kills >= 5 && DateTime.UtcNow >= m_NextJustAward) @@ -2336,7 +2685,9 @@ namespace Server.Mobiles var m = FindMostRecentDamager(false); if (m is BaseCreature bc) + { m = bc.GetMaster(); + } if (m != this && m is PlayerMobile) { @@ -2351,9 +2702,13 @@ namespace Server.Mobiles if (VirtueHelper.Award(m, VirtueName.Justice, pointsToGain, ref gainedPath)) { if (gainedPath) + { m.SendLocalizedMessage(1049367); // You have gained a path in Justice! + } else + { m.SendLocalizedMessage(1049363); // You have gained in Justice. + } m.FixedParticles(0x375A, 9, 20, 5027, EffectLayer.Waist); m.PlaySound(0x1F7); @@ -2364,11 +2719,15 @@ namespace Server.Mobiles } if (m_InsuranceAward is PlayerMobile pm) + { if (pm.m_InsuranceBonus > 0) + { pm.SendLocalizedMessage( 1060397, pm.m_InsuranceBonus.ToString() ); // ~1_AMOUNT~ gold has been deposited into your bank box. + } + } var killer = FindMostRecentDamager(true); @@ -2376,15 +2735,23 @@ namespace Server.Mobiles { var master = bcKiller.GetMaster(); if (master != null) + { killer = master; + } } if (Young && DuelContext == null) + { if (YoungDeathTeleport()) + { Timer.DelayCall(TimeSpan.FromSeconds(2.5), SendYoungDeathNotice); + } + } if (DuelContext?.Registered != true || !DuelContext.Started || m_DuelPlayer?.Eliminated != false) + { Faction.HandleDeath(this, killer); + } Guilds.Guild.HandleDeath(this, killer); @@ -2397,30 +2764,44 @@ namespace Server.Mobiles var list = new List(); foreach (var buff in m_BuffTable.Values) + { if (!buff.RetainThroughDeath) + { list.Add(buff); + } + } for (var i = 0; i < list.Count; i++) + { RemoveBuff(list[i]); + } } } public override bool MutateSpeech(List hears, ref string text, ref object context) { if (Alive) + { return false; + } if (Core.ML && Skills.SpiritSpeak.Value >= 100.0) + { return false; + } if (Core.AOS) + { for (var i = 0; i < hears.Count; ++i) { var m = hears[i]; if (m != this && m.Skills.SpiritSpeak.Value >= 100.0) + { return false; + } } + } return base.MutateSpeech(hears, ref text, ref context); } @@ -2500,7 +2881,9 @@ namespace Server.Mobiles public override void Damage(int amount, Mobile from) { if (EvilOmenSpell.TryEndEffect(this)) + { amount = (int)(amount * 1.25); + } var oath = BloodOathSpell.GetBloodOath(from); @@ -2512,22 +2895,33 @@ namespace Server.Mobiles { amount = (int)(amount * 1.1); - if (amount > 35 && from is PlayerMobile) /* capped @ 35, seems no expansion */ amount = 35; + if (amount > 35 && from is PlayerMobile) /* capped @ 35, seems no expansion */ + { + amount = 35; + } if (Core.ML) - from.Damage((int)(amount * (1 - (from.Skills.MagicResist.Value * .5 + 10) / 100)), this); + { + @from.Damage((int)(amount * (1 - (@from.Skills.MagicResist.Value * .5 + 10) / 100)), this); + } else - from.Damage(amount, this); + { + @from.Damage(amount, this); + } } if (from != null && Talisman is BaseTalisman talisman) + { if (talisman.Protection != null && talisman.Protection.Type != null) { var type = talisman.Protection.Type; - if (type.IsInstanceOfType(from)) + if (type.IsInstanceOfType(@from)) + { amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100)); + } } + } base.Damage(amount, from); } @@ -2537,7 +2931,9 @@ namespace Server.Mobiles if (Stealing.ClassicMode && target is PlayerMobile mobile && mobile.PermaFlags.Count > 0) { if (Notoriety.Compute(this, mobile) == Notoriety.Innocent) + { mobile.Delta(MobileDelta.Noto); + } return false; } @@ -2545,10 +2941,14 @@ namespace Server.Mobiles var bc = target as BaseCreature; if (bc?.InitialInnocent == true && !bc.Controlled) + { return false; + } if (Core.ML && bc?.Controlled == true && this == bc.ControlMaster) + { return false; + } return base.IsHarmfulCriminal(target); } @@ -2556,10 +2956,14 @@ namespace Server.Mobiles public bool AntiMacroCheck(Skill skill, object obj) { if (obj == null || m_AntiMacroTable == null || AccessLevel != AccessLevel.Player) + { return true; + } if (!m_AntiMacroTable.TryGetValue(skill, out var tbl)) + { m_AntiMacroTable[skill] = tbl = new Dictionary(); + } if (tbl.TryGetValue(obj, out var count)) { @@ -2597,7 +3001,10 @@ namespace Server.Mobiles { m_StuckMenuUses = new DateTime[reader.ReadInt()]; - for (var i = 0; i < m_StuckMenuUses.Length; ++i) m_StuckMenuUses[i] = reader.ReadDateTime(); + for (var i = 0; i < m_StuckMenuUses.Length; ++i) + { + m_StuckMenuUses[i] = reader.ReadDateTime(); + } } else { @@ -2636,7 +3043,9 @@ namespace Server.Mobiles { var r = reader.ReadInt(); if (reader.ReadBool()) // Don't add in recipes which we haven't gotten or have been removed + { m_AcquiredRecipes.Add(r, true); + } } } @@ -2675,7 +3084,9 @@ namespace Server.Mobiles var rank = reader.ReadEncodedInt(); var maxRank = RankDefinition.Ranks.Length - 1; if (rank > maxRank) + { rank = maxRank; + } m_GuildRank = RankDefinition.Ranks[rank]; LastOnline = reader.ReadDateTime(); @@ -2693,7 +3104,9 @@ namespace Server.Mobiles Quest = QuestSerializer.DeserializeQuest(reader); if (Quest != null) + { Quest.From = this; + } var count = reader.ReadEncodedInt(); @@ -2707,9 +3120,13 @@ namespace Server.Mobiles DateTime restartTime; if (version < 17) + { restartTime = DateTime.MaxValue; + } else + { restartTime = reader.ReadDateTime(); + } DoneQuests.Add(new QuestRestartInfo(questType, restartTime)); } @@ -2728,7 +3145,9 @@ namespace Server.Mobiles CompassionGains = reader.ReadEncodedInt(); if (CompassionGains > 0) + { NextCompassionDay = reader.ReadDeltaTime(); + } goto case 13; } @@ -2745,7 +3164,9 @@ namespace Server.Mobiles var paid = reader.ReadStrongItemList(); for (var i = 0; i < paid.Count; ++i) + { paid[i].PaidInsurance = true; + } } goto case 10; @@ -2824,7 +3245,10 @@ namespace Server.Mobiles case 0: { if (version < 26) + { AutoStabled = new List(); + } + break; } } @@ -2833,7 +3257,9 @@ namespace Server.Mobiles // Professions weren't verified on 1.0 RC0 if (!CharacterCreation.VerifyProfession(Profession)) + { Profession = 0; + } PermaFlags ??= new List(); JusticeProtectors ??= new List(); @@ -2843,26 +3269,34 @@ namespace Server.Mobiles m_GuildRank ??= RankDefinition.Member; if (LastOnline == DateTime.MinValue && Account != null) + { LastOnline = ((Account)Account).LastLogin; + } ChampionTitles ??= new ChampionTitleInfo(); if (AccessLevel > AccessLevel.Player) + { m_IgnoreMobiles = true; + } var list = Stabled; for (var i = 0; i < list.Count; ++i) + { if (list[i] is BaseCreature bc) { bc.IsStabled = true; bc.StabledBy = this; } + } CheckAtrophies(this); if (Hidden) // Hiding is the only buff where it has an effect that's serialized. + { AddBuff(new BuffInfo(BuffIcon.HidingAndOrStealth, 1075655)); + } } public override void Serialize(IGenericWriter writer) @@ -2875,7 +3309,9 @@ namespace Server.Mobiles .ToList(); foreach (var key in toRemove) + { t.Remove(key); + } } CheckKillDecay(); @@ -2893,7 +3329,9 @@ namespace Server.Mobiles writer.Write(m_StuckMenuUses.Length); for (var i = 0; i < m_StuckMenuUses.Length; ++i) + { writer.Write(m_StuckMenuUses[i]); + } } else { @@ -2961,7 +3399,9 @@ namespace Server.Mobiles writer.WriteEncodedInt(CompassionGains); if (CompassionGains > 0) + { writer.WriteDeltaTime(NextCompassionDay); + } BOBFilter.Serialize(writer); @@ -3011,7 +3451,9 @@ namespace Server.Mobiles ValorVirtue.CheckAtrophy(m); if (m is PlayerMobile mobile) + { ChampionTitleInfo.CheckAtrophy(mobile); + } } public void CheckKillDecay() @@ -3020,14 +3462,18 @@ namespace Server.Mobiles { m_ShortTermElapse += TimeSpan.FromHours(8); if (ShortTermMurders > 0) + { --ShortTermMurders; + } } if (m_LongTermElapse < GameTime) { m_LongTermElapse += TimeSpan.FromHours(40); if (Kills > 0) + { --Kills; + } } } @@ -3040,10 +3486,14 @@ namespace Server.Mobiles public override bool CanSee(Mobile m) { if (m is CharacterStatue statue) + { statue.OnRequestedAnimation(this); + } if (m is PlayerMobile mobile && mobile.VisibilityList.Contains(this)) + { return true; + } if (DuelContext?.Finished == false && DuelContext.m_Tournament != null && m_DuelPlayer?.Eliminated == false) { @@ -3054,11 +3504,15 @@ namespace Server.Mobiles var master = bc.GetMaster(); if (master != null) + { owner = master; + } } if (m.AccessLevel == AccessLevel.Player && owner is PlayerMobile pm && pm.DuelContext != DuelContext) + { return false; + } } return base.CanSee(m); @@ -3067,7 +3521,9 @@ namespace Server.Mobiles public virtual void CheckedAnimate(int action, int frameCount, int repeatCount, bool forward, bool repeat, int delay) { if (!Mounted) + { Animate(action, frameCount, repeatCount, forward, repeat, delay); + } } public override bool CanSee(Item item) => @@ -3101,40 +3557,54 @@ namespace Server.Mobiles var faction = pl.Faction; if (faction.Commander == this) + { list.Add(1042733, faction.Definition.PropName); // Commanding Lord of the ~1_FACTION_NAME~ + } else if (pl.Sheriff != null) + { list.Add( 1042734, "{0}\t{1}", pl.Sheriff.Definition.FriendlyName, faction.Definition.PropName ); // The Sheriff of ~1_CITY~, ~2_FACTION_NAME~ + } else if (pl.Finance != null) + { list.Add( 1042735, "{0}\t{1}", pl.Finance.Definition.FriendlyName, faction.Definition.PropName ); // The Finance Minister of ~1_CITY~, ~2_FACTION_NAME~ + } else if (pl.MerchantTitle != MerchantTitle.None) + { list.Add( 1060776, "{0}\t{1}", MerchantTitles.GetInfo(pl.MerchantTitle).Title, faction.Definition.PropName ); // ~1_val~, ~2_val~ + } else + { list.Add(1060776, "{0}\t{1}", pl.Rank.Title, faction.Definition.PropName); // ~1_val~, ~2_val~ + } } } if (Core.ML) + { for (var i = AllFollowers.Count - 1; i >= 0; i--) + { if (AllFollowers[i] is BaseCreature c && c.ControlOrder == OrderType.Guard) { list.Add(501129); // guarded break; } + } + } } public override void OnSingleClick(Mobile from) @@ -3169,10 +3639,14 @@ namespace Server.Mobiles ascii = true; if (pl.MerchantTitle != MerchantTitle.None) + { text = $"({MerchantTitles.GetInfo(pl.MerchantTitle).Title.String}, {faction.Definition.FriendlyName})"; + } else + { text = $"({pl.Rank.Title.String}, {faction.Definition.FriendlyName})"; + } } var hue = Faction.Find(from) == faction ? 98 : 38; @@ -3187,10 +3661,14 @@ namespace Server.Mobiles protected override bool OnMove(Direction d) { if (!Core.SE) + { return base.OnMove(d); + } if (AccessLevel != AccessLevel.Player) + { return true; + } if (Hidden && DesignContext.Find(this) == null) // Hidden & NOT customizing a house { @@ -3201,7 +3679,9 @@ namespace Server.Mobiles if (running) { if ((AllowedStealthSteps -= 2) <= 0) + { RevealingAction(); + } } else if (AllowedStealthSteps-- <= 0) { @@ -3220,10 +3700,13 @@ namespace Server.Mobiles public void AutoStablePets() { if (Core.SE && AllFollowers.Count > 0) + { for (var i = m_AllFollowers.Count - 1; i >= 0; --i) { if (!(AllFollowers[i] is BaseCreature pet) || pet.ControlMaster == null) + { continue; + } if (pet.Summoned) { @@ -3237,13 +3720,19 @@ namespace Server.Mobiles } if ((pet as IMount)?.Rider != null) + { continue; + } if ((pet is PackLlama || pet is PackHorse || pet is Beetle) && pet.Backpack?.Items.Count > 0) + { continue; + } if (pet is BaseEscortable) + { continue; + } pet.ControlTarget = null; pet.ControlOrder = OrderType.Stay; @@ -3260,12 +3749,15 @@ namespace Server.Mobiles Stabled.Add(pet); AutoStabled.Add(pet); } + } } public void ClaimAutoStabledPets() { if (!Core.SE || AutoStabled.Count <= 0) + { return; + } if (!Alive) { @@ -3278,7 +3770,9 @@ namespace Server.Mobiles for (var i = AutoStabled.Count - 1; i >= 0; --i) { if (!(AutoStabled[i] is BaseCreature pet)) + { continue; + } if (pet.Deleted) { @@ -3286,7 +3780,9 @@ namespace Server.Mobiles pet.StabledBy = null; if (Stabled.Contains(pet)) + { Stabled.Remove(pet); + } continue; } @@ -3296,7 +3792,9 @@ namespace Server.Mobiles pet.SetControlMaster(this); if (pet.Summoned) + { pet.SummonMaster = this; + } pet.ControlTarget = this; pet.ControlOrder = OrderType.Follow; @@ -3309,7 +3807,9 @@ namespace Server.Mobiles pet.Loyalty = BaseCreature.MaxLoyalty; // Wonderfully Happy if (Stabled.Contains(pet)) + { Stabled.Remove(pet); + } } else { @@ -3326,9 +3826,12 @@ namespace Server.Mobiles public void RecoverAmmo() { if (!Core.SE || !Alive) + { return; + } foreach (var kvp in RecoverableAmmo) + { if (kvp.Value > 0) { Item ammo = null; @@ -3343,7 +3846,9 @@ namespace Server.Mobiles } if (ammo == null) + { continue; + } ammo.Amount = kvp.Value; @@ -3357,6 +3862,7 @@ namespace Server.Mobiles PlaceInBackpack(ammo); SendLocalizedMessage(1073504, $"{ammo.Amount}\t{name}"); // You recover ~1_NUM~ ~2_AMMO~. } + } RecoverableAmmo.Clear(); } @@ -3366,7 +3872,9 @@ namespace Server.Mobiles private void ToggleItemInsurance() { if (!CheckAlive()) + { return; + } BeginTarget(-1, false, TargetFlags.None, ToggleItemInsurance_Callback); SendLocalizedMessage(1060868); // Target the item you wish to toggle insurance status on to cancel @@ -3376,19 +3884,29 @@ namespace Server.Mobiles { if (item is Container && !(item is BaseQuiver) || item is BagOfSending || item is KeyRing || item is PotionKeg || item is Sigil) + { return false; + } if (item.Stackable) + { return false; + } if (item.LootType == LootType.Cursed) + { return false; + } if (item.ItemID == 0x204E) // death shroud + { return false; + } if (item.Layer == Layer.Mount) + { return false; + } return item.LootType != LootType.Blessed && item.LootType != LootType.Newbied && item.BlessedFor != this; } @@ -3396,7 +3914,9 @@ namespace Server.Mobiles private void ToggleItemInsurance_Callback(Mobile from, object obj) { if (!CheckAlive()) + { return; + } ToggleItemInsurance_Callback(from, obj as Item, true); } @@ -3406,7 +3926,9 @@ namespace Server.Mobiles if (item?.IsChildOf(this) != true) { if (target) + { BeginTarget(-1, false, TargetFlags.None, ToggleItemInsurance_Callback); + } SendLocalizedMessage( 1060871, @@ -3433,7 +3955,9 @@ namespace Server.Mobiles else if (!CanInsure(item)) { if (target) + { BeginTarget(-1, false, TargetFlags.None, ToggleItemInsurance_Callback); + } SendLocalizedMessage(1060869, "", 0x23); // You cannot insure that } @@ -3477,7 +4001,9 @@ namespace Server.Mobiles private void AutoRenewInventoryInsurance() { if (!CheckAlive()) + { return; + } SendLocalizedMessage( 1060881, @@ -3490,12 +4016,16 @@ namespace Server.Mobiles private void CancelRenewInventoryInsurance() { if (!CheckAlive()) + { return; + } if (Core.SE) { if (!HasGump()) + { SendGump(new CancelRenewInventoryInsuranceGump(this, null)); + } } else { @@ -3511,27 +4041,39 @@ namespace Server.Mobiles private void OpenItemInsuranceMenu() { if (!CheckAlive()) + { return; + } var items = new List(); foreach (var item in Items) + { if (DisplayInItemInsuranceGump(item)) + { items.Add(item); + } + } var pack = Backpack; if (pack != null) + { items.AddRange(pack.FindItemsByType(DisplayInItemInsuranceGump)); + } // TODO: Investigate item sorting CloseGump(); if (items.Count == 0) + { SendLocalizedMessage(1114915, "", 0x35); // None of your current items meet the requirements for insurance. + } else + { SendGump(new ItemInsuranceMenuGump(this, items.ToArray())); + } } private bool DisplayInItemInsuranceGump(Item item) => (item.Visible || AccessLevel >= AccessLevel.GameMaster) && @@ -3540,7 +4082,9 @@ namespace Server.Mobiles private void ToggleQuestItem() { if (!CheckAlive()) + { return; + } ToggleQuestItemTarget(); } @@ -3561,10 +4105,14 @@ namespace Server.Mobiles private void ToggleQuestItem_Callback(Mobile from, object obj) { if (!CheckAlive()) + { return; + } if (!(obj is Item item)) + { return; + } if (from.Backpack == null || item.Parent != from.Backpack) { @@ -3591,39 +4139,57 @@ namespace Server.Mobiles public bool CanUseStuckMenu() { - if (m_StuckMenuUses == null) return true; + if (m_StuckMenuUses == null) + { + return true; + } for (var i = 0; i < m_StuckMenuUses.Length; ++i) + { if (DateTime.UtcNow - m_StuckMenuUses[i] > TimeSpan.FromDays(1.0)) + { return true; + } + } return false; } public void UsedStuckMenu() { - if (m_StuckMenuUses == null) m_StuckMenuUses = new DateTime[2]; + if (m_StuckMenuUses == null) + { + m_StuckMenuUses = new DateTime[2]; + } for (var i = 0; i < m_StuckMenuUses.Length; ++i) + { if (DateTime.UtcNow - m_StuckMenuUses[i] > TimeSpan.FromDays(1.0)) { m_StuckMenuUses[i] = DateTime.UtcNow; return; } + } } public override ApplyPoisonResult ApplyPoison(Mobile from, Poison poison) { if (!Alive) + { return ApplyPoisonResult.Immune; + } if (EvilOmenSpell.TryEndEffect(this)) + { poison = PoisonImpl.IncreaseLevel(poison); + } var result = base.ApplyPoison(from, poison); if (from != null && result == ApplyPoisonResult.Poisoned && PoisonTimer is PoisonImpl.PoisonTimer timer) - timer.From = from; + { + timer.From = @from; + } return result; } @@ -3634,16 +4200,23 @@ namespace Server.Mobiles public override void OnPoisonImmunity(Mobile from, Poison poison) { if (Young && (DuelContext?.Started != true || DuelContext.Finished)) + { SendLocalizedMessage( 502808 ); // You would have been poisoned, were you not new to the land of Britannia. Be careful in the future. + } else - base.OnPoisonImmunity(from, poison); + { + base.OnPoisonImmunity(@from, poison); + } } public override void OnKillsChange(int oldValue) { - if (Young && Kills > oldValue) ((Account)Account)?.RemoveYoungStatus(0); + if (Young && Kills > oldValue) + { + ((Account)Account)?.RemoveYoungStatus(0); + } } public override void OnGenderChanged(bool oldFemale) @@ -3669,13 +4242,17 @@ namespace Server.Mobiles public override void OnSkillChange(SkillName skill, double oldBase) { if (Young && SkillsTotal >= 4500) + { ((Account)Account) ?.RemoveYoungStatus( 1019036 ); // You have successfully obtained a respectable skill level, and have outgrown your status as a young player! + } if (MLQuestSystem.Enabled) + { MLQuestSystem.HandleSkillGain(this, skill); + } } public override void OnAccessLevelChanged(AccessLevel oldLevel) @@ -3696,12 +4273,16 @@ namespace Server.Mobiles public override int ComputeMovementSpeed(Direction dir, bool checkTurning) { if (checkTurning && (dir & Direction.Mask) != (Direction & Direction.Mask)) + { return RunMount; // We are NOT actually moving (just a direction change) + } var context = TransformationSpellHelper.GetContext(this); if (context?.Type == typeof(ReaperFormSpell)) + { return WalkFoot; + } var running = (dir & Direction.Running) != 0; @@ -3710,7 +4291,9 @@ namespace Server.Mobiles var animalContext = AnimalForm.GetContext(this); if (onHorse || animalContext?.SpeedBoost == true) + { return running ? RunMount : WalkMount; + } return running ? RunFoot : WalkFoot; } @@ -3718,7 +4301,9 @@ namespace Server.Mobiles public static TimeSpan MovementThrottle_Callback(NetState ns) { if (!(ns.Mobile is PlayerMobile pm) || !pm.UsesFastwalkPrevention) + { return TimeSpan.Zero; + } if (!pm.m_HasMoved) { @@ -3753,9 +4338,13 @@ namespace Server.Mobiles if (ns != null) { if (ns.StygianAbyss) + { ns.Send(new MobileMoving(m, Notoriety.Compute(this, m))); + } else + { ns.Send(new MobileMovingOld(m, Notoriety.Compute(this, m))); + } } } } @@ -3764,14 +4353,22 @@ namespace Server.Mobiles public void SetHairMods(int hairID, int beardID) { if (hairID == -1) + { InternalRestoreHair(true, ref m_HairModID, ref m_HairModHue); + } else if (hairID != -2) + { InternalChangeHair(true, hairID, ref m_HairModID, ref m_HairModHue); + } if (beardID == -1) + { InternalRestoreHair(false, ref m_BeardModID, ref m_BeardModHue); + } else if (beardID != -2) + { InternalChangeHair(false, beardID, ref m_BeardModID, ref m_BeardModHue); + } } private void CreateHair(bool hair, int id, int hue) @@ -3792,12 +4389,18 @@ namespace Server.Mobiles private void InternalRestoreHair(bool hair, ref int id, ref int hue) { if (id == -1) + { return; + } if (hair) + { HairItemID = 0; + } else + { FacialHairItemID = 0; + } // if (id != 0) CreateHair(hair, id, hue); @@ -3819,14 +4422,21 @@ namespace Server.Mobiles public override string ApplyNameSuffix(string suffix) { - if (Young) suffix = suffix.Length == 0 ? "(Young)" : $"{suffix} (Young)"; + if (Young) + { + suffix = suffix.Length == 0 ? "(Young)" : $"{suffix} (Young)"; + } if (EthicPlayer != null) { if (suffix.Length == 0) + { suffix = EthicPlayer.Ethic.Definition.Adjunct.String; + } else + { suffix = $"{suffix} {EthicPlayer.Ethic.Definition.Adjunct.String}"; + } } if (Core.ML && Map == Faction.Facet) @@ -3846,7 +4456,9 @@ namespace Server.Mobiles public override TimeSpan GetLogoutDelay() { if (Young || BedrollLogout || TestCenter.Enabled) + { return TimeSpan.Zero; + } return base.GetLogoutDelay(); } @@ -3854,16 +4466,24 @@ namespace Server.Mobiles public bool CheckYoungProtection(Mobile from) { if (!Young) + { return false; + } if (Region is BaseRegion region && !region.YoungProtected) + { return false; + } if (from is BaseCreature creature && creature.IgnoreYoungProtection) + { return false; + } if (Quest?.IgnoreYoungProtection(from) == true) + { return false; + } if (DateTime.UtcNow - m_LastYoungMessage > TimeSpan.FromMinutes(1.0)) { @@ -3893,7 +4513,9 @@ namespace Server.Mobiles || Region.IsPartOf("Samurai start location") || Region.IsPartOf("Ninja start location") || Region.IsPartOf("Ninja cave")) + { return false; + } Point3D loc; Map map; @@ -3913,15 +4535,25 @@ namespace Server.Mobiles Point3D[] list; if (map == Map.Trammel) + { list = m_TrammelDeathDestinations; + } else if (map == Map.Ilshenar) + { list = m_IlshenarDeathDestinations; + } else if (map == Map.Malas) + { list = m_MalasDeathDestinations; + } else if (map == Map.Tokuno) + { list = m_TokunoDeathDestinations; + } else + { return false; + } var dest = Point3D.Zero; var sqDistance = int.MaxValue; @@ -3955,7 +4587,9 @@ namespace Server.Mobiles if (SpeechLog.Enabled && NetState != null) { if (SpeechLog == null) + { SpeechLog = new SpeechLog(); + } SpeechLog.Add(e.Mobile, e.Speech); } @@ -3964,12 +4598,18 @@ namespace Server.Mobiles private void ToggleChampionTitleDisplay() { if (!CheckAlive()) + { return; + } if (DisplayChampionTitle) + { SendLocalizedMessage(1062419, "", 0x23); // You have chosen to hide your monster kill title. + } else + { SendLocalizedMessage(1062418, "", 0x23); // You have chosen to display your monster kill title. + } DisplayChampionTitle = !DisplayChampionTitle; } @@ -3981,7 +4621,9 @@ namespace Server.Mobiles public virtual void AcquireRecipe(Recipe r) { if (r != null) + { AcquireRecipe(r.ID); + } } public virtual void AcquireRecipe(int recipeID) @@ -3999,17 +4641,25 @@ namespace Server.Mobiles public void ResendBuffs() { if (!BuffInfo.Enabled || m_BuffTable == null) + { return; + } if (NetState?.BuffIcon == true) + { foreach (var info in m_BuffTable.Values) + { NetState.Send(new AddBuffPacket(this, info)); + } + } } public void AddBuff(BuffInfo b) { if (!BuffInfo.Enabled || b == null) + { return; + } RemoveBuff(b); // Check & subsequently remove the old one. @@ -4018,13 +4668,17 @@ namespace Server.Mobiles m_BuffTable.Add(b.ID, b); if (NetState?.BuffIcon == true) + { NetState.Send(new AddBuffPacket(this, b)); + } } public void RemoveBuff(BuffInfo b) { if (b == null) + { return; + } RemoveBuff(b.ID); } @@ -4032,20 +4686,28 @@ namespace Server.Mobiles public void RemoveBuff(BuffIcon b) { if (m_BuffTable?.ContainsKey(b) != true) + { return; + } var info = m_BuffTable[b]; if (info.Timer?.Running == true) + { info.Timer.Stop(); + } m_BuffTable.Remove(b); if (NetState?.BuffIcon == true) + { NetState.Send(new RemoveBuffPacket(this, b)); + } if (m_BuffTable.Count <= 0) + { m_BuffTable = null; + } } private class CountAndTimeStamp @@ -4080,7 +4742,9 @@ namespace Server.Mobiles private void RemoveBlock(Mobile mobile) { if (mobile is PlayerMobile pm) + { pm.m_MountBlock = null; + } } } @@ -4140,7 +4804,9 @@ namespace Server.Mobiles public override void OnResponse(NetState sender, RelayInfo info) { if (!m_Player.CheckAlive()) + { return; + } if (info.ButtonID == 1) { @@ -4157,7 +4823,9 @@ namespace Server.Mobiles } if (m_InsuranceGump != null) + { m_Player.SendGump(m_InsuranceGump.NewInstance()); + } } } @@ -4179,7 +4847,9 @@ namespace Server.Mobiles insure = new bool[items.Length]; for (var i = 0; i < items.Length; ++i) + { insure[i] = items[i].Insured; + } } m_Insure = insure; @@ -4197,9 +4867,13 @@ namespace Server.Mobiles AddHtmlLocalized(50, 472, 80, 20, 1011012, 0x7FFF); // CANCEL if (from.AutoRenewInsurance) + { AddButton(360, 10, 9723, 9724, 1); + } else + { AddButton(360, 10, 9720, 9722, 1); + } AddHtmlLocalized(395, 14, 105, 20, 1114122, 0x7FFF); // AUTO REINSURE @@ -4216,8 +4890,12 @@ namespace Server.Mobiles var cost = 0; for (var i = 0; i < items.Length; ++i) + { if (insure[i]) + { cost += GetInsuranceCost(items[i]); + } + } AddHtmlLocalized(15, 420, 300, 20, 1114310, 0x7FFF); // GOLD AVAILABLE: AddLabel(215, 420, 0x481, balance.ToString()); @@ -4280,7 +4958,9 @@ namespace Server.Mobiles public override void OnResponse(NetState sender, RelayInfo info) { if (info.ButtonID == 0 || !m_From.CheckAlive()) + { return; + } switch (info.ButtonID) { @@ -4289,7 +4969,9 @@ namespace Server.Mobiles if (m_From.AutoRenewInsurance) { if (!m_From.HasGump()) + { m_From.SendGump(new CancelRenewInventoryInsuranceGump(m_From, this)); + } } else { @@ -4308,14 +4990,18 @@ namespace Server.Mobiles case 3: // Prev { if (m_Page >= 1) + { m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page - 1)); + } break; } case 4: // Next { if ((m_Page + 1) * 4 < m_Items.Length) + { m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page + 1)); + } break; } @@ -4324,7 +5010,9 @@ namespace Server.Mobiles var idx = info.ButtonID - 100; if (idx >= 0 && idx < m_Items.Length) + { m_Insure[idx] = !m_Insure[idx]; + } m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page)); @@ -4366,7 +5054,9 @@ namespace Server.Mobiles public override void OnResponse(NetState sender, RelayInfo info) { if (!m_From.CheckAlive()) + { return; + } if (info.ButtonID == 1) { @@ -4375,7 +5065,9 @@ namespace Server.Mobiles var item = m_Items[i]; if (item.Insured != m_Insure[i]) + { m_From.ToggleItemInsurance_Callback(m_From, item, false); + } } } else @@ -4411,14 +5103,20 @@ namespace Server.Mobiles var length = reader.ReadEncodedInt(); m_Values = new TitleInfo[length]; - for (var i = 0; i < length; i++) m_Values[i] = new TitleInfo(reader); + for (var i = 0; i < length; i++) + { + m_Values[i] = new TitleInfo(reader); + } if (m_Values.Length != ChampionSpawnInfo.Table.Length) { var oldValues = m_Values; m_Values = new TitleInfo[ChampionSpawnInfo.Table.Length]; - for (var i = 0; i < m_Values.Length && i < oldValues.Length; i++) m_Values[i] = oldValues[i]; + for (var i = 0; i < m_Values.Length && i < oldValues.Length; i++) + { + m_Values[i] = oldValues[i]; + } } break; @@ -4500,7 +5198,9 @@ namespace Server.Mobiles public int GetValue(int index) { if (m_Values == null || index < 0 || index >= m_Values.Length) + { return 0; + } m_Values[index] ??= new TitleInfo(); @@ -4510,7 +5210,9 @@ namespace Server.Mobiles public DateTime GetLastDecay(int index) { if (m_Values == null || index < 0 || index >= m_Values.Length) + { return DateTime.MinValue; + } m_Values[index] ??= new TitleInfo(); @@ -4522,7 +5224,9 @@ namespace Server.Mobiles m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length]; if (index < 0 || index >= m_Values.Length) + { return; + } m_Values[index] ??= new TitleInfo(); @@ -4534,7 +5238,9 @@ namespace Server.Mobiles m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length]; if (index < 0 || index >= m_Values.Length || value <= 0) + { return; + } m_Values[index] ??= new TitleInfo(); @@ -4546,7 +5252,9 @@ namespace Server.Mobiles m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length]; if (index < 0 || index >= m_Values.Length || value <= 0) + { return; + } m_Values[index] ??= new TitleInfo(); @@ -4555,7 +5263,9 @@ namespace Server.Mobiles m_Values[index].Value -= Math.Min(value, m_Values[index].Value); if (before != m_Values[index].Value) + { m_Values[index].LastDecay = DateTime.UtcNow; + } } public override string ToString() => "..."; @@ -4581,13 +5291,19 @@ namespace Server.Mobiles { var t = pm.ChampionTitles; if (t == null) + { return; + } t.m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length]; for (var i = 0; i < t.m_Values.Length; i++) + { if (t.GetLastDecay(i) + LossDelay < DateTime.UtcNow) + { t.Atrophy(i, LossAmount); + } + } } public static void @@ -4595,7 +5311,9 @@ namespace Server.Mobiles { var t = pm.ChampionTitles; if (t == null) + { return; + } t.m_Values ??= new TitleInfo[ChampionSpawnInfo.Table.Length]; diff --git a/rider-settings.zip b/rider-settings.zip index 4e8d2444d..2bfd4ae2c 100644 Binary files a/rider-settings.zip and b/rider-settings.zip differ