First+Bug

The Bug
The bug we have chosen is the "scan damage" bug.

Reported by: knightmearh Priority: major Component: MAFH Version: 3.0+

When the player reaches an enemy in the Fortune Hunter game, they are provided with four buttons; Attack, Special, Magic, and Scan. The scan button should display the enemy's weakness and the number of hit points the enemy has left. We looked up the "def" of enemyScan in the source code and it seems to be correct. However, when the player uses the scan button, it does not do any of the functions that scan should. Also, the scan button attacks the enemy, which it should not. We think that when the user presses the scan button, it doesn't call the scan function, but the attack. We need to go through the code and find where the user interacts with the scan button and see what is actually called when that occurs. We have already found a few places where the scan button is being used as well as "scan descriptions,", but we can't seem to find what the problem is. Hopefully we will be able to find the source of the problem and make a contribution to Fortune Hunter.

The only possible solution found so far is that there could be an issue with the variable **player_input**. When 'scan' is chosen in the game, the message that comes up is "You attack for 10 damage". When searching the project folders, it came to our attention that player_input is what's setting all the messages for each of the menu options. It's hard to tell right now whether this is what's causing the bug, but it's the biggest candidate at the moment.

As for the project as a whole, our group has been able to successfully checkout the source code from the Fortune Hunter repository and run the game. We were also able to create a Netbeans project and loaded in the source code so that we can browse through the files and search for certain things. This will be useful for when we have found what is causing the bug. We will fix it in the source code and then run the game to see if we have corrected the issue.

A Possible Fix
After searching through the code, we found a possible fix in editing the MAFH2/BattleEngine.py file. Line 145 is the start of what to do if "scan" is selected in the battle menu. Commenting out the previous **self.attack_phase(menu) ** stops the scan function from dealing damage to the selected enemy, and shows the appropriate "Enemy Scanned!" message in the menu display, which was one step closer to fixing the problem. However, the HP and weakness of the enemy still failed to show up anywhere. Since the menu display already has a message, this should mean the status of the enemy is returned in the message window at the bottom of the screen (cut off on most testing resolutions). By studying the gameplay and the rest of the code, we could see the methods used to get text into the message window using **self.game_engine.get_object('mesg').add_line("") ****﻿**. Specifying the current target is a problem though. The **attack_phase(menu)** code that was previously called shows how those methods specify enemies to attack, and can be reused to get information about the enemy for scanning. While this may not have been the best solution, we modified code directly under the scan selection section as follows:

(starting at line 145)

elif selection == 'scan': >> menu.set_disp('Enemy Scanned!') >> self.isMagic = False >> #curTarget is the selected enemy >> curTarget = self.active_target - 1 >> #next two lines write enemy's HP & weakness to message window >> self.game_engine.get_object('mesg').add_line(_("Remaining HP: "+repr(self.enemy_list[curTarget].HP))) >> self.game_engine.get_object('mesg').add_line(_("Enemy Weakness: "+repr(self.enemy_list[curTarget].weakness))) >> #following removed, enemy no longer attacked >> #self.__attack_phase(menu)

<span style="font-family: Arial,Helvetica,sans-serif;">﻿curTarget gives the index of the currently selected enemy and is used in the enemy_list array, which is initialized with the start of the BattleEngine code. Each enemy object in the array has HP and weakness attributes and we send these to the message window at the bottom of the screen when the "scan" option is selected, as they should be.

<span style="font-family: Arial,Helvetica,sans-serif;">This has been tested to work correctly after attacks and even when switching between enemies in a battle. <span style="font-family: Arial,Helvetica,sans-serif;">(Note: Easy way to get through maze to testable enemies: Up, Up, Left, Up: Oh No, Dragons!)

After group discussion and collaboration, we will decide if this is the best possible coding and then upload our fix to the developers.

<span style="color: #800000; font-family: Impact,Charcoal,sans-serif; font-size: 210%; line-height: 27px;">Committing the Fix
We spoke with Jon Meschino about our fix for the "scan damage" bug. He told us to look at a tutorial for GIT so that we can commit our fix in the code back to the repository. We uploaded the code using git and added comments to the log: <span style="font-family: 'Courier New',Courier,monospace; font-size: 90%;">git add MAFH2/BattleEngine.py <span style="font-family: 'Courier New',Courier,monospace; font-size: 90%;">git commit Jon added Jaime and Brittany as committers so we could push the code to the sugarlabs repository: <span style="font-family: 'Courier New',Courier,monospace; font-size: 90%;">git push gitorious@git.sugarlabs.org:project-xavier/mainline.git master Our progress is now updated on their page. We also went ahead to the ticket list and changed the bug we chose to fixed. This removed it from the active ticket list (was ticket #60). You can view all tickets, including the closed ones, on this page.

We also asked Jon what he thought we should do for our next contribution. Since the bug tracker also lists tasks and enhancements, he suggested that we look at the list sorted by milestone. He said that if all the items for the milestone are completed, they are able to release a new copy of the code and commit it to the Sugar Labs repository. This allows other people in the Sugar community to view the progress of Fortune Hunter.