• NOW LIVE! Into the Woods--new character species, eerie monsters, and haunting villains to populate the woodlands of your D&D games.

[Petz] Battle Calculation/Rules

Morrus

Well, that was fun
Staff member
This is the routine which handles battles for those who were wondering about the specifics.

Code:
[font=Courier New][color=#0000bb]$op[/color][color=#007700]=[/color][color=#0000bb]$_GET[/color][color=#007700][[/color][color=#dd0000]'op'[/color][/font][font=Courier New][color=#007700]]; 
				if ([/color][color=#0000bb]$op[/color][/font][font=Courier New][color=#007700]) { 
					if ([/color][color=#0000bb]$player[/color][color=#007700]!=[/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700]) { 
						if ([/color][color=#0000bb]$op[/color][color=#007700]==[/color][color=#0000bb]1[/color][/font][font=Courier New][color=#007700]) { 
							if ([/color][color=#0000bb]$player[/color][color=#007700]==[/color][color=#0000bb]1[/color][/font][font=Courier New][color=#007700]) { 
								[/color][/font][font=Courier New][color=#ff8000]// Player1 Attacks 
								[/color][color=#007700]if ([/color][color=#0000bb]$battle[/color][color=#007700][[/color][color=#0000bb]TYPE[/color][color=#007700]]==[/color][color=#0000bb]1[/color][/font][font=Courier New][color=#007700]) { 
									[/color][/font][font=Courier New][color=#ff8000]// Do The Normal Attack 
									[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700]; 
									[/color][color=#0000bb]$cattack[/color][color=#007700]=[/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700]; 
									[/color][color=#0000bb]$counterd[/color][color=#007700]=[/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700]; 
									[/color][/font][font=Courier New][color=#ff8000]// Reworked In V2 
									[/color][color=#007700]if ([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]AGI[/color][color=#007700]]>[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]AGI[/color][/font][font=Courier New][color=#007700]]) { 
										if ([/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]1[/color][color=#007700], [/color][color=#0000bb]10[/color][color=#007700])<[/color][color=#0000bb]7[/color][/font][font=Courier New][color=#007700]) { 
											[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][/font][font=Courier New][color=#007700]]; 
										} else { 
											[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][color=#007700]]/[/color][color=#0000bb]2[/color][/font][font=Courier New][color=#007700]); 
										} 
									} else { 
										if ([/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]1[/color][color=#007700], [/color][color=#0000bb]10[/color][color=#007700])<[/color][color=#0000bb]7[/color][/font][font=Courier New][color=#007700]) { 
											[/color][color=#0000bb]$attack[/color][color=#007700]=([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700])-[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][/font][font=Courier New][color=#007700]]; 
										} else { 
											[/color][color=#0000bb]$attack[/color][color=#007700]=([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700])-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][color=#007700]]/[/color][color=#0000bb]3[/color][/font][font=Courier New][color=#007700]); 
										} 
									} 
									if ([/color][color=#0000bb]$attack[/color][color=#007700]<=[/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700]) { 
										[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]])-[/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][/font][font=Courier New][color=#007700]]); 
									} 
									[/color][/font][font=Courier New][color=#ff8000]// If We Can Do A Limit Brake Multiply Damage by 2 
									[/color][color=#007700]if ([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]pHP[/color][color=#007700]]<=[/color][color=#0000bb]10[/color][color=#007700]) { [/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$attack[/color][color=#007700]*[/color][color=#0000bb]2[/color][/font][font=Courier New][color=#007700]; } 
								} elseif ([/color][color=#0000bb]$battle[/color][color=#007700][[/color][color=#0000bb]TYPE[/color][color=#007700]]==[/color][color=#0000bb]3[/color][/font][font=Courier New][color=#007700]) { 
									[/color][/font][font=Courier New][color=#ff8000]// Do Attack Against Defence 
									[/color][color=#007700]if ([/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]1[/color][color=#007700], [/color][color=#0000bb]10[/color][color=#007700])>[/color][color=#0000bb]7[/color][/font][font=Courier New][color=#007700]) { 
										[/color][/font][font=Courier New][color=#ff8000]// You Lucky Guy 
										[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][color=#007700]]/[/color][color=#0000bb]2[/color][/font][font=Courier New][color=#007700]); 
									} else { 
										[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][/font][font=Courier New][color=#007700]]); 
									} 
								} elseif ([/color][color=#0000bb]$battle[/color][color=#007700][[/color][color=#0000bb]TYPE[/color][color=#007700]]==[/color][color=#0000bb]5[/color][/font][font=Courier New][color=#007700]) { 
									[/color][/font][font=Courier New][color=#ff8000]// You Are Fooked... Consider This... 
									[/color][color=#0000bb]$attack[/color][color=#007700]=([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]DEF[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700]))+([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]AGI[/color][color=#007700]]-([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]AGI[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700]))+ [/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]round[/color][color=#007700]([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]/[/color][color=#0000bb]5[/color][color=#007700], [/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700])); 
									[/color][/font][font=Courier New][color=#ff8000]// The Counter Attack 
									[/color][color=#007700]if ([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]HP[/color][color=#007700]]-[/color][color=#0000bb]$attack[/color][color=#007700]>=[/color][color=#0000bb]1[/color][/font][font=Courier New][color=#007700]) { 
										[/color][color=#0000bb]$cattack[/color][color=#007700]=([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]-([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]DEF[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700]))+([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]AGI[/color][color=#007700]]-([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]AGI[/color][color=#007700]]/[/color][color=#0000bb]2[/color][color=#007700]))+ [/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]round[/color][color=#007700]([/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]STR[/color][color=#007700]]/[/color][color=#0000bb]5[/color][color=#007700], [/color][color=#0000bb]0[/color][/font][font=Courier New][color=#007700])); 
										[/color][color=#0000bb]$counterd[/color][color=#007700]=[/color][color=#0000bb]1[/color][/font][font=Courier New][color=#007700]; 
									} 
								} elseif ([/color][color=#0000bb]$battle[/color][color=#007700][[/color][color=#0000bb]TYPE[/color][color=#007700]]==[/color][color=#0000bb]7[/color][/font][font=Courier New][color=#007700]) { 
									[/color][/font][font=Courier New][color=#ff8000]// do special! 
									[/color][color=#007700]if ([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]LVL[/color][color=#007700]]!=[/color][color=#0000bb]100[/color][/font][font=Courier New][color=#007700]) { 
										[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]HP[/color][color=#007700]]/[/color][color=#0000bb]100[/color][color=#007700]*[/color][color=#0000bb]rand[/color][color=#007700]([/color][color=#0000bb]$pet1[/color][color=#007700][[/color][color=#0000bb]LVL[/color][color=#007700]],[/color][color=#0000bb]99[/color][/font][font=Courier New][color=#007700]); 
									} else { 
										[/color][color=#0000bb]$attack[/color][color=#007700]=[/color][color=#0000bb]$pet2[/color][color=#007700][[/color][color=#0000bb]HP[/color][color=#007700]]/[/color][color=#0000bb]100[/color][color=#007700]*[/color][color=#0000bb]99[/color][/font][font=Courier New][color=#007700]; 
									} 
								} [/color][/font]
[font=Courier New][color=#007700]
[/color][/font]

It may take a bit of effort to translate that into English, though!
 
Last edited:

log in or register to remove this ad



The commenting for that sucks, but it doesn't look hard at all.

Do you think it might be possible to change the code for "money per post" to be a diminishing returns equation? What I mean is, do you think it would be possible to make the first post by a user per day worth (lets say 10) money, the second post worth (less than 10), down to the point where extra posts are only worth 1 money?

The reason why I would recommend this is so that Petz encourages posts, especially in the range of 1 to 10 a day, but not to the point where people are actually posting for the purpose of the mini-game.

Of course, my perception of a "possible" problem has not been proven at all, but I want to know what you think.
 

I'm attempting to play with the money for post routine at present, but having difficulty (learning as I go). This routine is specifically for the battle itself, though. I hoped it might provide some insight into how battles actually work. Also means that we could maybe modify it a bit if necessary.
 



I do not know php (which is what I assume this is...), but I'm re-writting this into common-speak. Heres the first half...

Here's the just of a round of combat... translated to psuedo-code.

If the battle type is 1, then the following happens:

Pet1 and Pet2s agilities are compared.

If Pet1s agility is greater than pet2, then 1d10 is rolled. If the result of 1d10 is less than 7, the attack is determined by Pet1s Strength minus Pet2s Defense. If the result of the roll was greater than seven, then the attack is determined by Pet1s Strength minus one-half of Pet2s defense.

If Pet1s agility is less than pet 2, then we roll a different 1d10. If the result of this roll us less than 7, then the attack is determined by one-half Pet1s strength minus Pet2s defense. If the result of the diceroll is 7 or more, the attack is determined by one-half Pet1s strength minus one-third of Pet2s defense.

After the attack is determined by one of the above two possibilities, the following happen.

If attack is less than or equal to 0, then attack is modified. A random number (from 0 to Pet1s strength) is rolled and then the program subtracts a different random number (from 0 to pet2s defense).

Now the code looks at what I think is Pet1s HP. If Pet1s HP is less than or equal to 10, the attack is doubled. This is called a limitbreak.



If the battle type is 3, then it acts like the first set of dicerolls from battle type 1 (in other words, agility isn't compared to determine what will happen, we just roll 1d10 and then compare pet stats).



If the battle type is 5, attack = (pet1s strength - one half pet2s defense) + (pet1s agility - one half pet2s agility) + (random number from 0 to pet1s strength divided by 5)

counterattack = (uses same formula as the attack)

counterattackd = 1 (I think this is used to show that you have counterattacked)



If the battle type is 7, we get a special attack.

If pet1s level doesn't equal 100, the attack equals [pet2s(hp) divided by 100] * a random number from the pets current level to 99.

If pet1s level is 100, then the attack deals 99% of pet2s hit points in damage.
 
Last edited:

Notes: ySTR = your pet's strength, oSTR = opposing pet's strength.
random(#) = a number between 0 and #. (Or possibly 1 and #)
random(#1,#2) = a number between #1 and #2.

NORMAL ATTACK:
If your pet's agility is greater than the other pet's agility:
• 60% => Damage = ySTR - oDEF
• 40% => Damage = ySTR - (oDEF/2)

otherwise:
• 60% => Damage = ySTR/2 - oDEF
• 40% => Damage = ySTR/2 - oDEF/3

If Attack is less or equal to 0 => Damage = random (ySTR) – random (oDEF)

If hit points under 10% => you deal Double Damage

ATTACK VS. DEFENCE:
• 20% => Damage = your STR less their DEF/2
• 80% => Damage = your STR less their DEF

COUNTER ATTACKS

Main attack: Damage = (ySTR – oDEF/2) +(yAGI-oAGI/2)+ random(ySTR/5)
Counter: (if you are still alive): Damage = (oSTR-yDEF/2) + (oAGI-yAGI/2)+random(oSTR/5)

SPECIAL ATTACKS

If you're not level 100: Damage = a random number (Level to 99) % times opposing hit points.

If you are level 100: Damage = 99% of their hit points.

Cheers!
 

Creamsteak said:
The reason why I would recommend this is so that Petz encourages posts, especially in the range of 1 to 10 a day, but not to the point where people are actually posting for the purpose of the mini-game.

Of course, my perception of a "possible" problem has not been proven at all, but I want to know what you think.

I wholeheartedly applaud such an idea. Pts per post straight up are maybe a little too encouraging for the game addicts that we are.
 

Into the Woods

Remove ads

Top