Jump to content
Existing user? Sign In

Sign In



Sign Up

PI - How to give items a category/type attack bonus such as Dragon/Demonbane


Tutus Frutus

Recommended Posts

  • 3 weeks later...
  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 months later...
  • 2 weeks later...
  • 2 weeks later...
  • 3 months later...
  • 1 month later...

Assuming your source is compatable with Java 13 you could use enhanced Switch as shown below and if your using java 17 LTS you could move to using Switch Expressions they are very beautiful even more so if you are using Arrays with named types.

Fun fact for anyone that is Beginner to Intermediate with the Java Programming Language did you know that Switch Cases are typically faster once compiled into byte code assuming you are using java conventions and using a modern JVM similar to Java 17.

Just using one or two if statements will be faster than using Switch or Switch Expressions but if you look at  most Server Applications they are riddled with if statements paired with ugly outdated and depressingly complex for a simple task.

 

Meet Easier

	public boolean isDemon() {
			switch (Defender.npcType) {
				case 1531, 3134, 2006, 2026, 7244, 1432, 415, 7410, 135, 3133, 484, 1619, 7276, 3138, 7397, 7398, 11, 22978 -> { //Dragon Hunter Lance
					if (attacker.lastWeaponUsed == 22978 && defender.isDragon()) {
						damage *= 1.2;
						accuracy *= 1.2;
					}
				}
			}

 

 

The First Part

		public boolean isDemon() {

			return switch (npcType) {
				case 1531, 3134, 2006, 2026, 7244, 1432, 415, 7410, 135, 3133, 484, 1619, 7276, 3138, 7397, 7398, 11 ->
						true;
				default -> false;
			};

		}

This assumes you have added anything useful yet here is the first switch statement

			switch (Defender.npcType) {

				case 1531:

				case 3134:

				case 2006:

				case 2026:

				case 7244:

				case 1432:

				case 415:

				case 7410:

				case 135:

				case 3133:

				case 484:

				case 1619:

				case 7276:

				case 3138:

				case 7397:

				case 7398:

				case 11:
				case 2978: { //Dragon Hunter Lance
							if (attacker.lastWeaponUsed == 22978 && defender.isDragon()) {
								damage *= 1.2;
								accuracy *= 1.2;
							}
						}

					return true;

			}

			return false;

		}

yes this works just fine but its freaking ugly also not using break; or return; on each case also slows down the byte code optimizations as it skips and moves threw each case.

 

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



Contact

[email protected]

astra.security

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

Runewild Ikov RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex in any way & exists solely for educational purposes.

×
×
  • Create New...