Skip to content

Commit

Permalink
fix damage system
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRevell committed Oct 7, 2013
1 parent 0b09e11 commit d95307c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion DialogViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface DialogViewController ()
@property (strong, nonatomic) MATrainer *user;
@property int step;
@property NSString *userName;
@property (strong, nonatomic) IBOutlet UIButton *next;

@end

Expand Down Expand Up @@ -61,8 +62,9 @@ - (void)viewDidAppear:(BOOL)animated
self.battleViewController.user = self.user;
}
else if (self.step == 4) {
self.next.hidden = true;
if (self.battleViewController.bm.trainer1.allPokemonDead) {
self.dialog.text = @"You've been defeated you, little bitch! Don't fuck with me again.";
self.dialog.text = @"You've been defeated, you little bitch! Don't fuck with me again.";
} else if (self.battleViewController.bm.trainer2.allPokemonDead){
self.dialog.text = @"Ah! How could you possibly defeat me???";
}
Expand Down Expand Up @@ -94,6 +96,7 @@ - (IBAction)next:(id)sender {
}
else if (self.step == 3) {
[self presentViewController:self.battleViewController animated:NO completion:nil];
self.dialog.text = @"";
self.step++;
}
}
Expand Down
1 change: 1 addition & 0 deletions DialogViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<connections>
<outlet property="computer" destination="QA2-b9-xHV" id="BxO-WU-5Ue"/>
<outlet property="dialog" destination="ide-q1-0lL" id="FPV-r6-aZn"/>
<outlet property="next" destination="b9r-Qy-HyY" id="J9W-Ru-ja5"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
Expand Down
1 change: 1 addition & 0 deletions Pokemon/BattleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
NSLog(@"balls %@", object);
// DEBUG: Why isn't this working?
self.user_pp.text = self.bm.trainer1.pokemon.pp_text;
self.computer_pp.text = self.bm.trainer2.pokemon.pp_text; // why i must do?
}
else if([keyPath isEqualToString:@"computer_pp"]) {
// DEBUG: Why isn't this working?
Expand Down
15 changes: 9 additions & 6 deletions Pokemon/MAPokemon.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ +(NSDictionary*)pokeTable {
@"special_attack": @65,
@"special_defense": @65,
@"speed": @45,
@"moves": @[[[MAPokemonMove alloc] initWithName:@"Tackle"], [[MAPokemonMove alloc] initWithName:@"Bubble"]]
@"moves": @[[[MAPokemonMove alloc] initWithName:@"Tackle"], [[MAPokemonMove alloc] initWithName:@"Leech Seed"]]
},
};

Expand All @@ -60,7 +60,7 @@ - (id)initWithType:(NSString *)type {
NSDictionary *pokes = [MAPokemon pokeTable];
NSDictionary *poke = [pokes objectForKey:type];

self.level = 1;
self.level = 10;
self.max_hp = [[poke objectForKey:@"hp"] intValue];
self.current_hp = [[poke objectForKey:@"hp"] intValue];
self.element = [poke objectForKey:@"type"];
Expand Down Expand Up @@ -96,14 +96,17 @@ -(NSString *)attackPokemon:(MAPokemon *)enemy WithMove:(int)move {
// compute modifier
double stab = [self.type isEqualToString:current_move.type] ? 1.5 : 1;
double type = 1;
double crit = 1;
double crit = ((arc4random() % 10) > 7) ? 2 : 1;
NSString *wasCrit = @"";
if (crit == 2) {
wasCrit = @"It was a critical attack!";
}
double r = (85 + arc4random() % 15) / 100.0f;
double mod = stab * type * crit * r;

NSLog(@"stab: %f, type: %f, crit: %f, r: %f, mod: %f", stab, type, crit, r, mod);

int damage = /*((2 * self.level + 10) / 250.0)
**/0.5 * (self.attack / (double)enemy.defense)
int damage = ((2 * self.level + 10) / 250.0) * (self.attack / (double)enemy.defense)
* current_move.power
+ 2;

Expand Down Expand Up @@ -136,7 +139,7 @@ -(NSString *)attackPokemon:(MAPokemon *)enemy WithMove:(int)move {
*/
[enemy getsHitWith:damage];

status = [NSString stringWithFormat:@"%@ attacks %@ with %@. %@ %@ takes %d damage", self.name, enemy.name, current_move.name, @"", enemy.name, damage ];
status = [NSString stringWithFormat:@"%@ attacks %@ with %@. %@ %@ takes %d damage", self.name, enemy.name, current_move.name, wasCrit, enemy.name, damage ];
//return current_move.power;
} else {
status = [NSString stringWithFormat:@"%@ did not have enough PP", self.name ];
Expand Down
11 changes: 9 additions & 2 deletions Pokemon/MAPokemonMove.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ +(NSDictionary*)moveTable {
@"pp": @1
},
@"Flamethrower": @{
@"type": @"Normal",
@"type": @"Fire",
@"category": @"Physical",
@"power": @40,
@"power": @70,
@"accuracy": @100,
@"pp": @3
},
Expand All @@ -45,6 +45,13 @@ +(NSDictionary*)moveTable {
@"accuracy": @100,
@"pp": @3
},
@"Leech Seed": @{
@"type": @"Leaf",
@"category": @"Special",
@"power": @20,
@"accuracy": @100,
@"pp": @3
},
};

return moves;
Expand Down

0 comments on commit d95307c

Please sign in to comment.