Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
bots now leave they're party after a pq (follower bots ignore the leave party mode), this fixes a bug where subsequent pqs would fail to start due to the party being invalid. also fixed a bug which caused characters to equip weapons which were not appropriate for their job at second job.
  • Loading branch information
pimittens committed Jun 20, 2024
1 parent 5b1d54e commit 9cefbcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
33 changes: 24 additions & 9 deletions src/main/java/client/CharacterBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import constants.skills.*;
import net.PacketProcessor;
import net.server.channel.handlers.AbstractDealDamageHandler;
import net.server.world.Party;
import org.w3c.dom.ranges.Range;
import server.ItemInformationProvider;
import server.StatEffect;
Expand All @@ -34,6 +35,7 @@ public enum Mode {
GRINDING, // pick a map and kill monsters
MANAGE_INVENTORY, // check if any equips are better than what they're using and sell lowest value items to make space
PQ, // do a pq
LEAVE_PARTY, // leave party after pq
BOSSING // fight a boss

}
Expand Down Expand Up @@ -228,6 +230,7 @@ public void update() {
createInventorySpace();
chooseMode();
}
case LEAVE_PARTY -> leaveParty();
case WAITING -> chooseMode();
case GRINDING -> grind(time);
case PQ -> doPQ(time);
Expand Down Expand Up @@ -276,7 +279,7 @@ public void followerUpdate() {
createInventorySpace();
chooseMode();
}
case WAITING -> currentMode = Mode.GRINDING;
case WAITING, LEAVE_PARTY -> currentMode = Mode.GRINDING; // followers don't need to do these
case GRINDING -> grind(time);
case PQ -> doPQ(time);
}
Expand Down Expand Up @@ -1163,22 +1166,34 @@ private static float calculateHitchance(int leveldelta, float playerAccuracy, in
}*/ // this formula appears to be incorrect, due to the negative first term of the quadratic it often gives a negative accuracy

private void chooseMode() {
currentModeStartTime = System.currentTimeMillis();
if (!currentMode.equals(Mode.MANAGE_INVENTORY)) { // manage inventory between modes
currentMode = Mode.MANAGE_INVENTORY;
// todo: go to henesys or fm
return;
}
currentModeStartTime = System.currentTimeMillis();
if (getPlayer().getJob().equals(Job.BEGINNER)) {
currentMode = Mode.GRINDING;
pickMap();
return;
}
// todo: pick mode randomly, maybe have a pq manager task that creates a party if enough bots are waiting for a pq
// todo: pick mode randomly
currentMode = Mode.GRINDING;
pickMap();
}

public void leaveParty() {
Party party = getPlayer().getParty();
if (party != null) {
List<Character> partymembers = getPlayer().getPartyMembersOnline();

Party.leaveParty(party, c);
getPlayer().updatePartySearchAvailability(true);
getPlayer().partyOperationUpdate(party, partymembers);
}
currentMode = Mode.WAITING;
}

private void pickMap() {
if (getPlayer().getLevel() < 6) {
changeMap(c.getChannelServer().getMapFactory().getMap(lv1to5Maps[Randomizer.nextInt(lv1to5Maps.length)]));
Expand Down Expand Up @@ -1814,13 +1829,13 @@ private boolean jobAppropriateEquip(int itemId) {

private boolean isJobAppropriateWeapon(int itemId) {
if (getPlayer().getJob().getId() / 100 == 1) {
if (getPlayer().getJob().getId() % 10 == 1) {
if (getPlayer().getJob().getId() % 100 / 10 == 1) {
return ItemConstants.is1hSword(itemId) || ItemConstants.is2hSword(itemId);
}
if (getPlayer().getJob().getId() % 10 == 2) {
if (getPlayer().getJob().getId() % 100 / 10 == 2) {
return ItemConstants.is1hBluntWeapon(itemId) || ItemConstants.is2hBluntWeapon(itemId);
}
if (getPlayer().getJob().getId() % 10 == 3) {
if (getPlayer().getJob().getId() % 100 / 10 == 3) {
return ItemConstants.isSpear(itemId);
}
return ItemConstants.is1hSword(itemId) || ItemConstants.is2hSword(itemId) || ItemConstants.is1hAxe(itemId) ||
Expand All @@ -1831,13 +1846,13 @@ private boolean isJobAppropriateWeapon(int itemId) {
return ItemConstants.isWand(itemId) || ItemConstants.isStaff(itemId);
}
if (getPlayer().getJob().getId() / 100 == 3) {
if (getPlayer().getJob().getId() % 10 == 2) {
if (getPlayer().getJob().getId() % 100 / 10 == 2) {
return ItemConstants.isCrossbow(itemId);
}
return ItemConstants.isBow(itemId);
}
if (getPlayer().getJob().getId() / 100 == 4) {
if (getPlayer().getJob().getId() % 10 == 2) {
if (getPlayer().getJob().getId() % 100 / 10 == 2) {
return ItemConstants.isDagger(itemId);
}
return ItemConstants.isClaw(itemId);
Expand Down Expand Up @@ -2335,7 +2350,7 @@ private void kpqStage5(int time) {
if (getPlayer().getPosition().x == 378 && getPlayer().getPosition().y == -2760) {
getPlayer().getEventInstance().giveEventReward(getPlayer()); // if they don't have space too bad
changeMap(c.getChannelServer().getMapFactory().getMap(103000000)); // go back to kerning instead of bonus stage
currentMode = Mode.WAITING;
currentMode = Mode.LEAVE_PARTY;
} else {
moveBot((short) 378, (short) -2760, time);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/server/task/UpdateBotsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class UpdateBotsTask implements Runnable {

@Override
public void run() {
long startTime = System.currentTimeMillis();
//long startTime = System.currentTimeMillis();
Server.getInstance().getBotManager().updateBots();
System.out.println("update bots completed in " + (System.currentTimeMillis() - startTime) + " ms");
//System.out.println("update bots completed in " + (System.currentTimeMillis() - startTime) + " ms");
}
}

0 comments on commit 9cefbcb

Please sign in to comment.