diff --git a/LICENSE b/LICENSE
index f288702..3877ae0 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,674 +1,674 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-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,
-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
-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
-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
-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
-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
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-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
-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
-pattern of such abuse occurs in the area of products for individuals to
-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
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-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
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-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
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-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,
-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
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-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
-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
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-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
-"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
-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
-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
-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,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- 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
-covered work is covered by this License only if the output, given its
-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
-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
-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
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- 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
- "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 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
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-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
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- 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
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- 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
- 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, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-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
-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
-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.
-
- "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
-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.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-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
-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).
-
- 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
-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.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-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
-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
-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.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- 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
-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
-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
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-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
-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).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-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
-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
-occurring solely as a consequence of using peer-to-peer transmission
-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
-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
-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
-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
-give under the previous paragraph, plus a right to possession of the
-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
-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
-any patent claim is infringed by making, using, selling, offering for
-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
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-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
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-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
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-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
-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
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-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
-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
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- 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
-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
-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.
-
- 13. Use with the GNU Affero General Public License.
-
- 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
-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
-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
-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
-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
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-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
-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
-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
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-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 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.
-
-
- Copyright (C)
-
- 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 .
-
-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)
- 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
-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,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-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
-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
-.
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+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,
+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
+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
+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
+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
+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
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+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
+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
+pattern of such abuse occurs in the area of products for individuals to
+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
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+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
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+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
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+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,
+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
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+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
+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
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+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
+"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
+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
+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
+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,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ 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
+covered work is covered by this License only if the output, given its
+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
+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
+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
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ 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
+ "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 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
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+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
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ 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
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ 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
+ 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, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+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
+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
+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.
+
+ "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
+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.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+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
+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).
+
+ 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
+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.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+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
+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
+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.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ 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
+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
+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
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+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
+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).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+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
+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
+occurring solely as a consequence of using peer-to-peer transmission
+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
+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
+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
+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
+give under the previous paragraph, plus a right to possession of the
+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
+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
+any patent claim is infringed by making, using, selling, offering for
+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
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+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
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+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
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+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
+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
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+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
+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
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ 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
+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
+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.
+
+ 13. Use with the GNU Affero General Public License.
+
+ 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
+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
+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
+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
+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
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+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
+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
+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
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+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 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.
+
+
+ Copyright (C)
+
+ 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 .
+
+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)
+ 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
+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,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+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
+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
+.
diff --git a/README.md b/README.md
index 6717fb9..65f944b 100644
--- a/README.md
+++ b/README.md
@@ -1,60 +1,60 @@
-## cs2TTT
-
-## Contributing
-TTT is in heavy development and I want you to know that contributions are always welcome. Please follow Microsoft's dependency injection system.
-
-> [!TIP]
-> Microsoft has some good documentation on dependency injection here:
-> [Overview](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection),
-> [Using Dependency Injection](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-usage),
-> [Dependency Injection Guidelines](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines).
-
-## Creating items
-
-Creating new items or modifying existing ones is easy. Create a new class in the correct directory, mod/TTT.Shop/Items/{group}. Then create it to your liking. Afterwards, compile the plugin and it's all set. The plugin handles loading all the items.
-
-> [!TIP]
-> Available groups are [All, Detective, Traitor].
-> SimpleName is used for /buy {name}
-
-#### Example Item
-```c#
-namespace TTT.Shop.Items.Traitor;
-
-public class AwpItem : IShopItem
-{
- public string Name()
- {
- return "AWP";
- }
-
- public string SimpleName()
- {
- return "awp";
- }
-
- public int Price()
- {
- return 2000;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
- if (player.PlayerRole() != Role.Traitor) return BuyResult.IncorrectRole;
- player.RemoveCredits(Price());
- player.Player().GiveNamedItem(CsItem.AWP);
- return BuyResult.Successful;
- }
-}
-```
-
-## Road Map
-- [✅] Role assignment
-- [✅] DNA Scanner
-- [✅] Tazer
-- [ ] Configuration
-- [ ] Karma system
-- [ ] Shop
-- [ ] RDM Manager
-- [ ] Add database support for logs and stats
+## cs2TTT
+
+## Contributing
+TTT is in heavy development and I want you to know that contributions are always welcome. Please follow Microsoft's dependency injection system.
+
+> [!TIP]
+> Microsoft has some good documentation on dependency injection here:
+> [Overview](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection),
+> [Using Dependency Injection](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-usage),
+> [Dependency Injection Guidelines](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines).
+
+## Creating items
+
+Creating new items or modifying existing ones is easy. Create a new class in the correct directory, mod/TTT.Shop/Items/{group}. Then create it to your liking. Afterwards, compile the plugin and it's all set. The plugin handles loading all the items.
+
+> [!TIP]
+> Available groups are [All, Detective, Traitor].
+> SimpleName is used for /buy {name}
+
+#### Example Item
+```c#
+namespace TTT.Shop.Items.Traitor;
+
+public class AwpItem : IShopItem
+{
+ public string Name()
+ {
+ return "AWP";
+ }
+
+ public string SimpleName()
+ {
+ return "awp";
+ }
+
+ public int Price()
+ {
+ return 2000;
+ }
+
+ public BuyResult OnBuy(GamePlayer player)
+ {
+ if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
+ if (player.PlayerRole() != Role.Traitor) return BuyResult.IncorrectRole;
+ player.RemoveCredits(Price());
+ player.Player().GiveNamedItem(CsItem.AWP);
+ return BuyResult.Successful;
+ }
+}
+```
+
+## Road Map
+- [✅] Role assignment
+- [✅] DNA Scanner
+- [✅] Tazer
+- [ ] Configuration
+- [ ] Karma system
+- [ ] Shop
+- [ ] RDM Manager
+- [ ] Add database support for logs and stats
diff --git a/TTT.sln b/TTT.sln
index 018a8b4..8d65e6e 100644
--- a/TTT.sln
+++ b/TTT.sln
@@ -23,6 +23,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTT.Round", "mod\TTT.Round\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Shop", "mod\TTT.Shop\TTT.Shop.csproj", "{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Formatting", "public\TTT.Formatting\TTT.Formatting.csproj", "{C6EE882B-E597-45DB-85FF-A521DC7A0AAE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Logs", "mod\TTT.Logs\TTT.Logs.csproj", "{E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Player", "mod\TTT.Player\TTT.Player.csproj", "{D9327D60-67EE-4AF3-BD99-8A95634600B5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TTT.Manager", "mod\TTT.Manager\TTT.Manager.csproj", "{C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -60,6 +68,22 @@ Global
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C6EE882B-E597-45DB-85FF-A521DC7A0AAE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D9327D60-67EE-4AF3-BD99-8A95634600B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D9327D60-67EE-4AF3-BD99-8A95634600B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D9327D60-67EE-4AF3-BD99-8A95634600B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D9327D60-67EE-4AF3-BD99-8A95634600B5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A917B0F5-762F-4C4A-9F50-02BA4A0C6B63} = {C7CCF187-9F99-4091-B092-6397C35BE9F1}
@@ -69,5 +93,9 @@ Global
{0E7A451E-D56F-4D96-9B5C-5F1B0A6B0656} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{511E712D-31D5-4EFC-9F0F-D9D4A83ED202} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
{DFBB6B95-ED8D-4E02-BAFA-C705ACBC6DB2} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
+ {C6EE882B-E597-45DB-85FF-A521DC7A0AAE} = {C84CEB1F-0132-43EF-9A5F-12C7AA08B8E7}
+ {E76CD078-0F1B-4EE8-9A19-EE93BAE3FA6B} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
+ {D9327D60-67EE-4AF3-BD99-8A95634600B5} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
+ {C3C26EF9-0E5E-4AAF-AE00-EFF4BB129FDB} = {14FF3D75-F9CF-4A32-9F59-83765EA68874}
EndGlobalSection
EndGlobal
diff --git a/gitignore b/gitignore
index aad3b71..d3bf8e7 100644
--- a/gitignore
+++ b/gitignore
@@ -1,12 +1,12 @@
-
-# Repository build files
-build/
-bin/
-obj/
-
-Debug/
-Release/
-
-# IDE files
-.idea/
-.vs/
+
+# Repository build files
+build/
+bin/
+obj/
+
+Debug/
+Release/
+
+# IDE files
+.idea/
+.vs/
diff --git a/global.json b/global.json
index b5b37b6..16f606c 100644
--- a/global.json
+++ b/global.json
@@ -1,7 +1,7 @@
-{
- "sdk": {
- "version": "8.0.0",
- "rollForward": "latestMajor",
- "allowPrerelease": false
- }
+{
+ "sdk": {
+ "version": "8.0.0",
+ "rollForward": "latestMajor",
+ "allowPrerelease": false
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Detective/DetectiveConfig.cs b/mod/TTT.Detective/DetectiveConfig.cs
new file mode 100644
index 0000000..04a1344
--- /dev/null
+++ b/mod/TTT.Detective/DetectiveConfig.cs
@@ -0,0 +1,7 @@
+namespace TTT.Detective;
+
+public class DetectiveConfig
+{
+ public bool DNAScannerEnabled { get; } = true;
+
+}
\ No newline at end of file
diff --git a/mod/TTT.Detective/DetectiveManager.cs b/mod/TTT.Detective/DetectiveManager.cs
index 27f3218..f22acc3 100644
--- a/mod/TTT.Detective/DetectiveManager.cs
+++ b/mod/TTT.Detective/DetectiveManager.cs
@@ -2,24 +2,20 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Memory;
+using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using TTT.Player;
using TTT.Public.Behaviors;
using TTT.Public.Extensions;
using TTT.Public.Formatting;
using TTT.Public.Mod.Detective;
using TTT.Public.Mod.Role;
+using TTT.Public.Player;
namespace TTT.Detective;
-public class DetectiveManager : IDetectiveService, IPluginBehavior
+public class DetectiveManager(IPlayerService roleService) : IDetectiveService, IPluginBehavior
{
private const int TaserAmmoType = 18;
- private readonly IRoleService _roleService;
-
- public DetectiveManager(IRoleService roleService)
- {
- _roleService = roleService;
- }
public void Start(BasePlugin parent)
{
@@ -30,24 +26,45 @@ public void Start(BasePlugin parent)
});
- /**
- VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
+ VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnZeus, HookMode.Pre);
+
+ }
+
+ public HookResult OnZeus(DynamicHook hook)
+ {
+ var ent = hook.GetParam(0);
+
+ var playerWhoWasDamaged = player(ent);
+
+ if (playerWhoWasDamaged == null) return HookResult.Continue;
+
+ var info = hook.GetParam(1);
+
+ CCSPlayerController? attacker = null;
+
+ if (info.Attacker.Value != null)
{
- var info = hook.GetParam(1);
- if (info.Attacker.Value == null || !info.Attacker.Value.IsValid) return HookResult.Continue;
- var attacker = info.Attacker.Value.As();
- if (attacker == hook.GetParam(0)) return HookResult.Continue;
- if (info.AmmoType is not TaserAmmoType) return HookResult.Continue;
+ var playerWhoAttacked = info.Attacker.Value.As();
- info.Damage = 1f;
+ attacker = playerWhoAttacked.Controller.Value.As();
- if (!attacker.IsReal()) return HookResult.Continue;
+ }
- var ammoType = info.AmmoType;
+ if (info.BitsDamageType is not 256) return HookResult.Continue;
+ if (attacker == null) return HookResult.Continue;
- return HookResult.Changed;
- }, HookMode.Pre);
- */
+ info.Damage = 0;
+
+ var targetRole = roleService.GetPlayer(playerWhoWasDamaged);
+
+ Server.NextFrame(() =>
+ {
+ attacker.PrintToChat(
+ StringUtils.FormatTTT(
+ $"You tased player {playerWhoWasDamaged.PlayerName} they are a {targetRole.PlayerRole().FormatRoleFull()}"));
+ });
+
+ return HookResult.Stop;
}
@@ -60,7 +77,7 @@ private void IdentifyBody(CCSPlayerController caller)
{
//add states
- if (_roleService.GetRole(caller) != Role.Detective) return;
+ if (roleService.GetPlayer(caller).PlayerRole() != Role.Detective) return;
var entity = caller.GetClientRagdollAimTarget();
@@ -68,7 +85,7 @@ private void IdentifyBody(CCSPlayerController caller)
if (entity.PawnIsAlive) return;
- var player = _roleService.GetPlayer(entity);
+ var player = roleService.GetPlayer(entity);
if (player.IsFound()) return;
@@ -85,11 +102,46 @@ private void IdentifyBody(CCSPlayerController caller)
else
message = StringUtils.FormatTTT(
player.PlayerRole().FormatStringFullAfter($"{plr.PlayerName} was killed by ") +
- _roleService.GetRole(killerEntity).FormatStringFullAfter(killerEntity.PlayerName));
+ roleService.GetPlayer(killerEntity).PlayerRole().FormatStringFullAfter(killerEntity.PlayerName));
player.SetFound(true);
Server.NextFrame(() => { Server.PrintToChatAll(message); });
}
+
+ //to be moved to a utility class
+ public static CCSPlayerController? player(CEntityInstance? instance)
+ {
+ if (instance == null)
+ {
+ return null;
+ }
+
+ if (instance.DesignerName != "player")
+ {
+ return null;
+ }
+
+ // grab the pawn index
+ int player_index = (int)instance.Index;
+
+ // grab player controller from pawn
+ CCSPlayerPawn player_pawn = Utilities.GetEntityFromIndex(player_index);
+
+ // pawn valid
+ if (player_pawn == null || !player_pawn.IsValid)
+ {
+ return null;
+ }
+
+ // controller valid
+ if (player_pawn.OriginalController == null || !player_pawn.OriginalController.IsValid)
+ {
+ return null;
+ }
+
+ // any further validity is up to the caller
+ return player_pawn.OriginalController.Value;
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Logs/LogBehavior.cs b/mod/TTT.Logs/LogBehavior.cs
new file mode 100644
index 0000000..f53703b
--- /dev/null
+++ b/mod/TTT.Logs/LogBehavior.cs
@@ -0,0 +1,83 @@
+using System.Collections.Generic;
+using System.Linq;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using TTT.Public.Action;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Logs;
+using Action = TTT.Public.Action.Action;
+
+namespace TTT.Logs;
+
+public class LogBehavior : ILogService, IPluginBehavior
+{
+ private int _round = 1;
+
+ public void Start(BasePlugin plugin)
+ {
+ }
+
+ [GameEventHandler]
+ public HookResult OnRoundStart(EventRoundStart _, GameEventInfo __)
+ {
+ CreateRound(_round++);
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnRoundEnd(EventRoundEnd _, GameEventInfo __)
+ {
+ PrintLogs(_round);
+ return HookResult.Continue;
+ }
+
+ private readonly Dictionary _logs = new();
+
+ public int GetCurrentRound()
+ {
+ return _round;
+ }
+
+ public void AddLog(Action action)
+ {
+ _logs[_round].AddLog(action);
+ }
+
+ public bool PrintLogs(int round)
+ {
+ if (_logs.ContainsKey(round)) return false;
+ foreach (var player in Utilities.GetPlayers().Where(plr => plr.IsReal()))
+ {
+ PrintToPlayer(player, round);
+ }
+
+ PrintToConsole(round);
+ return true;
+ }
+
+ public bool PrintToPlayer(CCSPlayerController player, int round)
+ {
+ if (!_logs.ContainsKey(round)) return false;
+ player.PrintToConsole(GetLogs(round).FormattedLogs());
+ return true;
+ }
+
+ public bool PrintToConsole(int round)
+ {
+ if (!_logs.ContainsKey(round)) return false;
+ Server.PrintToConsole(GetLogs(round).FormattedLogs());
+ return true;
+ }
+
+ public IRoundLogs GetLogs(int round)
+ {
+ return _logs[round];
+ }
+
+ public void CreateRound(int round)
+ {
+ _logs.Add(round, new RoundLog(round));
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Logs/LogServiceExtension.cs b/mod/TTT.Logs/LogServiceExtension.cs
new file mode 100644
index 0000000..f7b3feb
--- /dev/null
+++ b/mod/TTT.Logs/LogServiceExtension.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Logs;
+using TTT.Public.Mod.Role;
+
+namespace TTT.Logs;
+
+public static class LogServiceExtension
+{
+ public static void AddLogsService(this IServiceCollection collection)
+ {
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Logs/LogsCommand.cs b/mod/TTT.Logs/LogsCommand.cs
new file mode 100644
index 0000000..96bbcb2
--- /dev/null
+++ b/mod/TTT.Logs/LogsCommand.cs
@@ -0,0 +1,62 @@
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Admin;
+using CounterStrikeSharp.API.Modules.Commands;
+using TTT.Public.Behaviors;
+using TTT.Public.Formatting;
+using TTT.Public.Mod.Logs;
+
+namespace TTT.Logs;
+
+public class LogsCommand(ILogService service) : IPluginBehavior
+{
+ private readonly ILogService _service = service;
+
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+ [ConsoleCommand("css_logs", "Prints logs to console")]
+ [CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_ONLY)]
+ public void Command_Logs(CCSPlayerController? executor, CommandInfo info)
+ {
+
+ if (!AdminManager.PlayerHasPermissions(executor, "@css/kick"))
+ {
+ info.ReplyToCommand(StringUtils.FormatTTT("You do not have permission to execute this command"));
+ return;
+ }
+
+ var roundIdString = info.GetArg(1);
+
+ var roundId = service.GetCurrentRound();
+
+ if (!string.IsNullOrEmpty(roundIdString) || !int.TryParse(roundIdString, out roundId))
+ {
+ info.ReplyToCommand(StringUtils.FormatTTT("Invalid round id"));
+ return;
+ }
+
+ if (roundId <= 0)
+ {
+ info.ReplyToCommand( StringUtils.FormatTTT("Invalid round id"));
+ }
+
+ if (executor == null)
+ {
+ if (!service.PrintToConsole(roundId)) info.ReplyToCommand(StringUtils.FormatTTT("No logs found for round " + roundId));
+ return;
+ }
+
+ if (!AdminManager.PlayerHasPermissions(executor, "@css/kick"))
+ {
+ info.ReplyToCommand("You do not have permission to execute this command");
+ return;
+ }
+
+ info.ReplyToCommand(!service.PrintToPlayer(executor, roundId)
+ ? StringUtils.FormatTTT("No logs found for round " + roundId)
+ : StringUtils.FormatTTT("Logs printed to console"));
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Logs/LogsListener.cs b/mod/TTT.Logs/LogsListener.cs
new file mode 100644
index 0000000..a59382e
--- /dev/null
+++ b/mod/TTT.Logs/LogsListener.cs
@@ -0,0 +1,58 @@
+using System;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using TTT.Public.Action;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Logs;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Logs;
+
+public class LogsListener(ILogService logService, IPlayerService playerService) : IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info)
+ {
+ var attackedPlayer = @event.Userid;
+
+ if (attackedPlayer == null || !attackedPlayer.IsReal()) return HookResult.Continue;
+
+ var attackedRole = playerService.GetPlayer(attackedPlayer).PlayerRole();
+
+ var attacker = @event.Attacker == null ? null : new Tuple(@event.Attacker, playerService.GetPlayer(@event.Attacker).PlayerRole());
+
+ logService.AddLog(new DamageAction(attacker,new Tuple(attackedPlayer, attackedRole), @event.DmgHealth, ServerExtensions.GetGameRules().RoundTime));
+
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
+ {
+ var killedPlayer = @event.Userid;
+ var killer = @event.Attacker;
+
+ if (killedPlayer == null || !killedPlayer.IsReal()) return HookResult.Continue;
+
+ var killedRole = playerService.GetPlayer(killedPlayer).PlayerRole();
+
+ if (killer == null || !killer.IsReal())
+ {
+ logService.AddLog(new DeathAction(new Tuple(killedPlayer, killedRole)));
+ return HookResult.Continue;
+ }
+
+ var killerRole = playerService.GetPlayer(killer).PlayerRole();
+
+ logService.AddLog(new KillAction(new Tuple(killedPlayer, killedRole),
+ new Tuple(killer, killerRole)));
+ return HookResult.Continue;
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Logs/RoundLog.cs b/mod/TTT.Logs/RoundLog.cs
new file mode 100644
index 0000000..dcecb1e
--- /dev/null
+++ b/mod/TTT.Logs/RoundLog.cs
@@ -0,0 +1,45 @@
+using System.Collections.Generic;
+using System.Text;
+using TTT.Public.Action;
+using TTT.Public.Mod.Logs;
+using Action = TTT.Public.Action.Action;
+
+namespace TTT.Logs;
+
+public class RoundLog : IRoundLogs
+{
+ private readonly List _logs = [];
+ private readonly int _roundId;
+
+ public RoundLog(int roundId)
+ {
+ _roundId = roundId;
+ }
+
+ public IList GetLogs()
+ {
+ return _logs;
+ }
+
+ public void AddLog(Action action)
+ {
+ _logs.Add(action);
+ }
+
+ public void RemoveLog(Action action)
+ {
+ _logs.Remove(action);
+ }
+
+ public string FormattedLogs()
+ {
+ var builder = new StringBuilder();
+ builder.AppendLine($"[TTT] Logs round {_roundId}");
+
+ foreach (var action in _logs) builder.AppendLine(action.ActionMessage());
+
+ builder.AppendLine("[TTT] Logs ended!");
+
+ return builder.ToString();
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Logs/TTT.Logs.csproj b/mod/TTT.Logs/TTT.Logs.csproj
new file mode 100644
index 0000000..ca14336
--- /dev/null
+++ b/mod/TTT.Logs/TTT.Logs.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/mod/TTT.Roles/Helper/ChatManager.cs b/mod/TTT.Manager/ChatManager.cs
similarity index 92%
rename from mod/TTT.Roles/Helper/ChatManager.cs
rename to mod/TTT.Manager/ChatManager.cs
index ef84c52..c34d37c 100644
--- a/mod/TTT.Roles/Helper/ChatManager.cs
+++ b/mod/TTT.Manager/ChatManager.cs
@@ -1,51 +1,52 @@
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Modules.Commands;
-using CounterStrikeSharp.API.Modules.Utils;
-using TTT.Public.Behaviors;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-
-namespace TTT.Roles;
-
-public class ChatManager(IRoleService roleService) : IPluginBehavior
-{
- public void Start(BasePlugin plugin)
- {
- plugin.AddCommandListener("say_team", OnSayTeam);
- }
-
- private HookResult OnSayTeam(CCSPlayerController? caller, CommandInfo info)
- {
- if (caller == null || !caller.IsValid) return HookResult.Continue;
- var role = roleService.GetRole(caller);
- switch (role)
- {
- case Role.Innocent:
- return HookResult.Stop;
- case Role.Detective:
- {
- var message = $" {ChatColors.DarkBlue} DETECTIVE {caller.PlayerName} {info.GetArg(1)}";
- foreach (var player in roleService.GetDetectives())
- {
- player.PrintToChat(message);
- }
- break;
- }
- case Role.Traitor:
- {
- var message = $" {ChatColors.DarkRed} TRAITOR {caller.PlayerName} {info.GetArg(1)}";
- foreach (var player in roleService.GetTraitors())
- {
- player.PrintToChat(message);
- }
- break;
- }
- case Role.Unassigned:
- return HookResult.Continue;
- default:
- throw new ArgumentOutOfRangeException();
- }
-
- return HookResult.Handled;
- }
+using System;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Modules.Commands;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Public.Behaviors;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Manager;
+
+public class ChatManager(IRoleService roleService) : IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+ plugin.AddCommandListener("say_team", OnSayTeam);
+ }
+
+ private HookResult OnSayTeam(CCSPlayerController? caller, CommandInfo info)
+ {
+ if (caller == null || !caller.IsValid) return HookResult.Continue;
+ var role = roleService.GetRole(caller);
+ switch (role)
+ {
+ case Role.Innocent:
+ return HookResult.Stop;
+ case Role.Detective:
+ {
+ var message = $" {ChatColors.DarkBlue} DETECTIVE {caller.PlayerName} {info.GetArg(1)}";
+ foreach (var player in roleService.GetDetectives())
+ {
+ player.PrintToChat(message);
+ }
+ break;
+ }
+ case Role.Traitor:
+ {
+ var message = $" {ChatColors.DarkRed} TRAITOR {caller.PlayerName} {info.GetArg(1)}";
+ foreach (var player in roleService.GetTraitors())
+ {
+ player.PrintToChat(message);
+ }
+ break;
+ }
+ case Role.Unassigned:
+ return HookResult.Continue;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ return HookResult.Handled;
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Helper/InfoManager.cs b/mod/TTT.Manager/InfoManager.cs
similarity index 52%
rename from mod/TTT.Roles/Helper/InfoManager.cs
rename to mod/TTT.Manager/InfoManager.cs
index f180d3a..1866918 100644
--- a/mod/TTT.Roles/Helper/InfoManager.cs
+++ b/mod/TTT.Manager/InfoManager.cs
@@ -1,157 +1,154 @@
-using System.Numerics;
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using CounterStrikeSharp.API.Modules.Admin;
-using CounterStrikeSharp.API.Modules.Timers;
-using CounterStrikeSharp.API.Modules.Utils;
-using TTT.Player;
-using TTT.Public.Extensions;
-using TTT.Public.Formatting;
-using TTT.Public.Mod.Role;
-using TTT.Public.Mod.Round;
-using TTT.Public.Player;
-using TTT.Round;
-using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
-
-namespace TTT.Roles;
-
-public class InfoManager
-{
- private readonly Dictionary> _playerLookAtRole = new();
- private readonly RoleManager _roleService;
- private readonly IRoundService _manager;
- private readonly Dictionary> _spectatorLookAtRole = new();
-
- public InfoManager(RoleManager roleService, IRoundService manager, BasePlugin plugin)
- {
- _roleService = roleService;
- _manager = manager;
- plugin.RegisterListener(OnTick);
- plugin.AddTimer(0.3f, OnTickAll, TimerFlags.REPEAT);
- plugin.AddTimer(0.1f, OnTickScoreboard, TimerFlags.REPEAT);
-
- plugin.RegisterEventHandler(OnPlayerSpectateChange);
- }
-
- public void Reset()
- {
- _playerLookAtRole.Clear();
- _spectatorLookAtRole.Clear();
- }
-
- public void RegisterLookAtRole(CCSPlayerController player, Tuple role)
- {
- _playerLookAtRole.TryAdd(player, role);
- }
-
- public void RemoveLookAtRole(CCSPlayerController player)
- {
- _playerLookAtRole.Remove(player);
- }
-
- public void OnTickScoreboard()
- {
- return;
- foreach (var player in _roleService.GetPlayers().Keys)
- {
- player.ModifyScoreBoard();
- }
- }
-
-
- public void OnTick()
- {
- foreach (var gamePlayer in _roleService.Players())
- {
- if (_manager.GetRoundStatus() != RoundStatus.Started) return;
-
- var player = gamePlayer.Player();
-
- if (player == null) continue;
- if (!player.IsReal()) continue;
-
- var playerRole = gamePlayer.PlayerRole();
-
- if (playerRole == Role.Unassigned) continue;
- if (gamePlayer.ShopOpen()) continue;
-
- if (!player.PawnIsAlive && AdminManager.PlayerHasPermissions(player, "@css/kick"))
- {
- if (player.ObserverPawn.Value == null || !player.ObserverPawn.Value.IsValid) continue;
- if (player.ObserverPawn.Value.ObserverServices?.ObserverTarget.Value is null) continue;
- var target = player.ObserverPawn.Value.ObserverServices.ObserverTarget.Value?.As();
- if (target == null)
- {
- Server.NextFrame(() =>
- player.PrintToCenterHtml(
- $"Your Role: {playerRole.GetCenterRole()}"));
- }
- else
- {
- Server.NextFrame(() => player.PrintToCenterHtml(
- $"Your Role: {playerRole.GetCenterRole()}
"
- + $"{target.PlayerName}'s Role: {_roleService.GetRole(target).GetCenterRole()}"));
- }
-
- continue;
- }
-
- if (!_playerLookAtRole.TryGetValue(player, out var value))
- {
- Server.NextFrame(() =>
- player.PrintToCenterHtml(
- $"Your Role: {playerRole.GetCenterRole()}"));
- continue;
- }
-
- if (!value.Item1.IsReal()) continue;
-
- if (value.Item2 == playerRole || playerRole == Role.Traitor || value.Item2 == Role.Detective)
- {
- Server.NextFrame(() => player.PrintToCenterHtml(
- $"Your Role: {playerRole.GetCenterRole()}
"
- + $"{value.Item1.PlayerName}'s Role: {value.Item2.GetCenterRole()}"));
- }
-
-
- if (playerRole != Role.Innocent && (value.Item2 != Role.Traitor || playerRole != Role.Detective)) continue;
-
- Server.NextFrame(() => player.PrintToCenterHtml(
- $"Your Role: {playerRole.GetCenterRole()}
"
- + $"{value.Item1.PlayerName}'s Role: {Role.Unassigned.GetCenterRole()}"));
- }
- }
-
- public void OnTickAll()
- {
- var players = _roleService.GetPlayers().Keys;
-
- _playerLookAtRole.Clear();
-
- foreach (var player in players)
- {
- if (!player.IsReal()) continue;
-
- var target = player.GetClientPlayerAimTarget();
-
- if (target == null) continue;
- if (!target.IsReal()) continue;
-
- RegisterLookAtRole(player, new Tuple(target, _roleService.GetRole(target)));
- }
- }
-
- [GameEventHandler]
- private HookResult OnPlayerSpectateChange(EventSpecTargetUpdated @event, GameEventInfo info)
- {
- var player = @event.Userid;
- var target = new CCSPlayerController(@event.Target);
-
- if (!player.IsReal() || !target.IsReal()) return HookResult.Continue;
-
- _spectatorLookAtRole.TryAdd(player, new Tuple(target.PlayerName, _roleService.GetRole(target)));
-
- return HookResult.Continue;
- }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Admin;
+using CounterStrikeSharp.API.Modules.Memory;
+using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
+using CounterStrikeSharp.API.Modules.Timers;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Player;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Formatting;
+using TTT.Public.Mod.Role;
+using TTT.Public.Mod.Round;
+using TTT.Public.Player;
+using TTT.Round;
+using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
+
+namespace TTT.Manager;
+
+public class InfoManager : IPluginBehavior
+{
+ private readonly Dictionary> _playerLookAtRole = new();
+ private readonly IPlayerService _playerService;
+ private readonly IRoundService _manager;
+ private readonly Dictionary> _spectatorLookAtRole = new();
+
+ public InfoManager(IPlayerService playerService, IRoleService manager)
+ {
+ _playerService = playerService;
+ _manager = manager.GetRoundService();
+ }
+
+ public void Start(BasePlugin plugin)
+ {
+ plugin.RegisterListener(OnTick);
+ plugin.AddTimer(0.1f, OnTickAll, TimerFlags.REPEAT);
+ }
+
+ public void Reset()
+ {
+ _playerLookAtRole.Clear();
+ _spectatorLookAtRole.Clear();
+ }
+
+ public void RegisterLookAtRole(CCSPlayerController player, Tuple role)
+ {
+ _playerLookAtRole.TryAdd(player, role);
+ }
+
+ public void RemoveLookAtRole(CCSPlayerController player)
+ {
+ _playerLookAtRole.Remove(player);
+ }
+
+ public void OnTick()
+ {
+ foreach (var gamePlayer in _playerService.Players())
+ {
+ if (_manager.GetRoundStatus() != RoundStatus.Started) return;
+
+ var player = gamePlayer.Player();
+
+ if (player == null) continue;
+ if (!player.IsReal()) continue;
+
+ var playerRole = gamePlayer.PlayerRole();
+
+ if (playerRole == Role.Unassigned) continue;
+
+ if (!player.PawnIsAlive) continue;
+
+ if (!_playerLookAtRole.TryGetValue(player, out var value))
+ {
+ Server.NextFrame(() =>
+ player.PrintToCenterHtml(
+ $"Your Role: {playerRole.GetCenterRole()}"));
+ continue;
+ }
+
+ if (!value.Item1.IsReal()) continue;
+
+ if (!value.Item1.PawnIsAlive) HandleDeadTarget(player, playerRole, value.Item1, value.Item2);
+ else HandleAliveTarget(player, playerRole, value.Item1, value.Item2);
+ }
+ }
+
+ public void HandleDeadTarget(CCSPlayerController player, Role playerRole, CCSPlayerController target, Role targetRole)
+ {
+ Server.NextFrame(() => player.PrintToCenterHtml(
+ $"Your Role: {playerRole.GetCenterRole()}
"
+ + $"{target.PlayerName}'s Corpse
"
+ + $"{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ }
+
+ public void HandleAliveTarget(CCSPlayerController player, Role playerRole, CCSPlayerController target, Role targetRole)
+ {
+ switch (targetRole)
+ {
+ case Role.Detective:
+ Server.NextFrame(() => player.PrintToCenterHtml(
+ $"Your Role: {playerRole.GetCenterRole()}
"
+ + $"{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ return;
+ case Role.Traitor when playerRole == Role.Traitor:
+ Server.NextFrame(() => player.PrintToCenterHtml(
+ $"Your Role: {playerRole.GetCenterRole()}
"
+ + $"{target.PlayerName}'s Role: {targetRole.GetCenterRole()}"));
+ return;
+ default:
+ Server.NextFrame(() => player.PrintToCenterHtml(
+ $"Your Role: {playerRole.GetCenterRole()}
"
+ + $"{target.PlayerName}'s Role: {Role.Unassigned.GetCenterRole()}"));
+ break;
+ }
+ }
+
+ public void OnTickAll()
+ {
+ var players = _playerService.Players().Select(plr => plr.Player());
+
+ _playerLookAtRole.Clear();
+
+ foreach (var player in players)
+ {
+ if (player == null) continue;
+ if (!player.IsReal()) continue;
+
+ var target = player.GetClientPlayerAimTarget();
+
+ if (target == null) continue;
+ if (!target.IsReal()) continue;
+
+ RegisterLookAtRole(player, new Tuple(target, _playerService.GetPlayer(target).PlayerRole()));
+ }
+ }
+
+ [GameEventHandler]
+ private HookResult OnPlayerSpectateChange(EventSpecTargetUpdated @event, GameEventInfo info)
+ {
+ var player = @event.Userid;
+ var target = new CCSPlayerController(@event.Target);
+
+ if (!player.IsReal() || !target.IsReal()) return HookResult.Continue;
+
+ _spectatorLookAtRole.TryAdd(player, new Tuple(target.PlayerName, _playerService.GetPlayer(target).PlayerRole()));
+
+ return HookResult.Continue;
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Manager/ManagerServiceExtension.cs b/mod/TTT.Manager/ManagerServiceExtension.cs
new file mode 100644
index 0000000..73c6d15
--- /dev/null
+++ b/mod/TTT.Manager/ManagerServiceExtension.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Manager;
+
+namespace TTT.Manager;
+
+public static class ManagerServiceExtension
+{
+ public static void AddManagerService(this IServiceCollection collection)
+ {
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Helper/MuteManager.cs b/mod/TTT.Manager/MuteManager.cs
similarity index 60%
rename from mod/TTT.Roles/Helper/MuteManager.cs
rename to mod/TTT.Manager/MuteManager.cs
index 04fe483..e602e1c 100644
--- a/mod/TTT.Roles/Helper/MuteManager.cs
+++ b/mod/TTT.Manager/MuteManager.cs
@@ -1,74 +1,104 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Modules.Admin;
-using CounterStrikeSharp.API.Modules.Utils;
-using TTT.Public.Extensions;
-
-namespace TTT.Roles;
-
-public class MuteManager
-{
-
- public MuteManager(BasePlugin plugin)
- {
- plugin.RegisterListener(OnPlayerSpeak);
- }
-
- public void Mute(CCSPlayerController player)
- {
- if (BypassMute(player))
- return;
-
- player.VoiceFlags |= VoiceFlags.Muted;
- }
-
- public void UnMute(CCSPlayerController player)
- {
- player.VoiceFlags &= ~VoiceFlags.Muted;
- }
-
- public void UnMuteAll()
- {
- foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.Terrorist))
- {
- UnMute(player);
- }
- foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.CounterTerrorist))
- {
- UnMute(player);
- }
- }
-
- private void OnPlayerSpeak(int playerSlot)
- {
- var player = Utilities.GetPlayerFromSlot(playerSlot);
- if (!player.IsReal())
- return;
-
- if (!player.PawnIsAlive && !BypassMute(player))
- {
- // Normal players can't speak when dead
- Mute(player);
- Server.NextFrame(() => player.PrintToCenter("You are dead and muted!"));
- return;
- }
-
- if (IsMuted(player))
- {
- Server.NextFrame(() => player.PrintToCenter("You are muted!"));
- return;
- }
- }
-
- private bool IsMuted(CCSPlayerController player)
- {
- if (!player.IsReal())
- return false;
- return (player.VoiceFlags & VoiceFlags.Muted) != 0;
- }
-
- private bool BypassMute(CCSPlayerController player)
- {
- return player.IsReal() && AdminManager.PlayerHasPermissions(player, "@css/chat");
- }
+using System.Linq;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Admin;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Manager;
+
+namespace TTT.Manager;
+
+public class MuteManager : IMuteService, IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+ plugin.RegisterListener(OnPlayerSpeak);
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
+ {
+ if (@event.Userid == null) return HookResult.Continue;
+ Mute(@event.Userid);
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
+ {
+ UnMuteAll();
+ return HookResult.Continue;
+ }
+
+ public void Mute(CCSPlayerController player)
+ {
+ if (BypassMute(player))
+ return;
+
+ player.VoiceFlags |= VoiceFlags.Muted;
+ }
+
+ public void UnMute(CCSPlayerController player)
+ {
+ player.VoiceFlags &= ~VoiceFlags.Muted;
+ }
+
+ public void UnMuteAll()
+ {
+ foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.Terrorist))
+ {
+ UnMute(player);
+ }
+ foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.CounterTerrorist))
+ {
+ UnMute(player);
+ }
+ }
+
+ public void MuteAll()
+ {
+ foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.Terrorist))
+ {
+ Mute(player);
+ }
+ foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team == CsTeam.CounterTerrorist))
+ {
+ Mute(player);
+ }
+ }
+
+ private void OnPlayerSpeak(int playerSlot)
+ {
+ var player = Utilities.GetPlayerFromSlot(playerSlot);
+ if (!player.IsReal())
+ return;
+
+ if (!player.PawnIsAlive && !BypassMute(player))
+ {
+ // Normal players can't speak when dead
+ Mute(player);
+ Server.NextFrame(() => player.PrintToCenter("You are dead and muted!"));
+ return;
+ }
+
+ if (IsMuted(player))
+ {
+ Server.NextFrame(() => player.PrintToCenter("You are muted!"));
+ return;
+ }
+ }
+
+ private bool IsMuted(CCSPlayerController player)
+ {
+ if (!player.IsReal())
+ return false;
+ return (player.VoiceFlags & VoiceFlags.Muted) != 0;
+ }
+
+ private bool BypassMute(CCSPlayerController player)
+ {
+ return player.IsReal() && AdminManager.PlayerHasPermissions(player, "@css/chat");
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Manager/TTT.Manager.csproj b/mod/TTT.Manager/TTT.Manager.csproj
new file mode 100644
index 0000000..d0b8182
--- /dev/null
+++ b/mod/TTT.Manager/TTT.Manager.csproj
@@ -0,0 +1,12 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
diff --git a/mod/TTT.Manager/TraitorRoom.cs b/mod/TTT.Manager/TraitorRoom.cs
new file mode 100644
index 0000000..2ef1705
--- /dev/null
+++ b/mod/TTT.Manager/TraitorRoom.cs
@@ -0,0 +1,44 @@
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Player;
+
+namespace TTT.Manager;
+
+public class TraitorRoom(IPlayerService service) : IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+ plugin.AddTimer(0.1f, () =>
+ {
+ foreach (var plr in Utilities.GetPlayers().Where(player => player.IsReal()))
+ {
+ OpenTraitorRoom(plr);
+ }
+ });
+ }
+
+
+ public void OpenTraitorRoom(CCSPlayerController player)
+ {
+ if ((player.Buttons & PlayerButtons.Use) == 0) return;
+
+ var traitorRoom = player.GetClientPlayerTraitorRoom();
+
+ if (traitorRoom == null)
+ {
+ Server.NextFrame(() => player.PrintToCenter("No door has been found!"));
+ return;
+ }
+
+ if (traitorRoom.Globalname is not "traitor_door")
+ {
+ Server.NextFrame(() => player.PrintToCenter("Door is not a traitor room!"));
+ return;
+ }
+
+ traitorRoom.AcceptInput("Open");
+ Server.NextFrame(() => player.PrintToCenter("Found traitor room!"));
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Player/AntiBlockManager.cs b/mod/TTT.Player/AntiBlockManager.cs
new file mode 100644
index 0000000..14dc7d3
--- /dev/null
+++ b/mod/TTT.Player/AntiBlockManager.cs
@@ -0,0 +1,72 @@
+using System.Runtime.InteropServices;
+using System.Text.Json.Serialization;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Entities.Constants;
+using CounterStrikeSharp.API.Modules.Memory;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+
+namespace TTT.Player;
+
+public class AntiBlockManager : IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+ }
+
+ [GameEventHandler]
+ private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
+ {
+ if (!@event.Userid.IsValid) return HookResult.Continue;
+
+ var player = @event.Userid;
+
+ if (!player.IsReal()) return HookResult.Continue;
+
+ if (!player.PlayerPawn.IsValid) return HookResult.Continue;
+
+ var pawn = player.PlayerPawn;
+
+ Server.NextFrame(() => PlayerSpawnNextFrame(player, pawn));
+
+ return HookResult.Continue;
+ }
+
+ private readonly WIN_LINUX OnCollisionRulesChangedOffset = new(173, 172);
+
+ private void PlayerSpawnNextFrame(CCSPlayerController player, CHandle pawn)
+ {
+ pawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
+
+ pawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
+
+ var collisionRulesChanged =
+ new VirtualFunctionVoid(pawn.Value.Handle, OnCollisionRulesChangedOffset.Get());
+
+ collisionRulesChanged.Invoke(pawn.Value.Handle);
+ }
+
+ public class WIN_LINUX
+ {
+ [JsonPropertyName("Windows")] public T Windows { get; private set; }
+
+ [JsonPropertyName("Linux")] public T Linux { get; private set; }
+
+ public WIN_LINUX(T windows, T linux)
+ {
+ Windows = windows;
+ Linux = linux;
+ }
+
+ public T Get()
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ return Windows;
+ else
+ return Linux;
+ }
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Shop/CreditManager.cs b/mod/TTT.Player/CreditManager.cs
similarity index 67%
rename from mod/TTT.Roles/Shop/CreditManager.cs
rename to mod/TTT.Player/CreditManager.cs
index b516972..b694b93 100644
--- a/mod/TTT.Roles/Shop/CreditManager.cs
+++ b/mod/TTT.Player/CreditManager.cs
@@ -1,54 +1,49 @@
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using TTT.Public.Extensions;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-
-namespace TTT.Roles.Shop;
-
-public class CreditManager
-{
- private readonly IPlayerService _playerService;
-
- private CreditManager(BasePlugin plugin, IPlayerService playerService)
- {
- _playerService = playerService;
- plugin.RegisterEventHandler(OnPlayerDeath);
- }
-
- public static void Register(BasePlugin parent, IPlayerService service)
- {
- new CreditManager(parent, service);
- }
-
- [GameEventHandler]
- public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
- {
- var attacker = @event.Attacker;
- var victim = @event.Userid;
-
- if (attacker == null || victim == null) return HookResult.Continue;
- if (attacker == victim) return HookResult.Continue;
-
- var attackerPlayer = _playerService.GetPlayer(attacker);
- var victimPlayer = _playerService.GetPlayer(victim);
-
- if (attackerPlayer.PlayerRole() == Role.Traitor && victimPlayer.PlayerRole() != Role.Traitor)
- {
- attackerPlayer.AddCredits(250);
- return HookResult.Continue;
- }
-
- if (attackerPlayer.PlayerRole() != Role.Traitor && victimPlayer.PlayerRole() == Role.Traitor)
- {
- attackerPlayer.AddCredits(250);
- return HookResult.Continue;
- }
-
- attackerPlayer.RemoveCredits(100);
-
- return HookResult.Continue;
- }
-
-
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Roles.Shop;
+
+public class CreditManager(IPlayerService playerService) : IPluginBehavior
+{
+
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+
+ [GameEventHandler]
+ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
+ {
+ var attacker = @event.Attacker;
+ var victim = @event.Userid;
+
+ if (attacker == null || victim == null) return HookResult.Continue;
+ if (attacker == victim) return HookResult.Continue;
+
+ var attackerPlayer = playerService.GetPlayer(attacker);
+ var victimPlayer = playerService.GetPlayer(victim);
+
+ if (attackerPlayer.PlayerRole() == Role.Traitor && victimPlayer.PlayerRole() != Role.Traitor)
+ {
+ attackerPlayer.AddCredits(250);
+ return HookResult.Continue;
+ }
+
+ if (attackerPlayer.PlayerRole() != Role.Traitor && victimPlayer.PlayerRole() == Role.Traitor)
+ {
+ attackerPlayer.AddCredits(250);
+ return HookResult.Continue;
+ }
+
+ attackerPlayer.RemoveCredits(100);
+
+ return HookResult.Continue;
+ }
+
+
}
\ No newline at end of file
diff --git a/mod/TTT.Player/KarmaManager.cs b/mod/TTT.Player/KarmaManager.cs
new file mode 100644
index 0000000..336e9da
--- /dev/null
+++ b/mod/TTT.Player/KarmaManager.cs
@@ -0,0 +1,43 @@
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Player;
+
+public class KarmaManager(IPlayerService playerService) : IPluginBehavior
+{
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
+ {
+ var killedPlayer = @event.Userid;
+ var killer = @event.Attacker;
+ if (killedPlayer == null || !killedPlayer.IsReal()) return HookResult.Continue;
+ if (killer == null || !killer.IsReal()) return HookResult.Continue;
+
+ var gpKiller = playerService.GetPlayer(killer);
+ var gpKilled = playerService.GetPlayer(killedPlayer);
+
+ var killerRole = gpKiller.PlayerRole();
+ var killedRole = gpKilled.PlayerRole();
+
+ if (killerRole == killedRole)
+ {
+ gpKiller.RemoveKarma(5);
+ return HookResult.Stop;
+ }
+
+ if (killedRole == Role.Traitor)
+ {
+ gpKiller.AddKarma(2);
+ }
+ return HookResult.Continue;
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Player/PlayerBehavior.cs b/mod/TTT.Player/PlayerBehavior.cs
new file mode 100644
index 0000000..9785918
--- /dev/null
+++ b/mod/TTT.Player/PlayerBehavior.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using TTT.Public.Behaviors;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+using TTT.Round;
+
+namespace TTT.Player;
+
+public class PlayerBehavior() : IPlayerService, IPluginBehavior
+{
+
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
+ {
+ if (@event.Userid == null) throw new NullReferenceException("Could not find player object when connecting.");
+ CreatePlayer(@event.Userid);
+ return HookResult.Continue;
+ }
+
+ private readonly Dictionary _players = [];
+
+ public Dictionary GetPlayers()
+ {
+ return _players;
+ }
+
+ public void CreatePlayer(CCSPlayerController player)
+ {
+ if (_players.ContainsKey(player)) return;
+ _players.Add(player, new GamePlayer(Role.Unassigned, 0, 110, player.UserId.Value));
+ }
+
+ public void AddKarma(CCSPlayerController player, int karma)
+ {
+ if (!_players.TryGetValue(player, out var value)) return;
+ if (karma < 0) return;
+
+ if (karma + value.Karma() > 110)
+ value.SetKarma(110);
+ else
+ value.AddKarma(karma);
+ }
+
+ public void RemoveKarma(CCSPlayerController player, int karma)
+ {
+ if (!_players.TryGetValue(player, out var value)) return;
+ if (karma < 0) return;
+
+ if (value.Karma() - karma < 40)
+ value.SetKarma(40);
+ else
+ value.RemoveKarma(karma);
+ }
+
+ public List Players()
+ {
+ return _players.Values.ToList();
+ }
+
+ public GamePlayer GetPlayer(CCSPlayerController player)
+ {
+ return _players[player];
+ }
+
+ public void RemovePlayer(CCSPlayerController player)
+ {
+ _players.Remove(player);
+ }
+
+ public void Clr()
+ {
+ foreach (var player in Players())
+ {
+ player.SetKiller(null);
+ player.SetPlayerRole(Role.Unassigned);
+ player.ResetCredits();
+ player.ModifyKarma();
+ player.SetFound(false);
+ player.SetDead();
+ }
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Player/PlayerConfig.cs b/mod/TTT.Player/PlayerConfig.cs
new file mode 100644
index 0000000..51d41de
--- /dev/null
+++ b/mod/TTT.Player/PlayerConfig.cs
@@ -0,0 +1,9 @@
+namespace TTT.Player;
+
+public class PlayerConfig
+{
+ public int StartCredits { get; } = 1000;
+ public int StartKarma { get; } = 80;
+ public int MaxKarma { get; } = 110;
+ public int MinKarma { get; } = 40;
+}
\ No newline at end of file
diff --git a/mod/TTT.Player/PlayerServiceExtension.cs b/mod/TTT.Player/PlayerServiceExtension.cs
new file mode 100644
index 0000000..048c288
--- /dev/null
+++ b/mod/TTT.Player/PlayerServiceExtension.cs
@@ -0,0 +1,17 @@
+using Microsoft.Extensions.DependencyInjection;
+using TTT.Public.Extensions;
+using TTT.Public.Player;
+using TTT.Roles.Shop;
+
+namespace TTT.Player;
+
+public static class PlayerServiceExtension
+{
+ public static void AddPlayerService(this IServiceCollection collection)
+ {
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ }
+}
diff --git a/mod/TTT.Player/TTT.Player.csproj b/mod/TTT.Player/TTT.Player.csproj
new file mode 100644
index 0000000..ce5ec60
--- /dev/null
+++ b/mod/TTT.Player/TTT.Player.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/mod/TTT.Roles/Commands/RolesCommand.cs b/mod/TTT.Roles/Commands/RolesCommand.cs
index e133542..c396b49 100644
--- a/mod/TTT.Roles/Commands/RolesCommand.cs
+++ b/mod/TTT.Roles/Commands/RolesCommand.cs
@@ -1,54 +1,62 @@
-using System.Text;
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using CounterStrikeSharp.API.Modules.Admin;
-using CounterStrikeSharp.API.Modules.Commands;
-using TTT.Public.Behaviors;
-using TTT.Public.Extensions;
-using TTT.Public.Formatting;
-using TTT.Public.Mod.Role;
-using TTT.Public.Mod.Round;
-
-namespace TTT.Roles.Commands;
-
-public class RolesCommand : IPluginBehavior
-{
- private readonly IRoleService _roleService;
- private readonly IRoundService _roundService;
-
- public RolesCommand(IRoleService roleService, IRoundService roundService)
- {
- _roleService = roleService;
- _roundService = roundService;
- }
-
- [ConsoleCommand("css_roles", "Get the roles of all players")]
- [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
- public void Command_Toggle(CCSPlayerController? player, CommandInfo command)
- {
- if (!AdminManager.PlayerHasPermissions(player, "@css/kick")) return;
-
- if (_roundService.GetRoundStatus() != RoundStatus.Started)
- {
- command.ReplyToCommand(StringUtils.FormatTTT("The round has not started yet."));
- return;
- }
-
- StringBuilder sb = new();
-
- sb.AppendLine(StringUtils.FormatTTT("List of all players roles:"));
-
- foreach (var gamePlayer in _roleService.Players())
- {
- var plr = gamePlayer.Player();
- if (plr == null) continue;
- sb.AppendLine(StringUtils.FormatTTT(gamePlayer.PlayerRole().FormatStringAfter(plr.PlayerName)));
- }
-
- sb.AppendLine(StringUtils.FormatTTT("End."));
-
-
- command.ReplyToCommand(sb.ToString());
- }
+using System.Text;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Admin;
+using CounterStrikeSharp.API.Modules.Commands;
+using CounterStrikeSharp.API.Modules.Menu;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Formatting;
+using TTT.Public.Mod.Role;
+using TTT.Public.Mod.Round;
+using TTT.Public.Player;
+
+namespace TTT.Roles.Commands;
+
+public class RolesCommand : IPluginBehavior
+{
+ private readonly IPlayerService _roleService;
+ private readonly IRoundService _roundService;
+
+ public RolesCommand(IPlayerService roleService, IRoleService roundService)
+ {
+ _roleService = roleService;
+ _roundService = roundService.GetRoundService();
+ }
+
+ public void Start(BasePlugin plugin)
+ {
+
+ }
+
+ [ConsoleCommand("css_roles", "Get the roles of all players")]
+ [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)]
+ public void Command_Toggle(CCSPlayerController? player, CommandInfo command)
+ {
+ if (!AdminManager.PlayerHasPermissions(player, "@css/kick"))
+ {
+ command.ReplyToCommand(StringUtils.FormatTTT("You do not have permission to execute this command"));
+ return;
+ }
+
+ if (_roundService.GetRoundStatus() != RoundStatus.Started)
+ {
+ command.ReplyToCommand(StringUtils.FormatTTT("The round has not started yet."));
+ return;
+ }
+
+ StringBuilder sb = new();
+
+ command.ReplyToCommand(StringUtils.FormatTTT("List of all players roles:"));
+
+ foreach (var gamePlayer in _roleService.Players())
+ {
+ var plr = gamePlayer.Player();
+ if (plr == null) continue;
+ command.ReplyToCommand(StringUtils.FormatTTT(gamePlayer.PlayerRole().FormatStringFullAfter(plr.PlayerName)));
+ }
+
+ command.ReplyToCommand(StringUtils.FormatTTT("End."));
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Helper/KarmaManager.cs b/mod/TTT.Roles/Helper/KarmaManager.cs
deleted file mode 100644
index bebfca3..0000000
--- a/mod/TTT.Roles/Helper/KarmaManager.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using CounterStrikeSharp.API.Core;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-
-namespace TTT.Roles;
-
-public class KarmaManager
-{
- public KarmaManager(BasePlugin plugin, IRoleService service)
- {
- plugin.RegisterEventHandler((@event, info) =>
- {
- var attacker = @event.Attacker;
- var killedPlayer = @event.Userid;
-
- if (killedPlayer == null || attacker == null) return HookResult.Continue;
- if (killedPlayer == attacker) return HookResult.Continue;
-
- var attackerRole = service.GetRole(attacker);
- var killedRole = service.GetRole(killedPlayer);
-
- if (attackerRole == Role.Traitor && killedRole != Role.Traitor) return HookResult.Continue;
-
- service.GetPlayer(attacker).AddKarma();
-
- return HookResult.Continue;
- });
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Helper/RDMListener.cs b/mod/TTT.Roles/Helper/RDMListener.cs
deleted file mode 100644
index 65b9e37..0000000
--- a/mod/TTT.Roles/Helper/RDMListener.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using TTT.Public.Behaviors;
-using TTT.Public.Mod.Role;
-using TTT.Public.Mod.Round;
-using TTT.Round;
-
-namespace TTT.Roles;
-
-public class RDMListener(IRoleService roleService) : IPluginBehavior
-{
- public void Start(BasePlugin plugin)
- {
- plugin.RegisterEventHandler(OnPlayerKill);
- }
-
- [GameEventHandler]
- private HookResult OnPlayerKill(EventPlayerDeath @event, GameEventInfo info)
- {
- var attacker = @event.Attacker;
- var killedPlayer = @event.Userid;
-
- if (killedPlayer == null || attacker == null) return HookResult.Continue;
-
- var attackerRole = roleService.GetRole(attacker);
- var killedRole = roleService.GetRole(killedPlayer);
-
- if (attackerRole == Role.Traitor && killedRole != Role.Traitor) return HookResult.Continue;
- if (killedRole == Role.Traitor) return HookResult.Continue;
-
- roleService.GetPlayer(attacker).RemoveKarma();
-
- return HookResult.Continue;
- }
-}
diff --git a/mod/TTT.Roles/Helper/ModelHandler.cs b/mod/TTT.Roles/ModelHandler.cs
similarity index 96%
rename from mod/TTT.Roles/Helper/ModelHandler.cs
rename to mod/TTT.Roles/ModelHandler.cs
index 0623d6f..986e14f 100644
--- a/mod/TTT.Roles/Helper/ModelHandler.cs
+++ b/mod/TTT.Roles/ModelHandler.cs
@@ -1,36 +1,38 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-
-namespace TTT.Roles;
-
-public class ModelHandler
-{
- public static readonly string ModelPathCtmHeavy = "characters\\models\\ctm_heavy\\ctm_heavy.vmdl";
- public static readonly string ModelPathCtmSas = "characters\\models\\ctm_sas\\ctm_sas.vmdl";
- public static readonly string ModelPathTmHeavy = "characters\\models\\tm_phoenix_heavy\\tm_phoenix_heavy.vmdl";
- public static readonly string ModelPathTmPhoenix = "characters\\models\\tm_phoenix\\tm_phoenix.vmdl";
-
- public static void RegisterListener(BasePlugin plugin)
- {
- plugin.RegisterListener(map =>
- {
- Server.PrecacheModel(ModelPathCtmHeavy);
- Server.PrecacheModel(ModelPathCtmSas);
- Server.PrecacheModel(ModelPathTmPhoenix);
- Server.PrecacheModel(ModelPathTmHeavy);
- });
- }
-
- public static void SetModel(CCSPlayerController player, string modelPath)
- {
- player.PlayerPawn.Value.SetModel(modelPath);
- }
-
- public static void SetModelNextServerFrame(CCSPlayerController playerPawn, string model)
- {
- Server.NextFrame(() =>
- {
- SetModel(playerPawn, model);
- });
- }
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+
+namespace TTT.Roles;
+
+public class ModelHandler
+{
+ public static readonly string ModelPathCtmHeavy = "characters\\models\\ctm_heavy\\ctm_heavy.vmdl";
+ public static readonly string ModelPathCtmSas = "characters\\models\\ctm_sas\\ctm_sas.vmdl";
+ public static readonly string ModelPathTmHeavy = "characters\\models\\tm_phoenix_heavy\\tm_phoenix_heavy.vmdl";
+ public static readonly string ModelPathTmPhoenix = "characters\\models\\tm_phoenix\\tm_phoenix.vmdl";
+
+
+
+ public static void RegisterListener(BasePlugin plugin)
+ {
+ plugin.RegisterListener(map =>
+ {
+ Server.PrecacheModel(ModelPathCtmHeavy);
+ Server.PrecacheModel(ModelPathCtmSas);
+ Server.PrecacheModel(ModelPathTmPhoenix);
+ Server.PrecacheModel(ModelPathTmHeavy);
+ });
+ }
+
+ public static void SetModel(CCSPlayerController player, string modelPath)
+ {
+ player.PlayerPawn.Value.SetModel(modelPath);
+ }
+
+ public static void SetModelNextServerFrame(CCSPlayerController playerPawn, string model)
+ {
+ Server.NextFrame(() =>
+ {
+ SetModel(playerPawn, model);
+ });
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Player/PlayerHandler.cs b/mod/TTT.Roles/Player/PlayerHandler.cs
deleted file mode 100644
index 3a20236..0000000
--- a/mod/TTT.Roles/Player/PlayerHandler.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using CounterStrikeSharp.API.Core;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-using TTT.Round;
-
-namespace TTT.Player;
-
-public class PlayerHandler : IPlayerService
-{
- private readonly Dictionary _players = [];
-
- public Dictionary GetPlayers()
- {
- return _players;
- }
-
- public void CreatePlayer(CCSPlayerController player)
- {
- if (_players.ContainsKey(player)) return;
- _players.Add(player, new GamePlayer(Role.Unassigned, 1000, 80, player.UserId.Value));
- }
-
- public List Players()
- {
- return _players.Values.ToList();
- }
-
- public GamePlayer GetPlayer(CCSPlayerController player)
- {
- return _players[player];
- }
-
- public void RemovePlayer(CCSPlayerController player)
- {
- _players.Remove(player);
- }
-
- public void Clr()
- {
- foreach (var player in Players())
- {
- player.SetKiller(null);
- player.SetPlayerRole(Role.Unassigned);
- player.SetRagdollProp(null);
- player.ResetCredits();
- player.ModifyKarma();
- player.SetFound(false);
- player.SetDead();
- }
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Roles/RoleBehavior.cs b/mod/TTT.Roles/RoleBehavior.cs
new file mode 100644
index 0000000..860129a
--- /dev/null
+++ b/mod/TTT.Roles/RoleBehavior.cs
@@ -0,0 +1,302 @@
+using System.Drawing;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Core.Attributes.Registration;
+using CounterStrikeSharp.API.Modules.Entities.Constants;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Player;
+using TTT.Public.Behaviors;
+using TTT.Public.Extensions;
+using TTT.Public.Formatting;
+using TTT.Public.Mod.Role;
+using TTT.Public.Mod.Round;
+using TTT.Public.Player;
+using TTT.Round;
+
+namespace TTT.Roles;
+
+public class RoleBehavior : IRoleService, IPluginBehavior
+{
+ private const int MaxDetectives = 3;
+
+ private int _innocentsLeft;
+ private IRoundService _roundService;
+ private int _traitorsLeft;
+ private readonly IPlayerService service;
+
+ public RoleBehavior(IPlayerService playerService)
+ {
+ _roundService = new RoundBehavior(this);
+ service = playerService;
+ }
+
+ public void Start(BasePlugin parent)
+ {
+ ModelHandler.RegisterListener(parent);
+ _roundService.Start(parent);
+ /*
+ parent.RegisterEventHandler(OnPlayerConnect);
+ parent.RegisterEventHandler(OnRoundStart);
+ parent.RegisterEventHandler(OnRoundEnd);
+ parent.RegisterEventHandler(OnPlayerDisconnect);
+ parent.RegisterEventHandler(OnPlayerDeath, HookMode.Pre);
+ parent.RegisterEventHandler(OnMapStart);
+ */
+ }
+
+ public IRoundService GetRoundService()
+ {
+ return _roundService;
+ }
+
+ [GameEventHandler]
+ public HookResult OnRoundStart(EventRoundFreezeEnd @event, GameEventInfo info)
+ {
+ _roundService.SetRoundStatus(RoundStatus.Waiting);
+ foreach (var player in Utilities.GetPlayers().Where(player =>
+ player.IsReal() && player.Team != CsTeam.None || player.Team != CsTeam.Spectator))
+ {
+ player.RemoveWeapons();
+ if (!string.IsNullOrEmpty("weapon_glock"))
+ player.GiveNamedItem("weapon_glock");
+
+ if (!string.IsNullOrEmpty(string.Empty))
+ player.GiveNamedItem(string.Empty);
+
+ player.GiveNamedItem("weapon_glock");
+ service.GetPlayer(player).ModifyKarma();
+ }
+
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
+ {
+ if (Utilities.GetPlayers().Count(player =>
+ player.IsReal() && player.Team != CsTeam.None || player.Team == CsTeam.Spectator) < 3)
+ {
+ _roundService.ForceEnd();
+ }
+
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
+ {
+ info.DontBroadcast = true;
+
+ var playerWhoWasDamaged = @event.Userid;
+ var attacker = @event.Attacker;
+
+
+
+
+ if (playerWhoWasDamaged == null) return HookResult.Continue;
+
+ SetColor(playerWhoWasDamaged);
+
+ playerWhoWasDamaged.ModifyScoreBoard();
+
+ service.GetPlayer(playerWhoWasDamaged).SetKiller(attacker);
+
+ if (IsTraitor(playerWhoWasDamaged)) _traitorsLeft--;
+
+ if (IsDetective(playerWhoWasDamaged) || IsInnocent(playerWhoWasDamaged)) _innocentsLeft--;
+
+ if (_traitorsLeft == 0 || _innocentsLeft == 0) Server.NextFrame(() => _roundService.ForceEnd());
+
+ Server.NextFrame(() => playerWhoWasDamaged.CommitSuicide(false, true));
+
+ Server.NextFrame(() =>
+ {
+ Server.PrintToChatAll(
+ StringUtils.FormatTTT($"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}"));
+
+ if (attacker == playerWhoWasDamaged || attacker == null) return;
+
+ attacker.ModifyScoreBoard();
+
+ playerWhoWasDamaged.PrintToChat(StringUtils.FormatTTT(
+ $"You were killed by {GetRole(attacker).FormatStringFullAfter(" " + attacker.PlayerName)}."));
+ attacker.PrintToChat(StringUtils.FormatTTT(
+ $"You killed {GetRole(playerWhoWasDamaged).FormatStringFullAfter(" " + playerWhoWasDamaged.PlayerName)}."));
+ });
+
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
+ {
+ var players = Utilities.GetPlayers()
+ .Where(player => player.IsValid).Where(player => player.IsReal()).ToList();
+
+ foreach (var player in players) player.PrintToCenter(GetWinner().FormatStringFullAfter("s has won!"));
+
+ Server.NextFrame(Clear);
+
+ return HookResult.Continue;
+ }
+
+ [GameEventHandler]
+ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
+ {
+ var player = @event.Userid;
+ Server.NextFrame(() =>
+ {
+ service.RemovePlayer(player);
+ if (service.Players().Count == 0) _roundService.SetRoundStatus(RoundStatus.Paused);
+ });
+
+ return HookResult.Continue;
+ }
+
+ public void AddRoles()
+ {
+ var eligible = Utilities.GetPlayers()
+ .Where(player => player.IsReal())
+ .Where(player => player.Team is not (CsTeam.Spectator or CsTeam.None))
+ .ToList();
+
+ var traitorCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 3));
+ var detectiveCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 8));
+
+ _traitorsLeft = traitorCount;
+ _innocentsLeft = eligible.Count - traitorCount;
+
+ if (detectiveCount > MaxDetectives) detectiveCount = MaxDetectives;
+
+ for (var i = 0; i < traitorCount; i++)
+ {
+ var chosen = eligible[Random.Shared.Next(eligible.Count)];
+ eligible.Remove(chosen);
+ AddTraitor(chosen);
+ }
+
+ for (var i = 0; i < detectiveCount; i++)
+ {
+ var chosen = eligible[Random.Shared.Next(eligible.Count)];
+ eligible.Remove(chosen);
+ AddDetective(chosen);
+ }
+
+ AddInnocents(eligible);
+ }
+
+ public ISet GetTraitors()
+ {
+ return service.Players().Where(player => player.PlayerRole() == Role.Traitor).Select(player => player.Player())
+ .ToHashSet();
+ }
+
+ public ISet GetDetectives()
+ {
+ return service.Players().Where(player => player.PlayerRole() == Role.Detective).Select(player => player.Player())
+ .ToHashSet();
+ }
+
+ public ISet GetInnocents()
+ {
+ return service.Players().Where(player => player.PlayerRole() == Role.Innocent).Select(player => player.Player())
+ .ToHashSet();
+ }
+
+
+ public Role GetRole(CCSPlayerController player)
+ {
+ return service.GetPlayer(player).PlayerRole();
+ }
+
+ public void AddTraitor(CCSPlayerController player)
+ {
+ service.GetPlayer(player).SetPlayerRole(Role.Traitor);
+ player.SwitchTeam(CsTeam.Terrorist);
+ player.PrintToCenter(Role.Traitor.FormatStringFullBefore("You are now a(n)"));
+ player.PrintToChat(Role.Traitor.FormatStringFullBefore("You are now a(n)"));
+ ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathTmPhoenix);
+ }
+
+ public void AddDetective(CCSPlayerController player)
+ {
+ service.GetPlayer(player).SetPlayerRole(Role.Detective);
+ player.SwitchTeam(CsTeam.CounterTerrorist);
+ player.PrintToCenter(Role.Detective.FormatStringFullBefore("You are now a(n)"));
+ player.GiveNamedItem(CsItem.Taser);
+ ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathCtmSas);
+ }
+
+ public void AddInnocents(IEnumerable players)
+ {
+ foreach (var player in players)
+ {
+ service.GetPlayer(player).SetPlayerRole(Role.Innocent);
+ player.PrintToCenter(Role.Innocent.FormatStringFullBefore("You are now an"));
+ player.SwitchTeam(CsTeam.Terrorist);
+ ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathTmPhoenix);
+ }
+ }
+
+ public bool IsDetective(CCSPlayerController player)
+ {
+ return service.GetPlayer(player).PlayerRole() == Role.Detective;
+ }
+
+ public bool IsTraitor(CCSPlayerController player)
+ {
+ return service.GetPlayer(player).PlayerRole() == Role.Traitor;
+ }
+
+ public void Clear()
+ {
+ service.Clr();
+ foreach (var key in service.Players())
+ {
+ key.SetPlayerRole(Role.Unassigned);
+ if (key.Player() == null) continue;
+ RemoveColor(key.Player());
+ }
+ }
+
+ public bool IsInnocent(CCSPlayerController player)
+ {
+ return service.GetPlayer(player).PlayerRole() == Role.Innocent;
+ }
+
+ private Role GetWinner()
+ {
+ return _traitorsLeft == 0 ? Role.Traitor : Role.Innocent;
+ }
+
+ public void SetColor(CCSPlayerController player)
+ {
+ if (!player.IsReal()) return;
+
+ var pawn = player.PlayerPawn.Value;
+
+ if (pawn == null || !pawn.IsValid) return;
+
+ pawn.RenderMode = RenderMode_t.kRenderTransColor;
+ pawn.Render = GetRole(player).GetColor();
+
+ Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");
+ }
+
+ public void RemoveColor(CCSPlayerController player)
+ {
+ if (!player.IsReal()) return;
+
+ var pawn = player.PlayerPawn.Value;
+
+ if (pawn == null || !pawn.IsValid) return;
+
+ pawn.RenderMode = RenderMode_t.kRenderTransColor;
+ pawn.Render = Color.FromArgb(254, 255, 255, 255);
+
+
+ Utilities.SetStateChanged(pawn, "CBaseModelEntity", "m_clrRender");
+
+ }
+}
+
diff --git a/mod/TTT.Roles/RoleConfig.cs b/mod/TTT.Roles/RoleConfig.cs
new file mode 100644
index 0000000..74619c4
--- /dev/null
+++ b/mod/TTT.Roles/RoleConfig.cs
@@ -0,0 +1,10 @@
+namespace TTT.Roles;
+
+public class RoleConfig
+{
+ public int TraitorRatio { get; } = 3;
+ public int DetectiveRatio { get; } = 8;
+ public string? SecondaryWeapon { get; } = "weapon_glock";
+ public string? PrimaryWeapon { get; } = "";
+
+}
\ No newline at end of file
diff --git a/mod/TTT.Roles/RoleManager.cs b/mod/TTT.Roles/RoleManager.cs
deleted file mode 100644
index 4c8147b..0000000
--- a/mod/TTT.Roles/RoleManager.cs
+++ /dev/null
@@ -1,516 +0,0 @@
-using System.Drawing;
-using System.Runtime.InteropServices;
-using System.Text.Json.Serialization;
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using CounterStrikeSharp.API.Modules.Entities.Constants;
-using CounterStrikeSharp.API.Modules.Memory;
-using CounterStrikeSharp.API.Modules.Utils;
-using Microsoft.Extensions.Logging;
-using TTT.Player;
-using TTT.Public.Action;
-using TTT.Public.Behaviors;
-using TTT.Public.Extensions;
-using TTT.Public.Formatting;
-using TTT.Public.Mod.Role;
-using TTT.Public.Mod.Round;
-using TTT.Roles.Shop;
-using TTT.Round;
-
-namespace TTT.Roles;
-
-public class RoleManager : PlayerHandler, IRoleService, IPluginBehavior
-{
- private const int MaxDetectives = 3;
-
- private int _innocentsLeft;
- private IRoundService _roundService;
- private int _traitorsLeft;
- private InfoManager _infoManager;
- private MuteManager _muteManager;
-
- public void Start(BasePlugin parent)
- {
- _roundService = new RoundManager(this, parent);
- _infoManager = new InfoManager(this, _roundService, parent);
- _muteManager = new MuteManager(parent);
- ModelHandler.RegisterListener(parent);
- //ShopManager.Register(parent, this); //disabled until items are implemented.
- //CreditManager.Register(parent, this);
-
- parent.RegisterEventHandler(OnPlayerConnect);
- parent.RegisterEventHandler(OnRoundStart);
- parent.RegisterEventHandler(OnRoundEnd);
- parent.RegisterEventHandler(OnPlayerDisconnect);
- parent.RegisterEventHandler(OnPlayerDeath, HookMode.Pre);
- parent.RegisterEventHandler(OnMapStart);
- parent.RegisterEventHandler(Event_PlayerSpawn, HookMode.Post);
-
- VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
- {
- var ent = hook.GetParam(0);
-
- var playerWhoWasDamaged = player(ent);
-
- if (playerWhoWasDamaged == null) return HookResult.Continue;
-
- var info = hook.GetParam(1);
-
- CCSPlayerController? attacker = null;
-
- if (info.Attacker.Value != null)
- {
- var playerWhoAttacked = info.Attacker.Value.As();
-
- attacker = playerWhoAttacked.Controller.Value.As();
-
- }
-
- if (info.BitsDamageType is not 256) return HookResult.Continue;
- if (attacker == null) return HookResult.Continue;
-
- info.Damage = 0;
-
- var targetRole = GetPlayer(playerWhoWasDamaged);
-
- Server.NextFrame(() =>
- {
- attacker.PrintToChat(
- StringUtils.FormatTTT(
- $"You tased player {playerWhoWasDamaged.PlayerName} they are a {targetRole.PlayerRole().FormatRoleFull()}"));
- });
-
- _roundService.GetLogsService().AddLog(new MiscAction("tased player " + targetRole.PlayerRole().FormatStringFullAfter(playerWhoWasDamaged.PlayerName), attacker));
-
- return HookResult.Stop;
-
- }, HookMode.Pre);
-
- }
-
- [GameEventHandler]
- private HookResult OnRoundStart(EventRoundFreezeEnd @event, GameEventInfo info)
- {
- _roundService.SetRoundStatus(RoundStatus.Waiting);
- foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal() && player.Team != CsTeam.None || player.Team != CsTeam.Spectator))
- {
- player.RemoveWeapons();
- player.GiveNamedItem("weapon_knife");
- player.GiveNamedItem("weapon_glock");
- }
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
- {
- if (Utilities.GetPlayers().Count(player => player.IsReal() && player.Team != CsTeam.None || player.Team == CsTeam.Spectator) < 3)
- {
- _roundService.ForceEnd();
- }
-
- CreatePlayer(@event.Userid);
-
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnMapStart(EventGameStart @event, GameEventInfo info)
- {
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
- {
- info.DontBroadcast = true;
-
- var playerWhoWasDamaged = @event.Userid;
- var attacker = @event.Attacker;
-
- if (playerWhoWasDamaged == null) return HookResult.Continue;
-
- playerWhoWasDamaged.ModifyScoreBoard();
-
- GetPlayer(playerWhoWasDamaged).SetKiller(attacker);
-
- _muteManager.Mute(playerWhoWasDamaged);
-
- if (IsTraitor(playerWhoWasDamaged)) _traitorsLeft--;
-
- if (IsDetective(playerWhoWasDamaged) || IsInnocent(playerWhoWasDamaged)) _innocentsLeft--;
-
- if (_traitorsLeft == 0 || _innocentsLeft == 0) Server.NextFrame(() => _roundService.ForceEnd());
-
- Server.NextFrame(() => playerWhoWasDamaged.CommitSuicide(false, true));
-
- Server.NextFrame(() =>
- {
- Server.PrintToChatAll(StringUtils.FormatTTT($"{GetRole(playerWhoWasDamaged).FormatStringFullAfter(" has been found.")}"));
-
- if (attacker == playerWhoWasDamaged || attacker == null) return;
-
- attacker.ModifyScoreBoard();
-
- playerWhoWasDamaged.PrintToChat(StringUtils.FormatTTT(
- $"You were killed by {GetRole(attacker).FormatStringFullAfter(" " + attacker.PlayerName)}."));
- attacker.PrintToChat(StringUtils.FormatTTT($"You killed {GetRole(playerWhoWasDamaged).FormatStringFullAfter(" " + playerWhoWasDamaged.PlayerName)}."));
- });
-
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
- {
- var players = Utilities.GetPlayers()
- .Where(player => player.IsValid).Where(player => player.IsReal()).ToList();
-
- foreach (var player in players) player.PrintToCenter(GetWinner().FormatStringFullAfter("s has won!"));
-
- Server.NextFrame(Clear);
- _muteManager.UnMuteAll();
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
- {
- var player = @event.Userid;
- Server.NextFrame(() =>
- {
- RemovePlayer(player);
- if (GetPlayers().Count == 0) _roundService.SetRoundStatus(RoundStatus.Paused);
- });
-
- return HookResult.Continue;
- }
-
- public void AddRoles()
- {
- var eligible = Utilities.GetPlayers()
- .Where(player => player.IsReal())
- .Where(player => player.Team is not (CsTeam.Spectator or CsTeam.None))
- .ToList();
-
- var traitorCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 3));
- var detectiveCount = (int)Math.Floor(Convert.ToDouble(eligible.Count / 8));
-
- _traitorsLeft = traitorCount;
- _innocentsLeft = eligible.Count - traitorCount;
-
- if (detectiveCount > MaxDetectives) detectiveCount = MaxDetectives;
-
- for (var i = 0; i < traitorCount; i++)
- {
- var chosen = eligible[Random.Shared.Next(eligible.Count)];
- eligible.Remove(chosen);
- AddTraitor(chosen);
- }
-
- for (var i = 0; i < detectiveCount; i++)
- {
- var chosen = eligible[Random.Shared.Next(eligible.Count)];
- eligible.Remove(chosen);
- AddDetective(chosen);
- }
-
- AddInnocents(eligible);
- }
-
- public ISet GetTraitors()
- {
- return Players().Where(player => player.PlayerRole() == Role.Traitor).Select(player => player.Player()).ToHashSet();
- }
-
- public ISet GetDetectives()
- {
- return Players().Where(player => player.PlayerRole() == Role.Detective).Select(player => player.Player()).ToHashSet();
- }
-
- public ISet GetInnocents()
- {
- return Players().Where(player => player.PlayerRole() == Role.Innocent).Select(player => player.Player()).ToHashSet();
- }
-
-
- public Role GetRole(CCSPlayerController player)
- {
- return GetPlayer(player).PlayerRole();
- }
-
- public void AddTraitor(CCSPlayerController player)
- {
- GetPlayer(player).SetPlayerRole(Role.Traitor);
- player.SwitchTeam(CsTeam.Terrorist);
- player.PrintToCenter(Role.Traitor.FormatStringFullBefore("You are now a(n)"));
- player.PrintToChat(Role.Traitor.FormatStringFullBefore("You are now a(n)"));
- ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathTmPhoenix);
- }
-
- public void AddDetective(CCSPlayerController player)
- {
- GetPlayer(player).SetPlayerRole(Role.Detective);
- player.SwitchTeam(CsTeam.CounterTerrorist);
- player.PrintToCenter(Role.Detective.FormatStringFullBefore("You are now a(n)"));
- player.GiveNamedItem(CsItem.Taser);
- ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathCtmSas);
- }
-
- public void AddInnocents(IEnumerable players)
- {
- foreach (var player in players)
- {
- GetPlayer(player).SetPlayerRole(Role.Innocent);
- player.PrintToCenter(Role.Innocent.FormatStringFullBefore("You are now an"));
- player.SwitchTeam(CsTeam.Terrorist);
- ModelHandler.SetModelNextServerFrame(player, ModelHandler.ModelPathTmPhoenix);
- }
- }
-
- public bool IsDetective(CCSPlayerController player)
- {
- return GetPlayer(player).PlayerRole() == Role.Detective;
- }
-
- public bool IsTraitor(CCSPlayerController player)
- {
- return GetPlayer(player).PlayerRole() == Role.Traitor;
- }
-
- public void Clear()
- {
- Clr();
- _infoManager.Reset();
- foreach (var key in GetPlayers()) key.Value.SetPlayerRole(Role.Unassigned);
- }
-
- public void ApplyColorFromRole(CCSPlayerController player, Role role)
- {
- switch (role)
- {
- case Role.Traitor:
- ApplyTraitorColor(player);
- break;
- case Role.Detective:
- ApplyDetectiveColor(player);
- break;
- case Role.Innocent:
- ApplyInnocentColor(player);
- break;
- case Role.Unassigned:
- default:
- break;
- }
- }
-
- public bool IsInnocent(CCSPlayerController player)
- {
- return GetPlayer(player).PlayerRole() == Role.Innocent;
- }
-
- private void SetColors()
- {
- foreach (var key in Players())
- {
- if (key.PlayerRole() != Role.Innocent) return;
- ApplyInnocentColor(key.Player());
- }
- }
-
- private void RemoveColors()
- {
- var players = Utilities.GetPlayers()
- .Where(player => player.IsValid).ToList();
-
- foreach (var player in players)
- {
- if (player.Pawn.Value == null) return;
- player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor;
- player.Pawn.Value.Render = Color.FromArgb(254, 255, 255, 255);
- Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender");
- }
- }
-
- private void SetColorTeam(CBaseEntity entity, string className, string fieldName, Role role = Role.Innocent)
- {
- Guard.IsValidEntity(entity);
-
- if (!Schema.IsSchemaFieldNetworked(className, fieldName))
- {
- Application.Instance.Logger.LogWarning("Field {ClassName}:{FieldName} is not networked, but SetStateChanged was called on it.", className, fieldName);
- return;
- }
-
- foreach (var player in GetPlayers().Values.Where(player => player.PlayerRole() == role))
- {
- Guard.IsValidEntity(player.Player());
-
- var playerObj = player.Player();
-
- int offset = Schema.GetSchemaOffset(className, fieldName);
-
- VirtualFunctions.StateChanged(entity.NetworkTransmitComponent.Handle, entity.Handle, offset, -1, (short)playerObj.Index);
- }
- }
-
- private void ApplyDetectiveColor(CCSPlayerController player)
- {
- if (!player.IsReal() || player.Pawn.Value == null)
- return;
-
- player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor;
- player.Pawn.Value.Render = Color.Blue;
- SetColorTeam(player, "CBaseModelEntity", "m_clrRender", Role.Detective);
- }
-
- private void ApplyTraitorColor(CCSPlayerController player)
- {
- if (!player.IsReal() || player.Pawn.Value == null)
- return;
-
- player.Pawn.Value.RenderMode = RenderMode_t.kRenderGlow;
- player.Pawn.Value.Render = Color.Red;
- SetColorTeam(player, "CBaseModelEntity", "m_clrRender", Role.Traitor);
- //apply for traitors only somehow?
- }
-
- private void ApplyInnocentColor(CCSPlayerController player)
- {
- if (!player.IsReal() || player.Pawn.Value == null)
- return;
-
- player.Pawn.Value.RenderMode = RenderMode_t.kRenderGlow;
- player.Pawn.Value.Render = Color.Green;
-
- SetColorTeam(player, "CBaseModelEntity", "m_clrRender");
- }
-
- private Role GetWinner()
- {
- return _traitorsLeft == 0 ? Role.Traitor : Role.Innocent;
- }
-
- private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
- {
- if (!@event.Userid.IsValid)
- {
- return HookResult.Continue;
- }
-
- CCSPlayerController player = @event.Userid;
-
- if(!player.IsReal())
- {
- return HookResult.Continue;
- }
-
- if (!player.PlayerPawn.IsValid)
- {
- return HookResult.Continue;
- }
-
- CHandle pawn = player.PlayerPawn;
-
- Server.NextFrame(() => PlayerSpawnNextFrame(player, pawn));
-
- return HookResult.Continue;
- }
-
-
- private readonly WIN_LINUX OnCollisionRulesChangedOffset = new(173, 172);
-
- private void PlayerSpawnNextFrame(CCSPlayerController player, CHandle pawn)
- {
- pawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
-
- pawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
-
- VirtualFunctionVoid collisionRulesChanged =
- new VirtualFunctionVoid(pawn.Value.Handle, OnCollisionRulesChangedOffset.Get());
-
- collisionRulesChanged.Invoke(pawn.Value.Handle);
- }
- public static CCSPlayerController? player(CEntityInstance? instance)
- {
- if (instance == null)
- {
- return null;
- }
-
- if (instance.DesignerName != "player")
- {
- return null;
- }
-
- // grab the pawn index
- int player_index = (int)instance.Index;
-
- // grab player controller from pawn
- CCSPlayerPawn player_pawn = Utilities.GetEntityFromIndex(player_index);
-
- // pawn valid
- if (player_pawn == null || !player_pawn.IsValid)
- {
- return null;
- }
-
- // controller valid
- if (player_pawn.OriginalController == null || !player_pawn.OriginalController.IsValid)
- {
- return null;
- }
-
- // any further validity is up to the caller
- return player_pawn.OriginalController.Value;
- }
-}
-
-
-
-internal static class IsValid
-{
- public static bool PlayerIndex(uint playerIndex)
- {
- if(playerIndex == 0)
- {
- return false;
- }
-
- if(!(1 <= playerIndex && playerIndex <= Server.MaxPlayers))
- {
- return false;
- }
-
- return true;
- }
-}
-
-
-public class WIN_LINUX
-{
- [JsonPropertyName("Windows")]
- public T Windows { get; private set; }
-
- [JsonPropertyName("Linux")]
- public T Linux { get; private set; }
-
- public WIN_LINUX(T windows, T linux)
- {
- this.Windows = windows;
- this.Linux = linux;
- }
-
- public T Get()
- {
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- return this.Windows;
- }
- else
- {
- return this.Linux;
- }
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Roles/RoleServiceExtension.cs b/mod/TTT.Roles/RoleServiceExtension.cs
index 796f25f..af20a73 100644
--- a/mod/TTT.Roles/RoleServiceExtension.cs
+++ b/mod/TTT.Roles/RoleServiceExtension.cs
@@ -9,9 +9,7 @@ public static class RoleServiceExtension
{
public static void AddTTTRoles(this IServiceCollection collection)
{
- collection.AddPluginBehavior();
- collection.AddPluginBehavior();
- collection.AddPluginBehavior();
- //collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
+ collection.AddPluginBehavior();
}
}
\ No newline at end of file
diff --git a/mod/TTT.Roles/RoleTester.cs b/mod/TTT.Roles/RoleTester.cs
index 13d81a2..489cca3 100644
--- a/mod/TTT.Roles/RoleTester.cs
+++ b/mod/TTT.Roles/RoleTester.cs
@@ -1,22 +1,22 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Modules.Cvars;
-
-namespace TTT.Roles;
-
-public class RoleTester
-{
- private readonly FakeConVar _traitorTesterBlockTester = new("traitor_tester_block_tester",
- "For how long tester button should be disabled after using it. 0 to not block it.");
- private readonly FakeConVar _traitorTesterBlockTesterTime = new("traitor_tester_block_tester_time",
- "Determinate for how long tester button should be disabled. 0 to disable tester block.", 3);
- private readonly FakeConVar _traitorTesterBlockTesterMessage = new("traitor_tester_block_tester_message",
- "If 1 print to client info about tester cooldown. 0 to disable.");
- private readonly FakeConVar _traitorTesterLightTime = new("traitor_tester_light_time",
- "For how long the lights should be shown. Min value is 3 seconds.", 3);
- private readonly FakeConVar _traitorTesterLightDelayTime = new("traitor_tester_light_delay_time",
- "Determinate if the lights should be shown right away or after few secodns. 0 to disable.");
- private readonly FakeConVar _traitorTesterMaxPlayers = new("traitor_tester_max_players",
- "Determinate how many players can be checked at one. 0 to disable it.");
-
-
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Modules.Cvars;
+
+namespace TTT.Roles;
+
+public class RoleTester
+{
+ private readonly FakeConVar _traitorTesterBlockTester = new("traitor_tester_block_tester",
+ "For how long tester button should be disabled after using it. 0 to not block it.");
+ private readonly FakeConVar _traitorTesterBlockTesterTime = new("traitor_tester_block_tester_time",
+ "Determinate for how long tester button should be disabled. 0 to disable tester block.", 3);
+ private readonly FakeConVar _traitorTesterBlockTesterMessage = new("traitor_tester_block_tester_message",
+ "If 1 print to client info about tester cooldown. 0 to disable.");
+ private readonly FakeConVar _traitorTesterLightTime = new("traitor_tester_light_time",
+ "For how long the lights should be shown. Min value is 3 seconds.", 3);
+ private readonly FakeConVar _traitorTesterLightDelayTime = new("traitor_tester_light_delay_time",
+ "Determinate if the lights should be shown right away or after few secodns. 0 to disable.");
+ private readonly FakeConVar _traitorTesterMaxPlayers = new("traitor_tester_max_players",
+ "Determinate how many players can be checked at one. 0 to disable it.");
+
+
}
\ No newline at end of file
diff --git a/mod/TTT.Roles/Shop/ShopManager.cs b/mod/TTT.Roles/Shop/ShopManager.cs
deleted file mode 100644
index eeacb56..0000000
--- a/mod/TTT.Roles/Shop/ShopManager.cs
+++ /dev/null
@@ -1,100 +0,0 @@
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Modules.Commands;
-using TTT.Player;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-using TTT.Public.Shop;
-using TTT.Shop;
-
-namespace TTT.Roles.Shop;
-
-public class ShopManager
-{
- private readonly IPlayerService _playerService;
- private readonly BasePlugin _plugin;
- private static ShopManager Manager;
-
- private ShopManager(BasePlugin plugin, IPlayerService manager)
- {
- _playerService = manager;
- _plugin = plugin;
- plugin.AddCommand("css_shop", "Open the shop menu", OnShopCommand);
- plugin.AddCommand("css_buy", "Buys specified item", OnBuyCommand);
- }
-
- public static void Register(BasePlugin plugin, IPlayerService manager)
- {
- Manager = new ShopManager(plugin, manager);
- }
-
- public void OpenShop(GamePlayer player)
- {
- var role = player.PlayerRole();
- switch (role)
- {
- case Role.Innocent:
- new ShopMenu(_plugin, BaseShopHandler.Get(), player).Open(player.Player());
- player.SetShopOpen(true);
- break;
- case Role.Detective:
- new ShopMenu(_plugin, DetectiveShopHandler.Get(), player).Open(player.Player());
-
- player.SetShopOpen(true);
- break;
- case Role.Traitor:
- new ShopMenu(_plugin, TraitorShopHandler.Get(), player).Open(player.Player());
- player.SetShopOpen(true);
- break;
- case Role.Unassigned:
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- private void OnShopCommand(CCSPlayerController? player, CommandInfo info)
- {
- if (player == null)
- {
- info.ReplyToCommand("Can only be executed by a player!");
- return;
- }
- OpenShop(_playerService.GetPlayer(player));
- }
-
- private void OnBuyCommand(CCSPlayerController? player, CommandInfo info)
- {
- if (player == null)
- {
- info.ReplyToCommand("Can only be executed by a player!");
- return;
- }
-
- var item = info.GetArg(1);
-
- if (string.IsNullOrEmpty(item))
- {
- info.ReplyToCommand("Please specify an item to buy!");
- return;
- }
-
- var gamePlayer = _playerService.GetPlayer(player);
-
- switch (gamePlayer.PlayerRole())
- {
- case Role.Traitor:
- TraitorShopHandler.Get().BuyItem(gamePlayer, item);
- break;
- case Role.Detective:
- DetectiveShopHandler.Get().BuyItem(gamePlayer, item);
- break;
- case Role.Innocent:
- BaseShopHandler.Get().BuyItem(gamePlayer, item);
- break;
- case Role.Unassigned:
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Roles/TraitorRoom.cs b/mod/TTT.Roles/TraitorRoom.cs
index d394537..2da0707 100644
--- a/mod/TTT.Roles/TraitorRoom.cs
+++ b/mod/TTT.Roles/TraitorRoom.cs
@@ -1,8 +1,8 @@
-using CounterStrikeSharp.API.Core;
-
-namespace TTT.Roles;
-
-public class TraitorRoom
-{
-
+using CounterStrikeSharp.API.Core;
+
+namespace TTT.Roles;
+
+public class TraitorRoom
+{
+
}
\ No newline at end of file
diff --git a/mod/TTT.Round/LogsListener.cs b/mod/TTT.Round/LogsListener.cs
deleted file mode 100644
index 12f72cb..0000000
--- a/mod/TTT.Round/LogsListener.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-using System.Text;
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Core.Attributes.Registration;
-using TTT.Public.Action;
-using TTT.Public.Behaviors;
-using TTT.Public.Extensions;
-using TTT.Public.Mod.Role;
-
-namespace TTT.Round;
-
-public class LogsListener : ILogsService
-{
- private readonly HashSet _actions = new();
- private readonly IRoleService _roleService;
- private int _roundId = 0;
-
- public LogsListener(IRoleService roleService, BasePlugin parent, int roundId = 0)
- {
- _roleService = roleService;
- _roundId = roundId;
- parent.RegisterEventHandler(OnRoundEnd);
- parent.RegisterEventHandler(OnPlayerDamage);
- parent.RegisterEventHandler(OnPlayerDeath);
- }
-
- public void IncrementRound()
- {
- _roundId++;
- }
-
- public int GetCurrentRoundId()
- {
- return _roundId;
- }
-
- public void AddLog(IAction action)
- {
- _actions.Add(action);
- }
-
- [GameEventHandler]
- private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
- {
- var killer = @event.Attacker;
- var deadPlayer = @event.Userid;
-
- if (killer == null || deadPlayer == null) return HookResult.Continue;
- if (!killer.IsReal() || !deadPlayer.IsReal()) return HookResult.Continue;
-
- _actions.Add(new KillAction(new Tuple(killer, _roleService.GetRole(killer)),
- new Tuple(deadPlayer, _roleService.GetRole(deadPlayer))
- ));
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnPlayerDamage(EventPlayerHurt @event, GameEventInfo info)
- {
- var killer = @event.Attacker;
- var deadPlayer = @event.Userid;
- var damage = @event.DmgHealth;
-
- if (killer == null || deadPlayer == null) return HookResult.Continue;
-
- if (!killer.IsReal() || !deadPlayer.IsReal()) return HookResult.Continue;
- //var hitbox = @event.Hitgroup; wip
-
- _actions.Add(new DamageAction(new Tuple(killer, _roleService.GetRole(killer)),
- new Tuple(deadPlayer, _roleService.GetRole(deadPlayer)),
- damage,
- 0
- ));
-
- return HookResult.Continue;
- }
-
- [GameEventHandler]
- private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
- {
- var chatMessage = CreateChatMessage();
-
- foreach (var player in Utilities.GetPlayers().Where(player => player.IsValid).Where(player => player.IsReal())
- .ToList()) Server.NextFrame(() => player.PrintToConsole(chatMessage));
-
- Server.PrintToConsole(chatMessage);
-
- _actions.Clear();
-
- return HookResult.Continue;
- }
-
- private void Save()
- {
-
- }
-
- private string CreateChatMessage()
- {
- var builder = new StringBuilder();
- builder.AppendLine($"[TTT] Logs round {_roundId}");
-
- foreach (var action in _actions) builder.AppendLine(action.ActionMessage());
-
- builder.AppendLine("[TTT] Logs ended!");
-
- return builder.ToString();
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Round/Round.cs b/mod/TTT.Round/Round.cs
index b044195..cdaa1dc 100644
--- a/mod/TTT.Round/Round.cs
+++ b/mod/TTT.Round/Round.cs
@@ -1,101 +1,106 @@
-using System.Drawing;
-using System.Text;
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Modules.Utils;
-using TTT.Public.Configuration;
-using TTT.Public.Extensions;
-using TTT.Public.Mod.Role;
-using TTT.Public.Formatting;
-
-namespace TTT.Round;
-
-public class Round
-{
- private readonly IRoleService _roleService;
- private float _graceTime = Config.TTTConfig.GraceTime * 64;
-
- public Round(IRoleService roleService)
- {
- _roleService = roleService;
- }
-
- public void Tick()
- {
- _graceTime--;
-
- var players = Utilities.GetPlayers()
- .Where(player => player.IsValid)
- .Where(player => player.IsReal())
- .ToList();
-
- var formattedColor = $"";
-
- foreach (var player in players)
- {
- Server.NextFrame(() =>
- {
- player.PrintToCenterHtml(
- $"{formattedColor}[TTT] Game is starting in {Math.Floor(_graceTime / 64)} seconds");
- });
- }
- }
-
- public float GraceTime()
- {
- return _graceTime;
- }
-
- public void Start()
- {
- foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal()).Where(player => !player.PawnIsAlive).Where(player => player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist))
- {
- player.Respawn();
- }
-
- _roleService.AddRoles();
- Server.NextFrame(() => Server.PrintToChatAll(StringUtils.FormatTTT($"A new round has started! {_roleService.GetTraitors().Count} traitors.")));
- SendTraitorMessage();
- SendDetectiveMessage();
- SendInnocentMessage();
- }
-
- private void SendInnocentMessage()
- {
- foreach (var player in _roleService.GetInnocents())
- {
- Server.NextFrame(() => player.PrintToChat(StringUtils.FormatTTT("You are now an innocent")));
- }
- }
-
- private void SendTraitorMessage()
- {
- var traitors = _roleService.GetTraitors();
-
- foreach (var traitor in traitors)
- {
- Server.NextFrame(() => traitor.PrintToChat(StringUtils.FormatTTT("You are a Traitor")));
- Server.NextFrame(() => traitor.PrintToChat(StringUtils.FormatTTT("Traitors:")));
- foreach (var player in traitors)
- {
- var message = StringUtils.FormatTTT(Role.Traitor.FormatStringFullAfter(player.PlayerName));
- Server.NextFrame(() => traitor.PrintToChat(message));
- }
- }
- }
-
- private void SendDetectiveMessage()
- {
- var detectives = _roleService.GetDetectives();
-
- foreach (var detective in detectives)
- {
- Server.NextFrame(() => detective.PrintToChat(StringUtils.FormatTTT("You are a Detective")));
- Server.NextFrame(() => detective.PrintToChat(StringUtils.FormatTTT("Detective:")));
- foreach (var player in detectives)
- {
- var message = StringUtils.FormatTTT(Role.Detective.FormatStringFullAfter(" " + player.PlayerName));
- Server.NextFrame(() => detective.PrintToChat(message));
- }
- }
- }
+using System.Drawing;
+using System.Text;
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Public.Configuration;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Role;
+using TTT.Public.Formatting;
+
+namespace TTT.Round;
+
+public class Round
+{
+ private readonly IRoleService _roleService;
+ private readonly RoundConfig? _config;
+ private float _graceTime = 20;
+ private readonly int _roundId;
+
+ public Round(IRoleService roleService, RoundConfig? config, int roundId)
+ {
+ _roleService = roleService;
+ _config = config;
+ _graceTime = 20;
+ _roundId = roundId;
+ }
+
+ public void Tick()
+ {
+ _graceTime--;
+
+ var players = Utilities.GetPlayers()
+ .Where(player => player.IsValid)
+ .Where(player => player.IsReal())
+ .ToList();
+
+ var formattedColor = $"";
+
+ foreach (var player in players)
+ {
+ Server.NextFrame(() =>
+ {
+ player.PrintToCenterHtml(
+ $"{formattedColor}[TTT] Game is starting in {Math.Floor(_graceTime / 64)} seconds");
+ });
+ }
+ }
+
+ public float GraceTime()
+ {
+ return _graceTime;
+ }
+
+ public void Start()
+ {
+ foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal()).Where(player => !player.PawnIsAlive).Where(player => player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist))
+ {
+ player.Respawn();
+ }
+
+ _roleService.AddRoles();
+ Server.NextFrame(() => Server.PrintToChatAll(StringUtils.FormatTTT($"Round #{_roundId} has started! {_roleService.GetTraitors().Count} traitors.")));
+ SendTraitorMessage();
+ SendDetectiveMessage();
+ SendInnocentMessage();
+ }
+
+ private void SendInnocentMessage()
+ {
+ foreach (var player in _roleService.GetInnocents())
+ {
+ Server.NextFrame(() => player.PrintToChat(StringUtils.FormatTTT("You are now an innocent")));
+ }
+ }
+
+ private void SendTraitorMessage()
+ {
+ var traitors = _roleService.GetTraitors();
+
+ foreach (var traitor in traitors)
+ {
+ Server.NextFrame(() => traitor.PrintToChat(StringUtils.FormatTTT("You are a Traitor")));
+ Server.NextFrame(() => traitor.PrintToChat(StringUtils.FormatTTT("Traitors:")));
+ foreach (var player in traitors)
+ {
+ var message = StringUtils.FormatTTT(Role.Traitor.FormatStringFullAfter(player.PlayerName));
+ Server.NextFrame(() => traitor.PrintToChat(message));
+ }
+ }
+ }
+
+ private void SendDetectiveMessage()
+ {
+ var detectives = _roleService.GetDetectives();
+
+ foreach (var detective in detectives)
+ {
+ Server.NextFrame(() => detective.PrintToChat(StringUtils.FormatTTT("You are a Detective")));
+ Server.NextFrame(() => detective.PrintToChat(StringUtils.FormatTTT("Detective:")));
+ foreach (var player in detectives)
+ {
+ var message = StringUtils.FormatTTT(Role.Detective.FormatStringFullAfter(" " + player.PlayerName));
+ Server.NextFrame(() => detective.PrintToChat(message));
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/mod/TTT.Round/RoundManager.cs b/mod/TTT.Round/RoundBehavior.cs
similarity index 50%
rename from mod/TTT.Round/RoundManager.cs
rename to mod/TTT.Round/RoundBehavior.cs
index 5c4c007..a077423 100644
--- a/mod/TTT.Round/RoundManager.cs
+++ b/mod/TTT.Round/RoundBehavior.cs
@@ -1,66 +1,35 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CounterStrikeSharp.API.Modules.Timers;
using TTT.Public.Action;
+using TTT.Public.Behaviors;
using TTT.Public.Extensions;
using TTT.Public.Formatting;
+using TTT.Public.Mod.Logs;
using TTT.Public.Mod.Role;
using TTT.Public.Mod.Round;
+using TTT.Public.Player;
namespace TTT.Round;
-public class RoundManager : IRoundService
+public class RoundBehavior(IRoleService _roleService) : IRoundService
{
- private readonly IRoleService _roleService;
- private readonly LogsListener _logs;
private Round? _round;
private RoundStatus _roundStatus = RoundStatus.Paused;
-
- public RoundManager(IRoleService roleService, BasePlugin plugin)
+ private int _roundId = 1;
+
+ public void Start(BasePlugin plugin)
{
- _roleService = roleService;
- _logs = new LogsListener(roleService, plugin, 1);
plugin.RegisterListener(TickWaiting);
-
- plugin.AddCommandListener("jointeam", (player, info) =>
- {
- if (_roundStatus != RoundStatus.Started) return HookResult.Continue;
- if (player == null) return HookResult.Continue;
- if (!player.IsReal()) return HookResult.Continue;
- if (_roleService.GetRole(player) != Role.Unassigned) return HookResult.Continue;
- Server.NextFrame(() => player.CommitSuicide(false, true));
-
- return HookResult.Continue;
- }, HookMode.Pre);
-
- VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(hook =>
- {
- if (hook.GetParam(0).DesignerName is not "player") return HookResult.Continue;
- return _roundStatus != RoundStatus.Waiting ? HookResult.Continue : HookResult.Stop;
- }, HookMode.Pre);
-
- plugin.AddTimer(3, () =>
- {
- if (_roundStatus == RoundStatus.Started && Utilities.GetPlayers().Count(player => player.PawnIsAlive) == 1)
- {
- ForceEnd();
- }
-
- var traitorCount = _roleService.GetTraitors().Count(player => player.PawnIsAlive);
- var innocentCount = _roleService.GetInnocents().Count(player => player.PawnIsAlive);
- var detectiveCount = _roleService.GetDetectives().Count(player => player.PawnIsAlive);
-
- if (_roundStatus == RoundStatus.Started && (traitorCount == 0 || innocentCount + detectiveCount == 0))
- {
- ForceEnd();
- }
- }, TimerFlags.REPEAT);
+ plugin.AddCommandListener("jointeam", OnTeamJoin);
+ VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(BlockDamage, HookMode.Pre);
+ plugin.AddTimer(3, EndRound, TimerFlags.REPEAT);
}
-
public RoundStatus GetRoundStatus()
{
return _roundStatus;
@@ -74,7 +43,7 @@ public void SetRoundStatus(RoundStatus roundStatus)
ForceEnd();
break;
case RoundStatus.Waiting:
- _round = new Round(_roleService);
+ _round = new Round(_roleService, null, _roundId);
break;
case RoundStatus.Started:
ForceStart();
@@ -91,7 +60,7 @@ public void TickWaiting()
{
if (_round == null)
{
- _round = new Round(_roleService);
+ _round = new Round(_roleService, null, _roundId);
return;
}
@@ -102,7 +71,7 @@ public void TickWaiting()
if (_round.GraceTime() != 0) return;
- if (Utilities.GetPlayers().Where(player => player is { IsValid: true, PawnIsAlive: true }).ToList().Count <= 2)
+ if (Utilities.GetPlayers().Where(player => player is { IsValid: true, PawnIsAlive: true }).ToList().Count <= 0)
{
Server.PrintToChatAll(StringUtils.FormatTTT("Not enough players to start the round. Round has been ended."));
_roundStatus = RoundStatus.Paused;
@@ -117,20 +86,57 @@ public void ForceStart()
{
foreach (var player in Utilities.GetPlayers().Where(player => player.IsReal()).Where(player => player.IsReal())
.ToList()) player.VoiceFlags = VoiceFlags.Normal;
- _round!.Start();
+ _round!.Start();
+ ServerExtensions.GetGameRules().RoundTime = 360;
+ Utilities.SetStateChanged(ServerExtensions.GetGameRulesProxy(), "CCSGameRulesProxy", "m_pGameRules");
}
public void ForceEnd()
{
if (_roundStatus == RoundStatus.Ended) return;
_roundStatus = RoundStatus.Ended;
- _logs.IncrementRound();
Utilities.FindAllEntitiesByDesignerName("cs_gamerules").First().GameRules!.TerminateRound(5,
RoundEndReason.RoundDraw);
}
-
- public ILogsService GetLogsService()
+
+ private void EndRound()
+ {
+ return;
+ if (_roundStatus == RoundStatus.Started && Utilities.GetPlayers().Count(player => player.PawnIsAlive) == 1)
+ {
+ ForceEnd();
+ }
+
+ var traitorCount = _roleService.GetTraitors().Count(player => player.PawnIsAlive);
+ var innocentCount = _roleService.GetInnocents().Count(player => player.PawnIsAlive);
+ var detectiveCount = _roleService.GetDetectives().Count(player => player.PawnIsAlive);
+
+ if (_roundStatus == RoundStatus.Started && (traitorCount == 0 || innocentCount + detectiveCount == 0))
+ {
+ ForceEnd();
+ }
+ }
+
+ private HookResult BlockDamage(DynamicHook hook)
+ {
+ if (hook.GetParam(0).DesignerName is not "player") return HookResult.Continue;
+ return _roundStatus != RoundStatus.Waiting ? HookResult.Continue : HookResult.Stop;
+ }
+
+ private HookResult OnTeamJoin(CCSPlayerController? executor, CommandInfo info)
+ {
+ if (_roundStatus != RoundStatus.Started) return HookResult.Continue;
+ if (executor == null) return HookResult.Continue;
+ if (!executor.IsReal()) return HookResult.Continue;
+ if (_roleService.GetRole(executor) != Role.Unassigned) return HookResult.Continue;
+ Server.NextFrame(() => executor.CommitSuicide(false, true));
+
+ return HookResult.Continue;
+ }
+
+ private HookResult OnRoundEnd(EventRoundEnd _, GameEventInfo __)
{
- return _logs;
+ _roundId++;
+ return HookResult.Continue;
}
}
diff --git a/mod/TTT.Round/RoundConfig.cs b/mod/TTT.Round/RoundConfig.cs
new file mode 100644
index 0000000..a8e77f6
--- /dev/null
+++ b/mod/TTT.Round/RoundConfig.cs
@@ -0,0 +1,7 @@
+namespace TTT.Round;
+
+public class RoundConfig
+{
+ public int GracePeriod { get; } = 20;
+ public int RoundTime { get; } = 360;
+}
\ No newline at end of file
diff --git a/mod/TTT.Round/RoundServiceExtension.cs b/mod/TTT.Round/RoundServiceExtension.cs
new file mode 100644
index 0000000..b41b37b
--- /dev/null
+++ b/mod/TTT.Round/RoundServiceExtension.cs
@@ -0,0 +1,12 @@
+using Microsoft.Extensions.DependencyInjection;
+using TTT.Public.Extensions;
+using TTT.Public.Mod.Round;
+
+namespace TTT.Round;
+
+public static class RoundServiceExtension
+{
+ public static void AddRoundService(this IServiceCollection collection)
+ {
+ }
+}
\ No newline at end of file
diff --git a/mod/TTT.Shop/BaseShopHandler.cs b/mod/TTT.Shop/BaseShopHandler.cs
deleted file mode 100644
index 51315d2..0000000
--- a/mod/TTT.Shop/BaseShopHandler.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System.Collections.Generic;
-using System.Reflection;
-using TTT.Player;
-using TTT.Public.Behaviors;
-using TTT.Public.Formatting;
-using TTT.Public.Shop;
-using TTT.Shop.Items;
-
-namespace TTT.Shop;
-
-public class BaseShopHandler : IShopItemHandler, IPluginBehavior
-{
- private readonly ISet _items = new HashSet();
-
- private static readonly BaseShopHandler Instance = new BaseShopHandler();
-
- protected BaseShopHandler()
- {
- AddItems("All");
- AddItems("Innocent");
- }
-
- protected void AddItems(string name)
- {
- var fullName = "TTT.Shop.Items." + name;
- var q = from t in Assembly.GetExecutingAssembly().GetTypes()
- where t.IsClass && t.Namespace == fullName && t.GetInterface("IShopItem") != null
- select t;
-
- foreach (var type in q)
- {
- if (type == null) return;
- var item = (IShopItem?) Activator.CreateInstance(type);
- if (item == null) return;
- AddShopItem(item);
- }
- }
-
- public void BuyItem(GamePlayer player, string itemName)
- {
- foreach (var item in _items)
- {
- if (!item.SimpleName().Equals(itemName)) continue;
- BuyItem(player, item);
- return;
- }
- }
-
- private void BuyItem(GamePlayer player, IShopItem item)
- {
- var successful = item.OnBuy(player);
- switch (successful)
- {
- case BuyResult.NotEnoughCredits:
- player.Player()
- .PrintToChat(StringUtils.FormatTTT($"You don't have enough credits to buy {item.Name()}"));
- break;
- case BuyResult.Successful:
- player.Player().PrintToChat(StringUtils.FormatTTT($"You have bought {item.Name()}"));
- player.AddItem(item);
- break;
- case BuyResult.AlreadyOwned:
- player.Player().PrintToChat(StringUtils.FormatTTT($"You already own {item.Name()}"));
- break;
- case BuyResult.IncorrectRole:
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- public static BaseShopHandler Get()
- {
- return Instance;
- }
-
- public ISet GetShopItems()
- {
- return _items;
- }
-
- public void AddShopItem(IShopItem item)
- {
- _items.Add(item);
- }
-
-
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/DetectiveShopHandler.cs b/mod/TTT.Shop/DetectiveShopHandler.cs
deleted file mode 100644
index 5886b5c..0000000
--- a/mod/TTT.Shop/DetectiveShopHandler.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-
-using System.Reflection;
-using TTT.Public.Shop;
-
-namespace TTT.Shop;
-
-public class DetectiveShopHandler : BaseShopHandler
-{
- private static readonly DetectiveShopHandler _instance = new DetectiveShopHandler();
-
- private DetectiveShopHandler()
- {
- AddItems("Detective");
- }
-
-
- public new static DetectiveShopHandler Get()
- {
- return _instance;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/Items/Detective/DNAScannerItem.cs b/mod/TTT.Shop/Items/Detective/DNAScannerItem.cs
deleted file mode 100644
index f358d35..0000000
--- a/mod/TTT.Shop/Items/Detective/DNAScannerItem.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using TTT.Player;
-using TTT.Public.Shop;
-
-namespace TTT.Shop.Items.Detective;
-
-public class DNAScannerItem : IShopItem
-{
- public string Name()
- {
- return "DNA Scanner";
- }
-
- public string SimpleName()
- {
- return "dnascanner";
- }
-
- public int Price()
- {
- return 1000;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- return BuyResult.Successful;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/Items/Detective/TaserItem.cs b/mod/TTT.Shop/Items/Detective/TaserItem.cs
deleted file mode 100644
index 6e74e96..0000000
--- a/mod/TTT.Shop/Items/Detective/TaserItem.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-using TTT.Player;
-using TTT.Public.Shop;
-
-namespace TTT.Shop.Items.Detective;
-
-public class TaserItem : IShopItem
-{
- public string Name()
- {
- return "Taser";
- }
-
- public string SimpleName()
- {
- return "taser";
- }
-
- public int Price()
- {
- return 1000;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- return BuyResult.Successful;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/Items/Traitor/AkItem.cs b/mod/TTT.Shop/Items/Traitor/AkItem.cs
deleted file mode 100644
index de35566..0000000
--- a/mod/TTT.Shop/Items/Traitor/AkItem.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using CounterStrikeSharp.API.Modules.Entities.Constants;
-using TTT.Player;
-using TTT.Public.Mod.Role;
-using TTT.Public.Shop;
-
-namespace TTT.Shop.Items.Traitor;
-
-public class AkItem : IShopItem
-{
- public string Name()
- {
- return "AK-47";
- }
-
- public string SimpleName()
- {
- //css_buy ak47
- return "ak47";
- }
-
- public int Price()
- {
- return 500;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
- if (player.PlayerRole() != Role.Traitor) return BuyResult.IncorrectRole;
- player.RemoveCredits(Price());
- var playerObject = player.Player();
- playerObject.GiveNamedItem(CsItem.AK47);
- return BuyResult.Successful;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/Items/Traitor/AwpItem.cs b/mod/TTT.Shop/Items/Traitor/AwpItem.cs
deleted file mode 100644
index 64c6660..0000000
--- a/mod/TTT.Shop/Items/Traitor/AwpItem.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using CounterStrikeSharp.API.Modules.Entities.Constants;
-using TTT.Player;
-using TTT.Public.Mod.Role;
-using TTT.Public.Shop;
-
-namespace TTT.Shop.Items.Traitor;
-
-public class AwpItem : IShopItem
-{
- public string Name()
- {
- return "AWP";
- }
-
- public string SimpleName()
- {
- return "awp";
- }
-
- public int Price()
- {
- return 2000;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- if (player.Credits() < Price()) return BuyResult.NotEnoughCredits;
- if (player.PlayerRole() != Role.Detective) return BuyResult.IncorrectRole;
- player.RemoveCredits(Price());
- player.Player().GiveNamedItem(CsItem.AWP);
- return BuyResult.Successful;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/Items/Traitor/WallHackItem.cs b/mod/TTT.Shop/Items/Traitor/WallHackItem.cs
deleted file mode 100644
index 462076c..0000000
--- a/mod/TTT.Shop/Items/Traitor/WallHackItem.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-using TTT.Player;
-using TTT.Public.Shop;
-
-namespace TTT.Shop.Items.Traitor;
-
-public class WallHackItem : IShopItem
-{
-
- public string Name()
- {
- return "Wall Hack";
- }
-
- public string SimpleName()
- {
- return "wallhack";
- }
-
- public int Price()
- {
- return 1000;
- }
-
- public BuyResult OnBuy(GamePlayer player)
- {
- return BuyResult.Successful;
- }
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/TTT.Shop.csproj b/mod/TTT.Shop/TTT.Shop.csproj
index de5f0ec..31fb7ca 100644
--- a/mod/TTT.Shop/TTT.Shop.csproj
+++ b/mod/TTT.Shop/TTT.Shop.csproj
@@ -1,18 +1,14 @@
-
-
-
- net8.0
- enable
- enable
- TTT.Shop
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net8.0
+ enable
+ enable
+ TTT.Shop
+
+
+
+
+
+
+
diff --git a/mod/TTT.Shop/TraitorShopHandler.cs b/mod/TTT.Shop/TraitorShopHandler.cs
deleted file mode 100644
index a351aee..0000000
--- a/mod/TTT.Shop/TraitorShopHandler.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-using TTT.Shop.Items;
-
-namespace TTT.Shop;
-
-public class TraitorShopHandler : BaseShopHandler
-{
-
- private static readonly TraitorShopHandler _instance = new TraitorShopHandler();
-
- public TraitorShopHandler()
- {
- AddItems("Traitor");
- }
-
- public new static TraitorShopHandler Get()
- {
- return _instance;
- }
-
-}
\ No newline at end of file
diff --git a/mod/TTT.Shop/obj/rider.project.model.nuget.info b/mod/TTT.Shop/obj/rider.project.model.nuget.info
deleted file mode 100644
index 6df840f..0000000
--- a/mod/TTT.Shop/obj/rider.project.model.nuget.info
+++ /dev/null
@@ -1 +0,0 @@
-17201138354348749
\ No newline at end of file
diff --git a/public/TTT.Formatting/Base/IView.cs b/public/TTT.Formatting/Base/IView.cs
new file mode 100644
index 0000000..2d15db0
--- /dev/null
+++ b/public/TTT.Formatting/Base/IView.cs
@@ -0,0 +1,8 @@
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Base;
+
+public interface IView
+{
+ void Render(FormatWriter writer);
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Base/SimpleView.cs b/public/TTT.Formatting/Base/SimpleView.cs
new file mode 100644
index 0000000..b3382f8
--- /dev/null
+++ b/public/TTT.Formatting/Base/SimpleView.cs
@@ -0,0 +1,70 @@
+using System.Collections;
+
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Base;
+
+public class SimpleView : IView, IEnumerable>
+{
+ public struct Newline
+ {
+
+ }
+
+ public static Newline NEWLINE = new Newline();
+
+ private List> _lines = new();
+
+ public SimpleView()
+ {
+
+ }
+
+ ///
+ /// Add an item to the end of the last row in this SimpleView
+ /// Eg, { abc, 123, weee } is all one row
+ ///
+ ///
+ public void Add(FormatObject item)
+ {
+ if (_lines.Count == 0)
+ _lines.Add(new List());
+
+ _lines[_lines.Count - 1].Add(item);
+ }
+
+ ///
+ /// Add multiple items at a time to this SimpleView
+ ///
+ ///
+ public void Add(params FormatObject[] line)
+ {
+ if (_lines.Count == 0)
+ _lines.Add(new List());
+
+ _lines[_lines.Count - 1].AddRange(line);
+ }
+
+ ///
+ /// Add a new line to this SimpleView
+ ///
+ ///
+ public void Add(Newline newline)
+ {
+ _lines.Add(new List());
+ }
+
+ public void Render(FormatWriter writer)
+ {
+ foreach (var formatObjects in _lines)
+ writer.Line(formatObjects.ToArray());
+ }
+
+ public IEnumerator> GetEnumerator()
+ => _lines.GetEnumerator();
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+}
diff --git a/public/TTT.Formatting/Core/FormatObject.cs b/public/TTT.Formatting/Core/FormatObject.cs
new file mode 100644
index 0000000..956333d
--- /dev/null
+++ b/public/TTT.Formatting/Core/FormatObject.cs
@@ -0,0 +1,56 @@
+using CounterStrikeSharp.API.Core;
+using TTT.Formatting.Objects;
+using TTT.Public.Extensions;
+
+namespace TTT.Formatting.Core;
+
+public abstract class FormatObject
+{
+ ///
+ /// Output this format object compatible with CS2 chat formatting.
+ ///
+ ///
+ public virtual string ToChat()
+ {
+ return ToPlain();
+ }
+
+ ///
+ /// Output this format object in a panorama-compatible format.
+ ///
+ ///
+ public virtual string ToPanorama()
+ {
+ return ToPlain().Sanitize();
+ }
+
+ ///
+ /// Output plaintext
+ ///
+ ///
+ public abstract string ToPlain();
+
+
+ public static implicit operator FormatObject(string value)
+ {
+ return new StringFormatObject(value);
+ }
+
+ public static implicit operator FormatObject(CCSPlayerController value)
+ {
+ return new PlayerFormatObject(value);
+ }
+
+ public static implicit operator FormatObject(int value)
+ {
+ return new IntegerFormatObject(value);
+ }
+
+ public static FormatObject FromObject(object value)
+ {
+ return new StringFormatObject(value.ToString() ?? "null");
+ }
+
+ public override string ToString()
+ => ToPlain();
+}
diff --git a/public/TTT.Formatting/Core/FormatWriter.cs b/public/TTT.Formatting/Core/FormatWriter.cs
new file mode 100644
index 0000000..78f66d7
--- /dev/null
+++ b/public/TTT.Formatting/Core/FormatWriter.cs
@@ -0,0 +1,25 @@
+namespace TTT.Formatting.Core;
+
+public class FormatWriter
+{
+ private readonly List _lines = new();
+
+ public IEnumerable Lines => _lines;
+
+ public IEnumerable Chat
+ => Lines.Select(array => string.Join(' ', array.Select(obj => obj.ToChat())));
+
+ public IEnumerable Panorama
+ => Lines.Select(array => string.Join(' ', array.Select(obj => obj.ToPanorama())));
+
+ public IEnumerable Plain
+ => Lines.Select(array => string.Join(' ', array.Select(obj => obj.ToPlain())));
+
+
+ public FormatWriter Line(params FormatObject[] args)
+ {
+ _lines.Add(args);
+
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Extensions/ViewExtensions.cs b/public/TTT.Formatting/Extensions/ViewExtensions.cs
new file mode 100644
index 0000000..f03bfb6
--- /dev/null
+++ b/public/TTT.Formatting/Extensions/ViewExtensions.cs
@@ -0,0 +1,110 @@
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+
+using TTT.Formatting.Base;
+using TTT.Formatting.Core;
+using TTT.Public.Extensions;
+
+namespace TTT.Formatting.Extensions;
+
+public static class ViewExtensions
+{
+
+ public static FormatWriter ToWriter(this IView view)
+ {
+ var writer = new FormatWriter();
+
+ view.Render(writer);
+
+ return writer;
+ }
+
+ public static IView ToServerConsole(this IView view)
+ {
+ var writer = view.ToWriter();
+
+ foreach (string s in writer.Plain)
+ {
+ Server.PrintToConsole(s);
+ }
+
+ return view;
+ }
+
+ #region Individual
+
+ public static IView ToPlayerConsole(this IView view, CCSPlayerController player)
+ {
+ if (!player.IsReal() || player.IsBot)
+ return view;
+
+ var writer = view.ToWriter();
+
+ foreach (var writerLine in writer.Plain)
+ player.PrintToConsole(writerLine);
+
+ return view;
+ }
+
+ public static IView ToPlayerChat(this IView view, CCSPlayerController player)
+ {
+ if (!player.IsReal() || player.IsBot)
+ return view;
+
+ var writer = view.ToWriter();
+
+ foreach (var writerLine in writer.Chat)
+ player.PrintToChat(writerLine);
+
+ return view;
+ }
+
+ public static IView ToPlayerCenter(this IView view, CCSPlayerController player)
+ {
+ if (!player.IsReal() || player.IsBot)
+ return view;
+
+ var writer = view.ToWriter();
+ var merged = string.Join('\n', writer.Plain);
+
+ player.PrintToCenter(merged);
+
+ return view;
+ }
+
+ public static IView ToPlayerCenterHtml(this IView view, CCSPlayerController player)
+ {
+ if (!player.IsReal() || player.IsBot)
+ return view;
+
+ var writer = view.ToWriter();
+ var merged = string.Join('\n', writer.Panorama);
+
+ player.PrintToCenterHtml(merged);
+
+ return view;
+ }
+
+ #endregion
+
+ public static IView ToAllConsole(this IView view)
+ {
+ Utilities.GetPlayers().ForEach(player => view.ToPlayerConsole(player));
+
+ return view;
+ }
+
+ public static IView ToAllChat(this IView view)
+ {
+ Utilities.GetPlayers().ForEach(player => view.ToPlayerChat(player));
+
+ return view;
+ }
+
+ public static IView ToAllCenter(this IView view)
+ {
+ Utilities.GetPlayers().ForEach(player => view.ToPlayerCenter(player));
+
+ return view;
+ }
+}
diff --git a/public/TTT.Formatting/Languages/English.cs b/public/TTT.Formatting/Languages/English.cs
new file mode 100644
index 0000000..727c519
--- /dev/null
+++ b/public/TTT.Formatting/Languages/English.cs
@@ -0,0 +1,7 @@
+using TTT.Formatting.Logistics;
+
+namespace TTT.Formatting.Languages;
+
+public class English : IDialect
+{
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Logistics/IDialect.cs b/public/TTT.Formatting/Logistics/IDialect.cs
new file mode 100644
index 0000000..52b81ef
--- /dev/null
+++ b/public/TTT.Formatting/Logistics/IDialect.cs
@@ -0,0 +1,9 @@
+namespace TTT.Formatting.Logistics;
+
+///
+/// A specific language, such as "English" or "French",
+/// should inherit this interface.
+///
+public interface IDialect
+{
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Logistics/ILanguage.cs b/public/TTT.Formatting/Logistics/ILanguage.cs
new file mode 100644
index 0000000..d19e0d2
--- /dev/null
+++ b/public/TTT.Formatting/Logistics/ILanguage.cs
@@ -0,0 +1,11 @@
+namespace TTT.Formatting.Logistics;
+
+///
+/// Specifies that this class is written in a specific language
+/// Eg, ILanguage<English> or ILanguage<French>
+///
+///
+public interface ILanguage
+ where TDialect : IDialect
+{
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Logistics/LanguageConfig.cs b/public/TTT.Formatting/Logistics/LanguageConfig.cs
new file mode 100644
index 0000000..11c25ae
--- /dev/null
+++ b/public/TTT.Formatting/Logistics/LanguageConfig.cs
@@ -0,0 +1,18 @@
+using TTT.Formatting.Views;
+
+using Microsoft.Extensions.DependencyInjection;
+
+namespace TTT.Formatting.Logistics;
+
+public class LanguageConfig
+ where TDialect: IDialect
+{
+
+ private IServiceCollection _collection;
+
+ public LanguageConfig(IServiceCollection collection)
+ {
+ _collection = collection;
+ }
+
+}
diff --git a/public/TTT.Formatting/Logistics/RegisterLanguageExtensions.cs b/public/TTT.Formatting/Logistics/RegisterLanguageExtensions.cs
new file mode 100644
index 0000000..d2606f8
--- /dev/null
+++ b/public/TTT.Formatting/Logistics/RegisterLanguageExtensions.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace TTT.Formatting.Logistics;
+
+public static class RegisterLanguageExtensions
+{
+ public static void AddLanguage(
+ this IServiceCollection collection,
+ Action> factory)
+ where TDialect : IDialect
+ {
+ var config = new LanguageConfig(collection);
+
+ factory(config);
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Objects/HiddenFormatObject.cs b/public/TTT.Formatting/Objects/HiddenFormatObject.cs
new file mode 100644
index 0000000..ef4f112
--- /dev/null
+++ b/public/TTT.Formatting/Objects/HiddenFormatObject.cs
@@ -0,0 +1,40 @@
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Objects;
+
+public class HiddenFormatObject : FormatObject
+{
+ public FormatObject Value;
+
+ public HiddenFormatObject(FormatObject value)
+ {
+ Value = value;
+ }
+
+ public bool Plain { get; set; } = true;
+
+ public bool Panorama { get; set; } = true;
+
+ public bool Chat { get; set; } = true;
+
+ public override string ToChat()
+ {
+ if (Chat)
+ return Value.ToChat();
+ return string.Empty;
+ }
+
+ public override string ToPanorama()
+ {
+ if (Panorama)
+ return Value.ToPanorama();
+ return string.Empty;
+ }
+
+ public override string ToPlain()
+ {
+ if (Plain)
+ return Value.ToPlain();
+ return string.Empty;
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Objects/IntegerFormatObject.cs b/public/TTT.Formatting/Objects/IntegerFormatObject.cs
new file mode 100644
index 0000000..2f06eac
--- /dev/null
+++ b/public/TTT.Formatting/Objects/IntegerFormatObject.cs
@@ -0,0 +1,32 @@
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Objects;
+
+public class IntegerFormatObject : FormatObject
+{
+ private readonly char _chatColor;
+
+ public IntegerFormatObject(int value, char chatColor = '\x09')
+ {
+ Value = value;
+ _chatColor = chatColor;
+ }
+
+ public int Value { get; }
+
+ public override string ToChat()
+ {
+ return $"{_chatColor}{Value.ToString()}";
+ }
+
+ public override string ToPanorama()
+ {
+ return Value.ToString();
+ }
+
+ public override string ToPlain()
+ {
+ return Value.ToString();
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Objects/PlayerFormatObject.cs b/public/TTT.Formatting/Objects/PlayerFormatObject.cs
new file mode 100644
index 0000000..846fdcb
--- /dev/null
+++ b/public/TTT.Formatting/Objects/PlayerFormatObject.cs
@@ -0,0 +1,31 @@
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Modules.Utils;
+using TTT.Formatting.Core;
+using TTT.Public.Extensions;
+
+namespace TTT.Formatting.Objects;
+
+public class PlayerFormatObject : FormatObject
+{
+ private readonly string _name;
+
+ public PlayerFormatObject(CCSPlayerController player)
+ {
+ _name = player.PlayerName;
+ }
+
+ public override string ToChat()
+ {
+ return $"{ChatColors.Yellow}{_name}";
+ }
+
+ public override string ToPanorama()
+ {
+ return _name.Sanitize();
+ }
+
+ public override string ToPlain()
+ {
+ return _name;
+ }
+}
diff --git a/public/TTT.Formatting/Objects/StringFormatObject.cs b/public/TTT.Formatting/Objects/StringFormatObject.cs
new file mode 100644
index 0000000..7c85915
--- /dev/null
+++ b/public/TTT.Formatting/Objects/StringFormatObject.cs
@@ -0,0 +1,31 @@
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Objects;
+
+public class StringFormatObject : FormatObject
+{
+ private readonly char _chatColor;
+
+ public StringFormatObject(string value, char chatColor = '\x01')
+ {
+ Value = value;
+ _chatColor = chatColor;
+ }
+
+ public string Value { get; }
+
+ public override string ToChat()
+ {
+ return $"{_chatColor}{Value}";
+ }
+
+ public override string ToPanorama()
+ {
+ return Value;
+ }
+
+ public override string ToPlain()
+ {
+ return Value;
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Formatting/Objects/TreeFormatObject.cs b/public/TTT.Formatting/Objects/TreeFormatObject.cs
new file mode 100644
index 0000000..647c812
--- /dev/null
+++ b/public/TTT.Formatting/Objects/TreeFormatObject.cs
@@ -0,0 +1,86 @@
+using System.Collections;
+
+using TTT.Formatting.Core;
+
+namespace TTT.Formatting.Objects;
+
+///
+/// Merges several FormatObjects into one.
+/// This class will throw an error if any of it's descendant formatobjects are itself,
+/// to prevent looping.
+///
+public class TreeFormatObject : FormatObject, IEnumerable
+{
+ private List _children = new();
+
+ private int _locked = 0;
+
+ public TreeFormatObject()
+ {
+
+ }
+
+ ///
+ /// Lock this object, execute callback, then unlock.
+ ///
+ ///
+ private T Lock(Func callback)
+ {
+ // Achieve a re-entrant mutex for this thread.
+ // We can re-enter this lock as long as we are in the same thread, but others are blocked.
+ // this allows us to do the internal increment safely.
+ lock (this)
+ {
+ // set _locked to 1 if value is 0
+ int old = Interlocked.CompareExchange(ref _locked, 1, 0);
+
+ if (old == 1)
+ throw new Exception("Possible loop detected in TreeFormatObject! Already locked during traversal");
+
+ var result = callback();
+ _locked = 0;
+
+ return result;
+ }
+ }
+
+ public override string ToPlain()
+ {
+ return Lock(() =>
+ {
+ var childPlain = _children.Select(child => child.ToPlain());
+ return string.Join(' ', childPlain);
+ });
+ }
+
+ public override string ToChat()
+ {
+ return Lock(() =>
+ {
+ var childChat = _children.Select(child => child.ToChat());
+ return string.Join(' ', childChat);
+ });
+ }
+
+ public override string ToPanorama()
+ {
+ return Lock(() =>
+ {
+ var childPanorama = _children.Select(child => child.ToPanorama());
+ return string.Join(' ', childPanorama);
+ });
+ }
+
+ public void Add(FormatObject formatObject)
+ => _children.Add(formatObject);
+
+ public IEnumerator GetEnumerator()
+ {
+ return _children.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+}
diff --git a/public/TTT.Formatting/TTT.Formatting.csproj b/public/TTT.Formatting/TTT.Formatting.csproj
new file mode 100644
index 0000000..0d44a15
--- /dev/null
+++ b/public/TTT.Formatting/TTT.Formatting.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/public/TTT.Formatting/Views/IRoleNotifications.cs b/public/TTT.Formatting/Views/IRoleNotifications.cs
new file mode 100644
index 0000000..35826a6
--- /dev/null
+++ b/public/TTT.Formatting/Views/IRoleNotifications.cs
@@ -0,0 +1,11 @@
+using TTT.Formatting.Base;
+using TTT.Public.Mod.Role;
+
+namespace TTT.Formatting.Views;
+
+public interface IRoleNotifications
+{
+ IView GetRoleNotification(Role role);
+ IView KilledByRoleNotification(Role role);
+ IView KilledRoleNotification(Role role);
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Action/DamageAction.cs b/public/TTT.Public/Action/DamageAction.cs
index 58ca4d1..842b0c9 100644
--- a/public/TTT.Public/Action/DamageAction.cs
+++ b/public/TTT.Public/Action/DamageAction.cs
@@ -4,31 +4,38 @@
namespace TTT.Public.Action;
-public class DamageAction : IAction
+public class DamageAction : Action
{
- private readonly Tuple _actor;
+ private readonly Tuple? _actor;
private readonly Tuple _attackedPlayer;
private readonly int _damage;
+ private readonly int _roundTime;
- public DamageAction(Tuple actor, Tuple attackedPlayer,
+ public DamageAction(Tuple? actor, Tuple attackedPlayer,
int damage, int roundTime)
{
_actor = actor;
_attackedPlayer = attackedPlayer;
_damage = damage;
+ _roundTime = roundTime;
}
- public CCSPlayerController Actor()
+ public override CCSPlayerController Actor()
{
return _actor.Item1;
}
+
+ private string GetActorName()
+ {
+ return _actor?.Item2.FormatStringFullAfter(" " + _actor?.Item1.PlayerName) ?? "World";
+ }
- public string ActionMessage()
+ public override string ActionMessage()
{
- var actorRole = _actor.Item2;
+
var attackedPlayerRole = _attackedPlayer.Item2;
- return $"[TTT] {actorRole.FormatStringFullAfter(" " + _actor.Item1.PlayerName)}" +
+ return $"[TTT] {GetActorName()}" +
$" damaged {attackedPlayerRole.FormatStringFullAfter(" " + _attackedPlayer.Item1.PlayerName)}" +
- $" for {_damage} hp. {IAction.GoodAction(actorRole, attackedPlayerRole)}";
+ $" for {_damage} hp.";
}
}
\ No newline at end of file
diff --git a/public/TTT.Public/Action/DeathAction.cs b/public/TTT.Public/Action/DeathAction.cs
new file mode 100644
index 0000000..4c4fa32
--- /dev/null
+++ b/public/TTT.Public/Action/DeathAction.cs
@@ -0,0 +1,27 @@
+using CounterStrikeSharp.API.Core;
+using TTT.Public.Formatting;
+using TTT.Public.Mod.Role;
+
+namespace TTT.Public.Action;
+
+public class DeathAction : Action
+{
+ private readonly Tuple _actor;
+
+ public DeathAction(Tuple actor)
+ {
+ _actor = actor;
+ }
+
+ public override CCSPlayerController Actor()
+ {
+ return _actor.Item1;
+ }
+
+ public override string ActionMessage()
+ {
+ var actorRole = _actor.Item2;
+ return $"[TTT] {actorRole.FormatStringFullAfter(" " + _actor.Item1.PlayerName)}" +
+ $" was killed by world.";
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Action/IAction.cs b/public/TTT.Public/Action/IAction.cs
index 9112cd0..a32097a 100644
--- a/public/TTT.Public/Action/IAction.cs
+++ b/public/TTT.Public/Action/IAction.cs
@@ -3,10 +3,10 @@
namespace TTT.Public.Action;
-public interface IAction
+public abstract class Action
{
- CCSPlayerController Actor();
- string ActionMessage();
+ public abstract CCSPlayerController Actor();
+ public abstract string ActionMessage();
protected static string GoodAction(Role actor, Role actor2)
{
diff --git a/public/TTT.Public/Action/ILogsService.cs b/public/TTT.Public/Action/ILogsService.cs
deleted file mode 100644
index d905de9..0000000
--- a/public/TTT.Public/Action/ILogsService.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace TTT.Public.Action;
-
-public interface ILogsService
-{
- void AddLog(IAction action);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Action/KillAction.cs b/public/TTT.Public/Action/KillAction.cs
index c72f0a8..b383450 100644
--- a/public/TTT.Public/Action/KillAction.cs
+++ b/public/TTT.Public/Action/KillAction.cs
@@ -4,7 +4,7 @@
namespace TTT.Public.Action;
-public class KillAction : IAction
+public class KillAction : Action
{
private readonly Tuple _actor;
private readonly Tuple _attackedPlayer;
@@ -15,17 +15,17 @@ public KillAction(Tuple actor, Tuple
+ /// Get the configuration object with the provided name
+ ///
+ ///
+ /// If the configuration service would return the default value, fail instead. Loudly.
+ ///
+ ///
+ T Get(string path, bool failOnDefault = false)
+ where T : class, new();
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Database/DatabaseService.cs b/public/TTT.Public/Database/DatabaseService.cs
index aeffd11..39e8a51 100644
--- a/public/TTT.Public/Database/DatabaseService.cs
+++ b/public/TTT.Public/Database/DatabaseService.cs
@@ -1,67 +1,67 @@
-using CounterStrikeSharp.API.Core;
-using MySqlConnector;
-using TTT.Player;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-
-namespace TTT.Public.Database;
-
-public class DatabaseService
-{
- private MySqlConnection _connector;
-
- public DatabaseService()
- {
- _connector = new MySqlConnection();
- _connector.OpenAsync();
- CreateTable();
- }
-
- public void CreateTable()
- {
- Task.Run(async () =>
- {
- var command = new MySqlCommand("CREATE TABLE IF NOT EXISTS PlayerData(steamid VARCHAR(17) NOT NULL," +
- "kills INT," +
- "deaths INT," +
- "karma INT," +
- "traitor_kills INT," +
- "traitors_killed INT," +
- "PRIMARY KEY(steamid));");
- command.Connection = _connector;
- await command.ExecuteNonQueryAsync();
- });
-
- }
-
- public GamePlayer CreateProfile(CCSPlayerController player)
- {
- var id = player.SteamID;
-
- Task.Run(async () =>
- {
- var command = new MySqlCommand("INSERT IGNORE INTO PlayerData(steamid, kills, deaths, karma, traitor_kills, traitors_killed)" +
- $" VALUES ({id}, 0, 0, 80, 0, 0);");
- command.Connection = _connector;
- await command.ExecuteNonQueryAsync();
- });
- return new GamePlayer(Role.Unassigned, 800, 0, player.UserId.Value);
- }
-
- public void UpdatePlayer(GamePlayer player)
- {
- Task.Run(async () =>
- {
- var command = new MySqlCommand("UPDATE PlayerData SET kills = @kills, deaths = @deaths, karma = @karma, traitor_kills = @traitor_kills, traitors_killed = @traitors_killed" +
- " WHERE steamid = @steamid;");
- command.Parameters.AddWithValue("@kills", 0);
- command.Parameters.AddWithValue("@deaths", 0);
- command.Parameters.AddWithValue("@karma", player.Karma());
- command.Parameters.AddWithValue("@traitor_kills", 0);
- command.Parameters.AddWithValue("@traitors_killed", 0);
- command.Parameters.AddWithValue("@steamid", player.Player().SteamID);
- command.Connection = _connector;
- await command.ExecuteNonQueryAsync();
- });
- }
+using CounterStrikeSharp.API.Core;
+using MySqlConnector;
+using TTT.Player;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Public.Database;
+
+public class DatabaseService
+{
+ private MySqlConnection _connector;
+
+ public DatabaseService()
+ {
+ _connector = new MySqlConnection();
+ _connector.OpenAsync();
+ CreateTable();
+ }
+
+ public void CreateTable()
+ {
+ Task.Run(async () =>
+ {
+ var command = new MySqlCommand("CREATE TABLE IF NOT EXISTS PlayerData(steamid VARCHAR(17) NOT NULL," +
+ "kills INT," +
+ "deaths INT," +
+ "karma INT," +
+ "traitor_kills INT," +
+ "traitors_killed INT," +
+ "PRIMARY KEY(steamid));");
+ command.Connection = _connector;
+ await command.ExecuteNonQueryAsync();
+ });
+
+ }
+
+ public GamePlayer CreateProfile(CCSPlayerController player)
+ {
+ var id = player.SteamID;
+
+ Task.Run(async () =>
+ {
+ var command = new MySqlCommand("INSERT IGNORE INTO PlayerData(steamid, kills, deaths, karma, traitor_kills, traitors_killed)" +
+ $" VALUES ({id}, 0, 0, 80, 0, 0);");
+ command.Connection = _connector;
+ await command.ExecuteNonQueryAsync();
+ });
+ return new GamePlayer(Role.Unassigned, 800, 0, player.UserId.Value);
+ }
+
+ public void UpdatePlayer(GamePlayer player)
+ {
+ Task.Run(async () =>
+ {
+ var command = new MySqlCommand("UPDATE PlayerData SET kills = @kills, deaths = @deaths, karma = @karma, traitor_kills = @traitor_kills, traitors_killed = @traitors_killed" +
+ " WHERE steamid = @steamid;");
+ command.Parameters.AddWithValue("@kills", 0);
+ command.Parameters.AddWithValue("@deaths", 0);
+ command.Parameters.AddWithValue("@karma", player.Karma());
+ command.Parameters.AddWithValue("@traitor_kills", 0);
+ command.Parameters.AddWithValue("@traitors_killed", 0);
+ command.Parameters.AddWithValue("@steamid", player.Player().SteamID);
+ command.Connection = _connector;
+ await command.ExecuteNonQueryAsync();
+ });
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Extensions/EntityIOExtensions.cs b/public/TTT.Public/Extensions/EntityIOExtensions.cs
new file mode 100644
index 0000000..5183f40
--- /dev/null
+++ b/public/TTT.Public/Extensions/EntityIOExtensions.cs
@@ -0,0 +1,28 @@
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+
+namespace TTT.Public.Extensions;
+
+public static class EntityIOExtensions
+{
+ public static bool TryGetController(this CEntityInstance pawn, out CCSPlayerController? controller)
+ {
+ controller = null;
+
+ if (!pawn.IsValid)
+ return false;
+
+ var index = (int)pawn.Index;
+ var playerPawn = Utilities.GetEntityFromIndex(index);
+
+ if (!playerPawn.IsValid)
+ return false;
+
+ if (!playerPawn.OriginalController.IsValid)
+ return false;
+
+ controller = playerPawn.OriginalController.Value;
+
+ return controller?.IsReal() == true;
+ }
+}
diff --git a/public/TTT.Public/Extensions/PlayerExtensions.cs b/public/TTT.Public/Extensions/PlayerExtensions.cs
index e50b6f7..c73f338 100644
--- a/public/TTT.Public/Extensions/PlayerExtensions.cs
+++ b/public/TTT.Public/Extensions/PlayerExtensions.cs
@@ -51,7 +51,27 @@ public static string GetActiveWeaponName(this CCSPlayerController player)
return target.As().OriginalController.Value;
}
- return null;}
+ return null;
+ }
+
+ public static CBaseDoor? GetClientPlayerTraitorRoom(this CCSPlayerController player)
+ {
+ var GameRules = Utilities.FindAllEntitiesByDesignerName("cs_gamerules").FirstOrDefault()?.GameRules;
+
+ if (GameRules is null)
+ return null;
+
+ VirtualFunctionWithReturn findPickerEntity = new(GameRules.Handle, 28);
+ var target = new CBaseEntity(findPickerEntity.Invoke(GameRules.Handle, player.Handle));
+
+ if (target.DesignerName is "func_door" || target.DesignerName is "prop_door_rotating")
+ {
+ return target.As();
+ }
+
+ return null;
+ }
+
public static bool IsReal(this CCSPlayerController player)
{
diff --git a/mod/TTT.Round/ScoreboardListener.cs b/public/TTT.Public/Extensions/ScoreboardExtension.cs
similarity index 96%
rename from mod/TTT.Round/ScoreboardListener.cs
rename to public/TTT.Public/Extensions/ScoreboardExtension.cs
index b6184dd..d7f9902 100644
--- a/mod/TTT.Round/ScoreboardListener.cs
+++ b/public/TTT.Public/Extensions/ScoreboardExtension.cs
@@ -1,108 +1,108 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using TTT.Player;
-using TTT.Public.Extensions;
-
-namespace TTT.Round;
-
-public static class ScoreboardListener
-{
- public static void ModifyScoreBoard(this CCSPlayerController? player)
- {
- if (player == null) return;
- if (!player.IsReal()) return;
- var actionService = player.ActionTrackingServices;
- if (actionService == null) return;
-
-
- RemoveKills(player);
- RemoveDamage(player);
- RemoveDeaths(player);
- RemoveUtilityDamage(player);
- RemoveAssists(player);
- RemoveEnemiesFlashed(player);
- RemoveHeadshotKills(player);
- KillIconTest(player);
- }
-
- public static void ModifyKarma(this GamePlayer gamePlayer)
- {
- var player = gamePlayer.Player();
- if (player == null) return;
- SetScore(gamePlayer);
- }
-
- private static void SetScore(GamePlayer gamePlayer)
- {
- var player = gamePlayer.Player();
- if (player == null) return;
-
- if (player.Score == gamePlayer.Karma()) return;
- player.Score = gamePlayer.Karma();
- }
-
- private static void KillIconTest(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices;
- if (matchStats.NumRoundKills == 0 && matchStats.NumRoundKillsHeadshots == 0) return;
- matchStats.NumRoundKills = 0;
- matchStats.NumRoundKillsHeadshots = 0;
- Utilities.SetStateChanged(player, "CCSPlayerController_ActionTrackingServices", "m_iNumRoundKills");
- Utilities.SetStateChanged(player, "CCSPlayerController_ActionTrackingServices", "m_iNumRoundKillsHeadshots");
- }
-
- private static void RemoveKills(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.Kills == 0) return;
- matchStats.Kills = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iKills");
- }
-
- private static void RemoveDamage(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.Damage == 0) return;
- matchStats.Damage = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iDamage");
- }
-
- private static void RemoveUtilityDamage(CCSPlayerController player) {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.UtilityDamage == 0) return;
- matchStats.UtilityDamage = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iUtilityDamage");
- }
-
- private static void RemoveDeaths(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.Deaths == 0) return;
- matchStats.Deaths = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iDeaths");
- }
-
- private static void RemoveAssists(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.Assists == 0) return;
- matchStats.Assists = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iAssists");
- }
-
- private static void RemoveEnemiesFlashed(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.EnemiesFlashed == 0) return;
- matchStats.EnemiesFlashed = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iEnemiesFlashed");
- }
-
- private static void RemoveHeadshotKills(CCSPlayerController player)
- {
- var matchStats = player.ActionTrackingServices!.MatchStats;
- if (matchStats.HeadShotKills == 0) return;
- matchStats.HeadShotKills = 0;
- Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iHeadShotKills");
- }
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using TTT.Player;
+using TTT.Public.Extensions;
+
+namespace TTT.Round;
+
+public static class ScoreboardExtension
+{
+ public static void ModifyScoreBoard(this CCSPlayerController? player)
+ {
+ if (player == null) return;
+ if (!player.IsReal()) return;
+ var actionService = player.ActionTrackingServices;
+ if (actionService == null) return;
+
+
+ RemoveKills(player);
+ RemoveDamage(player);
+ RemoveDeaths(player);
+ RemoveUtilityDamage(player);
+ RemoveAssists(player);
+ RemoveEnemiesFlashed(player);
+ RemoveHeadshotKills(player);
+ KillIconTest(player);
+ }
+
+ public static void ModifyKarma(this GamePlayer gamePlayer)
+ {
+ var player = gamePlayer.Player();
+ if (player == null) return;
+ SetScore(gamePlayer);
+ }
+
+ private static void SetScore(GamePlayer gamePlayer)
+ {
+ var player = gamePlayer.Player();
+ if (player == null) return;
+
+ if (player.Score == gamePlayer.Karma()) return;
+ player.Score = gamePlayer.Karma();
+ }
+
+ private static void KillIconTest(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices;
+ if (matchStats.NumRoundKills == 0 && matchStats.NumRoundKillsHeadshots == 0) return;
+ matchStats.NumRoundKills = 0;
+ matchStats.NumRoundKillsHeadshots = 0;
+ Utilities.SetStateChanged(player, "CCSPlayerController_ActionTrackingServices", "m_iNumRoundKills");
+ Utilities.SetStateChanged(player, "CCSPlayerController_ActionTrackingServices", "m_iNumRoundKillsHeadshots");
+ }
+
+ private static void RemoveKills(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.Kills == 0) return;
+ matchStats.Kills = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iKills");
+ }
+
+ private static void RemoveDamage(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.Damage == 0) return;
+ matchStats.Damage = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iDamage");
+ }
+
+ private static void RemoveUtilityDamage(CCSPlayerController player) {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.UtilityDamage == 0) return;
+ matchStats.UtilityDamage = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iUtilityDamage");
+ }
+
+ private static void RemoveDeaths(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.Deaths == 0) return;
+ matchStats.Deaths = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iDeaths");
+ }
+
+ private static void RemoveAssists(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.Assists == 0) return;
+ matchStats.Assists = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iAssists");
+ }
+
+ private static void RemoveEnemiesFlashed(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.EnemiesFlashed == 0) return;
+ matchStats.EnemiesFlashed = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iEnemiesFlashed");
+ }
+
+ private static void RemoveHeadshotKills(CCSPlayerController player)
+ {
+ var matchStats = player.ActionTrackingServices!.MatchStats;
+ if (matchStats.HeadShotKills == 0) return;
+ matchStats.HeadShotKills = 0;
+ Utilities.SetStateChanged(player, "CSPerRoundStats_t", "m_iHeadShotKills");
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Extensions/ServerExtensions.cs b/public/TTT.Public/Extensions/ServerExtensions.cs
new file mode 100644
index 0000000..4bda151
--- /dev/null
+++ b/public/TTT.Public/Extensions/ServerExtensions.cs
@@ -0,0 +1,30 @@
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using CounterStrikeSharp.API.Modules.Memory;
+using CounterStrikeSharp.API.Modules.Utils;
+
+namespace TTT.Public.Extensions;
+
+public static class ServerExtensions
+{
+ public static void PrintToCenterAll(string message)
+ {
+ VirtualFunctions.ClientPrintAll(HudDestination.Center, message, 0, 0, 0, 0);
+ }
+
+ ///
+ /// Get the current CCSGameRules for the server
+ ///
+ ///
+ public static CCSGameRules GetGameRules()
+ {
+ // From killstr3ak
+ return Utilities.FindAllEntitiesByDesignerName("cs_gamerules").First().GameRules!;
+ }
+
+ public static CCSGameRulesProxy GetGameRulesProxy()
+ {
+ // From killstr3ak
+ return Utilities.FindAllEntitiesByDesignerName("cs_gamerules").First()!;
+ }
+}
diff --git a/public/TTT.Public/Extensions/ServiceCollectionExtension.cs b/public/TTT.Public/Extensions/ServiceCollectionExtensions.cs
similarity index 64%
rename from public/TTT.Public/Extensions/ServiceCollectionExtension.cs
rename to public/TTT.Public/Extensions/ServiceCollectionExtensions.cs
index 8ed0a84..1408fee 100644
--- a/public/TTT.Public/Extensions/ServiceCollectionExtension.cs
+++ b/public/TTT.Public/Extensions/ServiceCollectionExtensions.cs
@@ -1,5 +1,6 @@
-using Microsoft.Extensions.DependencyInjection;
-using TTT.Public.Behaviors;
+using TTT.Public.Behaviors;
+using TTT.Public.Configuration;
+using Microsoft.Extensions.DependencyInjection;
namespace TTT.Public.Extensions;
@@ -41,4 +42,22 @@ public static void AddPluginBehavior(this IServiceCollec
collection.AddTransient(provider => provider.GetRequiredService());
collection.AddTransient(provider => provider.GetRequiredService());
}
+
+ ///
+ /// Add an object to be loaded from the configuration file
+ ///
+ ///
+ /// The section where the configuration object will be loaded from
+ /// The configuration object. Must auto-fill all default values!
+ public static void AddConfig(this IServiceCollection collection, string sectionName)
+ where TConfig : class, new()
+ {
+ // Get the object by resolving IConfigService
+ // and use the Get() method.
+
+ // Not *really* important... but do we want to fail here or return default if section
+ // isn't available?
+ collection.AddTransient(provider => provider.GetRequiredService()
+ .Get(sectionName));
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Extensions/StringExtensions.cs b/public/TTT.Public/Extensions/StringExtensions.cs
new file mode 100644
index 0000000..777310e
--- /dev/null
+++ b/public/TTT.Public/Extensions/StringExtensions.cs
@@ -0,0 +1,10 @@
+namespace TTT.Public.Extensions;
+
+public static class StringExtensions
+{
+ public static string Sanitize(this string unknown)
+ {
+ return unknown
+ .Replace("<", "<");
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Extensions/VectorExtensions.cs b/public/TTT.Public/Extensions/VectorExtensions.cs
new file mode 100644
index 0000000..5e80cd3
--- /dev/null
+++ b/public/TTT.Public/Extensions/VectorExtensions.cs
@@ -0,0 +1,56 @@
+using CounterStrikeSharp.API.Modules.Utils;
+
+namespace TTT.Public.Extensions;
+
+public static class VectorExtensions
+{
+ public static Vector Clone(this Vector vector)
+ {
+ var vec = new Vector
+ {
+ X = vector.X,
+ Y = vector.Y,
+ Z = vector.Z
+ };
+ return vec;
+ }
+
+ public static Vector Add(this Vector vector, Vector other)
+ {
+ vector.X += other.X;
+ vector.Y += other.Y;
+ vector.Z += other.Z;
+ return vector;
+ }
+
+ public static Vector Scale(this Vector vector, float scale)
+ {
+ vector.X *= scale;
+ vector.Y *= scale;
+ vector.Z *= scale;
+ return vector;
+ }
+
+ public static Vector Normalize(this Vector vector)
+ {
+ var length = vector.Length();
+ vector.X /= length;
+ vector.Y /= length;
+ vector.Z /= length;
+ return vector;
+ }
+
+ public static float Distance(this Vector vector, Vector other)
+ {
+ return (float)Math.Sqrt(vector.DistanceSquared(other));
+ }
+
+ public static float DistanceSquared(this Vector vector, Vector other)
+ {
+ return (float)(
+ Math.Pow(vector.X - other.X, 2) +
+ Math.Pow(vector.Y - other.Y, 2) +
+ Math.Pow(vector.Z - other.Z, 2)
+ );
+ }
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Formatting/Format.cs b/public/TTT.Public/Formatting/Format.cs
index fda4d35..ac77113 100644
--- a/public/TTT.Public/Formatting/Format.cs
+++ b/public/TTT.Public/Formatting/Format.cs
@@ -63,4 +63,16 @@ public static string GetCenterRole(this Role role)
_ => ""
};
}
+
+ public static Color GetColor(this Role role)
+ {
+ return role switch
+ {
+ Role.Traitor => Color.Red,
+ Role.Detective => Color.Blue,
+ Role.Innocent => Color.Lime,
+ Role.Unassigned => Color.DarkGray,
+ _ => Color.Black
+ };
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Formatting/StringUtils.cs b/public/TTT.Public/Formatting/StringUtils.cs
index f0f3e47..a0aa8be 100644
--- a/public/TTT.Public/Formatting/StringUtils.cs
+++ b/public/TTT.Public/Formatting/StringUtils.cs
@@ -1,17 +1,17 @@
-using CounterStrikeSharp.API.Modules.Utils;
-
-namespace TTT.Public.Formatting;
-
-public class StringUtils
-{
- private StringUtils()
- {
- throw new NotSupportedException("Utility class");
- }
-
- public static string FormatTTT(string message)
- {
-
- return $" {ChatColors.Purple}[{ChatColors.Red}TTT{ChatColors.Purple}]{ChatColors.Green} {message}";
- }
+using CounterStrikeSharp.API.Modules.Utils;
+
+namespace TTT.Public.Formatting;
+
+public class StringUtils
+{
+ private StringUtils()
+ {
+ throw new NotSupportedException("Utility class");
+ }
+
+ public static string FormatTTT(string message)
+ {
+
+ return $" {ChatColors.Purple}[{ChatColors.Red}TTT{ChatColors.Purple}]{ChatColors.Green} {message}";
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/Logs/ILogService.cs b/public/TTT.Public/Mod/Logs/ILogService.cs
new file mode 100644
index 0000000..8e6f727
--- /dev/null
+++ b/public/TTT.Public/Mod/Logs/ILogService.cs
@@ -0,0 +1,15 @@
+using CounterStrikeSharp.API.Core;
+using TTT.Public.Action;
+
+namespace TTT.Public.Mod.Logs;
+
+public interface ILogService
+{
+ int GetCurrentRound();
+ void AddLog(Action.Action action);
+ bool PrintLogs(int round);
+ bool PrintToPlayer(CCSPlayerController player, int round);
+ bool PrintToConsole(int round);
+ IRoundLogs GetLogs(int round);
+ void CreateRound(int round);
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/Logs/IRoundLogs.cs b/public/TTT.Public/Mod/Logs/IRoundLogs.cs
new file mode 100644
index 0000000..8b07784
--- /dev/null
+++ b/public/TTT.Public/Mod/Logs/IRoundLogs.cs
@@ -0,0 +1,11 @@
+using TTT.Public.Action;
+
+namespace TTT.Public.Mod.Logs;
+
+public interface IRoundLogs
+{
+ IList GetLogs();
+ void AddLog(Action.Action action);
+ void RemoveLog(Action.Action action);
+ string FormattedLogs();
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/Manager/IMuteService.cs b/public/TTT.Public/Mod/Manager/IMuteService.cs
new file mode 100644
index 0000000..d61fb7f
--- /dev/null
+++ b/public/TTT.Public/Mod/Manager/IMuteService.cs
@@ -0,0 +1,11 @@
+using CounterStrikeSharp.API.Core;
+
+namespace TTT.Public.Mod.Manager;
+
+public interface IMuteService
+{
+ void Mute(CCSPlayerController player);
+ void UnMute(CCSPlayerController player);
+ void UnMuteAll();
+ void MuteAll();
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/PlayerBody/IPlayerBodyService.cs b/public/TTT.Public/Mod/PlayerBody/IPlayerBodyService.cs
deleted file mode 100644
index e35c017..0000000
--- a/public/TTT.Public/Mod/PlayerBody/IPlayerBodyService.cs
+++ /dev/null
@@ -1,5 +0,0 @@
-namespace TTT.Public.Mod.PlayerBody;
-
-public class IPlayerBodyService
-{
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/Role/IRoleService.cs b/public/TTT.Public/Mod/Role/IRoleService.cs
index dbd67c5..43ed3e2 100644
--- a/public/TTT.Public/Mod/Role/IRoleService.cs
+++ b/public/TTT.Public/Mod/Role/IRoleService.cs
@@ -1,12 +1,14 @@
using CounterStrikeSharp.API.Core;
+using TTT.Public.Mod.Round;
using TTT.Public.Player;
namespace TTT.Public.Mod.Role;
-public interface IRoleService : IPlayerService
+public interface IRoleService
{
Role GetRole(CCSPlayerController player);
void AddRoles();
+ IRoundService GetRoundService();
ISet GetTraitors();
ISet GetDetectives();
ISet GetInnocents();
@@ -15,7 +17,6 @@ public interface IRoleService : IPlayerService
void AddDetective(CCSPlayerController player);
void AddTraitor(CCSPlayerController player);
void AddInnocents(IEnumerable players);
- public void ApplyColorFromRole(CCSPlayerController player, Role role);
void Clear();
}
diff --git a/public/TTT.Public/Mod/Round/IRoundService.cs b/public/TTT.Public/Mod/Round/IRoundService.cs
index 549f5a1..4869e48 100644
--- a/public/TTT.Public/Mod/Round/IRoundService.cs
+++ b/public/TTT.Public/Mod/Round/IRoundService.cs
@@ -1,4 +1,5 @@
-using TTT.Public.Action;
+using CounterStrikeSharp.API.Core;
+using TTT.Public.Action;
namespace TTT.Public.Mod.Round;
@@ -6,11 +7,11 @@ public interface IRoundService
{
RoundStatus GetRoundStatus();
void SetRoundStatus(RoundStatus roundStatus);
+ void Start(BasePlugin plugin);
void TickWaiting();
void ForceStart();
void ForceEnd();
- ILogsService GetLogsService();
}
public enum RoundStatus
diff --git a/public/TTT.Public/Mod/Scoreboard/IScoreboardService.cs b/public/TTT.Public/Mod/Scoreboard/IScoreboardService.cs
deleted file mode 100644
index 5162088..0000000
--- a/public/TTT.Public/Mod/Scoreboard/IScoreboardService.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using CounterStrikeSharp.API.Core;
-
-namespace TTT.Public.Mod.Scoreboard;
-
-public interface IScoreboardService
-{
- void RemoveStats(CCSPlayerController player);
- void RenamePlayer(CCSPlayerController player);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Mod/Traitor/ITraitorService.cs b/public/TTT.Public/Mod/Traitor/ITraitorService.cs
new file mode 100644
index 0000000..9dc1b67
--- /dev/null
+++ b/public/TTT.Public/Mod/Traitor/ITraitorService.cs
@@ -0,0 +1,6 @@
+namespace TTT.Public.Mod.Traitor;
+
+public class ITraitorService
+{
+
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Player/GamePlayer.cs b/public/TTT.Public/Player/GamePlayer.cs
index c498b71..c5f2b70 100644
--- a/public/TTT.Public/Player/GamePlayer.cs
+++ b/public/TTT.Public/Player/GamePlayer.cs
@@ -1,156 +1,127 @@
-using CounterStrikeSharp.API;
-using CounterStrikeSharp.API.Core;
-using TTT.Public.Mod.Role;
-using TTT.Public.Player;
-using TTT.Public.Shop;
-
-namespace TTT.Player;
-
-public class GamePlayer : IInventory
-{
-
- private Role _playerRole;
- private int _playerId;
- private int _karma;
- private long _credits;
- private CCSPlayerController? _killer;
- private CRagdollProp? _ragdollProp;
- private readonly List _items = [];
- private bool _shopOpen = false;
- private bool _isFound = false;
- private bool _isDead = false;
-
- public GamePlayer(Role playerRole, long credits, int karma, int playerId)
- {
- _playerRole = playerRole;
- _credits = credits;
- _karma = karma;
- _killer = null;
- _ragdollProp = null;
- _playerId = playerId;
- }
-
- public void AddItem(IShopItem item)
- {
- _items.Add(item);
- }
-
- public void RemoveItem(string name)
- {
- _items.RemoveAll(shopItem => shopItem.Name().Equals(name));
- }
-
- public List GetItems()
- {
- return _items;
- }
-
- public bool HasItem(string item)
- {
- return _items.Any(shopItem => shopItem.Name().Equals(item));
- }
-
- public bool IsDead()
- {
- return _isDead;
- }
-
- public void SetDead(bool isDead = false)
- {
- _isDead = isDead;
- }
-
- public CCSPlayerController? Player()
- {
- return Utilities.GetPlayerFromUserid(_playerId);
- }
-
- public Role PlayerRole()
- {
- return _playerRole;
- }
-
- public int Karma()
- {
- return _karma;
- }
-
- public void AddKarma()
- {
- _karma += 2;
- }
-
- public void RemoveKarma()
- {
- _karma -= 5;
- if (_karma >= 40) return;
- _karma = 80;
- //Server.ExecuteCommand($"css_ban #{_playerId} 1440 Karma too low");
- }
-
- public void SetPlayerRole(Role role)
- {
- _playerRole = role;
- }
-
- public long Credits()
- {
- return _credits;
- }
-
- public void AddCredits(long increment)
- {
- _credits += increment;
- }
-
- public void RemoveCredits(long decrement)
- {
- _credits -= decrement;
- }
-
- public void ResetCredits()
- {
- _credits = 800;
- }
-
- public CCSPlayerController? Killer()
- {
- return _killer;
- }
-
- public void SetKiller(CCSPlayerController? killer)
- {
- _killer = killer;
- }
-
- public CRagdollProp? RagdollProp()
- {
- return _ragdollProp;
- }
-
- public void SetRagdollProp(CRagdollProp? prop)
- {
- _ragdollProp = prop;
- }
-
- public void SetShopOpen(bool open)
- {
- _shopOpen = open;
- }
-
- public bool ShopOpen()
- {
- return _shopOpen;
- }
-
- public bool SetFound(bool found)
- {
- _isFound = found;
- return _isFound;
- }
-
- public bool IsFound()
- {
- return _isFound;
- }
+using CounterStrikeSharp.API;
+using CounterStrikeSharp.API.Core;
+using TTT.Public.Mod.Role;
+using TTT.Public.Player;
+
+namespace TTT.Player;
+
+public class GamePlayer
+{
+
+ private Role _playerRole;
+ private int _playerId;
+ private int _karma;
+ private long _credits;
+ private CCSPlayerController? _killer;
+ private bool _shopOpen = false;
+ private bool _isFound = false;
+ private bool _isDead = false;
+
+ public GamePlayer(Role playerRole, long credits, int karma, int playerId)
+ {
+ _playerRole = playerRole;
+ _credits = credits;
+ _karma = karma;
+ _killer = null;
+ _playerId = playerId;
+ }
+
+ public bool IsDead()
+ {
+ return _isDead;
+ }
+
+ public void SetDead(bool isDead = false)
+ {
+ _isDead = isDead;
+ }
+
+ public CCSPlayerController? Player()
+ {
+ return Utilities.GetPlayerFromUserid(_playerId);
+ }
+
+ public Role PlayerRole()
+ {
+ return _playerRole;
+ }
+
+ public int Karma()
+ {
+ return _karma;
+ }
+
+ public void SetKarma(int karma)
+ {
+ _karma = karma;
+ }
+
+ public void AddKarma(int karma)
+ {
+ _karma += karma;
+ }
+
+ public void RemoveKarma(int karma)
+ {
+ _karma -= karma;
+ if (_karma >= 40) return;
+ _karma = 80;
+ //Server.ExecuteCommand($"css_ban #{_playerId} 1440 Karma too low");
+ }
+
+ public void SetPlayerRole(Role role)
+ {
+ _playerRole = role;
+ }
+
+ public long Credits()
+ {
+ return _credits;
+ }
+
+ public void AddCredits(long increment)
+ {
+ _credits += increment;
+ }
+
+ public void RemoveCredits(long decrement)
+ {
+ _credits -= decrement;
+ }
+
+ public void ResetCredits()
+ {
+ _credits = 800;
+ }
+
+ public CCSPlayerController? Killer()
+ {
+ return _killer;
+ }
+
+ public void SetKiller(CCSPlayerController? killer)
+ {
+ _killer = killer;
+ }
+
+ public void SetShopOpen(bool open)
+ {
+ _shopOpen = open;
+ }
+
+ public bool ShopOpen()
+ {
+ return _shopOpen;
+ }
+
+ public bool SetFound(bool found)
+ {
+ _isFound = found;
+ return _isFound;
+ }
+
+ public bool IsFound()
+ {
+ return _isFound;
+ }
}
\ No newline at end of file
diff --git a/public/TTT.Public/Player/IPlayerService.cs b/public/TTT.Public/Player/IPlayerService.cs
index 627527d..aa51184 100644
--- a/public/TTT.Public/Player/IPlayerService.cs
+++ b/public/TTT.Public/Player/IPlayerService.cs
@@ -1,13 +1,16 @@
-using CounterStrikeSharp.API.Core;
-using TTT.Player;
-using TTT.Public.Mod.Role;
-
-namespace TTT.Public.Player;
-
-public interface IPlayerService
-{
- List Players();
- GamePlayer GetPlayer(CCSPlayerController player);
- void RemovePlayer(CCSPlayerController player);
- void Clr();
+using CounterStrikeSharp.API.Core;
+using TTT.Player;
+using TTT.Public.Mod.Role;
+
+namespace TTT.Public.Player;
+
+public interface IPlayerService
+{
+ List Players();
+ GamePlayer GetPlayer(CCSPlayerController player);
+ void RemovePlayer(CCSPlayerController player);
+ void CreatePlayer(CCSPlayerController player);
+ void Clr();
+ void AddKarma(CCSPlayerController player, int karma);
+ void RemoveKarma(CCSPlayerController player, int karma);
}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/AbstractShopItem.cs b/public/TTT.Public/Shop/AbstractShopItem.cs
new file mode 100644
index 0000000..d7028f6
--- /dev/null
+++ b/public/TTT.Public/Shop/AbstractShopItem.cs
@@ -0,0 +1,24 @@
+using TTT.Player;
+
+namespace TTT.Public.Shop;
+
+public abstract class AbstractShopItem
+{
+ public abstract string Name { get; }
+ public abstract string ShortName { get; }
+ public abstract string Description { get; }
+ public abstract void OnBuy(GamePlayer player);
+
+ public bool CanBuy(GamePlayer player)
+ {
+ return player.Credits() >= ItemCost();
+ }
+
+ public int ItemCost()
+ {
+ //grab from config
+ // config.getCost(Name)
+ return 0;
+ }
+
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/BuyResult.cs b/public/TTT.Public/Shop/BuyResult.cs
deleted file mode 100644
index c15701a..0000000
--- a/public/TTT.Public/Shop/BuyResult.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace TTT.Public.Shop;
-
-public enum BuyResult
-{
- Successful,
- NotEnoughCredits,
- AlreadyOwned,
- IncorrectRole
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/IActionItem.cs b/public/TTT.Public/Shop/IActionItem.cs
deleted file mode 100644
index e773e19..0000000
--- a/public/TTT.Public/Shop/IActionItem.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using TTT.Player;
-
-namespace TTT.Public.Shop;
-
-public interface IActionItem : IShopItem
-{
- void OnAction(GamePlayer player);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/IInventory.cs b/public/TTT.Public/Shop/IInventory.cs
deleted file mode 100644
index 24b7d85..0000000
--- a/public/TTT.Public/Shop/IInventory.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace TTT.Public.Shop;
-
-public interface IInventory
-{
- List GetItems();
- bool HasItem(string name);
- void AddItem(IShopItem item);
- void RemoveItem(string name);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/IShopItem.cs b/public/TTT.Public/Shop/IShopItem.cs
deleted file mode 100644
index 4edcd3e..0000000
--- a/public/TTT.Public/Shop/IShopItem.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using CounterStrikeSharp.API.Core;
-using TTT.Player;
-
-namespace TTT.Public.Shop;
-
-public interface IShopItem
-{
- ///
- /// Display name in the shop
- ///
- /// The item name
- string Name();
-
- ///
- /// The simple name of the item
- ///
- /// The simple name of the item
- string SimpleName();
-
- ///
- /// The price of the item
- ///
- /// The price of the item
- int Price();
-
- ///
- /// Called when the player buys the item
- ///
- /// The player that bought the item
- /// if the item was bought or not.
- BuyResult OnBuy(GamePlayer player);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/IShopItemHandler.cs b/public/TTT.Public/Shop/IShopItemHandler.cs
deleted file mode 100644
index c02df2c..0000000
--- a/public/TTT.Public/Shop/IShopItemHandler.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace TTT.Public.Shop;
-
-public interface IShopItemHandler
-{
- ISet GetShopItems();
- void AddShopItem(IShopItem item);
-}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/ShopConfig.cs b/public/TTT.Public/Shop/ShopConfig.cs
new file mode 100644
index 0000000..a987316
--- /dev/null
+++ b/public/TTT.Public/Shop/ShopConfig.cs
@@ -0,0 +1,8 @@
+using CounterStrikeSharp.API.Core;
+
+namespace TTT.Public.Shop;
+
+public class ShopConfig
+{
+
+}
\ No newline at end of file
diff --git a/public/TTT.Public/Shop/ShopMenu.cs b/public/TTT.Public/Shop/ShopMenu.cs
deleted file mode 100644
index 71a7957..0000000
--- a/public/TTT.Public/Shop/ShopMenu.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-using CounterStrikeSharp.API.Core;
-using CounterStrikeSharp.API.Modules.Menu;
-using TTT.Player;
-using TTT.Public.Formatting;
-using TTT.Public.Player;
-
-namespace TTT.Public.Shop;
-
-public class ShopMenu
-{
- private readonly CenterHtmlMenu _menu;
- private readonly GamePlayer _playerService;
- private readonly IShopItemHandler _shopItemHandler;
-
- public ShopMenu(BasePlugin plugin, IShopItemHandler shopItemHandler, GamePlayer playerService)
- {
- _menu = new CenterHtmlMenu($"Shop - {playerService.Credits()} credits", plugin);
- _shopItemHandler = shopItemHandler;
- _playerService = playerService;
- Create();
- }
-
- public void BuyItem(GamePlayer player, IShopItem item)
- {
- var successful = item.OnBuy(player);
- switch (successful)
- {
- case BuyResult.NotEnoughCredits:
- player.Player()
- .PrintToChat(StringUtils.FormatTTT($"You don't have enough credits to buy {item.Name()}"));
- break;
- case BuyResult.Successful:
- player.Player().PrintToChat(StringUtils.FormatTTT($"You have bought {item.Name()}"));
- player.AddItem(item);
- break;
- case BuyResult.AlreadyOwned:
- player.Player().PrintToChat(StringUtils.FormatTTT($"You already own {item.Name()}"));
- break;
- case BuyResult.IncorrectRole:
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- public void BuyItem(GamePlayer player, int index)
- {
- var item = _shopItemHandler.GetShopItems().ElementAt(index);
- BuyItem(player, item);
- }
-
- public void BuyItem(GamePlayer player, string name)
- {
- foreach (var item in _shopItemHandler.GetShopItems())
- {
- if (!item.SimpleName().Equals(name)) continue;
- BuyItem(player, item);
- return;
- }
- player.Player().PrintToChat(StringUtils.FormatTTT("Item not found!"));
- }
-
- public void Create()
- {
- foreach (var option in _menu.MenuOptions.Where(option => option.Text.Equals("close")))
- {
- option.OnSelect += (player, _) =>
- {
- _playerService.SetShopOpen(false);
- };
- }
-
- for (var index = 0; index < _shopItemHandler.GetShopItems().Count; index++)
- {
- var item = _shopItemHandler.GetShopItems().ElementAt(index);
- _menu.AddMenuOption(item.Name() + $" - {item.Price()} credits",
- (player, _) =>
- {
- BuyItem(_playerService, item);
- _playerService.SetShopOpen(false);
- });
- }
- }
-
- public void Open(CCSPlayerController player)
- {
- _menu.Open(player);
-
- }
-}
\ No newline at end of file
diff --git a/public/TTT.Public/TTT.Public.csproj b/public/TTT.Public/TTT.Public.csproj
index 97a24db..4740ad1 100644
--- a/public/TTT.Public/TTT.Public.csproj
+++ b/public/TTT.Public/TTT.Public.csproj
@@ -8,7 +8,4 @@
-
-
-
\ No newline at end of file
diff --git a/src/TTT/Config/ConfigService.cs b/src/TTT/Config/ConfigService.cs
new file mode 100644
index 0000000..21737e4
--- /dev/null
+++ b/src/TTT/Config/ConfigService.cs
@@ -0,0 +1,68 @@
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using CounterStrikeSharp.API;
+using TTT.Public.Configuration;
+using Microsoft.Extensions.Logging;
+
+namespace TTT.Config;
+
+///
+/// A service to load and parse configuration files.
+///
+public class ConfigService : IConfigService
+{
+ private readonly ILogger _logger;
+
+ ///
+ /// Constructor
+ ///
+ ///
+ public ConfigService(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public T Get(string path, bool fail = false)
+ where T : class, new()
+ {
+ var jsonPath = Path.Combine(Server.GameDirectory, IConfigService.ConfigPath);
+
+ if (!File.Exists(jsonPath))
+ return Fail(fail, "Config file does not exist");
+
+ var jsonText = File.ReadAllText(jsonPath);
+
+ var jsonObject = JsonNode.Parse(jsonText);
+ if (jsonObject == null)
+ return Fail(fail, $"Unable to parse configuration file at {jsonPath}");
+
+ var configObject = jsonObject[path];
+ if (configObject == null)
+ return Fail(fail, $"Unable to navigate to config section {path}");
+
+ var config = configObject.Deserialize();
+ if (config == null)
+ return Fail(fail, $"Unable to deserialize ({configObject.ToJsonString()}) into {typeof(T).FullName}.");
+
+ return config;
+ }
+
+ private T Fail(bool fail, string message)
+ where T : class, new()
+ {
+ // We would be returning default.
+ // Check if caller wants us to cry and scream instead.
+ if (fail)
+ throw new InvalidOperationException(message);
+
+ _logger.LogWarning("[Config] Tripped load fail state with message: {@Message}", message);
+
+ return new T();
+ }
+}
\ No newline at end of file
diff --git a/src/TTT/TTT.csproj b/src/TTT/TTT.csproj
index 2d96799..ac57023 100644
--- a/src/TTT/TTT.csproj
+++ b/src/TTT/TTT.csproj
@@ -4,11 +4,18 @@
enable
enable
+
+
+
+
+
+
+
$(MSBuildThisFileDirectory)/../../build
@@ -17,6 +24,7 @@
false
true
+
diff --git a/src/TTT/TTTServiceCollection.cs b/src/TTT/TTTServiceCollection.cs
index e196600..7644954 100644
--- a/src/TTT/TTTServiceCollection.cs
+++ b/src/TTT/TTTServiceCollection.cs
@@ -1,7 +1,11 @@
using CounterStrikeSharp.API.Core;
using Microsoft.Extensions.DependencyInjection;
using TTT.Detective;
+using TTT.Logs;
+using TTT.Manager;
+using TTT.Player;
using TTT.Roles;
+using TTT.Round;
namespace TTT;
@@ -9,7 +13,10 @@ public class TTTServiceCollection : IPluginServiceCollection
{
public void ConfigureServices(IServiceCollection serviceCollection)
{
+ serviceCollection.AddPlayerService();
serviceCollection.AddTTTRoles();
serviceCollection.AddDetectiveBehavior();
+ serviceCollection.AddLogsService();
+ serviceCollection.AddManagerService();
}
}
\ No newline at end of file