{"action":"closed","issue":{"url":"https://api.github.com/repos/Aatu/FieryVoid/issues/134","labels_url":"https://api.github.com/repos/Aatu/FieryVoid/issues/134/labels{/name}","comments_url":"https://api.github.com/repos/Aatu/FieryVoid/issues/134/comments","events_url":"https://api.github.com/repos/Aatu/FieryVoid/issues/134/events","html_url":"https://github.com/Aatu/FieryVoid/issues/134","id":122127984,"number":134,"title":"hitloc","user":{"login":"AncientSion","id":4209179,"avatar_url":"https://avatars.githubusercontent.com/u/4209179?v=3","gravatar_id":"","url":"https://api.github.com/users/AncientSion","html_url":"https://github.com/AncientSion","followers_url":"https://api.github.com/users/AncientSion/followers","following_url":"https://api.github.com/users/AncientSion/following{/other_user}","gists_url":"https://api.github.com/users/AncientSion/gists{/gist_id}","starred_url":"https://api.github.com/users/AncientSion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AncientSion/subscriptions","organizations_url":"https://api.github.com/users/AncientSion/orgs","repos_url":"https://api.github.com/users/AncientSion/repos","events_url":"https://api.github.com/users/AncientSion/events{/privacy}","received_events_url":"https://api.github.com/users/AncientSion/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-14T20:48:20Z","updated_at":"2015-12-20T20:57:22Z","closed_at":"2015-12-20T20:57:22Z","body":"need it here so i can read over it at work\r\n\r\n        public function getHitSystemByTable($pos, $shooter, $fire, $weapon, $location){\r\n            $system = null;\r\n            $name = false;\r\n            \r\n            if ($fire->calledid != -1)\r\n                $system = $this->getSystemById($fire->calledid);\r\n            \r\n            if ($system != null && !$system->isDestroyed())\r\n                return $system;\r\n        \r\n            if ($location === null)\r\n                $location = $this->getHitSection($pos, $shooter, $fire->turn, $weapon);\r\n\r\n\r\n            debug::log(\"checking if FLASH\");\r\n\r\n            $destroyedThisTurn = false;\r\n\r\n            if ($weapon->flashDamage){\r\n                debug::log(\"is FLASH\");\r\n                debug::log(\"check if a system on target location was destroyed this turn\");\r\n                foreach ($this->systems as $system){\r\n                    if ($system->isDestroyed() && $system->location == $location){\r\n                        foreach ($system->damage as $damage){\r\n                            if ($damage->turn == $fire->turn){\r\n                                $destroyedThisTurn = true;\r\n                                break;\r\n                            }\r\n                        }\r\n                    }\r\n                    if ($destroyedThisTurn){\r\n                        break;\r\n                    }\r\n                }\r\n            }\r\n\r\n\r\n            if ($destroyedThisTurn){\r\n                debug::log(\"one destroyed this turn!\");\r\n            }\r\n            else {\r\n                debug::log(\"nope\");\r\n            }\r\n\r\n            debug::log(\"begin normal roll on hitchart routine\");\r\n\r\n            $hitChart = $this->hitChart[$location];\r\n            $roll = mt_rand(1, 20);\r\n\r\n            if (isset($this->hitChart[$location][$roll])){\r\n                $name = $this->hitChart[$location][$roll];\r\n            }\r\n            else {\r\n                while (!$name){\r\n                    $roll++;\r\n                    if (isset($hitChart[$roll])){\r\n                        $name = $hitChart[$roll];\r\n                    }\r\n                }\r\n            }\r\n\r\n            debug::log(\"roll: \".$roll.\" on loc: \".$location.\"__name: \".$name);\r\n\r\n            if ($name == \"Primary\"){\r\n                if ($weapon->flashDamage){\r\n                    debug::log(\"primary and flash, START ANEW\");\r\n                    return $this->getHitSystem($pos, $shooter, $fire, $weapon, null);\r\n                }\r\n                else {\r\n                    $name = false;\r\n                    $location = 0;\r\n                    $roll = mt_rand(1, 20);\r\n                    debug::log(\"redirecting to PRIMARY ___ NEW roll: \".$roll.\" on loc: \".$location);\r\n                }\r\n            }\r\n\r\n            if (isset($this->hitChart[$location][$roll])){\r\n                    $name = $this->hitChart[$location][$roll];\r\n            }\r\n            else {\r\n                while (!$name){\r\n                    $roll++;\r\n                    if (isset($this->hitChart[$location][$roll])){\r\n                        $name = $this->hitChart[$location][$roll];\r\n                    }\r\n                }\r\n            }\r\n\r\n            debug::log(\"hitLoc: \".$location.\", hitting: \".$name);\r\n\r\n            $systems = array();\r\n\r\n            if ($weapon->flashDamage){\r\n                debug::log(\"FLASH type, gathering all from location\");\r\n                foreach ($this->systems as $system){\r\n                    if ($system->location == $location && !$system->isDestroyed() && !$system instanceof Structure){\r\n                        $systems[] = $system;\r\n                    }\r\n                }\r\n            }\r\n            else {\r\n                debug::log(\"NO FLASH, gathering by location and name\");\r\n                foreach ($this->systems as $system){\r\n                    if ($system->location == $location){\r\n                        if ($system->displayName == $name){\r\n                            $systems[] = $system;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n\r\n            // if you have more than 0 systems if you elligable array\r\n            if (sizeof($systems) > 0){\r\n                debug::log(\"more than one valid sys\");\r\n                $roll = mt_rand(1, sizeof($systems));\r\n                $system = $systems[$roll-1];\r\n                debug::log(\"target systems: \".sizeof($systems).\", rolled: \".$roll.\", hitting: \".$system->displayName);\r\n                if (!$system->isDestroyed()){\r\n                    debug::log(\"sys is not destroyed, return it!\");\r\n                    return $system;\r\n                }\r\n                else {\r\n                    debug::log(\"sys is destroyed, try getUndamagedSameSystem!\");\r\n                    $newSystem = $this->getUndamagedSameSystem($system, $location);\r\n\r\n                    if ($newSystem){                        \r\n                    debug::log(\"got one, return it\");\r\n                        return $newSystem;\r\n                    }\r\n                    else {\r\n                        if ($weapon->flashDamage){\r\n                            debug::log(\"got no same name system and im flash, getHitSystem anew\");\r\n                            return $this->getHitSystem($pos, $shooter, $fire, $weapon, $location);\r\n                        }\r\n                        else {\r\n                            debug::log(\"not flash, got no same name system, get structure \".$location);\r\n                            $system = $this->getStructureSystem($location);\r\n                            // this is no MCV, so check for outer structure being ded\r\n                            if ($system->isDestroyed()){\r\n                                debug::log(\"target sys is destroyed, getting overkill to structure 0\");\r\n                                return $this->getStructureSystem(0);\r\n                            }\r\n                            else {\r\n                                debug::log(\"its alive, return it\");\r\n                                return $system;\r\n                            }\r\n                        }   \r\n                    }\r\n                }\r\n            }\r\n\r\n            // if you have no elligibe systems in your array\r\n            else {\r\n                debug::log(\"size of stems = 0 no valid target systems -- TYPO or section down ??\");\r\n\r\n                if ($weapon->flashDamage){\r\n                    debug::log(\"flash type\");\r\n\r\n                    debug::log(\"checking for outer structure\");\r\n                    $system = $this->getStructureSystem($location);\r\n\r\n                    if ($system->isDestroyed()){\r\n                    debug::log(\"but its destroyed, returning any primary system\");\r\n                        return $this->getHitSystem($pos, $shooter, $fire, $weapon, 0);\r\n                    }\r\n                    else {\r\n                    debug::log(\"outer structure is alive, returning it\");\r\n                        return $system;\r\n                    }\r\n                }\r\n                else if ($destroyedThisTurn){\r\n                    debug::log(\"non flash, destroyed something earlier on this target loc, overkill into struct 0\");\r\n                    $structure = $this->getStructureSystem(0);\r\n\r\n                    if ($structure->isDestroyed()){\r\n                        debug::log(\"structure destroyed - return null\");\r\n                        return null;\r\n                    }\r\n                    else {\r\n                        debug::log(\"structure intact, return it\");\r\n                        return $structure;\r\n                    }\r\n                }\r\n                else {\r\n                    debug::log(\"LAST ELSE, cant resolve shit\");\r\n                }\r\n            }\r\n        }"}}