File game.player.js
has 1254 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict'
/* global ss, $, $game, $BODY */
// TODO: Refactor
exports
has 64 functions (exceeds 20 allowed). Consider refactoring. Open
var $player = module.exports = {
firstName: null,
id: null,
game: null,
Function calculateSeeds
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
calculateSeeds: function (options) {
var tiles = []
// Get the tiles that need to be bombed
if (options.radius > 1) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function drawSeed
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
drawSeed: function (pos) {
if (_seeds.draw > 0) {
var drawLocal = false
if ($player.seedMode === 'draw') {
var currentTile = $game.$map.currentTiles[pos.x][pos.y]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function displayNpcComments
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
displayNpcComments: function () {
// Clear any previous comment bubbles
$player.clearNpcComments()
// Get on-screen NPCs
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function dropSeed
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
dropSeed: function (options) {
if (options.x !== undefined && options.x >= 0) {
options.mX = $game.$map.currentTiles[options.x][options.y].x
options.mY = $game.$map.currentTiles[options.x][options.y].y
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _move
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
function _move () {
/** IMPORTANT note: x and y are really flipped!!! **/ // is this true?
// First, check what step of animation we are on.
// After one animation cycle, reset steps and moves
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function displayNpcComments
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
displayNpcComments: function () {
// Clear any previous comment bubbles
$player.clearNpcComments()
// Get on-screen NPCs
Function beginMove
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
beginMove: function (targetPosition) {
var localPosition = $player.getLocalPosition()
var path
// Clear HUD
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function calculateSeeds
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
calculateSeeds: function (options) {
var tiles = []
// Get the tiles that need to be bombed
if (options.radius > 1) {
Function _move
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _move () {
/** IMPORTANT note: x and y are really flipped!!! **/ // is this true?
// First, check what step of animation we are on.
// After one animation cycle, reset steps and moves
Function init
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
init: function (callback) {
// get the players info from the db, alerts other users of presence
ss.rpc('game.player.init', function (playerInfo) {
// time in seconds since 1970 or whatever
_startTime = new Date().getTime() / 1000
Function drawSeed
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
drawSeed: function (pos) {
if (_seeds.draw > 0) {
var drawLocal = false
if ($player.seedMode === 'draw') {
var currentTile = $game.$map.currentTiles[pos.x][pos.y]
Function dropSeed
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
dropSeed: function (options) {
if (options.x !== undefined && options.x >= 0) {
options.mX = $game.$map.currentTiles[options.x][options.y].x
options.mY = $game.$map.currentTiles[options.x][options.y].y
}
Function sendSeedBomb
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
sendSeedBomb: function (data) {
var waitingEl = document.getElementById('waiting-for-seed')
// set a waiting boolean so we don't plant more until receive data back from rpc
$game.flags.set('awaiting-seed')
Function moveStraight
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
moveStraight: function (direction) {
var location
var targetPosition
var x, y
Function beginMove
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
beginMove: function (targetPosition) {
var localPosition = $player.getLocalPosition()
var path
// Clear HUD
Function saveResource
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
saveResource: function (resource) {
var playerResource = _resources[resource.id]
var npc = $game.$npc.findNpcByResourceId(resource.id)
var npcLevel = npc.getLevel()
var playerLevel = $player.getLevel()
Function beam
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
beam: function (location) {
$game.flags.set('is-beaming')
$game.flags.set('screen-transition')
$game.$input.resetUI()
$game.$chat.clearAllChats()
Function resetInit
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
resetInit: function () {
_curFrame = 0
_currentStepIncX = 0
_currentStepIncY = 0
_direction = 0
Function moveStraight
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
moveStraight: function (direction) {
var location
var targetPosition
var x, y
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function saveResourceLocally
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
saveResourceLocally: function (data) {
var playerResource = _resources[data.id]
// See if the resource is already in the player's game data
// If so, retrieve it and update it
Function saveResourceLocally
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
saveResourceLocally: function (data) {
var playerResource = _resources[data.id]
// See if the resource is already in the player's game data
// If so, retrieve it and update it
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _setPlayerInformation
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _setPlayerInformation (info) {
// Ensure that flags start from a clean state
$game.flags.unsetAll()
// private
Function nextLevel
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
nextLevel: function () {
$player.currentLevel += 1
$player.seenRobot = false
$game.$botanist.setState(0)
$game.flags.unset('botanist-teleported')
Function saveOtherCommunityResources
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
saveOtherCommunityResources: function (answeredResourceId) {
// Hack for community inventory items
// Dummy data for other resources
var ids = [4001, 4002, 4003]
var bunchOfResources = []
Function saveResource
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
saveResource: function (resource) {
var playerResource = _resources[resource.id]
var npc = $game.$npc.findNpcByResourceId(resource.id)
var npcLevel = npc.getLevel()
var playerLevel = $player.getLevel()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
else return -1
Avoid too many return
statements within this function. Open
else if (diffX < 0 && diffY > 0) return 3
Function getGameRegion
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
getGameRegion: function () {
// Compare player position to centers of the world
var position = this.getPosition()
var posX = position.x
var posY = position.y
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
return '#' + ('0' + (rgb.r.toString(16))).slice(-2) + ('0' + (rgb.g.toString(16))).slice(-2) + ('0' + (rgb.b.toString(16))).slice(-2)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 95.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 'down':
y = location.y
while ((y <= $game.VIEWPORT_HEIGHT - 1) && $game.$map.currentTiles[x][y].tileState === 0) {
targetPosition = { x: x, y: y }
y++
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 86.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 'right':
x = location.x
while ((x <= $game.VIEWPORT_WIDTH - 1) && $game.$map.currentTiles[x][y].tileState === 0) {
targetPosition = { x: x, y: y }
x++
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 86.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
makePrivate: function (id) {
if (_resources[id]) {
_resources[id].madePublic = false
ss.rpc('game.npc.makeResponsePrivate', {
playerId: $player.id,
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 77.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
makePublic: function (id) {
if (_resources[id]) {
_resources[id].madePublic = true
ss.rpc('game.npc.makeResponsePublic', {
playerId: $player.id,
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 77.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
while (x >= 0 && $game.$map.currentTiles[x][y].tileState === 0) {
targetPosition = { x: x, y: y }
x--
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 62.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
while (y >= 0 && $game.$map.currentTiles[x][y].tileState === 0) {
targetPosition = { x: x, y: y }
y--
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 62.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ((targetPosition.x === 0 ||
targetPosition.x === $game.VIEWPORT_WIDTH - 1 ||
targetPosition.y === 0 ||
targetPosition.y === $game.VIEWPORT_HEIGHT - 1) &&
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 61.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76