5 Replies - 950 Views - Last Post: 16 July 2011 - 12:35 AM Rate Topic: -----

#1 bjmoreton   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-July 11

Attack Formula help

Posted 14 July 2011 - 07:45 PM

Hello, I am new to these forums and I am currently working on a Web-based game based around Dragonball Z. Yes I know DBZ is old but I love it and so do a lot of others. I have a few friends that are going to help me with the questing,maping and whatnot of the game but none are programmers so they can't help with this part. They all think my attack system is alright but I think it could use some work... Here is what I have so far this is written in PHP,HTML,MySQL and Javascript(Ajax).

/*
The HitChance has a max of +20(at 100 dex) same with AvoidChance
The DamageMod(DMGMod) has a 5times max multiplier at 100 strength
The CriticalBonus has a 40 max at 100 dex so a CritChance of 50 or higher(half the time)
The CriticalRBonus has at the moment just a 0.05 chance increase(Just Saiyan race is added)
*/	
		Public Function CalcATK($Offense, $OType, $Defense, $DType, $Skill){
			$OffStats = $this->GetStats($Offense, $OType); //Grab the Offenses Stats
			$DefStats = $this->Getstats($Defense, $DType); //Grab the Defenses Stats
            $OffRStats = $this->GetRacialBonus($OffStats->Race); //Grab the Offenses Racial Bonuses
            $DefRStats = $this->GetRacialBonus($DefStats->Race); //Grab the Defenses Racial Bonuses

			if($Skill == "None"){
				if($OffStats->Powerlevel >= $DefStats->Powerlevel){ //Offense is stronger or Equal to Defense
					$PLDiff = $OffStats->Powerlevel - $DefStats->Powerlevel; //Find the PL Difference
                    $HitChance = rand(0, ($OffStats->DEX + ($OffStats->DEX * 0.2) + ($PLDiff * 0.001))); //Get a random number between 0 and the OffenseDex + (OffenseDex * 0.14) + (PowerlevelDiff * 0.001)
                    $AvoidChance = rand(0, (($DefStats->DEX + ($DefStats->DEX * 0.2)) - ($PLDiff * 0.001))); //Get a random number between 0 and the DefenseDex + (DefenseDex * 0.14) - (PowerlevelDiff * 0.001)
                    
                    if($HitChance > $AvoidChance){$ChanceToHit = 1;} //If HitChance is greater than AvoidChance then it's a hit
                    if($AvoidChance > $HitChance){$ChanceToHit = 0;} //If AvoidCHance is greater than HitChance then it's a miss
				} else { //Offense is Weaker than Defense
					$PLDiff = $DefStats->Powerlevel - $OffStats->Powerlevel; //Find the PL Difference
                    $HitChance = rand(0, (($OffStats->DEX + ($OffStats->DEX * 0.2)) - ($PLDiff * 0.001))); //Get a random number between 0 and the OffenseDex + (OffenseDex * 0.14) - (PowerlevelDiff * 0.001)
                    $AvoidChance = rand(0, ($DefStats->DEX + ($DefStats->DEX * 0.2) + ($PLDiff * 0.001))); //Get a random number between 0 and the DefenseDex + (OffenseDex * 0.14) + (PowerlevelDiff * 0.001)
                    
                    if($HitChance > $AvoidChance){$ChanceToHit = 1;} //If HitChance is greater than AvoidChance then it's a hit
                    if($AvoidChance > $HitChance){$ChanceToHit = 0;} //If AvoidCHance is greater than HitChance then it's a miss
				}

				if($ChanceToHit > 0){ //ChanceToHit greater than 0 so its a hit
				    $DMGMod = ($OffStats->STR * 0.1); //Get the Offense Damage Modifier
                    $WeaponDMG = rand(1, 5); //Weapon Damage(Until weapons are added I used 1 to 5)
                    $DMG = round(($WeaponDMG * $DMGMod) + $WeaponDMG); //Get the total damage
                    $CritChance = rand(1, 100); //The Critical chance of 1 to 100
                    $CritBonus = $OffStats->DEX * 0.4; //The Offense Critical Hit Bonus
                    $CritRBonus = 100 * $OffRStats->CritChance; //Get the Racial Crit Bonus
                    if($CritChance >= (90 - $CritBonus - $CritRBonus)){$DMG = $DMG * 2;$Crit=" - CRIT";} //If CritChance is greter than (90 - CritBonus - CritRBonus), then it's a critical hit. Double DMG
                    
                    return $DMG.$Crit; //Return the DMG to the game
				} else { //ChanceToHit was 0 so its a miss
                    return "Missed"; //Return Miss to the game
				}
			} else {
				/*
					Process Skill Data - Still working on Melee will do skills after it's finsihed.
				*/
			}
		}



DBZ Game there is the link to see this in action. Right now each player has 1000pl, 5 dex and 5 strength. I just don't think the way I am doing this is the best way. If anyone has any thoughts or criticism on my code that would be greatly appreciated. I want to make this better.

Is This A Good Question/Topic? 0
  • +

Replies To: Attack Formula help

#2 anonymous26   User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Attack Formula help

Posted 15 July 2011 - 01:04 AM

Are you using this same code for both the player and NPCs?
Was This Post Helpful? 0
  • +
  • -

#3 bjmoreton   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-July 11

Re: Attack Formula help

Posted 15 July 2011 - 08:11 AM

View PostButchDean, on 15 July 2011 - 01:04 AM, said:

Are you using this same code for both the player and NPCs?


Yes I am using the same code for both. I just recall the CalcATK function using the Defense(NPC Enemy at the moment) stats.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26   User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Attack Formula help

Posted 15 July 2011 - 02:26 PM

Problem here is that the overall logic is pretty simple, so you will need to be more specific as to what you feel your goals are for improvement.
Was This Post Helpful? 0
  • +
  • -

#5 bjmoreton   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-July 11

Re: Attack Formula help

Posted 15 July 2011 - 10:19 PM

My goals are at the moment to get a stable battle system together that makes sense and does what it needs to do. I don't want it throwing out random numbers and then someone saying the system is unfair,bad,etc. I would eventually like to addin something like World of Warcrafts Attack power from strength and agility(in my case this would be Dexterity). I don't want it to be to simple but I don't want it to be over complicated either. I am also going to be adding in Armor Bonuses,Armor Piercing rates,hopefully a better critical hit system and everything. But for now this is the basic concept that I came up with and now I am building on it. What I am looking for is just overall ideas on ways this system could turn out how I want it to.
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26   User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Attack Formula help

Posted 16 July 2011 - 12:35 AM

Well, as you can see not many replies have popped up because you are looking for a game design brainstorming session, and here we have load of programmers! So unless you find a bunch of designers you're pretty much on your own.

One thing I will say though is that no-one's game escapes criticism, so don't worry too much about it. The best you can do is to implement several ideas or tweaks to the code you have above and get people to give you specific feedback not only on what they felt was wrong with the game but also what was right. Questions to ask for example would be:

1. Was the game an enjoyable experience that you feel held your attention for a long period of time?

2. Was the game too easy or difficult overall?

3. What do you feel was wrong with the game?

4. What do you feel was right with the game?

As said, it is very important to also find out what people generally liked about the game so that those likable features can be enhanced. Why do you think there are so many sequels to the most successful games on the market that often appear improved? Because the design and/or production teams looked at sales and reviews, collated relevant information for both the good and bad feedback, and tweaked the next iteration of the game accordingly; people like nice graphics so they improve the graphics, people like realistic AI so they tweak that to make it more interactive, etc.

I've gone off on a bit of a tangent but hopefully it has clarified in your mind how to go about improving the AI for your game. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1