Skip to content

Commit

Permalink
add proper is not comsume throwing star logic, add handling (logic & …
Browse files Browse the repository at this point in the history
…packet) of potentials, need to handle reveal potentials and recalc logic
  • Loading branch information
doriyan13 committed Mar 17, 2024
1 parent 775af7f commit 6eba72c
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public void decode(AttackType type, InPacket inPacket) {
this.bulletPos = inPacket.decodeShort();
short pnCashItemPos = inPacket.decodeShort();
byte nShootRange0a = inPacket.decodeByte();
//TODO: need to hook all the skills and handle this - | need to handle it properly!!
// is_shoot_skill_not_consuming_bullit -> Line 2331 | 0x006EEAF0
if (true /*is_shoot_skill_not_consuming_bullet(skillId)*/) {
if (SkillUtils.isShootSkillNotConsumingBullet(skillId)) {
int pnItemID = inPacket.decodeInt();
System.out.println("pnItemID - " + pnItemID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
import com.dori.SpringStory.connection.packet.packets.CWvsContext;
import com.dori.SpringStory.dataHandlers.ItemDataHandler;
import com.dori.SpringStory.dataHandlers.dataEntities.ItemData;
import com.dori.SpringStory.enums.EquipBaseStat;
import com.dori.SpringStory.enums.InventoryType;
import com.dori.SpringStory.enums.ScrollStat;
import com.dori.SpringStory.enums.*;
import com.dori.SpringStory.inventory.Equip;
import com.dori.SpringStory.inventory.Item;
import com.dori.SpringStory.logger.Logger;
import com.dori.SpringStory.utils.ItemUtils;

import java.util.Map;

import static com.dori.SpringStory.connection.packet.headers.InHeader.UserHyperUpgradeItemUseRequest;
import static com.dori.SpringStory.connection.packet.headers.InHeader.UserUpgradeItemUseRequest;
import static com.dori.SpringStory.connection.packet.headers.InHeader.*;
import static com.dori.SpringStory.constants.GameConstants.*;
import static com.dori.SpringStory.enums.InventoryOperation.Add;
import static com.dori.SpringStory.enums.InventoryType.EQUIP;
Expand Down Expand Up @@ -119,9 +116,64 @@ public static void handleUserHyperUpgradeItemUseRequest(MapleClient c,
ItemUtils.applyEnchantment(equip);
// Update the equip for the client -
chr.write(CWvsContext.inventoryOperation(true, Add, (short) (equip.getInvType() == EQUIPPED ? -equip.getBagIndex() : equip.getBagIndex()), (short) 0, equip));
chr.write(CUser.showItemHyperUpgradeEffect(chr.getId(), true, enchantSkill, 0));
} else {
ItemUtils.applyEnchantmentBoom(chr, equip, scroll, enchantSkill);
}
chr.write(CUser.showItemHyperUpgradeEffect(chr.getId(), success, enchantSkill, 0));
}


@Handler(op = UserItemOptionUpgradeItemUseRequest)
public static void handleUserItemOptionUpgradeItemUseRequest(MapleClient c,
InPacket inPacket) {
MapleChar chr = c.getChr();

inPacket.decodeInt(); // update time
short useItemPos = inPacket.decodeShort(); //Use Position
short equipPos = inPacket.decodeShort(); //Eqp Position
boolean enchantSkill = inPacket.decodeBool();

Item scroll = chr.getInventoryByType(InventoryType.CONSUME).getItemByIndex(useItemPos);
InventoryType invType = equipPos < 0 ? EQUIPPED : EQUIP;
Equip equip = (Equip) chr.getInventoryByType(invType).getItemByIndex(equipPos);
if (!ItemUtils.isScrollingEquipValid(chr, scroll, equip) || ItemUtils.isNotItemOptionUpgradeItem(scroll.getItemId())) {
return;
} else if (!ItemUtils.canEquipHavePotential(equip)) {
logger.warning(String.format("Character %d tried to add potential an eligible item (id %d)", chr.getId(), equip.getItemId()));
chr.enableAction();
return;
}
boolean advancePotentialScroll = scroll.getItemId() % 2 == 0;
int successRate = advancePotentialScroll ? ADVANCE_POTENTIAL_BASE_PERCENTAGE : POTENTIAL_BASE_PERCENTAGE;
boolean success = ItemUtils.willSuccess(successRate);

// First remove the scroll (avoid duplication after use) -
chr.consumeItem(InventoryType.CONSUME, scroll.getItemId(), 1);
if (success) {
equip.setGrade(PotentialGradeCode.HiddenRare);
// Update the equip for the client -
chr.write(CWvsContext.inventoryOperation(true, Add, (short) (equip.getInvType() == EQUIPPED ? -equip.getBagIndex() : equip.getBagIndex()), (short) 0, equip));
chr.write(CUser.showOptionItemUpgradeEffect(chr.getId(), true, enchantSkill, 0));
} else {
ItemUtils.applyPotentialBoom(chr, equip, scroll, enchantSkill);
}
}

@Handler(op = UserItemReleaseRequest)
public static void handleUserItemReleaseRequest(MapleClient c,
InPacket inPacket) {
MapleChar chr = c.getChr();

inPacket.decodeInt(); // update time
short useItemPos = inPacket.decodeShort(); //Use Position
short equipPos = inPacket.decodeShort(); //Eqp Position

Item scroll = chr.getInventoryByType(InventoryType.CONSUME).getItemByIndex(useItemPos);
InventoryType invType = equipPos < 0 ? EQUIPPED : EQUIP;
Equip equip = (Equip) chr.getInventoryByType(invType).getItemByIndex(equipPos);
if (!ItemUtils.isScrollingEquipValid(chr, scroll, equip) || !PotentialGradeCode.isHiddenPotential(equip.getGrade())) {
return;
}
//TODO: need to handle calcs for adding option - and wz read it & also third line calc & recalc rates!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ static OutPacket showItemHyperUpgradeEffect(int charID,

return outPacket;
}

static OutPacket showOptionItemUpgradeEffect(int charID,
boolean success,
boolean enchantSkill,
int nEnchantCategory){
OutPacket outPacket = new OutPacket(OutHeader.UserShowItemOptionUpgradeEffect);
outPacket.encodeInt(charID);
outPacket.encodeBool(success);
outPacket.encodeBool(!success);
outPacket.encodeBool(enchantSkill);
outPacket.encodeInt(nEnchantCategory);

return outPacket;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ public interface GameConstants {
int BASE_ATK_ENHANCEMENT = 3;
int BASE_SECONDARY_STAT_ENHANCEMENT = 5;
int BASE_MOBILITY_STAT_ENHANCEMENT = 2;
// Potential -
int POTENTIAL_BASE_PERCENTAGE = 70;
int ADVANCE_POTENTIAL_BASE_PERCENTAGE = 90;
}
27 changes: 27 additions & 0 deletions src/main/java/com/dori/SpringStory/enums/PotentialGradeCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dori.SpringStory.enums;

import lombok.Getter;

@Getter
public enum PotentialGradeCode {
Normal(0),
HiddenRare(1),
HiddenEpic(2),
HiddenUnique(3),
HiddenLegendary(4),
Rare(5),
Epic(6),
Unique(7),
Legendary(8)
;

private final int val;

PotentialGradeCode(int val) {
this.val = val;
}

public static boolean isHiddenPotential(PotentialGradeCode potentialGrade) {
return potentialGrade == HiddenRare || potentialGrade == HiddenEpic || potentialGrade == HiddenUnique || potentialGrade == HiddenLegendary;
}
}
8 changes: 6 additions & 2 deletions src/main/java/com/dori/SpringStory/inventory/Equip.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import com.dori.SpringStory.dataHandlers.dataEntities.EquipData;
import com.dori.SpringStory.enums.EquipAttribute;
import com.dori.SpringStory.enums.EquipBaseStat;
import com.dori.SpringStory.enums.PotentialGradeCode;
import com.dori.SpringStory.utils.utilEntities.FileTime;
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

import static com.dori.SpringStory.enums.PotentialGradeCode.Normal;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
Expand Down Expand Up @@ -53,7 +56,7 @@ public class Equip extends Item {
private short exp;
private short durability = 100; // suppose to be 100
private short iuc;
private short grade;
private PotentialGradeCode grade;
private byte iReduceReq;
private short specialAttribute;
private short durabilityMax;
Expand Down Expand Up @@ -148,6 +151,7 @@ public Equip(EquipData equipData) {
this.superiorEqp = equipData.isSuperiorEqp();
this.iReduceReq = equipData.getIReduceReq();
this.specialGrade = equipData.getSpecialGrade();
this.grade = Normal;
this.options = equipData.getOptions();
}

Expand Down Expand Up @@ -182,7 +186,7 @@ public void encode(OutPacket outPacket) {
outPacket.encodeInt(exp);
outPacket.encodeInt(durability);
outPacket.encodeInt(iuc);
outPacket.encodeByte(grade);
outPacket.encodeByte(grade.getVal());
outPacket.encodeByte(starUpgradeCount);

for (int i = 0; i < 3; i++) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/dori/SpringStory/utils/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,24 @@ static void applyEnchantment(@NotNull Equip equip) {
}
}

static boolean isNotItemOptionUpgradeItem(int nItemID) {
return nItemID / 100 != 20494;
}

static boolean canEquipHavePotential(Equip equip) {
return !equip.isCash() &&
canEquipTypeHavePotential(equip.getItemId()) &&
(ItemDataHandler.getEquipDataByID(equip.getItemId()).getTuc() >= 1 || isSecondary(equip.getItemId()));
}

static void applyPotentialBoom(@NotNull MapleChar chr,
@NotNull Equip equip,
@NotNull Item scroll,
boolean bEnchantSkill) {
chr.consumeItem(InventoryType.CONSUME, scroll.getItemId(), 1);
chr.removeItem(equip.getInvType(), equip.getItemId());
chr.write(CUser.showOptionItemUpgradeEffect(chr.getId(), false, bEnchantSkill, 0));
}


}
19 changes: 19 additions & 0 deletions src/main/java/com/dori/SpringStory/utils/SkillUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,23 @@ static int getNumOfStarsToConsumeBySkillID(int skillID) {
}
return amountOfStarsToConsume;
}

static boolean isShootSkillNotUsingShootingWeapon(int skillId) {
return switch (skillId) {
case 4121003, 4221003, 5121002, 11101004, 15111006, 15111007, 21100004, 21110004, 21120006, 33101007 ->
true;
default -> false;
};
}

static boolean isShootSkillNotConsumingBullet(int skillId) {
if (isShootSkillNotUsingShootingWeapon(skillId)) {
return true;
}
return switch (skillId) {
case 3101003, 3201003, 4111004, 13101005, 14101006, 33101002, 35001001, 35001004, 35101009, 35101010, 35111004, 35111015, 35121005, 35121012, 35121013 ->
true;
default -> false;
};
}
}
2 changes: 1 addition & 1 deletion src/main/resources/InHeadersAddys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ CNpc::GenerateMovePath | 0x00671590 | 241
? | 0x009D5B70 | 0x4B
? | 0x009D5C60 | 0x4C
? | 0x009D5D50 | 0x0F6
? | 0x009D5F10 | 0x61
CWvsContext::SendItemReleaseRequest | 0x009D5F10 | 97
? | 0x009D6000 | 0x5F
CWvsContext::SendHyperUpgradeItemUseRequest | 0x009D6130 | 94
CWvsContext::SendUpgradeItemUseRequest | 0x009D6260 | 93
Expand Down

0 comments on commit 6eba72c

Please sign in to comment.