{"action":"created","issue":{"url":"https://api.github.com/repos/magarena/magarena/issues/494","labels_url":"https://api.github.com/repos/magarena/magarena/issues/494/labels{/name}","comments_url":"https://api.github.com/repos/magarena/magarena/issues/494/comments","events_url":"https://api.github.com/repos/magarena/magarena/issues/494/events","html_url":"https://github.com/magarena/magarena/issues/494","id":116001452,"number":494,"title":"DestroyAction(p.getEquippedCreature()) crashes if p is not equipped","user":{"login":"melvinzhang","id":1620634,"avatar_url":"https://avatars.githubusercontent.com/u/1620634?v=3","gravatar_id":"","url":"https://api.github.com/users/melvinzhang","html_url":"https://github.com/melvinzhang","followers_url":"https://api.github.com/users/melvinzhang/followers","following_url":"https://api.github.com/users/melvinzhang/following{/other_user}","gists_url":"https://api.github.com/users/melvinzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/melvinzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melvinzhang/subscriptions","organizations_url":"https://api.github.com/users/melvinzhang/orgs","repos_url":"https://api.github.com/users/melvinzhang/repos","events_url":"https://api.github.com/users/melvinzhang/events{/privacy}","received_events_url":"https://api.github.com/users/melvinzhang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-10T00:47:21Z","updated_at":"2015-11-10T05:49:50Z","closed_at":null,"body":"```\r\nCaused by: magic.exception.GameException: java.lang.ArrayIndexOutOfBoundsException: -1\r\n\tat magic.model.MagicGame.doAction(MagicGame.java:554)\r\n\tat Dead_Iron_Sledge$1.executeEvent(Dead_Iron_Sledge.groovy:22)\r\n\tat magic.model.event.MagicEvent.executeEvent(MagicEvent.java:659)\r\n\tat magic.model.MagicGame.executeEvent(MagicGame.java:763)\r\n\tat magic.model.stack.MagicItemOnStack.resolve(MagicItemOnStack.java:127)\r\n\tat magic.model.action.StackResolveAction.doAction(StackResolveAction.java:13)\r\n\tat magic.model.MagicGame.doAction(MagicGame.java:552)\r\n\t... 6 more\r\nCaused by: java.lang.ArrayIndexOutOfBoundsException: -1\r\n\tat magic.model.MagicLogMessageBuilder.appendMessage(MagicLogMessageBuilder.java:19)\r\n\tat magic.model.MagicGame.logAppendMessage(MagicGame.java:688)\r\n\tat magic.model.action.DestroyAction.doAction(DestroyAction.java:78)\r\n\tat magic.model.MagicGame.doAction(MagicGame.java:552)\r\n\t... 12 more\r\n```\r\n\r\ngetEquppedCreature may return MagicPernanent.NONE, calling DestroyAction on NONE crashes."},"comment":{"url":"https://api.github.com/repos/magarena/magarena/issues/comments/155302341","html_url":"https://github.com/magarena/magarena/issues/494#issuecomment-155302341","issue_url":"https://api.github.com/repos/magarena/magarena/issues/494","id":155302341,"user":{"login":"melvinzhang","id":1620634,"avatar_url":"https://avatars.githubusercontent.com/u/1620634?v=3","gravatar_id":"","url":"https://api.github.com/users/melvinzhang","html_url":"https://github.com/melvinzhang","followers_url":"https://api.github.com/users/melvinzhang/followers","following_url":"https://api.github.com/users/melvinzhang/following{/other_user}","gists_url":"https://api.github.com/users/melvinzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/melvinzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melvinzhang/subscriptions","organizations_url":"https://api.github.com/users/melvinzhang/orgs","repos_url":"https://api.github.com/users/melvinzhang/repos","events_url":"https://api.github.com/users/melvinzhang/events{/privacy}","received_events_url":"https://api.github.com/users/melvinzhang/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T05:49:49Z","updated_at":"2015-11-10T05:49:49Z","body":"In the case of Dead Iron Sledge (where this exception occurred), I think the problem is referring to equipped creature in executeEvent as event.getPermanent().getEquippedCreature(), it should not be the equipped creature when the effect resolves, rather it should be the equipped creature at the point when the trigger occurs. \r\n\r\nCause it is possible to have the trigger occur and then re-equipped Dead Iron Sledge on a different permanent and when the trigger resolves it should not destroy the currently equipped creature but the previous one.\r\n\r\nThe correct fix in this case is to construct a MagicPermanentList with the target and equipped creature as elements as pass that as the ref in the MagicEvent and invoke destory as new DestroyAction(event.getRefPermanentList())"}}