├── .circleci └── config.yml ├── .commitlintrc.json ├── .editorconfig ├── .github ├── code_of_conduct.md └── pull_request_template.md ├── .gitignore ├── .npmrc ├── contributing.md ├── generator ├── index.ts ├── package.json ├── templates │ ├── _package.json │ ├── _readme.md │ ├── _tsconfig.json │ ├── index.ts │ └── test.ts ├── tsconfig.json └── types │ └── is-scoped │ └── index.d.ts ├── lerna.json ├── license.md ├── package.json ├── readme.md ├── src ├── is-creep-alive │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-creep-spawning │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-invader │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-my-room │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-object-visible │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-room-visible │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-simulation │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── is-source-keeper │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json └── tower-effectiveness-at-range │ ├── index.ts │ ├── package.json │ ├── readme.md │ ├── test.ts │ └── tsconfig.json ├── todo.md ├── tsconfig.base.json └── tslint.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Javascript Node CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-javascript/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | - image: circleci/node:8.9.3 10 | 11 | working_directory: ~/repo 12 | 13 | steps: 14 | - checkout 15 | 16 | # Download and cache dependencies 17 | - restore_cache: 18 | keys: 19 | - v1-dependencies-{{ checksum "package.json" }} 20 | # fallback to using the latest cache if no exact match is found 21 | - v1-dependencies- 22 | 23 | - run: 24 | name: install 25 | command: yarn install 26 | 27 | - save_cache: 28 | paths: 29 | - node_modules 30 | key: v1-dependencies-{{ checksum "package.json" }} 31 | 32 | # run tests! 33 | - run: 34 | name: test 35 | command: yarn test 36 | 37 | - run: 38 | name: lint 39 | command: yarn run lint 40 | 41 | - deploy: 42 | name: release 43 | command: yarn run release || true 44 | -------------------------------------------------------------------------------- /.commitlintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@commitlint/config-conventional", 4 | "@commitlint/config-lerna-scopes" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.{yml,json,md}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.github/code_of_conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at dev@postcrafter.de. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | TODO 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lerna-debug.log 2 | package-lock.json 3 | yarn.lock 4 | *.d.ts 5 | *.js 6 | *.js.map 7 | .nyc_output/ 8 | node_modules/ -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | First off, thank you for considering contributing to OpenScreeps! Before you deep dive and help out with development, make sure to read the following sections in order to know what and how to work on something. If you need help with anything, feel free to create [an issue on GitHub][github-issue] or contact us in [#open-screeps][slack] on slack. 4 | 5 | ## Code of Conduct 6 | 7 | All members of the community are expected to follow the [code of conduct][code-of-conduct]. 8 | 9 | ## Getting started 10 | 11 | There are several way to contribute to this project, the following section will show you how. 12 | 13 | ### Write code 14 | 15 | This section will help you writing code for the OpenScreeps project. It is assumed that you have basic knowledge of how git and GitHub work. 16 | 17 | #### Local Development 18 | 19 | ##### Edit an existing module 20 | 1. Install dependencies: `npm install` 21 | 2. Make your changes to the module and edit the tests if required 22 | 3. Verify the tests are still passing by executing `npm test` 23 | 4. Make sure the readme reflects your changes 24 | 25 | ##### Create a new module 26 | 1. Install dependencies: `npm install` 27 | 2. Execute `npm run create` and follow the instructions 28 | 3. Create your module and write relevant ava cases 29 | 4. Run the tests by executing `npm test` 30 | 5. Make sure the readme is up to date and contains a relevant example 31 | 32 | #### Git Commit Messages 33 | - Follow [Conventional Commits][conventional-commits] 34 | - Use `npm run commit` to get some assistance creating the commit 35 | 36 | #### Pull Requests 37 | - Fill in [the required template][pull-request-template] 38 | - Do not include issue numbers in the PR title 39 | 40 | ### Review a pull request 41 | 42 | TODO 43 | 44 | ### Report a bug 45 | 46 | TODO 47 | 48 | ### Request a feature 49 | 50 | TODO 51 | 52 | ### Share ideas 53 | 54 | TODO 55 | 56 | [code-of-conduct]: ./.github/code_of_conduct.md 57 | [pull-request-template]: ./.github/pull_request_template.md 58 | 59 | [conventional-commits]: https://conventionalcommits.org/ 60 | [slack]: https://screeps.slack.com/messages/open-screeps 61 | 62 | [github-fork]: https://github.com/postcrafter/open-screeps/fork 63 | [github-issue]: https://github.com/postcrafter/open-screeps/issues/new 64 | [github-issues]: https://github.com/postcrafter/open-screeps/issues 65 | [github-questions]: https://github.com/PostCrafter/open-screeps/labels/question 66 | [github-pull-requests]: https://github.com/postcrafter/open-screeps/pulls 67 | -------------------------------------------------------------------------------- /generator/index.ts: -------------------------------------------------------------------------------- 1 | import yeomanGenerator = require('yeoman-generator'); 2 | import isScoped = require('is-scoped'); 3 | 4 | const notEmpty = (input: string) => input.length > 0; 5 | 6 | export = class extends yeomanGenerator { 7 | constructor(args: string | string[], options: {}) { 8 | super(args, options); 9 | } 10 | init() { 11 | return this.prompt([ 12 | { 13 | name: 'moduleName', 14 | message: 'name:', 15 | validate(input) { 16 | if (isScoped(input)) { 17 | return 'the scope will be applied to the module automatically'; 18 | } 19 | return notEmpty(input); 20 | }, 21 | }, 22 | { 23 | name: 'moduleDescription', 24 | message: 'description:', 25 | validate: notEmpty, 26 | }, 27 | { 28 | name: 'moduleAuthor', 29 | message: 'author:', 30 | validate: notEmpty, 31 | }, 32 | ]).then((props) => { 33 | const vars = { 34 | moduleName: props.moduleName, 35 | moduleDescription: props.moduleDescription, 36 | moduleAuthor: props.moduleAuthor, 37 | }; 38 | 39 | this.destinationRoot(this.destinationPath('src', props.moduleName)); 40 | 41 | this.fs.copyTpl(this.templatePath(), this.destinationPath(), vars); 42 | 43 | const mv = (from: string, to: string) => { 44 | return this.fs.move(this.destinationPath(from), this.destinationPath(to), vars); 45 | }; 46 | 47 | mv('_package.json', 'package.json'); 48 | mv('_readme.md', 'readme.md'); 49 | mv('_tsconfig.json', 'tsconfig.json'); 50 | }); 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/generator", 3 | "version": "0.0.0", 4 | "description": "a yeoman generator to scaffold open-screeps modules", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "lint": "tslint -p ./tsconfig.json", 9 | "prepare": "tsc" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/postcrafter/open-screeps.git" 14 | }, 15 | "keywords": [ 16 | "yeoman-generator", 17 | "open-screeps" 18 | ], 19 | "author": "Leo \"PostCrafter\" Friedrichs", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/postcrafter/open-screeps/issues" 23 | }, 24 | "homepage": "https://github.com/postcrafter/open-screeps/generator#readme", 25 | "dependencies": { 26 | "@types/yeoman-generator": "^2.0.0", 27 | "yeoman-generator": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "tslint": "^5.9.1", 31 | "tslint-config-airbnb": "^5.4.2", 32 | "typescript": "^2.6.2" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /generator/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/<%= moduleName %>", 3 | "version": "0.0.0-development", 4 | "description": "<%= moduleDescription %>", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "<%= moduleAuthor %>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/<%= moduleName %>#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.0.2", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /generator/templates/_readme.md: -------------------------------------------------------------------------------- 1 | # <%= moduleName %> 2 | > <%= moduleDescription %> 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/<%= moduleName %> 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { example } from '@open-screeps/<%= moduleName %>'; 12 | ``` 13 | 14 | ## Related 15 | 16 | ## License 17 | [MIT](../../license.md) 18 | -------------------------------------------------------------------------------- /generator/templates/_tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /generator/templates/index.ts: -------------------------------------------------------------------------------- 1 | export function example(): void {} 2 | -------------------------------------------------------------------------------- /generator/templates/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { example } from './index'; 4 | 5 | ava('Should act as an example to be used as a template', (t) => { 6 | example(); 7 | t.pass('Calls example() once in order to trigger code coverage'); 8 | }); 9 | -------------------------------------------------------------------------------- /generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "paths": { 6 | "is-scoped": ["./types/is-scoped"] 7 | }, 8 | "declaration": false 9 | }, 10 | "exclude": [ 11 | "templates/" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /generator/types/is-scoped/index.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for is-scoped 1.0 2 | // Project: https://github.com/sindresorhus/is-scoped#readme 3 | // Definitions by: Leo Friedrichs 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | export = isScoped; 7 | 8 | declare function isScoped(input: string): boolean; 9 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.5.1", 3 | "packages": [ 4 | "generator/", 5 | "src/*" 6 | ], 7 | "version": "independent", 8 | "commands": { 9 | "publish": { 10 | "allowBranch": "master", 11 | "ignore": [ 12 | "*.md" 13 | ] 14 | } 15 | }, 16 | "hoist": [ 17 | "@types/screeps", 18 | "@commitlint/cli", 19 | "@commitlint/config-conventional", 20 | "@commitlint/config-lerna-scopes", 21 | "ava", 22 | "lerna", 23 | "commitizen", 24 | "condition-circle", 25 | "cz-conventional-changelog", 26 | "husky", 27 | "nyc", 28 | "semantic-release", 29 | "semantic-release-monorepo", 30 | "tslint", 31 | "tslint-config-airbnb", 32 | "typescript", 33 | "yo" 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright © 2017 Leo "PostCrafter" Friedrichs 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the “Software”), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "open-screeps", 3 | "version": "0.0.0", 4 | "description": "reusable and tested building blocks for every screeps code base", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "commit": "git-cz", 9 | "commitmsg": "commitlint -e $GIT_PARAMS", 10 | "create": "yo ./generator", 11 | "lerna": "lerna", 12 | "lint": "lerna run lint", 13 | "test": "lerna run test", 14 | "release": "lerna run release", 15 | "postinstall": "lerna bootstrap -- --no-package-lock" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/postcrafter/open-screeps.git" 20 | }, 21 | "keywords": [ 22 | "screeps" 23 | ], 24 | "author": "Leo \"PostCrafter\" Friedrichs ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/postcrafter/open-screeps/issues" 28 | }, 29 | "homepage": "https://github.com/postcrafter/open-screeps#readme", 30 | "devDependencies": { 31 | "@commitlint/cli": "^5.2.6", 32 | "@commitlint/config-conventional": "^5.2.3", 33 | "@commitlint/config-lerna-scopes": "^5.2.6", 34 | "commitizen": "^2.9.6", 35 | "cz-conventional-changelog": "^2.1.0", 36 | "husky": "^0.14.3", 37 | "lerna": "^2.5.1", 38 | "yo": "^2.0.0" 39 | }, 40 | "config": { 41 | "commitizen": { 42 | "path": "./node_modules/cz-conventional-changelog" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # OpenScreeps 2 | 3 | > reusable and tested building blocks for every [screeps][screeps-website] code base 4 | 5 | This repository is a collection of useful snippets and methods that I came up with when programming for the game [screeps][screeps-website]. I'm now attempting to restructure my code and splitting it into reusable modules for everyone to enjoy, teaching myself how to work with unit tests and a monorepo in the progress. 6 | 7 | ## Disclaimer 8 | 9 | This is still heavily work in progress while I extract modules from my code and get used to different tools. The disclaimer will get removed once I've established a workflow and published the packages to npm. 10 | 11 | ## Usage 12 | 13 | Creating a functional and feature rich bot for [screeps][screeps-website] can be a tedious and time consuming process. This projects aims to provide a lot of single purpose modules to simplify and extend the provided game API and improve the way you write your code. 14 | 15 | You can check the `src/` directory for a list of created modules, the directory names are usually very good indicators of what the containing code does. Never the less each module has a readme file with a description of it's purpose and a short example. 16 | 17 | ## Built with 18 | 19 | - [Lerna][lerna-npm] for managing the monorepo and cross-dependencies 20 | - [TypeScript][typescript-npm] for statically typed JavaScript 21 | - [@types/screeps][@types/screeps-npm] for the screeps API type definitions 22 | - [AVA][ava-npm] as the test runner 23 | - [nyc][nyc-npm] for coverage reports 24 | 25 | ## Contributing 26 | 27 | Check out our [Contributing Guidelines][contributing]. 28 | 29 | ## License 30 | 31 | [MIT][license] 32 | 33 | [license]: ./license.md 34 | [contributing]: ./contributing.md 35 | 36 | [npm-website]: https://npmjs.org 37 | [screeps-website]: https://screeps.com 38 | 39 | [@types/screeps-npm]: https://npmjs.org/package/@types/screeps 40 | [ava-npm]: https://npmjs.org/package/ava 41 | [lerna-npm]: https://npmjs.org/package/lerna 42 | [nyc-npm]: https://npmjs.org/package/nyc 43 | [typescript-npm]: https://npmjs.org/package/typescript 44 | -------------------------------------------------------------------------------- /src/is-creep-alive/index.ts: -------------------------------------------------------------------------------- 1 | export function isCreepAlive(creep: string): boolean { 2 | return creep in Game.creeps; 3 | } 4 | -------------------------------------------------------------------------------- /src/is-creep-alive/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-creep-alive", 3 | "version": "0.0.0-development", 4 | "description": "Returns true if the creep is alive", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Adam Laycock <adam'arcath.net>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-creep-alive#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.0.2", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/is-creep-alive/readme.md: -------------------------------------------------------------------------------- 1 | # is-creep-alive 2 | > Returns true if the creep is alive 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-creep-alive 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isCreepAlive } from '@open-screeps/is-creep-alive'; 12 | 13 | const livingCreeps = _.filter(Memory.creepList, (creepName) => isCreepAlive(creepName)) 14 | ``` 15 | 16 | ## Related 17 | - [is-creep-spawning](https://github.com/PostCrafter/open-screeps/tree/master/src/is-creep-spawning) 18 | - [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) 19 | 20 | ## License 21 | [MIT](../../license.md) 22 | -------------------------------------------------------------------------------- /src/is-creep-alive/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isCreepAlive } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame() { 8 | global.Game = { 9 | creeps: { 10 | dave: {}, 11 | bob: {}, 12 | }, 13 | }; 14 | } 15 | 16 | ava('Should return the right values for is creep alive', (t) => { 17 | stubGame(); 18 | 19 | t.true(isCreepAlive('dave')); 20 | t.false(isCreepAlive('phil')); 21 | }); 22 | -------------------------------------------------------------------------------- /src/is-creep-alive/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-creep-spawning/index.ts: -------------------------------------------------------------------------------- 1 | import { isCreepAlive } from '@open-screeps/is-creep-alive'; 2 | 3 | export function isCreepSpawning(creepName: string | Creep): boolean { 4 | let creep: Creep; 5 | 6 | if (typeof creepName === 'string') { 7 | if (!isCreepAlive(creepName)) { 8 | return false; 9 | } 10 | 11 | creep = Game.creeps[creepName]; 12 | } else { 13 | creep = creepName; 14 | } 15 | 16 | return creep.spawning; 17 | } 18 | -------------------------------------------------------------------------------- /src/is-creep-spawning/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-creep-spawning", 3 | "version": "0.0.0-development", 4 | "description": "Is the named/supplied creep spawning?", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Adam Laycock <adam@arcath.net>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-creep-spawning#readme", 29 | "dependencies": { 30 | "@open-screeps/is-creep-alive": "*", 31 | "@types/screeps": "^0.0.0" 32 | }, 33 | "devDependencies": { 34 | "ava": "^0.24.0", 35 | "condition-circle": "^2.0.1", 36 | "nyc": "^11.3.0", 37 | "semantic-release": "^11.0.2", 38 | "semantic-release-monorepo": "^4.0.0", 39 | "tslint": "^5.9.1", 40 | "tslint-config-airbnb": "^5.4.2", 41 | "typescript": "^2.6.2" 42 | }, 43 | "publishConfig": { 44 | "access": "public" 45 | }, 46 | "release": { 47 | "verifyConditions": "condition-circle" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/is-creep-spawning/readme.md: -------------------------------------------------------------------------------- 1 | # is-creep-spawning 2 | > Is the named/supplied creep spawning? 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-creep-spawning 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isCreepSpawning } from '@open-screeps/is-creep-spawning'; 12 | 13 | const spawningCreeps = _.filter(Game.creeps, (creep) => isCreepSpawning(creep)) 14 | ``` 15 | 16 | ## Related 17 | - [is-creep-alive](https://github.com/PostCrafter/open-screeps/tree/master/src/is-creep-alive) 18 | 19 | ## License 20 | [MIT](../../license.md) 21 | -------------------------------------------------------------------------------- /src/is-creep-spawning/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isCreepSpawning } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame() { 8 | global.Game = { 9 | creeps: { 10 | dave: { 11 | spawning: true, 12 | }, 13 | phil: { 14 | spawning: false, 15 | }, 16 | }, 17 | }; 18 | } 19 | 20 | ava('Should return the right values for the given creeps', (t) => { 21 | stubGame(); 22 | 23 | t.true(isCreepSpawning('dave')); 24 | t.false(isCreepSpawning('phil')); 25 | t.false(isCreepSpawning('jeff')); 26 | t.true(isCreepSpawning(Game.creeps['dave'])); 27 | }); 28 | -------------------------------------------------------------------------------- /src/is-creep-spawning/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-invader/index.ts: -------------------------------------------------------------------------------- 1 | export const INVADER_USERNAME = 'Invader'; 2 | 3 | export function isInvader(target: string | Creep): boolean { 4 | if (target instanceof Creep) { 5 | return isInvader(target.owner.username); 6 | } 7 | return target === INVADER_USERNAME; 8 | } 9 | -------------------------------------------------------------------------------- /src/is-invader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-invader", 3 | "version": "0.0.0-development", 4 | "description": "Check if something is an Invader", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Leo \"PostCrafter\" Friedrichs ", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/PostCrafter/open-screeps/tree/master/src/is-invader#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.1.0", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/is-invader/readme.md: -------------------------------------------------------------------------------- 1 | # is-invader 2 | > Check if something is an Invader 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-invader 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isInvader } from '@open-screeps/is-invader'; 12 | 13 | const hostiles = Game.rooms.sim.find(FIND_HOSTILE_CREEPS); 14 | const invaders = invaders.filter(isInvader); 15 | ``` 16 | 17 | ## Related 18 | - [is-source-keeper](https://github.com/PostCrafter/open-screeps/tree/master/src/is-source-keeper) 19 | 20 | ## License 21 | [MIT](../../license.md) 22 | -------------------------------------------------------------------------------- /src/is-invader/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isInvader, INVADER_USERNAME } from './index'; 4 | 5 | declare const global: any; 6 | 7 | // @todo stub creep with sinon 8 | // @todo spy if .owner.username is actually accessed 9 | 10 | class StubCreep { 11 | public owner: { username: string }; 12 | constructor(username: string) { 13 | this.owner = { 14 | username, 15 | }; 16 | } 17 | } 18 | 19 | ava.beforeEach(() => { 20 | global.Creep = StubCreep; 21 | }); 22 | 23 | ava('INVADER_USERNAME should match string "Invader"', (t) => { 24 | t.is(INVADER_USERNAME, 'Invader'); 25 | }); 26 | 27 | ava('When passing a string, it should only return true when matching INVADER_USERNAME', (t) => { 28 | t.true(isInvader(INVADER_USERNAME)); 29 | t.false(isInvader('PostCrafter')); 30 | t.false(isInvader('Source Keeper')); 31 | t.false(isInvader('Screeps')); 32 | }); 33 | 34 | ava( 35 | 'When passing a Creep should only return true when the owner is matching INVADER_USERNAME', 36 | (t) => { 37 | t.true(isInvader(stubCreep(INVADER_USERNAME))); 38 | t.false(isInvader(stubCreep('PostCrafter'))); 39 | t.false(isInvader(stubCreep('Source Keeper'))); 40 | t.false(isInvader(stubCreep('Screeps'))); 41 | }, 42 | ); 43 | 44 | ava.todo('Generative testing with testcheck-js for any other ava cases'); 45 | 46 | function stubCreep(ownerUsername: string): Creep { 47 | return new StubCreep(ownerUsername) as Creep; 48 | } 49 | -------------------------------------------------------------------------------- /src/is-invader/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-my-room/index.ts: -------------------------------------------------------------------------------- 1 | import { isRoomVisible } from '@open-screeps/is-room-visible'; 2 | 3 | export function isMyRoom(roomName: string | Room): boolean { 4 | let room: Room; 5 | 6 | if (typeof roomName === 'string') { 7 | if (!isRoomVisible(roomName)) { 8 | return false; 9 | } 10 | 11 | room = Game.rooms[roomName]; 12 | } else { 13 | room = roomName; 14 | } 15 | 16 | if (room.controller === undefined) { 17 | return false; 18 | } 19 | 20 | return room.controller.my; 21 | } 22 | -------------------------------------------------------------------------------- /src/is-my-room/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-my-room", 3 | "version": "0.0.0-development", 4 | "description": "Check wether a room is yours", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Adam Laycock", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-my-room#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0", 31 | "@open-screeps/is-room-visible": "^1.0.0" 32 | }, 33 | "devDependencies": { 34 | "ava": "^0.24.0", 35 | "condition-circle": "^2.0.1", 36 | "nyc": "^11.3.0", 37 | "semantic-release": "^11.0.2", 38 | "semantic-release-monorepo": "^4.0.0", 39 | "tslint": "^5.9.1", 40 | "tslint-config-airbnb": "^5.4.2", 41 | "typescript": "^2.6.2" 42 | }, 43 | "publishConfig": { 44 | "access": "public" 45 | }, 46 | "release": { 47 | "verifyConditions": "condition-circle" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/is-my-room/readme.md: -------------------------------------------------------------------------------- 1 | # is-my-room 2 | > Check wether a room is yours 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-my-room 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isMyRoom } from '@open-screeps/is-my-room'; 12 | 13 | const myRooms = _.filter(Game.rooms, room => isMyRoom(room)) 14 | ``` 15 | 16 | ## Related 17 | - [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) 18 | 19 | ## License 20 | [MIT](../../license.md) 21 | -------------------------------------------------------------------------------- /src/is-my-room/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isMyRoom } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame() { 8 | global.Game = { 9 | rooms: { 10 | W1N1: { 11 | controller: { 12 | my: true, 13 | }, 14 | }, 15 | W2N1: { 16 | controller: { 17 | my: false, 18 | }, 19 | }, 20 | W3N1: {}, 21 | }, 22 | }; 23 | } 24 | 25 | ava('Should only return true for owned rooms', (t) => { 26 | stubGame(); 27 | 28 | t.true(isMyRoom('W1N1')); 29 | t.false(isMyRoom('W2N1')); 30 | t.false(isMyRoom('W3N1')); 31 | t.false(isMyRoom('E1N1')); 32 | t.true(isMyRoom(Game.rooms['W1N1'])); 33 | t.false(isMyRoom(Game.rooms['W3N1'])); 34 | t.false(isMyRoom('')); 35 | }); 36 | -------------------------------------------------------------------------------- /src/is-my-room/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-object-visible/index.ts: -------------------------------------------------------------------------------- 1 | export function isObjectVisible(id: string): boolean { 2 | return Game.getObjectById(id) !== null; 3 | } 4 | -------------------------------------------------------------------------------- /src/is-object-visible/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-object-visible", 3 | "version": "0.0.0-development", 4 | "description": "Is the game object visible", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Adam Laycock <adam@arcath.net>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-object-visible#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.0.2", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/is-object-visible/readme.md: -------------------------------------------------------------------------------- 1 | # is-object-visible 2 | > Is the game object visible 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-object-visible 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isObjectVisible } from '@open-screeps/is-object-visible'; 12 | 13 | if(isObjectVisible('someid')){ 14 | const source = Game.getObjectById('someid') 15 | } 16 | ``` 17 | 18 | ## Related 19 | - [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) 20 | 21 | ## License 22 | [MIT](../../license.md) 23 | -------------------------------------------------------------------------------- /src/is-object-visible/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isObjectVisible } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame() { 8 | const objects: {[id: string]: {} | null} = { 9 | foo: {}, 10 | bar: null, 11 | }; 12 | 13 | global.Game = { 14 | getObjectById: (id: string) => { 15 | return objects[id]; 16 | }, 17 | }; 18 | } 19 | 20 | ava('Should return the right values', (t) => { 21 | stubGame(); 22 | 23 | t.true(isObjectVisible('foo')); 24 | t.false(isObjectVisible('bar')); 25 | }); 26 | -------------------------------------------------------------------------------- /src/is-object-visible/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-room-visible/index.ts: -------------------------------------------------------------------------------- 1 | export function isRoomVisible(roomName: string): boolean { 2 | return roomName in Game.rooms; 3 | } 4 | -------------------------------------------------------------------------------- /src/is-room-visible/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-room-visible", 3 | "version": "0.0.0-development", 4 | "description": "Check whether a room is currently visible", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Leo "PostCrafter" Friedrichs <dev@postcrafter.de>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-room-visible#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.1.0", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/is-room-visible/readme.md: -------------------------------------------------------------------------------- 1 | # is-room-visible 2 | > Check whether a room is currently visible 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-room-visible 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isRoomVisible } from '@open-screeps/is-room-visible'; 12 | 13 | const observerTargets = Object.keys(Memory.rooms).filter(r => isRoomVisible(r)); 14 | ``` 15 | 16 | ## Related 17 | - [is-simulation](https://github.com/PostCrafter/open-screeps/tree/master/src/is-simulation) 18 | 19 | ## License 20 | [MIT](../../license.md) 21 | -------------------------------------------------------------------------------- /src/is-room-visible/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isRoomVisible } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame(...rooms: string[]) { 8 | type RoomsStub = { 9 | [roomName: string]: boolean; 10 | }; 11 | 12 | global.Game = rooms.reduce( 13 | (game, roomName) => { 14 | game.rooms[roomName] = true; 15 | return game; 16 | }, 17 | { 18 | rooms: {} as RoomsStub, 19 | }, 20 | ); 21 | } 22 | 23 | ava('Should only return true if the object `Game.rooms` contains the specified key', (t) => { 24 | stubGame('E2S7'); 25 | t.true(isRoomVisible('E2S7')); 26 | t.false(isRoomVisible('tutorial')); 27 | t.false(isRoomVisible('sim')); 28 | }); 29 | -------------------------------------------------------------------------------- /src/is-room-visible/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-simulation/index.ts: -------------------------------------------------------------------------------- 1 | import { isRoomVisible } from '@open-screeps/is-room-visible'; 2 | 3 | export const ROOM_SIMULATION = 'sim'; 4 | 5 | export function isSimulation() { 6 | return isRoomVisible(ROOM_SIMULATION); 7 | } 8 | -------------------------------------------------------------------------------- /src/is-simulation/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-simulation", 3 | "version": "0.0.0-development", 4 | "description": "Check whether the code is running in simulation", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Leo "PostCrafter" Friedrichs <dev@postcrafter.de>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/is-simulation#readme", 29 | "dependencies": { 30 | "@open-screeps/is-room-visible": "*", 31 | "@types/screeps": "^0.0.0" 32 | }, 33 | "devDependencies": { 34 | "@semantic-release/git": "^2.0.1", 35 | "ava": "^0.24.0", 36 | "condition-circle": "^2.0.1", 37 | "coveralls": "^3.0.0", 38 | "nyc": "^11.3.0", 39 | "semantic-release": "^11.1.0", 40 | "semantic-release-monorepo": "^4.0.0", 41 | "tslint": "^5.9.1", 42 | "tslint-config-airbnb": "^5.4.2", 43 | "typescript": "^2.6.2" 44 | }, 45 | "publishConfig": { 46 | "access": "public" 47 | }, 48 | "release": { 49 | "verifyConditions": "condition-circle" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/is-simulation/readme.md: -------------------------------------------------------------------------------- 1 | # is-simulation 2 | > Check whether the code is running in simulation 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-simulation 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isSimulation } from '@open-screeps/is-simulation'; 12 | 13 | if (isSimulation()) { 14 | console.log('Code loaded in simulation.'); 15 | } 16 | ``` 17 | 18 | ## Related 19 | - [is-room-visible](https://github.com/PostCrafter/open-screeps/tree/master/src/is-room-visible) 20 | 21 | ## License 22 | [MIT](../../license.md) 23 | -------------------------------------------------------------------------------- /src/is-simulation/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isSimulation, ROOM_SIMULATION } from './index'; 4 | 5 | declare const global: any; 6 | 7 | function stubGame(...rooms: string[]) { 8 | type RoomsStub = { 9 | [roomName: string]: boolean; 10 | }; 11 | 12 | global.Game = rooms.reduce( 13 | (game, roomName) => { 14 | game.rooms[roomName] = true; 15 | return game; 16 | }, 17 | { 18 | rooms: {} as RoomsStub, 19 | }, 20 | ); 21 | } 22 | 23 | ava('Should return true when the room `ROOM_SIMULATION` is visible.', (t) => { 24 | stubGame(ROOM_SIMULATION); 25 | t.true(isSimulation()); 26 | }); 27 | 28 | ava('Should return false when the room `ROOM_SIMULATION` is not visible.', (t) => { 29 | stubGame('tutorial'); 30 | t.false(isSimulation()); 31 | }); 32 | -------------------------------------------------------------------------------- /src/is-simulation/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/is-source-keeper/index.ts: -------------------------------------------------------------------------------- 1 | export const SOURCEKEEPER_USERNAME = 'Source Keeper'; 2 | 3 | export function isSourceKeeper(target: string | Creep): boolean { 4 | if (target instanceof Creep) { 5 | return isSourceKeeper(target.owner.username); 6 | } 7 | return target === SOURCEKEEPER_USERNAME; 8 | } 9 | -------------------------------------------------------------------------------- /src/is-source-keeper/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/is-source-keeper", 3 | "version": "0.0.0-development", 4 | "description": "Check is something is a Source Keeper", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Leo \"PostCrafter\" Friedrichs ", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/PostCrafter/open-screeps/tree/master/src/is-source-keeper#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.1.0", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/is-source-keeper/readme.md: -------------------------------------------------------------------------------- 1 | # is-source-keeper 2 | > Check if something is a Source Keeper 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/is-source-keeper 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { isSourceKeeper } from '@open-screeps/is-source-keeper'; 12 | 13 | const hostiles = Game.rooms.sim.find(FIND_HOSTILE_CREEPS); 14 | const sourceKeepers = invaders.filter(isSourceKeeper); 15 | ``` 16 | 17 | ## Related 18 | - [is-invader](https://github.com/PostCrafter/open-screeps/tree/master/src/is-invader) 19 | 20 | ## License 21 | [MIT](../../license.md) 22 | -------------------------------------------------------------------------------- /src/is-source-keeper/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { isSourceKeeper, SOURCEKEEPER_USERNAME } from './index'; 4 | 5 | declare const global: any; 6 | 7 | // @todo stub creep with sinon 8 | // @todo spy if .owner.username is actually accessed 9 | 10 | class StubCreep { 11 | public owner: { username: string }; 12 | constructor(username: string) { 13 | this.owner = { 14 | username, 15 | }; 16 | } 17 | } 18 | 19 | ava.beforeEach(() => { 20 | global.Creep = StubCreep; 21 | }); 22 | 23 | ava('SOURCEKEEPER_USERNAME should match string "Source Keeper"', (t) => { 24 | t.is(SOURCEKEEPER_USERNAME, 'Source Keeper'); 25 | }); 26 | 27 | ava( 28 | 'When passing a string, it should only return true when matching SOURCEKEEPER_USERNAME', 29 | (t) => { 30 | t.true(isSourceKeeper(SOURCEKEEPER_USERNAME)); 31 | t.false(isSourceKeeper('PostCrafter')); 32 | t.false(isSourceKeeper('Invader')); 33 | t.false(isSourceKeeper('Screeps')); 34 | }, 35 | ); 36 | 37 | ava( 38 | 'When passing a Creep should only return true when the owner is matching SOURCEKEEPER_USERNAME', 39 | (t) => { 40 | t.true(isSourceKeeper(stubCreep(SOURCEKEEPER_USERNAME))); 41 | t.false(isSourceKeeper(stubCreep('PostCrafter'))); 42 | t.false(isSourceKeeper(stubCreep('Invader'))); 43 | t.false(isSourceKeeper(stubCreep('Screeps'))); 44 | t.false(isSourceKeeper(stubCreep('Rising'))); 45 | }, 46 | ); 47 | 48 | ava.todo('Generative testing with testcheck-js for any other ava cases'); 49 | 50 | function stubCreep(ownerUsername: string): Creep { 51 | return new StubCreep(ownerUsername) as Creep; 52 | } 53 | -------------------------------------------------------------------------------- /src/is-source-keeper/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /src/tower-effectiveness-at-range/index.ts: -------------------------------------------------------------------------------- 1 | export function towerEffectivenessAtRange( 2 | range: number, 3 | max: number, 4 | ): number { 5 | if (range <= TOWER_OPTIMAL_RANGE) { 6 | return max; 7 | } 8 | if (range >= TOWER_FALLOFF_RANGE) { 9 | return max * (1 - TOWER_FALLOFF); 10 | } 11 | 12 | const towerFalloffPerTile = TOWER_FALLOFF / (TOWER_FALLOFF_RANGE - TOWER_OPTIMAL_RANGE); 13 | 14 | return max * (1 - (range - TOWER_OPTIMAL_RANGE) * towerFalloffPerTile); 15 | } 16 | -------------------------------------------------------------------------------- /src/tower-effectiveness-at-range/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@open-screeps/tower-effectiveness-at-range", 3 | "version": "0.0.0-development", 4 | "description": "Calculate the effectiveness of tower actions at the given range", 5 | "main": "index.js", 6 | "scripts": { 7 | "lint": "tslint -p ./tsconfig.json", 8 | "test": "tsc && nyc ava", 9 | "prepare": "npm test", 10 | "release": "semantic-release -e semantic-release-monorepo" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/postcrafter/open-screeps.git" 15 | }, 16 | "files": [ 17 | "index.{d.ts,js,js.map}" 18 | ], 19 | "keywords": [ 20 | "screeps", 21 | "open-screeps" 22 | ], 23 | "author": "Adam Laycock <adam@arcath.net>", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/postcrafter/open-screeps/issues" 27 | }, 28 | "homepage": "https://github.com/postcrafter/open-screeps/src/tower-effectiveness-at-range#readme", 29 | "dependencies": { 30 | "@types/screeps": "^0.0.0" 31 | }, 32 | "devDependencies": { 33 | "ava": "^0.24.0", 34 | "condition-circle": "^2.0.1", 35 | "nyc": "^11.3.0", 36 | "semantic-release": "^11.0.2", 37 | "semantic-release-monorepo": "^4.0.0", 38 | "tslint": "^5.9.1", 39 | "tslint-config-airbnb": "^5.4.2", 40 | "typescript": "^2.6.2" 41 | }, 42 | "publishConfig": { 43 | "access": "public" 44 | }, 45 | "release": { 46 | "verifyConditions": "condition-circle" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/tower-effectiveness-at-range/readme.md: -------------------------------------------------------------------------------- 1 | # tower-effectiveness-at-range 2 | > Calculate the effectiveness of tower actions at the given range 3 | 4 | ## Install 5 | ```sh 6 | $ npm install @open-screeps/tower-effectiveness-at-range 7 | ``` 8 | 9 | ## Usage 10 | ```typescript 11 | import { towerEffectivenessAtRange } from '@open-screeps/tower-effectiveness-at-range'; 12 | 13 | let damage = towerEffectivenessAtRange(creep.pos.getRangeTo(tower)); 14 | 15 | let heal = towerEffectivenessAtRange(creep.pos.getRangeTo(tower), 'heal'); 16 | 17 | let repair = towerEffectivenessAtRange(container.pos.getRangeTo(tower), 'repair'); 18 | ``` 19 | 20 | ## Related 21 | 22 | ## License 23 | [MIT](../../license.md) 24 | -------------------------------------------------------------------------------- /src/tower-effectiveness-at-range/test.ts: -------------------------------------------------------------------------------- 1 | import ava from 'ava'; 2 | 3 | import { towerEffectivenessAtRange } from './index'; 4 | 5 | declare const global: any; 6 | 7 | global.TOWER_HITS = 3000; 8 | global.TOWER_CAPACITY = 1000; 9 | global.TOWER_ENERGY_COST = 10; 10 | global.TOWER_POWER_ATTACK = 600; 11 | global.TOWER_POWER_HEAL = 400; 12 | global.TOWER_POWER_REPAIR = 800; 13 | global.TOWER_OPTIMAL_RANGE = 5; 14 | global.TOWER_FALLOFF_RANGE = 20; 15 | global.TOWER_FALLOFF = 0.75; 16 | 17 | ava('Should calculate the tower effectiveness for the given ranges', (t) => { 18 | t.is(towerEffectivenessAtRange(2, TOWER_POWER_ATTACK), 600); 19 | t.is(towerEffectivenessAtRange(21, TOWER_POWER_ATTACK), 150); 20 | t.is(towerEffectivenessAtRange(10, TOWER_POWER_ATTACK), 450); 21 | t.is(towerEffectivenessAtRange(15, TOWER_POWER_ATTACK), 300); 22 | t.is(towerEffectivenessAtRange(2, TOWER_POWER_HEAL), 400); 23 | t.is(towerEffectivenessAtRange(2, TOWER_POWER_REPAIR), 800); 24 | }); 25 | -------------------------------------------------------------------------------- /src/tower-effectiveness-at-range/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json" 3 | } 4 | -------------------------------------------------------------------------------- /todo.md: -------------------------------------------------------------------------------- 1 | # ToDo 2 | - Extend project readme 3 | - contribution guide lines 4 | - instructions for non-typescript users 5 | - Coverage reports 6 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2015", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "sourceMap": true, 7 | "strict": true, 8 | "experimentalDecorators": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint-config-airbnb", 3 | "rules": { 4 | "ter-indent": [true, "tab"] 5 | } 6 | } 7 | --------------------------------------------------------------------------------